123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857 |
- package com.onemap.analyse.task;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.google.common.base.Joiner;
- import com.onemap.analyse.domain.*;
- import com.onemap.analyse.mapper.*;
- import com.onemap.analyse.utils.NpoiHelper;
- import com.onemap.analyse.utils.NumberUtil;
- import com.onemap.common.core.utils.StringUtils;
- import net.lingala.zip4j.core.ZipFile;
- import net.lingala.zip4j.exception.ZipException;
- import net.lingala.zip4j.model.ZipParameters;
- import net.lingala.zip4j.util.Zip4jConstants;
- import org.apache.commons.io.FileUtils;
- import org.apache.poi.xwpf.usermodel.*;
- import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth;
- import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr;
- import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Component;
- import javax.annotation.Resource;
- import java.io.*;
- import java.math.BigInteger;
- import java.text.SimpleDateFormat;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * 辅助选址模块定时刷新任务
- */
- @Component
- public class FzxzSchedule {
- //间隔时间 单位ms
- public static final long TIME_INTERVAL = 1 * 15000;
- //任务状态标识码
- private RwztDTO Rwzt = new RwztDTO();
- @Resource
- private FzxzMapper fzxzMapper;
- @Resource
- private FxrwrzMapper fxrwrzMapper;
- @Resource
- private FzxzJgGISMapper fzxzJgGISMapper;
- @Resource
- private FzxzXzyzMapper fzxzXzyzMapper;
- @Resource
- private FzxzTbMapper fzxzTbMapper;
- @Resource
- private FzxzJgyzMapper fzxzJgyzMapper;
- //辅助选址python方法名标识
- @Value("${Fzxz.functionId}")
- private String functionId;
- @Value("${Fzxz.mapFunctionId}")
- private String mapFunctionId;
- @Value("${Fzxz.fzxzShp}")
- private String fzxzShp;
- @Value("${Hgxfx.temp}")
- private String temp;
- ///**
- // * Scheduled 定时器参数
- // * cron表达式:指定任务在特定时间执行
- // * fixedDelay:表示上一次任务执行完成后多久再执行,参数类型long,单位:ms
- // * fixedDelayString:与fixedDelay一样,只是参数类型是String
- // * fixedRate:表示按一定的频率执行任务,参数类型long,单位:ms 如: fixedRate(5000),表示这个定时器任务每5秒执行一次
- // * fixedRateString:与fixedRate一样,只是参数类型变为String
- // * initialDelay:表示延迟多久再第一次执行任务,参数类型为long ,单位:ms
- // * initialDelayString:与initialDelay一样,只是参数类型String
- // */
- ///**
- // * @Async("name") 开启多线程
- // */
- ///**
- // * 辅助选址执行入口
- // */
- //@Async("taskExecutor")
- //@Scheduled(fixedDelay = TIME_INTERVAL)
- //public void FzxzStatus() {
- // try {
- // QueryWrapper<FzxzDTO> wrapper = new QueryWrapper<FzxzDTO>();
- // wrapper.eq("rwzt", Rwzt.getCreate());
- // //以创建时间正序排列
- // wrapper.orderByAsc("cjsj");
- // //每次只操作一条记录
- // List<FzxzDTO> ress = fzxzMapper.selectList(wrapper);
- // if (ress.size() > 0) {
- // FzxzDTO res = ress.get(0);
- // //插入执行状态
- // res.setRwzt(Rwzt.getRun());
- // res.setRwkssj(new Date());
- // QueryWrapper<FzxzDTO> query = new QueryWrapper<FzxzDTO>();
- // query.eq("bsm", res.getBsm());
- // fzxzMapper.update(res, query);
- // //插入任务日志
- // FxrwrzDTO rzDto = new FxrwrzDTO();
- // rzDto.setRwbsm(res.getBsm());
- // rzDto.setRwlx("辅助选址");
- // rzDto.setRzlr("开始分析");
- // rzDto.setRzlx("info");
- // rzDto.setRzsj(new Date());
- // fxrwrzMapper.insert(rzDto);
- // //执行python
- // Map<String, String> params = new HashMap<>();
- // params.put("bsm", res.getBsm());
- // String result = PythonExecute.Run(functionId, params);
- // if (!StringUtils.isEmpty(result) && result.contains("OK")) {//成功
- // res.setRwjssj(new Date());
- // res.setRwzt(Rwzt.getComplete());
- // //TODO 生成辅助选址结果报告 返回 FxReport实体
- // FzxzReport report = createReport(res.getBsm(), null);
- // if (report != null) {
- // res.setFxbg(report.getReportfile().replace(".docx", ".pdf"));
- // res.setZip(report.getZipfile());
- // }
- // fzxzMapper.update(res, query);
- // //插入成功日志
- // FxrwrzDTO successDto = new FxrwrzDTO();
- // successDto.setRwbsm(res.getBsm());
- // successDto.setRwlx("辅助选址");
- // successDto.setRzlr("计算完成");
- // successDto.setRzlx("info");
- // successDto.setRzsj(new Date());
- // fxrwrzMapper.insert(successDto);
- // } else {//失败
- // res.setRwjssj(new Date());
- // res.setRwzt(Rwzt.getError());
- // fzxzMapper.update(res, query);
- // //插入任务日志
- // FxrwrzDTO errorDto = new FxrwrzDTO();
- // errorDto.setRwbsm(res.getBsm());
- // errorDto.setRwlx("辅助选址");
- // errorDto.setRzlr("计算错误");
- // errorDto.setRzsj(new Date());
- // errorDto.setRzlx("error");
- // errorDto.setFxjg(result);
- // fxrwrzMapper.insert(errorDto);
- // }
- // System.out.println("辅助选址模块:" + res.getBsm() + "完成!!!!!!!! " + new Date().toString());
- // }
- // } catch (Exception e) {
- // e.printStackTrace();
- // }
- //}
- //根据选址任务生成报告
- public FzxzReport createReport(String bsm, List<String> xzbsmList) {
- //插入开始生成报告日志
- FxrwrzDTO successDto = new FxrwrzDTO();
- successDto.setRwbsm(bsm);
- successDto.setRwlx("辅助选址");
- successDto.setRzlr("开始生成选址报告");
- successDto.setRzlx("info");
- successDto.setRzsj(new Date());
- fxrwrzMapper.insert(successDto);
- FzxzEntityDTO res = fzxzMapper.GetFzxzByBsm(bsm);
- FzxzReport fzxzReport = new FzxzReport();
- if (res != null) {
- //文件硬盘真实路径
- String timeStamp = new Date().getTime() + "";
- String rootPath = temp + File.separator + "辅助选址报告" + File.separator + res.getBsm();
- File f = new File(rootPath);
- if (!f.exists()) {
- f.mkdirs();
- }
- String reportPath = res.getXmmc() + "(选址报告)_" + timeStamp + ".docx";
- String simplePath = res.getXmmc() + "(选址简报)_" + timeStamp + ".docx";
- String zipPath = res.getXmmc() + "_" + timeStamp + ".zip";
- //选址报告
- createReport(res, rootPath + File.separator + reportPath, xzbsmList);
- //选址简报
- createSimpleReport(res, rootPath + File.separator + simplePath, xzbsmList);
- //zip打包
- createZipReport(res, rootPath + File.separator + zipPath
- , rootPath + File.separator + reportPath
- , rootPath + File.separator + simplePath);
- //生成返回结果
- fzxzReport.setRootPath(StringUtils.getFileStaticPath(rootPath));
- fzxzReport.setReportfile(StringUtils.getFileStaticPath(rootPath + File.separator + reportPath));
- fzxzReport.setSimplefile(StringUtils.getFileStaticPath(rootPath + File.separator + simplePath));
- fzxzReport.setZipfile(StringUtils.getFileStaticPath(rootPath + File.separator + zipPath));
- fzxzReport.setBsm(bsm);
- fzxzReport.setFxbg(fzxzReport.getReportfile());
- fzxzReport.setJsdw(res.getJsdw());
- fzxzReport.setXmmc(res.getXmmc());
- //查询分析结果图斑信息
- QueryWrapper<FzxzJgGisDTO> giswrapper = new QueryWrapper<FzxzJgGisDTO>();
- giswrapper.eq("rwbsm", res.getBsm());
- List<FzxzJgGisDTO> gisinfo = fzxzJgGISMapper.selectList(giswrapper);
- fzxzReport.setItems(gisinfo);
- }
- //插入开始生成报告日志
- FxrwrzDTO successDto2 = new FxrwrzDTO();
- successDto2.setRwbsm(bsm);
- successDto2.setRwlx("辅助选址");
- successDto2.setRzlr("选址报告生成结束");
- successDto2.setRzlx("info");
- successDto2.setRzsj(new Date());
- fxrwrzMapper.insert(successDto2);
- return fzxzReport;
- }
- /**
- * 选址报告
- */
- private void createReport(FzxzEntityDTO res, String reportPath, List<String> xzbsmList) {
- List<String> imgList = ReportImg(res, xzbsmList);
- //创建document文档对象对象实例
- XWPFDocument document = null;
- OutputStream outputStream = null;//把doc输出到输出流
- try {
- document = new XWPFDocument();
- int pos = 0;
- //文本标题
- NpoiHelper.title(document, res.getXmmc() + "选址报告", pos++);
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
- NpoiHelper.Option optionCENTER = new NpoiHelper.Option();
- optionCENTER.setAlign(ParagraphAlignment.CENTER);
- document.setParagraph(NpoiHelper.newParagraph(document, sdf.format(new Date()), optionCENTER), pos++);
- NpoiHelper.catalog(document, "一、项目选址信息", pos++);
- String ydmj = res.getYdmjbegin() + " - " + res.getYdmjend();
- if (StringUtils.isEmpty(res.getYdmjbegin()) || Double.parseDouble(res.getYdmjbegin()) == 0)
- ydmj = "≤" + res.getYdmjend();
- else if (StringUtils.isEmpty(res.getYdmjend()) || Double.parseDouble(res.getYdmjend()) == 0)
- ydmj = "≥" + res.getYdmjbegin();
- List<String> listTemp = new ArrayList<String>();
- listTemp.add("\t项目名称:" + res.getXmmc());
- listTemp.add("\t建设单位:" + res.getJsdw());
- listTemp.add("\t用地面积:" + ydmj + "平方米");
- listTemp.add("\t用地性质:" + res.getYdmc());
- listTemp.add("\t影响因子:");
- NpoiHelper.content(document, listTemp, pos++);
- List tabYzTitles = new ArrayList<NpoiHelper.TableTitle>();
- NpoiHelper.TableTitle tableTitle = new NpoiHelper.TableTitle();
- tableTitle.setKey("YXYZMC");
- tableTitle.setName("因子名称");
- tableTitle.setWidth(2880);
- tabYzTitles.add(tableTitle);
- tableTitle = new NpoiHelper.TableTitle();
- tableTitle.setKey("YZTJ_TEXT");
- tableTitle.setName("影响条件");
- tableTitle.setAlign(ParagraphAlignment.CENTER);
- tableTitle.setWidth(2880);
- tabYzTitles.add(tableTitle);
- tableTitle = new NpoiHelper.TableTitle();
- tableTitle.setKey("YXZ");
- tableTitle.setName("约束范围值(M)");
- tableTitle.setAlign(ParagraphAlignment.CENTER);
- tableTitle.setWidth(2880);
- tabYzTitles.add(tableTitle);
- //查询选址因子,并且转换为List<Map> 因子条件(包含:C、不包含:N、分析:A)
- QueryWrapper<FzxzXzyzDTO> wrapper = new QueryWrapper<FzxzXzyzDTO>();
- wrapper.eq("rwbsm", res.getBsm());
- List<FzxzXzyzDTO> fzxzXzyzDTOList = fzxzXzyzMapper.selectList(wrapper);
- List<Map<String, Object>> dataTablelist = new ArrayList<>();
- for (int i = 0; i < fzxzXzyzDTOList.size(); i++) {
- Map<String, Object> map = new HashMap<>();
- FzxzXzyzDTO fzxzXzyzDTO = fzxzXzyzDTOList.get(i);
- map.put("YXYZMC", fzxzXzyzDTO.getYxyzmc());
- String yztj = "";
- if (fzxzXzyzDTO.getYztj() != null) {
- if ("C".equals(fzxzXzyzDTO.getYztj().toUpperCase())) {
- yztj = "包含";
- }
- if ("N".equals(fzxzXzyzDTO.getYztj().toUpperCase())) {
- yztj = "不包含";
- }
- if ("A".equals(fzxzXzyzDTO.getYztj().toUpperCase()) || "F".equals(fzxzXzyzDTO.getYztj().toUpperCase())) {
- yztj = "分析";
- }
- }
- map.put("YZTJ_TEXT", yztj);
- String yxz = "";
- if (StringUtils.isNotEmpty(fzxzXzyzDTO.getYxz())) {
- yxz = fzxzXzyzDTO.getYxz();
- }
- map.put("YXZ", yxz);
- dataTablelist.add(map);
- }
- XWPFTable tableYz = NpoiHelper.setComTable(document, tabYzTitles, dataTablelist, "表1:选址影响因子", pos++);
- NpoiHelper.catalog(document, "二、选址范围分析", pos++);
- //查询辅助选址分析图斑
- QueryWrapper<FzxzTbEntityDTO> wrapperTb = new QueryWrapper<FzxzTbEntityDTO>();
- wrapperTb.eq("rwbsm", res.getBsm());
- wrapperTb.groupBy("objectid", "rwbsm", "ydyhfldm", "ydyhflmc", "frequency", "sum_mj");
- List<FzxzTbEntityDTO> fzxzTbEntityDTOList = fzxzTbMapper.selectList(wrapperTb);
- //计算面积总和
- double sumcount = 0;
- for (int i = 0; i < fzxzTbEntityDTOList.size(); i++) {
- sumcount = sumcount + fzxzTbEntityDTOList.get(i).getSumMj();
- }
- List<FzxzTbEntityDTO> list = fzxzTbEntityDTOList.stream().sorted(
- Comparator.comparing(FzxzTbEntityDTO::getSumMj).reversed()
- ).collect(Collectors.toList());
- String fwfx = "\t根据指定选址分析得出,所选范围共" + Math.round(sumcount) + "平方米,其中";
- List<Map<String, Object>> fztable = new ArrayList<>();
- //生成地类分析统计表
- for (int i = 0; i < list.size(); i++) {
- FzxzTbEntityDTO item = list.get(i);
- String zb = String.format("%.1f", item.getSumMj() / sumcount * 100);
- if (i < 5) {
- //面积前五的占比地类计算
- fwfx += item.getYdyhflmc()
- + Math.round(item.getSumMj()) + "平方米,占比" + zb + "%;";
- }
- //List<FzxzTbEntityDTO>转List<Map<String, Object>> 地类编码 地类名称 面积(平方千米) 占比(%)
- Map map = new HashMap();
- map.put("ZB", zb);
- map.put("YDYHFLDM", item.getYdyhfldm());
- map.put("YDYHFLMC", item.getYdyhflmc());
- map.put("SUM_MJ", Math.round(item.getSumMj()));
- fztable.add(map);
- }
- fwfx = fwfx.substring(0, fwfx.length() - 1) + "。详情如下:";
- NpoiHelper.content(document, fwfx, pos++);
- //地类编码 地类名称 面积(平方千米) 占比(%)
- List<NpoiHelper.TableTitle> tabYztbTitles = new ArrayList();
- NpoiHelper.TableTitle tableTitleTb = new NpoiHelper.TableTitle();
- tableTitleTb.setKey("YDYHFLDM");
- tableTitleTb.setName("地类编码");
- tableTitleTb.setAlign(ParagraphAlignment.CENTER);
- tableTitleTb.setWidth(2010);
- tabYztbTitles.add(tableTitleTb);
- tableTitleTb = new NpoiHelper.TableTitle();
- tableTitleTb.setKey("YDYHFLMC");
- tableTitleTb.setName("地类名称");
- tableTitleTb.setWidth(2910);
- tabYztbTitles.add(tableTitleTb);
- tableTitleTb = new NpoiHelper.TableTitle();
- tableTitleTb.setKey("SUM_MJ");
- tableTitleTb.setName("面积(平方千米)");
- tableTitleTb.setAlign(ParagraphAlignment.CENTER);
- tableTitleTb.setWidth(1870);
- tabYztbTitles.add(tableTitleTb);
- tableTitleTb = new NpoiHelper.TableTitle();
- tableTitleTb.setKey("ZB");
- tableTitleTb.setName("占比(%)");
- tableTitleTb.setAlign(ParagraphAlignment.CENTER);
- tableTitleTb.setWidth(1700);
- tabYztbTitles.add(tableTitleTb);
- XWPFTable tableYztb = NpoiHelper.setComTable(document, tabYztbTitles, fztable, "表2:地类分析统计表", pos++);
- //查询结果GIS FzxzJgGisDTO
- QueryWrapper<FzxzJgGisDTO> giswrapper = new QueryWrapper<FzxzJgGisDTO>();
- giswrapper.eq("rwbsm", res.getBsm());
- //筛选方案,根据传参或者预选方案
- // giswrapper.ne("yxfa", "0");
- if (xzbsmList != null) {
- giswrapper.in("bsm", xzbsmList);
- }
- List<FzxzJgGisDTO> fzxzJgGisDTOList = fzxzJgGISMapper.selectList(giswrapper);
- NpoiHelper.catalog(document, "三、选址分析", pos++);
- String ydmc = res.getYdmc();
- if(!StringUtils.isEmpty(ydmc)){
- if (ydmc.lastIndexOf("用地") == ydmc.length() - 2) {
- ydmc = res.getYdmc().substring(0, ydmc.length() - 2);
- }
- NpoiHelper.content(document, "\t按照项目选址要求和影响因子,经对所选范围内的所有"
- + ydmc + "用地进行分析,筛选出符合要求的方案共" + fzxzJgGisDTOList.size() + "个。", pos++);
- }else{
- NpoiHelper.content(document, "\t按照项目选址要求和影响因子,经对所选范围内的所有用地进行分析,筛选出符合要求的方案共" + fzxzJgGisDTOList.size() + "个。", pos++);
- }
- int index = 1;
- NpoiHelper.Option optionIsBold = new NpoiHelper.Option();
- optionIsBold.setBold(true);
- for (int i = 0; i < fzxzJgGisDTOList.size(); i++) {
- FzxzJgGisDTO item = fzxzJgGisDTOList.get(i);
- document.setParagraph(NpoiHelper.newParagraph(document, index + "、方案" + NumberUtil.int2chineseNum(index)
- , optionIsBold), pos++);
- XWPFTable table = document.createTable(7, 4);
- table.setWidth(9000);//总宽度
- for (int k = 0; k < 4; k++) {
- XWPFTableCell cell = table.getRow(0).getCell(k);
- CTTcPr ctTcPr = cell.getCTTc().isSetTcPr() ? cell.getCTTc().getTcPr() : cell.getCTTc().addNewTcPr();
- CTTblWidth ctTblWidth = ctTcPr.addNewTcW();
- ctTblWidth.setW(BigInteger.valueOf(2250));
- ctTblWidth.setType(STTblWidth.DXA);
- }
- //Table 表格第一行
- table.getRow(0).getCell(0).setColor("DBE5F1");
- NpoiHelper.mergeHorizontal(table, 0, 0, 3);
- table.getRow(0).getCell(0).setParagraph(NpoiHelper.setCellText(table, "符合用地情况", optionIsBold));
- //Table 表格第二行
- table.getRow(1).getCell(0).setParagraph(NpoiHelper.setCellText(table, "地类编码", optionIsBold));
- table.getRow(1).getCell(1).setParagraph(NpoiHelper.setCellText(table, item.getDlbm(), null));
- table.getRow(1).getCell(2).setParagraph(NpoiHelper.setCellText(table, "地类名称", optionIsBold));
- table.getRow(1).getCell(3).setParagraph(NpoiHelper.setCellText(table, item.getDlmc(), null));
- //Table 表格第三行
- table.getRow(2).getCell(0).setParagraph(NpoiHelper.setCellText(table, "地块面积", optionIsBold));
- table.getRow(2).getCell(1).setParagraph(NpoiHelper.setCellText(table, Math.round(item.getTbmj()) + "平方米", null));
- table.getRow(2).getCell(2).setParagraph(NpoiHelper.setCellText(table, "土地位置", optionIsBold));
- table.getRow(2).getCell(3).setParagraph(NpoiHelper.setCellText(table, item.getXzqmc(), null));
- //Table 表格第四行
- table.getRow(3).getCell(0).setColor("DBE5F1");
- NpoiHelper.mergeHorizontal(table, 3, 0, 3);
- table.getRow(3).getCell(0).setParagraph(NpoiHelper.setCellText(table, "地块位置信息", optionIsBold));
- //Table 表格第五行 -专题图
- NpoiHelper.mergeHorizontal(table, 4, 0, 1);
- NpoiHelper.mergeHorizontal(table, 4, 2, 3);
- String mapF = "";
- String mapM = "";
- if (imgList != null && imgList.size() > 0) {
- for (int j = 0; j < imgList.size(); j++) {
- String s = imgList.get(j);
- if (s.indexOf(item.getBsm() + "_F") >= 0) {
- mapF = s;//全局
- }
- if (s.indexOf(item.getBsm() + "_M") >= 0) {
- mapM = s;//局部
- }
- }
- }
- if (StringUtils.isNotEmpty(mapF)) {
- FileInputStream fis = null;
- try {
- fis = new FileInputStream(new File(mapF));
- XWPFParagraph paragraph = table.getRow(4).getCell(0).addParagraph();
- paragraph.setAlignment(ParagraphAlignment.CENTER);
- XWPFRun run = paragraph.createRun();
- run.addPicture(
- fis, // 条形码图片的位置
- Document.PICTURE_TYPE_JPEG, // 图片类型
- item.getBsm() + "_F.jpeg", // 图片名称
- 2200000, // 图片的长
- 1700000 // 图片的宽
- );
- run.addBreak(BreakType.TEXT_WRAPPING);
- run.setText("(宏观位置)");
- } catch (Exception e) {
- System.out.println(e.toString());
- } finally {
- if (fis != null) {
- try {
- fis.close();
- } catch (IOException e) {
- throw e;
- }
- }
- }
- }
- if (StringUtils.isNotEmpty(mapM)) {
- FileInputStream fis = null;
- try {
- fis = new FileInputStream(new File(mapM));
- XWPFParagraph paragraph = table.getRow(4).getCell(2).addParagraph();
- paragraph.setAlignment(ParagraphAlignment.CENTER);
- XWPFRun run = paragraph.createRun();
- run.addPicture(
- fis, // 条形码图片的位置
- Document.PICTURE_TYPE_JPEG, // 图片类型
- item.getBsm() + "_M.jpeg", // 图片名称
- 2200000, // 图片的长
- 1700000 // 图片的宽
- );
- run.addBreak(BreakType.TEXT_WRAPPING);
- run.setText("(具体位置)");
- } catch (Exception e) {
- System.out.println(e.toString());
- throw e;
- } finally {
- if (fis != null) {
- try {
- fis.close();
- } catch (IOException e) {
- throw e;
- }
- }
- }
- }
- //Table 表格第六行
- table.getRow(5).getCell(0).setColor("DBE5F1");
- NpoiHelper.mergeHorizontal(table, 5, 0, 3);
- table.getRow(5).getCell(0).setParagraph(NpoiHelper.setCellText(table, "分析结论", optionIsBold));
- //Table 表格第七行
- NpoiHelper.mergeHorizontal(table, 6, 0, 3);
- XWPFParagraph para6 = table.getRow(6).getCell(0).addParagraph();
- para6.setAlignment(ParagraphAlignment.LEFT);
- //查询辅助选址因子
- QueryWrapper<FzxzJgyzDTO> jgyzWrapper = new QueryWrapper<FzxzJgyzDTO>();
- jgyzWrapper.eq("jbbsm", item.getBsm());
- jgyzWrapper.ne("yztj", "F");
- List<FzxzJgyzDTO> jgyzList = fzxzJgyzMapper.selectList(jgyzWrapper);
- int jgyzid = 1;
- for (int j = 0; j < jgyzList.size(); j++) {
- FzxzJgyzDTO fzxzJgyzDTO = jgyzList.get(j);
- XWPFRun run = para6.createRun();
- run.setText(jgyzid + "、" + fzxzJgyzDTO.getFxjg());
- run.addBreak(BreakType.TEXT_WRAPPING);
- jgyzid++;
- }
- //查询辅助选址因子
- jgyzWrapper = new QueryWrapper<FzxzJgyzDTO>();
- jgyzWrapper.eq("jbbsm", item.getBsm());
- jgyzWrapper.eq("yztj", "F");
- jgyzList = fzxzJgyzMapper.selectList(jgyzWrapper);
- for (int j = 0; j < jgyzList.size(); j++) {
- FzxzJgyzDTO jgyz = jgyzList.get(j);
- XWPFRun run = para6.createRun();
- String jg = jgyz.getFxjg();
- Double jgDouble = 0.0;
- try {
- jgDouble = Double.parseDouble(jg);
- run.setText(jgyzid + "、压占" + jgyz.getYxyzmc() + "面积" + jg + "平方米");
- } catch (Exception e) {
- run.setText(jg);
- }
- run.addBreak(BreakType.TEXT_WRAPPING);
- jgyzid++;
- }
- index++;
- }
- File fileDoc = new File(reportPath);
- if (fileDoc.exists()) {
- FileUtils.forceDelete(fileDoc);
- }
- //word文件输出流
- outputStream = new FileOutputStream(reportPath);
- document.write(outputStream);
- } catch (Exception e) {
- e.printStackTrace();
- //插入任务日志
- FxrwrzDTO errorDto = new FxrwrzDTO();
- errorDto.setRwbsm(res.getBsm());
- errorDto.setRwlx("辅助选址");
- errorDto.setRzlr("生成选址报告错误:" + e.getMessage());
- errorDto.setRzsj(new Date());
- errorDto.setRzlx("error");
- fxrwrzMapper.insert(errorDto);
- } 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();
- }
- }
- }
- //转PDF
- String outfilepath = reportPath.replace(".docx", ".pdf");
- NpoiHelper.doc2pdf(reportPath, outfilepath);
- System.out.println(outfilepath);
- }
- /**
- * 选址简报
- */
- private void createSimpleReport(FzxzEntityDTO res, String reportPath, List<String> xzbsmList) {
- //创建document文档对象对象实例
- XWPFDocument document = null;
- OutputStream outputStream = null;//把doc输出到输出流
- try {
- //创建document文档对象对象实例
- document = new XWPFDocument();
- int pos = 0;
- NpoiHelper.Option optionCENTER = new NpoiHelper.Option();
- optionCENTER.setAlign(ParagraphAlignment.CENTER);
- //文本标题
- NpoiHelper.title(document, res.getXmmc() + "选址简报", pos++);
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
- document.setParagraph(NpoiHelper.newParagraph(document, sdf.format(new Date()), optionCENTER), pos++);
- NpoiHelper.catalog(document, "一、项目选址信息", pos++);
- XWPFTable table = document.createTable(4, 4);
- table.setWidth(8500);//总宽度
- for (int k = 0; k < 4; k++) {
- XWPFTableCell cell = table.getRow(0).getCell(k);
- CTTcPr ctTcPr = cell.getCTTc().isSetTcPr() ? cell.getCTTc().getTcPr() : cell.getCTTc().addNewTcPr();
- CTTblWidth ctTblWidth = ctTcPr.addNewTcW();
- ctTblWidth.setW(BigInteger.valueOf(2125));
- ctTblWidth.setType(STTblWidth.DXA);
- }
- //Table 表格第一行
- NpoiHelper.Option optionIsBoldCENTER = new NpoiHelper.Option();
- optionIsBoldCENTER.setAlign(ParagraphAlignment.CENTER);
- optionIsBoldCENTER.setBold(true);
- table.getRow(0).getCell(0).setColor("DBE5F1");
- table.getRow(0).getCell(0).setParagraph(NpoiHelper.setCellText(table, "项目名称", optionIsBoldCENTER));
- NpoiHelper.mergeHorizontal(table, 0, 1, 3);
- table.getRow(0).getCell(1).setParagraph(NpoiHelper.setCellText(table, res.getXmmc(), null));
- //Table 表格第二行
- table.getRow(1).getCell(0).setColor("DBE5F1");
- table.getRow(1).getCell(0).setParagraph(NpoiHelper.setCellText(table, "建设单位", optionIsBoldCENTER));
- NpoiHelper.mergeHorizontal(table, 1, 1, 3);
- table.getRow(1).getCell(1).setParagraph(NpoiHelper.setCellText(table, res.getJsdw(), null));
- //Table 表格第三行
- String ydmj = res.getYdmjbegin() + " - " + res.getYdmjend();
- if (StringUtils.isEmpty(res.getYdmjbegin()) || Double.parseDouble(res.getYdmjbegin()) == 0)
- ydmj = "≤" + res.getYdmjend();
- else if (StringUtils.isEmpty(res.getYdmjend()) || Double.parseDouble(res.getYdmjend()) == 0)
- ydmj = "≥" + res.getYdmjbegin();
- table.getRow(2).getCell(0).setColor("DBE5F1");
- table.getRow(2).getCell(0).setParagraph(NpoiHelper.setCellText(table, "用地面积", optionIsBoldCENTER));
- table.getRow(2).getCell(1).setParagraph(NpoiHelper.setCellText(table, ydmj + "平方米", null));
- table.getRow(2).getCell(2).setColor("DBE5F1");
- table.getRow(2).getCell(2).setParagraph(NpoiHelper.setCellText(table, "用地性质", optionIsBoldCENTER));
- table.getRow(2).getCell(3).setParagraph(NpoiHelper.setCellText(table, res.getYdmc(), null));
- //Table 表格第四行
- table.getRow(3).getCell(1).setColor("DBE5F1");
- table.getRow(3).getCell(2).setColor("DBE5F1");
- table.getRow(3).getCell(3).setColor("DBE5F1");
- table.getRow(3).getCell(0).setParagraph(NpoiHelper.setCellText(table, "选址因子", optionIsBoldCENTER));
- table.getRow(3).getCell(1).setParagraph(NpoiHelper.setCellText(table, "因子名称", optionIsBoldCENTER));
- table.getRow(3).getCell(2).setParagraph(NpoiHelper.setCellText(table, "影响条件", optionIsBoldCENTER));
- table.getRow(3).getCell(3).setParagraph(NpoiHelper.setCellText(table, "约束范围值(M)", optionIsBoldCENTER));
- //查询选址因子,并且转换为List<Map> 因子条件(包含:C、不包含:N、分析:A)
- QueryWrapper<FzxzXzyzDTO> wrapper = new QueryWrapper<FzxzXzyzDTO>();
- wrapper.eq("rwbsm", res.getBsm());
- List<FzxzXzyzDTO> fzxzXzyzDTOList = fzxzXzyzMapper.selectList(wrapper);
- for (int i = 0; i < fzxzXzyzDTOList.size(); i++) {
- FzxzXzyzDTO fzxzXzyzDTO = fzxzXzyzDTOList.get(i);
- String yztj = "";
- if (fzxzXzyzDTO.getYztj() != null) {
- if ("C".equals(fzxzXzyzDTO.getYztj().toUpperCase())) {
- yztj = "包含";
- }
- if ("N".equals(fzxzXzyzDTO.getYztj().toUpperCase())) {
- yztj = "不包含";
- }
- if ("A".equals(fzxzXzyzDTO.getYztj().toUpperCase()) || "F".equals(fzxzXzyzDTO.getYztj().toUpperCase())) {
- yztj = "分析";
- }
- }
- String yxz = "";
- if (StringUtils.isNotEmpty(fzxzXzyzDTO.getYxz())) {
- yxz = fzxzXzyzDTO.getYxz();
- }
- XWPFTableRow mr = table.createRow();
- mr.getCell(1).setParagraph(NpoiHelper.setCellText(table, fzxzXzyzDTO.getYxyzmc(), optionCENTER));
- mr.getCell(2).setParagraph(NpoiHelper.setCellText(table, yztj, optionCENTER));
- mr.getCell(3).setParagraph(NpoiHelper.setCellText(table, yxz, optionCENTER));
- }
- NpoiHelper.mergeCellsVertically(table, 0, 3, 3 + fzxzXzyzDTOList.size());
- table.getRow(3).getCell(0).setColor("DBE5F1");
- //选址分析
- NpoiHelper.catalog(document, "二、选址分析", pos++);
- XWPFTable tableFx = document.createTable(1, 4);
- tableFx.setWidth(8500);//总宽度
- for (int k = 0; k < 4; k++) {
- XWPFTableCell cell = tableFx.getRow(0).getCell(k);
- CTTcPr ctTcPr = cell.getCTTc().isSetTcPr() ? cell.getCTTc().getTcPr() : cell.getCTTc().addNewTcPr();
- CTTblWidth ctTblWidth = ctTcPr.addNewTcW();
- ctTblWidth.setW(BigInteger.valueOf(2125));
- ctTblWidth.setType(STTblWidth.DXA);
- }
- //查询结果GIS FzxzJgGisDTO
- QueryWrapper<FzxzJgGisDTO> giswrapper = new QueryWrapper<FzxzJgGisDTO>();
- giswrapper.eq("rwbsm", res.getBsm());
- //筛选方案,根据传参或者预选方案
- // giswrapper.ne("yxfa", "0");
- if (xzbsmList != null) {
- giswrapper.in("bsm", xzbsmList);
- }
- List<FzxzJgGisDTO> fzxzJgGisDTOList = fzxzJgGISMapper.selectList(giswrapper);
- int index = 1;
- NpoiHelper.Option optionIsBold = new NpoiHelper.Option();
- optionIsBold.setBold(true);
- int rowIndex = 0;
- for (int i = 0; i < fzxzJgGisDTOList.size(); i++) {
- FzxzJgGisDTO item = fzxzJgGisDTOList.get(i);
- XWPFTableRow mr = tableFx.createRow();
- rowIndex++;
- mr.getCell(0).setColor("DBE5F1");
- NpoiHelper.mergeHorizontal(tableFx, rowIndex, 0, 1);
- mr.getCell(0).setParagraph(NpoiHelper.setCellText(tableFx, "方案" + NumberUtil.int2chineseNum(index), optionIsBold));
- //tableFx 表格第二行
- mr = tableFx.createRow();
- rowIndex++;
- mr.getCell(0).setParagraph(NpoiHelper.setCellText(tableFx, "地类编码", optionIsBoldCENTER));
- mr.getCell(1).setParagraph(NpoiHelper.setCellText(tableFx, item.getDlbm(), null));
- mr.getCell(2).setParagraph(NpoiHelper.setCellText(tableFx, "地类名称", optionIsBoldCENTER));
- mr.getCell(3).setParagraph(NpoiHelper.setCellText(tableFx, item.getDlmc(), null));
- //tableFx 表格第三行
- mr = tableFx.createRow();
- rowIndex++;
- mr.getCell(0).setParagraph(NpoiHelper.setCellText(tableFx, "地块面积", optionIsBoldCENTER));
- mr.getCell(1).setParagraph(NpoiHelper.setCellText(tableFx, Math.round(item.getTbmj()) + "平方米", null));
- mr.getCell(2).setParagraph(NpoiHelper.setCellText(tableFx, "土地位置", optionIsBoldCENTER));
- mr.getCell(3).setParagraph(NpoiHelper.setCellText(tableFx, item.getXzqmc(), null));
- //tableFx 表格第四行
- mr = tableFx.createRow();
- rowIndex++;
- mr.getCell(0).setParagraph(NpoiHelper.setCellText(tableFx, "压占分析", optionIsBoldCENTER));
- NpoiHelper.mergeHorizontal(tableFx, rowIndex, 1, 3);
- XWPFParagraph para6 = mr.getCell(1).addParagraph();
- para6.setAlignment(ParagraphAlignment.LEFT);
- //查询选址因子 因子条件(包含:C、不包含:N、分析:A)
- QueryWrapper<FzxzJgyzDTO> fzxzJgyzDTOQueryWrapper = new QueryWrapper<FzxzJgyzDTO>();
- fzxzJgyzDTOQueryWrapper.eq("jbbsm", item.getBsm());
- fzxzJgyzDTOQueryWrapper.eq("yztj", "F");
- List<FzxzJgyzDTO> fzxzJgyzDTOList = fzxzJgyzMapper.selectList(fzxzJgyzDTOQueryWrapper);
- int jgyzid = 1;
- for (int j = 0; j < fzxzJgyzDTOList.size(); j++) {
- FzxzJgyzDTO jgyz = fzxzJgyzDTOList.get(j);
- XWPFRun run = para6.createRun();
- String jg = jgyz.getFxjg();
- Double jgDouble = 0.0;
- try {
- jgDouble = Double.parseDouble(jg);
- run.setText(jgyzid + "、压占" + jgyz.getYxyzmc() + "面积" + jg + "平方米");
- } catch (Exception e) {
- run.setText(jgyzid + "、" + jg);
- }
- if (jgyzid < fzxzJgyzDTOList.size())
- run.addBreak(BreakType.TEXT_WRAPPING);
- jgyzid++;
- }
- index++;
- }
- tableFx.removeRow(0);
- File fileDoc = new File(reportPath);
- if (fileDoc.exists()) {
- FileUtils.forceDelete(fileDoc);
- }
- //word文件输出流
- outputStream = new FileOutputStream(reportPath);
- document.write(outputStream);
- } catch (
- Exception e) {
- e.printStackTrace();
- System.out.println(e.toString());
- //插入任务日志
- FxrwrzDTO errorDto = new FxrwrzDTO();
- errorDto.setRwbsm(res.getBsm());
- errorDto.setRwlx("辅助选址");
- errorDto.setRzlr("生成选址简报错误:" + e.getMessage());
- errorDto.setRzsj(new Date());
- errorDto.setRzlx("error");
- fxrwrzMapper.insert(errorDto);
- } 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();
- }
- }
- }
- //转PDF
- String outfilepath = reportPath.replace(".docx", ".pdf");
- NpoiHelper.doc2pdf(reportPath, outfilepath);
- System.out.println(outfilepath);
- }
- /**
- * zip打包
- */
- private void createZipReport(FzxzEntityDTO res, String reportZip, String reportPath, String simplePath) {
- File f = new File(fzxzShp);
- System.out.println("选址分析报告打包zip:" + reportPath);
- System.out.println("选址分析报告打包shp:" + fzxzShp);
- if (StringUtils.isNotEmpty(fzxzShp)) {
- String filePath = fzxzShp.substring(0, fzxzShp.lastIndexOf("."));
- String docReportPath = reportPath.substring(0, reportPath.lastIndexOf("."));
- String docSimplePath = reportPath.substring(0, reportPath.lastIndexOf("."));
- // 生成的压缩文件
- ZipFile zipFile = null;
- try {
- zipFile = new ZipFile(reportZip);
- ZipParameters parameters = new ZipParameters();
- // 压缩方式
- parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
- // 压缩级别
- parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
- zipFile.addFile(new File(simplePath), parameters);
- zipFile.addFile(new File(reportPath), parameters);
- zipFile.addFile(new File(filePath + ".shp"), parameters);
- zipFile.addFile(new File(filePath + ".shx"), parameters);
- zipFile.addFile(new File(filePath + ".dbf"), parameters);
- zipFile.addFile(new File(filePath + ".cpg"), parameters);
- zipFile.addFile(new File(filePath + ".prj"), parameters);
- } catch (ZipException e) {
- System.out.println(e.toString());
- //插入任务日志
- FxrwrzDTO errorDto = new FxrwrzDTO();
- errorDto.setRwbsm(res.getBsm());
- errorDto.setRwlx("辅助选址");
- errorDto.setRzlr("生成选址报告zip打包错误:" + e.getMessage());
- errorDto.setRzsj(new Date());
- errorDto.setRzlx("error");
- fxrwrzMapper.insert(errorDto);
- }
- }
- }
- /**
- * 导出报告图片
- *
- * @return
- */
- private List<String> ReportImg(FzxzEntityDTO res, List<String> xzbsmList) {
- //查询分析结果图斑信息
- QueryWrapper<FzxzJgGisDTO> giswrapper = new QueryWrapper<FzxzJgGisDTO>();
- giswrapper.eq("rwbsm", res.getBsm());
- //筛选方案,根据传参或者预选方案
- // giswrapper.ne("yxfa", "0");
- if (xzbsmList != null) {
- giswrapper.in("bsm", xzbsmList);
- }
- List<FzxzJgGisDTO> fzxzJgGisDTOList = fzxzJgGISMapper.selectList(giswrapper);
- //SDE转SHP
- String inShp = fzxzShp;
- List objidlist = new ArrayList<>();
- for (FzxzJgGisDTO cur : fzxzJgGisDTOList) {
- objidlist.add(cur.getObjectid());
- }
- String objids = Joiner.on(",").join(objidlist);
- sde2Shp("KJGH.T_FZSS_FZXZ_JG_GIS", inShp, "\"OBJECTID\" IN (" + objids + ")");
- //执行python
- Map<String, String> params = new HashMap<>();
- List<String> result = PythonExecute.RunFzxzMap(mapFunctionId, params);
- return result;
- }
- /**
- * SDE转SHP
- *
- * @param table SDE表
- * @param shpfile shp文件
- * @param where 追加字段
- * @return
- */
- public static String sde2Shp(String table, String shpfile, String where) {
- if (StringUtils.isNotEmpty(where)) {
- Map<String, String> params = new HashMap<>();
- params.put("table", table);
- params.put("shpfile", shpfile);
- params.put("where", where);
- return PythonExecute.RunGisHelper("sde2shp", params);
- } else {
- Map<String, String> params = new HashMap<>();
- params.put("table", table);
- params.put("shpfile", shpfile);
- return PythonExecute.RunGisHelper("sde2shp", params);
- }
- }
- }
|