Explorar o código

添加报告样式

gushoubang hai 9 meses
pai
achega
ea6ef03479

+ 172 - 140
onemap-modules/onemap-analyse/src/main/java/com/onemap/analyse/service/impl/ReportServiceImpl.java

@@ -123,8 +123,7 @@ public class ReportServiceImpl implements IReportService {
 
             // 1、项目选址信息
             NpoiHelper.catalog(document, "一、项目选址信息", pos++);
-            String ydmj = NumberUtil.double2TwoDecimal(UnitsUtil.m2ToMu(res.getYdmjbegin())) +
-                    " - " + NumberUtil.double2TwoDecimal(UnitsUtil.m2ToMu(res.getYdmjend()));
+            String ydmj = NumberUtil.double2TwoDecimal(UnitsUtil.m2ToMu(res.getYdmjbegin())) + " - " + NumberUtil.double2TwoDecimal(UnitsUtil.m2ToMu(res.getYdmjend()));
             List<String> listTemp = new ArrayList<>();
             listTemp.add("\t项目名称:" + res.getXmmc());
             listTemp.add("\t建设单位:" + res.getJsdw());
@@ -255,154 +254,114 @@ public class ReportServiceImpl implements IReportService {
                 NpoiHelper.content(document, "\t按照项目选址要求和影响因子,经对所选范围内的所有用地进行分析,筛选出符合要求的方案共" + fzxzJgGisDTOList.size() + "个。", pos++);
             }
 
-            int index = 1;
-            NpoiHelper.Option optionIsBold = new NpoiHelper.Option();
-            optionIsBold.setBold(true);
+            // int index = 1;
+
             for (int i = 0; i < fzxzJgGisDTOList.size(); i++) {
                 SelectionResDTO item = fzxzJgGisDTOList.get(i);
 
-                // 查询地块信息
-                String rawTableName = item.getSjyb();
-                Integer rawItemId = item.getDkid();
-                List<String> columns = new ArrayList<>();
-                columns.add("kzxxgyddm");
-                columns.add("kzxxgydmc");
-                columns.add("xjxzqmc");
-                columns.add("dkbm");
-                Map<String, Object> rawTable = ghdkaMapper.getInfoByColumn(rawTableName, rawItemId.toString(), columns);
-                String dkName = "";
-                String dkCode = "";
-                String xzqmc = "";
-                String dkbm = "";
-                if (rawTable != null) {
-                    if (rawTable.containsKey("kzxxgydmc")) {
-                        dkName = rawTable.get("kzxxgydmc").toString();// 地块类型
-                    }
-                    if (rawTable.containsKey("kzxxgyddm")) {
-                        dkCode = rawTable.get("kzxxgyddm").toString();// 地块编码
-                    }
-                    if (rawTable.containsKey("xjxzqmc")) {
-                        xzqmc = rawTable.get("xjxzqmc").toString();// 行政区名称
-                    }
-                    if (rawTable.containsKey("dkbm")) {
-                        dkbm = rawTable.get("dkbm").toString();// 地块编码
-                    }
-                }
+                // 地块信息
+                List<Map<String, String>> dkList = getDkList(item.getSjyb(), item.getDkid().toString());
+
+                NpoiHelper.Option optionIsBold = new NpoiHelper.Option();
+                optionIsBold.setBold(true);// 加粗
+
+                document.setParagraph(NpoiHelper.newParagraph(document, i + 1 + "、方案" + NumberUtil.int2chineseNum(i + 1), optionIsBold), pos++);
+                XWPFTable table = document.createTable(dkList.size() + 4, 4);// 创建表格
+                table.setWidth(8300);// 总宽度
 
 
-                document.setParagraph(NpoiHelper.newParagraph(document, index + "、方案" + NumberUtil.int2chineseNum(index), optionIsBold), pos++);
-                XWPFTable table = document.createTable(8, 4);//8行4列
-                table.setWidth(9000);// 总宽度
-                for (int k = 0; k < 4; k++) {
-                    XWPFTableCell cell = table.getRow(0).getCell(k);
-                    CTTcPr ctTcPr = cell.getCTTc().isSetTcPr() ? cell.getCTTc().getTcPr() : cell.getCTTc().addNewTcPr();
-                    CTTblWidth ctTblWidth = ctTcPr.addNewTcW();
-                    ctTblWidth.setW(BigInteger.valueOf(2250));
-                    ctTblWidth.setType(STTblWidth.DXA);
+                for (int j = 0; j < dkList.size(); j++) {
+                    Map<String, String> rowMap = dkList.get(j);
+                    table.getRow(j).getCell(0).setParagraph(NpoiHelper.setCellText(table, rowMap.get("colum0"), null));
+                    table.getRow(j).getCell(1).setParagraph(NpoiHelper.setCellText(table, rowMap.get("colum1"), null));
+                    table.getRow(j).getCell(2).setParagraph(NpoiHelper.setCellText(table, rowMap.get("colum2"), null));
+                    table.getRow(j).getCell(3).setParagraph(NpoiHelper.setCellText(table, rowMap.get("colum3"), null));
                 }
-                // Table 表格第一行
-                table.getRow(0).getCell(0).setColor("DBE5F1");
-                NpoiHelper.mergeHorizontal(table, 0, 0, 3);
-                table.getRow(0).getCell(0).setParagraph(NpoiHelper.setCellText(table, "符合用地情况", optionIsBold));
-                // Table 表格第二行
-                table.getRow(1).getCell(0).setParagraph(NpoiHelper.setCellText(table, "地块编码", optionIsBold));
-                table.getRow(1).getCell(1).setParagraph(NpoiHelper.setCellText(table, dkbm, null));
-                table.getRow(1).getCell(2).setParagraph(NpoiHelper.setCellText(table, "县级行政区", optionIsBold));
-                table.getRow(1).getCell(3).setParagraph(NpoiHelper.setCellText(table, xzqmc, null));
-                // Table 表格第三行
-                table.getRow(2).getCell(0).setParagraph(NpoiHelper.setCellText(table, "地类编码", optionIsBold));
-                table.getRow(2).getCell(1).setParagraph(NpoiHelper.setCellText(table, dkCode, null));
-                table.getRow(2).getCell(2).setParagraph(NpoiHelper.setCellText(table, "地类名称", optionIsBold));
-                table.getRow(2).getCell(3).setParagraph(NpoiHelper.setCellText(table, dkName, null));
-                // Table 表格第四行
-                table.getRow(3).getCell(0).setParagraph(NpoiHelper.setCellText(table, "地块面积", optionIsBold));
-                table.getRow(3).getCell(1).setParagraph(NpoiHelper.setCellText(table,
-                        NumberUtil.double2TwoDecimal(UnitsUtil.m2ToMu(item.getArea())) + "亩", null));
-                table.getRow(3).getCell(2).setParagraph(NpoiHelper.setCellText(table, "土地位置", optionIsBold));
-                // table.getRow(2).getCell(3).setParagraph(NpoiHelper.setCellText(table, item.getXzqmc(), null));
-                // Table 表格第五行
-                table.getRow(4).getCell(0).setColor("DBE5F1");
-                NpoiHelper.mergeHorizontal(table, 4, 0, 3);//合并单元格
-                table.getRow(4).getCell(0).setParagraph(NpoiHelper.setCellText(table, "地块位置信息", optionIsBold));
+                // row
+                // table.getRow(4).getCell(0).setColor("DBE5F1");
+                NpoiHelper.mergeHorizontal(table, dkList.size(), 1, 3);// 合并单元格
+                table.getRow(dkList.size()).getCell(0).setParagraph(NpoiHelper.setCellText(table, "配建机动车位说明", optionIsBold));
+
+                // row
+                NpoiHelper.mergeHorizontal(table, dkList.size() + 1, 1, 3);// 合并单元格
+                table.getRow(dkList.size() + 1).getCell(0).setParagraph(NpoiHelper.setCellText(table, "准地价预估(万元)", optionIsBold));
                 // Table 表格第六行 -专题图
-                NpoiHelper.mergeHorizontal(table, 5, 0, 3);
-                String mapF = "";
-                String mapM = "";
-
-                // TODO 生成位置图片
-                // if (imgList != null && imgList.size() > 0) {
-                //     for (int j = 0; j < imgList.size(); j++) {
-                //         String s = imgList.get(j);
-                //         if (s.indexOf(item.getBsm() + "_F") >= 0) {
-                //             mapF = s;// 全局
+                NpoiHelper.mergeHorizontal(table, dkList.size() + 2, 0, 3);
+                table.getRow(dkList.size() + 2).getCell(0).setParagraph(NpoiHelper.setCellText(table, "地块位置", optionIsBold));
+
+                // String mapF = "";
+                // String mapM = "";
+                //
+                // // TODO 生成位置图片
+                // // if (imgList != null && imgList.size() > 0) {
+                // //     for (int j = 0; j < imgList.size(); j++) {
+                // //         String s = imgList.get(j);
+                // //         if (s.indexOf(item.getBsm() + "_F") >= 0) {
+                // //             mapF = s;// 全局
+                // //         }
+                // //         if (s.indexOf(item.getBsm() + "_M") >= 0) {
+                // //             mapM = s;// 局部
+                // //         }
+                // //     }
+                // // }
+                // if (StringUtils.isNotEmpty(mapF)) {
+                //     FileInputStream fis = null;
+                //     try {
+                //         fis = new FileInputStream(new File(mapF));
+                //         XWPFParagraph paragraph = table.getRow(4).getCell(0).addParagraph();
+                //         paragraph.setAlignment(ParagraphAlignment.CENTER);
+                //         XWPFRun run = paragraph.createRun();
+                //         run.addPicture(fis,    // 条形码图片的位置
+                //                 Document.PICTURE_TYPE_JPEG, // 图片类型
+                //                 item.getBsm() + "_F.jpeg", // 图片名称
+                //                 2200000, // 图片的长
+                //                 1700000 // 图片的宽
+                //         );
+                //         run.addBreak(BreakType.TEXT_WRAPPING);
+                //         run.setText("(宏观位置)");
+                //     } catch (Exception e) {
+                //         System.out.println(e.toString());
+                //     } finally {
+                //         if (fis != null) {
+                //             try {
+                //                 fis.close();
+                //             } catch (IOException e) {
+                //                 throw e;
+                //             }
                 //         }
-                //         if (s.indexOf(item.getBsm() + "_M") >= 0) {
-                //             mapM = s;// 局部
+                //     }
+                // }
+                // if (StringUtils.isNotEmpty(mapM)) {
+                //     FileInputStream fis = null;
+                //     try {
+                //         fis = new FileInputStream(new File(mapM));
+                //         XWPFParagraph paragraph = table.getRow(4).getCell(2).addParagraph();
+                //         paragraph.setAlignment(ParagraphAlignment.CENTER);
+                //         XWPFRun run = paragraph.createRun();
+                //         run.addPicture(fis,    // 条形码图片的位置
+                //                 Document.PICTURE_TYPE_JPEG, // 图片类型
+                //                 item.getBsm() + "_M.jpeg", // 图片名称
+                //                 2200000, // 图片的长
+                //                 1700000 // 图片的宽
+                //         );
+                //         run.addBreak(BreakType.TEXT_WRAPPING);
+                //         run.setText("(具体位置)");
+                //     } catch (Exception e) {
+                //         System.out.println(e.toString());
+                //         throw e;
+                //     } finally {
+                //         if (fis != null) {
+                //             try {
+                //                 fis.close();
+                //             } catch (IOException e) {
+                //                 throw e;
+                //             }
                 //         }
                 //     }
                 // }
-                if (StringUtils.isNotEmpty(mapF)) {
-                    FileInputStream fis = null;
-                    try {
-                        fis = new FileInputStream(new File(mapF));
-                        XWPFParagraph paragraph = table.getRow(4).getCell(0).addParagraph();
-                        paragraph.setAlignment(ParagraphAlignment.CENTER);
-                        XWPFRun run = paragraph.createRun();
-                        run.addPicture(fis,    // 条形码图片的位置
-                                Document.PICTURE_TYPE_JPEG, // 图片类型
-                                item.getBsm() + "_F.jpeg", // 图片名称
-                                2200000, // 图片的长
-                                1700000 // 图片的宽
-                        );
-                        run.addBreak(BreakType.TEXT_WRAPPING);
-                        run.setText("(宏观位置)");
-                    } catch (Exception e) {
-                        System.out.println(e.toString());
-                    } finally {
-                        if (fis != null) {
-                            try {
-                                fis.close();
-                            } catch (IOException e) {
-                                throw e;
-                            }
-                        }
-                    }
-                }
-                if (StringUtils.isNotEmpty(mapM)) {
-                    FileInputStream fis = null;
-                    try {
-                        fis = new FileInputStream(new File(mapM));
-                        XWPFParagraph paragraph = table.getRow(4).getCell(2).addParagraph();
-                        paragraph.setAlignment(ParagraphAlignment.CENTER);
-                        XWPFRun run = paragraph.createRun();
-                        run.addPicture(fis,    // 条形码图片的位置
-                                Document.PICTURE_TYPE_JPEG, // 图片类型
-                                item.getBsm() + "_M.jpeg", // 图片名称
-                                2200000, // 图片的长
-                                1700000 // 图片的宽
-                        );
-                        run.addBreak(BreakType.TEXT_WRAPPING);
-                        run.setText("(具体位置)");
-                    } catch (Exception e) {
-                        System.out.println(e.toString());
-                        throw e;
-                    } finally {
-                        if (fis != null) {
-                            try {
-                                fis.close();
-                            } catch (IOException e) {
-                                throw e;
-                            }
-                        }
-                    }
-                }
-                // Table 表格第七行
-                table.getRow(6).getCell(0).setColor("DBE5F1");
-                NpoiHelper.mergeHorizontal(table, 6, 0, 3);
-                table.getRow(6).getCell(0).setParagraph(NpoiHelper.setCellText(table, "分析结论", optionIsBold));
-                // Table 表格第八行
-                NpoiHelper.mergeHorizontal(table, 7, 0, 3);
-                XWPFParagraph para6 = table.getRow(7).getCell(0).addParagraph();
+                // Table 图片
+                NpoiHelper.mergeHorizontal(table, dkList.size() + 3, 0, 3);
+                XWPFParagraph para6 = table.getRow(dkList.size() + 3).getCell(0).addParagraph();
                 para6.setAlignment(ParagraphAlignment.LEFT);
 
 
@@ -434,7 +393,6 @@ public class ReportServiceImpl implements IReportService {
                     run.addBreak(BreakType.TEXT_WRAPPING);
                     jgyzid++;
                 }
-                index++;
             }
             File fileDoc = new File(reportPath);
             if (fileDoc.exists()) {
@@ -500,6 +458,80 @@ public class ReportServiceImpl implements IReportService {
         return map;
     }
 
+    /**
+     * 获取地块信息
+     */
+    private List<Map<String, String>> getDkList(String rawTableName, String rawItemId) {
+        // 查询地块信息
+        List<String> columns = new ArrayList<>();
+        columns.add("kzxxgyddm");
+        columns.add("kzxxgydmc");
+        columns.add("xjxzqmc");
+        columns.add("dkbm");
+        columns.add("ydmj");
+        columns.add("jzmj");
+        columns.add("rjld");
+        columns.add("rjlx");
+        columns.add("jzmdd");
+        columns.add("jzmdx");
+        columns.add("ldld");
+        columns.add("ldlx");
+        Map<String, Object> rawTable = ghdkaMapper.getInfoByColumn(rawTableName, rawItemId.toString(), columns);
+
+        List<Map<String, String>> rows = new ArrayList<>();
+        if (rawTable != null) {
+            Map<String, String> row1temMap = new HashMap<>();
+            row1temMap.put("colum0", "地块编码");
+            row1temMap.put("colum1", rawTable.get("dkbm") + "");
+            row1temMap.put("colum2", "县级行政区");
+            row1temMap.put("colum3", rawTable.get("xjxzqmc") + "");
+            rows.add(row1temMap);
+
+            Map<String, String> row2ItemMap = new HashMap<>();
+            row2ItemMap.put("colum0", "地块用地类别代码");
+            row2ItemMap.put("colum1", rawTable.get("kzxxgyddm") + "");
+            row2ItemMap.put("colum2", "地块用地类别名称");
+            row2ItemMap.put("colum3", rawTable.get("kzxxgydmc") + "");
+            rows.add(row2ItemMap);
+
+            Map<String, String> row3ItemMap = new HashMap<>();
+            row3ItemMap.put("colum0", "用地面积(亩)");
+            row3ItemMap.put("colum1", rawTable.get("ydmj") + "");
+            row3ItemMap.put("colum2", "建筑面积(亩)");
+            row3ItemMap.put("colum3", rawTable.get("jzmj") + "");
+            rows.add(row3ItemMap);
+
+            Map<String, String> row4ItemMap = new HashMap<>();
+            row4ItemMap.put("colum0", "容积率上限");
+            row4ItemMap.put("colum1", rawTable.get("rjld") + "");
+            row4ItemMap.put("colum2", "容积率下限");
+            row4ItemMap.put("colum3", rawTable.get("rjlx") + "");
+            rows.add(row4ItemMap);
+
+            Map<String, String> row5ItemMap = new HashMap<>();
+            row5ItemMap.put("colum0", "建筑密度上限(%)");
+            row5ItemMap.put("colum1", rawTable.get("jzmdd") + "");
+            row5ItemMap.put("colum2", "建筑密度下限(%)");
+            row5ItemMap.put("colum3", rawTable.get("jzmdx") + "");
+            rows.add(row5ItemMap);
+
+            Map<String, String> row6ItemMap = new HashMap<>();
+            row6ItemMap.put("colum0", "绿地率上限(%)");
+            row6ItemMap.put("colum1", rawTable.get("ldld") + "");
+            row6ItemMap.put("colum2", "绿地率下限(%)");
+            row6ItemMap.put("colum3", rawTable.get("ldlx") + "");
+            rows.add(row6ItemMap);
+
+            Map<String, String> row7ItemMap = new HashMap<>();
+            row7ItemMap.put("colum0", "建筑限高上限(米)");
+            row7ItemMap.put("colum1", rawTable.get("jzxgd") + "");
+            row7ItemMap.put("colum2", "建筑限高下限(米)");
+            row7ItemMap.put("colum3", rawTable.get("jzxgx") + "");
+            rows.add(row7ItemMap);
+        }
+        return rows;
+    }
+
     /**
      * TODO 待定
      * 导出报告图片

+ 4 - 2
onemap-modules/onemap-analyse/src/main/java/com/onemap/analyse/utils/NumberUtil.java

@@ -104,7 +104,8 @@ public class NumberUtil {
     /**
      * float 保留两位小数
      */
-    public static float float2TwoDecimal(float f) {
+    public static float float2TwoDecimal(Float f) {
+        if (f == null) return 0;
         BigDecimal b = new BigDecimal(f);
         return b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
     }
@@ -112,7 +113,8 @@ public class NumberUtil {
     /**
      * double 保留两位小数
      */
-    public static double double2TwoDecimal(double d) {
+    public static double double2TwoDecimal(Double d) {
+        if (d == null) return 0;
         BigDecimal b = new BigDecimal(d);
         return b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
     }