|
|
@@ -23,6 +23,8 @@ import com.sckw.payment.model.dto.SettlementWalletDto;
|
|
|
import com.sckw.payment.model.vo.req.SettlementWalletReq;
|
|
|
import com.sckw.payment.model.vo.req.WalletPayReq;
|
|
|
import com.sckw.payment.model.vo.res.SettlementWalletVo;
|
|
|
+import com.sckw.redis.config.RedisLockUtil;
|
|
|
+import com.sckw.redis.constant.RedisConstant;
|
|
|
import com.sckw.system.api.RemoteSystemService;
|
|
|
import com.sckw.system.api.model.dto.res.UserCacheResDto;
|
|
|
import jakarta.annotation.Resource;
|
|
|
@@ -62,6 +64,8 @@ public class KwpSettlementWalletService {
|
|
|
@Resource
|
|
|
private KwpWalletRelationService walletRelationService;
|
|
|
@Resource
|
|
|
+ private RedisLockUtil redisLockUtil;
|
|
|
+ @Resource
|
|
|
private KwpSettlementTradeTrackService settlementTradeTrackService;
|
|
|
@DubboReference(version = "2.0.0", group = "design", check = false)
|
|
|
private RemoteSystemService remoteSystemService;
|
|
|
@@ -227,37 +231,40 @@ public class KwpSettlementWalletService {
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public String confirmTradePayment(WalletPayReq walletPayReq) {
|
|
|
- SettlementTradeDto byId = kwpSettlementTradeService.getById(walletPayReq.getIdLong(), TradeUnitType.SELL);
|
|
|
- if (Objects.isNull(byId)) {
|
|
|
- throw new BusinessException("结算单不存在");
|
|
|
- }
|
|
|
- if (StringUtils.isNotBlank(byId.getTrading()) && !byId.getTrading().startsWith(TradingEnum.RECEIVE_PAY.getValue())) {
|
|
|
- throw new BusinessException("只支持货货到付款方式订单进行当前操作");
|
|
|
- }
|
|
|
- List<LedgerUnitDto> listById = kwpSettlementTradeService.getListById(walletPayReq.getIdLong());
|
|
|
- if (CollectionUtils.isEmpty(listById) || listById.size() != 2) {
|
|
|
- throw new BusinessException("对账单交易企业双方不存在或缺少");
|
|
|
- }
|
|
|
- Long uid = null;
|
|
|
- Long filter = null;
|
|
|
- for (LedgerUnitDto ledgerUnitDto : listById) {
|
|
|
- Integer unitType = ledgerUnitDto.getUnitType();
|
|
|
- if (TradeUnitType.PURCHASE.equals(unitType)) {
|
|
|
- uid = ledgerUnitDto.getTopEntId();
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (TradeUnitType.SELL.equals(unitType)) {
|
|
|
- filter = ledgerUnitDto.getTopEntId();
|
|
|
- }
|
|
|
- }
|
|
|
- String relation = walletRelationService.getRelation(uid);
|
|
|
- String filterUser = walletRelationService.getRelation(filter);
|
|
|
- if (StringUtils.isBlank(relation) || StringUtils.isBlank(filterUser)) {
|
|
|
- throw new BusinessException("顶级企业未开通电子钱包");
|
|
|
- }
|
|
|
- //付款金额
|
|
|
- BigDecimal price = walletPayReq.getPrice();
|
|
|
- //todo-xcq-完善
|
|
|
+ String key = String.format(RedisConstant.SETTLEMENT_KEY, walletPayReq.getId());
|
|
|
+ if (redisLockUtil.tryLock(key)) {
|
|
|
+ try {
|
|
|
+ SettlementTradeDto byId = kwpSettlementTradeService.getById(walletPayReq.getIdLong(), TradeUnitType.SELL);
|
|
|
+ if (Objects.isNull(byId)) {
|
|
|
+ throw new BusinessException("结算单不存在");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(byId.getTrading()) && !byId.getTrading().startsWith(TradingEnum.RECEIVE_PAY.getValue())) {
|
|
|
+ throw new BusinessException("只支持货货到付款方式订单进行当前操作");
|
|
|
+ }
|
|
|
+ List<LedgerUnitDto> listById = kwpSettlementTradeService.getListById(walletPayReq.getIdLong());
|
|
|
+ if (CollectionUtils.isEmpty(listById) || listById.size() != 2) {
|
|
|
+ throw new BusinessException("对账单交易企业双方不存在或缺少");
|
|
|
+ }
|
|
|
+ Long uid = null;
|
|
|
+ Long filter = null;
|
|
|
+ for (LedgerUnitDto ledgerUnitDto : listById) {
|
|
|
+ Integer unitType = ledgerUnitDto.getUnitType();
|
|
|
+ if (TradeUnitType.PURCHASE.equals(unitType)) {
|
|
|
+ uid = ledgerUnitDto.getTopEntId();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (TradeUnitType.SELL.equals(unitType)) {
|
|
|
+ filter = ledgerUnitDto.getTopEntId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String relation = walletRelationService.getRelation(uid);
|
|
|
+ String filterUser = walletRelationService.getRelation(filter);
|
|
|
+ if (StringUtils.isBlank(relation) || StringUtils.isBlank(filterUser)) {
|
|
|
+ throw new BusinessException("顶级企业未开通电子钱包");
|
|
|
+ }
|
|
|
+ //付款金额
|
|
|
+ BigDecimal price = walletPayReq.getPrice();
|
|
|
+ //todo-xcq-完善
|
|
|
|
|
|
// R<List<WalletDto>> wallet = payCenterService.wallet(relation, ChannelEnum.getByCode(byId.getTrading()), filterUser);
|
|
|
// if (CollectionUtils.isEmpty(wallet.getData())) {
|
|
|
@@ -269,45 +276,50 @@ public class KwpSettlementWalletService {
|
|
|
// if (bigDecimal.compareTo(price) < 0) {
|
|
|
// throw new BusinessException("钱包可用余额不足");
|
|
|
// }
|
|
|
- //待付款金额-本次付款金额= 剩余待付款金额
|
|
|
- BigDecimal subtract = byId.getWaitPrice().subtract(walletPayReq.getPrice());
|
|
|
- if (subtract.compareTo(new BigDecimal("0.0")) < 0) {
|
|
|
- throw new BusinessException("付款金额不能大于待付款金额");
|
|
|
+ //待付款金额-本次付款金额= 剩余待付款金额
|
|
|
+ BigDecimal subtract = byId.getWaitPrice().subtract(walletPayReq.getPrice());
|
|
|
+ if (subtract.compareTo(new BigDecimal("0.0")) < 0) {
|
|
|
+ throw new BusinessException("付款金额不能大于待付款金额");
|
|
|
+ }
|
|
|
+ //新增电子钱包结算记录
|
|
|
+ KwpSettlementWallet kwpSettlementWallet = new KwpSettlementWallet();
|
|
|
+ kwpSettlementWallet.setId(new IdWorker(1).nextId());
|
|
|
+ kwpSettlementWallet.setEntId(LoginUserHolder.getEntId());
|
|
|
+ kwpSettlementWallet.setSettlementId(walletPayReq.getIdLong());
|
|
|
+ kwpSettlementWallet.setOrderType(SettlementOrderTypeEnum.TRADE.getStatus());
|
|
|
+ kwpSettlementWallet.setChannel(WalletChannelEnum.getValue(byId.getTrading()));
|
|
|
+ kwpSettlementWallet.setPayTime(LocalDateTime.now());
|
|
|
+ kwpSettlementWallet.setPayPrice(walletPayReq.getPrice());
|
|
|
+ kwpSettlementWallet.setTopayPrice(subtract);
|
|
|
+ kwpSettlementWallet.setType(SettlementWalletPayTypeEnum.CASH_ON_DELIVERY.getStatus());
|
|
|
+ kwpSettlementWallet.setRemark("");
|
|
|
+ kwpSettlementWallet.setStatus(0);
|
|
|
+ kwpSettlementWallet.setCreateBy(LoginUserHolder.getUserId());
|
|
|
+ kwpSettlementWallet.setCreateTime(LocalDateTime.now());
|
|
|
+ kwpSettlementWallet.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ kwpSettlementWallet.setUpdateTime(LocalDateTime.now());
|
|
|
+ kwpSettlementWallet.setDelFlag(0);
|
|
|
+ settlementWalletMapper.insert(kwpSettlementWallet);
|
|
|
+
|
|
|
+ //更新交易结算单状态和金额
|
|
|
+ KwpSettlementTrade kwpSettlementTrade = new KwpSettlementTrade();
|
|
|
+ kwpSettlementTrade.setId(byId.getId());
|
|
|
+ kwpSettlementTrade.setActualPrice(byId.getActualPrice().add(price));
|
|
|
+ kwpSettlementTrade.setStatus(subtract.compareTo(new BigDecimal("0.0")) == 0 ? SettlementEnum.ALL_PAYMENT.getStatus()
|
|
|
+ : SettlementEnum.PARTIAL_PAYMENT.getStatus());
|
|
|
+ kwpSettlementTrade.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ kwpSettlementTrade.setUpdateTime(LocalDateTime.now());
|
|
|
+ kwpSettlementTradeService.updateById(kwpSettlementTrade);
|
|
|
+
|
|
|
+ settlementTradeTrackService.save(KwpSettlementTradeTrack.build(byId.getId(), SettlementTrackEnum.RECEIVE_PAY.getStatus()));
|
|
|
+ //todo-xcq 调用中台接口
|
|
|
+
|
|
|
+ return "付款确认成功";
|
|
|
+ } finally {
|
|
|
+ redisLockUtil.unlock(key);
|
|
|
+ }
|
|
|
}
|
|
|
- //新增电子钱包结算记录
|
|
|
- KwpSettlementWallet kwpSettlementWallet = new KwpSettlementWallet();
|
|
|
- kwpSettlementWallet.setId(new IdWorker(1).nextId());
|
|
|
- kwpSettlementWallet.setEntId(LoginUserHolder.getEntId());
|
|
|
- kwpSettlementWallet.setSettlementId(walletPayReq.getIdLong());
|
|
|
- kwpSettlementWallet.setOrderType(SettlementOrderTypeEnum.TRADE.getStatus());
|
|
|
- kwpSettlementWallet.setChannel(WalletChannelEnum.getValue(byId.getTrading()));
|
|
|
- kwpSettlementWallet.setPayTime(LocalDateTime.now());
|
|
|
- kwpSettlementWallet.setPayPrice(walletPayReq.getPrice());
|
|
|
- kwpSettlementWallet.setTopayPrice(subtract);
|
|
|
- kwpSettlementWallet.setType(SettlementWalletPayTypeEnum.CASH_ON_DELIVERY.getStatus());
|
|
|
- kwpSettlementWallet.setRemark("");
|
|
|
- kwpSettlementWallet.setStatus(0);
|
|
|
- kwpSettlementWallet.setCreateBy(LoginUserHolder.getUserId());
|
|
|
- kwpSettlementWallet.setCreateTime(LocalDateTime.now());
|
|
|
- kwpSettlementWallet.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
- kwpSettlementWallet.setUpdateTime(LocalDateTime.now());
|
|
|
- kwpSettlementWallet.setDelFlag(0);
|
|
|
- settlementWalletMapper.insert(kwpSettlementWallet);
|
|
|
-
|
|
|
- //更新交易结算单状态和金额
|
|
|
- KwpSettlementTrade kwpSettlementTrade = new KwpSettlementTrade();
|
|
|
- kwpSettlementTrade.setId(byId.getId());
|
|
|
- kwpSettlementTrade.setActualPrice(byId.getActualPrice().add(price));
|
|
|
- kwpSettlementTrade.setStatus(subtract.compareTo(new BigDecimal("0.0")) == 0 ? SettlementEnum.ALL_PAYMENT.getStatus()
|
|
|
- : SettlementEnum.PARTIAL_PAYMENT.getStatus());
|
|
|
- kwpSettlementTrade.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
- kwpSettlementTrade.setUpdateTime(LocalDateTime.now());
|
|
|
- kwpSettlementTradeService.updateById(kwpSettlementTrade);
|
|
|
-
|
|
|
- settlementTradeTrackService.save(KwpSettlementTradeTrack.build(byId.getId(), SettlementTrackEnum.RECEIVE_PAY.getStatus()));
|
|
|
- //todo-xcq 调用中台接口
|
|
|
-
|
|
|
- return "付款确认成功";
|
|
|
+ return "请勿重复提交!";
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -388,44 +400,54 @@ public class KwpSettlementWalletService {
|
|
|
* @return
|
|
|
*/
|
|
|
public String confirmTradeCollection(Long id) {
|
|
|
- SettlementTradeDto byId = kwpSettlementTradeService.getById(id, TradeUnitType.PURCHASE);
|
|
|
- if (Objects.isNull(byId)) {
|
|
|
- throw new BusinessException("结算单不存在");
|
|
|
- }
|
|
|
- if (StringUtils.isNotBlank(byId.getTrading()) && !byId.getTrading().startsWith(TradingEnum.PRE_PAY.getValue())) {
|
|
|
- throw new BusinessException("只支持预付款交易方法进行预付款确认操作");
|
|
|
+ String key = String.format(RedisConstant.SETTLEMENT_KEY, id);
|
|
|
+
|
|
|
+ if (redisLockUtil.tryLock(key)) {
|
|
|
+ try {
|
|
|
+ SettlementTradeDto byId = kwpSettlementTradeService.getById(id, TradeUnitType.PURCHASE);
|
|
|
+ if (Objects.isNull(byId)) {
|
|
|
+ throw new BusinessException("结算单不存在");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(byId.getTrading()) && !byId.getTrading().startsWith(TradingEnum.PRE_PAY.getValue())) {
|
|
|
+ throw new BusinessException("只支持预付款交易方式进行预付款确认操作");
|
|
|
+ }
|
|
|
+ //更新交易结算单状态和金额
|
|
|
+ KwpSettlementTrade kwpSettlementTrade = new KwpSettlementTrade();
|
|
|
+ kwpSettlementTrade.setId(byId.getId());
|
|
|
+ kwpSettlementTrade.setActualPrice(byId.getTotalPrice());
|
|
|
+ kwpSettlementTrade.setStatus(SettlementEnum.ALL_PAYMENT.getStatus());
|
|
|
+ kwpSettlementTrade.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ kwpSettlementTrade.setUpdateTime(LocalDateTime.now());
|
|
|
+ kwpSettlementTradeService.updateById(kwpSettlementTrade);
|
|
|
+ //新增电子钱包结算记录
|
|
|
+ KwpSettlementWallet kwpSettlementWallet = new KwpSettlementWallet();
|
|
|
+ kwpSettlementWallet.setId(new IdWorker(1).nextId());
|
|
|
+ kwpSettlementWallet.setEntId(LoginUserHolder.getEntId());
|
|
|
+ kwpSettlementWallet.setSettlementId(byId.getId());
|
|
|
+ kwpSettlementWallet.setOrderType(SettlementOrderTypeEnum.TRADE.getStatus());
|
|
|
+ kwpSettlementWallet.setChannel(WalletChannelEnum.getValue(byId.getTrading()));
|
|
|
+ kwpSettlementWallet.setPayTime(LocalDateTime.now());
|
|
|
+ kwpSettlementWallet.setPayPrice(byId.getTotalPrice());
|
|
|
+ kwpSettlementWallet.setTopayPrice(new BigDecimal("0.0"));
|
|
|
+ kwpSettlementWallet.setType(SettlementWalletPayTypeEnum.ADVANCE_PAYMENT.getStatus());
|
|
|
+ kwpSettlementWallet.setRemark("");
|
|
|
+ kwpSettlementWallet.setStatus(0);
|
|
|
+ kwpSettlementWallet.setCreateBy(LoginUserHolder.getUserId());
|
|
|
+ kwpSettlementWallet.setCreateTime(LocalDateTime.now());
|
|
|
+ kwpSettlementWallet.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ kwpSettlementWallet.setUpdateTime(LocalDateTime.now());
|
|
|
+ kwpSettlementWallet.setDelFlag(0);
|
|
|
+ settlementWalletMapper.insert(kwpSettlementWallet);
|
|
|
+ settlementTradeTrackService.save(KwpSettlementTradeTrack.build(byId.getId(), SettlementTrackEnum.PRE_PAY.getStatus()));
|
|
|
+ //todo-xcq 调用中台接口
|
|
|
+ //todo-xcq 调用订单接口,更新订单状态
|
|
|
+ return "确认回款成功";
|
|
|
+ } finally {
|
|
|
+ redisLockUtil.unlock(key);
|
|
|
+ }
|
|
|
}
|
|
|
- //更新交易结算单状态和金额
|
|
|
- KwpSettlementTrade kwpSettlementTrade = new KwpSettlementTrade();
|
|
|
- kwpSettlementTrade.setId(byId.getId());
|
|
|
- kwpSettlementTrade.setActualPrice(byId.getTotalPrice());
|
|
|
- kwpSettlementTrade.setStatus(SettlementEnum.ALL_PAYMENT.getStatus());
|
|
|
- kwpSettlementTrade.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
- kwpSettlementTrade.setUpdateTime(LocalDateTime.now());
|
|
|
- kwpSettlementTradeService.updateById(kwpSettlementTrade);
|
|
|
- //新增电子钱包结算记录
|
|
|
- KwpSettlementWallet kwpSettlementWallet = new KwpSettlementWallet();
|
|
|
- kwpSettlementWallet.setId(new IdWorker(1).nextId());
|
|
|
- kwpSettlementWallet.setEntId(LoginUserHolder.getEntId());
|
|
|
- kwpSettlementWallet.setSettlementId(byId.getId());
|
|
|
- kwpSettlementWallet.setOrderType(SettlementOrderTypeEnum.TRADE.getStatus());
|
|
|
- kwpSettlementWallet.setChannel(WalletChannelEnum.getValue(byId.getTrading()));
|
|
|
- kwpSettlementWallet.setPayTime(LocalDateTime.now());
|
|
|
- kwpSettlementWallet.setPayPrice(byId.getTotalPrice());
|
|
|
- kwpSettlementWallet.setTopayPrice(new BigDecimal("0.0"));
|
|
|
- kwpSettlementWallet.setType(SettlementWalletPayTypeEnum.ADVANCE_PAYMENT.getStatus());
|
|
|
- kwpSettlementWallet.setRemark("");
|
|
|
- kwpSettlementWallet.setStatus(0);
|
|
|
- kwpSettlementWallet.setCreateBy(LoginUserHolder.getUserId());
|
|
|
- kwpSettlementWallet.setCreateTime(LocalDateTime.now());
|
|
|
- kwpSettlementWallet.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
- kwpSettlementWallet.setUpdateTime(LocalDateTime.now());
|
|
|
- kwpSettlementWallet.setDelFlag(0);
|
|
|
- settlementWalletMapper.insert(kwpSettlementWallet);
|
|
|
- settlementTradeTrackService.save(KwpSettlementTradeTrack.build(byId.getId(), SettlementTrackEnum.PRE_PAY.getStatus()));
|
|
|
- //todo-xcq 调用中台接口
|
|
|
- //todo-xcq 调用订单接口,更新订单状态
|
|
|
- return "确认回款成功";
|
|
|
+ return "请勿重复提交!";
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|