shiyunteng
昨天 fca21683e1b5b906d2514082ddfbae8eb820c9ea
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractPaymentScheduleProcessServiceImpl.java
@@ -8,14 +8,8 @@
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.by4cloud.platformx.business.dto.ContractPaymentScheduleProcessAddDTO;
import com.by4cloud.platformx.business.entity.Contract;
import com.by4cloud.platformx.business.entity.ContractPaymentSchedule;
import com.by4cloud.platformx.business.entity.ContractPaymentScheduleProcess;
import com.by4cloud.platformx.business.entity.PaymentConfirm;
import com.by4cloud.platformx.business.mapper.ContractMapper;
import com.by4cloud.platformx.business.mapper.ContractPaymentScheduleMapper;
import com.by4cloud.platformx.business.mapper.ContractPaymentScheduleProcessMapper;
import com.by4cloud.platformx.business.mapper.PaymentConfirmMapper;
import com.by4cloud.platformx.business.entity.*;
import com.by4cloud.platformx.business.mapper.*;
import com.by4cloud.platformx.business.service.ContractPaymentScheduleProcessService;
import com.by4cloud.platformx.business.vo.ContractPaymentScheduleVo;
import com.by4cloud.platformx.business.vo.ScheduleProcessVo;
@@ -41,6 +35,7 @@
   private final ContractPaymentScheduleMapper contractPaymentScheduleMapper;
   private final ContractPaymentScheduleProcessMapper processMapper;
   private final ContractMapper contractMapper;
   private final ContractSubjectMatterMapper subjectMatterMapper;
   private final PaymentConfirmMapper paymentConfirmMapper;
   @Override
@@ -51,6 +46,13 @@
      }
      //合同
      Contract contract = contractMapper.selectById(schedule.getContractId());
      List<ContractSubjectMatter> subjectMatterList = subjectMatterMapper.selectList(Wrappers.<ContractSubjectMatter>lambdaQuery().eq(ContractSubjectMatter::getContractId,contract.getId()));
      if (ArrayUtil.isEmpty(subjectMatterList.toArray())){
         return R.failed("该合同标的物异常,请联系技术人员");
      }
      if (!subjectMatterList.stream().allMatch(item->item.getDeliveryStatus()==2)){
         return R.failed("出库数量小于当前合同标的物数量,无法进行当前操作");
      }
      //新增当前阶段应收
      PaymentConfirm currentConfim = new PaymentConfirm();
      currentConfim.setBusinessType(schedule.getStageName()+"应收");
@@ -88,7 +90,7 @@
      ContractPaymentSchedule beforeSchedule = contractPaymentScheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, schedule.getContractId())
            .lt(ContractPaymentSchedule::getStageOrder, schedule.getStageOrder()).orderByDesc(ContractPaymentSchedule::getCreateTime).last("limit 1"));
      if (ObjUtil.isNotNull(beforeSchedule)){
         beforeSchedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getProcessDate(),beforeSchedule.getAgreedDays()));
         beforeSchedule.setEffectiveEndDate(schedule.getEffectiveDate());
         contractPaymentScheduleMapper.updateById(beforeSchedule);
         //之前阶段是否收款完成
//         if (beforeSchedule.getPaymentStatus()!=2){
@@ -166,6 +168,14 @@
         //更新合同下个阶段
         contract.setNextScheduleName("无");
         contractMapper.updateById(contract);
         //当前为合同最后阶段
         PaymentConfirm lastNewConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId,contract.getId())
               .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1"));
         if (lastNewConfirm.getTotalAmount().compareTo(new BigDecimal("0"))>=0){
            //有预付且超过应收 关闭合同状态
            contract.setContractStatus(3);
            contractMapper.updateById(contract);
         }
      }
      return R.ok();
   }
@@ -176,20 +186,13 @@
            .select(ContractPaymentSchedule::getId,ContractPaymentSchedule::getStageName,ContractPaymentSchedule::getEffectiveDate,
                  ContractPaymentSchedule::getPlannedAmount,ContractPaymentSchedule::getPlannedAmount,
                  ContractPaymentSchedule::getEffectiveEndDate,ContractPaymentSchedule::getPaymentDate,
                  ContractPaymentSchedule::getPaymentStatus,ContractPaymentSchedule::getActualAmount)
                  ContractPaymentSchedule::getPaymentStatus,ContractPaymentSchedule::getActualAmount,
                  ContractPaymentSchedule::getAgreedDays)
            .select(ContractPaymentScheduleProcess::getProcessDate)
            .leftJoin(ContractPaymentScheduleProcess.class,ContractPaymentScheduleProcess::getScheduleId,ContractPaymentSchedule::getId)
            .eq(ContractPaymentSchedule::getContractId,id)
            .orderByAsc(ContractPaymentSchedule::getCreateTime);
      List<ContractPaymentScheduleVo> scheduleVoList = contractPaymentScheduleMapper.selectJoinList(ContractPaymentScheduleVo.class,wrapper);
      if (ArrayUtil.isEmpty(scheduleVoList.toArray())){
         scheduleVoList.stream().forEach(contractPaymentScheduleVo -> {
            List<ContractPaymentScheduleProcess> paymentScheduleProcessList = processMapper.selectList(Wrappers.<ContractPaymentScheduleProcess>lambdaQuery()
                  .eq(ContractPaymentScheduleProcess::getContractId,contractPaymentScheduleVo.getId())
                  .orderByAsc(ContractPaymentScheduleProcess::getCreateTime));
            if (ArrayUtil.isNotEmpty(paymentScheduleProcessList.toArray())){
               contractPaymentScheduleVo.setProcessVoList(BeanUtil.copyToList(paymentScheduleProcessList, ScheduleProcessVo.class));
            }
         });
      }
      return R.ok(scheduleVoList);
   }
}