shiyunteng
8 小时以前 2db76f2066701cbe292f206ad49a7f8523b8aa9f
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractServiceImpl.java
@@ -1,6 +1,7 @@
package com.by4cloud.platformx.business.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
@@ -54,6 +55,8 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
;
/**
 * @author cd
 * @description
@@ -80,6 +83,7 @@
   private final PaymentSlipMapper paymentSlipMapper;
   private final ContractInvoiceMapper contractInvoiceMapper;
   private final StringRedisTemplate redisTemplate;
   private final ContractOutBoundMapper contractOutBoundMapper;
   @Value("${erp.ymj}")
   private String ymjErp;
@@ -155,7 +159,7 @@
         }
      }
      if (ArrayUtil.isEmpty(addDTO.getContractSubjectMatter().toArray())){
      if (CollUtil.isEmpty(addDTO.getContractSubjectMatter())){
         return R.failed("标的物不能为空");
      }
@@ -183,7 +187,7 @@
      }
      baseMapper.insert(contract);
      if (ArrayUtil.isNotEmpty(addDTO.getContractSubjectMatter())) {
      if (CollUtil.isNotEmpty(addDTO.getContractSubjectMatter())) {
         addDTO.getContractSubjectMatter().stream().forEach(contractSubjectMatterAddDTO -> {
            ContractSubjectMatter subjectMatter = BeanUtil.copyProperties(contractSubjectMatterAddDTO, ContractSubjectMatter.class);
            subjectMatter.setContractId(contract.getId());
@@ -214,7 +218,7 @@
      }
      if (ArrayUtil.isNotEmpty(addDTO.getContractPaymentSchedule())) {
      if (CollUtil.isNotEmpty(addDTO.getContractPaymentSchedule())) {
         AtomicInteger index = new AtomicInteger(1);
         addDTO.getContractPaymentSchedule().stream().forEach(contractPaymentScheduleAddDTO -> {
            int currentIndex = index.getAndIncrement();
@@ -323,7 +327,7 @@
      }
      baseMapper.updateById(contract);
      if (ArrayUtil.isNotEmpty(updateDTO.getContractSubjectMatter())) {
      if (CollUtil.isNotEmpty(updateDTO.getContractSubjectMatter())) {
         contractSubjectMatterMapper.delete(Wrappers.<ContractSubjectMatter>lambdaQuery().eq(ContractSubjectMatter::getContractId, contract.getId()));
         updateDTO.getContractSubjectMatter().stream().forEach(contractSubjectMatterAddDTO -> {
@@ -350,7 +354,7 @@
         });
      }
      if (ArrayUtil.isNotEmpty(updateDTO.getContractPaymentSchedule())) {
      if (CollUtil.isNotEmpty(updateDTO.getContractPaymentSchedule())) {
         contractPaymentScheduleMapper.delete(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, contract.getId()));
         AtomicInteger index = new AtomicInteger(1);
@@ -398,6 +402,21 @@
      if (ObjUtil.isNotNull(a)){
         detailVo.setPartyAOrgCode(a.getCreditCode());
      }
      List<ContractOutBound> outBoundList = contractOutBoundMapper.selectList(Wrappers.<ContractOutBound>lambdaQuery()
            .eq(ContractOutBound::getContractId,id).orderByAsc(ContractOutBound::getOutBoundTime));
      if (CollUtil.isNotEmpty(outBoundList)){
         detailVo.setContractOutBound(outBoundList);
      }
      List<ContractInvoice> invoiceList = contractInvoiceMapper.selectList(Wrappers.<ContractInvoice>lambdaQuery()
            .eq(ContractInvoice::getContractId,id).orderByAsc(ContractInvoice::getCreateTime));
      if (CollUtil.isNotEmpty(invoiceList)){
         detailVo.setContractInvoice(invoiceList);
      }
      List<PaymentSlip> slipList = paymentSlipMapper.selectList(Wrappers.<PaymentSlip>lambdaQuery()
            .eq(PaymentSlip::getContractId,id).orderByAsc(PaymentSlip::getPaymentTime));
      if (CollUtil.isNotEmpty(slipList)){
         detailVo.setPaymentSlip(slipList);
      }
      return detailVo;
   }
@@ -426,7 +445,7 @@
      List<ContractSubjectMatter> subjectMatterList = contractSubjectMatterMapper.selectList(Wrappers.<ContractSubjectMatter>lambdaQuery()
            .eq(ContractSubjectMatter::getContractId,id));
      if (StrUtil.isNotEmpty(contract.getContractCategory()) && StrUtil.equals(contract.getContractCategory(), "water_house")) {
         if (ArrayUtil.isNotEmpty(subjectMatterList.toArray())) {
         if (CollUtil.isNotEmpty(subjectMatterList)) {
            for (ContractSubjectMatter contractSubjectMatter: subjectMatterList)  {
               if (StrUtil.equals(contract.getExecFrequency(), "1")) {
                  Long weeksTrue = DateUtil.betweenWeek(DateUtil.beginOfWeek(contract.getEffectiveDate()),
@@ -576,7 +595,7 @@
               .eq(ContractPaymentSchedule::getContractId, fitstSchedule.getContractId())
               .gt(ContractPaymentSchedule::getStageOrder, fitstSchedule.getStageOrder())
               .orderByAsc(ContractPaymentSchedule::getCreateTime));
         if (ArrayUtil.isNotEmpty(afterSchedule.toArray()) && afterSchedule.size() == 1) {
         if (ArrayUtil.isNotEmpty(afterSchedule) && afterSchedule.size() == 1) {
            //最后阶段生效时间
            ContractPaymentSchedule endSchedule = afterSchedule.get(0);
            if (StrUtil.equals(endSchedule.getStageName(), "质保金")) {
@@ -610,7 +629,7 @@
            contract.setNextScheduleName(endSchedule.getStageName());
            baseMapper.updateById(contract);
         }
         if (ArrayUtil.isNotEmpty(afterSchedule.toArray()) && afterSchedule.size() > 1) {
         if (ArrayUtil.isNotEmpty(afterSchedule) && afterSchedule.size() > 1) {
            //第一阶段生效时间
//         fitstSchedule.setEffectiveEndDate(DateUtil.offsetDay(contract.getSignDate(),fitstSchedule.getAgreedDays()));
//         contractPaymentScheduleMapper.updateById(fitstSchedule);
@@ -619,7 +638,7 @@
            baseMapper.updateById(contract);
         }
         //只有当前合同签字阶段
//      if(ArrayUtil.isEmpty(afterSchedule.toArray())){
//      if(ArrayUtil.isEmpty(afterSchedule)){
//         fitstSchedule.setEffectiveEndDate(DateUtil.offsetDay(contract.getSignDate(),fitstSchedule.getAgreedDays()));
//         contractPaymentScheduleMapper.updateById(fitstSchedule);
//      }
@@ -641,7 +660,7 @@
               request.put("moneySum",contract.getAmount());
               request.put("signManner","面签");
               request.put("salesman","");
               if (ArrayUtil.isNotEmpty(subjectMatterList.toArray())){
               if (ArrayUtil.isNotEmpty(subjectMatterList)){
                  JSONArray subjectMatter = new JSONArray();
                  subjectMatterList.stream().forEach(contractSubjectMatter -> {
                     JSONObject subjectMatterItem = new JSONObject();
@@ -834,7 +853,7 @@
               outAmountList.add(outConfirm.getTransationAmount());
            }
         }
         if (ArrayUtil.isNotEmpty(outAmountList.toArray())) {
         if (ArrayUtil.isNotEmpty(outAmountList)) {
            BigDecimal currentInSum = outAmountList.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
            //新增当前合同 资金转入
            PaymentConfirm inConfirm = BeanUtil.copyProperties(paymentConfirm, PaymentConfirm.class, "id", "transationAmount",
@@ -870,7 +889,7 @@
            .lt(ContractPaymentSchedule::getEffectiveEndDate, DateUtil.today())
            .ne(ContractPaymentSchedule::getPaymentStatus, "2")
            .ne(ContractPaymentSchedule::getPaymentStatus, 3));
      if (ArrayUtil.isNotEmpty(scheduleList.toArray())) {
      if (ArrayUtil.isNotEmpty(scheduleList)) {
         scheduleList.stream().forEach(contractPaymentSchedule -> {
            Contract contract = baseMapper.selectById(contractPaymentSchedule.getContractId());
            if (ObjUtil.isNotNull(contract)) {
@@ -1077,7 +1096,7 @@
   public R genCycleReceiced() {
      List<ContractExecDate> execDateList = contractExecDateMapper.selectList(Wrappers.<ContractExecDate>lambdaQuery()
            .le(ContractExecDate::getExecDate, DateUtil.today()).eq(ContractExecDate::getGenFlag,"0"));
      if (ArrayUtil.isNotEmpty(execDateList.toArray())) {
      if (ArrayUtil.isNotEmpty(execDateList)) {
         execDateList.stream().forEach(contractExecDate -> {
            Contract contract = baseMapper.selectById(contractExecDate.getContractId());
            ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery()
@@ -1587,10 +1606,10 @@
   @Override
   public R addContractSgb(ContractAddDTO addDTO) {
      if (ArrayUtil.isEmpty(addDTO.getContractSubjectMatter().toArray())){
      if (ArrayUtil.isEmpty(addDTO.getContractSubjectMatter())){
         return R.failed("请添加标的物");
      }
      if (ArrayUtil.isEmpty(addDTO.getContractPaymentSchedule().toArray())){
      if (ArrayUtil.isEmpty(addDTO.getContractPaymentSchedule())){
         return R.failed("请添加付款阶段或付款阶段缺少");
      }
      if (!isValidPaymentStages(addDTO.getContractPaymentSchedule())){
@@ -1710,10 +1729,10 @@
   @Override
   public R updateContractSgb(ContractUpdateDTO updateDTO) {
      if (ArrayUtil.isEmpty(updateDTO.getContractSubjectMatter().toArray())){
      if (ArrayUtil.isEmpty(updateDTO.getContractSubjectMatter())){
         return R.failed("请添加标的物");
      }
      if (ArrayUtil.isEmpty(updateDTO.getContractPaymentSchedule().toArray())){
      if (ArrayUtil.isEmpty(updateDTO.getContractPaymentSchedule())){
         return R.failed("请添加付款阶段或付款阶段缺少");
      }
      if (!isValidPaymentStages(updateDTO.getContractPaymentSchedule())){
@@ -1964,20 +1983,22 @@
   @Override
   public Page fourAssociation(Page page,ContractQueryDTO queryDTO) {
      Page<FourAssociationPageVo> page1 = baseMapper.fourAssociation(page,queryDTO,DataScope.of("comp_id"));
      if (ArrayUtil.isNotEmpty(page1.getRecords().toArray())){
      if (ArrayUtil.isNotEmpty(page1.getRecords())){
         page1.getRecords().stream().forEach(fourAssociationPageVo -> {
            List<PaymentSlip> slips = paymentSlipMapper.selectList(Wrappers.<PaymentSlip>lambdaQuery().eq(PaymentSlip::getContractId,fourAssociationPageVo.getId())
                  .orderByAsc(PaymentSlip::getPaymentTime));
            if (ArrayUtil.isNotEmpty(slips.toArray())){
            if (ArrayUtil.isNotEmpty(slips)){
               fourAssociationPageVo.setSlipVoList(BeanUtil.copyToList(slips,ContractSlipVo.class));
            }
            List<ContractInvoice> invoices = contractInvoiceMapper.selectList(Wrappers.<ContractInvoice>lambdaQuery().eq(ContractInvoice::getContractId,fourAssociationPageVo.getId())
                  .orderByAsc(ContractInvoice::getInvoiceTime));
            if (ArrayUtil.isNotEmpty(invoices.toArray())){
            if (ArrayUtil.isNotEmpty(invoices)){
               fourAssociationPageVo.setInvoiceVoList(BeanUtil.copyToList(invoices, ContractInvoiceVo.class));
            }
            if (fourAssociationPageVo.getAmount().compareTo(fourAssociationPageVo.getPaidAmount())==0&&
                  fourAssociationPageVo.getAmount().compareTo(fourAssociationPageVo.getBillingAmout())==0){
                  fourAssociationPageVo.getAmount().compareTo(fourAssociationPageVo.getBillingAmout())==0&&
               ArrayUtil.isNotEmpty(slips)&&ArrayUtil.isNotEmpty(invoices)
            ){
               fourAssociationPageVo.setAssociation("已完成");
            }
         });