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

确认收货处理相关借款逻辑

上级 a5ffa0f6
...@@ -52,7 +52,7 @@ public class OwnerLoanAccountRunningWaterRecordVO { ...@@ -52,7 +52,7 @@ public class OwnerLoanAccountRunningWaterRecordVO {
private BigDecimal alterationBalance; private BigDecimal alterationBalance;
@MoneyOutConvert @MoneyOutConvert
@ApiModelProperty(value = "可用余额", example = "1.23") @ApiModelProperty(value = "可用余额", example = "1.23")
private BigDecimal useableBalance; private BigDecimal useAbleBalance;
@MoneyOutConvert @MoneyOutConvert
@ApiModelProperty(value = "冻结余额", example = "1.23") @ApiModelProperty(value = "冻结余额", example = "1.23")
private BigDecimal frozenBalance; private BigDecimal frozenBalance;
......
...@@ -34,6 +34,4 @@ public interface OwnerRunningWaterRecordDao extends BaseDao<OwnerRunningWaterRec ...@@ -34,6 +34,4 @@ public interface OwnerRunningWaterRecordDao extends BaseDao<OwnerRunningWaterRec
List<OwnerAccountRunningWaterRecordVO> marginAccountList(PagePlatformMarginAccountParam param); List<OwnerAccountRunningWaterRecordVO> marginAccountList(PagePlatformMarginAccountParam param);
OwnerRunningWaterRecord getOneByOrderNoAndRunningWaterTypeAndAccountType(String orderNo, Integer runningWaterType, Integer accountType);
} }
...@@ -66,11 +66,4 @@ public class OwnerRunningWaterRecordDaoImpl extends BaseDaoImpl<OwnerRunningWate ...@@ -66,11 +66,4 @@ public class OwnerRunningWaterRecordDaoImpl extends BaseDaoImpl<OwnerRunningWate
return baseMapper.marginAccountList(param); return baseMapper.marginAccountList(param);
} }
@Override
public OwnerRunningWaterRecord getOneByOrderNoAndRunningWaterTypeAndAccountType(String orderNo, Integer runningWaterType, Integer accountType) {
return baseMapper.selectOne(lQrWrapper().eq(OwnerRunningWaterRecord::getOrderNo, orderNo)
.eq(OwnerRunningWaterRecord::getRunningWaterType, runningWaterType)
.eq(OwnerRunningWaterRecord::getAccountType, accountType)
);
}
} }
...@@ -31,10 +31,22 @@ public class OwnerLoanAccountDaoImpl extends BaseDaoImpl<OwnerLoanAccountMapper, ...@@ -31,10 +31,22 @@ public class OwnerLoanAccountDaoImpl extends BaseDaoImpl<OwnerLoanAccountMapper,
} }
} }
@Override
public Integer childWriteOffOwnerLoanAccountCAS(OwnerLoanAccount account, LocalDateTime now) {
String nowStr = DateUtils.formatDateTime(now).get();
return baseMapper.childWriteOffOwnerLoanAccountCAS(account, nowStr);
}
@Override @Override
public IPage<CarrierOwnerLoanAccountVO> pageByParam(PageOwnerLoanAccountParam param) { public IPage<CarrierOwnerLoanAccountVO> pageByParam(PageOwnerLoanAccountParam param) {
Page<CarrierOwnerLoanAccountVO> page = Page.of(param.getPage(), param.getPageSize()); Page<CarrierOwnerLoanAccountVO> page = Page.of(param.getPage(), param.getPageSize());
return baseMapper.pageByParam(page,param); return baseMapper.pageByParam(page,param);
} }
@Override
public Integer thawOwnerLoanAccountCAS(OwnerLoanAccount account, LocalDateTime now) {
String nowStr = DateUtils.formatDateTime(now).get();
return baseMapper.thawOwnerLoanAccountCAS(account, nowStr);
}
} }
...@@ -77,4 +77,19 @@ public class OwnerLoanAccountRunningWaterRecordDaoImpl extends BaseDaoImpl<Owner ...@@ -77,4 +77,19 @@ public class OwnerLoanAccountRunningWaterRecordDaoImpl extends BaseDaoImpl<Owner
query.orderByDesc(OwnerLoanAccountRunningWaterRecord :: getModifiedTime); query.orderByDesc(OwnerLoanAccountRunningWaterRecord :: getModifiedTime);
return baseMapper.selectList(query); return baseMapper.selectList(query);
} }
@Override
public OwnerLoanAccountRunningWaterRecord getOneByChildNoAndStatus(String childNo, Integer type) {
return baseMapper.selectOne(lQrWrapper().eq(OwnerLoanAccountRunningWaterRecord::getChildNo, childNo)
.eq(OwnerLoanAccountRunningWaterRecord::getRunningWaterType, type)
);
}
@Override
public List<OwnerLoanAccountRunningWaterRecord> getListByOrderNoAndRunningWaterType(String childNo, Integer runningWaterType) {
return baseMapper.selectList(lQrWrapper().eq(OwnerLoanAccountRunningWaterRecord::getChildNo, childNo)
.eq(OwnerLoanAccountRunningWaterRecord::getRunningWaterType, runningWaterType)
.orderByAsc(OwnerLoanAccountRunningWaterRecord::getId)
);
}
} }
...@@ -70,4 +70,5 @@ public class OwnerLoanRecordDaoImpl extends BaseDaoImpl<OwnerLoanRecordMapper, O ...@@ -70,4 +70,5 @@ public class OwnerLoanRecordDaoImpl extends BaseDaoImpl<OwnerLoanRecordMapper, O
); );
} }
} }
...@@ -18,6 +18,22 @@ public interface OwnerLoanAccountDao extends BaseDao<OwnerLoanAccountMapper, Own ...@@ -18,6 +18,22 @@ public interface OwnerLoanAccountDao extends BaseDao<OwnerLoanAccountMapper, Own
Integer updateAccountCAS(OwnerLoanAccount account, LocalDateTime now, boolean flag); Integer updateAccountCAS(OwnerLoanAccount account, LocalDateTime now, boolean flag);
/**
* 核心抵扣
* @param account
* @param now
* @return
*/
Integer childWriteOffOwnerLoanAccountCAS(OwnerLoanAccount account, LocalDateTime now);
IPage<CarrierOwnerLoanAccountVO> pageByParam(PageOwnerLoanAccountParam param); IPage<CarrierOwnerLoanAccountVO> pageByParam(PageOwnerLoanAccountParam param);
/**
* 解冻账户金额
* @param account
* @param now
* @return
*/
Integer thawOwnerLoanAccountCAS(OwnerLoanAccount account, LocalDateTime now);
} }
...@@ -22,4 +22,8 @@ public interface OwnerLoanAccountRunningWaterRecordDao extends BaseDao<OwnerLoan ...@@ -22,4 +22,8 @@ public interface OwnerLoanAccountRunningWaterRecordDao extends BaseDao<OwnerLoan
IPage<OwnerLoanAccountRunningWaterRecord> pageOwnerLoanRunWaterRecord(Long userNo, PageOwnerLoanRunWaterRecordParam param); IPage<OwnerLoanAccountRunningWaterRecord> pageOwnerLoanRunWaterRecord(Long userNo, PageOwnerLoanRunWaterRecordParam param);
List<OwnerLoanAccountRunningWaterRecord> listOwnerLoanRunWaterRecord(Long userNo, PageOwnerLoanRunWaterRecordParam param); List<OwnerLoanAccountRunningWaterRecord> listOwnerLoanRunWaterRecord(Long userNo, PageOwnerLoanRunWaterRecordParam param);
OwnerLoanAccountRunningWaterRecord getOneByChildNoAndStatus(String childNo, Integer type);
List<OwnerLoanAccountRunningWaterRecord> getListByOrderNoAndRunningWaterType(String childNo, Integer runningWaterType);
} }
...@@ -22,4 +22,6 @@ public interface OwnerLoanRecordDao extends BaseDao<OwnerLoanRecordMapper, Owner ...@@ -22,4 +22,6 @@ public interface OwnerLoanRecordDao extends BaseDao<OwnerLoanRecordMapper, Owner
IPage<OwnerLoanRecordVO> pageByParam(PageOwnerLoanRecordOfOwner param); IPage<OwnerLoanRecordVO> pageByParam(PageOwnerLoanRecordOfOwner param);
List<OwnerLoanRecord> selectLoanBalance(Long userNo); List<OwnerLoanRecord> selectLoanBalance(Long userNo);
} }
...@@ -2,6 +2,7 @@ package com.clx.performance.listener; ...@@ -2,6 +2,7 @@ package com.clx.performance.listener;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.clx.performance.component.IdGenerateSnowFlake; import com.clx.performance.component.IdGenerateSnowFlake;
import com.clx.performance.component.OrderChildLoanComponent;
import com.clx.performance.component.ThirdComponent; import com.clx.performance.component.ThirdComponent;
import com.clx.performance.constant.RabbitKeyConstants; import com.clx.performance.constant.RabbitKeyConstants;
import com.clx.performance.dao.OrderChildSyncTransportInvoiceRecordDao; import com.clx.performance.dao.OrderChildSyncTransportInvoiceRecordDao;
...@@ -65,6 +66,8 @@ public class OrderChildSyncTransportListener { ...@@ -65,6 +66,8 @@ public class OrderChildSyncTransportListener {
private final SettlementMqService settlementMqService; private final SettlementMqService settlementMqService;
private final OrderChildLoanComponent orderChildLoanComponent;
@RabbitListener(queues = RabbitKeyConstants.ORDER_CHILD_SYNC_TRANSPORT_QUEUE) @RabbitListener(queues = RabbitKeyConstants.ORDER_CHILD_SYNC_TRANSPORT_QUEUE)
public void onMessage(String message) { public void onMessage(String message) {
OrderChild orderChild = JSONUtil.toBean(message, OrderChild.class); OrderChild orderChild = JSONUtil.toBean(message, OrderChild.class);
...@@ -101,6 +104,9 @@ public class OrderChildSyncTransportListener { ...@@ -101,6 +104,9 @@ public class OrderChildSyncTransportListener {
public void extracted(OrderChild orderChild, OrderChildSyncDTO bean, String remark, public void extracted(OrderChild orderChild, OrderChildSyncDTO bean, String remark,
SettlementOwnerDetail settlementOwnerDetail, SettlementOwnerDetail settlementOwnerDetail,
Integer invoiceType, SettlementDriverDetail settlementDriverDetail) { Integer invoiceType, SettlementDriverDetail settlementDriverDetail) {
// 结算金额
settlementOwnerDetail.setSettlementFreight(settlementFreightCalc(orderChild.getSettlementWay(), settlementOwnerDetail));
if (null != bean && bean.getCode() == 0) { if (null != bean && bean.getCode() == 0) {
log.info("当前OrderChildSyncTransportListener监听同步网络货运成功,运单号为{}", orderChild.getChildNo()); log.info("当前OrderChildSyncTransportListener监听同步网络货运成功,运单号为{}", orderChild.getChildNo());
if (null != bean.getData() && bean.getData().getStatus() == 1) { if (null != bean.getData() && bean.getData().getStatus() == 1) {
...@@ -127,8 +133,6 @@ public class OrderChildSyncTransportListener { ...@@ -127,8 +133,6 @@ public class OrderChildSyncTransportListener {
if (subtract.compareTo(BigDecimal.ZERO) <= 0 || ans.compareTo(BigDecimal.ZERO) == 0) { if (subtract.compareTo(BigDecimal.ZERO) <= 0 || ans.compareTo(BigDecimal.ZERO) == 0) {
settlementOwnerDetail.setPrepayFreight(BigDecimal.ZERO); settlementOwnerDetail.setPrepayFreight(BigDecimal.ZERO);
settlementDriverDetail.setPrepayFreightFlag(SettlementDriverEnum.PrepayFreightFlag.NO_PAY.getCode()); settlementDriverDetail.setPrepayFreightFlag(SettlementDriverEnum.PrepayFreightFlag.NO_PAY.getCode());
BigDecimal settlementFreight = settlementOwnerDetail.getSettlementFreight();
//生成借款标识
} else { } else {
if (subtract.subtract(ans).compareTo(BigDecimal.ZERO) >= 0) { if (subtract.subtract(ans).compareTo(BigDecimal.ZERO) >= 0) {
...@@ -149,11 +153,8 @@ public class OrderChildSyncTransportListener { ...@@ -149,11 +153,8 @@ public class OrderChildSyncTransportListener {
} else { } else {
settlementOwnerDetail.setPrepayFreight(BigDecimal.ZERO); settlementOwnerDetail.setPrepayFreight(BigDecimal.ZERO);
settlementDriverDetail.setPrepayFreightFlag(SettlementDriverEnum.PrepayFreightFlag.NO_PAY.getCode()); settlementDriverDetail.setPrepayFreightFlag(SettlementDriverEnum.PrepayFreightFlag.NO_PAY.getCode());
} }
} }
} else { } else {
settlementDriverDetail.setPrepayFreightFlag(SettlementDriverEnum.PrepayFreightFlag.NO_PAY.getCode()); settlementDriverDetail.setPrepayFreightFlag(SettlementDriverEnum.PrepayFreightFlag.NO_PAY.getCode());
settlementOwnerDetail.setPrepayFreight(BigDecimal.ZERO); settlementOwnerDetail.setPrepayFreight(BigDecimal.ZERO);
...@@ -166,8 +167,6 @@ public class OrderChildSyncTransportListener { ...@@ -166,8 +167,6 @@ public class OrderChildSyncTransportListener {
settlementOwnerDetail.setFinalPaymentStatus(SettlementOwnerDetailEnum.FinalPaymentStatus.NO.getCode()); settlementOwnerDetail.setFinalPaymentStatus(SettlementOwnerDetailEnum.FinalPaymentStatus.NO.getCode());
} }
// 结算金额
settlementOwnerDetail.setSettlementFreight(settlementFreightCalc(orderChild.getSettlementWay(), settlementOwnerDetail));
if (SettlementOwnerEnum.InvoiceType.ORDINARY.getCode().equals(invoiceType)) { if (SettlementOwnerEnum.InvoiceType.ORDINARY.getCode().equals(invoiceType)) {
if (settlementOwnerDetail.getSettlementFreight().compareTo(BigDecimal.ZERO) == 0) { if (settlementOwnerDetail.getSettlementFreight().compareTo(BigDecimal.ZERO) == 0) {
settlementOwnerDetail.setFinalPaymentStatus(SettlementOwnerDetailEnum.FinalPaymentStatus.NO_REQUIRE.getCode()); settlementOwnerDetail.setFinalPaymentStatus(SettlementOwnerDetailEnum.FinalPaymentStatus.NO_REQUIRE.getCode());
...@@ -179,6 +178,8 @@ public class OrderChildSyncTransportListener { ...@@ -179,6 +178,8 @@ public class OrderChildSyncTransportListener {
} }
settlementOwnerDetail.setInvoiceType(invoiceType); settlementOwnerDetail.setInvoiceType(invoiceType);
settlementDriverDetail.setInvoiceType(invoiceType); settlementDriverDetail.setInvoiceType(invoiceType);
//生成借款标识
orderChildLoanComponent.orderConfirmAfterProcess(settlementDriverDetail, settlementOwnerDetail);
log.info("当前货主结算信息{},车主结算信息:{}", JSONUtil.parse(settlementOwnerDetail), JSONUtil.parse(settlementDriverDetail)); log.info("当前货主结算信息{},车主结算信息:{}", JSONUtil.parse(settlementOwnerDetail), JSONUtil.parse(settlementDriverDetail));
settlementOwnerDetailDao.updateInvoiceType(settlementOwnerDetail); settlementOwnerDetailDao.updateInvoiceType(settlementOwnerDetail);
......
...@@ -26,7 +26,7 @@ public interface OwnerLoanAccountMapper extends BaseMapper<OwnerLoanAccount> { ...@@ -26,7 +26,7 @@ public interface OwnerLoanAccountMapper extends BaseMapper<OwnerLoanAccount> {
Integer addAccount(@Param("account") OwnerLoanAccount account, @Param("now") String nowStr); Integer addAccount(@Param("account") OwnerLoanAccount account, @Param("now") String nowStr);
@Update("update owner_loan_account set funding_account_balance = funding_account_balance - #{account.fundingAccountBalance}" + @Update("update owner_loan_account set funding_account_balance = funding_account_balance - #{account.fundingAccountBalance}" +
",funding_usable_balance = funding_usable_balance + #{account.fundingUsableBalance},funding_frozen_balance = funding_frozen_balance - #{account.fundingFrozenBalance}" + ",funding_usable_balance = funding_usable_balance - #{account.fundingUsableBalance},funding_frozen_balance = funding_frozen_balance + #{account.fundingFrozenBalance}" +
",virtually_account_balance = virtually_account_balance - #{account.virtuallyAccountBalance},virtually_usable_balance = virtually_usable_balance - #{account.virtuallyUsableBalance}" + ",virtually_account_balance = virtually_account_balance - #{account.virtuallyAccountBalance},virtually_usable_balance = virtually_usable_balance - #{account.virtuallyUsableBalance}" +
",virtually_frozen_balance = virtually_frozen_balance + #{account.virtuallyFrozenBalance}" + ",virtually_frozen_balance = virtually_frozen_balance + #{account.virtuallyFrozenBalance}" +
",modified_time=#{now}" ",modified_time=#{now}"
...@@ -40,4 +40,21 @@ public interface OwnerLoanAccountMapper extends BaseMapper<OwnerLoanAccount> { ...@@ -40,4 +40,21 @@ public interface OwnerLoanAccountMapper extends BaseMapper<OwnerLoanAccount> {
@SelectProvider(type = OwnerLoanAccountSqlProvider.class, method = "pageByParam") @SelectProvider(type = OwnerLoanAccountSqlProvider.class, method = "pageByParam")
IPage<CarrierOwnerLoanAccountVO> pageByParam(@Param("page") Page<CarrierOwnerLoanAccountVO> page, @Param("param") PageOwnerLoanAccountParam param); IPage<CarrierOwnerLoanAccountVO> pageByParam(@Param("page") Page<CarrierOwnerLoanAccountVO> page, @Param("param") PageOwnerLoanAccountParam param);
@Update("update owner_loan_account set funding_account_balance = funding_account_balance - #{account.fundingAccountBalance}" +
",funding_usable_balance = funding_usable_balance - #{account.fundingUsableBalance},funding_frozen_balance = funding_frozen_balance - #{account.fundingFrozenBalance}" +
",virtually_account_balance = virtually_account_balance - #{account.virtuallyAccountBalance},virtually_usable_balance = virtually_usable_balance - #{account.virtuallyUsableBalance}" +
",virtually_frozen_balance = virtually_frozen_balance - #{account.virtuallyFrozenBalance}" +
",modified_time=#{now}"
+ "where id = #{account.id} and modified_time = #{account.modifiedTime}"
)
Integer childWriteOffOwnerLoanAccountCAS(OwnerLoanAccount account, String nowStr);
@Update("update owner_loan_account set funding_account_balance = funding_account_balance + #{account.fundingAccountBalance}" +
",funding_usable_balance = funding_usable_balance + #{account.fundingUsableBalance},funding_frozen_balance = funding_frozen_balance - #{account.fundingFrozenBalance}" +
",virtually_account_balance = virtually_account_balance + #{account.virtuallyAccountBalance},virtually_usable_balance = virtually_usable_balance + #{account.virtuallyUsableBalance}" +
",virtually_frozen_balance = virtually_frozen_balance - #{account.virtuallyFrozenBalance}" +
",modified_time=#{now}"
+ "where id = #{account.id} and modified_time = #{account.modifiedTime}"
)
Integer thawOwnerLoanAccountCAS(OwnerLoanAccount account, String nowStr);
} }
...@@ -53,6 +53,10 @@ public class OwnerLoanAccountRunningWaterRecord implements HasKey<Integer> { ...@@ -53,6 +53,10 @@ public class OwnerLoanAccountRunningWaterRecord implements HasKey<Integer> {
@ApiModelProperty("借款单号") @ApiModelProperty("借款单号")
private Long loanNo; private Long loanNo;
@TableField("loan_type")
@ApiModelProperty("借款类型 1:虚拟货币 2:资金")
private Integer loanType;
@TableField("child_no") @TableField("child_no")
@ApiModelProperty("运单编号") @ApiModelProperty("运单编号")
...@@ -68,9 +72,9 @@ public class OwnerLoanAccountRunningWaterRecord implements HasKey<Integer> { ...@@ -68,9 +72,9 @@ public class OwnerLoanAccountRunningWaterRecord implements HasKey<Integer> {
@ApiModelProperty("金额") @ApiModelProperty("金额")
private BigDecimal alterationBalance; private BigDecimal alterationBalance;
@TableField("useable_balance") @TableField("use_able_balance")
@ApiModelProperty("可用余额") @ApiModelProperty("可用余额")
private BigDecimal useableBalance; private BigDecimal useAbleBalance;
@TableField("frozen_balance") @TableField("frozen_balance")
@ApiModelProperty("冻结余额") @ApiModelProperty("冻结余额")
......
...@@ -43,6 +43,7 @@ public class SettlementDriver implements HasKey<Integer> { ...@@ -43,6 +43,7 @@ public class SettlementDriver implements HasKey<Integer> {
private BigDecimal lossWeight; //货损吨数 private BigDecimal lossWeight; //货损吨数
private BigDecimal lossFreight; //货损金额(分) private BigDecimal lossFreight; //货损金额(分)
private BigDecimal settlementFreight; //结算金额(分) private BigDecimal settlementFreight; //结算金额(分)
private Integer loanFlag; //借款标示 0:未借款 1:已借款
private Integer invoiceType; //开票标识:1网运单 2普通单 private Integer invoiceType; //开票标识:1网运单 2普通单
private String settlementPlatform; //结算平台 private String settlementPlatform; //结算平台
private Integer prepayFreightFlag; //预付运费标示 0:未预付 1:已预付 private Integer prepayFreightFlag; //预付运费标示 0:未预付 1:已预付
......
...@@ -44,6 +44,7 @@ public class SettlementDriverDetail implements HasKey<Integer> { ...@@ -44,6 +44,7 @@ public class SettlementDriverDetail implements HasKey<Integer> {
private BigDecimal lossFreight; //货损金额(分) private BigDecimal lossFreight; //货损金额(分)
private BigDecimal prepayFreight; //预付运费金额(分) private BigDecimal prepayFreight; //预付运费金额(分)
private Integer prepayFreightFlag; //预付运费标示 0:未预付 1:已预付 private Integer prepayFreightFlag; //预付运费标示 0:未预付 1:已预付
private Integer loanFlag; //借款标示 0:未借款 1:已借款
private BigDecimal settlementFreight; //结算金额(分) private BigDecimal settlementFreight; //结算金额(分)
private Integer invoiceType; //开票标识:1网运单 2普通单 private Integer invoiceType; //开票标识:1网运单 2普通单
private Integer status; //状态 private Integer status; //状态
......
...@@ -41,6 +41,7 @@ public class SettlementOwner implements HasKey<Integer> { ...@@ -41,6 +41,7 @@ public class SettlementOwner implements HasKey<Integer> {
private BigDecimal lossFreight; //货损金额(分) private BigDecimal lossFreight; //货损金额(分)
private BigDecimal prepayFreight; //预付运费金额(分) private BigDecimal prepayFreight; //预付运费金额(分)
private BigDecimal settlementFreight; //结算金额(分) private BigDecimal settlementFreight; //结算金额(分)
private BigDecimal loanFreight; //借款金额(分)
private Integer invoiceType; //开票标识:1网运单 2普通单 private Integer invoiceType; //开票标识:1网运单 2普通单
private BigDecimal invoiceFreight; //开票金额(分) private BigDecimal invoiceFreight; //开票金额(分)
private String invoiceImg; //结算凭证 private String invoiceImg; //结算凭证
......
...@@ -49,6 +49,7 @@ public class SettlementOwnerDetail implements HasKey<Integer> { ...@@ -49,6 +49,7 @@ public class SettlementOwnerDetail implements HasKey<Integer> {
private BigDecimal lossFreight; //货损金额(分) private BigDecimal lossFreight; //货损金额(分)
private BigDecimal prepayFreight; //预付运费金额(分) private BigDecimal prepayFreight; //预付运费金额(分)
private BigDecimal settlementFreight; //结算金额(分) private BigDecimal settlementFreight; //结算金额(分)
private BigDecimal loanFreight; //借款抵扣金额(分)
private BigDecimal invoiceFreight; //开票金额(分) private BigDecimal invoiceFreight; //开票金额(分)
private Integer invoiceType; //开票标识:1网运单 2普通单 private Integer invoiceType; //开票标识:1网运单 2普通单
private Integer finalPaymentStatus; //尾款状态 0-否,1-是,2-无需支付 private Integer finalPaymentStatus; //尾款状态 0-否,1-是,2-无需支付
......
...@@ -16,6 +16,7 @@ import com.clx.performance.dao.loan.OwnerLoanRecordDao; ...@@ -16,6 +16,7 @@ import com.clx.performance.dao.loan.OwnerLoanRecordDao;
import com.clx.performance.dao.loan.OwnerRepaymentDao; import com.clx.performance.dao.loan.OwnerRepaymentDao;
import com.clx.performance.enums.PerformanceResultEnum; import com.clx.performance.enums.PerformanceResultEnum;
import com.clx.performance.enums.RunningWaterTypeEnum; import com.clx.performance.enums.RunningWaterTypeEnum;
import com.clx.performance.enums.loan.OwnerLoanAccountRunningWaterRecordEnum;
import com.clx.performance.enums.loan.OwnerLoanRecordEnum; import com.clx.performance.enums.loan.OwnerLoanRecordEnum;
import com.clx.performance.enums.loan.OwnerRePaymentEnum; import com.clx.performance.enums.loan.OwnerRePaymentEnum;
import com.clx.performance.model.OwnerBindCardRecord; import com.clx.performance.model.OwnerBindCardRecord;
...@@ -40,6 +41,7 @@ import com.clx.user.feign.OwnerFeign; ...@@ -40,6 +41,7 @@ import com.clx.user.feign.OwnerFeign;
import com.clx.user.vo.feign.OwnerInfoFeignVO; import com.clx.user.vo.feign.OwnerInfoFeignVO;
import com.msl.common.base.Optional; import com.msl.common.base.Optional;
import com.msl.common.enums.ResultCodeEnum; import com.msl.common.enums.ResultCodeEnum;
import com.msl.common.exception.ServiceSystemException;
import com.msl.common.result.Result; import com.msl.common.result.Result;
import com.msl.common.utils.DateUtils; import com.msl.common.utils.DateUtils;
import com.msl.document.api.feign.ContractEvidenceFeign; import com.msl.document.api.feign.ContractEvidenceFeign;
...@@ -54,6 +56,7 @@ import org.apache.poi.ss.formula.functions.T; ...@@ -54,6 +56,7 @@ import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -323,4 +326,98 @@ public class OwnerLoanRecordServiceImpl implements OwnerLoanRecordService { ...@@ -323,4 +326,98 @@ public class OwnerLoanRecordServiceImpl implements OwnerLoanRecordService {
Result<ContractEvidenceRecordVo> contractEvidenceDetail = contractEvidenceFeign.getContractEvidenceDetail(longResult.getData()); Result<ContractEvidenceRecordVo> contractEvidenceDetail = contractEvidenceFeign.getContractEvidenceDetail(longResult.getData());
return contractEvidenceDetail.getData().getFileUrl(); return contractEvidenceDetail.getData().getFileUrl();
} }
@Override
@Transactional(rollbackFor = Exception.class)
public void getLoanBalance(BigDecimal orderChildPrice, Long userNo, String childNo) {
//TODO 需要加锁处理
List<OwnerLoanRecord> updateList = new LinkedList<>();
List<OwnerLoanRecord> ownerLoanRecords = ownerLoanRecordDao.selectLoanBalance(userNo);
BigDecimal orderChildPriceTemp = orderChildPrice;
for (OwnerLoanRecord ownerLoanRecord : ownerLoanRecords) {
BigDecimal loanResidueBalance = ownerLoanRecord.getLoanResidueBalance();
log.info("12.当前预估运费金额:{},借款单号{},借款剩余金额{}", orderChildPriceTemp, ownerLoanRecord.getLoanNo(), loanResidueBalance);
if (loanResidueBalance.compareTo(orderChildPriceTemp) >= 0) {
log.info("当前借款单的剩余金额足够预估运费金额");
generateFrozenOwnerLoanRunningWater(ownerLoanRecord, childNo, orderChildPrice);
updateList.add(ownerLoanRecord.setLoanResidueBalance(loanResidueBalance.subtract(orderChildPriceTemp)));
orderChildPriceTemp = BigDecimal.ZERO;
break;
} else {
log.info("当前借款单的剩余金额不够抵扣预估运费金额,先进行扣除当前借款所有剩余");
generateFrozenOwnerLoanRunningWater(ownerLoanRecord, childNo, orderChildPrice);
updateList.add(ownerLoanRecord.setLoanResidueBalance(BigDecimal.ZERO));
orderChildPriceTemp = orderChildPriceTemp.subtract(loanResidueBalance);
}
}
if (orderChildPriceTemp.compareTo(BigDecimal.ZERO) != 0) {
throw new ServiceSystemException(PerformanceResultEnum.ORDER_CHILD_SAVE_FAIL, "货主货款不足");
}
for (OwnerLoanRecord update : updateList) {
ownerLoanRecordDao.updateEntityByKey(update);
}
}
public void generateFrozenOwnerLoanRunningWater(OwnerLoanRecord ownerLoanRecord, String childNo, BigDecimal orderChildPrice) {
log.info("13.生成借款冻结流水");
OwnerLoanAccount update = new OwnerLoanAccount();
while (true) {
ownerLoanAccountUpdate(ownerLoanRecord, orderChildPrice, update);
Integer i = ownerLoanAccountDao.updateAccountCAS(update, LocalDateTime.now(), false);
log.info("CAS更新结果:{}", i);
if (i == 1) {
OwnerLoanAccountRunningWaterRecord waterRecord = new OwnerLoanAccountRunningWaterRecord();
waterRecord.setLoanNo(ownerLoanRecord.getLoanNo());
waterRecord.setOwnerUserName(ownerLoanRecord.getOwnerUserName());
waterRecord.setOwnerUserNo(ownerLoanRecord.getOwnerUserNo());
waterRecord.setMobile(ownerLoanRecord.getMobile());
waterRecord.setLoanType(ownerLoanRecord.getLoanType());
waterRecord.setRunningWaterNo(idGenerateSnowFlake.nextId(1L));
waterRecord.setChildNo(childNo);
waterRecord.setRunningWaterType(OwnerLoanAccountRunningWaterRecordEnum.RunWaterType.APPROVE_FROZEN.getCode());
waterRecord.setAlterationBalance(orderChildPrice);
OwnerLoanAccount account = ownerLoanAccountDao.getOneByField(OwnerLoanAccount::getOwnerUserNo,
ownerLoanRecord.getOwnerUserNo()).get();
waterRecord.setAccountBalance(account.getVirtuallyAccountBalance().add(account.getFundingAccountBalance()));
waterRecord.setUseAbleBalance(account.getVirtuallyUsableBalance().add(account.getFundingUsableBalance()));
waterRecord.setFrozenBalance(account.getVirtuallyFrozenBalance().add(account.getFundingFrozenBalance()));
waterRecord.setCreateBy("系统");
ownerLoanAccountRunningWaterRecordDao.saveEntity(waterRecord);
break;
}
}
}
public void ownerLoanAccountUpdate(OwnerLoanRecord ownerLoanRecord, BigDecimal orderChildPrice, OwnerLoanAccount update) {
log.info("执行CAS前置借款账户信息赋值");
Integer loanType = ownerLoanRecord.getLoanType();
OwnerLoanAccount account = ownerLoanAccountDao.getOneByField(OwnerLoanAccount::getOwnerUserNo,
ownerLoanRecord.getOwnerUserNo()).get();
if (OwnerLoanRecordEnum.LoanType.VIRTUAL_CURRENCY.getCode().equals(loanType)) {
log.info("进行虚拟货币信息赋值");
update.setId(account.getId());
update.setModifiedTime(account.getModifiedTime());
update.setVirtuallyFrozenBalance(orderChildPrice);
update.setVirtuallyUsableBalance(orderChildPrice);
update.setVirtuallyAccountBalance(BigDecimal.ZERO);
update.setFundingAccountBalance(BigDecimal.ZERO);
update.setFundingFrozenBalance(BigDecimal.ZERO);
update.setFundingUsableBalance(BigDecimal.ZERO);
} else {
log.info("进行资金信息赋值");
update.setId(account.getId());
update.setModifiedTime(account.getModifiedTime());
update.setFundingFrozenBalance(orderChildPrice);
update.setFundingUsableBalance(orderChildPrice);
update.setFundingAccountBalance(BigDecimal.ZERO);
update.setVirtuallyFrozenBalance(BigDecimal.ZERO);
update.setVirtuallyUsableBalance(BigDecimal.ZERO);
update.setVirtuallyAccountBalance(BigDecimal.ZERO);
}
}
} }
...@@ -189,6 +189,7 @@ public class SettlementMqHandlerServiceImpl implements SettlementMqHandlerServic ...@@ -189,6 +189,7 @@ public class SettlementMqHandlerServiceImpl implements SettlementMqHandlerServic
settlementDriver.setFreight(detail.getFreight()); settlementDriver.setFreight(detail.getFreight());
settlementDriver.setLossPrice(detail.getLossPrice()); settlementDriver.setLossPrice(detail.getLossPrice());
settlementDriver.setLossWeight(detail.getLossWeight()); settlementDriver.setLossWeight(detail.getLossWeight());
settlementDriver.setLoanFlag(detail.getLoanFlag());
settlementDriver.setLossFreight(detail.getLossFreight()); settlementDriver.setLossFreight(detail.getLossFreight());
settlementDriver.setPrepayFreightFlag(detail.getPrepayFreightFlag()); settlementDriver.setPrepayFreightFlag(detail.getPrepayFreightFlag());
settlementDriver.setSettlementFreight(detail.getSettlementFreight()); settlementDriver.setSettlementFreight(detail.getSettlementFreight());
...@@ -312,6 +313,7 @@ public class SettlementMqHandlerServiceImpl implements SettlementMqHandlerServic ...@@ -312,6 +313,7 @@ public class SettlementMqHandlerServiceImpl implements SettlementMqHandlerServic
settlementOwner.setLossWeight(settlementOwnerDetail.getLossWeight()); settlementOwner.setLossWeight(settlementOwnerDetail.getLossWeight());
settlementOwner.setLossFreight(settlementOwnerDetail.getLossFreight()); settlementOwner.setLossFreight(settlementOwnerDetail.getLossFreight());
settlementOwner.setSettlementFreight(settlementOwnerDetail.getSettlementFreight()); settlementOwner.setSettlementFreight(settlementOwnerDetail.getSettlementFreight());
settlementOwner.setLoanFreight(settlementOwnerDetail.getLoanFreight());
settlementOwner.setInvoiceType(settlementOwnerDetail.getInvoiceType()); settlementOwner.setInvoiceType(settlementOwnerDetail.getInvoiceType());
settlementOwner.setInvoiceFreight(settlementOwnerDetail.getInvoiceFreight()); settlementOwner.setInvoiceFreight(settlementOwnerDetail.getInvoiceFreight());
...@@ -361,6 +363,7 @@ public class SettlementMqHandlerServiceImpl implements SettlementMqHandlerServic ...@@ -361,6 +363,7 @@ public class SettlementMqHandlerServiceImpl implements SettlementMqHandlerServic
settlementOwner.setFreight(settlementOwner.getFreight().add(item.getFreight())); settlementOwner.setFreight(settlementOwner.getFreight().add(item.getFreight()));
settlementOwner.setLossWeight(settlementOwner.getLossWeight().add(item.getLossWeight())); settlementOwner.setLossWeight(settlementOwner.getLossWeight().add(item.getLossWeight()));
settlementOwner.setLossFreight(settlementOwner.getLossFreight().add(item.getLossFreight())); settlementOwner.setLossFreight(settlementOwner.getLossFreight().add(item.getLossFreight()));
settlementOwner.setLoanFreight(settlementOwner.getLoanFreight().add(item.getLoanFreight()));
settlementOwner.setPrepayFreight(settlementOwner.getPrepayFreight().add(item.getPrepayFreight())); settlementOwner.setPrepayFreight(settlementOwner.getPrepayFreight().add(item.getPrepayFreight()));
settlementOwner.setSettlementFreight(settlementOwner.getSettlementFreight().add(item.getSettlementFreight())); settlementOwner.setSettlementFreight(settlementOwner.getSettlementFreight().add(item.getSettlementFreight()));
settlementOwner.setInvoiceFreight(settlementOwner.getInvoiceFreight().add(item.getInvoiceFreight())); settlementOwner.setInvoiceFreight(settlementOwner.getInvoiceFreight().add(item.getInvoiceFreight()));
...@@ -389,6 +392,7 @@ public class SettlementMqHandlerServiceImpl implements SettlementMqHandlerServic ...@@ -389,6 +392,7 @@ public class SettlementMqHandlerServiceImpl implements SettlementMqHandlerServic
settlementOwner.setLossWeight(settlementOwnerDetail.getLossWeight()); settlementOwner.setLossWeight(settlementOwnerDetail.getLossWeight());
settlementOwner.setLossFreight(settlementOwnerDetail.getLossFreight()); settlementOwner.setLossFreight(settlementOwnerDetail.getLossFreight());
settlementOwner.setSettlementFreight(settlementOwnerDetail.getSettlementFreight()); settlementOwner.setSettlementFreight(settlementOwnerDetail.getSettlementFreight());
settlementOwner.setLoanFreight(settlementOwnerDetail.getLoanFreight());
settlementOwner.setInvoiceType(settlementOwnerDetail.getInvoiceType()); settlementOwner.setInvoiceType(settlementOwnerDetail.getInvoiceType());
settlementOwner.setInvoiceFreight(settlementOwnerDetail.getInvoiceFreight()); settlementOwner.setInvoiceFreight(settlementOwnerDetail.getInvoiceFreight());
......
...@@ -12,6 +12,8 @@ import com.clx.performance.vo.pc.loan.carrier.OwnerOrderPaymentDetailVO; ...@@ -12,6 +12,8 @@ import com.clx.performance.vo.pc.loan.carrier.OwnerOrderPaymentDetailVO;
import com.clx.performance.vo.pc.loan.owner.OwnerLoanRecordDetail; import com.clx.performance.vo.pc.loan.owner.OwnerLoanRecordDetail;
import com.clx.performance.vo.pc.loan.carrier.CarrierTransferPaymentDetailVO; import com.clx.performance.vo.pc.loan.carrier.CarrierTransferPaymentDetailVO;
import java.math.BigDecimal;
/** /**
* @author kavin * @author kavin
* Date 2024-01-20 * Date 2024-01-20
...@@ -35,4 +37,6 @@ public interface OwnerLoanRecordService { ...@@ -35,4 +37,6 @@ public interface OwnerLoanRecordService {
CarrierTransferPaymentDetailVO getTransferPaymentDetail(Integer id); CarrierTransferPaymentDetailVO getTransferPaymentDetail(Integer id);
String savePaymentApplicationForm(ExportPaymentApplicationFormParam param); String savePaymentApplicationForm(ExportPaymentApplicationFormParam param);
void getLoanBalance(BigDecimal orderChildPrice, Long userNo, String childNo);
} }
...@@ -17,7 +17,7 @@ public class OwnerLoanAccountRunningWaterRecordSqlProvider { ...@@ -17,7 +17,7 @@ public class OwnerLoanAccountRunningWaterRecordSqlProvider {
SELECT(" id, owner_user_no as ownerUserNo, owner_user_name as ownerUserName, mobile, " + SELECT(" id, owner_user_no as ownerUserNo, owner_user_name as ownerUserName, mobile, " +
" running_water_no as runningWaterNo, loan_no as loanNo, child_no as childNo, " + " running_water_no as runningWaterNo, loan_no as loanNo, child_no as childNo, " +
" running_water_type as runningWaterType, " + " running_water_type as runningWaterType, " +
" alteration_balance as alterationBalance, useable_balance as useableBalance, frozen_balance as frozenBalance, account_balance as accountBalance, " + " alteration_balance as alterationBalance, use_able_balance as useAbleBalance, frozen_balance as frozenBalance, account_balance as accountBalance, " +
" create_by as createBy, " + " create_by as createBy, " +
" date_format(create_time, '%Y-%m-%d %H:%i:%s') as createTime, " + " date_format(create_time, '%Y-%m-%d %H:%i:%s') as createTime, " +
" date_format(modified_time, '%Y-%m-%d %H:%i:%s') as modifiedTime " " date_format(modified_time, '%Y-%m-%d %H:%i:%s') as modifiedTime "
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论