platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractInvoiceServiceImpl.java
@@ -239,13 +239,13 @@
               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("请在产品信息中补充税收分类信息");
                  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("请在产品信息中补充税收分类信息");
                  return R.failed("请检查产品编码是否存在或请在产品信息中补充税收分类信息");
               }
            }
         }
@@ -289,13 +289,13 @@
            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("请在产品信息中补充税收分类信息");
               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("请在产品信息中补充税收分类信息");
               return R.failed("请检查产品编码是否存在或请在产品信息中补充税收分类信息");
            }
         }
@@ -303,11 +303,11 @@
      //机动车开票
      if (StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(), "4")) {
         if (StrUtil.isBlank(genInvoiceInfoDTO.getVehicleNo())) {
            return R.failed("机动车开票请输入车架号");
            return R.failed("机动车销售发票请输入车架号");
         }
         BigDecimal invoiceNumSum = genInvoiceInfoDTO.getOutBoundInvoiceList().stream().map(item -> item.getInvoiceNum()).reduce(BigDecimal.ZERO, BigDecimal::add);
         if (invoiceNumSum.compareTo(new BigDecimal("1")) > 0) {
            return R.failed("机动车开票只能1次开1辆");
            return R.failed("机动车销售发票只能1次开1辆");
         }
         JSONObject request = genQueryVinParam(genInvoiceInfoDTO.getVehicleNo(), b);
         R r1 = requestQueryVehicleNo(request);
@@ -348,13 +348,13 @@
            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("请在产品信息中补充税收分类信息");
               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("请在产品信息中补充税收分类信息");
               return R.failed("请检查产品编码是否存在或请在产品信息中补充税收分类信息");
            }
         }
@@ -492,6 +492,7 @@
      log.info("机动车合格证查询接口入参:{},", request.toJSONString());
      String result = HttpUtil.post(bwUrl + "method=baiwang.output.invoice.queryVinDetail&version=1.0&request_id=" + requestId, request.toJSONString());
//      String result = "{\"success\":true,\"requestId\":\"5c2bc8a3-1399-4ff0-a039-92688c6740e0\",\"model\":[{\"engineNo\":\"5210F866\",\"vehicleName\":\"轿车\",\"vehicleSourceCode\":\"\",\"passengersLimited\":\"\",\"originPlace\":\"\",\"vehicleManufactureDate\":\"\",\"vehicleIdForAccountingUuid\":\"\",\"brandModel\":\"北京牌/BJJBJJ7201TN\",\"certificateInvoiceFlag\":\"\\\"certificateInvoiceFlag\\\": \\\"Y\\\"\",\"importCertificateNo\":\"HWJC22411181133\",\"certificateNo\":\"WZHGZBH22411181133\",\"paymentVoucherNo\":\"\",\"certificateStatusCode\":\"\\\"certificateStatusCode\\\": \\\"0\\\"\",\"vehicleNo\":\"CLSBDH22406190234\",\"invoiceUnavailableReasonCode\":\"\",\"manufacturingEnterprise\":\"佛山简捷陶瓷材料科技有限公司\",\"invoiceUnavailableReasonDesc\":\"\",\"tonnage\":0,\"inspectionListNo\":\"\",\"vehicleType\":\"\"}]}";
      log.info("机动车合格证查询接口回参:{},", result);
      saveBwRequestRecord("baiwang.output.invoice.queryVinDetail", requestId, request.toJSONString(), result);
      JSONObject resultObj = JSONObject.parseObject(result);
