|
|
@@ -2,10 +2,13 @@ package com.sckw.freight.service;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.sckw.freight.entity.freight.KwpSettlementLogistics;
|
|
|
+import com.sckw.freight.entity.payment.PayOrder;
|
|
|
import com.sckw.freight.mapper.freight.KwpLedgerLogisticsMapper;
|
|
|
import com.sckw.freight.mapper.freight.KwpSettlementLogisticsMapper;
|
|
|
+import com.sckw.freight.mapper.payment.PayOrderMapper;
|
|
|
+import com.sckw.freight.model.dto.BusinessNo;
|
|
|
+import com.sckw.freight.model.dto.Order;
|
|
|
import com.sckw.freight.model.dto.PatchPay;
|
|
|
-import com.sckw.freight.model.dto.PayOrderDetail;
|
|
|
import com.sckw.freight.model.enums.ChannelEnum;
|
|
|
import com.sckw.freight.model.enums.KwpSettlementLogisticsStatusEnum;
|
|
|
import com.sckw.freight.model.po.LedgerLogisticsAndBuySellInfo;
|
|
|
@@ -14,9 +17,11 @@ import com.sckw.freight.service.freight.IKwpSettlementLogisticsService;
|
|
|
import com.sckw.freight.util.MoneyChange;
|
|
|
import com.sckw.freight.util.R;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
@@ -41,6 +46,8 @@ public class JobService {
|
|
|
KwpLedgerLogisticsMapper kwpLedgerLogisticsMapper;
|
|
|
@Autowired
|
|
|
KwpSettlementLogisticsMapper kwpSettlementLogisticsMapper;
|
|
|
+ @Autowired
|
|
|
+ PayOrderMapper payOrderMapper;
|
|
|
|
|
|
/**
|
|
|
* 【轮循程序】
|
|
|
@@ -72,47 +79,114 @@ public class JobService {
|
|
|
LambdaQueryWrapper<KwpSettlementLogistics> settlementLogisticsLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
settlementLogisticsLambdaQueryWrapper.eq(KwpSettlementLogistics::getLLedgerId, logisticsAndBuySellInfo.getId());
|
|
|
settlementLogisticsLambdaQueryWrapper.eq(KwpSettlementLogistics::getStatus, KwpSettlementLogisticsStatusEnum.Nopaid.getCode());
|
|
|
- settlementLogisticsLambdaQueryWrapper.select(KwpSettlementLogistics::getSlOrderNo);
|
|
|
+ settlementLogisticsLambdaQueryWrapper.select(KwpSettlementLogistics::getSlOrderNo, KwpSettlementLogistics::getId,
|
|
|
+ KwpSettlementLogistics::getRemark);
|
|
|
List<KwpSettlementLogistics> settlementLogistics = kwpSettlementLogisticsMapper.selectList(settlementLogisticsLambdaQueryWrapper);
|
|
|
if (settlementLogistics == null || settlementLogistics.isEmpty()) {
|
|
|
//没有未支付的结算信息 直接下一条
|
|
|
continue;
|
|
|
}
|
|
|
for (KwpSettlementLogistics settlementLogisticsInfo : settlementLogistics) {
|
|
|
+ boolean _cz = false, _yp = false, _qf = false, _tx = false;
|
|
|
try {
|
|
|
|
|
|
- R<PayOrderDetail> details = payCenterService.getPayDetailByOrderNo(settlementLogisticsInfo.getSlOrderNo());
|
|
|
- if (details == null || details.getCode() != 200 || details.getData() == null || !details.getStatus()) {
|
|
|
+// R<PayOrderDetail> details = payCenterService.getPayDetailByOrderNo(settlementLogisticsInfo.getSlOrderNo());
|
|
|
+// if (details == null || details.getCode() != 200 || details.getData() == null || !details.getStatus()) {
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+ //记录先关单号,防止重复调用 (0-失败,1一成功) remark=充值状态|预付状态|清分状态|提现状态
|
|
|
+ String remark = settlementLogisticsInfo.getRemark();
|
|
|
+ if (!StringUtils.isBlank(remark)) {
|
|
|
+ String[] split = remark.split("\\|");
|
|
|
+ if (split.length == 4) {
|
|
|
+ _cz = split[0].equals("1");
|
|
|
+ _yp = split[1].equals("1");
|
|
|
+ _qf = split[2].equals("1");
|
|
|
+ _tx = split[3].equals("1");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //只接查充值订单
|
|
|
+ LambdaQueryWrapper<PayOrder> payOrderLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ payOrderLambdaQueryWrapper.eq(PayOrder::getOrderNo, settlementLogisticsInfo.getSlOrderNo());
|
|
|
+ payOrderLambdaQueryWrapper.eq(PayOrder::getStatus, 1);//已支付
|
|
|
+ List<PayOrder> payOrders = payOrderMapper.selectList(payOrderLambdaQueryWrapper);
|
|
|
+ if (payOrders == null || payOrders.isEmpty()) {
|
|
|
+ _cz = false;
|
|
|
continue;
|
|
|
}
|
|
|
+ _cz = true;
|
|
|
+ PayOrder details = payOrders.get(0);
|
|
|
+ BigDecimal money = MoneyChange.smallMoney(new BigDecimal(details.getMoney()));
|
|
|
//根据充值订单状态 处理结算状态
|
|
|
- if (details.getData().getStatus() == 1) {//已支付
|
|
|
- //发起预付
|
|
|
- payCenterService.advancePayApply(logisticsAndBuySellInfo.getBuyUid() , ChannelEnum.XW,
|
|
|
- logisticsAndBuySellInfo.getSellUid() , MoneyChange.bigMoney(details.getData().getMoney()));
|
|
|
-
|
|
|
-
|
|
|
+ //if (details.getData().getStatus() == 1) {//已支付
|
|
|
+ if (!_yp) { //发起预付
|
|
|
+ R<Order> orderR = payCenterService.advancePayApply(logisticsAndBuySellInfo.getBuyUid(), ChannelEnum.XW,
|
|
|
+ logisticsAndBuySellInfo.getSellUid(), MoneyChange.bigMoney(money));
|
|
|
+ if (orderR == null || !orderR.getStatus() || orderR.getData() == null) {
|
|
|
+ _yp = false;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ _yp = true;
|
|
|
+ }
|
|
|
+ if (_yp && !_qf) {
|
|
|
// 1.记账
|
|
|
List<PatchPay> list = new ArrayList<>();
|
|
|
PatchPay patchPay = new PatchPay();
|
|
|
- patchPay.setUid(logisticsAndBuySellInfo.getSellUid() );
|
|
|
- patchPay.setMoney(MoneyChange.bigMoney(details.getData().getMoney()));
|
|
|
+ patchPay.setUid(logisticsAndBuySellInfo.getSellUid());
|
|
|
+ patchPay.setMoney(MoneyChange.bigMoney(money));
|
|
|
+ patchPay.setRemark("对账单结算");
|
|
|
list.add(patchPay);
|
|
|
- //清分
|
|
|
- payCenterService.payAgentPayV2(logisticsAndBuySellInfo.getBuyUid() , logisticsAndBuySellInfo.getSellUid() , ChannelEnum.XW,
|
|
|
- MoneyChange.bigMoney(details.getData().getMoney()), list, settlementLogisticsInfo.getSlOrderNo(), "1");
|
|
|
+ try {
|
|
|
|
|
|
- //提现
|
|
|
- payCenterService.withdrawTake(logisticsAndBuySellInfo.getSellUid() , ChannelEnum.XW,
|
|
|
- MoneyChange.bigMoney(details.getData().getMoney()),
|
|
|
- "");
|
|
|
+ //清分
|
|
|
+ R<BusinessNo> businessNoR = payCenterService.payAgentPayV2(logisticsAndBuySellInfo.getBuyUid(), logisticsAndBuySellInfo.getSellUid(), ChannelEnum.XW,
|
|
|
+ MoneyChange.bigMoney(money), list, settlementLogisticsInfo.getSlOrderNo(), "1");
|
|
|
+ if (businessNoR == null || !businessNoR.getStatus() || businessNoR.getData() == null) {
|
|
|
+ _qf = false;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ _qf = true;
|
|
|
+ } catch (Exception e) {
|
|
|
+ _qf = false;
|
|
|
+ log.error("发起预付异常", e);
|
|
|
+ }
|
|
|
|
|
|
- //修改结算单状态
|
|
|
- iKwpSettlementLogisticsService.updateSettlementLogisticsStatusPaid(settlementLogisticsInfo, details.getData());
|
|
|
}
|
|
|
+ if (_qf && !_tx) {
|
|
|
+ try {
|
|
|
+ //提现
|
|
|
+ R<Order> withdrawTake = payCenterService.withdrawTake(logisticsAndBuySellInfo.getSellUid(), ChannelEnum.XW,
|
|
|
+ MoneyChange.bigMoney(money),
|
|
|
+ "提现");
|
|
|
+ if (withdrawTake == null || !withdrawTake.getStatus() || withdrawTake.getData() == null) {
|
|
|
+ _tx = false;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ _tx = true;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ _tx = false;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (_tx) {
|
|
|
+ //修改结算单状态
|
|
|
+ iKwpSettlementLogisticsService.updateSettlementLogisticsStatusPaid(settlementLogisticsInfo, details);
|
|
|
+ } // }
|
|
|
} catch (Exception e) {
|
|
|
log.error("获取/处理 充值详情异常", e);
|
|
|
}
|
|
|
+ finally {
|
|
|
+ try {
|
|
|
+ KwpSettlementLogistics newSetlementLogistics = new KwpSettlementLogistics();
|
|
|
+ newSetlementLogistics.setId(settlementLogisticsInfo.getId());
|
|
|
+ String remark =(_cz?"1":"0")+"|"+(_yp?"1":"0")+"|"+(_qf?"1":"0")+"|"+(_tx?"1":"0");
|
|
|
+ newSetlementLogistics.setRemark(remark);
|
|
|
+ kwpSettlementLogisticsMapper.updateById(newSetlementLogistics);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("修改结算单状态异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
log.error("【" + logisticsAndBuySellInfo.getId() + "】轮循任务执行失败", e);
|