소스 검색

无效理由导出,修改表格格式

chendayu 2 년 전
부모
커밋
a6a95a7dee

+ 8 - 6
RMS/src/main/java/cn/cslg/report/controller/InvalidReReport/InvalidReasonController.java

@@ -34,10 +34,11 @@ public class InvalidReasonController {
     private final InvalidReasonService invalidReasonService;
     private final InvalidReasonFieldValueService invalidReasonFieldValueService;
     private final ExportArgumentsScenariosService exportArgumentsScenariosService;
+
     @Operation(summary = "添加无效理由和证据")
     @PostMapping("/addInvalidReason")
     public String addInvalidReason(@RequestBody InvalidReasonDTO invalidReasonDTO) {
-        if(invalidReasonDTO != null) {
+        if (invalidReasonDTO != null) {
             invalidReasonService.addInvalidReason(invalidReasonDTO);
             return Response.success("新增成功");
         } else {
@@ -48,7 +49,7 @@ public class InvalidReasonController {
     @Operation(summary = "删除无效理由和证据")
     @PostMapping("/deleteInvalidReason")
     public String deleteInvalidReason(@RequestBody List<Integer> ids) {
-        if(ids != null && ids.size() != 0){
+        if (ids != null && ids.size() != 0) {
             invalidReasonService.deleteInvalidReason(ids);
             return Response.success("删除成功");
         } else {
@@ -59,14 +60,14 @@ public class InvalidReasonController {
     @Operation(summary = "更新无效理由和证据")
     @PostMapping("/updateInvalidReason")
     public String updateInvalidReason(@RequestBody InvalidReasonDTO invalidReasonDTO) throws IOException {
-             invalidReasonService.updateInvalidReason(invalidReasonDTO);
+        invalidReasonService.updateInvalidReason(invalidReasonDTO);
         return Response.success();
     }
 
     @Operation(summary = "查找无效理由和证据")
     @GetMapping("/queryInvalidReason")
     public String queryInvalidReason(Integer reportId) throws IOException {
-        if(reportId != null && reportId > 0) {
+        if (reportId != null && reportId > 0) {
             List<QueryInvalidReasonVO> queryInvalidReasonVOS = invalidReasonService.queryInvalidReason(reportId);
             return Response.success(queryInvalidReasonVOS);
         } else {
@@ -92,7 +93,7 @@ public class InvalidReasonController {
     @PostMapping("/addOrUpdateValue")
     public String addOrUpdateValue(@RequestBody List<InvalidReasonFieldValueDTO> invalidReasonFieldValueDTOS) throws IOException {
         Boolean isFlag = invalidReasonFieldValueService.addOrUpdate(invalidReasonFieldValueDTOS);
-        if(!isFlag){
+        if (!isFlag) {
             Response.error("添加失败");
         }
         return Response.success("添加成功");
@@ -104,10 +105,11 @@ public class InvalidReasonController {
         invalidReasonService.updateArgumentStr(updateArgumentStrDTO);
         return Response.success();
     }
+
     @Operation(summary = "导出无效理由")
     @GetMapping("/exportInvalid")
     public String exportInvalid(Integer reportId) throws IOException {
-       String url =  exportArgumentsScenariosService.ExportToWord(reportId);
+        String url = exportArgumentsScenariosService.ExportToWord(reportId);
         return url;
     }
 }

+ 112 - 16
RMS/src/main/java/cn/cslg/report/service/business/ExportArgumentsScenariosService.java

@@ -8,10 +8,12 @@ import cn.cslg.report.common.utils.*;
 import cn.cslg.report.common.utils.SecurityUtils.LoginUtils;
 import cn.cslg.report.entity.Report;
 import cn.cslg.report.entity.ReportDocument;
+import cn.cslg.report.entity.ValueObject;
 import cn.cslg.report.entity.invalidReReport.InvalidReasonField;
 import cn.cslg.report.service.business.InvalidReReport.InvalidReasonFieldService;
 import cn.cslg.report.service.business.InvalidReReport.InvalidReasonService;
 import cn.hutool.core.util.IdUtil;
+import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.deepoove.poi.XWPFTemplate;
 import com.deepoove.poi.config.Configure;
@@ -93,19 +95,48 @@ public class ExportArgumentsScenariosService {
         WordUtil.setParagraph(doc, report.getName() + "无效理由", "宋体", 16, 10, true, ParagraphAlignment.CENTER);
         //设置副标题
         WordUtil.setParagraph(doc, "生成时间:" + new Date().toString(), "宋体", 10, 10, true, ParagraphAlignment.RIGHT);
-        int colTotalCount = fields.size() + 5;
+        int fieldTableCount = 0;
+        if (fields.size() > 1) {
+            fieldTableCount = (fields.size() - 1) * 4 + 1;
+        }
+        int colTotalCount = fieldTableCount + 5;
+
         //总条数
         int dataCount = queryInvalidReasonVOS.size();
         //创建表格
-        XWPFTable xTable = doc.createTable(1, colTotalCount);
+        XWPFTable xTable = doc.createTable(2, colTotalCount);
         CTTblPr tblPr = xTable.getCTTbl().addNewTblPr();
         tblPr.addNewJc().setVal(STJc.CENTER);
         //设置边框
         WordUtil.setTableBolder(xTable, 10, "000000");
         // 创建表头数据
+        int startIndex = 6;
+        int nameListIndex = 6;
+        String[] valueArr = new String[4];
+        valueArr[0] = "起诉人意见";
+        valueArr[1] = "被诉人意见";
+        valueArr[2] = "第三方机构意见";
+        valueArr[3] = "法院意见";
+        int valueArrIndex = 0;
         for (int j = 0; j < colTotalCount; j++) {
-            WordUtil.setCellText(xTable.getRow(0).getCell(j), nameList.get(j), 1200, "宋体", 10, true);
+            if (j < 6) {
+                WordUtil.setCellText(xTable.getRow(0).getCell(j), nameList.get(j), 1200, "宋体", 10, true);
+                WordUtil.setCellText(xTable.getRow(1).getCell(j), nameList.get(j), 1200, "宋体", 10, true);
+                WordUtil.mergeCellsVertically(xTable, j, 0, 1);
+            } else {
+                WordUtil.setCellText(xTable.getRow(0).getCell(j), nameList.get(nameListIndex), 1200, "宋体", 10, true);
+                WordUtil.setCellText(xTable.getRow(1).getCell(j), valueArr[valueArrIndex], 1200, "宋体", 10, true);
+                valueArrIndex++;
+                if (j - startIndex == 3) {
+                    valueArrIndex = 0;
+                    WordUtil.mergeCellsHorizontal(xTable, 0, startIndex, j);
+                    startIndex = j + 1;
+                    nameListIndex++;
+                }
+
+            }
         }
+
         //记录对比文件文件内容map
         Map<Integer, String> fileMap = new TreeMap<>();
         //记录合并数据map
@@ -121,7 +152,10 @@ public class ExportArgumentsScenariosService {
                 map.put(name, map.get(name) + 1);
             }
             List<InvalidReasonFieldValueDTO> fieldValueDTOS = queryInvalidReasonVO.getFields();
-            XWPFTableRow row = xTable.insertNewTableRow(i2 + 1);
+            XWPFTableRow row = xTable.insertNewTableRow(i2 + 2);
+            startIndex = 6;
+            valueArrIndex = 0;
+            nameListIndex = 0;
             for (int j = 0; j < colTotalCount; j++) {
                 XWPFTableCell cell = row.createCell();
                 XWPFRun run;
@@ -137,13 +171,12 @@ public class ExportArgumentsScenariosService {
                         run.setText("不具备创造性");
                     } else if (name == 3) {
                         run.setText("不具备新颖性");
-                    }
-                    else if (name == 4) {
+                    } else if (name == 4) {
                         run.setText("重复授权");
                     }
                 } else if (j == 2) {
-                    int content = queryInvalidReasonVO.getContent();
-                    if (content == -1) {
+                    Integer content = queryInvalidReasonVO.getContent();
+                    if (content == null || content == -1) {
                         run.setText("说明书");
                     } else {
                         run.setText("权要" + (content + 1));
@@ -182,7 +215,7 @@ public class ExportArgumentsScenariosService {
                                     }
                                 }
                                 //记录对比文件名称字典
-                                if (fileMap.get(proofIn.getSort()) == null&&proofIn.getId()!=0) {
+                                if (fileMap.get(proofIn.getSort()) == null && proofIn.getId() != 0) {
                                     fileMap.put(proofIn.getSort(), proofIn.getFileName());
                                 }
                             }
@@ -192,20 +225,83 @@ public class ExportArgumentsScenariosService {
                         run.setText(stringBuilder.toString());
                     }
                 } else if (j == 4) {
-                    map1.put("argument" + nameCount, queryInvalidReasonVO.getArgumentStr());
+                    String value = queryInvalidReasonVO.getArgumentStr();
+                    String argumentStr = "";
+                    try {
+                        List<String> list = JSONObject.parseObject(value, List.class);
+                        argumentStr = list.get(0);
+                        if (argumentStr == null) {
+                            argumentStr = "";
+                        }
+                    } catch (Exception e) {
+                        argumentStr = value;
+                    }
+                    map1.put("argument" + nameCount, argumentStr);
                     run.setText("{{argument" + nameCount + "}}");
                     nameCount = nameCount + 1;
                 } else {
-                    InvalidReasonField field = fields.get(j - 5);
+                    InvalidReasonField field;
+                    if (j == 5) {
+                        field = fields.get(nameListIndex);
+                        nameListIndex++;
+                    } else {
+                        field = fields.get(nameListIndex);
+                        if (j - startIndex == 3) {
+                            nameListIndex++;
+                        }
+                    }
                     InvalidReasonFieldValueDTO valueDTO = fieldValueDTOS.stream().filter(item -> item.getFieldId().equals(field.getId())).findFirst().orElse(new InvalidReasonFieldValueDTO());
-                    map1.put(valueDTO.getFieldKey() + nameCount, valueDTO.getFieldValue());
-                    run.setText("{{" + valueDTO.getFieldKey() + nameCount + "}}");
+                    String value = valueDTO.getFieldValue();
+                    String str = "";
+                    if (j == 5) {  //复审委意见
+                        try {
+                            List<String> list = JSONObject.parseObject(value, List.class);
+                            str = list.get(0);
+                            if (str == null) {
+                                str = "";
+                            }
+                        } catch (Exception e) {
+                            str = value;
+                        }
+                    } else {
+                        int count = j - startIndex;
+                        try {
+                            ValueObject valueObject = JSONObject.parseObject(value, ValueObject.class);
+                            List<String> suggestion = null;
+                            switch (count) {
+                                case 0:
+                                    suggestion = valueObject.getProsecutor();
+                                    break;
+                                case 1:
+                                    suggestion = valueObject.getRespondent();
+                                    break;
+                                case 2:
+                                    suggestion = valueObject.getInstitution();
+                                    break;
+                                case 3:
+                                    suggestion = valueObject.getCourt();
+                            }
+                            if (suggestion == null) {
+                                str = "";
+                            } else {
+                                str = suggestion.get(0);
+                            }
+                        } catch (Exception e) {
+                            if (count == 3) {
+                                str = value;
+                            } else {
+                                str = "";
+                            }
+                        }
+                    }
+                    map1.put(valueDTO.getFieldKey() + j + nameCount, str);
+                    run.setText("{{" + valueDTO.getFieldKey() + j + nameCount + "}}");
                     nameCount = nameCount + 1;
                 }
             }
         }
         //添加文件说明行
-        XWPFTableRow row = xTable.insertNewTableRow(dataCount + 1);
+        XWPFTableRow row = xTable.insertNewTableRow(dataCount + 2);
         XWPFTableCell cell = row.createCell();
         XWPFRun run;
         run = WordUtil.setTableCellStyle(cell, "1200", ParagraphAlignment.CENTER, "微软雅黑", 9, false);
@@ -220,9 +316,9 @@ public class ExportArgumentsScenariosService {
             XWPFRun runTem;
             runTem = WordUtil.setTableCellStyle(cellTem, "1200", ParagraphAlignment.CENTER, "微软雅黑", 9, false);
         }
-        WordUtil.mergeCellsHorizontal(xTable, dataCount + 1, 0, colTotalCount - 1);
+        WordUtil.mergeCellsHorizontal(xTable, dataCount + 2, 0, colTotalCount - 1);
         //记录合并起始位置
-        Integer t = 1;
+        Integer t = 2;
         for (int i : map.keySet()) {
             int end = t + map.get(i) - 1;
             WordUtil.mergeCellsVertically(xTable, 1, t, end);