@@ -529,9 +530,9 @@
   private R requestQueryVehicleNo(JSONObject request) {
      String requestId = IdUtil.fastUUID();
      log.info("查询税局车架号码入参:{},", request.toJSONString());
      String result = HttpUtil.post(bwUrl + "method=baiwang.output.einvoice.queryvinlist&version=1.0&request_id=" + requestId, request.toJSONString());
//      String result = "{\"success\":true,\"requestId\":\"5c2bc8a3-1399-4ff0-a039-92688c6740e0\",\"model\":[{\"vehicleNo\":\"\",\"isNotOpenInvReason\":\"\",\"isOpenInvoice\":true}]}";
      log.info("查询税局车架号码回参:{},", result);
      saveBwRequestRecord("baiwang.output.einvoice.queryvinlist", requestId, request.toJSONString(), result);
      JSONObject resultObj = JSONObject.parseObject(result);
@@ -572,6 +573,12 @@
      vo.setPartyBBankAccount(b.getOrgBankAccount());
      vo.setInvoiceType(a.getInvoiceType());
      vo.setRemarks(genInvoiceInfoDTO.getRemarks());
      if (StrUtil.isNotBlank(b.getOrgContact())) {
         vo.setContact(b.getOrgContact());
      }
      if (StrUtil.isNotBlank(b.getOrgAddress())) {
         vo.setAddress(b.getOrgAddress());
      }
      vo.setOutBoundInvoiceList(genInvoiceInfoDTO.getOutBoundInvoiceList());
      if (StrUtil.isNotBlank(genInvoiceInfoDTO.getInvoiceType())) {
         vo.setInvoiceVehicleType(genInvoiceInfoDTO.getInvoiceType());
@@ -584,6 +591,9 @@
      }
      if (StrUtil.isNotBlank(genInvoiceInfoDTO.getVehicleData())) {
         vo.setVehicleData(genInvoiceInfoDTO.getVehicleData());
      }
      if (StrUtil.isNotBlank(genInvoiceInfoDTO.getSwjg())) {
         vo.setSwjg(genInvoiceInfoDTO.getSwjg());
      }
      List<InvoiceItemVo> invoiceItemVoList = new ArrayList<>();
      List<String> erpCode = new ArrayList<>();
@@ -1399,7 +1409,7 @@
      }
      BusinessCustomer customer = businessCustomerMapper.selectById(contract.getPartyAId());
      if (ObjUtil.isNull(customer) || StrUtil.isEmpty(customer.getBipCode())) {
         log.error("查询合同信息异常");
         log.error("查询客户信息异常");
         return;
      }
      R<SysDept> r = remoteDeptService.getById(contract.getPartyBId());
@@ -1408,16 +1418,16 @@
         return;
      }
      SysDept comp = r.getData();
      R<SysDept> rDept = remoteDeptService.getById(SecurityUtils.getUser().getDeptId());
      if (!r.isOk()) {
         log.error("查询单位信息异常");
         return;
      }
      SysDept dept = rDept.getData();
