完善收支项目接口的重复提示

This commit is contained in:
jishenghua
2025-06-11 23:34:30 +08:00
parent 6d9bd40f65
commit e26e16d85b
3 changed files with 32 additions and 2 deletions

View File

@@ -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

View File

@@ -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<String, Object> objectMap = new HashMap<>();
int exist = inOutItemService.checkIsNameExist(id, name);

View File

@@ -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<InOutItem> 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);