shiyunteng
2026-09-18 c5c284896ce6428cffc5092e9cdef4fefc23409f
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractInvoiceServiceImpl.java
@@ -229,6 +229,24 @@
            if (ObjUtil.isNotNull(subjectMatter)) {
               advanceAmount = advanceAmount.add(contractOutBoundInvoiceVo.getInvoiceNum().multiply(subjectMatter.getUnitPrice()));
            }
            List<String> smjList = new ArrayList<>();
            smjList.add(smj);
            smjList.add(smjsc);
            smjList.add(smjzt);
            if (("" + SecurityUtils.getUser().getCompId()).equals(smj) || ("" + SecurityUtils.getUser().getCompId()).equals(smjsc) ||
                  ("" + SecurityUtils.getUser().getCompId()).equals(smjzt)) {
               Product product = productMapper.selectOne(Wrappers.<Product>lambdaQuery().eq(Product::getErpCode, subjectMatter.getMaterialCode())
                     .in(Product::getCompId, smjList).last("limit 1"));
               if (ObjUtil.isNull(product) || StrUtil.isBlank(product.getTaxClass()) || StrUtil.isBlank(product.getTaxCode())) {
                  return R.failed("请在产品信息中补充税收分类信息");
               }
            } else {
               Product product = productMapper.selectOne(Wrappers.<Product>lambdaQuery().eq(Product::getErpCode, subjectMatter.getMaterialCode())
                     .eq(Product::getCompId, SecurityUtils.getUser().getCompId()).last("limit 1"));
               if (ObjUtil.isNull(product) || StrUtil.isBlank(product.getTaxClass()) || StrUtil.isBlank(product.getTaxCode())) {
                  return R.failed("请在产品信息中补充税收分类信息");
               }
            }
         }
         log.info("advanceAmount:{}", advanceAmount);
         log.info("schedule.getPlannedAmount:{}", schedule.getPlannedAmount());
@@ -260,6 +278,28 @@
      BusinessCustomer customer = businessCustomerMapper.selectById(contract.getPartyAId());
      if (ObjUtil.isNull(customer)) {
         return R.failed("获取购方单位异常");
      }
      for (ContractOutBoundInvoiceVo contractOutBoundInvoiceVo : genInvoiceInfoDTO.getOutBoundInvoiceList()) {
         ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
         List<String> smjList = new ArrayList<>();
         smjList.add(smj);
         smjList.add(smjsc);
         smjList.add(smjzt);
         if (("" + SecurityUtils.getUser().getCompId()).equals(smj) || ("" + SecurityUtils.getUser().getCompId()).equals(smjsc) ||
               ("" + SecurityUtils.getUser().getCompId()).equals(smjzt)) {
            Product product = productMapper.selectOne(Wrappers.<Product>lambdaQuery().eq(Product::getErpCode, contractOutBound.getSubjectMatterCode())
                  .in(Product::getCompId, smjList).last("limit 1"));
            if (ObjUtil.isNull(product) || StrUtil.isBlank(product.getTaxClass()) || StrUtil.isBlank(product.getTaxCode())) {
               return R.failed("请在产品信息中补充税收分类信息");
            }
         } else {
            Product product = productMapper.selectOne(Wrappers.<Product>lambdaQuery().eq(Product::getErpCode, contractOutBound.getSubjectMatterCode())
                  .eq(Product::getCompId, SecurityUtils.getUser().getCompId()).last("limit 1"));
            if (ObjUtil.isNull(product) || StrUtil.isBlank(product.getTaxClass()) || StrUtil.isBlank(product.getTaxCode())) {
               return R.failed("请在产品信息中补充税收分类信息");
            }
         }
      }
      //机动车开票
      if (StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(), "4")) {
@@ -300,7 +340,28 @@
      if (ObjUtil.isNull(customer)) {
         return R.failed("获取购方单位异常");
      }
      for (ContractOutBoundInvoiceVo contractOutBoundInvoiceVo : mergeInvoiceDTO.getOutBoundInvoiceList()) {
         ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId());
         List<String> smjList = new ArrayList<>();
         smjList.add(smj);
         smjList.add(smjsc);
         smjList.add(smjzt);
         if (("" + SecurityUtils.getUser().getCompId()).equals(smj) || ("" + SecurityUtils.getUser().getCompId()).equals(smjsc) ||
               ("" + SecurityUtils.getUser().getCompId()).equals(smjzt)) {
            Product product = productMapper.selectOne(Wrappers.<Product>lambdaQuery().eq(Product::getErpCode, contractOutBound.getSubjectMatterCode())
                  .in(Product::getCompId, smjList).last("limit 1"));
            if (ObjUtil.isNull(product) || StrUtil.isBlank(product.getTaxClass()) || StrUtil.isBlank(product.getTaxCode())) {
               return R.failed("请在产品信息中补充税收分类信息");
            }
         } else {
            Product product = productMapper.selectOne(Wrappers.<Product>lambdaQuery().eq(Product::getErpCode, contractOutBound.getSubjectMatterCode())
                  .eq(Product::getCompId, SecurityUtils.getUser().getCompId()).last("limit 1"));
            if (ObjUtil.isNull(product) || StrUtil.isBlank(product.getTaxClass()) || StrUtil.isBlank(product.getTaxCode())) {
               return R.failed("请在产品信息中补充税收分类信息");
            }
         }
      }
      GenInvoiceInfoVo vo = genMergeInvoiceVo(mergeInvoiceDTO, customer, b);
      vo = transBipVo(vo, b, customer);
      return R.ok(vo);
