Browse Source

支付接口

v1.0
15989082884@163.com 2 years ago
parent
commit
2353f4f051
  1. 33
      src/main/java/com/qs/serve/modules/pay/controller/PayPaymentController.java
  2. 7
      src/main/java/com/qs/serve/modules/pay/entity/PayPayment.java
  3. 12
      src/main/java/com/qs/serve/modules/pay/entity/PayPaymentItem.java
  4. 29
      src/main/java/com/qs/serve/modules/pay/entity/bo/PayPaymentBo.java
  5. 6
      src/main/java/com/qs/serve/modules/pay/mapper/PayPaymentMapper.java
  6. 2
      src/main/java/com/qs/serve/modules/pay/service/PayPaymentService.java
  7. 280
      src/main/java/com/qs/serve/modules/pay/service/impl/PayPaymentServiceImpl.java
  8. 2
      src/main/java/com/qs/serve/modules/vtb/service/VtbVerificationSubjectService.java
  9. 6
      src/main/java/com/qs/serve/modules/vtb/service/impl/VtbVerificationSubjectServiceImpl.java

33
src/main/java/com/qs/serve/modules/pay/controller/PayPaymentController.java

@ -223,22 +223,22 @@ public class PayPaymentController {
* @param param * @param param
* @return * @return
*/ */
@PostMapping("/unPayment") // @PostMapping("/unPayment")
@SysLog(module = SystemModule.Payment, title = "支付", biz = BizType.INSERT) // @SysLog(module = SystemModule.Payment, title = "支付", biz = BizType.INSERT)
@PreAuthorize("hasRole('pay:payment:pay')") // @PreAuthorize("hasRole('pay:payment:pay')")
public R<PayPayment> save(@RequestBody @Valid PayUnPaymentBo param){ // public R<PayPayment> save(@RequestBody @Valid PayUnPaymentBo param){
PayPaymentBo paymentBo = CopierUtil.copy(param,new PayPaymentBo()); // PayPaymentBo paymentBo = CopierUtil.copy(param,new PayPaymentBo());
paymentBo.setPayType(PaymentType.UN_PAYMENT); // paymentBo.setPayType(PaymentType.UN_PAYMENT);
PayPayment payPayment = payPaymentService.payment(paymentBo); // PayPayment payPayment = payPaymentService.payment(paymentBo);
return R.ok(payPayment); // return R.ok(payPayment);
} // }
/** /**
* 新增支付核销调用 * 新增支付
* @param param * @param param
* @return * @return
*/ */
@PostMapping("/payment") @PostMapping("/save")
@SysLog(module = SystemModule.Payment, title = "支付", biz = BizType.INSERT) @SysLog(module = SystemModule.Payment, title = "支付", biz = BizType.INSERT)
@PreAuthorize("hasRole('pay:payment:pay')") @PreAuthorize("hasRole('pay:payment:pay')")
public R<PayPayment> save(@RequestBody @Valid PayPaymentBo param){ public R<PayPayment> save(@RequestBody @Valid PayPaymentBo param){
@ -248,15 +248,14 @@ public class PayPaymentController {
/** /**
* 取消支付 * 取消支付
* @param id * @param erpId
* @return * @return
*/ */
@DeleteMapping("/cancel/{id}") @GetMapping("/cancel/{id}")
@SysLog(module = SystemModule.Payment, title = "支付", biz = BizType.DELETE) @SysLog(module = SystemModule.Payment, title = "取消支付", biz = BizType.DELETE)
@PreAuthorize("hasRole('pay:payment:cancel')") @PreAuthorize("hasRole('pay:payment:cancel')")
public R<?> cancelById(@PathVariable("id") Long id){ public R<?> cancelById(@PathVariable("id") String erpId){
//TODO 远程同步东哥的数据,方案暂未落实 payPaymentService.cancel(erpId);
payPaymentService.cancel(id);
return R.ok(); return R.ok();
} }

7
src/main/java/com/qs/serve/modules/pay/entity/PayPayment.java

@ -95,6 +95,12 @@ public class PayPayment implements Serializable {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private LocalDateTime payTime; private LocalDateTime payTime;
@NotNull(message = "支付时间不能为空")
@Length(max = 0,message = "支付时间长度不能超过0字")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private LocalDateTime payDate;
/** /**
* 取消标识 * 取消标识
* 不再支付列表0-冻结1-解冻 * 不再支付列表0-冻结1-解冻
@ -127,6 +133,7 @@ public class PayPayment implements Serializable {
private Long costApplyId; private Long costApplyId;
@TableField(condition = SqlCondition.LIKE) @TableField(condition = SqlCondition.LIKE)
@NotNull(message = "ErpId不能为空")
private String erpId; private String erpId;
/** 所属租户 */ /** 所属租户 */

12
src/main/java/com/qs/serve/modules/pay/entity/PayPaymentItem.java

@ -108,6 +108,12 @@ public class PayPaymentItem implements Serializable {
@TableField(fill = FieldFill.UPDATE) @TableField(fill = FieldFill.UPDATE)
private LocalDateTime updateTime; private LocalDateTime updateTime;
@TableField(condition = SqlCondition.LIKE)
private String erpId;
@TableField(condition = SqlCondition.LIKE)
private String billNumber;
/** 所属租户 */ /** 所属租户 */
@JsonIgnore @JsonIgnore
@JsonProperty @JsonProperty
@ -126,12 +132,6 @@ public class PayPaymentItem implements Serializable {
@JsonProperty @JsonProperty
private String delFlag; private String delFlag;
@TableField(condition = SqlCondition.LIKE)
private String erpId;
@TableField(condition = SqlCondition.LIKE)
private String billNumber;
/** 支付时间 */ /** 支付时间 */
@NotNull(message = "支付时间不能为空") @NotNull(message = "支付时间不能为空")
@Length(max = 0,message = "支付时间长度不能超过0字") @Length(max = 0,message = "支付时间长度不能超过0字")

29
src/main/java/com/qs/serve/modules/pay/entity/bo/PayPaymentBo.java

@ -5,6 +5,8 @@ import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
@ -24,12 +26,9 @@ import javax.validation.constraints.NotBlank;
@Data @Data
public class PayPaymentBo implements Serializable { public class PayPaymentBo implements Serializable {
/** 标题 */ /** 核销子项编码 */
private String title; @NotNull(message = "核销子项编码不能为空")
private String verificationSubCode;
/** 供应商id */
@NotNull(message = "供应商id不能为空")
private Long supplierId;
/** 支付金额 */ /** 支付金额 */
@DecimalMin(value = "0.01",message = "支付金额必须大于0元") @DecimalMin(value = "0.01",message = "支付金额必须大于0元")
@ -37,7 +36,8 @@ public class PayPaymentBo implements Serializable {
private BigDecimal payAmount; private BigDecimal payAmount;
/** ERP编码 */ /** ERP编码 */
private String erpCode; @NotNull(message = "ERP编码不能为空")
private String erpId;
/** 发票编号 */ /** 发票编号 */
@NotNull(message = "发票编号不能为空") @NotNull(message = "发票编号不能为空")
@ -47,11 +47,24 @@ public class PayPaymentBo implements Serializable {
@Length(max = 255,message = "备注长度不能超过255字") @Length(max = 255,message = "备注长度不能超过255字")
private String remark; private String remark;
/** 支付时间 */
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private LocalDateTime payTime;
/** 支付日期 */
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private LocalDateTime payDate;
/** 人员工号 */
@NotNull(message = "人员工号不能为空")
private String userCode;
/** /**
* 支付类型 * 支付类型
* pay - 支付 * pay - 支付
* unPay - 不再支付 TODO 同步告知东哥 * unPay - 不再支付
**/ **/
@NotNull(message = "支付类型不能为空") @NotNull(message = "支付类型不能为空")
private String payType; private String payType;

6
src/main/java/com/qs/serve/modules/pay/mapper/PayPaymentMapper.java

@ -1,7 +1,10 @@
package com.qs.serve.modules.pay.mapper; package com.qs.serve.modules.pay.mapper;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qs.serve.modules.pay.entity.PayPayment; import com.qs.serve.modules.pay.entity.PayPayment;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
/** /**
* 支付 Mapper * 支付 Mapper
@ -10,5 +13,8 @@ import com.qs.serve.modules.pay.entity.PayPayment;
*/ */
public interface PayPaymentMapper extends BaseMapper<PayPayment> { public interface PayPaymentMapper extends BaseMapper<PayPayment> {
@InterceptorIgnore(tenantLine = "1")
@Select("select * from pay_payment where erp_id = #{erpId}")
PayPayment getByErpId(@Param("erpId")String erpId);
} }

2
src/main/java/com/qs/serve/modules/pay/service/PayPaymentService.java

@ -23,7 +23,7 @@ public interface PayPaymentService extends IService<PayPayment> {
* 取消支付 * 取消支付
* @param id * @param id
*/ */
void cancel(Long id); void cancel(String erpId);
/** /**
* 获取供应商需支付明细 * 获取供应商需支付明细

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

@ -1,9 +1,11 @@
package com.qs.serve.modules.pay.service.impl; package com.qs.serve.modules.pay.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qs.serve.common.util.Assert; import com.qs.serve.common.util.Assert;
import com.qs.serve.common.util.AuthContextUtils; import com.qs.serve.common.util.AuthContextUtils;
import com.qs.serve.common.util.CopierUtil;
import com.qs.serve.common.util.StringUtils; import com.qs.serve.common.util.StringUtils;
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;
@ -27,6 +29,7 @@ import com.qs.serve.modules.vtb.service.VtbVerificationSubjectService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.qs.serve.modules.pay.entity.PayPayment; import com.qs.serve.modules.pay.entity.PayPayment;
import com.qs.serve.modules.pay.service.PayPaymentService; import com.qs.serve.modules.pay.service.PayPaymentService;
@ -60,190 +63,143 @@ public class PayPaymentServiceImpl extends ServiceImpl<PayPaymentMapper,PayPayme
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public PayPayment payment(PayPaymentBo paymentBo) { public PayPayment payment(PayPaymentBo paymentBo) {
LocalDateTime now = LocalDateTime.now();
String payType = paymentBo.getPayType(); String payType = paymentBo.getPayType();
if(!payType.equals(PaymentType.PAYMENT)&&!payType.equals(PaymentType.UN_PAYMENT)){ if(!payType.equals(PaymentType.PAYMENT)&&!payType.equals(PaymentType.UN_PAYMENT)){
Assert.throwEx("param err P1 "); Assert.throwEx("支付类型异常");
} }
SysUser sysUser = sysUserService.getById(AuthContextUtils.getSysUserId());
PayPaymentAmountDto amountDto = this.getSupplierBalance(paymentBo.getSupplierId()); LambdaQueryWrapper<PayPayment> lqw = new LambdaQueryWrapper<>();
BigDecimal allowAmount = amountDto.getTotalAmount().subtract(amountDto.getHasPayment()); lqw.eq(PayPayment::getErpId,paymentBo.getErpId());
BmsSupplier supplier = supplierService.getById(paymentBo.getSupplierId()); if(this.count(lqw)>0){
//本次支付金额 Assert.throwEx("已存在ERPID");
BigDecimal currentAmount = paymentBo.getPayAmount();
//本次支付余额
BigDecimal currentBalance = paymentBo.getPayAmount();
if(currentAmount.compareTo(allowAmount)>0){
Assert.throwEx("支付不能超过待支付金额!");
} }
//截断:添加历史金额支付记录
BigDecimal supplierHisAmount = supplier.getInitCurAmount();
PayHistoryItem historyItem = null;
if(supplierHisAmount.compareTo(BigDecimal.ZERO)>0){
historyItem = new PayHistoryItem();
historyItem.setPayType(payType);
historyItem.setSupplierId(paymentBo.getSupplierId());
historyItem.setRemark(paymentBo.getRemark());
if(supplierHisAmount.compareTo(currentAmount)>=0){
historyItem.setItemPayAmount(currentAmount);
supplier.setInitCurAmount(supplierHisAmount.subtract(currentAmount));
currentBalance = BigDecimal.ZERO;
}else {
historyItem.setItemPayAmount(supplierHisAmount);
supplier.setInitCurAmount(BigDecimal.ZERO);
currentBalance = currentAmount.subtract(supplierHisAmount);
}
SysUser sysUser = sysUserService.getByAccount(paymentBo.getUserCode());
if(sysUser==null){
Assert.throwEx("人员工号异常");
} }
List<VtbVerificationSubject> verificationSubjectList = amountDto.getVerificationSubjectList();
List<PayPaymentItem> paymentItemList = new ArrayList<>();
List<VtbVerificationSubject> verificationSubjectUpdateList = new ArrayList<>();
for (VtbVerificationSubject verificationSubject : verificationSubjectList) {
if(currentBalance.compareTo(BigDecimal.ZERO)==0){
break;
}
currentBalance = this.buildPaymentItems(paymentBo, currentBalance, paymentItemList, verificationSubjectUpdateList, verificationSubject);
if(payType.equals(PaymentType.PAYMENT)){
//TODO 保存支付记录
XltPaymentRecord paymentRecord = new XltPaymentRecord();
xiaoLuTonService.savePaymentRecord(paymentRecord);
}else if(payType.equals(PaymentType.UN_PAYMENT)){
//TODO 不再支付保存记录待定
} VtbVerificationSubject verSubject = verificationSubjectService.getByVerificationSubjectCode(paymentBo.getVerificationSubCode());
if(verSubject==null){
Assert.throwEx("核销子项编码异常");
}
LambdaQueryWrapper<PayPaymentItem> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(PayPaymentItem::getVerificationSubjectId,verSubject.getId());
List<PayPaymentItem> payPaymentItemList = paymentItemService.list(lambdaQueryWrapper);
BigDecimal payedAmount = payPaymentItemList.stream().map(a->a.getItemPayAmount()).reduce(BigDecimal.ZERO,BigDecimal::add);
BigDecimal notPayAmount = verSubject.getUsedAmount().subtract(payedAmount);
if(paymentBo.getPayAmount().compareTo(notPayAmount)>0){
Assert.throwEx("支付金额已超出可支付额");
} }
PayPayment payPayment = new PayPayment(); PayPayment payPayment = new PayPayment();
payPayment.setPayType(payType); payPayment.setPayType(paymentBo.getPayType());
payPayment.setPayCode("PM"+ StringUtils.genShortId()); payPayment.setPayCode(paymentBo.getErpId());
payPayment.setSupplierId(paymentBo.getSupplierId()); payPayment.setSupplierId(verSubject.getSupplierId());
payPayment.setSupplierCode(supplier.getCode()); payPayment.setSupplierCode(verSubject.getSupplierCode());
payPayment.setSupplierName(supplier.getName()); payPayment.setSupplierName(verSubject.getSupplierName());
payPayment.setPayAmount(paymentBo.getPayAmount()); payPayment.setPayAmount(paymentBo.getPayAmount());
payPayment.setUserId(sysUser.getId()); payPayment.setUserId(sysUser.getId());
payPayment.setUserCode(sysUser.getCode()); payPayment.setUserCode(sysUser.getCode());
payPayment.setUserName(sysUser.getName()); payPayment.setUserName(sysUser.getName());
payPayment.setPayTime(paymentBo.getPayTime());
payPayment.setPayDate(paymentBo.getPayDate());
payPayment.setBillNumber(paymentBo.getBillNumber());
payPayment.setRemark(paymentBo.getRemark()); payPayment.setRemark(paymentBo.getRemark());
payPayment.setPayTime(LocalDateTime.now()); payPayment.setTenantId("001");
payPayment.setErpCode(paymentBo.getErpCode()); payPayment.setCostApplyId(verSubject.getCostApplyId());
payPayment.setErpId(paymentBo.getErpId());
PayPaymentItem payPaymentItem = new PayPaymentItem();
payPaymentItem = CopierUtil.copy(payPayment,payPaymentItem);
payPaymentItem.setItemPayAmount(payPayment.getPayAmount());
payPaymentItem.setVerificationId(verSubject.getVerificationId());
payPaymentItem.setVerificationSubjectId(verSubject.getId());
payPaymentItem.setActivityId(verSubject.getActivityId());
payPaymentItem.setSubjectCode(verSubject.getSubjectCode());
payPaymentItem.setSubjectId(verSubject.getSubjectId());
payPaymentItem.setSubjectName(verSubject.getSubjectName());
payPaymentItem.setRemark(payPayment.getRemark());
this.save(payPayment); this.save(payPayment);
//保存历史金额
if(historyItem!=null){ payPaymentItem.setPaymentId(payPayment.getId());
historyItem.setPaymentId(payPayment.getId());
payHistoryItemService.save(historyItem); paymentItemService.save(payPaymentItem);
}
//关联活动编码
if(paymentItemList.size()>0){
List<Long> actIds = paymentItemList.stream().map(PayPaymentItem::getActivityId).distinct().collect(Collectors.toList());
List<TbsActivity> activityList = activityService.listByIds(actIds);
for (PayPaymentItem paymentItem : paymentItemList) {
for (TbsActivity activity : activityList) {
if(activity.getId().equals(paymentItem.getActivityId())){
paymentItem.setActivityCode(activity.getActivityCode());
break;
}
}
paymentItem.setPaymentId(payPayment.getId());
}
paymentItemService.saveBatch(paymentItemList);
}
if(verificationSubjectUpdateList.size()>0){
verificationSubjectService.updateBatchById(verificationSubjectUpdateList);
}
return payPayment; return payPayment;
} }
/** // /**
* 构建支付明细 // * 构建支付明细
* @param paymentBo // * @param paymentBo
* @param currentBalance // * @param currentBalance
* @param paymentItemList // * @param paymentItemList
* @param verificationSubjectUpdateList // * @param verificationSubjectUpdateList
* @param verificationSubject // * @param verificationSubject
* @return currentBalance 本次支付余额 // * @return currentBalance 本次支付余额
*/ // */
@NotNull // @NotNull
private BigDecimal buildPaymentItems(PayPaymentBo paymentBo, BigDecimal currentBalance, List<PayPaymentItem> paymentItemList, List<VtbVerificationSubject> verificationSubjectUpdateList, VtbVerificationSubject verificationSubject) { // private BigDecimal buildPaymentItems(PayPaymentBo paymentBo, BigDecimal currentBalance, List<PayPaymentItem> paymentItemList, List<VtbVerificationSubject> verificationSubjectUpdateList, VtbVerificationSubject verificationSubject) {
//统计历史支付金额 // //统计历史支付金额
BigDecimal hisPayAmount = BigDecimal.ZERO; // BigDecimal hisPayAmount = BigDecimal.ZERO;
List<PayPaymentItem> payPaymentItems = paymentItemService.listByVerSubjectId(verificationSubject.getId()); // List<PayPaymentItem> payPaymentItems = paymentItemService.listByVerSubjectId(verificationSubject.getId());
for (PayPaymentItem paymentItem : payPaymentItems) { // for (PayPaymentItem paymentItem : payPaymentItems) {
hisPayAmount = hisPayAmount.add(paymentItem.getItemPayAmount()); // hisPayAmount = hisPayAmount.add(paymentItem.getItemPayAmount());
} // }
//当前项未支付 // //当前项未支付
BigDecimal shouldPay = verificationSubject.getUsedAmount().subtract(hisPayAmount); // BigDecimal shouldPay = verificationSubject.getUsedAmount().subtract(hisPayAmount);
//当前项支付金额 // //当前项支付金额
BigDecimal currentItemPay; // BigDecimal currentItemPay;
if(currentBalance.compareTo(shouldPay)>0){ // if(currentBalance.compareTo(shouldPay)>0){
currentItemPay = shouldPay; // currentItemPay = shouldPay;
currentBalance = currentBalance.subtract(shouldPay); // currentBalance = currentBalance.subtract(shouldPay);
}else { // }else {
currentItemPay = currentBalance; // currentItemPay = currentBalance;
currentBalance = BigDecimal.ZERO; // currentBalance = BigDecimal.ZERO;
} // }
PayPaymentItem paymentItem = new PayPaymentItem(); // PayPaymentItem paymentItem = new PayPaymentItem();
paymentItem.setPayType(paymentBo.getPayType()); // paymentItem.setPayType(paymentBo.getPayType());
paymentItem.setSupplierId(paymentBo.getSupplierId()); // paymentItem.setSupplierId(paymentBo.getSupplierId());
paymentItem.setItemPayAmount(currentItemPay); // paymentItem.setItemPayAmount(currentItemPay);
paymentItem.setVerificationId(verificationSubject.getVerificationId()); // paymentItem.setVerificationId(verificationSubject.getVerificationId());
paymentItem.setVerificationSubjectId(verificationSubject.getId()); // paymentItem.setVerificationSubjectId(verificationSubject.getId());
paymentItem.setCostApplyId(verificationSubject.getCostApplyId()); // paymentItem.setCostApplyId(verificationSubject.getCostApplyId());
paymentItem.setActivityId(verificationSubject.getActivityId()); // paymentItem.setActivityId(verificationSubject.getActivityId());
paymentItem.setSubjectId(verificationSubject.getSubjectId()); // paymentItem.setSubjectId(verificationSubject.getSubjectId());
paymentItem.setSubjectCode(verificationSubject.getSubjectCode()); // paymentItem.setSubjectCode(verificationSubject.getSubjectCode());
paymentItem.setSubjectName(verificationSubject.getSubjectName()); // paymentItem.setSubjectName(verificationSubject.getSubjectName());
paymentItemList.add(paymentItem); // paymentItemList.add(paymentItem);
//更新核销科目余额 // //更新核销科目余额
BigDecimal payAmountOfVer = verificationSubject.getPayAmount().add(currentItemPay); // BigDecimal payAmountOfVer = verificationSubject.getPayAmount().add(currentItemPay);
VtbVerificationSubject subjectParam = new VtbVerificationSubject(); // VtbVerificationSubject subjectParam = new VtbVerificationSubject();
subjectParam.setId(verificationSubject.getId()); // subjectParam.setId(verificationSubject.getId());
subjectParam.setPayAmount(payAmountOfVer); // subjectParam.setPayAmount(payAmountOfVer);
if(verificationSubject.getUsedAmount().compareTo(payAmountOfVer)==0){ // if(verificationSubject.getUsedAmount().compareTo(payAmountOfVer)==0){
subjectParam.setPayFinishedFlag(1); // subjectParam.setPayFinishedFlag(1);
} // }
verificationSubjectUpdateList.add(subjectParam); // verificationSubjectUpdateList.add(subjectParam);
return currentBalance; // return currentBalance;
} // }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void cancel(Long id) { public void cancel(String erpId) {
PayPayment dbPay = this.getById(id);
if(dbPay.getCancelFlag().equals(1)){ PayPayment dbPay = this.baseMapper.getByErpId(erpId);
Assert.throwEx("已取消,请勿重复提交"); if(dbPay==null){
} Assert.throwEx("没有该支付数据!");
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)
.distinct().collect(Collectors.toList());
List<Long> verSubjectIds = paymentItemList.stream().map(PayPaymentItem::getVerificationSubjectId)
.distinct().collect(Collectors.toList());
List<VtbVerificationSubject> verificationSubjectList = verificationSubjectService.listByIds(verSubjectIds);
for (VtbVerificationSubject verificationSubject : verificationSubjectList) {
for (PayPaymentItem paymentItem : paymentItemList) {
if(verificationSubject.getId().equals(paymentItem.getVerificationSubjectId())){
BigDecimal payAmount = verificationSubject.getPayAmount().subtract(paymentItem.getItemPayAmount());
verificationSubject.setPayAmount(payAmount);
}
}
} }
List<VtbVerificationSubject> verificationSubjectUpdateList = verificationSubjectList.stream().map(obj->{
VtbVerificationSubject param = new VtbVerificationSubject(); LambdaQueryWrapper<PayPayment> lambdaQueryWrapper = new LambdaQueryWrapper<>();
param.setId(obj.getId()); lambdaQueryWrapper.eq(PayPayment::getErpId,erpId);
param.setPayAmount(obj.getPayAmount()); this.remove(lambdaQueryWrapper);
param.setPayFinishedFlag(0);
return param; LambdaQueryWrapper<PayPaymentItem> paymentItemLambdaQueryWrapper = new LambdaQueryWrapper<>();
}).collect(Collectors.toList()); paymentItemLambdaQueryWrapper.eq(PayPaymentItem::getErpId,erpId);
//更新数据 paymentItemService.remove(paymentItemLambdaQueryWrapper);
PayPayment payPayment = new PayPayment();
payPayment.setId(id);
payPayment.setCancelFlag(1);
payPayment.setCancelTime(LocalDateTime.now());
this.updateById(payPayment);
paymentItemService.removeBatchByIds(paymentItemIds);
payHistoryItemService.removeBatchByIds(historyItemIds);
verificationSubjectService.updateBatchById(verificationSubjectUpdateList);
} }
@Override @Override

2
src/main/java/com/qs/serve/modules/vtb/service/VtbVerificationSubjectService.java

@ -16,5 +16,7 @@ public interface VtbVerificationSubjectService extends IService<VtbVerificationS
void removeByVerificationId(Long verificationId); void removeByVerificationId(Long verificationId);
VtbVerificationSubject getByVerificationSubjectCode(String verificationSubjectCode);
} }

6
src/main/java/com/qs/serve/modules/vtb/service/impl/VtbVerificationSubjectServiceImpl.java

@ -35,5 +35,11 @@ public class VtbVerificationSubjectServiceImpl extends ServiceImpl<VtbVerificati
this.remove(lqw); this.remove(lqw);
} }
@Override
public VtbVerificationSubject getByVerificationSubjectCode(String verificationSubjectCode) {
LambdaQueryWrapper<VtbVerificationSubject> lqw = new LambdaQueryWrapper<>();
lqw.eq(VtbVerificationSubject::getVerificationSubCode,verificationSubjectCode);
return this.getOne(lqw);
}
} }

Loading…
Cancel
Save