浏览代码

计量报表写入功能重置

yangyj 1 年之前
父节点
当前提交
cd3519c7b5

+ 119 - 0
blade-service/blade-meter/src/main/java/org/springblade/meter/controller/TaskController.java

@@ -12,6 +12,7 @@ import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
+import lombok.Data;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.time.DateUtils;
 import org.apache.poi.ss.usermodel.Cell;
@@ -38,6 +39,7 @@ import org.springblade.core.tool.utils.*;
 import org.springblade.feign.ArchiveFileTaskClient;
 import org.springblade.manager.entity.ContractInfo;
 import org.springblade.manager.entity.ContractRelationJlyz;
+import org.springblade.manager.entity.ExcelTab;
 import org.springblade.manager.entity.WbsTreePrivate;
 import org.springblade.manager.feign.FormulaClient;
 import org.springblade.manager.vo.ReportResult;
@@ -2572,4 +2574,121 @@ public class TaskController extends BladeController {
         return R.success(fileUrl);
     }
 
+
+    /*中期支付证书报表、开工、材料手册报表*/
+    public void generateReportsPdf(Report report){
+        /*报表记录新增或者重算的时候会调用当前方法,生成PDF*/
+        /*保存两类PDF,一每种表独立一份放标浏览,二合成表用于电签*/
+        /*数据完全独立互不影响,可以并发生成,预估PDF的总大小来绝对是否全部在内存中生成PDF*/
+        List<ReportResult> reportResults = formulaClient.formulaExecute3(report.getContractId(), report.getId(), report.getType());
+        if(Func.isNotEmpty(reportResults)){
+            List<String> dataListPdf = new ArrayList<>();
+            String file_path = CollectionUtils.getSysLocalFileUrl();
+            String fileUrl = "";
+            Long sid = 0L;
+            for (ReportResult data : reportResults) {
+                Long excelId = data.getExcelId();
+                String exSql = "SELECT * from m_excel_tab where id=" + excelId + "";
+               // ExcelTab
+                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") + "";
+
+                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);
+                    dataListPdf.add(pdfPath);
+                    //关闭流
+                    IoUtil.closeQuietly(outputStream);
+                    IoUtil.closeQuietly(exceInp);
+                } catch (Exception e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        }
+
+    }
+
+    @Data
+   static class Report{
+        public static final String[] REPORT_TYPE=new String[]{"s_material_start_statement","s_interim_pay_certificate"};
+        public static final String[] PERIOD_TYPE=new String[]{"s_contract_meter_period","s_meter_period"};
+        /**报表记录id*/
+        private Long id;
+        /**报表PDF地址*/
+        private String pdfUrl;
+        /*报表对应计量期Id*/
+        private Long periodId;
+        /**计量期ID*/
+        private Long contractId;
+        /**计量类型,0中间计量 1材料,2开工动员*/
+        private Integer type;
+   }
+
+   public Report generateReport(String reportId,Integer type){
+        return new Report();
+   }
+
+
+
 }