Explorar o código

计量系统万盛系统专用

DengLinLang hai 6 días
pai
achega
1ff27ac6cb

+ 15 - 0
blade-common/src/main/java/org/springblade/common/constant/MeasurementStorage.java

@@ -0,0 +1,15 @@
+package org.springblade.common.constant;
+
+/**
+ * 计量系统计算值存储redis KEY
+ */
+public interface MeasurementStorage {
+    //上期末扣取保留金
+    String PRE_END_RESERVE_MONEY = "preEndReserveMoney-";
+    //本期扣取保留金
+    String CUR_END_RESERVE_MONEY = "curEndReserveMoney-";
+    //本期末累计扣取保留金
+    String CUR_END_RESERVE_MONEY_SUM = "curEndReserveMoneySum-";
+    //本期计量
+    String CUR_MEASUREMENT = "curMeasurement-";
+}

+ 2 - 1
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/ReportResult.java

@@ -3,7 +3,6 @@ package org.springblade.manager.vo;
 import lombok.Data;
 import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.ss.util.CellRangeAddress;
-import org.springblade.common.utils.SnowFlakeUtil;
 import org.springblade.core.tool.utils.Func;
 import org.springblade.core.tool.utils.StringPool;
 
@@ -51,6 +50,8 @@ public class ReportResult {
     private String deleteRow;
     /**模板类型*/
     private Integer modelType=MeterInfo.MB_GX;
+    /**pdfOssPath字段String类型*/
+    private String ossPdfUrl;
 
     public String getPdfPath(){
         return this.pdfPath;

+ 697 - 19
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/FormulaServiceImpl.java

@@ -23,6 +23,7 @@ import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.jsoup.nodes.Element;
 import org.jsoup.select.Elements;
+import org.springblade.common.constant.MeasurementStorage;
 import org.springblade.common.utils.BaseUtils;
 import org.springblade.common.utils.CommonUtil;
 import org.springblade.common.utils.SnowFlakeUtil;
@@ -42,16 +43,13 @@ import org.springblade.manager.mapper.FormulaMapper;
 import org.springblade.manager.mapper.WbsTreeContractMapper;
 import org.springblade.manager.mapper.WbsTreePrivateMapper;
 import org.springblade.manager.service.*;
+import org.springblade.manager.utils.AmountToChineseConverter;
 import org.springblade.manager.utils.FileUtils;
 import org.springblade.manager.vo.*;
-import org.springblade.meter.entity.ContractInventoryForm;
-import org.springblade.meter.entity.ContractMeterPeriod;
-import org.springblade.meter.entity.InterimPayCertificateItem;
-import org.springblade.meter.entity.MiddleMeterApply;
+import org.springblade.meter.entity.*;
 import org.springblade.meter.feign.CertificateItemClient;
 import org.springblade.meter.feign.MiddleMeterApplyClient;
 import org.springblade.meter.vo.MeterInventoryDetailVO;
-import org.springblade.meter.vo.MeterInventoryVO;
 import org.springblade.meter.vo.MeterInventoryVO1;
 import org.springblade.resource.feign.CommonFileClient;
 import org.springblade.resource.feign.NewIOSSClient;
@@ -60,6 +58,7 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.dao.EmptyResultDataAccessException;
+import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.mock.web.MockMultipartFile;
@@ -70,6 +69,8 @@ import org.springframework.web.multipart.MultipartFile;
 import javax.validation.constraints.NotNull;
 import java.io.*;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.time.LocalDate;
 import java.util.*;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -130,6 +131,8 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
         @Lazy
         @Autowired
         private IExcelTabService excelTabService;
+        @Autowired
+        private StringRedisTemplate redisTemplate;
 
     @Override
     public void execute(TableElementConverter tec) {
@@ -895,7 +898,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
                             efm.setParamId(d.getId());
                             efm.setElementId(e.getId());
                             efm.setFormulaId(tf.getId());
-                            this.elementFormulaMappingService.save(efm);
+                            //this.elementFormulaMappingService.save(efm);
                         }
                     });
                 });
@@ -915,7 +918,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
                             efm.setParamId(d.getId());
                             efm.setElementId(e.getId());
                             efm.setFormulaId(tf.getId());
-                            this.elementFormulaMappingService.save(efm);
+                            //this.elementFormulaMappingService.save(efm);
                         }
                     });
                 });
@@ -2158,11 +2161,28 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
 
     @Override
     public List<ReportResult> execute4(Long contractId, Long periodId, Integer type,Long projectId) {
+
+        Long redisId = SnowFlakeUtil.getId();
         //判断计算的是哪一期。
         String sql="Select * from s_contract_meter_period where contract_id="+contractId+" and is_deleted=0"+" order by start_date";
         List<ContractMeterPeriod> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(ContractMeterPeriod.class));
+        ArrayList<ReportResult> reportResults = new ArrayList<>();
+        //中期支付报表封面
+        String url = "https://blade-oss-chongqing.oss-cn-shenzhen.aliyuncs.com//upload/20240828/3ee50ef54005c95bd724bcabae54058c.XLSX";
         //中间支付审核表
         String url1 = "https://blade-oss-chongqing.oss-cn-shenzhen.aliyuncs.com//upload/20241120/ea6c945827dd2990a9c7b1957fe201c4.XLSX";
+        //补助款申请支付审核表
+        String url2 = "https://blade-oss-chongqing.oss-cn-shenzhen.aliyuncs.com//upload/20241120/970eec0eb3cf3d215263a0e2f24c142e.xlsx";
+        //中间计量支付证书
+        String url3 = "https://blade-oss-chongqing.oss-cn-shenzhen.aliyuncs.com//upload/20240828/fb1110ae6aab7295759775206e5b44b8.XLSX";
+        // 获取中期支付报表封面的pdfurl
+        ReportResult CoverOfMidtermPaymentReportPDF = getCoverOfMidtermPaymentReportPDF(url,contractId,periodId);
+        //获取中间支付审核表的pdfurl
+        ReportResult intermediatePaymentPDF = getIntermediatePaymentPDF(url1,contractId,periodId,list,redisId);
+        //获取补助款申请支付审核表pdfUrl
+        ReportResult subsidyApplicationPaymentReviewPDF = getSubsidyApplicationPaymentReviewPDF(url2,contractId,periodId,list);
+        //获取中间计量支付证书pdfUrl
+        ReportResult intermediateMeasurementPaymentCertificatePDF = getIntermediateMeasurementPaymentCertificatePDF(url3,contractId,periodId,list);
         //中间计量支付申请表
         String url4="https://blade-oss-chongqing.oss-cn-shenzhen.aliyuncs.com//upload/20240828/bff82dd0a1b7394f5fdab1322a3e6023.XLSX";
         //工程支付月报
@@ -2176,18 +2196,468 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
         //获取工程支付月报pdfUrl
         //ReportResult monthlyReportPDF=getMonthlyReportPDF(url5);
         //获取清单支付报表PDF
