|
@@ -5,12 +5,16 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.sckw.core.common.enums.enums.ErrorCodeEnum;
|
|
import com.sckw.core.common.enums.enums.ErrorCodeEnum;
|
|
|
import com.sckw.core.exception.BusinessPlatfromException;
|
|
import com.sckw.core.exception.BusinessPlatfromException;
|
|
|
import com.sckw.core.model.constant.Global;
|
|
import com.sckw.core.model.constant.Global;
|
|
|
|
|
+import com.sckw.core.model.enums.ParkingChangeStrategyEnum;
|
|
|
import com.sckw.core.web.context.LoginUserHolder;
|
|
import com.sckw.core.web.context.LoginUserHolder;
|
|
|
import com.sckw.transport.model.KwtParkingChargeStrategy;
|
|
import com.sckw.transport.model.KwtParkingChargeStrategy;
|
|
|
import com.sckw.transport.model.KwtParkingChargeStrategyUnit;
|
|
import com.sckw.transport.model.KwtParkingChargeStrategyUnit;
|
|
|
import com.sckw.transport.model.KwtParkingWalletFee;
|
|
import com.sckw.transport.model.KwtParkingWalletFee;
|
|
|
|
|
+import com.sckw.transport.model.KwtParkingWalletFeeBalance;
|
|
|
import com.sckw.transport.model.param.ParkingWalletFeeEstimateQueryParam;
|
|
import com.sckw.transport.model.param.ParkingWalletFeeEstimateQueryParam;
|
|
|
import com.sckw.transport.model.param.ParkingWalletFeeEstimateResp;
|
|
import com.sckw.transport.model.param.ParkingWalletFeeEstimateResp;
|
|
|
|
|
+import com.sckw.transport.api.model.param.ParkingWalletFeeFreezeParam;
|
|
|
|
|
+import com.sckw.transport.api.model.vo.ParkingWalletFeeFreezeResult;
|
|
|
import com.sckw.transport.repository.KwtParkingChangeStrategyRepository;
|
|
import com.sckw.transport.repository.KwtParkingChangeStrategyRepository;
|
|
|
import com.sckw.transport.repository.KwtParkingChangeStrategyUnitRepository;
|
|
import com.sckw.transport.repository.KwtParkingChangeStrategyUnitRepository;
|
|
|
import com.sckw.system.api.RemoteSystemService;
|
|
import com.sckw.system.api.RemoteSystemService;
|
|
@@ -21,10 +25,12 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
|
import java.util.Comparator;
|
|
import java.util.Comparator;
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
|
|
|
|
|
@@ -43,6 +49,8 @@ public class ParkingWalletFeeService {
|
|
|
|
|
|
|
|
private static final BigDecimal ZERO_AMOUNT = BigDecimal.ZERO;
|
|
private static final BigDecimal ZERO_AMOUNT = BigDecimal.ZERO;
|
|
|
private static final int STRATEGY_OPEN = 1;
|
|
private static final int STRATEGY_OPEN = 1;
|
|
|
|
|
+ private static final int TRADE_TYPE_FREEZE = 4;
|
|
|
|
|
+ private static final int TRADE_TYPE_UNFREEZE = 5;
|
|
|
|
|
|
|
|
private final KwtParkingWalletFeeRepository parkingWalletFeeRepository;
|
|
private final KwtParkingWalletFeeRepository parkingWalletFeeRepository;
|
|
|
private final KwtParkingWalletFeeBalanceRepository parkingWalletFeeBalanceRepository;
|
|
private final KwtParkingWalletFeeBalanceRepository parkingWalletFeeBalanceRepository;
|
|
@@ -72,7 +80,7 @@ public class ParkingWalletFeeService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 查询采购方当前服务费余额
|
|
// 查询采购方当前服务费余额
|
|
|
- BigDecimal serviceFeeBalance = queryServiceFeeBalance(entId);
|
|
|
|
|
|
|
+ BigDecimal serviceFeeBalance = queryServiceFeeBalance(entId, null);
|
|
|
|
|
|
|
|
// 查询当前企业生效中的收费策略(仅取状态开启的最新一条)
|
|
// 查询当前企业生效中的收费策略(仅取状态开启的最新一条)
|
|
|
KwtParkingChargeStrategy currentStrategy = queryCurrentEnableStrategy(entId);
|
|
KwtParkingChargeStrategy currentStrategy = queryCurrentEnableStrategy(entId);
|
|
@@ -101,6 +109,261 @@ public class ParkingWalletFeeService {
|
|
|
return resp;
|
|
return resp;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 贸易订单下单应用收费策略并冻结服务费
|
|
|
|
|
+ * 规则:
|
|
|
|
|
+ * 1. 收费策略开关未开启时,不冻结服务费,订单记录为未应用收费策略
|
|
|
|
|
+ * 2. 收费策略开关开启时,冻结金额=采购数量*策略单价,并记录策略信息
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param param 冻结参数
|
|
|
|
|
+ * @return 收费策略应用结果
|
|
|
|
|
+ */
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public ParkingWalletFeeFreezeResult applyChargeStrategyFreeze(ParkingWalletFeeFreezeParam param) {
|
|
|
|
|
+ log.info("贸易订单应用收费策略开始,param:{}", param);
|
|
|
|
|
+ if (param == null || param.getProEntId() == null) {
|
|
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "采购方企业id不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (param.getPurchaseQuantity() == null || param.getPurchaseQuantity().compareTo(ZERO_AMOUNT) < 0) {
|
|
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "采购数量不能为空且不能小于0");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (param.getOrderNo() == null || param.getOrderNo().isBlank()) {
|
|
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "贸易订单号不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ParkingWalletFeeFreezeResult result = new ParkingWalletFeeFreezeResult();
|
|
|
|
|
+ result.setApplyChargeStrategy(Global.NO);
|
|
|
|
|
+ result.setFreezeAmount(ZERO_AMOUNT);
|
|
|
|
|
+
|
|
|
|
|
+ KwtParkingChargeStrategy currentStrategy = queryCurrentEnableStrategy(param.getProEntId());
|
|
|
|
|
+ if (currentStrategy == null || !Objects.equals(currentStrategy.getStatus(), STRATEGY_OPEN)) {
|
|
|
|
|
+ log.info("收费策略未开启或未匹配,跳过服务费冻结,proEntId:{}, orderNo:{}",
|
|
|
|
|
+ param.getProEntId(), param.getOrderNo());
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal unitFee = currentStrategy.getMethod() == null ? ZERO_AMOUNT : currentStrategy.getMethod();
|
|
|
|
|
+ if (unitFee.compareTo(ZERO_AMOUNT) <= 0) {
|
|
|
|
|
+ log.info("收费策略单价无效,跳过服务费冻结,strategyId:{}, unitFee:{}",
|
|
|
|
|
+ currentStrategy.getId(), unitFee);
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal freezeAmount = param.getPurchaseQuantity().multiply(unitFee).setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
+ KwtParkingWalletFee walletFee = queryWalletFee(param.getProEntId(), param.getSupEntId());
|
|
|
|
|
+ if (walletFee == null) {
|
|
|
|
|
+ log.warn("服务费账户不存在,proEntId:{}, supEntId:{}, orderNo:{}",
|
|
|
|
|
+ param.getProEntId(), param.getSupEntId(), param.getOrderNo());
|
|
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "采购方服务费账户不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal currentBalance = walletFee.getServiceFeeBalance() == null ? ZERO_AMOUNT : walletFee.getServiceFeeBalance();
|
|
|
|
|
+ if (currentBalance.compareTo(freezeAmount) < 0) {
|
|
|
|
|
+ log.warn("服务费余额不足,proEntId:{}, orderNo:{}, balance:{}, freezeAmount:{}",
|
|
|
|
|
+ param.getProEntId(), param.getOrderNo(), currentBalance, freezeAmount);
|
|
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "服务费余额不足,无法下单");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal currentTradingAmount = walletFee.getTradingAmount() == null ? ZERO_AMOUNT : walletFee.getTradingAmount();
|
|
|
|
|
+ walletFee.setServiceFeeBalance(currentBalance.subtract(freezeAmount));
|
|
|
|
|
+ walletFee.setTradingAmount(currentTradingAmount.add(freezeAmount));
|
|
|
|
|
+ parkingWalletFeeRepository.updateById(walletFee);
|
|
|
|
|
+
|
|
|
|
|
+ saveFreezeWalletBalanceLog(param, walletFee, freezeAmount);
|
|
|
|
|
+
|
|
|
|
|
+ result.setApplyChargeStrategy(Global.YES);
|
|
|
|
|
+ result.setChargeStrategyId(currentStrategy.getId());
|
|
|
|
|
+ result.setChargeStrategyDesc(buildStrategyMethodDesc(currentStrategy));
|
|
|
|
|
+ result.setFreezeAmount(freezeAmount);
|
|
|
|
|
+ result.setServiceFeeBalance(walletFee.getServiceFeeBalance());
|
|
|
|
|
+ log.info("贸易订单应用收费策略完成,orderNo:{}, result:{}", param.getOrderNo(), result);
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 贸易订单审核拒绝解冻服务费
|
|
|
|
|
+ * 规则:根据订单冻结记录解冻,返还服务费余额并写入钱包日志
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param param 解冻参数
|
|
|
|
|
+ * @return 解冻结果(含采购方服务费余额)
|
|
|
|
|
+ */
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public ParkingWalletFeeFreezeResult unfreezeChargeStrategy(ParkingWalletFeeFreezeParam param) {
|
|
|
|
|
+ log.info("贸易订单解冻服务费开始,param:{}", param);
|
|
|
|
|
+ validateUnfreezeParam(param);
|
|
|
|
|
+
|
|
|
|
|
+ ParkingWalletFeeFreezeResult result = new ParkingWalletFeeFreezeResult();
|
|
|
|
|
+ result.setApplyChargeStrategy(Global.YES);
|
|
|
|
|
+
|
|
|
|
|
+ if (existsUnfreezeRecord(param.getOrderNo(), param.getProEntId(), param.getSupEntId())) {
|
|
|
|
|
+ log.info("服务费已解冻,跳过重复处理,orderNo:{}, proEntId:{}", param.getOrderNo(), param.getProEntId());
|
|
|
|
|
+ result.setServiceFeeBalance(queryServiceFeeBalance(param.getProEntId(), param.getSupEntId()));
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ KwtParkingWalletFeeBalance freezeRecord = queryFreezeBalanceRecord(param);
|
|
|
|
|
+ if (freezeRecord == null) {
|
|
|
|
|
+ log.warn("未找到服务费冻结记录,orderNo:{}, proEntId:{}", param.getOrderNo(), param.getProEntId());
|
|
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "服务费冻结记录不存在,无法解冻");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal unfreezeAmount = freezeRecord.getTradeAmount() == null ? ZERO_AMOUNT : freezeRecord.getTradeAmount();
|
|
|
|
|
+ if (unfreezeAmount.compareTo(ZERO_AMOUNT) <= 0) {
|
|
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "服务费冻结金额异常,无法解冻");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ KwtParkingWalletFee walletFee = queryWalletFee(param.getProEntId(), param.getSupEntId());
|
|
|
|
|
+ if (walletFee == null) {
|
|
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "采购方服务费账户不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal currentTradingAmount = walletFee.getTradingAmount() == null ? ZERO_AMOUNT : walletFee.getTradingAmount();
|
|
|
|
|
+ if (currentTradingAmount.compareTo(unfreezeAmount) < 0) {
|
|
|
|
|
+ log.warn("服务费履约中金额不足,无法解冻,orderNo:{}, tradingAmount:{}, unfreezeAmount:{}",
|
|
|
|
|
+ param.getOrderNo(), currentTradingAmount, unfreezeAmount);
|
|
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "服务费履约中金额不足,无法解冻");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal currentBalance = walletFee.getServiceFeeBalance() == null ? ZERO_AMOUNT : walletFee.getServiceFeeBalance();
|
|
|
|
|
+ walletFee.setServiceFeeBalance(currentBalance.add(unfreezeAmount));
|
|
|
|
|
+ walletFee.setTradingAmount(currentTradingAmount.subtract(unfreezeAmount));
|
|
|
|
|
+ parkingWalletFeeRepository.updateById(walletFee);
|
|
|
|
|
+
|
|
|
|
|
+ saveUnfreezeWalletBalanceLog(param, walletFee, unfreezeAmount);
|
|
|
|
|
+ result.setFreezeAmount(unfreezeAmount);
|
|
|
|
|
+ result.setServiceFeeBalance(walletFee.getServiceFeeBalance());
|
|
|
|
|
+ log.info("贸易订单解冻服务费完成,orderNo:{}, unfreezeAmount:{}, balanceAfter:{}",
|
|
|
|
|
+ param.getOrderNo(), unfreezeAmount, walletFee.getServiceFeeBalance());
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询采购方服务费余额
|
|
|
|
|
+ */
|
|
|
|
|
+ public BigDecimal queryPurchaserServiceFeeBalance(Long proEntId, Long supEntId) {
|
|
|
|
|
+ return queryServiceFeeBalance(proEntId, supEntId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void validateUnfreezeParam(ParkingWalletFeeFreezeParam param) {
|
|
|
|
|
+ if (param == null || param.getProEntId() == null) {
|
|
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "采购方企业id不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (param.getOrderNo() == null || param.getOrderNo().isBlank()) {
|
|
|
|
|
+ throw new BusinessPlatfromException(ErrorCodeEnum.PARAM_ERROR, "贸易订单号不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean existsUnfreezeRecord(String orderNo, Long proEntId, Long supEntId) {
|
|
|
|
|
+ return parkingWalletFeeBalanceRepository.count(
|
|
|
|
|
+ Wrappers.<KwtParkingWalletFeeBalance>lambdaQuery()
|
|
|
|
|
+ .eq(KwtParkingWalletFeeBalance::getOrderNo, orderNo)
|
|
|
|
|
+ .eq(KwtParkingWalletFeeBalance::getProEntId, proEntId)
|
|
|
|
|
+ .eq(supEntId != null, KwtParkingWalletFeeBalance::getSupEntId, supEntId)
|
|
|
|
|
+ .eq(KwtParkingWalletFeeBalance::getTradeType, TRADE_TYPE_UNFREEZE)
|
|
|
|
|
+ .eq(KwtParkingWalletFeeBalance::getDelFlag, Global.NO)
|
|
|
|
|
+ ) > 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private KwtParkingWalletFeeBalance queryFreezeBalanceRecord(ParkingWalletFeeFreezeParam param) {
|
|
|
|
|
+ return parkingWalletFeeBalanceRepository.getOne(
|
|
|
|
|
+ Wrappers.<KwtParkingWalletFeeBalance>lambdaQuery()
|
|
|
|
|
+ .eq(KwtParkingWalletFeeBalance::getOrderNo, param.getOrderNo())
|
|
|
|
|
+ .eq(KwtParkingWalletFeeBalance::getProEntId, param.getProEntId())
|
|
|
|
|
+ .eq(param.getSupEntId() != null, KwtParkingWalletFeeBalance::getSupEntId, param.getSupEntId())
|
|
|
|
|
+ .eq(KwtParkingWalletFeeBalance::getTradeType, TRADE_TYPE_FREEZE)
|
|
|
|
|
+ .eq(KwtParkingWalletFeeBalance::getDelFlag, Global.NO)
|
|
|
|
|
+ .orderByDesc(KwtParkingWalletFeeBalance::getId)
|
|
|
|
|
+ .last("limit 1"),
|
|
|
|
|
+ false
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void saveUnfreezeWalletBalanceLog(ParkingWalletFeeFreezeParam param,
|
|
|
|
|
+ KwtParkingWalletFee walletFee,
|
|
|
|
|
+ BigDecimal unfreezeAmount) {
|
|
|
|
|
+ Long operatorId = resolveOperatorId(param.getOperatorId());
|
|
|
|
|
+ Date now = new Date();
|
|
|
|
|
+ KwtParkingWalletFeeBalance balanceRecord = new KwtParkingWalletFeeBalance();
|
|
|
|
|
+ balanceRecord.setOrderNo(param.getOrderNo());
|
|
|
|
|
+ balanceRecord.setProEntId(param.getProEntId());
|
|
|
|
|
+ balanceRecord.setSupEntId(param.getSupEntId());
|
|
|
|
|
+ balanceRecord.setTradeType(TRADE_TYPE_UNFREEZE);
|
|
|
|
|
+ balanceRecord.setTradeAmount(unfreezeAmount);
|
|
|
|
|
+ balanceRecord.setServiceFeeBalance(walletFee.getServiceFeeBalance());
|
|
|
|
|
+ balanceRecord.setTradingAmount(walletFee.getTradingAmount());
|
|
|
|
|
+ balanceRecord.setRemark("贸易订单号:" + param.getOrderNo() + ",审核拒绝解冻服务费");
|
|
|
|
|
+ balanceRecord.setDelFlag(Global.NO);
|
|
|
|
|
+ balanceRecord.setCreateUser(operatorId);
|
|
|
|
|
+ balanceRecord.setUpdateUser(operatorId);
|
|
|
|
|
+ balanceRecord.setCreateTime(now);
|
|
|
|
|
+ balanceRecord.setUpdateTime(now);
|
|
|
|
|
+ parkingWalletFeeBalanceRepository.save(balanceRecord);
|
|
|
|
|
+ log.info("服务费解冻钱包日志已写入kwt_parking_wallet_fee_balance,orderNo:{}, proEntId:{}, supEntId:{}, tradeType:{}, tradeAmount:{}, balanceAfter:{}",
|
|
|
|
|
+ param.getOrderNo(), param.getProEntId(), param.getSupEntId(), TRADE_TYPE_UNFREEZE,
|
|
|
|
|
+ unfreezeAmount, walletFee.getServiceFeeBalance());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String buildStrategyMethodDesc(KwtParkingChargeStrategy strategy) {
|
|
|
|
|
+ if (strategy == null || strategy.getMethod() == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (Objects.equals(ParkingChangeStrategyEnum.BY_TON.getCode(), strategy.getType())) {
|
|
|
|
|
+ return strategy.getMethod().stripTrailingZeros().toPlainString() + "元/吨";
|
|
|
|
|
+ }
|
|
|
|
|
+ if (Objects.equals(ParkingChangeStrategyEnum.BY_TIME.getCode(), strategy.getType())) {
|
|
|
|
|
+ return strategy.getMethod().stripTrailingZeros().toPlainString() + "元/次";
|
|
|
|
|
+ }
|
|
|
|
|
+ return strategy.getMethod().stripTrailingZeros().toPlainString() + "元/月";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 写入服务费钱包日志(kwt_parking_wallet_fee_balance)
|
|
|
|
|
+ */
|
|
|
|
|
+ private void saveFreezeWalletBalanceLog(ParkingWalletFeeFreezeParam param,
|
|
|
|
|
+ KwtParkingWalletFee walletFee,
|
|
|
|
|
+ BigDecimal freezeAmount) {
|
|
|
|
|
+ Long operatorId = resolveOperatorId(param.getOperatorId());
|
|
|
|
|
+ Date now = new Date();
|
|
|
|
|
+ KwtParkingWalletFeeBalance balanceRecord = new KwtParkingWalletFeeBalance();
|
|
|
|
|
+ balanceRecord.setOrderNo(param.getOrderNo());
|
|
|
|
|
+ balanceRecord.setProEntId(param.getProEntId());
|
|
|
|
|
+ balanceRecord.setSupEntId(param.getSupEntId());
|
|
|
|
|
+ balanceRecord.setTradeType(TRADE_TYPE_FREEZE);
|
|
|
|
|
+ balanceRecord.setTradeAmount(freezeAmount);
|
|
|
|
|
+ balanceRecord.setServiceFeeBalance(walletFee.getServiceFeeBalance());
|
|
|
|
|
+ balanceRecord.setTradingAmount(walletFee.getTradingAmount());
|
|
|
|
|
+ balanceRecord.setRemark("贸易订单号:" + param.getOrderNo() + ",下单冻结服务费");
|
|
|
|
|
+ balanceRecord.setDelFlag(Global.NO);
|
|
|
|
|
+ balanceRecord.setCreateUser(operatorId);
|
|
|
|
|
+ balanceRecord.setUpdateUser(operatorId);
|
|
|
|
|
+ balanceRecord.setCreateTime(now);
|
|
|
|
|
+ balanceRecord.setUpdateTime(now);
|
|
|
|
|
+ parkingWalletFeeBalanceRepository.save(balanceRecord);
|
|
|
|
|
+ log.info("服务费钱包日志已写入kwt_parking_wallet_fee_balance,orderNo:{}, proEntId:{}, supEntId:{}, tradeType:{}, tradeAmount:{}, balanceAfter:{}",
|
|
|
|
|
+ param.getOrderNo(), param.getProEntId(), param.getSupEntId(), TRADE_TYPE_FREEZE,
|
|
|
|
|
+ freezeAmount, walletFee.getServiceFeeBalance());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private KwtParkingWalletFee queryWalletFee(Long proEntId, Long supEntId) {
|
|
|
|
|
+ return parkingWalletFeeRepository.getOne(
|
|
|
|
|
+ Wrappers.<KwtParkingWalletFee>lambdaQuery()
|
|
|
|
|
+ .eq(KwtParkingWalletFee::getProEntId, proEntId)
|
|
|
|
|
+ .eq(supEntId != null, KwtParkingWalletFee::getSupEntId, supEntId)
|
|
|
|
|
+ .eq(KwtParkingWalletFee::getDelFlag, Global.NO)
|
|
|
|
|
+ .orderByDesc(KwtParkingWalletFee::getId)
|
|
|
|
|
+ .last("limit 1"),
|
|
|
|
|
+ false
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Long resolveOperatorId(Long operatorId) {
|
|
|
|
|
+ Long loginUserId = LoginUserHolder.getUserId();
|
|
|
|
|
+ if (loginUserId != null) {
|
|
|
|
|
+ return loginUserId;
|
|
|
|
|
+ }
|
|
|
|
|
+ return operatorId == null ? -1L : operatorId;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 计算服务费余额支持的最大可购买数量
|
|
* 计算服务费余额支持的最大可购买数量
|
|
|
* 仅在收费策略开关开启且单价大于0时计算:服务费余额 / 策略单价(向下取整,保留4位小数)
|
|
* 仅在收费策略开关开启且单价大于0时计算:服务费余额 / 策略单价(向下取整,保留4位小数)
|
|
@@ -119,7 +382,8 @@ public class ParkingWalletFeeService {
|
|
|
currentStrategy == null ? "未匹配到收费策略" : "收费策略未开启或单价<=0");
|
|
currentStrategy == null ? "未匹配到收费策略" : "收费策略未开启或单价<=0");
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
- BigDecimal maxPurchaseQuantity = serviceFeeBalance.divide(currentStrategyUnitFee, 4, RoundingMode.DOWN);
|
|
|
|
|
|
|
+ //向下取整
|
|
|
|
|
+ BigDecimal maxPurchaseQuantity = serviceFeeBalance.divide(currentStrategyUnitFee, 0, RoundingMode.DOWN);
|
|
|
log.info("最大可购买数量计算完成,serviceFeeBalance:{}, unitFee:{}, maxPurchaseQuantity:{}",
|
|
log.info("最大可购买数量计算完成,serviceFeeBalance:{}, unitFee:{}, maxPurchaseQuantity:{}",
|
|
|
serviceFeeBalance, currentStrategyUnitFee, maxPurchaseQuantity);
|
|
serviceFeeBalance, currentStrategyUnitFee, maxPurchaseQuantity);
|
|
|
return maxPurchaseQuantity.max(ZERO_AMOUNT);
|
|
return maxPurchaseQuantity.max(ZERO_AMOUNT);
|
|
@@ -178,23 +442,17 @@ public class ParkingWalletFeeService {
|
|
|
* 查询企业当前可用服务费余额
|
|
* 查询企业当前可用服务费余额
|
|
|
*
|
|
*
|
|
|
* @param proEntId 采购企业id
|
|
* @param proEntId 采购企业id
|
|
|
|
|
+ * @param supEntId 供应商企业id,可为空
|
|
|
* @return 服务费余额,无记录时返回0
|
|
* @return 服务费余额,无记录时返回0
|
|
|
*/
|
|
*/
|
|
|
- private BigDecimal queryServiceFeeBalance(Long proEntId) {
|
|
|
|
|
- KwtParkingWalletFee walletFee = parkingWalletFeeRepository.getOne(
|
|
|
|
|
- Wrappers.<KwtParkingWalletFee>lambdaQuery()
|
|
|
|
|
- .eq(KwtParkingWalletFee::getProEntId, proEntId)
|
|
|
|
|
- .eq(KwtParkingWalletFee::getDelFlag, Global.NO)
|
|
|
|
|
- .orderByDesc(KwtParkingWalletFee::getId)
|
|
|
|
|
- .last("limit 1"),
|
|
|
|
|
- false
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ private BigDecimal queryServiceFeeBalance(Long proEntId, Long supEntId) {
|
|
|
|
|
+ KwtParkingWalletFee walletFee = queryWalletFee(proEntId, supEntId);
|
|
|
if (walletFee == null || walletFee.getServiceFeeBalance() == null) {
|
|
if (walletFee == null || walletFee.getServiceFeeBalance() == null) {
|
|
|
- log.info("查询服务费余额为空,按0处理,proEntId:{}", proEntId);
|
|
|
|
|
|
|
+ log.info("查询服务费余额为空,按0处理,proEntId:{}, supEntId:{}", proEntId, supEntId);
|
|
|
return ZERO_AMOUNT;
|
|
return ZERO_AMOUNT;
|
|
|
}
|
|
}
|
|
|
- log.info("查询服务费余额成功,proEntId:{}, serviceFeeBalance:{}",
|
|
|
|
|
- proEntId, walletFee.getServiceFeeBalance());
|
|
|
|
|
|
|
+ log.info("查询服务费余额成功,proEntId:{}, supEntId:{}, serviceFeeBalance:{}",
|
|
|
|
|
+ proEntId, supEntId, walletFee.getServiceFeeBalance());
|
|
|
return walletFee.getServiceFeeBalance();
|
|
return walletFee.getServiceFeeBalance();
|
|
|
}
|
|
}
|
|
|
|
|
|