0
点赞
收藏
分享

微信扫一扫

Java使用OpenOffice将office文件转换为PDF

TiaNa_na 04-16 11:30 阅读 2

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

 public String createPDF(String num, HttpServletRequest request, HttpServletResponse response) throws IOException {
        Fill fill = polluteFillService.getInfoById(num);
        String provinceCode = fill.getProvinceCode();
        String cityCode = fill.getCityCode();
        String districtCode = fill.getDistrictCode();
//        File file = new File(BASE_PATH, "图斑编号" + UUID.randomUUID() + ".pdf");
        String path = BASE_PATH + provinceCode + "\\" + cityCode + "\\" + districtCode;
        File dir = new File(path);
        String property = System.getProperty("user.dir");

        boolean isExistFile = false;
        if(!dir.exists()){
            isExistFile = dir.mkdirs();
        } else {
            isExistFile = true;
        }
        if(!isExistFile){
            throw new BizRuntimeException("找不到文件夹");
        }
        File file = new File(path, fill.getTbbh() + ".pdf");
        // 创建PDF文档
        PdfWriter pdfWriter = new PdfWriter(file);
        PdfDocument pdfDocument = new PdfDocument(pdfWriter);
        // 创建文档对象
        Document document = new Document(pdfDocument);
        //创建表格单元格大小
        float[] columnWidths = new float[]{10, 20, 20, 20, 20, 20, 20, 20, 20};
        Table table = new Table(columnWidths);
        table.setWidth(UnitValue.createPercentValue(100));
        table.setFixedLayout();
        //设置表格字体
        PdfFont sysFont = PdfFontFactory.createFont(FONT);
        table.setFont(sysFont);
        table.setFontSize(FONT_SIZE);
        Div div = new Div().add(new Paragraph("矿山(图斑)污染状况调查表").setTextAlignment(TextAlignment.CENTER));
        div.setFont(sysFont);
        div.setFontSize(15);
        table.setCaption(div);
        basicinformat(table, fill);
        int lineNum = mining(table, fill);
        lineNum = solidWaste(table, fill, lineNum);
        lineNum = acidicWastewater(table, fill, lineNum);
        lineNum = agriculturalLand(table, fill, lineNum);
        lineNum = exegesis(table, lineNum);
        tableTail(table, fill, lineNum);
        // 添加表格到PDF文档
        document.add(table);
        // 关闭文档
        document.close();
        pdfDocument.close();
        pdfWriter.close();
        return file.getPath();
    }
 //基本信息
    private void basicinformat(Table table, Fill fill) throws MalformedURLException {
        Cell cell = new Cell(1, 1).setBorderBottom(Border.NO_BORDER).setKeepTogether(true);
        //第一行 图斑编号
        Cell c1 = new Cell(1, 2).add(new Paragraph("图斑编号*"));
        Cell c2 = new Cell(1, 2).add(new Paragraph(org.springframework.util.StringUtils.hasText(fill.getTbbh()) ? fill.getTbbh() : ""));
        Cell c3 = new Cell(1, 2).add(new Paragraph("矿山名称"));
        Cell c4 = new Cell(1, 2).add(new Paragraph(org.springframework.util.StringUtils.hasText(fill.getMineName()) ? fill.getMineName() : ""));
        table.addCell(cell).addCell(c1).addCell(c2).addCell(c3).addCell(c4);
        //第二行 地点
        Cell c5 = new Cell(2, 2).add(new Paragraph("地点*"));
        Cell c6 = new Cell(2, 6).add(new Paragraph(org.springframework.util.StringUtils.hasText(fill.getDetailedAddress()) ? fill.getDetailedAddress() : ""));
        table.addCell(new Cell(2, 1).setBorderTop(Border.NO_BORDER).setBorderBottom(Border.NO_BORDER)).addCell(c5).addCell(c6);
        //第三行 坐标
        Cell c7 = new Cell(3, 2).add(new Paragraph("坐标*(保留6位小数)"));
        Cell c8 = new Cell(3, 6);
        Paragraph lon = new Paragraph("经度:").add(org.springframework.util.StringUtils.hasText(fill.getLongitudeFlag()) ? fill.getLongitudeFlag() + "        " : "        ");
        lon.add("纬度:").add(org.springframework.util.StringUtils.hasText(fill.getLatitudeFlag()) ? fill.getLatitudeFlag() : "");
        c8.add(lon);
        table.addCell(new Cell(3, 1).setBorderTop(Border.NO_BORDER).setBorderBottom(Border.NO_BORDER)).addCell(c7).addCell(c8);
        //第四行
        Cell c9 = new Cell(4, 2).add(new Paragraph("地形地貌"));
        Cell c10 = new Cell(4, 6);
        List<String> topography = fill.getTopography();
        Paragraph topographyP = new Paragraph();
        if (topography.contains("D005-001")) {
            topographyP.add(new Image(ImageDataFactory.create(YES_PICTURE)).setWidth(RADIO_SIZE).setHeight(RADIO_SIZE)).add(" 平地   ");
        } else {
            topographyP.add(new Image(ImageDataFactory.create(NO_PICTURE)).setWidth(RADIO_SIZE).setHeight(RADIO_SIZE)).add(" 平地   ");
        }
        if (topography.contains("D005-002")) {
            topographyP.add(new Image(ImageDataFactory.create(YES_PICTURE)).setWidth(RADIO_SIZE).setHeight(RADIO_SIZE)).add(" 山脚   ");
        } else {
            topographyP.add(new Image(ImageDataFactory.create(NO_PICTURE)).setWidth(RADIO_SIZE).setHeight(RADIO_SIZE)).add(" 山脚   ");
        }
        if (topography.contains("D005-003")) {
            topographyP.add(new Image(ImageDataFactory.create(YES_PICTURE)).setWidth(RADIO_SIZE).setHeight(RADIO_SIZE)).add(" 斜坡   ");
        } else {
            topographyP.add(new Image(ImageDataFactory.create(NO_PICTURE)).setWidth(RADIO_SIZE).setHeight(RADIO_SIZE)).add(" 斜坡   ");
        }
        if (topography.contains("D005-004")) {
            topographyP.add(new Image(ImageDataFactory.create(YES_PICTURE)).setWidth(RADIO_SIZE).setHeight(RADIO_SIZE)).add(" 河谷   ");
        } else {
            topographyP.add(new Image(ImageDataFactory.create(NO_PICTURE)).setWidth(RADIO_SIZE).setHeight(RADIO_SIZE)).add(" 河谷   ");
        }
        if (topography.contains("D005-005")) {
            topographyP.add(new Image(ImageDataFactory.create(YES_PICTURE)).setWidth(RADIO_SIZE).setHeight(RADIO_SIZE)).add(" 阶地   ");
        } else {
            topographyP.add(new Image(ImageDataFactory.create(NO_PICTURE)).setWidth(RADIO_SIZE).setHeight(RADIO_SIZE)).add(" 阶地   ");
        }
        if (topography.contains("D005-006")) {
            topographyP.add(new Image(ImageDataFactory.create(YES_PICTURE)).setWidth(RADIO_SIZE).setHeight(RADIO_SIZE)).add(" 冲沟   ");
        } else {
            topographyP.add(new Image(ImageDataFactory.create(NO_PICTURE)).setWidth(RADIO_SIZE).setHeight(RADIO_SIZE)).add(" 冲沟   ");
        }
        if (topography.contains("D005-007")) {
            topographyP.add(new Image(ImageDataFactory.create(YES_PICTURE)).setWidth(RADIO_SIZE).setHeight(RADIO_SIZE)).add(" 冲积扇   ");
        } else {
            topographyP.add(new Image(ImageDataFactory.create(NO_PICTURE)).setWidth(RADIO_SIZE).setHeight(RADIO_SIZE)).add(" 冲积扇   ");
        }
        if (topography.contains("D005-00RADIO_SIZE")) {
            topographyP.add(new Image(ImageDataFactory.create(YES_PICTURE)).setWidth(RADIO_SIZE).setHeight(RADIO_SIZE)).add(" 残丘   ");
        } else {
            topographyP.add(new Image(ImageDataFactory.create(NO_PICTURE)).setWidth(RADIO_SIZE).setHeight(RADIO_SIZE)).add(" 残丘   ");
        }
        if (topography.contains("D005-009")) {
            topographyP.add(new Image(ImageDataFactory.create(YES_PICTURE)).setWidth(RADIO_SIZE).setHeight(RADIO_SIZE)).add(" 洼地   ");
        } else {
            topographyP.add(new Image(ImageDataFactory.create(NO_PICTURE)).setWidth(RADIO_SIZE).setHeight(RADIO_SIZE)).add(" 洼地   ");
        }
        Paragraph topographyOther = new Paragraph();
        if (topography.contains("D005-010")) {
            topographyOther.add(new Image(ImageDataFactory.create(YES_PICTURE)).setWidth(RADIO_SIZE).setHeight(RADIO_SIZE)).add(" 其他:")
                    .add(org.springframework.util.StringUtils.hasText(fill.getTopographyDetail()) ? fill.getTopographyDetail() : "");
        } else {
            topographyOther.add(new Image(ImageDataFactory.create(NO_PICTURE)).setWidth(RADIO_SIZE).setHeight(RADIO_SIZE)).add(" 其他   ");
        }
        table.addCell(new Cell(4, 1).add(new Paragraph("基本信息")).setBorderTop(Border.NO_BORDER).setBorderBottom(Border.NO_BORDER)).addCell(c9).addCell(c10.add(topographyP).add(topographyOther));
        //第五行
        Cell c11 = new Cell(5, 2).add(new Paragraph("气象"));
        Cell c12 = new Cell(5, 1).add(new Paragraph("平均气温"));
        Cell c13 = new Cell(5, 2).add(new Paragraph(org.springframework.util.StringUtils.hasText(fill.getAverageTemperatures()) ? fill.getAverageTemperatures() : "").add("℃"));
        Cell c14 = new Cell(5, 1).add(new Paragraph("年降雨量*"));
        Cell c15 = new Cell(5, 2).add(new Paragraph(org.springframework.util.StringUtils.hasText(fill.getAnnualRainfall()) ? fill.getAnnualRainfall() : "").add("毫米"));
        table.addCell(new Cell(5, 1).setBorderTop(Border.NO_BORDER)).addCell(c11).addCell(c12).addCell(c13).addCell(c14).addCell(c15);
    }


    //矿山开采
    private int mining(Table table, Fill fill) throws MalformedURLException {
        //第六行
        Cell c1 = new Cell(6, 1).setBorderBottom(Border.NO_BORDER);
        Cell c2 = new Cell(6, 2).add(new Paragraph("矿种*"));
        List<String> mineralSpecies = fill.getMineralSpecies();
        if (CollectionUtils.isEmpty(mineralSpecies)) {
            mineralSpecies = new ArrayList<>();
        }
        List<String> nameList = dictMapper.selectList(Wrappers.lambdaQuery(Dict.class).in(Dict::getValue, mineralSpecies))
                .stream().map(Dict::getName).collect(Collectors.toList());
        String join = String.join(",", nameList);
        Cell c3 = new Cell(6, 6).add(new Paragraph(join));
        table.addCell(c1).addCell(c2).addCell(c3);
        //第七行
        Cell c4 = new Cell(7, 1).setBorderBottom(Border.NO_BORDER).setBorderTop(Border.NO_BORDER);
        Cell c5 = new Cell(7, 2).add(new Paragraph("开采历史"));
        String miningHistory = fill.getMiningHistory();
        Paragraph p1 = new Paragraph();
        Image yes = new Image(ImageDataFactory.create(YES_PICTURE)).setWidth(RADIO_SIZE).setHeight(RADIO_SIZE);
        Image no = new Image(ImageDataFactory.create(NO_PICTURE)).setWidth(RADIO_SIZE).setHeight(RADIO_SIZE);
        p1.add(Objects.equals("K001-001", miningHistory) ? yes : no).add(" 100年以上   ")
                .add(Objects.equals("K001-002", miningHistory) ? yes : no).add(" 50-100年    ")
                .add(Objects.equals("K001-003", miningHistory) ? yes : no).add(" 10-50年    ")
                .add(Objects.equals("K001-004", miningHistory) ? yes : no).add(" 10年以下");
        table.addCell(c4).addCell(c5).addCell(new Cell(7, 6).add(p1));
        //第八行
        Cell c6 = new Cell(8, 1).setBorderBottom(Border.NO_BORDER).setBorderTop(Border.NO_BORDER);
        Cell c7 = new Cell(8, 2).add(new Paragraph("采矿方式"));
        List<String> miningMethods = fill.getMiningMethods();
        if (CollectionUtils.isEmpty(miningMethods)) {
            miningMethods = new ArrayList<>();
        }
        Cell c8 = new Cell(8, 6);
        Paragraph p2 = new Paragraph().add(miningMethods.contains("C001-001") ? yes : no).add(" 地下开采     ")
                .add(miningMethods.contains("C001-002") ? yes : no).add(" 露天开采     ")
                .add(miningMethods.contains("C001-003") ? yes : no).add(" 联合开采     ")
                .add(miningMethods.contains("C001-004") ? yes : no).add(" 其他:");
        if (miningMethods.contains("C001-004") && org.springframework.util.StringUtils.hasText(fill.getMiningMethodsDetail())) {
            p2.add(fill.getMiningMethodsDetail());
        }
        table.addCell(c6).addCell(c7).addCell(c8.add(p2));
        //第九行
        Cell c9 = new Cell(9, 1).setBorderBottom(Border.NO_BORDER).setBorderTop(Border.NO_BORDER);
        Cell c10 = new Cell(9, 2).add(new Paragraph("选矿工艺"));
        List<String> process = fill.getMineralProcessingProcess();
        if (CollectionUtils.isEmpty(process)) {
            process = new ArrayList<>();
        }
        Paragraph p3 = new Paragraph().add(process.contains("X001-001") ? yes : no).add(" 重选   ")
                .add(process.contains("X001-002") ? yes : no).add(" 浮选   ")
                .add(process.contains("X001-003") ? yes : no).add(" 磁选   ")
                .add(process.contains("X001-004") ? yes : no).add(" 联合选矿   ")
                .add(process.contains("X001-005") ? yes : no).add(" 其他:");
        if (process.contains("X001-005") && StringUtils.isNotBlank(fill.getMineralProcessingProcessDetail())) {
            p3.add(fill.getMineralProcessingProcessDetail());
        }
        table.addCell(c9).addCell(c10).addCell(new Cell(9, 6).add(p3));
        //第十行
        Cell c11 = new Cell(10, 1).add(new Paragraph("矿山开")).setBorderBottom(Border.NO_BORDER).setBorderTop(Border.NO_BORDER);
        Cell c12 = new Cell(10, 2).add(new Paragraph("就地选矿"));
        String inSituBeneficiation = fill.getInSituBeneficiation();
        Paragraph p4 = new Paragraph();
        if (Objects.equals(inSituBeneficiation, "1")) {
            p4.add(yes).add(" 是    ").add(no).add(" 否   ");
        } else if (Objects.equals(inSituBeneficiation, "2")) {
            p4.add(no).add(" 是    ").add(yes).add(" 否   ");
        } else {
            p4.add(no).add(" 是    ").add(no).add(" 否   ");
        }
        table.addCell(c11).addCell(c12).addCell(new Cell(10, 6).add(p4));
        //第十一行
        Cell c13 = new Cell(11, 1).add(new Paragraph("采")).setBorderBottom(Border.NO_BORDER).setBorderTop(Border.NO_BORDER);
        Cell c14 = new Cell(11, 2).add(new Paragraph("就地冶炼"));
        String smeltingInSitu = fill.getSmeltingInSitu();
        Paragraph p5 = new Paragraph();
        if (Objects.equals(smeltingInSitu, "1")) {
            p5.add(yes).add(" 是    ").add(no).add(" 否   ");
        } else if (Objects.equals(smeltingInSitu, "2")) {
            p5.add(no).add(" 是    ").add(yes).add(" 否   ");
        } else {
            p5.add(no).add(" 是    ").add(no).add(" 否   ");
        }
        table.addCell(c13).addCell(c14).addCell(new Cell(11, 6).add(p5));
        //第十二行
        Cell c15 = new Cell(12, 1).setBorderBottom(Border.NO_BORDER).setBorderTop(Border.NO_BORDER);
        Cell c16 = new Cell(12, 2).setBorderBottom(Border.NO_BORDER);
        Cell c17 = new Cell(12, 2).add(new Paragraph("指标")).setTextAlignment(TextAlignment.CENTER);
        Cell c18 = new Cell(12, 2).add(new Paragraph("最小值").setTextAlignment(TextAlignment.CENTER));
        Cell c19 = new Cell(12, 2).add(new Paragraph("最大值").setTextAlignment(TextAlignment.CENTER));
        table.addCell(c15).addCell(c16).addCell(c17).addCell(c18).addCell(c19);
        int lineNum = 13;
        List<String> indicators = fill.getIndicators();
        List<String> indicatorsMax = fill.getIndicatorsMax();
        List<String> indicatorsMin = fill.getIndicatorsMin();
        List<Dict> dicts = dictMapper.selectList(Wrappers.lambdaQuery(Dict.class).in(Dict::getValue, indicators));
        Map<String, String> hashMap = new HashMap<>();
        if (!CollectionUtils.isEmpty(dicts)) {
            hashMap = dicts.stream().collect(Collectors.toMap(Dict::getValue, Dict::getName));
            for (int i = 0; i < dicts.size(); i++) {
                Cell cell1 = new Cell(lineNum, 1).setBorderBottom(Border.NO_BORDER).setBorderTop(Border.NO_BORDER);
                Cell cell2 = new Cell(lineNum, 2).setBorderBottom(Border.NO_BORDER).setBorderTop(Border.NO_BORDER);
                if (i == dicts.size() / 2) {
                    cell2.add(new Paragraph("矿石重金属或其他元素含量(毫"));
                } else if (i == (dicts.size() / 2 + 1)) {
                    cell2.add(new Paragraph("克/千克)"));
                }
                Cell cell3 = new Cell(lineNum, 2).add(new Paragraph(hashMap.get(dicts.get(i).getValue())).setTextAlignment(TextAlignment.CENTER));
                Cell cell4 = new Cell(lineNum, 2).add(new Paragraph(StringUtils.isNotBlank(indicatorsMin.get(i)) ? indicatorsMin.get(i) : "").setTextAlignment(TextAlignment.CENTER));
                Cell cell5 = new Cell(lineNum, 2).add(new Paragraph(StringUtils.isNotBlank(indicatorsMax.get(i)) ? indicatorsMax.get(i) : "").setTextAlignment(TextAlignment.CENTER));
                table.addCell(cell1).addCell(cell2).addCell(cell3).addCell(cell4).addCell(cell5);
                lineNum += 1;
            }
        }
        return lineNum;
    }
 //矿业固体废物
    private int solidWaste(Table table, Fill fill, int lineNum) throws MalformedURLException {
        Image yes = new Image(ImageDataFactory.create(YES_PICTURE)).setWidth(RADIO_SIZE).setHeight(RADIO_SIZE);
        Image no = new Image(ImageDataFactory.create(NO_PICTURE)).setWidth(RADIO_SIZE).setHeight(RADIO_SIZE);
        //是否存在固体废物
        Cell c1 = new Cell(lineNum, 1).setBorderBottom(Border.NO_BORDER);
        Cell c2 = new Cell(lineNum, 2).add(new Paragraph("是否存在固体废物*"));
        Cell c3 = new Cell(lineNum, 6);
        String isExists = fill.getIsExists();
        Paragraph p1 = new Paragraph();
        if (Objects.equals(isExists, "1")) {
            p1.add(yes).add(" 是    ").add(no).add(" 否 ");
        } else if (Objects.equals(isExists, "2")) {
            p1.add(no).add(" 是    ").add(yes).add(" 否 ");
        } else {
            p1.add(no).add(" 是    ").add(no).add(" 否 ");
        }
        p1.add("(若选择该项,本部分后面内容可不填写)");
        table.addCell(c1).addCell(c2).addCell(c3.add(p1));
        lineNum += 1;
        //如果选项是否 所有条件值置为空
        if (Objects.equals(isExists, "2")) {
            fill.setSolidWasteCategory(new ArrayList<>());
            fill.setNumberOfStackPoints("");
            fill.setSurroundingAgriculturalLand("");
            fill.setTotalAmountOfStorage("");
            fill.setTotalAreaOfTheStockpile("");
            fill.setMorphology(new ArrayList<>());
            fill.setSolidWasteProperties(new ArrayList<>());
            fill.setMajorPollutionPathways(new ArrayList<>());
            fill.setPreventionAndMeasures("");
            fill.setPollutionOfAgriculturalLand(new PollutionOfAgriculturalLand());
        }
        //固废类别
        Cell c4 = new Cell(lineNum, 1).setBorderBottom(Border.NO_BORDER).setBorderTop(Border.NO_BORDER);
        Cell c5 = new Cell(lineNum, 2).add(new Paragraph("固废类别*"));
        Cell c6 = new Cell(lineNum, 6);

        List<String> solidWasteCategory = fill.getSolidWasteCategory();
        if (CollectionUtils.isEmpty(solidWasteCategory)) {
            solidWasteCategory = new ArrayList<>();
        }
        Paragraph p2 = new Paragraph();
        p2.add(solidWasteCategory.contains("G001-001") ? yes : no).add(" 采矿废石     ")
                .add(solidWasteCategory.contains("G001-002") ? yes : no).add(" 选矿尾矿     ")
                .add(solidWasteCategory.contains("G001-003") ? yes : no).add(" 煤矸石     ")
                .add(solidWasteCategory.contains("G001-004") ? yes : no).add(" 冶炼废渣     ")
                .add(solidWasteCategory.contains("G001-005") ? yes : no).add(" 其他:");
        if (solidWasteCategory.contains("G001-005") && StringUtils.isNotBlank(fill.getSolidWasteCategoryDetail())) {
            p2.add(fill.getSolidWasteCategoryDetail());
        }
        table.addCell(c4).addCell(c5).addCell(c6.add(p2));
        lineNum += 1;
        //堆存点数量
        Cell c7 = new Cell(lineNum, 1).setBorderBottom(Border.NO_BORDER).setBorderTop(Border.NO_BORDER);
        Cell c8 = new Cell(lineNum, 2).add(new Paragraph("堆存点数量*"));
        String points = fill.getNumberOfStackPoints();
        Cell c9 = new Cell(lineNum, 2).add(new Paragraph(StringUtils.isNotBlank(points) ? points : "").add("处"));
        Cell c10 = new Cell(lineNum, 2).add(new Paragraph("距离周边农用地*"));
        String land = fill.getSurroundingAgriculturalLand();
        Cell c11 = new Cell(lineNum, 2).add(new Paragraph(StringUtils.isNotBlank(land) ? land : "").add("千米"));
        table.addCell(c7).addCell(c8).addCell(c9).addCell(c10).addCell(c11);
        lineNum += 1;
        //堆存总量
        Cell c12 = new Cell(lineNum, 1).setBorderBottom(Border.NO_BORDER).setBorderTop(Border.NO_BORDER);
        Cell c13 = new Cell(lineNum, 2).add(new Paragraph("堆存总量*"));
        String storage = fill.getTotalAmountOfStorage();
        Cell c14 = new Cell(lineNum, 2).add(new Paragraph(StringUtils.isNotBlank(storage) ? points : "").add("万吨"));
        Cell c15 = new Cell(lineNum, 2).add(new Paragraph("堆存总面积*"));
        String stockpile = fill.getTotalAreaOfTheStockpile();
        Cell c16 = new Cell(lineNum, 2).add(new Paragraph(StringUtils.isNotBlank(stockpile) ? stockpile : "").add("平方米"));
        table.addCell(c12).addCell(c13).addCell(c14).addCell(c15).addCell(c16);
        lineNum += 1;
        //形态
        Cell c17 = new Cell(lineNum, 1).setBorderBottom(Border.NO_BORDER).setBorderTop(Border.NO_BORDER);
        Cell c18 = new Cell(lineNum, 2).add(new Paragraph("形态"));
        List<String> morphology = fill.getMorphology();
        if (CollectionUtils.isEmpty(morphology)) {
            morphology = new ArrayList<>();
        }
        Cell c19 = new Cell(lineNum, 6);
        Paragraph p3 = new Paragraph();
        p3.add(morphology.contains("X002-001") ? yes : no).add(" 固体废物     ")
                .add(morphology.contains("X002-002") ? yes : no).add(" 半固体废物     ")
                .add(morphology.contains("X002-003") ? yes : no).add(" 其他:");
        if (morphology.contains("X002-003") && StringUtils.isNotBlank(fill.getMorphologyDetail())) {
            p3.add(fill.getMorphologyDetail());
        }
        table.addCell(c17).addCell(c18).addCell(c19.add(p3));
        lineNum += 1;
        List<Stockpile> properties = fill.getSolidWasteProperties();
        List<String> proList = properties.stream().map(item -> item.getSolidWasteProperties()).collect(Collectors.toList());
        List<String> stackingMode = properties.stream().map(item -> item.getStackingMode()).collect(Collectors.toList());
        if (CollectionUtils.isEmpty(stackingMode)) {
            stackingMode = new ArrayList<>();
        }
        //固废属性
        Cell c20 = new Cell(lineNum, 1).add(new Paragraph("矿业固体废物")).setBorderBottom(Border.NO_BORDER).setBorderTop(Border.NO_BORDER);
        Cell c21 = new Cell(lineNum, 2).add(new Paragraph("固体废物属性*"));
        if (CollectionUtils.isEmpty(proList)) {
            proList = new ArrayList<>();
        }
        Cell c22 = new Cell(lineNum, 6);
        Paragraph p4 = new Paragraph();
        p4.add(proList.contains("G002-001") ? yes : no).add(" 第I类一般工业固体废物     ")
                .add(proList.contains("G002-002") ? yes : no).add(" 第II类一般工业固体废物     ")
                .add(proList.contains("G002-003") ? yes : no).add(" 危险废物     ")
                .add(proList.contains("G002-004") ? yes : no).add(" 属性不明确     ")
                .add(proList.contains("G002-005") ? yes : no).add(" 硫化矿开采产生的固体废物     ");
        table.addCell(c20).addCell(c21).addCell(c22.add(p4));
        lineNum += 1;
        //堆存方式
        Cell c23 = new Cell(lineNum, 1).setBorderBottom(Border.NO_BORDER).setBorderTop(Border.NO_BORDER);
        Cell c24 = new Cell(lineNum, 2).add(new Paragraph("堆存方式"));
        Cell c25 = new Cell(lineNum, 6);
        Paragraph p5 = new Paragraph()
                .add(stackingMode.contains("D006-001") ? yes : no).add(" 贮存场     ")
                .add(stackingMode.contains("D006-002") ? yes : no).add(" 填埋场     ")
                .add(stackingMode.contains("D006-003") ? yes : no).add(" 尾矿库     ")
                .add(stackingMode.contains("D006-004") ? yes : no).add(" 散乱堆放     ")
                .add(stackingMode.contains("D006-005") ? yes : no).add(" 其他:");
        if (stackingMode.contains("X002-003")) {
            List<String> collect = properties.stream().filter(item -> Objects.equals(item.getStackingMode(), "D006-005"))
                    .map(Stockpile::getOther).collect(Collectors.toList());
            if (!CollectionUtils.isEmpty(collect) && collect.size() >= 1)
                p5.add(collect.get(1));
        }
        table.addCell(c23).addCell(c24).addCell(c25.add(p5));
        lineNum += 1;
        //主要污染途径
        Cell c26 = new Cell(lineNum, 1).setBorderBottom(Border.NO_BORDER).setBorderTop(Border.NO_BORDER);
        Cell c27 = new Cell(lineNum, 2).add(new Paragraph("主要污染途径"));
        Cell c28 = new Cell(lineNum, 6);
        List<String> pathways = fill.getMajorPollutionPathways();
        if (CollectionUtils.isEmpty(pathways)) {
            pathways = new ArrayList<>();
        }
        Paragraph p6 = new Paragraph()
                .add(pathways.contains("Z001-001") ? yes : no).add(" 风力侵蚀造成扬尘    ")
                .add(pathways.contains("Z001-002") ? yes : no).add(" 地面径流造成固废流失    ")
                .add(pathways.contains("Z001-003") ? yes : no).add(" 其他:");
        if (pathways.contains("Z001-003") && StringUtils.isNotBlank(fill.getMajorPollutionPathwaysDetail())) {
            p6.add(fill.getMajorPollutionPathwaysDetail());
        }
        table.addCell(c26).addCell(c27).addCell(c28);
        lineNum += 1;
        //污染防治措施
        Cell c29 = new Cell(lineNum, 1).setBorderBottom(Border.NO_BORDER).setBorderTop(Border.NO_BORDER);
        Cell c30 = new Cell(lineNum, 2).add(new Paragraph("污染防治措施*"));
        Cell c31 = new Cell(lineNum, 6);
        String measures = fill.getPreventionAndMeasures();
        Paragraph p7 = new Paragraph()
                .add(Objects.equals(measures, "W001-001") ? yes : no).add(" 按照有关标准贮存或处置     ")
                .add(Objects.equals(measures, "W001-002") ? yes : no).add(" 无防扬散、防流失、防渗流措施      ")
                .add(Objects.equals(measures, "W001-003") ? yes : no).add(" 其他:");
        if (Objects.equals(measures, "W001-003") && StringUtils.isNotBlank(fill.getPreventionAndMeasuresDetail())) {
            p7.add(fill.getPreventionAndMeasuresDetail());
        }
        table.addCell(c29).addCell(c30).addCell(c31.add(p7));
        lineNum += 1;
        //污染农用地情况
        PollutionOfAgriculturalLand pollutionOfAgriculturalLand = fill.getPollutionOfAgriculturalLand();
        Cell c32 = new Cell(lineNum, 1).setBorderBottom(Border.NO_BORDER).setBorderTop(Border.NO_BORDER);
        Cell c33 = new Cell(lineNum, 2).setBorderBottom(Border.NO_BORDER).setBorderTop(Border.NO_BORDER);
        Cell c34 = new Cell(lineNum, 4).add(new Paragraph("尾矿、废渣是否通过雨水冲刷进入灌溉水系"));
        Cell c35 = new Cell(lineNum, 2);
        String pl1 = pollutionOfAgriculturalLand.getPl1();
        table.addCell(c32).addCell(c33).addCell(c34).addCell(c35.add(isRadio(pl1)));
        lineNum += 1;
        Cell c36 = new Cell(lineNum, 1).setBorderBottom(Border.NO_BORDER).setBorderTop(Border.NO_BORDER);
        Cell c37 = new Cell(lineNum, 2).add(new Paragraph("污染农用地情况*")).setBorderBottom(Border.NO_BORDER).setBorderTop(Border.NO_BORDER);
        Cell c38 = new Cell(lineNum, 4).add(new Paragraph("地面径流造成固废流失"));
        String pl2 = pollutionOfAgriculturalLand.getPl2();
        Cell c39 = new Cell(lineNum, 2).add(isRadio(pl2));
        table.addCell(c36).addCell(c37).addCell(c38).addCell(c39);
        lineNum += 1;
        Cell c40 = new Cell(lineNum, 1).setBorderBottom(Border.NO_BORDER).setBorderTop(Border.NO_BORDER);
        Cell c41 = new Cell(lineNum, 2).setBorderBottom(Border.NO_BORDER).setBorderTop(Border.NO_BORDER);
        Cell c42 = new Cell(lineNum, 4).add(new Paragraph("是否存在矿石运输通过扬散污染农用地现象"));
        String pl3 = pollutionOfAgriculturalLand.getPl3();
        Cell c43 = new Cell(lineNum, 2).add(isRadio(pl3));
        table.addCell(c40).addCell(c41).addCell(c42).addCell(c43);
        lineNum += 1;
        String pl4 = pollutionOfAgriculturalLand.getPl4();
        Cell c44 = new Cell(lineNum, 1).setBorderBottom(Border.NO_BORDER).setBorderTop(Border.NO_BORDER);
        Cell c45 = new Cell(lineNum, 2).setBorderTop(Border.NO_BORDER);
        Cell c46 = new Cell(lineNum, 6).add(new Paragraph("其他:")
                .add(StringUtils.isNotBlank(pl4) ? pl4 : ""));
        table.addCell(c44).addCell(c45).addCell(c46);
        lineNum += 1;
        Cell c47 = new Cell(lineNum, 1).setBorderBottom(Border.NO_BORDER).setBorderTop(Border.NO_BORDER);
        Cell c48 = new Cell(lineNum, 2).add(new Paragraph("现场照片")).setBorderBottom(Border.NO_BORDER);
        Cell c49 = new Cell(lineNum, 6);
        int pictureSize = 0;
        Paragraph p8 = new Paragraph();
        if (org.springframework.util.StringUtils.hasText(fill.getClosePhoto5())) {
            AppFile picture = appFileService.getById(fill.getClosePhoto5());
            if (!ObjectUtils.isEmpty(picture)) {
                try {
                    InputStream is = null;
                    try {
                        is = new BufferedInputStream(new FileInputStream(picture.getPath()));
                        BufferedImage image2 = ImageIO.read(is);
                        Image image = new Image(ImageDataFactory.create(image2, null)).setMarginRight(2);
                        image.setWidth(115).setHeight(155);
                        p8.add(image);
                        pictureSize++;
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                } catch (Exception e) {
                    log.error(e.getMessage());
                }
            }
        }
        if (org.springframework.util.StringUtils.hasText(fill.getClosePhoto6())) {
            AppFile picture = appFileService.getById(fill.getClosePhoto6());
            if (!ObjectUtils.isEmpty(picture)) {
                try {
                    InputStream is = new BufferedInputStream(new FileInputStream(picture.getPath()));
                    BufferedImage image2 = ImageIO.read(is);
                    Image image = new Image(ImageDataFactory.create(image2, null)).setMarginRight(2);
                    image.setWidth(115).setHeight(155);
                    p8.add(image);
                } catch (Exception e) {
                    log.error(e.getMessage());
                }
            }
        }
        if (org.springframework.util.StringUtils.hasText(fill.getClosePhoto7())) {
            AppFile picture = appFileService.getById(fill.getClosePhoto7());
            if (!ObjectUtils.isEmpty(picture)) {
                try {
                    InputStream is = null;
                    try {
                        is = new BufferedInputStream(new FileInputStream(picture.getPath()));
                        BufferedImage image2 = ImageIO.read(is);
                        Image image = new Image(ImageDataFactory.create(image2, null)).setMarginRight(2);
                        image.setWidth(115).setHeight(155);
                        p8.add(image);
                        pictureSize++;
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                } catch (Exception e) {
                    log.error(e.getMessage());
                }
            }
        }
        if (pictureSize > 0) {
            c48.setPaddingTop(80);
        }
        Cell c50 = new Cell(lineNum, 1).setBorderBottom(Border.NO_BORDER).setBorderTop(Border.NO_BORDER);
        Cell c51 = new Cell(lineNum, 2).setHeight(12).setBorderTop(Border.NO_BORDER);
        Cell c52 = new Cell(lineNum, 6);
        Paragraph p9 = new Paragraph();
        if (org.springframework.util.StringUtils.hasText(fill.getClosePhoto8())) {
            AppFile picture = appFileService.getById(fill.getClosePhoto8());
            if (!ObjectUtils.isEmpty(picture)) {
                try {
                    InputStream is = null;
                    try {
                        is = new BufferedInputStream(new FileInputStream(picture.getPath()));
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                    if (is != null) {
                        BufferedImage image2 = ImageIO.read(is);
                        Image image = new Image(ImageDataFactory.create(image2, null)).setMarginRight(2);
                        image.setWidth(115).setHeight(155);
                        p9.add(image);
                    }
                } catch (Exception e) {
                    log.error(e.getMessage());
                }
            }
        }
        if (org.springframework.util.StringUtils.hasText(fill.getFarPhoto3())) {
            AppFile picture = appFileService.getById(fill.getFarPhoto3());
            if (!ObjectUtils.isEmpty(picture)) {
                try {
                    InputStream is = null;
                    try {
                        is = new BufferedInputStream(
                                new FileInputStream(picture.getPath()));
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                    if (is != null) {
                        BufferedImage image2 = ImageIO.read(is);
                        Image image = new Image(ImageDataFactory.create(image2, null)).setMarginRight(2);
                        image.setWidth(115).setHeight(155);
                        p9.add(image);
                    }
                } catch (Exception e) {
                    log.error(e.getMessage());
                }
            }
        }
        if (org.springframework.util.StringUtils.hasText(fill.getFarPhoto4())) {
            AppFile picture = appFileService.getById(fill.getFarPhoto4());
            if (!ObjectUtils.isEmpty(picture)) {
                try {
                    InputStream is = null;
                    try {
                        is = new BufferedInputStream(
                                new FileInputStream(picture.getPath()));
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                    if (is != null) {
                        BufferedImage image2 = ImageIO.read(is);
                        Image image = new Image(ImageDataFactory.create(image2, null)).setMarginRight(2);
                        image.setWidth(115).setHeight(155);
                        p9.add(image);
                    }
                } catch (Exception e) {
                    log.error(e.getMessage());
                }
            }
        }
        table.addCell(c47).addCell(c48).addCell(c49.add(p8));
        lineNum += 1;
        table.addCell(c50).addCell(c51).addCell(c52.add(p9));
        lineNum += 1;
        List<String> otherPhotos2 = fill.getOtherPhotos2();
        if (!CollectionUtils.isEmpty(otherPhotos2)) {
            int line = otherPhotos2.size() / 3;
            if (otherPhotos2.size() % 3 != 0) {
                line++;
            }
            for (int i = 0; i < line; i++) {
                Cell cell1 = new Cell(lineNum, 1);
                Cell cell2 = new Cell(lineNum, 2);
                if (i == 0 && i == line - 1) {
                    cell1.setBorderTop(Border.NO_BORDER);
                } else if (i == 0) {
                    cell1.setBorderTop(Border.NO_BORDER).setBorderBottom(Border.NO_BORDER);
                    cell2.setBorderBottom(Border.NO_BORDER);
                } else if (i == line - 1) {
                    cell1.setBorderTop(Border.NO_BORDER);
                    cell2.setBorderTop(Border.NO_BORDER);
                } else {
                    cell1.setBorderTop(Border.NO_BORDER).setBorderBottom(Border.NO_BORDER);
                    cell2.setBorderTop(Border.NO_BORDER).setBorderBottom(Border.NO_BORDER);
                }
                Cell cell3 = new Cell(lineNum, 6);
                if (i == line / 2) {
                    cell2.add(new Paragraph("其他照片"));
                }
                Paragraph paragraph = new Paragraph();
                String pictureId0 = otherPhotos2.get(i * 3 + 0);
                if (org.springframework.util.StringUtils.hasText(pictureId0)) {
                    AppFile picture = appFileService.getById(pictureId0);
                    if (!ObjectUtils.isEmpty(picture)) {
                        try {
                            InputStream is = null;
                            try {
                                is = new BufferedInputStream(new FileInputStream(picture.getPath()));
                                BufferedImage image2 = ImageIO.read(is);
                                Image image = new Image(ImageDataFactory.create(image2, null)).setMarginRight(2);
                                image.setWidth(115).setHeight(155);
                                paragraph.add(image);
                            } catch (FileNotFoundException e) {
                                e.printStackTrace();
                            }

                        } catch (Exception e) {
                            log.error(e.getMessage());
                        }
                    }
                }
                if ((i * 3 + 1) <= otherPhotos2.size() - 1) {
                    String pictureId1 = otherPhotos2.get(i * 3 + 1);
                    if (org.springframework.util.StringUtils.hasText(pictureId1)) {
                        AppFile picture = appFileService.getById(pictureId1);
                        if (!ObjectUtils.isEmpty(picture)) {
                            try {
                                InputStream is = null;
                                try {
                                    is = new BufferedInputStream(new FileInputStream(picture.getPath()));
                                    BufferedImage image2 = ImageIO.read(is);
                                    Image image = new Image(ImageDataFactory.create(image2, null)).setMarginRight(2);
                                    image.setWidth(115).setHeight(155);
                                    paragraph.add(image);
                                } catch (FileNotFoundException e) {
                                    e.printStackTrace();
                                }

                            } catch (Exception e) {
                                log.error(e.getMessage());
                            }
                        }
                    }
                }
                if ((i * 3 + 2) <= otherPhotos2.size() - 1) {
                    String pictureId2 = otherPhotos2.get(i * 3 + 2);
                    if (org.springframework.util.StringUtils.hasText(pictureId2)) {
                        AppFile picture = appFileService.getById(pictureId2);
                        if (!ObjectUtils.isEmpty(picture)) {
                            try {
                                InputStream is = null;
                                try {
                                    is = new BufferedInputStream(new FileInputStream(picture.getPath()));
                                    BufferedImage image2 = ImageIO.read(is);
                                    Image image = new Image(ImageDataFactory.create(image2, null)).setMarginRight(2);
                                    image.setWidth(115).setHeight(155);
                                    paragraph.add(image);
                                } catch (FileNotFoundException e) {
                                    e.printStackTrace();
                                }

                            } catch (Exception e) {
                                log.error(e.getMessage());
                            }
                        }
                    }
                }
                table.addCell(cell1).addCell(cell2).addCell(cell3.add(paragraph));
                lineNum++;
            }
        } else {
            Cell cell1 = new Cell(lineNum, 1).setBorderTop(Border.NO_BORDER);
            Cell cell2 = new Cell(lineNum, 2).add(new Paragraph("其他照片"));
            Cell cell3 = new Cell(lineNum, 6);
            table.addCell(cell1).addCell(cell2).addCell(cell3);
            lineNum++;
        }
        return lineNum;
    }
    //表尾
    private int tableTail(Table table, Fill fill, int lineNum) {
        Cell cell = new Cell(lineNum, 1).setBorder(Border.NO_BORDER);
        Cell tail = new Cell(lineNum, 8).setBorder(Border.NO_BORDER);
        String date = fill.getDate();
        String year = "";
        String month = "";
        String day = "";
        if (StringUtils.isNotBlank(date)) {
            String[] dates = date.split(" ");
            if (dates != null && dates.length >= 1) {
                String[] split = dates[0].split("-");
                if (split.length == 1) {
                    year = split[0];
                } else if (split.length == 2) {
                    year = split[0];
                    month = split[1];
                } else if (split.length == 3) {
                    year = split[0];
                    month = split[1];
                    day = split[2];
                }
            }
        }
        Paragraph paragraph = new Paragraph();
        paragraph.add("   调查人:").add(StringUtils.isNotBlank(fill.getInvestigator()) ? fill.getInvestigator() + "      " : "         ")
                .add("  记录人:").add(StringUtils.isNotBlank(fill.getNoteTaker()) ? fill.getNoteTaker() + "      " : "         ")
                .add("  审核人:").add(StringUtils.isNotBlank(fill.getNoteTaker()) ? fill.getNoteTaker() + "      " : "         ")
                .add("调查日期:  ").add(StringUtils.isNotBlank(year) ? year + " " : "   ").add("年   ")
                .add(StringUtils.isNotBlank(month) ? month + " " : "   ")
                .add("月   ").add(StringUtils.isNotBlank(day) ? day + " " : "   ").add("日   ");
        table.addCell(cell).addCell(tail.add(paragraph));
        return lineNum++;
    }
举报

相关推荐

0 条评论