|
@ -63,7 +63,7 @@ public class DcBusiHisReportController extends BaseController { |
|
|
JSONObject tableColum = new JSONObject(); |
|
|
JSONObject tableColum = new JSONObject(); |
|
|
tableColum.put("field", "totalTime"); |
|
|
tableColum.put("field", "totalTime"); |
|
|
tableColum.put("title", "统计时间"); |
|
|
tableColum.put("title", "统计时间"); |
|
|
tableColum.put("width", 100); |
|
|
tableColum.put("width", 160); |
|
|
tableColumns.add(tableColum); |
|
|
tableColumns.add(tableColum); |
|
|
List tableDatas = new ArrayList(); |
|
|
List tableDatas = new ArrayList(); |
|
|
DcDymicHeaderQueryVo dcDymicHeaderQueryVo = new DcDymicHeaderQueryVo(); |
|
|
DcDymicHeaderQueryVo dcDymicHeaderQueryVo = new DcDymicHeaderQueryVo(); |
|
@ -80,15 +80,15 @@ public class DcBusiHisReportController extends BaseController { |
|
|
JSONObject ct = new JSONObject(); |
|
|
JSONObject ct = new JSONObject(); |
|
|
ct.put("field", "C"+dcDymicReportHeaderVo.getColCode()); |
|
|
ct.put("field", "C"+dcDymicReportHeaderVo.getColCode()); |
|
|
ct.put("title", dcDymicReportHeaderVo.getColName1() + "[" + dcDymicReportHeaderVo.getColName2() + "]"); |
|
|
ct.put("title", dcDymicReportHeaderVo.getColName1() + "[" + dcDymicReportHeaderVo.getColName2() + "]"); |
|
|
ct.put("width", 80); |
|
|
ct.put("width", 200); |
|
|
columnMap.put(dcDymicReportHeaderVo.getColCode(), dcDymicReportHeaderVo.getParamCode()); |
|
|
columnMap.put(dcDymicReportHeaderVo.getColCode(), dcDymicReportHeaderVo.getParamCode()); |
|
|
tableColumns.add(ct); |
|
|
tableColumns.add(ct); |
|
|
}); |
|
|
}); |
|
|
Map<Timestamp, List<LogTimescaleHistoryThreeVo>> data = list.stream().sorted(Comparator.comparing((LogTimescaleHistoryThreeVo::getTimestampKey))).collect(Collectors.groupingBy(LogTimescaleHistoryThreeVo::getTimestampKey)); |
|
|
Map<String, List<LogTimescaleHistoryThreeVo>> data = list.stream().collect(Collectors.groupingBy(LogTimescaleHistoryThreeVo::getTimeStampString)); |
|
|
//生成talbecolum { field: 'id', title: 'ID', width: 80, fixed: 'left' },
|
|
|
//生成talbecolum { field: 'id', title: 'ID', width: 80, fixed: 'left' },
|
|
|
//生成tabledata
|
|
|
//生成tabledata
|
|
|
//PageInfo pageInfo=new PageInfo(pageNum,pageSize);
|
|
|
//PageInfo pageInfo=new PageInfo(pageNum,pageSize);
|
|
|
data.entrySet().stream().forEach(entry -> { |
|
|
data.entrySet().stream().sorted(Map.Entry.comparingByKey()).forEach(entry -> { |
|
|
JSONObject jdata = new JSONObject(); |
|
|
JSONObject jdata = new JSONObject(); |
|
|
jdata.put("totalTime", entry.getKey()); |
|
|
jdata.put("totalTime", entry.getKey()); |
|
|
entry.getValue().stream().sorted(Comparator.comparing(LogTimescaleHistoryThreeVo::getDeviceUuid).thenComparing(LogTimescaleHistoryThreeVo::getParamCode)) |
|
|
entry.getValue().stream().sorted(Comparator.comparing(LogTimescaleHistoryThreeVo::getDeviceUuid).thenComparing(LogTimescaleHistoryThreeVo::getParamCode)) |
|
@ -145,7 +145,7 @@ public class DcBusiHisReportController extends BaseController { |
|
|
columnMap.put(dcDymicReportHeaderVo.getColCode(), ct); |
|
|
columnMap.put(dcDymicReportHeaderVo.getColCode(), ct); |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
Map<Timestamp, List<LogTimescaleHistoryThreeVo>> data = list.stream().sorted(Comparator.comparing((LogTimescaleHistoryThreeVo::getTimestampKey))).collect(Collectors.groupingBy(LogTimescaleHistoryThreeVo::getTimestampKey)); |
|
|
Map<Date, List<LogTimescaleHistoryThreeVo>> data = list.stream().collect(Collectors.groupingBy(LogTimescaleHistoryThreeVo::getTimestampKey)); |
|
|
data.entrySet().stream().forEach(entry -> { |
|
|
data.entrySet().stream().forEach(entry -> { |
|
|
JSONObject tc = new JSONObject(); |
|
|
JSONObject tc = new JSONObject(); |
|
|
tc.put("field", entry.getKey().toString()); |
|
|
tc.put("field", entry.getKey().toString()); |
|
@ -154,7 +154,7 @@ public class DcBusiHisReportController extends BaseController { |
|
|
tableColumns.add(tc); |
|
|
tableColumns.add(tc); |
|
|
}); |
|
|
}); |
|
|
Map<String, List<LogTimescaleHistoryThreeVo>> data2 = list.stream().sorted(Comparator.comparing((LogTimescaleHistoryThreeVo::getDeviceUuid))).collect(Collectors.groupingBy(LogTimescaleHistoryThreeVo::getDeviceUuid)); |
|
|
Map<String, List<LogTimescaleHistoryThreeVo>> data2 = list.stream().sorted(Comparator.comparing((LogTimescaleHistoryThreeVo::getDeviceUuid))).collect(Collectors.groupingBy(LogTimescaleHistoryThreeVo::getDeviceUuid)); |
|
|
data2.entrySet().stream().forEach(entry -> { |
|
|
data2.entrySet().stream().sorted(Map.Entry.comparingByKey()).forEach(entry -> { |
|
|
entry.getValue().stream().sorted(Comparator.comparing(LogTimescaleHistoryThreeVo::getParamCode)).forEach(vo -> { |
|
|
entry.getValue().stream().sorted(Comparator.comparing(LogTimescaleHistoryThreeVo::getParamCode)).forEach(vo -> { |
|
|
JSONObject jsonObject = columnMap.get(vo.getDeviceUuid() + "_" + vo.getParamCode()); |
|
|
JSONObject jsonObject = columnMap.get(vo.getDeviceUuid() + "_" + vo.getParamCode()); |
|
|
if(StringUtils.isNotNull(jsonObject)){ |
|
|
if(StringUtils.isNotNull(jsonObject)){ |
|
@ -183,10 +183,10 @@ public class DcBusiHisReportController extends BaseController { |
|
|
} |
|
|
} |
|
|
///按时间 设备+参数 形成数据--时间分组
|
|
|
///按时间 设备+参数 形成数据--时间分组
|
|
|
private List<Map<String, Object>> getMapList(List<LogTimescaleHistoryThreeVo> list, List<DcDymicReportHeaderVo> dcDymicReportHeaderVos) { |
|
|
private List<Map<String, Object>> getMapList(List<LogTimescaleHistoryThreeVo> list, List<DcDymicReportHeaderVo> dcDymicReportHeaderVos) { |
|
|
Map<Timestamp, List<LogTimescaleHistoryThreeVo>> collect = list.stream().sorted(Comparator.comparing(LogTimescaleHistoryThreeVo::getTimestampKey)).collect(Collectors.groupingBy(LogTimescaleHistoryThreeVo::getTimestampKey)); |
|
|
Map<String, List<LogTimescaleHistoryThreeVo>> collect = list.stream().collect(Collectors.groupingBy(LogTimescaleHistoryThreeVo::getTimeStampString)); |
|
|
return collect.entrySet().stream().map(entry -> { |
|
|
return collect.entrySet().stream().sorted(Map.Entry.comparingByKey()).map(entry -> { |
|
|
Map<String, Object> map = new LinkedHashMap<>(); |
|
|
Map<String, Object> map = new LinkedHashMap<>(); |
|
|
map.put("统计时间", DateUtil.format(entry.getKey(), DatePattern.NORM_DATETIME_PATTERN)); |
|
|
map.put("统计时间",entry.getKey()); |
|
|
entry.getValue().stream().sorted(Comparator.comparing(LogTimescaleHistoryThreeVo::getDeviceUuid).thenComparing(LogTimescaleHistoryThreeVo::getParamCode)).forEach(vo -> { |
|
|
entry.getValue().stream().sorted(Comparator.comparing(LogTimescaleHistoryThreeVo::getDeviceUuid).thenComparing(LogTimescaleHistoryThreeVo::getParamCode)).forEach(vo -> { |
|
|
String key=vo.getDeviceUuid() + "_" + vo.getParamCode(); |
|
|
String key=vo.getDeviceUuid() + "_" + vo.getParamCode(); |
|
|
Optional<DcDymicReportHeaderVo> first = dcDymicReportHeaderVos.stream().filter(vos -> vos.getColCode().equals(key)).findFirst(); |
|
|
Optional<DcDymicReportHeaderVo> first = dcDymicReportHeaderVos.stream().filter(vos -> vos.getColCode().equals(key)).findFirst(); |
|
@ -200,63 +200,36 @@ public class DcBusiHisReportController extends BaseController { |
|
|
} |
|
|
} |
|
|
/// 设备+参数 形成数据--设备-参数分组
|
|
|
/// 设备+参数 形成数据--设备-参数分组
|
|
|
private List<Map<String, Object>> getMapListDevice(List<LogTimescaleHistoryThreeVo> list,List<DcDymicReportHeaderVo> dcDymicReportHeaderVos) { |
|
|
private List<Map<String, Object>> getMapListDevice(List<LogTimescaleHistoryThreeVo> list,List<DcDymicReportHeaderVo> dcDymicReportHeaderVos) { |
|
|
Map<String, List<LogTimescaleHistoryThreeVo>> collect = list.stream().sorted(Comparator.comparing(LogTimescaleHistoryThreeVo::getDeviceUuid)).collect(Collectors.groupingBy(LogTimescaleHistoryThreeVo::getDeviceUuid)); |
|
|
Map<String, List<LogTimescaleHistoryThreeVo>> collect = list.stream().collect(Collectors.groupingBy(item->item.getDeviceUuid()+"_"+item.getParamCode())); |
|
|
List<Map<String, Object>> collect1 = collect.entrySet().stream().map(entry -> { |
|
|
List<Map<String, Object>> collect1 = collect.entrySet().stream().map(entry -> { |
|
|
Map<String, Object> map = new LinkedHashMap<>(); |
|
|
Map<String, Object> map = new LinkedHashMap<>(); |
|
|
entry.getValue().stream().sorted(Comparator.comparing(LogTimescaleHistoryThreeVo::getTimestampKey)).forEach(vo -> { |
|
|
entry.getValue().stream().sorted(Comparator.comparing(LogTimescaleHistoryThreeVo::getTimestampKey).thenComparing(LogTimescaleHistoryThreeVo::getParamCode)).forEach(vo -> { |
|
|
String key = vo.getDeviceUuid() + "_" + vo.getParamCode(); |
|
|
String key = vo.getDeviceUuid() + "_" + vo.getParamCode(); |
|
|
Optional<DcDymicReportHeaderVo> first = dcDymicReportHeaderVos.stream().filter(vos -> vos.getColCode().equals(key)).findFirst(); |
|
|
Optional<DcDymicReportHeaderVo> first = dcDymicReportHeaderVos.stream().filter(vos -> vos.getColCode().equals(key)).findFirst(); |
|
|
if (first.isPresent()) { |
|
|
if (first.isPresent()) { |
|
|
map.put("设备名称", first.get().getColName1()); |
|
|
map.put("设备名称", first.get().getColName1()); |
|
|
map.put("参数名称", first.get().getColName2()); |
|
|
map.put("参数名称", first.get().getColName2()); |
|
|
map.put(DateUtil.format(vo.getTimestampKey(), DatePattern.NORM_DATETIME_PATTERN), vo.getParamValueNum()); |
|
|
map.put(vo.getTimeStampString(), vo.getParamValueNum()); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
return map; |
|
|
return map; |
|
|
}).collect(Collectors.toList()); |
|
|
}).collect(Collectors.toList()); |
|
|
return collect1; |
|
|
return collect1; |
|
|
} |
|
|
} |
|
|
//获取excel表头格式1
|
|
|
|
|
|
private List<Map<String, List>> getMapListHeader(List<DcDymicReportHeaderVo> dcDymicReportHeaderVos) { |
|
|
|
|
|
//初始化map 获取字段的名称 根据
|
|
|
|
|
|
Map<String, List<DcDymicReportHeaderVo>> collect = dcDymicReportHeaderVos.stream().collect(Collectors.groupingBy(DcDymicReportHeaderVo::getColName1)); |
|
|
|
|
|
List<Map<String, List>> headerList = dcDymicReportHeaderVos.stream().sorted(Comparator.comparing(DcDymicReportHeaderVo::getDeviceUUID).thenComparing(DcDymicReportHeaderVo::getParamCode).thenComparing(DcDymicReportHeaderVo::getPartion)).map(entry -> { |
|
|
|
|
|
Map<String, List> map = new LinkedHashMap<>(); |
|
|
|
|
|
map.put(entry.getColName1(), collect.get(entry.getColName1()).stream().map(DcDymicReportHeaderVo::getColName2).collect(Collectors.toList())); |
|
|
|
|
|
return map; |
|
|
|
|
|
} |
|
|
|
|
|
).collect(Collectors.toList()); |
|
|
|
|
|
//headerList.add(0,"统计时间");
|
|
|
|
|
|
return headerList; |
|
|
|
|
|
} |
|
|
|
|
|
//获取数据
|
|
|
|
|
|
|
|
|
|
|
|
private List<List<String>> getMapListHeaderString(DcDymicHeaderQueryVo dcDymicHeaderQueryVo) { |
|
|
|
|
|
List<String> lists = new ArrayList<>(); |
|
|
|
|
|
List<DcDymicReportHeaderVo> dcDymicReportHeaderVos = logTimesacleHistoryThreeService.selectHeaderInfo(dcDymicHeaderQueryVo); |
|
|
|
|
|
//初始化map 获取字段的名称 根据
|
|
|
|
|
|
List<String> headerList = dcDymicReportHeaderVos.stream().sorted(Comparator.comparing(DcDymicReportHeaderVo::getColCode)).map(DcDymicReportHeaderVo::getColName2 |
|
|
|
|
|
).collect(Collectors.toList()); |
|
|
|
|
|
//设置表字表头的时间类型
|
|
|
|
|
|
headerList.add(0, "统计时间"); |
|
|
|
|
|
List<List<String>> ret = new ArrayList<>(); |
|
|
|
|
|
ret.add(headerList); |
|
|
|
|
|
return ret; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* "生产设备参数统计明细表导出功能 |
|
|
* "生产设备参数统计明细表导出功能 |
|
|
*/ |
|
|
*/ |
|
|
@ApiOperation("生产设备参数统计明细表导出功能--时间纵向") |
|
|
@ApiOperation("生产设备参数统计明细表导出功能--时间纵向") |
|
|
@PostMapping ("/export") |
|
|
@PostMapping ("/export") |
|
|
public void export(HttpServletResponse response, @RequestBody LogTimeThreeQueryParamVo queryVo) throws IOException { |
|
|
public void export(HttpServletResponse response, LogTimeThreeQueryParamVo queryVo) throws IOException { |
|
|
List<Map<String, Object>> mapList=getExcellData(queryVo,2); |
|
|
List<Map<String, Object>> mapList=getExcellData(queryVo,2); |
|
|
toExcel(response,mapList); |
|
|
toExcel(response,mapList); |
|
|
} |
|
|
} |
|
|
@ApiOperation("生产设备参数统计明细表导出功能-时间横向") |
|
|
@ApiOperation("生产设备参数统计明细表导出功能-时间横向") |
|
|
@PostMapping("/export2") |
|
|
@PostMapping("/export2") |
|
|
public void export2(HttpServletResponse response, @RequestBody LogTimeThreeQueryParamVo queryVo) throws IOException { |
|
|
public void export2(HttpServletResponse response, LogTimeThreeQueryParamVo queryVo) throws IOException { |
|
|
List<Map<String, Object>> mapList=getExcellData(queryVo,2); |
|
|
List<Map<String, Object>> mapList=getExcellData(queryVo,1); |
|
|
// 通过工具类创建writer,默认创建xls格式
|
|
|
// 通过工具类创建writer,默认创建xls格式
|
|
|
toExcel(response,mapList); |
|
|
toExcel(response,mapList); |
|
|
|
|
|
|
|
@ -281,21 +254,12 @@ public class DcBusiHisReportController extends BaseController { |
|
|
|
|
|
|
|
|
private void toExcel(HttpServletResponse response,List<Map<String, Object>> mapList) throws IOException { |
|
|
private void toExcel(HttpServletResponse response,List<Map<String, Object>> mapList) throws IOException { |
|
|
String fileName ="report"+DateUtil.now() + ".xls"; |
|
|
String fileName ="report"+DateUtil.now() + ".xls"; |
|
|
//response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
|
|
//response.setCharacterEncoding("utf-8");
|
|
|
response.setCharacterEncoding("utf-8"); |
|
|
ExcelWriter writer = ExcelUtil.getWriter(); |
|
|
ExcelWriter writer = ExcelUtil.getWriter(); |
|
|
// 一次性写出内容,使用默认样式,强制输出标题
|
|
|
|
|
|
//writer.write(mapList, true);
|
|
|
|
|
|
|
|
|
|
|
|
//List<Map<String, List>> mapListHeader = getMapListHeader(dcDymicReportHeaderVos);
|
|
|
|
|
|
//writer.writeHeadRow(mapListHeader);
|
|
|
|
|
|
writer.write(mapList, true); |
|
|
writer.write(mapList, true); |
|
|
//out为OutputStream,需要写出到的目标流
|
|
|
|
|
|
|
|
|
|
|
|
//response为HttpServletResponse对象
|
|
|
|
|
|
response.setContentType("application/vnd.ms-excel;charset=utf-8"); |
|
|
|
|
|
//test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
|
|
|
//test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
|
|
|
response.setHeader("Content-Disposition", "attachment;filename="+fileName); |
|
|
//response.setHeader("Content-Disposition", "attachment;filename="+fileName);
|
|
|
ServletOutputStream out = response.getOutputStream(); |
|
|
ServletOutputStream out = response.getOutputStream(); |
|
|
writer.flush(out, true); |
|
|
writer.flush(out, true); |
|
|
// 关闭writer,释放内存
|
|
|
// 关闭writer,释放内存
|
|
|