郑永安
2023-06-19 7a6abd05683528032687c75e80e0bd2030a3e46c
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
package com.gkhy.safePlatform.account.service.baseService.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.safePlatform.account.entity.user.UserInfo;
import com.gkhy.safePlatform.account.entity.user.UserInfoDO;
import com.gkhy.safePlatform.account.enums.UserStatusEnum;
import com.gkhy.safePlatform.account.model.query.db.AccountDBQuery;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.exception.BusinessException;
import com.gkhy.safePlatform.commons.utils.StringUtils;
import com.gkhy.safePlatform.account.repository.UserInfoRepository;
import com.gkhy.safePlatform.account.service.baseService.UserInfoService;
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
@Service("userInfoService")
public class UserInfoServiceImpl extends ServiceImpl<UserInfoRepository, UserInfo> implements UserInfoService {
 
    @Autowired
    private UserInfoRepository userInfoRepository;
 
 
    @Override
    public UserInfo getUserByUsername(String username) {
        if (StringUtils.isBlank(username))
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        return userInfoRepository.getUserInfoByUsername(username);
    }
 
    @Override
    public UserInfo getUserByUserId(Long userId) {
        if (userId == null)
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        return userInfoRepository.getUserInfoByUserId(userId);
    }
 
 
 
    @Override
    public void abandonAccount(Long userId) {
        if (userId == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        int i = userInfoRepository.updateStatus(userId,UserStatusEnum.ABANDONED.getCode());
        if (i == 0) {
            throw new BusinessException(ResultCodes.SERVER_UPDATE_DATA_NO_CHANGE);
        }
        if (i > 1) {
            throw new BusinessException(ResultCodes.SERVER_UPDATE_ERROR);
        }
    }
 
    @Override
    public void saveUserInfo(UserInfo userInfo) {
        if (userInfo == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        int i = userInfoRepository.insertUserInfo(userInfo);
        if (i != 1) {
            throw new BusinessException(ResultCodes.SERVER_ADD_ERROR);
        }
    }
 
 
 
    @Override
    public void updateUserInfo(UserInfo userInfo) {
        if (userInfo == null || userInfo.getUid() == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        int i = userInfoRepository.updateUserInfo(userInfo);
        if (i == 0) {
            throw new BusinessException(ResultCodes.SERVER_UPDATE_DATA_NO_CHANGE);
        }
        if (i > 1) {
            throw new BusinessException(ResultCodes.SERVER_UPDATE_ERROR);
        }
    }
 
    @Override
    public List<UserInfoDO> listPage(Page<UserInfoDO> page, AccountDBQuery accountDBQuery) {
        if (page == null || accountDBQuery == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        return userInfoRepository.listPage(page, accountDBQuery);
    }
 
 
    @Override
    public List<UserInfoDO> getDepUserList(Long depId) {
        if (depId == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        return userInfoRepository.getDepUserList(depId);
    }
 
    @Override
    public long countByDepId(Long depId) {
        if (depId == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        return userInfoRepository.selectCount(new LambdaQueryWrapper<UserInfo>()
                // 部门id
                .eq(UserInfo::getDepId,depId)
                // 状态
                .eq(UserInfo::getStatus,UserStatusEnum.VALID.getCode()));
    }
 
    @Override
    public long countByPositionId(Long positionId) {
        if (positionId == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        return userInfoRepository.selectCount(new LambdaQueryWrapper<UserInfo>()
                // 岗位id
                .eq(UserInfo::getPositionId,positionId)
                // 状态
                .eq(UserInfo::getStatus,UserStatusEnum.VALID.getCode())
        );
    }
 
    @Override
    public long countByIdentify(String identify) {
        if (StringUtils.isBlank(identify)) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        return userInfoRepository.selectCount(new LambdaQueryWrapper<UserInfo>()
                // 身份证
                .eq(UserInfo::getIdentify,identify)
                // 状态
                .eq(UserInfo::getStatus,UserStatusEnum.VALID.getCode()));
    }
 
    @Override
    public long countByRealName(String realName) {
        if (StringUtils.isBlank(realName)) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        return userInfoRepository.selectCount(new LambdaQueryWrapper<UserInfo>()
                // 真名
                .eq(UserInfo::getRealName,realName));
    }
 
    @Override
    public UserInfoDO getUserByPhone(String phone) {
        if (StringUtils.isBlank(phone)) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        return userInfoRepository.getUserByPhone(phone);
    }
 
    @Override
    public long countByPhone(String phone) {
        if (StringUtils.isBlank(phone)) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        return userInfoRepository.selectCount(new LambdaQueryWrapper<UserInfo>()
                // 手机号
                .eq(UserInfo::getPhone,phone)
                // 状态
                .eq(UserInfo::getStatus,UserStatusEnum.VALID.getCode()));
    }
 
    @Override
    public List<UserInfoDO> listAllUser() {
        return userInfoRepository.listAllUser();
    }
 
    @Override
    public List<UserInfoDO> listUserByUids(List<Long> uids) {
        return userInfoRepository.listUserInfoDOByUids(uids);
    }
 
    @Override
    public List<UserInfoDO> listUserByRealName(String realName) {
        if (StringUtils.isBlank(realName)) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        return userInfoRepository.listUserByRealName(realName);
    }
 
    @Override
    public long countByRoleId(Long roleId) {
        if (roleId == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        return userInfoRepository.selectCount(new LambdaQueryWrapper<UserInfo>()
                // 角色id
                .eq(UserInfo::getRoleId,roleId)
                // 状态
                .eq(UserInfo::getStatus,UserStatusEnum.VALID.getCode()));
    }
 
    @Override
    public void resetRoleToNullByRoleId(Long roleId) {
        if (roleId == null) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        userInfoRepository.resetRoleToNullByRoleId(roleId);
    }
 
    @Override
    public UserInfo getUserInfoByIdentify(String identify) {
        if (StringUtils.isBlank(identify)) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        List<UserInfo> userInfos = userInfoRepository.selectList(new LambdaQueryWrapper<UserInfo>()
                // 身份证
                .eq(UserInfo::getIdentify, identify)
                // 状态
                .eq(UserInfo::getStatus, UserStatusEnum.VALID.getCode()));
        if (userInfos.size() == 0) {
            return null;
        }
        if (userInfos.size() > 1) {
            throw new BusinessException(ResultCodes.SERVER_DATABASE_DATA_DUPLICATED);
        }
 
        return userInfos.get(0);
    }
 
    @Override
    public UserInfo getUserInfoByPhone(String phone) {
        if (StringUtils.isBlank(phone)) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        List<UserInfo> userInfos = userInfoRepository.selectList(new LambdaQueryWrapper<UserInfo>()
                // 手机号
                .eq(UserInfo::getPhone, phone)
                // 状态
                .eq(UserInfo::getStatus, UserStatusEnum.VALID.getCode()));
        if (userInfos.size() == 0) {
            return null;
        }
        if (userInfos.size() > 1) {
            throw new BusinessException(ResultCodes.SERVER_DATABASE_DATA_DUPLICATED);
        }
        return userInfos.get(0);
    }
 
    @Override
    public UserInfo getUserInfoByEmail(String email) {
        if (StringUtils.isBlank(email)) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        List<UserInfo> userInfos = userInfoRepository.selectList(new LambdaQueryWrapper<UserInfo>()
                // 手机号
                .eq(UserInfo::getEmail, email)
                // 状态
                .eq(UserInfo::getStatus, UserStatusEnum.VALID.getCode()));
        if (userInfos.size() == 0) {
            return null;
        }
        if (userInfos.size() > 1) {
            throw new BusinessException(ResultCodes.SERVER_DATABASE_DATA_DUPLICATED);
        }
        return userInfos.get(0);
    }
 
    @Override
    public long countByEmail(String email) {
        if (StringUtils.isBlank(email)) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        return userInfoRepository.selectCount(new LambdaQueryWrapper<UserInfo>()
                // email
                .eq(UserInfo::getEmail,email)
                // 状态
                .eq(UserInfo::getStatus,UserStatusEnum.VALID.getCode()));
    }
 
    @Override
    public void updatePassword(Long uid, String salt, String hash) {
        if (uid == null || StringUtils.isBlank(salt) || StringUtils.isBlank(hash)) {
            throw new BusinessException(ResultCodes.SERVER_PARAM_NULL);
        }
        int i = userInfoRepository.updatePassword(uid, salt, hash);
        if (i == 0) {
            throw new BusinessException(ResultCodes.SERVER_UPDATE_DATA_NO_CHANGE);
        }
        if (i > 1) {
            throw new BusinessException(ResultCodes.SERVER_UPDATE_ERROR);
        }
 
    }
 
 
}