Переглянути джерело

Merge branch 'master' of http://softwarescience.top:3000/RWA/RWAServer

ZhangYanJie 2 тижнів тому
батько
коміт
7888dc4ae6

+ 1 - 1
Procedure/backend/project/src/main/java/com/sundata/product/rwa/calc/controllers/CalcRunningController.java

@@ -77,7 +77,7 @@ public class CalcRunningController extends BaseAction {
     public CalcTaskResult startReportInit(@RequestBody CalcInterfaceParam calcInterfaceParam) {
         Map<String, Object> context = new HashMap<>();
         context.put("dataDate", calcInterfaceParam.getDataDate());
-        return calcRunningService.startCalc(calcInterfaceParam.getCalculateInstanceNumber(), new ReportInitUnit(calcInterfaceParam.getCalculateInstanceNumber(), calcInterfaceParam.getCalcCode(), 0, null), context);
+        return calcRunningService.startCalc(calcInterfaceParam.getCalculateInstanceNumber(), new ReportInitUnit(calcInterfaceParam.getCalcCode(), calcInterfaceParam.getCalcCode(), 0, null), context);
     }
 
 

+ 37 - 29
Procedure/backend/project/src/main/java/com/sundata/product/rwa/calc/service/ReportCalcService.java

@@ -3,6 +3,8 @@ package com.sundata.product.rwa.calc.service;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.date.TimeInterval;
 import cn.hutool.core.lang.UUID;
+import cn.hutool.core.util.NumberUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.hutool.extra.spring.SpringUtil;
 import com.sundata.common.util.DBExecutor;
 import com.sundata.common.util.FileUtil;
@@ -15,6 +17,8 @@ import com.sundata.product.rwa.util.CollectionToMapConverter;
 import com.sundata.product.rwa.util.DataUtil;
 import org.apache.commons.text.StringSubstitutor;
 import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.util.CellUtil;
+import org.apache.poi.ss.util.SheetUtil;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.jxls.builder.JxlsOutputFile;
 import org.jxls.transform.poi.JxlsPoiTemplateFillerBuilder;
@@ -108,7 +112,7 @@ public class ReportCalcService {
 
                 Map<String, List<ReportCalculationModel>> selectCalcReportDatas = service.selectCalcReportData(reportDefinitionModel.getReportNo());
                 // 这张报表需要公式计算的 计算单元,配置中,需要明确,一旦公式类型,必须配置Excel来源公式 字典:UNIT_STYLE_TYPE
-                List<ReportCalculationModel> fillInCalcs = selectCalcReportDatas.get("FillIn").stream().filter(e -> "1".equals(e.getUnitStyleType())).toList();
+                List<ReportCalculationModel> fillInCalcs = new ArrayList<>(selectCalcReportDatas.get("FillIn").stream().filter(e -> "1".equals(e.getUnitStyleType())).toList());
                 File tempTmpFile = createTempReport(reportDefinitionModel, calcIndex, dataDate, context);
                 tempTmpFiles.add(tempTmpFile);
                 log.debug("复制临时模板文件内容到 mainTmpWorkbook 文件中,并将配置的Excel公式,其他报表来源公式均配置到 mainTmpWorkbook 中");
@@ -123,33 +127,36 @@ public class ReportCalcService {
                         for (int j = tempSheet.getFirstRowNum(); j < tempSheet.getLastRowNum(); j++) {
                             int finalJ = j;
                             List<ReportCalculationModel> thisRowNumModel = thisSheetNumModel.stream().filter(e -> finalJ == (e.getReportUnitRow())).toList();
-                            Row tempRow = tempSheet.getRow(j);
+                            Row tempRow = CellUtil.getRow(j,tempSheet);
                             if (tempRow != null) {
                                 Row mainTmpRow = mainTmpSheet.createRow(j);
                                 for (int k = tempRow.getFirstCellNum(); k < tempRow.getLastCellNum(); k++) {
                                     int finalK = k;
-                                    List<ReportCalculationModel> thisCellNumModel = thisSheetNumModel.stream().filter(e -> finalK == (e.getReportUnitCell())).toList();
-                                    Cell tempCell = tempRow.getCell(k);
-                                    Cell mainTmpCell = null;
+                                    List<ReportCalculationModel> thisCellNumModel = thisRowNumModel.stream().filter(e -> finalK == (e.getReportUnitCell())).toList();
+                                    Cell tempCell = CellUtil.getCell(tempRow,k);
+                                    Cell mainTmpCell = CellUtil.getCell(mainTmpRow,k);;
+                                    if (thisCellNumModel.size() == 1) {
+                                        log.debug("读取该报表配置中的手动配置公式的单元格");
+                                        // 将对应配置的参数处理为公式内容
+                                        mainTmpCell.setCellFormula(thisCellNumModel.get(0).getUnitCalcInfo());
+                                        continue;
+                                    }
                                     if (tempCell != null) {
-                                        mainTmpCell = mainTmpRow.createCell(k);
                                         switch (tempCell.getCellType()) {
                                             case STRING -> mainTmpCell.setCellValue(tempCell.getStringCellValue());
                                             case NUMERIC -> mainTmpCell.setCellValue(tempCell.getNumericCellValue());
-                                            case FORMULA -> mainTmpCell.setCellFormula(tempCell.getCellFormula());
+                                            case FORMULA -> {
+                                                if (StrUtil.isEmpty(tempCell.getCellFormula())) {
+                                                    mainTmpCell.setCellFormula("");
+                                                }else {
+                                                    mainTmpCell.setCellFormula(tempCell.getCellFormula());
+                                                }
+
+                                            }
                                             default -> mainTmpCell.setCellValue("");
                                         }
                                     }
-                                    if (thisCellNumModel.size() == 1) {
-                                        log.debug("读取该报表配置中的手动配置公式的单元格");
-                                        if (mainTmpRow.getCell(k) == null) {
-                                            mainTmpCell = mainTmpRow.getCell(k);
-                                        } else {
-                                            mainTmpCell = mainTmpRow.createCell(k);
-                                        }
-                                        // 将对应配置的参数处理为公式内容
-                                        mainTmpCell.setCellFormula(thisCellNumModel.get(0).getUnitCalcInfo());
-                                    }
+
                                 }
                             }
                         }
@@ -315,25 +322,26 @@ public class ReportCalcService {
                     if (sheet == null) {
                         sheet = workbook.createSheet();
                     }
-                    Row row = sheet.getRow(reportCalculationModel.getReportUnitRow());
-                    if (row == null) {
-                        row = sheet.createRow(reportCalculationModel.getReportUnitRow());
-                    }
-                    Cell cell = row.createCell(reportCalculationModel.getReportUnitCell());
-                    if (cell == null) {
-                        cell = row.createCell(reportCalculationModel.getReportUnitCell());
-                    }
-                    if ("1".equals(reportCalculationModel.getUnitType())) {
+                    Row row = CellUtil.getRow(reportCalculationModel.getReportUnitRow(),sheet);
+                    Cell cell = CellUtil.getCell(row,reportCalculationModel.getReportUnitCell());
+                    if ("1".equals(reportCalculationModel.getUnitStyleType())) {
                         // 如果单元格类型是公式
                         cell.setCellFormula(reportCalculationModel.getUnitCalcInfo());
-                    } else if ("2".equals(reportCalculationModel.getUnitType())) {
+                    } else if ("2".equals(reportCalculationModel.getUnitStyleType())) {
                         // 如果单元格类型是字符串
                         cell.setCellValue(String.valueOf(reportUnitParamCalcModel.getValue()));
-                    } else if ("3".equals(reportCalculationModel.getUnitType())) {
+                    } else if ("3".equals(reportCalculationModel.getUnitStyleType())) {
                         // 如果单元格类型是数字
-                        cell.setCellValue((Double) DataUtil.getDataDefault(reportUnitParamCalcModel.getValue(), Double.class));
+                        String value = String.valueOf(reportUnitParamCalcModel.getValue());
+                        if ("null".equals(value)) {
+                            value = "0.0";
+                        }
+                        cell.setCellValue(NumberUtil.parseDouble(value,0.0));
+                    } else {
+                        cell.setCellValue("");
                     }
                 }
+                workbook.getCreationHelper().createFormulaEvaluator().evaluateAll();
                 workbook.write(Files.newOutputStream(tempTmpFilePath.toPath()));
                 workbook.close();
             } catch (IOException e) {

+ 9 - 1
Procedure/backend/project/src/main/java/com/sundata/product/rwa/calc/service/ReportUnitParamCalcService.java

@@ -49,6 +49,8 @@ public class ReportUnitParamCalcService {
 
         List<ReportUnitParamCalcModel> models = new ArrayList<>();
         log.debug("开始报表计算单元的处理,报表编号:{},计算单元条目数:{}", reportno, modelList.size());
+//        String delete = "delete from RWA_SYSTEM_REPORT_PROCESS_TABLEUNIT where CALCINDEX = :CALCINDEX";
+//        jdbcTemplate.update(delete, sqlParam);
         for (ReportCalculationModel reportCalculationModel : modelList) {
             // 时间
             TimeInterval timeInterval = new TimeInterval();
@@ -68,12 +70,18 @@ public class ReportUnitParamCalcService {
             paramCalcModel.setValue(model.getValue());
             models.add(paramCalcModel);
 
-            String sql = "INSERT INTO RWA_SYSTEM_REPORT_PROCESS_TABLEUNIT(CALCINDEX, SDATE, EDATE, TERM, DATA_DATE, REPORT_RESULT_NO, REPORT_NO, REPORT_UNIT_NO, CALC_TOOK, REPORT_UNIT_STR_TIME, REPORT_UNIT_END_TIME) VALUES (:CALCINDEX, :SDATE, :EDATE, :TERM, :DATA_DATE, :REPORT_RESULT_NO, :REPORT_NO, :REPORT_UNIT_NO, :CALC_TOOK, :REPORT_UNIT_STR_TIME, :REPORT_UNIT_END_TIME)";
+
+            String sql = "INSERT INTO RWA_SYSTEM_REPORT_PROCESS_TABLEUNIT(CALCINDEX, SDATE, EDATE, TERM, DATA_DATE, REPORT_RESULT_NO, REPORT_NO, REPORT_UNIT_NO, CALC_TOOK, REPORT_UNIT_STR_TIME, REPORT_UNIT_END_TIME ,REPORT_UNIT_RESULT) VALUES (:CALCINDEX, :SDATE, :EDATE, :TERM, :DATA_DATE, :REPORT_RESULT_NO, :REPORT_NO, :REPORT_UNIT_NO, :CALC_TOOK, :REPORT_UNIT_STR_TIME, :REPORT_UNIT_END_TIME ,:REPORT_UNIT_RESULT)";
 
             sqlParam.addValue("REPORT_UNIT_NO", reportCalculationModel.getReportUnitNo());
             sqlParam.addValue("CALC_TOOK", timeInterval.interval());
             sqlParam.addValue("REPORT_UNIT_STR_TIME", DateUtil.formatDateTime(startDateTime));
             sqlParam.addValue("REPORT_UNIT_END_TIME", DateUtil.formatDateTime(new Date()));
+            String value = model.getValue().toString();
+            if (value.getBytes().length > 300) {
+                value = value.substring(0, 300/4);
+            }
+            sqlParam.addValue("REPORT_UNIT_RESULT",value);
             jdbcTemplate.update(sql, sqlParam);
         }
 

+ 1 - 6
Procedure/backend/project/src/main/java/com/sundata/product/rwa/util/DataUtil.java

@@ -16,12 +16,7 @@ public class DataUtil {
             return getDefaultValue(clazz);
         } else {
             // 如果对象的类型与目标类型一致,直接返回
-            if (clazz.isInstance(object)) {
-                return object;
-            } else {
-                // 如果类型不一致,也返回默认值
-                return getDefaultValue(clazz);
-            }
+            return object;
         }
     }