From 42826c84c2c1fca13cf45490cc1bee873b05fee6 Mon Sep 17 00:00:00 2001 From: zhousq Date: Thu, 8 Feb 2024 11:21:50 +0800 Subject: [PATCH] =?UTF-8?q?2024-02-08=20IOT=E7=9A=84=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BB=9F=E8=AE=A1=E6=8E=A5=E5=8F=A3bug?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=92=8C=E5=8A=9F=E8=83=BD=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DcBusiHisReportController.java | 74 +++++-------------- .../bi/domain/LogTimeThreeQueryParamVo.java | 8 +- .../bi/domain/LogTimescaleHistoryThreeVo.java | 6 +- .../mapper/LogTimeScaleThreeMapper.xml | 5 +- 4 files changed, 31 insertions(+), 62 deletions(-) diff --git a/lzbi-module/src/main/java/com/lzbi/bi/controller/DcBusiHisReportController.java b/lzbi-module/src/main/java/com/lzbi/bi/controller/DcBusiHisReportController.java index 2440855..ca1d362 100644 --- a/lzbi-module/src/main/java/com/lzbi/bi/controller/DcBusiHisReportController.java +++ b/lzbi-module/src/main/java/com/lzbi/bi/controller/DcBusiHisReportController.java @@ -63,7 +63,7 @@ public class DcBusiHisReportController extends BaseController { JSONObject tableColum = new JSONObject(); tableColum.put("field", "totalTime"); tableColum.put("title", "统计时间"); - tableColum.put("width", 100); + tableColum.put("width", 160); tableColumns.add(tableColum); List tableDatas = new ArrayList(); DcDymicHeaderQueryVo dcDymicHeaderQueryVo = new DcDymicHeaderQueryVo(); @@ -80,15 +80,15 @@ public class DcBusiHisReportController extends BaseController { JSONObject ct = new JSONObject(); ct.put("field", "C"+dcDymicReportHeaderVo.getColCode()); ct.put("title", dcDymicReportHeaderVo.getColName1() + "[" + dcDymicReportHeaderVo.getColName2() + "]"); - ct.put("width", 80); + ct.put("width", 200); columnMap.put(dcDymicReportHeaderVo.getColCode(), dcDymicReportHeaderVo.getParamCode()); tableColumns.add(ct); }); - Map> data = list.stream().sorted(Comparator.comparing((LogTimescaleHistoryThreeVo::getTimestampKey))).collect(Collectors.groupingBy(LogTimescaleHistoryThreeVo::getTimestampKey)); + Map> data = list.stream().collect(Collectors.groupingBy(LogTimescaleHistoryThreeVo::getTimeStampString)); //生成talbecolum { field: 'id', title: 'ID', width: 80, fixed: 'left' }, //生成tabledata //PageInfo pageInfo=new PageInfo(pageNum,pageSize); - data.entrySet().stream().forEach(entry -> { + data.entrySet().stream().sorted(Map.Entry.comparingByKey()).forEach(entry -> { JSONObject jdata = new JSONObject(); jdata.put("totalTime", entry.getKey()); 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); }); - Map> data = list.stream().sorted(Comparator.comparing((LogTimescaleHistoryThreeVo::getTimestampKey))).collect(Collectors.groupingBy(LogTimescaleHistoryThreeVo::getTimestampKey)); + Map> data = list.stream().collect(Collectors.groupingBy(LogTimescaleHistoryThreeVo::getTimestampKey)); data.entrySet().stream().forEach(entry -> { JSONObject tc = new JSONObject(); tc.put("field", entry.getKey().toString()); @@ -154,7 +154,7 @@ public class DcBusiHisReportController extends BaseController { tableColumns.add(tc); }); Map> 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 -> { JSONObject jsonObject = columnMap.get(vo.getDeviceUuid() + "_" + vo.getParamCode()); if(StringUtils.isNotNull(jsonObject)){ @@ -183,10 +183,10 @@ public class DcBusiHisReportController extends BaseController { } ///按时间 设备+参数 形成数据--时间分组 private List> getMapList(List list, List dcDymicReportHeaderVos) { - Map> collect = list.stream().sorted(Comparator.comparing(LogTimescaleHistoryThreeVo::getTimestampKey)).collect(Collectors.groupingBy(LogTimescaleHistoryThreeVo::getTimestampKey)); - return collect.entrySet().stream().map(entry -> { + Map> collect = list.stream().collect(Collectors.groupingBy(LogTimescaleHistoryThreeVo::getTimeStampString)); + return collect.entrySet().stream().sorted(Map.Entry.comparingByKey()).map(entry -> { Map 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 -> { String key=vo.getDeviceUuid() + "_" + vo.getParamCode(); Optional first = dcDymicReportHeaderVos.stream().filter(vos -> vos.getColCode().equals(key)).findFirst(); @@ -200,63 +200,36 @@ public class DcBusiHisReportController extends BaseController { } /// 设备+参数 形成数据--设备-参数分组 private List> getMapListDevice(List list,List dcDymicReportHeaderVos) { - Map> collect = list.stream().sorted(Comparator.comparing(LogTimescaleHistoryThreeVo::getDeviceUuid)).collect(Collectors.groupingBy(LogTimescaleHistoryThreeVo::getDeviceUuid)); + Map> collect = list.stream().collect(Collectors.groupingBy(item->item.getDeviceUuid()+"_"+item.getParamCode())); List> collect1 = collect.entrySet().stream().map(entry -> { Map 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(); Optional first = dcDymicReportHeaderVos.stream().filter(vos -> vos.getColCode().equals(key)).findFirst(); if (first.isPresent()) { map.put("设备名称", first.get().getColName1()); 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; }).collect(Collectors.toList()); return collect1; } - //获取excel表头格式1 - private List> getMapListHeader(List dcDymicReportHeaderVos) { - //初始化map 获取字段的名称 根据 - Map> collect = dcDymicReportHeaderVos.stream().collect(Collectors.groupingBy(DcDymicReportHeaderVo::getColName1)); - List> headerList = dcDymicReportHeaderVos.stream().sorted(Comparator.comparing(DcDymicReportHeaderVo::getDeviceUUID).thenComparing(DcDymicReportHeaderVo::getParamCode).thenComparing(DcDymicReportHeaderVo::getPartion)).map(entry -> { - Map 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> getMapListHeaderString(DcDymicHeaderQueryVo dcDymicHeaderQueryVo) { - List lists = new ArrayList<>(); - List dcDymicReportHeaderVos = logTimesacleHistoryThreeService.selectHeaderInfo(dcDymicHeaderQueryVo); - //初始化map 获取字段的名称 根据 - List headerList = dcDymicReportHeaderVos.stream().sorted(Comparator.comparing(DcDymicReportHeaderVo::getColCode)).map(DcDymicReportHeaderVo::getColName2 - ).collect(Collectors.toList()); - //设置表字表头的时间类型 - headerList.add(0, "统计时间"); - List> ret = new ArrayList<>(); - ret.add(headerList); - return ret; - } /** * "生产设备参数统计明细表导出功能 */ @ApiOperation("生产设备参数统计明细表导出功能--时间纵向") - @PostMapping("/export") - public void export(HttpServletResponse response, @RequestBody LogTimeThreeQueryParamVo queryVo) throws IOException { + @PostMapping ("/export") + public void export(HttpServletResponse response, LogTimeThreeQueryParamVo queryVo) throws IOException { List> mapList=getExcellData(queryVo,2); toExcel(response,mapList); } @ApiOperation("生产设备参数统计明细表导出功能-时间横向") @PostMapping("/export2") - public void export2(HttpServletResponse response, @RequestBody LogTimeThreeQueryParamVo queryVo) throws IOException { - List> mapList=getExcellData(queryVo,2); + public void export2(HttpServletResponse response, LogTimeThreeQueryParamVo queryVo) throws IOException { + List> mapList=getExcellData(queryVo,1); // 通过工具类创建writer,默认创建xls格式 toExcel(response,mapList); @@ -281,21 +254,12 @@ public class DcBusiHisReportController extends BaseController { private void toExcel(HttpServletResponse response,List> mapList) throws IOException { String fileName ="report"+DateUtil.now() + ".xls"; - //response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); - //response.setCharacterEncoding("utf-8"); + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); ExcelWriter writer = ExcelUtil.getWriter(); - // 一次性写出内容,使用默认样式,强制输出标题 - //writer.write(mapList, true); - - //List> mapListHeader = getMapListHeader(dcDymicReportHeaderVos); - //writer.writeHeadRow(mapListHeader); writer.write(mapList, true); - //out为OutputStream,需要写出到的目标流 - - //response为HttpServletResponse对象 - response.setContentType("application/vnd.ms-excel;charset=utf-8"); //test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码 - response.setHeader("Content-Disposition", "attachment;filename="+fileName); + //response.setHeader("Content-Disposition", "attachment;filename="+fileName); ServletOutputStream out = response.getOutputStream(); writer.flush(out, true); // 关闭writer,释放内存 diff --git a/lzbi-module/src/main/java/com/lzbi/bi/domain/LogTimeThreeQueryParamVo.java b/lzbi-module/src/main/java/com/lzbi/bi/domain/LogTimeThreeQueryParamVo.java index bef6453..380269b 100644 --- a/lzbi-module/src/main/java/com/lzbi/bi/domain/LogTimeThreeQueryParamVo.java +++ b/lzbi-module/src/main/java/com/lzbi/bi/domain/LogTimeThreeQueryParamVo.java @@ -33,12 +33,12 @@ public class LogTimeThreeQueryParamVo { /** 参数模版列表 */ @ApiModelProperty(name = "参数模版列表",notes = "") private List queryParamClass ; - private Integer pageNum; - private Integer pageSize; + //private Integer pageNum; + // private Integer pageSize; public String getBeginTime() { - return beginTime+" 00:00:00"; + return this.beginTime+" 00:00:00"; } public String getEndTime() { - return endTime+" 23:59:59"; + return this.endTime+" 23:59:59"; } } diff --git a/lzbi-module/src/main/java/com/lzbi/bi/domain/LogTimescaleHistoryThreeVo.java b/lzbi-module/src/main/java/com/lzbi/bi/domain/LogTimescaleHistoryThreeVo.java index e0a740c..19baab0 100644 --- a/lzbi-module/src/main/java/com/lzbi/bi/domain/LogTimescaleHistoryThreeVo.java +++ b/lzbi-module/src/main/java/com/lzbi/bi/domain/LogTimescaleHistoryThreeVo.java @@ -8,6 +8,7 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import java.sql.Date; import java.sql.Timestamp; @Data @@ -19,7 +20,7 @@ import java.sql.Timestamp; public class LogTimescaleHistoryThreeVo { /** 时间戳 */ @ApiModelProperty(name = "时间戳",notes = "") - private Timestamp timestampKey; + private Date timestampKey; /** 中台设备UUID */ @ApiModelProperty(name = "中台设备UUID",notes = "") private String deviceUuid ; @@ -39,7 +40,8 @@ public class LogTimescaleHistoryThreeVo { private String logSrctag ; @ApiModelProperty(name = "数值来源的时间tingsboard ts ;ioserver t",notes = "") private String logSrctype ; - + @ApiModelProperty(name = "时间戳-字符串",notes = "") + private String timeStampString; } \ No newline at end of file diff --git a/lzbi-module/src/main/resources/mapper/LogTimeScaleThreeMapper.xml b/lzbi-module/src/main/resources/mapper/LogTimeScaleThreeMapper.xml index a63425a..39cfcc2 100644 --- a/lzbi-module/src/main/resources/mapper/LogTimeScaleThreeMapper.xml +++ b/lzbi-module/src/main/resources/mapper/LogTimeScaleThreeMapper.xml @@ -13,6 +13,8 @@ + + @@ -30,7 +32,8 @@