FzxzSchedule.java 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  1. package com.onemap.analyse.task;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.google.common.base.Joiner;
  4. import com.onemap.analyse.domain.*;
  5. import com.onemap.analyse.mapper.*;
  6. import com.onemap.analyse.utils.NpoiHelper;
  7. import com.onemap.analyse.utils.NumberUtil;
  8. import com.onemap.common.core.utils.StringUtils;
  9. import net.lingala.zip4j.core.ZipFile;
  10. import net.lingala.zip4j.exception.ZipException;
  11. import net.lingala.zip4j.model.ZipParameters;
  12. import net.lingala.zip4j.util.Zip4jConstants;
  13. import org.apache.commons.io.FileUtils;
  14. import org.apache.poi.xwpf.usermodel.*;
  15. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth;
  16. import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr;
  17. import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
  18. import org.springframework.beans.factory.annotation.Value;
  19. import org.springframework.stereotype.Component;
  20. import javax.annotation.Resource;
  21. import java.io.*;
  22. import java.math.BigInteger;
  23. import java.text.SimpleDateFormat;
  24. import java.util.*;
  25. import java.util.stream.Collectors;
  26. /**
  27. * 辅助选址模块定时刷新任务
  28. */
  29. @Component
  30. public class FzxzSchedule {
  31. //间隔时间 单位ms
  32. public static final long TIME_INTERVAL = 1 * 15000;
  33. //任务状态标识码
  34. private RwztDTO Rwzt = new RwztDTO();
  35. @Resource
  36. private FzxzMapper fzxzMapper;
  37. @Resource
  38. private FxrwrzMapper fxrwrzMapper;
  39. @Resource
  40. private FzxzJgGISMapper fzxzJgGISMapper;
  41. @Resource
  42. private FzxzXzyzMapper fzxzXzyzMapper;
  43. @Resource
  44. private FzxzTbMapper fzxzTbMapper;
  45. @Resource
  46. private FzxzJgyzMapper fzxzJgyzMapper;
  47. //辅助选址python方法名标识
  48. @Value("${Fzxz.functionId}")
  49. private String functionId;
  50. @Value("${Fzxz.mapFunctionId}")
  51. private String mapFunctionId;
  52. @Value("${Fzxz.fzxzShp}")
  53. private String fzxzShp;
  54. @Value("${Hgxfx.temp}")
  55. private String temp;
  56. ///**
  57. // * Scheduled 定时器参数
  58. // * cron表达式:指定任务在特定时间执行
  59. // * fixedDelay:表示上一次任务执行完成后多久再执行,参数类型long,单位:ms
  60. // * fixedDelayString:与fixedDelay一样,只是参数类型是String
  61. // * fixedRate:表示按一定的频率执行任务,参数类型long,单位:ms 如: fixedRate(5000),表示这个定时器任务每5秒执行一次
  62. // * fixedRateString:与fixedRate一样,只是参数类型变为String
  63. // * initialDelay:表示延迟多久再第一次执行任务,参数类型为long ,单位:ms
  64. // * initialDelayString:与initialDelay一样,只是参数类型String
  65. // */
  66. ///**
  67. // * @Async("name") 开启多线程
  68. // */
  69. ///**
  70. // * 辅助选址执行入口
  71. // */
  72. //@Async("taskExecutor")
  73. //@Scheduled(fixedDelay = TIME_INTERVAL)
  74. //public void FzxzStatus() {
  75. // try {
  76. // QueryWrapper<FzxzDTO> wrapper = new QueryWrapper<FzxzDTO>();
  77. // wrapper.eq("rwzt", Rwzt.getCreate());
  78. // //以创建时间正序排列
  79. // wrapper.orderByAsc("cjsj");
  80. // //每次只操作一条记录
  81. // List<FzxzDTO> ress = fzxzMapper.selectList(wrapper);
  82. // if (ress.size() > 0) {
  83. // FzxzDTO res = ress.get(0);
  84. // //插入执行状态
  85. // res.setRwzt(Rwzt.getRun());
  86. // res.setRwkssj(new Date());
  87. // QueryWrapper<FzxzDTO> query = new QueryWrapper<FzxzDTO>();
  88. // query.eq("bsm", res.getBsm());
  89. // fzxzMapper.update(res, query);
  90. // //插入任务日志
  91. // FxrwrzDTO rzDto = new FxrwrzDTO();
  92. // rzDto.setRwbsm(res.getBsm());
  93. // rzDto.setRwlx("辅助选址");
  94. // rzDto.setRzlr("开始分析");
  95. // rzDto.setRzlx("info");
  96. // rzDto.setRzsj(new Date());
  97. // fxrwrzMapper.insert(rzDto);
  98. // //执行python
  99. // Map<String, String> params = new HashMap<>();
  100. // params.put("bsm", res.getBsm());
  101. // String result = PythonExecute.Run(functionId, params);
  102. // if (!StringUtils.isEmpty(result) && result.contains("OK")) {//成功
  103. // res.setRwjssj(new Date());
  104. // res.setRwzt(Rwzt.getComplete());
  105. // //TODO 生成辅助选址结果报告 返回 FxReport实体
  106. // FzxzReport report = createReport(res.getBsm(), null);
  107. // if (report != null) {
  108. // res.setFxbg(report.getReportfile().replace(".docx", ".pdf"));
  109. // res.setZip(report.getZipfile());
  110. // }
  111. // fzxzMapper.update(res, query);
  112. // //插入成功日志
  113. // FxrwrzDTO successDto = new FxrwrzDTO();
  114. // successDto.setRwbsm(res.getBsm());
  115. // successDto.setRwlx("辅助选址");
  116. // successDto.setRzlr("计算完成");
  117. // successDto.setRzlx("info");
  118. // successDto.setRzsj(new Date());
  119. // fxrwrzMapper.insert(successDto);
  120. // } else {//失败
  121. // res.setRwjssj(new Date());
  122. // res.setRwzt(Rwzt.getError());
  123. // fzxzMapper.update(res, query);
  124. // //插入任务日志
  125. // FxrwrzDTO errorDto = new FxrwrzDTO();
  126. // errorDto.setRwbsm(res.getBsm());
  127. // errorDto.setRwlx("辅助选址");
  128. // errorDto.setRzlr("计算错误");
  129. // errorDto.setRzsj(new Date());
  130. // errorDto.setRzlx("error");
  131. // errorDto.setFxjg(result);
  132. // fxrwrzMapper.insert(errorDto);
  133. // }
  134. // System.out.println("辅助选址模块:" + res.getBsm() + "完成!!!!!!!! " + new Date().toString());
  135. // }
  136. // } catch (Exception e) {
  137. // e.printStackTrace();
  138. // }
  139. //}
  140. //根据选址任务生成报告
  141. public FzxzReport createReport(String bsm, List<String> xzbsmList) {
  142. //插入开始生成报告日志
  143. FxrwrzDTO successDto = new FxrwrzDTO();
  144. successDto.setRwbsm(bsm);
  145. successDto.setRwlx("辅助选址");
  146. successDto.setRzlr("开始生成选址报告");
  147. successDto.setRzlx("info");
  148. successDto.setRzsj(new Date());
  149. fxrwrzMapper.insert(successDto);
  150. FzxzEntityDTO res = fzxzMapper.GetFzxzByBsm(bsm);
  151. FzxzReport fzxzReport = new FzxzReport();
  152. if (res != null) {
  153. //文件硬盘真实路径
  154. String timeStamp = new Date().getTime() + "";
  155. String rootPath = temp + File.separator + "辅助选址报告" + File.separator + res.getBsm();
  156. File f = new File(rootPath);
  157. if (!f.exists()) {
  158. f.mkdirs();
  159. }
  160. String reportPath = res.getXmmc() + "(选址报告)_" + timeStamp + ".docx";
  161. String simplePath = res.getXmmc() + "(选址简报)_" + timeStamp + ".docx";
  162. String zipPath = res.getXmmc() + "_" + timeStamp + ".zip";
  163. //选址报告
  164. createReport(res, rootPath + File.separator + reportPath, xzbsmList);
  165. //选址简报
  166. createSimpleReport(res, rootPath + File.separator + simplePath, xzbsmList);
  167. //zip打包
  168. createZipReport(res, rootPath + File.separator + zipPath
  169. , rootPath + File.separator + reportPath
  170. , rootPath + File.separator + simplePath);
  171. //生成返回结果
  172. fzxzReport.setRootPath(StringUtils.getFileStaticPath(rootPath));
  173. fzxzReport.setReportfile(StringUtils.getFileStaticPath(rootPath + File.separator + reportPath));
  174. fzxzReport.setSimplefile(StringUtils.getFileStaticPath(rootPath + File.separator + simplePath));
  175. fzxzReport.setZipfile(StringUtils.getFileStaticPath(rootPath + File.separator + zipPath));
  176. fzxzReport.setBsm(bsm);
  177. fzxzReport.setFxbg(fzxzReport.getReportfile());
  178. fzxzReport.setJsdw(res.getJsdw());
  179. fzxzReport.setXmmc(res.getXmmc());
  180. //查询分析结果图斑信息
  181. QueryWrapper<FzxzJgGisDTO> giswrapper = new QueryWrapper<FzxzJgGisDTO>();
  182. giswrapper.eq("rwbsm", res.getBsm());
  183. List<FzxzJgGisDTO> gisinfo = fzxzJgGISMapper.selectList(giswrapper);
  184. fzxzReport.setItems(gisinfo);
  185. }
  186. //插入开始生成报告日志
  187. FxrwrzDTO successDto2 = new FxrwrzDTO();
  188. successDto2.setRwbsm(bsm);
  189. successDto2.setRwlx("辅助选址");
  190. successDto2.setRzlr("选址报告生成结束");
  191. successDto2.setRzlx("info");
  192. successDto2.setRzsj(new Date());
  193. fxrwrzMapper.insert(successDto2);
  194. return fzxzReport;
  195. }
  196. /**
  197. * 选址报告
  198. */
  199. private void createReport(FzxzEntityDTO res, String reportPath, List<String> xzbsmList) {
  200. List<String> imgList = ReportImg(res, xzbsmList);
  201. //创建document文档对象对象实例
  202. XWPFDocument document = null;
  203. OutputStream outputStream = null;//把doc输出到输出流
  204. try {
  205. document = new XWPFDocument();
  206. int pos = 0;
  207. //文本标题
  208. NpoiHelper.title(document, res.getXmmc() + "选址报告", pos++);
  209. SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
  210. NpoiHelper.Option optionCENTER = new NpoiHelper.Option();
  211. optionCENTER.setAlign(ParagraphAlignment.CENTER);
  212. document.setParagraph(NpoiHelper.newParagraph(document, sdf.format(new Date()), optionCENTER), pos++);
  213. NpoiHelper.catalog(document, "一、项目选址信息", pos++);
  214. String ydmj = res.getYdmjbegin() + " - " + res.getYdmjend();
  215. if (StringUtils.isEmpty(res.getYdmjbegin()) || Double.parseDouble(res.getYdmjbegin()) == 0)
  216. ydmj = "≤" + res.getYdmjend();
  217. else if (StringUtils.isEmpty(res.getYdmjend()) || Double.parseDouble(res.getYdmjend()) == 0)
  218. ydmj = "≥" + res.getYdmjbegin();
  219. List<String> listTemp = new ArrayList<String>();
  220. listTemp.add("\t项目名称:" + res.getXmmc());
  221. listTemp.add("\t建设单位:" + res.getJsdw());
  222. listTemp.add("\t用地面积:" + ydmj + "平方米");
  223. listTemp.add("\t用地性质:" + res.getYdmc());
  224. listTemp.add("\t影响因子:");
  225. NpoiHelper.content(document, listTemp, pos++);
  226. List tabYzTitles = new ArrayList<NpoiHelper.TableTitle>();
  227. NpoiHelper.TableTitle tableTitle = new NpoiHelper.TableTitle();
  228. tableTitle.setKey("YXYZMC");
  229. tableTitle.setName("因子名称");
  230. tableTitle.setWidth(2880);
  231. tabYzTitles.add(tableTitle);
  232. tableTitle = new NpoiHelper.TableTitle();
  233. tableTitle.setKey("YZTJ_TEXT");
  234. tableTitle.setName("影响条件");
  235. tableTitle.setAlign(ParagraphAlignment.CENTER);
  236. tableTitle.setWidth(2880);
  237. tabYzTitles.add(tableTitle);
  238. tableTitle = new NpoiHelper.TableTitle();
  239. tableTitle.setKey("YXZ");
  240. tableTitle.setName("约束范围值(M)");
  241. tableTitle.setAlign(ParagraphAlignment.CENTER);
  242. tableTitle.setWidth(2880);
  243. tabYzTitles.add(tableTitle);
  244. //查询选址因子,并且转换为List<Map> 因子条件(包含:C、不包含:N、分析:A)
  245. QueryWrapper<FzxzXzyzDTO> wrapper = new QueryWrapper<FzxzXzyzDTO>();
  246. wrapper.eq("rwbsm", res.getBsm());
  247. List<FzxzXzyzDTO> fzxzXzyzDTOList = fzxzXzyzMapper.selectList(wrapper);
  248. List<Map<String, Object>> dataTablelist = new ArrayList<>();
  249. for (int i = 0; i < fzxzXzyzDTOList.size(); i++) {
  250. Map<String, Object> map = new HashMap<>();
  251. FzxzXzyzDTO fzxzXzyzDTO = fzxzXzyzDTOList.get(i);
  252. map.put("YXYZMC", fzxzXzyzDTO.getYxyzmc());
  253. String yztj = "";
  254. if (fzxzXzyzDTO.getYztj() != null) {
  255. if ("C".equals(fzxzXzyzDTO.getYztj().toUpperCase())) {
  256. yztj = "包含";
  257. }
  258. if ("N".equals(fzxzXzyzDTO.getYztj().toUpperCase())) {
  259. yztj = "不包含";
  260. }
  261. if ("A".equals(fzxzXzyzDTO.getYztj().toUpperCase()) || "F".equals(fzxzXzyzDTO.getYztj().toUpperCase())) {
  262. yztj = "分析";
  263. }
  264. }
  265. map.put("YZTJ_TEXT", yztj);
  266. String yxz = "";
  267. if (StringUtils.isNotEmpty(fzxzXzyzDTO.getYxz())) {
  268. yxz = fzxzXzyzDTO.getYxz();
  269. }
  270. map.put("YXZ", yxz);
  271. dataTablelist.add(map);
  272. }
  273. XWPFTable tableYz = NpoiHelper.setComTable(document, tabYzTitles, dataTablelist, "表1:选址影响因子", pos++);
  274. NpoiHelper.catalog(document, "二、选址范围分析", pos++);
  275. //查询辅助选址分析图斑
  276. QueryWrapper<FzxzTbEntityDTO> wrapperTb = new QueryWrapper<FzxzTbEntityDTO>();
  277. wrapperTb.eq("rwbsm", res.getBsm());
  278. wrapperTb.groupBy("objectid", "rwbsm", "ydyhfldm", "ydyhflmc", "frequency", "sum_mj");
  279. List<FzxzTbEntityDTO> fzxzTbEntityDTOList = fzxzTbMapper.selectList(wrapperTb);
  280. //计算面积总和
  281. double sumcount = 0;
  282. for (int i = 0; i < fzxzTbEntityDTOList.size(); i++) {
  283. sumcount = sumcount + fzxzTbEntityDTOList.get(i).getSumMj();
  284. }
  285. List<FzxzTbEntityDTO> list = fzxzTbEntityDTOList.stream().sorted(
  286. Comparator.comparing(FzxzTbEntityDTO::getSumMj).reversed()
  287. ).collect(Collectors.toList());
  288. String fwfx = "\t根据指定选址分析得出,所选范围共" + Math.round(sumcount) + "平方米,其中";
  289. List<Map<String, Object>> fztable = new ArrayList<>();
  290. //生成地类分析统计表
  291. for (int i = 0; i < list.size(); i++) {
  292. FzxzTbEntityDTO item = list.get(i);
  293. String zb = String.format("%.1f", item.getSumMj() / sumcount * 100);
  294. if (i < 5) {
  295. //面积前五的占比地类计算
  296. fwfx += item.getYdyhflmc()
  297. + Math.round(item.getSumMj()) + "平方米,占比" + zb + "%;";
  298. }
  299. //List<FzxzTbEntityDTO>转List<Map<String, Object>> 地类编码 地类名称 面积(平方千米) 占比(%)
  300. Map map = new HashMap();
  301. map.put("ZB", zb);
  302. map.put("YDYHFLDM", item.getYdyhfldm());
  303. map.put("YDYHFLMC", item.getYdyhflmc());
  304. map.put("SUM_MJ", Math.round(item.getSumMj()));
  305. fztable.add(map);
  306. }
  307. fwfx = fwfx.substring(0, fwfx.length() - 1) + "。详情如下:";
  308. NpoiHelper.content(document, fwfx, pos++);
  309. //地类编码 地类名称 面积(平方千米) 占比(%)
  310. List<NpoiHelper.TableTitle> tabYztbTitles = new ArrayList();
  311. NpoiHelper.TableTitle tableTitleTb = new NpoiHelper.TableTitle();
  312. tableTitleTb.setKey("YDYHFLDM");
  313. tableTitleTb.setName("地类编码");
  314. tableTitleTb.setAlign(ParagraphAlignment.CENTER);
  315. tableTitleTb.setWidth(2010);
  316. tabYztbTitles.add(tableTitleTb);
  317. tableTitleTb = new NpoiHelper.TableTitle();
  318. tableTitleTb.setKey("YDYHFLMC");
  319. tableTitleTb.setName("地类名称");
  320. tableTitleTb.setWidth(2910);
  321. tabYztbTitles.add(tableTitleTb);
  322. tableTitleTb = new NpoiHelper.TableTitle();
  323. tableTitleTb.setKey("SUM_MJ");
  324. tableTitleTb.setName("面积(平方千米)");
  325. tableTitleTb.setAlign(ParagraphAlignment.CENTER);
  326. tableTitleTb.setWidth(1870);
  327. tabYztbTitles.add(tableTitleTb);
  328. tableTitleTb = new NpoiHelper.TableTitle();
  329. tableTitleTb.setKey("ZB");
  330. tableTitleTb.setName("占比(%)");
  331. tableTitleTb.setAlign(ParagraphAlignment.CENTER);
  332. tableTitleTb.setWidth(1700);
  333. tabYztbTitles.add(tableTitleTb);
  334. XWPFTable tableYztb = NpoiHelper.setComTable(document, tabYztbTitles, fztable, "表2:地类分析统计表", pos++);
  335. //查询结果GIS FzxzJgGisDTO
  336. QueryWrapper<FzxzJgGisDTO> giswrapper = new QueryWrapper<FzxzJgGisDTO>();
  337. giswrapper.eq("rwbsm", res.getBsm());
  338. //筛选方案,根据传参或者预选方案
  339. // giswrapper.ne("yxfa", "0");
  340. if (xzbsmList != null) {
  341. giswrapper.in("bsm", xzbsmList);
  342. }
  343. List<FzxzJgGisDTO> fzxzJgGisDTOList = fzxzJgGISMapper.selectList(giswrapper);
  344. NpoiHelper.catalog(document, "三、选址分析", pos++);
  345. String ydmc = res.getYdmc();
  346. if(!StringUtils.isEmpty(ydmc)){
  347. if (ydmc.lastIndexOf("用地") == ydmc.length() - 2) {
  348. ydmc = res.getYdmc().substring(0, ydmc.length() - 2);
  349. }
  350. NpoiHelper.content(document, "\t按照项目选址要求和影响因子,经对所选范围内的所有"
  351. + ydmc + "用地进行分析,筛选出符合要求的方案共" + fzxzJgGisDTOList.size() + "个。", pos++);
  352. }else{
  353. NpoiHelper.content(document, "\t按照项目选址要求和影响因子,经对所选范围内的所有用地进行分析,筛选出符合要求的方案共" + fzxzJgGisDTOList.size() + "个。", pos++);
  354. }
  355. int index = 1;
  356. NpoiHelper.Option optionIsBold = new NpoiHelper.Option();
  357. optionIsBold.setBold(true);
  358. for (int i = 0; i < fzxzJgGisDTOList.size(); i++) {
  359. FzxzJgGisDTO item = fzxzJgGisDTOList.get(i);
  360. document.setParagraph(NpoiHelper.newParagraph(document, index + "、方案" + NumberUtil.int2chineseNum(index)
  361. , optionIsBold), pos++);
  362. XWPFTable table = document.createTable(7, 4);
  363. table.setWidth(9000);//总宽度
  364. for (int k = 0; k < 4; k++) {
  365. XWPFTableCell cell = table.getRow(0).getCell(k);
  366. CTTcPr ctTcPr = cell.getCTTc().isSetTcPr() ? cell.getCTTc().getTcPr() : cell.getCTTc().addNewTcPr();
  367. CTTblWidth ctTblWidth = ctTcPr.addNewTcW();
  368. ctTblWidth.setW(BigInteger.valueOf(2250));
  369. ctTblWidth.setType(STTblWidth.DXA);
  370. }
  371. //Table 表格第一行
  372. table.getRow(0).getCell(0).setColor("DBE5F1");
  373. NpoiHelper.mergeHorizontal(table, 0, 0, 3);
  374. table.getRow(0).getCell(0).setParagraph(NpoiHelper.setCellText(table, "符合用地情况", optionIsBold));
  375. //Table 表格第二行
  376. table.getRow(1).getCell(0).setParagraph(NpoiHelper.setCellText(table, "地类编码", optionIsBold));
  377. table.getRow(1).getCell(1).setParagraph(NpoiHelper.setCellText(table, item.getDlbm(), null));
  378. table.getRow(1).getCell(2).setParagraph(NpoiHelper.setCellText(table, "地类名称", optionIsBold));
  379. table.getRow(1).getCell(3).setParagraph(NpoiHelper.setCellText(table, item.getDlmc(), null));
  380. //Table 表格第三行
  381. table.getRow(2).getCell(0).setParagraph(NpoiHelper.setCellText(table, "地块面积", optionIsBold));
  382. table.getRow(2).getCell(1).setParagraph(NpoiHelper.setCellText(table, Math.round(item.getTbmj()) + "平方米", null));
  383. table.getRow(2).getCell(2).setParagraph(NpoiHelper.setCellText(table, "土地位置", optionIsBold));
  384. table.getRow(2).getCell(3).setParagraph(NpoiHelper.setCellText(table, item.getXzqmc(), null));
  385. //Table 表格第四行
  386. table.getRow(3).getCell(0).setColor("DBE5F1");
  387. NpoiHelper.mergeHorizontal(table, 3, 0, 3);
  388. table.getRow(3).getCell(0).setParagraph(NpoiHelper.setCellText(table, "地块位置信息", optionIsBold));
  389. //Table 表格第五行 -专题图
  390. NpoiHelper.mergeHorizontal(table, 4, 0, 1);
  391. NpoiHelper.mergeHorizontal(table, 4, 2, 3);
  392. String mapF = "";
  393. String mapM = "";
  394. if (imgList != null && imgList.size() > 0) {
  395. for (int j = 0; j < imgList.size(); j++) {
  396. String s = imgList.get(j);
  397. if (s.indexOf(item.getBsm() + "_F") >= 0) {
  398. mapF = s;//全局
  399. }
  400. if (s.indexOf(item.getBsm() + "_M") >= 0) {
  401. mapM = s;//局部
  402. }
  403. }
  404. }
  405. if (StringUtils.isNotEmpty(mapF)) {
  406. FileInputStream fis = null;
  407. try {
  408. fis = new FileInputStream(new File(mapF));
  409. XWPFParagraph paragraph = table.getRow(4).getCell(0).addParagraph();
  410. paragraph.setAlignment(ParagraphAlignment.CENTER);
  411. XWPFRun run = paragraph.createRun();
  412. run.addPicture(
  413. fis, // 条形码图片的位置
  414. Document.PICTURE_TYPE_JPEG, // 图片类型
  415. item.getBsm() + "_F.jpeg", // 图片名称
  416. 2200000, // 图片的长
  417. 1700000 // 图片的宽
  418. );
  419. run.addBreak(BreakType.TEXT_WRAPPING);
  420. run.setText("(宏观位置)");
  421. } catch (Exception e) {
  422. System.out.println(e.toString());
  423. } finally {
  424. if (fis != null) {
  425. try {
  426. fis.close();
  427. } catch (IOException e) {
  428. throw e;
  429. }
  430. }
  431. }
  432. }
  433. if (StringUtils.isNotEmpty(mapM)) {
  434. FileInputStream fis = null;
  435. try {
  436. fis = new FileInputStream(new File(mapM));
  437. XWPFParagraph paragraph = table.getRow(4).getCell(2).addParagraph();
  438. paragraph.setAlignment(ParagraphAlignment.CENTER);
  439. XWPFRun run = paragraph.createRun();
  440. run.addPicture(
  441. fis, // 条形码图片的位置
  442. Document.PICTURE_TYPE_JPEG, // 图片类型
  443. item.getBsm() + "_M.jpeg", // 图片名称
  444. 2200000, // 图片的长
  445. 1700000 // 图片的宽
  446. );
  447. run.addBreak(BreakType.TEXT_WRAPPING);
  448. run.setText("(具体位置)");
  449. } catch (Exception e) {
  450. System.out.println(e.toString());
  451. throw e;
  452. } finally {
  453. if (fis != null) {
  454. try {
  455. fis.close();
  456. } catch (IOException e) {
  457. throw e;
  458. }
  459. }
  460. }
  461. }
  462. //Table 表格第六行
  463. table.getRow(5).getCell(0).setColor("DBE5F1");
  464. NpoiHelper.mergeHorizontal(table, 5, 0, 3);
  465. table.getRow(5).getCell(0).setParagraph(NpoiHelper.setCellText(table, "分析结论", optionIsBold));
  466. //Table 表格第七行
  467. NpoiHelper.mergeHorizontal(table, 6, 0, 3);
  468. XWPFParagraph para6 = table.getRow(6).getCell(0).addParagraph();
  469. para6.setAlignment(ParagraphAlignment.LEFT);
  470. //查询辅助选址因子
  471. QueryWrapper<FzxzJgyzDTO> jgyzWrapper = new QueryWrapper<FzxzJgyzDTO>();
  472. jgyzWrapper.eq("jbbsm", item.getBsm());
  473. jgyzWrapper.ne("yztj", "F");
  474. List<FzxzJgyzDTO> jgyzList = fzxzJgyzMapper.selectList(jgyzWrapper);
  475. int jgyzid = 1;
  476. for (int j = 0; j < jgyzList.size(); j++) {
  477. FzxzJgyzDTO fzxzJgyzDTO = jgyzList.get(j);
  478. XWPFRun run = para6.createRun();
  479. run.setText(jgyzid + "、" + fzxzJgyzDTO.getFxjg());
  480. run.addBreak(BreakType.TEXT_WRAPPING);
  481. jgyzid++;
  482. }
  483. //查询辅助选址因子
  484. jgyzWrapper = new QueryWrapper<FzxzJgyzDTO>();
  485. jgyzWrapper.eq("jbbsm", item.getBsm());
  486. jgyzWrapper.eq("yztj", "F");
  487. jgyzList = fzxzJgyzMapper.selectList(jgyzWrapper);
  488. for (int j = 0; j < jgyzList.size(); j++) {
  489. FzxzJgyzDTO jgyz = jgyzList.get(j);
  490. XWPFRun run = para6.createRun();
  491. String jg = jgyz.getFxjg();
  492. Double jgDouble = 0.0;
  493. try {
  494. jgDouble = Double.parseDouble(jg);
  495. run.setText(jgyzid + "、压占" + jgyz.getYxyzmc() + "面积" + jg + "平方米");
  496. } catch (Exception e) {
  497. run.setText(jg);
  498. }
  499. run.addBreak(BreakType.TEXT_WRAPPING);
  500. jgyzid++;
  501. }
  502. index++;
  503. }
  504. File fileDoc = new File(reportPath);
  505. if (fileDoc.exists()) {
  506. FileUtils.forceDelete(fileDoc);
  507. }
  508. //word文件输出流
  509. outputStream = new FileOutputStream(reportPath);
  510. document.write(outputStream);
  511. } catch (Exception e) {
  512. e.printStackTrace();
  513. //插入任务日志
  514. FxrwrzDTO errorDto = new FxrwrzDTO();
  515. errorDto.setRwbsm(res.getBsm());
  516. errorDto.setRwlx("辅助选址");
  517. errorDto.setRzlr("生成选址报告错误:" + e.getMessage());
  518. errorDto.setRzsj(new Date());
  519. errorDto.setRzlx("error");
  520. fxrwrzMapper.insert(errorDto);
  521. } finally {
  522. if (document != null) {
  523. try {
  524. document.close();
  525. } catch (Exception ex) {
  526. System.out.println(ex.toString());
  527. }
  528. }
  529. if (outputStream != null) {
  530. try {
  531. outputStream.close();
  532. } catch (IOException e) {
  533. e.printStackTrace();
  534. }
  535. }
  536. }
  537. //转PDF
  538. String outfilepath = reportPath.replace(".docx", ".pdf");
  539. NpoiHelper.doc2pdf(reportPath, outfilepath);
  540. System.out.println(outfilepath);
  541. }
  542. /**
  543. * 选址简报
  544. */
  545. private void createSimpleReport(FzxzEntityDTO res, String reportPath, List<String> xzbsmList) {
  546. //创建document文档对象对象实例
  547. XWPFDocument document = null;
  548. OutputStream outputStream = null;//把doc输出到输出流
  549. try {
  550. //创建document文档对象对象实例
  551. document = new XWPFDocument();
  552. int pos = 0;
  553. NpoiHelper.Option optionCENTER = new NpoiHelper.Option();
  554. optionCENTER.setAlign(ParagraphAlignment.CENTER);
  555. //文本标题
  556. NpoiHelper.title(document, res.getXmmc() + "选址简报", pos++);
  557. SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
  558. document.setParagraph(NpoiHelper.newParagraph(document, sdf.format(new Date()), optionCENTER), pos++);
  559. NpoiHelper.catalog(document, "一、项目选址信息", pos++);
  560. XWPFTable table = document.createTable(4, 4);
  561. table.setWidth(8500);//总宽度
  562. for (int k = 0; k < 4; k++) {
  563. XWPFTableCell cell = table.getRow(0).getCell(k);
  564. CTTcPr ctTcPr = cell.getCTTc().isSetTcPr() ? cell.getCTTc().getTcPr() : cell.getCTTc().addNewTcPr();
  565. CTTblWidth ctTblWidth = ctTcPr.addNewTcW();
  566. ctTblWidth.setW(BigInteger.valueOf(2125));
  567. ctTblWidth.setType(STTblWidth.DXA);
  568. }
  569. //Table 表格第一行
  570. NpoiHelper.Option optionIsBoldCENTER = new NpoiHelper.Option();
  571. optionIsBoldCENTER.setAlign(ParagraphAlignment.CENTER);
  572. optionIsBoldCENTER.setBold(true);
  573. table.getRow(0).getCell(0).setColor("DBE5F1");
  574. table.getRow(0).getCell(0).setParagraph(NpoiHelper.setCellText(table, "项目名称", optionIsBoldCENTER));
  575. NpoiHelper.mergeHorizontal(table, 0, 1, 3);
  576. table.getRow(0).getCell(1).setParagraph(NpoiHelper.setCellText(table, res.getXmmc(), null));
  577. //Table 表格第二行
  578. table.getRow(1).getCell(0).setColor("DBE5F1");
  579. table.getRow(1).getCell(0).setParagraph(NpoiHelper.setCellText(table, "建设单位", optionIsBoldCENTER));
  580. NpoiHelper.mergeHorizontal(table, 1, 1, 3);
  581. table.getRow(1).getCell(1).setParagraph(NpoiHelper.setCellText(table, res.getJsdw(), null));
  582. //Table 表格第三行
  583. String ydmj = res.getYdmjbegin() + " - " + res.getYdmjend();
  584. if (StringUtils.isEmpty(res.getYdmjbegin()) || Double.parseDouble(res.getYdmjbegin()) == 0)
  585. ydmj = "≤" + res.getYdmjend();
  586. else if (StringUtils.isEmpty(res.getYdmjend()) || Double.parseDouble(res.getYdmjend()) == 0)
  587. ydmj = "≥" + res.getYdmjbegin();
  588. table.getRow(2).getCell(0).setColor("DBE5F1");
  589. table.getRow(2).getCell(0).setParagraph(NpoiHelper.setCellText(table, "用地面积", optionIsBoldCENTER));
  590. table.getRow(2).getCell(1).setParagraph(NpoiHelper.setCellText(table, ydmj + "平方米", null));
  591. table.getRow(2).getCell(2).setColor("DBE5F1");
  592. table.getRow(2).getCell(2).setParagraph(NpoiHelper.setCellText(table, "用地性质", optionIsBoldCENTER));
  593. table.getRow(2).getCell(3).setParagraph(NpoiHelper.setCellText(table, res.getYdmc(), null));
  594. //Table 表格第四行
  595. table.getRow(3).getCell(1).setColor("DBE5F1");
  596. table.getRow(3).getCell(2).setColor("DBE5F1");
  597. table.getRow(3).getCell(3).setColor("DBE5F1");
  598. table.getRow(3).getCell(0).setParagraph(NpoiHelper.setCellText(table, "选址因子", optionIsBoldCENTER));
  599. table.getRow(3).getCell(1).setParagraph(NpoiHelper.setCellText(table, "因子名称", optionIsBoldCENTER));
  600. table.getRow(3).getCell(2).setParagraph(NpoiHelper.setCellText(table, "影响条件", optionIsBoldCENTER));
  601. table.getRow(3).getCell(3).setParagraph(NpoiHelper.setCellText(table, "约束范围值(M)", optionIsBoldCENTER));
  602. //查询选址因子,并且转换为List<Map> 因子条件(包含:C、不包含:N、分析:A)
  603. QueryWrapper<FzxzXzyzDTO> wrapper = new QueryWrapper<FzxzXzyzDTO>();
  604. wrapper.eq("rwbsm", res.getBsm());
  605. List<FzxzXzyzDTO> fzxzXzyzDTOList = fzxzXzyzMapper.selectList(wrapper);
  606. for (int i = 0; i < fzxzXzyzDTOList.size(); i++) {
  607. FzxzXzyzDTO fzxzXzyzDTO = fzxzXzyzDTOList.get(i);
  608. String yztj = "";
  609. if (fzxzXzyzDTO.getYztj() != null) {
  610. if ("C".equals(fzxzXzyzDTO.getYztj().toUpperCase())) {
  611. yztj = "包含";
  612. }
  613. if ("N".equals(fzxzXzyzDTO.getYztj().toUpperCase())) {
  614. yztj = "不包含";
  615. }
  616. if ("A".equals(fzxzXzyzDTO.getYztj().toUpperCase()) || "F".equals(fzxzXzyzDTO.getYztj().toUpperCase())) {
  617. yztj = "分析";
  618. }
  619. }
  620. String yxz = "";
  621. if (StringUtils.isNotEmpty(fzxzXzyzDTO.getYxz())) {
  622. yxz = fzxzXzyzDTO.getYxz();
  623. }
  624. XWPFTableRow mr = table.createRow();
  625. mr.getCell(1).setParagraph(NpoiHelper.setCellText(table, fzxzXzyzDTO.getYxyzmc(), optionCENTER));
  626. mr.getCell(2).setParagraph(NpoiHelper.setCellText(table, yztj, optionCENTER));
  627. mr.getCell(3).setParagraph(NpoiHelper.setCellText(table, yxz, optionCENTER));
  628. }
  629. NpoiHelper.mergeCellsVertically(table, 0, 3, 3 + fzxzXzyzDTOList.size());
  630. table.getRow(3).getCell(0).setColor("DBE5F1");
  631. //选址分析
  632. NpoiHelper.catalog(document, "二、选址分析", pos++);
  633. XWPFTable tableFx = document.createTable(1, 4);
  634. tableFx.setWidth(8500);//总宽度
  635. for (int k = 0; k < 4; k++) {
  636. XWPFTableCell cell = tableFx.getRow(0).getCell(k);
  637. CTTcPr ctTcPr = cell.getCTTc().isSetTcPr() ? cell.getCTTc().getTcPr() : cell.getCTTc().addNewTcPr();
  638. CTTblWidth ctTblWidth = ctTcPr.addNewTcW();
  639. ctTblWidth.setW(BigInteger.valueOf(2125));
  640. ctTblWidth.setType(STTblWidth.DXA);
  641. }
  642. //查询结果GIS FzxzJgGisDTO
  643. QueryWrapper<FzxzJgGisDTO> giswrapper = new QueryWrapper<FzxzJgGisDTO>();
  644. giswrapper.eq("rwbsm", res.getBsm());
  645. //筛选方案,根据传参或者预选方案
  646. // giswrapper.ne("yxfa", "0");
  647. if (xzbsmList != null) {
  648. giswrapper.in("bsm", xzbsmList);
  649. }
  650. List<FzxzJgGisDTO> fzxzJgGisDTOList = fzxzJgGISMapper.selectList(giswrapper);
  651. int index = 1;
  652. NpoiHelper.Option optionIsBold = new NpoiHelper.Option();
  653. optionIsBold.setBold(true);
  654. int rowIndex = 0;
  655. for (int i = 0; i < fzxzJgGisDTOList.size(); i++) {
  656. FzxzJgGisDTO item = fzxzJgGisDTOList.get(i);
  657. XWPFTableRow mr = tableFx.createRow();
  658. rowIndex++;
  659. mr.getCell(0).setColor("DBE5F1");
  660. NpoiHelper.mergeHorizontal(tableFx, rowIndex, 0, 1);
  661. mr.getCell(0).setParagraph(NpoiHelper.setCellText(tableFx, "方案" + NumberUtil.int2chineseNum(index), optionIsBold));
  662. //tableFx 表格第二行
  663. mr = tableFx.createRow();
  664. rowIndex++;
  665. mr.getCell(0).setParagraph(NpoiHelper.setCellText(tableFx, "地类编码", optionIsBoldCENTER));
  666. mr.getCell(1).setParagraph(NpoiHelper.setCellText(tableFx, item.getDlbm(), null));
  667. mr.getCell(2).setParagraph(NpoiHelper.setCellText(tableFx, "地类名称", optionIsBoldCENTER));
  668. mr.getCell(3).setParagraph(NpoiHelper.setCellText(tableFx, item.getDlmc(), null));
  669. //tableFx 表格第三行
  670. mr = tableFx.createRow();
  671. rowIndex++;
  672. mr.getCell(0).setParagraph(NpoiHelper.setCellText(tableFx, "地块面积", optionIsBoldCENTER));
  673. mr.getCell(1).setParagraph(NpoiHelper.setCellText(tableFx, Math.round(item.getTbmj()) + "平方米", null));
  674. mr.getCell(2).setParagraph(NpoiHelper.setCellText(tableFx, "土地位置", optionIsBoldCENTER));
  675. mr.getCell(3).setParagraph(NpoiHelper.setCellText(tableFx, item.getXzqmc(), null));
  676. //tableFx 表格第四行
  677. mr = tableFx.createRow();
  678. rowIndex++;
  679. mr.getCell(0).setParagraph(NpoiHelper.setCellText(tableFx, "压占分析", optionIsBoldCENTER));
  680. NpoiHelper.mergeHorizontal(tableFx, rowIndex, 1, 3);
  681. XWPFParagraph para6 = mr.getCell(1).addParagraph();
  682. para6.setAlignment(ParagraphAlignment.LEFT);
  683. //查询选址因子 因子条件(包含:C、不包含:N、分析:A)
  684. QueryWrapper<FzxzJgyzDTO> fzxzJgyzDTOQueryWrapper = new QueryWrapper<FzxzJgyzDTO>();
  685. fzxzJgyzDTOQueryWrapper.eq("jbbsm", item.getBsm());
  686. fzxzJgyzDTOQueryWrapper.eq("yztj", "F");
  687. List<FzxzJgyzDTO> fzxzJgyzDTOList = fzxzJgyzMapper.selectList(fzxzJgyzDTOQueryWrapper);
  688. int jgyzid = 1;
  689. for (int j = 0; j < fzxzJgyzDTOList.size(); j++) {
  690. FzxzJgyzDTO jgyz = fzxzJgyzDTOList.get(j);
  691. XWPFRun run = para6.createRun();
  692. String jg = jgyz.getFxjg();
  693. Double jgDouble = 0.0;
  694. try {
  695. jgDouble = Double.parseDouble(jg);
  696. run.setText(jgyzid + "、压占" + jgyz.getYxyzmc() + "面积" + jg + "平方米");
  697. } catch (Exception e) {
  698. run.setText(jgyzid + "、" + jg);
  699. }
  700. if (jgyzid < fzxzJgyzDTOList.size())
  701. run.addBreak(BreakType.TEXT_WRAPPING);
  702. jgyzid++;
  703. }
  704. index++;
  705. }
  706. tableFx.removeRow(0);
  707. File fileDoc = new File(reportPath);
  708. if (fileDoc.exists()) {
  709. FileUtils.forceDelete(fileDoc);
  710. }
  711. //word文件输出流
  712. outputStream = new FileOutputStream(reportPath);
  713. document.write(outputStream);
  714. } catch (
  715. Exception e) {
  716. e.printStackTrace();
  717. System.out.println(e.toString());
  718. //插入任务日志
  719. FxrwrzDTO errorDto = new FxrwrzDTO();
  720. errorDto.setRwbsm(res.getBsm());
  721. errorDto.setRwlx("辅助选址");
  722. errorDto.setRzlr("生成选址简报错误:" + e.getMessage());
  723. errorDto.setRzsj(new Date());
  724. errorDto.setRzlx("error");
  725. fxrwrzMapper.insert(errorDto);
  726. } finally {
  727. if (document != null) {
  728. try {
  729. document.close();
  730. } catch (Exception ex) {
  731. System.out.println(ex.toString());
  732. }
  733. }
  734. if (outputStream != null) {
  735. try {
  736. outputStream.close();
  737. } catch (IOException e) {
  738. e.printStackTrace();
  739. }
  740. }
  741. }
  742. //转PDF
  743. String outfilepath = reportPath.replace(".docx", ".pdf");
  744. NpoiHelper.doc2pdf(reportPath, outfilepath);
  745. System.out.println(outfilepath);
  746. }
  747. /**
  748. * zip打包
  749. */
  750. private void createZipReport(FzxzEntityDTO res, String reportZip, String reportPath, String simplePath) {
  751. File f = new File(fzxzShp);
  752. System.out.println("选址分析报告打包zip:" + reportPath);
  753. System.out.println("选址分析报告打包shp:" + fzxzShp);
  754. if (StringUtils.isNotEmpty(fzxzShp)) {
  755. String filePath = fzxzShp.substring(0, fzxzShp.lastIndexOf("."));
  756. String docReportPath = reportPath.substring(0, reportPath.lastIndexOf("."));
  757. String docSimplePath = reportPath.substring(0, reportPath.lastIndexOf("."));
  758. // 生成的压缩文件
  759. ZipFile zipFile = null;
  760. try {
  761. zipFile = new ZipFile(reportZip);
  762. ZipParameters parameters = new ZipParameters();
  763. // 压缩方式
  764. parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
  765. // 压缩级别
  766. parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
  767. zipFile.addFile(new File(simplePath), parameters);
  768. zipFile.addFile(new File(reportPath), parameters);
  769. zipFile.addFile(new File(filePath + ".shp"), parameters);
  770. zipFile.addFile(new File(filePath + ".shx"), parameters);
  771. zipFile.addFile(new File(filePath + ".dbf"), parameters);
  772. zipFile.addFile(new File(filePath + ".cpg"), parameters);
  773. zipFile.addFile(new File(filePath + ".prj"), parameters);
  774. } catch (ZipException e) {
  775. System.out.println(e.toString());
  776. //插入任务日志
  777. FxrwrzDTO errorDto = new FxrwrzDTO();
  778. errorDto.setRwbsm(res.getBsm());
  779. errorDto.setRwlx("辅助选址");
  780. errorDto.setRzlr("生成选址报告zip打包错误:" + e.getMessage());
  781. errorDto.setRzsj(new Date());
  782. errorDto.setRzlx("error");
  783. fxrwrzMapper.insert(errorDto);
  784. }
  785. }
  786. }
  787. /**
  788. * 导出报告图片
  789. *
  790. * @return
  791. */
  792. private List<String> ReportImg(FzxzEntityDTO res, List<String> xzbsmList) {
  793. //查询分析结果图斑信息
  794. QueryWrapper<FzxzJgGisDTO> giswrapper = new QueryWrapper<FzxzJgGisDTO>();
  795. giswrapper.eq("rwbsm", res.getBsm());
  796. //筛选方案,根据传参或者预选方案
  797. // giswrapper.ne("yxfa", "0");
  798. if (xzbsmList != null) {
  799. giswrapper.in("bsm", xzbsmList);
  800. }
  801. List<FzxzJgGisDTO> fzxzJgGisDTOList = fzxzJgGISMapper.selectList(giswrapper);
  802. //SDE转SHP
  803. String inShp = fzxzShp;
  804. List objidlist = new ArrayList<>();
  805. for (FzxzJgGisDTO cur : fzxzJgGisDTOList) {
  806. objidlist.add(cur.getObjectid());
  807. }
  808. String objids = Joiner.on(",").join(objidlist);
  809. sde2Shp("KJGH.T_FZSS_FZXZ_JG_GIS", inShp, "\"OBJECTID\" IN (" + objids + ")");
  810. //执行python
  811. Map<String, String> params = new HashMap<>();
  812. List<String> result = PythonExecute.RunFzxzMap(mapFunctionId, params);
  813. return result;
  814. }
  815. /**
  816. * SDE转SHP
  817. *
  818. * @param table SDE表
  819. * @param shpfile shp文件
  820. * @param where 追加字段
  821. * @return
  822. */
  823. public static String sde2Shp(String table, String shpfile, String where) {
  824. if (StringUtils.isNotEmpty(where)) {
  825. Map<String, String> params = new HashMap<>();
  826. params.put("table", table);
  827. params.put("shpfile", shpfile);
  828. params.put("where", where);
  829. return PythonExecute.RunGisHelper("sde2shp", params);
  830. } else {
  831. Map<String, String> params = new HashMap<>();
  832. params.put("table", table);
  833. params.put("shpfile", shpfile);
  834. return PythonExecute.RunGisHelper("sde2shp", params);
  835. }
  836. }
  837. }