|
@ -7,16 +7,16 @@ import cn.hutool.poi.excel.BigExcelWriter; |
|
|
import cn.hutool.poi.excel.ExcelUtil; |
|
|
import cn.hutool.poi.excel.ExcelUtil; |
|
|
import cn.hutool.poi.excel.ExcelWriter; |
|
|
import cn.hutool.poi.excel.ExcelWriter; |
|
|
import com.alibaba.fastjson2.JSONObject; |
|
|
import com.alibaba.fastjson2.JSONObject; |
|
|
import com.lzbi.bi.domain.DcDymicHeaderQueryVo; |
|
|
import com.lzbi.asset.domain.DcBaseAssetInfo; |
|
|
import com.lzbi.bi.domain.DcDymicReportHeaderVo; |
|
|
import com.lzbi.bi.domain.*; |
|
|
import com.lzbi.bi.domain.LogTimeThreeQueryParamVo; |
|
|
import com.lzbi.code.domain.WeatherReportVO; |
|
|
import com.lzbi.bi.domain.LogTimescaleHistoryThreeVo; |
|
|
|
|
|
import com.lzbi.code.service.LogTimesacleHistoryThreeService; |
|
|
import com.lzbi.code.service.LogTimesacleHistoryThreeService; |
|
|
import com.lzbi.common.core.controller.BaseController; |
|
|
import com.lzbi.common.core.controller.BaseController; |
|
|
import com.lzbi.common.core.domain.AjaxResult; |
|
|
import com.lzbi.common.core.domain.AjaxResult; |
|
|
import com.lzbi.common.utils.StringUtils; |
|
|
import com.lzbi.common.utils.StringUtils; |
|
|
import io.swagger.annotations.Api; |
|
|
import io.swagger.annotations.Api; |
|
|
import io.swagger.annotations.ApiOperation; |
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
import javax.annotation.Resource; |
|
@ -33,12 +33,14 @@ import java.util.stream.Collectors; |
|
|
* @author : zhousq |
|
|
* @author : zhousq |
|
|
* @date : 2024-02-5 |
|
|
* @date : 2024-02-5 |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
@Slf4j |
|
|
@Api(tags = "生产设备参数统计明细表功能接口") |
|
|
@Api(tags = "生产设备参数统计明细表功能接口") |
|
|
@RestController |
|
|
@RestController |
|
|
@RequestMapping("/dc/hisDetailReport") |
|
|
@RequestMapping("/dc/hisDetailReport") |
|
|
public class DcBusiHisReportController extends BaseController { |
|
|
public class DcBusiHisReportController extends BaseController { |
|
|
@Resource |
|
|
@Resource |
|
|
private LogTimesacleHistoryThreeService logTimesacleHistoryThreeService; |
|
|
private LogTimesacleHistoryThreeService logTimesacleHistoryThreeService; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 分页列表查询 |
|
|
* 分页列表查询 |
|
|
* |
|
|
* |
|
@ -70,7 +72,7 @@ public class DcBusiHisReportController extends BaseController { |
|
|
.sorted(Comparator.comparing(DcDymicReportHeaderVo::getDeviceUUID).thenComparing(DcDymicReportHeaderVo::getParamCode)) |
|
|
.sorted(Comparator.comparing(DcDymicReportHeaderVo::getDeviceUUID).thenComparing(DcDymicReportHeaderVo::getParamCode)) |
|
|
.forEach(dcDymicReportHeaderVo -> { |
|
|
.forEach(dcDymicReportHeaderVo -> { |
|
|
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", 200); |
|
|
ct.put("width", 200); |
|
|
columnMap.put(dcDymicReportHeaderVo.getColCode(), dcDymicReportHeaderVo.getParamCode()); |
|
|
columnMap.put(dcDymicReportHeaderVo.getColCode(), dcDymicReportHeaderVo.getParamCode()); |
|
@ -87,7 +89,7 @@ public class DcBusiHisReportController extends BaseController { |
|
|
.forEach(tVo -> { |
|
|
.forEach(tVo -> { |
|
|
String ck = tVo.getDeviceUuid() + "_" + tVo.getParamCode(); |
|
|
String ck = tVo.getDeviceUuid() + "_" + tVo.getParamCode(); |
|
|
if (StringUtils.isNotNull(columnMap.get(ck))) { |
|
|
if (StringUtils.isNotNull(columnMap.get(ck))) { |
|
|
jdata.put("C"+ck, tVo.getParamValueNum()); |
|
|
jdata.put("C" + ck, tVo.getParamValueNum()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
@ -132,7 +134,7 @@ public class DcBusiHisReportController extends BaseController { |
|
|
.sorted(Comparator.comparing(DcDymicReportHeaderVo::getDeviceUUID).thenComparing(DcDymicReportHeaderVo::getParamCode)) |
|
|
.sorted(Comparator.comparing(DcDymicReportHeaderVo::getDeviceUUID).thenComparing(DcDymicReportHeaderVo::getParamCode)) |
|
|
.forEach(dcDymicReportHeaderVo -> { |
|
|
.forEach(dcDymicReportHeaderVo -> { |
|
|
JSONObject ct = new JSONObject(); |
|
|
JSONObject ct = new JSONObject(); |
|
|
ct.put("deviceName", "C"+dcDymicReportHeaderVo.getColCode()); |
|
|
ct.put("deviceName", "C" + dcDymicReportHeaderVo.getColCode()); |
|
|
ct.put("paramName", dcDymicReportHeaderVo.getColName1() + "[" + dcDymicReportHeaderVo.getColName2() + "]"); |
|
|
ct.put("paramName", dcDymicReportHeaderVo.getColName1() + "[" + dcDymicReportHeaderVo.getColName2() + "]"); |
|
|
columnMap.put(dcDymicReportHeaderVo.getColCode(), ct); |
|
|
columnMap.put(dcDymicReportHeaderVo.getColCode(), ct); |
|
|
|
|
|
|
|
@ -149,7 +151,7 @@ public class DcBusiHisReportController extends BaseController { |
|
|
data2.entrySet().stream().sorted(Map.Entry.comparingByKey()).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)) { |
|
|
jsonObject.put(vo.getTimestampKey().toString(), vo.getParamValueNum()); |
|
|
jsonObject.put(vo.getTimestampKey().toString(), vo.getParamValueNum()); |
|
|
} |
|
|
} |
|
|
tableDatas.add(jsonObject); |
|
|
tableDatas.add(jsonObject); |
|
@ -161,41 +163,44 @@ public class DcBusiHisReportController extends BaseController { |
|
|
return AjaxResult.success(dataInfo); |
|
|
return AjaxResult.success(dataInfo); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private String validatorator(LogTimeThreeQueryParamVo queryVo) { |
|
|
private String validatorator(LogTimeThreeQueryParamVo queryVo) { |
|
|
if (StringUtils.isNull(queryVo.getBeginTime())||StringUtils.isEmpty(queryVo.getBeginTime())) { |
|
|
if (StringUtils.isNull(queryVo.getBeginTime()) || StringUtils.isEmpty(queryVo.getBeginTime())) { |
|
|
return "查询失败,开始时间不能为空!"; |
|
|
return "查询失败,开始时间不能为空!"; |
|
|
} |
|
|
} |
|
|
if (StringUtils.isNull(queryVo.getEndTime())||StringUtils.isEmpty(queryVo.getEndTime())) { |
|
|
if (StringUtils.isNull(queryVo.getEndTime()) || StringUtils.isEmpty(queryVo.getEndTime())) { |
|
|
return "查询失败,结束时间不能为空!"; |
|
|
return "查询失败,结束时间不能为空!"; |
|
|
} |
|
|
} |
|
|
if (StringUtils.isNull(queryVo.getQueryParamClass())||StringUtils.isEmpty(queryVo.getQueryParamClass())) { |
|
|
if (StringUtils.isNull(queryVo.getQueryParamClass()) || StringUtils.isEmpty(queryVo.getQueryParamClass())) { |
|
|
return "查询失败,参数类型不能为空!"; |
|
|
return "查询失败,参数类型不能为空!"; |
|
|
} |
|
|
} |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
///按时间 设备+参数 形成数据--时间分组
|
|
|
///按时间 设备+参数 形成数据--时间分组
|
|
|
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<String, List<LogTimescaleHistoryThreeVo>> collect = list.stream().collect(Collectors.groupingBy(LogTimescaleHistoryThreeVo::getTimeStampString)); |
|
|
Map<String, List<LogTimescaleHistoryThreeVo>> collect = list.stream().collect(Collectors.groupingBy(LogTimescaleHistoryThreeVo::getTimeStampString)); |
|
|
return collect.entrySet().stream().sorted(Map.Entry.comparingByKey()).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("统计时间",entry.getKey()); |
|
|
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(); |
|
|
if(first.isPresent()){ |
|
|
if (first.isPresent()) { |
|
|
//map.put(first.get().getColName1(), first.get().getColName2());
|
|
|
//map.put(first.get().getColName1(), first.get().getColName2());
|
|
|
map.put(first.get().getColName1()+'.'+first.get().getColName2(), vo.getParamValueNum()); |
|
|
map.put(first.get().getColName1() + '.' + first.get().getColName2(), vo.getParamValueNum()); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
return map; |
|
|
return map; |
|
|
}).collect(Collectors.toList()); |
|
|
}).collect(Collectors.toList()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// 设备+参数 形成数据--设备-参数分组
|
|
|
/// 设备+参数 形成数据--设备-参数分组
|
|
|
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().collect(Collectors.groupingBy(item->item.getDeviceUuid()+"_"+item.getParamCode())); |
|
|
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).thenComparing(LogTimescaleHistoryThreeVo::getParamCode)).forEach(vo -> { |
|
|
entry.getValue().stream().sorted(Comparator.comparing(LogTimescaleHistoryThreeVo::getTimeStampString).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()) { |
|
@ -213,22 +218,24 @@ public class DcBusiHisReportController extends BaseController { |
|
|
* "生产设备参数统计明细表导出功能 |
|
|
* "生产设备参数统计明细表导出功能 |
|
|
*/ |
|
|
*/ |
|
|
@ApiOperation("生产设备参数统计明细表导出功能--时间纵向") |
|
|
@ApiOperation("生产设备参数统计明细表导出功能--时间纵向") |
|
|
@PostMapping ("/export") |
|
|
@PostMapping("/export") |
|
|
public void export(HttpServletResponse response, 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, LogTimeThreeQueryParamVo queryVo) throws IOException { |
|
|
public void export2(HttpServletResponse response, LogTimeThreeQueryParamVo queryVo) throws IOException { |
|
|
List<Map<String, Object>> mapList=getExcellData(queryVo,1); |
|
|
List<Map<String, Object>> mapList = getExcellData(queryVo, 1); |
|
|
// 通过工具类创建writer,默认创建xls格式
|
|
|
// 通过工具类创建writer,默认创建xls格式
|
|
|
toExcel(response,mapList); |
|
|
toExcel(response, mapList); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//获取excel数据 1 excel设备参数为列模式 2 excel时间为列模式 3 浏览器设备参数为列模式
|
|
|
//获取excel数据 1 excel设备参数为列模式 2 excel时间为列模式 3 浏览器设备参数为列模式
|
|
|
//注意 excel有最大列数显示255 ,超出列数会报错
|
|
|
//注意 excel有最大列数显示255 ,超出列数会报错
|
|
|
private List<Map<String, Object>> getExcellData(LogTimeThreeQueryParamVo queryVo,int type){ |
|
|
private List<Map<String, Object>> getExcellData(LogTimeThreeQueryParamVo queryVo, int type) { |
|
|
// 设置头部数据,
|
|
|
// 设置头部数据,
|
|
|
DcDymicHeaderQueryVo dcDymicHeaderQueryVo = new DcDymicHeaderQueryVo(); |
|
|
DcDymicHeaderQueryVo dcDymicHeaderQueryVo = new DcDymicHeaderQueryVo(); |
|
|
dcDymicHeaderQueryVo.setParamModels(queryVo.getQueryParamClass()); |
|
|
dcDymicHeaderQueryVo.setParamModels(queryVo.getQueryParamClass()); |
|
@ -237,19 +244,19 @@ public class DcBusiHisReportController extends BaseController { |
|
|
List<String> collect = dcDymicReportHeaderVos.stream().map(DcDymicReportHeaderVo::getParamCode).collect(Collectors.toList()); |
|
|
List<String> collect = dcDymicReportHeaderVos.stream().map(DcDymicReportHeaderVo::getParamCode).collect(Collectors.toList()); |
|
|
queryVo.setQueryParamCodes(collect); |
|
|
queryVo.setQueryParamCodes(collect); |
|
|
List<LogTimescaleHistoryThreeVo> list = logTimesacleHistoryThreeService.selectDetailByQuery(queryVo); |
|
|
List<LogTimescaleHistoryThreeVo> list = logTimesacleHistoryThreeService.selectDetailByQuery(queryVo); |
|
|
if(type==1){ |
|
|
if (type == 1) { |
|
|
return getMapListDevice(list,dcDymicReportHeaderVos); |
|
|
return getMapListDevice(list, dcDymicReportHeaderVos); |
|
|
}else { |
|
|
} else { |
|
|
return getMapList(list,dcDymicReportHeaderVos); |
|
|
return getMapList(list, dcDymicReportHeaderVos); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
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() + ".xlsx"; |
|
|
String fileName = "report" + DateUtil.now() + ".xlsx"; |
|
|
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(true);
|
|
|
//ExcelWriter writer = ExcelUtil.getWriter(true);
|
|
|
BigExcelWriter writer= ExcelUtil.getBigWriter(); |
|
|
BigExcelWriter writer = ExcelUtil.getBigWriter(); |
|
|
writer.write(mapList, true); |
|
|
writer.write(mapList, true); |
|
|
//test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
|
|
|
//test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
|
|
|
//response.setHeader("Content-Disposition", "attachment;filename="+fileName);
|
|
|
//response.setHeader("Content-Disposition", "attachment;filename="+fileName);
|
|
@ -260,17 +267,33 @@ public class DcBusiHisReportController extends BaseController { |
|
|
//此处记得关闭输出Servlet流
|
|
|
//此处记得关闭输出Servlet流
|
|
|
IoUtil.close(out); |
|
|
IoUtil.close(out); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ApiOperation("获取生产IOT系统参数模版列表") |
|
|
@ApiOperation("获取生产IOT系统参数模版列表") |
|
|
@GetMapping("/getParamClass") |
|
|
@GetMapping("/getParamClass") |
|
|
public AjaxResult getParamClass(){ |
|
|
public AjaxResult getParamClass() { |
|
|
return AjaxResult.success(logTimesacleHistoryThreeService.selectParamModels()) ; |
|
|
return AjaxResult.success(logTimesacleHistoryThreeService.selectParamModels()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ApiOperation("获取生产IOT系统设备列表") |
|
|
@ApiOperation("获取生产IOT系统设备列表") |
|
|
@GetMapping("/getDevicie/{orgCode}") |
|
|
@GetMapping("/getDevicie/{orgCode}") |
|
|
public AjaxResult selectDevices(@PathVariable Long orgCode) { |
|
|
public AjaxResult selectDevices(@PathVariable Long orgCode) { |
|
|
if(orgCode==0){ |
|
|
if (orgCode == 0) { |
|
|
return AjaxResult.success(logTimesacleHistoryThreeService.selectDevices(null)) ; |
|
|
return AjaxResult.success(logTimesacleHistoryThreeService.selectDevices(null)); |
|
|
} |
|
|
} |
|
|
return AjaxResult.success(logTimesacleHistoryThreeService.selectDevices(orgCode)) ; |
|
|
return AjaxResult.success(logTimesacleHistoryThreeService.selectDevices(orgCode)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("根据父id获取下级地区--级联数据") |
|
|
|
|
|
@GetMapping("/selectAreaElementCascaderByParentId") |
|
|
|
|
|
public AjaxResult selectAreaElementCascaderByParentId(@RequestParam("parentId") Integer parentId) { |
|
|
|
|
|
return AjaxResult.success(logTimesacleHistoryThreeService.selectAreaElementCascaderByParentId(parentId)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("天气报表") |
|
|
|
|
|
@PostMapping("/exportWeather") |
|
|
|
|
|
public void exportWeather(HttpServletResponse response, ExportWeatherReq exportWeatherReq) throws IOException { |
|
|
|
|
|
List<WeatherReportVO> weatherReport = logTimesacleHistoryThreeService.getWeatherReport(exportWeatherReq); |
|
|
|
|
|
com.lzbi.common.utils.poi.ExcelUtil<WeatherReportVO> util = new com.lzbi.common.utils.poi.ExcelUtil<WeatherReportVO>(WeatherReportVO.class); |
|
|
|
|
|
util.exportExcel(response, weatherReport, "天气报表"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |