|
@@ -8,15 +8,14 @@ import com.dayou.brokerage.constants.BrokerageRule;
|
|
|
import com.dayou.common.BaseEntity;
|
|
|
import com.dayou.dto.PaymentDetailDTO;
|
|
|
import com.dayou.dto.PaymentExportDTO;
|
|
|
-import com.dayou.entity.PaymentCollection;
|
|
|
-import com.dayou.entity.UserTarget;
|
|
|
+import com.dayou.entity.*;
|
|
|
import com.dayou.enums.OperationTypeEnum;
|
|
|
import com.dayou.exception.ErrorCode;
|
|
|
import com.dayou.mapper.PaymentCollectionMapper;
|
|
|
-import com.dayou.service.IItemService;
|
|
|
-import com.dayou.service.IPaymentCollectionService;
|
|
|
+import com.dayou.service.*;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.dayou.utils.DateUtils;
|
|
|
+import com.dayou.utils.LoginContext;
|
|
|
import com.dayou.vo.ItemPaymentVO;
|
|
|
import com.dayou.vo.PaymentCollectionVO;
|
|
|
import com.sun.org.apache.xpath.internal.operations.Bool;
|
|
@@ -46,6 +45,8 @@ import java.util.stream.Collectors;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import com.dayou.enums.BatchTaskTypeEnum;
|
|
|
|
|
|
+import static com.dayou.enums.MainBusinessEnum.ITEM_BUSINESS;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* 回款记录 服务实现类
|
|
@@ -63,6 +64,15 @@ public class PaymentCollectionServiceImpl extends ServiceImpl<PaymentCollectionM
|
|
|
@Autowired
|
|
|
private IItemService iItemService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IFinanceRealFundService financeRealFundService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOrderFundService orderFundService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFinanceClaimService financeClaimService;
|
|
|
+
|
|
|
@Override
|
|
|
@SuppressWarnings("unchecked")
|
|
|
public Page<PaymentCollectionVO> selectPage(Page page, PaymentCollectionVO paymentCollection){
|
|
@@ -90,29 +100,50 @@ public class PaymentCollectionServiceImpl extends ServiceImpl<PaymentCollectionM
|
|
|
}
|
|
|
|
|
|
@DoBrokerage(operation = OperationTypeEnum.SETTLE,rule = BrokerageRule.LAND_MARKETER_RULE)
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public Boolean add(PaymentCollection paymentCollection){
|
|
|
Double amount = paymentCollection.getAmount();
|
|
|
+ //检查实收款余额
|
|
|
+ Long realAmountId = paymentCollection.getRealAmountId();
|
|
|
+ BigDecimal notClaimAmount = financeRealFundService.getNotClaimAmount(realAmountId);
|
|
|
+ if (notClaimAmount.compareTo(BigDecimal.valueOf(amount)) < 0){
|
|
|
+ ErrorCode.throwBusinessException(ErrorCode.CUSTOM_ERROR,"抱歉!实收款金额小于认领金额");
|
|
|
+ }
|
|
|
+ //检查是否有订单收款记录
|
|
|
+ Item item = iItemService.getById(paymentCollection.getItemId());
|
|
|
+ Long orderFundId = paymentCollection.getOrderFundId();
|
|
|
+ if (orderFundId ==null){
|
|
|
+ //创建订单收款记录
|
|
|
+ OrderFund orderFund = new OrderFund();
|
|
|
+ orderFund.setShouldAmount(item.getAmount());
|
|
|
+ orderFund.setOrderName(item.getName());
|
|
|
+ orderFund.setOrderId(item.getBusinessNo());
|
|
|
+ orderFund.setBusinessId(item.getId());
|
|
|
+ orderFund.setBusinessType(ITEM_BUSINESS.name());
|
|
|
+ orderFundService.add(orderFund);
|
|
|
+ orderFundId = orderFund.getId();
|
|
|
+ }
|
|
|
if (amount==null || amount<0){
|
|
|
ErrorCode.throwBusinessException(ErrorCode.CUSTOM_ERROR,"抱歉!回款金额不能小于0");
|
|
|
}
|
|
|
- BigDecimal totalAmount = iItemService.getById(paymentCollection.getItemId()).getAmount();
|
|
|
+ BigDecimal totalAmount = item.getAmount();
|
|
|
if (totalAmount==null){
|
|
|
ErrorCode.throwBusinessException(ErrorCode.CUSTOM_ERROR,"抱歉!该项目合同金额未填写,请先完善合同金额再操作。");
|
|
|
}
|
|
|
- List<Double> doneAmount = this.list(new LambdaQueryWrapper<PaymentCollection>()
|
|
|
- .select(PaymentCollection::getAmount)
|
|
|
- .eq(PaymentCollection::getItemId, paymentCollection.getItemId())
|
|
|
- .eq(BaseEntity::getDeleted, Boolean.FALSE)).stream().map(PaymentCollection::getAmount).collect(Collectors.toList());
|
|
|
-
|
|
|
-
|
|
|
- BigDecimal sum = BigDecimal.valueOf(doneAmount.stream().reduce(0D, Double::sum));
|
|
|
-
|
|
|
- BigDecimal payment = BigDecimal.valueOf(amount);
|
|
|
- BigDecimal add = sum.add(payment);
|
|
|
- if (add.compareTo(totalAmount)==1){
|
|
|
- ErrorCode.throwBusinessException(ErrorCode.CUSTOM_ERROR,"新增回款金额已大于合同签订金额,请检查.");
|
|
|
- }
|
|
|
+ //创建认领记录流水表
|
|
|
+ FinanceClaim financeClaim = new FinanceClaim();
|
|
|
+ financeClaim.setRealFundId(realAmountId);
|
|
|
+ financeClaim.setClaimUserId(LoginContext.getCurrentUserId());
|
|
|
+ financeClaim.setOrderFundId(orderFundId);
|
|
|
+ financeClaim.setClaimAmount(BigDecimal.valueOf(amount));
|
|
|
+ financeClaim.setClaimDatetime(DateUtils.localDateToDate(paymentCollection.getPaymentDate()));
|
|
|
+ financeClaimService.save(financeClaim);
|
|
|
+
|
|
|
+ //更新订单收款表实收款信息
|
|
|
+ BigDecimal totalClaimAmountByOrderFundId = financeClaimService.getTotalClaimAmountByOrderFundId(orderFundId);
|
|
|
+ orderFundService.update(new LambdaUpdateWrapper<OrderFund>()
|
|
|
+ .eq(OrderFund::getId, orderFundId).set(OrderFund::getRealAmount,totalClaimAmountByOrderFundId));
|
|
|
return this.save(paymentCollection);
|
|
|
}
|
|
|
|