Browse Source

1、修改报表导出方法

develop
bobol 9 months ago
parent
commit
f13e613c75
  1. 2
      lzbi-admin/src/main/resources/application.yml
  2. 99
      lzbi-module/src/main/java/com/lzbi/bi/controller/DcBusiHisReportController.java
  3. 35
      lzbi-module/src/main/java/com/lzbi/bi/domain/ElementCascaderVO.java
  4. 25
      lzbi-module/src/main/java/com/lzbi/bi/domain/ExportWeatherReq.java
  5. 34
      lzbi-module/src/main/java/com/lzbi/bi/mapper/LogTimeScaleThreeMapper.java
  6. 10
      lzbi-module/src/main/java/com/lzbi/bi/service/DcBusiDataScreenNewService.java
  7. 29
      lzbi-module/src/main/java/com/lzbi/code/domain/WeatherReportVO.java
  8. 14
      lzbi-module/src/main/java/com/lzbi/code/service/LogTimesacleHistoryThreeService.java
  9. 30
      lzbi-module/src/main/resources/mapper/LogTimeScaleThreeMapper.xml

2
lzbi-admin/src/main/resources/application.yml

@ -60,7 +60,7 @@ spring:
# 国际化资源文件路径
basename: i18n/messages
profiles:
active: dev
active: test
# 文件上传
servlet:
multipart:

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

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

35
lzbi-module/src/main/java/com/lzbi/bi/domain/ElementCascaderVO.java

@ -0,0 +1,35 @@
package com.lzbi.bi.domain;
import lombok.Data;
import java.util.List;
/**
* @ClassName ElementCascaderVO
* @Description 饿了么级联组件vo
* @Version 1.0
*/
@Data
public class ElementCascaderVO {
/**
*
*/
private String value;
/**
* 标签
*/
private String label;
/**
* 是否禁用
*/
private boolean disabled;
/**
* 是否是叶子节点
*/
private boolean leaf;
/**
* 子节点
*/
private List<ElementCascaderVO> children;
}

25
lzbi-module/src/main/java/com/lzbi/bi/domain/ExportWeatherReq.java

@ -0,0 +1,25 @@
package com.lzbi.bi.domain;
import lombok.Data;
/**
* @ClassName ExportWeatherReq
* @Description 导出天气报表请求参数
* @Version 1.0
*/
@Data
public class ExportWeatherReq {
/**
* 省市区
*/
private String adcode;
/**
* 开始时间
*/
private String beginTime;
/**
* 结束时间
*/
private String endTime;
}

34
lzbi-module/src/main/java/com/lzbi/bi/mapper/LogTimeScaleThreeMapper.java

@ -1,12 +1,11 @@
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 com.lzbi.bi.domain.*;
import com.lzbi.code.domain.WeatherReportVO;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
@ -16,15 +15,32 @@ import java.util.Map;
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);
List<Map<String, String>> selectParamModels();
@MapKey("code")
List<Map<String, String>> selectDevices(Long orgCode);
/**
* 根据父级id查询下级地区--级联数据
*
* @param parentId
* @return
*/
List<ElementCascaderVO> selectAreaElementCascaderByParentId(@Param("parentId") Integer parentId);
/**
* 获取天气信息
*
* @param adcode
* @return
*/
List<WeatherReportVO> getWeatherReport(ExportWeatherReq exportWeatherReq);
}

10
lzbi-module/src/main/java/com/lzbi/bi/service/DcBusiDataScreenNewService.java

