StudentTransferNodeTest.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package com.xjrsoft.module.liteflow.node;
  2. import cn.dev33.satoken.secure.BCrypt;
  3. import cn.hutool.core.convert.Convert;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.xjrsoft.XjrSoftApplication;
  6. import com.xjrsoft.common.enums.ArchivesStatusEnum;
  7. import com.xjrsoft.common.enums.DeleteMark;
  8. import com.xjrsoft.common.enums.EnabledMark;
  9. import com.xjrsoft.common.utils.LocalDateUtil;
  10. import com.xjrsoft.config.CommonPropertiesConfig;
  11. import com.xjrsoft.module.base.entity.BaseClass;
  12. import com.xjrsoft.module.base.mapper.BaseClassMapper;
  13. import com.xjrsoft.module.organization.dto.GetUserByParamDto;
  14. import com.xjrsoft.module.organization.entity.User;
  15. import com.xjrsoft.module.organization.service.IUserService;
  16. import com.xjrsoft.module.student.entity.BaseClassMajorSet;
  17. import com.xjrsoft.module.student.entity.BaseNewStudent;
  18. import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
  19. import com.xjrsoft.module.student.entity.StudentTransfer;
  20. import com.xjrsoft.module.student.mapper.BaseClassMajorSetMapper;
  21. import com.xjrsoft.module.student.mapper.StudentTransferMapper;
  22. import com.xjrsoft.module.student.service.IBaseNewStudentService;
  23. import com.xjrsoft.module.student.service.IBaseStudentSchoolRollService;
  24. import org.junit.jupiter.api.Test;
  25. import org.junit.runner.RunWith;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.boot.test.context.SpringBootTest;
  28. import org.springframework.test.context.junit4.SpringRunner;
  29. import java.time.LocalDate;
  30. import java.time.LocalDateTime;
  31. import java.util.Map;
  32. import static org.junit.jupiter.api.Assertions.*;
  33. /**
  34. * @author dzx
  35. * @date 2025/3/21
  36. */
  37. @RunWith(SpringRunner.class)
  38. @SpringBootTest(classes = XjrSoftApplication.class)
  39. class StudentTransferNodeTest {
  40. @Autowired
  41. private StudentTransferMapper studentTransferMapper;
  42. @Autowired
  43. private IBaseStudentSchoolRollService studentSchoolRollService;
  44. @Autowired
  45. private BaseClassMapper baseClassMapper;
  46. @Autowired
  47. private BaseClassMajorSetMapper baseClassMajorSetMapper;
  48. @Autowired
  49. private IBaseNewStudentService newStudentService;
  50. @Autowired
  51. private IUserService userService;
  52. @Autowired
  53. private CommonPropertiesConfig propertiesConfig;
  54. @Test
  55. public void process() throws Exception {
  56. // 获取表单中数据编号
  57. Long formId = 1902955784296742912L;
  58. if (formId != null) {
  59. //查询出数据
  60. StudentTransfer studentTransfer = studentTransferMapper.selectById(formId);
  61. BaseNewStudent newStudent = newStudentService.getById(studentTransfer.getStudentUserId());
  62. User user = userService.getUserByParam(
  63. new GetUserByParamDto() {{
  64. setCredentialNumber(newStudent.getCredentialNumber());
  65. }}
  66. );
  67. LocalDate birthDate = LocalDateUtil.getBirthDate(newStudent.getCredentialNumber());
  68. BaseClass baseClass = baseClassMapper.selectById(studentTransfer.getClassId());
  69. if(user == null){
  70. User xjrUser = new User() {{
  71. setCreateDate(LocalDateTime.now());
  72. // setPassword(BCrypt.hashpw(propertiesConfig.getDefaultPassword(), BCrypt.gensalt()));
  73. String credentialNumber = newStudent.getCredentialNumber();
  74. String lastSixDigits = credentialNumber.length() <= 6
  75. ? credentialNumber
  76. : credentialNumber.substring(credentialNumber.length() - 6);
  77. setPassword(BCrypt.hashpw(lastSixDigits, BCrypt.gensalt()));
  78. setName(newStudent.getName());
  79. setUserName(newStudent.getCredentialNumber());
  80. setCredentialNumber(newStudent.getCredentialNumber());
  81. setCredentialType("ZZLS10007");
  82. setMobile(newStudent.getMobile());
  83. setEnabledMark(EnabledMark.ENABLED.getCode());
  84. setGender(newStudent.getGender());
  85. setIsChangePassword(1);
  86. setBirthDate(birthDate.atStartOfDay());
  87. }};
  88. userService.save(xjrUser);
  89. BaseClassMajorSet majorSet = baseClassMajorSetMapper.selectOne(
  90. new QueryWrapper<BaseClassMajorSet>().lambda()
  91. .eq(BaseClassMajorSet::getClassId, studentTransfer.getClassId())
  92. .eq(BaseClassMajorSet::getDeleteMark, DeleteMark.NODELETE.getCode())
  93. );
  94. BaseStudentSchoolRoll roll = new BaseStudentSchoolRoll();
  95. roll.setStduyStatus(studentTransfer.getStudyStatus());
  96. roll.setClassId(studentTransfer.getClassId());
  97. roll.setEnrollType(baseClass.getEnrollType());
  98. roll.setCreateDate(LocalDateTime.now());
  99. roll.setGradeId(baseClass.getGradeId());
  100. roll.setMajorSetId(majorSet.getMajorSetId());
  101. roll.setCreateUserId(studentTransfer.getCreateUserId());
  102. roll.setArchivesStatus(ArchivesStatusEnum.FB2901.getCode());
  103. roll.setUserId(xjrUser.getId());
  104. roll.setDeleteMark(DeleteMark.NODELETE.getCode());
  105. roll.setEnabledMark(EnabledMark.ENABLED.getCode());
  106. //新增学籍信息
  107. studentSchoolRollService.save(roll);
  108. }else{
  109. studentSchoolRollService.updateStudentClass(studentTransfer.getClassId(), user.getId());
  110. }
  111. newStudent.setRemarks("通过插班进入" + baseClass.getName());
  112. newStudent.setStatus(1);
  113. newStudent.setOperateMode(2);
  114. newStudentService.updateById(newStudent);
  115. }
  116. }
  117. }