BaseNewStudentTaskTest.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. package com.xjrsoft.module.job;
  2. import cn.dev33.satoken.stp.StpUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.xjrsoft.XjrSoftApplication;
  6. import com.xjrsoft.common.enums.DeleteMark;
  7. import com.xjrsoft.common.enums.EnabledMark;
  8. import com.xjrsoft.common.enums.EnrollTypeEnum;
  9. import com.xjrsoft.common.enums.GenderDictionaryEnum;
  10. import com.xjrsoft.common.enums.StudentTypeEnum;
  11. import com.xjrsoft.common.enums.StudyStatusEnum;
  12. import com.xjrsoft.common.mybatis.SqlRunnerAdapter;
  13. import com.xjrsoft.module.base.entity.BaseGrade;
  14. import com.xjrsoft.module.base.entity.BaseMajorSet;
  15. import com.xjrsoft.module.base.service.IBaseGradeService;
  16. import com.xjrsoft.module.base.service.IBaseMajorSetService;
  17. import com.xjrsoft.module.student.entity.BaseNewStudent;
  18. import com.xjrsoft.module.student.entity.EnrollmentPlan;
  19. import com.xjrsoft.module.student.entity.PbCseFeeobjupdate;
  20. import com.xjrsoft.module.student.service.IBaseNewStudentService;
  21. import com.xjrsoft.module.student.service.IEnrollmentPlanService;
  22. import com.xjrsoft.module.student.service.IPbCseFeeobjupdateService;
  23. import org.apache.commons.lang.StringUtils;
  24. import org.junit.jupiter.api.AfterEach;
  25. import org.junit.jupiter.api.BeforeEach;
  26. import org.junit.jupiter.api.Test;
  27. import org.junit.runner.RunWith;
  28. import org.springframework.beans.factory.annotation.Autowired;
  29. import org.springframework.boot.test.context.SpringBootTest;
  30. import org.springframework.scheduling.annotation.Scheduled;
  31. import org.springframework.test.context.junit4.SpringRunner;
  32. import java.math.BigDecimal;
  33. import java.util.ArrayList;
  34. import java.util.Date;
  35. import java.util.HashMap;
  36. import java.util.HashSet;
  37. import java.util.List;
  38. import java.util.Map;
  39. import java.util.Set;
  40. import java.util.stream.Collectors;
  41. import static org.junit.jupiter.api.Assertions.*;
  42. /**
  43. * @author dzx
  44. * @date 2025/3/4
  45. */
  46. @RunWith(SpringRunner.class)
  47. @SpringBootTest(classes = XjrSoftApplication.class)
  48. class BaseNewStudentTaskTest {
  49. @Autowired
  50. private IBaseNewStudentService newStudentService;
  51. @Autowired
  52. private IPbCseFeeobjupdateService cseFeeobjupdateService;
  53. @Autowired
  54. private IEnrollmentPlanService planService;
  55. @Autowired
  56. private IBaseGradeService gradeService;
  57. @Autowired
  58. private IBaseMajorSetService majorSetService;
  59. @BeforeEach
  60. void setUp() {
  61. // 模拟用户登录
  62. StpUtil.login(1000000000000000000L); // 假设用户ID为1
  63. }
  64. @AfterEach
  65. void tearDown() {
  66. // 清理会话
  67. StpUtil.logout();
  68. }
  69. @Test
  70. public void execute(){
  71. doExecute();
  72. }
  73. void doExecute() {
  74. List<PbCseFeeobjupdate> dataList = cseFeeobjupdateService.list();
  75. String sql = "select distinct enteryear, userdef6 from pb_cse_feeobjupdate";
  76. List<Map<String, Object>> gradeList = SqlRunnerAdapter.db().selectList(sql);
  77. List<EnrollmentPlan> planDataList = planService.list(
  78. new QueryWrapper<EnrollmentPlan>().lambda()
  79. .eq(EnrollmentPlan::getDeleteMark, DeleteMark.NODELETE.getCode())
  80. .eq(EnrollmentPlan::getEnabledMark, EnabledMark.ENABLED.getCode())
  81. );
  82. Map<String, Long> planDataMap = planDataList.stream().collect(Collectors.toMap(x -> x.getEnrollType() + x.getGradeId(), EnrollmentPlan::getId));
  83. Map<String, Long> planMap = new HashMap<>();
  84. //插入招生计划数据
  85. gradeList.forEach((x) -> {
  86. EnrollmentPlan plan = new EnrollmentPlan();
  87. plan.setCreateDate(new Date());
  88. plan.setEnabledMark(EnabledMark.ENABLED.getCode());
  89. plan.setDeleteMark(DeleteMark.NODELETE.getCode());
  90. if ("1".equals(x.get("userdef6").toString())) {
  91. plan.setEnrollType(EnrollTypeEnum.SPRING_ENROLLMENT.getCode());
  92. } else if ("2".equals(x.get("userdef6").toString())) {
  93. plan.setEnrollType(EnrollTypeEnum.AUTUMN_ENROLLMENT.getCode());
  94. }
  95. //查询年级
  96. BaseGrade grade = gradeService.getOne(
  97. new QueryWrapper<BaseGrade>().lambda()
  98. .eq(BaseGrade::getDeleteMark, DeleteMark.NODELETE.getCode())
  99. .like(BaseGrade::getTitle, x.get("enteryear").toString())
  100. );
  101. plan.setGradeId(grade.getId());
  102. Long oldPlanId = planDataMap.get(plan.getEnrollType() + plan.getGradeId());
  103. planMap.put(x.get("enteryear").toString() + x.get("userdef6").toString(), oldPlanId);
  104. //判断是否已经存在,不存在就新增
  105. if (oldPlanId == null) {
  106. planService.save(plan);
  107. planMap.put(x.get("enteryear").toString() + x.get("userdef6").toString(), plan.getId());
  108. }
  109. });
  110. //查询已存在的新生信息
  111. List<BaseNewStudent> existsNewStudentList = newStudentService.list(
  112. new QueryWrapper<BaseNewStudent>().lambda()
  113. .eq(BaseNewStudent::getDeleteMark, DeleteMark.NODELETE.getCode())
  114. );
  115. Map<String, BaseNewStudent> existsNewStudentMap = existsNewStudentList.stream().filter(x -> StrUtil.isEmpty(x.getDeleteReason())).collect(Collectors.toMap(BaseNewStudent::getCredentialNumber, x -> x));
  116. List<BaseMajorSet> majorSetList = majorSetService.list(
  117. new QueryWrapper<BaseMajorSet>().lambda()
  118. .eq(BaseMajorSet::getDeleteMark, DeleteMark.NODELETE.getCode())
  119. .eq(BaseMajorSet::getEnabledMark, EnabledMark.ENABLED.getCode())
  120. );
  121. Map<String, Long> majorSetNameMap = majorSetList.stream().collect(Collectors.toMap(BaseMajorSet::getName, BaseMajorSet::getId));
  122. Set<String> insCredentialNumber = new HashSet<>();
  123. //循环攀宝的数据,准备更新到新生表中
  124. List<BaseNewStudent> updateList = new ArrayList<>();
  125. List<BaseNewStudent> insertList = new ArrayList<>();
  126. for (PbCseFeeobjupdate feeobjupdate : dataList) {
  127. BaseNewStudent existsNewStudent = existsNewStudentMap.get(feeobjupdate.getPersonalid());
  128. Long planId = planMap.get(feeobjupdate.getEnteryear() + feeobjupdate.getUserdef6());
  129. if (existsNewStudent != null) {
  130. existsNewStudent.setName(feeobjupdate.getFeeobjname());
  131. existsNewStudent.setPaymnystate(feeobjupdate.getPaymnystate());
  132. existsNewStudent.setPrevious(feeobjupdate.getPrevious());
  133. existsNewStudent.setProvince(feeobjupdate.getProvince());
  134. existsNewStudent.setCity(feeobjupdate.getCity());
  135. existsNewStudent.setMyarea(feeobjupdate.getMyarea());
  136. if (StrUtil.isNotEmpty(feeobjupdate.getSg())) {
  137. if (StringUtils.isNumeric(feeobjupdate.getSg())) {
  138. existsNewStudent.setHeight(BigDecimal.valueOf(Double.parseDouble(feeobjupdate.getSg())));
  139. }
  140. }
  141. if (StrUtil.isNotEmpty(feeobjupdate.getTz())) {
  142. if (StringUtils.isNumeric(feeobjupdate.getTz())) {
  143. existsNewStudent.setWeight(BigDecimal.valueOf(Double.parseDouble(feeobjupdate.getTz())));
  144. }
  145. }
  146. existsNewStudent.setGraduateSchool(feeobjupdate.getGraduations());
  147. existsNewStudent.setGraduateClass(feeobjupdate.getGradclass());
  148. existsNewStudent.setStduyStatus(StudyStatusEnum.getCode(feeobjupdate.getQuartername()));
  149. existsNewStudent.setSource(StudentTypeEnum.getCode(feeobjupdate.getResourcename()));
  150. existsNewStudent.setMobile(feeobjupdate.getTelephone());
  151. existsNewStudent.setFamilyMobile(feeobjupdate.getJzlxdh());
  152. existsNewStudent.setFamilyAddress(feeobjupdate.getAddress());
  153. existsNewStudent.setFirstAmbition(majorSetNameMap.get(feeobjupdate.getSpecname()));
  154. existsNewStudent.setFirstAmbitionId(majorSetNameMap.get(feeobjupdate.getSpecname()));
  155. existsNewStudent.setSecondAmbition(majorSetNameMap.get(feeobjupdate.getZytjspec()));
  156. existsNewStudent.setSecondAmbitionId(majorSetNameMap.get(feeobjupdate.getZytjspec()));
  157. existsNewStudent.setGender(GenderDictionaryEnum.getCode(feeobjupdate.getSex()));
  158. existsNewStudent.setModifyDate(new Date());
  159. existsNewStudent.setStatus(0);
  160. existsNewStudent.setIsCanBanding(1);
  161. existsNewStudent.setEnrollmentPlanId(planId);
  162. updateList.add(existsNewStudent);
  163. continue;
  164. }
  165. insertList.add(
  166. new BaseNewStudent() {{
  167. setCredentialNumber(feeobjupdate.getPersonalid());
  168. setName(feeobjupdate.getFeeobjname());
  169. setPaymnystate(feeobjupdate.getPaymnystate());
  170. setPrevious(feeobjupdate.getPrevious());
  171. setProvince(feeobjupdate.getProvince());
  172. setCity(feeobjupdate.getCity());
  173. setMyarea(feeobjupdate.getMyarea());
  174. if (StrUtil.isNotEmpty(feeobjupdate.getSg())) {
  175. if (StringUtils.isNumeric(feeobjupdate.getSg())) {
  176. setHeight(BigDecimal.valueOf(Double.parseDouble(feeobjupdate.getSg())));
  177. }
  178. }
  179. if (StrUtil.isNotEmpty(feeobjupdate.getTz())) {
  180. if (StringUtils.isNumeric(feeobjupdate.getTz())) {
  181. setWeight(BigDecimal.valueOf(Double.parseDouble(feeobjupdate.getTz())));
  182. }
  183. }
  184. setGraduateSchool(feeobjupdate.getGraduations());
  185. setGraduateClass(feeobjupdate.getGradclass());
  186. setStduyStatus(StudyStatusEnum.getCode(feeobjupdate.getQuartername()));
  187. setSource(StudentTypeEnum.getCode(feeobjupdate.getResourcename()));
  188. setMobile(feeobjupdate.getTelephone());
  189. setFamilyMobile(feeobjupdate.getJzlxdh());
  190. setFamilyAddress(feeobjupdate.getAddress());
  191. setFirstAmbition(majorSetNameMap.get(feeobjupdate.getSpecname()));
  192. setFirstAmbitionId(majorSetNameMap.get(feeobjupdate.getSpecname()));
  193. setSecondAmbition(majorSetNameMap.get(feeobjupdate.getZytjspec()));
  194. setSecondAmbitionId(majorSetNameMap.get(feeobjupdate.getZytjspec()));
  195. setGender(GenderDictionaryEnum.getCode(feeobjupdate.getSex()));
  196. setEnrollmentPlanId(planId);
  197. setCreateDate(new Date());
  198. setStatus(0);
  199. setIsCanBanding(1);
  200. }}
  201. );
  202. }
  203. if (!updateList.isEmpty()) {
  204. newStudentService.updateBatchById(updateList);
  205. }
  206. if (!insertList.isEmpty()) {
  207. newStudentService.saveBatch(insertList);
  208. }
  209. }
  210. }