BandingTaskServiceImpl.java 27 KB

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