|
@ -7,9 +7,11 @@ import com.qs.serve.common.util.AuthContextUtils; |
|
|
import com.qs.serve.modules.bms.entity.BmsSupplier; |
|
|
import com.qs.serve.modules.bms.entity.BmsSupplier; |
|
|
import com.qs.serve.modules.bms.service.BmsSupplierService; |
|
|
import com.qs.serve.modules.bms.service.BmsSupplierService; |
|
|
import com.qs.serve.modules.pay.common.PaymentType; |
|
|
import com.qs.serve.modules.pay.common.PaymentType; |
|
|
|
|
|
import com.qs.serve.modules.pay.entity.PayHistoryItem; |
|
|
import com.qs.serve.modules.pay.entity.PayPaymentItem; |
|
|
import com.qs.serve.modules.pay.entity.PayPaymentItem; |
|
|
import com.qs.serve.modules.pay.entity.bo.PayPaymentBo; |
|
|
import com.qs.serve.modules.pay.entity.bo.PayPaymentBo; |
|
|
import com.qs.serve.modules.pay.entity.dto.PayPaymentAmountDto; |
|
|
import com.qs.serve.modules.pay.entity.dto.PayPaymentAmountDto; |
|
|
|
|
|
import com.qs.serve.modules.pay.service.PayHistoryItemService; |
|
|
import com.qs.serve.modules.pay.service.PayPaymentItemService; |
|
|
import com.qs.serve.modules.pay.service.PayPaymentItemService; |
|
|
import com.qs.serve.modules.sys.entity.SysUser; |
|
|
import com.qs.serve.modules.sys.entity.SysUser; |
|
|
import com.qs.serve.modules.sys.service.SysUserService; |
|
|
import com.qs.serve.modules.sys.service.SysUserService; |
|
@ -47,6 +49,7 @@ public class PayPaymentServiceImpl extends ServiceImpl<PayPaymentMapper,PayPayme |
|
|
private PayPaymentItemService paymentItemService; |
|
|
private PayPaymentItemService paymentItemService; |
|
|
private VtbVerificationSubjectService verificationSubjectService; |
|
|
private VtbVerificationSubjectService verificationSubjectService; |
|
|
private TbsActivityService activityService; |
|
|
private TbsActivityService activityService; |
|
|
|
|
|
private PayHistoryItemService payHistoryItemService; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Transactional(rollbackFor = Exception.class) |
|
@ -66,14 +69,36 @@ public class PayPaymentServiceImpl extends ServiceImpl<PayPaymentMapper,PayPayme |
|
|
if(currentAmount.compareTo(allowAmount)>0){ |
|
|
if(currentAmount.compareTo(allowAmount)>0){ |
|
|
Assert.throwEx("支付不能超过待支付金额!"); |
|
|
Assert.throwEx("支付不能超过待支付金额!"); |
|
|
} |
|
|
} |
|
|
|
|
|
//截断:添加历史金额支付记录
|
|
|
|
|
|
BigDecimal supplierHisAmount = supplier.getInitCurAmount(); |
|
|
|
|
|
PayHistoryItem historyItem = null; |
|
|
|
|
|
if(supplierHisAmount.compareTo(BigDecimal.ZERO)>0){ |
|
|
|
|
|
historyItem = new PayHistoryItem(); |
|
|
|
|
|
if(supplierHisAmount.compareTo(currentAmount)>=0){ |
|
|
|
|
|
historyItem.setPayType(payType); |
|
|
|
|
|
historyItem.setSupplierId(paymentBo.getSupplierId()); |
|
|
|
|
|
historyItem.setItemPayAmount(currentAmount); |
|
|
|
|
|
historyItem.setRemark(paymentBo.getRemark()); |
|
|
|
|
|
supplier.setInitCurAmount(supplierHisAmount.subtract(currentAmount)); |
|
|
|
|
|
currentBalance = BigDecimal.ZERO; |
|
|
|
|
|
}else { |
|
|
|
|
|
historyItem.setPayType(payType); |
|
|
|
|
|
historyItem.setSupplierId(paymentBo.getSupplierId()); |
|
|
|
|
|
historyItem.setItemPayAmount(supplierHisAmount); |
|
|
|
|
|
historyItem.setRemark(paymentBo.getRemark()); |
|
|
|
|
|
supplier.setInitCurAmount(BigDecimal.ZERO); |
|
|
|
|
|
currentBalance = currentAmount.subtract(supplierHisAmount); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
List<VtbVerificationSubject> verificationSubjectList = amountDto.getVerificationSubjectList(); |
|
|
List<VtbVerificationSubject> verificationSubjectList = amountDto.getVerificationSubjectList(); |
|
|
List<PayPaymentItem> paymentItemList = new ArrayList<>(); |
|
|
List<PayPaymentItem> paymentItemList = new ArrayList<>(); |
|
|
List<VtbVerificationSubject> verificationSubjectUpdateList = new ArrayList<>(); |
|
|
List<VtbVerificationSubject> verificationSubjectUpdateList = new ArrayList<>(); |
|
|
for (VtbVerificationSubject verificationSubject : verificationSubjectList) { |
|
|
for (VtbVerificationSubject verificationSubject : verificationSubjectList) { |
|
|
currentBalance = this.buildPaymentItems(paymentBo, currentBalance, paymentItemList, verificationSubjectUpdateList, verificationSubject); |
|
|
|
|
|
if(currentBalance.compareTo(BigDecimal.ZERO)==0){ |
|
|
if(currentBalance.compareTo(BigDecimal.ZERO)==0){ |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
currentBalance = this.buildPaymentItems(paymentBo, currentBalance, paymentItemList, verificationSubjectUpdateList, verificationSubject); |
|
|
} |
|
|
} |
|
|
PayPayment payPayment = new PayPayment(); |
|
|
PayPayment payPayment = new PayPayment(); |
|
|
payPayment.setPayType(payType); |
|
|
payPayment.setPayType(payType); |
|
@ -88,8 +113,14 @@ public class PayPaymentServiceImpl extends ServiceImpl<PayPaymentMapper,PayPayme |
|
|
payPayment.setPayTime(LocalDateTime.now()); |
|
|
payPayment.setPayTime(LocalDateTime.now()); |
|
|
payPayment.setErpCode(paymentBo.getErpCode()); |
|
|
payPayment.setErpCode(paymentBo.getErpCode()); |
|
|
this.save(payPayment); |
|
|
this.save(payPayment); |
|
|
List<Long> actIds = paymentItemList.stream().map(PayPaymentItem::getActivityId).distinct().collect(Collectors.toList()); |
|
|
//保存历史金额
|
|
|
|
|
|
if(historyItem!=null){ |
|
|
|
|
|
historyItem.setPaymentId(payPayment.getId()); |
|
|
|
|
|
payHistoryItemService.save(historyItem); |
|
|
|
|
|
} |
|
|
//关联活动编码
|
|
|
//关联活动编码
|
|
|
|
|
|
if(paymentItemList.size()>0){ |
|
|
|
|
|
List<Long> actIds = paymentItemList.stream().map(PayPaymentItem::getActivityId).distinct().collect(Collectors.toList()); |
|
|
List<TbsActivity> activityList = activityService.listByIds(actIds); |
|
|
List<TbsActivity> activityList = activityService.listByIds(actIds); |
|
|
for (PayPaymentItem paymentItem : paymentItemList) { |
|
|
for (PayPaymentItem paymentItem : paymentItemList) { |
|
|
for (TbsActivity activity : activityList) { |
|
|
for (TbsActivity activity : activityList) { |
|
@ -100,8 +131,11 @@ public class PayPaymentServiceImpl extends ServiceImpl<PayPaymentMapper,PayPayme |
|
|
} |
|
|
} |
|
|
paymentItem.setPaymentId(payPayment.getId()); |
|
|
paymentItem.setPaymentId(payPayment.getId()); |
|
|
} |
|
|
} |
|
|
verificationSubjectService.updateBatchById(verificationSubjectUpdateList); |
|
|
|
|
|
paymentItemService.saveBatch(paymentItemList); |
|
|
paymentItemService.saveBatch(paymentItemList); |
|
|
|
|
|
} |
|
|
|
|
|
if(verificationSubjectUpdateList.size()>0){ |
|
|
|
|
|
verificationSubjectService.updateBatchById(verificationSubjectUpdateList); |
|
|
|
|
|
} |
|
|
return payPayment; |
|
|
return payPayment; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -165,6 +199,9 @@ public class PayPaymentServiceImpl extends ServiceImpl<PayPaymentMapper,PayPayme |
|
|
Assert.throwEx("已取消,请勿重复提交"); |
|
|
Assert.throwEx("已取消,请勿重复提交"); |
|
|
} |
|
|
} |
|
|
List<PayPaymentItem> paymentItemList = paymentItemService.listByPaymentId(id); |
|
|
List<PayPaymentItem> paymentItemList = paymentItemService.listByPaymentId(id); |
|
|
|
|
|
List<PayHistoryItem> historyItemList = payHistoryItemService.listByPaymentId(id); |
|
|
|
|
|
List<Long> historyItemIds = historyItemList.stream().map(PayHistoryItem::getId) |
|
|
|
|
|
.distinct().collect(Collectors.toList()); |
|
|
List<Long> paymentItemIds = paymentItemList.stream().map(PayPaymentItem::getId) |
|
|
List<Long> paymentItemIds = paymentItemList.stream().map(PayPaymentItem::getId) |
|
|
.distinct().collect(Collectors.toList()); |
|
|
.distinct().collect(Collectors.toList()); |
|
|
List<Long> verSubjectIds = paymentItemList.stream().map(PayPaymentItem::getVerificationSubjectId) |
|
|
List<Long> verSubjectIds = paymentItemList.stream().map(PayPaymentItem::getVerificationSubjectId) |
|
@ -191,6 +228,7 @@ public class PayPaymentServiceImpl extends ServiceImpl<PayPaymentMapper,PayPayme |
|
|
payPayment.setCancelFlag(1); |
|
|
payPayment.setCancelFlag(1); |
|
|
this.updateById(payPayment); |
|
|
this.updateById(payPayment); |
|
|
paymentItemService.removeBatchByIds(paymentItemIds); |
|
|
paymentItemService.removeBatchByIds(paymentItemIds); |
|
|
|
|
|
payHistoryItemService.removeBatchByIds(historyItemIds); |
|
|
verificationSubjectService.updateBatchById(verificationSubjectUpdateList); |
|
|
verificationSubjectService.updateBatchById(verificationSubjectUpdateList); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -201,8 +239,18 @@ public class PayPaymentServiceImpl extends ServiceImpl<PayPaymentMapper,PayPayme |
|
|
lqw.eq(VtbVerificationSubject::getPayFinishedFlag,0); |
|
|
lqw.eq(VtbVerificationSubject::getPayFinishedFlag,0); |
|
|
lqw.eq(VtbVerificationSubject::getEffectiveFlag,1); |
|
|
lqw.eq(VtbVerificationSubject::getEffectiveFlag,1); |
|
|
List<VtbVerificationSubject> vtbVerificationSubjectList = verificationSubjectService.list(lqw); |
|
|
List<VtbVerificationSubject> vtbVerificationSubjectList = verificationSubjectService.list(lqw); |
|
|
BigDecimal totalAmount = BigDecimal.ZERO; |
|
|
BmsSupplier supplier = supplierService.getById(supplierId); |
|
|
BigDecimal hasAmount = BigDecimal.ZERO; |
|
|
BigDecimal hasAmount = BigDecimal.ZERO; |
|
|
|
|
|
//添加历史金额支持
|
|
|
|
|
|
BigDecimal totalAmount = supplier.getInitCurAmount(); |
|
|
|
|
|
if(totalAmount.compareTo(BigDecimal.ZERO)>0){ |
|
|
|
|
|
LambdaQueryWrapper<PayHistoryItem> lqw2 = new LambdaQueryWrapper<>(); |
|
|
|
|
|
lqw2.eq(PayHistoryItem::getSupplierId,supplierId); |
|
|
|
|
|
List<PayHistoryItem> historyItems = payHistoryItemService.list(lqw2); |
|
|
|
|
|
for (PayHistoryItem historyItem : historyItems) { |
|
|
|
|
|
hasAmount = hasAmount.add(historyItem.getItemPayAmount()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
for (VtbVerificationSubject verificationSubject : vtbVerificationSubjectList) { |
|
|
for (VtbVerificationSubject verificationSubject : vtbVerificationSubjectList) { |
|
|
totalAmount = totalAmount.add(verificationSubject.getUsedAmount()); |
|
|
totalAmount = totalAmount.add(verificationSubject.getUsedAmount()); |
|
|
hasAmount = hasAmount.add(verificationSubject.getPayAmount()); |
|
|
hasAmount = hasAmount.add(verificationSubject.getPayAmount()); |
|
|