mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
部门管理接口入参检查完善
This commit is contained in:
+6
-1
@@ -135,7 +135,12 @@ public class GlobalExceptionHandler {
|
||||
log.warn("[handleBindException]", ex);
|
||||
FieldError fieldError = ex.getFieldError();
|
||||
assert fieldError != null; // 断言,避免告警
|
||||
return CommonResult.error(BAD_REQUEST.getCode(), String.format("请求参数不正确:%s", fieldError.getRejectedValue()));
|
||||
String defaultMessage = fieldError.getDefaultMessage();
|
||||
if (CharSequenceUtil.isNotEmpty(defaultMessage)) {
|
||||
return CommonResult.error(BAD_REQUEST.getCode(), String.format("请求参数不正确:%s", defaultMessage));
|
||||
} else {
|
||||
return CommonResult.error(BAD_REQUEST.getCode(), String.format("请求参数不正确:%s", fieldError.getRejectedValue()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ public class DeptController {
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获取部门列表")
|
||||
//@PreAuthorize("@ss.hasPermission('system:dept:query')")
|
||||
public CommonResult<List<DeptRespVO>> getDeptList(DeptListReqVO reqVO) {
|
||||
public CommonResult<List<DeptRespVO>> getDeptList(@Valid DeptListReqVO reqVO) {
|
||||
List<DeptDO> list = deptService.getDeptList(reqVO);
|
||||
return success(BeanUtils.toBean(list, DeptRespVO.class));
|
||||
}
|
||||
|
||||
+5
@@ -1,16 +1,21 @@
|
||||
package com.cf.imes.module.system.controller.admin.dept.vo.dept;
|
||||
|
||||
import com.cf.imes.module.system.validation.system.common.CommonStatus;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
@Schema(description = "管理后台 - 部门列表 Request VO")
|
||||
@Data
|
||||
public class DeptListReqVO {
|
||||
|
||||
@Schema(description = "部门名称,模糊匹配", example = "晨丰")
|
||||
@Size(max = 30, message = "部门名称长度不能超过 30 个字符")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "展示状态,参见 CommonStatusEnum 枚举类", example = "1")
|
||||
@CommonStatus
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "组织id")
|
||||
|
||||
+9
-4
@@ -1,13 +1,14 @@
|
||||
package com.cf.imes.module.system.controller.admin.dept.vo.dept;
|
||||
|
||||
import com.cf.imes.framework.common.enums.CommonStatusEnum;
|
||||
import com.cf.imes.framework.common.validation.InEnum;
|
||||
import com.cf.imes.framework.common.validation.Mobile;
|
||||
import com.cf.imes.module.system.validation.system.common.CommonStatus;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
@@ -27,6 +28,7 @@ public class DeptSaveReqVO {
|
||||
private String name;
|
||||
|
||||
@Schema(description = "父部门 ID", example = "1024")
|
||||
@NotNull(message = "上级部门不能为空")
|
||||
private Long parentId;
|
||||
|
||||
@Schema(description = "显示顺序不能为空", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
@@ -34,21 +36,24 @@ public class DeptSaveReqVO {
|
||||
private Integer sort;
|
||||
|
||||
@Schema(description = "负责人", example = "2048")
|
||||
@Length(min = 0, max = 10, message = "负责人不可太长")
|
||||
@Length(max = 10, message = "负责人长度不能超过10个字符")
|
||||
private String leader;
|
||||
|
||||
@Schema(description = "联系电话", example = "15601691000")
|
||||
@Size(max = 11, message = "联系电话长度不能超过11个字符")
|
||||
@Mobile
|
||||
@NotEmpty(message = "联系电话不能为空")
|
||||
private String phone;
|
||||
|
||||
@Schema(description = "邮箱", example = "chenfeng@cf.com")
|
||||
@Email(message = "邮箱格式不正确")
|
||||
@Size(max = 50, message = "邮箱长度不能超过 50 个字符")
|
||||
@NotEmpty(message = "邮箱不能为空")
|
||||
private String email;
|
||||
|
||||
@Schema(description = "状态,见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "状态不能为空")
|
||||
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
|
||||
@CommonStatus
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.cf.imes.module.system.validation.system.common;
|
||||
|
||||
import javax.validation.Constraint;
|
||||
import javax.validation.Payload;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 状态校验注解
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2024/10/12 9:48
|
||||
*/
|
||||
@Target({
|
||||
ElementType.FIELD,
|
||||
})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Constraint(
|
||||
validatedBy = {CommonStatusValidator.class}
|
||||
)
|
||||
public @interface CommonStatus {
|
||||
String message() default "状态不合法,0:开启、1:关闭";
|
||||
|
||||
Class<?>[] groups() default {};
|
||||
|
||||
Class<? extends Payload>[] payload() default {};
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.cf.imes.module.system.validation.system.common;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.cf.imes.framework.common.enums.CommonStatusEnum;
|
||||
|
||||
import javax.validation.ConstraintValidator;
|
||||
import javax.validation.ConstraintValidatorContext;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 状态校验器
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2024/10/12 9:50
|
||||
*/
|
||||
public class CommonStatusValidator implements ConstraintValidator<CommonStatus, Integer> {
|
||||
|
||||
@Override
|
||||
public boolean isValid(Integer value, ConstraintValidatorContext context) {
|
||||
if (ObjectUtil.isNull(value)) {
|
||||
return true;
|
||||
}
|
||||
for (CommonStatusEnum statusEnum : CommonStatusEnum.values()) {
|
||||
if (Objects.equals(statusEnum.getStatus(), value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user