feat: 优化参数校验
This commit is contained in:
parent
6d00705773
commit
4091e676d7
|
|
@ -58,8 +58,8 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.validation</groupId>
|
||||
<artifactId>jakarta.validation-api</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ import java.util.List;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/adminuser")
|
||||
public class AdminUserController {
|
||||
public class AdminUserController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
private IAdminUserService adminUserService;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.*;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -24,7 +25,7 @@ import java.util.List;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/appuser")
|
||||
public class AppUserController {
|
||||
public class AppUserController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
private IAppUserService appUserService;
|
||||
|
|
@ -86,7 +87,7 @@ public class AppUserController {
|
|||
* @param id 审批id
|
||||
*/
|
||||
@GetMapping("getAppUserApplyfor")
|
||||
public ApiResult<AppUserApplyforVO> getAppUserApplyfor(@Valid @RequestParam Integer id) {
|
||||
public ApiResult<AppUserApplyforVO> getAppUserApplyfor(@Valid @NotNull(message = "审批id不能为空") @RequestParam Integer id) {
|
||||
return ApiResult.success(appUserApplyforService.getAppUserApplyfor(id));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ import java.util.Objects;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/baseArea")
|
||||
public class BaseAreaController {
|
||||
public class BaseAreaController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
ITBaseAreaService baseAreaService;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package com.nflg.mobilebroken.admin.controller;
|
||||
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Validated
|
||||
@RestController
|
||||
public class ControllerBase {
|
||||
|
||||
}
|
||||
|
|
@ -38,7 +38,7 @@ import java.util.Objects;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/customer")
|
||||
public class CustomerController {
|
||||
public class CustomerController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
ITBaseCustomerService baseCustomerService;
|
||||
|
|
|
|||
|
|
@ -5,13 +5,10 @@ import cn.hutool.core.convert.Convert;
|
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.nflg.mobilebroken.admin.pojo.dto.DepartmentDTO;
|
||||
import com.nflg.mobilebroken.admin.pojo.query.DepartmentQuery;
|
||||
import com.nflg.mobilebroken.admin.pojo.query.DeviceComponentQuery;
|
||||
import com.nflg.mobilebroken.common.pojo.ApiResult;
|
||||
import com.nflg.mobilebroken.common.pojo.PageData;
|
||||
import com.nflg.mobilebroken.common.util.VUtils;
|
||||
import com.nflg.mobilebroken.repository.entity.DeviceComponent;
|
||||
import com.nflg.mobilebroken.repository.entity.TBaseDepartment;
|
||||
import com.nflg.mobilebroken.repository.service.IDeviceComponentService;
|
||||
import com.nflg.mobilebroken.repository.service.ITBaseDepartmentService;
|
||||
import com.nflg.mobilebroken.starter.annotation.MethodInfoMark;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
|
@ -25,7 +22,7 @@ import java.util.List;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/department")
|
||||
public class DepartmentController {
|
||||
public class DepartmentController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
ITBaseDepartmentService departmentService;
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import java.util.List;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/deviceComponent")
|
||||
public class DeviceComponentController {
|
||||
public class DeviceComponentController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
IDeviceComponentService deviceComponentService;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import java.util.Objects;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/device")
|
||||
public class DeviceController {
|
||||
public class DeviceController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
IDeviceService deviceService;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import java.util.List;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/deviceType")
|
||||
public class DeviceTypeController {
|
||||
public class DeviceTypeController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
ITBaseDeviceTypeService baseDeviceTypeService;
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ import java.util.Objects;
|
|||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/dictionary")
|
||||
public class DictionaryController {
|
||||
public class DictionaryController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
private IDictionaryService dictionaryService;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import java.util.List;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/menu")
|
||||
public class MenuController {
|
||||
public class MenuController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
private IAdminMenuService adminMenuService;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import java.util.List;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/message")
|
||||
public class MessageController {
|
||||
public class MessageController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
private IAdminMessageService adminMessageService;
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ import java.util.*;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/multilingual")
|
||||
public class MultilingualController {
|
||||
public class MultilingualController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
private ILanguageService languageService;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import java.util.List;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/paramconfig")
|
||||
public class ParamConfigController {
|
||||
public class ParamConfigController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
private IParamConfigService paramConfigService;
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import java.util.stream.Collectors;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/position")
|
||||
public class PositionController {
|
||||
public class PositionController extends ControllerBase {
|
||||
|
||||
|
||||
@Resource
|
||||
|
|
|
|||
|
|
@ -2,16 +2,13 @@ package com.nflg.mobilebroken.admin.controller;
|
|||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.nflg.mobilebroken.admin.pojo.query.DepartmentQuery;
|
||||
import com.nflg.mobilebroken.admin.pojo.query.RequestLogQuery;
|
||||
import com.nflg.mobilebroken.common.pojo.ApiResult;
|
||||
import com.nflg.mobilebroken.common.pojo.PageData;
|
||||
import com.nflg.mobilebroken.common.pojo.vo.TBaseAreaVO;
|
||||
import com.nflg.mobilebroken.repository.entity.TBaseRequestLog;
|
||||
import com.nflg.mobilebroken.repository.entity.TBaseRequestLogDetail;
|
||||
import com.nflg.mobilebroken.repository.service.ITBaseRequestLogDetailService;
|
||||
import com.nflg.mobilebroken.repository.service.ITBaseRequestLogService;
|
||||
import com.nflg.mobilebroken.starter.annotation.MethodInfoMark;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
|
@ -23,7 +20,7 @@ import javax.annotation.Resource;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/requestLog")
|
||||
public class RequestLogController {
|
||||
public class RequestLogController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
ITBaseRequestLogService logService;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import java.util.List;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/role")
|
||||
public class RoleController {
|
||||
public class RoleController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
private IAdminRoleService adminRoleService;
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ import java.util.List;
|
|||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/ticket")
|
||||
public class TicketController {
|
||||
public class TicketController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
private ITicketService ticketService;
|
||||
|
|
|
|||
|
|
@ -64,6 +64,10 @@
|
|||
<artifactId>junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@ import org.springframework.context.annotation.ComponentScan;
|
|||
|
||||
@SpringBootApplication
|
||||
@MapperScan("com.nflg.mobilebroken.repository.mapper")
|
||||
@ComponentScan(basePackages = {"com.nflg.mobilebroken"})
|
||||
@ComponentScan(basePackages = {"com.nflg.mobilebroken.repository.service", "com.nflg.mobilebroken.auth"
|
||||
, "com.nflg.mobilebroken.starter"})
|
||||
@EnableDiscoveryClient
|
||||
@Slf4j
|
||||
public class AuthApplication {
|
||||
|
|
|
|||
|
|
@ -13,12 +13,11 @@ import com.nflg.mobilebroken.repository.entity.AdminUser;
|
|||
import com.nflg.mobilebroken.repository.service.IAdminRoleService;
|
||||
import com.nflg.mobilebroken.repository.service.IAdminUserRoleMapService;
|
||||
import com.nflg.mobilebroken.repository.service.IAdminUserService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
|
|
@ -28,7 +27,7 @@ import java.util.Objects;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/admin")
|
||||
public class AdminController {
|
||||
public class AdminController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
private IAdminUserService adminUserService;
|
||||
|
|
@ -46,7 +45,8 @@ public class AdminController {
|
|||
* @return token
|
||||
*/
|
||||
@GetMapping("login")
|
||||
public ApiResult<SaTokenInfo> login(String userName, String password) {
|
||||
public ApiResult<SaTokenInfo> login(@Valid @NotBlank(message = "用户名不能为空") @RequestParam("userName") String userName,
|
||||
@Valid @NotBlank(message = "密码不能为空") @RequestParam("password") String password) {
|
||||
AdminUser user=adminUserService.getUser(userName,password);
|
||||
VUtils.trueThrow(Objects.isNull(user)).throwMessage(STATE.PassportErr,"用户名或密码错误");
|
||||
VUtils.trueThrow(!user.getEnable()).throwMessage(STATE.PassportErr, "用户被禁用,请联系管理员");
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import java.util.Objects;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/app")
|
||||
public class AppController {
|
||||
public class AppController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
IAppUserService appUserService;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package com.nflg.mobilebroken.auth.controller;
|
||||
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Validated
|
||||
@RestController
|
||||
public class ControllerBase {
|
||||
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@ import java.util.Objects;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/test")
|
||||
public class TestController {
|
||||
public class TestController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
private IAppUserService appUserService;
|
||||
|
|
|
|||
|
|
@ -65,6 +65,10 @@
|
|||
<groupId>com.nflg</groupId>
|
||||
<artifactId>nflg-mobilebroken-repository</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import java.util.List;
|
|||
@RestController
|
||||
@RequestMapping("/area")
|
||||
//@SaUserCheckLogin
|
||||
public class AreaController {
|
||||
public class AreaController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
private IAppAreaService appAreaService;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package com.nflg.mobilebroken.cfs.controller;
|
||||
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Validated
|
||||
@RestController
|
||||
public class ControllerBase {
|
||||
|
||||
}
|
||||
|
|
@ -28,7 +28,7 @@ import java.util.List;
|
|||
@RestController
|
||||
@RequestMapping("/file")
|
||||
//@SaUserCheckLogin
|
||||
public class FileController {
|
||||
public class FileController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
private FileUploadService fileUploadService;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import java.util.Map;
|
|||
@RestController
|
||||
@RequestMapping("/message")
|
||||
//@SaUserCheckLogin
|
||||
public class MessageController {
|
||||
public class MessageController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import java.io.IOException;
|
|||
@Slf4j
|
||||
@RequestMapping("/sse")
|
||||
//@SaUserCheckLogin
|
||||
public class SSEController {
|
||||
public class SSEController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
private APPSSEManagerService sseManagerService;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import java.util.stream.Collectors;
|
|||
@RestController
|
||||
@RequestMapping("/system")
|
||||
//@SaUserCheckLogin
|
||||
public class SystemController {
|
||||
public class SystemController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
private ILanguageService languageService;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import java.io.IOException;
|
|||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("/test")
|
||||
public class TestController {
|
||||
public class TestController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
private APPSSEManagerService sseManagerService;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import java.util.stream.Collectors;
|
|||
@RestController
|
||||
@RequestMapping("/ticket")
|
||||
//@SaUserCheckLogin
|
||||
public class TiketController {
|
||||
public class TiketController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
private IDeviceService deviceService;
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ import java.util.List;
|
|||
@RestController
|
||||
@RequestMapping("/user")
|
||||
//@SaUserCheckLogin
|
||||
public class UserController {
|
||||
public class UserController extends ControllerBase {
|
||||
|
||||
@Resource
|
||||
private IAppUserService appUserService;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.nflg.mobilebroken.starter.advice;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.nflg.mobilebroken.common.constant.STATE;
|
||||
import com.nflg.mobilebroken.common.exception.NflgException;
|
||||
import com.nflg.mobilebroken.common.pojo.ApiResult;
|
||||
|
|
@ -7,19 +8,29 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestControllerAdvice
|
||||
@Slf4j
|
||||
public class GlobalRestControllerAdvice {
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public ApiResult handleAllExceptions(Exception ex) {
|
||||
public ApiResult<Void> handleAllExceptions(Exception ex) {
|
||||
log.error("服务器内部错误: ", ex);
|
||||
return ApiResult.error(STATE.BusinessError,"服务器内部错误: " + ex.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(NflgException.class)
|
||||
public ApiResult handleNflgException(NflgException ex) {
|
||||
public ApiResult<Void> handleNflgException(NflgException ex) {
|
||||
log.error("业务错误: ", ex);
|
||||
return ApiResult.error(STATE.BusinessError,ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ExceptionHandler(ConstraintViolationException.class)
|
||||
public ApiResult<Void> handleConstraintViolationException(ConstraintViolationException ex) {
|
||||
log.error("数据校验失败: ", ex);
|
||||
return ApiResult.error(STATE.ParamErr, "数据校验失败: " + StrUtil.join(",", ex.getConstraintViolations().stream().map(ConstraintViolation::getMessage).collect(Collectors.toList())));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue