Bläddra i källkod

复读和激活账号,当用户已经存在,应该重置登录密码

大数据与最优化研究所 4 månader sedan
förälder
incheckning
25eaca55d9

+ 15 - 0
src/main/java/com/xjrsoft/module/liteflow/node/WfStudentRepeatStudyNode.java

@@ -1,8 +1,10 @@
 package com.xjrsoft.module.liteflow.node;
 
+import cn.dev33.satoken.secure.BCrypt;
 import cn.hutool.core.convert.Convert;
 import cn.hutool.db.Entity;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import com.xjrsoft.common.enums.ArchivesStatusEnum;
 import com.xjrsoft.common.enums.StudentTypeEnum;
@@ -18,6 +20,7 @@ import com.xjrsoft.module.student.dto.AddBaseStudentFamilyMemberDto;
 import com.xjrsoft.module.student.dto.AddBaseStudentSchoolRollDto;
 import com.xjrsoft.module.student.dto.AddBaseStudentSubsidizeDto;
 import com.xjrsoft.module.student.dto.AddBaseStudentUserDto;
+import com.xjrsoft.module.student.entity.BaseStudentUser;
 import com.xjrsoft.module.student.service.IBaseStudentSchoolRollService;
 import com.xjrsoft.module.student.service.IBaseStudentService;
 import com.xjrsoft.module.student.service.IStudentManagerService;
@@ -138,6 +141,18 @@ public class WfStudentRepeatStudyNode extends NodeComponent {
 
                                 studentService.add(baseStudentUser);
                             }else{
+                                // 当学生用户已经存在,应该修改用户密码为证件号后六位
+                                String lastSixDigits = credentialNumber.length() <= 6
+                                        ? credentialNumber
+                                        : credentialNumber.substring(credentialNumber.length() - 6);
+
+                                LambdaUpdateWrapper<BaseStudentUser> baseStudentUserLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
+                                baseStudentUserLambdaUpdateWrapper
+                                        .set(BaseStudentUser::getPassword, BCrypt.hashpw(lastSixDigits, BCrypt.gensalt()))
+                                        .eq(BaseStudentUser::getCredentialNumber, credentialNumber)
+                                        ;
+                                studentService.update(baseStudentUserLambdaUpdateWrapper);
+
                                 schoolRollService.activateStudent(user.getId(), null);
                                 schoolRollService.updateStudentClassGradeMajorStduyStatus(
                                         Long.parseLong(objectMap.get("class_id").toString()),

+ 13 - 0
src/main/java/com/xjrsoft/module/student/controller/BaseNewStudentController.java

@@ -15,6 +15,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.xjrsoft.common.annotation.XjrLog;
 import com.xjrsoft.common.constant.GlobalConstant;
 import com.xjrsoft.common.enums.EnabledMark;
+import com.xjrsoft.common.exception.MyException;
 import com.xjrsoft.common.model.result.RT;
 import com.xjrsoft.common.page.ConventPage;
 import com.xjrsoft.common.page.PageOutput;
@@ -58,6 +59,7 @@ import com.xjrsoft.module.student.vo.EnrollmentPlanTreeVo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.DeleteMapping;
@@ -275,6 +277,17 @@ public class BaseNewStudentController {
         user.setMobile(dto.getMobile());
         user.setEnabledMark(EnabledMark.ENABLED.getCode());
         user.setModifyDate(LocalDateTime.now());
+        String credentialNumber = user.getCredentialNumber();
+
+        if (StringUtils.isEmpty(credentialNumber)) {
+            throw new MyException(user.getName() + "证件号为空,请填写后激活账号");
+        }
+
+        String lastSixDigits = credentialNumber.length() <= 6
+                ? credentialNumber
+                : credentialNumber.substring(credentialNumber.length() - 6);
+        user.setPassword(BCrypt.hashpw(lastSixDigits, BCrypt.gensalt()));
+
         userService.updateById(user);
         // 新增家庭成员信息
         if(StrUtil.isNotEmpty(dto.getParentName()) && StrUtil.isNotEmpty(dto.getParentMobile())){

+ 17 - 2
src/test/java/com/xjrsoft/module/liteflow/node/WfStudentRepeatStudyNodeTest.java

@@ -1,7 +1,9 @@
 package com.xjrsoft.module.liteflow.node;
 
+import cn.dev33.satoken.secure.BCrypt;
 import cn.hutool.core.convert.Convert;
 import cn.hutool.db.Entity;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import com.xjrsoft.XjrSoftApplication;
 import com.xjrsoft.common.enums.ArchivesStatusEnum;
@@ -17,6 +19,7 @@ import com.xjrsoft.module.student.dto.AddBaseStudentFamilyMemberDto;
 import com.xjrsoft.module.student.dto.AddBaseStudentSchoolRollDto;
 import com.xjrsoft.module.student.dto.AddBaseStudentSubsidizeDto;
 import com.xjrsoft.module.student.dto.AddBaseStudentUserDto;
+import com.xjrsoft.module.student.entity.BaseStudentUser;
 import com.xjrsoft.module.student.service.IBaseStudentSchoolRollService;
 import com.xjrsoft.module.student.service.IStudentManagerService;
 import com.xjrsoft.module.workflow.service.IWorkflowExecuteService;
@@ -54,7 +57,7 @@ class WfStudentRepeatStudyNodeTest {
 
     @Test
     void test(){
-        Long formId = 1907636186804998144L;
+        Long formId = 1952276941219917824L;
 
         String tableName = "wf_student_repeat_study";
         Entity where = Entity.create(tableName);
@@ -83,7 +86,7 @@ class WfStudentRepeatStudyNodeTest {
             List<AddBaseStudentSchoolRollDto> baseStudentSchoolRollList = new ArrayList<>();
             AddBaseStudentSchoolRollDto rollDto = new AddBaseStudentSchoolRollDto();
             rollDto.setStduyStatus(objectMap.get("stduy_status").toString());
-            rollDto.setStduyStatus(ArchivesStatusEnum.FB2901.getCode());
+            rollDto.setArchivesStatus(ArchivesStatusEnum.FB2901.getCode());
             rollDto.setMajorSetId(Long.parseLong(objectMap.get("major_set_id").toString()));
             rollDto.setStudentType(StudentTypeEnum.FB2801.getCode());
             rollDto.setClassId(Long.parseLong(objectMap.get("class_id").toString()));
@@ -115,6 +118,18 @@ class WfStudentRepeatStudyNodeTest {
 
             studentService.add(baseStudentUser);
         }else{
+            // 当学生用户已经存在,应该修改用户密码为证件号后六位
+            String lastSixDigits = credentialNumber.length() <= 6
+                    ? credentialNumber
+                    : credentialNumber.substring(credentialNumber.length() - 6);
+
+            LambdaUpdateWrapper<BaseStudentUser> baseStudentUserLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
+            baseStudentUserLambdaUpdateWrapper
+                    .set(BaseStudentUser::getPassword, BCrypt.hashpw(lastSixDigits, BCrypt.gensalt()))
+                    .eq(BaseStudentUser::getCredentialNumber, credentialNumber)
+            ;
+            studentService.update(baseStudentUserLambdaUpdateWrapper);
+
             schoolRollService.activateStudent(user.getId(), null);
             schoolRollService.updateStudentClassGradeMajorStduyStatus(
                     Long.parseLong(objectMap.get("class_id").toString()),