Browse Source

学生唯一性验证

dzx 7 months ago
parent
commit
93550d4da8

+ 14 - 8
src/main/java/com/xjrsoft/module/student/controller/StudentManagerController.java

@@ -12,6 +12,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import com.xjrsoft.common.annotation.XjrLog;
+import com.xjrsoft.common.enums.ArchivesStatusEnum;
 import com.xjrsoft.common.enums.DeleteMark;
 import com.xjrsoft.common.enums.GenderDictionaryEnum;
 import com.xjrsoft.common.exception.MyException;
@@ -235,17 +236,22 @@ public class StudentManagerController {
     @SaCheckPermission("studentmanager:add")
     @XjrLog(value = "新增学生", saveResponseData = true)
     public R add(@Valid @RequestBody AddBaseStudentUserDto dto) {
-        List<BaseStudentSompleInfoVo> infos = schoolRollService.getInfosByParam(new BaseStudentSimpleInfoDto() {{
-            setIdNumber(dto.getCredentialNumber());
-            setFindNewStudent(0);
-        }});
-        if(!infos.isEmpty()){
-            return R.ok(infos.get(0));
+        return R.ok(studentManagerService.add(dto));
+    }
+
+    @GetMapping(value = "/find-student-exist")
+    @ApiOperation(value = "新增前判断学生是否存在")
+    @SaCheckPermission("studentmanager:detail")
+    @XjrLog(value = "新增前判断学生是否存在")
+    public RT<BaseStudentSompleInfoVo> info(@Valid BaseStudentSimpleInfoDto dto) {
+        List<BaseStudentSompleInfoVo> infos = schoolRollService.getInfosByParam(dto);
+        if(infos.isEmpty()){
+            return RT.ok();
         }
-        studentManagerService.add(dto);
-        return R.ok();
+        return RT.ok(infos.get(0));
     }
 
+
     @PostMapping("upload-image")
     @ApiOperation(value = "上传学生学籍照片")
     @SaCheckPermission("studentmanager:add")

+ 14 - 7
src/main/java/com/xjrsoft/module/student/service/impl/StudentManagerServiceImpl.java

@@ -77,7 +77,7 @@ import java.util.stream.Collectors;
 @Service
 @AllArgsConstructor
 public class StudentManagerServiceImpl extends MPJBaseServiceImpl<BaseStudentUserMapper, BaseStudentUser> implements IStudentManagerService {
-    private final com.xjrsoft.module.student.mapper.BaseStudentUserMapper studentbaseManagerBaseStudentUserMapper;
+    private final com.xjrsoft.module.student.mapper.BaseStudentUserMapper baseStudentUserMapper;
 
     private final IBaseStudentService baseStudentService;
     private final BaseClassMapper baseClassMapper;
@@ -122,7 +122,7 @@ public class StudentManagerServiceImpl extends MPJBaseServiceImpl<BaseStudentUse
 
         // 用户身份证后6位作为默认密码
         baseStudentUser.setPassword(BCrypt.hashpw(propertiesConfig.getDefaultPassword(), BCrypt.gensalt()));
-        studentbaseManagerBaseStudentUserMapper.insert(baseStudentUser);
+        baseStudentUserMapper.insert(baseStudentUser);
         for (BaseStudent baseStudent : baseStudentUser.getBaseStudentList()) {
 
             baseStudent.setUserId(baseStudentUser.getId());
@@ -206,11 +206,18 @@ public class StudentManagerServiceImpl extends MPJBaseServiceImpl<BaseStudentUse
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Boolean update(UpdateBaseStudentUserDto dto) {
-
+        List<BaseStudentUser> studentUserList = baseStudentUserMapper.selectList(
+                new QueryWrapper<BaseStudentUser>().lambda()
+                        .eq(BaseStudentUser::getCredentialNumber, dto.getCredentialNumber())
+                        .ne(BaseStudentUser::getId, dto.getId())
+        );
+        if(!studentUserList.isEmpty()){
+            throw new MyException("该身份证已被其他人占用,请检查是否正确");
+        }
         BaseStudentUser baseStudentUser = BeanUtil.toBean(dto, BaseStudentUser.class);
         baseStudentUser.setCode(dto.getUserName());
 
-        studentbaseManagerBaseStudentUserMapper.updateById(baseStudentUser);
+        baseStudentUserMapper.updateById(baseStudentUser);
 
         //先删除再新增
         userDeptRelationService.remove(Wrappers.<UserDeptRelation>query().lambda().eq(UserDeptRelation::getUserId, baseStudentUser.getId()));
@@ -431,7 +438,7 @@ public class StudentManagerServiceImpl extends MPJBaseServiceImpl<BaseStudentUse
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Boolean delete(List<Long> ids) {
-        studentbaseManagerBaseStudentUserMapper.deleteBatchIds(ids);
+        baseStudentUserMapper.deleteBatchIds(ids);
         baseStudentService.remove(Wrappers.lambdaQuery(BaseStudent.class).in(BaseStudent::getUserId, ids));
         studentContactService.remove(Wrappers.lambdaQuery(BaseStudentContact.class).in(BaseStudentContact::getUserId, ids));
         familyMapper.delete(Wrappers.lambdaQuery(BaseStudentFamily.class).in(BaseStudentFamily::getUserId, ids));
@@ -1019,7 +1026,7 @@ public class StudentManagerServiceImpl extends MPJBaseServiceImpl<BaseStudentUse
 
     @Override
     public Boolean uploadImage(Long userId, MultipartFile file) throws IOException {
-        BaseStudentUser studentUser = studentbaseManagerBaseStudentUserMapper.selectById(userId);
+        BaseStudentUser studentUser = baseStudentUserMapper.selectById(userId);
         String[] imgSuffix = new String[]{"png", "jpg", "jpeg"};
         String suffix = StringUtils.substringAfterLast(file.getOriginalFilename(), StringPool.DOT);
         if (!Arrays.asList(imgSuffix).contains(suffix)) {
@@ -1035,7 +1042,7 @@ public class StudentManagerServiceImpl extends MPJBaseServiceImpl<BaseStudentUse
             }
         };
         studentUser.setAvatar(map.get(suffix) + base64String);
-        studentbaseManagerBaseStudentUserMapper.updateById(studentUser);
+        baseStudentUserMapper.updateById(studentUser);
         return true;
     }