@@ -532,7 +593,7 @@
      List<InvoiceItemVo> invoiceItemVoList = new ArrayList<>();
      List<String> erpCode = new ArrayList<>();
      List<ContractOutBoundMergeVo> mergeOutBounds = new ArrayList<>();
      if (genInvoiceInfoDTO.getInvoiceType().equals("3")){
      if (genInvoiceInfoDTO.getInvoiceType().equals("3")) {
         String[] vehiclenNoList = genInvoiceInfoDTO.getVehicleNo().split(",");
         for (int i = 0; i < vehiclenNoList.length; i++) {
            ContractOutBound contractOutBound = contractOutBoundMapper.selectById(genInvoiceInfoDTO.getOutBoundInvoiceList().get(0).getContractOutBoundId());
@@ -856,7 +917,7 @@
         }
         GenInvoiceInfoVo vo = BeanUtil.copyProperties(toInvoiceDTO, GenInvoiceInfoVo.class);
         //发票保存
         ContractInvoice invoice = saveContractInvoice(vo, contract, toInvoiceDTO.getOutBoundInvoiceList(), DateUtil.current() + "", "1",null);
         ContractInvoice invoice = saveContractInvoice(vo, contract, toInvoiceDTO.getOutBoundInvoiceList(), DateUtil.current() + "", "1", null);
         //启动流程
         ProcessInstanceParamDto dto = new ProcessInstanceParamDto();
         Map<String, Object> map = BeanUtil.beanToMap(invoice);
@@ -876,7 +937,7 @@
      }
      GenInvoiceInfoVo vo = BeanUtil.copyProperties(toInvoiceDTO, GenInvoiceInfoVo.class);
      //发票保存
      ContractInvoice invoice = saveContractInvoice(vo, contract, toInvoiceDTO.getOutBoundInvoiceList(), DateUtil.current() + "", "0",null);
      ContractInvoice invoice = saveContractInvoice(vo, contract, toInvoiceDTO.getOutBoundInvoiceList(), DateUtil.current() + "", "0", null);
      //启动流程
      ProcessInstanceParamDto dto = new ProcessInstanceParamDto();
      Map<String, Object> map = BeanUtil.beanToMap(invoice);
@@ -1036,7 +1097,7 @@
      List<ContractInvoice> invoiceList = baseMapper.selectList(Wrappers.<ContractInvoice>lambdaQuery()
            .eq(ContractInvoice::getContractId, contractId)
            .or()
            .like(ContractInvoice::getContractIds,contractId)
            .like(ContractInvoice::getContractIds, contractId)
            .orderByDesc(ContractInvoice::getCreateTime));
      return R.ok(invoiceList);
   }
