5
0

3 Incheckningar decf5ab0fc ... 535591e761

Upphovsman SHA1 Meddelande Datum
  大数据与最优化研究所 535591e761 新生数据处理 3 månader sedan
  大数据与最优化研究所 d372bac6cb 新生数据处理 3 månader sedan
  大数据与最优化研究所 38f49f1cb5 新生数据处理 3 månader sedan

+ 1 - 1
src/main/java/com/xjrsoft/module/organization/controller/UserController.java

@@ -190,7 +190,7 @@ public class UserController {
                     .eq(ObjectUtil.isNotNull(dto.getEmployWay()), BaseTeacher::getEmployWay, dto.getEmployWay())
                     .eq(ObjectUtil.isNotNull(dto.getClassId()), BaseStudentSchoolRoll::getClassId, dto.getClassId())
                     .eq(ObjectUtil.isNotNull(dto.getRoleId()), UserRoleRelation::getRoleId, dto.getRoleId())
-                    .eq(ObjectUtil.isNotNull(dto.getIsTeach()), BaseTeacherRegular::getIsTeach, dto.getIsTeach())
+                    .eq(ObjectUtils.isNotEmpty(dto.getIsTeach()), BaseTeacherRegular::getIsTeach, dto.getIsTeach())
                     .orderByDesc(User::getId)
                     .select(User::getId)
                     .select("d1.name", UserPageVo::getEmployWay)

+ 285 - 0
src/test/java/com/xjrsoft/module/student/service/impl/StudentReportRecordServiceImplTest.java

@@ -1,10 +1,64 @@
 package com.xjrsoft.module.student.service.impl;
 
+import cn.dev33.satoken.secure.BCrypt;
+import cn.dev33.satoken.stp.StpUtil;
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.util.NumberUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
+import com.xjrsoft.common.constant.GlobalConstant;
+import com.xjrsoft.common.enums.ArchivesStatusEnum;
+import com.xjrsoft.common.enums.DeleteMark;
+import com.xjrsoft.common.enums.EnabledMark;
+import com.xjrsoft.common.enums.RoleEnum;
 import com.xjrsoft.common.exception.MyException;
+import com.xjrsoft.common.utils.LocalDateTimeUtil;
 import com.xjrsoft.common.utils.LocalDateUtil;
+import com.xjrsoft.common.utils.RedisUtil;
+import com.xjrsoft.common.utils.VoToColumnUtil;
+import com.xjrsoft.config.CommonPropertiesConfig;
+import com.xjrsoft.module.banding.entity.BandingTask;
+import com.xjrsoft.module.banding.entity.BandingTaskClass;
+import com.xjrsoft.module.banding.entity.BandingTaskClassStudent;
+import com.xjrsoft.module.banding.entity.BandingTaskClassStudentSure;
+import com.xjrsoft.module.banding.service.IBandingTaskClassService;
+import com.xjrsoft.module.banding.service.IBandingTaskClassStudentService;
+import com.xjrsoft.module.banding.service.IBandingTaskService;
+import com.xjrsoft.module.base.entity.BaseClass;
+import com.xjrsoft.module.base.entity.BaseGrade;
+import com.xjrsoft.module.base.entity.BaseMajorSet;
+import com.xjrsoft.module.base.mapper.BaseClassMapper;
+import com.xjrsoft.module.base.mapper.BaseGradeMapper;
+import com.xjrsoft.module.base.mapper.BaseMajorSetMapper;
+import com.xjrsoft.module.organization.entity.User;
+import com.xjrsoft.module.organization.entity.UserRoleRelation;
+import com.xjrsoft.module.organization.service.IUserRoleRelationService;
+import com.xjrsoft.module.organization.service.IUserService;
+import com.xjrsoft.module.personnel.service.IStundentFaceProcessService;
+import com.xjrsoft.module.student.entity.*;
+import com.xjrsoft.module.student.mapper.BaseNewStudentMapper;
+import com.xjrsoft.module.student.mapper.StudentReportPlanMapper;
+import com.xjrsoft.module.student.service.*;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.stream.Collectors;
 
 import static org.junit.jupiter.api.Assertions.*;
 
@@ -12,8 +66,58 @@ import static org.junit.jupiter.api.Assertions.*;
  * @author dzx
  * @date 2025/2/11
  */
+@SpringBootTest
 class StudentReportRecordServiceImplTest {
 
+    @Autowired
+    private BaseNewStudentMapper newStudentMapper;
+
+    @Autowired
+    private IBandingTaskClassService taskClassService;
+
+    @Autowired
+    private BaseClassMapper classMapper;;
+
+    @Autowired
+    private IBaseStudentService studentService;
+
+    @Autowired
+    private IUserService userService;
+
+    @Autowired
+    private IBaseStudentSchoolRollService rollService;
+
+    @Autowired
+    private IUserRoleRelationService roleRelationService;
+
+    @Autowired
+    private IBaseStudentFamilyService familyService;
+
+    @Autowired
+    private RedisUtil redisUtil;
+
+    @Autowired
+    private IBandingTaskService taskService;
+
+    @Autowired
+    private BaseGradeMapper gradeMapper;
+
+    @Autowired
+    private BaseMajorSetMapper majorSetMapper;
+
+
+    @BeforeEach
+    void setUp() {
+        // 模拟用户登录
+        StpUtil.login(1000000000000000000L); // 假设用户ID为1
+    }
+
+    @AfterEach
+    void tearDown() {
+        // 清理会话
+        StpUtil.logout();
+    }
+
     @Test
     void Test(){
         LocalDate startDate = LocalDate.of(2024, 2, 11);
@@ -27,4 +131,185 @@ class StudentReportRecordServiceImplTest {
         }
     }
 
+    @Test
+    void tryReadingSign() {
+        LocalDateTime now = LocalDateTime.now();
+        // 查出所有有分班存在的新生信息
+        MPJLambdaWrapper<BaseNewStudent> baseNewStudentMPJLambdaWrapper = new MPJLambdaWrapper<>();
+        baseNewStudentMPJLambdaWrapper
+                .select(BaseNewStudent::getId)
+                .select(BaseNewStudent.class, x -> VoToColumnUtil.fieldsToColumns(BaseNewStudent.class).contains(x.getProperty()))
+                .innerJoin(BandingTaskClassStudent.class, BandingTaskClassStudent::getNewStudentId, BaseNewStudent::getId)
+                .innerJoin(BandingTaskClass.class, BandingTaskClass::getId, BandingTaskClassStudent::getBandingTaskClassId)
+                .innerJoin(BandingTask.class, BandingTask::getId, BandingTaskClass::getBandingTaskId)
+                .eq(BandingTask::getGradeId, 1868532405673439232L)
+                .isNotNull(BandingTaskClassStudent::getBandingTaskClassId)
+                ;
+        List<BaseNewStudent> baseNewStudents =  newStudentMapper.selectJoinList(BaseNewStudent.class, baseNewStudentMPJLambdaWrapper);
+
+        // 进行学生数据处理,学生信息已经存在的要修改学生班级数据
+        for(BaseNewStudent student : baseNewStudents){
+            BandingTaskClass taskClass = taskClassService.getOne(
+                    new MPJLambdaWrapper<BandingTaskClass>()
+                            .select(BandingTaskClass::getId)
+                            .select(BandingTaskClass.class, x -> VoToColumnUtil.fieldsToColumns(BandingTaskClass.class).contains(x.getProperty()))
+                            .innerJoin(BandingTaskClassStudent.class, BandingTaskClassStudent::getBandingTaskClassId, BandingTaskClass::getId)
+                            .eq(BandingTaskClassStudent::getNewStudentId, student.getId())
+                            .eq(BandingTaskClassStudent::getDeleteMark, DeleteMark.NODELETE.getCode())
+                            .eq(BandingTaskClassStudent::getEnabledMark, EnabledMark.ENABLED.getCode())
+                            .eq(BandingTaskClass::getDeleteMark, DeleteMark.NODELETE.getCode())
+                            .eq(BandingTaskClass::getEnabledMark, EnabledMark.ENABLED.getCode())
+            );
+
+            //先查询是否已经存在这个班级,如果存在就更新,不存在就新增
+            BaseClass baseClass = classMapper.selectById(taskClass.getBaseClassId());
+            if(ObjectUtils.isEmpty(baseClass)){
+                BandingTask task = taskService.getById(taskClass.getBandingTaskId());
+                List<BaseClass> classList = classMapper.selectList(
+                        new QueryWrapper<BaseClass>().lambda()
+                                .eq(BaseClass::getDeleteMark, DeleteMark.NODELETE.getCode())
+                                .eq(BaseClass::getGradeId, task.getGradeId())
+                                .eq(BaseClass::getEnrollType, task.getEnrollType())
+                );
+                BaseGrade baseGrade = gradeMapper.selectById(task.getGradeId());
+                List<BaseClass> classCodes = classList.stream().filter(x -> x.getCode() != null)
+                        .sorted(Comparator.comparing(BaseClass::getCode))
+                        .collect(Collectors.toList());
+
+                String classCode = null;
+                if(!classCodes.isEmpty()){
+                    classCode = classCodes.get(0).getCode();
+                }
+
+                baseClass = new BaseClass();
+                BeanUtil.copyProperties(taskClass, baseClass);
+                baseClass.setCreateDate(new Date());
+                baseClass.setCreateUserId(StpUtil.getLoginIdAsLong());
+                int i = 0;
+                if(NumberUtil.isNumber(classCode)){
+                    i = Integer.parseInt(classCode.trim().substring(classCode.length() - 3));
+                    i ++;
+                    baseClass.setCode(baseGrade.getTitle().replace("年", "") + String.format("%03d", i));
+                }
+                baseClass.setGradeId(task.getGradeId());
+                BaseMajorSet majorSet = majorSetMapper.selectById(baseClass.getMajorSetId());
+                baseClass.setOrgId(majorSet.getDepartmentId());
+                baseClass.setId(null);
+                classMapper.insert(baseClass);
+
+                taskClass.setBaseClassId(baseClass.getId());
+                taskClassService.updateById(taskClass);
+            }
+
+            //根据身份证号查询这个学生是否存在
+            User user = userService.getOne(
+                    new MPJLambdaWrapper<User>()
+                            .disableLogicDel()
+                            .select(User::getId)
+                            .select(User.class, x -> VoToColumnUtil.fieldsToColumns(User.class).contains(x.getProperty()))
+                            .eq(User::getCredentialNumber, student.getCredentialNumber())
+            );
+            if(ObjectUtils.isNotEmpty(user)){
+                // 学生已存在,则修改班级信息
+                rollService.updateStudentClass(baseClass.getId(), user.getId());
+
+                // 激活学生
+                rollService.activateStudent(user.getId());
+            }else{
+                LocalDate birthDate = getBirthDate(student.getCredentialNumber());
+                User xjrUser = new User() {{
+                    setCreateDate(now);
+                    // setPassword(BCrypt.hashpw(propertiesConfig.getDefaultPassword(), BCrypt.gensalt()));
+
+                    if (StringUtils.isEmpty(student.getCredentialNumber())) {
+                        throw new MyException(student.getName() + "证件号为空,请填写后提交");
+                    }
+                    String credentialNumber = student.getCredentialNumber();
+                    String lastSixDigits = credentialNumber.length() <= 6
+                            ? credentialNumber
+                            : credentialNumber.substring(credentialNumber.length() - 6);
+                    setPassword(BCrypt.hashpw(lastSixDigits, BCrypt.gensalt()));
+
+                    setName(student.getName());
+                    setUserName(student.getCredentialNumber());
+                    setCredentialNumber(student.getCredentialNumber());
+                    setCredentialType("ZZLS10007");
+                    setMobile(student.getMobile());
+                    setEnabledMark(EnabledMark.ENABLED.getCode());
+                    setGender(student.getGender());
+                    setIsChangePassword(1);
+                    setBirthDate(birthDate.atStartOfDay());
+                }};
+                userService.save(xjrUser);
+
+                UserRoleRelation userRoleRelation = new UserRoleRelation() {{
+                    setRoleId(RoleEnum.STUDENT.getCode());
+                    setUserId(xjrUser.getId());
+                }};
+                roleRelationService.save(userRoleRelation);
+
+                BaseStudent baseStudent = new BaseStudent() {{
+                    setUserId(xjrUser.getId());
+                    setCreateDate(now);
+                    setStudentId(student.getCredentialNumber());
+                    if(student.getHeight() != null){
+                        setHeight(student.getHeight().doubleValue());
+                    }
+                    if(student.getWeight() != null){
+                        setWeight(student.getWeight().doubleValue());
+                    }
+                    setIsNormal(1);
+                }};
+                studentService.save(baseStudent);
+
+                BaseStudentSchoolRoll schoolRoll = new BaseStudentSchoolRoll();
+                schoolRoll.setUserId(xjrUser.getId());
+                if(student.getScore() != null){
+                    schoolRoll.setGraduatedScore(student.getScore().doubleValue());
+                }
+                schoolRoll.setInternshipState("IT_0001");
+                schoolRoll.setGraduatedUniversity(student.getGraduateSchool());
+                schoolRoll.setClassId(baseClass.getId());
+                schoolRoll.setMajorSetId(baseClass.getMajorSetId());
+                schoolRoll.setStduyStatus(student.getStduyStatus());
+                schoolRoll.setDeleteMark(DeleteMark.NODELETE.getCode());
+                schoolRoll.setEnrollType(baseClass.getEnrollType());
+                schoolRoll.setStudentType(student.getSource());
+                schoolRoll.setGradeId(baseClass.getGradeId());
+                schoolRoll.setArchivesStatus(ArchivesStatusEnum.FB2901.getCode());
+                schoolRoll.setCreateDate(now);
+
+                rollService.save(schoolRoll);
+
+                BaseStudentFamily studentFamily = new BaseStudentFamily() {{
+                    setCreateDate(now);
+                    setUserId(xjrUser.getId());
+                    setTelephone(student.getFamilyMobile());
+                    setAddress(student.getFamilyAddress());
+                }};
+                familyService.save(studentFamily);
+
+                CompletableFuture.runAsync(() -> {
+                    List<User> userList = userService.list();
+                    redisUtil.set(GlobalConstant.USER_CACHE_KEY, userList);
+
+                    List<UserRoleRelation> userRoleRelationList = roleRelationService.list(Wrappers.lambdaQuery(UserRoleRelation.class));
+                    redisUtil.set(GlobalConstant.USER_ROLE_RELATION_CACHE_KEY, userRoleRelationList);
+                });
+            }
+        }
+    }
+
+    LocalDate getBirthDate(String idCardNumber){
+        // 获取出生日期前6位,即yyyyMM
+        String birthdayString = idCardNumber.substring(6, 14);
+
+        // 将字符串解析为LocalDate对象
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
+        try {
+            return LocalDate.parse(birthdayString, formatter);
+        }catch (Exception e){
+            throw new MyException("身份证号填写错误,无法提取出生日期");
+        }
+    }
 }