|
@@ -6,10 +6,10 @@ import com.xhkjedu.suser.mapper.gradeclass.ClassStudentMapper;
|
6
|
6
|
import com.xhkjedu.suser.mapper.gradeclass.GroupStudentMapper;
|
7
|
7
|
import com.xhkjedu.suser.mapper.gradeclass.SchoolMapper;
|
8
|
8
|
import com.xhkjedu.suser.mapper.liveplay.CourseMapper;
|
|
9
|
+import com.xhkjedu.suser.mapper.system.UserMapper;
|
9
|
10
|
import com.xhkjedu.suser.model.gradeclass.TClassStudent;
|
10
|
11
|
import com.xhkjedu.suser.model.gradeclass.TGroupStudent;
|
11
|
12
|
import com.xhkjedu.suser.model.system.TUser;
|
12
|
|
-import com.xhkjedu.suser.service.system.UserService;
|
13
|
13
|
import com.xhkjedu.suser.utils.PoiUtils;
|
14
|
14
|
import com.xhkjedu.suser.vo.gradeclass.ClassStudentVo;
|
15
|
15
|
import com.xhkjedu.suser.vo.gradeclass.ClassVo;
|
|
@@ -41,7 +41,7 @@ public class ClassStudentService {
|
41
|
41
|
@Resource
|
42
|
42
|
private ClassStudentMapper classStudentMapper;
|
43
|
43
|
@Resource
|
44
|
|
- private UserService userService;
|
|
44
|
+ private UserMapper userMapper;
|
45
|
45
|
@Resource
|
46
|
46
|
private ClassMapper classMapper;
|
47
|
47
|
@Resource
|
|
@@ -70,7 +70,6 @@ public class ClassStudentService {
|
70
|
70
|
List<Integer> changeCourseidList = new ArrayList<>();//用户更新直播课中学生数量
|
71
|
71
|
List<Map> courses = courseMapper.listXzCourse(classid);
|
72
|
72
|
for (TClassStudent student : students) {
|
73
|
|
- //save(student);
|
74
|
73
|
Integer studentid = student.getStudentid();
|
75
|
74
|
//全体分组
|
76
|
75
|
ImportStudentVo stu = getNumById(classid, studentid, year);
|
|
@@ -122,7 +121,6 @@ public class ClassStudentService {
|
122
|
121
|
Integer schoolid = classVo.getSchoolid();
|
123
|
122
|
Integer createid = classVo.getCreateid();
|
124
|
123
|
Integer groupid = classVo.getGroupid();
|
125
|
|
- Integer year = classVo.getYear();
|
126
|
124
|
List<Integer> studentIds = classStudentMapper.listStudentIdByClassId(classid);//班级原有学生
|
127
|
125
|
for (Integer studentid : newStuIds) {
|
128
|
126
|
if (!N_Utils.numInList(studentid, studentIds)) {//新添加的学生
|
|
@@ -136,7 +134,6 @@ public class ClassStudentService {
|
136
|
134
|
Map<String, List<Map>> courseMap = new HashMap();//班级直播课
|
137
|
135
|
for (Integer studentId : studentIds) {
|
138
|
136
|
if (!N_Utils.numInList(studentId, newStuIds)) {//删除的学生
|
139
|
|
- //deleteById(classid, studentId);
|
140
|
137
|
//把这个学生从此行政班、提高班关联的所有直播班移除
|
141
|
138
|
delStudentIdList.add(studentId);
|
142
|
139
|
String classids = classStudentMapper.getClassIdsByCidAndSid(classid, studentId);//获取学生除某个班外的行政班和提高班ids
|
|
@@ -198,35 +195,22 @@ public class ClassStudentService {
|
198
|
195
|
public void save(TClassStudent model) throws Exception {
|
199
|
196
|
try {
|
200
|
197
|
model.setCreatetime(N_Utils.getSecondTimestamp());
|
|
198
|
+ Integer schoolid = model.getSchoolid();
|
201
|
199
|
if (!N_Utils.isEmpty(model.getStudentno())) {
|
202
|
200
|
String headpic = model.getHeadpic();
|
203
|
|
- TUser user = userService.getObjByLoginName(model.getStudentno());
|
|
201
|
+ TUser user = userMapper.getObjByLoginName(model.getStudentno());
|
204
|
202
|
if (user == null) {//学生信息在用户表不存在,添加学生信息
|
205
|
|
- user = new TUser();
|
206
|
|
- user.setUsertype(2);
|
207
|
|
- user.setUsername(model.getStudentname());
|
208
|
|
- user.setLoginname(model.getStudentno());
|
209
|
|
- user.setLoginpwd("123456");
|
210
|
|
- user.setUsersex(model.getUsersex());
|
211
|
|
- user.setStudentno(model.getStudentno());
|
212
|
|
- user.setCreateid(model.getCreateid());
|
213
|
|
- user.setSchoolid(model.getSchoolid());
|
214
|
|
- user.setUsertime(model.getUsertime());
|
215
|
|
- user.setHeadpic(headpic);
|
216
|
|
- user.setUserphone(model.getUserphone());
|
217
|
|
- ResultVo vo = userService.save(user);
|
218
|
|
- if (vo.getCode() != 0) throw new Exception(vo.getMsg());
|
219
|
|
- user.setUserid((Integer) vo.getObj());
|
|
203
|
+ user = saveUser(model);//保存用户信息
|
220
|
204
|
} else if (user.getUsertype() != 2) {
|
221
|
205
|
throw new Exception("禁止添加非学生账号");
|
222
|
|
- } else if (!model.getSchoolid().equals(user.getSchoolid())) {
|
|
206
|
+ } else if (!schoolid.equals(user.getSchoolid())) {
|
223
|
207
|
throw new Exception("禁止添加非本校学生账号");
|
224
|
208
|
} else if (N_Utils.isNotEmpty(headpic) || 1 != user.getUserstate()) {
|
225
|
209
|
TUser stu = new TUser();
|
226
|
210
|
Integer userid = user.getUserid();
|
227
|
211
|
stu.setUserid(userid);
|
228
|
212
|
if (N_Utils.isNotEmpty(headpic)) {
|
229
|
|
- TUser u = userService.getUserTypeAndHeadTime(userid);//获取用户类型和修改头像时间
|
|
213
|
+ TUser u = userMapper.getUserTypeAndHeadTime(userid);//获取用户类型和修改头像时间
|
230
|
214
|
if (u.getHeadtime() == 0) {
|
231
|
215
|
throw new Exception("6个月内只能修改一次");
|
232
|
216
|
} else {
|
|
@@ -237,7 +221,7 @@ public class ClassStudentService {
|
237
|
221
|
if (1 != user.getUserstate()) {//已删除用户改为正常用户
|
238
|
222
|
stu.setUserstate(1);
|
239
|
223
|
}
|
240
|
|
- userService.updateByPrimaryKeySelective(stu);
|
|
224
|
+ userMapper.updateByPrimaryKeySelective(stu);
|
241
|
225
|
}
|
242
|
226
|
|
243
|
227
|
model.setStudentid(user.getUserid());
|
|
@@ -263,7 +247,7 @@ public class ClassStudentService {
|
263
|
247
|
groupStudent.setGroupid(model.getGroupid());
|
264
|
248
|
groupStudent.setStudentid(model.getStudentid());
|
265
|
249
|
groupStudent.setCreateid(model.getCreateid());
|
266
|
|
- groupStudent.setSchoolid(model.getSchoolid());
|
|
250
|
+ groupStudent.setSchoolid(schoolid);
|
267
|
251
|
addGroupStudentList.add(groupStudent);
|
268
|
252
|
}
|
269
|
253
|
List<Integer> changeCourseidList = new ArrayList<>();//用户更新直播课中学生数量
|
|
@@ -290,6 +274,60 @@ public class ClassStudentService {
|
290
|
274
|
}
|
291
|
275
|
}
|
292
|
276
|
|
|
277
|
+ /**
|
|
278
|
+ * 保存用户信息
|
|
279
|
+ *
|
|
280
|
+ * @param [model]
|
|
281
|
+ * @return com.xhkjedu.suser.model.system.TUser
|
|
282
|
+ * @author ywx
|
|
283
|
+ * @date 2022/5/20 10:22
|
|
284
|
+ */
|
|
285
|
+ private TUser saveUser(TClassStudent model) throws Exception {
|
|
286
|
+ Integer schoolid = model.getSchoolid();
|
|
287
|
+ TUser user = new TUser();
|
|
288
|
+ user.setUsertype(2);
|
|
289
|
+ user.setUsername(model.getStudentname());
|
|
290
|
+ user.setLoginname(model.getStudentno());
|
|
291
|
+ user.setLoginpwd(N_Utils.getMD5Pwd("123456"));
|
|
292
|
+ user.setUsersex(model.getUsersex());
|
|
293
|
+ user.setStudentno(model.getStudentno());
|
|
294
|
+ user.setCreateid(model.getCreateid());
|
|
295
|
+ user.setSchoolid(schoolid);
|
|
296
|
+ user.setUsertime(model.getUsertime());
|
|
297
|
+ user.setHeadpic(model.getHeadpic());
|
|
298
|
+ user.setUserphone(model.getUserphone());
|
|
299
|
+ Integer usernum = schoolMapper.getUserNumById(schoolid);
|
|
300
|
+ if (usernum != null) {
|
|
301
|
+ Integer usernum2 = userMapper.getUserNumBySchoolId(schoolid);
|
|
302
|
+ usernum2 = usernum2 + 1;//学校账号数量+本次添加的人
|
|
303
|
+ if (usernum.compareTo(usernum2) == -1) {
|
|
304
|
+ throw new Exception("账号数量已超限,请联系管理员");
|
|
305
|
+ }
|
|
306
|
+ }
|
|
307
|
+ user.setUserstate(1);
|
|
308
|
+ user.setCreatetime(N_Utils.getSecondTimestamp());
|
|
309
|
+ Integer bindphoned = 0;
|
|
310
|
+ String userphone = user.getUserphone();
|
|
311
|
+ if (N_Utils.isNotEmpty(userphone)) {
|
|
312
|
+ //获取手机号绑定的其他用户数量
|
|
313
|
+ Integer num = userMapper.getNumByUserPhone(0, userphone);
|
|
314
|
+ if (num != 0) {//手机号被其他账号绑定,不保存返回提示信息
|
|
315
|
+ throw new Exception("手机号【" + userphone + "】已被绑定");
|
|
316
|
+ } else {//手机号未被其他账号绑定,设置已绑定手机号
|
|
317
|
+ bindphoned = 1;
|
|
318
|
+ }
|
|
319
|
+ }
|
|
320
|
+ user.setBindphoned(bindphoned);
|
|
321
|
+ if ("NaN-aN-aN".equals(user.getUsertime())) {//有效期异常值置空
|
|
322
|
+ user.setUsertime(null);
|
|
323
|
+ }
|
|
324
|
+ user.setBindsecret(0);
|
|
325
|
+ user.setUserlock(0);
|
|
326
|
+ userMapper.insertUseGeneratedKeys(user);
|
|
327
|
+ user.setUserid(user.getId());
|
|
328
|
+ return user;
|
|
329
|
+ }
|
|
330
|
+
|
293
|
331
|
//删除
|
294
|
332
|
@Transactional(rollbackFor = Exception.class)
|
295
|
333
|
public void deleteById(Integer classid, Integer studentid) {
|
|
@@ -332,7 +370,7 @@ public class ClassStudentService {
|
332
|
370
|
|
333
|
371
|
//修改
|
334
|
372
|
public ResultVo update(TClassStudent model) {
|
335
|
|
- TUser u = userService.getObjByLoginName(model.getStudentno());
|
|
373
|
+ TUser u = userMapper.getObjByLoginName(model.getStudentno());
|
336
|
374
|
if (u != null && !model.getStudentid().equals(u.getUserid())) {
|
337
|
375
|
return new ResultVo(1, "该账号已被【" + u.getUsername() + "】占用");
|
338
|
376
|
}
|
|
@@ -346,8 +384,23 @@ public class ClassStudentService {
|
346
|
384
|
user.setUserphone(model.getUserphone());
|
347
|
385
|
user.setUsertime(model.getUsertime());
|
348
|
386
|
user.setHeadpic(model.getHeadpic());
|
349
|
|
- ResultVo vo = userService.update(user);
|
350
|
|
- if (vo.getCode() != 0) return vo;
|
|
387
|
+ Integer bindphoned = 0;
|
|
388
|
+ String userphone = user.getUserphone();
|
|
389
|
+ if (N_Utils.isEmpty(userphone) || userphone.contains("****")) {//手机号为空或带星号不修改手机号和是否绑定手机号
|
|
390
|
+ bindphoned = null;
|
|
391
|
+ user.setUserphone(null);
|
|
392
|
+ } else if (N_Utils.isNotEmpty(userphone)) {
|
|
393
|
+ //获取手机号绑定的其他用户数量
|
|
394
|
+ Integer num = userMapper.getNumByUserPhone(user.getUserid(), userphone);
|
|
395
|
+ if (num != 0) return new ResultVo(1, "此手机号已被绑定");
|
|
396
|
+ bindphoned = 1;
|
|
397
|
+ }
|
|
398
|
+ user.setBindphoned(bindphoned);
|
|
399
|
+ if ("NaN-aN-aN".equals(user.getUsertime())) {//有效期异常值置空
|
|
400
|
+ user.setUsertime(null);
|
|
401
|
+ }
|
|
402
|
+ user.setCreatetime(N_Utils.getSecondTimestamp());
|
|
403
|
+ userMapper.updateByPrimaryKeySelective(user);
|
351
|
404
|
return new ResultVo(0, "修改成功");
|
352
|
405
|
}
|
353
|
406
|
|
|
@@ -378,22 +431,17 @@ public class ClassStudentService {
|
378
|
431
|
}
|
379
|
432
|
Integer usernum = schoolMapper.getUserNumById(schoolid);
|
380
|
433
|
if (usernum != null) {
|
381
|
|
- Integer usernum2 = userService.getUserNumBySchoolId(schoolid);
|
|
434
|
+ Integer usernum2 = userMapper.getUserNumBySchoolId(schoolid);
|
382
|
435
|
usernum2 = usernum2 + stunum;//学校账号数量+本次添加的人
|
383
|
436
|
if (usernum.compareTo(usernum2) == -1) {
|
384
|
437
|
return new ResultVo(1, "账号数量已超限,请联系管理员");
|
385
|
438
|
}
|
386
|
439
|
}
|
387
|
440
|
map.remove("users");//导入成功的学生信息不返回给前端
|
388
|
|
- /*if (!CollectionUtils.isEmpty((List<TUser>)map.get("excelExisted"))) {
|
389
|
|
- map.put("code",1);
|
390
|
|
- return new ResultVo(0, "导入失败", map);
|
391
|
|
- }*/
|
392
|
441
|
|
393
|
442
|
List<TUser> users = new ArrayList<>();
|
394
|
443
|
List<TClassStudent> classStudents = new ArrayList<>();
|
395
|
444
|
List<TGroupStudent> groupStudents = new ArrayList<>();
|
396
|
|
- //List<Integer> delClassidList = new ArrayList<>();//需要删除的班级学生信息
|
397
|
445
|
List<TClassStudent> delStudentList = new ArrayList<>();//要删除的班级学生集合
|
398
|
446
|
List<Integer> changeCourseidList = new ArrayList<>();//用户更新直播课中学生数量
|
399
|
447
|
Map<Integer, List<Map>> courseMap = new HashMap<>();//要添加班级直播
|
|
@@ -401,7 +449,7 @@ public class ClassStudentService {
|
401
|
449
|
// 以下学生信息已存在
|
402
|
450
|
List<TUser> usersExisted = new ArrayList<>();
|
403
|
451
|
for (TUser user : students) {
|
404
|
|
- TUser u = userService.getObjByLoginName(user.getLoginname());
|
|
452
|
+ TUser u = userMapper.getObjByLoginName(user.getLoginname());
|
405
|
453
|
if (null == u) {
|
406
|
454
|
user.setSchoolid(schoolid);
|
407
|
455
|
user.setCreateid(createid);
|
|
@@ -421,7 +469,7 @@ public class ClassStudentService {
|
421
|
469
|
Integer classid = user.getClassid();
|
422
|
470
|
if (!classid.equals(oldclassid) && 2 == u.getUsertype() && schoolid == u.getSchoolid()) {
|
423
|
471
|
if (1 != u.getUserstate()) {
|
424
|
|
- userService.updateState(u.getUserid(), 1);
|
|
472
|
+ userMapper.updateState(u.getUserid(), 1);
|
425
|
473
|
}
|
426
|
474
|
//要添加的班级
|
427
|
475
|
setStudents(classid, schoolid, createid, user.getGroupid(), classStudents, groupStudents, studentid);//处理班级加入学生
|
|
@@ -466,7 +514,7 @@ public class ClassStudentService {
|
466
|
514
|
|
467
|
515
|
//保存用户信息
|
468
|
516
|
if (!CollectionUtils.isEmpty(users)) {
|
469
|
|
- userService.batchSave(users);
|
|
517
|
+ userMapper.insertList(users);
|
470
|
518
|
for (TUser user : users) {
|
471
|
519
|
Integer studentid = user.getId();
|
472
|
520
|
Integer classid = user.getClassid();
|
|
@@ -478,12 +526,9 @@ public class ClassStudentService {
|
478
|
526
|
|
479
|
527
|
List<Integer> classidlist = new ArrayList<>();
|
480
|
528
|
if (N_Utils.isListNotEmpty(delStudentList)) {//要删除的班级学生集合
|
481
|
|
- Map<Integer, List<TClassStudent>> slist = delStudentList.stream().collect(Collectors.groupingBy(m -> m.getStudentid()));
|
482
|
|
- for (Map.Entry<Integer, List<TClassStudent>> entry : slist.entrySet()) {
|
483
|
|
- List<Integer> delClassidList = delStudentList.stream().map(TClassStudent::getClassid).collect(Collectors.toList());
|
484
|
|
- classStudentMapper.deleteBatchStudent(delClassidList, entry.getKey().toString());//批量移除班级学生
|
485
|
|
- classidlist.addAll(delClassidList);
|
486
|
|
- }
|
|
529
|
+ List<Integer> delClassidList = delStudentList.stream().map(TClassStudent::getClassid).collect(Collectors.toList());
|
|
530
|
+ classStudentMapper.deleteBatchStudent2(delStudentList);//批量删除班级、分组对应学生
|
|
531
|
+ classidlist.addAll(delClassidList);
|
487
|
532
|
}
|
488
|
533
|
|
489
|
534
|
//保存学生关联信息
|
|
@@ -587,7 +632,7 @@ public class ClassStudentService {
|
587
|
632
|
// 以下学生信息不存在
|
588
|
633
|
List<TUser> usersNotExisted = new ArrayList<>();
|
589
|
634
|
for (TUser user : students) {
|
590
|
|
- TUser u = userService.getObjByLoginName(user.getLoginname());
|
|
635
|
+ TUser u = userMapper.getObjByLoginName(user.getLoginname());
|
591
|
636
|
if (null == u) {
|
592
|
637
|
user.setSchoolid(schoolid);
|
593
|
638
|
user.setCreateid(createid);
|
|
@@ -604,7 +649,7 @@ public class ClassStudentService {
|
604
|
649
|
usersNotExisted.add(u);
|
605
|
650
|
} else if (0 == classnum && 2 == u.getUsertype() && schoolid == u.getSchoolid()) {
|
606
|
651
|
if (1 != u.getUserstate()) {
|
607
|
|
- userService.updateState(u.getUserid(), 1);
|
|
652
|
+ userMapper.updateState(u.getUserid(), 1);
|
608
|
653
|
}
|
609
|
654
|
setStudents(classid, schoolid, createid, user.getGroupid(), classStudents, groupStudents, studentid);//处理班级加入学生
|
610
|
655
|
List<Map> courses = listCourseByClassId(courseMap, classid);
|
|
@@ -803,7 +848,21 @@ public class ClassStudentService {
|
803
|
848
|
* @Date 2020/9/18 11:56
|
804
|
849
|
**/
|
805
|
850
|
public void removeBind(Integer studentid) {
|
806
|
|
- userService.removeBind(studentid);
|
|
851
|
+ List<Integer> studentids = new ArrayList<>();
|
|
852
|
+ studentids.add(studentid);
|
|
853
|
+ userMapper.batchRemoveBind(studentids);//批量解绑
|
|
854
|
+ }
|
|
855
|
+
|
|
856
|
+ /**
|
|
857
|
+ * 批量解绑
|
|
858
|
+ *
|
|
859
|
+ * @param [studentids]
|
|
860
|
+ * @return void
|
|
861
|
+ * @author ywx
|
|
862
|
+ * @date 2022/5/20 13:48
|
|
863
|
+ */
|
|
864
|
+ public void batchRemoveBind(List<Integer> studentids) {
|
|
865
|
+ userMapper.batchRemoveBind(studentids);//批量解绑
|
807
|
866
|
}
|
808
|
867
|
|
809
|
868
|
/**
|
|
@@ -870,4 +929,160 @@ public class ClassStudentService {
|
870
|
929
|
}
|
871
|
930
|
return new ResultVo(0, "取消选课成功");
|
872
|
931
|
}
|
|
932
|
+
|
|
933
|
+ /**
|
|
934
|
+ * 批量移除学生
|
|
935
|
+ *
|
|
936
|
+ * @param [students]
|
|
937
|
+ * @return void
|
|
938
|
+ * @author ywx
|
|
939
|
+ * @date 2022/5/20 14:52
|
|
940
|
+ */
|
|
941
|
+ @Transactional(rollbackFor = Exception.class)
|
|
942
|
+ public void batchDelete(List<TClassStudent> students) {
|
|
943
|
+ try {
|
|
944
|
+ List<TClassStudent> delStudentList = new ArrayList<>();//要删除的班级学生集合
|
|
945
|
+ delStudentList.addAll(students);
|
|
946
|
+ List<Integer> delids = students.stream().map(TClassStudent::getClassid).distinct().collect(Collectors.toList());
|
|
947
|
+
|
|
948
|
+ List<Map> classMap = classStudentMapper.listClassIdsByCidAndSid(students);//获取学生除某个班外的行政班和提高班ids
|
|
949
|
+ Map<Integer, String> studentClassMap = new HashMap<>();//学生除某个班外的行政班和提高班ids集合
|
|
950
|
+ for (Map map : classMap) {
|
|
951
|
+ studentClassMap.put((Integer) map.get("studentid"), map.get("classids").toString());
|
|
952
|
+ }
|
|
953
|
+ List<Map> courseAll = courseMapper.listXzCourse2(delids);//指定班级的直播课
|
|
954
|
+ Map<Integer, List<Map>> delCourseMap = courseAll.stream().collect(Collectors.groupingBy(m -> (Integer) m.get("oldclassid")));
|
|
955
|
+
|
|
956
|
+ List<Integer> changeCourseidList = new ArrayList<>();//用户更新直播课中学生数量
|
|
957
|
+ for (TClassStudent student : students) {
|
|
958
|
+ Integer classid = student.getClassid();
|
|
959
|
+ Integer studentid = student.getStudentid();
|
|
960
|
+ //把这个学生从此行政班、提高班关联的所有直播班移除
|
|
961
|
+ String classids = studentClassMap.get(studentid);//获取学生除某个班外的行政班和提高班ids
|
|
962
|
+ List<Map> courses = delCourseMap.get(classid);//指定班级的直播课
|
|
963
|
+ if (courses == null) courses = new ArrayList<>();//null时执行hs1.removeAll(hs2)报错
|
|
964
|
+ if (N_Utils.isNotEmpty(classids)) {
|
|
965
|
+ List<Map> courses2 = courseMapper.listCourse(classids);//某些班的直播课
|
|
966
|
+ if (N_Utils.isListNotEmpty(courses2)) {//要排除班级的直播不为空
|
|
967
|
+ HashSet hs1 = new HashSet(courses);
|
|
968
|
+ HashSet hs2 = new HashSet(courses2);
|
|
969
|
+ hs1.removeAll(hs2);//指定班级排除某些班级的直播
|
|
970
|
+ courses = new ArrayList<>();
|
|
971
|
+ courses.addAll(hs1);
|
|
972
|
+ }
|
|
973
|
+ }
|
|
974
|
+ handleDelClassCourse2(delStudentList, changeCourseidList, courses, studentid);//处理关联的直播课以及需要删除学生的直播班id
|
|
975
|
+ }
|
|
976
|
+
|
|
977
|
+ List<Integer> delClassidList = delStudentList.stream().map(TClassStudent::getClassid).distinct().collect(Collectors.toList());
|
|
978
|
+ classStudentMapper.deleteBatchStudent2(delStudentList);//批量删除班级、分组对应学生
|
|
979
|
+ String numclassids = delClassidList.stream().distinct().map(String::valueOf).collect(Collectors.joining(","));
|
|
980
|
+ classMapper.updateClassGroupNumByType(numclassids);//批量修改班级、班级分组数量
|
|
981
|
+ if (N_Utils.isListNotEmpty(changeCourseidList)) {
|
|
982
|
+ String numcourseids = changeCourseidList.stream().distinct().map(String::valueOf).collect(Collectors.joining(","));
|
|
983
|
+ courseMapper.updateStuNumBatch(numcourseids);//批量修改课程学生数量
|
|
984
|
+ }
|
|
985
|
+ } catch (Exception e) {
|
|
986
|
+ log.error("批量移除学生出错:" + e.getMessage());
|
|
987
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
988
|
+ throw new MissingParametersException(e.getMessage());
|
|
989
|
+ }
|
|
990
|
+ }
|
|
991
|
+
|
|
992
|
+ /**
|
|
993
|
+ * 批量转班
|
|
994
|
+ *
|
|
995
|
+ * @param [students]
|
|
996
|
+ * @return void
|
|
997
|
+ * @author ywx
|
|
998
|
+ * @date 2022/5/20 17:07
|
|
999
|
+ */
|
|
1000
|
+ @Transactional(rollbackFor = Exception.class)
|
|
1001
|
+ public void batchMoveClass(List<TClassStudent> students) {
|
|
1002
|
+ try {
|
|
1003
|
+ List<TClassStudent> delStudentList = new ArrayList<>();//要删除的班级学生集合
|
|
1004
|
+ List<TClassStudent> addClassStudentList = new ArrayList<>();//新增的班级学生集合
|
|
1005
|
+ List<TGroupStudent> addGroupStudentList = new ArrayList<>();//新增的班级分组集合
|
|
1006
|
+ List<Integer> changeCourseidList = new ArrayList<>();//用户更新直播课中学生数量
|
|
1007
|
+
|
|
1008
|
+ List<Integer> classIds = students.stream().map(TClassStudent::getClassid).distinct().collect(Collectors.toList());
|
|
1009
|
+ List<ClassVo> classes = classMapper.listByIds(classIds);//获取新班级信息
|
|
1010
|
+ List<Map> addCourseAll = courseMapper.listXzCourse2(classIds);//指定班级的直播课
|
|
1011
|
+ Map<Integer, List<Map>> addCourseMap = addCourseAll.stream().collect(Collectors.groupingBy(m -> (Integer) m.get("oldclassid")));
|
|
1012
|
+
|
|
1013
|
+ List<TClassStudent> oldStudents = new ArrayList<>();//要转班的班级学生集合
|
|
1014
|
+ for (TClassStudent student : students) {
|
|
1015
|
+ TClassStudent oldStu = new TClassStudent();
|
|
1016
|
+ oldStu.setClassid(student.getOldclassid());
|
|
1017
|
+ oldStu.setStudentid(student.getStudentid());
|
|
1018
|
+ oldStudents.add(oldStu);
|
|
1019
|
+ }
|
|
1020
|
+ List<Map> classMap = classStudentMapper.listClassIdsByCidAndSid(oldStudents);//获取学生除某个班外的行政班和提高班ids
|
|
1021
|
+ Map<Integer, String> studentClassMap = new HashMap<>();//学生除某个班外的行政班和提高班ids集合
|
|
1022
|
+ for (Map map : classMap) {
|
|
1023
|
+ studentClassMap.put((Integer) map.get("studentid"), map.get("classids").toString());
|
|
1024
|
+ }
|
|
1025
|
+ List<Integer> delids = students.stream().map(TClassStudent::getOldclassid).distinct().collect(Collectors.toList());
|
|
1026
|
+ List<Map> courseAll = courseMapper.listXzCourse2(delids);//指定班级的直播课
|
|
1027
|
+ Map<Integer, List<Map>> courseMap = courseAll.stream().collect(Collectors.groupingBy(m -> (Integer) m.get("oldclassid")));
|
|
1028
|
+ Map<String, List<Map>> delCourseMap = new HashMap();//要删除班级直播课
|
|
1029
|
+ for (TClassStudent student : students) {
|
|
1030
|
+ Integer studentid = student.getStudentid();
|
|
1031
|
+ Integer classid = student.getClassid();
|
|
1032
|
+ //把这个学生从此行政班、提高班关联的所有直播班移除
|
|
1033
|
+ String classids = studentClassMap.get(studentid);//获取学生除某个班外的行政班和提高班ids
|
|
1034
|
+ List<Map> courses = courseMap.get(student.getOldclassid());//指定班级的直播课
|
|
1035
|
+ if (courses == null) courses = new ArrayList<>();//null时执行hs1.removeAll(hs2)报错
|
|
1036
|
+ List<Map> courses2;
|
|
1037
|
+ if (N_Utils.isNotEmpty(classids)) {
|
|
1038
|
+ courses2 = delCourseMap.get(classids);
|
|
1039
|
+ if (N_Utils.isListEmpty(courses2)) {
|
|
1040
|
+ courses2 = courseMapper.listCourse(classids);//某些班的直播课
|
|
1041
|
+ delCourseMap.put(classids, courses2);
|
|
1042
|
+ }
|
|
1043
|
+ if (courses2 == null) {//要排除班级的直播为空
|
|
1044
|
+ courses2 = courses;
|
|
1045
|
+ } else {//要排除班级的直播不为空
|
|
1046
|
+ HashSet hs1 = new HashSet(courses);
|
|
1047
|
+ HashSet hs2 = new HashSet(courses2);
|
|
1048
|
+ hs1.removeAll(hs2);//指定班级排除某些班级的直播
|
|
1049
|
+ courses2 = new ArrayList<>();
|
|
1050
|
+ courses2.addAll(hs1);
|
|
1051
|
+ }
|
|
1052
|
+ } else {
|
|
1053
|
+ courses2 = courses;//指定班级的直播课
|
|
1054
|
+ }
|
|
1055
|
+ handleDelClassCourse2(delStudentList, changeCourseidList, courses2, studentid);//处理关联的直播课以及需要删除学生的直播班id
|
|
1056
|
+
|
|
1057
|
+ //学生新添加班级的信息
|
|
1058
|
+ ClassVo classVo = classes.stream().filter(c -> c.getClassid().equals(classid)).findFirst().orElse(null);//获取新班级信息
|
|
1059
|
+ //学生要加入新的班级信息处理
|
|
1060
|
+ moveClassHandleAddGroupStudent(addClassStudentList, addGroupStudentList, classVo, studentid);
|
|
1061
|
+
|
|
1062
|
+ //获取新班级关联直播课关联的班级,并把学生加入
|
|
1063
|
+ courses = addCourseMap.get(classid);
|
|
1064
|
+ handleAddClassCourse(addClassStudentList, addGroupStudentList, changeCourseidList, courses, studentid);
|
|
1065
|
+ }
|
|
1066
|
+
|
|
1067
|
+ List<Integer> delClassidList = delStudentList.stream().map(TClassStudent::getClassid).distinct().collect(Collectors.toList());
|
|
1068
|
+ classStudentMapper.deleteBatchStudent2(delStudentList);//批量删除班级、分组对应学生
|
|
1069
|
+ classStudentMapper.saveBatchClassStudent(addClassStudentList);//批量新增班级学生
|
|
1070
|
+ groupStudentMapper.saveBatchGroupStudent(addGroupStudentList);//批量新增班级分组学生
|
|
1071
|
+
|
|
1072
|
+ //新增学生的班级id集合
|
|
1073
|
+ List<Integer> saveclassids = addClassStudentList.stream().map(TClassStudent::getClassid).distinct().collect(Collectors.toList());
|
|
1074
|
+ delClassidList.addAll(saveclassids);
|
|
1075
|
+
|
|
1076
|
+ String numclassids = delClassidList.stream().distinct().map(String::valueOf).collect(Collectors.joining(","));
|
|
1077
|
+ classMapper.updateClassGroupNumByType(numclassids);//批量修改班级、班级分组数量
|
|
1078
|
+ if (N_Utils.isListNotEmpty(changeCourseidList)) {
|
|
1079
|
+ String numcourseids = changeCourseidList.stream().distinct().map(String::valueOf).collect(Collectors.joining(","));
|
|
1080
|
+ courseMapper.updateStuNumBatch(numcourseids);//批量修改课程学生数量
|
|
1081
|
+ }
|
|
1082
|
+ } catch (Exception e) {
|
|
1083
|
+ log.error("批量转班出错:" + e.getMessage());
|
|
1084
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
1085
|
+ throw new MissingParametersException(e.getMessage());
|
|
1086
|
+ }
|
|
1087
|
+ }
|
873
|
1088
|
}
|