@@ -1047,10 +1108,10 @@
      blueInvoice.setRedReversal("2");
      baseMapper.updateById(blueInvoice);
      ContractInvoice invoice = new ContractInvoice();
      if (!blueInvoice.getIsMerge()){
      if (!blueInvoice.getIsMerge()) {
         invoice.setContractId(blueInvoice.getContractId());
      }
      if (blueInvoice.getIsMerge()){
      if (blueInvoice.getIsMerge()) {
         invoice.setContractIds(blueInvoice.getContractIds());
         invoice.setIsMerge(true);
      }
@@ -1091,7 +1152,7 @@
      ProcessInstanceParamDto dto = new ProcessInstanceParamDto();
      Map<String, Object> map = BeanUtil.beanToMap(invoice);
      dto.setParamMap(map);
      if (!blueInvoice.getIsMerge()){
      if (!blueInvoice.getIsMerge()) {
         Contract contract = contractMapper.selectById(blueInvoice.getContractId());
         if (StrUtil.equals(contract.getContractCategory(), "water_house")) {
            map.put("contractCategory", "water_house");
@@ -1141,7 +1202,7 @@
//         invoiceDetail.put("goodsPrice", invoiceItemVo.getUnitPrice());
         invoiceDetail.put("goodsTotalPrice", invoiceItemVo.getPriceNoTax());
         invoiceDetail.put("goodsTotalTax", invoiceItemVo.getPriceTax());
         if (StrUtil.isNotBlank(vo.getInvoiceVehicleType())&&(vo.getInvoiceVehicleType().equals("3") || vo.getInvoiceVehicleType().equals("4"))) {
         if (StrUtil.isNotBlank(vo.getInvoiceVehicleType()) && (vo.getInvoiceVehicleType().equals("3") || vo.getInvoiceVehicleType().equals("4"))) {
            invoiceDetail.put("goodsSpecification", invoiceItemVo.getSpecification());
         }
         invoiceDetailsList.add(invoiceDetail);
@@ -1422,15 +1483,18 @@
         item.put("taxRate", invoiceItemVo.getTaxRate());
         item.put("oriTaxAmount", invoiceItemVo.getPriceTax());
         item.put("oriTaxIncludedAmount", invoiceItemVo.getPriceAndTax());
         item.put("remarks", invoiceItemVo.getZy());//摘要
         item.put("_status", "Insert");
         JSONObject freeChId = new JSONObject();
         freeChId.put("GX08", invoiceItemVo.getHsdy());//核算单元
         freeChId.put("YSYF14", "2");//款项类型 1 预收款 2 应收款
         freeChId.put("YSYF31", invoiceItemVo.getSfjs());//是否计税
         freeChId.put("JT04", invoiceItemVo.getHsjylx());//核算交易类型 0101 集团外部 01020301 三级分子公司间 01020302 三级分公司与子子公司之间
         freeChId.put("JT06", invoiceItemVo.getKxmx());//款项明细
         freeChId.put("JT32", invoiceItemVo.getZyys());//作业要素
         freeChId.put("zzbkfl", invoiceItemVo.getBkfl());//板块分类
         freeChId.put("JT12", invoiceItemVo.getCpwlfl());//产品物料分类
         item.put("freeChId", freeChId);
         bodyItem.add(item);
      }
@@ -1547,7 +1611,7 @@
      //蓝票
      if (invoice.getInvoiceCategory().equals("1")) {
         // TODO 开蓝票接口机动车销售
         if (StrUtil.equals(vo.getInvoiceVehicleType(), "4")&&bwFlag) {
         if (StrUtil.equals(vo.getInvoiceVehicleType(), "4") && bwFlag) {
            JSONObject request = genBlueInvoiceVehicle(vo, invoice.getSerialNo(), dept);
            String requestId = IdUtil.fastUUID();
            invoice.setBwRequestId(requestId);
@@ -1573,7 +1637,7 @@
         }
         // TODO 开蓝票接口机动车专用
         if (StrUtil.equals(vo.getInvoiceVehicleType(), "3")&&bwFlag) {
         if (StrUtil.equals(vo.getInvoiceVehicleType(), "3") && bwFlag) {
            JSONObject request = genBlueInvoiceVehiclePre(vo, invoice.getSerialNo(), dept);
            String requestId = IdUtil.fastUUID();
            invoice.setBwRequestId(requestId);
@@ -1599,7 +1663,7 @@
         }
         // TODO 开蓝票接口 非机动车
         if (!StrUtil.equals(vo.getInvoiceVehicleType(), "3") && !StrUtil.equals(vo.getInvoiceVehicleType(), "4")&&bwFlag) {
         if (!StrUtil.equals(vo.getInvoiceVehicleType(), "3") && !StrUtil.equals(vo.getInvoiceVehicleType(), "4") && bwFlag) {
            JSONObject request = genBlueInvoice(vo, invoice.getSerialNo(), dept);
            String requestId = IdUtil.fastUUID();
            invoice.setBwRequestId(requestId);
@@ -1833,7 +1897,7 @@
                  });
               }
            }
         }else {
         } else {
            blueInvoice.setRedReversal("1");
            baseMapper.updateById(blueInvoice);
            //合并开票
@@ -1848,18 +1912,18 @@
                     for (ContractOutBoundInvoiceVo outBoundInvoiceVo : vo.getOutBoundInvoiceList()) {
                        BigDecimal contractBillAmount = new BigDecimal("0");
                        if (CollUtil.isNotEmpty(vo.getOutBoundInvoiceList())) {
                              ContractOutBound contractOutBound = contractOutBoundMapper.selectById(outBoundInvoiceVo.getContractOutBoundId());
                              if (ObjUtil.isNotNull(contractOutBound) && contractOutBound.getContractId().equals(contract.getId())) {
                                 ContractSubjectMatter subjectMatter = subjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery()
                                       .eq(ContractSubjectMatter::getMaterialCode, contractOutBound.getSubjectMatterCode())
                                       .eq(StrUtil.isNotBlank(contractOutBound.getLineNo()), ContractSubjectMatter::getLineNo, contractOutBound.getLineNo())
                                       .eq(ContractSubjectMatter::getContractId, contract.getId()).last("limit 1"));
                                 if (ObjUtil.isNotNull(subjectMatter) && ObjUtil.isNotNull(subjectMatter.getUnitPrice())) {
                                    contractBillAmount = contractBillAmount.add(outBoundInvoiceVo.getInvoiceNum().multiply(subjectMatter.getUnitPrice()));
                                 }
                                 contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().subtract(outBoundInvoiceVo.getInvoiceNum()));
                                 contractOutBoundMapper.updateById(contractOutBound);
                           ContractOutBound contractOutBound = contractOutBoundMapper.selectById(outBoundInvoiceVo.getContractOutBoundId());
                           if (ObjUtil.isNotNull(contractOutBound) && contractOutBound.getContractId().equals(contract.getId())) {
                              ContractSubjectMatter subjectMatter = subjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery()
                                    .eq(ContractSubjectMatter::getMaterialCode, contractOutBound.getSubjectMatterCode())
                                    .eq(StrUtil.isNotBlank(contractOutBound.getLineNo()), ContractSubjectMatter::getLineNo, contractOutBound.getLineNo())
                                    .eq(ContractSubjectMatter::getContractId, contract.getId()).last("limit 1"));
                              if (ObjUtil.isNotNull(subjectMatter) && ObjUtil.isNotNull(subjectMatter.getUnitPrice())) {
                                 contractBillAmount = contractBillAmount.add(outBoundInvoiceVo.getInvoiceNum().multiply(subjectMatter.getUnitPrice()));
                              }
                              contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().subtract(outBoundInvoiceVo.getInvoiceNum()));
                              contractOutBoundMapper.updateById(contractOutBound);
                           }
                        }
                        //更新合同开票状态 前提出库完成
                        contract.setBillingStatus("2");
@@ -2160,7 +2224,7 @@
            baseMapper.updateById(contractInvoice);
            return R.ok();
         }
         return R.failed(resultJson, "应收发票集成失败");
         return R.failed(result);
      }
      //红票
      if (StrUtil.equals(contractInvoice.getInvoiceCategory(), "2")) {
@@ -2179,7 +2243,7 @@
            baseMapper.updateById(contractInvoice);
            return R.ok();
         }
         return R.failed(resultJson, "应收发票删除失败");
         return R.failed(result);
      }
      return R.ok();
   }