Browse Source

Merge remote-tracking branch 'origin/wn' into ywx

tags/正式3.10.0
雍文秀 1 year ago
parent
commit
7871a82593

+ 3
- 0
suser/src/main/java/com/xhkjedu/suser/mapper/system/UserMapper.java View File

@@ -269,4 +269,7 @@ public interface UserMapper extends TkMapper<TUser> {
269 269
 
270 270
     //更新用户信息
271 271
     void updateUser(@Param("u") TUser user);
272
+
273
+    //获取当前区域码
274
+    String getCloudCode();
272 275
 }

+ 14
- 2
suser/src/main/java/com/xhkjedu/suser/model/system/TUser.java View File

@@ -153,13 +153,25 @@ public class TUser extends BaseBean {
153 153
     @Transient
154 154
     private String qrkey;// 扫码登录时二维码唯一标识
155 155
 
156
-    @Transient
156
+ /*   @Transient
157 157
     private String browser;//浏览器
158 158
 
159 159
     @Transient
160
-    private String os;//操作系统
160
+    private String os;//操作系统*/
161 161
 
162 162
     //重置默认头像1重置
163 163
     @Transient
164 164
     private Integer resethead;
165
+
166
+    //系统版本(android、鸿蒙、荣耀系统等)
167
+    @Transient
168
+    private String systemversion;
169
+
170
+    @Transient
171
+    //登录终端品牌(华为、小米、荣耀、vivo、oppo等)
172
+    private String ultypeband;
173
+
174
+    @Transient
175
+    //登录终端型号(华为mate9、小米13等)
176
+    private String ultypemodel;
165 177
 }

+ 12
- 0
suser/src/main/java/com/xhkjedu/suser/model/system/TUserLog.java View File

