Browse Source

1、报表导出

develop
bobol 11 months ago
parent
commit
8a2ae4dd2b
  1. 12
      lzbi-admin/src/main/resources/application-dev.yml
  2. 9
      lzbi-admin/src/main/resources/application-test.yml
  3. 22
      lzbi-common/src/main/java/com/lzbi/common/constant/PartitionConstants.java
  4. 12
      lzbi-module/pom.xml
  5. 14
      lzbi-module/src/main/java/com/lzbi/bi/controller/DCVedioScreenControler.java
  6. 5
      lzbi-module/src/main/java/com/lzbi/bi/service/DcBusiDataScreenNewService.java
  7. 103
      lzbi-module/src/main/java/com/lzbi/draft/controller/ReportController.java
  8. 1
      lzbi-module/src/main/java/com/lzbi/draft/service/ReportService.java
  9. 54
      lzbi-module/src/main/java/com/lzbi/task/domain/DaTangGuanJingDataVO.java
  10. 50
      lzbi-module/src/main/java/com/lzbi/task/domain/MultipleDeviceDataVO.java
  11. 32
      lzbi-module/src/main/java/com/lzbi/task/domain/ReadQueryReq.java
  12. 63
      lzbi-module/src/main/java/com/lzbi/task/domain/SheetInfoBean.java
  13. 19
      lzbi-module/src/main/java/com/lzbi/task/domain/ThourWeatherVO.java
  14. 4
      lzbi-module/src/main/java/com/lzbi/task/mapper/WorkParamReadMapper.java
  15. 109
      lzbi-module/src/main/java/com/lzbi/task/service/WorkParamReadService.java
  16. 2
      lzbi-module/src/main/resources/mapper/asset/WorkParamReadMapper.xml

12
lzbi-admin/src/main/resources/application-dev.yml

@ -94,12 +94,12 @@ spring:
#url: jdbc:mysql://10.10.10.56:13306/lzdc_bi_db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
#username: luenmei
#password: 123456
#workDB:
#driverClassName: org.postgresql.Driver
#type: com.alibaba.druid.pool.DruidDataSource
#url: jdbc:postgresql://10.10.10.56:5432/dctestdb?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=Asia/Shanghai
#username: postgres
#password: 123456
workDB:
driverClassName: org.postgresql.Driver
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:postgresql://10.10.10.56:5432/dctestdb?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=Asia/Shanghai
username: postgres
password: 123456
primary: master
luenmeilz:
#视频设备监控地址

9
lzbi-admin/src/main/resources/application-test.yml

@ -98,7 +98,14 @@ spring:
username: postgres
password: 123456
primary: master
luenmeilz:
#视频设备监控地址
vedio-server:
url: http://10.10.10.40:18000
login: /api/v1/login?username={username}&password={password}
deviceList: /api/v1/devicesconfig?device={device}&start={start}&limit={limit}
channelList: /api/v1/channelsconfig?device={device}&start={start}&limit={limit}
channelStream: /api/v1/devices/channelstream?device={device}&channel={channel}&protocol={protocol}&Token={Token}&type={type}
# 日志配置
logging:
file:

22
lzbi-common/src/main/java/com/lzbi/common/constant/PartitionConstants.java

@ -0,0 +1,22 @@
package com.lzbi.common.constant;
import java.util.HashMap;
import java.util.Map;
public class PartitionConstants {
public static final Map<String, String> partition = new HashMap<>();
static {
partition.put("A", "低区");
partition.put("B", "中区");
partition.put("C", "高区");
partition.put("D", "别墅区");
partition.put("E", "商业区");
partition.put("F", "中高区");
partition.put("G", "空调低区");
partition.put("H", "空调高区");
partition.put("I", "厂房区");
partition.put("J", "办公区");
}
}

12
lzbi-module/pom.xml

@ -41,6 +41,18 @@
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel-core</artifactId>
<version>3.3.2</version>
</dependency>
<!-- Mysql驱动包 -->
<!-- <dependency>-->
<!-- <groupId>mysql</groupId>-->

