|
@@ -9,6 +9,7 @@ import com.xhkjedu.suser.mapper.gradeclass.ClassTeacherMapper;
|
9
|
9
|
import com.xhkjedu.suser.mapper.gradeclass.SchoolMapper;
|
10
|
10
|
import com.xhkjedu.suser.mapper.subjectbook.TeacherPowersbMapper;
|
11
|
11
|
import com.xhkjedu.suser.mapper.system.MsgMapper;
|
|
12
|
+import com.xhkjedu.suser.mapper.system.UserLogMapper;
|
12
|
13
|
import com.xhkjedu.suser.mapper.system.UserMapper;
|
13
|
14
|
import com.xhkjedu.suser.mapper.system.UserUsecretMapper;
|
14
|
15
|
import com.xhkjedu.suser.model.gradeclass.TClassTeacher;
|
|
@@ -16,6 +17,7 @@ import com.xhkjedu.suser.model.system.TMsg;
|
16
|
17
|
import com.xhkjedu.suser.model.system.TUser;
|
17
|
18
|
import com.xhkjedu.suser.model.system.TUserLog;
|
18
|
19
|
import com.xhkjedu.suser.model.system.TUserUsecret;
|
|
20
|
+import com.xhkjedu.suser.utils.IpRegionUtil;
|
19
|
21
|
import com.xhkjedu.suser.utils.PoiUtils;
|
20
|
22
|
import com.xhkjedu.suser.utils.SMSSender;
|
21
|
23
|
import com.xhkjedu.suser.utils.UserUtil;
|
|
@@ -65,6 +67,8 @@ public class UserService extends JedisUtil {
|
65
|
67
|
private UserUsecretMapper userUsecretMapper;
|
66
|
68
|
@Resource
|
67
|
69
|
private TeacherPowersbMapper teacherPowersbMapper;
|
|
70
|
+ @Resource
|
|
71
|
+ private UserLogMapper userLogMapper;
|
68
|
72
|
|
69
|
73
|
/**
|
70
|
74
|
* 功能描述 根据登录名和密码获取用户信息
|
|
@@ -101,7 +105,7 @@ public class UserService extends JedisUtil {
|
101
|
105
|
private ResultVo checkLoginUser(TUser user, UserVo userVo, Integer checkmethod) {
|
102
|
106
|
if (checkmethod == 1 && !userVo.getLoginpwd().equals(user.getLoginpwd())) {
|
103
|
107
|
//帐号密码登录
|
104
|
|
- return new ResultVo(1, "密码错误");
|
|
108
|
+ return new ResultVo(1, "密码错误", userVo);
|
105
|
109
|
} else {
|
106
|
110
|
Integer usertype = userVo.getUsertype();
|
107
|
111
|
if (usertype == 999) {
|
|
@@ -109,20 +113,20 @@ public class UserService extends JedisUtil {
|
109
|
113
|
}
|
110
|
114
|
//判断学校状态
|
111
|
115
|
if (userVo.getSchoolstate() != 1) {
|
112
|
|
- return new ResultVo(1, "此学校已锁定,禁止登录");
|
|
116
|
+ return new ResultVo(1, "此学校已锁定,禁止登录", userVo);
|
113
|
117
|
}
|
114
|
118
|
//判断用户状态
|
115
|
119
|
if (userVo.getUserstate() != 1) {
|
116
|
120
|
if (usertype == 2) {//学生
|
117
|
|
- return new ResultVo(1, "此账号无权访问,请联系老师");
|
|
121
|
+ return new ResultVo(1, "此账号无权访问,请联系老师", userVo);
|
118
|
122
|
} else {
|
119
|
|
- return new ResultVo(1, "此账号无权访问,请联系管理员");
|
|
123
|
+ return new ResultVo(1, "此账号无权访问,请联系管理员", userVo);
|
120
|
124
|
}
|
121
|
125
|
}
|
122
|
126
|
|
123
|
127
|
//判断用户状态
|
124
|
128
|
if (userVo.getUserlock() == 1) {
|
125
|
|
- return new ResultVo(1, "此账号已锁定,禁止登录");
|
|
129
|
+ return new ResultVo(1, "此账号已锁定,禁止登录", userVo);
|
126
|
130
|
}
|
127
|
131
|
|
128
|
132
|
//判断用户有效期
|
|
@@ -131,9 +135,9 @@ public class UserService extends JedisUtil {
|
131
|
135
|
String dayBegin = DatesUtil.getDayBegin();
|
132
|
136
|
if (usertime.compareTo(dayBegin) < 0) {
|
133
|
137
|
if (usertype == 2) {//学生
|
134
|
|
- return new ResultVo(1, "账号已过有效期,请联系老师");
|
|
138
|
+ return new ResultVo(1, "账号已过有效期,请联系老师", userVo);
|
135
|
139
|
} else {
|
136
|
|
- return new ResultVo(1, "账号已过有效期,请联系管理员");
|
|
140
|
+ return new ResultVo(1, "账号已过有效期,请联系管理员", userVo);
|
137
|
141
|
}
|
138
|
142
|
}
|
139
|
143
|
}
|
|
@@ -141,7 +145,7 @@ public class UserService extends JedisUtil {
|
141
|
145
|
//进行角色判断
|
142
|
146
|
if (usertype == 2) {
|
143
|
147
|
Integer stuweb = userVo.getStuweb();
|
144
|
|
- if (stuweb != null && stuweb != 1) return new ResultVo(1, "学生账号无法登录");
|
|
148
|
+ if (stuweb != null && stuweb != 1) return new ResultVo(1, "学生账号无法登录", userVo);
|
145
|
149
|
|
146
|
150
|
Integer sbindmac = userVo.getSbindmac();
|
147
|
151
|
String mac = user.getMac();
|
|
@@ -150,11 +154,11 @@ public class UserService extends JedisUtil {
|
150
|
154
|
UserVo binduser = userMapper.getStudentByuserIdMac(userVo.getUserid(), mac);
|
151
|
155
|
if (sbindmac == 1 && N_Utils.isNotEmpty(mac)) {
|
152
|
156
|
if (N_Utils.isNotEmpty(binduser.getMac()) && !mac.equals(binduser.getMac())) {
|
153
|
|
- return new ResultVo(1, "登录失败,该账号已与其他设备关联");
|
|
157
|
+ return new ResultVo(1, "该账号已与其他设备关联", userVo);
|
154
|
158
|
} else {
|
155
|
159
|
//20211221添加注释,sql语句修改了,不绑定的情况下会出现一个mac可以绑定多个帐号,绑定情况下没问题
|
156
|
160
|
if (N_Utils.isNotEmpty(binduser.getMacname()) && !binduser.getMacname().equals(user.getLoginname())) {
|
157
|
|
- return new ResultVo(1, "登录失败,该设备已与其他账号关联");
|
|
161
|
+ return new ResultVo(1, "该设备已与其他账号关联", userVo);
|
158
|
162
|
} else {
|
159
|
163
|
return new ResultVo(0, "登录成功", userVo);
|
160
|
164
|
}
|
|
@@ -162,7 +166,7 @@ public class UserService extends JedisUtil {
|
162
|
166
|
}
|
163
|
167
|
//验证用户是否有行政班
|
164
|
168
|
if (binduser.getXznum() == 0) {
|
165
|
|
- return new ResultVo(1, "此账号未分配班级");
|
|
169
|
+ return new ResultVo(1, "此账号未分配班级", userVo);
|
166
|
170
|
}
|
167
|
171
|
|
168
|
172
|
String device = user.getDevice();//只有学生
|
|
@@ -200,18 +204,14 @@ public class UserService extends JedisUtil {
|
200
|
204
|
user.setSchoolid(userVo.getSchoolid());
|
201
|
205
|
user.setUsertype(userVo.getUsertype());
|
202
|
206
|
if (userVo.getUsertype() != 1) {
|
203
|
|
- resultVo = new ResultVo(1, "禁止非教师帐号登录");
|
|
207
|
+ resultVo = new ResultVo(1, "禁止非教师帐号登录", userVo);
|
204
|
208
|
} else {
|
205
|
209
|
//验证用户信息
|
206
|
210
|
resultVo = this.checkLoginUser(user, userVo, 1);
|
207
|
211
|
}
|
208
|
|
-
|
209
|
212
|
} else {
|
210
|
213
|
resultVo = new ResultVo(1, "此账号不存在");
|
211
|
214
|
}
|
212
|
|
-
|
213
|
|
-
|
214
|
|
-
|
215
|
215
|
return getLogResultVo(user, resultVo, loginpwd, request);
|
216
|
216
|
}
|
217
|
217
|
|
|
@@ -247,7 +247,7 @@ public class UserService extends JedisUtil {
|
247
|
247
|
//验证学生登录系列问题
|
248
|
248
|
private ResultVo checkLoginStudent(TUser user, UserVo userVo) {
|
249
|
249
|
if (!userVo.getLoginpwd().equals(user.getLoginpwd())) {
|
250
|
|
- return new ResultVo(1, "密码错误");
|
|
250
|
+ return new ResultVo(1, "密码错误", userVo);
|
251
|
251
|
} else {
|
252
|
252
|
Integer sbindmac = userVo.getSbindmac();//学校是否绑定设备0未绑定1绑定
|
253
|
253
|
String mac = user.getMac();
|
|
@@ -255,34 +255,34 @@ public class UserService extends JedisUtil {
|
255
|
255
|
|
256
|
256
|
//判断学校状态
|
257
|
257
|
if (userVo.getSchoolstate() != 1) {
|
258
|
|
- return new ResultVo(1, "此学校已锁定,禁止登录");
|
|
258
|
+ return new ResultVo(1, "此学校已锁定,禁止登录", userVo);
|
259
|
259
|
}
|
260
|
260
|
|
261
|
261
|
//判断用户状态
|
262
|
262
|
if (userVo.getUserstate() != 1) {
|
263
|
263
|
if (userVo.getUsertype() == 2) {//学生
|
264
|
|
- return new ResultVo(1, "此账号无权访问,请联系老师");
|
|
264
|
+ return new ResultVo(1, "此账号无权访问,请联系老师", userVo);
|
265
|
265
|
}
|
266
|
266
|
}
|
267
|
267
|
|
268
|
268
|
if (userVo.getUserlock() == 1) {
|
269
|
|
- return new ResultVo(1, "此账号已锁定,禁止登录");
|
|
269
|
+ return new ResultVo(1, "此账号已锁定,禁止登录", userVo);
|
270
|
270
|
} else if (userVo.getUsertype() != 2) {
|
271
|
|
- return new ResultVo(1, "登录失败,仅允许学生登录");
|
|
271
|
+ return new ResultVo(1, "登录失败,仅允许学生登录", userVo);
|
272
|
272
|
} else if (userVo.getXznum() == 0) {
|
273
|
|
- return new ResultVo(1, "此账号未分配班级");
|
|
273
|
+ return new ResultVo(1, "此账号未分配班级", userVo);
|
274
|
274
|
} else if (N_Utils.isNotEmpty(usertime)) {
|
275
|
275
|
String dayBegin = DatesUtil.getDayBegin();
|
276
|
276
|
if (usertime.compareTo(dayBegin) < 0) {
|
277
|
|
- return new ResultVo(1, "账号已过有效期,请联系老师");
|
|
277
|
+ return new ResultVo(1, "账号已过有效期,请联系老师", userVo);
|
278
|
278
|
}
|
279
|
279
|
} else if (sbindmac == 1 && N_Utils.isNotEmpty(mac)) {
|
280
|
280
|
if (N_Utils.isNotEmpty(userVo.getMac()) && !mac.equals(userVo.getMac())) {
|
281
|
|
- return new ResultVo(1, "登录失败,该账号已与其他设备关联");
|
|
281
|
+ return new ResultVo(1, "登录失败,该账号已与其他设备关联", userVo);
|
282
|
282
|
} else {
|
283
|
283
|
//20211221添加注释,sql语句修改了,不绑定的情况下会出现一个mac可以绑定多个帐号,绑定情况下没问题
|
284
|
284
|
if (N_Utils.isNotEmpty(userVo.getMacname()) && !userVo.getMacname().equals(user.getLoginname())) {
|
285
|
|
- return new ResultVo(1, "登录失败,该设备已与其他账号关联");
|
|
285
|
+ return new ResultVo(1, "登录失败,该设备已与其他账号关联", userVo);
|
286
|
286
|
}
|
287
|
287
|
}
|
288
|
288
|
}
|
|
@@ -312,7 +312,7 @@ public class UserService extends JedisUtil {
|
312
|
312
|
Integer usertype = user.getUsertype();
|
313
|
313
|
Integer utype = userVo.getUsertype();
|
314
|
314
|
if (usertype != null && usertype == 1 && utype != 0 & utype != 1) {//教师端只能管理员、教师登录
|
315
|
|
- return new ResultVo(1, "禁止非教师帐号登录");
|
|
315
|
+ return new ResultVo(1, "禁止非教师帐号登录", userVo);
|
316
|
316
|
}
|
317
|
317
|
user.setUserid(userVo.getUserid());
|
318
|
318
|
user.setUsername(userVo.getUsername());
|
|
@@ -389,7 +389,6 @@ public class UserService extends JedisUtil {
|
389
|
389
|
TUserLog userLog = new TUserLog();
|
390
|
390
|
userLog.setLoginname(loginname);
|
391
|
391
|
userLog.setMac(user.getMac());
|
392
|
|
- Integer usertype = user.getUsertype();
|
393
|
392
|
UserVo userVo = null;
|
394
|
393
|
if (result.getCode() == 0) {
|
395
|
394
|
userVo = (UserVo) result.getObj();
|
|
@@ -401,7 +400,9 @@ public class UserService extends JedisUtil {
|
401
|
400
|
if (!redis_rtn) {
|
402
|
401
|
result.setCode(1);
|
403
|
402
|
result.setMsg("加入缓存出错!");
|
404
|
|
- return result;
|
|
403
|
+ userLog.setLoginstate(2);
|
|
404
|
+ userLog.setLogtxt("登录失败," + result.getMsg());
|
|
405
|
+ // return result;
|
405
|
406
|
} else {
|
406
|
407
|
userLog.setLoginstate(1);
|
407
|
408
|
userLog.setLogtxt("登录成功");
|
|
@@ -410,18 +411,71 @@ public class UserService extends JedisUtil {
|
410
|
411
|
result.setObj(userVo);
|
411
|
412
|
}
|
412
|
413
|
} else {
|
|
414
|
+ if(N_Utils.isNotEmpty(result.getObj())){
|
|
415
|
+ userVo = (UserVo) result.getObj();
|
|
416
|
+ }
|
413
|
417
|
userLog.setLoginstate(2);
|
414
|
|
- userLog.setLogtxt(result.getMsg() + ",密码:" + loginpwd);
|
|
418
|
+ if(result.getMsg().contains("密码错误")){
|
|
419
|
+ userLog.setLogtxt("登录失败," + result.getMsg() + ",密码:" + loginpwd);
|
|
420
|
+ }else{
|
|
421
|
+ userLog.setLogtxt("登录失败," + result.getMsg());
|
|
422
|
+ }
|
415
|
423
|
}
|
|
424
|
+
|
416
|
425
|
//保存登录日志
|
417
|
|
- userLogService.saveSyncLoginLog(userLog,user,request);
|
418
|
|
- boolean cloudsynclogin = ConfigKey.cloudsynclogin;//为true时代表同步云平台
|
419
|
|
- if(cloudsynclogin && userLog.getLoginstate() !=null && userLog.getLoginstate() == 1){
|
420
|
|
- userLogService.saveSyncUserLogin(userVo, user, userLog);
|
421
|
|
- }
|
|
426
|
+ saveSyncLoginLog(userLog,user,userVo,request);
|
|
427
|
+
|
422
|
428
|
return result;
|
423
|
429
|
}
|
424
|
430
|
|
|
431
|
+ //保存登录日志
|
|
432
|
+ @Async("asyncPoolTaskExecutor")
|
|
433
|
+ public void saveSyncLoginLog(TUserLog userLog, TUser user,UserVo userVo, HttpServletRequest request) {
|
|
434
|
+ try {
|
|
435
|
+
|
|
436
|
+ userLog.setUserid(user.getUserid());
|
|
437
|
+ userLog.setUsername(user.getUsername());
|
|
438
|
+ userLog.setSchoolid(user.getSchoolid());
|
|
439
|
+ Integer usertype = user.getUsertype();
|
|
440
|
+ userLog.setUsertype(usertype);
|
|
441
|
+ String ultype = user.getUltype();
|
|
442
|
+ if (N_Utils.isNotEmpty(ultype) && ultype.equals("p_web") && usertype != null) {
|
|
443
|
+ //网页端学生和教师合并登录,前端传p_web,拼接完整的ultype
|
|
444
|
+ if (usertype == 2) {
|
|
445
|
+ userLog.setUltype(user.getUltype() + "_s");
|
|
446
|
+ } else {
|
|
447
|
+ userLog.setUltype(user.getUltype() + "_t");
|
|
448
|
+ }
|
|
449
|
+ } else {
|
|
450
|
+ userLog.setUltype(user.getUltype());
|
|
451
|
+ }
|
|
452
|
+
|
|
453
|
+ userLog.setVersionnum(user.getVersionnum());
|
|
454
|
+ int logintime = N_Utils.getSecondTimestamp();
|
|
455
|
+ userLog.setLogtime(logintime);
|
|
456
|
+
|
|
457
|
+ //获取请求ip并解析区域
|
|
458
|
+ String ip = UserUtil.getIpAddress(request);
|
|
459
|
+ String region = null;
|
|
460
|
+ if (N_Utils.isNotEmpty(ip)) {
|
|
461
|
+ IpRegionUtil ipRegionUtil = new IpRegionUtil();
|
|
462
|
+ region = ipRegionUtil.getIpForAddress(ip);
|
|
463
|
+ }
|
|
464
|
+ userLog.setLogip(ip);
|
|
465
|
+ userLog.setLogaddress(region);
|
|
466
|
+
|
|
467
|
+ boolean cloudsynclogin = ConfigKey.cloudsynclogin;//为true时代表同步云平台
|
|
468
|
+ if(cloudsynclogin && userLog.getLoginstate() !=null){
|
|
469
|
+ userLogService.saveSyncUserLogin(userVo, user, userLog);
|
|
470
|
+ }
|
|
471
|
+
|
|
472
|
+ userLogMapper.insertSelective(userLog);
|
|
473
|
+
|
|
474
|
+ } catch (Exception e) {
|
|
475
|
+ log.error("添加登录日志失败:" + e.getMessage());
|
|
476
|
+ }
|
|
477
|
+ }
|
|
478
|
+
|
425
|
479
|
/**
|
426
|
480
|
* 添加用户信息
|
427
|
481
|
*
|