From 782775acdbfee4e9c894d58cbde1ebd6ce8ff412 Mon Sep 17 00:00:00 2001 From: shijie <648688341@qq.com> Date: Wed, 24 Feb 2021 10:22:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=B3=BB=E7=BB=9F=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=A8=A1=E5=9D=97bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tms/common/exception/ExceptionCatch.java | 13 + .../controller/SystemSettingController.java | 3 +- .../com/msdw/tms/entity/UserInfoEntity.java | 5 + .../tms/entity/response/ResponseResult.java | 54 +++- .../resources/mapper/tms/SystemSetting.xml | 10 +- .../service/AchievementManagementTest.java | 278 +++++++++--------- 6 files changed, 212 insertions(+), 151 deletions(-) diff --git a/src/main/java/com/msdw/tms/common/exception/ExceptionCatch.java b/src/main/java/com/msdw/tms/common/exception/ExceptionCatch.java index fdbea6f..5043a2d 100644 --- a/src/main/java/com/msdw/tms/common/exception/ExceptionCatch.java +++ b/src/main/java/com/msdw/tms/common/exception/ExceptionCatch.java @@ -7,6 +7,7 @@ import com.msdw.tms.entity.response.ResultCode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.converter.HttpMessageNotReadableException; +import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; @@ -59,4 +60,16 @@ public class ExceptionCatch { ResultCode resultCode = customException.getResultCode(); return new ResponseResult(resultCode); } + + @ExceptionHandler(MethodArgumentNotValidException.class)//捕获CustomException类型异常 + @ResponseBody + public ResponseResult MethodArgumentNotValidException(MethodArgumentNotValidException customException) { + customException.printStackTrace(); + //记录日志 + LOGGER.error("catch exception:{}", customException.getMessage()); + String message = customException.getBindingResult().getAllErrors().get(0).getDefaultMessage(); + int code =402; + + return ResponseResult.FAIL(code,message); + } } diff --git a/src/main/java/com/msdw/tms/controller/SystemSettingController.java b/src/main/java/com/msdw/tms/controller/SystemSettingController.java index cf67939..1a9989c 100644 --- a/src/main/java/com/msdw/tms/controller/SystemSettingController.java +++ b/src/main/java/com/msdw/tms/controller/SystemSettingController.java @@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; import java.io.IOException; import java.util.HashMap; import java.util.List; @@ -32,7 +33,7 @@ public class SystemSettingController implements SystemSetttingApi { */ @Override @PostMapping("/addStaff") - public R addStaff(@RequestBody StaffVo staffVo){ + public R addStaff(@RequestBody @Valid StaffVo staffVo){ R r = systemSetttingService.addStaff(staffVo); return r; } diff --git a/src/main/java/com/msdw/tms/entity/UserInfoEntity.java b/src/main/java/com/msdw/tms/entity/UserInfoEntity.java index 7a2b646..a0f2a63 100644 --- a/src/main/java/com/msdw/tms/entity/UserInfoEntity.java +++ b/src/main/java/com/msdw/tms/entity/UserInfoEntity.java @@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.experimental.Accessors; +import javax.validation.constraints.Pattern; + @Accessors(chain = true) @Data @TableName("hr_user_info") @@ -15,6 +17,7 @@ public class UserInfoEntity { //用户姓名 private String userName; //用户账号 + @Pattern(regexp = "/^[1-9]([0-9]{1,5})?$/", message = "账号只能为数字!") private String account; //用户密码 private String password; @@ -60,4 +63,6 @@ public class UserInfoEntity { private Integer schoolAppellationId; //token private String token; + //最后登录时间 + private String lastLoginTime; } diff --git a/src/main/java/com/msdw/tms/entity/response/ResponseResult.java b/src/main/java/com/msdw/tms/entity/response/ResponseResult.java index c05f8ed..2b2464b 100644 --- a/src/main/java/com/msdw/tms/entity/response/ResponseResult.java +++ b/src/main/java/com/msdw/tms/entity/response/ResponseResult.java @@ -1,22 +1,46 @@ package com.msdw.tms.entity.response; +import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import lombok.ToString; +/** + * @Author: gongsj. + * @Description: 统一返回的结果集。 + * @Date:Created in 2020/09/07 12:28. + * @Modified By: + */ @Data @ToString @NoArgsConstructor -public class ResponseResult implements Response { +@AllArgsConstructor +public class ResponseResult { + /** + * 操作是否成功 + */ + private boolean success; - //操作是否成功 - boolean success = SUCCESS; + /** + * 状态码 + */ + private int code; - //操作代码 - int code = SUCCESS_CODE; + /** + * 返回的数据 + */ + private T data; - //提示信息 - String message; + /** + * 提示信息 + */ + private String message; + + public ResponseResult(boolean success, int code, String message) { + this.success = success; + this.code = code; + this.message = message; + } public ResponseResult(ResultCode resultCode) { this.success = resultCode.success(); @@ -28,8 +52,24 @@ public class ResponseResult implements Response { return new ResponseResult(CommonCode.SUCCESS); } + public static ResponseResult SUCCESS(Object t) { + return new ResponseResult<>(true, 10000, t, "操作成功!"); + } + + public static ResponseResult FAIL(Object t) { + return new ResponseResult<>(false, 99999, t, "操作失败,请检查客户名称是否已存在或者文件和数据格式是否正确!"); + } + + public ResponseResult SUCCESS_DATA(T t) { + return new ResponseResult<>(false, 20000, t, "操作失败!"); + } + public static ResponseResult FAIL() { return new ResponseResult(CommonCode.FAIL); } + public static ResponseResult FAIL(int code, String message) { + return new ResponseResult<>(false, code, null, message); + } + } diff --git a/src/main/resources/mapper/tms/SystemSetting.xml b/src/main/resources/mapper/tms/SystemSetting.xml index a48e684..86f6802 100644 --- a/src/main/resources/mapper/tms/SystemSetting.xml +++ b/src/main/resources/mapper/tms/SystemSetting.xml @@ -96,12 +96,14 @@ s.staffId, s.workNumber, s.staffProfessionalArchitectureId, - s.staffProfessionalArchitectureName, + spa.staffProfessionalArchitectureName, s.staffGradeId, - s.staffGradeName + sg.staffGradeName FROM hr_user_info u LEFT JOIN staff s ON u.userId = s.userId + LEFT JOIN staff_professional_architecture spa on spa.staffProfessionalArchitectureId = s.staffProfessionalArchitectureId + LEFT JOIN staff_grade sg on sg.staffGradeId = s.staffGradeId WHERE s.schoolId = #{schoolId} AND @@ -109,8 +111,8 @@ AND s.isdel=0 AND (u.userName LIKE CONCAT('%',#{searchContent},'%') OR s.workNumber LIKE CONCAT('%',#{searchContent},'%') OR u.account LIKE CONCAT('%',#{searchContent},'%') ) - AND FIND_IN_SET(staffGradeId,#{staffGradeIds}) - AND FIND_IN_SET(staffProfessionalArchitectureId,#{staffProfessionalArchitectureIds}) + AND FIND_IN_SET(s.staffGradeId,#{staffGradeIds}) + AND FIND_IN_SET(s.staffProfessionalArchitectureId,#{staffProfessionalArchitectureIds}) GROUP BY s.userId ORDER BY u.updateTime DESC,u.lastLoginTime DESC,creationTime DESC