Commit 728dc489 by zhangkb

提交改变接口httpStatus代码

parent fdb461f0
package com.keymobile.indicators.api.hytobacco;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
......@@ -13,7 +12,6 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
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.IndCatalog;
import com.keymobile.indicators.service.hytobacco.DriveIndCatalogService;
......@@ -93,14 +91,20 @@ public class IndCatalogCtrl {
//考核指标目录
@ApiOperation(value = "新建考核指标目录", notes = "新建考核指标目录")
@PostMapping(value = "/createDriveIndCatalog")
public Integer createDriveIndCatalog(@RequestBody DriveIndCatalog driveIndCatalog) throws Exception{
public Integer createDriveIndCatalog(@RequestBody DriveIndCatalog driveIndCatalog,
HttpServletResponse response) throws Exception{
String message = null;
if(driveIndCatalog.getId()==null) {
message = "新增考核指标目录:{}";
}else {
message = "修改考核指标目录:{}";
}
driveIndCatalog = driveIndCatalogService.saveOrUpdate(driveIndCatalog);
try {
driveIndCatalog = driveIndCatalogService.saveOrUpdate(driveIndCatalog);
} catch (Exception e) {
response.sendError(500);
throw new Exception(e.getMessage());
}
LogManager.logInfo(Constants.LOG_INDICATOR_DRIVE_INDI_API,message,driveIndCatalog.getCatalogName());
return driveIndCatalog.getId();
}
......
......@@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -33,14 +35,20 @@ public class IndScorecardCtrl {
@ApiOperation(value = "新增/修改评分卡目录", notes = "新增/修改评分卡目录")
@PostMapping(value = "/saveOrUpdateCatalog")
public Integer saveOrUpdateCatalog(@RequestBody ScorecardCatalog scorecardCatalog)throws Exception{
public Integer saveOrUpdateCatalog(@RequestBody ScorecardCatalog scorecardCatalog,
HttpServletResponse response)throws Exception{
String message = null;
if(scorecardCatalog.getId()==null) {
message = "新增指标计分规则目录:{}";
}else {
message = "修改指标计分规则目录:{}";
}
scorecardCatalog = scorecardCatalogService.saveOrUpdate(scorecardCatalog);
try {
scorecardCatalog = scorecardCatalogService.saveOrUpdate(scorecardCatalog);
} catch (Exception e) {
response.sendError(500);
throw new Exception(e.getMessage());
}
LogManager.logInfo(Constants.LOG_INDICATOR_SCORECARD_API,message,scorecardCatalog.getCatalogName());
return scorecardCatalog.getId();
}
......
......@@ -3,6 +3,8 @@ package com.keymobile.indicators.api.hytobacco;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -56,15 +58,23 @@ public class IndicatorsDefCtrl {
@ApiOperation(value = "新建基础指标(isUpdate:0 新增 1修改)", notes = "新建基础指标(isUpdate:0 新增 1修改)")
@PostMapping(value = "/createBaseInd")
public void createBaseInd(@RequestBody BaseIndDef baseIndDef,@RequestParam Integer catalogId,
public String createBaseInd(@RequestBody BaseIndDef baseIndDef,@RequestParam Integer catalogId,
@RequestParam String catalogIdPath,@RequestParam String user,
@RequestParam String isUpdate,@RequestParam String code) throws Exception{
baseIndDefService.saveOrUpdate(baseIndDef, catalogId, catalogIdPath, user, isUpdate, code);
if("0".equals(isUpdate)) {
LogManager.logInfo(Constants.LOG_INDICATOR_BASE_INDI_API,"新增基础项:{}",baseIndDef.getIndName());
}else {
LogManager.logInfo(Constants.LOG_INDICATOR_BASE_INDI_API,"修改基础项:{}",baseIndDef.getIndName());
@RequestParam String isUpdate,@RequestParam String code,
HttpServletResponse response) throws Exception{
String result = null;
try {
result = baseIndDefService.saveOrUpdate(baseIndDef, catalogId, catalogIdPath, user, isUpdate, code);
if("0".equals(isUpdate)) {
LogManager.logInfo(Constants.LOG_INDICATOR_BASE_INDI_API,"新增基础项:{}",baseIndDef.getIndName());
}else {
LogManager.logInfo(Constants.LOG_INDICATOR_BASE_INDI_API,"修改基础项:{}",baseIndDef.getIndName());
}
} catch (Exception e) {
response.sendError(500);
throw new Exception(e.getMessage());
}
return result;
}
@ApiOperation(value = "删除基础指标", notes = "删除基础指标")
......@@ -119,13 +129,21 @@ public class IndicatorsDefCtrl {
@PostMapping(value = "/createDriveInd")
public String createDriveInd(@RequestBody DriveIndDef driveIndDef,@RequestParam String code,@RequestParam Integer catalogId,
@RequestParam String catalogIdPath,@RequestParam String user,@RequestParam String isUpdate,
@RequestParam(required=false) String shortboardIds) throws Exception{
if("0".equals(isUpdate)) {
LogManager.logInfo(Constants.LOG_INDICATOR_DRIVE_INDI_API,"新增考核指标:{}",driveIndDef.getIndName());
}else {
LogManager.logInfo(Constants.LOG_INDICATOR_DRIVE_INDI_API,"新增考核指标:{}",driveIndDef.getIndName());
@RequestParam(required=false) String shortboardIds,
HttpServletResponse response) throws Exception{
String result = null;
try {
result = driveIndDefService.saveOrUpdate(driveIndDef, code, catalogId, catalogIdPath, user, isUpdate, shortboardIds);
if("0".equals(isUpdate)) {
LogManager.logInfo(Constants.LOG_INDICATOR_DRIVE_INDI_API,"新增考核指标:{}",driveIndDef.getIndName());
}else {
LogManager.logInfo(Constants.LOG_INDICATOR_DRIVE_INDI_API,"新增考核指标:{}",driveIndDef.getIndName());
}
} catch (Exception e) {
response.sendError(500);
throw new Exception(e.getMessage());
}
return driveIndDefService.saveOrUpdate(driveIndDef, code, catalogId, catalogIdPath, user, isUpdate, shortboardIds);
return result;
}
@ApiOperation(value = "删除考核指标", notes = "删除考核指标")
......
......@@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -33,14 +35,20 @@ public class ObjScoreRuleCtrl {
@ApiOperation(value = "新增/修改单位规则目录", notes = "新增/修改单位规则目录")
@PostMapping(value = "/saveOrUpdateCatalog")
public Integer saveOrUpdateCatalog(@RequestBody ScoreRuleCatalog scoreRuleCatalog)throws Exception{
public Integer saveOrUpdateCatalog(@RequestBody ScoreRuleCatalog scoreRuleCatalog,
HttpServletResponse response)throws Exception{
String message = null;
if(scoreRuleCatalog.getId()==null) {
message = "新增单位得分规则目录:{}";
}else {
message = "修改单位得分规则目录:{}";
}
scoreRuleCatalog = scoreRuleCatalogService.saveOrUpdate(scoreRuleCatalog);
try {
scoreRuleCatalog = scoreRuleCatalogService.saveOrUpdate(scoreRuleCatalog);
} catch (Exception e) {
response.sendError(500);
throw new Exception(e.getMessage());
}
LogManager.logInfo(Constants.LOG_INDICATOR_OBJ_SCORERULE_API,message,scoreRuleCatalog.getCatalogName());
return scoreRuleCatalog.getId();
}
......
......@@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -33,14 +35,20 @@ public class ShortboardRuleCtrl {
@ApiOperation(value = "新增/修改短板筛选规则目录", notes = "新增/修改短板筛选规则目录")
@PostMapping(value = "/saveOrUpdateCatalog")
public Integer saveOrUpdateCatalog(@RequestBody ShortboardCatalog shortboardCatalog)throws Exception{
public Integer saveOrUpdateCatalog(@RequestBody ShortboardCatalog shortboardCatalog,
HttpServletResponse response)throws Exception{
String message = null;
if(shortboardCatalog.getId()==null) {
message = "新增短板筛选规则目录:{}";
}else {
message = "修改短板筛选规则目录:{}";
}
shortboardCatalog = shortboardCatalogService.saveOrUpdate(shortboardCatalog);
try {
shortboardCatalog = shortboardCatalogService.saveOrUpdate(shortboardCatalog);
} catch (Exception e) {
response.sendError(500);
throw new Exception(e.getMessage());
}
LogManager.logInfo(Constants.LOG_INDICATOR_SHORTBOARD_RULE_API,message,shortboardCatalog.getCatalogName());
return shortboardCatalog.getId();
}
......
......@@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -37,14 +39,20 @@ public class ShortboardUnitCtrl {
@ApiOperation(value = "新增/修改短板筛选单元目录", notes = "新增/修改短板筛选单元目录")
@PostMapping(value = "/saveOrUpdateCatalog")
public Integer saveOrUpdateCatalog(@RequestBody ShortboardUnitCatalog shortboardUnitCatalog)throws Exception{
public Integer saveOrUpdateCatalog(@RequestBody ShortboardUnitCatalog shortboardUnitCatalog,
HttpServletResponse response)throws Exception{
String message = null;
if(shortboardUnitCatalog.getId()==null) {
message = "新增短板规则目录:{}";
}else {
message = "修改短板规则目录:{}";
}
shortboardUnitCatalog = shortboardUnitCatalogService.saveOrUpdate(shortboardUnitCatalog);
try {
shortboardUnitCatalog = shortboardUnitCatalogService.saveOrUpdate(shortboardUnitCatalog);
} catch (Exception e) {
response.sendError(500);
throw new Exception(e.getMessage());
}
LogManager.logInfo(Constants.LOG_INDICATOR_SHORTBOARD_UNIT_API,message,shortboardUnitCatalog.getCatalogName());
return shortboardUnitCatalog.getId();
}
......
package com.keymobile.indicators.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR,reason="server error")
public class ApiException extends Exception{
public ApiException(String msg) {
super(msg);
}
}
......@@ -31,16 +31,16 @@ public class BaseIndDefService {
//判断公式合法性
if(StringUtils.isNotBlank(baseIndDef.getIndFormat()) &&
!CalculateUtils.isValidformula(baseIndDef.getIndFormat())) {
return "formula is not valid";
throw new Exception("公式校验不合法");
}
if(StringUtils.isBlank(baseIndDef.getIndId())) {
return "indId can not be null";
throw new Exception("数据项编号不能为空");
}
//如果是新增,需要判断库中是否已存在指标编号
if("0".equals(isUpdate)) {//新增
BaseIndDef dbBaseIndDef = this.getById(baseIndDef.getIndId());
if(dbBaseIndDef!=null) {
return "indId is exist,create base indicators fail";
throw new Exception("数据项编号已存在,新增基础数据项失败");
}else {
baseIndDef.setCreater(user);
baseIndDef.setCreateTime(new Date());
......@@ -68,7 +68,7 @@ public class BaseIndDefService {
baseIndDefMapper.updateByPrimaryKey(baseIndDef);
}
}else {
return "base ind is not exist,update ind fail";
throw new Exception("数据项已存在,修改失败");
}
}
//保存或修改指标关系
......
......@@ -43,15 +43,15 @@ public class DriveIndDefService {
//判断公式合法性
if(StringUtils.isNotBlank(driveIndDef.getIndFormat()) &&
!CalculateUtils.isValidformula(driveIndDef.getIndFormat())) {
return "formula is not valid";
throw new Exception("校验公式不合法");
}
if(StringUtils.isBlank(driveIndDef.getIndId())) {
return "indId can not be null";
throw new Exception("指标编号不能为空");
}
if("0".equals(isUpdate)) {//新建
DriveIndDef dbDriveIndDef = this.getById(driveIndDef.getIndId());
if(dbDriveIndDef!=null) {
return "indId is exist,create drive indicators fail";
throw new Exception("指标编号存在,新增指标失败");
}else {
driveIndDef.setCreater(user);
driveIndDef.setCreateTime(new Date());
......@@ -79,7 +79,7 @@ public class DriveIndDefService {
driveIndDefMapper.updateByPrimaryKey(driveIndDef);
}
}else {
return "drive ind is not exist,update ind fail";
throw new Exception("指标不存在,修改失败");
}
}
//插入短板筛选规则
......
......@@ -11,7 +11,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.keymobile.indicators.exception.ApiException;
import com.keymobile.indicators.model.entity.indicators.IndCatalog;
import com.keymobile.indicators.model.mapper.indicators.BaseIndDefMapper;
import com.keymobile.indicators.model.mapper.indmapper.IndCatalogMapper;
......
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