统计分析导出Excel并生成折线图;
This commit is contained in:
parent
cfdb86e037
commit
91efa06892
@ -28,7 +28,6 @@ public class StatisticalAnalysisController {
|
||||
/**
|
||||
* 趋势分析Excel导出
|
||||
* @param param 查询条件
|
||||
* @return TD数据库数据
|
||||
*/
|
||||
@PostMapping("/trendAnalyseExport")
|
||||
public void trendAnalyseExport(@RequestBody List<TrendAnalyseDto> param ,HttpServletRequest request, HttpServletResponse response) {
|
||||
@ -38,7 +37,6 @@ public class StatisticalAnalysisController {
|
||||
/**
|
||||
* 功率曲线Excel导出
|
||||
* @param param 查询条件
|
||||
* @return TD数据库数据
|
||||
*/
|
||||
@PostMapping("/powerCurveExport")
|
||||
public void powerCurveExport(@RequestBody TrendAnalyseDto param ,HttpServletRequest request, HttpServletResponse response) {
|
||||
@ -49,7 +47,6 @@ public class StatisticalAnalysisController {
|
||||
/**
|
||||
* 趋势对比Excel导出
|
||||
* @param param 查询条件
|
||||
* @return TD数据库数据
|
||||
*/
|
||||
@PostMapping("/trendContrastExport")
|
||||
public void trendContrastExport(@RequestBody TrendContrastDto param , HttpServletRequest request, HttpServletResponse response) {
|
||||
|
@ -62,7 +62,7 @@ public class StatisticalAnalysisServiceImpl implements StatisticalAnalysisServic
|
||||
@Autowired
|
||||
private SysIotModelFieldMapper sysIotModelFieldMapper;
|
||||
|
||||
private SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
|
||||
private final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
|
||||
|
||||
/**
|
||||
* 趋势分析Excel导出
|
||||
@ -217,8 +217,7 @@ public class StatisticalAnalysisServiceImpl implements StatisticalAnalysisServic
|
||||
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, Object>> mapEntry : stringMapEntry.getValue().entrySet()) {
|
||||
String key = mapEntry.getKey();
|
||||
pointName = key;
|
||||
pointName = mapEntry.getKey();
|
||||
for (Map.Entry<String, Object> stringObjectEntry : mapEntry.getValue().entrySet()) {
|
||||
String key1 = stringObjectEntry.getKey();
|
||||
if (key1.equals("times")) {
|
||||
@ -226,7 +225,7 @@ public class StatisticalAnalysisServiceImpl implements StatisticalAnalysisServic
|
||||
List<String> liststr = times.stream()
|
||||
.map(timestamp -> new Date(timestamp))
|
||||
.map(date -> sdf.format(date))
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
timesListstr.addAll(liststr);
|
||||
}
|
||||
if (key1.equals("values")) {
|
||||
@ -262,9 +261,9 @@ public class StatisticalAnalysisServiceImpl implements StatisticalAnalysisServic
|
||||
/**
|
||||
* 趋势对比填充Excel数据集
|
||||
*
|
||||
* @param dataList
|
||||
* @param map
|
||||
* @param dataset
|
||||
* @param dataList Excel数据集
|
||||
* @param map 表格的列
|
||||
* @param dataset Excel数据集
|
||||
*/
|
||||
private void setTrendContrastExcelValue(Map<String, Map<String, Map<String, Object>>> maps,
|
||||
List<Map<String, Object>> dataList,
|
||||
@ -282,7 +281,7 @@ public class StatisticalAnalysisServiceImpl implements StatisticalAnalysisServic
|
||||
List<String> liststr = times.stream()
|
||||
.map(timestamp -> new Date(timestamp))
|
||||
.map(date -> sdf.format(date))
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
timesListstr.addAll(liststr);
|
||||
}
|
||||
if (key1.equals("values")) {
|
||||
@ -348,9 +347,7 @@ public class StatisticalAnalysisServiceImpl implements StatisticalAnalysisServic
|
||||
map.put("time", "时间");
|
||||
List<String> strList = new ArrayList<>();
|
||||
for (SnapshotValueQueryParam device : param.getDevices()) {
|
||||
for (String attribute : device.getAttributes()) {
|
||||
strList.add(attribute);
|
||||
}
|
||||
strList.addAll(device.getAttributes());
|
||||
}
|
||||
QueryWrapper<SysIotModelField> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("attribute_code", strList);
|
||||
@ -399,7 +396,7 @@ public class StatisticalAnalysisServiceImpl implements StatisticalAnalysisServic
|
||||
List<String> liststr = times.stream()
|
||||
.map(timestamp -> new Date(timestamp))
|
||||
.map(date -> sdf.format(date))
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
timesListstr.addAll(liststr);
|
||||
}
|
||||
if (key1.equals("values")) {
|
||||
@ -459,8 +456,8 @@ public class StatisticalAnalysisServiceImpl implements StatisticalAnalysisServic
|
||||
/**
|
||||
* 下载Excel
|
||||
*
|
||||
* @param response
|
||||
* @param writer
|
||||
* @param response 响应对象
|
||||
* @param writer Excel对象
|
||||
*/
|
||||
private void downloadExcel(HttpServletResponse response, ExcelWriter writer,String title) {
|
||||
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("Pragma", "no-cache");
|
||||
response.setDateHeader("Expires", 0);
|
||||
ServletOutputStream out = null;
|
||||
try {
|
||||
// 设置请求头属性
|
||||
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,释放内存
|
||||
@ -546,20 +542,16 @@ public class StatisticalAnalysisServiceImpl implements StatisticalAnalysisServic
|
||||
int height = 400;
|
||||
try {
|
||||
ChartUtils.saveChartAsPNG(new File(chartFilePath), chart, width, height);
|
||||
} catch (IOException e) {
|
||||
throw new ServiceException("图表保存为PNG文件失败==" + e);
|
||||
}
|
||||
byte[] bytes = null;
|
||||
try {
|
||||
bytes = java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(chartFilePath));
|
||||
byte[] bytes = java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(chartFilePath));
|
||||
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);
|
||||
} catch (IOException 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