BandingTaskServiceImpl.java 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. package com.xjrsoft.module.banding.service.impl;
  2. import cn.dev33.satoken.secure.BCrypt;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  5. import com.github.yulichang.base.MPJBaseServiceImpl;
  6. import com.github.yulichang.wrapper.MPJLambdaWrapper;
  7. import com.xjrsoft.common.enums.ArchivesStatusEnum;
  8. import com.xjrsoft.common.enums.EnabledMark;
  9. import com.xjrsoft.common.enums.GenderDictionaryEnum;
  10. import com.xjrsoft.common.enums.RoleEnum;
  11. import com.xjrsoft.common.exception.MyException;
  12. import com.xjrsoft.common.utils.VoToColumnUtil;
  13. import com.xjrsoft.config.CommonPropertiesConfig;
  14. import com.xjrsoft.module.banding.dto.AutomaticBandingTaskDto;
  15. import com.xjrsoft.module.banding.dto.BandingTaskClassStudentPageDto;
  16. import com.xjrsoft.module.banding.dto.SureBandingTaskDto;
  17. import com.xjrsoft.module.banding.entity.BandingRule;
  18. import com.xjrsoft.module.banding.entity.BandingTask;
  19. import com.xjrsoft.module.banding.entity.BandingTaskClass;
  20. import com.xjrsoft.module.banding.entity.BandingTaskClassStudent;
  21. import com.xjrsoft.module.banding.entity.BandingTaskMajorCondition;
  22. import com.xjrsoft.module.banding.entity.BandingTaskRule;
  23. import com.xjrsoft.module.banding.mapper.BandingRuleMapper;
  24. import com.xjrsoft.module.banding.mapper.BandingTaskClassMapper;
  25. import com.xjrsoft.module.banding.mapper.BandingTaskMapper;
  26. import com.xjrsoft.module.banding.mapper.BandingTaskRuleMapper;
  27. import com.xjrsoft.module.banding.service.IBandingTaskClassStudentService;
  28. import com.xjrsoft.module.banding.service.IBandingTaskMajorConditionService;
  29. import com.xjrsoft.module.banding.service.IBandingTaskService;
  30. import com.xjrsoft.module.banding.vo.BandingTaskClassSureListVo;
  31. import com.xjrsoft.module.base.entity.BaseClass;
  32. import com.xjrsoft.module.base.service.IBaseClassService;
  33. import com.xjrsoft.module.organization.entity.User;
  34. import com.xjrsoft.module.organization.entity.UserRoleRelation;
  35. import com.xjrsoft.module.organization.service.IUserRoleRelationService;
  36. import com.xjrsoft.module.organization.service.IUserService;
  37. import com.xjrsoft.module.outint.vo.IdCountVo;
  38. import com.xjrsoft.module.student.entity.BaseClassMajorSet;
  39. import com.xjrsoft.module.student.entity.BaseNewStudent;
  40. import com.xjrsoft.module.student.entity.BaseStudent;
  41. import com.xjrsoft.module.student.entity.BaseStudentFamily;
  42. import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
  43. import com.xjrsoft.module.student.entity.EnrollmentPlan;
  44. import com.xjrsoft.module.student.mapper.BaseClassMajorSetMapper;
  45. import com.xjrsoft.module.student.service.IBaseNewStudentService;
  46. import com.xjrsoft.module.student.service.IBaseStudentFamilyService;
  47. import com.xjrsoft.module.student.service.IBaseStudentSchoolRollService;
  48. import com.xjrsoft.module.student.service.IBaseStudentService;
  49. import lombok.AllArgsConstructor;
  50. import org.springframework.stereotype.Service;
  51. import org.springframework.transaction.annotation.Transactional;
  52. import java.time.LocalDateTime;
  53. import java.time.format.DateTimeFormatter;
  54. import java.util.ArrayList;
  55. import java.util.Collections;
  56. import java.util.Date;
  57. import java.util.HashMap;
  58. import java.util.List;
  59. import java.util.Map;
  60. import java.util.Objects;
  61. import java.util.Random;
  62. import java.util.stream.Collectors;
  63. /**
  64. * @title: 新生分班任务
  65. * @Author dzx
  66. * @Date: 2024-07-01
  67. * @Version 1.0
  68. */
  69. @Service
  70. @AllArgsConstructor
  71. public class BandingTaskServiceImpl extends MPJBaseServiceImpl<BandingTaskMapper, BandingTask> implements IBandingTaskService {
  72. private final BandingTaskMapper bandingTaskMapper;
  73. private final BandingRuleMapper ruleMapper;
  74. private final BandingTaskRuleMapper taskRuleMapper;
  75. private final BandingTaskClassMapper taskClassMapper;
  76. private final IBaseNewStudentService newStudentService;
  77. private final IBandingTaskClassStudentService classStudentService;
  78. private final IBandingTaskMajorConditionService conditionService;
  79. private final IBaseClassService classService;
  80. private final BaseClassMajorSetMapper classMajorSetMapper;
  81. private final CommonPropertiesConfig propertiesConfig;
  82. private final IUserService userService;
  83. private final IUserRoleRelationService roleRelationService;
  84. private final IBaseStudentSchoolRollService schoolRollService;
  85. private final IBaseStudentService studentService;
  86. private final IBaseStudentFamilyService familyService;
  87. @Override
  88. @Transactional(rollbackFor = Exception.class)
  89. public Boolean add(BandingTask bandingTask) {
  90. bandingTask.setCreateDate(new Date());
  91. bandingTaskMapper.insert(bandingTask);
  92. return true;
  93. }
  94. @Override
  95. @Transactional(rollbackFor = Exception.class)
  96. public Boolean update(BandingTask bandingTask) {
  97. bandingTask.setModifyDate(new Date());
  98. bandingTaskMapper.updateById(bandingTask);
  99. return true;
  100. }
  101. @Override
  102. @Transactional(rollbackFor = Exception.class)
  103. public Boolean delete(List<Long> ids) {
  104. bandingTaskMapper.deleteBatchIds(ids);
  105. taskRuleMapper.delete(Wrappers.lambdaQuery(BandingTaskRule.class).in(BandingTaskRule::getBandingTaskId, ids));
  106. taskClassMapper.delete(Wrappers.lambdaQuery(BandingTaskClass.class).in(BandingTaskClass::getBandingTaskId, ids));
  107. return true;
  108. }
  109. /**
  110. * 自动分班
  111. * 1、根据分班任务的信息,查询出来需要分班的学生
  112. * 2、查询该任务下的班级信息
  113. * 3、查询该任务使用的规则
  114. * 4、执行自动分班
  115. * 5、完成后,将分好班的信息存到banding_task_class_student表中
  116. */
  117. @Override
  118. public Boolean automaticBanding(AutomaticBandingTaskDto dto) {
  119. BandingTask bandingTask = this.getById(dto.getBandingTaskId());
  120. if(bandingTask == null){
  121. throw new MyException("未能查询到该任务,无法自动分班");
  122. }
  123. //1、查询需要分班的学生信息
  124. List<String> orderColumn = new ArrayList();
  125. orderColumn.add("height");orderColumn.add("score");
  126. List<BaseNewStudent> baseNewStudents = newStudentService.selectJoinList(BaseNewStudent.class,
  127. new MPJLambdaWrapper<BaseNewStudent>()
  128. .select(BaseNewStudent::getId)
  129. .select(BaseNewStudent.class, x -> VoToColumnUtil.fieldsToColumns(BaseNewStudent.class).contains(x.getProperty()))
  130. .leftJoin(EnrollmentPlan.class, EnrollmentPlan::getId, BaseNewStudent::getEnrollmentPlanId)
  131. .eq(EnrollmentPlan::getGradeId, bandingTask.getGradeId())
  132. .eq(EnrollmentPlan::getEnrollType, bandingTask.getEnrollType())
  133. .eq(BaseNewStudent::getStatus, 0)
  134. .orderByDescStr(orderColumn)
  135. );
  136. //2、查询所有班级信息
  137. List<BandingTaskClass> classList = taskClassMapper.getListOrderByAsc(bandingTask.getId());
  138. //3、查询所用到的规则
  139. List<BandingRule> ruleList = ruleMapper.selectJoinList(BandingRule.class,
  140. new MPJLambdaWrapper<BandingRule>()
  141. .select(BandingRule::getId)
  142. .select(BandingRule.class, x -> VoToColumnUtil.fieldsToColumns(BandingRule.class).contains(x.getProperty()))
  143. .innerJoin(BandingTaskRule.class, BandingTaskRule::getBandingRuleId, BandingRule::getId)
  144. .eq(BandingTaskRule::getBandingTaskId, bandingTask.getId())
  145. );
  146. List<String> ruleCodes = ruleList.stream().map(BandingRule::getCode).collect(Collectors.toList());
  147. //包含下面个条件,则需要计算每个班级应该分配的人数
  148. Map<Long, Integer> classLimitMap = new HashMap<>();
  149. if(ruleCodes.contains("BR0004")){
  150. //查询每个专业下面有多少个班级
  151. Map<Long, Integer> majorClassCount = taskClassMapper.getMajorClassCount(bandingTask.getId())
  152. .stream().collect(Collectors.toMap(IdCountVo::getId, IdCountVo::getCount));
  153. //查询每个专业下面的班级人数
  154. Map<Long, Integer> majorClassStudentCount = taskClassMapper.getMajorClassStudentCount(bandingTask.getId())
  155. .stream().collect(Collectors.toMap(IdCountVo::getId, IdCountVo::getCount));
  156. //查询每个专业人数
  157. Map<Long, Integer> majorStudentCount = newStudentService.getMajorStudentCount()
  158. .stream().collect(Collectors.toMap(IdCountVo::getId, IdCountVo::getCount));
  159. Map<Long, Integer> majorLimitMap = new HashMap<>();
  160. for (Long majorSetId : majorClassStudentCount.keySet()) {
  161. Integer majorClassNumber = majorClassStudentCount.get(majorSetId);
  162. Integer majorStudentNumber = majorStudentCount.get(majorSetId);
  163. Integer classCount = majorClassCount.get(majorSetId);
  164. if(majorStudentNumber < majorClassNumber){//报名人数小于班级人数
  165. Integer classLimtCount = majorStudentNumber / classCount;
  166. majorLimitMap.put(majorSetId, classLimtCount);
  167. }else{
  168. Integer classLimtCount = majorClassNumber / classCount;
  169. majorLimitMap.put(majorSetId, classLimtCount);
  170. }
  171. }
  172. for (BandingTaskClass bandingTaskClass : classList) {
  173. classLimitMap.put(bandingTaskClass.getId(), majorLimitMap.get(bandingTaskClass.getMajorSetId()));
  174. }
  175. }
  176. //查询每个专业的限制条件
  177. List<BandingTaskMajorCondition> list = conditionService.list(
  178. new QueryWrapper<BandingTaskMajorCondition>().lambda()
  179. .eq(BandingTaskMajorCondition::getBandingTaskId, dto.getBandingTaskId())
  180. );
  181. Map<Long, BandingTaskMajorCondition> classConditionMap = new HashMap<>();
  182. for (BandingTaskMajorCondition conditionDto : list) {
  183. classConditionMap.put(conditionDto.getMajorSetId(), conditionDto);
  184. }
  185. Map<Long, List<BaseNewStudent>> classStudentMap = new HashMap<>();
  186. if(ruleCodes.contains("BR0002")){
  187. classStudentMap.putAll(divideStudentByScore(classConditionMap, baseNewStudents, classList));
  188. }
  189. //存班级和学生的关系
  190. Map<Long, Long> studentClassMap = new HashMap<>();
  191. //4、开始分班
  192. for (BandingTaskClass taskClass : classList) {
  193. Integer number = taskClass.getNumber();//班级总人数
  194. if(classLimitMap.get(taskClass.getId()) != null){
  195. if(number > classLimitMap.get(taskClass.getId())){
  196. number = classLimitMap.get(taskClass.getId());
  197. }
  198. }
  199. Integer maleCount = 0, femaleCount = 0;
  200. if(ruleCodes.contains("BR0001")){
  201. maleCount = number / 2;
  202. femaleCount = number / 2;
  203. //如果班级人数是奇数,随机分配一个名额
  204. if(number % 2 != 0){
  205. Random random = new Random();
  206. int randomIndex = random.nextInt(GenderDictionaryEnum.getCodes().length);
  207. String randomGender = GenderDictionaryEnum.getCodes()[randomIndex];
  208. if(GenderDictionaryEnum.MALE.getCode().equals(randomGender)){
  209. maleCount ++;
  210. }else if(GenderDictionaryEnum.FEMALE.getCode().equals(randomGender)){
  211. femaleCount ++ ;
  212. }
  213. }
  214. }
  215. List<String> nameList = new ArrayList<>();
  216. List<BaseNewStudent> maleList = new ArrayList();
  217. List<BaseNewStudent> femaleList = new ArrayList();
  218. List<BaseNewStudent> studentList = new ArrayList<>();
  219. studentList.addAll(baseNewStudents);
  220. if(ruleCodes.contains("BR0002") && !classStudentMap.get(taskClass.getMajorSetId()).isEmpty()){
  221. studentList.clear();
  222. studentList.addAll(classStudentMap.get(taskClass.getMajorSetId()));
  223. }
  224. for (BaseNewStudent newStudent : studentList) {
  225. //人数已满,进行下一个班级的的循环
  226. if(nameList.size() == number){
  227. break;
  228. }
  229. //该学生已被分配
  230. if(studentClassMap.containsKey(newStudent.getId())){
  231. continue;
  232. }
  233. if(ruleCodes.contains("BR0003") && nameList.contains(newStudent.getName())){
  234. continue;
  235. }
  236. //专业不匹配,直接跳过
  237. if(!Objects.equals(taskClass.getMajorSetId(), newStudent.getFirstAmbitionId()) && !Objects.equals(taskClass.getMajorSetId(), newStudent.getSecondAmbitionId())){
  238. continue;
  239. }
  240. //判断该班性别是否已满
  241. if(ruleCodes.contains("BR0001")){
  242. if(GenderDictionaryEnum.MALE.getCode().equals(newStudent.getGender()) && maleList.size() == maleCount){
  243. continue;
  244. }else if(GenderDictionaryEnum.FEMALE.getCode().equals(newStudent.getGender()) && femaleList.size() == femaleCount){
  245. continue;
  246. }
  247. }
  248. List<Boolean> conditionList = new ArrayList<>();
  249. BandingTaskMajorCondition condition = classConditionMap.get(taskClass.getMajorSetId());
  250. if(condition.getHeight() !=null && newStudent.getHeight() != null && newStudent.getHeight().compareTo(condition.getHeight()) >= 0 ){
  251. conditionList.add(true);
  252. }else if(condition.getHeight() !=null && newStudent.getHeight() != null && newStudent.getHeight().compareTo(condition.getHeight()) < 0){
  253. conditionList.add(false);
  254. }else if(condition.getHeight() !=null && newStudent.getHeight() == null){
  255. conditionList.add(false);
  256. }
  257. if(condition.getScore() !=null && newStudent.getScore() != null && newStudent.getScore().compareTo(condition.getScore()) >= 0 ){
  258. conditionList.add(true);
  259. }else if(condition.getScore() !=null && newStudent.getScore() != null && newStudent.getScore().compareTo(condition.getScore()) < 0){
  260. conditionList.add(false);
  261. }else if(condition.getScore() !=null && newStudent.getScore() == null){
  262. conditionList.add(false);
  263. }
  264. //如果包含false,则表明不符合条件,这个学生跳过
  265. if(conditionList.contains(false)){
  266. continue;
  267. }
  268. studentClassMap.put(newStudent.getId(), taskClass.getId());
  269. if(GenderDictionaryEnum.MALE.getCode().equals(newStudent.getGender())){
  270. maleList.add(newStudent);
  271. }else if(GenderDictionaryEnum.FEMALE.getCode().equals(newStudent.getGender())){
  272. femaleList.add(newStudent);
  273. }
  274. nameList.add(newStudent.getName());
  275. }
  276. }
  277. List<BandingTaskClassStudent> dataList = new ArrayList<>();
  278. Date createDate = new Date();
  279. for (Long studentId : studentClassMap.keySet()) {
  280. dataList.add(
  281. new BandingTaskClassStudent(){{
  282. setBandingTaskClassId(studentClassMap.get(studentId));
  283. setNewStudentId(studentId);
  284. setStatus(0);
  285. setCreateDate(createDate);
  286. }}
  287. );
  288. }
  289. if(!dataList.isEmpty()){
  290. classStudentService.saveBatch(dataList);
  291. }
  292. return true;
  293. }
  294. /**
  295. * 按照成绩均衡划分学生
  296. * @return 班级id和学生
  297. */
  298. Map<Long, List<BaseNewStudent>> divideStudentByScore(Map<Long, BandingTaskMajorCondition> classConditionMap, List<BaseNewStudent> baseNewStudents,
  299. List<BandingTaskClass> classList){
  300. Map<Long, List<BaseNewStudent>> classStudentMap = new HashMap<>();
  301. for (Long majorSetId : classConditionMap.keySet()) {
  302. // 1、先把每个专业匹配的学生分组存一起,并按照分数高低排序
  303. List<BaseNewStudent> stuList = new ArrayList<>();
  304. for (BaseNewStudent newStudent : baseNewStudents) {
  305. if(!Objects.equals(majorSetId, newStudent.getFirstAmbitionId()) && !Objects.equals(majorSetId, newStudent.getSecondAmbitionId())){
  306. continue;
  307. }
  308. List<Boolean> conditionList = new ArrayList<>();
  309. BandingTaskMajorCondition condition = classConditionMap.get(majorSetId);
  310. if(condition.getHeight() !=null && newStudent.getHeight() != null && newStudent.getHeight().compareTo(condition.getHeight()) >= 0 ){
  311. conditionList.add(true);
  312. }else if(condition.getHeight() !=null && newStudent.getHeight() != null && newStudent.getHeight().compareTo(condition.getHeight()) < 0){
  313. conditionList.add(false);
  314. }else if(condition.getHeight() !=null && newStudent.getHeight() == null){
  315. conditionList.add(false);
  316. }
  317. if(condition.getScore() !=null && newStudent.getScore() != null && newStudent.getScore().compareTo(condition.getScore()) >= 0 ){
  318. conditionList.add(true);
  319. }else if(condition.getScore() !=null && newStudent.getScore() != null && newStudent.getScore().compareTo(condition.getScore()) < 0){
  320. conditionList.add(false);
  321. }else if(condition.getScore() !=null && newStudent.getScore() == null){
  322. conditionList.add(false);
  323. }
  324. //如果包含false,则表明不符合条件,这个学生跳过
  325. if(conditionList.contains(false)){
  326. continue;
  327. }
  328. stuList.add(newStudent);
  329. }
  330. Collections.sort(stuList, (s1, s2) -> (int) (s2.getScore().doubleValue() - s1.getScore().doubleValue())); //按照成绩降序排序
  331. //查询该专业下面有几个班级,把这部分学生按照成绩均匀分组
  332. List<List<BaseNewStudent>> result = new ArrayList<>();
  333. for (int i = 0; i < classList.size(); i++) {
  334. result.add(new ArrayList<>());
  335. }
  336. for (int i = 0; i < stuList.size(); i++) {
  337. BaseNewStudent currentStudent = stuList.get(i);
  338. int classIndex = i % stuList.size(); //分配班级
  339. result.get(classIndex).add(currentStudent);
  340. }
  341. for (int i = 0; i < result.size(); i ++){
  342. classStudentMap.put(classList.get(i).getId(), result.get(i));
  343. }
  344. }
  345. return classStudentMap;
  346. }
  347. @Override
  348. public Boolean sure(SureBandingTaskDto dto) {
  349. List<BandingTaskClassStudent> classStudents = classStudentService.selectJoinList(BandingTaskClassStudent.class,
  350. new MPJLambdaWrapper<BandingTaskClassStudent>()
  351. .select(BandingTaskClassStudent::getId)
  352. .select(BandingTaskClassStudent.class, x -> VoToColumnUtil.fieldsToColumns(BandingTaskClassStudent.class).contains(x.getProperty()))
  353. .leftJoin(BandingTaskClass.class, BandingTaskClass::getId, BandingTaskClassStudent::getBandingTaskClassId)
  354. .eq(BandingTaskClass::getBandingTaskId, dto.getId())
  355. .eq(BandingTaskClassStudent::getStatus, 1)
  356. );
  357. List<Long> studentIds = classStudents.stream().map(BandingTaskClassStudent::getNewStudentId).collect(Collectors.toList());
  358. List<BaseNewStudent> list = newStudentService.list(
  359. new QueryWrapper<BaseNewStudent>().lambda()
  360. .in(BaseNewStudent::getId, studentIds)
  361. );
  362. List<BaseNewStudent> updateList = new ArrayList<>();
  363. for (BaseNewStudent student : list) {
  364. student.setStatus(1);
  365. updateList.add(student);
  366. }
  367. if(!updateList.isEmpty()){
  368. newStudentService.updateBatchById(updateList);
  369. }
  370. //形成学生数据
  371. createStudentData(dto.getId(), classStudents, updateList);
  372. BandingTask bandingTask = this.getById(dto.getId());
  373. bandingTask.setStatus(1);
  374. bandingTask.setModifyDate(new Date());
  375. Boolean isSuccess = this.update(bandingTask);
  376. return isSuccess;
  377. }
  378. void createStudentData(Long badingTaskId,List<BandingTaskClassStudent> classStudents, List<BaseNewStudent> updateList){
  379. Date createDate = new Date();
  380. BandingTask bandingTask = this.getById(badingTaskId);
  381. List<BandingTaskClassSureListVo> classSure = taskClassMapper.getClassSure(new BandingTaskClassStudentPageDto() {{
  382. setBandingTaskId(badingTaskId);
  383. }});
  384. Map<Long, Integer> classTotal = classSure.stream().collect(Collectors.toMap(BandingTaskClassSureListVo::getId, BandingTaskClassSureListVo::getNumber));
  385. Map<Long, Integer> classBoy = classSure.stream().collect(Collectors.toMap(BandingTaskClassSureListVo::getId, BandingTaskClassSureListVo::getMaleCount));
  386. Map<Long, Integer> classGirl = classSure.stream().collect(Collectors.toMap(BandingTaskClassSureListVo::getId, BandingTaskClassSureListVo::getFemaleCount));
  387. //生成班级数据
  388. Map<Long, Long> classMap = new HashMap<>();
  389. Map<Long, Long> taskClassMajorMap = new HashMap<>();
  390. //查询出需要新增的班级信息
  391. List<Long> classIds = classStudents.stream().map(BandingTaskClassStudent::getBandingTaskClassId).collect(Collectors.toList());
  392. List<BandingTaskClass> classList = taskClassMapper.selectList(new QueryWrapper<BandingTaskClass>().lambda().in(BandingTaskClass::getId, classIds));
  393. for (BandingTaskClass taskClass : classList) {
  394. BaseClass baseClass = new BaseClass() {{
  395. setName(taskClass.getName());
  396. setClassroomId(taskClass.getClassroomId());
  397. setTeacherId(taskClass.getTeacherId());
  398. setIsGraduate(1);
  399. setIsOrderClass(taskClass.getIsOrderClass().intValue());
  400. setGradeId(bandingTask.getGradeId());
  401. setEnrollType(bandingTask.getEnrollType());
  402. }};
  403. classService.save(baseClass);
  404. BaseClassMajorSet majorSet = new BaseClassMajorSet() {{
  405. setCreateDate(createDate);
  406. setMajorSetId(taskClass.getMajorSetId());
  407. setClassId(baseClass.getId());
  408. setPlanTotalStudent(taskClass.getNumber());
  409. setTotalStudent(classTotal.get(taskClass.getId()));
  410. setBoyNum(classBoy.get(taskClass.getId()));
  411. setGirlNum(classGirl.get(taskClass.getId()));
  412. }};
  413. classMajorSetMapper.insert(majorSet);
  414. classMap.put(taskClass.getId(), baseClass.getId());
  415. taskClassMajorMap.put(taskClass.getId(), taskClass.getMajorSetId());
  416. }
  417. /**
  418. * 新增学生数据
  419. * 1、新增用户xjr_user
  420. * 2、新增用户与角色的关系xjr_user_role_relation
  421. * 3、新增学生基本信息base_student
  422. * 4、新增学籍信息表base_student_school_roll
  423. * 5、新增家庭信息表base_student_family
  424. */
  425. LocalDateTime now = LocalDateTime.now();
  426. Map<Long, Long> studentClassRelation = classStudents.stream().collect(Collectors.toMap(BandingTaskClassStudent::getNewStudentId, BandingTaskClassStudent::getBandingTaskClassId));
  427. for (BaseNewStudent student : updateList) {
  428. LocalDateTime birthDate = getBirthDate(student.getCredentialNumber());
  429. User xjrUser = new User() {{
  430. setCreateDate(now);
  431. setPassword(BCrypt.hashpw(propertiesConfig.getDefaultPassword(), BCrypt.gensalt()));
  432. setName(student.getName());
  433. setUserName(student.getCredentialNumber());
  434. setCredentialNumber(student.getCredentialNumber());
  435. setCredentialType("ZZLS10007");
  436. setMobile(student.getMobile());
  437. setEnabledMark(EnabledMark.DISABLED.getCode());
  438. setGender(student.getGender());
  439. setIsChangePassword(1);
  440. setBirthDate(birthDate);
  441. }};
  442. userService.save(xjrUser);
  443. UserRoleRelation userRoleRelation = new UserRoleRelation() {{
  444. setRoleId(RoleEnum.STUDENT.getCode());
  445. setUserId(xjrUser.getId());
  446. }};
  447. roleRelationService.save(userRoleRelation);
  448. BaseStudent baseStudent = new BaseStudent() {{
  449. setUserId(xjrUser.getId());
  450. setCreateDate(now);
  451. setStudentId(student.getCredentialNumber());
  452. setHeight(student.getHeight().doubleValue());
  453. setWeight(student.getWeight().doubleValue());
  454. }};
  455. studentService.save(baseStudent);
  456. BaseStudentSchoolRoll schoolRoll = new BaseStudentSchoolRoll() {{
  457. setUserId(xjrUser.getId());
  458. setGraduatedScore(student.getScore().doubleValue());
  459. setGraduatedUniversity(student.getGraduateSchool());
  460. setClassId(classMap.get(studentClassRelation.get(student.getId())));
  461. setMajorSetId(taskClassMajorMap.get(studentClassRelation.get(student.getId())));
  462. setStduyStatus(student.getStduyStatus());
  463. setEnrollType(bandingTask.getEnrollType());
  464. setStudentSource(student.getSource());
  465. setGradeId(bandingTask.getGradeId());
  466. setArchivesStatus(ArchivesStatusEnum.FB2901.getCode());
  467. setCreateDate(now);
  468. }};
  469. schoolRollService.save(schoolRoll);
  470. BaseStudentFamily studentFamily = new BaseStudentFamily() {{
  471. setCreateDate(now);
  472. setUserId(xjrUser.getId());
  473. setTelephone(student.getFamilyMobile());
  474. setAddress(student.getFamilyAddress());
  475. }};
  476. familyService.save(studentFamily);
  477. }
  478. }
  479. LocalDateTime getBirthDate(String idCardNumber){
  480. // 获取出生日期前6位,即yyyyMM
  481. String birthdayString = idCardNumber.substring(6, 14);
  482. // 将字符串解析为LocalDate对象
  483. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
  484. return LocalDateTime.parse(birthdayString, formatter);
  485. }
  486. }