소스 검색

班级学生添加、修改、导入,添加准考证号

tags/正式版本
雍文秀 2 년 전
부모
커밋
a0d20f3ccb

+ 6
- 0
suser/src/main/java/com/xhkjedu/suser/mapper/system/UserMapper.java 파일 보기

@@ -252,4 +252,10 @@ public interface UserMapper extends TkMapper<TUser> {
252 252
 
253 253
     //批量更新用户状态
254 254
     void batchUpdateUserState(@Param("userstate") Integer userstate, @Param("userids") List<Integer> userids);
255
+
256
+    //根据登录名查找用户集合
257
+    List<TUser> listByLoginNames(@Param("loginnames") List<String> loginnames);
258
+
259
+    //批量更新用户信息
260
+    void batchUpdateUser(@Param("users") List<TUser> users);
255 261
 }

+ 4
- 0
suser/src/main/java/com/xhkjedu/suser/model/gradeclass/TClassStudent.java 파일 보기

@@ -33,6 +33,10 @@ public class TClassStudent extends BaseBean {
33 33
     @Transient
34 34
     private String studentno;
35 35
 
36
+    @Transient
37
+    //准考证号
38
+    private String examno;
39
+
36 40
     //学生姓名
37 41
     @Transient
38 42
     private String studentname;

+ 3
- 0
suser/src/main/java/com/xhkjedu/suser/model/system/TUser.java 파일 보기

@@ -31,6 +31,9 @@ public class TUser extends BaseBean {
31 31
     //学生学号
32 32
     private String studentno;
33 33
 
34
+    //准考证号
35
+    private String examno;
36
+
34 37
     //登录密码
35 38
     private String loginpwd;
36 39
 

+ 46
- 4
suser/src/main/java/com/xhkjedu/suser/service/gradeclass/ClassStudentService.java 파일 보기

@@ -200,14 +200,17 @@ public class ClassStudentService {
200 200
             if (!N_Utils.isEmpty(model.getStudentno())) {
201 201
                 String headpic = model.getHeadpic();
202 202
                 TUser user = userMapper.getObjByLoginName(model.getStudentno());
203
+                String examno = model.getExamno();
203 204
                 if (user == null) {//学生信息在用户表不存在,添加学生信息
204 205
                     user = saveUser(model);//保存用户信息
205 206
                 } else if (user.getUsertype() != 2) {
206 207
                     throw new Exception("禁止添加非学生账号");
207 208
                 } else if (!schoolid.equals(user.getSchoolid())) {
208 209
                     throw new Exception("禁止添加非本校学生账号");
209
-                } else if (N_Utils.isNotEmpty(headpic) || 1 != user.getUserstate()) {
210
+                } else if (N_Utils.isNotEmpty(headpic) || 1 != user.getUserstate()
211
+                        || (N_Utils.isNotEmpty(examno) && !examno.equals(user.getExamno()))) {
210 212
                     TUser stu = new TUser();
213
+                    stu.setExamno(examno);
211 214
                     Integer userid = user.getUserid();
212 215
                     stu.setUserid(userid);
213 216
                     if (N_Utils.isNotEmpty(headpic)) {
@@ -382,6 +385,7 @@ public class ClassStudentService {
382 385
         user.setUsersex(model.getUsersex());
383 386
         user.setUsername(model.getStudentname());
384 387
         user.setStudentno(model.getStudentno());
388
+        user.setExamno(model.getExamno());
385 389
         user.setLoginname(model.getStudentno());
386 390
         user.setUserphone(model.getUserphone());
387 391
         user.setUsertime(model.getUsertime());
@@ -431,6 +435,12 @@ public class ClassStudentService {
431 435
             if (stunum.compareTo(lnum) != 0) {
432 436
                 return new ResultVo(1, "有重复的登录学号");
433 437
             }
438
+            List<String> elist = students.stream().filter(u -> N_Utils.isNotEmpty(u.getExamno())).map(TUser::getExamno).collect(Collectors.toList());
439
+            long examnum2 = elist.stream().distinct().count();
440
+            Integer examnum = elist.size();
441
+            if (examnum2 < examnum) {
442
+                return new ResultVo(1, "有重复的准考证号");
443
+            }
434 444
             Integer usernum = schoolMapper.getUserNumById(schoolid);
435 445
             if (usernum != null) {
436 446
                 Integer usernum2 = userMapper.getUserNumBySchoolId(schoolid);
@@ -452,8 +462,12 @@ public class ClassStudentService {
452 462
             List<TUser> studentsExisted = new ArrayList<>();//已存在学生列表
453 463
             List<TUser> usersExisted = new ArrayList<>();//已存在非本校账号列表
454 464
             List<TUser> delUsers = new ArrayList<>();//已删除学生列表
465
+            List<TUser> updateUsers = new ArrayList<>();//要更新学生列表
466
+            List<String> loginnames = students.stream().map(s -> s.getLoginname()).collect(Collectors.toList());
467
+            Map<String, TUser> userMap = userMapper.listByLoginNames(loginnames).stream()
468
+                    .collect(Collectors.toMap(u -> u.getLoginname(), u -> u));
455 469
             for (TUser user : students) {
456
-                TUser u = userMapper.getObjByLoginName(user.getLoginname());
470
+                TUser u = userMap.get(user.getLoginname());
457 471
                 if (null == u) {
458 472
                     user.setSchoolid(schoolid);
459 473
                     user.setCreateid(createid);
@@ -516,10 +530,19 @@ public class ClassStudentService {
516 530
                                 handleDelClassCourse2(delStudentList, changeCourseidList, courses2, studentid);//处理关联的直播课以及需要删除学生的直播班id
517 531
                             }
518 532
                         }
533
+                        String examno = user.getExamno();
534
+                        if (N_Utils.isNotEmpty(examno) && !examno.equals(u.getExamno())) {
535
+                            user.setUserid(u.getUserid());
536
+                            updateUsers.add(user);
537
+                        }
519 538
                     }
520 539
                 }
521 540
             }
522 541
 
542
+            if(N_Utils.isListNotEmpty(updateUsers)){
543
+                userMapper.batchUpdateUser(updateUsers);//批量更新用户信息
544
+            }
545
+
523 546
             //保存用户信息
524 547
             if (!CollectionUtils.isEmpty(users)) {
525 548
                 userMapper.insertList(users);
@@ -635,6 +658,12 @@ public class ClassStudentService {
635 658
             if (stunum.compareTo(lnum) != 0) {
636 659
                 return new ResultVo(1, "有重复的登录学号");
637 660
             }
661
+            List<String> elist = students.stream().filter(u -> N_Utils.isNotEmpty(u.getExamno())).map(TUser::getExamno).collect(Collectors.toList());
662
+            long examnum2 = elist.stream().distinct().count();
663
+            Integer examnum = elist.size();
664
+            if (examnum2 < examnum) {
665
+                return new ResultVo(1, "有重复的准考证号");
666
+            }
638 667
             map.remove("users");//导入成功的学生信息不返回给前端
639 668
 
640 669
             List<TClassStudent> classStudents = new ArrayList<>();
@@ -644,8 +673,12 @@ public class ClassStudentService {
644 673
             // 以下学生信息不存在
645 674
             List<TUser> usersNotExisted = new ArrayList<>();
646 675
             List<TUser> delUsers = new ArrayList<>();//已删除学生列表
676
+            List<TUser> updateUsers = new ArrayList<>();//要更新学生列表
677
+            List<String> loginnames = students.stream().map(s -> s.getLoginname()).collect(Collectors.toList());
678
+            Map<String, TUser> userMap = userMapper.listByLoginNames(loginnames).stream()
679
+                    .collect(Collectors.toMap(u -> u.getLoginname(), u -> u));
647 680
             for (TUser user : students) {
648
-                TUser u = userMapper.getObjByLoginName(user.getLoginname());
681
+                TUser u = userMap.get(user.getLoginname());
649 682
                 if (null == u) {
650 683
                     user.setSchoolid(schoolid);
651 684
                     user.setCreateid(createid);
@@ -669,10 +702,19 @@ public class ClassStudentService {
669 702
                             List<Map> courses = listCourseByClassId(courseMap, classid);
670 703
                             handleAddClassCourse(classStudents, groupStudents, changeCourseidList, courses, studentid);//处理班级加入学生中关联的直播课加入学生
671 704
                         }
705
+                        String examno = user.getExamno();
706
+                        if (N_Utils.isNotEmpty(examno) && !examno.equals(u.getExamno())) {
707
+                            user.setUserid(u.getUserid());
708
+                            updateUsers.add(user);
709
+                        }
672 710
                     }
673 711
                 }
674 712
             }
675 713
 
714
+            if(N_Utils.isListNotEmpty(updateUsers)){
715
+                userMapper.batchUpdateUser(updateUsers);//批量更新用户信息
716
+            }
717
+
676 718
             //保存学生关联信息
677 719
             if (!CollectionUtils.isEmpty(classStudents)) {
678 720
                 classStudentMapper.saveBatchClassStudent(classStudents);
@@ -830,7 +872,7 @@ public class ClassStudentService {
830 872
     }
831 873
 
832 874
     //处理要班级加入学生
833
-    private void moveClassHandleAddGroupStudent(List<TClassStudent> addClassStudentList,List<TGroupStudent> addGroupStudentList,ClassVo classVo,Integer studentid){
875
+    private void moveClassHandleAddGroupStudent(List<TClassStudent> addClassStudentList, List<TGroupStudent> addGroupStudentList, ClassVo classVo, Integer studentid) {
834 876
         Integer timestamp = N_Utils.getSecondTimestamp();
835 877
         //班级学生
836 878
         TClassStudent cs = new TClassStudent();

+ 2
- 0
suser/src/main/java/com/xhkjedu/suser/utils/PoiUtils.java 파일 보기

@@ -150,6 +150,8 @@ public class PoiUtils {
150 150
                                 throw new Exception("第" + (x + 1) + "行班级不存在");
151 151
                             }
152 152
                         }
153
+                    } else if (y == 5) {//准考证号
154
+                        user.setExamno(getCellValue(cell));
153 155
                     }
154 156
                 }
155 157
 

+ 3
- 0
suser/src/main/java/com/xhkjedu/suser/vo/gradeclass/ClassStudentVo.java 파일 보기

@@ -10,6 +10,9 @@ public class ClassStudentVo {
10 10
     //学号
11 11
     private String studentno;
12 12
 
13
+    //准考证号
14
+    private String examno;
15
+
13 16
     //学生姓名
14 17
     private String studentname;
15 18
 

+ 3
- 3
suser/src/main/resources/mapper/gradeclass/ClassStudentMapper.xml 파일 보기

@@ -4,7 +4,7 @@
4 4
     <!--班级学生列表-->
5 5
     <select id="findAll" resultType="com.xhkjedu.suser.vo.gradeclass.ClassStudentVo">
6 6
         select cs.csid,cs.classid,c.classname,c.gradeid,u.username studentname,u.studentno,u.usersex,u.userid studentid,u.loginname,cs.createtime
7
-        ,u.bindmac,u.mac,u.headpic,u.usertime,u.userlock
7
+        ,u.bindmac,u.mac,u.headpic,u.usertime,u.userlock,u.examno
8 8
         ,(case when u.userphone='' then userphone else concat(left(u.userphone,3),'****',right(u.userphone,4)) end)userphone
9 9
         from t_class_student cs left join t_user u on cs.studentid = u.userid
10 10
         left join t_class c on cs.classid=c.classid
@@ -75,7 +75,7 @@
75 75
 
76 76
     <select id="listNoClassStu" resultType="com.xhkjedu.suser.vo.gradeclass.ClassStudentVo">
77 77
         select u.username studentname,u.studentno,u.usersex,u.userid studentid,u.loginname,u.createtime,
78
-        u.bindmac,u.mac,u.userstate,u.usertime,u.headpic,u.userlock
78
+        u.bindmac,u.mac,u.userstate,u.usertime,u.headpic,u.userlock,u.examno
79 79
         ,(case when u.userphone='' then userphone else concat(left(u.userphone,3),'****',right(u.userphone,4)) end)userphone
80 80
         from t_user u left join
81 81
         (select cs1.studentid,cs1.createtime from t_class_student cs1
@@ -105,7 +105,7 @@
105 105
     <!--获取全校学生-->
106 106
     <select id="listAllStudents" resultType="com.xhkjedu.suser.vo.gradeclass.ClassStudentVo">
107 107
         select u.username studentname,u.studentno,
108
-        u.usersex,u.userid studentid,u.loginname,cs.createtime,u.userlock,
108
+        u.usersex,u.userid studentid,u.loginname,cs.createtime,u.userlock,u.examno,
109 109
         u.bindmac,u.mac,u.headpic,u.usertime,c.gradeid,c.classname,c.classid
110 110
         ,(case when u.userphone='' then userphone else concat(left(u.userphone,3),'****',right(u.userphone,4)) end)userphone
111 111
         from t_user u left join t_class_student cs on u.userid=cs.studentid

+ 16
- 1
suser/src/main/resources/mapper/system/UserMapper.xml 파일 보기

@@ -87,7 +87,7 @@
87 87
     </select>
88 88
     <!--根据登录账号获取用户详情-->
89 89
     <select id="getObjByLoginName" resultType="com.xhkjedu.suser.model.system.TUser">
90
-        select u.userid,u.username,u.loginname,u.usersex,u.usertype,u.userstate,u.schoolid
90
+        select u.userid,u.username,u.loginname,u.examno,u.usersex,u.usertype,u.userstate,u.schoolid
91 91
         from t_user u where binary u.loginname=#{loginname} limit 1
92 92
     </select>
93 93
     <!--修改用户状态-->
@@ -283,4 +283,19 @@
283 283
         from t_cloud c,t_user u left join t_school s on u.schoolid = s.schoolid
284 284
         where u.userphone=#{userphone} limit 1
285 285
     </select>
286
+    <!--根据登录名查找用户集合-->
287
+    <select id="listByLoginNames" resultType="com.xhkjedu.suser.model.system.TUser">
288
+        select u.userid,u.username,u.loginname,u.examno,u.usersex,u.usertype,u.userstate,u.schoolid
289
+        from t_user u where
290
+        <foreach collection="loginnames" item="loginname" separator="or">
291
+            binary u.loginname=#{loginname}
292
+        </foreach>
293
+    </select>
294
+    <!--批量更新用户信息-->
295
+    <update id="batchUpdateUser">
296
+        <foreach collection="users" item="u" separator="or">
297
+            update t_user set username=#{u.username},examno=#{u.examno},usersex=#{u.usersex}
298
+            where userid=#{u.userid}
299
+        </foreach>
300
+    </update>
286 301
 </mapper>

Loading…
취소
저장