Commit 881a6658 by zhangkb

自定义异常

parent 67c93692
...@@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.ResponseStatus; ...@@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.keymobile.indicators.constant.Constants; import com.keymobile.indicators.constant.Constants;
import com.keymobile.indicators.exception.ApiException;
import com.keymobile.indicators.model.entity.indicators.DriveIndCatalog; import com.keymobile.indicators.model.entity.indicators.DriveIndCatalog;
import com.keymobile.indicators.model.entity.indicators.IndCatalog; import com.keymobile.indicators.model.entity.indicators.IndCatalog;
import com.keymobile.indicators.service.hytobacco.DriveIndCatalogService; import com.keymobile.indicators.service.hytobacco.DriveIndCatalogService;
...@@ -31,9 +32,8 @@ public class IndCatalogCtrl { ...@@ -31,9 +32,8 @@ public class IndCatalogCtrl {
private DriveIndCatalogService driveIndCatalogService; private DriveIndCatalogService driveIndCatalogService;
@ApiOperation(value = "新建基础指标目录", notes = "新建基础指标目录") @ApiOperation(value = "新建基础指标目录", notes = "新建基础指标目录")
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
@PostMapping(value = "/createBaseIndCatalog") @PostMapping(value = "/createBaseIndCatalog")
public Integer createBaseIndCatalog(@RequestBody IndCatalog indCatalog) throws Exception{ public Integer createBaseIndCatalog(@RequestBody IndCatalog indCatalog) throws ApiException{
String message = null; String message = null;
if(indCatalog.getId()==null) { if(indCatalog.getId()==null) {
message = "新增基础项目录:{}"; message = "新增基础项目录:{}";
......
package com.keymobile.indicators.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
public class ApiException extends Exception{
public ApiException(String msg) {
super(msg);
}
}
...@@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory; ...@@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.keymobile.indicators.exception.ApiException;
import com.keymobile.indicators.model.entity.indicators.IndCatalog; import com.keymobile.indicators.model.entity.indicators.IndCatalog;
import com.keymobile.indicators.model.mapper.indicators.BaseIndDefMapper; import com.keymobile.indicators.model.mapper.indicators.BaseIndDefMapper;
import com.keymobile.indicators.model.mapper.indmapper.IndCatalogMapper; import com.keymobile.indicators.model.mapper.indmapper.IndCatalogMapper;
...@@ -24,11 +25,11 @@ public class IndCatalogService { ...@@ -24,11 +25,11 @@ public class IndCatalogService {
@Autowired @Autowired
private BaseIndDefMapper baseIndDefMapper; private BaseIndDefMapper baseIndDefMapper;
public IndCatalog saveOrUpdate(IndCatalog indCatalog) throws Exception{ public IndCatalog saveOrUpdate(IndCatalog indCatalog) throws ApiException{
if(indCatalog.getId()==null) {//新增 if(indCatalog.getId()==null) {//新增
if(!indCatalogMapper.findIsExist(indCatalog.getCatalogName(), indCatalog.getParentId(), if(!indCatalogMapper.findIsExist(indCatalog.getCatalogName(), indCatalog.getParentId(),
indCatalog.getCode()).isEmpty()) { indCatalog.getCode()).isEmpty()) {
throw new Exception("存在同名目录"); throw new ApiException("存在同名目录");
} }
//保存 //保存
indCatalogMapper.insert(indCatalog); indCatalogMapper.insert(indCatalog);
...@@ -36,7 +37,7 @@ public class IndCatalogService { ...@@ -36,7 +37,7 @@ public class IndCatalogService {
List<IndCatalog> dbList = indCatalogMapper.findIsExist(indCatalog.getCatalogName(), indCatalog.getParentId(), List<IndCatalog> dbList = indCatalogMapper.findIsExist(indCatalog.getCatalogName(), indCatalog.getParentId(),
indCatalog.getCode()); indCatalog.getCode());
if(!dbList.isEmpty() && !dbList.get(0).getId().equals(indCatalog.getId())) { if(!dbList.isEmpty() && !dbList.get(0).getId().equals(indCatalog.getId())) {
throw new Exception("存在同名目录"); throw new ApiException("存在同名目录");
} }
} }
//获取parentId拼接idPath //获取parentId拼接idPath
...@@ -46,7 +47,7 @@ public class IndCatalogService { ...@@ -46,7 +47,7 @@ public class IndCatalogService {
}else { }else {
IndCatalog parentIndCatalog = indCatalogMapper.selectByPrimaryKey(indCatalog.getParentId()); IndCatalog parentIndCatalog = indCatalogMapper.selectByPrimaryKey(indCatalog.getParentId());
if(parentIndCatalog==null) { if(parentIndCatalog==null) {
throw new Exception("父节点不存在:parent catalog is not exist"); throw new ApiException("父节点不存在:parent catalog is not exist");
}else { }else {
indCatalog.setIdPath(parentIndCatalog.getIdPath()+indCatalog.getId()+";"); indCatalog.setIdPath(parentIndCatalog.getIdPath()+indCatalog.getId()+";");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment