diff --git a/lzbi-module/src/main/java/com/lzbi/bi/controller/DcBusiDataScreenNewController.java b/lzbi-module/src/main/java/com/lzbi/bi/controller/DcBusiDataScreenNewController.java index b06cec1..73d947e 100644 --- a/lzbi-module/src/main/java/com/lzbi/bi/controller/DcBusiDataScreenNewController.java +++ b/lzbi-module/src/main/java/com/lzbi/bi/controller/DcBusiDataScreenNewController.java @@ -93,4 +93,5 @@ public class DcBusiDataScreenNewController extends BaseController { public AjaxResult corporateStatistics(@Validated DcBusDataScreenNewReq dcBusDataScreenNewReq) { return success(dcBusiDataScreenNewService.getCorporateStatistics(dcBusDataScreenNewReq)); } + } 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 a663cec..77a768b 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,10 +1,17 @@ package com.lzbi.draft.controller; +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.service.WorkParamReadService; import org.springframework.beans.factory.annotation.Autowired; +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; @@ -19,13 +26,46 @@ import java.util.List; */ @RestController @RequestMapping("/report") -public class ReportController { +public class ReportController extends BaseController { @Autowired private ReportService reportService; + @Autowired + private WorkParamReadService workParamReadService; + @GetMapping("/targetDraftMonthReport") public List targetDraftMonthReport(TargetDraftMonthReportReq targetDraftMonthReportReq) { return reportService.getTargetDraftMonthReport(targetDraftMonthReportReq); } + + /** + * 获取数据 + * @param readQueryParams + * @return + */ + @GetMapping("/multipleDeviceData") + public List getMultipleDeviceData(@Validated ReadQueryParams readQueryParams) { + return workParamReadService.getMultipleDeviceData(readQueryParams); + } + + /** + * 获取数据 + * @param readQueryParams + * @return + */ + @GetMapping("/daTangGuanJingData") + public List getDaTangGuanJingDataVO(@Validated ReadQueryParams readQueryParams) { + return workParamReadService.getDaTangGuanJingDataVO(readQueryParams); + } + + /** + * 获取小时天气 + * @param readQueryParams + * @return + */ + @GetMapping("/thourWeather") + public List getThourWeather(@Validated ReadQueryParams readQueryParams) { + return workParamReadService.getThourWeather(readQueryParams); + } } 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 new file mode 100644 index 0000000..b4ed612 --- /dev/null +++ b/lzbi-module/src/main/java/com/lzbi/task/domain/DaTangGuanJingDataVO.java @@ -0,0 +1,88 @@ +package com.lzbi.task.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +@Data +public class DaTangGuanJingDataVO { + + /** + * 瞬时流量 + */ + private Double ssll; + /** + * 累计热量 + */ + private Double ssrl; + /** + * 一网供温 + */ + private Double ywgw; + /** + * 一网回温 + */ + private Double ywhw; + /** + * 一网供压 + */ + private Double ywgy; + /** + * 一网回压 + */ + private Double ywhy; + /** + * 供水流量 + */ + private Double gsll; + /** + * 回水流量 + */ + private Double hsll; + /** + * 瞬时补水 + */ + private Double ssbs; + /** + * 累计补水 + */ + private Double ljbs; + /** + * 阀门给定 + */ + private Double fmgd; + /** + * 阀门反馈 + */ + private Double fmfk; + /** + * 设备编码 + */ + private String deviceName; + /** + * 分区 + */ + private String partion; + /** + * 统计时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH") + private Date thour; + + public DaTangGuanJingDataVO() { + this.ssll = 0D; + this.ssrl = 0D; + this.ywgw = 0D; + this.ywhw = 0D; + this.ywgy = 0D; + this.ywhy = 0D; + this.gsll = 0D; + this.hsll = 0D; + this.ssbs = 0D; + this.ljbs = 0D; + this.fmgd = 0D; + this.fmfk = 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 new file mode 100644 index 0000000..a91c6e9 --- /dev/null +++ b/lzbi-module/src/main/java/com/lzbi/task/domain/MultipleDeviceDataVO.java @@ -0,0 +1,88 @@ +package com.lzbi.task.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +@Data +public class MultipleDeviceDataVO { + + /** + * 瞬时流量 + */ + private Double ssll; + /** + * 累计热量 + */ + private Double ssrl; + /** + * 一网供温 + */ + private Double ywgw; + /** + * 一网回温 + */ + private Double ywhw; + /** + * 一网供压 + */ + private Double ywgy; + /** + * 一网回压 + */ + private Double ywhy; + /** + * 二网供温 + */ + private Double ewgw; + /** + * 二网回温 + */ + private Double ewhw; + /** + * 二网供压 + */ + private Double ewgy; + /** + * 二网回压 + */ + private Double ewhy; + /** + * 阀门给定 + */ + private Double fmgd; + /** + * 阀门反馈 + */ + private Double fmfk; + /** + * 设备编码 + */ + private String deviceName; + /** + * 分区 + */ + private String partion; + /** + * 统计时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH") + private Date thour; + + public MultipleDeviceDataVO() { + this.ssll = 0D; + this.ssrl = 0D; + this.ywgw = 0D; + this.ywhw = 0D; + this.ywgy = 0D; + this.ywhy = 0D; + this.ewgw = 0D; + this.ewhw = 0D; + this.ewgy = 0D; + this.ewhy = 0D; + this.fmgd = 0D; + this.fmfk = 0D; + } +} diff --git a/lzbi-module/src/main/java/com/lzbi/task/domain/ReadQueryParams.java b/lzbi-module/src/main/java/com/lzbi/task/domain/ReadQueryParams.java index d20d043..b28fe8c 100644 --- a/lzbi-module/src/main/java/com/lzbi/task/domain/ReadQueryParams.java +++ b/lzbi-module/src/main/java/com/lzbi/task/domain/ReadQueryParams.java @@ -1,7 +1,10 @@ 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.List; /** @@ -11,8 +14,18 @@ import java.util.List; */ @Data public class ReadQueryParams { + + @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/ThourWeatherVO.java b/lzbi-module/src/main/java/com/lzbi/task/domain/ThourWeatherVO.java new file mode 100644 index 0000000..ae70cea --- /dev/null +++ b/lzbi-module/src/main/java/com/lzbi/task/domain/ThourWeatherVO.java @@ -0,0 +1,26 @@ +package com.lzbi.task.domain; + +import lombok.Data; + +import java.util.Date; + +@Data +public class ThourWeatherVO { + + /** + * 城市 + */ + private String city; + /** + * 天气 + */ + private String weather; + /** + * 温度 + */ + private Double temperature; + /** + * 时间 + */ + private String thour; +} diff --git a/lzbi-module/src/main/java/com/lzbi/task/domain/WorkDataDTO.java b/lzbi-module/src/main/java/com/lzbi/task/domain/WorkDataDTO.java new file mode 100644 index 0000000..22643f4 --- /dev/null +++ b/lzbi-module/src/main/java/com/lzbi/task/domain/WorkDataDTO.java @@ -0,0 +1,40 @@ +package com.lzbi.task.domain; + +import lombok.Data; + +import java.util.Date; + +@Data +public class WorkDataDTO { + + /** 参数编码 */ + private String paramModelId ; + /** 参数编码名称 */ + private String paramModeName ; + /** 设备编码 */ + private String deviceCode ; + /** 设备编码 */ + private String deviceName ; + /** 分区 */ + private String partion; + /** 统计时间 */ + private Date thour ; + /** 和值 */ + private Double total ; + /** 总条数 */ + private Double countsAll ; + /** 除零总数 */ + private Double countsZero ; + /** 最大值 */ + private Double maxVal ; + /** 最小值 */ + private Double minVal ; + /** 开始值 */ + private Double firstVal ; + /** 结束值 */ + private Double lastVal ; + /** 统计日 */ + private String dateCount ; + /** 小时 */ + private Integer hourCount ; +} 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 b0bfa29..a727348 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 @@ -1,9 +1,7 @@ package com.lzbi.task.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.lzbi.task.domain.DcBusiWorkReadLog; -import com.lzbi.task.domain.ReadQueryParams; -import com.lzbi.task.domain.WorkParamInfo; +import com.lzbi.task.domain.*; import java.util.List; @@ -17,4 +15,8 @@ import java.util.List; public interface WorkParamReadMapper extends BaseMapper { public List readWorkValue(ReadQueryParams readQueryParams); + + List readWorkData (ReadQueryParams readQueryParams); + + List getThourWeather(ReadQueryParams readQueryParams); } 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 1f71412..0b32836 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,14 +1,19 @@ package com.lzbi.task.service; +import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.lzbi.task.domain.DcBusiWorkReadLog; -import com.lzbi.task.domain.ReadQueryParams; -import com.lzbi.task.domain.WorkParamInfo; +import com.lzbi.task.domain.*; import com.lzbi.task.mapper.WorkParamReadMapper; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; -import java.util.List; +import java.lang.reflect.Field; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.*; +import java.util.stream.Collectors; /** @@ -17,14 +22,137 @@ import java.util.List; * @author win * @date 2023-11-29 */ -//@DS("workDB") +@DS("workDB") @Service -public class WorkParamReadService extends ServiceImpl implements IService +@Slf4j +public class WorkParamReadService extends ServiceImpl implements IService { -{ /*获取生产单元的参数读取配置 * */ - public List readWorkValue(ReadQueryParams readQueryParams){ + 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)); + Class clazz = MultipleDeviceDataVO.class; + Field[] fields = clazz.getDeclaredFields(); + List list = new ArrayList<>(); + List workDataDTOS = baseMapper.readWorkData(readQueryParams); + if (!CollectionUtils.isEmpty(workDataDTOS)) { + Map> timeMap = workDataDTOS.stream().collect(Collectors.groupingBy(WorkDataDTO::getThour)); + timeMap.forEach((key, value) -> { + Map> deviceMap = value.stream().collect(Collectors.groupingBy(WorkDataDTO::getDeviceCode)); + for (String deviceCode : DEVICE_CODE_ARR) { + if (deviceMap.containsKey(deviceCode)) { + List workDataDTOList = deviceMap.get(deviceCode); + Map> partionMap = workDataDTOList.stream().collect(Collectors.groupingBy(WorkDataDTO::getPartion)); + partionMap.forEach((p, l) -> { + Map> paramModelMap = l.stream().collect(Collectors.groupingBy(WorkDataDTO::getParamModelId)); + MultipleDeviceDataVO multipleDeviceDataVO = new MultipleDeviceDataVO(); + multipleDeviceDataVO.setThour(key); + multipleDeviceDataVO.setDeviceName(deviceMap.get(deviceCode).get(0).getDeviceName()); + multipleDeviceDataVO.setPartion(p); + for (int i = 0, len = PARAM_CODE_ARR.length; i < len; i++) { + try { + if (!fields[i].isAccessible()) { + fields[i].setAccessible(true); + } + List workDataDTOList1 = paramModelMap.get(PARAM_CODE_ARR[i]); + if (!CollectionUtils.isEmpty(workDataDTOList1)) { + WorkDataDTO workDataDTO1 = workDataDTOList1.get(0); + Double v = 0D; + if (i == 1) { + if (null != workDataDTO1.getLastVal()) { + v = workDataDTO1.getLastVal(); + } + } else { + if (null != workDataDTO1.getTotal() && null != workDataDTO1.getCountsZero()) { + v = workDataDTO1.getTotal() / workDataDTO1.getCountsZero(); + } + } + + if (null != v && !Double.isNaN(v)) { + v = BigDecimal.valueOf(v).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); + fields[i].set(multipleDeviceDataVO, v); + } + } + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + list.add(multipleDeviceDataVO); + }); + } + } + }); + } + return list; + } + + public List getDaTangGuanJingDataVO(ReadQueryParams readQueryParams) { + 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)); + Class clazz = DaTangGuanJingDataVO.class; + Field[] fields = clazz.getDeclaredFields(); + List list = new ArrayList<>(); + List workDataDTOS = baseMapper.readWorkData(readQueryParams); + if (!CollectionUtils.isEmpty(workDataDTOS)) { + Map> timeMap = workDataDTOS.stream().collect(Collectors.groupingBy(WorkDataDTO::getThour)); + timeMap.forEach((key, value) -> { + Map> deviceMap = value.stream().collect(Collectors.groupingBy(WorkDataDTO::getDeviceCode)); + for (String deviceCode : DEVICE_CODE_ARR) { + if (deviceMap.containsKey(deviceCode)) { + List workDataDTOList = deviceMap.get(deviceCode); + Map> partionMap = workDataDTOList.stream().collect(Collectors.groupingBy(WorkDataDTO::getPartion)); + partionMap.forEach((p, l) -> { + Map> paramModelMap = l.stream().collect(Collectors.groupingBy(WorkDataDTO::getParamModelId)); + DaTangGuanJingDataVO daTangGuanJingDataVO = new DaTangGuanJingDataVO(); + daTangGuanJingDataVO.setThour(key); + daTangGuanJingDataVO.setDeviceName(deviceMap.get(deviceCode).get(0).getDeviceName()); + daTangGuanJingDataVO.setPartion(p); + for (int i = 0, len = PARAM_CODE_ARR.length; i < len; i++) { + try { + if (!fields[i].isAccessible()) { + fields[i].setAccessible(true); + } + List workDataDTOList1 = paramModelMap.get(PARAM_CODE_ARR[i]); + if (!CollectionUtils.isEmpty(workDataDTOList1)) { + WorkDataDTO workDataDTO1 = workDataDTOList1.get(0); + Double v = 0D; + if (i == 1) { + if (null != workDataDTO1.getLastVal()) { + v = workDataDTO1.getLastVal(); + } + } else { + if (null != workDataDTO1.getTotal() && null != workDataDTO1.getCountsZero()) { + v = workDataDTO1.getTotal() / workDataDTO1.getCountsZero(); + } + } + if (null != v && !Double.isNaN(v)) { + v = BigDecimal.valueOf(v).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); + fields[i].set(daTangGuanJingDataVO, v); + } + } + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + list.add(daTangGuanJingDataVO); + }); + } + } + }); + } + return list; + } + + public List getThourWeather(ReadQueryParams readQueryParams) { + return baseMapper.getThourWeather(readQueryParams); + } } diff --git a/lzbi-module/src/main/resources/mapper/asset/WorkParamReadMapper.xml b/lzbi-module/src/main/resources/mapper/asset/WorkParamReadMapper.xml index 099a7cc..3699fa5 100644 --- a/lzbi-module/src/main/resources/mapper/asset/WorkParamReadMapper.xml +++ b/lzbi-module/src/main/resources/mapper/asset/WorkParamReadMapper.xml @@ -39,4 +39,80 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" GROUP BY thour, param_code,device_uuid ORDER BY thour asc + + + + + + + + + + + + + + + + + + + + \ No newline at end of file