Bladeren bron

新增考生端修改学生密码

wangliang 2 jaren geleden
bovenliggende
commit
78e09aa6a2

+ 6 - 21
themis-admin/src/main/java/com/qmth/themis/admin/api/TEStudentController.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.qmth.themis.business.annotation.ApiJsonObject;
 import com.qmth.themis.business.annotation.ApiJsonProperty;
+import com.qmth.themis.business.bean.StudentParams;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.response.TEStudentDto;
 import com.qmth.themis.business.entity.TBUser;
@@ -20,6 +21,7 @@ import com.qmth.themis.common.util.ResultUtil;
 import io.swagger.annotations.*;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.validation.BindingResult;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
@@ -110,28 +112,11 @@ public class TEStudentController {
     @ApiOperation(value = "学生修改密码接口")
     @RequestMapping(value = "/updatePwd", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class)})
-    @Transactional
-    public Result studentUpdatePwd(@ApiJsonObject(name = "studentUpdatePwd", value = {
-            @ApiJsonProperty(key = "id", type = "long", example = "1", description = "用户ID"),
-            @ApiJsonProperty(key = "password", description = "新密码")
-    }) @ApiParam(value = "学生信息", required = true) @RequestBody Map<String, Object> mapParameter) {
-        if (Objects.isNull(mapParameter.get(SystemConstant.ID)) || Objects.equals(mapParameter.get(SystemConstant.ID), "")) {
-            throw new BusinessException(ExceptionResultEnum.STUDENT_ID_IS_NULL);
+    public Result studentUpdatePwd(@Validated @RequestBody StudentParams studentParams, BindingResult bindingResult) {
+        if (bindingResult.hasErrors()) {
+            return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
         }
-        Long id = Long.parseLong(String.valueOf(mapParameter.get(SystemConstant.ID)));
-        if (Objects.isNull(mapParameter.get("password")) || Objects.equals(mapParameter.get("password"), "")) {
-            throw new BusinessException(ExceptionResultEnum.PASSWORD_IS_NULL);
-        }
-        String password = String.valueOf(mapParameter.get("password"));
-        TEStudent teStudent = teStudentService.getById(id);
-        if (Objects.isNull(teStudent)) {
-            throw new BusinessException(ExceptionResultEnum.STUDENT_INFO_IS_NULL);
-        }
-        TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
-        teStudent.setPassword(password);
-        teStudent.setUpdateId(tbUser.getId());
-        teStudentService.updateById(teStudent);
-        cacheService.updateStudentAccountCache(teStudent.getId());
+        teStudentService.updatePwd(studentParams);
         return ResultUtil.ok(true);
     }
 

+ 43 - 0
themis-business/src/main/java/com/qmth/themis/business/bean/StudentParams.java

@@ -0,0 +1,43 @@
+package com.qmth.themis.business.bean;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import io.swagger.annotations.ApiModelProperty;
+
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+
+/**
+ * @Description: 学生参数
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2022/8/16
+ */
+public class StudentParams implements Serializable {
+
+    @JsonSerialize(using = ToStringSerializer.class)
+    @ApiModelProperty(value = "学生id")
+    @NotNull(message = "学生id不能为空")
+    private Long id;
+
+    @ApiModelProperty(value = "新密码")
+    @NotNull(message = "密码不能为空")
+    private String password;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+}

+ 8 - 0
themis-business/src/main/java/com/qmth/themis/business/service/TEStudentService.java

@@ -2,6 +2,7 @@ package com.qmth.themis.business.service;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.themis.business.bean.StudentParams;
 import com.qmth.themis.business.bean.admin.StudentPhotoUploadResponseBean;
 import com.qmth.themis.business.dto.response.TEStudentDto;
 import com.qmth.themis.business.dto.response.TEStudentExamRecordDto;
@@ -52,4 +53,11 @@ public interface TEStudentService extends IService<TEStudent> {
      * @return
      */
     public StudentPhotoUploadResponseBean photoUpload(Long orgId, String identity, MultipartFile file, String md5);
+
+    /**
+     * 修改学生密码
+     *
+     * @param studentParams
+     */
+    public void updatePwd(StudentParams studentParams);
 }

+ 25 - 1
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEStudentServiceImpl.java

@@ -6,16 +6,20 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.google.common.reflect.TypeToken;
 import com.google.gson.Gson;
+import com.qmth.themis.business.bean.StudentParams;
 import com.qmth.themis.business.bean.admin.StudentPhotoUploadResponseBean;
+import com.qmth.themis.business.constant.SpringContextHolder;
 import com.qmth.themis.business.dao.TEStudentMapper;
 import com.qmth.themis.business.dto.response.TEStudentDto;
 import com.qmth.themis.business.dto.response.TEStudentExamRecordDto;
 import com.qmth.themis.business.dto.response.TEStudentMonitorRecordDto;
+import com.qmth.themis.business.entity.TBUser;
 import com.qmth.themis.business.entity.TEStudent;
 import com.qmth.themis.business.service.CacheService;
 import com.qmth.themis.business.service.TEStudentService;
-import com.qmth.themis.business.util.JacksonUtil;
 import com.qmth.themis.business.util.OssUtil;
+import com.qmth.themis.business.util.ServletUtil;
+import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.util.HexUtils;
 import org.springframework.stereotype.Service;
@@ -28,6 +32,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
 
 /**
  * @Description: 学生档案 服务实现类
@@ -120,4 +126,22 @@ public class TEStudentServiceImpl extends ServiceImpl<TEStudentMapper, TEStudent
             }
         }
     }
+
+    /**
+     * 修改学生密码
+     *
+     * @param studentParams
+     */
+    @Override
+    @Transactional
+    public void updatePwd(StudentParams studentParams) {
+        TEStudent teStudent = this.getById(studentParams.getId());
+        Optional.ofNullable(teStudent).orElseThrow(() -> new BusinessException(ExceptionResultEnum.STUDENT_INFO_IS_NULL));
+        TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
+        teStudent.setPassword(studentParams.getPassword());
+        teStudent.setUpdateId(Objects.nonNull(tbUser) ? tbUser.getId() : -1);
+        TEStudentService teStudentService = SpringContextHolder.getBean(TEStudentService.class);
+        teStudentService.updateById(teStudent);
+        cacheService.updateStudentAccountCache(teStudent.getId());
+    }
 }

+ 14 - 0
themis-exam/src/main/java/com/qmth/themis/exam/api/TEStudentController.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.google.gson.Gson;
 import com.qmth.themis.business.annotation.ApiJsonObject;
 import com.qmth.themis.business.annotation.ApiJsonProperty;
+import com.qmth.themis.business.bean.StudentParams;
 import com.qmth.themis.business.bean.exam.ExamActivityUnFinishBean;
 import com.qmth.themis.business.bean.exam.ExamUnFinishBean;
 import com.qmth.themis.business.cache.ExamRecordCacheUtil;
@@ -41,6 +42,8 @@ import io.swagger.annotations.*;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.validation.BindingResult;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
@@ -364,4 +367,15 @@ public class TEStudentController {
         }
         return map;
     }
+
+    @ApiOperation(value = "学生修改密码接口")
+    @RequestMapping(value = "/updatePwd", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class)})
+    public Result studentUpdatePwd(@Validated @RequestBody StudentParams studentParams, BindingResult bindingResult) {
+        if (bindingResult.hasErrors()) {
+            return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
+        }
+        teStudentService.updatePwd(studentParams);
+        return ResultUtil.ok(true);
+    }
 }