bobol
9 months ago
10 changed files with 639 additions and 0 deletions
@ -0,0 +1,319 @@ |
|||
package com.lzbi.bi.controller; |
|||
|
|||
|
|||
import cn.hutool.core.date.DatePattern; |
|||
import cn.hutool.core.date.DateUtil; |
|||
import cn.hutool.core.io.IoUtil; |
|||
import cn.hutool.poi.excel.ExcelUtil; |
|||
import cn.hutool.poi.excel.ExcelWriter; |
|||
import com.alibaba.fastjson2.JSONObject; |
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
|
|||
import com.github.pagehelper.PageHelper; |
|||
import com.github.pagehelper.PageInfo; |
|||
import com.lzbi.bi.domain.DcDymicHeaderQueryVo; |
|||
import com.lzbi.bi.domain.DcDymicReportHeaderVo; |
|||
import com.lzbi.bi.domain.LogTimeThreeQueryParamVo; |
|||
import com.lzbi.bi.domain.LogTimescaleHistoryThreeVo; |
|||
import com.lzbi.code.service.LogTimesacleHistoryThreeService; |
|||
import com.lzbi.common.core.controller.BaseController; |
|||
import com.lzbi.common.core.domain.AjaxResult; |
|||
import com.lzbi.common.core.page.TableDataInfo; |
|||
import com.lzbi.common.utils.DateUtils; |
|||
import com.lzbi.common.utils.StringUtils; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import javax.annotation.Resource; |
|||
import javax.servlet.ServletOutputStream; |
|||
import javax.servlet.http.HttpServletResponse; |
|||
import javax.validation.constraints.NotNull; |
|||
import java.io.IOException; |
|||
import java.sql.Timestamp; |
|||
import java.util.*; |
|||
import java.util.stream.Collectors; |
|||
|
|||
/** |
|||
* 生产设备参数统计明细表; |
|||
* |
|||
* @author : zhousq |
|||
* @date : 2024-02-5 |
|||
*/ |
|||
@Api(tags = "生产设备参数统计明细表功能接口") |
|||
@RestController |
|||
@RequestMapping("/dc/hisDetailReport") |
|||
public class DcBusiHisReportController extends BaseController { |
|||
@Resource |
|||
private LogTimesacleHistoryThreeService logTimesacleHistoryThreeService; |
|||
/** |
|||
* 分页列表查询 |
|||
* |
|||
* @return 分页数据 |
|||
*/ |
|||
@PostMapping("/listReport") |
|||
public AjaxResult list(@RequestBody LogTimeThreeQueryParamVo queryVo) { |
|||
String error = validatorator(queryVo); |
|||
if (error != null) { |
|||
return AjaxResult.error(error); |
|||
} else { |
|||
// 设置头部数据,
|
|||
List tableColumns = new ArrayList(); |
|||
JSONObject tableColum = new JSONObject(); |
|||
tableColum.put("field", "totalTime"); |
|||
tableColum.put("title", "统计时间"); |
|||
tableColum.put("width", 100); |
|||
tableColumns.add(tableColum); |
|||
List tableDatas = new ArrayList(); |
|||
DcDymicHeaderQueryVo dcDymicHeaderQueryVo = new DcDymicHeaderQueryVo(); |
|||
dcDymicHeaderQueryVo.setParamModels(queryVo.getQueryParamClass()); |
|||
dcDymicHeaderQueryVo.setDeviceUuids(queryVo.getDeviceUuids()); |
|||
List<DcDymicReportHeaderVo> dcDymicReportHeaderVos = logTimesacleHistoryThreeService.selectHeaderInfo(dcDymicHeaderQueryVo); |
|||
List<String> collect = dcDymicReportHeaderVos.stream().map(DcDymicReportHeaderVo::getParamCode).collect(Collectors.toList()); |
|||
queryVo.setQueryParamCodes(collect); |
|||
List<LogTimescaleHistoryThreeVo> list = logTimesacleHistoryThreeService.selectDetailByQuery(queryVo); |
|||
Map<String, String> columnMap = new LinkedHashMap<>(); |
|||
dcDymicReportHeaderVos.stream() |
|||
.sorted(Comparator.comparing(DcDymicReportHeaderVo::getDeviceUUID).thenComparing(DcDymicReportHeaderVo::getParamCode)) |
|||
.forEach(dcDymicReportHeaderVo -> { |
|||
JSONObject ct = new JSONObject(); |
|||
ct.put("field", "C"+dcDymicReportHeaderVo.getColCode()); |
|||
ct.put("title", dcDymicReportHeaderVo.getColName1() + "[" + dcDymicReportHeaderVo.getColName2() + "]"); |
|||
ct.put("width", 80); |
|||
columnMap.put(dcDymicReportHeaderVo.getColCode(), dcDymicReportHeaderVo.getParamCode()); |
|||
tableColumns.add(ct); |
|||
}); |
|||
Map<Timestamp, List<LogTimescaleHistoryThreeVo>> data = list.stream().sorted(Comparator.comparing((LogTimescaleHistoryThreeVo::getTimestampKey))).collect(Collectors.groupingBy(LogTimescaleHistoryThreeVo::getTimestampKey)); |
|||
//生成talbecolum { field: 'id', title: 'ID', width: 80, fixed: 'left' },
|
|||
//生成tabledata
|
|||
//PageInfo pageInfo=new PageInfo(pageNum,pageSize);
|
|||
data.entrySet().stream().forEach(entry -> { |
|||
JSONObject jdata = new JSONObject(); |
|||
jdata.put("totalTime", entry.getKey()); |
|||
entry.getValue().stream().sorted(Comparator.comparing(LogTimescaleHistoryThreeVo::getDeviceUuid).thenComparing(LogTimescaleHistoryThreeVo::getParamCode)) |
|||
.forEach(tVo -> { |
|||
String ck = tVo.getDeviceUuid() + "_" + tVo.getParamCode(); |
|||
if (StringUtils.isNotNull(columnMap.get(ck))) { |
|||
jdata.put("C"+ck, tVo.getParamValueNum()); |
|||
} |
|||
|
|||
}); |
|||
tableDatas.add(jdata); |
|||
}); |
|||
JSONObject dataInfo = new JSONObject(); |
|||
dataInfo.put("header", tableColumns); |
|||
dataInfo.put("tableData", tableDatas); |
|||
return AjaxResult.success(dataInfo); |
|||
} |
|||
|
|||
} |
|||
|
|||
@PostMapping("/listDetail") |
|||
public AjaxResult listDetail(@NotNull @RequestBody LogTimeThreeQueryParamVo queryVo) { |
|||
String error = validatorator(queryVo); |
|||
if (error != null) { |
|||
return AjaxResult.error(error); |
|||
} else { |
|||
// 设置头部数据,
|
|||
List tableColumns = new ArrayList(); |
|||
JSONObject tableColum = new JSONObject(); |
|||
tableColum.put("field", "deviceName"); |
|||
tableColum.put("title", "设备名称"); |
|||
tableColum.put("width", 100); |
|||
tableColumns.add(tableColum); |
|||
tableColum = new JSONObject(); |
|||
tableColum.put("field", "paramName"); |
|||
tableColum.put("title", "参数名称"); |
|||
tableColum.put("width", 100); |
|||
tableColumns.add(tableColum); |
|||
List tableDatas = new ArrayList(); |
|||
DcDymicHeaderQueryVo dcDymicHeaderQueryVo = new DcDymicHeaderQueryVo(); |
|||
dcDymicHeaderQueryVo.setParamModels(queryVo.getQueryParamClass()); |
|||
dcDymicHeaderQueryVo.setDeviceUuids(queryVo.getDeviceUuids()); |
|||
List<DcDymicReportHeaderVo> dcDymicReportHeaderVos = logTimesacleHistoryThreeService.selectHeaderInfo(dcDymicHeaderQueryVo); |
|||
List<String> collect = dcDymicReportHeaderVos.stream().map(DcDymicReportHeaderVo::getParamCode).collect(Collectors.toList()); |
|||
queryVo.setQueryParamCodes(collect); |
|||
List<LogTimescaleHistoryThreeVo> list = logTimesacleHistoryThreeService.selectDetailByQuery(queryVo); |
|||
Map<String, JSONObject> columnMap = new LinkedHashMap<>(); |
|||
dcDymicReportHeaderVos.stream() |
|||
.sorted(Comparator.comparing(DcDymicReportHeaderVo::getDeviceUUID).thenComparing(DcDymicReportHeaderVo::getParamCode)) |
|||
.forEach(dcDymicReportHeaderVo -> { |
|||
JSONObject ct = new JSONObject(); |
|||
ct.put("deviceName", "C"+dcDymicReportHeaderVo.getColCode()); |
|||
ct.put("paramName", dcDymicReportHeaderVo.getColName1() + "[" + dcDymicReportHeaderVo.getColName2() + "]"); |
|||
columnMap.put(dcDymicReportHeaderVo.getColCode(), ct); |
|||
|
|||
}); |
|||
Map<Timestamp, List<LogTimescaleHistoryThreeVo>> data = list.stream().sorted(Comparator.comparing((LogTimescaleHistoryThreeVo::getTimestampKey))).collect(Collectors.groupingBy(LogTimescaleHistoryThreeVo::getTimestampKey)); |
|||
data.entrySet().stream().forEach(entry -> { |
|||
JSONObject tc = new JSONObject(); |
|||
tc.put("field", entry.getKey().toString()); |
|||
tc.put("title", entry.getKey()); |
|||
tc.put("width", 100); |
|||
tableColumns.add(tc); |
|||
}); |
|||
Map<String, List<LogTimescaleHistoryThreeVo>> data2 = list.stream().sorted(Comparator.comparing((LogTimescaleHistoryThreeVo::getDeviceUuid))).collect(Collectors.groupingBy(LogTimescaleHistoryThreeVo::getDeviceUuid)); |
|||
data2.entrySet().stream().forEach(entry -> { |
|||
entry.getValue().stream().sorted(Comparator.comparing(LogTimescaleHistoryThreeVo::getParamCode)).forEach(vo -> { |
|||
JSONObject jsonObject = columnMap.get(vo.getDeviceUuid() + "_" + vo.getParamCode()); |
|||
if(StringUtils.isNotNull(jsonObject)){ |
|||
jsonObject.put(vo.getTimestampKey().toString(), vo.getParamValueNum()); |
|||
} |
|||
tableDatas.add(jsonObject); |
|||
}); |
|||
}); |
|||
JSONObject dataInfo = new JSONObject(); |
|||
dataInfo.put("header", tableColumns); |
|||
dataInfo.put("tableData", tableDatas); |
|||
return AjaxResult.success(dataInfo); |
|||
} |
|||
} |
|||
private String validatorator(LogTimeThreeQueryParamVo queryVo) { |
|||
if (StringUtils.isNull(queryVo.getBeginTime())||StringUtils.isEmpty(queryVo.getBeginTime())) { |
|||
return "查询失败,开始时间不能为空!"; |
|||
} |
|||
if (StringUtils.isNull(queryVo.getEndTime())||StringUtils.isEmpty(queryVo.getEndTime())) { |
|||
return "查询失败,结束时间不能为空!"; |
|||
} |
|||
if (StringUtils.isNull(queryVo.getQueryParamClass())||StringUtils.isEmpty(queryVo.getQueryParamClass())) { |
|||
return "查询失败,参数类型不能为空!"; |
|||
} |
|||
return null; |
|||
} |
|||
///按时间 设备+参数 形成数据--时间分组
|
|||
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)); |
|||
return collect.entrySet().stream().map(entry -> { |
|||
Map<String, Object> map = new LinkedHashMap<>(); |
|||
map.put("统计时间", DateUtil.format(entry.getKey(), DatePattern.NORM_DATETIME_PATTERN)); |
|||
entry.getValue().stream().sorted(Comparator.comparing(LogTimescaleHistoryThreeVo::getDeviceUuid).thenComparing(LogTimescaleHistoryThreeVo::getParamCode)).forEach(vo -> { |
|||
String key=vo.getDeviceUuid() + "_" + vo.getParamCode(); |
|||
Optional<DcDymicReportHeaderVo> first = dcDymicReportHeaderVos.stream().filter(vos -> vos.getColCode().equals(key)).findFirst(); |
|||
if(first.isPresent()){ |
|||
//map.put(first.get().getColName1(), first.get().getColName2());
|
|||
map.put(first.get().getColName1()+'.'+first.get().getColName2(), vo.getParamValueNum()); |
|||
} |
|||
}); |
|||
return map; |
|||
}).collect(Collectors.toList()); |
|||
} |
|||
/// 设备+参数 形成数据--设备-参数分组
|
|||
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)); |
|||
List<Map<String, Object>> collect1 = collect.entrySet().stream().map(entry -> { |
|||
Map<String, Object> map = new LinkedHashMap<>(); |
|||
entry.getValue().stream().sorted(Comparator.comparing(LogTimescaleHistoryThreeVo::getTimestampKey)).forEach(vo -> { |
|||
String key = vo.getDeviceUuid() + "_" + vo.getParamCode(); |
|||
Optional<DcDymicReportHeaderVo> 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()); |
|||
} |
|||
}); |
|||
return map; |
|||
}).collect(Collectors.toList()); |
|||
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("生产设备参数统计明细表导出功能--时间纵向") |
|||
@PostMapping("/export") |
|||
public void export(HttpServletResponse response, @RequestBody LogTimeThreeQueryParamVo queryVo) throws IOException { |
|||
List<Map<String, Object>> mapList=getExcellData(queryVo,2); |
|||
toExcel(response,mapList); |
|||
} |
|||
@ApiOperation("生产设备参数统计明细表导出功能-时间横向") |
|||
@PostMapping("/export2") |
|||
public void export2(HttpServletResponse response, @RequestBody LogTimeThreeQueryParamVo queryVo) throws IOException { |
|||
List<Map<String, Object>> mapList=getExcellData(queryVo,2); |
|||
// 通过工具类创建writer,默认创建xls格式
|
|||
toExcel(response,mapList); |
|||
|
|||
} |
|||
//获取excel数据 1 excel设备参数为列模式 2 excel时间为列模式 3 浏览器设备参数为列模式
|
|||
//注意 excel有最大列数显示255 ,超出列数会报错
|
|||
private List<Map<String, Object>> getExcellData(LogTimeThreeQueryParamVo queryVo,int type){ |
|||
// 设置头部数据,
|
|||
DcDymicHeaderQueryVo dcDymicHeaderQueryVo = new DcDymicHeaderQueryVo(); |
|||
dcDymicHeaderQueryVo.setParamModels(queryVo.getQueryParamClass()); |
|||
dcDymicHeaderQueryVo.setDeviceUuids(queryVo.getDeviceUuids()); |
|||
List<DcDymicReportHeaderVo> dcDymicReportHeaderVos = logTimesacleHistoryThreeService.selectHeaderInfo(dcDymicHeaderQueryVo); |
|||
List<String> collect = dcDymicReportHeaderVos.stream().map(DcDymicReportHeaderVo::getParamCode).collect(Collectors.toList()); |
|||
queryVo.setQueryParamCodes(collect); |
|||
List<LogTimescaleHistoryThreeVo> list = logTimesacleHistoryThreeService.selectDetailByQuery(queryVo); |
|||
if(type==1){ |
|||
return getMapListDevice(list,dcDymicReportHeaderVos); |
|||
}else { |
|||
return getMapList(list,dcDymicReportHeaderVos); |
|||
} |
|||
} |
|||
|
|||
private void toExcel(HttpServletResponse response,List<Map<String, Object>> mapList) throws IOException { |
|||
String fileName ="report"+DateUtil.now() + ".xls"; |
|||
//response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|||
//response.setCharacterEncoding("utf-8");
|
|||
ExcelWriter writer = ExcelUtil.getWriter(); |
|||
// 一次性写出内容,使用默认样式,强制输出标题
|
|||
//writer.write(mapList, true);
|
|||
|
|||
//List<Map<String, 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); |
|||
ServletOutputStream out = response.getOutputStream(); |
|||
writer.flush(out, true); |
|||
// 关闭writer,释放内存
|
|||
writer.close(); |
|||
//此处记得关闭输出Servlet流
|
|||
IoUtil.close(out); |
|||
} |
|||
@ApiOperation("获取生产IOT系统参数模版列表") |
|||
@GetMapping("/getParamClass") |
|||
public AjaxResult getParamClass(){ |
|||
return AjaxResult.success(logTimesacleHistoryThreeService.selectParamModels()) ; |
|||
} |
|||
@ApiOperation("获取生产IOT系统设备列表") |
|||
@GetMapping("/getDevicie/{orgCode}") |
|||
public AjaxResult selectDevices(@PathVariable Long orgCode) { |
|||
if(orgCode==0){ |
|||
return AjaxResult.success(logTimesacleHistoryThreeService.selectDevices(null)) ; |
|||
} |
|||
return AjaxResult.success(logTimesacleHistoryThreeService.selectDevices(orgCode)) ; |
|||
} |
|||
} |
@ -0,0 +1,13 @@ |
|||
package com.lzbi.bi.domain; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Data |
|||
public class DcDymicHeaderQueryVo { |
|||
/*设备UUID列表*/ |
|||
private List<String> deviceUuids; |
|||
/**参数类型列表*/ |
|||
private List<String> paramModels; |
|||
} |
@ -0,0 +1,23 @@ |
|||
package com.lzbi.bi.domain; |
|||
|
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
public class DcDymicReportHeaderVo { |
|||
/**字段名称-一级标题*/ |
|||
private String colName1; |
|||
/**字段名称-二级标题*/ |
|||
private String colName2; |
|||
/**字段编码*/ |
|||
private String colCode; |
|||
/**类型编码*/ |
|||
private String classCode; |
|||
/**类型名称*/ |
|||
private String className; |
|||
/**字段名称*/ |
|||
private String deviceUUID; |
|||
/**参数编码*/ |
|||
private String paramCode; |
|||
/**参数分区*/ |
|||
private String partion; |
|||
} |
@ -0,0 +1,44 @@ |
|||
package com.lzbi.bi.domain; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
import lombok.experimental.Accessors; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @Description: level3 日志查询参数 |
|||
*/ |
|||
@Data |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
@Accessors(chain = true) |
|||
@ApiModel(value = "level3 日志查询参数",description = "") |
|||
public class LogTimeThreeQueryParamVo { |
|||
/** 开始时间 */ |
|||
@ApiModelProperty(name = "开始时间",notes = "") |
|||
private String beginTime; |
|||
/** 结束时间 */ |
|||
@ApiModelProperty(name = "开始时间",notes = "") |
|||
private String endTime; |
|||
/** 中台设备UUID */ |
|||
@ApiModelProperty(name = "中台设备UUID",notes = "") |
|||
private List<String> deviceUuids ; |
|||
/** 参数列表 */ |
|||
@ApiModelProperty(name = "参数列表",notes = "") |
|||
private List<String> queryParamCodes ; |
|||
/** 参数模版列表 */ |
|||
@ApiModelProperty(name = "参数模版列表",notes = "") |
|||
private List<String> queryParamClass ; |
|||
private Integer pageNum; |
|||
private Integer pageSize; |
|||
public String getBeginTime() { |
|||
return beginTime+" 00:00:00"; |
|||
} |
|||
public String getEndTime() { |
|||
return endTime+" 23:59:59"; |
|||
} |
|||
} |
@ -0,0 +1,45 @@ |
|||
package com.lzbi.bi.domain; |
|||
|
|||
|
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
import java.sql.Timestamp; |
|||
|
|||
@Data |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
//@Accessors(chain = true)
|
|||
@ApiModel(value = "数据采集历史汇总表",description = "") |
|||
@TableName("dc_base_log_history_level3") |
|||
public class LogTimescaleHistoryThreeVo { |
|||
/** 时间戳 */ |
|||
@ApiModelProperty(name = "时间戳",notes = "") |
|||
private Timestamp timestampKey; |
|||
/** 中台设备UUID */ |
|||
@ApiModelProperty(name = "中台设备UUID",notes = "") |
|||
private String deviceUuid ; |
|||
/** 参数编码 */ |
|||
@ApiModelProperty(name = "参数编码",notes = "") |
|||
private String paramCode ; |
|||
/** 参数值数值型 */ |
|||
@ApiModelProperty(name = "参数值数值型",notes = "") |
|||
private Double paramValueNum ; |
|||
/** 参数类型 */ |
|||
@ApiModelProperty(name = "参数类型",notes = "") |
|||
private String paramType ; |
|||
/** 参数值字符型 */ |
|||
@ApiModelProperty(name = "参数值字符型",notes = "") |
|||
private String paramValueStr ; |
|||
@ApiModelProperty(name = "数值来源类型",notes = "") |
|||
private String logSrctag ; |
|||
@ApiModelProperty(name = "数值来源的时间tingsboard ts ;ioserver t",notes = "") |
|||
private String logSrctype ; |
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,31 @@ |
|||
package com.lzbi.bi.mapper; |
|||
import com.baomidou.mybatisplus.annotation.InterceptorIgnore; |
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.lzbi.bi.domain.DcDymicHeaderQueryVo; |
|||
import com.lzbi.bi.domain.DcDymicReportHeaderVo; |
|||
import com.lzbi.bi.domain.LogTimeThreeQueryParamVo; |
|||
import com.lzbi.bi.domain.LogTimescaleHistoryThreeVo; |
|||
import org.apache.ibatis.annotations.MapKey; |
|||
|
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
|
|||
@InterceptorIgnore(tenantLine = "true") |
|||
public interface LogTimeScaleThreeMapper extends BaseMapper<LogTimescaleHistoryThreeVo> { |
|||
|
|||
|
|||
|
|||
//List<DeviceHistoryResponseVo> selectVo(DeviceHistoryQueryVo queryVo);
|
|||
List<LogTimescaleHistoryThreeVo> selectDetailByQuery(LogTimeThreeQueryParamVo queryVo); |
|||
List<DcDymicReportHeaderVo> selectHeaderInfo(DcDymicHeaderQueryVo queryVo); |
|||
@MapKey("code") |
|||
List<Map<String,String>> selectParamModels(); |
|||
@MapKey("code") |
|||
List<Map<String,String>> selectDevices(Long orgCode); |
|||
|
|||
} |
|||
|
|||
|
|||
|
@ -0,0 +1,43 @@ |
|||
package com.lzbi.code.service; |
|||
|
|||
import com.baomidou.dynamic.datasource.annotation.DS; |
|||
import com.baomidou.mybatisplus.extension.service.IService; |
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
|
|||
import com.lzbi.bi.domain.DcDymicHeaderQueryVo; |
|||
import com.lzbi.bi.domain.DcDymicReportHeaderVo; |
|||
import com.lzbi.bi.domain.LogTimeThreeQueryParamVo; |
|||
import com.lzbi.bi.domain.LogTimescaleHistoryThreeVo; |
|||
import com.lzbi.bi.mapper.LogTimeScaleThreeMapper; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.ibatis.annotations.MapKey; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
@DS("workDB") |
|||
@Slf4j |
|||
@Service |
|||
public class LogTimesacleHistoryThreeService extends ServiceImpl<LogTimeScaleThreeMapper, LogTimescaleHistoryThreeVo> implements IService<LogTimescaleHistoryThreeVo> { |
|||
|
|||
|
|||
//@DataScopeCommon(deptAlias = "param")
|
|||
//public List<DeviceHistoryResponseVo> selectVo(DeviceHistoryQueryVo queryVo){
|
|||
// return baseMapper.selectVo(queryVo);
|
|||
//}
|
|||
|
|||
public List<LogTimescaleHistoryThreeVo> selectDetailByQuery(LogTimeThreeQueryParamVo queryVo){ |
|||
return baseMapper.selectDetailByQuery(queryVo); |
|||
} |
|||
public List<DcDymicReportHeaderVo> selectHeaderInfo(DcDymicHeaderQueryVo queryVo){ |
|||
return baseMapper.selectHeaderInfo(queryVo); |
|||
} |
|||
public List<Map<String,String>> selectParamModels(){ |
|||
return baseMapper.selectParamModels(); |
|||
} |
|||
|
|||
public List<Map<String,String>> selectDevices(Long orgCode){ |
|||
return baseMapper.selectDevices(orgCode); |
|||
} |
|||
} |
@ -0,0 +1,102 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<!DOCTYPE mapper |
|||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
|||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
<mapper namespace="com.lzbi.bi.mapper.LogTimeScaleThreeMapper"> |
|||
|
|||
<resultMap type="com.lzbi.bi.domain.LogTimescaleHistoryThreeVo" id="dcBaseLogHistory"> |
|||
<id property="timestampKey" column="timestamp_key"/> |
|||
<result property="deviceUuid" column="device_uuid"/> |
|||
<result property="paramCode" column="param_code"/> |
|||
<result property="paramValueNum" column="param_value_num"/> |
|||
<result property="paramType" column="param_type"/> |
|||
<result property="paramValueStr" column="param_value_str"/> |
|||
<result property="logSrctag" column="log_srctag"/> |
|||
<result property="logSrctype" column="log_srctype"/> |
|||
</resultMap> |
|||
|
|||
<resultMap type="com.lzbi.bi.domain.DcDymicReportHeaderVo" id="headerQuery"> |
|||
<id property="colName1" column="colName1"/> |
|||
<id property="colName2" column="colName2"/> |
|||
<result property="colCode" column="colCode"/> |
|||
<result property="classCode" column="classCode"/> |
|||
<result property="className" column="className"/> |
|||
<result property="deviceUUID" column="deviceUUID"/> |
|||
<result property="paramCode" column="paramCode"/> |
|||
<result property="partion" column="partion"/> |
|||
|
|||
</resultMap> |
|||
|
|||
|
|||
|
|||
<select id="selectDetailByQuery" resultMap="dcBaseLogHistory" > |
|||
select timestamp_key, |
|||
device_uuid, |
|||
param_code, |
|||
param_value_num, |
|||
param_type, |
|||
param_value_str, |
|||
log_srctag, |
|||
log_srctype from dc_base_log_history_level3 |
|||
where timestamp_key BETWEEN to_timestamp(#{beginTime},'yyyy-MM-dd hh24:mi:ss') |
|||
and to_timestamp(#{endTime},'yyyy-MM-dd hh24:mi:ss') |
|||
and param_type='double' |
|||
and param_code in |
|||
<foreach collection="queryParamCodes" item="code" open="(" separator="," close=")"> |
|||
#{code} |
|||
</foreach> |
|||
|
|||
<if test="deviceUuids != null"> |
|||
and device_uuid in |
|||
<foreach collection="deviceUuids" item="uuid" open="(" separator="," close=")"> |
|||
#{uuid} |
|||
</foreach> |
|||
</if> |
|||
order by timestamp_key desc |
|||
</select> |
|||
<select id="selectHeaderInfo" parameterType="com.lzbi.bi.domain.DcDymicHeaderQueryVo" resultMap="headerQuery"> |
|||
select a.device_name as colName1, |
|||
concat(c.param_class_name,'.',d.dict_label) as colName2, |
|||
concat(a.center_device_code, '_', b.param_code) as colCode, |
|||
b.param_model_id as classCode, |
|||
c.param_class_name as className, |
|||
a.center_device_code as deviceUUID, |
|||
b.param_code as paramCode, |
|||
d.dict_value as partion |
|||
from dc_base_deviceinfo a, |
|||
dc_base_device_param b, |
|||
dc_model_paramclass c, |
|||
sys_dict_data d |
|||
where a.center_device_code = b.device_uuid |
|||
and b.param_model_id = c.param_class_code |
|||
and d.dict_type='dc_device_partion' |
|||
and d.dict_value=b.partion |
|||
<if test="deviceUuids!= null"> |
|||
and a.center_device_code IN |
|||
<foreach collection="deviceUuids" item="deviceUuid" open="(" separator="," close=")"> |
|||
#{deviceUuid} |
|||
</foreach> |
|||
</if> |
|||
<if test="paramModels!= null"> |
|||
and c.param_class_code in |
|||
<foreach collection="paramModels" item="paramModel" open="(" separator="," close=")"> |
|||
#{paramModel} |
|||
</foreach> |
|||
</if> |
|||
ORDER BY a.center_device_code,b.param_code,b.partion |
|||
</select> |
|||
<select id="selectParamModels" resultType="map"> |
|||
SELECT param_class_code as code,param_class_name as name from dc_model_paramclass where delete_by is null ORDER BY param_class_code asc |
|||
|
|||
</select> |
|||
<select id="selectDevices" resultType="map"> |
|||
SELECT center_device_code as code,device_name as name |
|||
from dc_base_deviceinfo |
|||
where delete_by is null |
|||
and enabled_flag=true |
|||
<if test="orgCode!= null"> |
|||
and org_code =#{orgCode} |
|||
</if> |
|||
ORDER BY center_device_code asc |
|||
</select> |
|||
</mapper> |
Loading…
Reference in new issue