feat(新增): 全局异常拦截器添加主键异常
This commit is contained in:
parent
7fb81488f9
commit
53df9cb143
|
@ -5,7 +5,6 @@ import { $t } from '@/plugins/i18n';
|
|||
export const columns: TableColumnList = [
|
||||
{ type: 'selection', align: 'left' },
|
||||
{ type: 'index', index: (index: number) => index + 1, label: '序号', width: 60 },
|
||||
{ label: $t('id'), prop: 'id' },
|
||||
#foreach($field in $baseFieldList)
|
||||
// $field.annotation
|
||||
{ label: $t('${lowercaseName}_$field.name'), prop: '$field.name' },
|
||||
|
|
|
@ -24,8 +24,6 @@ public class GlobalExceptionHandler {
|
|||
@ExceptionHandler(BunnyException.class)
|
||||
@ResponseBody
|
||||
public Result<Object> exceptionHandler(BunnyException exception) {
|
||||
log.error("GlobalExceptionHandler===>自定义异常信息:{}", exception.getMessage());
|
||||
|
||||
Integer code = exception.getCode() != null ? exception.getCode() : 500;
|
||||
return Result.error(null, code, exception.getMessage());
|
||||
}
|
||||
|
@ -52,6 +50,13 @@ public class GlobalExceptionHandler {
|
|||
return Result.error(null, 500, dataTooLongErrorMatcher.group(1) + " 字段数据过大");
|
||||
}
|
||||
|
||||
// 主键冲突
|
||||
String primaryKeyError = "Duplicate entry '(.*?)' for key .*";
|
||||
Matcher primaryKeyErrorMatcher = Pattern.compile(primaryKeyError).matcher(message);
|
||||
if (primaryKeyErrorMatcher.find()) {
|
||||
return Result.error(null, 500, "主键值" + primaryKeyErrorMatcher.group(1) + "已存在");
|
||||
}
|
||||
|
||||
return Result.error(null, 500, "服务器异常");
|
||||
}
|
||||
|
||||
|
|
|
@ -16,9 +16,8 @@ import lombok.NoArgsConstructor;
|
|||
public class PowerAddDto {
|
||||
|
||||
@Schema(name = "id", title = "主键")
|
||||
@NotNull(message = "id不能为空")
|
||||
private Long id;
|
||||
|
||||
|
||||
@Schema(name = "parentId", title = "父级id")
|
||||
private Long parentId;
|
||||
|
||||
|
|
|
@ -59,9 +59,9 @@ public class PowerController {
|
|||
|
||||
@Operation(summary = "添加权限", description = "添加权限")
|
||||
@PostMapping("addPower")
|
||||
public Mono<Result<String>> addPower(@Valid @RequestBody PowerAddDto dto) {
|
||||
public Result<String> addPower(@Valid @RequestBody PowerAddDto dto) {
|
||||
powerService.addPower(dto);
|
||||
return Mono.just(Result.success(ResultCodeEnum.ADD_SUCCESS));
|
||||
return Result.success(ResultCodeEnum.ADD_SUCCESS);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新权限", description = "更新权限")
|
||||
|
|
|
@ -37,7 +37,7 @@ public class SchedulersController {
|
|||
@Autowired
|
||||
private SchedulersService schedulersService;
|
||||
|
||||
@Operation(summary = "分页查询Schedulers视图", description = "分页查询Schedulers视图")
|
||||
@Operation(summary = "分页查询视图", description = "分页查询视图")
|
||||
@GetMapping("getSchedulersList/{page}/{limit}")
|
||||
public Mono<Result<PageResult<SchedulersVo>>> getSchedulersList(
|
||||
@Parameter(name = "page", description = "当前页", required = true)
|
||||
|
@ -57,28 +57,28 @@ public class SchedulersController {
|
|||
return Mono.just(Result.success(mapList));
|
||||
}
|
||||
|
||||
@Operation(summary = "添加Schedulers任务", description = "添加Schedulers任务")
|
||||
@Operation(summary = "添加任务", description = "添加任务")
|
||||
@PostMapping("addSchedulers")
|
||||
public Mono<Result<String>> addSchedulers(@Valid @RequestBody SchedulersAddDto dto) {
|
||||
schedulersService.addSchedulers(dto);
|
||||
return Mono.just(Result.success(ResultCodeEnum.ADD_SUCCESS));
|
||||
}
|
||||
|
||||
@Operation(summary = "暂停Schedulers任务", description = "暂停任务")
|
||||
@Operation(summary = "暂停任务", description = "暂停任务")
|
||||
@PutMapping("/pauseScheduler")
|
||||
public Result<String> pause(@RequestBody SchedulersOperationDto dto) {
|
||||
schedulersService.pauseScheduler(dto);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "恢复Schedulers任务", description = "恢复任务")
|
||||
@Operation(summary = "恢复任务", description = "恢复任务")
|
||||
@PutMapping("/resumeScheduler")
|
||||
public Result<String> resume(@RequestBody SchedulersOperationDto dto) {
|
||||
schedulersService.resumeScheduler(dto);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "删除Schedulers任务", description = "删除任务")
|
||||
@Operation(summary = "删除任务", description = "删除任务")
|
||||
@DeleteMapping("/deleteSchedulers")
|
||||
public Mono<Result<Object>> deleteSchedulers(@RequestBody SchedulersOperationDto dto) {
|
||||
schedulersService.deleteSchedulers(dto);
|
||||
|
|
|
@ -76,8 +76,6 @@ public class PowerServiceImpl extends ServiceImpl<PowerMapper, Power> implements
|
|||
// 添加权限时确保权限码和请求地址是唯一的
|
||||
LambdaQueryWrapper<Power> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(Power::getPowerCode, dto.getPowerCode())
|
||||
.or()
|
||||
.eq(Power::getPowerName, dto.getPowerName())
|
||||
.or()
|
||||
.eq(Power::getRequestUrl, dto.getRequestUrl());
|
||||
List<Power> powerList = list(wrapper);
|
||||
|
|
|
@ -17,8 +17,8 @@ mybatis-plus:
|
|||
global-config:
|
||||
db-config:
|
||||
logic-delete-field: isDeleted
|
||||
configuration:
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 查看日志
|
||||
# configuration:
|
||||
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 查看日志
|
||||
|
||||
# rabbitmq:
|
||||
# host: ${bunny.rabbitmq.host}
|
||||
|
|
Loading…
Reference in New Issue