|
@@ -1,11 +1,15 @@
|
|
|
package com.dayou.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.dayou.common.BaseEntity;
|
|
|
import com.dayou.dto.*;
|
|
|
import com.dayou.entity.*;
|
|
|
+import com.dayou.enums.MainBusinessEnum;
|
|
|
import com.dayou.exception.ErrorCode;
|
|
|
import com.dayou.mapper.AssetsProductionMapper;
|
|
|
+import com.dayou.mapper.OrderFundMapper;
|
|
|
+import com.dayou.mapper.ProductionFundMapper;
|
|
|
import com.dayou.service.*;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.dayou.utils.LoginContext;
|
|
@@ -18,9 +22,11 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -62,6 +68,15 @@ public class AssetsProductionServiceImpl extends ServiceImpl<AssetsProductionMap
|
|
|
@Autowired
|
|
|
private IBusinessProductionChoiceLogService choiceLogService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IFinanceClaimService financeClaimService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProductionFundMapper productionFundMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrderFundMapper orderFundMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 根据资产业务id查询资产业务产品
|
|
|
*
|
|
@@ -91,7 +106,7 @@ public class AssetsProductionServiceImpl extends ServiceImpl<AssetsProductionMap
|
|
|
this.save(assetsProduction);
|
|
|
// 选择产品时给当前选择产品的评估对象添加选择产品记录
|
|
|
List<BusinessProductionChoiceLog> choiceLogList = new ArrayList<>();
|
|
|
- for (Long targetId : assetsProduction.getTargetIdList()){
|
|
|
+ for (Long targetId : assetsProduction.getTargetIdList()) {
|
|
|
BusinessProductionChoiceLog choiceLog = new BusinessProductionChoiceLog();
|
|
|
choiceLog.setBusinessType("ASSET_BUSINESS");
|
|
|
choiceLog.setProductionType(assetsProduction.getProductionType());
|
|
@@ -109,7 +124,7 @@ public class AssetsProductionServiceImpl extends ServiceImpl<AssetsProductionMap
|
|
|
public Boolean update(AssetsProduction assetsProduction) {
|
|
|
// 更新选择产品时给当前选择产品的评估对象更新选择产品记录
|
|
|
List<BusinessProductionChoiceLog> choiceLogList = new ArrayList<>();
|
|
|
- for (Long targetId : assetsProduction.getTargetIdList()){
|
|
|
+ for (Long targetId : assetsProduction.getTargetIdList()) {
|
|
|
BusinessProductionChoiceLog choiceLog = choiceLogService.getOne(new LambdaQueryWrapper<BusinessProductionChoiceLog>()
|
|
|
.eq(BusinessProductionChoiceLog::getBusinessType, "ASSET_BUSINESS")
|
|
|
.eq(BusinessProductionChoiceLog::getBusinessId, assetsProduction.getBusinessId())
|
|
@@ -169,7 +184,7 @@ public class AssetsProductionServiceImpl extends ServiceImpl<AssetsProductionMap
|
|
|
// 生成产品二维码
|
|
|
assetsProduction.setQrCode(businessProductionService.doCreateNormalCode(assetsProduction.getProductionType(), assetsProduction.getProductionNo()));
|
|
|
// 新增产品收款信息
|
|
|
- if (!assetsProduction.getProductionType().equals(STATEMENT.getCode())){
|
|
|
+ if (!assetsProduction.getProductionType().equals(STATEMENT.getCode())) {
|
|
|
addAssetsProShouldAmount(assetsProduction);
|
|
|
}
|
|
|
return assetsProductionMapper.writeAssetsProduction(assetsProduction);
|
|
@@ -315,6 +330,7 @@ public class AssetsProductionServiceImpl extends ServiceImpl<AssetsProductionMap
|
|
|
|
|
|
/**
|
|
|
* 产品标记送达
|
|
|
+ *
|
|
|
* @param productionNo 产品号
|
|
|
* @return Boolean
|
|
|
*/
|
|
@@ -325,6 +341,7 @@ public class AssetsProductionServiceImpl extends ServiceImpl<AssetsProductionMap
|
|
|
|
|
|
/**
|
|
|
* 查找实收款认领产品列表
|
|
|
+ *
|
|
|
* @param apFundSelectDTO 查询dto
|
|
|
* @return List<AssetsProductionFundVo>
|
|
|
*/
|
|
@@ -335,6 +352,7 @@ public class AssetsProductionServiceImpl extends ServiceImpl<AssetsProductionMap
|
|
|
|
|
|
/**
|
|
|
* 查找实收款认领订单列表
|
|
|
+ *
|
|
|
* @param apFundSelectDTO 查询dto
|
|
|
* @return List<AssetsProductionFundVo>
|
|
|
*/
|
|
@@ -344,7 +362,94 @@ public class AssetsProductionServiceImpl extends ServiceImpl<AssetsProductionMap
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 认领实收款到 产品
|
|
|
+ *
|
|
|
+ * @param claimOrders 认领信息
|
|
|
+ * @return Boolean
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean doAllotRealAmountToProd(List<OrderReportDTO> claimOrders) {
|
|
|
+ if (CollectionUtil.isNotEmpty(claimOrders)) {
|
|
|
+ //先校验各订单此次认领金额之和是否大于这笔实收款的剩余金额
|
|
|
+ Long financeFundId = claimOrders.get(0).getFinanceFundId();
|
|
|
+ BigDecimal residueAmount = financeClaimService.checkFinanceFound(financeFundId);
|
|
|
+ BigDecimal thisTimeTotalAmount = claimOrders.stream().map(OrderReportDTO::getThisTimeAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ if (thisTimeTotalAmount.compareTo(residueAmount) > 0) {
|
|
|
+ ErrorCode.throwBusinessException(ErrorCode.CUSTOM_ERROR, "本次订单认领之和大于实收款剩余金额,请检查后再认领。");
|
|
|
+ return Boolean.FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (OrderReportDTO orderReportDTO : claimOrders) {
|
|
|
+ BigDecimal thisTimeAmount = orderReportDTO.getThisTimeAmount();
|
|
|
+ if (thisTimeAmount == null || thisTimeAmount.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 更新产品实收款
|
|
|
+ productionFundMapper.updateRealAmount(orderReportDTO.getProductionFundId(), thisTimeAmount);
|
|
|
+ // 更新订单实收款
|
|
|
+ orderFundMapper.updateRealAmount(orderReportDTO.getOrderFundId(), thisTimeAmount);
|
|
|
+
|
|
|
+ //插入订单认领记录流水表
|
|
|
+ FinanceClaim financeClaim = new FinanceClaim();
|
|
|
+ Long userId = LoginContext.getCurrentUserId();
|
|
|
+ financeClaim.setClaimUserId(userId);
|
|
|
+ financeClaim.setRealFundId(financeFundId);
|
|
|
+ financeClaim.setOrderFundId(orderReportDTO.getProductionFundId());
|
|
|
+ financeClaim.setClaimAmount(thisTimeAmount);
|
|
|
+ financeClaim.setClaimDatetime(LocalDateTime.now());
|
|
|
+ financeClaim.setProductionFundId(orderReportDTO.getOrderFundId());
|
|
|
+ financeClaimService.add(financeClaim);
|
|
|
+ }
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
+ return Boolean.FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据订单收款id获取产品收款信息
|
|
|
+ * @param orderFundId 资产订单收款id
|
|
|
+ * @return List<ReportDTO>
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<ReportDTO> getProductionFundByOrderFundId(Long orderFundId) {
|
|
|
+ return assetsProductionMapper.getProductionFundByOrderFundId(orderFundId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 资产分配订单实收款到产品
|
|
|
+ *
|
|
|
+ * @param orderReportDTO 分配信息
|
|
|
+ * @return Boolean
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean allotOrderRealAmountToProduction(OrderReportDTO orderReportDTO) {
|
|
|
+ List<ReportDTO> reports = orderReportDTO.getReports();
|
|
|
+ Long orderFundId = orderReportDTO.getOrderFundId();
|
|
|
+ BigDecimal residueAmount = orderFundMapper.residueNotAllotAmount(orderFundId);
|
|
|
+ BigDecimal totalAmount = reports.stream().map(ReportDTO::getThisTimeAmount).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ if (orderReportDTO.getRealAmount() == null) {
|
|
|
+ ErrorCode.throwBusinessException(ErrorCode.CUSTOM_ERROR, "该订单还未认领实收款,请先认领实收款后再分配。");
|
|
|
+ }
|
|
|
+ if (totalAmount.compareTo(residueAmount) > 0) {
|
|
|
+ ErrorCode.throwBusinessException(ErrorCode.CUSTOM_ERROR, "产品分配金额不能大于订单未分配金额,请检查后再试。");
|
|
|
+ }
|
|
|
+ if (CollectionUtil.isNotEmpty(reports)) {
|
|
|
+ for (ReportDTO reportDTO : reports) {
|
|
|
+ Long productionFundId = reportDTO.getProductionFundId();
|
|
|
+ if (reportDTO.getThisTimeAmount() == null || reportDTO.getThisTimeAmount().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ productionFundMapper.updateRealAmount(productionFundId, reportDTO.getThisTimeAmount());
|
|
|
+ }
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
+ return Boolean.FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 新增订单产品收款信息
|
|
|
+ *
|
|
|
* @param assetsProduction 资产产品信息
|
|
|
*/
|
|
|
public void addAssetsProShouldAmount(AssetsProduction assetsProduction) {
|
|
@@ -352,7 +457,7 @@ public class AssetsProductionServiceImpl extends ServiceImpl<AssetsProductionMap
|
|
|
List<AssetsEvaluationTarget> targetList = assetsEvaluationTargetService.list(new LambdaQueryWrapper<AssetsEvaluationTarget>()
|
|
|
.select(AssetsEvaluationTarget::getCheckValue)
|
|
|
.eq(AssetsEvaluationTarget::getReportNo, assetsProduction.getProductionNo()));
|
|
|
- if (ObjectUtil.isNotNull(targetList) && ObjectUtil.isNotEmpty(targetList)){
|
|
|
+ if (ObjectUtil.isNotNull(targetList) && ObjectUtil.isNotEmpty(targetList)) {
|
|
|
// 使用流计算审核价格的总和
|
|
|
BigDecimal total = targetList.stream()
|
|
|
.map(AssetsEvaluationTarget::getCheckValue)
|
|
@@ -365,7 +470,7 @@ public class AssetsProductionServiceImpl extends ServiceImpl<AssetsProductionMap
|
|
|
.select(OrderFund::getId)
|
|
|
.eq(OrderFund::getBusinessId, assetsProduction.getBusinessId()));
|
|
|
ProductionFund productionFund = new ProductionFund();
|
|
|
- productionFund.setBusinessType("ASSET_BUSINESS");
|
|
|
+ productionFund.setBusinessType(ASSET_BUSINESS.getCode());
|
|
|
productionFund.setBusinessId(assetsProduction.getBusinessId());
|
|
|
productionFund.setOrderFundId(orderFund.getId());
|
|
|
productionFund.setEvaluateAmount(total);
|