Kaynağa Gözat

计量材料pdf

zhuwei 1 yıl önce
ebeveyn
işleme
6addfd162c

+ 5 - 0
blade-service-api/blade-meter-api/src/main/java/org/springblade/meter/entity/MaterialStartStatement.java

@@ -21,6 +21,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
 import java.io.Serializable;
 import java.time.LocalDate;
 
+import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import org.springblade.core.mp.base.BaseEntity;
 import lombok.Data;
@@ -35,6 +36,7 @@ import lombok.EqualsAndHashCode;
 @Data
 @TableName("s_material_start_statement")
 @EqualsAndHashCode(callSuper = true)
+@ApiModel(value = "材料和开工报表实体类", description = "材料和开工报表实体类")
 public class MaterialStartStatement extends BaseEntity {
 
     private static final long serialVersionUID = 1L;
@@ -98,5 +100,8 @@ public class MaterialStartStatement extends BaseEntity {
     @ApiModelProperty(value = "审批状态,0未上报,1待审批,2已审批")
     private Integer approveStatus;
 
+    @ApiModelProperty(value = "pdfUrl")
+    private String rawUrl;
+
 
 }

+ 6 - 0
blade-service/blade-meter/pom.xml

@@ -69,6 +69,12 @@
             <version>2.9.1.RELEASE</version>
             <scope>compile</scope>
         </dependency>
+        <dependency>
+            <groupId>com.itextpdf</groupId>
+            <artifactId>itextpdf</artifactId>
+            <version>5.5.13</version>
+            <scope>compile</scope>
+        </dependency>
     </dependencies>
 
 </project>

+ 114 - 96
blade-service/blade-meter/src/main/java/org/springblade/meter/controller/TaskController.java

@@ -43,7 +43,9 @@ import org.springblade.manager.feign.FormulaClient;
 import org.springblade.manager.vo.ReportResult;
 import org.springblade.meter.dto.*;
 import org.springblade.meter.entity.*;
+import org.springblade.meter.mapper.MaterialStartStatementMapper;
 import org.springblade.meter.mapper.MiddleMeterApplyMapper;
+import org.springblade.meter.service.IMaterialStartStatementService;
 import org.springblade.meter.service.impl.*;
 import org.springblade.meter.utils.CollectionUtils;
 import org.springblade.meter.vo.*;
@@ -98,6 +100,8 @@ public class TaskController extends BladeController {
     private final ChangeTokenInventoryServiceImpl changeTokenInventoryService;
     private final ChangeTokenInventoryServiceTaskImpl changeTokenInventoryServiceTask;
 
+    private final IMaterialStartStatementService materialStartStatementService;
+
     // 计量公式入口
     private final FormulaClient formulaClient;
 
@@ -2059,22 +2063,21 @@ public class TaskController extends BladeController {
     // pdf 生成
     private boolean meterPdfInfo(Task task) {
         // 材料生成pdf
-        if(task.getType()==2){
+        if (task.getType() == 2) {
             // 获取填报数据
 
             // 调用公式
-            List<ReportResult> reportResults = formulaClient.formulaExecute3(Long.parseLong(task.getContractId()), Long.parseLong(task.getFormDataId()),1);
+            List<ReportResult> reportResults = formulaClient.formulaExecute3(Long.parseLong(task.getContractId()), Long.parseLong(task.getFormDataId()), 1);
             //生成pdf
-            String fen ="SELECT * from m_wbs_tree_private WHERE project_id='"+task.getProjectId()+"' and wbs_type=3 and parent_id=(SELECT id from m_wbs_tree_private where project_id='"+task.getProjectId()+"' and is_deleted=0 and type=1 and wbs_type=3 and node_type=31)" +
+            String fen = "SELECT * from m_wbs_tree_private WHERE project_id='" + task.getProjectId() + "' and wbs_type=3 and parent_id=(SELECT id from m_wbs_tree_private where project_id='" + task.getProjectId() + "' and is_deleted=0 and type=1 and wbs_type=3 and node_type=31)" +
                     "AND type = 2 AND status = 1 and is_deleted= 0 ORDER BY sort";
-            WbsTreePrivate wbsTreePrivate = jdbcTemplate.query(fen, new BeanPropertyRowMapper<>(WbsTreePrivate.class)).stream().findAny().orElse(null);;
-
+            WbsTreePrivate wbsTreePrivate = jdbcTemplate.query(fen, new BeanPropertyRowMapper<>(WbsTreePrivate.class)).stream().findAny().orElse(null);
+            ;
 
 
         }
 
 
-
         return true;
     }
 
@@ -2442,112 +2445,127 @@ public class TaskController extends BladeController {
     }
 
 
-
-
-    @GetMapping("/meterPdfInfo22")
+    @GetMapping("/meterPdfInfo")
     @ApiOperationSupport(order = 20)
     @ApiOperation(value = "计量生成Pdf", notes = "计量生成Pdf")
-    public R meterPdfInfo22(@RequestParam String  ContractId,@RequestParam String FormDataId,@RequestParam Integer type){
+    public R meterPdfInfo(@RequestParam String ContractId, @RequestParam String FormDataId, @RequestParam Integer type) {
         String file_path = CollectionUtils.getSysLocalFileUrl();
+        String fileUrl = "";
+        Long sid = 0l;
+        MaterialStartStatement materialS = materialStartStatementService.getBaseMapper().selectOne(Wrappers.<MaterialStartStatement>lambdaQuery().eq(MaterialStartStatement::getContractId, ContractId).eq(MaterialStartStatement::getMeterPeriodId, FormDataId).eq(MaterialStartStatement::getType, 1));
+        if (materialS == null || Func.isNull(materialS)) {
+            MeterPeriod me = periodService.getById(FormDataId);
+            MaterialStartStatement data = new MaterialStartStatement();
+            data.setMeterPeriodId(Func.toLong(FormDataId));
+            data.setPrintDate(me.getFormPrintDate());
+            data.setRepaymentCause("材料预付款");
+            data.setStatementName("材料预付款--" + me.getPeriodName());
+            materialStartStatementService.addOrUpdate(data);
+            sid = data.getId();
+        } else {
+            sid = materialS.getId();
+        }
+        List<ReportResult> sul = new ArrayList<>();
         // 材料生成pdf
-        if(type==2){
-            // 获取填报数据
-            String sql = "SELECT * FROM s_material_start_statement where contract_id="+ContractId+" and type=1 and meter_period_id="+FormDataId+"";
-            Map<String, Object> dataInfo = jdbcTemplate.queryForMap(sql);
-            Long sid = Func.toLong(dataInfo.get("id"));
-            // 调用公式
-            List<ReportResult> sul = formulaClient.formulaExecute3(Long.parseLong(ContractId), sid,1);
-            if(sul!=null && sul.size()>=1){
-                for(ReportResult data:sul){
-                    Long excelId = data.getExcelId();
-                    String exSql = "SELECT * from m_excel_tab where id="+excelId+"";
-                    Map<String, Object> exMap = jdbcTemplate.queryForMap(exSql);
-                    if (exMap == null) {
-                        return R.fail("未获取到该表单的信息");
-                    }
-                    if (exMap.get("file_url") == null) {
-                        return R.fail("htmlUrl is null");
-                    }
-                    String pkeyId=sid+""+excelId;
-                    String pdfPath = file_path + "/pdf//" + pkeyId + ".pdf";
-                    String excelPath = file_path + "/pdf//" + pkeyId + ".xlsx";
 
-                    String excelUrl = exMap.get("file_url")+"";
+        sul = formulaClient.formulaExecute3(Long.parseLong(ContractId), sid, type);
+        // 获取填报数据
+        List<String> dataListPdf = new ArrayList<>();
+
+        if (sul != null && sul.size() >= 1) {
+            for (ReportResult data : sul) {
+                Long excelId = data.getExcelId();
+                String exSql = "SELECT * from m_excel_tab where id=" + excelId + "";
+                Map<String, Object> exMap = jdbcTemplate.queryForMap(exSql);
+                if (exMap == null) {
+                    return R.fail("未获取到该表单的信息");
+                }
+                if (exMap.get("file_url") == null) {
+                    return R.fail("htmlUrl is null");
+                }
+                String pkeyId = sid + "" + excelId;
+                String pdfPath = file_path + "/pdf//" + pkeyId + ".pdf";
+                String excelPath = file_path + "/pdf//" + pkeyId + ".xlsx";
 
-                    File tabPdf = null;
-                    try {
-                        tabPdf = ResourceUtil.getFile(pdfPath);
-                    } catch (FileNotFoundException e) {
-                        throw new RuntimeException(e);
-                    }
-                    if (tabPdf.exists()) {
-                        tabPdf.delete();
-                    }
+                String excelUrl = exMap.get("file_url") + "";
 
-                    List<Map<String, Object>> data1 = data.getData();
-                    //获取excel流 和 html流
-                    try {
-                        InputStream exceInp = CommonUtil.getOSSInputStream(excelUrl);
-                        Workbook workbook = null;
-                        int index = excelUrl.lastIndexOf(".");
-                        String suffix = excelUrl.substring(index).toLowerCase();
-
-                        if (".xls".equals(suffix)) {
-                            workbook = new XSSFWorkbook(exceInp);
-                        } else if (".xlsx".equals(suffix)) {
-                            workbook = new XSSFWorkbook(exceInp);
-                        }
-                        //获取工作表
-                        Sheet sheet = workbook.getSheetAt(0);
-                        sheet.setForceFormulaRecalculation(true);
-
-                        // 写入数据
-                        List<Map<String, Object>> dataData = data.getData();
-                        if(dataData!=null && dataData.size()>=1){
-                            for(Map<String, Object> dama:dataData){
-
-                                // 循环Key
-                                for(String keys:dama.keySet()){
-                                    int y1 = Func.toInt(keys.split("_")[0]);
-                                    int x1 = Func.toInt(keys.split("_")[1]);
-                                    Row row = sheet.getRow(y1 - 1);
-                                    if (row != null) {
-                                        Cell cell = row.getCell(x1 - 1);
-                                        String dataval = dama.get(keys)+"";
-                                        if(dataval.indexOf("第")>=0 && dataval.indexOf("次支付")>=0){
-                                            String datare = dataval.replace("第","").replace("次交付","");
-                                            dataval = datare.replace("次支付","");
-                                        }
-                                        cell.setCellValue(dataval);
+                File tabPdf = null;
+                try {
+                    tabPdf = ResourceUtil.getFile(pdfPath);
+                } catch (FileNotFoundException e) {
+                    throw new RuntimeException(e);
+                }
+                if (tabPdf.exists()) {
+                    tabPdf.delete();
+                }
+
+
+                //获取excel流 和 html流
+                try {
+                    InputStream exceInp = CommonUtil.getOSSInputStream(excelUrl);
+                    Workbook workbook = null;
+                    int index = excelUrl.lastIndexOf(".");
+                    String suffix = excelUrl.substring(index).toLowerCase();
+
+                    if (".xls".equals(suffix)) {
+                        workbook = new XSSFWorkbook(exceInp);
+                    } else if (".xlsx".equals(suffix)) {
+                        workbook = new XSSFWorkbook(exceInp);
+                    }
+                    //获取工作表
+                    Sheet sheet = workbook.getSheetAt(0);
+                    sheet.setForceFormulaRecalculation(true);
+
+                    // 写入数据
+                    List<Map<String, Object>> dataData = data.getData();
+                    if (dataData != null && dataData.size() >= 1) {
+                        for (Map<String, Object> dama : dataData) {
+
+                            // 循环Key
+                            for (String keys : dama.keySet()) {
+                                int y1 = Func.toInt(keys.split("_")[0]);
+                                int x1 = Func.toInt(keys.split("_")[1]);
+                                Row row = sheet.getRow(y1 - 1);
+                                if (row != null) {
+                                    Cell cell = row.getCell(x1 - 1);
+                                    String dataval = dama.get(keys) + "";
+                                    if (dataval.indexOf("第") >= 0 && dataval.indexOf("次支付") >= 0) {
+                                        String datare = dataval.replace("第", "").replace("次交付", "");
+                                        dataval = datare.replace("次支付", "");
                                     }
+                                    cell.setCellValue(dataval);
                                 }
                             }
                         }
-
-                        //输出流
-                        FileOutputStream outputStream = new FileOutputStream(excelPath);
-                        workbook.write(outputStream);
-
-                        CollectionUtils.excelToPdf(excelPath, pdfPath);
-                        BladeFile bladeFile = newIOSSClient.uploadFile(pkeyId + ".pdf", pdfPath);
-
-                        /*UpdateWrapper<WbsTreeContract> updateWrapper = new UpdateWrapper<>();
-                        updateWrapper.in("p_key_id", pkeyId + "");
-                        updateWrapper.set("pdf_url", fileUrl);
-                        updateWrapper.set("real_fill_rate", realFillRate);
-                        wbsTreeContractService.update(updateWrapper);*/
-
-                        //关闭流
-                        IoUtil.closeQuietly(outputStream);
-                        IoUtil.closeQuietly(exceInp);
-                    } catch (Exception e) {
-                        throw new RuntimeException(e);
                     }
+
+                    //输出流
+                    FileOutputStream outputStream = new FileOutputStream(excelPath);
+                    workbook.write(outputStream);
+                    CollectionUtils.excelToPdf(excelPath, pdfPath);
+                    dataListPdf.add(pdfPath);
+                    //关闭流
+                    IoUtil.closeQuietly(outputStream);
+                    IoUtil.closeQuietly(exceInp);
+                } catch (Exception e) {
+                    throw new RuntimeException(e);
                 }
             }
         }
 
-        return R.success("1234");
+        Long dataId = SnowFlakeUtil.getId();
+        String lasPdf = file_path + "/pdf//" + dataId + "_last.pdf";
+
+        if (dataListPdf.size() > 0) {
+            CollectionUtils.mergePdfPublicMethods(dataListPdf, lasPdf);
+            BladeFile bladeFile2 = newIOSSClient.uploadFile(dataId + "_last.pdf", lasPdf);
+            fileUrl = bladeFile2.getLink();
+        }
+
+        String upSql = "update s_material_start_statement set raw_url='" + fileUrl + "' where contract_id=" + ContractId + " and type=1 and meter_period_id=" + FormDataId + "";
+        jdbcTemplate.execute(upSql);
+
+        return R.success(fileUrl);
     }
 
 }

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

@@ -22,6 +22,7 @@
         <result column="repayment_cause" property="repaymentCause"/>
         <result column="calculate_date" property="calculateDate"/>
         <result column="sort" property="sort"/>
+        <result column="raw_url" property="rawUrl"/>
     </resultMap>
     <select id="page2" resultType="org.springblade.meter.entity.MaterialStartStatement">
         select *

+ 55 - 0
blade-service/blade-meter/src/main/java/org/springblade/meter/utils/CollectionUtils.java

@@ -1,16 +1,21 @@
 package org.springblade.meter.utils;
 
 import com.aspose.cells.SaveFormat;
+import com.itextpdf.text.Document;
+import com.itextpdf.text.pdf.PdfCopy;
+import com.itextpdf.text.pdf.PdfReader;
 import org.apache.poi.ss.usermodel.PrintSetup;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.WorkbookFactory;
 import org.springblade.common.constant.CommonConstant;
+import org.springblade.common.utils.CommonUtil;
 import org.springblade.common.utils.SystemUtils;
 import org.springblade.core.tool.utils.IoUtil;
 import org.springblade.core.tool.utils.ResourceUtil;
 import org.springblade.system.cache.ParamCache;
 
 import java.io.*;
+import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.concurrent.ConcurrentHashMap;
@@ -100,4 +105,54 @@ public class CollectionUtils {
             }
         }
     }
+
+    /**
+     * 合并方法
+     */
+    public static void mergePdfPublicMethods(List<String> urlList, String localImgUrl) {
+        PdfReader reader = null;
+
+        Document doc = new Document();
+        PdfCopy pdfCopy = null;
+        try {
+            pdfCopy = new PdfCopy(doc, new FileOutputStream(localImgUrl));
+            int pageCount;
+            doc.open();
+
+            for (String urlStr : urlList) {
+                try {
+                    //获取OSS文件输入流
+                    if(urlStr.indexOf("http")>=0){
+                        reader = new PdfReader(Objects.requireNonNull(CommonUtil.getOSSInputStream(urlStr)));
+                    }else{
+                        reader = new PdfReader(Objects.requireNonNull(new FileInputStream(new File(urlStr))));
+                    }
+
+
+                    pageCount = reader.getNumberOfPages();
+
+                    for (int i = 0; i < pageCount; ++i) {
+                        int is = i + 1;
+                        pdfCopy.addPage(pdfCopy.getImportedPage(reader, is));
+                    }
+                } catch (Exception e) {
+                    e.printStackTrace();
+                } finally {
+                    if (reader != null) {
+                        reader.close();
+                    }
+                }
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            if (pdfCopy != null) {
+                pdfCopy.flush();
+                pdfCopy.close();
+            }
+            doc.close();
+        }
+    }
+
 }