统计分析导出Excel并生成折线图;
This commit is contained in:
parent
cfdb86e037
commit
91efa06892
@ -28,7 +28,6 @@ public class StatisticalAnalysisController {
|
|||||||
/**
|
/**
|
||||||
* 趋势分析Excel导出
|
* 趋势分析Excel导出
|
||||||
* @param param 查询条件
|
* @param param 查询条件
|
||||||
* @return TD数据库数据
|
|
||||||
*/
|
*/
|
||||||
@PostMapping("/trendAnalyseExport")
|
@PostMapping("/trendAnalyseExport")
|
||||||
public void trendAnalyseExport(@RequestBody List<TrendAnalyseDto> param ,HttpServletRequest request, HttpServletResponse response) {
|
public void trendAnalyseExport(@RequestBody List<TrendAnalyseDto> param ,HttpServletRequest request, HttpServletResponse response) {
|
||||||
@ -38,7 +37,6 @@ public class StatisticalAnalysisController {
|
|||||||
/**
|
/**
|
||||||
* 功率曲线Excel导出
|
* 功率曲线Excel导出
|
||||||
* @param param 查询条件
|
* @param param 查询条件
|
||||||
* @return TD数据库数据
|
|
||||||
*/
|
*/
|
||||||
@PostMapping("/powerCurveExport")
|
@PostMapping("/powerCurveExport")
|
||||||
public void powerCurveExport(@RequestBody TrendAnalyseDto param ,HttpServletRequest request, HttpServletResponse response) {
|
public void powerCurveExport(@RequestBody TrendAnalyseDto param ,HttpServletRequest request, HttpServletResponse response) {
|
||||||
@ -49,7 +47,6 @@ public class StatisticalAnalysisController {
|
|||||||
/**
|
/**
|
||||||
* 趋势对比Excel导出
|
* 趋势对比Excel导出
|
||||||
* @param param 查询条件
|
* @param param 查询条件
|
||||||
* @return TD数据库数据
|
|
||||||
*/
|
*/
|
||||||
@PostMapping("/trendContrastExport")
|
@PostMapping("/trendContrastExport")
|
||||||
public void trendContrastExport(@RequestBody TrendContrastDto param , HttpServletRequest request, HttpServletResponse response) {
|
public void trendContrastExport(@RequestBody TrendContrastDto param , HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
@ -62,7 +62,7 @@ public class StatisticalAnalysisServiceImpl implements StatisticalAnalysisServic
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SysIotModelFieldMapper sysIotModelFieldMapper;
|
private SysIotModelFieldMapper sysIotModelFieldMapper;
|
||||||
|
|
||||||
private SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
|
private final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 趋势分析Excel导出
|
* 趋势分析Excel导出
|
||||||
@ -217,8 +217,7 @@ public class StatisticalAnalysisServiceImpl implements StatisticalAnalysisServic
|
|||||||
Map<String, Map<String, Map<String, Object>>> stringMapMap = mapsList.get(i);
|
Map<String, Map<String, Map<String, Object>>> stringMapMap = mapsList.get(i);
|
||||||
for (Map.Entry<String, Map<String, Map<String, Object>>> stringMapEntry : stringMapMap.entrySet()) {
|
for (Map.Entry<String, Map<String, Map<String, Object>>> stringMapEntry : stringMapMap.entrySet()) {
|
||||||
for (Map.Entry<String, Map<String, Object>> mapEntry : stringMapEntry.getValue().entrySet()) {
|
for (Map.Entry<String, Map<String, Object>> mapEntry : stringMapEntry.getValue().entrySet()) {
|
||||||
String key = mapEntry.getKey();
|
pointName = mapEntry.getKey();
|
||||||
pointName = key;
|
|
||||||
for (Map.Entry<String, Object> stringObjectEntry : mapEntry.getValue().entrySet()) {
|
for (Map.Entry<String, Object> stringObjectEntry : mapEntry.getValue().entrySet()) {
|
||||||
String key1 = stringObjectEntry.getKey();
|
String key1 = stringObjectEntry.getKey();
|
||||||
if (key1.equals("times")) {
|
if (key1.equals("times")) {
|
||||||
@ -226,7 +225,7 @@ public class StatisticalAnalysisServiceImpl implements StatisticalAnalysisServic
|
|||||||
List<String> liststr = times.stream()
|
List<String> liststr = times.stream()
|
||||||
.map(timestamp -> new Date(timestamp))
|
.map(timestamp -> new Date(timestamp))
|
||||||
.map(date -> sdf.format(date))
|
.map(date -> sdf.format(date))
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
timesListstr.addAll(liststr);
|
timesListstr.addAll(liststr);
|
||||||
}
|
}
|
||||||
if (key1.equals("values")) {
|
if (key1.equals("values")) {
|
||||||
@ -262,9 +261,9 @@ public class StatisticalAnalysisServiceImpl implements StatisticalAnalysisServic
|
|||||||
/**
|
/**
|
||||||
* 趋势对比填充Excel数据集
|
* 趋势对比填充Excel数据集
|
||||||
*
|
*
|
||||||
* @param dataList
|
* @param dataList Excel数据集
|
||||||
* @param map
|
* @param map 表格的列
|
||||||
* @param dataset
|
* @param dataset Excel数据集
|
||||||
*/
|
*/
|
||||||
private void setTrendContrastExcelValue(Map<String, Map<String, Map<String, Object>>> maps,
|
private void setTrendContrastExcelValue(Map<String, Map<String, Map<String, Object>>> maps,
|
||||||
List<Map<String, Object>> dataList,
|
List<Map<String, Object>> dataList,
|
||||||
@ -282,7 +281,7 @@ public class StatisticalAnalysisServiceImpl implements StatisticalAnalysisServic
|
|||||||
List<String> liststr = times.stream()
|
List<String> liststr = times.stream()
|
||||||
.map(timestamp -> new Date(timestamp))
|
.map(timestamp -> new Date(timestamp))
|
||||||
.map(date -> sdf.format(date))
|
.map(date -> sdf.format(date))
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
timesListstr.addAll(liststr);
|
timesListstr.addAll(liststr);
|
||||||
}
|
}
|
||||||
if (key1.equals("values")) {
|
if (key1.equals("values")) {
|
||||||
@ -348,9 +347,7 @@ public class StatisticalAnalysisServiceImpl implements StatisticalAnalysisServic
|
|||||||
map.put("time", "时间");
|
map.put("time", "时间");
|
||||||
List<String> strList = new ArrayList<>();
|
List<String> strList = new ArrayList<>();
|
||||||
for (SnapshotValueQueryParam device : param.getDevices()) {
|
for (SnapshotValueQueryParam device : param.getDevices()) {
|
||||||
for (String attribute : device.getAttributes()) {
|
strList.addAll(device.getAttributes());
|
||||||
strList.add(attribute);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
QueryWrapper<SysIotModelField> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<SysIotModelField> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.in("attribute_code", strList);
|
queryWrapper.in("attribute_code", strList);
|
||||||
@ -399,7 +396,7 @@ public class StatisticalAnalysisServiceImpl implements StatisticalAnalysisServic
|
|||||||
List<String> liststr = times.stream()
|
List<String> liststr = times.stream()
|
||||||
.map(timestamp -> new Date(timestamp))
|
.map(timestamp -> new Date(timestamp))
|
||||||
.map(date -> sdf.format(date))
|
.map(date -> sdf.format(date))
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
timesListstr.addAll(liststr);
|
timesListstr.addAll(liststr);
|
||||||
}
|
}
|
||||||
if (key1.equals("values")) {
|
if (key1.equals("values")) {
|
||||||
@ -459,8 +456,8 @@ public class StatisticalAnalysisServiceImpl implements StatisticalAnalysisServic
|
|||||||
/**
|
/**
|
||||||
* 下载Excel
|
* 下载Excel
|
||||||
*
|
*
|
||||||
* @param response
|
* @param response 响应对象
|
||||||
* @param writer
|
* @param writer Excel对象
|
||||||
*/
|
*/
|
||||||
private void downloadExcel(HttpServletResponse response, ExcelWriter writer,String title) {
|
private void downloadExcel(HttpServletResponse response, ExcelWriter writer,String title) {
|
||||||
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
||||||
@ -469,11 +466,10 @@ public class StatisticalAnalysisServiceImpl implements StatisticalAnalysisServic
|
|||||||
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||||
response.setHeader("Pragma", "no-cache");
|
response.setHeader("Pragma", "no-cache");
|
||||||
response.setDateHeader("Expires", 0);
|
response.setDateHeader("Expires", 0);
|
||||||
ServletOutputStream out = null;
|
|
||||||
try {
|
try {
|
||||||
// 设置请求头属性
|
// 设置请求头属性
|
||||||
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(title+".xls", StandardCharsets.UTF_8));
|
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(title+".xls", StandardCharsets.UTF_8));
|
||||||
out = response.getOutputStream();
|
ServletOutputStream out = response.getOutputStream();
|
||||||
// 写出到文件
|
// 写出到文件
|
||||||
writer.flush(out, true);
|
writer.flush(out, true);
|
||||||
// 关闭writer,释放内存
|
// 关闭writer,释放内存
|
||||||
@ -546,20 +542,16 @@ public class StatisticalAnalysisServiceImpl implements StatisticalAnalysisServic
|
|||||||
int height = 400;
|
int height = 400;
|
||||||
try {
|
try {
|
||||||
ChartUtils.saveChartAsPNG(new File(chartFilePath), chart, width, height);
|
ChartUtils.saveChartAsPNG(new File(chartFilePath), chart, width, height);
|
||||||
} catch (IOException e) {
|
byte[] bytes = java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(chartFilePath));
|
||||||
throw new ServiceException("图表保存为PNG文件失败==" + e);
|
int pictureIdx = workbook.addPicture(bytes, Workbook.PICTURE_TYPE_PNG);
|
||||||
}
|
// 计算数据的最后一行,创建图表插入位置的锚点
|
||||||
byte[] bytes = null;
|
XSSFClientAnchor anchor = new XSSFClientAnchor(0, 1, 0, 1, 0, data.size() + 2, 15, data.size() + 30);
|
||||||
try {
|
XSSFDrawing drawing = xssfSheet.createDrawingPatriarch();
|
||||||
bytes = java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(chartFilePath));
|
drawing.createPicture(anchor, pictureIdx);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ServiceException("图表保存失败==" + e);
|
throw new ServiceException("图表保存失败==" + e);
|
||||||
}
|
}
|
||||||
int pictureIdx = workbook.addPicture(bytes, Workbook.PICTURE_TYPE_PNG);
|
|
||||||
// 计算数据的最后一行,创建图表插入位置的锚点
|
|
||||||
XSSFClientAnchor anchor = new XSSFClientAnchor(0, 1, 0, 1, 0, data.size() + 2, 15, data.size() + 30);
|
|
||||||
XSSFDrawing drawing = xssfSheet.createDrawingPatriarch();
|
|
||||||
drawing.createPicture(anchor, pictureIdx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user