|
@@ -0,0 +1,714 @@
|
|
|
+package com.onemap.analyse.service.impl;
|
|
|
+
|
|
|
+import com.onemap.analyse.service.GdbhReportService;
|
|
|
+import com.onemap.analyse.service.ILogService;
|
|
|
+import com.onemap.analyse.service.QytdzzReportService;
|
|
|
+import com.onemap.analyse.utils.NpoiHelper;
|
|
|
+import com.onemap.common.core.utils.DateUtils;
|
|
|
+import com.onemap.common.core.utils.StringUtils;
|
|
|
+import com.onemap.common.core.web.domain.RequestResult;
|
|
|
+import com.onemap.system.api.ApplyService;
|
|
|
+import com.onemap.system.api.SpatialService;
|
|
|
+import com.onemap.system.api.domain.WktsVo;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
+import org.apache.poi.util.Units;
|
|
|
+import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
|
|
|
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
|
+import org.apache.poi.xwpf.usermodel.XWPFRun;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.imageio.ImageIO;
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
+import java.io.*;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class QytdzzReportServiceImpl implements QytdzzReportService {
|
|
|
+ @Resource
|
|
|
+ private SpatialService spatialService;
|
|
|
+ @Value("${Hgxfx.temp}")
|
|
|
+ private String temp;
|
|
|
+ @Resource
|
|
|
+ private ILogService iLogService;
|
|
|
+ @Resource
|
|
|
+ private ApplyService applyService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String QytdzzCenerateDocx(Map<String, Object> qytuzzJgMap) throws Exception {
|
|
|
+ Map<String, Object> yjjg = (Map) qytuzzJgMap.get("YJJG");
|
|
|
+ String bsm = (String) yjjg.get("bsm");
|
|
|
+ iLogService.saveLog(bsm, "整治预判分析", "整治预判分析中生成报告开始。。。", "info");
|
|
|
+
|
|
|
+ // 文件硬盘真实路径
|
|
|
+ String timeStamp = DateUtils.dateTimeNow() + "";
|
|
|
+ String tempPath = temp;
|
|
|
+ String rootPath = File.separator + "整治预判分析报告" + File.separator + bsm;
|
|
|
+ String docxName = "整治预判分析报告_" + timeStamp + ".docx";
|
|
|
+ File f = new File(tempPath + rootPath);
|
|
|
+ if (!f.exists()) {
|
|
|
+ f.mkdirs();
|
|
|
+ }
|
|
|
+ String path = tempPath + rootPath + File.separator + docxName;
|
|
|
+ String xDpath = rootPath + File.separator + docxName;
|
|
|
+ createReportDoc(qytuzzJgMap, path);
|
|
|
+
|
|
|
+ iLogService.saveLog(bsm, "整治预判分析", "整治预判分析中生成报告完成。。。", "info");
|
|
|
+ return xDpath.replace("\\", "/");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createReportDoc(Map<String, Object> qytuzzJgMap, String reportPath) throws Exception {
|
|
|
+ Map<String, Object> yjjg = (Map<String, Object>) qytuzzJgMap.get("YJJG");
|
|
|
+ List<Map<String, Object>> tdxz = (List<Map<String, Object>>) qytuzzJgMap.get("3D");
|
|
|
+ List<Map<String, Object>> xzgd = (List<Map<String, Object>>) qytuzzJgMap.get("XZGD");
|
|
|
+ List<Map<String, Object>> sqsx = (List<Map<String, Object>>) qytuzzJgMap.get("SQSX");
|
|
|
+ List<Map<String, Object>> ghdk = (List<Map<String, Object>>) qytuzzJgMap.get("GHDK");
|
|
|
+
|
|
|
+ String bsm = (String) yjjg.get("bsm");
|
|
|
+ String xmmc = (String) yjjg.get("xmmc");
|
|
|
+ Integer sumNumber = (Integer) yjjg.get("sumNumber");
|
|
|
+ Double xzmj = (Double) yjjg.get("xzmj");
|
|
|
+ String ewkt = (String) yjjg.get("geom");
|
|
|
+ XWPFDocument document = null;
|
|
|
+ OutputStream outputStream = null;// 把doc输出到输出流
|
|
|
+ try {
|
|
|
+ document = new XWPFDocument();
|
|
|
+ int pos = 0;
|
|
|
+ // 0、文本标题
|
|
|
+ NpoiHelper.title(document, "整治预判分析报告", pos++);
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
|
|
|
+
|
|
|
+ // 1、项目选址信息
|
|
|
+ NpoiHelper.catalog(document, "一、整治预判分析信息", pos++);
|
|
|
+ List<String> listTemp = new ArrayList<>();
|
|
|
+ listTemp.add("\t预检分析名称:" + xmmc);
|
|
|
+ listTemp.add("\t预检分析面积:" + xzmj + "㎡");
|
|
|
+ listTemp.add("\t预检分析时间:" + DateUtils.getTime());
|
|
|
+
|
|
|
+ NpoiHelper.content(document, listTemp, pos++);
|
|
|
+ //因子
|
|
|
+// factorWrite(document, pos++, gdbhJgMap);
|
|
|
+ NpoiHelper.content(document, "预检分析范围", pos++);
|
|
|
+
|
|
|
+ WktsVo wktsVo = new WktsVo();
|
|
|
+ List<WktsVo.WktInfo> wktInfos = new ArrayList<>();
|
|
|
+ WktsVo.WktInfo wktInfoData = new WktsVo.WktInfo();
|
|
|
+ wktInfoData.setWkt(ewkt);
|
|
|
+ wktInfos.add(wktInfoData);
|
|
|
+ wktsVo.setWktInfos(wktInfos);
|
|
|
+ RequestResult requestResult = spatialService.getImage(wktsVo);
|
|
|
+ if (requestResult.isSuccess()) {
|
|
|
+ Map<String, String> map = (Map<String, String>) requestResult.get("data");
|
|
|
+ String path = map.get("path");
|
|
|
+ InputStream is = new FileInputStream(path);
|
|
|
+ BufferedImage bufferedImage = ImageIO.read(new File(path));
|
|
|
+ int originalWidth = bufferedImage.getWidth();
|
|
|
+ int originalHeight = bufferedImage.getHeight();
|
|
|
+ int useWidth = 400; // Set the desired width
|
|
|
+ int useHeight = useWidth * originalHeight / originalWidth;
|
|
|
+ XWPFRun run = document.createParagraph().createRun();
|
|
|
+ run.addPicture(is, XWPFDocument.PICTURE_TYPE_PNG, null, Units.toEMU(useWidth), Units.toEMU(useHeight));
|
|
|
+ pos++;
|
|
|
+ }
|
|
|
+
|
|
|
+ NpoiHelper.catalog(document, "二、整治前后土地利用结构变化分析结果", pos++);
|
|
|
+ NpoiHelper.content(document, "\t按照预检分析址范围,经对所选范围内的所有土地现状进行分析,分析结果如下:", pos++);
|
|
|
+ tdxzWrite(document, pos++, tdxz, "整治前后土地利用结构变化", ewkt);
|
|
|
+ pos++;
|
|
|
+
|
|
|
+ NpoiHelper.catalog(document, "三、新增耕地分析结果", pos++);
|
|
|
+ NpoiHelper.content(document, "\t按照预检分析址范围,经对所选范围内的新增土地进行分析,分析结果如下:", pos++);
|
|
|
+ xzgdWrite(document, pos++, xzgd, "新增耕地分析", ewkt);
|
|
|
+ pos++;
|
|
|
+
|
|
|
+ NpoiHelper.catalog(document, "四、三线分析结果", pos++);
|
|
|
+ NpoiHelper.content(document, "\t按照预检分析址范围,经对所选范围内的三区三线数据进行分析,分析结果如下:", pos++);
|
|
|
+ sqsxWrite(document, pos++, sqsx, "三线分析", ewkt);
|
|
|
+ pos++;
|
|
|
+
|
|
|
+ NpoiHelper.catalog(document, "五、三线分析结果", pos++);
|
|
|
+ NpoiHelper.content(document, "\t按照预检分析址范围,经对所选范围内的详细规划数据进行分析,分析结果如下:", pos++);
|
|
|
+ ghdkWrite(document, pos++, ghdk, "详细规划分析", ewkt);
|
|
|
+ pos++;
|
|
|
+
|
|
|
+// //结果
|
|
|
+// NpoiHelper.catalog(document, "二、耕地保护分析结果", pos++);
|
|
|
+// NpoiHelper.content(document, "\t按照耕地保护选址范围和分析模型,经对所选范围内的所有模型进行分析,分析结果如下:", pos++);
|
|
|
+// jiefuo(document, pos, gdbhJgMap, bsm, ewkt);
|
|
|
+ File fileDoc = new File(reportPath);
|
|
|
+ if (fileDoc.exists()) {
|
|
|
+ FileUtils.forceDelete(fileDoc);
|
|
|
+ }
|
|
|
+ // word文件输出流
|
|
|
+ outputStream = new FileOutputStream(reportPath);
|
|
|
+ document.write(outputStream);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ // 插入任务日志
|
|
|
+ // TODO 插入任务日志
|
|
|
+ iLogService.saveLog(bsm, "耕地保护分析", "生成耕地保护分析报告错误:" + e.getMessage(), "error");
|
|
|
+ throw e;
|
|
|
+ } finally {
|
|
|
+ if (document != null) {
|
|
|
+ try {
|
|
|
+ document.close();
|
|
|
+ } catch (Exception ex) {
|
|
|
+ System.out.println(ex.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (outputStream != null) {
|
|
|
+ try {
|
|
|
+ outputStream.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void tdxzWrite(XWPFDocument document, int pos, List<Map<String, Object>> dataTablelist, String title, String ewkt) throws IOException, InvalidFormatException {
|
|
|
+ List tabYzTitles = new ArrayList<NpoiHelper.TableTitle>();
|
|
|
+
|
|
|
+ NpoiHelper.TableTitle tableTitle = new NpoiHelper.TableTitle();
|
|
|
+ tableTitle.setKey("key");
|
|
|
+ tableTitle.setName("道路名称");
|
|
|
+ tableTitle.setWidth(1880);
|
|
|
+ tabYzTitles.add(tableTitle);
|
|
|
+
|
|
|
+ tableTitle = new NpoiHelper.TableTitle();
|
|
|
+ tableTitle.setKey("zzq_area");
|
|
|
+ tableTitle.setName("面积");
|
|
|
+ tableTitle.setWidth(1880);
|
|
|
+ tabYzTitles.add(tableTitle);
|
|
|
+
|
|
|
+ tableTitle = new NpoiHelper.TableTitle();
|
|
|
+ tableTitle.setKey("zzh_area");
|
|
|
+ tableTitle.setName("面积");
|
|
|
+ tableTitle.setWidth(1880);
|
|
|
+ tabYzTitles.add(tableTitle);
|
|
|
+
|
|
|
+ tableTitle = new NpoiHelper.TableTitle();
|
|
|
+ tableTitle.setKey("ce_area");
|
|
|
+ tableTitle.setName("面积");
|
|
|
+ tableTitle.setWidth(1880);
|
|
|
+ tabYzTitles.add(tableTitle);
|
|
|
+ NpoiHelper.setComTable(document, tabYzTitles, dataTablelist, title, pos);
|
|
|
+
|
|
|
+
|
|
|
+ List<WktsVo.WktInfo> sandiaoWtsList = new ArrayList<>();
|
|
|
+ WktsVo.WktInfo wktInfoData0 = new WktsVo.WktInfo();
|
|
|
+ wktInfoData0.setWkt(ewkt);
|
|
|
+ sandiaoWtsList.add(wktInfoData0);
|
|
|
+ if (dataTablelist != null && dataTablelist.size() > 0) {
|
|
|
+ for (Map map_0 : dataTablelist) {
|
|
|
+ String zzh_geom = (String) map_0.get("zzh_geom");
|
|
|
+ if (StringUtils.isNotEmpty(zzh_geom)) {
|
|
|
+ WktsVo.WktInfo wktInfo = new WktsVo.WktInfo();
|
|
|
+ String colorString = generateRandomColor();
|
|
|
+ wktInfo.setWkt(zzh_geom);
|
|
|
+ wktInfo.setFillColor(colorString);
|
|
|
+ wktInfo.setBorderColor(colorString);
|
|
|
+ sandiaoWtsList.add(wktInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ String zzq_geom = (String) map_0.get("zzq_geom");
|
|
|
+ if (StringUtils.isNotEmpty(zzq_geom)) {
|
|
|
+ WktsVo.WktInfo wktInfo = new WktsVo.WktInfo();
|
|
|
+ String colorString = generateRandomColor();
|
|
|
+ wktInfo.setWkt(zzq_geom);
|
|
|
+ wktInfo.setFillColor(colorString);
|
|
|
+ wktInfo.setBorderColor(colorString);
|
|
|
+ sandiaoWtsList.add(wktInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ WktsVo sandiaoWktsVo = new WktsVo();
|
|
|
+ sandiaoWktsVo.setWktInfos(sandiaoWtsList);
|
|
|
+ RequestResult requestResult1 = spatialService.getImage(sandiaoWktsVo);
|
|
|
+ if (requestResult1.isSuccess()) {
|
|
|
+ Map<String, String> map = (Map<String, String>) requestResult1.get("data");
|
|
|
+ String path = map.get("path");
|
|
|
+ InputStream is = new FileInputStream(path);
|
|
|
+ BufferedImage bufferedImage = ImageIO.read(new File(path));
|
|
|
+ int originalWidth = bufferedImage.getWidth();
|
|
|
+ int originalHeight = bufferedImage.getHeight();
|
|
|
+ int useWidth = 400; // Set the desired width
|
|
|
+ int useHeight = useWidth * originalHeight / originalWidth;
|
|
|
+ XWPFRun run = document.createParagraph().createRun();
|
|
|
+ run.addPicture(is, XWPFDocument.PICTURE_TYPE_PNG, null, Units.toEMU(useWidth), Units.toEMU(useHeight));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //因子信息配置
|
|
|
+ private void ghdkWrite(XWPFDocument document, int pos, List<Map<String, Object>> dataTablelist, String title, String ewkt) throws IOException, InvalidFormatException {
|
|
|
+ List tabYzTitles = new ArrayList<NpoiHelper.TableTitle>();
|
|
|
+
|
|
|
+ NpoiHelper.TableTitle tableTitle = new NpoiHelper.TableTitle();
|
|
|
+ tableTitle.setKey("groupvalue");
|
|
|
+ tableTitle.setName("业务类型");
|
|
|
+ tableTitle.setWidth(1880);
|
|
|
+ tabYzTitles.add(tableTitle);
|
|
|
+
|
|
|
+ tableTitle = new NpoiHelper.TableTitle();
|
|
|
+ tableTitle.setKey("sumvalue");
|
|
|
+ tableTitle.setName("面积");
|
|
|
+ tableTitle.setWidth(1880);
|
|
|
+ tabYzTitles.add(tableTitle);
|
|
|
+ NpoiHelper.setComTable(document, tabYzTitles, dataTablelist, title, pos);
|
|
|
+
|
|
|
+ List<WktsVo.WktInfo> sandiaoWtsList = new ArrayList<>();
|
|
|
+ WktsVo.WktInfo wktInfoData0 = new WktsVo.WktInfo();
|
|
|
+ wktInfoData0.setWkt(ewkt);
|
|
|
+ sandiaoWtsList.add(wktInfoData0);
|
|
|
+ if (dataTablelist != null && dataTablelist.size() > 0) {
|
|
|
+ for (Map map_0 : dataTablelist) {
|
|
|
+ WktsVo.WktInfo wktInfo = new WktsVo.WktInfo();
|
|
|
+ String geom = (String) map_0.get("geomvalue");
|
|
|
+ if (StringUtils.isNotEmpty(geom)) {
|
|
|
+ wktInfo.setWkt(geom);
|
|
|
+ String colorString = generateRandomColor();
|
|
|
+ wktInfo.setFillColor(colorString);
|
|
|
+ wktInfo.setBorderColor(colorString);
|
|
|
+ sandiaoWtsList.add(wktInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ WktsVo sandiaoWktsVo = new WktsVo();
|
|
|
+ sandiaoWktsVo.setWktInfos(sandiaoWtsList);
|
|
|
+ RequestResult requestResult1 = spatialService.getImage(sandiaoWktsVo);
|
|
|
+ if (requestResult1.isSuccess()) {
|
|
|
+ Map<String, String> map = (Map<String, String>) requestResult1.get("data");
|
|
|
+ String path = map.get("path");
|
|
|
+ InputStream is = new FileInputStream(path);
|
|
|
+ BufferedImage bufferedImage = ImageIO.read(new File(path));
|
|
|
+ int originalWidth = bufferedImage.getWidth();
|
|
|
+ int originalHeight = bufferedImage.getHeight();
|
|
|
+ int useWidth = 400; // Set the desired width
|
|
|
+ int useHeight = useWidth * originalHeight / originalWidth;
|
|
|
+ XWPFRun run = document.createParagraph().createRun();
|
|
|
+ run.addPicture(is, XWPFDocument.PICTURE_TYPE_PNG, null, Units.toEMU(useWidth), Units.toEMU(useHeight));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //因子信息配置
|
|
|
+ private void sqsxWrite(XWPFDocument document, int pos, List<Map<String, Object>> dataTablelist, String title, String ewkt) throws IOException, InvalidFormatException {
|
|
|
+ List tabYzTitles = new ArrayList<NpoiHelper.TableTitle>();
|
|
|
+
|
|
|
+ NpoiHelper.TableTitle tableTitle = new NpoiHelper.TableTitle();
|
|
|
+ tableTitle.setKey("yzBsm");
|
|
|
+ tableTitle.setName("业务类型");
|
|
|
+ tableTitle.setWidth(1880);
|
|
|
+ tabYzTitles.add(tableTitle);
|
|
|
+
|
|
|
+ tableTitle = new NpoiHelper.TableTitle();
|
|
|
+ tableTitle.setKey("sumvalue");
|
|
|
+ tableTitle.setName("面积");
|
|
|
+ tableTitle.setWidth(1880);
|
|
|
+ tabYzTitles.add(tableTitle);
|
|
|
+ NpoiHelper.setComTable(document, tabYzTitles, dataTablelist, title, pos);
|
|
|
+
|
|
|
+ List<WktsVo.WktInfo> sandiaoWtsList = new ArrayList<>();
|
|
|
+ WktsVo.WktInfo wktInfoData0 = new WktsVo.WktInfo();
|
|
|
+ wktInfoData0.setWkt(ewkt);
|
|
|
+ sandiaoWtsList.add(wktInfoData0);
|
|
|
+ if (dataTablelist != null && dataTablelist.size() > 0) {
|
|
|
+ for (Map map_0 : dataTablelist) {
|
|
|
+ WktsVo.WktInfo wktInfo = new WktsVo.WktInfo();
|
|
|
+ String geom = (String) map_0.get("geomvalue");
|
|
|
+ if (StringUtils.isNotEmpty(geom)) {
|
|
|
+ wktInfo.setWkt(geom);
|
|
|
+ String colorString = generateRandomColor();
|
|
|
+ wktInfo.setFillColor(colorString);
|
|
|
+ wktInfo.setBorderColor(colorString);
|
|
|
+ sandiaoWtsList.add(wktInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ WktsVo sandiaoWktsVo = new WktsVo();
|
|
|
+ sandiaoWktsVo.setWktInfos(sandiaoWtsList);
|
|
|
+ RequestResult requestResult1 = spatialService.getImage(sandiaoWktsVo);
|
|
|
+ if (requestResult1.isSuccess()) {
|
|
|
+ Map<String, String> map = (Map<String, String>) requestResult1.get("data");
|
|
|
+ String path = map.get("path");
|
|
|
+ InputStream is = new FileInputStream(path);
|
|
|
+ BufferedImage bufferedImage = ImageIO.read(new File(path));
|
|
|
+ int originalWidth = bufferedImage.getWidth();
|
|
|
+ int originalHeight = bufferedImage.getHeight();
|
|
|
+ int useWidth = 400; // Set the desired width
|
|
|
+ int useHeight = useWidth * originalHeight / originalWidth;
|
|
|
+ XWPFRun run = document.createParagraph().createRun();
|
|
|
+ run.addPicture(is, XWPFDocument.PICTURE_TYPE_PNG, null, Units.toEMU(useWidth), Units.toEMU(useHeight));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void xzgdWrite(XWPFDocument document, int pos, List<Map<String, Object>> dataTablelist, String title, String ewkt) throws IOException, InvalidFormatException {
|
|
|
+ List tabYzTitles = new ArrayList<NpoiHelper.TableTitle>();
|
|
|
+
|
|
|
+ NpoiHelper.TableTitle tableTitle = new NpoiHelper.TableTitle();
|
|
|
+ tableTitle.setKey("countvalue");
|
|
|
+ tableTitle.setName("新增耕地个数");
|
|
|
+ tableTitle.setWidth(1880);
|
|
|
+ tabYzTitles.add(tableTitle);
|
|
|
+
|
|
|
+ tableTitle = new NpoiHelper.TableTitle();
|
|
|
+ tableTitle.setKey("sumvalue");
|
|
|
+ tableTitle.setName("新增耕地面积");
|
|
|
+ tableTitle.setWidth(1880);
|
|
|
+ tabYzTitles.add(tableTitle);
|
|
|
+ NpoiHelper.setComTable(document, tabYzTitles, dataTablelist, title, pos);
|
|
|
+
|
|
|
+ List<WktsVo.WktInfo> sandiaoWtsList = new ArrayList<>();
|
|
|
+ WktsVo.WktInfo wktInfoData0 = new WktsVo.WktInfo();
|
|
|
+ wktInfoData0.setWkt(ewkt);
|
|
|
+ sandiaoWtsList.add(wktInfoData0);
|
|
|
+ if (dataTablelist != null && dataTablelist.size() > 0) {
|
|
|
+ for (Map map_0 : dataTablelist) {
|
|
|
+ WktsVo.WktInfo wktInfo = new WktsVo.WktInfo();
|
|
|
+ String geom = (String) map_0.get("geomvalue");
|
|
|
+ if (StringUtils.isNotEmpty(geom)) {
|
|
|
+ wktInfo.setWkt(geom);
|
|
|
+ String colorString = generateRandomColor();
|
|
|
+ wktInfo.setFillColor(colorString);
|
|
|
+ wktInfo.setBorderColor(colorString);
|
|
|
+ sandiaoWtsList.add(wktInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ WktsVo sandiaoWktsVo = new WktsVo();
|
|
|
+ sandiaoWktsVo.setWktInfos(sandiaoWtsList);
|
|
|
+ RequestResult requestResult1 = spatialService.getImage(sandiaoWktsVo);
|
|
|
+ if (requestResult1.isSuccess()) {
|
|
|
+ Map<String, String> map = (Map<String, String>) requestResult1.get("data");
|
|
|
+ String path = map.get("path");
|
|
|
+ InputStream is = new FileInputStream(path);
|
|
|
+ BufferedImage bufferedImage = ImageIO.read(new File(path));
|
|
|
+ int originalWidth = bufferedImage.getWidth();
|
|
|
+ int originalHeight = bufferedImage.getHeight();
|
|
|
+ int useWidth = 400; // Set the desired width
|
|
|
+ int useHeight = useWidth * originalHeight / originalWidth;
|
|
|
+ XWPFRun run = document.createParagraph().createRun();
|
|
|
+ run.addPicture(is, XWPFDocument.PICTURE_TYPE_PNG, null, Units.toEMU(useWidth), Units.toEMU(useHeight));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //因子信息配置
|
|
|
+ private void factorWrite(XWPFDocument document, int pos, Map jdList) {
|
|
|
+ List tabYzTitles = new ArrayList<NpoiHelper.TableTitle>();
|
|
|
+
|
|
|
+ NpoiHelper.TableTitle tableTitle = new NpoiHelper.TableTitle();
|
|
|
+ tableTitle.setKey("YXYZMCI");
|
|
|
+ tableTitle.setName("分析模型");
|
|
|
+ tableTitle.setWidth(1880);
|
|
|
+ tabYzTitles.add(tableTitle);
|
|
|
+
|
|
|
+ tableTitle = new NpoiHelper.TableTitle();
|
|
|
+ tableTitle.setKey("YXYZMCⅡ");
|
|
|
+ tableTitle.setName("数据名称");
|
|
|
+ tableTitle.setWidth(1880);
|
|
|
+ tabYzTitles.add(tableTitle);
|
|
|
+ List<Map<String, Object>> dataTablelist = getScxList(jdList);
|
|
|
+ NpoiHelper.setComTable(document, tabYzTitles, dataTablelist, "分析模型", pos);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void createReport(Map gdbhJgMap, String reportPath) throws Exception {
|
|
|
+ Map d_xmxx_0 = (Map) gdbhJgMap.get("xmxx");
|
|
|
+ String bsm = (String) d_xmxx_0.get("bsm");
|
|
|
+ String xmmc = (String) d_xmxx_0.get("xmmc");
|
|
|
+ Integer sumNumber = (Integer) d_xmxx_0.get("sumNumber");
|
|
|
+ Double xzmj = (Double) d_xmxx_0.get("xzmj");
|
|
|
+
|
|
|
+ XWPFDocument document = null;
|
|
|
+ OutputStream outputStream = null;// 把doc输出到输出流
|
|
|
+ try {
|
|
|
+ RequestResult res_0 = applyService.QueryGdbhJgGeom(bsm);
|
|
|
+ if (res_0.isError()) {
|
|
|
+ throw new Exception(String.valueOf(res_0.get(RequestResult.MSG_TAG)));
|
|
|
+ }
|
|
|
+
|
|
|
+ Map res_1 = (Map) res_0.get(RequestResult.DATA_TAG);
|
|
|
+ String ewkt = (String) res_1.get("geom");
|
|
|
+
|
|
|
+ document = new XWPFDocument();
|
|
|
+
|
|
|
+ int pos = 0;
|
|
|
+ // 0、文本标题
|
|
|
+ NpoiHelper.title(document, "耕地保护分析报告", pos++);
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
|
|
|
+
|
|
|
+ // 1、项目选址信息
|
|
|
+ NpoiHelper.catalog(document, "一、耕地保护分析信息", pos++);
|
|
|
+ List<String> listTemp = new ArrayList<>();
|
|
|
+ listTemp.add("\t项目名称:" + xmmc);
|
|
|
+ listTemp.add("\t图斑个数:" + sumNumber + "个");
|
|
|
+ listTemp.add("\t图斑面积:" + xzmj + "㎡");
|
|
|
+ listTemp.add("\t分析时间:" + DateUtils.getTime());
|
|
|
+ listTemp.add("\t分析因子:");
|
|
|
+ NpoiHelper.content(document, listTemp, pos++);
|
|
|
+ //因子
|
|
|
+ factorWrite(document, pos++, gdbhJgMap);
|
|
|
+ NpoiHelper.content(document, "分析范围", pos++);
|
|
|
+
|
|
|
+ WktsVo wktsVo = new WktsVo();
|
|
|
+ List<WktsVo.WktInfo> wktInfos = new ArrayList<>();
|
|
|
+ WktsVo.WktInfo wktInfoData = new WktsVo.WktInfo();
|
|
|
+ wktInfoData.setWkt(ewkt);
|
|
|
+ wktInfos.add(wktInfoData);
|
|
|
+ wktsVo.setWktInfos(wktInfos);
|
|
|
+ RequestResult requestResult = spatialService.getImage(wktsVo);
|
|
|
+ if (requestResult.isSuccess()) {
|
|
|
+ Map<String, String> map = (Map<String, String>) requestResult.get("data");
|
|
|
+ String path = map.get("path");
|
|
|
+ InputStream is = new FileInputStream(path);
|
|
|
+ BufferedImage bufferedImage = ImageIO.read(new File(path));
|
|
|
+ int originalWidth = bufferedImage.getWidth();
|
|
|
+ int originalHeight = bufferedImage.getHeight();
|
|
|
+ int useWidth = 400; // Set the desired width
|
|
|
+ int useHeight = useWidth * originalHeight / originalWidth;
|
|
|
+ XWPFRun run = document.createParagraph().createRun();
|
|
|
+ run.addPicture(is, XWPFDocument.PICTURE_TYPE_PNG, null, Units.toEMU(useWidth), Units.toEMU(useHeight));
|
|
|
+ pos++;
|
|
|
+ }
|
|
|
+
|
|
|
+ //结果
|
|
|
+ NpoiHelper.catalog(document, "二、耕地保护分析结果", pos++);
|
|
|
+ NpoiHelper.content(document, "\t按照耕地保护选址范围和分析模型,经对所选范围内的所有模型进行分析,分析结果如下:", pos++);
|
|
|
+ jiefuo(document, pos, gdbhJgMap, bsm, ewkt);
|
|
|
+ File fileDoc = new File(reportPath);
|
|
|
+ if (fileDoc.exists()) {
|
|
|
+ FileUtils.forceDelete(fileDoc);
|
|
|
+ }
|
|
|
+ // word文件输出流
|
|
|
+ outputStream = new FileOutputStream(reportPath);
|
|
|
+ document.write(outputStream);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ // 插入任务日志
|
|
|
+ // TODO 插入任务日志
|
|
|
+ iLogService.saveLog(bsm, "耕地保护分析", "生成耕地保护分析报告错误:" + e.getMessage(), "error");
|
|
|
+ throw e;
|
|
|
+ } finally {
|
|
|
+ if (document != null) {
|
|
|
+ try {
|
|
|
+ document.close();
|
|
|
+ } catch (Exception ex) {
|
|
|
+ System.out.println(ex.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (outputStream != null) {
|
|
|
+ try {
|
|
|
+ outputStream.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Map<String, Object>> getScxList(List<Map> jdList, Map<String, Object> factorMap, int level) {
|
|
|
+ List<Map<String, Object>> retList = new ArrayList<>();
|
|
|
+ for (Map mapData : jdList) {
|
|
|
+ String scxname = (String) mapData.get("scxname");
|
|
|
+
|
|
|
+ Map<String, Object> factorMap00 = new HashMap<>();
|
|
|
+ factorMap00.put("YXYZMCI", "");
|
|
|
+ factorMap00.put("YXYZMCⅡ", "");
|
|
|
+ factorMap00.put("YXYZMCⅢ", "");
|
|
|
+ factorMap00.put("YXZ", "");
|
|
|
+ if (factorMap != null) {
|
|
|
+ factorMap00.putAll(factorMap);
|
|
|
+ }
|
|
|
+ if (level == 0) {
|
|
|
+ factorMap00.put("YXYZMCI", scxname);
|
|
|
+ } else if (level == 1) {
|
|
|
+ factorMap00.put("YXYZMCⅡ", scxname);
|
|
|
+ } else if (level == 2) {
|
|
|
+ factorMap00.put("YXYZMCⅢ", scxname);
|
|
|
+ }
|
|
|
+ Object distanceObj = mapData.get("distance");
|
|
|
+ if (StringUtils.isNotNull(distanceObj)) {
|
|
|
+ factorMap00.put("YXZ", distanceObj);
|
|
|
+ }
|
|
|
+ retList.add(factorMap00);
|
|
|
+ Object childrenObj = mapData.get("children");
|
|
|
+ if (StringUtils.isNotNull(childrenObj)) {
|
|
|
+ List<Map> childrenList = (List<Map>) childrenObj;
|
|
|
+ List<Map<String, Object>> childrenMap = getScxList(childrenList, factorMap00, level + 1);
|
|
|
+ retList.addAll(childrenMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return retList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private int jiefuo(XWPFDocument document, int pos, Map jgMap, String rwbsm, String ewkt) throws Exception {
|
|
|
+ if (StringUtils.isNull(jgMap)) {
|
|
|
+ return pos;
|
|
|
+ }
|
|
|
+
|
|
|
+// XWPFParagraph pageBreakParagraph2 = document.createParagraph();
|
|
|
+// XWPFRun pageBreakRun2 = pageBreakParagraph2.createRun();
|
|
|
+// pageBreakRun2.addBreak(BreakType.PAGE);
|
|
|
+
|
|
|
+ Map sandiao = (Map) jgMap.get("sandiao");
|
|
|
+ String v_mx_bsmmc_0 = (String) sandiao.get("mx_bsmmc");
|
|
|
+ NpoiHelper.content(document, v_mx_bsmmc_0 + "; 分析结果如下:", pos++, ParagraphAlignment.CENTER);
|
|
|
+
|
|
|
+ List<Map<String, Object>> v_mx_data_0 = (List<Map<String, Object>>) sandiao.get("mx_data");
|
|
|
+ List sanDiaoTitles = new ArrayList<NpoiHelper.TableTitle>();
|
|
|
+ NpoiHelper.TableTitle tableTitle1 = new NpoiHelper.TableTitle();
|
|
|
+ tableTitle1.setKey("groupvalue");
|
|
|
+ tableTitle1.setName("三调类型");
|
|
|
+ tableTitle1.setWidth(2880);
|
|
|
+ sanDiaoTitles.add(tableTitle1);
|
|
|
+
|
|
|
+ tableTitle1 = new NpoiHelper.TableTitle();
|
|
|
+ tableTitle1.setKey("sumvalue");
|
|
|
+ tableTitle1.setName("三调类型面积(单位:㎡)");
|
|
|
+ tableTitle1.setWidth(3000);
|
|
|
+ sanDiaoTitles.add(tableTitle1);
|
|
|
+ NpoiHelper.setComTable(document, sanDiaoTitles, v_mx_data_0, "", pos);
|
|
|
+
|
|
|
+ List<WktsVo.WktInfo> sandiaoWtsList = new ArrayList<>();
|
|
|
+ WktsVo.WktInfo wktInfoData0 = new WktsVo.WktInfo();
|
|
|
+ wktInfoData0.setWkt(ewkt);
|
|
|
+ sandiaoWtsList.add(wktInfoData0);
|
|
|
+ if (v_mx_data_0 != null && v_mx_data_0.size() > 0) {
|
|
|
+ for (Map map_0 : v_mx_data_0) {
|
|
|
+ WktsVo.WktInfo wktInfo = new WktsVo.WktInfo();
|
|
|
+ String geom = (String) map_0.get("geom");
|
|
|
+ wktInfo.setWkt(geom);
|
|
|
+ String colorString = generateRandomColor();
|
|
|
+ wktInfo.setFillColor(colorString);
|
|
|
+ wktInfo.setBorderColor(colorString);
|
|
|
+ sandiaoWtsList.add(wktInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ WktsVo sandiaoWktsVo = new WktsVo();
|
|
|
+ sandiaoWktsVo.setWktInfos(sandiaoWtsList);
|
|
|
+ RequestResult requestResult1 = spatialService.getImage(sandiaoWktsVo);
|
|
|
+ if (requestResult1.isSuccess()) {
|
|
|
+ Map<String, String> map = (Map<String, String>) requestResult1.get("data");
|
|
|
+ String path = map.get("path");
|
|
|
+ InputStream is = new FileInputStream(path);
|
|
|
+ BufferedImage bufferedImage = ImageIO.read(new File(path));
|
|
|
+ int originalWidth = bufferedImage.getWidth();
|
|
|
+ int originalHeight = bufferedImage.getHeight();
|
|
|
+ int useWidth = 400; // Set the desired width
|
|
|
+ int useHeight = useWidth * originalHeight / originalWidth;
|
|
|
+ XWPFRun run = document.createParagraph().createRun();
|
|
|
+ run.addPicture(is, XWPFDocument.PICTURE_TYPE_PNG, null, Units.toEMU(useWidth), Units.toEMU(useHeight));
|
|
|
+ pos++;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Map> yzjg = (List<Map>) jgMap.get("yzjg");
|
|
|
+ for (Map yz_data : yzjg) {
|
|
|
+// XWPFParagraph pageBreakParagraph1 = document.createParagraph();
|
|
|
+// XWPFRun pageBreakRun1 = pageBreakParagraph1.createRun();
|
|
|
+// pageBreakRun1.addBreak(BreakType.PAGE);
|
|
|
+
|
|
|
+ String mx_bsmmc = (String) yz_data.get("mx_bsmmc");
|
|
|
+ String mx_bsm = (String) yz_data.get("mx_bsm");
|
|
|
+ NpoiHelper.content(document, mx_bsmmc + "; 分析结果如下:", pos++, ParagraphAlignment.CENTER);
|
|
|
+ List<Map> mx_data_list = (List<Map>) yz_data.get("mx_data");
|
|
|
+ for (Map d0_yz_data : mx_data_list) {
|
|
|
+ Integer d0_sumcount = (Integer) d0_yz_data.get("sumcount");
|
|
|
+ String d0_bsmmc = (String) d0_yz_data.get("bsmmc");
|
|
|
+ Double d0_sumvalue = (Double) d0_yz_data.get("sumvalue");
|
|
|
+ String d0_bsm = (String) d0_yz_data.get("bsm");
|
|
|
+
|
|
|
+ List tabYzTitles = new ArrayList<NpoiHelper.TableTitle>();
|
|
|
+ NpoiHelper.TableTitle tableTitle = new NpoiHelper.TableTitle();
|
|
|
+ tableTitle.setKey("sumcount");
|
|
|
+ tableTitle.setName(d0_bsmmc + "个数");
|
|
|
+ tableTitle.setWidth(2880);
|
|
|
+ tabYzTitles.add(tableTitle);
|
|
|
+
|
|
|
+ tableTitle = new NpoiHelper.TableTitle();
|
|
|
+ tableTitle.setKey("sumvalue");
|
|
|
+ tableTitle.setName(d0_bsmmc + "面积(单位:㎡)");
|
|
|
+ tableTitle.setWidth(3000);
|
|
|
+ tabYzTitles.add(tableTitle);
|
|
|
+ List<Map<String, Object>> dataTablelist = new ArrayList<>();
|
|
|
+ dataTablelist.add(d0_yz_data);
|
|
|
+ NpoiHelper.setComTable(document, tabYzTitles, dataTablelist, "", pos);
|
|
|
+
|
|
|
+ RequestResult res_0 = applyService.QueryGdbhJgYz(rwbsm, mx_bsm, d0_bsm);
|
|
|
+ if (res_0.isError()) {
|
|
|
+ throw new Exception(String.valueOf(res_0.get(RequestResult.MSG_TAG)));
|
|
|
+ }
|
|
|
+
|
|
|
+ //TODO 先测试
|
|
|
+ List<Map> res_1 = (List<Map>) res_0.get(RequestResult.DATA_TAG);
|
|
|
+
|
|
|
+ WktsVo wktsVo = new WktsVo();
|
|
|
+ List<WktsVo.WktInfo> wktInfos = new ArrayList<>();
|
|
|
+ WktsVo.WktInfo wktInfoData = new WktsVo.WktInfo();
|
|
|
+ wktInfoData.setWkt(ewkt);
|
|
|
+ wktInfos.add(wktInfoData);
|
|
|
+
|
|
|
+ if (res_1 != null && res_1.size() > 0) {
|
|
|
+ for (Map map_0 : res_1) {
|
|
|
+ WktsVo.WktInfo wktInfo = new WktsVo.WktInfo();
|
|
|
+ String geom = (String) map_0.get("geom");
|
|
|
+ wktInfo.setWkt(geom);
|
|
|
+ String colorString = generateRandomColor();
|
|
|
+ wktInfo.setFillColor(colorString);
|
|
|
+ wktInfo.setBorderColor(colorString);
|
|
|
+ wktInfos.add(wktInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ wktsVo.setWktInfos(wktInfos);
|
|
|
+ RequestResult requestResult = spatialService.getImage(wktsVo);
|
|
|
+ if (requestResult.isSuccess()) {
|
|
|
+ Map<String, String> map = (Map<String, String>) requestResult.get("data");
|
|
|
+ String path = map.get("path");
|
|
|
+ InputStream is = new FileInputStream(path);
|
|
|
+ BufferedImage bufferedImage = ImageIO.read(new File(path));
|
|
|
+ int originalWidth = bufferedImage.getWidth();
|
|
|
+ int originalHeight = bufferedImage.getHeight();
|
|
|
+ int useWidth = 400; // Set the desired width
|
|
|
+ int useHeight = useWidth * originalHeight / originalWidth;
|
|
|
+ XWPFRun run = document.createParagraph().createRun();
|
|
|
+ run.addPicture(is, XWPFDocument.PICTURE_TYPE_PNG, null, Units.toEMU(useWidth), Units.toEMU(useHeight));
|
|
|
+ pos++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return pos;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String generateRandomColor() {
|
|
|
+ Random random = new Random();
|
|
|
+ int red = random.nextInt(256);
|
|
|
+ int green = random.nextInt(256);
|
|
|
+ int blue = random.nextInt(256);
|
|
|
+ return String.format("#%02x%02x%02x", red, green, blue);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<Map<String, Object>> getScxList(Map factorMap) {
|
|
|
+ List<Map<String, Object>> retList = new ArrayList<>();
|
|
|
+ List<Map> jdList = (List<Map>) factorMap.get("yzjg");
|
|
|
+ for (Map mapData : jdList) {
|
|
|
+ String scxname = (String) mapData.get("mx_bsmmc");
|
|
|
+ List<Map> mx_data = (List<Map>) mapData.get("mx_data");
|
|
|
+ for (Map mapMxData : mx_data) {
|
|
|
+ String bsmmc = (String) mapMxData.get("bsmmc");
|
|
|
+ Map<String, Object> factorMap00 = new HashMap<>();
|
|
|
+ factorMap00.put("YXYZMCI", scxname);
|
|
|
+ factorMap00.put("YXYZMCⅡ", bsmmc);
|
|
|
+ retList.add(factorMap00);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return retList;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|