diff --git a/lzbi-admin/src/main/resources/application-dev.yml b/lzbi-admin/src/main/resources/application-dev.yml index 370f5a0..2be7870 100644 --- a/lzbi-admin/src/main/resources/application-dev.yml +++ b/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: #视频设备监控地址 diff --git a/lzbi-admin/src/main/resources/application-test.yml b/lzbi-admin/src/main/resources/application-test.yml index ebaed55..38b7627 100644 --- a/lzbi-admin/src/main/resources/application-test.yml +++ b/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: diff --git a/lzbi-common/src/main/java/com/lzbi/common/constant/PartitionConstants.java b/lzbi-common/src/main/java/com/lzbi/common/constant/PartitionConstants.java new file mode 100644 index 0000000..39bd010 --- /dev/null +++ b/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 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", "办公区"); + } +} diff --git a/lzbi-module/pom.xml b/lzbi-module/pom.xml index a306c99..daa10ca 100644 --- a/lzbi-module/pom.xml +++ b/lzbi-module/pom.xml @@ -41,6 +41,18 @@ 1.6.2 + + com.alibaba + easyexcel + 3.3.2 + + + com.alibaba + easyexcel-core + 3.3.2 + + + diff --git a/lzbi-module/src/main/java/com/lzbi/bi/controller/DCVedioScreenControler.java b/lzbi-module/src/main/java/com/lzbi/bi/controller/DCVedioScreenControler.java index 9132ba2..ff62673 100644 --- a/lzbi-module/src/main/java/com/lzbi/bi/controller/DCVedioScreenControler.java +++ b/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) { diff --git a/lzbi-module/src/main/java/com/lzbi/bi/service/DcBusiDataScreenNewService.java b/lzbi-module/src/main/java/com/lzbi/bi/service/DcBusiDataScreenNewService.java index 52f105c..76659ea 100644 --- a/lzbi-module/src/main/java/com/lzbi/bi/service/DcBusiDataScreenNewService.java +++ b/lzbi-module/src/main/java/com/lzbi/bi/service/DcBusiDataScreenNewService.java @@ -108,9 +108,6 @@ public class DcBusiDataScreenNewService { public List getBoilerStatistics(DcBusDataScreenNewReq dcBusDataScreenNewReq) { List 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); diff --git a/lzbi-module/src/main/java/com/lzbi/draft/controller/ReportController.java b/lzbi-module/src/main/java/com/lzbi/draft/controller/ReportController.java index 77a768b..93b97b5 100644 --- a/lzbi-module/src/main/java/com/lzbi/draft/controller/ReportController.java +++ b/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 targetDraftMonthReport(TargetDraftMonthReportReq targetDraftMonthReportReq) { return reportService.getTargetDraftMonthReport(targetDraftMonthReportReq); } + @GetMapping("/export") + public Map export(ReadQueryReq readQueryReq) { + CountDownLatch countDownLatch = new CountDownLatch(3); + // 构造各个sheet页相关信息 + Map map = new ConcurrentHashMap(); + threadPoolTaskExecutor.execute(() -> { + List multipleDeviceData = workParamReadService.getMultipleDeviceData(readQueryReq); + map.put("s1", new SheetInfoBean("多设备", MultipleDeviceDataVO.class, multipleDeviceData)); + countDownLatch.countDown(); + }); + threadPoolTaskExecutor.execute(() -> { + List 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 = 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 getMultipleDeviceData(@Validated ReadQueryParams readQueryParams) { - return workParamReadService.getMultipleDeviceData(readQueryParams); + public List getMultipleDeviceData(@Validated ReadQueryReq readQueryReq) { + return workParamReadService.getMultipleDeviceData(readQueryReq); } /** * 获取数据 - * @param readQueryParams + * @param readQueryReq * @return */ @GetMapping("/daTangGuanJingData") - public List getDaTangGuanJingDataVO(@Validated ReadQueryParams readQueryParams) { - return workParamReadService.getDaTangGuanJingDataVO(readQueryParams); + public List getDaTangGuanJingDataVO(@Validated ReadQueryReq readQueryReq) { + return workParamReadService.getDaTangGuanJingDataVO(readQueryReq); } /** * 获取小时天气 - * @param readQueryParams + * @param readQueryReq * @return */ @GetMapping("/thourWeather") - public List getThourWeather(@Validated ReadQueryParams readQueryParams) { - return workParamReadService.getThourWeather(readQueryParams); + public List getThourWeather(@Validated ReadQueryReq readQueryReq) { + return workParamReadService.getThourWeather(readQueryReq); } } diff --git a/lzbi-module/src/main/java/com/lzbi/draft/service/ReportService.java b/lzbi-module/src/main/java/com/lzbi/draft/service/ReportService.java index 3dc9232..a59ceb9 100644 --- a/lzbi-module/src/main/java/com/lzbi/draft/service/ReportService.java +++ b/lzbi-module/src/main/java/com/lzbi/draft/service/ReportService.java @@ -64,4 +64,5 @@ public class ReportService { } return list; } + } diff --git a/lzbi-module/src/main/java/com/lzbi/task/domain/DaTangGuanJingDataVO.java b/lzbi-module/src/main/java/com/lzbi/task/domain/DaTangGuanJingDataVO.java index b4ed612..77e76ca 100644 --- a/lzbi-module/src/main/java/com/lzbi/task/domain/DaTangGuanJingDataVO.java +++ b/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; diff --git a/lzbi-module/src/main/java/com/lzbi/task/domain/MultipleDeviceDataVO.java b/lzbi-module/src/main/java/com/lzbi/task/domain/MultipleDeviceDataVO.java index a91c6e9..1b8f816 100644 --- a/lzbi-module/src/main/java/com/lzbi/task/domain/MultipleDeviceDataVO.java +++ b/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; diff --git a/lzbi-module/src/main/java/com/lzbi/task/domain/ReadQueryReq.java b/lzbi-module/src/main/java/com/lzbi/task/domain/ReadQueryReq.java new file mode 100644 index 0000000..d578ac8 --- /dev/null +++ b/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 deviceCodes; + + private List paramCodes; +} diff --git a/lzbi-module/src/main/java/com/lzbi/task/domain/SheetInfoBean.java b/lzbi-module/src/main/java/com/lzbi/task/domain/SheetInfoBean.java new file mode 100644 index 0000000..c515a69 --- /dev/null +++ b/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 + + '}'; + } +} diff --git a/lzbi-module/src/main/java/com/lzbi/task/domain/ThourWeatherVO.java b/lzbi-module/src/main/java/com/lzbi/task/domain/ThourWeatherVO.java index ae70cea..c83ab16 100644 --- a/lzbi-module/src/main/java/com/lzbi/task/domain/ThourWeatherVO.java +++ b/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; } diff --git a/lzbi-module/src/main/java/com/lzbi/task/mapper/WorkParamReadMapper.java b/lzbi-module/src/main/java/com/lzbi/task/mapper/WorkParamReadMapper.java index a727348..c61d016 100644 --- a/lzbi-module/src/main/java/com/lzbi/task/mapper/WorkParamReadMapper.java +++ b/lzbi-module/src/main/java/com/lzbi/task/mapper/WorkParamReadMapper.java @@ -16,7 +16,7 @@ public interface WorkParamReadMapper extends BaseMapper { public List readWorkValue(ReadQueryParams readQueryParams); - List readWorkData (ReadQueryParams readQueryParams); + List readWorkData (ReadQueryReq readQueryReq); - List getThourWeather(ReadQueryParams readQueryParams); + List getThourWeather(ReadQueryReq readQueryReq); } diff --git a/lzbi-module/src/main/java/com/lzbi/task/service/WorkParamReadService.java b/lzbi-module/src/main/java/com/lzbi/task/service/WorkParamReadService.java index 0b32836..5beed12 100644 --- a/lzbi-module/src/main/java/com/lzbi/task/service/WorkParamReadService.java +++ b/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 implements IService { + @Autowired + private ThreadPoolTaskExecutor threadPoolTaskExecutor; + /*获取生产单元的参数读取配置 * */ public List readWorkValue(ReadQueryParams readQueryParams) { return baseMapper.readWorkValue(readQueryParams); } - public List 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 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 dateRange = new ArrayList<>(); + while (!startDate.isAfter(endDate)) { + dateRange.add(dateTimeFormatter.format(startDate)); + startDate = startDate.plusDays(1); + } + dateRange.add(endDateStr); + return dateRange; + } + + public List getMultipleDeviceData(ReadQueryReq readQueryReq) { + Vector list = new Vector<>(); Class clazz = MultipleDeviceDataVO.class; Field[] fields = clazz.getDeclaredFields(); - List list = new ArrayList<>(); - List 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 workDataDTOS = new LinkedList<>(); + List 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> timeMap = workDataDTOS.stream().collect(Collectors.groupingBy(WorkDataDTO::getThour)); - timeMap.forEach((key, value) -> { + Set keySet = timeMap.keySet(); + List keyList = keySet.stream().sorted().collect(Collectors.toList()); + keyList.forEach(key -> { + List value = timeMap.get(key); Map> 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 workDataDTOList1 = paramModelMap.get(PARAM_CODE_ARR[i]); if (!CollectionUtils.isEmpty(workDataDTOList1)) { @@ -77,7 +130,7 @@ public class WorkParamReadService extends ServiceImpl getDaTangGuanJingDataVO(ReadQueryParams readQueryParams) { + public List 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 clazz = DaTangGuanJingDataVO.class; Field[] fields = clazz.getDeclaredFields(); - List list = new ArrayList<>(); - List workDataDTOS = baseMapper.readWorkData(readQueryParams); + Vector list = new Vector<>(); + List workDataDTOS = baseMapper.readWorkData(readQueryReq); if (!CollectionUtils.isEmpty(workDataDTOS)) { Map> timeMap = workDataDTOS.stream().collect(Collectors.groupingBy(WorkDataDTO::getThour)); - timeMap.forEach((key, value) -> { + Set keySet = timeMap.keySet(); + List keyList = keySet.stream().sorted().collect(Collectors.toList()); + keyList.forEach(key -> { + List value = timeMap.get(key); Map> 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 workDataDTOList1 = paramModelMap.get(PARAM_CODE_ARR[i]); if (!CollectionUtils.isEmpty(workDataDTOList1)) { @@ -136,7 +193,7 @@ public class WorkParamReadService extends ServiceImpl getThourWeather(ReadQueryParams readQueryParams) { - return baseMapper.getThourWeather(readQueryParams); + public List getThourWeather(ReadQueryReq readQueryReq) { + List list = baseMapper.getThourWeather(readQueryReq); + log.info("天气:{}", list); + return list; } + } diff --git a/lzbi-module/src/main/resources/mapper/asset/WorkParamReadMapper.xml b/lzbi-module/src/main/resources/mapper/asset/WorkParamReadMapper.xml index 3699fa5..4e5f0ce 100644 --- a/lzbi-module/src/main/resources/mapper/asset/WorkParamReadMapper.xml +++ b/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,