14
lzbi-module/src/main/java/com/lzbi/bi/controller/DCVedioScreenControler.java

@ -120,10 +120,7 @@ public class DCVedioScreenControler extends BaseController {
ResponseEntity response = restTemplate.exchange(videoConfig.getDeviceList(), HttpMethod.GET, entity, JSONObject.class, query);
log.info("获取设备列表请求结果:{}", response);
JSONObject body = this.getBody((JSONObject) response.getBody());
if (null != body) {
return AjaxResult.success(body);
}
return AjaxResult.success(null);
return AjaxResult.success(body);
}
@ApiOperation("获取通道列表")
@ -151,10 +148,7 @@ public class DCVedioScreenControler extends BaseController {
ResponseEntity response = restTemplate.exchange(videoConfig.getChannelList(), HttpMethod.GET, entity, JSONObject.class, query);
log.info("获取通道列表请求结果:{}", response);
JSONObject body = this.getBody((JSONObject) response.getBody());
if (null != body) {
return AjaxResult.success(body);
}
return AjaxResult.success(null);
return AjaxResult.success(body);
}
@ApiOperation(value = "获取设备通道直播链接(具有保活功能,建议按需模式25s-30s调用一次)")
@ -186,9 +180,9 @@ public class DCVedioScreenControler extends BaseController {
log.info("获取设备通道直播链接请求结果:{}", response);
JSONObject body = this.getBody((JSONObject) response.getBody());
if (null != body) {
return AjaxResult.success(body);
body.put("LiveAddress", videoConfig.getUrl());
}
return AjaxResult.success(null);
return AjaxResult.success(body);
}
private JSONObject getBody(JSONObject resp) {

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

@ -108,9 +108,6 @@ public class DcBusiDataScreenNewService {
public List<BoilerStatisticsVO> getBoilerStatistics(DcBusDataScreenNewReq dcBusDataScreenNewReq) {
List<BoilerStatisticsVO> list = new ArrayList<>();
// list.add(new BoilerStatisticsVO("热源1", BigDecimal.valueOf(248776)));
// list.add(new BoilerStatisticsVO("热源2", BigDecimal.valueOf(248776)));
// list.add(new BoilerStatisticsVO("热源3", BigDecimal.valueOf(248776)));
DcBusiTargetDraftMonth params = new DcBusiTargetDraftMonth();
BeanUtils.copyBeanProp(params, dcBusDataScreenNewReq);
String yearMonthDay = dcBusDataScreenNewReq.getYearMonthDay();
@ -137,7 +134,7 @@ public class DcBusiDataScreenNewService {
}
BigDecimal sum = new BigDecimal(0);
for (int i = 0, len = value.size(); i < len; i++) {
sum = sum.add(value.get(i).getValOriginal());
sum = sum.add(value.get(i).getValResult());
}
boilerStatisticsVO.setValue(sum);
list.add(boilerStatisticsVO);

103
lzbi-module/src/main/java/com/lzbi/draft/controller/ReportController.java

@ -1,22 +1,31 @@
package com.lzbi.draft.controller;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.lzbi.common.config.RuoYiConfig;
import com.lzbi.common.core.controller.BaseController;
import com.lzbi.common.core.domain.AjaxResult;
import com.lzbi.draft.entity.req.TargetDraftMonthReportReq;
import com.lzbi.draft.entity.vo.TargetDraftMonthReportVO;
import com.lzbi.draft.service.ReportService;
import com.lzbi.task.domain.DaTangGuanJingDataVO;
import com.lzbi.task.domain.MultipleDeviceDataVO;
import com.lzbi.task.domain.ReadQueryParams;
import com.lzbi.task.domain.ThourWeatherVO;
import com.lzbi.task.domain.*;
import com.lzbi.task.service.WorkParamReadService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
/**
* 报表Controller
@ -24,6 +33,7 @@ import java.util.List;
* @author lienbo
* @date 2023-12-12
*/
@Slf4j
@RestController
@RequestMapping("/report")
public class ReportController extends BaseController {
@ -34,38 +44,105 @@ public class ReportController extends BaseController {
@Autowired
private WorkParamReadService workParamReadService;
@Autowired
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
@Autowired
private RuoYiConfig ruoYiConfig;
@GetMapping("/targetDraftMonthReport")
public List<TargetDraftMonthReportVO> targetDraftMonthReport(TargetDraftMonthReportReq targetDraftMonthReportReq) {
return reportService.getTargetDraftMonthReport(targetDraftMonthReportReq);
}
@GetMapping("/export")
public Map<String, SheetInfoBean> export(ReadQueryReq readQueryReq) {
CountDownLatch countDownLatch = new CountDownLatch(3);
// 构造各个sheet页相关信息
Map<String, SheetInfoBean> map = new ConcurrentHashMap();
threadPoolTaskExecutor.execute(() -> {
List<MultipleDeviceDataVO> multipleDeviceData = workParamReadService.getMultipleDeviceData(readQueryReq);
map.put("s1", new SheetInfoBean("多设备", MultipleDeviceDataVO.class, multipleDeviceData));
countDownLatch.countDown();
});
threadPoolTaskExecutor.execute(() -> {
List<ThourWeatherVO> thourWeather = workParamReadService.getThourWeather(readQueryReq);
map.put("s3", new SheetInfoBean("天气", ThourWeatherVO.class, thourWeather));
countDownLatch.countDown();
});
try {
Thread.sleep(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
threadPoolTaskExecutor.execute(() -> {
List<DaTangGuanJingDataVO> daTangGuanJingDataVO = workParamReadService.getDaTangGuanJingDataVO(readQueryReq);
map.put("s2", new SheetInfoBean("大唐管井", DaTangGuanJingDataVO.class, daTangGuanJingDataVO));
countDownLatch.countDown();
});
try {
countDownLatch.await();
} catch (InterruptedException e) {
log.error("门闩异常", e);
}
String filePath = ruoYiConfig.getProfile() + "/数据报表_" + System.currentTimeMillis() + ".xlsx";
log.info("文件路径:{}", filePath);
// 导出文件
File file = new File(filePath);
try {
file.createNewFile();
} catch (IOException e) {
throw new RuntimeException(e);
}
try(ExcelWriter excelWriter = EasyExcel.write(file).build()) {
WriteSheet writeSheet;
// 构建sheet对象
writeSheet = EasyExcel.writerSheet(map.get("s1").getSheetName()).head(map.get("s1").getHeadClass()).build();
// 写出sheet数据
excelWriter.write(map.get("s1").getDataList(), writeSheet);
// 构建sheet对象
writeSheet = EasyExcel.writerSheet(map.get("s2").getSheetName()).head(map.get("s2").getHeadClass()).build();
// 写出sheet数据
excelWriter.write(map.get("s2").getDataList(), writeSheet);
// 构建sheet对象
writeSheet = EasyExcel.writerSheet(map.get("s3").getSheetName()).head(map.get("s3").getHeadClass()).build();
// 写出sheet数据
excelWriter.write(map.get("s3").getDataList(), writeSheet);
// 关流
excelWriter.finish();
} catch (Exception e) {
log.error("导出excel失败", e);
}
return map;
}
/**
* 获取数据
* @param readQueryParams
* @param readQueryReq
* @return
*/
@GetMapping("/multipleDeviceData")
public List<MultipleDeviceDataVO> getMultipleDeviceData(@Validated ReadQueryParams readQueryParams) {
return workParamReadService.getMultipleDeviceData(readQueryParams);
public List<MultipleDeviceDataVO> getMultipleDeviceData(@Validated ReadQueryReq readQueryReq) {
return workParamReadService.getMultipleDeviceData(readQueryReq);
}
/**
* 获取数据
* @param readQueryParams
* @param readQueryReq
* @return
*/
@GetMapping("/daTangGuanJingData")
public List<DaTangGuanJingDataVO> getDaTangGuanJingDataVO(@Validated ReadQueryParams readQueryParams) {
return workParamReadService.getDaTangGuanJingDataVO(readQueryParams);
public List<DaTangGuanJingDataVO> getDaTangGuanJingDataVO(@Validated ReadQueryReq readQueryReq) {
return workParamReadService.getDaTangGuanJingDataVO(readQueryReq);
}
/**
* 获取小时天气
* @param readQueryParams
* @param readQueryReq
* @return
*/
@GetMapping("/thourWeather")
public List<ThourWeatherVO> getThourWeather(@Validated ReadQueryParams readQueryParams) {
return workParamReadService.getThourWeather(readQueryParams);
public List<ThourWeatherVO> getThourWeather(@Validated ReadQueryReq readQueryReq) {
return workParamReadService.getThourWeather(readQueryReq);
}
}

1
lzbi-module/src/main/java/com/lzbi/draft/service/ReportService.java

@ -64,4 +64,5 @@ public class ReportService {
}
return list;
}
}

54
lzbi-module/src/main/java/com/lzbi/task/domain/DaTangGuanJingDataVO.java

@ -1,75 +1,99 @@
package com.lzbi.task.domain;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentStyle;
import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum;
import com.alibaba.excel.enums.poi.VerticalAlignmentEnum;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@ContentStyle(verticalAlignment = VerticalAlignmentEnum.CENTER, horizontalAlignment = HorizontalAlignmentEnum.CENTER)
@ColumnWidth(20)
@Data
public class DaTangGuanJingDataVO {
/**
* 设备编码
*/
@ExcelProperty("站名")
private String deviceName;
/**
* 分区
*/
// @ExcelProperty("分区")
@ExcelIgnore
private String partion;
/**
* 统计时间
*/
@ExcelProperty("统计时间")
@JsonFormat(pattern = "yyyy-MM-dd HH")
private Date thour;
/**
* 瞬时流量
*/
@ExcelProperty("瞬时流量")
private Double ssll;
/**
* 累计热量
* 瞬时热量
*/
@ExcelProperty("瞬时热量")
private Double ssrl;
/**
* 一网供温
*/
@ExcelProperty("一网供温")
private Double ywgw;
/**
* 一网回温
*/
@ExcelProperty("一网回温")
private Double ywhw;
/**
* 一网供压
*/
@ExcelProperty("一网供压")
private Double ywgy;
/**
* 一网回压
*/
@ExcelProperty("一网回压")
private Double ywhy;
/**
* 供水流量
*/
@ExcelProperty("供水流量")
private Double gsll;
/**
* 回水流量
*/
@ExcelProperty("回水流量")
private Double hsll;
/**
* 瞬时补水
*/
@ExcelProperty("瞬时补水")
private Double ssbs;
/**
* 累计补水
*/
@ExcelProperty("累计补水")
private Double ljbs;
/**
* 阀门给定
*/
@ExcelProperty("阀门给定")
private Double fmgd;
/**
* 阀门反馈
*/
@ExcelProperty("阀门反馈")
private Double fmfk;
/**
* 设备编码
*/
private String deviceName;
/**
* 分区
*/
private String partion;
/**
* 统计时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH")
private Date thour;
public DaTangGuanJingDataVO() {
this.ssll = 0D;

50
lzbi-module/src/main/java/com/lzbi/task/domain/MultipleDeviceDataVO.java

@ -1,75 +1,97 @@
package com.lzbi.task.domain;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentStyle;
import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum;
import com.alibaba.excel.enums.poi.VerticalAlignmentEnum;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@ContentStyle(verticalAlignment = VerticalAlignmentEnum.CENTER, horizontalAlignment = HorizontalAlignmentEnum.CENTER)
@ColumnWidth(20)
@Data
public class MultipleDeviceDataVO {
/**
* 设备编码
*/
@ExcelProperty("站名")
private String deviceName;
/**
* 分区
*/
@ExcelProperty("分区")
private String partion;
/**
* 统计时间
*/
@ExcelProperty("统计时间")
@JsonFormat(pattern = "yyyy-MM-dd HH")
private Date thour;
/**
* 瞬时流量
*/
@ExcelProperty("瞬时流量")
private Double ssll;
/**
* 累计热量
* 顺时热量
*/
@ExcelProperty("顺时热量")
private Double ssrl;
/**
* 一网供温
*/
@ExcelProperty("一网供温")
private Double ywgw;
/**
* 一网回温
*/
@ExcelProperty("一网回温")
private Double ywhw;
/**
* 一网供压
*/
@ExcelProperty("一网供压")
private Double ywgy;
/**
* 一网回压
*/
@ExcelProperty("一网回压")
private Double ywhy;
/**
* 二网供温
*/
@ExcelProperty("二网供温")
private Double ewgw;
/**
* 二网回温
*/
@ExcelProperty("二网回温")
private Double ewhw;
/**
* 二网供压
*/
@ExcelProperty("二网供压")
private Double ewgy;
/**
* 二网回压
*/
@ExcelProperty("二网回压")
private Double ewhy;
/**
* 阀门给定
*/
@ExcelProperty("阀门给定")
private Double fmgd;
/**
* 阀门反馈
*/
@ExcelProperty("阀门反馈")
private Double fmfk;
/**
* 设备编码
*/
private String deviceName;
/**
* 分区
*/
private String partion;
/**
* 统计时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH")
private Date thour;
public MultipleDeviceDataVO() {
this.ssll = 0D;

32
lzbi-module/src/main/java/com/lzbi/task/domain/ReadQueryReq.java

@ -0,0 +1,32 @@
package com.lzbi.task.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;
/**
* @auth create by Administrator
* @date 2023/11/30
* ReadQueryParams
*/
@Data
public class ReadQueryReq {
@NotNull(message = "请输入起始时间")
@JsonFormat(pattern = "yyyy-MM-dd HH")
@DateTimeFormat(pattern = "yyyy-MM-dd HH")
private String beginTime;
@NotNull(message = "请输入结束时间")
@JsonFormat(pattern = "yyyy-MM-dd HH")
@DateTimeFormat(pattern = "yyyy-MM-dd HH")
private String endTime;
private List<String> deviceCodes;
private List<String> paramCodes;
}

63
lzbi-module/src/main/java/com/lzbi/task/domain/SheetInfoBean.java

@ -0,0 +1,63 @@
package com.lzbi.task.domain;
import java.util.List;
public class SheetInfoBean {
/**
* sheet页名称
*/
private String sheetName;
/**
* sheet标题bean
*/
private Class<?> headClass;
/**
* sheet页数据
*/
private List<?> dataList;
public SheetInfoBean() {
}
public SheetInfoBean(String sheetName, Class<?> headClass, List<?> dataList) {
this.sheetName = sheetName;
this.headClass = headClass;
this.dataList = dataList;
}
public String getSheetName() {
return sheetName;
}
public void setSheetName(String sheetName) {
this.sheetName = sheetName;
}
public Class<?> getHeadClass() {
return headClass;
}
public void setHeadClass(Class<?> headClass) {
this.headClass = headClass;
}
public List<?> getDataList() {
return dataList;
}
public void setDataList(List<?> dataList) {
this.dataList = dataList;
}
@Override
public String toString() {
return "SheetInfoBean{" +
"sheetName='" + sheetName + '\'' +
", headClass=" + headClass +
", dataList=" + dataList +
'}';
}
}

19
lzbi-module/src/main/java/com/lzbi/task/domain/ThourWeatherVO.java

@ -1,26 +1,37 @@
package com.lzbi.task.domain;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentStyle;
import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum;
import com.alibaba.excel.enums.poi.VerticalAlignmentEnum;
import lombok.Data;
import java.util.Date;
@ContentStyle(verticalAlignment = VerticalAlignmentEnum.CENTER, horizontalAlignment = HorizontalAlignmentEnum.CENTER)
@ColumnWidth(20)
@Data
public class ThourWeatherVO {
/**
* 城市
*/
@ExcelProperty("区域")
private String city;
/**
* 时间
*/
@ExcelProperty("时间")
private String thour;
/**
* 天气
*/
@ExcelProperty("天气")
private String weather;
/**
* 温度
*/
@ExcelProperty("气温")
private Double temperature;
/**
* 时间
*/
private String thour;
}

4
lzbi-module/src/main/java/com/lzbi/task/mapper/WorkParamReadMapper.java

@ -16,7 +16,7 @@ public interface WorkParamReadMapper extends BaseMapper<WorkParamInfo>
{
public List<DcBusiWorkReadLog> readWorkValue(ReadQueryParams readQueryParams);
List<WorkDataDTO> readWorkData (ReadQueryParams readQueryParams);
List<WorkDataDTO> readWorkData (ReadQueryReq readQueryReq);
List<ThourWeatherVO> getThourWeather(ReadQueryParams readQueryParams);
List<ThourWeatherVO> getThourWeather(ReadQueryReq readQueryReq);
}

109
lzbi-module/src/main/java/com/lzbi/task/service/WorkParamReadService.java

@ -1,18 +1,34 @@
package com.lzbi.task.service;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.fastjson2.JSONArray;
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.common.config.RuoYiConfig;
import com.lzbi.common.constant.PartitionConstants;
import com.lzbi.draft.entity.req.TargetDraftMonthReportReq;
import com.lzbi.draft.entity.vo.TargetDraftMonthReportVO;
import com.lzbi.task.domain.*;
import com.lzbi.task.mapper.WorkParamReadMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.io.File;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.stream.Collectors;
@ -27,24 +43,61 @@ import java.util.stream.Collectors;
@Slf4j
public class WorkParamReadService extends ServiceImpl<WorkParamReadMapper, WorkParamInfo> implements IService<WorkParamInfo> {
@Autowired
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
/*获取生产单元的参数读取配置
* */
public List<DcBusiWorkReadLog> readWorkValue(ReadQueryParams readQueryParams) {
return baseMapper.readWorkValue(readQueryParams);
}
public List<MultipleDeviceDataVO> getMultipleDeviceData(ReadQueryParams readQueryParams) {
String[] DEVICE_CODE_ARR = new String[]{"00011","00053","00054","00050","00055","00051","00052","00059","00056","00057","00022","00023","00024","00009","00058","00026","00029","00030","00031","00032","00044","00013","00007","00017","00046","00042","00019","00016","00001","00028","00045","00021","00010","00041","00015","00014","00005","00006","00002","00003","00004","00008","00018","00027","00043","00020","00040"};
String[] PARAM_CODE_ARR = new String[]{"007", "009", "011", "012", "013", "014", "045", "046", "047", "048", "028", "029"};
readQueryParams.setParamCodes(Arrays.asList(PARAM_CODE_ARR));
readQueryParams.setDeviceCodes(Arrays.asList(DEVICE_CODE_ARR));
private List<String> splitByDay(String startDateStr, String endDateStr) {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH");
LocalDateTime startDate = LocalDateTime.parse(startDateStr, dateTimeFormatter);
LocalDateTime endDate = LocalDateTime.parse(endDateStr, dateTimeFormatter);
List<String> dateRange = new ArrayList<>();
while (!startDate.isAfter(endDate)) {
dateRange.add(dateTimeFormatter.format(startDate));
startDate = startDate.plusDays(1);
}
dateRange.add(endDateStr);
return dateRange;
}
public List<MultipleDeviceDataVO> getMultipleDeviceData(ReadQueryReq readQueryReq) {
Vector<MultipleDeviceDataVO> list = new Vector<>();
Class<MultipleDeviceDataVO> clazz = MultipleDeviceDataVO.class;
Field[] fields = clazz.getDeclaredFields();
List<MultipleDeviceDataVO> list = new ArrayList<>();
List<WorkDataDTO> workDataDTOS = baseMapper.readWorkData(readQueryParams);
String[] DEVICE_CODE_ARR = new String[]{"00011","00053","00054","00050","00055","00051","00052","00059","00056","00057","00022","00023","00024","00009","00058","00026","00029","00030","00031","00032","00044","00013","00007","00017","00046","00042","00019","00016","00001","00028","00045","00021","00010","00041","00015","00014","00005","00006","00002","00003","00004","00008","00018","00027","00043","00020","00040"};
String[] PARAM_CODE_ARR = new String[]{"007", "009", "011", "012", "013", "014", "045", "046", "047", "048", "028", "029"};
List<WorkDataDTO> workDataDTOS = new LinkedList<>();
List<String> dateList = this.splitByDay(readQueryReq.getBeginTime(), readQueryReq.getEndTime());
int size = dateList.size() - 1;
CountDownLatch countDownLatch = new CountDownLatch(size);
for (int i = 0; i < size; i++) {
ReadQueryReq req = new ReadQueryReq();
req.setBeginTime(dateList.get(i));
req.setEndTime(dateList.get(i + 1));
req.setParamCodes(Arrays.asList(PARAM_CODE_ARR));
req.setDeviceCodes(Arrays.asList(DEVICE_CODE_ARR));
threadPoolTaskExecutor.execute(() -> {
workDataDTOS.addAll(baseMapper.readWorkData(req));
log.info("{}~{} 执行成功", req.getBeginTime(), req.getEndTime());
countDownLatch.countDown();
});
}
try {
countDownLatch.await();
} catch (InterruptedException e) {
log.error("门闩异常", e);
}
if (!CollectionUtils.isEmpty(workDataDTOS)) {
Map<Date, List<WorkDataDTO>> timeMap = workDataDTOS.stream().collect(Collectors.groupingBy(WorkDataDTO::getThour));
timeMap.forEach((key, value) -> {
Set<Date> keySet = timeMap.keySet();
List<Date> keyList = keySet.stream().sorted().collect(Collectors.toList());
keyList.forEach(key -> {
List<WorkDataDTO> value = timeMap.get(key);
Map<String, List<WorkDataDTO>> deviceMap = value.stream().collect(Collectors.groupingBy(WorkDataDTO::getDeviceCode));
for (String deviceCode : DEVICE_CODE_ARR) {
if (deviceMap.containsKey(deviceCode)) {
@ -55,11 +108,11 @@ public class WorkParamReadService extends ServiceImpl<WorkParamReadMapper, WorkP
MultipleDeviceDataVO multipleDeviceDataVO = new MultipleDeviceDataVO();
multipleDeviceDataVO.setThour(key);
multipleDeviceDataVO.setDeviceName(deviceMap.get(deviceCode).get(0).getDeviceName());
multipleDeviceDataVO.setPartion(p);
multipleDeviceDataVO.setPartion(PartitionConstants.partition.get(p));
for (int i = 0, len = PARAM_CODE_ARR.length; i < len; i++) {
try {
if (!fields[i].isAccessible()) {
fields[i].setAccessible(true);
if (!fields[i + 3].isAccessible()) {
fields[i + 3].setAccessible(true);
}
List<WorkDataDTO> workDataDTOList1 = paramModelMap.get(PARAM_CODE_ARR[i]);
if (!CollectionUtils.isEmpty(workDataDTOList1)) {
@ -77,7 +130,7 @@ public class WorkParamReadService extends ServiceImpl<WorkParamReadMapper, WorkP
if (null != v && !Double.isNaN(v)) {
v = BigDecimal.valueOf(v).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
fields[i].set(multipleDeviceDataVO, v);
fields[i + 3].set(multipleDeviceDataVO, v);
}
}
} catch (IllegalAccessException e) {
@ -90,21 +143,25 @@ public class WorkParamReadService extends ServiceImpl<WorkParamReadMapper, WorkP
}
});
}
log.info("多设备:{}", list);
return list;
}
public List<DaTangGuanJingDataVO> getDaTangGuanJingDataVO(ReadQueryParams readQueryParams) {
public List<DaTangGuanJingDataVO> getDaTangGuanJingDataVO(ReadQueryReq readQueryReq) {
String[] DEVICE_CODE_ARR = new String[]{"00033"};
String[] PARAM_CODE_ARR = new String[]{"007", "009", "011", "012", "013", "014", "049", "054", "030", "031", "028", "029"};
readQueryParams.setParamCodes(Arrays.asList(PARAM_CODE_ARR));
readQueryParams.setDeviceCodes(Arrays.asList(DEVICE_CODE_ARR));
readQueryReq.setParamCodes(Arrays.asList(PARAM_CODE_ARR));
readQueryReq.setDeviceCodes(Arrays.asList(DEVICE_CODE_ARR));
Class<DaTangGuanJingDataVO> clazz = DaTangGuanJingDataVO.class;
Field[] fields = clazz.getDeclaredFields();
List<DaTangGuanJingDataVO> list = new ArrayList<>();
List<WorkDataDTO> workDataDTOS = baseMapper.readWorkData(readQueryParams);
Vector<DaTangGuanJingDataVO> list = new Vector<>();
List<WorkDataDTO> workDataDTOS = baseMapper.readWorkData(readQueryReq);
if (!CollectionUtils.isEmpty(workDataDTOS)) {
Map<Date, List<WorkDataDTO>> timeMap = workDataDTOS.stream().collect(Collectors.groupingBy(WorkDataDTO::getThour));
timeMap.forEach((key, value) -> {
Set<Date> keySet = timeMap.keySet();
List<Date> keyList = keySet.stream().sorted().collect(Collectors.toList());
keyList.forEach(key -> {
List<WorkDataDTO> value = timeMap.get(key);
Map<String, List<WorkDataDTO>> deviceMap = value.stream().collect(Collectors.groupingBy(WorkDataDTO::getDeviceCode));
for (String deviceCode : DEVICE_CODE_ARR) {
if (deviceMap.containsKey(deviceCode)) {
@ -115,11 +172,11 @@ public class WorkParamReadService extends ServiceImpl<WorkParamReadMapper, WorkP
DaTangGuanJingDataVO daTangGuanJingDataVO = new DaTangGuanJingDataVO();
daTangGuanJingDataVO.setThour(key);
daTangGuanJingDataVO.setDeviceName(deviceMap.get(deviceCode).get(0).getDeviceName());
daTangGuanJingDataVO.setPartion(p);
daTangGuanJingDataVO.setPartion(PartitionConstants.partition.get(p));
for (int i = 0, len = PARAM_CODE_ARR.length; i < len; i++) {
try {
if (!fields[i].isAccessible()) {
fields[i].setAccessible(true);
if (!fields[i + 3].isAccessible()) {
fields[i + 3].setAccessible(true);
}
List<WorkDataDTO> workDataDTOList1 = paramModelMap.get(PARAM_CODE_ARR[i]);
if (!CollectionUtils.isEmpty(workDataDTOList1)) {
@ -136,7 +193,7 @@ public class WorkParamReadService extends ServiceImpl<WorkParamReadMapper, WorkP
}
if (null != v && !Double.isNaN(v)) {
v = BigDecimal.valueOf(v).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
fields[i].set(daTangGuanJingDataVO, v);
fields[i + 3].set(daTangGuanJingDataVO, v);
}
}
} catch (IllegalAccessException e) {
@ -149,10 +206,14 @@ public class WorkParamReadService extends ServiceImpl<WorkParamReadMapper, WorkP
}
});
}
log.info("大唐管井:{}", list);
return list;
}
public List<ThourWeatherVO> getThourWeather(ReadQueryParams readQueryParams) {
return baseMapper.getThourWeather(readQueryParams);
public List<ThourWeatherVO> getThourWeather(ReadQueryReq readQueryReq) {
List<ThourWeatherVO> list = baseMapper.getThourWeather(readQueryReq);
log.info("天气:{}", list);
return list;
}
}

2
lzbi-module/src/main/resources/mapper/asset/WorkParamReadMapper.xml

@ -65,7 +65,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
t4.partion,
time_bucket ( '1 HOUR', t1.timestamp_key ) AS thour,
SUM ( CASE WHEN t1.param_value_num > 0.00 THEN t1.param_value_num ELSE 0 END ) AS total,
COUNT ( * ) AS countsall,
COUNT ( 1 ) AS countsall,
SUM ( CASE WHEN t1.param_value_num > 0.00 THEN 1 ELSE 0 END ) AS countsz,
MAX ( t1.param_value_num ) AS maxVal,
FIRST ( t1.param_value_num, timestamp_key ) AS firstVal,

Loading…
Cancel
Save