智慧保安后台管理-外网项目备份
zhongrj
2024-03-25 3222d83845148e2479af6aeb0f029def5f28f8b2
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package org.springblade.modules.system.service.impl;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor;
import org.springblade.common.cache.SysCache;
import org.springblade.common.constant.CommonConstant;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.DigestUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.modules.system.entity.Role;
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.entity.UserWx;
import org.springblade.modules.system.excel.UserExcel;
import org.springblade.modules.system.excel.UserWxExcel;
import org.springblade.modules.system.mapper.UserWxMapper;
import org.springblade.modules.system.service.IRoleService;
import org.springblade.modules.system.service.IUserWxService;
import org.springblade.modules.system.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.Arrays;
import java.util.List;
import java.util.Map;
 
@Service
@AllArgsConstructor
public class UserWxServiceImpl extends BaseServiceImpl<UserWxMapper, UserWx> implements IUserWxService {
    private final IRoleService roleService;
 
    @Override
    public Boolean wxRegister(UserWx user) {
 
        //密码加密
        if (Func.isNotEmpty(user.getPassword())) {
            user.setPassword(DigestUtil.encrypt(user.getPassword()));
        }
 
        UserWx params = new UserWx();
        params.setCardid(user.getCardid());
        //查看数据库是否有相同身份证号
        List<UserWx> list = list(Condition.getQueryWrapper(params));
        if (list.size() > 0) {
            throw new ServiceException("该身份证号已注册");
        }
 
        //注册新用户
        user.setAccount(user.getPhone());
        //微信注册角色
        user.setRoleId("1734015564173127681");
        //微信注册机构
        user.setDeptId("1734016112398020609");
        user.setTenantId("000000");
        if (StringUtil.isNotBlank(user.getRealName())) {
            user.setName(user.getRealName());
        } else {
            user.setName("微信用户" + user.getPhone());
            user.setRealName("微信用户" + user.getPhone());
        }
        boolean save = save(user);
        return save;
    }
 
    @Override
    public UserWx getUserWx(String tenantId, String account, String password) {
        return baseMapper.getUserWx(tenantId, account, password);
    }
 
    @Override
    public IPage<UserVO> selectUserPage(IPage<UserVO> page, User user, Long deptId, String tenantId) {
        List<Long> deptIdList = SysCache.getDeptChildIds(deptId);
        List<UserVO> users = baseMapper.selectUserPage(page, user, deptIdList, tenantId);
        if (users.size() > 0) {
            //遍历获取部门名称,角色名称
            users.forEach(userVO -> {
                //查询当前部门名称及父级部门名称
                if (null != userVO.getDeptId()) {
                    List<String> list = baseMapper.getDeptName(userVO.getDeptId());
                    if (list.size() > 1) {
                        if (null != list.get(1) && list.get(1) != "") {
                            userVO.setDeptName(list.get(1) + "," + list.get(0));
                        } else {
                            userVO.setDeptName(list.get(0));
                        }
                    }
                    if (list.size() == 1) {
                        userVO.setDeptName(list.get(0));
                    }
                }
                //查询角色名称
                if (null != userVO.getRoleId()) {
                    List<String> asList = Arrays.asList(userVO.getRoleId().split(","));
                    StringBuilder builder = new StringBuilder();
                    asList.forEach(roleIs -> {
                        Role role = roleService.getById(roleIs);
                        if (null != role) {
                            builder.append(role.getRoleName() + ",");
                        }
                    });
                    String substringRoleName = null;
                    if (builder.toString().length() > 0) {
                        substringRoleName = builder.toString().substring(0, builder.toString().length() - 1);
                    }
                    userVO.setRoleName(substringRoleName);
                }
            });
        }
        return page.setRecords(users);
    }
 
    @Override
    public UserVO getUserDetailById(Long id) {
        return baseMapper.getUserDetailById(id);
    }
 
    @Override
    public boolean resetPassword(String userIds) {
        UserWx user = new UserWx();
        user.setPassword(DigestUtil.encrypt(CommonConstant.DEFAULT_PASSWORD));
        user.setUpdateTime(DateUtil.now());
        return this.update(user, Wrappers.<UserWx>update().lambda().in(UserWx::getId, Func.toLongList(userIds)));
    }
 
    @Override
    public boolean removeUser(String userIds) {
        if (Func.contains(Func.toLongArray(userIds), AuthUtil.getUserId())) {
            throw new ServiceException("不能删除本账号!");
        }
        return deleteLogic(Func.toLongList(userIds));
    }
 
    @Override
    public List<UserWxExcel> exportUser(Map<String, Object> param) {
        List<UserWxExcel> userList = baseMapper.exportUser(param);
        return userList;
    }
}