@ -92,19 +92,19 @@ public class DcBusiDataScreenNewService {
public List<BoilerStatisticsVO> getBoilerStatistics(TargetDraftDaynewReqVo vo) {
List<BoilerStatisticsVO> list = new ArrayList<>();
List<String> reportNames = Stream.of(ReportNameEnum.WATER_SUPPLY_TEMPERATURE.getName(), ReportNameEnum.RETURN_WATER_TEMPERATURE.getName()).collect(Collectors.toList());
List<String> reportNames = Stream.of(ReportNameEnum.NUMBER_OF_STEAM_FURNACES_IN_OPERATION.getName(), ReportNameEnum.NUMBER_OF_WATER_FURNACES_IN_OPERATION.getName()).collect(Collectors.toList());
vo.setAssetType("0").setAssetLevel("10").setReportNames(reportNames).setOrgIds(Stream.of(vo.getOrgId()).collect(Collectors.toList()));
List<TargetDraftDaynewResVo> targetDraftDaynewResVos = dcBusiTargetDraftDaynewService.selectTargetDraftDaynewList(vo);
if (CollUtil.isEmpty(targetDraftDaynewResVos)) {
return list;
}
list.add(BoilerStatisticsVO.builder()
.label(ReportNameEnum.WATER_SUPPLY_TEMPERATURE.getName())
.value(targetDraftDaynewResVos.stream().filter(x -> x.getReportName().equals(ReportNameEnum.WATER_SUPPLY_TEMPERATURE.getName())).findFirst().orElse(new TargetDraftDaynewResVo()).getValueResult())
.label(ReportNameEnum.NUMBER_OF_STEAM_FURNACES_IN_OPERATION.getName())
.value(targetDraftDaynewResVos.stream().filter(x -> x.getReportName().equals(ReportNameEnum.NUMBER_OF_STEAM_FURNACES_IN_OPERATION.getName())).findFirst().orElse(new TargetDraftDaynewResVo()).getValueResult())
.build());
list.add(BoilerStatisticsVO.builder()
.label(ReportNameEnum.RETURN_WATER_TEMPERATURE.getName())
.value(targetDraftDaynewResVos.stream().filter(x -> x.getReportName().equals(ReportNameEnum.RETURN_WATER_TEMPERATURE.getName())).findFirst().orElse(new TargetDraftDaynewResVo()).getValueResult())
.label(ReportNameEnum.NUMBER_OF_WATER_FURNACES_IN_OPERATION.getName())
.value(targetDraftDaynewResVos.stream().filter(x -> x.getReportName().equals(ReportNameEnum.NUMBER_OF_WATER_FURNACES_IN_OPERATION.getName())).findFirst().orElse(new TargetDraftDaynewResVo()).getValueResult())
.build());
return list;
}

29
lzbi-module/src/main/java/com/lzbi/code/domain/WeatherReportVO.java

@ -0,0 +1,29 @@
package com.lzbi.code.domain;
import com.lzbi.common.annotation.Excel;
import lombok.Data;
@Data
public class WeatherReportVO {
/**
* 时间
*/
@Excel(name = "时间")
private String timestampString;
/**
* 地区
*/
@Excel(name = "地区")
private String city;
/**
* 天气
*/
@Excel(name = "天气")
private String weather;
/**
* 温度
*/
@Excel(name = "温度")
private String temperature;
}

14
lzbi-module/src/main/java/com/lzbi/code/service/LogTimesacleHistoryThreeService.java

@ -4,11 +4,9 @@ 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.domain.*;
import com.lzbi.bi.mapper.LogTimeScaleThreeMapper;
import com.lzbi.code.domain.WeatherReportVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.MapKey;
import org.springframework.stereotype.Service;
@ -40,4 +38,12 @@ public class LogTimesacleHistoryThreeService extends ServiceImpl<LogTimeScaleThr
public List<Map<String,String>> selectDevices(Long orgCode){
return baseMapper.selectDevices(orgCode);
}
public List<ElementCascaderVO> selectAreaElementCascaderByParentId(Integer parentId){
return baseMapper.selectAreaElementCascaderByParentId(parentId);
}
public List<WeatherReportVO> getWeatherReport(ExportWeatherReq exportWeatherReq){
return baseMapper.getWeatherReport(exportWeatherReq);
}
}

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

@ -102,4 +102,34 @@
</if>
ORDER BY center_device_code asc
</select>
<select id="selectAreaElementCascaderByParentId" resultType="com.lzbi.bi.domain.ElementCascaderVO">
SELECT id as value,
name as label,
CASE
WHEN layer &lt; 3 THEN 0
ELSE 1
END
AS leaf
from dc_area
where parent_id =
#{parentId, jdbcType=NUMERIC}
ORDER
BY
sort_code
asc
</select>
<select id="getWeatherReport" parameterType="com.lzbi.bi.domain.ExportWeatherReq" resultType="com.lzbi.code.domain.WeatherReportVO">
SELECT to_char(reporttime, 'yyyy-MM-dd hh24') as timestampString,
MAX(city) as city,
MAX(weather) as weather,
MAX(temperature) as temperature
FROM "dc_busi_real_weather_hours"
WHERE adcode = #{adcode}
and reporttime BETWEEN to_timestamp(#{beginTime}, 'yyyy-MM-dd hh24:mi:ss')
and to_timestamp(#{endTime}, 'yyyy-MM-dd hh24:mi:ss')
GROUP BY timestampString
ORDER BY timestampString
</select>
</mapper>
Loading…
Cancel
Save