@@ -23,6 +23,9 @@ public class TUserLog extends BaseBean {
23 23
     //登录名
24 24
     private String loginname;
25 25
 
26
+    //用户类型999超管0学校管理员1教师2学生
27
+    private Integer usertype;
28
+
26 29
     //登录状态1成功2失败
27 30
     private Integer loginstate;
28 31
 
@@ -38,9 +41,18 @@ public class TUserLog extends BaseBean {
38 41
     //登录终端设备
39 42
     private String ultype;
40 43
 
44
+    //登录终端品牌(华为、小米、荣耀、vivo、oppo等)
45
+    private String ultypeband;
46
+
47
+    //登录终端型号(华为mate9、小米13等)
48
+    private String ultypemodel;
49
+
41 50
     //版本号
42 51
     private String versionnum;
43 52
 
53
+    //系统版本(android、鸿蒙、荣耀系统等)
54
+    private String systemversion;
55
+
44 56
     //备注
45 57
     private String logtxt;
46 58
 

+ 28
- 50
suser/src/main/java/com/xhkjedu/suser/service/system/UserLogService.java View File

@@ -2,11 +2,9 @@ package com.xhkjedu.suser.service.system;
2 2
 
3 3
 import com.alibaba.fastjson.JSON;
4 4
 import com.xhkjedu.suser.config.ConfigKey;
5
-import com.xhkjedu.suser.mapper.system.UserLogMapper;
5
+import com.xhkjedu.suser.mapper.system.UserMapper;
6 6
 import com.xhkjedu.suser.model.system.TUser;
7 7
 import com.xhkjedu.suser.model.system.TUserLog;
8
-import com.xhkjedu.suser.utils.IpRegionUtil;
9
-import com.xhkjedu.suser.utils.UserUtil;
10 8
 import com.xhkjedu.suser.vo.system.UserVo;
11 9
 import com.xhkjedu.utils.N_Utils;
12 10
 import lombok.extern.slf4j.Slf4j;
@@ -14,7 +12,6 @@ import org.springframework.scheduling.annotation.Async;
14 12
 import org.springframework.stereotype.Service;
15 13
 
16 14
 import javax.annotation.Resource;
17
-import javax.servlet.http.HttpServletRequest;
18 15
 import java.util.HashMap;
19 16
 import java.util.Map;
20 17
 
@@ -27,62 +24,43 @@ import java.util.Map;
27 24
 @Slf4j
28 25
 public class UserLogService {
29 26
     @Resource
30
-    private UserLogMapper userLogMapper;
27
+    private UserMapper userMapper;
31 28
 
32 29
     //保存登录日志
33
-    @Async("asyncPoolTaskExecutor")
34
-    public void saveSyncLoginLog(TUserLog userLog, TUser user, HttpServletRequest request) {
35
-        try {
36
-            userLog.setUserid(user.getUserid());
37
-            userLog.setUsername(user.getUsername());
38
-            userLog.setSchoolid(user.getSchoolid());
39
-            //获取请求ip并解析区域
40
-            String ip = UserUtil.getIpAddress(request);
41
-            String region = null;
42
-            if (N_Utils.isNotEmpty(ip)) {
43
-                IpRegionUtil ipRegionUtil = new IpRegionUtil();
44
-                region = ipRegionUtil.getIpForAddress(ip);
45
-            }
46
-            userLog.setLogip(ip);
47
-            userLog.setLogaddress(region);
48
-            Integer usertype = user.getUsertype();
49
-            String ultype = user.getUltype();
50
-            if (N_Utils.isNotEmpty(ultype) && ultype.equals("p_web") && usertype != null) {
51
-                //网页端学生和教师合并登录,前端传p_web,拼接完整的ultype
52
-                if (usertype == 2) {
53
-                    userLog.setUltype(user.getUltype() + "_s");
54
-                } else {
55
-                    userLog.setUltype(user.getUltype() + "_t");
56
-                }
57
-            } else {
58
-                userLog.setUltype(user.getUltype());
59
-            }
60 30
 
61
-            userLog.setVersionnum(user.getVersionnum());
62
-            int logintime = N_Utils.getSecondTimestamp();
63
-            userLog.setLogtime(logintime);
64
-            userLogMapper.insertSelective(userLog);
65
-        } catch (Exception e) {
66
-            log.error("添加登录日志失败:" + e.getMessage());
67
-        }
68
-    }
69 31
 
70 32
     //用户登录信息同步到云平台
71 33
     @Async("asyncPoolTaskExecutor")
72 34
     public void saveSyncUserLogin(UserVo userVo, TUser user, TUserLog userLog) {
73 35
         Map<String, Object> params = new HashMap<>();
74
-        params.put("cloudcode", userVo.getCloudcode());
75
-        params.put("schoolname", userVo.getSchoolname());
76
-        params.put("userid", userVo.getUserid());
77
-        params.put("loginname", userVo.getLoginname());
78
-        params.put("usertype", userVo.getUsertype());
79
-        params.put("device", userLog.getUltype());
36
+        if(userVo == null){
37
+            //获取当前区域码
38
+            String cloudcode = userMapper.getCloudCode();
39
+            params.put("cloudcode", cloudcode);
40
+            params.put("schoolname", "");
41
+            params.put("userid", user.getUserid());
42
+            params.put("loginname", user.getLoginname());
43
+            params.put("username", "");
44
+
45
+        }else{
46
+            params.put("cloudcode", userVo.getCloudcode());
47
+            params.put("schoolname", userVo.getSchoolname());
48
+            params.put("userid", userVo.getUserid());
49
+            params.put("loginname", userVo.getLoginname());
50
+            params.put("username", userVo.getUsername());
51
+        }
52
+        params.put("deviceband", user.getUltypeband());
53
+        params.put("devicemodel", user.getUltypemodel());
80 54
         params.put("mac", user.getMac());
81
-        params.put("loginip", userLog.getLogip());
82
-        params.put("logintime", userLog.getLogtime());
83 55
         params.put("versioncode", user.getVersionnum());
84
-        params.put("browser", user.getBrowser());
85
-        params.put("env", user.getOs());
56
+        params.put("systemversion", user.getSystemversion());
57
+        params.put("usertype", userLog.getUsertype());
58
+        params.put("device", userLog.getUltype());
59
+        params.put("logip", userLog.getLogip());
60
+        params.put("logaddress", userLog.getLogaddress());
61
+        params.put("logtime", userLog.getLogtime());
62
+        params.put("loginstate", userLog.getLoginstate());
63
+        params.put("logtxt",userLog.getLogtxt());
86 64
 
87 65
         try {
88 66
             N_Utils.sendJsonPost(ConfigKey.cloudapi + "rlinfo/save", JSON.toJSONString(params));

+ 88
- 34
suser/src/main/java/com/xhkjedu/suser/service/system/UserService.java View File

@@ -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
      *

+ 5
- 0
suser/src/main/resources/mapper/system/UserMapper.xml View File

@@ -340,4 +340,9 @@
340 340
         </if>
341 341
         where userid=#{user.userid}
342 342
     </update>
343
+
344
+    <!--获取当前区域码-->
345
+    <select id="getCloudCode" resultType="java.lang.String">
346
+        select cloudcode from t_cloud order by cloudid limit 1;
347
+    </select>
343 348
 </mapper>

Loading…
Cancel
Save