UserInfoServiceImpl.java 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package jnpf.permission.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import jnpf.permission.connector.UserInfoService;
  4. import jnpf.permission.entity.UserEntity;
  5. import jnpf.permission.service.UserService;
  6. import jnpf.util.JsonUtil;
  7. import jnpf.util.Md5Util;
  8. import jnpf.util.RandomUtil;
  9. import jnpf.util.StringUtil;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Service;
  12. import java.util.Map;
  13. /**
  14. * 用户信息保存
  15. *
  16. * @author :JNPF开发平台组
  17. * @version: V3.1.0
  18. * @copyright 引迈信息技术有限公司
  19. * @date :2022/7/28 14:38
  20. */
  21. @Service
  22. public class UserInfoServiceImpl implements UserInfoService {
  23. @Autowired
  24. private UserService userService;
  25. @Override
  26. public Boolean create(Map<String, Object> map) {
  27. UserEntity entity = JsonUtil.getJsonToBean(map, UserEntity.class);
  28. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  29. queryWrapper.lambda().eq(UserEntity::getAccount, entity.getAccount());
  30. UserEntity entity1 = userService.getOne(queryWrapper);
  31. if (entity1 != null) {
  32. entity.setId(entity1.getId());
  33. if(StringUtil.isNotEmpty(entity.getPassword())) {
  34. entity.setPassword(Md5Util.getStringMd5(entity.getPassword() + entity1.getSecretkey().toLowerCase()));
  35. }
  36. return userService.updateById(entity);
  37. } else {
  38. if (StringUtil.isEmpty(entity.getId())) {
  39. String userId = RandomUtil.uuId();
  40. entity.setId(userId);
  41. }
  42. entity.setSecretkey(RandomUtil.uuId());
  43. entity.setPassword(Md5Util.getStringMd5(entity.getPassword() + entity.getSecretkey().toLowerCase()));
  44. entity.setIsAdministrator(0);
  45. return userService.save(entity);
  46. }
  47. }
  48. @Override
  49. public Boolean update(Map<String, Object> map) {
  50. return create(map);
  51. }
  52. @Override
  53. public Boolean delete(Map<String, Object> map) {
  54. UserEntity entity = JsonUtil.getJsonToBean(map, UserEntity.class);
  55. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  56. queryWrapper.lambda().eq(UserEntity::getAccount, entity.getAccount());
  57. UserEntity entity1 = userService.getOne(queryWrapper);
  58. if (entity1 != null) {
  59. entity.setId(entity1.getId());
  60. }
  61. return userService.removeById(entity.getId());
  62. }
  63. @Override
  64. public Map<String, Object> getInfo(String id) {
  65. UserEntity entity = userService.getInfo(id);
  66. return JsonUtil.entityToMap(entity);
  67. }
  68. }