2022/10/21提交
This commit is contained in:
@ -2,7 +2,7 @@ package com.ruoyi.web.controller.shate;
|
||||
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.utils.BarChart;
|
||||
import com.ruoyi.common.utils.chartForWord.CustomXWPFDocument;
|
||||
import com.ruoyi.common.utils.CustomXWPFDocument;
|
||||
import com.ruoyi.common.utils.shate.PageUtils;
|
||||
|
||||
import com.ruoyi.system.domain_shate.*;
|
||||
@ -11,7 +11,6 @@ import com.ruoyi.system.service_shate.IPlantingSuitabilityService;
|
||||
import com.ruoyi.system.service_shate.ISeedingSuccessService;
|
||||
import com.ruoyi.system.service_shate.IVegetationHealthServices;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.w3c.dom.Document;
|
||||
@ -560,11 +559,16 @@ public class DateUploadController
|
||||
//创建第一个段落的内容
|
||||
BarChart.createParagraphAndInsertWord(docxDocument, "Date time: "+year);
|
||||
BarChart.createParagraphAndInsertWord(docxDocument, "Evaluation area: "+zone);
|
||||
|
||||
|
||||
//创建第二段落的标题
|
||||
BarChart.createFirstLevelTopic(docxDocument, "2.Results of remote sensing monitoring of seeding success rate");
|
||||
//循环判断有多少个资源
|
||||
List<SeedingSuccessRate> seedingSuccessRates = seedingSuccessService.sqlSeeding(zone, year);
|
||||
for (SeedingSuccessRate seedingSuccessRate : seedingSuccessRates) {
|
||||
//图片的url
|
||||
//String productCode1 = seedingSuccessRate.getProductCode1();
|
||||
//String productCode2 = seedingSuccessRate.getProductCode2();
|
||||
//创建第二段落的内容
|
||||
BarChart.insertPic(docxDocument, "C:\\Users\\xkrs\\Desktop\\pic\\1.png");
|
||||
BarChart.setPicTitle(docxDocument, "Spatial distribution data of successful seeding regions");
|
||||
@ -577,7 +581,9 @@ public class DateUploadController
|
||||
//获取ProductCode1的集合
|
||||
List<String> M_code=new ArrayList<>();
|
||||
List<String> H_code=new ArrayList<>();
|
||||
//查询数据库中有多少条数据
|
||||
List<VegetationHealth> vegetationHealths = vegetationHealthServices.sqlInfo(zone, year);
|
||||
//循环查询的数据分别加入到不同的集合中作为中质量和高质量的循环次数
|
||||
for (VegetationHealth vegetationHealth : vegetationHealths) {
|
||||
String productCode1 = vegetationHealth.getProductCode1();
|
||||
if(productCode1.startsWith("M"))
|
||||
@ -637,6 +643,8 @@ public class DateUploadController
|
||||
List<PlantingSuitability> plantingSuitabilities = plantingSuitabilityService.sqlSeeding(zone);
|
||||
for (PlantingSuitability suitability : plantingSuitabilities) {
|
||||
BarChart.createFirstLevelTopic(docxDocument,"4.Results of remote sensing monitoring of planting suitability");
|
||||
//获取图片的url
|
||||
String productCode1 = suitability.getProductCode1();
|
||||
//第四个标题的内容
|
||||
BarChart.insertPic(docxDocument,"C:\\Users\\xkrs\\Desktop\\pic\\1.png");
|
||||
BarChart.setPicTitle(docxDocument,"Spatial distribution data of planting suitability");
|
||||
@ -647,7 +655,7 @@ public class DateUploadController
|
||||
Double s3 = suitability.getNotSuitable();
|
||||
Double[] yAxisData2 = new Double[]{s1, s2, s3};
|
||||
BarChart.drawTable(docxDocument,xAxisData2,yAxisData2);
|
||||
BarChart.setPicTitle(docxDocument,"Spatial distribution data of planting suitability");
|
||||
BarChart.setPicTitle(docxDocument,"Classification statistics of planting suitability");
|
||||
BarChart.createParagraphAndInsertWord(docxDocument,"In "+suitability.getZone()+" region, the area of very suitable region was "+suitability.getVerySuitable()+" hm², accounting for "+BarChart.getDoubleNumber((suitability.getVerySuitable()/suitability.getTotalArea())*100)+"%. The area of suitable grade was "+suitability.getSuitable()+" hm², accounting for "+BarChart.getDoubleNumber((suitability.getSuitable()/suitability.getTotalArea())*100)+"%. The area of unsuitable area was "+suitability.getNotSuitable()+" hm², accounting for "+BarChart.getDoubleNumber((suitability.getNotSuitable()/suitability.getTotalArea())*100)+"%.");
|
||||
}
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
|
@ -1,199 +0,0 @@
|
||||
package com.ruoyi.web.controller.shate;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.ruoyi.common.utils.chartForWord.CustomXWPFDocument;
|
||||
import com.ruoyi.common.utils.chartForWord.ExportUtils;
|
||||
import com.ruoyi.common.utils.chartForWord.PoiChartsTools;
|
||||
import com.ruoyi.common.utils.chartForWord.PoiWordUtil;
|
||||
import com.ruoyi.system.service_shate.impl.DateUploadServiceImpl;
|
||||
import org.apache.poi.ooxml.POIXMLDocumentPart;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFTable;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 操作word
|
||||
* @author shuaihua zang
|
||||
* http://localhost:9080/poi/barCharts
|
||||
*/
|
||||
@RestController
|
||||
public class PoiController {
|
||||
|
||||
|
||||
|
||||
@GetMapping("/poi/barCharts")
|
||||
public void barCharts(HttpServletResponse response) {
|
||||
|
||||
|
||||
|
||||
try (InputStream is = this.getClass().getClassLoader()
|
||||
.getResourceAsStream("V3.0.docx");
|
||||
ServletOutputStream out = response.getOutputStream()) {
|
||||
if (is == null) {
|
||||
throw new RuntimeException("未找到模板信息");
|
||||
}
|
||||
//XWPFDocument doc = new XWPFDocument(is);
|
||||
CustomXWPFDocument doc = new CustomXWPFDocument(is);
|
||||
this.doBarCharts(PoiChartsTools.getPOIXMLDocumentPart(doc,
|
||||
"/word/charts/chart1.xml"));
|
||||
this.doBarCharts(PoiChartsTools.getPOIXMLDocumentPart(doc,
|
||||
"/word/charts/chart2.xml"));
|
||||
this.doBarCharts(PoiChartsTools.getPOIXMLDocumentPart(doc,
|
||||
"/word/charts/chart3.xml"));
|
||||
ExportUtils exportUtils=new ExportUtils();
|
||||
exportUtils.insertImage(doc);
|
||||
exportUtils.insertText(doc);
|
||||
|
||||
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("application/msword");
|
||||
//response.setContentType("application/octet-stream");
|
||||
//String filename = "test.docx";
|
||||
//response.setHeader("Content-disposition", "attachment;filename="
|
||||
//+ URLEncoder.encode(filename, "UTF-8"));
|
||||
//doc.write(out);
|
||||
//out.flush();
|
||||
String fileName = "Evaluation report of planting monitoring in ITBA Nature Reserve - V3.0.docx";
|
||||
response.setHeader("Content-Disposition", "attachment;fileName=" + new String(fileName.getBytes("UTF-8"), "ISO-8859-1"));
|
||||
ServletOutputStream responseOutputStream = response.getOutputStream();
|
||||
doc.write(responseOutputStream);
|
||||
responseOutputStream.flush();
|
||||
responseOutputStream.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理图表数据-柱状图
|
||||
*/
|
||||
public void doBarCharts(POIXMLDocumentPart chart1) {
|
||||
/*// 行 标题
|
||||
List<String> titleArr = CollUtil.newArrayList(" ", "Health","Normal","Not-Health");
|
||||
// 字段名
|
||||
List<String> fldNameArr = CollUtil.newArrayList("item1", "item2","item3","item4");
|
||||
// 数据集合
|
||||
List<Map<String, String>> listItemsByType = new ArrayList<Map<String, String>>();
|
||||
Map<String, String> base1 = new HashMap<>(4);
|
||||
base1.put("item1", " " );
|
||||
base1.put("item2", "1000");
|
||||
base1.put("item3", "700");
|
||||
base1.put("item4", "1200" );
|
||||
listItemsByType.add(base1);*/
|
||||
// 行 标题
|
||||
List<String> titleArr = CollUtil.newArrayList(" ", "date");
|
||||
// 字段名
|
||||
List<String> fldNameArr = CollUtil.newArrayList("item1", "item2");
|
||||
// 数据集合
|
||||
List<Map<String, String>> listItemsByType = new ArrayList<Map<String, String>>();
|
||||
for(int i=0;i<3;i++)
|
||||
{
|
||||
if(i==0)
|
||||
{
|
||||
Map<String, String> base1 = new HashMap<>(2);
|
||||
base1.put("item1", "Health" );
|
||||
base1.put("item2", "100");
|
||||
listItemsByType.add(base1);
|
||||
}
|
||||
if(i==1)
|
||||
{
|
||||
Map<String, String> base1 = new HashMap<>(2);
|
||||
base1.put("item1", "Normal" );
|
||||
base1.put("item2", "300");
|
||||
listItemsByType.add(base1);
|
||||
}
|
||||
if(i==2)
|
||||
{
|
||||
Map<String, String> base1 = new HashMap<>(2);
|
||||
base1.put("item1", "Not-Health" );
|
||||
base1.put("item2", "500");
|
||||
listItemsByType.add(base1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
PoiChartsTools.replaceBarCharts(chart1, titleArr, fldNameArr, listItemsByType);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理图表数据-折线图
|
||||
*/
|
||||
private void doLineChart(POIXMLDocumentPart chart) {
|
||||
// 行 标题
|
||||
List<String> titleArr = CollUtil.newArrayList("类别", "系列1", "系列2", "系列3");
|
||||
// 字段名
|
||||
List<String> fldNameArr = CollUtil.newArrayList("item1", "item2", "item3", "item4");
|
||||
// 数据集合
|
||||
List<Map<String, String>> listItemsByType = new ArrayList<Map<String, String>>();
|
||||
for (int i = 1; i < 5; i++) {
|
||||
Map<String, String> base1 = new HashMap<>(4);
|
||||
base1.put("item1", "折线图" + i);
|
||||
base1.put("item2", "100");
|
||||
base1.put("item3", "20");
|
||||
base1.put("item4", "3");
|
||||
listItemsByType.add(base1);
|
||||
}
|
||||
PoiChartsTools.replaceLineCharts(chart, titleArr, fldNameArr, listItemsByType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理图表数据-饼图
|
||||
*/
|
||||
private void doPieCharts(POIXMLDocumentPart chart) {
|
||||
// 行 标题
|
||||
List<String> titleArr = CollUtil.newArrayList("类别", "系列1", "系列2", "系列3");
|
||||
// 字段名
|
||||
List<String> fldNameArr = CollUtil.newArrayList("item1", "item2", "item3", "item4");
|
||||
// 数据集合
|
||||
List<Map<String, String>> listItemsByType = new ArrayList<Map<String, String>>();
|
||||
for (int i = 1; i < 5; i++) {
|
||||
Map<String, String> base1 = new HashMap<>(4);
|
||||
base1.put("item1", "饼图" + i);
|
||||
base1.put("item2", "100");
|
||||
base1.put("item3", "20");
|
||||
base1.put("item4", "3");
|
||||
listItemsByType.add(base1);
|
||||
}
|
||||
PoiChartsTools.replacePieCharts(chart, titleArr, fldNameArr, listItemsByType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理表格-新增行
|
||||
*/
|
||||
private void insertTable(XWPFTable table) {
|
||||
List<List<String[]>> tableList = new ArrayList<>();
|
||||
List<String[]> table1 = new ArrayList<>();
|
||||
table1.add(new String[]{"1", "张三", "男", "22", "186xxxxxxxx"});
|
||||
table1.add(new String[]{"2", "李四", "女", "23", "187xxxxxxxx"});
|
||||
table1.add(new String[]{"3", "王五", "男", "24", "188xxxxxxxx"});
|
||||
table1.add(new String[]{"4", "赵六", "女", "25", "189xxxxxxxx"});
|
||||
tableList.add(table1);
|
||||
PoiWordUtil.insertTable(table, table1, 2);
|
||||
PoiWordUtil.mergeCellsHorizontal(table, 0, 0, 1);
|
||||
PoiWordUtil.mergeCellsHorizontal(table, 0, 3, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理表格-替换表格中信息
|
||||
*/
|
||||
private void replaceTable(XWPFTable table) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("name", "XXXWord");
|
||||
params.put("start", "2021-04-21");
|
||||
params.put("end", "2021-04-28");
|
||||
PoiWordUtil.replaceTableParams(table, params);
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user