|
|
@ -65,7 +65,7 @@ public class PayPaymentServiceImpl extends ServiceImpl<PayPaymentMapper,PayPayme |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public PayPayment payment(PayPaymentBo paymentBo) { |
|
|
|
String payType = paymentBo.getPayType(); |
|
|
|
if(!payType.equals(PaymentType.PAYMENT)&&!payType.equals(PaymentType.UN_PAYMENT)){ |
|
|
|
if(!payType.equals(PaymentType.PAYMENT)){ |
|
|
|
Assert.throwEx("支付类型异常"); |
|
|
|
} |
|
|
|
|
|
|
@ -81,42 +81,34 @@ public class PayPaymentServiceImpl extends ServiceImpl<PayPaymentMapper,PayPayme |
|
|
|
} |
|
|
|
|
|
|
|
LambdaQueryWrapper<VtbVerification> vtbLqw = new LambdaQueryWrapper<>(); |
|
|
|
vtbLqw.eq(VtbVerification::getVerificationMainCode,paymentBo.getVerificationSubCode()); |
|
|
|
vtbLqw.eq(VtbVerification::getVerificationCode,paymentBo.getVerificationSubCode()); |
|
|
|
List<VtbVerification> verificationList = verificationService.list(vtbLqw); |
|
|
|
// if(verificationList.size()==0){
|
|
|
|
// Assert.throwEx("核销编码异常");
|
|
|
|
// }
|
|
|
|
|
|
|
|
VtbVerificationSubject vtbSub = verificationSubjectService.getByVerificationSubjectCode(paymentBo.getVerificationSubCode()); |
|
|
|
if(vtbSub==null && verificationList.size()==0){ |
|
|
|
Assert.throwEx("核销编码异常"); |
|
|
|
} |
|
|
|
if(verificationList.size()==0){ |
|
|
|
String verificationCode = paymentBo.getVerificationSubCode(); |
|
|
|
|
|
|
|
LambdaQueryWrapper<PayPaymentItem> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
lambdaQueryWrapper.eq(PayPaymentItem::getVerificationMainCode,paymentBo.getVerificationSubCode()); |
|
|
|
List<PayPaymentItem> payPaymentItemList = paymentItemService.list(lambdaQueryWrapper); |
|
|
|
BigDecimal payedAmount = payPaymentItemList.stream().map(a->a.getItemPayAmount()).reduce(BigDecimal.ZERO,BigDecimal::add); |
|
|
|
BigDecimal verificationAmount = null; |
|
|
|
if(vtbSub!=null){ |
|
|
|
verificationAmount = vtbSub.getUsedAmount(); |
|
|
|
}else if(verificationList.size()!=0) { |
|
|
|
verificationAmount = verificationList.stream().map(a -> a.getAmount()).reduce(BigDecimal.ZERO, BigDecimal::add); |
|
|
|
}else{ |
|
|
|
Assert.throwEx("核销金额异常"); |
|
|
|
String verificationMainCode = verificationCode; |
|
|
|
if(verificationCode.contains("_")) { |
|
|
|
verificationMainCode = verificationCode.substring(0, verificationCode.indexOf("_")); |
|
|
|
} |
|
|
|
LambdaQueryWrapper<VtbVerification> vtbMainLqw = new LambdaQueryWrapper<>(); |
|
|
|
vtbMainLqw.eq(VtbVerification::getVerificationMainCode,verificationMainCode); |
|
|
|
verificationList = verificationService.list(vtbMainLqw); |
|
|
|
if(verificationList.size()==0){ |
|
|
|
Assert.throwEx("没有找到核销:"+ paymentBo.getVerificationSubCode()); |
|
|
|
} |
|
|
|
} |
|
|
|
BigDecimal notPayAmount = verificationAmount.subtract(payedAmount); |
|
|
|
|
|
|
|
BigDecimal payAmount = paymentBo.getPayAmount(); |
|
|
|
if(paymentBo.getPayAmount()==null){ |
|
|
|
Assert.throwEx("支付金额不能为空!"); |
|
|
|
} |
|
|
|
|
|
|
|
if(paymentBo.getPayAmount().compareTo(notPayAmount)>0){ |
|
|
|
Assert.throwEx("支付金额已超出可支付额"); |
|
|
|
if(payAmount.compareTo(BigDecimal.ZERO)<=0){ |
|
|
|
Assert.throwEx("支付金额小于或等于0:"+paymentBo.getErpId()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
PayPayment payPayment = new PayPayment(); |
|
|
|
payPayment.setPayType(paymentBo.getPayType()); |
|
|
|
payPayment.setPayType(PaymentType.PAYMENT); |
|
|
|
payPayment.setPayCode(paymentBo.getErpId()); |
|
|
|
payPayment.setPayAmount(paymentBo.getPayAmount()); |
|
|
|
payPayment.setUserId(sysUser.getId()); |
|
|
@ -129,50 +121,58 @@ public class PayPaymentServiceImpl extends ServiceImpl<PayPaymentMapper,PayPayme |
|
|
|
payPayment.setTenantId("001"); |
|
|
|
payPayment.setErpId(paymentBo.getErpId()); |
|
|
|
|
|
|
|
if(vtbSub!=null) { |
|
|
|
payPayment.setSupplierId(vtbSub.getSupplierId()); |
|
|
|
payPayment.setSupplierCode(vtbSub.getSupplierCode()); |
|
|
|
payPayment.setSupplierName(vtbSub.getSupplierName()); |
|
|
|
payPayment.setCostApplyId(vtbSub.getCostApplyId()); |
|
|
|
}else if(verificationList.size()>0) { |
|
|
|
VtbVerification vtbMain = verificationList.get(0); |
|
|
|
payPayment.setSupplierId(vtbMain.getSupplierId()); |
|
|
|
payPayment.setSupplierCode(vtbMain.getSupplierCode()); |
|
|
|
payPayment.setSupplierName(vtbMain.getSupplierName()); |
|
|
|
payPayment.setCostApplyId(vtbMain.getCostApplyId()); |
|
|
|
} |
|
|
|
|
|
|
|
List<PayPaymentItem> newPayList = new ArrayList<>(); |
|
|
|
|
|
|
|
for(VtbVerification vtb:verificationList){ |
|
|
|
if(payAmount.compareTo(BigDecimal.ZERO)<=0){ |
|
|
|
continue; |
|
|
|
} |
|
|
|
LambdaQueryWrapper<PayPaymentItem> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
lambdaQueryWrapper.eq(PayPaymentItem::getVerificationId,vtb.getId()); |
|
|
|
List<PayPaymentItem> payPaymentItemList = paymentItemService.list(lambdaQueryWrapper); |
|
|
|
BigDecimal usedAmount = payPaymentItemList.stream().map(a->a.getItemPayAmount()).reduce(BigDecimal.ZERO,BigDecimal::add); |
|
|
|
if(usedAmount==null){ |
|
|
|
usedAmount = BigDecimal.ZERO; |
|
|
|
} |
|
|
|
if(vtb.getAmount().compareTo(usedAmount)>0) { |
|
|
|
PayPaymentItem payPaymentItem = new PayPaymentItem(); |
|
|
|
payPaymentItem = CopierUtil.copy(payPayment,payPaymentItem); |
|
|
|
payPaymentItem.setItemPayAmount(payPayment.getPayAmount()); |
|
|
|
payPaymentItem.setRemark(payPayment.getRemark()); |
|
|
|
payPaymentItem.setCostApplyId(vtb.getCostApplyId()); |
|
|
|
payPaymentItem.setSupplierId(vtb.getSupplierId()); |
|
|
|
payPaymentItem.setVerificationId(vtb.getId()); |
|
|
|
payPaymentItem.setVerificationSubjectId(null); |
|
|
|
payPaymentItem.setVerificationCode(vtb.getVerificationCode()); |
|
|
|
|
|
|
|
BigDecimal vtbAmountUnused = vtb.getAmount().subtract(usedAmount); |
|
|
|
if(payAmount.compareTo(vtbAmountUnused)>0){ |
|
|
|
payPaymentItem.setItemPayAmount(vtbAmountUnused); |
|
|
|
}else{ |
|
|
|
payPaymentItem.setItemPayAmount(payAmount); |
|
|
|
} |
|
|
|
payAmount = payAmount.subtract(payPaymentItem.getItemPayAmount()); |
|
|
|
newPayList.add(payPaymentItem); |
|
|
|
|
|
|
|
if(vtbSub!=null) { |
|
|
|
String verCode = vtbSub.getVerificationSubCode(); |
|
|
|
if(verCode.contains("_")){ |
|
|
|
verCode = verCode.substring(0,verCode.indexOf("_")); |
|
|
|
} |
|
|
|
payPaymentItem.setVerificationId(vtbSub.getVerificationId()); |
|
|
|
payPaymentItem.setVerificationMainCode(verCode); |
|
|
|
payPaymentItem.setVerificationCode(vtbSub.getVerificationSubCode()); |
|
|
|
payPaymentItem.setVerificationSubjectId(vtbSub.getId()); |
|
|
|
payPaymentItem.setActivityId(vtbSub.getActivityId()); |
|
|
|
payPaymentItem.setSubjectCode(vtbSub.getSubjectCode()); |
|
|
|
payPaymentItem.setSubjectId(vtbSub.getSubjectId()); |
|
|
|
payPaymentItem.setSubjectName(vtbSub.getSubjectName()); |
|
|
|
}else if(verificationList.size()>0){ |
|
|
|
VtbVerification vtbMain = verificationList.get(0); |
|
|
|
payPaymentItem.setVerificationId(vtbMain.getId()); |
|
|
|
payPaymentItem.setVerificationMainCode(vtbMain.getVerificationMainCode()); |
|
|
|
payPaymentItem.setVerificationCode(vtbMain.getVerificationCode()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(payAmount.compareTo(BigDecimal.ZERO)>0){ |
|
|
|
Assert.throwEx("支付金额超出核销可支付金额!"); |
|
|
|
} |
|
|
|
|
|
|
|
this.save(payPayment); |
|
|
|
|
|
|
|
payPaymentItem.setPaymentId(payPayment.getId()); |
|
|
|
newPayList = newPayList.stream().map(a->{ |
|
|
|
a.setPaymentId(payPayment.getId()); |
|
|
|
return a; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
|
|
paymentItemService.save(payPaymentItem); |
|
|
|
paymentItemService.saveBatch(newPayList); |
|
|
|
|
|
|
|
return payPayment; |
|
|
|
} |
|
|
@ -181,12 +181,12 @@ public class PayPaymentServiceImpl extends ServiceImpl<PayPaymentMapper,PayPayme |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public PayPayment unpayment(PayPaymentBo paymentBo) { |
|
|
|
String payType = paymentBo.getPayType(); |
|
|
|
if(!payType.equals(PaymentType.PAYMENT)&&!payType.equals(PaymentType.UN_PAYMENT)){ |
|
|
|
if(!payType.equals(PaymentType.UN_PAYMENT)){ |
|
|
|
Assert.throwEx("支付类型异常"); |
|
|
|
} |
|
|
|
|
|
|
|
LambdaQueryWrapper<PayPayment> lqw = new LambdaQueryWrapper<>(); |
|
|
|
lqw.eq(PayPayment::getErpId,paymentBo.getErpId()); |
|
|
|
lqw.eq(PayPayment::getErpId,paymentBo.getErpId()+PaymentType.UN_PAYMENT); |
|
|
|
if(this.count(lqw)>0){ |
|
|
|
Assert.throwEx("已存在ERPID"); |
|
|
|
} |
|
|
@ -197,44 +197,29 @@ public class PayPaymentServiceImpl extends ServiceImpl<PayPaymentMapper,PayPayme |
|
|
|
} |
|
|
|
|
|
|
|
LambdaQueryWrapper<VtbVerification> vtbLqw = new LambdaQueryWrapper<>(); |
|
|
|
vtbLqw.eq(VtbVerification::getVerificationMainCode,paymentBo.getVerificationSubCode()); |
|
|
|
vtbLqw.eq(VtbVerification::getVerificationCode,paymentBo.getVerificationSubCode()); |
|
|
|
List<VtbVerification> verificationList = verificationService.list(vtbLqw); |
|
|
|
// if(verificationList.size()==0){
|
|
|
|
// Assert.throwEx("核销编码异常");
|
|
|
|
// }
|
|
|
|
|
|
|
|
VtbVerificationSubject vtbSub = verificationSubjectService.getByVerificationSubjectCode(paymentBo.getVerificationSubCode()); |
|
|
|
if(vtbSub==null && verificationList.size()==0){ |
|
|
|
Assert.throwEx("核销编码异常"); |
|
|
|
} |
|
|
|
if(verificationList.size()==0){ |
|
|
|
String verificationCode = paymentBo.getVerificationSubCode(); |
|
|
|
|
|
|
|
LambdaQueryWrapper<PayPaymentItem> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
lambdaQueryWrapper.eq(PayPaymentItem::getVerificationMainCode,paymentBo.getVerificationSubCode()); |
|
|
|
List<PayPaymentItem> payPaymentItemList = paymentItemService.list(lambdaQueryWrapper); |
|
|
|
BigDecimal payedAmount = payPaymentItemList.stream().map(a->a.getItemPayAmount()).reduce(BigDecimal.ZERO,BigDecimal::add); |
|
|
|
BigDecimal verificationAmount = null; |
|
|
|
if(vtbSub!=null){ |
|
|
|
verificationAmount = vtbSub.getUsedAmount(); |
|
|
|
}else if(verificationList.size()!=0) { |
|
|
|
verificationAmount = verificationList.stream().map(a -> a.getAmount()).reduce(BigDecimal.ZERO, BigDecimal::add); |
|
|
|
}else{ |
|
|
|
Assert.throwEx("核销金额异常"); |
|
|
|
String verificationMainCode = verificationCode; |
|
|
|
if(verificationCode.contains("_")) { |
|
|
|
verificationMainCode = verificationCode.substring(0, verificationCode.indexOf("_")); |
|
|
|
} |
|
|
|
BigDecimal notPayAmount = verificationAmount.subtract(payedAmount); |
|
|
|
|
|
|
|
if(1 != paymentBo.getRelease()) { |
|
|
|
if(paymentBo.getPayAmount()==null){ |
|
|
|
Assert.throwEx("支付金额不能为空!"); |
|
|
|
} |
|
|
|
if (paymentBo.getPayAmount().compareTo(notPayAmount) > 0) { |
|
|
|
Assert.throwEx("支付金额已超出可支付额"); |
|
|
|
LambdaQueryWrapper<VtbVerification> vtbMainLqw = new LambdaQueryWrapper<>(); |
|
|
|
vtbMainLqw.eq(VtbVerification::getVerificationMainCode,verificationMainCode); |
|
|
|
verificationList = verificationService.list(vtbMainLqw); |
|
|
|
if(verificationList.size()==0){ |
|
|
|
Assert.throwEx("没有找到核销:"+ paymentBo.getVerificationSubCode()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
BigDecimal payAmount = BigDecimal.ZERO; |
|
|
|
|
|
|
|
PayPayment payPayment = new PayPayment(); |
|
|
|
payPayment.setPayType("unPay"); |
|
|
|
payPayment.setPayType(PaymentType.UN_PAYMENT); |
|
|
|
payPayment.setPayCode(paymentBo.getErpId()); |
|
|
|
payPayment.setPayAmount(paymentBo.getPayAmount()); |
|
|
|
payPayment.setUserId(sysUser.getId()); |
|
|
|
payPayment.setUserCode(sysUser.getCode()); |
|
|
|
payPayment.setUserName(sysUser.getName()); |
|
|
@ -243,68 +228,59 @@ public class PayPaymentServiceImpl extends ServiceImpl<PayPaymentMapper,PayPayme |
|
|
|
payPayment.setBillNumber(paymentBo.getBillNumber()); |
|
|
|
payPayment.setRemark(paymentBo.getRemark()); |
|
|
|
payPayment.setTenantId("001"); |
|
|
|
// payPayment.setErpId(paymentBo.getErpId());
|
|
|
|
|
|
|
|
if(vtbSub!=null) { |
|
|
|
payPayment.setSupplierId(vtbSub.getSupplierId()); |
|
|
|
payPayment.setSupplierCode(vtbSub.getSupplierCode()); |
|
|
|
payPayment.setSupplierName(vtbSub.getSupplierName()); |
|
|
|
payPayment.setCostApplyId(vtbSub.getCostApplyId()); |
|
|
|
if(1==paymentBo.getRelease()){ |
|
|
|
payPayment.setPayAmount(notPayAmount); |
|
|
|
} |
|
|
|
payPayment.setErpId(paymentBo.getErpId()+PaymentType.UN_PAYMENT); |
|
|
|
|
|
|
|
}else if(verificationList.size()>0) { |
|
|
|
VtbVerification vtbMain = verificationList.get(0); |
|
|
|
payPayment.setSupplierId(vtbMain.getSupplierId()); |
|
|
|
payPayment.setSupplierCode(vtbMain.getSupplierCode()); |
|
|
|
payPayment.setSupplierName(vtbMain.getSupplierName()); |
|
|
|
payPayment.setCostApplyId(vtbMain.getCostApplyId()); |
|
|
|
if(1==paymentBo.getRelease()){ |
|
|
|
payPayment.setPayAmount(notPayAmount); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
List<PayPaymentItem> newPayList = new ArrayList<>(); |
|
|
|
|
|
|
|
for(VtbVerification vtb:verificationList){ |
|
|
|
|
|
|
|
LambdaQueryWrapper<PayPaymentItem> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
lambdaQueryWrapper.eq(PayPaymentItem::getVerificationId,vtb.getId()); |
|
|
|
List<PayPaymentItem> payPaymentItemList = paymentItemService.list(lambdaQueryWrapper); |
|
|
|
BigDecimal usedAmount = payPaymentItemList.stream().map(a->a.getItemPayAmount()).reduce(BigDecimal.ZERO,BigDecimal::add); |
|
|
|
if(usedAmount==null){ |
|
|
|
usedAmount = BigDecimal.ZERO; |
|
|
|
} |
|
|
|
if(vtb.getAmount().compareTo(usedAmount)>0) { |
|
|
|
PayPaymentItem payPaymentItem = new PayPaymentItem(); |
|
|
|
payPaymentItem = CopierUtil.copy(payPayment,payPaymentItem); |
|
|
|
payPaymentItem.setItemPayAmount(payPayment.getPayAmount()); |
|
|
|
payPaymentItem.setRemark(payPayment.getRemark()); |
|
|
|
payPaymentItem.setCostApplyId(vtb.getCostApplyId()); |
|
|
|
payPaymentItem.setSupplierId(vtb.getSupplierId()); |
|
|
|
payPaymentItem.setVerificationId(vtb.getId()); |
|
|
|
payPaymentItem.setVerificationSubjectId(null); |
|
|
|
payPaymentItem.setVerificationCode(vtb.getVerificationCode()); |
|
|
|
|
|
|
|
if(vtbSub!=null) { |
|
|
|
String verCode = vtbSub.getVerificationSubCode(); |
|
|
|
if(verCode.contains("_")){ |
|
|
|
verCode = verCode.substring(0,verCode.indexOf("_")); |
|
|
|
} |
|
|
|
payPaymentItem.setVerificationId(vtbSub.getVerificationId()); |
|
|
|
payPaymentItem.setVerificationMainCode(verCode); |
|
|
|
payPaymentItem.setVerificationCode(vtbSub.getVerificationSubCode()); |
|
|
|
payPaymentItem.setVerificationSubjectId(vtbSub.getId()); |
|
|
|
payPaymentItem.setActivityId(vtbSub.getActivityId()); |
|
|
|
payPaymentItem.setSubjectCode(vtbSub.getSubjectCode()); |
|
|
|
payPaymentItem.setSubjectId(vtbSub.getSubjectId()); |
|
|
|
payPaymentItem.setSubjectName(vtbSub.getSubjectName()); |
|
|
|
}else if(verificationList.size()>0){ |
|
|
|
VtbVerification vtbMain = verificationList.get(0); |
|
|
|
payPaymentItem.setVerificationId(vtbMain.getId()); |
|
|
|
payPaymentItem.setVerificationMainCode(vtbMain.getVerificationMainCode()); |
|
|
|
payPaymentItem.setVerificationCode(vtbMain.getVerificationCode()); |
|
|
|
BigDecimal vtbAmountUnused = vtb.getAmount().subtract(usedAmount); |
|
|
|
if(vtbAmountUnused.compareTo(BigDecimal.ZERO)>0){ |
|
|
|
payPaymentItem.setItemPayAmount(vtbAmountUnused); |
|
|
|
} |
|
|
|
payAmount = payAmount.add(payPaymentItem.getItemPayAmount()); |
|
|
|
newPayList.add(payPaymentItem); |
|
|
|
|
|
|
|
this.save(payPayment); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
payPaymentItem.setPaymentId(payPayment.getId()); |
|
|
|
if(payAmount.compareTo(BigDecimal.ZERO)==0){ |
|
|
|
Assert.throwEx("核销已完全支付!没有不再支付金额"); |
|
|
|
} |
|
|
|
|
|
|
|
paymentItemService.save(payPaymentItem); |
|
|
|
payPayment.setPayAmount(payAmount); |
|
|
|
|
|
|
|
if(vtbSub!=null){ |
|
|
|
vtbSub.setPayReleaseFlag(1); |
|
|
|
verificationSubjectService.updateById(vtbSub); |
|
|
|
}else if(verificationList.size()!=0) { |
|
|
|
verificationList.forEach(a->a.setPayReleaseFlag(1)); |
|
|
|
verificationService.updateBatchById(verificationList); |
|
|
|
// verificationAmount = verificationList.stream().map(a -> a.getAmount()).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
} |
|
|
|
|
|
|
|
this.save(payPayment); |
|
|
|
|
|
|
|
newPayList = newPayList.stream().map(a->{ |
|
|
|
a.setPaymentId(payPayment.getId()); |
|
|
|
return a; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
|
|
paymentItemService.saveBatch(newPayList); |
|
|
|
|
|
|
|
return payPayment; |
|
|
|
} |
|
|
@ -377,6 +353,15 @@ public class PayPaymentServiceImpl extends ServiceImpl<PayPaymentMapper,PayPayme |
|
|
|
LambdaQueryWrapper<PayPaymentItem> paymentItemLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
paymentItemLambdaQueryWrapper.eq(PayPaymentItem::getErpId,erpId); |
|
|
|
paymentItemService.remove(paymentItemLambdaQueryWrapper); |
|
|
|
|
|
|
|
LambdaQueryWrapper<PayPayment> lambdaQueryWrapper2 = new LambdaQueryWrapper<>(); |
|
|
|
lambdaQueryWrapper2.eq(PayPayment::getErpId,erpId+PaymentType.UN_PAYMENT); |
|
|
|
this.remove(lambdaQueryWrapper2); |
|
|
|
|
|
|
|
LambdaQueryWrapper<PayPaymentItem> paymentItemLambdaQueryWrapper2 = new LambdaQueryWrapper<>(); |
|
|
|
paymentItemLambdaQueryWrapper2.eq(PayPaymentItem::getErpId,erpId+PaymentType.UN_PAYMENT); |
|
|
|
paymentItemService.remove(paymentItemLambdaQueryWrapper2); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|