Browse Source

2024-02-08 IOT的生产数据统计接口bug修复和功能完善

develop
zhousq 10 months ago
parent
commit
42826c84c2
  1. 72
      lzbi-module/src/main/java/com/lzbi/bi/controller/DcBusiHisReportController.java
  2. 8
      lzbi-module/src/main/java/com/lzbi/bi/domain/LogTimeThreeQueryParamVo.java
  3. 6
      lzbi-module/src/main/java/com/lzbi/bi/domain/LogTimescaleHistoryThreeVo.java
  4. 5
      lzbi-module/src/main/resources/mapper/LogTimeScaleThreeMapper.xml

72
lzbi-module/src/main/java/com/lzbi/bi/controller/DcBusiHisReportController.java

@ -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,释放内存

8
lzbi-module/src/main/java/com/lzbi/bi/domain/LogTimeThreeQueryParamVo.java

@ -33,12 +33,12 @@ public class LogTimeThreeQueryParamVo {
/** 参数模版列表 */ /** 参数模版列表 */
@ApiModelProperty(name = "参数模版列表",notes = "") @ApiModelProperty(name = "参数模版列表",notes = "")
private List<String> queryParamClass ; private List<String> queryParamClass ;
private Integer pageNum; //private Integer pageNum;
private Integer pageSize; // private Integer pageSize;
public String getBeginTime() { public String getBeginTime() {
return beginTime+" 00:00:00"; return this.beginTime+" 00:00:00";
} }
public String getEndTime() { public String getEndTime() {
return endTime+" 23:59:59"; return this.endTime+" 23:59:59";
} }
} }

6
lzbi-module/src/main/java/com/lzbi/bi/domain/LogTimescaleHistoryThreeVo.java

@ -8,6 +8,7 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.sql.Date;
import java.sql.Timestamp; import java.sql.Timestamp;
@Data @Data
@ -19,7 +20,7 @@ import java.sql.Timestamp;
public class LogTimescaleHistoryThreeVo { public class LogTimescaleHistoryThreeVo {
/** 时间戳 */ /** 时间戳 */
@ApiModelProperty(name = "时间戳",notes = "") @ApiModelProperty(name = "时间戳",notes = "")
private Timestamp timestampKey; private Date timestampKey;
/** 中台设备UUID */ /** 中台设备UUID */
@ApiModelProperty(name = "中台设备UUID",notes = "") @ApiModelProperty(name = "中台设备UUID",notes = "")
private String deviceUuid ; private String deviceUuid ;
@ -39,7 +40,8 @@ public class LogTimescaleHistoryThreeVo {
private String logSrctag ; private String logSrctag ;
@ApiModelProperty(name = "数值来源的时间tingsboard ts ;ioserver t",notes = "") @ApiModelProperty(name = "数值来源的时间tingsboard ts ;ioserver t",notes = "")
private String logSrctype ; private String logSrctype ;
@ApiModelProperty(name = "时间戳-字符串",notes = "")
private String timeStampString;
} }

5
lzbi-module/src/main/resources/mapper/LogTimeScaleThreeMapper.xml

@ -13,6 +13,8 @@
<result property="paramValueStr" column="param_value_str"/> <result property="paramValueStr" column="param_value_str"/>
<result property="logSrctag" column="log_srctag"/> <result property="logSrctag" column="log_srctag"/>
<result property="logSrctype" column="log_srctype"/> <result property="logSrctype" column="log_srctype"/>
<result property="timeStampString" column="timestampString"/>
</resultMap> </resultMap>
<resultMap type="com.lzbi.bi.domain.DcDymicReportHeaderVo" id="headerQuery"> <resultMap type="com.lzbi.bi.domain.DcDymicReportHeaderVo" id="headerQuery">
@ -30,7 +32,8 @@
<select id="selectDetailByQuery" resultMap="dcBaseLogHistory" > <select id="selectDetailByQuery" resultMap="dcBaseLogHistory" >
select timestamp_key, select to_char(timestamp_key ,'yyyy-MM-dd hh24') as timestampString,
timestamp_key,
device_uuid, device_uuid,
param_code, param_code,
param_value_num, param_value_num,

Loading…
Cancel
Save