提交单据的时候增加校验单号是否重复

This commit is contained in:
季圣华
2023-03-02 22:57:24 +08:00
parent d70be28df7
commit 4562b66fc3
7 changed files with 48 additions and 8 deletions

View File

@@ -88,7 +88,7 @@ public class AccountHeadComponent implements ICommonQuery {
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return accountHeadService.checkIsNameExist(id, name);
return 0;
}
}

View File

@@ -225,9 +225,16 @@ public class AccountHeadService {
return 1;
}
public int checkIsNameExist(Long id, String name)throws Exception {
/**
* 校验单据编号是否存在
* @param id
* @param billNo
* @return
* @throws Exception
*/
public int checkIsBillNoExist(Long id, String billNo)throws Exception {
AccountHeadExample example = new AccountHeadExample();
example.createCriteria().andIdNotEqualTo(id).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
example.createCriteria().andIdNotEqualTo(id).andBillNoEqualTo(billNo).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<AccountHead> list = null;
try{
list = accountHeadMapper.selectByExample(example);
@@ -273,6 +280,11 @@ public class AccountHeadService {
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void addAccountHeadAndDetail(String beanJson, String rows, HttpServletRequest request) throws Exception {
AccountHead accountHead = JSONObject.parseObject(beanJson, AccountHead.class);
//校验单号是否重复
if(checkIsBillNoExist(0L, accountHead.getBillNo())>0) {
throw new BusinessRunTimeException(ExceptionConstants.ACCOUNT_HEAD_BILL_NO_EXIST_CODE,
String.format(ExceptionConstants.ACCOUNT_HEAD_BILL_NO_EXIST_MSG));
}
User userInfo=userService.getCurrentUser();
accountHead.setCreator(userInfo==null?null:userInfo.getId());
if(StringUtil.isEmpty(accountHead.getStatus())) {
@@ -299,6 +311,11 @@ public class AccountHeadService {
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void updateAccountHeadAndDetail(String beanJson, String rows, HttpServletRequest request) throws Exception {
AccountHead accountHead = JSONObject.parseObject(beanJson, AccountHead.class);
//校验单号是否重复
if(checkIsBillNoExist(accountHead.getId(), accountHead.getBillNo())>0) {
throw new BusinessRunTimeException(ExceptionConstants.ACCOUNT_HEAD_BILL_NO_EXIST_CODE,
String.format(ExceptionConstants.ACCOUNT_HEAD_BILL_NO_EXIST_MSG));
}
//获取之前的金额数据
BigDecimal preTotalPrice = getAccountHead(accountHead.getId()).getTotalPrice().abs();
accountHeadMapper.updateByPrimaryKeySelective(accountHead);

View File

@@ -96,7 +96,7 @@ public class DepotHeadComponent implements ICommonQuery {
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return depotHeadService.checkIsNameExist(id, name);
return 0;
}
}

View File

@@ -515,9 +515,16 @@ public class DepotHeadService {
return list;
}
public int checkIsNameExist(Long id, String name)throws Exception {
/**
* 校验单据编号是否存在
* @param id
* @param number
* @return
* @throws Exception
*/
public int checkIsBillNumberExist(Long id, String number)throws Exception {
DepotHeadExample example = new DepotHeadExample();
example.createCriteria().andIdNotEqualTo(id).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
example.createCriteria().andIdNotEqualTo(id).andNumberEqualTo(number).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<DepotHead> list = null;
try{
list = depotHeadMapper.selectByExample(example);
@@ -894,6 +901,11 @@ public class DepotHeadService {
HttpServletRequest request) throws Exception {
/**处理单据主表数据*/
DepotHead depotHead = JSONObject.parseObject(beanJson, DepotHead.class);
//校验单号是否重复
if(checkIsBillNumberExist(0L, depotHead.getNumber())>0) {
throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_BILL_NUMBER_EXIST_CODE,
String.format(ExceptionConstants.DEPOT_HEAD_BILL_NUMBER_EXIST_MSG));
}
String subType = depotHead.getSubType();
//结算账户校验
if("采购".equals(subType) || "采购退货".equals(subType) || "销售".equals(subType) || "销售退货".equals(subType)) {
@@ -984,6 +996,11 @@ public class DepotHeadService {
public void updateDepotHeadAndDetail(String beanJson, String rows,HttpServletRequest request)throws Exception {
/**更新单据主表信息*/
DepotHead depotHead = JSONObject.parseObject(beanJson, DepotHead.class);
//校验单号是否重复
if(checkIsBillNumberExist(depotHead.getId(), depotHead.getNumber())>0) {
throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_BILL_NUMBER_EXIST_CODE,
String.format(ExceptionConstants.DEPOT_HEAD_BILL_NUMBER_EXIST_MSG));
}
//获取之前的金额数据
BigDecimal preTotalPrice = getDepotHead(depotHead.getId()).getTotalPrice().abs();
String subType = depotHead.getSubType();