Browse Source

支付修改

v1.0
15989082884@163.com 2 years ago
parent
commit
c3efb352a3
  1. 271
      src/main/java/com/qs/serve/modules/pay/service/impl/PayPaymentServiceImpl.java

271
src/main/java/com/qs/serve/modules/pay/service/impl/PayPaymentServiceImpl.java

@ -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());
}
VtbVerification vtbMain = verificationList.get(0);
payPayment.setSupplierId(vtbMain.getSupplierId());
payPayment.setSupplierCode(vtbMain.getSupplierCode());
payPayment.setSupplierName(vtbMain.getSupplierName());
List<PayPaymentItem> newPayList = new ArrayList<>();
PayPaymentItem payPaymentItem = new PayPaymentItem();
payPaymentItem = CopierUtil.copy(payPayment,payPaymentItem);
payPaymentItem.setItemPayAmount(payPayment.getPayAmount());
payPaymentItem.setRemark(payPayment.getRemark());
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.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("核销编码异常");
}
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("核销金额异常");
}
BigDecimal notPayAmount = verificationAmount.subtract(payedAmount);
if(verificationList.size()==0){
String verificationCode = paymentBo.getVerificationSubCode();
if(1 != paymentBo.getRelease()) {
if(paymentBo.getPayAmount()==null){
Assert.throwEx("支付金额不能为空!");
String verificationMainCode = verificationCode;
if(verificationCode.contains("_")) {
verificationMainCode = verificationCode.substring(0, verificationCode.indexOf("_"));
}
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);
VtbVerification vtbMain = verificationList.get(0);
payPayment.setSupplierId(vtbMain.getSupplierId());
payPayment.setSupplierCode(vtbMain.getSupplierCode());
payPayment.setSupplierName(vtbMain.getSupplierName());
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.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(vtbAmountUnused.compareTo(BigDecimal.ZERO)>0){
payPaymentItem.setItemPayAmount(vtbAmountUnused);
}
payAmount = payAmount.add(payPaymentItem.getItemPayAmount());
newPayList.add(payPaymentItem);
}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);
}
}
if(payAmount.compareTo(BigDecimal.ZERO)==0){
Assert.throwEx("核销已完全支付!没有不再支付金额");
}
PayPaymentItem payPaymentItem = new PayPaymentItem();
payPaymentItem = CopierUtil.copy(payPayment,payPaymentItem);
payPaymentItem.setItemPayAmount(payPayment.getPayAmount());
payPaymentItem.setRemark(payPayment.getRemark());
payPayment.setPayAmount(payAmount);
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());
}
this.save(payPayment);
payPaymentItem.setPaymentId(payPayment.getId());
newPayList = newPayList.stream().map(a->{
a.setPaymentId(payPayment.getId());
return a;
}).collect(Collectors.toList());
paymentItemService.save(payPaymentItem);
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);
}
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

Loading…
Cancel
Save