浏览代码

新生数据同步自动同步

dzx 9 月之前
父节点
当前提交
6e3d321813

+ 12 - 3
src/main/java/com/xjrsoft/common/enums/StudentTypeEnum.java

@@ -10,11 +10,11 @@ import java.util.Map;
  * @Version 1.0
  */
 public enum StudentTypeEnum {
-    FB2801("FB2801", "普惠制学生"),
+    FB2801("FB2801", "普通学生(非贫困)"),
 
-    FB2802("FB2802", "建卡、低保、特困学生"),
+    FB2802("FB2802", "贫困生(建卡、低保、特困)"),
 
-    FB2803("FB2803", "其他贫困学生");
+    FB2803("FB2803", "其他类型贫困");
 
     final String code;
     final String value;
@@ -43,4 +43,13 @@ public enum StudentTypeEnum {
     public static String fromCode(String code) {
         return lookup.get(code);
     }
+
+    public static String getCode(String value) {
+        for (StudentTypeEnum item : values()) {
+            if (item.getValue().equals(value)) {
+                return  item.getCode();
+            }
+        }
+        return null;
+    }
 }

+ 9 - 0
src/main/java/com/xjrsoft/common/enums/StudyStatusEnum.java

@@ -57,4 +57,13 @@ public enum StudyStatusEnum {
     public static String fromCode(String code) {
         return lookup.get(code);
     }
+
+    public static String getCode(String value) {
+        for (StudyStatusEnum item : values()) {
+            if (item.getValue().equals(value)) {
+                return  item.getCode();
+            }
+        }
+        return null;
+    }
 }

+ 9 - 8
src/main/java/com/xjrsoft/module/job/BaseNewStudentTask.java

@@ -119,6 +119,7 @@ public class BaseNewStudentTask {
                         .eq(BaseMajorSet::getEnabledMark, EnabledMark.ENABLED.getCode())
         );
         Map<String, Long> majorSetMap = majorSetList.stream().collect(Collectors.toMap(BaseMajorSet::getCode, BaseMajorSet::getId));
+        Map<String, Long> majorSetNameMap = majorSetList.stream().collect(Collectors.toMap(BaseMajorSet::getName, BaseMajorSet::getId));
 
         //循环攀宝的数据,准备更新到新生表中
         List<BaseNewStudent> updateList = new ArrayList<>();
@@ -136,15 +137,15 @@ public class BaseNewStudentTask {
                 existsNewStudent.setHeight(BigDecimal.valueOf(Double.parseDouble(feeobjupdate.getSg())));
                 existsNewStudent.setWeight(BigDecimal.valueOf(Double.parseDouble(feeobjupdate.getTz())));
                 existsNewStudent.setGraduateSchool(feeobjupdate.getGraduations());
-                existsNewStudent.setStduyStatus(StudyStatusEnum.fromCode(feeobjupdate.getQuartername()));
-                existsNewStudent.setSource(StudentTypeEnum.fromCode(feeobjupdate.getResourcename()));
+                existsNewStudent.setStduyStatus(StudyStatusEnum.getCode(feeobjupdate.getQuartername()));
+                existsNewStudent.setSource(StudentTypeEnum.getCode(feeobjupdate.getResourcename()));
                 existsNewStudent.setMobile(feeobjupdate.getTelephone());
                 existsNewStudent.setFamilyMobile(feeobjupdate.getJzlxdh());
                 existsNewStudent.setFamilyAddress(feeobjupdate.getAddress());
                 existsNewStudent.setFirstAmbition(majorSetMap.get(feeobjupdate.getSpeccode()));
                 existsNewStudent.setFirstAmbitionId(majorSetMap.get(feeobjupdate.getSpeccode()));
-                existsNewStudent.setSecondAmbition(majorSetMap.get(feeobjupdate.getZytjspec()));
-                existsNewStudent.setSecondAmbitionId(majorSetMap.get(feeobjupdate.getZytjspec()));
+                existsNewStudent.setSecondAmbition(majorSetNameMap.get(feeobjupdate.getZytjspec()));
+                existsNewStudent.setSecondAmbitionId(majorSetNameMap.get(feeobjupdate.getZytjspec()));
                 existsNewStudent.setGender(GenderDictionaryEnum.getCode(feeobjupdate.getSex()));
                 existsNewStudent.setModifyDate(new Date());
 
@@ -165,15 +166,15 @@ public class BaseNewStudentTask {
                         setHeight(BigDecimal.valueOf(Double.parseDouble(feeobjupdate.getSg())));
                         setWeight(BigDecimal.valueOf(Double.parseDouble(feeobjupdate.getTz())));
                         setGraduateSchool(feeobjupdate.getGraduations());
-                        setStduyStatus(StudyStatusEnum.fromCode(feeobjupdate.getQuartername()));
-                        setSource(StudentTypeEnum.fromCode(feeobjupdate.getResourcename()));
+                        setStduyStatus(StudyStatusEnum.getCode(feeobjupdate.getQuartername()));
+                        setSource(StudentTypeEnum.getCode(feeobjupdate.getResourcename()));
                         setMobile(feeobjupdate.getTelephone());
                         setFamilyMobile(feeobjupdate.getJzlxdh());
                         setFamilyAddress(feeobjupdate.getAddress());
                         setFirstAmbition(majorSetMap.get(feeobjupdate.getSpeccode()));
                         setFirstAmbitionId(majorSetMap.get(feeobjupdate.getSpeccode()));
-                        setSecondAmbition(majorSetMap.get(feeobjupdate.getZytjspec()));
-                        setSecondAmbitionId(majorSetMap.get(feeobjupdate.getZytjspec()));
+                        setSecondAmbition(majorSetNameMap.get(feeobjupdate.getZytjspec()));
+                        setSecondAmbitionId(majorSetNameMap.get(feeobjupdate.getZytjspec()));
                         setGender(GenderDictionaryEnum.getCode(feeobjupdate.getSex()));
                         setEnrollmentPlanId(planId);
                         setCreateDate(new Date());

+ 196 - 0
src/test/java/com/xjrsoft/module/job/BaseNewStudentTaskTest.java

@@ -0,0 +1,196 @@
+package com.xjrsoft.module.job;
+
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.xjrsoft.XjrSoftApplication;
+import com.xjrsoft.common.enums.DeleteMark;
+import com.xjrsoft.common.enums.EnabledMark;
+import com.xjrsoft.common.enums.EnrollTypeEnum;
+import com.xjrsoft.common.enums.GenderDictionaryEnum;
+import com.xjrsoft.common.enums.StudentTypeEnum;
+import com.xjrsoft.common.enums.StudyStatusEnum;
+import com.xjrsoft.module.base.entity.BaseGrade;
+import com.xjrsoft.module.base.entity.BaseMajorSet;
+import com.xjrsoft.module.base.service.IBaseGradeService;
+import com.xjrsoft.module.base.service.IBaseMajorSetService;
+import com.xjrsoft.module.student.entity.BaseNewStudent;
+import com.xjrsoft.module.student.entity.EnrollmentPlan;
+import com.xjrsoft.module.student.entity.PbCseFeeobjupdate;
+import com.xjrsoft.module.student.service.IBaseNewStudentService;
+import com.xjrsoft.module.student.service.IEnrollmentPlanService;
+import com.xjrsoft.module.student.service.IPbCseFeeobjupdateService;
+import org.junit.jupiter.api.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+/**
+ * @author dzx
+ * @date 2025/3/4
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = XjrSoftApplication.class)
+class BaseNewStudentTaskTest {
+
+
+    @Autowired
+    private IBaseNewStudentService newStudentService;
+
+    @Autowired
+    private IPbCseFeeobjupdateService cseFeeobjupdateService;
+
+    @Autowired
+    private IEnrollmentPlanService planService;
+
+    @Autowired
+    private IBaseGradeService gradeService;
+
+    @Autowired
+    private IBaseMajorSetService majorSetService;
+
+    @Test
+    public void execute(){
+        doExecute();
+    }
+
+    void doExecute(){
+        List<PbCseFeeobjupdate> dataList = cseFeeobjupdateService.list();
+        Map<String, String> gradeMap = dataList.stream().filter(x -> StrUtil.isNotEmpty(x.getEnteryear()) && StrUtil.isNotEmpty(x.getUserdef6()))
+                .collect(Collectors.toMap(PbCseFeeobjupdate::getEnteryear, PbCseFeeobjupdate::getUserdef6));
+
+        List<EnrollmentPlan> planDataList = planService.list(
+                new QueryWrapper<EnrollmentPlan>().lambda()
+                        .eq(EnrollmentPlan::getDeleteMark, DeleteMark.NODELETE.getCode())
+                        .eq(EnrollmentPlan::getEnabledMark, EnabledMark.ENABLED.getCode())
+        );
+        Map<String, Long> planDataMap = planDataList.stream().collect(Collectors.toMap(x -> x.getEnrollType() + x.getGradeId(), EnrollmentPlan::getId));
+
+        Map<String, Long> planMap = new HashMap<>();
+        //插入招生计划数据
+        gradeMap.forEach((enteryear, userdef6)->{
+            EnrollmentPlan plan = new EnrollmentPlan();
+            plan.setCreateDate(new Date());
+            plan.setEnabledMark(EnabledMark.ENABLED.getCode());
+            plan.setDeleteMark(DeleteMark.NODELETE.getCode());
+            if("1".equals(userdef6)){
+                plan.setEnrollType(EnrollTypeEnum.SPRING_ENROLLMENT.getCode());
+            }else if("2".equals(userdef6)){
+                plan.setEnrollType(EnrollTypeEnum.AUTUMN_ENROLLMENT.getCode());
+            }
+
+            //查询年级
+            BaseGrade grade = gradeService.getOne(
+                    new QueryWrapper<BaseGrade>().lambda()
+                            .eq(BaseGrade::getDeleteMark, DeleteMark.NODELETE.getCode())
+                            .like(BaseGrade::getTitle, enteryear)
+            );
+            plan.setGradeId(grade.getId());
+
+            Long oldPlanId = planDataMap.get(plan.getEnrollType() + plan.getGradeId());
+
+            planMap.put(enteryear + userdef6, oldPlanId);
+
+            //判断是否已经存在,不存在就新增
+            if(oldPlanId == null){
+                planService.save(plan);
+                planMap.put(enteryear + userdef6, plan.getId());
+            }
+        });
+
+        //查询已存在的新生信息
+        List<BaseNewStudent> existsNewStudentList = newStudentService.list(
+                new QueryWrapper<BaseNewStudent>().lambda()
+                        .eq(BaseNewStudent::getDeleteMark, DeleteMark.NODELETE.getCode())
+        );
+        Map<String, BaseNewStudent> existsNewStudentMap = existsNewStudentList.stream().filter(x -> StrUtil.isEmpty(x.getDeleteReason())).collect(Collectors.toMap(BaseNewStudent::getCredentialNumber, x -> x));
+
+        List<BaseMajorSet> majorSetList = majorSetService.list(
+                new QueryWrapper<BaseMajorSet>().lambda()
+                        .eq(BaseMajorSet::getDeleteMark, DeleteMark.NODELETE.getCode())
+                        .eq(BaseMajorSet::getEnabledMark, EnabledMark.ENABLED.getCode())
+        );
+        Map<String, Long> majorSetMap = majorSetList.stream().collect(Collectors.toMap(BaseMajorSet::getCode, BaseMajorSet::getId));
+
+        //循环攀宝的数据,准备更新到新生表中
+        List<BaseNewStudent> updateList = new ArrayList<>();
+        List<BaseNewStudent> insertList = new ArrayList<>();
+        for (PbCseFeeobjupdate feeobjupdate : dataList) {
+            BaseNewStudent existsNewStudent = existsNewStudentMap.get(feeobjupdate.getPersonalid());
+
+            if(existsNewStudent != null){
+                existsNewStudent.setName(feeobjupdate.getFeeobjname());
+                existsNewStudent.setPaymnystate(feeobjupdate.getPaymnystate());
+                existsNewStudent.setPrevious(feeobjupdate.getPrevious());
+                existsNewStudent.setProvince(feeobjupdate.getProvince());
+                existsNewStudent.setCity(feeobjupdate.getCity());
+                existsNewStudent.setMyarea(feeobjupdate.getMyarea());
+                existsNewStudent.setHeight(BigDecimal.valueOf(Double.parseDouble(feeobjupdate.getSg())));
+                existsNewStudent.setWeight(BigDecimal.valueOf(Double.parseDouble(feeobjupdate.getTz())));
+                existsNewStudent.setGraduateSchool(feeobjupdate.getGraduations());
+                existsNewStudent.setStduyStatus(StudyStatusEnum.getCode(feeobjupdate.getQuartername()));
+                existsNewStudent.setSource(StudentTypeEnum.getCode(feeobjupdate.getResourcename()));
+                existsNewStudent.setMobile(feeobjupdate.getTelephone());
+                existsNewStudent.setFamilyMobile(feeobjupdate.getJzlxdh());
+                existsNewStudent.setFamilyAddress(feeobjupdate.getAddress());
+                existsNewStudent.setFirstAmbition(majorSetMap.get(feeobjupdate.getSpeccode()));
+                existsNewStudent.setFirstAmbitionId(majorSetMap.get(feeobjupdate.getSpeccode()));
+                existsNewStudent.setSecondAmbition(majorSetMap.get(feeobjupdate.getZytjspec()));
+                existsNewStudent.setSecondAmbitionId(majorSetMap.get(feeobjupdate.getZytjspec()));
+                existsNewStudent.setGender(GenderDictionaryEnum.getCode(feeobjupdate.getSex()));
+                existsNewStudent.setModifyDate(new Date());
+
+                updateList.add(existsNewStudent);
+                continue;
+            }
+
+            Long planId = planMap.get(feeobjupdate.getEnteryear() + feeobjupdate.getUserdef6());
+            insertList.add(
+                    new BaseNewStudent(){{
+                        setCredentialNumber(feeobjupdate.getPersonalid());
+                        setName(feeobjupdate.getFeeobjname());
+                        setPaymnystate(feeobjupdate.getPaymnystate());
+                        setPrevious(feeobjupdate.getPrevious());
+                        setProvince(feeobjupdate.getProvince());
+                        setCity(feeobjupdate.getCity());
+                        setMyarea(feeobjupdate.getMyarea());
+                        setHeight(BigDecimal.valueOf(Double.parseDouble(feeobjupdate.getSg())));
+                        setWeight(BigDecimal.valueOf(Double.parseDouble(feeobjupdate.getTz())));
+                        setGraduateSchool(feeobjupdate.getGraduations());
+                        setStduyStatus(StudyStatusEnum.getCode(feeobjupdate.getQuartername()));
+                        setSource(StudentTypeEnum.getCode(feeobjupdate.getResourcename()));
+                        setMobile(feeobjupdate.getTelephone());
+                        setFamilyMobile(feeobjupdate.getJzlxdh());
+                        setFamilyAddress(feeobjupdate.getAddress());
+                        setFirstAmbition(majorSetMap.get(feeobjupdate.getSpeccode()));
+                        setFirstAmbitionId(majorSetMap.get(feeobjupdate.getSpeccode()));
+                        setSecondAmbition(majorSetMap.get(feeobjupdate.getZytjspec()));
+                        setSecondAmbitionId(majorSetMap.get(feeobjupdate.getZytjspec()));
+                        setGender(GenderDictionaryEnum.getCode(feeobjupdate.getSex()));
+                        setEnrollmentPlanId(planId);
+                        setCreateDate(new Date());
+                    }}
+            );
+        }
+
+        if(!updateList.isEmpty()){
+            newStudentService.updateBatchById(updateList);
+        }
+        if(!insertList.isEmpty()){
+            newStudentService.saveBatch(insertList);
+        }
+
+    }
+
+}