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