Browse Source

教研密码

tags/正式3.2.0
王宁 2 years ago
parent
commit
f568bd1662

+ 182
- 149
suser/src/main/java/com/xhkjedu/suser/service/system/UserService.java View File

13
 import com.xhkjedu.suser.utils.JedisUtil;
13
 import com.xhkjedu.suser.utils.JedisUtil;
14
 import com.xhkjedu.suser.utils.PoiUtils;
14
 import com.xhkjedu.suser.utils.PoiUtils;
15
 import com.xhkjedu.suser.utils.SMSSender;
15
 import com.xhkjedu.suser.utils.SMSSender;
16
+import com.xhkjedu.suser.utils.UserUtil;
16
 import com.xhkjedu.suser.vo.assess.AssessParams;
17
 import com.xhkjedu.suser.vo.assess.AssessParams;
17
 import com.xhkjedu.suser.vo.system.TeacherVo;
18
 import com.xhkjedu.suser.vo.system.TeacherVo;
18
 import com.xhkjedu.suser.vo.system.UserVo;
19
 import com.xhkjedu.suser.vo.system.UserVo;
19
 import com.xhkjedu.suser.vo.system.ZtMsgVo;
20
 import com.xhkjedu.suser.vo.system.ZtMsgVo;
20
-import com.xhkjedu.utils.DESUtils;
21
-import com.xhkjedu.utils.DatesUtil;
22
-import com.xhkjedu.utils.MD5;
23
-import com.xhkjedu.utils.N_Utils;
24
-import com.xhkjedu.utils.PageUtil;
21
+import com.xhkjedu.utils.*;
25
 import com.xhkjedu.vo.PageResult;
22
 import com.xhkjedu.vo.PageResult;
26
 import com.xhkjedu.vo.ResultVo;
23
 import com.xhkjedu.vo.ResultVo;
27
 import lombok.extern.slf4j.Slf4j;
24
 import lombok.extern.slf4j.Slf4j;
32
 
29
 
33
 import javax.annotation.Resource;
30
 import javax.annotation.Resource;
34
 import javax.servlet.http.HttpServletRequest;
31
 import javax.servlet.http.HttpServletRequest;
35
-import java.util.ArrayList;
36
-import java.util.HashMap;
37
-import java.util.List;
38
-import java.util.Map;
39
-import java.util.UUID;
32
+import java.util.*;
40
 
33
 
41
 /**
34
 /**
42
  * @ClassName UserService
35
  * @ClassName UserService
58
     private SchoolMapper schoolMapper;
51
     private SchoolMapper schoolMapper;
59
 
52
 
60
     /**
53
     /**
61
-     *功能描述  根据登录名和密码获取用户信息
54
+     * 功能描述  根据登录名和密码获取用户信息
55
+     *
56
+     * @param * @param user
57
+     * @return com.xhkjedu.vo.ResultVo
62
      * @author WN
58
      * @author WN
63
      * @date 2020/6/1
59
      * @date 2020/6/1
64
-     * @param  * @param user
65
-     * @return com.xhkjedu.vo.ResultVo
66
      */
60
      */
67
-    public ResultVo getUserByLoginnameAndPwd(TUser user,HttpServletRequest request){
61
+    public ResultVo getUserByLoginnameAndPwd(TUser user, HttpServletRequest request) {
68
         ResultVo resultVo = null;
62
         ResultVo resultVo = null;
69
         String loginpwd = user.getLoginpwd();
63
         String loginpwd = user.getLoginpwd();
70
         setLoginPwd(user);
64
         setLoginPwd(user);
71
         UserVo userVo = userMapper.getUserByLoginname(user.getLoginname());
65
         UserVo userVo = userMapper.getUserByLoginname(user.getLoginname());
72
 
66
 
73
-        if(userVo!=null && userVo.getUserid()>0){
67
+        if (userVo != null && userVo.getUserid() > 0) {
74
             user.setUserid(userVo.getUserid());
68
             user.setUserid(userVo.getUserid());
75
             user.setUsername(userVo.getUsername());
69
             user.setUsername(userVo.getUsername());
76
             user.setSchoolid(userVo.getSchoolid());
70
             user.setSchoolid(userVo.getSchoolid());
81
                     resultVo = new ResultVo(0, "登录成功", userVo);
75
                     resultVo = new ResultVo(0, "登录成功", userVo);
82
                 } else if (userVo.getUsertype() == 2) {
76
                 } else if (userVo.getUsertype() == 2) {
83
                     resultVo = new ResultVo(1, "禁止学生登录");
77
                     resultVo = new ResultVo(1, "禁止学生登录");
84
-                } else if(userVo.getSchoolstate()!=1){
85
-                    resultVo = new ResultVo(1,"用户所在学校暂无权限");
86
-                }else{
87
-                    if(userVo.getUserstate()!=1){
88
-                        resultVo = new ResultVo(1,"该账户无权访问,请联系老师");
89
-                    }else{
90
-                        resultVo = new ResultVo(0,"登录成功",userVo);
78
+                } else if (userVo.getSchoolstate() != 1) {
79
+                    resultVo = new ResultVo(1, "用户所在学校暂无权限");
80
+                } else {
81
+                    if (userVo.getUserstate() != 1) {
82
+                        resultVo = new ResultVo(1, "该账户无权访问,请联系老师");
83
+                    } else {
84
+                        resultVo = new ResultVo(0, "登录成功", userVo);
91
                     }
85
                     }
92
                 }
86
                 }
93
             }
87
             }
94
-        }else{
95
-            resultVo = new ResultVo(1,"该账号不存在");
88
+        } else {
89
+            resultVo = new ResultVo(1, "该账号不存在");
96
         }
90
         }
97
 
91
 
98
         return getLogResultVo(user, resultVo, loginpwd, request);
92
         return getLogResultVo(user, resultVo, loginpwd, request);
99
     }
93
     }
100
 
94
 
101
     //教师登录
95
     //教师登录
