123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670 |
- package com.onemap.sanya.controller;
- import com.alibaba.cloud.commons.io.FileUtils;
- import com.alibaba.fastjson.util.IOUtils;
- import com.alibaba.fastjson2.JSON;
- import com.alibaba.fastjson2.JSONObject;
- import com.deepoove.poi.XWPFTemplate;
- import com.deepoove.poi.config.Configure;
- import com.deepoove.poi.data.PictureRenderData;
- import com.deepoove.poi.data.PictureType;
- import com.deepoove.poi.data.Pictures;
- import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
- import com.deepoove.poi.template.MetaTemplate;
- import com.deepoove.poi.template.run.RunTemplate;
- import com.onemap.common.core.utils.StringUtils;
- import com.onemap.common.core.web.controller.BaseController;
- import com.onemap.common.core.web.domain.AjaxResult;
- import com.onemap.sanya.domain.*;
- import com.onemap.sanya.domain.mergeCell.AnalyseDetailTablePolicy;
- import com.onemap.system.api.domain.SysUser;
- import com.onemap.system.api.factory.RemoteLogFallbackFactory;
- import org.apache.poi.xwpf.usermodel.*;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.core.io.ClassPathResource;
- import org.springframework.util.ClassUtils;
- import org.springframework.util.ResourceUtils;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.io.*;
- import java.net.URLEncoder;
- import java.nio.charset.StandardCharsets;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * @author Zzz
- */
- @CrossOrigin(origins = "*")
- @RestController
- @RequestMapping("/sanya")
- public class SanYaController extends BaseController {
- private static final Logger log = LoggerFactory.getLogger(SanYaController.class);
- private static final String[] LvArray = {"Ⅰ", "Ⅱ", "Ⅲ", "Ⅳ", "Ⅴ", "Ⅵ", "Ⅶ", "Ⅷ", "Ⅸ", "Ⅹ"};
- /**
- * 导出选址报告word
- * @param request
- * @param response
- */
- @RequestMapping("/exportWord1")
- private void exportWord1(HttpServletRequest request, HttpServletResponse response) {
- try {
- SiteSelectionReport siteSelectionReport = setWordData1();
- if (siteSelectionReport == null) {
- log.info("选址报告数据为空,导出失败!");
- return;
- }
- ClassPathResource classPathResource = new ClassPathResource("template/word/"+"01-选址报告-02.docx");
- InputStream inputStream = classPathResource.getInputStream();
- Configure configure = Configure.builder()
- .bind("tableList", new LoopRowTableRenderPolicy())
- .bind("analyseList", new AnalyseDetailTablePolicy()).build();
- // 通过 XWPFTemplate 编译文件并渲染数据到模板中
- XWPFTemplate template = XWPFTemplate.compile(inputStream, configure).render(siteSelectionReport);
- //生成临时文件存放地址
- //String temDir = basePath;
- //生成文件名
- String wordName = "01-选址报告-02" + "-" + System.currentTimeMillis();
- writeWord(response, null, wordName, template);
- } catch (Exception e) {
- e.printStackTrace();
- log.error("选址报告导出异常,{}" + e);
- }
- }
- /**
- * 导出选址报告word
- * @param request
- * @param response
- */
- @RequestMapping("/exportWord2")
- private void exportWord2(HttpServletRequest request, HttpServletResponse response) {
- try {
- ComplianceAnalysisReport complianceAnalysisReport = setWordData2();
- if (complianceAnalysisReport == null) {
- log.info("合规性分析报告数据为空,导出失败!");
- return;
- }
- ClassPathResource classPathResource = new ClassPathResource("template/word/"+"02-合规性分析报告-02.docx");
- InputStream inputStream = classPathResource.getInputStream();
- Configure configure = Configure.builder()
- .bind("tableList01", new LoopRowTableRenderPolicy())
- .bind("tableList02", new LoopRowTableRenderPolicy())
- .bind("analyseList01", new AnalyseDetailTablePolicy())
- .bind("analyseList02", new AnalyseDetailTablePolicy()).build();
- // 通过 XWPFTemplate 编译文件并渲染数据到模板中
- XWPFTemplate template = XWPFTemplate.compile(inputStream, configure).render(complianceAnalysisReport);
- List<MetaTemplate> elementTemplates = template.getElementTemplates();
- for (MetaTemplate elementTemplate : elementTemplates) {
- String variable = elementTemplate.variable();
- if ("{{tableList01}}".equals(variable) || "{{tableList02}}".equals(variable)) {
- RunTemplate runTemplate = (RunTemplate) elementTemplate;
- XWPFRun run = runTemplate.getRun();
- XWPFTableCell cell = (XWPFTableCell) ((XWPFParagraph) run.getParent()).getBody();
- List<XWPFTableRow> rows = cell.getTableRow().getTable().getRows();
- int rowIndex = rows.indexOf(cell.getTableRow());
- XWPFTable table = cell.getTableRow().getTable();
- table.removeRow(rowIndex);
- }
- }
- //生成临时文件存放地址
- //String temDir = basePath;
- //生成文件名
- String wordName = "02-合规性分析报告-02" + "-" + System.currentTimeMillis();
- writeWord(response, null, wordName, template);
- } catch (Exception e) {
- e.printStackTrace();
- log.error("合规性分析报告导出异常,{}" + e);
- }
- }
- /**
- * 导出征收补偿预估报告word
- * @param request
- * @param response
- */
- @RequestMapping("/exportWord3")
- private void exportWord3(HttpServletRequest request, HttpServletResponse response) {
- try {
- CompensateEstimateReport compensateEstimateReport = setWordData3();
- if (compensateEstimateReport == null) {
- log.info("征收补偿预估报告数据为空,导出失败!");
- return;
- }
- ClassPathResource classPathResource = new ClassPathResource("template/word/"+"03-征收补偿预估报告-02.docx");
- InputStream inputStream = classPathResource.getInputStream();
- Configure configure = Configure.builder()
- .bind("tableList01", new LoopRowTableRenderPolicy()).build();
- // 通过 XWPFTemplate 编译文件并渲染数据到模板中
- XWPFTemplate template = XWPFTemplate.compile(inputStream, configure).render(compensateEstimateReport);
- //生成临时文件存放地址
- //String temDir = basePath;
- //生成文件名
- String wordName = "03-征收补偿预估报告-02" + "-" + System.currentTimeMillis();
- writeWord(response, null, wordName, template);
- } catch (Exception e) {
- e.printStackTrace();
- log.error("征收补偿预估报告导出异常,{}" + e);
- }
- }
- /**
- * 导出基准地价报告word
- * @param request
- * @param response
- */
- @RequestMapping("/exportWord4")
- private void exportWord4(@RequestBody BenchmarkLandPriceReport benchmarkLandPriceReport, HttpServletRequest request, HttpServletResponse response) {
- try {
- // BenchmarkLandPriceReport benchmarkLandPriceReport = setWordData4();
- if (benchmarkLandPriceReport == null) {
- log.info("基准地价报告数据为空,导出失败!");
- return ;
- }
- List<PicData> picList = new ArrayList<>();
- //将base64图片转为PictureRenderData
- for (String base64ImageData:benchmarkLandPriceReport.getPicBase64List()) {
- PictureRenderData pictureRenderData =Pictures.ofBase64(base64ImageData, PictureType.JPEG).size(300, 200).create();
- picList.add(new PicData(pictureRenderData));
- }
- benchmarkLandPriceReport.setPicList(picList);
- ClassPathResource classPathResource = new ClassPathResource("template/word/"+"04-基准地价报告-02.docx");
- InputStream inputStream = classPathResource.getInputStream();
- Configure configure = Configure.builder()
- .bind("tableList01", new LoopRowTableRenderPolicy())
- .bind("tableList02", new LoopRowTableRenderPolicy()).build();
- // 通过 XWPFTemplate 编译文件并渲染数据到模板中
- XWPFTemplate template = XWPFTemplate.compile(inputStream, configure).render(benchmarkLandPriceReport);
- List<MetaTemplate> elementTemplates = template.getElementTemplates();
- for (MetaTemplate elementTemplate : elementTemplates) {
- String variable = elementTemplate.variable();
- if ("{{tableList01}}".equals(variable) || "{{tableList02}}".equals(variable)) {
- RunTemplate runTemplate = (RunTemplate) elementTemplate;
- XWPFRun run = runTemplate.getRun();
- XWPFTableCell cell = (XWPFTableCell) ((XWPFParagraph) run.getParent()).getBody();
- List<XWPFTableRow> rows = cell.getTableRow().getTable().getRows();
- int rowIndex = rows.indexOf(cell.getTableRow());
- XWPFTable table = cell.getTableRow().getTable();
- table.removeRow(rowIndex);
- }
- }
- //生成文件存放地址
- // String temDir = this.getClass().getClassLoader().getResource("template/storageword/").getPath();
- //ClassUtils.getDefaultClassLoader().getResource("").getPath() + "template/storageword/";;
- //生成文件名
- String wordName = "04-基准地价报告-02" + "-" + System.currentTimeMillis();
- writeWord(response, null, wordName, template);
- } catch (Exception e) {
- e.printStackTrace();
- log.error("基准地价报告导出异常,{}" + e);
- }
- }
- /**
- * 下载分析文档
- * @param fileName
- * @param response
- */
- @RequestMapping("/getWord")
- private void getWord( String fileName,HttpServletResponse response) {
- String filePath = ClassUtils.getDefaultClassLoader().getResource("").getPath() + "template/storageword/";
- // 设置请求头
- response.setContentType("application/octet-stream");
- response.addHeader("Content-Disposition", "attachment;filename=\"" + new String(fileName.getBytes(), StandardCharsets.UTF_8) + "\"");
- response.setHeader("download-filename", fileName);
- // 开放请求头download-filename前端获取权限
- response.setHeader("Access-Control-Expose-Headers", "download-filename");
- FileInputStream fis = null;
- OutputStream os = null;
- try {
- // 输出
- os = response.getOutputStream();
- File file = new File(filePath+fileName);
- if (!file.exists()) {
- throw new FileNotFoundException(filePath+fileName);
- }
- fis = new FileInputStream(file);
- byte[] b = new byte[1024];
- int length;
- while ((length = fis.read(b)) > 0) {
- os.write(b, 0, length);
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- IOUtils.close(os);
- IOUtils.close(fis);
- }
- }
- /**
- * 封装-选址报告导出数据
- *
- * @return
- */
- private SiteSelectionReport setWordData1() {
- try {
- SiteSelectionReport siteSelectionReport = new SiteSelectionReport();
- // // 模拟数据 读取静态JSON文件填充数据 根据resource文件路径,生成文件
- // File jsonFile = ResourceUtils.getFile("classpath:template/json/word.json");
- // // 解析文件为指定编码的字符串
- // String json = FileUtils.readFileToString(jsonFile, "UTF-8");
- ClassPathResource classPathResource = new ClassPathResource("template/json/word.json");
- InputStream inputStream = classPathResource.getInputStream();
- String json = org.apache.commons.io.IOUtils.toString(inputStream, StandardCharsets.UTF_8);
- // 转换格式
- JSONObject jsonObject = JSON.parseObject(json);
- // 读取模拟数据 并赋值给导出对象
- String wordDataJson = jsonObject.get("wordData1").toString();
- siteSelectionReport = JSON.parseObject(wordDataJson, SiteSelectionReport.class);
- //模拟 影响因子数据 赋值给导出对象
- List<FactorData> factorDataList = new ArrayList<>();
- for (int i = 0; i < 6; i++) {
- factorDataList.add(new FactorData().FactorDataForSiteSelectionReport("测试因子名称" + i, "测试计算方法" + i, "测试因子约束" + i));
- }
- siteSelectionReport.setTableList(factorDataList);
- //模拟读取静态图片 赋值给导出对象
- String imgPath = ClassUtils.getDefaultClassLoader().getResource("").getPath() + "template/img/test.png";
- PictureRenderData pictureRenderData = Pictures.ofLocal(imgPath).size(300, 200).create();
- List<PicData> picList = new ArrayList<>();
- picList.add(new PicData(pictureRenderData));
- picList.add(new PicData(pictureRenderData));
- picList.add(new PicData(pictureRenderData));
- siteSelectionReport.setPicList(picList);
- // 读取分析JSON 用于生成选址范围现状分析导出数据格式
- String analyseJson = jsonObject.get("analyseJson").toString();
- List<JsonConvert> analyseConList = JSON.parseArray(analyseJson, JsonConvert.class);
- List<AnalyseData> analyseList = new ArrayList<>();
- Double totalArea = 0.0;
- String detail = "";
- //遍历选址范围现状分析 封装数据 默认数据为0-100
- for (JsonConvert jsonConvert : analyseConList) {
- String key = jsonConvert.getKey();
- String value = jsonConvert.getValue();
- List<JsonConvert> children = jsonConvert.getChildren();
- AnalyseData analyseData = null;
- if (children != null && children.size() > 0) {
- for (JsonConvert child : children) {
- String cKey = child.getKey();
- String cValue = child.getValue();
- //封装一级,二级,模拟设置分析值
- analyseData = new AnalyseData(key, value, cKey, cValue, new Random().nextDouble()*100, new Random().nextDouble()*100);
- analyseList.add(analyseData);
- //计算总面积
- if (analyseData.getAreaValue() != null) {
- totalArea = totalArea + analyseData.getAreaValue();
- }
- //拼接范围说明字符
- if (analyseData.getAreaValue() != null && analyseData.getPercentValue() != null) {
- detail = detail + analyseData.getSecondName() + analyseData.getAreaValue() + "平方米,占比" + analyseData.getPercentValue() + "%;";
- }
- }
- } else {
- analyseData = new AnalyseData(key, value, "", "", null, null);
- analyseList.add(analyseData);
- }
- }
- // 赋值导出对象
- siteSelectionReport.setTotalArea(totalArea + "");
- siteSelectionReport.setDetail(detail);
- siteSelectionReport.setAnalyseList(analyseList);
- return siteSelectionReport;
- } catch (Exception e) {
- e.printStackTrace();
- log.error("选址报告数据封装异常,{}" + e);
- }
- return null;
- }
- /**
- * 封装-合规性分析报告导出数据
- *
- * @return
- */
- private ComplianceAnalysisReport setWordData2() {
- try {
- ComplianceAnalysisReport complianceAnalysisReport = new ComplianceAnalysisReport();
- // // 模拟数据 读取静态JSON文件填充数据 根据resource文件路径,生成文件
- // File jsonFile = ResourceUtils.getFile("classpath:template/json/word.json");
- // // 解析文件为指定编码的字符串
- // String json = FileUtils.readFileToString(jsonFile, "UTF-8");
- ClassPathResource classPathResource = new ClassPathResource("template/json/word.json");
- InputStream inputStream = classPathResource.getInputStream();
- String json = org.apache.commons.io.IOUtils.toString(inputStream, StandardCharsets.UTF_8);
- // 转换格式
- JSONObject jsonObject = JSON.parseObject(json);
- // 读取模拟数据 并赋值给导出对象
- String wordDataJson = jsonObject.get("wordData2").toString();
- complianceAnalysisReport = JSON.parseObject(wordDataJson, ComplianceAnalysisReport.class);
- // 读取分析JSON 用于生成选址范围现状分析导出数据格式
- String analyseJson = jsonObject.get("analyseJson").toString();
- List<JsonConvert> analyseConList = JSON.parseArray(analyseJson, JsonConvert.class);
- List<AnalyseData> analyseList01 = new ArrayList<>();
- List<AnalyseData> analyseList02 = new ArrayList<>();
- Double totalArea01 = 0.0;
- String detail01 = "";
- Double totalArea02 = 0.0;
- String detail02 = "";
- //遍历选址范围 生成现状分析和控制性详细规划分析 封装数据 默认数据为0-100
- for (JsonConvert jsonConvert : analyseConList) {
- String key = jsonConvert.getKey();
- String value = jsonConvert.getValue();
- List<JsonConvert> children = jsonConvert.getChildren();
- AnalyseData analyseData01 = null;
- AnalyseData analyseData02 = null;
- if (children != null && children.size() > 0) {
- for (JsonConvert child : children) {
- String cKey = child.getKey();
- String cValue = child.getValue();
- //封装一级,二级,模拟设置分析值
- analyseData01 = new AnalyseData(key, value, cKey, cValue, new Random().nextDouble()*100, new Random().nextDouble()*100);
- analyseData02 = new AnalyseData(key, value, cKey, cValue, new Random().nextDouble()*100, new Random().nextDouble()*100);
- analyseList01.add(analyseData01);
- analyseList02.add(analyseData02);
- //计算现状分析总面积
- if (analyseData01.getAreaValue() != null) {
- totalArea01 = totalArea01 + analyseData01.getAreaValue();
- }
- //拼接现状分析范围说明字符
- if (analyseData01.getAreaValue() != null && analyseData01.getPercentValue() != null) {
- detail01 = detail01 + analyseData01.getSecondName() + analyseData01.getAreaValue() + "平方米,占比" + analyseData01.getPercentValue() + "%;";
- }
- //计算控制性详细规划分析总面积
- if (analyseData02.getAreaValue() != null) {
- totalArea02 = totalArea02 + analyseData02.getAreaValue();
- }
- //拼接控制性详细规划分析范围说明字符
- if (analyseData02.getAreaValue() != null && analyseData02.getPercentValue() != null) {
- detail02 = detail02 + analyseData02.getSecondName() + analyseData02.getAreaValue() + "平方米,占比" + analyseData02.getPercentValue() + "%;";
- }
- }
- } else {
- analyseData01 = new AnalyseData(key, value, "", "", null, null);
- analyseData02 = new AnalyseData(key, value, "", "", null, null);
- analyseList01.add(analyseData01);
- analyseList02.add(analyseData02);
- }
- }
- //生成分析因子->现状分析 数据 根据现状上面的现状分析计算而来
- List<FactorData> tableList01 = new ArrayList<>();
- if (analyseList01 != null && analyseList01.size() > 0) {
- Map<String, List<AnalyseData>> analyseCollect01 = analyseList01.stream().collect(Collectors.groupingBy(AnalyseData::getFirstCode));
- if (analyseCollect01 != null && analyseCollect01.size() > 0) {
- analyseCollect01.entrySet()
- .stream()
- .sorted(Map.Entry.comparingByKey())
- .forEach(entry -> {
- List<AnalyseData> analyseDataList = entry.getValue();
- Double sum = analyseDataList.stream().mapToDouble(obj -> obj.getAreaValue() != null ? obj.getAreaValue() : 0).sum();
- AnalyseData analyseData = analyseDataList.get(0);
- String firstCode = analyseData.getFirstCode();
- String firstName = analyseData.getFirstName();
- tableList01.add(new FactorData().FactorDataForComplianceAnalysisReport01(firstCode + " " + firstName, sum + ""));
- });
- }
- }
- //生成分析因子->控制性详细规划分析 数据 根据现状上面的控制性详细规划分析计算而来
- List<FactorData> tableList02 = new ArrayList<>();
- if (analyseList02 != null && analyseList02.size() > 0) {
- Map<String, List<AnalyseData>> analyseCollect02 = analyseList02.stream().collect(Collectors.groupingBy(AnalyseData::getFirstCode));
- if (analyseCollect02 != null && analyseCollect02.size() > 0) {
- analyseCollect02.entrySet()
- .stream()
- .sorted(Map.Entry.comparingByKey())
- .forEach(entry -> {
- List<AnalyseData> analyseDataList = entry.getValue();
- Double sum = analyseDataList.stream().mapToDouble(obj -> obj.getAreaValue() != null ? obj.getAreaValue() : 0).sum();
- AnalyseData analyseData = analyseDataList.get(0);
- String firstCode = analyseData.getFirstCode();
- String firstName = analyseData.getFirstName();
- tableList02.add(new FactorData().FactorDataForComplianceAnalysisReport02(firstCode + " " + firstName, sum + ""));
- });
- }
- }
- // 赋值导出对象
- complianceAnalysisReport.setTableList01(tableList01);
- complianceAnalysisReport.setTableList02(tableList02);
- complianceAnalysisReport.setAnalyseList01(analyseList01);
- complianceAnalysisReport.setTotalArea01(totalArea01);
- complianceAnalysisReport.setDetail01(detail01);
- complianceAnalysisReport.setAnalyseList02(analyseList02);
- complianceAnalysisReport.setTotalArea02(totalArea02);
- complianceAnalysisReport.setDetail02(detail02);
- return complianceAnalysisReport;
- } catch (Exception e) {
- e.printStackTrace();
- log.error("合规性分析报告封装异常,{}" + e);
- }
- return null;
- }
- /**
- * 封装-征收补偿预估报告导出数据
- *
- * @return
- */
- private CompensateEstimateReport setWordData3() {
- try {
- CompensateEstimateReport compensateEstimateReport = new CompensateEstimateReport();
- // // 模拟数据 读取静态JSON文件填充数据 根据resource文件路径,生成文件
- // File jsonFile = ResourceUtils.getFile("classpath:template/json/word.json");
- // // 解析文件为指定编码的字符串
- // String json = FileUtils.readFileToString(jsonFile, "UTF-8");
- ClassPathResource classPathResource = new ClassPathResource("template/json/word.json");
- InputStream inputStream = classPathResource.getInputStream();
- String json = org.apache.commons.io.IOUtils.toString(inputStream, StandardCharsets.UTF_8);
- // 转换格式
- JSONObject jsonObject = JSON.parseObject(json);
- // 读取模拟数据 并赋值给导出对象
- String wordDataJson = jsonObject.get("wordData3").toString();
- compensateEstimateReport = JSON.parseObject(wordDataJson, CompensateEstimateReport.class);
- //模拟读取静态图片 赋值给导出对象
- String imgPath = ClassUtils.getDefaultClassLoader().getResource("").getPath() + "template/img/test.png";
- PictureRenderData pictureRenderData = Pictures.ofLocal(imgPath).size(300, 200).create();
- List<PicData> picList = new ArrayList<>();
- picList.add(new PicData(pictureRenderData));
- picList.add(new PicData(pictureRenderData));
- picList.add(new PicData(pictureRenderData));
- compensateEstimateReport.setPicList(picList);
- //模拟 3.2房屋补偿费预估->各个房屋补偿情况 数据
- List<HouseCompensate> tableList01 = new ArrayList<>();
- for (int i = 0; i < 10; i++) {
- tableList01.add(new HouseCompensate(i, "房屋编号" + i, "产权人" + i, new Random().nextInt(100), "房屋结构" + i, new Random().nextInt(100), "房屋地址" + i));
- }
- //根据各个房屋补偿情况统计面积,拆迁款等内容 初始为0
- int numberEHD = 0;
- int feeECHD = 0;
- int totalFA = 0;
- int averageFeeECHD = 0;
- if (tableList01 != null && tableList01.size() > 0) {
- numberEHD = tableList01.size();
- feeECHD = tableList01.stream().mapToInt(obj -> obj.getFeeCHD() != null ? obj.getFeeCHD() : 0).sum();
- totalFA = tableList01.stream().mapToInt(obj -> obj.getFloorArea() != null ? obj.getFloorArea() : 0).sum();
- averageFeeECHD = feeECHD / totalFA;
- }
- // 赋值导出对象
- compensateEstimateReport.setTableList01(tableList01);
- compensateEstimateReport.setNumberEHD(numberEHD);
- compensateEstimateReport.setFeeECHD(feeECHD);
- compensateEstimateReport.setTotalFA(totalFA);
- compensateEstimateReport.setAverageFeeECHD(averageFeeECHD);
- return compensateEstimateReport;
- } catch (Exception e) {
- e.printStackTrace();
- log.error("征收补偿预估报告封装异常,{}" + e);
- }
- return null;
- }
- /**
- * 封装-基准地价报告导出数据
- *
- * @return
- */
- // private BenchmarkLandPriceReport setWordData4() {
- // try {
- // BenchmarkLandPriceReport benchmarkLandPriceReport = new BenchmarkLandPriceReport();
- // // 模拟数据 读取静态JSON文件填充数据 根据resource文件路径,生成文件
- // File jsonFile = ResourceUtils.getFile("classpath:template/json/word.json");
- // // 解析文件为指定编码的字符串
- // String json = FileUtils.readFileToString(jsonFile, "UTF-8");
- // // 转换格式
- // JSONObject jsonObject = JSON.parseObject(json);
- // // 读取模拟数据 并赋值给导出对象
- // String wordDataJson = jsonObject.get("wordData4").toString();
- // benchmarkLandPriceReport = JSON.parseObject(wordDataJson, BenchmarkLandPriceReport.class);
- //
- // //模拟读取静态图片 赋值给导出对象
- // String imgPath = ClassUtils.getDefaultClassLoader().getResource("").getPath() + "template/img/test.png";
- // PictureRenderData pictureRenderData = Pictures.ofLocal(imgPath).size(300, 200).create();
- // List<PicData> picList = new ArrayList<>();
- // picList.add(new PicData(pictureRenderData));
- // picList.add(new PicData(pictureRenderData));
- // picList.add(new PicData(pictureRenderData));
- // benchmarkLandPriceReport.setPicList(picList);
- //
- // //模拟 用地地价预估情况 数据,分为 国有建设用地 集体建设用地
- // List<LandPriceEstimation> tableList01 = new ArrayList<>();
- // List<LandPriceEstimation> tableList02 = new ArrayList<>();
- // for (int i = 0; i < 6; i++) {
- // tableList01.add(new LandPriceEstimation(LvArray[i], new Random().nextDouble()*100, new Random().nextDouble()*100, new Random().nextDouble()*100));
- // tableList02.add(new LandPriceEstimation(LvArray[i], new Random().nextDouble()*100, new Random().nextDouble()*100, new Random().nextDouble()*100));
- // }
- //
- // //国有建设用地面积 国有土地地价预估 默认0
- // Double areaSCL = 0.0;
- // Double landPriceESCL = 0.0;
- // //集体建设用地面积 集体土地地价预估 默认0
- // Double areaCCL = 0.0;
- // Double landPriceECCL = 0.0;
- // //总面积 总地价预估 默认0
- // Double totalArea = 0.0;
- // Double totalLandPrice = 0.0;
- // if (tableList01 != null && tableList01.size() > 0) {
- // areaSCL = tableList01.stream().mapToDouble(obj -> obj.getArea() != null ? obj.getArea() : 0).sum();
- // landPriceESCL = tableList01.stream().mapToDouble(obj -> obj.getLandPriceES() != null ? obj.getLandPriceES() : 0).sum();
- // }
- // if (tableList02 != null && tableList02.size() > 0) {
- // areaCCL = tableList02.stream().mapToDouble(obj -> obj.getArea() != null ? obj.getArea() : 0).sum();
- // landPriceECCL = tableList02.stream().mapToDouble(obj -> obj.getLandPriceES() != null ? obj.getLandPriceES() : 0).sum();
- // }
- // if (areaSCL > 0 && areaCCL > 0) {
- // totalArea = areaSCL + areaCCL;
- // }
- // if (landPriceESCL > 0 && landPriceECCL > 0) {
- // totalLandPrice = landPriceESCL + landPriceECCL;
- // }
- // // 赋值导出对象
- // benchmarkLandPriceReport.setTableList01(tableList01);
- // benchmarkLandPriceReport.setTableList02(tableList02);
- // benchmarkLandPriceReport.setTotalArea(totalArea);
- // benchmarkLandPriceReport.setTotalLandPrice(totalLandPrice);
- // benchmarkLandPriceReport.setAreaSCL(areaSCL);
- // benchmarkLandPriceReport.setLandPriceESCL(landPriceESCL);
- // benchmarkLandPriceReport.setAreaCCL(areaCCL);
- // benchmarkLandPriceReport.setLandPriceECCL(landPriceECCL);
- // return benchmarkLandPriceReport;
- // } catch (Exception e) {
- // e.printStackTrace();
- // log.error("基准地价报告数据封装异常,{}" + e);
- // }
- // return null;
- // }
- /**
- * word写出
- *
- * @param response
- * @param temDir
- * @param wordName
- * @param template
- * @throws Exception
- */
- private void writeWord(HttpServletResponse response, String temDir, String wordName, XWPFTemplate template) throws Exception {
- // 生成的word格式
- String formatSuffix = ".docx";
- // 拼接后的文件名 文件名.带后缀
- String fileName = wordName + formatSuffix;
- //=================生成word到设置浏览默认下载地址=================
- // 设置强制下载不打开
- response.setContentType("application/force-download");
- response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
- // 设置文件名
- response.addHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(fileName, "UTF-8"));
- OutputStream out = response.getOutputStream();
- template.write(out);
- out.flush();
- out.close();
- template.close();
- //删除临时文件
- if(StringUtils.isNotEmpty(temDir)){
- File file = new File(temDir + fileName);
- file.setWritable(true);
- file.delete();
- }
- }
- /**
- * word存储
- *
- * @param response
- * @param temDir
- * @param wordName
- * @param template
- * @throws Exception
- */
- private String storageWord(HttpServletResponse response, String temDir, String wordName, XWPFTemplate template) throws Exception {
- // 生成的word格式
- String formatSuffix = ".docx";
- // 拼接后的文件名 文件名.带后缀
- String fileName = wordName + formatSuffix;
- File file = new File(temDir + fileName);
- FileOutputStream out = new FileOutputStream(file);
- template.write(out);
- out.close();
- return fileName;
- }
- }
|