|
|
@ -38,27 +38,17 @@ public class BillServiceImp implements BillService { |
|
|
if(!Optional.ofNullable(queryResult).isPresent()){ |
|
|
if(!Optional.ofNullable(queryResult).isPresent()){ |
|
|
throw new BusinessException(ErrorConstant.BILL_INVALID); |
|
|
throw new BusinessException(ErrorConstant.BILL_INVALID); |
|
|
} |
|
|
} |
|
|
|
|
|
if(queryResult.getPayAmount().compareTo(queryResult.getTotalAmount()) >= 0) |
|
|
|
|
|
throw new BusinessException(ErrorConstant.BILL_COMPLETE_PAYMENT); |
|
|
orderBO.setAmount(queryResult.getTotalAmount()); |
|
|
orderBO.setAmount(queryResult.getTotalAmount()); |
|
|
List<SaleBill> saleBillList = new ArrayList<>(); |
|
|
List<SaleBill> saleBillList = new ArrayList<>(); |
|
|
saleBillList.add(queryResult); |
|
|
saleBillList.add(queryResult); |
|
|
|
|
|
List<String> billIdList = new ArrayList<>(); |
|
|
|
|
|
billIdList.add(queryResult.getId()); |
|
|
|
|
|
orderBO.setBillIdList(billIdList); |
|
|
orderBO.setSaleBillList(saleBillList); |
|
|
orderBO.setSaleBillList(saleBillList); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 核销销售单据 |
|
|
|
|
|
* @param saleBillBO |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
@Override |
|
|
|
|
|
public void writeOffBill(SaleBillBO saleBillBO) { |
|
|
|
|
|
SaleBill saleBill = new SaleBill(); |
|
|
|
|
|
saleBill.setId(saleBillBO.getId()); |
|
|
|
|
|
saleBill.setPayAmount(saleBillBO.getPayAmount()); |
|
|
|
|
|
int count = saleBillMapper.writeOffBill(saleBill); |
|
|
|
|
|
if(count > 0) return; |
|
|
|
|
|
throw new BusinessException(ErrorConstant.BILL_WRITE_OFF_FAIL); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 销售单据合并 |
|
|
* 销售单据合并 |
|
|
* @param orderBO |
|
|
* @param orderBO |
|
|
@ -72,14 +62,18 @@ public class BillServiceImp implements BillService { |
|
|
String[] billIdArray = billIds.split(","); |
|
|
String[] billIdArray = billIds.split(","); |
|
|
List<SaleBill> billAmountList = saleBillMapper.mergeBill(billIdArray); |
|
|
List<SaleBill> billAmountList = saleBillMapper.mergeBill(billIdArray); |
|
|
if(!Optional.ofNullable(billAmountList).isPresent()) |
|
|
if(!Optional.ofNullable(billAmountList).isPresent()) |
|
|
throw new BusinessException(ErrorConstant.SALE_BILL__INVALID); |
|
|
throw new BusinessException(ErrorConstant.SALE_BILL_INVALID); |
|
|
BigDecimal orderAmount = new BigDecimal(0); |
|
|
BigDecimal orderAmount = new BigDecimal(0); |
|
|
List<String> billIdList = new ArrayList<>(); |
|
|
List<String> billIdList = new ArrayList<>(); |
|
|
billAmountList.forEach( |
|
|
for (SaleBill bill : billAmountList){ |
|
|
bill-> { |
|
|
if(bill.getPayAmount().compareTo(bill.getTotalAmount()) >= 0) |
|
|
billIdList.add(bill.getId()); |
|
|
continue; |
|
|
orderAmount.add(bill.getTotalAmount()); |
|
|
billIdList.add(bill.getId()); |
|
|
}); |
|
|
orderAmount = orderAmount.add(bill.getTotalAmount()); |
|
|
|
|
|
} |
|
|
|
|
|
if(orderAmount.compareTo(BigDecimal.ZERO) <= 0){ |
|
|
|
|
|
throw new BusinessException(ErrorConstant.ALL_BILL_COMPLETE_PAYMENT); |
|
|
|
|
|
} |
|
|
orderBO.setAmount(orderAmount); |
|
|
orderBO.setAmount(orderAmount); |
|
|
orderBO.setSaleBillList(billAmountList); |
|
|
orderBO.setSaleBillList(billAmountList); |
|
|
orderBO.setBillIdList(billIdList); |
|
|
orderBO.setBillIdList(billIdList); |
|
|
@ -92,21 +86,24 @@ public class BillServiceImp implements BillService { |
|
|
@Override |
|
|
@Override |
|
|
public void childBill(OrderBO orderBO,Boolean rootFlag) { |
|
|
public void childBill(OrderBO orderBO,Boolean rootFlag) { |
|
|
List<String> billIdList = orderBO.getBillIdList(); |
|
|
List<String> billIdList = orderBO.getBillIdList(); |
|
|
List<String> childBillIdList; |
|
|
List<String> queryBillIdList; |
|
|
if(rootFlag) |
|
|
if(rootFlag) |
|
|
childBillIdList = billIdList; |
|
|
queryBillIdList = billIdList; |
|
|
else |
|
|
else |
|
|
childBillIdList = orderBO.getChildIdList(); |
|
|
queryBillIdList = orderBO.getChildIdList(); |
|
|
BigDecimal amount = orderBO.getAmount(); |
|
|
if(null == queryBillIdList || queryBillIdList.size() == 0) return; |
|
|
List<SaleBill> saleBillList = saleBillMapper.childBill(childBillIdList); |
|
|
List<SaleBill> saleBillList = saleBillMapper.childBill(queryBillIdList); |
|
|
// 查询结果不存在结束流程
|
|
|
// 查询结果不存在结束流程
|
|
|
if(!Optional.ofNullable(saleBillList).isPresent()) return; |
|
|
if(null == saleBillList || saleBillList.size() == 0) return; |
|
|
childBillIdList.clear(); |
|
|
List<String> childBillIdList = new ArrayList<>(); |
|
|
saleBillList.forEach(saleBill -> { |
|
|
BigDecimal amount = orderBO.getAmount(); |
|
|
amount.add(saleBill.getTotalAmount()); |
|
|
for (SaleBill saleBill: saleBillList) { |
|
|
|
|
|
amount = amount.add(saleBill.getTotalAmount()); |
|
|
billIdList.add(saleBill.getId()); |
|
|
billIdList.add(saleBill.getId()); |
|
|
childBillIdList.add(saleBill.getId()); |
|
|
childBillIdList.add(saleBill.getId()); |
|
|
}); |
|
|
} |
|
|
|
|
|
// 金额设置
|
|
|
|
|
|
orderBO.setAmount(amount); |
|
|
// 所有的子单据编号需要存储
|
|
|
// 所有的子单据编号需要存储
|
|
|
orderBO.setBillIdList(billIdList); |
|
|
orderBO.setBillIdList(billIdList); |
|
|
// 重置需作为父节点查询的单据编号
|
|
|
// 重置需作为父节点查询的单据编号
|
|
|
@ -114,4 +111,11 @@ public class BillServiceImp implements BillService { |
|
|
// 递归
|
|
|
// 递归
|
|
|
childBill(orderBO,false); |
|
|
childBill(orderBO,false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void writeOffAmount(String orderId) { |
|
|
|
|
|
int count = saleBillMapper.writeOffBill(orderId); |
|
|
|
|
|
if(count > 0) return; |
|
|
|
|
|
throw new BusinessException(ErrorConstant.BILL_WRITE_OFF_FAIL); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|