102
-    public ResultVo loginTeacher(TUser user,HttpServletRequest request){
96
+    public ResultVo loginTeacher(TUser user, HttpServletRequest request) {
103
         ResultVo resultVo = null;
97
         ResultVo resultVo = null;
104
         String loginpwd = user.getLoginpwd();
98
         String loginpwd = user.getLoginpwd();
105
         setLoginPwd(user);
99
         setLoginPwd(user);
106
         UserVo userVo = userMapper.getUserByLoginname(user.getLoginname());
100
         UserVo userVo = userMapper.getUserByLoginname(user.getLoginname());
107
 
101
 
108
-        if(userVo!=null && userVo.getUserid()>0) {
102
+        if (userVo != null && userVo.getUserid() > 0) {
109
             user.setUserid(userVo.getUserid());
103
             user.setUserid(userVo.getUserid());
110
             user.setUsername(userVo.getUsername());
104
             user.setUsername(userVo.getUsername());
111
             user.setSchoolid(userVo.getSchoolid());
105
             user.setSchoolid(userVo.getSchoolid());
116
                     resultVo = new ResultVo(1, "禁止非教师账号登录");
110
                     resultVo = new ResultVo(1, "禁止非教师账号登录");
117
                 } else if (userVo.getSchoolstate() != 1) {
111
                 } else if (userVo.getSchoolstate() != 1) {
118
                     resultVo = new ResultVo(1, "用户所在学校暂无权限");
112
                     resultVo = new ResultVo(1, "用户所在学校暂无权限");
119
-                }else{
120
-                    if(userVo.getUserstate()!=1){
121
-                        resultVo = new ResultVo(1,"该账户无权访问,请联系老师");
122
-                    }else{
123
-                        resultVo = new ResultVo(0,"登录成功",userVo);
113
+                } else {
114
+                    if (userVo.getUserstate() != 1) {
115
+                        resultVo = new ResultVo(1, "该账户无权访问,请联系老师");
116
+                    } else {
117
+                        resultVo = new ResultVo(0, "登录成功", userVo);
124
                     }
118
                     }
125
                 }
119
                 }
126
             }
120
             }
127
-        }else{
128
-            resultVo = new ResultVo(1,"该账号不存在");
121
+        } else {
122
+            resultVo = new ResultVo(1, "该账号不存在");
129
         }
123
         }
130
 
124
 
131
         return getLogResultVo(user, resultVo, loginpwd, request);
125
         return getLogResultVo(user, resultVo, loginpwd, request);
133
 
127
 
134
     /**
128
     /**
135
      * 学生登录
129
      * 学生登录
130
+     *
131
+     * @return com.xhkjedu.vo.ResultVo
136
      * @Param [user]
132
      * @Param [user]
137
      * @Author ywx
133
      * @Author ywx
138
      * @Date 2020/6/2 11:14
134
      * @Date 2020/6/2 11:14
139
-     * @return com.xhkjedu.vo.ResultVo
140
      **/
135
      **/
