From e26e16d85bc343d9af4b027e85e6411eb11bf063 Mon Sep 17 00:00:00 2001 From: jishenghua <752718920@qq.com> Date: Wed, 11 Jun 2025 23:34:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=94=B6=E6=94=AF=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=8E=A5=E5=8F=A3=E7=9A=84=E9=87=8D=E5=A4=8D=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jsh/erp/constants/ExceptionConstants.java | 3 +++ .../erp/controller/InOutItemController.java | 5 ++-- .../com/jsh/erp/service/InOutItemService.java | 26 +++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) 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);