shiyunteng
11 小时以前 2db76f2066701cbe292f206ad49a7f8523b8aa9f
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/OutBoundServiceImpl.java
@@ -1,9 +1,8 @@
package com.by4cloud.platformx.business.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -26,6 +25,8 @@
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
;
/**
 * EPR出库记录
@@ -63,7 +64,7 @@
   @Override
   public R add(OutBoundAddDTO addDTO) {
      if (ArrayUtil.isEmpty(addDTO.getSubjectMatterList().toArray())) {
      if (CollUtil.isEmpty(addDTO.getSubjectMatterList())) {
         return R.failed("出库标的物不能为空");
      }
      MPJLambdaWrapper<ContractSubjectMatter> wrapper = new MPJLambdaWrapper<ContractSubjectMatter>()
@@ -79,7 +80,7 @@
            )
            .orderByAsc(ContractSubjectMatter::getCreateTime);
      List<ContractSubjectMatter> subjectMatterList = contractSubjectMatterMapper.selectList(wrapper);
      if (ArrayUtil.isEmpty(subjectMatterList.toArray())) {
      if (CollUtil.isEmpty(subjectMatterList)) {
         return R.failed("没有查询到相关合同订单");
      }
      List<String> erpCodeList = subjectMatterList.stream().map(ContractSubjectMatter::getMaterialCode).collect(Collectors.toList());
@@ -185,7 +186,7 @@
      });
      //出库应收款明细
      if (ArrayUtil.isNotEmpty(currentOutMap.keySet())) {
      if (CollUtil.isNotEmpty(currentOutMap.keySet())) {
         for (Long contractId : currentOutMap.keySet()) {
            //当前出库合同出库标的物
            List<ContractSubjectMatter> contractSubjectMatterList = contractSubjectMatterMapper.selectList(Wrappers.<ContractSubjectMatter>lambdaQuery()
@@ -264,7 +265,7 @@
                     //客户付款完成合同
                     List<Contract> customerCompleteContractList = contractMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getPartyAId, contract.getPartyAId())
                           .eq(Contract::getPartyBId, SecurityUtils.getUser().getCompId()).apply(" amount = paid_amount"));
                     if (ArrayUtil.isNotEmpty(customerCompleteContractList)) {
                     if (CollUtil.isNotEmpty(customerCompleteContractList)) {
                        List<BigDecimal> outAmountList = new ArrayList<>();
                        for (Contract completeContract : customerCompleteContractList
                        ) {
@@ -283,7 +284,7 @@
                              outAmountList.add(outConfirm.getTransationAmount());
                           }
                        }
                        if (ArrayUtil.isNotEmpty(outAmountList.toArray())) {
                        if (CollUtil.isNotEmpty(outAmountList)) {
                           BigDecimal currentInSum = outAmountList.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
                           //新增当前合同 资金转入
                           PaymentConfirm inConfirm = BeanUtil.copyProperties(paymentConfirm, PaymentConfirm.class, "id", "transationAmount",
@@ -316,7 +317,7 @@
                  //查询是否有后续阶段
//                  List<ContractPaymentSchedule> afterSchedule = scheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, contractId)
//                        .gt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder()));
//                  if (ArrayUtil.isEmpty(afterSchedule.toArray())) {
//                  if (.isEmpty(afterSchedule)) {
//                     schedule.setEffectiveEndDate(contract.getExpirationDate());
//                  }
                  scheduleMapper.updateById(schedule);
@@ -346,7 +347,7 @@
                     .eq(ContractPaymentSchedule::getContractId, schedule.getContractId())
                     .gt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder())
                     .orderByAsc(ContractPaymentSchedule::getCreateTime));
               if (ArrayUtil.isNotEmpty(afterSchedule.toArray()) && afterSchedule.size() == 1) {
               if (CollUtil.isNotEmpty(afterSchedule) && afterSchedule.size() == 1) {
                  //最后阶段生效时间
                  ContractPaymentSchedule endSchedule = afterSchedule.get(0);
                  if (StrUtil.equals(endSchedule.getStageName(), "质保金")) {
@@ -383,12 +384,12 @@
                  contract.setNextScheduleName(endSchedule.getStageName());
                  contractMapper.updateById(contract);
               }
               if (ArrayUtil.isNotEmpty(afterSchedule.toArray()) && afterSchedule.size() > 1) {
               if (CollUtil.isNotEmpty(afterSchedule) && afterSchedule.size() > 1) {
                  //更新合同下个阶段
                  contract.setNextScheduleName(afterSchedule.get(0).getStageName());
                  contractMapper.updateById(contract);
               }
               if (ArrayUtil.isEmpty(afterSchedule.toArray())) {
               if (CollUtil.isEmpty(afterSchedule)) {
//                  schedule.setEffectiveEndDate(contract.getExpirationDate());
//                  scheduleMapper.updateById(schedule);
                  //更新合同下个阶段
@@ -460,7 +461,7 @@
   @Override
   public R addContractOut(OutBoundAddDTO addDTO) {
      if (ArrayUtil.isEmpty(addDTO.getSubjectMatterList().toArray())) {
      if (CollUtil.isEmpty(addDTO.getSubjectMatterList())) {
         return R.failed("出库标的物不能为空");
      }
      // 1. 确定查询用的合同编号字段值
@@ -486,6 +487,10 @@
      if (ObjUtil.isNull(contract)) {
         return R.failed("合同信息查询失败");
      }
      if (addDTO.getSubjectMatterList().stream().allMatch(item->item.getOutBoundNum().compareTo(new BigDecimal("0"))==0)){
         return R.failed("出库数量不能都为为0");
      }
      addDTO.setSubjectMatterList(addDTO.getSubjectMatterList().stream().filter(item->item.getOutBoundNum().compareTo(new BigDecimal("0"))>0).collect(Collectors.toList()));
      //出库数量校验
      for (OutSubjectMatterAddDTO outSubjectMatterAddDTO:   addDTO.getSubjectMatterList()) {
         ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery()
@@ -495,9 +500,6 @@
               .last("limit 1"));
         if (ObjUtil.isNull(subjectMatter)){
            continue;
         }
         if (outSubjectMatterAddDTO.getOutBoundNum().compareTo(new BigDecimal("0"))==0){
            return R.failed(outSubjectMatterAddDTO.getSubjectMatterCode()+"出库数量不能为0");
         }
         if (subjectMatter.getDeliveryStatus()==0){
            if (outSubjectMatterAddDTO.getOutBoundNum().compareTo(subjectMatter.getQuantity())>0){
@@ -644,7 +646,7 @@
               //客户付款完成合同
               List<Contract> customerCompleteContractList = contractMapper.selectList(Wrappers.<Contract>lambdaQuery().eq(Contract::getPartyAId, contract.getPartyAId())
                     .eq(Contract::getPartyBId, SecurityUtils.getUser().getCompId()).apply(" amount = paid_amount"));
               if (ArrayUtil.isNotEmpty(customerCompleteContractList)) {
               if (CollUtil.isNotEmpty(customerCompleteContractList)) {
                  List<BigDecimal> outAmountList = new ArrayList<>();
                  for (Contract completeContract : customerCompleteContractList
                  ) {
@@ -663,7 +665,7 @@
                        outAmountList.add(outConfirm.getTransationAmount());
                     }
                  }
                  if (ArrayUtil.isNotEmpty(outAmountList.toArray())) {
                  if (CollUtil.isNotEmpty(outAmountList)) {
                     BigDecimal currentInSum = outAmountList.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
                     //新增当前合同 资金转入
                     PaymentConfirm inConfirm = BeanUtil.copyProperties(paymentConfirm, PaymentConfirm.class, "id", "transationAmount",
@@ -711,14 +713,13 @@
         List<ContractPaymentSchedule> afterSchedule = scheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery()
               .eq(ContractPaymentSchedule::getContractId, schedule.getContractId())
               .gt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder())
               .gt(ContractPaymentSchedule::getPaymentRatio, 0)
               .orderByAsc(ContractPaymentSchedule::getCreateTime));
         if (ArrayUtil.isNotEmpty(afterSchedule.toArray())&&contract.getOutBoundAmout().compareTo(contract.getAmount())==0) {
         if (CollUtil.isNotEmpty(afterSchedule)&&contract.getOutBoundAmout().compareTo(contract.getAmount())==0) {
            contract.setNextScheduleName(afterSchedule.get(0).getStageName());
            contractMapper.updateById(contract);
         }
         if (ArrayUtil.isEmpty(afterSchedule.toArray())) {
         if (CollUtil.isEmpty(afterSchedule)) {
            schedule.setEffectiveEndDate(contract.getExpirationDate());
            scheduleMapper.updateById(schedule);
            //更新合同下个阶段
@@ -833,12 +834,12 @@
   @Override
   public R delOutBound(String batchNumber) {
      List<OutBound> outBoundList = baseMapper.selectList(Wrappers.<OutBound>lambdaQuery().eq(OutBound::getBatchNumber,batchNumber));
      if (ArrayUtil.isEmpty(outBoundList)){
      if (CollUtil.isEmpty(outBoundList)){
         return R.failed("出库信息异常,请联系营销系统管理人员");
      }
      List<ContractOutBound> contractOutBoundList = contractOutBoundMapper.selectList(Wrappers.<ContractOutBound>lambdaQuery()
            .in(ContractOutBound::getOutBoundId,outBoundList.stream().map(OutBound::getId).collect(Collectors.toList())));
      if (ArrayUtil.isEmpty(contractOutBoundList)){
      if (CollUtil.isEmpty(contractOutBoundList)){
         return R.failed("出库信息异常,请联系营销系统管理人员");
      }
      boolean allZero = true;