提交 cad22df2 authored 作者: huyufan's avatar huyufan

借款相关接单拦截判断

上级 5ef33676
package com.clx.performance.component;
import com.clx.order.feign.OrderFeign;
import com.clx.order.vo.feign.FeignOrderInfoVO;
import com.clx.order.vo.pc.owner.OwnerQuotationDetailVO;
import com.clx.performance.dao.OrderChildDao;
import com.clx.performance.dao.OwnerRunningWaterRecordDao;
import com.clx.performance.dao.loan.OwnerLoanAccountDao;
import com.clx.performance.dao.loan.OwnerRepaymentDao;
import com.clx.performance.enums.OrderGoodsOverWeightEnum;
import com.clx.performance.enums.OwnerAccountEnum;
import com.clx.performance.enums.PerformanceResultEnum;
import com.clx.performance.enums.loan.OwnerRePaymentEnum;
import com.clx.performance.model.OrderChild;
import com.clx.performance.model.OrderGoods;
import com.clx.performance.model.OwnerRunningWaterRecord;
import com.clx.performance.model.loan.OwnerLoanAccount;
import com.clx.performance.model.loan.OwnerRepayment;
import com.clx.user.vo.feign.OwnerInfoFeignVO;
import com.msl.common.base.Optional;
import com.msl.common.exception.ServiceSystemException;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.List;
@Component
@AllArgsConstructor
public class OrderChildLoanComponent {
private final OrderFeign orderFeign;
private final OwnerRunningWaterRecordDao ownerRunningWaterRecordDao;
private final OrderChildDao orderChildDao;
private final OwnerLoanAccountDao ownerLoanAccountDao;
private final OwnerRepaymentDao ownerRepaymentDao;
public void getChildDetermine(FeignOrderInfoVO orderInfoVO, OwnerInfoFeignVO ownerInfoFeignVO, OrderGoods orderGoods) {
OwnerQuotationDetailVO quotationDetailVO = orderFeign.getQuotationByOrderNo(orderInfoVO.getOrderNo()).getData();
BigDecimal freightFreezeRate = quotationDetailVO.getFreightFreezeRate();
if (freightFreezeRate.compareTo(BigDecimal.ONE) == 0) {
//百分百预付不需要考虑借款账户
return;
}
//发货-是否可超标准 0 否 1 是
Integer overWeight = orderInfoVO.getOverWeight();
if (OrderGoodsOverWeightEnum.NO.getCode().equals(overWeight)) {
determine(orderGoods.getPendingOrderFreight().multiply(new BigDecimal(35)));
} else {
determine(orderGoods.getPendingOrderFreight().multiply(new BigDecimal(50)));
}
}
public void determine(BigDecimal orderChildPrice) {
List<OwnerRunningWaterRecord> runningWaterRecordList = ownerRunningWaterRecordDao.getOwnerRunningWaterRecord("");
BigDecimal frozen = runningWaterRecordList.stream().filter(item -> {
return item.getRunningWaterType().equals(OwnerAccountEnum.RunningWaterStatus.FROZEN.getCode())
&& item.getAccountType().equals(OwnerAccountEnum.AccountTypeStatus.PREPAID_FREIGHT_ACCOUNT.getCode())
;
}).map(OwnerRunningWaterRecord::getAlterationBalance).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal takeOut = runningWaterRecordList.stream().filter(item -> {
return item.getRunningWaterType().equals(OwnerAccountEnum.RunningWaterStatus.TAKE_OUT.getCode())
&& item.getAccountType().equals(OwnerAccountEnum.AccountTypeStatus.PREPAID_FREIGHT_ACCOUNT.getCode())
;
}).map(OwnerRunningWaterRecord::getAlterationBalance).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal subtract = frozen.subtract(takeOut);
if (subtract.compareTo(BigDecimal.ZERO) > 0) {
//查询未结算的运单(没有产生扣除流水的运单)
List<OrderChild> orderChildList = orderChildDao.selectInTransitOrderChildLtUnsettle("");
BigDecimal orderChildSum = orderChildList.stream().map(OrderChild::getWeight).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal ans = subtract.subtract(orderChildSum);
if (ans.compareTo(BigDecimal.ZERO) >= 0 && ans.compareTo(orderChildPrice) >= 0) {
//预付运费够
return;
}
}
// 进行借款判断
OwnerLoanAccount ownerLoanAccount = ownerLoanAccountDao.getOneByField(OwnerLoanAccount::getOwnerUserNo, null).get();
BigDecimal ownerLoanAccountSum = ownerLoanAccount.getVirtuallyUsableBalance().add(ownerLoanAccount.getFundingUsableBalance());
if (ownerLoanAccountSum.compareTo(orderChildPrice) < 0) {
throw new ServiceSystemException(PerformanceResultEnum.ORDER_CHILD_SAVE_FAIL, "货主已欠款");
}
//借款账户钱够,判断是否逾期
Optional<OwnerRepayment> optional = ownerRepaymentDao.getLimitOneByField(OwnerRepayment::getBeOverdue, OwnerRePaymentEnum.BeOverdue.YES.getCode());
if (optional.isPresent()) {
//逾期:不允许
throw new ServiceSystemException(PerformanceResultEnum.ORDER_CHILD_SAVE_FAIL, "货主已欠款");
}
}
}
...@@ -7,6 +7,7 @@ import com.msl.common.exception.ServiceSystemException; ...@@ -7,6 +7,7 @@ import com.msl.common.exception.ServiceSystemException;
import com.msl.common.utils.DateUtils; import com.msl.common.utils.DateUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.redisson.api.RLock; import org.redisson.api.RLock;
import org.redisson.api.RedissonClient; import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
......
package com.clx.performance.model.loan; package com.clx.performance.model.loan;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.msl.common.config.KeyColumn; import com.msl.common.config.KeyColumn;
import com.msl.common.model.HasKey; import com.msl.common.model.HasKey;
...@@ -8,11 +10,9 @@ import io.swagger.annotations.ApiModelProperty; ...@@ -8,11 +10,9 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import java.math.BigDecimal; import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.io.Serializable;
/** /**
* @author kavin * @author kavin
...@@ -44,13 +44,29 @@ public class OwnerLoanAccount implements HasKey<Integer> { ...@@ -44,13 +44,29 @@ public class OwnerLoanAccount implements HasKey<Integer> {
@ApiModelProperty("账户类型: 默认3 借款账户") @ApiModelProperty("账户类型: 默认3 借款账户")
private Integer accountType; private Integer accountType;
@TableField("funding_amount") @TableField("funding_account_balance")
@ApiModelProperty("资金金额") @ApiModelProperty("资金账户金额")
private BigDecimal fundingAmount; private BigDecimal fundingAccountBalance;
@TableField("funding_usable_balance")
@ApiModelProperty("资金可用金额")
private BigDecimal fundingUsableBalance;
@TableField("funding_frozen_balance")
@ApiModelProperty("资金冻结金额")
private BigDecimal fundingFrozenBalance;
@TableField("virtually_account_balance")
@ApiModelProperty("虚拟币账户金额")
private BigDecimal virtuallyAccountBalance;
@TableField("virtually_usable_balance")
@ApiModelProperty("虚拟币可用余额")
private BigDecimal virtuallyUsableBalance;
@TableField("virtually_amount") @TableField("virtually_frozen_balance")
@ApiModelProperty("虚拟币额") @ApiModelProperty("虚拟币冻结余额")
private BigDecimal virtuallyAmount; private BigDecimal virtuallyFrozenBalance;
@TableField("funding_arrears") @TableField("funding_arrears")
@ApiModelProperty("资金欠款") @ApiModelProperty("资金欠款")
......
...@@ -312,6 +312,9 @@ public class OrderChildServiceImpl implements OrderChildService { ...@@ -312,6 +312,9 @@ public class OrderChildServiceImpl implements OrderChildService {
throw new ServiceSystemException(PerformanceResultEnum.ORDER_WEIGHT_LACK); throw new ServiceSystemException(PerformanceResultEnum.ORDER_WEIGHT_LACK);
} }
//TODO 借款账户相关限制
OrderChild orderChild = new OrderChild(); OrderChild orderChild = new OrderChild();
orderChild.setChildNo(childNo); orderChild.setChildNo(childNo);
orderChild.setUserNo(userNo); orderChild.setUserNo(userNo);
......
...@@ -38,10 +38,15 @@ public class OwnerLoanAccountServiceImpl implements OwnerLoanAccountService { ...@@ -38,10 +38,15 @@ public class OwnerLoanAccountServiceImpl implements OwnerLoanAccountService {
entity.setOwnerUserNo(ownerUserNo); entity.setOwnerUserNo(ownerUserNo);
entity.setMobile(mobile); entity.setMobile(mobile);
entity.setOwnerUserName(ownerUserName); entity.setOwnerUserName(ownerUserName);
entity.setFundingAmount(BigDecimal.ZERO); entity.setFundingAccountBalance(BigDecimal.ZERO);
entity.setFundingAmount(BigDecimal.ZERO); entity.setFundingFrozenBalance(BigDecimal.ZERO);
entity.setVirtuallyAmount(BigDecimal.ZERO); entity.setFundingUsableBalance(BigDecimal.ZERO);
entity.setFundingArrears(BigDecimal.ZERO);
entity.setVirtuallyArrears(BigDecimal.ZERO); entity.setVirtuallyArrears(BigDecimal.ZERO);
entity.setVirtuallyAccountBalance(BigDecimal.ZERO);
entity.setVirtuallyUsableBalance(BigDecimal.ZERO);
entity.setVirtuallyFrozenBalance(BigDecimal.ZERO);
ownerLoanAccountDao.saveEntity(entity); ownerLoanAccountDao.saveEntity(entity);
} }
......
...@@ -142,8 +142,8 @@ public class OwnerLoanRecordServiceImpl implements OwnerLoanRecordService { ...@@ -142,8 +142,8 @@ public class OwnerLoanRecordServiceImpl implements OwnerLoanRecordService {
ownerLoanRecord.getOwnerUserNo()).get(); ownerLoanRecord.getOwnerUserNo()).get();
OwnerLoanAccount entity = new OwnerLoanAccount(); OwnerLoanAccount entity = new OwnerLoanAccount();
entity.setId(ownerLoanAccount.getId()); entity.setId(ownerLoanAccount.getId());
entity.setVirtuallyAmount(ownerLoanRecord.getLoanBalance()); /* entity.setVirtuallyAmount(ownerLoanRecord.getLoanBalance());
entity.setFundingAmount(BigDecimal.ZERO); entity.setFundingAmount(BigDecimal.ZERO);*/
entity.setModifiedTime(ownerLoanAccount.getModifiedTime()); entity.setModifiedTime(ownerLoanAccount.getModifiedTime());
Integer flag = ownerLoanAccountDao.updateAccountCAS(entity, LocalDateTime.now(), true); Integer flag = ownerLoanAccountDao.updateAccountCAS(entity, LocalDateTime.now(), true);
if (flag == 1) { if (flag == 1) {
...@@ -187,7 +187,7 @@ public class OwnerLoanRecordServiceImpl implements OwnerLoanRecordService { ...@@ -187,7 +187,7 @@ public class OwnerLoanRecordServiceImpl implements OwnerLoanRecordService {
.setLoanNo(ownerLoanRecord.getLoanNo()) .setLoanNo(ownerLoanRecord.getLoanNo())
.setRunningWaterType(RunningWaterTypeEnum.Status.LOAN.getCode()) .setRunningWaterType(RunningWaterTypeEnum.Status.LOAN.getCode())
.setAlterationBalance(ownerLoanRecord.getLoanBalance()) .setAlterationBalance(ownerLoanRecord.getLoanBalance())
.setAccountBalance(ownerLoanAccount.getFundingAmount().add(ownerLoanAccount.getVirtuallyAmount())) .setAccountBalance(ownerLoanAccount.getFundingAccountBalance().add(ownerLoanAccount.getVirtuallyAccountBalance()))
.setCreateBy("系统"); .setCreateBy("系统");
ownerLoanAccountRunningWaterRecordDao.saveEntity(record); ownerLoanAccountRunningWaterRecordDao.saveEntity(record);
} }
......
...@@ -62,13 +62,9 @@ public class SettlementServiceImpl implements SettlementService { ...@@ -62,13 +62,9 @@ public class SettlementServiceImpl implements SettlementService {
SettlementOwnerDetail settlementOwnerDetail = settlementOwnerDetailDao.getByChildNo(childNo).orElseThrow(PerformanceResultEnum.DATA_NOT_FIND); SettlementOwnerDetail settlementOwnerDetail = settlementOwnerDetailDao.getByChildNo(childNo).orElseThrow(PerformanceResultEnum.DATA_NOT_FIND);
SettlementDriverDetail settlementDriverDetail = settlementDriverDetailDao.getByChildNo(childNo).orElseThrow(PerformanceResultEnum.DATA_NOT_FIND); SettlementDriverDetail settlementDriverDetail = settlementDriverDetailDao.getByChildNo(childNo).orElseThrow(PerformanceResultEnum.DATA_NOT_FIND);
if (settlementOwnerDetail.getInvoiceType() != null) {
return;
}
// 开票金额 // 开票金额
settlementOwnerDetail.setInvoiceFreight(invoiceFreightCalc(orderChild.getSettlementWay(), settlementOwnerDetail)); settlementOwnerDetail.setInvoiceFreight(invoiceFreightCalc(orderChild.getSettlementWay(), settlementOwnerDetail));
if (settlementDriverDetail.getSettlementFreight().compareTo(BigDecimal.ZERO) <= 0) { if (settlementDriverDetail.getSettlementFreight().compareTo(BigDecimal.ZERO) <= 0) {
invoiceType = SettlementOwnerEnum.InvoiceType.ORDINARY.getCode();
settlementDriverDetail.setPrepayFreightFlag(SettlementDriverEnum.PrepayFreightFlag.NO_PAY.getCode()); settlementDriverDetail.setPrepayFreightFlag(SettlementDriverEnum.PrepayFreightFlag.NO_PAY.getCode());
settlementOwnerDetail.setPrepayFreight(BigDecimal.ZERO); settlementOwnerDetail.setPrepayFreight(BigDecimal.ZERO);
} else { } else {
...@@ -77,71 +73,6 @@ public class SettlementServiceImpl implements SettlementService { ...@@ -77,71 +73,6 @@ public class SettlementServiceImpl implements SettlementService {
RabbitKeyConstants.ORDER_CHILD_SYNC_TRANSPORT_EXCHANGE, RabbitKeyConstants.ORDER_CHILD_SYNC_TRANSPORT_ROUTE_KEY, message RabbitKeyConstants.ORDER_CHILD_SYNC_TRANSPORT_EXCHANGE, RabbitKeyConstants.ORDER_CHILD_SYNC_TRANSPORT_ROUTE_KEY, message
); );
return; return;
// OrderGoods orderGoods = orderGoodsDao.getByOrderGoodsNo(orderChild.getOrderGoodsNo()).get();
// //是否通过风控,调用网络货运
// ThirdOrderChildBrokerParam param = transportSyncService.generateOrderChildSync(orderChild, orderGoods, settlementOwnerDetail, settlementDriverDetail);
// HttpDTO httpDTOResult = transportFeignService.orderChildSync(param);
// String decrypt = ThirdComponent.decrypt(httpDTOResult.getData());
// OrderChildSyncDTO bean = JSONUtil.toBean(decrypt, OrderChildSyncDTO.class);
// log.info("OrderChildSyncDTO信息为:{}", JSONUtil.parse(bean));
// if (bean.getCode() == 0) {
// Integer status = bean.getData().getStatus();
// if (status == 1) {
// //通过风控
// List<OwnerRunningWaterRecord> runningWaterRecordList = ownerRunningWaterRecordDao.getOwnerRunningWaterRecord(orderChild.getOrderNo());
// BigDecimal frozen = runningWaterRecordList.stream().filter(item -> {
// return item.getRunningWaterType().equals(OwnerAccountEnum.RunningWaterStatus.FROZEN.getCode())
// && item.getAccountType().equals(OwnerAccountEnum.AccountTypeStatus.PREPAID_FREIGHT_ACCOUNT.getCode())
// ;
// }).map(OwnerRunningWaterRecord::getAlterationBalance).reduce(BigDecimal.ZERO, BigDecimal::add);
//
// BigDecimal takeOut = runningWaterRecordList.stream().filter(item -> {
// return item.getRunningWaterType().equals(OwnerAccountEnum.RunningWaterStatus.TAKE_OUT.getCode())
// && item.getAccountType().equals(OwnerAccountEnum.AccountTypeStatus.PREPAID_FREIGHT_ACCOUNT.getCode())
// ;
// }).map(OwnerRunningWaterRecord::getAlterationBalance).reduce(BigDecimal.ZERO, BigDecimal::add);
// //设置预付运费金额
// BigDecimal ans = getPrepayFreightPay(orderChild.getSettlementWay(), settlementOwnerDetail, frozen);
// BigDecimal subtract = frozen.subtract(takeOut);
// log.info("冻结预付运费:{}, 扣除的流水总和:{}", frozen, takeOut);
// invoiceType = SettlementOwnerEnum.InvoiceType.ONLINE.getCode();
// settlementDriverDetail.setPrepayFreight(ans);
// //冻结的预付运费为0 或者 此刻预付运费也可能为0,那么就不用生成扣除相关流水逻辑
// if (subtract.compareTo(BigDecimal.ZERO) <= 0 || ans.compareTo(BigDecimal.ZERO) == 0) {
// settlementOwnerDetail.setPrepayFreight(BigDecimal.ZERO);
// settlementDriverDetail.setPrepayFreightFlag(SettlementDriverEnum.PrepayFreightFlag.NO_PAY.getCode());
// } else {
// if (subtract.subtract(ans).compareTo(BigDecimal.ZERO) >= 0) {
// //账户扣钱并生成扣除流水
// generateTakeOutRunningWatter(orderChild, ans, settlementOwnerDetail, settlementDriverDetail);
// try {
// //网络货运钱包账户
// networkDriverRunningWaterRecordService.generateNetworkDriverRunningWaterRecord(
// settlementDriverDetail,
// NetworkDriverAccountEnum.RunningWaterStatus.SETTLEMENT.getCode()
// );
// //生成提现记录
// networkDriverRunningWaterRecordService.generateNetworkCaseOutRecord(settlementDriverDetail);
// }catch (Exception e) {
// log.info("运单同步网络货运生成司机运单结算流水失败:{}", e.getMessage());
// }
//
// } else {
// settlementOwnerDetail.setPrepayFreight(BigDecimal.ZERO);
// settlementDriverDetail.setPrepayFreightFlag(SettlementDriverEnum.PrepayFreightFlag.NO_PAY.getCode());
//
// }
// }
//
// } else {
// settlementDriverDetail.setPrepayFreightFlag(SettlementDriverEnum.PrepayFreightFlag.NO_PAY.getCode());
// settlementOwnerDetail.setPrepayFreight(BigDecimal.ZERO);
// settlementOwnerDetail.setFinalPaymentStatus(SettlementOwnerDetailEnum.FinalPaymentStatus.NO.getCode());
// }
// } else {
// throw new ServiceSystemException(PerformanceResultEnum.ORDER_CHILD_SYNC_ERROR);
//
// }
} }
// 结算金额 // 结算金额
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论