diff --git a/jshERP-boot/src/main/java/com/jsh/erp/constants/ExceptionConstants.java b/jshERP-boot/src/main/java/com/jsh/erp/constants/ExceptionConstants.java index a132a761..2face8d4 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/constants/ExceptionConstants.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/constants/ExceptionConstants.java @@ -146,6 +146,9 @@ public class ExceptionConstants { //修改收支项目信息失败 public static final int IN_OUT_ITEM_EDIT_FAILED_CODE = 3500002; public static final String IN_OUT_ITEM_EDIT_FAILED_MSG = "修改收支项目信息失败"; + //该收支项目的名称已经存在 + public static final int IN_OUT_ITEM_NAME_EXIST_FAILED_CODE = 3500003; + public static final String IN_OUT_ITEM_NAME_EXIST_FAILED_MSG = "该收支项目的名称已经存在,请修改!"; /** * 多单位信息 * type = 40 diff --git a/jshERP-boot/src/main/java/com/jsh/erp/controller/InOutItemController.java b/jshERP-boot/src/main/java/com/jsh/erp/controller/InOutItemController.java index 6a33dfe9..2a0b9eb2 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/controller/InOutItemController.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/controller/InOutItemController.java @@ -94,8 +94,9 @@ public class InOutItemController extends BaseController { } @GetMapping(value = "/checkIsNameExist") - @ApiOperation(value = "检查名称是否存在") - public String checkIsNameExist(@RequestParam Long id, @RequestParam(value ="name", required = false) String name, + @ApiOperation(value = "检查名称是否存在-后续废弃") + public String checkIsNameExist(@RequestParam Long id, + @RequestParam(value ="name", required = false) String name, HttpServletRequest request)throws Exception { Map objectMap = new HashMap<>(); int exist = inOutItemService.checkIsNameExist(id, name); diff --git a/jshERP-boot/src/main/java/com/jsh/erp/service/InOutItemService.java b/jshERP-boot/src/main/java/com/jsh/erp/service/InOutItemService.java index efaf043b..1bc46cf9 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/service/InOutItemService.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/service/InOutItemService.java @@ -92,6 +92,12 @@ public class InOutItemService { @Transactional(value = "transactionManager", rollbackFor = Exception.class) public int insertInOutItem(JSONObject obj, HttpServletRequest request)throws Exception { InOutItem inOutItem = JSONObject.parseObject(obj.toJSONString(), InOutItem.class); + int exist = checkIsNameAndTypeExist(inOutItem.getId(), inOutItem.getName(), inOutItem.getType()); + if(exist>0) { + //存在 + throw new BusinessRunTimeException(ExceptionConstants.IN_OUT_ITEM_NAME_EXIST_FAILED_CODE, + ExceptionConstants.IN_OUT_ITEM_NAME_EXIST_FAILED_MSG); + } int result=0; try{ inOutItem.setEnabled(true); @@ -107,6 +113,12 @@ public class InOutItemService { @Transactional(value = "transactionManager", rollbackFor = Exception.class) public int updateInOutItem(JSONObject obj, HttpServletRequest request)throws Exception { InOutItem inOutItem = JSONObject.parseObject(obj.toJSONString(), InOutItem.class); + int exist = checkIsNameAndTypeExist(inOutItem.getId(), inOutItem.getName(), inOutItem.getType()); + if(exist>0) { + //存在 + throw new BusinessRunTimeException(ExceptionConstants.IN_OUT_ITEM_NAME_EXIST_FAILED_CODE, + ExceptionConstants.IN_OUT_ITEM_NAME_EXIST_FAILED_MSG); + } int result=0; try{ result=inOutItemMapper.updateByPrimaryKeySelective(inOutItem); @@ -163,6 +175,20 @@ public class InOutItemService { return result; } + public int checkIsNameAndTypeExist(Long id, String name, String type)throws Exception { + id = id==null?0L:id; + InOutItemExample example = new InOutItemExample(); + example.createCriteria().andIdNotEqualTo(id).andNameEqualTo(name).andTypeEqualTo(type).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); + List list = null; + try{ + list=inOutItemMapper.selectByExample(example); + }catch(Exception e){ + JshException.readFail(logger, e); + } + + return list==null?0:list.size(); + } + public int checkIsNameExist(Long id, String name)throws Exception { InOutItemExample example = new InOutItemExample(); example.createCriteria().andIdNotEqualTo(id).andNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);