//      R<SysDept> rDept = remoteDeptService.getById(SecurityUtils.getUser().getDeptId());
//      if (!r.isOk()) {
//         log.error("查询单位信息异常");
//         return;
//      }
//      SysDept dept = rDept.getData();
      //蓝票
      if (StrUtil.equals(contractInvoice.getInvoiceCategory(), "1")) {
         JSONObject params = genBlueReceiveParams(contractInvoice, contract, customer, comp, dept);
         JSONObject params = genBlueReceiveParams(contractInvoice, contract, customer, comp);
         String finalAccessToken = accessToken;
         log.info("应收发票集成入参:{}", params.toJSONString());
@@ -1463,7 +1473,8 @@
   }
   private JSONObject genBlueReceiveParams(ContractInvoice contractInvoice, Contract contract, BusinessCustomer customer
         , SysDept comp, SysDept dept) {
         , SysDept comp) {
      GenInvoiceInfoVo vo = BeanUtil.copyProperties(JSONObject.parseObject(contractInvoice.getInvoicePreview()), GenInvoiceInfoVo.class);
      JSONObject jsonObject = new JSONObject();
      JSONObject data = new JSONObject();
      if (contractInvoice.getInvoiceCategory().equals("1")) {
@@ -1475,17 +1486,17 @@
      data.put("exchangeRate", "1");//汇率
      data.put("exchangeRateDate", DateUtil.now());//汇率时间
      data.put("objectType", "1");//往来对象类型(枚举值 1:客户; 2:员工;3:资金业务对象)
      data.put("deptCode", dept.getOrgCode());//部门编码 SS2
      data.put("staffCode", SecurityUtils.getUser().getNickname());//业务员编码
      data.put("deptCode", vo.getBipVo().getBm());//部门编码 SS2
      data.put("staffCode", vo.getBipVo().getYwy());//业务员编码
      data.put("customerCode", customer.getBipCode());//客户编码
      data.put("financeOrgCode", comp.getBipCode());//开票组织编码
      data.put("orgCode", comp.getBipCode());//业务组织编码
      data.put("bustypeCode", "ZBYXGLXT");//交易类型编码 暂估默认ZGYSFP,销售默认ZBYXGLXT
      data.put("bustypeCode", "ZBYXGLXT");//交易类型编码 暂估默认ZGYSFP,销售默认ZBYXGLXT  ar_invoice 应收发票
      data.put("contractNo", contract.getContractNo());
      data.put("oriCurrencyCode", "CNY");//币种
      data.put("_status", "Insert");
      GenInvoiceInfoVo vo = BeanUtil.copyProperties(JSONObject.parseObject(contractInvoice.getInvoicePreview()), GenInvoiceInfoVo.class);
      JSONArray bodyItem = new JSONArray();
      for (InvoiceItemVo invoiceItemVo : vo.getBipVo().getItemList()) {
         JSONObject item = new JSONObject();
@@ -1718,7 +1729,8 @@
                  contract.setBillingStatus("3");
               }
               if (contract.getPaidAmount().compareTo(contract.getAmount().subtract(contract.getDropAmount())) >= 0 &&
                     contract.getBillingAmout().compareTo(contract.getAmount()) == 0) {
                     contract.getBillingAmout().compareTo(contract.getAmount()) == 0&&
                     StrUtil.isBlank(contract.getNextScheduleName())) {
                  contract.setContractStatus(3);
               }
               if (contract.getBillingAmout().compareTo(contract.getAmount()) < 0) {
@@ -1755,7 +1767,8 @@
                     contract.setBillingStatus("3");
                  }
                  if (contract.getBillingAmout().compareTo(contract.getAmount()) == 0 &&
                        contract.getPaidAmount().compareTo(contract.getAmount().subtract(contract.getDropAmount())) >= 0) {
                        contract.getPaidAmount().compareTo(contract.getAmount().subtract(contract.getDropAmount())) >= 0&&
                        StrUtil.isBlank(contract.getNextScheduleName())) {
                     contract.setBillingStatus("3");
                     contract.setContractStatus(3);
                  }
@@ -2209,16 +2222,16 @@
      }
      SysDept comp = r.getData();
      R<SysDept> rDept = remoteDeptService.getById(SecurityUtils.getUser().getDeptId());
      if (!r.isOk()) {
         log.error("查询部门信息异常");
         return R.failed("查询部门信息异常");
      }
      SysDept dept = rDept.getData();
//      R<SysDept> rDept = remoteDeptService.getById(SecurityUtils.getUser().getDeptId());
//      if (!r.isOk()) {
//         log.error("查询部门信息异常");
//         return R.failed("查询部门信息异常");
//      }
//      SysDept dept = rDept.getData();
      //蓝票
      if (StrUtil.equals(contractInvoice.getInvoiceCategory(), "1")) {
         JSONObject params = genBlueReceiveParams(contractInvoice, contract, customer, comp, dept);
         JSONObject params = genBlueReceiveParams(contractInvoice, contract, customer, comp);
         String finalAccessToken = accessToken;
         log.info("应收发票集成入参:{}", params.toJSONString());
@@ -2408,6 +2421,17 @@
      return bipPushPdf(invoice.getId());
   }
   @Override
   public R updBwParamById(UpdBwParamDTO dto) {
      ContractInvoice invoice = baseMapper.selectById(dto.getId());
      if (ObjUtil.isNull(invoice)){
         return R.failed("发票信息异常");
      }
      invoice.setBwRequestParam(dto.getBwRequestParam());
      baseMapper.updateById(invoice);
      return R.ok();
   }
   public static void main(String[] args) {
      File file = new File("d://tmp//" + IdUtil.fastUUID() + ".pdf");
      HttpUtil.downloadFile("http://fp.baiwang.com/format/d?d=BB99645F8ED2AE7D2055E7D29330D366B7CAE92C278C6BB84D222610CEC2118D", file);