141
-    public ResultVo loginStudent(TUser user, HttpServletRequest request){
136
+    public ResultVo loginStudent(TUser user, HttpServletRequest request) {
142
         ResultVo resultVo = null;
137
         ResultVo resultVo = null;
143
         String loginpwd = user.getLoginpwd();
138
         String loginpwd = user.getLoginpwd();
144
         setLoginPwd(user);
139
         setLoginPwd(user);
145
         String mac = user.getMac();
140
         String mac = user.getMac();
146
-        UserVo userVo = userMapper.getUserByLoginnameMac(user.getLoginname(),mac);
141
+        UserVo userVo = userMapper.getUserByLoginnameMac(user.getLoginname(), mac);
147
 
142
 
148
-        if(userVo!=null && userVo.getUserid()>0) {
143
+        if (userVo != null && userVo.getUserid() > 0) {
149
             Integer sbindmac = userVo.getSbindmac();
144
             Integer sbindmac = userVo.getSbindmac();
150
             user.setUserid(userVo.getUserid());
145
             user.setUserid(userVo.getUserid());
151
             user.setUsername(userVo.getUsername());
146
             user.setUsername(userVo.getUsername());
156
                 if (userVo.getUsertype() != 2) {
151
                 if (userVo.getUsertype() != 2) {
157
                     resultVo = new ResultVo(1, "登录失败,仅允许学生登录");
152
                     resultVo = new ResultVo(1, "登录失败,仅允许学生登录");
158
                 } else if (userVo.getXznum() == 0) {
153
                 } else if (userVo.getXznum() == 0) {
159
-                    resultVo = new ResultVo(1,"该账号未分配班级");
154
+                    resultVo = new ResultVo(1, "该账号未分配班级");
160
                 } else if (sbindmac == 1 && N_Utils.isNotEmpty(mac)) {
155
                 } else if (sbindmac == 1 && N_Utils.isNotEmpty(mac)) {
161
                     if (N_Utils.isNotEmpty(userVo.getMac()) && !mac.equals(userVo.getMac())) {
156
                     if (N_Utils.isNotEmpty(userVo.getMac()) && !mac.equals(userVo.getMac())) {
162
                         resultVo = new ResultVo(1, "登录失败,该账号已与其他设备关联");
157
                         resultVo = new ResultVo(1, "登录失败,该账号已与其他设备关联");
176
                 userVo.setBindmac(sbindmac);
171
                 userVo.setBindmac(sbindmac);
177
                 userMapper.updateBindMac(userVo);
172
                 userMapper.updateBindMac(userVo);
178
             }
173
             }
179
-        }else{
180
-            resultVo = new ResultVo(1,"该账号不存在");
174
+        } else {
175
+            resultVo = new ResultVo(1, "该账号不存在");
181
         }
176
         }
182
 
177
 
183
         return getLogResultVo(user, resultVo, loginpwd, request);
178
         return getLogResultVo(user, resultVo, loginpwd, request);
185
 
180
 
186
     /**
181
     /**
187
      * 登录日志
182
      * 登录日志
183
+     *
184
+     * @return com.xhkjedu.vo.ResultVo
188
      * @Param [loginname, device, user, result]
185
      * @Param [loginname, device, user, result]
189
      * @Author ywx
186
      * @Author ywx
190
      * @Date 2020/6/2 11:08
187
      * @Date 2020/6/2 11:08
191
-     * @return com.xhkjedu.vo.ResultVo
192
      **/
188
      **/
193
     private ResultVo getLogResultVo(TUser user, ResultVo result, String loginpwd, HttpServletRequest request) {
189
     private ResultVo getLogResultVo(TUser user, ResultVo result, String loginpwd, HttpServletRequest request) {
194
         String loginname = user.getLoginname();
190
         String loginname = user.getLoginname();
209
             //redis
205
             //redis
210
             String ticketKey = UUID.randomUUID().toString().replace("-", "");
206
             String ticketKey = UUID.randomUUID().toString().replace("-", "");
211
             String token = DESUtils.encrypt(ticketKey, ConfigKey.secretKey);//加密
207
             String token = DESUtils.encrypt(ticketKey, ConfigKey.secretKey);//加密
212
-            String key = userVo.getCloudcode()+"_"+userVo.getUserid()+"_"+user.getUltype();
208
+            String key = userVo.getCloudcode() + "_" + userVo.getUserid() + "_" + user.getUltype();
213
             Boolean redis_rtn = set(key, token, ConfigKey.redisdatatime);
209
             Boolean redis_rtn = set(key, token, ConfigKey.redisdatatime);
214
-            if(!redis_rtn){
210
+            if (!redis_rtn) {
215
                 result.setCode(1);
211
                 result.setCode(1);
216
                 result.setMsg("加入缓存出错!");
212
                 result.setMsg("加入缓存出错!");
217
                 return result;
213
                 return result;
224
             }
220
             }
225
         } else {
221
         } else {
226
             userLog.setLoginstate(2);
222
             userLog.setLoginstate(2);
227
-            userLog.setLogtxt(result.getMsg()+",密码:"+loginpwd);
223
+            userLog.setLogtxt(result.getMsg() + ",密码:" + loginpwd);
228
         }
224
         }
229
         try {
225
         try {
230
             userLog.setUserid(user.getUserid());
226
             userLog.setUserid(user.getUserid());
245
 
241
 
246
     /**
242
     /**
247
      * 添加用户信息
243
      * 添加用户信息
244
+     *
245
+     * @return com.xhkjedu.vo.ResultVo
248
      * @Param [user]
246
      * @Param [user]
249
      * @Author ywx
247
      * @Author ywx
250
      * @Date 2020/6/2 9:45
248
      * @Date 2020/6/2 9:45
251
-     * @return com.xhkjedu.vo.ResultVo
252
      **/
249
      **/
253
     public ResultVo save(TUser user) {
250
     public ResultVo save(TUser user) {
254
         Integer schoolid = user.getSchoolid();
251
         Integer schoolid = user.getSchoolid();
257
             Integer usernum2 = userMapper.getUserNumBySchoolId(schoolid);
254
             Integer usernum2 = userMapper.getUserNumBySchoolId(schoolid);
258
             usernum2 = usernum2 + 1;//学校账号数量+本次添加的人
255
             usernum2 = usernum2 + 1;//学校账号数量+本次添加的人
259
             if (usernum.compareTo(usernum2) == -1) {
256
             if (usernum.compareTo(usernum2) == -1) {
260
-                return new ResultVo(1,"账号数量已超限,请联系管理员");
257
+                return new ResultVo(1, "账号数量已超限,请联系管理员");
261
             }
258
             }
262
         }
259
         }
263
         user.setUserstate(1);
260
         user.setUserstate(1);
264
         user.setCreatetime(N_Utils.getSecondTimestamp());
261
         user.setCreatetime(N_Utils.getSecondTimestamp());
265
         setLoginPwd(user);
262
         setLoginPwd(user);
266
         userMapper.insertUseGeneratedKeys(user);
263
         userMapper.insertUseGeneratedKeys(user);
267
-        return new ResultVo(0, "保存成功",user.getId());
264
+        return new ResultVo(0, "保存成功", user.getId());
268
     }
265
     }
269
 
266
 
270
     /**
267
     /**
271
      * 修改用户信息
268
      * 修改用户信息
269
+     *
270
+     * @return com.xhkjedu.vo.ResultVo
272
      * @Param [user]
271
      * @Param [user]
273
      * @Author ywx
272
      * @Author ywx
274
      * @Date 2020/6/2 9:51
273
      * @Date 2020/6/2 9:51
275
-     * @return com.xhkjedu.vo.ResultVo
276
      **/
274
      **/
277
     public ResultVo update(TUser user) {
275
     public ResultVo update(TUser user) {
278
         if (N_Utils.isNotEmpty(user.getLoginpwd())) {
276
         if (N_Utils.isNotEmpty(user.getLoginpwd())) {
282
         if (N_Utils.isNotEmpty(loginname)) {
280
         if (N_Utils.isNotEmpty(loginname)) {
283
             TUser user1 = getObjByLoginName(loginname);
281
             TUser user1 = getObjByLoginName(loginname);
284
             //登录账号改变并且和别的账号冲突
282
             //登录账号改变并且和别的账号冲突
285
-            if (user1!=null && !user1.getUserid().equals(user.getUserid())) {
286
-                return new ResultVo(1,"此用户已存在,请更换!");
283
+            if (user1 != null && !user1.getUserid().equals(user.getUserid())) {
284
+                return new ResultVo(1, "此用户已存在,请更换!");
287
             }
285
             }
288
         }
286
         }
289
         user.setCreatetime(N_Utils.getSecondTimestamp());
287
         user.setCreatetime(N_Utils.getSecondTimestamp());
290
         userMapper.updateByPrimaryKeySelective(user);
288
         userMapper.updateByPrimaryKeySelective(user);
291
-        return new ResultVo(0,"修改成功");
289
+        return new ResultVo(0, "修改成功");
292
     }
290
     }
293
 
291
 
294
     private void setLoginPwd(TUser user) {
292
     private void setLoginPwd(TUser user) {
299
 
297
 
300
     /**
298
     /**
301
      * 删除用户
299
      * 删除用户
300
+     *
301
+     * @return com.xhkjedu.vo.ResultVo
302
      * @Param [user]
302
      * @Param [user]
303
      * @Author ywx
303
      * @Author ywx
304
      * @Date 2020/6/2 9:59
304
      * @Date 2020/6/2 9:59
305
-     * @return com.xhkjedu.vo.ResultVo
306
      **/
305
      **/
307
     public ResultVo deleteById(TUser user) {
306
     public ResultVo deleteById(TUser user) {
308
         user.setDeletetime(N_Utils.getSecondTimestamp());
307
         user.setDeletetime(N_Utils.getSecondTimestamp());
309
         userMapper.deleteById(user);
308
         userMapper.deleteById(user);
310
-        return new ResultVo(0,"删除成功");
309
+        return new ResultVo(0, "删除成功");
311
     }
310
     }
312
 
311
 
313
     /**
312
     /**
314
      * 获取用户列表
313
      * 获取用户列表
314
+     *
315
+     * @return com.xhkjedu.vo.ResultVo
315
      * @Param [user]
316
      * @Param [user]
316
      * @Author ywx
317
      * @Author ywx
317
      * @Date 2020/6/2 10:06
318
      * @Date 2020/6/2 10:06
318
-     * @return com.xhkjedu.vo.ResultVo
319
      **/
319
      **/
320
     public ResultVo findAll(TUser user) {
320
     public ResultVo findAll(TUser user) {
321
         PageHelper.startPage(user.getPage(), user.getPageSize());
321
         PageHelper.startPage(user.getPage(), user.getPageSize());
322
         List<UserVo> list = userMapper.findAll(user);
322
         List<UserVo> list = userMapper.findAll(user);
323
         PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(list));
323
         PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(list));
324
-        return new ResultVo(0,"获取列表成功", pageResult);
324
+        return new ResultVo(0, "获取列表成功", pageResult);
325
     }
325
     }
326
 
326
 
327
     /**
327
     /**
328
      * 获取用户详情
328
      * 获取用户详情
329
+     *
330
+     * @return com.xhkjedu.vo.ResultVo
329
      * @Param [userid]
331
      * @Param [userid]
330
      * @Author ywx
332
      * @Author ywx
331
      * @Date 2020/6/2 10:23
333
      * @Date 2020/6/2 10:23
332
-     * @return com.xhkjedu.vo.ResultVo
333
      **/
334
      **/
334
     public ResultVo findById(Integer userid) {
335
     public ResultVo findById(Integer userid) {
335
         UserVo userVo = userMapper.findById(userid);
336
         UserVo userVo = userMapper.findById(userid);
336
-        return new ResultVo(0,"获取详情成功", userVo);
337
+        return new ResultVo(0, "获取详情成功", userVo);
337
     }
338
     }
338
 
339
 
339
     /**
340
     /**
340
      * 修改用户密码
341
      * 修改用户密码
342
+     *
343
+     * @return com.xhkjedu.vo.ResultVo
341
      * @Param [user]
344
      * @Param [user]
342
      * @Author ywx
345
      * @Author ywx
343
      * @Date 2020/6/2 10:30
346
      * @Date 2020/6/2 10:30
344
-     * @return com.xhkjedu.vo.ResultVo
345
      **/
347
      **/
346
     public ResultVo updatePwd(TUser user) {
348
     public ResultVo updatePwd(TUser user) {
347
-        UserVo userVo = userMapper.findById(user.getUserid());
348
-
349
-        String oldpwd = this.md5pwd(user.getOldpwd());
350
-        if(userVo.getLoginpwd().equals(oldpwd)){
351
-            setLoginPwd(user);
352
-            userMapper.updatePwd(user);
353
-            return new ResultVo(0,"修改成功");
354
-        }else{
355
-            return new ResultVo(1,"原密码错误");
349
+        ResultVo pwdResultVo = UserUtil.checkhLoginPwd(user.getLoginpwd());
350
+        if (pwdResultVo.getCode() == 0) {
351
+            UserVo userVo = userMapper.findById(user.getUserid());
352
+            String oldpwd = this.md5pwd(user.getOldpwd());
353
+            if (userVo.getLoginpwd().equals(oldpwd)) {
354
+                setLoginPwd(user);
355
+                userMapper.updatePwd(user);
356
+                return new ResultVo(0, "修改成功");
357
+            } else {
358
+                return new ResultVo(1, "原密码错误");
359
+            }
360
+        } else {
361
+            return pwdResultVo;
356
         }
362
         }
357
-
358
     }
363
     }
359
 
364
 
360
     /**
365
     /**
361
      * 修改用户头像
366
      * 修改用户头像
367
+     *
368
+     * @return com.xhkjedu.vo.ResultVo
362
      * @Param [user]
369
      * @Param [user]
363
      * @Author ywx
370
      * @Author ywx
364
      * @Date 2020/6/2 10:37
371
      * @Date 2020/6/2 10:37
365
-     * @return com.xhkjedu.vo.ResultVo
366
      **/
372
      **/
367
     public ResultVo updateHeadPic(TUser user) {
373
     public ResultVo updateHeadPic(TUser user) {
368
         userMapper.updateHeadPic(user);
374
         userMapper.updateHeadPic(user);
369
-        return new ResultVo(0,"修改成功");
375
+        return new ResultVo(0, "修改成功");
370
     }
376
     }
371
 
377
 
372
     /**
378
     /**
373
      * 检查登录账号是否存在
379
      * 检查登录账号是否存在
380
+     *
381
+     * @return com.xhkjedu.vo.ResultVo
374
      * @Param [loginname]
382
      * @Param [loginname]
375
      * @Author ywx
383
      * @Author ywx
376
      * @Date 2020/6/2 10:44
384
      * @Date 2020/6/2 10:44
377
-     * @return com.xhkjedu.vo.ResultVo
378
      **/
385
      **/
379
     public ResultVo checkLoginName(String loginname) {
386
     public ResultVo checkLoginName(String loginname) {
380
         Integer num = userMapper.checkLoginName(loginname);
387
         Integer num = userMapper.checkLoginName(loginname);
381
-        if (num != 0){
382
-            return new ResultVo(1,"此用户已存在,请更换!");
388
+        if (num != 0) {
389
+            return new ResultVo(1, "此用户已存在,请更换!");
383
         } else {
390
         } else {
384
             return new ResultVo(0, "检查登录账号是否存在成功");
391
             return new ResultVo(0, "检查登录账号是否存在成功");
385
         }
392
         }
387
 
394
 
388
     /**
395
     /**
389
      * 根据登录账号获取用户详情
396
      * 根据登录账号获取用户详情
397
+     *
398
+     * @return com.xhkjedu.model.system.TUser
390
      * @Param [loginname]
399
      * @Param [loginname]
391
      * @Author ywx
400
      * @Author ywx
392
      * @Date 2020/6/3 9:33
401
      * @Date 2020/6/3 9:33
393
-     * @return com.xhkjedu.model.system.TUser
394
      **/
402
      **/
395
     public TUser getObjByLoginName(String loginname) {
403
     public TUser getObjByLoginName(String loginname) {
396
         return userMapper.getObjByLoginName(loginname);
404
         return userMapper.getObjByLoginName(loginname);
398
 
406
 
399
     /**
407
     /**
400
      * 批量添加
408
      * 批量添加
409
+     *
410
+     * @return void
401
      * @Param [users]
411
      * @Param [users]
402
      * @Author ywx
412
      * @Author ywx
403
      * @Date 2020/6/3 18:27
413
      * @Date 2020/6/3 18:27
404
-     * @return void
405
      **/
414
      **/
406
     public void batchSave(List<TUser> users) throws Exception {
415
     public void batchSave(List<TUser> users) throws Exception {
407
         Integer schoolid = users.get(0).getSchoolid();
416
         Integer schoolid = users.get(0).getSchoolid();
418
 
427
 
419
     /**
428
     /**
420
      * 修改用户状态
429
      * 修改用户状态
430
+     *
431
+     * @return void
421
      * @Param [userid, userstate]
432
      * @Param [userid, userstate]
422
      * @Author ywx
433
      * @Author ywx
423
      * @Date 2020/6/4 9:08
434
      * @Date 2020/6/4 9:08
424
-     * @return void
425
      **/
435
      **/
426
     public void updateState(Integer userid, int userstate) {
436
     public void updateState(Integer userid, int userstate) {
427
         userMapper.updateState(userid, userstate);
437
         userMapper.updateState(userid, userstate);
429
 
439
 
430
     /**
440
     /**
431
      * 导入教师
441
      * 导入教师
442
+     *
443
+     * @return com.xhkjedu.vo.ResultVo
432
      * @Param [file, tUser]
444
      * @Param [file, tUser]
433
      * @Author ywx
445
      * @Author ywx
434
      * @Date 2020/6/5 8:47
446
      * @Date 2020/6/5 8:47
435
-     * @return com.xhkjedu.vo.ResultVo
436
      **/
447
      **/
437
     public ResultVo importTeacher(MultipartFile file, TUser tUser) {
448
     public ResultVo importTeacher(MultipartFile file, TUser tUser) {
438
         Integer schoolid = tUser.getSchoolid();
449
         Integer schoolid = tUser.getSchoolid();
439
         Integer createid = tUser.getCreateid();
450
         Integer createid = tUser.getCreateid();
440
-        N_Utils.validation(new Object[]{schoolid,"学校id",1,createid,"创建人id",1});
451
+        N_Utils.validation(new Object[]{schoolid, "学校id", 1, createid, "创建人id", 1});
441
         try {
452
         try {
442
-            Map<String,Object> map = PoiUtils.readExcelUser(file, 1);
443
-            List<TUser> teachers = (List<TUser>)map.get("users");
453
+            Map<String, Object> map = PoiUtils.readExcelUser(file, 1);
454
+            List<TUser> teachers = (List<TUser>) map.get("users");
444
             map.remove("users");//导入成功的教师信息不返回给前端
455
             map.remove("users");//导入成功的教师信息不返回给前端
445
 
456
 
446
             List<TUser> users = new ArrayList<>();
457
             List<TUser> users = new ArrayList<>();
448
             List<TUser> usersExisted = new ArrayList<>();
459
             List<TUser> usersExisted = new ArrayList<>();
449
             for (TUser user : teachers) {
460
             for (TUser user : teachers) {
450
                 TUser u = getObjByLoginName(user.getLoginname());
461
                 TUser u = getObjByLoginName(user.getLoginname());
451
-                if (null == u){
462
+                if (null == u) {
452
                     user.setSchoolid(schoolid);
463
                     user.setSchoolid(schoolid);
453
                     user.setCreateid(createid);
464
                     user.setCreateid(createid);
454
                     user.setCreatetime(N_Utils.getSecondTimestamp());
465
                     user.setCreatetime(N_Utils.getSecondTimestamp());
455
                     user.setUserstate(1);
466
                     user.setUserstate(1);
456
                     users.add(user);
467
                     users.add(user);
457
                 } else {
468
                 } else {
458
-                    if (1 != u.getUsertype() || schoolid != u.getSchoolid()){
469
+                    if (1 != u.getUsertype() || schoolid != u.getSchoolid()) {
459
                         usersExisted.add(u);
470
                         usersExisted.add(u);
460
                     } else {
471
                     } else {
461
                         usersExisted.add(u);
472
                         usersExisted.add(u);
467
             if (!CollectionUtils.isEmpty(users)) {
478
             if (!CollectionUtils.isEmpty(users)) {
468
                 batchSave(users);
479
                 batchSave(users);
469
             }
480
             }
470
-            map.put("usersExisted",usersExisted);
471
-            if (N_Utils.isListNotEmpty(usersExisted)){
472
-                map.put("code",1);
481
+            map.put("usersExisted", usersExisted);
482
+            if (N_Utils.isListNotEmpty(usersExisted)) {
483
+                map.put("code", 1);
473
             } else {
484
             } else {
474
-                map.put("code",0);
485
+                map.put("code", 0);
475
             }
486
             }
476
             return new ResultVo(0, "导入成功", map);
487
             return new ResultVo(0, "导入成功", map);
477
         } catch (Exception e) {
488
         } catch (Exception e) {
480
         }
491
         }
481
     }
492
     }
482
 
493
 
483
-    private String md5pwd(String pwd){
494
+    private String md5pwd(String pwd) {
484
         MD5 m = new MD5();
495
         MD5 m = new MD5();
485
         String loginpwd = m.getMD5ofStr(m.getMD5ofStr(m.getMD5ofStr(pwd)));
496
         String loginpwd = m.getMD5ofStr(m.getMD5ofStr(m.getMD5ofStr(pwd)));
486
         return loginpwd;
497
         return loginpwd;
487
     }
498
     }
488
 
499
 
489
     /**
500
     /**
490
-     *功能描述 修改操作密码
501
+     * 功能描述 修改操作密码
502
+     *
503
+     * @param * @param user
504
+     * @return void
491
      * @author WN
505
      * @author WN
492
      * @date 2020/6/17
506
      * @date 2020/6/17
493
-     * @param  * @param user
494
-     * @return void
495
      */
507
      */
496
-    public void updateOpepasswordByUserId(TUser user){
508
+    public void updateOpepasswordByUserId(TUser user) {
497
         String pwd = md5pwd(user.getOpepassword());
509
         String pwd = md5pwd(user.getOpepassword());
498
-        userMapper.updateOpepasswordByUserId(user.getUserid(),pwd);
510
+        userMapper.updateOpepasswordByUserId(user.getUserid(), pwd);
499
     }
511
     }
500
 
512
 
501
     /**
513
     /**
502
-     *功能描述 验证用户操作密码
514
+     * 功能描述 验证用户操作密码
515
+     *
516
+     * @param * @param user
517
+     * @return java.lang.Integer
503
      * @author WN
518
      * @author WN
504
      * @date 2020/6/17
519
      * @date 2020/6/17
505
-     * @param  * @param user
506
-     * @return java.lang.Integer
507
      */
520
      */
508
-    public Integer getUserIdByOpepassword(TUser user){
521
+    public Integer getUserIdByOpepassword(TUser user) {
509
         String pwd = md5pwd(user.getOpepassword());
522
         String pwd = md5pwd(user.getOpepassword());
510
-        return userMapper.getUserIdByOpepassword(user.getUserid(),pwd);
523
+        return userMapper.getUserIdByOpepassword(user.getUserid(), pwd);
511
     }
524
     }
512
 
525
 
513
     /**
526
     /**
514
      * 教师基本信息
527
      * 教师基本信息
528
+     *
529
+     * @return com.xhkjedu.suser.vo.system.TeacherVo
515
      * @Param [userid]
530
      * @Param [userid]
516
      * @Author ywx
531
      * @Author ywx
517
      * @Date 2020/6/29 16:23
532
      * @Date 2020/6/29 16:23
518
-     * @return com.xhkjedu.suser.vo.system.TeacherVo
519
      **/
533
      **/
520
     public TeacherVo getTeacherInfo(Integer userid, Integer classtype) {
534
     public TeacherVo getTeacherInfo(Integer userid, Integer classtype) {
521
         return userMapper.getTeacherInfo(userid, classtype);
535
         return userMapper.getTeacherInfo(userid, classtype);
523
 
537
 
524
     /**
538
     /**
525
      * 重置密码
539
      * 重置密码
540
+     *
541
+     * @return com.xhkjedu.vo.ResultVo
526
      * @Param [user]
542
      * @Param [user]
527
      * @Author ywx
543
      * @Author ywx
528
      * @Date 2020/7/30 14:25
544
      * @Date 2020/7/30 14:25
529
-     * @return com.xhkjedu.vo.ResultVo
530
      **/
545
      **/
531
     public ResultVo resetPwd(TUser user) {
546
     public ResultVo resetPwd(TUser user) {
532
-        setLoginPwd(user);
533
-        userMapper.updatePwd(user);
534
-        return new ResultVo(0,"重置密码成功");
547
+        ResultVo pwdResultVo = UserUtil.checkhLoginPwd(user.getLoginpwd());
548
+        if (pwdResultVo.getCode() == 0) {//密码验证通过
549
+            setLoginPwd(user);
550
+            userMapper.updatePwd(user);
551
+            return new ResultVo(0, "重置密码成功");
552
+        } else {
553
+            return pwdResultVo;
554
+        }
535
     }
555
     }
536
 
556
 
537
     /**
557
     /**
538
      * 解除mac绑定
558
      * 解除mac绑定
559
+     *
560
+     * @return void
539
      * @Param [studentid]
561
      * @Param [studentid]
540
      * @Author ywx
562
      * @Author ywx
541
      * @Date 2020/9/18 11:56
563
      * @Date 2020/9/18 11:56
542
-     * @return void
543
      **/
564
      **/
544
     public void removeBind(Integer studentid) {
565
     public void removeBind(Integer studentid) {
545
         UserVo user = new UserVo();
566
         UserVo user = new UserVo();
551
 
572
 
552
     /**
573
     /**
553
      * 生成修改码
574
      * 生成修改码
575
+     *
576
+     * @return com.xhkjedu.vo.ResultVo
554
      * @Param [userphone]
577
      * @Param [userphone]
555
      * @Author ywx
578
      * @Author ywx
556
      * @Date 2020/10/13 15:08
579
      * @Date 2020/10/13 15:08
557
-     * @return com.xhkjedu.vo.ResultVo
558
      **/
580
      **/
559
     public ResultVo updateCode(String userphone) {
581
     public ResultVo updateCode(String userphone) {
560
         String templateCode = "xgmm";
582
         String templateCode = "xgmm";
561
         if (generateCode(userphone, templateCode)) return new ResultVo(1, "请输入验证码或者在5分钟之后重新点击");
583
         if (generateCode(userphone, templateCode)) return new ResultVo(1, "请输入验证码或者在5分钟之后重新点击");
562
-        return new ResultVo(0,"生成修改码成功");
584
+        return new ResultVo(0, "生成修改码成功");
563
     }
585
     }
564
 
586
 
565
     /**
587
     /**
566
      * 生成验证码
588
      * 生成验证码
589
+     *
590
+     * @return boolean
567
      * @Param [userphone, templateCode]
591
      * @Param [userphone, templateCode]
568
      * @Author ywx
592
      * @Author ywx
569
      * @Date 2020/5/8 10:04
593
      * @Date 2020/5/8 10:04
570
-     * @return boolean
571
      **/
594
      **/
572
     private boolean generateCode(String userphone, String templateCode) {
595
     private boolean generateCode(String userphone, String templateCode) {
573
         Integer msgNum = msgMapper.getMsgNumByUserPhone(userphone);//5分钟内发送短信次数
596
         Integer msgNum = msgMapper.getMsgNumByUserPhone(userphone);//5分钟内发送短信次数
599
 
622
 
600
     /**
623
     /**
601
      * 通过短信修改密码
624
      * 通过短信修改密码
625
+     *
626
+     * @return com.xhkjedu.vo.ResultVo
602
      * @Param [user]
627
      * @Param [user]
603
      * @Author ywx
628
      * @Author ywx
604
      * @Date 2020/10/13 15:17
629
      * @Date 2020/10/13 15:17
605
-     * @return com.xhkjedu.vo.ResultVo
606
      **/
630
      **/
607
     public ResultVo updatePwdByCode(TUser user) {
631
     public ResultVo updatePwdByCode(TUser user) {
608
-        setLoginPwd(user);
609
-        ResultVo x = getCodeResultVo(user.getUserphone(), user.getMsgcode());
610
-        if (x != null) return x;
611
-        userMapper.updatePwdByCode(user);
612
-        return new ResultVo(0,"修改成功");
632
+        ResultVo pwdResultVo = UserUtil.checkhLoginPwd(user.getLoginpwd());
633
+        if (pwdResultVo.getCode() == 0) {
634
+            setLoginPwd(user);
635
+            ResultVo x = getCodeResultVo(user.getUserphone(), user.getMsgcode());
636
+            if (x != null) return x;
637
+            userMapper.updatePwdByCode(user);
638
+            return new ResultVo(0, "修改成功");
639
+        } else {
640
+            return pwdResultVo;
641
+        }
613
     }
642
     }
614
 
643
 
615
     /**
644
     /**
616
      * 判断验证码是否有效
645
      * 判断验证码是否有效
646
+     *
647
+     * @return com.xhkjedu.model.baseinfo.ResultVo
617
      * @Param [userphone, messageCode]
648
      * @Param [userphone, messageCode]
618
      * @Author ywx
649
      * @Author ywx
619
      * @Date 2020/5/8 10:21
650
      * @Date 2020/5/8 10:21
620
-     * @return com.xhkjedu.model.baseinfo.ResultVo
621
      **/
651
      **/
622
     private ResultVo getCodeResultVo(String userphone, Integer messageCode) {
652
     private ResultVo getCodeResultVo(String userphone, Integer messageCode) {
623
         TMsg msg = msgMapper.findByUserPhoneAndCode(userphone, messageCode);//根据手机号和验证码获取短信信息
653
         TMsg msg = msgMapper.findByUserPhoneAndCode(userphone, messageCode);//根据手机号和验证码获取短信信息
629
 
659
 
630
     /**
660
     /**
631
      * 生成登录确认码
661
      * 生成登录确认码
662
+     *
663
+     * @return com.xhkjedu.vo.ResultVo
632
      * @Param [userphone]
664
      * @Param [userphone]
633
      * @Author ywx
665
      * @Author ywx
634
      * @Date 2020/10/13 15:19
666
      * @Date 2020/10/13 15:19
635
-     * @return com.xhkjedu.vo.ResultVo
636
      **/
667
      **/
637
     public ResultVo loginCode(String userphone) {
668
     public ResultVo loginCode(String userphone) {
638
-        N_Utils.validation(new Object[]{userphone,"手机号",2});
669
+        N_Utils.validation(new Object[]{userphone, "手机号", 2});
639
         String templateCode = "dlqr";
670
         String templateCode = "dlqr";
640
         if (generateCode(userphone, templateCode)) return new ResultVo(1, "请输入验证码或者在5分钟之后重新点击");
671
         if (generateCode(userphone, templateCode)) return new ResultVo(1, "请输入验证码或者在5分钟之后重新点击");
641
-        return new ResultVo(0,"生成登录确认码成功");
672
+        return new ResultVo(0, "生成登录确认码成功");
642
     }
673
     }
643
 
674
 
644
     /**
675
     /**
645
      * 验证码登录
676
      * 验证码登录
677
+     *
678
+     * @return com.xhkjedu.vo.ResultVo
646
      * @Param [user]
679
      * @Param [user]
647
      * @Author ywx
680
      * @Author ywx
648
      * @Date 2020/10/13 15:36
681
      * @Date 2020/10/13 15:36
649
-     * @return com.xhkjedu.vo.ResultVo
650
      **/
682
      **/
651
-    public ResultVo loginByCode(TUser user,HttpServletRequest request) {
683
+    public ResultVo loginByCode(TUser user, HttpServletRequest request) {
652
         ResultVo resultVo = getCodeResultVo(user.getUserphone(), user.getMsgcode());
684
         ResultVo resultVo = getCodeResultVo(user.getUserphone(), user.getMsgcode());
653
         if (resultVo != null) return resultVo;
685
         if (resultVo != null) return resultVo;
654
         UserVo userVo = userMapper.getUserByLoginname(user.getUserphone());
686
         UserVo userVo = userMapper.getUserByLoginname(user.getUserphone());
655
 
687
 
656
-        if(userVo!=null && userVo.getUserid()>0){
688
+        if (userVo != null && userVo.getUserid() > 0) {
657
             user.setUserid(userVo.getUserid());
689
             user.setUserid(userVo.getUserid());
658
             user.setUsername(userVo.getUsername());
690
             user.setUsername(userVo.getUsername());
659
             user.setSchoolid(userVo.getSchoolid());
691
             user.setSchoolid(userVo.getSchoolid());
660
-            if(userVo.getUsertype()==999){
661
-                resultVo = new ResultVo(0,"登录成功",userVo);
662
-            } else if(userVo.getUsertype()==2){
663
-                resultVo = new ResultVo(1,"禁止学生登录");
664
-            } else if(userVo.getSchoolstate()!=1){
665
-                resultVo = new ResultVo(1,"用户所在学校暂无权限");
666
-            }else{
667
-                if(userVo.getUserstate()!=1){
668
-                    resultVo = new ResultVo(1,"该账户无权访问,请联系老师");
669
-                }else{
670
-                    resultVo = new ResultVo(0,"登录成功",userVo);
692
+            if (userVo.getUsertype() == 999) {
693
+                resultVo = new ResultVo(0, "登录成功", userVo);
694
+            } else if (userVo.getUsertype() == 2) {
695
+                resultVo = new ResultVo(1, "禁止学生登录");
696
+            } else if (userVo.getSchoolstate() != 1) {
697
+                resultVo = new ResultVo(1, "用户所在学校暂无权限");
698
+            } else {
699
+                if (userVo.getUserstate() != 1) {
700
+                    resultVo = new ResultVo(1, "该账户无权访问,请联系老师");
701
+                } else {
702
+                    resultVo = new ResultVo(0, "登录成功", userVo);
671
                 }
703
                 }
672
             }
704
             }
673
-        }else{
674
-            resultVo = new ResultVo(1,"该账号不存在");
705
+        } else {
706
+            resultVo = new ResultVo(1, "该账号不存在");
675
         }
707
         }
676
 
708
 
677
-        return getLogResultVo(user, resultVo, user.getMsgcode()+"", request);
709
+        return getLogResultVo(user, resultVo, user.getMsgcode() + "", request);
678
     }
710
     }
679
 
711
 
680
     public ResultVo batchUpdatePwd(TUser user) {
712
     public ResultVo batchUpdatePwd(TUser user) {
681
         setLoginPwd(user);
713
         setLoginPwd(user);
682
         userMapper.batchUpdatePwd(user);
714
         userMapper.batchUpdatePwd(user);
683
-        return new ResultVo(0,"修改成功");
715
+        return new ResultVo(0, "修改成功");
684
     }
716
     }
685
 
717
 
686
     public ResultVo checkLogin(Integer userid, String loginpwd) {
718
     public ResultVo checkLogin(Integer userid, String loginpwd) {
719
         ResultVo resultVo = null;
751
         ResultVo resultVo = null;
720
         UserVo userVo = userMapper.getUserByLoginname(user.getLoginname());
752
         UserVo userVo = userMapper.getUserByLoginname(user.getLoginname());
721
 
753
 
722
-        if(userVo!=null && userVo.getUserid()>0){
754
+        if (userVo != null && userVo.getUserid() > 0) {
723
             user.setUserid(userVo.getUserid());
755
             user.setUserid(userVo.getUserid());
724
             user.setUsername(userVo.getUsername());
756
             user.setUsername(userVo.getUsername());
725
             user.setSchoolid(userVo.getSchoolid());
757
             user.setSchoolid(userVo.getSchoolid());
726
             user.setUltype("p_web_t");
758
             user.setUltype("p_web_t");
727
-            if(userVo.getUsertype()==999){
728
-                resultVo = new ResultVo(0,"登录成功",userVo);
729
-            } else if(userVo.getUsertype()==2){
730
-                resultVo = new ResultVo(1,"禁止学生登录");
731
-            } else if(userVo.getSchoolstate()!=1){
732
-                resultVo = new ResultVo(1,"用户所在学校暂无权限");
733
-            }else{
734
-                if(userVo.getUserstate()!=1){
735
-                    resultVo = new ResultVo(1,"该账户无权访问,请联系老师");
736
-                }else{
737
-                    resultVo = new ResultVo(0,"登录成功",userVo);
759
+            if (userVo.getUsertype() == 999) {
760
+                resultVo = new ResultVo(0, "登录成功", userVo);
761
+            } else if (userVo.getUsertype() == 2) {
762
+                resultVo = new ResultVo(1, "禁止学生登录");
763
+            } else if (userVo.getSchoolstate() != 1) {
764
+                resultVo = new ResultVo(1, "用户所在学校暂无权限");
765
+            } else {
766
+                if (userVo.getUserstate() != 1) {
767
+                    resultVo = new ResultVo(1, "该账户无权访问,请联系老师");
768
+                } else {
769
+                    resultVo = new ResultVo(0, "登录成功", userVo);
738
                 }
770
                 }
739
             }
771
             }
740
-        }else{
741
-            resultVo = new ResultVo(1,"该账号不存在");
772
+        } else {
773
+            resultVo = new ResultVo(1, "该账号不存在");
742
         }
774
         }
743
 
775
 
744
         return getLogResultVo(user, resultVo, "", request);
776
         return getLogResultVo(user, resultVo, "", request);
746
 
778
 
747
     /**
779
     /**
748
      * 获取头像是否可以修改
780
      * 获取头像是否可以修改
781
+     *
782
+     * @return java.lang.Integer
749
      * @Param [userid]
783
      * @Param [userid]
750
      * @Author ywx
784
      * @Author ywx
751
      * @Date 2022/3/14 9:58
785
      * @Date 2022/3/14 9:58
752
-     * @return java.lang.Integer
753
      **/
786
      **/
754
     public Integer getHeadTime(Integer userid) {
787
     public Integer getHeadTime(Integer userid) {
755
         return userMapper.getHeadTime(userid);
788
         return userMapper.getHeadTime(userid);

+ 21
- 2
suser/src/main/java/com/xhkjedu/suser/utils/UserUtil.java View File

1
 package com.xhkjedu.suser.utils;
1
 package com.xhkjedu.suser.utils;
2
 
2
 
3
+import com.xhkjedu.vo.ResultVo;
3
 import lombok.extern.slf4j.Slf4j;
4
 import lombok.extern.slf4j.Slf4j;
4
 import org.springframework.http.HttpEntity;
5
 import org.springframework.http.HttpEntity;
5
 import org.springframework.http.HttpHeaders;
6
 import org.springframework.http.HttpHeaders;
22
 public class UserUtil {
23
 public class UserUtil {
23
     /**
24
     /**
24
      * 发送form-data请求返回json结果
25
      * 发送form-data请求返回json结果
26
+     *
27
+     * @return java.lang.String
25
      * @Param [apiUrl, param]
28
      * @Param [apiUrl, param]
26
      * @Author ywx
29
      * @Author ywx
27
      * @Date 2021/5/14 17:41
30
      * @Date 2021/5/14 17:41
28
-     * @return java.lang.String
29
      **/
31
      **/
30
     public static String sendFormData(String apiUrl, MultiValueMap<String, String> param) {
32
     public static String sendFormData(String apiUrl, MultiValueMap<String, String> param) {
31
         try {
33
         try {
39
             String result = response.getBody();
41
             String result = response.getBody();
40
             return result;
42
             return result;
41
         } catch (RestClientException e) {
43
         } catch (RestClientException e) {
42
-            log.error("发送form-data请求失败",e.getMessage());
44
+            log.error("发送form-data请求失败", e.getMessage());
43
             return null;
45
             return null;
44
         }
46
         }
45
     }
47
     }
48
+
49
+    /**
50
+     * 功能描述  校验密码,包含字母和数字,长度6-16
51
+     *
52
+     * @param * @param loginpwd
53
+     * @return ResultVo
54
+     * @author WN
55
+     * @date 2022/3/15
56
+     */
57
+    public static ResultVo checkhLoginPwd(String loginpwd) {
58
+        ResultVo resultVo = new ResultVo(1, "密码必须是6-16位的英文字母、数字组合");
59
+        String passRegex = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$";
60
+        if (loginpwd.matches(passRegex)) {
61
+            resultVo = new ResultVo(0, "密码符合规范");
62
+        }
63
+        return resultVo;
64
+    }
46
 }
65
 }

Loading…
Cancel
Save