提交代码

master
rong.liu 2 years ago
parent 3ebc8cdf60
commit 0f85c6f0e2
  1. 20
      src/main/java/com/huoran/iasf/common/exception/NotFoundException.java
  2. 4
      src/main/java/com/huoran/iasf/common/exception/code/BaseResponseCode.java
  3. 9
      src/main/java/com/huoran/iasf/common/exception/handler/RestExceptionHandler.java
  4. 15
      src/main/java/com/huoran/iasf/controller/SysContentController.java

@ -0,0 +1,20 @@
package com.huoran.iasf.common.exception;
import com.huoran.iasf.common.exception.code.BaseResponseCode;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
/**
* BusinessException
*
* @author cheney
* @version V1.0
* @date 2022年7月28日
*/
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class NotFoundException extends RuntimeException {
private BaseResponseCode baseResponseCode;
}

@ -51,7 +51,9 @@ public enum BaseResponseCode implements ResponseCodeInterface {
OPERATION_MENU_PERMISSION_URL_NOT_NULL(401015, "菜单权限的url不能为空"),
OPERATION_MENU_PERMISSION_URL_PERMS_NULL(401016, "菜单权限的标识符不能为空"),
ROLE_ERROR(401017, "账号角色被删,请联系管理员添加角色后再试"),
EXCEL_FILE_NULL(40006, "导入失败,导入数据为空!")
EXCEL_FILE_NULL(40006, "导入失败,导入数据为空!"),
DATA_DOES_NOT_EXIST(500, "当前数据不存在"),
;
/**

@ -2,6 +2,7 @@ package com.huoran.iasf.common.exception.handler;
import com.google.common.collect.Maps;
import com.huoran.iasf.common.exception.BusinessException;
import com.huoran.iasf.common.exception.NotFoundException;
import com.huoran.iasf.common.exception.code.BaseResponseCode;
import com.huoran.iasf.common.utils.R;
import lombok.extern.slf4j.Slf4j;
@ -69,6 +70,14 @@ public class RestExceptionHandler {
return new R(em.getCode(), em.getMsg());
}
@ExceptionHandler(value = NotFoundException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public R businessExceptionHandler(NotFoundException e) {
log.error("Exception,exception:{}", e, e);
BaseResponseCode em = e.getBaseResponseCode();
return new R(em.getCode(), em.getMsg());
}
/**
* 没有权限 返回403视图
*/

@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.huoran.iasf.common.exception.NotFoundException;
import com.huoran.iasf.common.exception.code.BaseResponseCode;
import com.huoran.iasf.entity.SysColumn;
import com.huoran.iasf.entity.SysContentFile;
import com.huoran.iasf.entity.SysFilesEntity;
@ -70,15 +72,24 @@ public class SysContentController {
@PostMapping("/findById")
@ApiOperation(value = "查询详情", response = SysContent.class)
public R findById(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id) {
SysContent sysContent = service.getById(id);
if (sysContent == null) {
throw new NotFoundException(BaseResponseCode.DATA_DOES_NOT_EXIST);
}
SysColumn sysColumn = columnService.getById(sysContent.getColumnId());
if (sysColumn == null) {
throw new NotFoundException(BaseResponseCode.DATA_DOES_NOT_EXIST);
}
if (sysColumn.getColumnName() != null) {
sysContent.setColumnName(sysColumn.getColumnName());
}
List<SysContentFile> fileList = fileService.getFileByContentId(id);
sysContent.setFileList(fileList);
return R.success(sysContent);
}
@ -265,9 +276,7 @@ public class SysContentController {
@PostMapping("/modifiedSort")
@ApiOperation(value = "修改排序", response = SysContent.class)
public R modifiedSort(
@ApiParam(name = "sequenceNumber", value = "要排序的序号", required = true) @RequestParam Integer sequenceNumber,
@ApiParam(name = "articleId", value = "文章Id", required = true) @RequestParam Integer articleId) {
public R modifiedSort(@ApiParam(name = "sequenceNumber", value = "要排序的序号", required = true) @RequestParam Integer sequenceNumber, @ApiParam(name = "articleId", value = "文章Id", required = true) @RequestParam Integer articleId) {
return service.modifiedSort(sequenceNumber, articleId);
}

Loading…
Cancel
Save