|
|
@@ -1,19 +1,33 @@
|
|
|
package com.siwei.apply.service.impl;
|
|
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.siwei.apply.domain.DecisionTask;
|
|
|
import com.siwei.apply.domain.vo.*;
|
|
|
import com.siwei.apply.enums.DecisionType;
|
|
|
import com.siwei.apply.mapper.DecisionTaskMapper;
|
|
|
import com.siwei.apply.service.DecisionTaskService;
|
|
|
+import com.siwei.apply.service.IImageService;
|
|
|
+import com.siwei.apply.utils.NpoiHelper;
|
|
|
import com.siwei.common.core.exception.ServiceException;
|
|
|
+import com.siwei.common.core.utils.DateUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+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.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.imageio.ImageIO;
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
+import java.io.*;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -23,6 +37,9 @@ public class DecisionTaskServiceImpl implements DecisionTaskService {
|
|
|
@Autowired
|
|
|
private DecisionTaskMapper decisionTaskMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private IImageService imageService;
|
|
|
+
|
|
|
@Override
|
|
|
public String add(DecisionTaskVo decisionTaskVo) {
|
|
|
DecisionTask decisionTask = new DecisionTask();
|
|
|
@@ -239,6 +256,301 @@ public class DecisionTaskServiceImpl implements DecisionTaskService {
|
|
|
|
|
|
|
|
|
|
|
|
+ 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) d_xmxx_0.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);
|
|
|
+
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ String jsonString = objectMapper.writeValueAsString(wktsVo);
|
|
|
+ System.out.println("JSON输出: " + jsonString);
|
|
|
+
|
|
|
+ //RequestResult requestResult = spatialService.getImage(wktsVo);
|
|
|
+ Map<String, String> imageMap = this.getImage(wktsVo);
|
|
|
+ if (imageMap !=null && imageMap.get("path")!=null) {
|
|
|
+ //Map<String, String> map = (Map<String, String>) requestResult.get("data");
|
|
|
+ String path = imageMap.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 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 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;
|
|
|
+ }
|
|
|
+ private int jiefuo(XWPFDocument document, int pos, Map jgMap, String rwbsm, String ewkt) throws Exception {
|
|
|
+ if (Objects.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);
|
|
|
+ Map<String, String> sandiaoImageMap = this.getImage(sandiaoWktsVo);
|
|
|
+ if (sandiaoImageMap!=null && sandiaoImageMap.get("path")!=null) {
|
|
|
+ //Map<String, String> map = (Map<String, String>) requestResult1.get("data");
|
|
|
+ String path = sandiaoImageMap.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 先测试
|
|
|
+// Map<String, Object> res_11 = (Map) res_0.get(RequestResult.DATA_TAG);
|
|
|
+// List<Map> res_1 = (List<Map>) res_11.get("datalist");
|
|
|
+ // ------ 这里获取实际数据内容
|
|
|
+
|
|
|
+ List<Map> res_1 = new ArrayList<>();
|
|
|
+
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ Map<String, String> imageMap = this.getImage(wktsVo);
|
|
|
+ if (imageMap !=null && imageMap.get("path")!=null) {
|
|
|
+ //Map<String, String> map = (Map<String, String>) requestResult.get("data");
|
|
|
+ String path = imageMap.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);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String, String> getImage(WktsVo wktsVo) throws Exception {
|
|
|
+ String path = imageService.getSensingImage(wktsVo);
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("path", path);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|