-        ReportResult inventoryPayReportPDF=getInventoryPayReportPDF(url6,contractId,periodId,projectId,list);
-        return null;
+        //ReportResult inventoryPayReportPDF=getInventoryPayReportPDF(url6,contractId,periodId,projectId,list);
+        reportResults.add(CoverOfMidtermPaymentReportPDF);
+        reportResults.add(intermediatePaymentPDF);
+        reportResults.add(subsidyApplicationPaymentReviewPDF);
+        reportResults.add(intermediateMeasurementPaymentCertificatePDF);
+        //reportResults.add(inventoryPayReportPDF);
+        return reportResults;
+    }
+
+    /**
+     * 中期支付报表封面
+     */
+    private ReportResult getCoverOfMidtermPaymentReportPDF(String url, Long contractId, Long periodId) {
+        //获取本期计量期
+        String sqlForMeterPeriodById = "SELECT id,period_number,start_date,end_date FROM s_contract_meter_period WHERE id="+periodId+" and is_deleted = 0 ";
+        ContractMeterPeriod contractMeterPeriodNow = jdbcTemplate.queryForObject(sqlForMeterPeriodById, new BeanPropertyRowMapper<>(ContractMeterPeriod.class));
+        //本期计量期id
+        Long contractMeterPeriodNowId = contractMeterPeriodNow.getId();
+        //本期计量开始时间
+        LocalDate startDate = contractMeterPeriodNow.getStartDate();
+        //本期计量开始时间
+        LocalDate endDate = contractMeterPeriodNow.getEndDate();
+        InputStream modInput = null;
+        FileInputStream excelFileInput = null;
+        FileOutputStream outputStream = null;
+        Workbook workbook = null;
+        MultipartFile files = null;
+        try {
+            modInput = CommonUtil.getOSSInputStream(url);
+            workbook = WorkbookFactory.create(modInput);
+            Sheet sheet = workbook.getSheetAt(0);
+            //期号
+            String periodNumber = contractMeterPeriodNow.getPeriodNumber();
+            if (ObjectUtil.isNotEmpty(periodNumber)){
+                Cell d4 = getCellByAddress(sheet, "D4");
+                d4.setCellValue(periodNumber);
+            }
+            //施工单位
+            Cell c9 = getCellByAddress(sheet, "C9");
+            c9.setCellValue("重庆交通建设(集团)有限责任公司");
+            //监理单位
+            Cell c10 = getCellByAddress(sheet, "C10");
+            c10.setCellValue("重庆市交通工程监理咨询有限责任公司");
+            //日期
+            Cell c11 = getCellByAddress(sheet, "C11");
+            c11.setCellValue(endDate.toString());
+
+            String file_path = FileUtils.getSysLocalFileUrl();
+            String locationFile = file_path + SnowFlakeUtil.getId() + ".xlsx";
+            outputStream = new FileOutputStream(locationFile);
+            //生成一份新的excel
+            workbook.write(outputStream);
+            //将excel转PDF
+            File excelFile = new File(locationFile);
+            excelFileInput = new FileInputStream(excelFile);
+            files = new MockMultipartFile("file", excelFile.getName(), "text/plain", IOUtils.toByteArray(excelFileInput));
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        NewBladeFile bladeFile = this.commonFileClient.excelToPdf(files);
+        ReportResult reportResult = new ReportResult();
+        reportResult.setOssPdfUrl(bladeFile.getPdfUrl());
+        reportResult.setPdfPath(bladeFile.getPdfUrl());
+        reportResult.setName("中期支付报表封面");
+        return reportResult;
+    }
+
+    /**
+     *中间计量支付证书获取PDFurl
+     */
+    private ReportResult getIntermediateMeasurementPaymentCertificatePDF(String url3, Long contractId, Long periodId, List<ContractMeterPeriod> list) {
+        //判断当前是否是只有1期计量
+        Boolean isOnePeriod = false;
+        if(list.size() ==1 ){
+            isOnePeriod = true;
+        }
+        //获取本期计量期
+        String sqlForMeterPeriodById = "SELECT id,period_number,start_date,end_date FROM s_contract_meter_period WHERE id="+periodId+" and is_deleted = 0 ";
+        ContractMeterPeriod contractMeterPeriodNow = jdbcTemplate.queryForObject(sqlForMeterPeriodById, new BeanPropertyRowMapper<>(ContractMeterPeriod.class));
+        //本期计量期id
+        Long contractMeterPeriodNowId = contractMeterPeriodNow.getId();
+        //本期计量开始时间
+        LocalDate startDate = contractMeterPeriodNow.getStartDate();
+        //本期计量开始时间
+        LocalDate endDate = contractMeterPeriodNow.getEndDate();
+        InputStream modInput = null;
+        FileInputStream excelFileInput = null;
+        FileOutputStream outputStream = null;
+        Workbook workbook = null;
+        MultipartFile files = null;
+        try {
+            modInput = CommonUtil.getOSSInputStream(url3);
+            workbook = WorkbookFactory.create(modInput);
+            Sheet sheet = workbook.getSheetAt(0);
+            //------------------------------------------------------------上期末累计计量金额------------------------------------------------------------
+            BigDecimal allMoney = new BigDecimal(0);
+            //顺便计算上期末累计支付
+            BigDecimal lastEndPay = new BigDecimal(0);
+            //顺便计算上期末累计扣取保留金
+            BigDecimal lastEndDeduct = new BigDecimal(0);
+            String lastEndMeasurement = "";
+            if(isOnePeriod){
+                lastEndMeasurement = "0";
+            }else {
+                //根据开始时间获取当前计量期之前的所有计量期
+                List<Long> lastAllPeriodIds = list.stream().filter(item -> item.getStartDate().isBefore(startDate)).map(ContractMeterPeriod::getId).collect(Collectors.toList());
+                //获取之前所有计量期的本期计量之和=上期末累计计量
+                String lastAllPeriodIdsStr = org.apache.commons.lang.StringUtils.join(lastAllPeriodIds, ",");
+                String sql2 = "SELECT id,contract_form_id,contract_meter_id,contract_id,current_price,current_meter_total,contract_period_id FROM `s_inventory_form_apply` WHERE contract_period_id in ("+lastAllPeriodIdsStr+") and contract_id = '"+contractId+"' and is_deleted = 0";
+                List<InventoryFormApply> inventoryFormApplies = jdbcTemplate.query(sql2, new BeanPropertyRowMapper<>(InventoryFormApply.class));
+                //根据计量期id进行分类
+                Map<Long, List<InventoryFormApply>> collect = inventoryFormApplies.stream().collect(Collectors.groupingBy(InventoryFormApply::getContractPeriodId));
+                for (Long l : collect.keySet()) {
+                    //某一计量期的本期计量
+                    BigDecimal money = new BigDecimal(0);
+                    //某一计量期的所有数据
+                    List<InventoryFormApply> inventoryFormApplies1 = collect.get(l);
+                    //按照清单id分组
+                    Map<Long, List<InventoryFormApply>> map = inventoryFormApplies1.stream().collect(Collectors.groupingBy(InventoryFormApply::getContractFormId));
+                    for (Long aLong : map.keySet()) {
+                        //同一清单的数据
+                        List<InventoryFormApply> inventoryFormApplies2 = map.get(aLong);
+                        //同一清单的累计计量数量
+                        BigDecimal sum = new BigDecimal(0);
+                        for (InventoryFormApply inventoryFormApply : inventoryFormApplies2) {
+                            BigDecimal currentMeterTotal = inventoryFormApply.getCurrentMeterTotal();
+                            sum = sum.add(currentMeterTotal);
+                        }
+                        //计算当前清单集合的计量金额 = 累计计量数量 * 单价  四舍五入保留整数
+                        money =  money.add(sum.multiply(inventoryFormApplies2.get(0).getCurrentPrice()).setScale(0, BigDecimal.ROUND_HALF_UP));
+                    }
+                    //本期支付
+                    BigDecimal nowPeriodPay = money.multiply(new BigDecimal(0.75)).setScale(0, BigDecimal.ROUND_HALF_UP);
+                    //上期末累计支付
+                    lastEndPay = lastEndPay.add(nowPeriodPay);
+                    //上期末累计扣取保留金
+                    lastEndDeduct = lastEndDeduct.add(money.subtract(nowPeriodPay));
+                    //上期末累计计量
+                    allMoney = allMoney.add(money);
+                }
+            }
+            String sql3 = "SELECT id,contract_form_id,contract_meter_id,contract_id,current_price,current_meter_total FROM `s_inventory_form_apply` " +
+                    "WHERE contract_id = '"+contractId+"' and contract_period_id = "+contractMeterPeriodNowId;
+            List<InventoryFormApply> inventoryFormAppliesNow = jdbcTemplate.query(sql3, new BeanPropertyRowMapper<>(InventoryFormApply.class));
+            //按照清单id分组
+            Map<Long, List<InventoryFormApply>> map = inventoryFormAppliesNow.stream().collect(Collectors.groupingBy(InventoryFormApply::getContractFormId));
+            //本期计量量
+            BigDecimal AllcurrentMeterTotal = new BigDecimal(0);
+            for (Long l : map.keySet()) {
+                List<InventoryFormApply> inventoryFormApplies = map.get(l);
+                BigDecimal metetTotal = new BigDecimal(0);
+                for (InventoryFormApply inventoryFormApply : inventoryFormApplies) {
+                    BigDecimal metetnum = inventoryFormApply.getCurrentMeterTotal();
+                    metetTotal = metetTotal.add(metetnum);
+                }
+                AllcurrentMeterTotal = AllcurrentMeterTotal.add(metetTotal.multiply(inventoryFormApplies.get(0).getCurrentPrice()).setScale(0, BigDecimal.ROUND_HALF_UP));
+            }
+            //------------------------------------------------------------同意本期支付工程款------------------------------------------------------------
+            BigDecimal currentPay = AllcurrentMeterTotal.multiply(new BigDecimal(0.75)).setScale(0, BigDecimal.ROUND_HALF_UP);
+            //小写
+            Cell c7 = getCellByAddress(sheet, "C7");
+            c7.setCellValue(currentPay.toString());
+            //大写
+            Cell d6 = getCellByAddress(sheet, "D6");
+            d6.setCellValue(AmountToChineseConverter.convertToChinese(currentPay));
+            //-----------------------------------------------------------承包单位申报款--------------------------------------------------------------------
+            Cell e10 = getCellByAddress(sheet, "E10");
+            e10.setCellValue(AllcurrentMeterTotal.toString());
+            //-----------------------------------------------------------经审核承包单位应得款--------------------------------------------------------------------
+            Cell e11 = getCellByAddress(sheet, "E11");
+            e11.setCellValue(currentPay.toString());
+            //------------------------------------------------------------本期应扣款------------------------------------------------------------
+            //本期扣取保留金=本期计量 - 本期支付
+            BigDecimal deductionMoney = AllcurrentMeterTotal.subtract(currentPay);
+            Cell e12 = getCellByAddress(sheet, "E12");
+            e12.setCellValue(deductionMoney.toString());
+            //------------------------------------------------------------本期应付款------------------------------------------------------------
+            Cell e13 = getCellByAddress(sheet, "E13");
+            e13.setCellValue(currentPay.toString());
+
+            //***************************************************************所有日期*************************************************************************
+            //顶部日期
+            Cell f25 = getCellByAddress(sheet, "F25");
+            f25.setCellValue(endDate.toString());
+            //工程名称
+            Cell c3 = getCellByAddress(sheet, "C3");
+            c3.setCellValue("S104金桥至万盛城区段升级改造工程一期(田顶至滩子口段)");
+
+            String file_path = FileUtils.getSysLocalFileUrl();
+            String locationFile = file_path + SnowFlakeUtil.getId() + ".xlsx";
+            outputStream = new FileOutputStream(locationFile);
+            //生成一份新的excel
+            workbook.write(outputStream);
+            //将excel转PDF
+            File excelFile = new File(locationFile);
+            excelFileInput = new FileInputStream(excelFile);
+            files = new MockMultipartFile("file", excelFile.getName(), "text/plain", IOUtils.toByteArray(excelFileInput));
+
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        NewBladeFile bladeFile = this.commonFileClient.excelToPdf(files);
+        ReportResult reportResult = new ReportResult();
+        reportResult.setOssPdfUrl(bladeFile.getPdfUrl());
+        reportResult.setPdfPath(bladeFile.getPdfUrl());
+        reportResult.setName("中间计量支付证书");
+        return reportResult;
     }
 
+    /**
+     *补助款申请支付审核表获取PDFurl
+     */
+    private ReportResult getSubsidyApplicationPaymentReviewPDF(String url2, Long contractId, Long periodId, List<ContractMeterPeriod> list) {
+        //判断当前是否是只有1期计量
+        Boolean isOnePeriod = false;
+        if(list.size() ==1 ){
+            isOnePeriod = true;
+        }
+        //获取本期计量期
+        String sqlForMeterPeriodById = "SELECT id,period_number,start_date,end_date FROM s_contract_meter_period WHERE id="+periodId+" and is_deleted = 0 ";
+        ContractMeterPeriod contractMeterPeriodNow = jdbcTemplate.queryForObject(sqlForMeterPeriodById, new BeanPropertyRowMapper<>(ContractMeterPeriod.class));
+        //本期计量期id
+        Long contractMeterPeriodNowId = contractMeterPeriodNow.getId();
+        //本期计量开始时间
+        LocalDate startDate = contractMeterPeriodNow.getStartDate();
+        //本期计量开始时间
+        LocalDate endDate = contractMeterPeriodNow.getEndDate();
+        InputStream modInput = null;
+        FileInputStream excelFileInput = null;
+        FileOutputStream outputStream = null;
+        Workbook workbook = null;
+        MultipartFile files = null;
+        try {
+            modInput = CommonUtil.getOSSInputStream(url2);
+            workbook = WorkbookFactory.create(modInput);
+            Sheet sheet = workbook.getSheetAt(0);
+            //***************************************************************建安费*************************************************************************
+            Cell a6 = getCellByAddress(sheet, "A6");
+            a6.setCellValue("建安费");
+            //------------------------------------------------------------项目总投资------------------------------------------------------------
+            String sql1 = "SELECT SUM(contract_money) FROM `s_contract_inventory_form` WHERE contract_id="+contractId+" and is_deleted = 0 ";
+            BigDecimal totalMoney = jdbcTemplate.queryForObject(sql1, BigDecimal.class);
+            totalMoney = totalMoney.setScale(0, BigDecimal.ROUND_HALF_UP);
+            Cell b6 = getCellByAddress(sheet, "B6");
+            b6.setCellValue(totalMoney.toString());
+            //------------------------------------------------------------上期末累计计量金额------------------------------------------------------------
+            BigDecimal allMoney = new BigDecimal(0);
+            //顺便计算上期末累计支付
+            BigDecimal lastEndPay = new BigDecimal(0);
+            //顺便计算上期末累计扣取保留金
+            BigDecimal lastEndDeduct = new BigDecimal(0);
+            String lastEndMeasurement = "";
+            if(isOnePeriod){
+                lastEndMeasurement = "0";
+            }else {
+                //根据开始时间获取当前计量期之前的所有计量期
+                List<Long> lastAllPeriodIds = list.stream().filter(item -> item.getStartDate().isBefore(startDate)).map(ContractMeterPeriod::getId).collect(Collectors.toList());
+                //获取之前所有计量期的本期计量之和=上期末累计计量
+                String lastAllPeriodIdsStr = org.apache.commons.lang.StringUtils.join(lastAllPeriodIds, ",");
+                String sql2 = "SELECT id,contract_form_id,contract_meter_id,contract_id,current_price,current_meter_total,contract_period_id FROM `s_inventory_form_apply` WHERE contract_period_id in ("+lastAllPeriodIdsStr+") and contract_id = '"+contractId+"' and is_deleted = 0";
+                List<InventoryFormApply> inventoryFormApplies = jdbcTemplate.query(sql2, new BeanPropertyRowMapper<>(InventoryFormApply.class));
+                //根据计量期id进行分类
+                Map<Long, List<InventoryFormApply>> collect = inventoryFormApplies.stream().collect(Collectors.groupingBy(InventoryFormApply::getContractPeriodId));
+                for (Long l : collect.keySet()) {
+                    //某一计量期的本期计量
+                    BigDecimal money = new BigDecimal(0);
+                    //某一计量期的所有数据
+                    List<InventoryFormApply> inventoryFormApplies1 = collect.get(l);
+                    //按照清单id分组
+                    Map<Long, List<InventoryFormApply>> map = inventoryFormApplies1.stream().collect(Collectors.groupingBy(InventoryFormApply::getContractFormId));
+                    for (Long aLong : map.keySet()) {
+                        //同一清单的数据
+                        List<InventoryFormApply> inventoryFormApplies2 = map.get(aLong);
+                        //同一清单的累计计量数量
+                        BigDecimal sum = new BigDecimal(0);
+                        for (InventoryFormApply inventoryFormApply : inventoryFormApplies2) {
+                            BigDecimal currentMeterTotal = inventoryFormApply.getCurrentMeterTotal();
+                            sum = sum.add(currentMeterTotal);
+                        }
+                        //计算当前清单集合的计量金额 = 累计计量数量 * 单价  四舍五入保留整数
+                        money =  money.add(sum.multiply(inventoryFormApplies2.get(0).getCurrentPrice()).setScale(0, BigDecimal.ROUND_HALF_UP));
+                    }
+                    //本期支付
+                    BigDecimal nowPeriodPay = money.multiply(new BigDecimal(0.75)).setScale(0, BigDecimal.ROUND_HALF_UP);
+                    //上期末累计支付
+                    lastEndPay = lastEndPay.add(nowPeriodPay);
+                    //上期末累计扣取保留金
+                    lastEndDeduct = lastEndDeduct.add(money.subtract(nowPeriodPay));
+                    //上期末累计计量
+                    allMoney = allMoney.add(money);
+                }
+            }
+            Cell d6 = getCellByAddress(sheet, "D6");
+            d6.setCellValue(allMoney.toString());
+            //------------------------------------------------------------上期末累计支付金额------------------------------------------------------------
+            Cell e6 = getCellByAddress(sheet, "E6");
+            e6.setCellValue(lastEndPay.toString());
+            //------------------------------------------------------------本期计量金额------------------------------------------------------------
+            String sql3 = "SELECT id,contract_form_id,contract_meter_id,contract_id,current_price,current_meter_total FROM `s_inventory_form_apply` " +
+                    "WHERE contract_id = '"+contractId+"' and contract_period_id = "+contractMeterPeriodNowId;
+            List<InventoryFormApply> inventoryFormAppliesNow = jdbcTemplate.query(sql3, new BeanPropertyRowMapper<>(InventoryFormApply.class));
+            //按照清单id分组
+            Map<Long, List<InventoryFormApply>> map = inventoryFormAppliesNow.stream().collect(Collectors.groupingBy(InventoryFormApply::getContractFormId));
+            //本期计量量
+            BigDecimal AllcurrentMeterTotal = new BigDecimal(0);
+            for (Long l : map.keySet()) {
+                List<InventoryFormApply> inventoryFormApplies = map.get(l);
+                BigDecimal metetTotal = new BigDecimal(0);
+                for (InventoryFormApply inventoryFormApply : inventoryFormApplies) {
+                    BigDecimal metetnum = inventoryFormApply.getCurrentMeterTotal();
+                    metetTotal = metetTotal.add(metetnum);
+                }
+                AllcurrentMeterTotal = AllcurrentMeterTotal.add(metetTotal.multiply(inventoryFormApplies.get(0).getCurrentPrice()).setScale(0, BigDecimal.ROUND_HALF_UP));
+            }
+            Cell g6 = getCellByAddress(sheet, "G6");
+            g6.setCellValue(AllcurrentMeterTotal.toString());
+            //------------------------------------------------------------本期累计计量金额------------------------------------------------------------
+            //上期末累计计量金额+本期计量金额
+            BigDecimal allMoneyNow = allMoney.add(AllcurrentMeterTotal);
+            Cell h6 = getCellByAddress(sheet, "H6");
+            h6.setCellValue(allMoneyNow.toString());
+            //------------------------------------------------------------本期支付金额------------------------------------------------------------
+            BigDecimal currentPay = AllcurrentMeterTotal.multiply(new BigDecimal(0.75)).setScale(0, BigDecimal.ROUND_HALF_UP);
+            Cell i6 = getCellByAddress(sheet, "I6");
+            i6.setCellValue(currentPay.toString());
+            //------------------------------------------------------------本期末累计支付金额------------------------------------------------------------
+            //上期末累计支付+本期支付
+            BigDecimal endPay = lastEndPay.add(currentPay);
+            Cell k6 = getCellByAddress(sheet, "K6");
+            k6.setCellValue(endPay.toString());
+            //------------------------------------------------------------支付比例------------------------------------------------------------
+            Cell m6 = getCellByAddress(sheet, "M6");
+            m6.setCellValue("75.00%");
+
+
+
+            //***************************************************************其他费用*************************************************************************
+            Cell a7 = getCellByAddress(sheet, "A7");
+            a7.setCellValue("其他费用");
+            //------------------------------------------------------------项目总投资------------------------------------------------------------
+            Cell b7 = getCellByAddress(sheet, "B7");
+            b7.setCellValue("");
+            //------------------------------------------------------------上期末累计计量金额------------------------------------------------------------
+            Cell d7 = getCellByAddress(sheet, "D7");
+            d7.setCellValue("0");
+            //------------------------------------------------------------上期末累计支付金额------------------------------------------------------------
+            Cell e7 = getCellByAddress(sheet, "E7");
+            e7.setCellValue("0");
+            //------------------------------------------------------------本期计量金额------------------------------------------------------------
+            Cell g7 = getCellByAddress(sheet, "G7");
+            g7.setCellValue("0");
+            //------------------------------------------------------------本期累计计量金额------------------------------------------------------------
+            //上期末累计计量金额+本期计量金额
+            Cell h7 = getCellByAddress(sheet, "H7");
+            h7.setCellValue("0");
+            //------------------------------------------------------------本期支付金额------------------------------------------------------------
+            Cell i7 = getCellByAddress(sheet, "I7");
+            i7.setCellValue("0");
+            //------------------------------------------------------------本期末累计支付金额------------------------------------------------------------
+            Cell k7 = getCellByAddress(sheet, "K7");
+            k7.setCellValue("0");
+            //------------------------------------------------------------支付比例------------------------------------------------------------
+            Cell m7 = getCellByAddress(sheet, "M7");
+
+
+            //***************************************************************合计*************************************************************************
+            //------------------------------------------------------------项目总投资------------------------------------------------------------
+            Cell b8 = getCellByAddress(sheet, "B8");
+            b8.setCellValue(totalMoney.toString());
+            //------------------------------------------------------------上期末累计计量金额------------------------------------------------------------
+            Cell d8 = getCellByAddress(sheet, "D8");
+            d8.setCellValue(allMoney.toString());
+            //------------------------------------------------------------上期末累计支付金额------------------------------------------------------------
+            Cell e8 = getCellByAddress(sheet, "E8");
+            e8.setCellValue(lastEndPay.toString());
+            //------------------------------------------------------------本期计量金额------------------------------------------------------------
+            Cell g8 = getCellByAddress(sheet, "G8");
+            g8.setCellValue(AllcurrentMeterTotal.toString());
+            //------------------------------------------------------------本期累计计量金额------------------------------------------------------------
+            //上期末累计计量金额+本期计量金额
+            Cell h8 = getCellByAddress(sheet, "H8");
+            h8.setCellValue(allMoneyNow.toString());
+            //------------------------------------------------------------本期支付金额------------------------------------------------------------
+            Cell i8 = getCellByAddress(sheet, "I8");
+            i8.setCellValue(currentPay.toString());
+            //------------------------------------------------------------本期末累计支付金额------------------------------------------------------------
+            Cell k8 = getCellByAddress(sheet, "K8");
+            k8.setCellValue(endPay.toString());
+            //------------------------------------------------------------支付比例------------------------------------------------------------
+            Cell m8 = getCellByAddress(sheet, "M8");
+
+            //***************************************************************所有日期*************************************************************************
+            //顶部日期
+            Cell j4 = getCellByAddress(sheet, "J4");
+            j4.setCellValue(endDate.toString());
+            //交通建设事务中心审核意见日期
+            Cell m12 = getCellByAddress(sheet, "M12");
+            m12.setCellValue(endDate.toString());
+            //业务科室审核意见
+            Cell m15 = getCellByAddress(sheet, "M15");
+            m15.setCellValue(endDate.toString());
+            //财务科审核意见
+            Cell m18 = getCellByAddress(sheet, "M18");
+            m18.setCellValue(endDate.toString());
+            //业务科室分管领导审核意见
+            Cell m21 = getCellByAddress(sheet, "M21");
+            m21.setCellValue(endDate.toString());
+            //财务分管领导审核意见
+            Cell m24 = getCellByAddress(sheet, "M24");
+            m24.setCellValue(endDate.toString());
+            //财务分管领导审核意见
+            Cell m27 = getCellByAddress(sheet, "M27");
+            m27.setCellValue(endDate.toString());
+            //***************************************************************标题*************************************************************************
+            String periodNumber = contractMeterPeriodNow.getPeriodNumber();
+            if(ObjectUtil.isNotEmpty(periodNumber)){
+                Cell e3 = getCellByAddress(sheet, "E3");
+                e3.setCellValue(periodNumber);
+            }
+            //填报单位
+            Cell d4 = getCellByAddress(sheet, "D4");
+            d4.setCellValue("重庆市万盛经济开发区交通建设事务中心");
+
+            String file_path = FileUtils.getSysLocalFileUrl();
+            String locationFile = file_path + SnowFlakeUtil.getId() + ".xlsx";
+            outputStream = new FileOutputStream(locationFile);
+            //生成一份新的excel
+            workbook.write(outputStream);
+            //将excel转PDF
+            File excelFile = new File(locationFile);
+            excelFileInput = new FileInputStream(excelFile);
+            files = new MockMultipartFile("file", excelFile.getName(), "text/plain", IOUtils.toByteArray(excelFileInput));
+
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        NewBladeFile bladeFile = this.commonFileClient.excelToPdf(files);
+        ReportResult reportResult = new ReportResult();
+        reportResult.setOssPdfUrl(bladeFile.getPdfUrl());
+        reportResult.setPdfPath(bladeFile.getPdfUrl());
+        reportResult.setName("补助款申请支付审核表");
+        return reportResult;
+    }
 
     /**
      * 中间支付审核表获取PDFurl
-     *
-     * @param url
-     * @return
      */
-    public ReportResult getIntermediatePaymentPDF(String url) {
+    public ReportResult  getIntermediatePaymentPDF(String url,Long contractId,Long periodId,List<ContractMeterPeriod> list,Long redisId) {
+        //判断当前是否是只有1期计量
+        Boolean isOnePeriod = false;
+        if(list.size() ==1 ){
+            isOnePeriod = true;
+        }
+        //获取本期计量期
+        String sqlForMeterPeriodById = "SELECT id,period_number,start_date,end_date FROM s_contract_meter_period WHERE id="+periodId+" and is_deleted = 0 ";
+        ContractMeterPeriod contractMeterPeriodNow = jdbcTemplate.queryForObject(sqlForMeterPeriodById, new BeanPropertyRowMapper<>(ContractMeterPeriod.class));
+        //本期计量期id
+        Long contractMeterPeriodNowId = contractMeterPeriodNow.getId();
+        //本期计量开始时间
+        LocalDate startDate = contractMeterPeriodNow.getStartDate();
+        //本期计量开始时间
+        LocalDate endDate = contractMeterPeriodNow.getEndDate();
         InputStream modInput = null;
         FileInputStream excelFileInput = null;
         FileOutputStream outputStream = null;
@@ -2197,11 +2667,219 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
             modInput = CommonUtil.getOSSInputStream(url);
             workbook = WorkbookFactory.create(modInput);
             Sheet sheet = workbook.getSheetAt(0);
-            //根据坐标获取单元格
+            //------------------------------------------------------------签约合同价------------------------------------------------------------
+            String sql1 = "SELECT SUM(contract_money) FROM `s_contract_inventory_form` WHERE contract_id="+contractId+" and is_deleted = 0 ";
+            BigDecimal totalMoney = jdbcTemplate.queryForObject(sql1, BigDecimal.class);
+            totalMoney = totalMoney.setScale(0, BigDecimal.ROUND_HALF_UP);
+            Cell a5 = getCellByAddress(sheet, "A5");
+            a5.setCellValue(totalMoney.toString());
+            //------------------------------------------------------------上期末累计变更------------------------------------------------------------
+            BigDecimal lastEndChangeMoney = new BigDecimal(0);
+
+            if (isOnePeriod){
+                lastEndChangeMoney = lastEndChangeMoney;
+            }else {
+                //根据开始时间获取当前计量期之前的所有计量期
+                List<ContractMeterPeriod> listFlitered = list.stream().filter(item -> item.getStartDate().isBefore(startDate)).collect(Collectors.toList());
+                for (ContractMeterPeriod contractMeterPeriod : listFlitered) {
+                    //本期变更
+                    BigDecimal changeMoneyNow = new BigDecimal(0);
+                    String sql2 = "SELECT change_money, change_approval_date FROM `s_change_token_form` WHERE contract_id = '"+contractId +"' and approve_status = 2 and command_status = 1 and is_deleted = 0 ";
+                    List<ChangeToken> changeTokens = jdbcTemplate.query(sql2, new BeanPropertyRowMapper<>(ChangeToken.class));
+                    List<ChangeToken> collect = changeTokens.stream()
+                            .filter(c -> c.getChangeApprovalDate().isAfter(contractMeterPeriod.getStartDate()) && c.getChangeApprovalDate().isBefore(contractMeterPeriod.getEndDate()))
+                            .collect(Collectors.toList());
+                    if(ObjectUtil.isNotEmpty(collect)){
+                        for (ChangeToken changeToken : collect) {
+                            changeMoneyNow =  changeMoneyNow.add(changeToken.getChangeMoney());
+                        }
+                    }
+                    changeMoneyNow = changeMoneyNow.setScale(0, RoundingMode.HALF_UP);
+                    lastEndChangeMoney = lastEndChangeMoney.add(changeMoneyNow);
+                }
+            }
+
             Cell c5 = getCellByAddress(sheet, "C5");
-            c5.setCellValue("大笨熊二号");
+            c5.setCellValue(lastEndChangeMoney.toString());
+            //------------------------------------------------------------本期变更------------------------------------------------------------
+            //获取当前合同段的所有已审批并且已下达的变更令
+            String sql4 = "SELECT id,change_money,change_approval_date from s_change_token_form where contract_id = '"+contractId +"' and approve_status = 2 and command_status = 1 and is_deleted = 0";
+            List<ChangeTokenForm> changeTokenForms = jdbcTemplate.query(sql4, new BeanPropertyRowMapper<>(ChangeTokenForm.class));
+            //筛选出时间在本期计量开始和结束时间之内的数据
+            List<ChangeTokenForm> changeTokenForms1 = changeTokenForms.stream()
+                    .filter(changeTokenForm -> changeTokenForm.getChangeApprovalDate().isAfter(startDate) && changeTokenForm.getChangeApprovalDate().isBefore(endDate))
+                    .collect(Collectors.toList());
+            //本期变更金额
+            BigDecimal changeMoneySum = new BigDecimal(0);
+            if(ObjectUtil.isNotEmpty(changeTokenForms1)){
+                for (ChangeTokenForm changeTokenForm : changeTokenForms1) {
+                    changeMoneySum = changeMoneySum.add(changeTokenForm.getChangeMoney());
+                }
+            }
+            changeMoneySum = changeMoneySum.setScale(0, RoundingMode.HALF_UP);
+            Cell e5 = getCellByAddress(sheet, "E5");
+            e5.setCellValue(changeMoneySum.toString());
+            //------------------------------------------------------------本期末累计变更------------------------------------------------------------
+            //上期末累计变更+本期变更
+            BigDecimal lastEndChangeMoneySum = lastEndChangeMoney.add(changeMoneySum);
+            Cell g5 = getCellByAddress(sheet, "G5");
+            g5.setCellValue(lastEndChangeMoneySum.toString());
+            //------------------------------------------------------------变更后合同价------------------------------------------------------------
+            //签约合同价+本期末累计变更(可能是负数)
+            BigDecimal changeMoney = totalMoney.add(lastEndChangeMoneySum);
+
+            Cell i5 = getCellByAddress(sheet, "I5");
+            i5.setCellValue(changeMoney.toString());
+            //------------------------------------------------------------上期末累计计量-------------------------------------------------------------
+            BigDecimal allMoney = new BigDecimal(0);
+            //顺便计算上期末累计支付
+            BigDecimal lastEndPay = new BigDecimal(0);
+            //顺便计算上期末累计扣取保留金
+            BigDecimal lastEndDeduct = new BigDecimal(0);
+            String lastEndMeasurement = "";
+            if(isOnePeriod){
+                lastEndMeasurement = "0";
+            }else {
+                //根据开始时间获取当前计量期之前的所有计量期
+                List<Long> lastAllPeriodIds = list.stream().filter(item -> item.getStartDate().isBefore(startDate)).map(ContractMeterPeriod::getId).collect(Collectors.toList());
+                //获取之前所有计量期的本期计量之和=上期末累计计量
+                String lastAllPeriodIdsStr = org.apache.commons.lang.StringUtils.join(lastAllPeriodIds, ",");
+                String sql2 = "SELECT id,contract_form_id,contract_meter_id,contract_id,current_price,current_meter_total,contract_period_id FROM `s_inventory_form_apply` WHERE contract_period_id in ("+lastAllPeriodIdsStr+") and contract_id = '"+contractId+"' and is_deleted = 0";
+                List<InventoryFormApply> inventoryFormApplies = jdbcTemplate.query(sql2, new BeanPropertyRowMapper<>(InventoryFormApply.class));
+                //根据计量期id进行分类
+                Map<Long, List<InventoryFormApply>> collect = inventoryFormApplies.stream().collect(Collectors.groupingBy(InventoryFormApply::getContractPeriodId));
+                for (Long l : collect.keySet()) {
+                    //某一计量期的本期计量
+                    BigDecimal money = new BigDecimal(0);
+                    //某一计量期的所有数据
+                    List<InventoryFormApply> inventoryFormApplies1 = collect.get(l);
+                    //按照清单id分组
+                    Map<Long, List<InventoryFormApply>> map = inventoryFormApplies1.stream().collect(Collectors.groupingBy(InventoryFormApply::getContractFormId));
+                    for (Long aLong : map.keySet()) {
+                        //同一清单的数据
+                        List<InventoryFormApply> inventoryFormApplies2 = map.get(aLong);
+                        //同一清单的累计计量数量
+                        BigDecimal sum = new BigDecimal(0);
+                        for (InventoryFormApply inventoryFormApply : inventoryFormApplies2) {
+                            BigDecimal currentMeterTotal = inventoryFormApply.getCurrentMeterTotal();
+                            sum = sum.add(currentMeterTotal);
+                        }
+                        //计算当前清单集合的计量金额 = 累计计量数量 * 单价  四舍五入保留整数
+                        money =  money.add(sum.multiply(inventoryFormApplies2.get(0).getCurrentPrice()).setScale(0, BigDecimal.ROUND_HALF_UP));
+                    }
+                    //本期支付
+                    BigDecimal nowPeriodPay = money.multiply(new BigDecimal(0.75)).setScale(0, BigDecimal.ROUND_HALF_UP);
+                    //上期末累计支付
+                    lastEndPay = lastEndPay.add(nowPeriodPay);
+                    //上期末累计扣取保留金
+                    lastEndDeduct = lastEndDeduct.add(money.subtract(nowPeriodPay));
+                    //上期末累计计量
+                    allMoney = allMoney.add(money);
+                }
+            }
+            Cell a7 = getCellByAddress(sheet, "A7");
+            a7.setCellValue(allMoney.toString());
+            //---------------------------------------------------------------上期末累计支付---------------------------------------------------------------------------------------------------------
+            Cell c7 = getCellByAddress(sheet, "C7");
+            c7.setCellValue(lastEndPay.toString());
+            //---------------------------------------------------------------本期计量-----------------------------------------------------------------------------------------------------------
+            String sql3 = "SELECT id,contract_form_id,contract_meter_id,contract_id,current_price,current_meter_total FROM `s_inventory_form_apply` " +
+                    "WHERE contract_id = '"+contractId+"' and contract_period_id = "+contractMeterPeriodNowId;
+            List<InventoryFormApply> inventoryFormAppliesNow = jdbcTemplate.query(sql3, new BeanPropertyRowMapper<>(InventoryFormApply.class));
+            //按照清单id分组
+            Map<Long, List<InventoryFormApply>> map = inventoryFormAppliesNow.stream().collect(Collectors.groupingBy(InventoryFormApply::getContractFormId));
+            //本期计量量
+            BigDecimal AllcurrentMeterTotal = new BigDecimal(0);
+            for (Long l : map.keySet()) {
+                List<InventoryFormApply> inventoryFormApplies = map.get(l);
+                BigDecimal metetTotal = new BigDecimal(0);
+                for (InventoryFormApply inventoryFormApply : inventoryFormApplies) {
+                    BigDecimal metetnum = inventoryFormApply.getCurrentMeterTotal();
+                    metetTotal = metetTotal.add(metetnum);
+                }
+                AllcurrentMeterTotal = AllcurrentMeterTotal.add(metetTotal.multiply(inventoryFormApplies.get(0).getCurrentPrice()).setScale(0, BigDecimal.ROUND_HALF_UP));
+            }
+            Cell e7 = getCellByAddress(sheet, "E7");
+            e7.setCellValue(AllcurrentMeterTotal.toString());
+            //------------------------------------------------------------本期末累计计量------------------------------------------------------------
+            //上期末+本期
+            BigDecimal endMoney = allMoney.add(AllcurrentMeterTotal);
+            Cell g7 = getCellByAddress(sheet, "G7");
+            g7.setCellValue(endMoney.toString());
+            //------------------------------------------------------------本期支付------------------------------------------------------------
+            //本期计量 * 0.75
+            BigDecimal currentPay = AllcurrentMeterTotal.multiply(new BigDecimal(0.75)).setScale(0, BigDecimal.ROUND_HALF_UP);
+            Cell i7 = getCellByAddress(sheet, "I7");
+            i7.setCellValue(currentPay.toString());
+            //------------------------------------------------------------本期末累计支付------------------------------------------------------------
+            //上期末累计支付+本期支付
+            BigDecimal endPay = lastEndPay.add(currentPay);
+            Cell a9 = getCellByAddress(sheet, "A9");
+            a9.setCellValue(endPay.toString());
+            //------------------------------------------------------------累计支付百分数%------------------------------------------------------------
+            //本期末累计支付/变更后合同价 保留两位小数
+            BigDecimal percent = endPay.divide(changeMoney,2, BigDecimal.ROUND_HALF_UP);
+            BigDecimal multiply100 = percent.multiply(new BigDecimal(100));
+            Cell c9 = getCellByAddress(sheet, "C9");
+            c9.setCellValue(multiply100+"%");
+            //------------------------------------------------------------上期末累计扣取保留金------------------------------------------------------------
+            Cell e9 = getCellByAddress(sheet, "E9");
+            e9.setCellValue(lastEndDeduct.toString());
+            //------------------------------------------------------------本期扣取保留金------------------------------------------------------------
+            //本期扣取保留金=本期计量 - 本期支付
+            BigDecimal deductionMoney = AllcurrentMeterTotal.subtract(currentPay);
+            Cell g9 = getCellByAddress(sheet, "G9");
+            g9.setCellValue(deductionMoney.toString());
+            //------------------------------------------------------------本期末累计扣取保留金------------------------------------------------------------
+            //本期末累计扣取保留金=上期末累计扣取保留金+本期累计扣取保留金
+            BigDecimal endDeductionMoney = lastEndDeduct.add(deductionMoney);
+            Cell i9 = getCellByAddress(sheet, "I9");
+            i9.setCellValue(endDeductionMoney.toString());
+            //------------------------------------------------------------日期------------------------------------------------------------
+            //顶部日期
+            Cell g3 = getCellByAddress(sheet, "G3");
+            g3.setCellValue(endDate.toString());
+            //施工单位申报意见
+            Cell j11 = getCellByAddress(sheet, "J11");
+            j11.setCellValue(endDate.toString());
+            //监理单位审核
+            Cell j13 = getCellByAddress(sheet, "J13");
+            j13.setCellValue(endDate.toString());
+            //业务部门审核意见
+            Cell j16 = getCellByAddress(sheet, "J16");
+            j16.setCellValue(endDate.toString());
+            //财务部门审核意见
+            Cell j19 = getCellByAddress(sheet, "J19");
+            j19.setCellValue(endDate.toString());
+            //分管领导审核意见
+            Cell j22 = getCellByAddress(sheet, "J22");
+            j22.setCellValue(endDate.toString());
+            //主要领导审核意见
+            Cell j25 = getCellByAddress(sheet, "J25");
+            j25.setCellValue(endDate.toString());
+            //------------------------------------------------------------标题------------------------------------------------------------
+            CellStyle cellStyle = workbook.createCellStyle();
+            cellStyle.setWrapText(false);
+            String periodNumber = contractMeterPeriodNow.getPeriodNumber();
+            if(ObjectUtil.isNotEmpty(periodNumber)){
+                Cell e2 = getCellByAddress(sheet, "E2");
+                e2.setCellStyle(cellStyle);
+                e2.setCellValue(periodNumber);
+            }
+            //施工单位
+            Cell b3 = getCellByAddress(sheet, "B3");
+            b3.setCellValue("重庆交通建设(集团)有限责任公司");
+            //---------------------------结果存储redis---------------------------------
+            //上期末累计扣取保留金
+            redisTemplate.opsForValue().set(MeasurementStorage.PRE_END_RESERVE_MONEY +redisId, lastEndDeduct.toString());
+            //本期扣取保留金
+            redisTemplate.opsForValue().set(MeasurementStorage.CUR_END_RESERVE_MONEY +redisId, deductionMoney.toString());
+            //本期末累计扣取保留金
+            redisTemplate.opsForValue().set(MeasurementStorage.CUR_END_RESERVE_MONEY_SUM +redisId, endDeductionMoney.toString());
+            //本期计量
+            redisTemplate.opsForValue().set(MeasurementStorage.CUR_MEASUREMENT +redisId, AllcurrentMeterTotal.toString());
+
             String file_path = FileUtils.getSysLocalFileUrl();
-            //String file_path = "C://upload1//";
             String locationFile = file_path + SnowFlakeUtil.getId() + ".xlsx";
             outputStream = new FileOutputStream(locationFile);
             //生成一份新的excel
@@ -2215,9 +2893,9 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
         }
         NewBladeFile bladeFile = this.commonFileClient.excelToPdf(files);
         ReportResult reportResult = new ReportResult();
-        CompletableFuture<String> stringCompletableFuture = new CompletableFuture<>();
-        stringCompletableFuture.complete(bladeFile.getLink());
-        reportResult.setPdfOssPath(stringCompletableFuture);
+        reportResult.setOssPdfUrl(bladeFile.getPdfUrl());
+        reportResult.setPdfPath(bladeFile.getPdfUrl());
+        reportResult.setName("中间支付审核表");
         return reportResult;
 
     }

+ 130 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/utils/AmountToChineseConverter.java

@@ -0,0 +1,130 @@
+package org.springblade.manager.utils;
+
+import java.math.BigDecimal;
+
+public class AmountToChineseConverter {
+
+    private static final String[] CHINESE_DIGITS = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
+    private static final String[] UNITS = {"", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "万"};
+    private static final String[] DECIMAL_UNITS = {"角", "分"};
+
+    public static String convertToChinese(BigDecimal amount) {
+        if (amount.compareTo(BigDecimal.ZERO) < 0) {
+            throw new IllegalArgumentException("Amount must be non-negative");
+        }
+
+        // 将BigDecimal转换为字符串并分割整数部分和小数部分
+        String amountStr = amount.toPlainString();
+        int dotIndex = amountStr.indexOf('.');
+        String integerPartStr = dotIndex > 0 ? amountStr.substring(0, dotIndex) : amountStr;
+        String decimalPartStr = dotIndex > 0 ? amountStr.substring(dotIndex + 1) : "";
+
+        // 处理整数部分
+        StringBuilder result = new StringBuilder();
+        if (integerPartStr.equals("0")) {
+            result.append("零元整");
+        } else {
+            result.append(convertIntegerPart(new BigDecimal(integerPartStr))).append("元");
+        }
+
+        // 处理小数部分
+        if (!decimalPartStr.isEmpty()) {
+            String decimalResult = convertDecimalPart(decimalPartStr);
+            if (!decimalResult.isEmpty()) {
+                result.append(decimalResult);
+            } else {
+                result.append("整");
+            }
+        } else {
+            result.append("整");
+        }
+
+        return result.toString();
+    }
+
+    private static String convertIntegerPart(BigDecimal number) {
+        if (number.compareTo(BigDecimal.ZERO) == 0) {
+            return "";
+        }
+
+        StringBuilder result = new StringBuilder();
+        String numberStr = number.toPlainString();
+
+        // 分割成亿、万和个位部分
+        String yiPart = numberStr.length() > 8 ? numberStr.substring(0, numberStr.length() - 8) : "";
+        String wanPart = numberStr.length() > 4 ? numberStr.substring(numberStr.length() - 8, numberStr.length() - 4) : "";
+        String gePart = numberStr.length() > 4 ? numberStr.substring(numberStr.length() - 4) : numberStr;
+
+        if (!yiPart.isEmpty()) {
+            result.append(convertPart(yiPart)).append("亿");
+        }
+        if (!wanPart.isEmpty()) {
+            result.append(convertPart(wanPart)).append("万");
+        }
+        if (!gePart.isEmpty()) {
+            result.append(convertPart(gePart));
+        }
+
+        // 去掉多余的“零”
+        while (result.indexOf("零") == result.lastIndexOf("零") && result.indexOf("零") != -1) {
+            result.deleteCharAt(result.indexOf("零"));
+        }
+
+        return result.toString();
+    }
+
+    private static String convertPart(String part) {
+        StringBuilder result = new StringBuilder();
+        boolean hasNonZero = false;
+
+        for (int i = 0; i < part.length(); i++) {
+            char digitChar = part.charAt(part.length() - 1 - i);
+            int digit = Character.digit(digitChar, 10);
+
+            if (digit == 0) {
+                if (hasNonZero) {
+                    result.insert(0, CHINESE_DIGITS[digit]);
+                    hasNonZero = false;
+                }
+            } else {
+                result.insert(0, CHINESE_DIGITS[digit] + UNITS[i]);
+                hasNonZero = true;
+            }
+        }
+
+        return result.toString();
+    }
+
+    private static String convertDecimalPart(String decimalPartStr) {
+        StringBuilder result = new StringBuilder();
+
+        // 确保小数部分最多两位
+        if (decimalPartStr.length() > 2) {
+            decimalPartStr = decimalPartStr.substring(0, 2);
+        }
+
+        for (int i = 0; i < decimalPartStr.length(); i++) {
+            char digitChar = decimalPartStr.charAt(i);
+            int digit = Character.digit(digitChar, 10);
+
+            if (digit > 0) {
+                result.append(CHINESE_DIGITS[digit]).append(DECIMAL_UNITS[i]);
+            }
+        }
+
+        // 如果小数部分为空,添加“整”
+        if (result.length() == 0) {
+            result.append("整");
+        }
+
+        return result.toString();
+    }
+
+    public static void main(String[] args) {
+        BigDecimal amount = new BigDecimal("713.12");
+        System.out.println(amount + " 转换为中文大写: " + convertToChinese(amount));
+
+        BigDecimal largeAmount = new BigDecimal("121234567890123.45");
+        System.out.println(largeAmount + " 转换为中文大写: " + convertToChinese(largeAmount));
+    }
+}

+ 23 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/utils/FileUtils.java

@@ -501,6 +501,29 @@ public class FileUtils {
         }
         return fileInputStream;
     }
+    //根据流存储文件到本地
+    public static void saveFile(InputStream inputStream, String filePath) {
+
+        String localFilePath = filePath; // 本地文件路径
+
+        try (
+             FileOutputStream outputStream = new FileOutputStream(localFilePath)) {
+
+            byte[] buffer = new byte[1024];
+            int length;
+
+            while ((length = inputStream.read(buffer)) > 0) {
+                outputStream.write(buffer, 0, length);
+            }
+
+            System.out.println("文件下载成功,保存路径: " + localFilePath);
+
+        } catch (IOException e) {
+            e.printStackTrace();
+            System.err.println("文件下载失败: " + e.getMessage());
+        }
+
+    }
 
     public static String getNetUrl(String fileUrl){
         String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);

+ 25 - 3
blade-service/blade-meter/src/main/java/org/springblade/meter/controller/TaskController.java

@@ -3670,9 +3670,32 @@ public class TaskController extends BladeController {
         /*分为新增和更新*/
         /*如果数据没有变化,则各表的PDF可以不用更新*/
         ExecutionTime executionTime = new ExecutionTime();
-        List<ReportResult> reportResults;
-        if(ObjectUtil.isNotEmpty(report.getProjectId())&&report.getProjectId().equals(1764484458576179201L)){
+        List<ReportResult> reportResults=new ArrayList<>();
+        if(ObjectUtil.isNotEmpty(report.getPeriodId())&&report.getProjectId().equals(1764484458576179201L)){
              reportResults=formulaClient.formulaExecute4(report.getContractId(),report.getPeriodId(),report.getType(),report.getProjectId());
+            /*合并所有表*/
+            String file_path = CollectionUtils.getSysLocalFileUrl();
+            Long dataId = SnowFlakeUtil.getId();
+            String lasPdf = file_path + "/pdf//" + dataId + "_last.pdf";
+            CollectionUtils.mergePdfPublicMethods(reportResults.stream().map(ReportResult::getPdfPath).collect(Collectors.toList()), lasPdf);
+            BladeFile bladeFile = newIOSSClient.uploadFile(dataId + "_last.pdf", lasPdf);
+            String rawPdfUrL = bladeFile.getLink();
+            StringBuilder stringBuilder = new StringBuilder("{");
+            for (ReportResult reportResult : reportResults) {
+                String name = reportResult.getName();
+                String pdfOssPath = reportResult.getOssPdfUrl();
+                stringBuilder.append("\"");
+                stringBuilder.append(name);
+                stringBuilder.append("\":\"");
+                stringBuilder.append(pdfOssPath);
+                stringBuilder.append("\",");
+            }
+            stringBuilder.deleteCharAt(stringBuilder.length() - 1);
+            stringBuilder.append("}");
+            String string = stringBuilder.toString();
+            String sqlUpdate = "update s_interim_pay_certificate set file_url_list = '"+string +"',raw_url = '"+rawPdfUrL+"' where id = "+report.getId();
+            jdbcTemplate.execute(sqlUpdate);
+            return R.data(rawPdfUrL);
         }else{
              reportResults = formulaClient.formulaExecute3(report.getContractId(), report.getId(), report.getType());
         executionTime.info("公式执行");
@@ -4265,7 +4288,6 @@ public class TaskController extends BladeController {
         report.setContractId(Long.parseLong(map.get("contract_id").toString()));
         report.setPeriodId(Long.parseLong(map.get("period_id").toString()));
         report.setProjectId(Long.parseLong(map.get("project_id").toString()));
-
         return report;
     }
 

+ 1 - 1
blade-service/blade-meter/src/main/java/org/springblade/meter/mapper/MiddleMeterApplyMapper.xml

@@ -150,7 +150,7 @@
 
     </select>
     <select id="meterPeriodAllForm" resultType="org.springblade.meter.vo.MeterInventoryDetailVO">
-        SELECT cif.id,ifa.meter_number,cif.form_number,cif.form_name,,cif.unit,cif.current_price,cif.change_total,ifa.current_meter_total,ifa.current_meter_money,ifa.contract_form_id,
+        SELECT cif.id,ifa.meter_number,cif.form_number,cif.form_name,cif.unit,cif.current_price,cif.change_total,ifa.current_meter_total,ifa.current_meter_money,ifa.contract_form_id,
                (select period_number from s_contract_meter_period cmp where cmp.id = ifa.contract_period_id) as meterPeriodName,
                 (select engineer_divide from s_middle_meter_apply mma where mma.id = ifa.middle_meter_id) as engineerDivide,
                CASE when (select approve_status from s_middle_meter_apply mma where mma.id = ifa.middle_meter_id) = 0 then '未上报' when (select approve_status from s_middle_meter_apply mma where mma.id = ifa.middle_meter_id) = 1 then '待审批' when (select approve_status from s_middle_meter_apply mma where mma.id = ifa.middle_meter_id) = 2 then '已审批'