Browse Source

报表i

develop
bobol 11 months ago
parent
commit
39499ebfdd
  1. 1
      lzbi-module/src/main/java/com/lzbi/bi/controller/DcBusiDataScreenNewController.java
  2. 42
      lzbi-module/src/main/java/com/lzbi/draft/controller/ReportController.java
  3. 88
      lzbi-module/src/main/java/com/lzbi/task/domain/DaTangGuanJingDataVO.java
  4. 88
      lzbi-module/src/main/java/com/lzbi/task/domain/MultipleDeviceDataVO.java
  5. 13
      lzbi-module/src/main/java/com/lzbi/task/domain/ReadQueryParams.java
  6. 26
      lzbi-module/src/main/java/com/lzbi/task/domain/ThourWeatherVO.java
  7. 40
      lzbi-module/src/main/java/com/lzbi/task/domain/WorkDataDTO.java
  8. 8
      lzbi-module/src/main/java/com/lzbi/task/mapper/WorkParamReadMapper.java
  9. 142
      lzbi-module/src/main/java/com/lzbi/task/service/WorkParamReadService.java
  10. 76
      lzbi-module/src/main/resources/mapper/asset/WorkParamReadMapper.xml

1
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));
}
}

42
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<TargetDraftMonthReportVO> targetDraftMonthReport(TargetDraftMonthReportReq targetDraftMonthReportReq) {
return reportService.getTargetDraftMonthReport(targetDraftMonthReportReq);
}
/**
* 获取数据
* @param readQueryParams
* @return
*/
@GetMapping("/multipleDeviceData")
public List<MultipleDeviceDataVO> getMultipleDeviceData(@Validated ReadQueryParams readQueryParams) {
return workParamReadService.getMultipleDeviceData(readQueryParams);
}
/**
* 获取数据
* @param readQueryParams
* @return
*/
@GetMapping("/daTangGuanJingData")
public List<DaTangGuanJingDataVO> getDaTangGuanJingDataVO(@Validated ReadQueryParams readQueryParams) {
return workParamReadService.getDaTangGuanJingDataVO(readQueryParams);
}
/**
* 获取小时天气
* @param readQueryParams
* @return
*/
@GetMapping("/thourWeather")
public List<ThourWeatherVO> getThourWeather(@Validated ReadQueryParams readQueryParams) {
return workParamReadService.getThourWeather(readQueryParams);
}
}

88
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;
}
}

88
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;
}
}

13
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<String> deviceCodes;
private List<String> paramCodes;
}

26
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;
}

40
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 ;
}

8
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<WorkParamInfo>
{
public List<DcBusiWorkReadLog> readWorkValue(ReadQueryParams readQueryParams);
List<WorkDataDTO> readWorkData (ReadQueryParams readQueryParams);
List<ThourWeatherVO> getThourWeather(ReadQueryParams readQueryParams);
}

142
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<WorkParamReadMapper, WorkParamInfo> implements IService<WorkParamInfo>
@Slf4j
public class WorkParamReadService extends ServiceImpl<WorkParamReadMapper, WorkParamInfo> implements IService<WorkParamInfo> {
{
/*获取生产单元的参数读取配置
* */
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));
Class<MultipleDeviceDataVO> clazz = MultipleDeviceDataVO.class;
Field[] fields = clazz.getDeclaredFields();
List<MultipleDeviceDataVO> list = new ArrayList<>();
List<WorkDataDTO> workDataDTOS = baseMapper.readWorkData(readQueryParams);
if (!CollectionUtils.isEmpty(workDataDTOS)) {
Map<Date, List<WorkDataDTO>> timeMap = workDataDTOS.stream().collect(Collectors.groupingBy(WorkDataDTO::getThour));
timeMap.forEach((key, value) -> {
Map<String, List<WorkDataDTO>> deviceMap = value.stream().collect(Collectors.groupingBy(WorkDataDTO::getDeviceCode));
for (String deviceCode : DEVICE_CODE_ARR) {
if (deviceMap.containsKey(deviceCode)) {
List<WorkDataDTO> workDataDTOList = deviceMap.get(deviceCode);
Map<String, List<WorkDataDTO>> partionMap = workDataDTOList.stream().collect(Collectors.groupingBy(WorkDataDTO::getPartion));
partionMap.forEach((p, l) -> {
Map<String, List<WorkDataDTO>> 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<WorkDataDTO> 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<DaTangGuanJingDataVO> 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<DaTangGuanJingDataVO> clazz = DaTangGuanJingDataVO.class;
Field[] fields = clazz.getDeclaredFields();
List<DaTangGuanJingDataVO> list = new ArrayList<>();
List<WorkDataDTO> workDataDTOS = baseMapper.readWorkData(readQueryParams);
if (!CollectionUtils.isEmpty(workDataDTOS)) {
Map<Date, List<WorkDataDTO>> timeMap = workDataDTOS.stream().collect(Collectors.groupingBy(WorkDataDTO::getThour));
timeMap.forEach((key, value) -> {
Map<String, List<WorkDataDTO>> deviceMap = value.stream().collect(Collectors.groupingBy(WorkDataDTO::getDeviceCode));
for (String deviceCode : DEVICE_CODE_ARR) {
if (deviceMap.containsKey(deviceCode)) {
List<WorkDataDTO> workDataDTOList = deviceMap.get(deviceCode);
Map<String, List<WorkDataDTO>> partionMap = workDataDTOList.stream().collect(Collectors.groupingBy(WorkDataDTO::getPartion));
partionMap.forEach((p, l) -> {
Map<String, List<WorkDataDTO>> 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<WorkDataDTO> 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<ThourWeatherVO> getThourWeather(ReadQueryParams readQueryParams) {
return baseMapper.getThourWeather(readQueryParams);
}
}

76
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
</select>
<resultMap type="com.lzbi.task.domain.WorkDataDTO" id="WorkDataVoResult">
<result property="paramModelId" column="param_model_id" />
<result property="paramModeName" column="param_class_name" />
<result property="deviceCode" column="device_uuid" />
<result property="deviceName" column="device_name" />
<result property="partion" column="partion" />
<result property="thour" column="thour" />
<result property="total" column="total" />
<result property="countsAll" column="countsall" />
<result property="countsZero" column="countsz" />
<result property="maxVal" column="maxVal" />
<result property="minVal" column="minVal" />
<result property="firstVal" column="firstVal" />
<result property="lastVal" column="lastVal" />
</resultMap>
<select id="readWorkData" resultMap="WorkDataVoResult" parameterType="com.lzbi.task.domain.ReadQueryParams">
SELECT
t2.param_model_id,
t3.param_class_name,
t1.device_uuid,
t5.device_name,
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,
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,
LAST ( t1.param_value_num, timestamp_key ) AS lastVal,
MIN ( t1.param_value_num ) AS minVal
FROM
dc_base_log_history_level1 t1
INNER JOIN dc_base_device_param t2 ON t1.param_code = t2.param_code
AND t2.param_model_id IN
<foreach item="item" index="index" collection="paramCodes" open="(" close=")" separator=",">
#{item}
</foreach>
LEFT JOIN dc_model_paramclass t3 ON t2.param_model_id = t3.param_class_code
LEFT JOIN dc_base_device_param t4 ON t4.param_code = t1.param_code
AND t4.device_uuid = t4.device_uuid
LEFT JOIN dc_base_deviceinfo t5 ON t5.center_device_code = t1.device_uuid
WHERE
t1.timestamp_key BETWEEN to_timestamp( #{beginTime}, 'yyyy-MM-dd hh24:mi:ss' )
AND to_timestamp( #{endTime}, 'yyyy-MM-dd hh24:mi:ss' )
AND t1.device_uuid in
<foreach item="item" index="index" collection="deviceCodes" open="(" close=")" separator=",">
#{item}
</foreach>
GROUP BY
thour,
t1.device_uuid,
t2.param_model_id,
t3.param_class_name,
t4.partion,
t5.device_name
</select>
<select id="getThourWeather" parameterType="com.lzbi.task.domain.ReadQueryParams" resultType="com.lzbi.task.domain.ThourWeatherVO">
SELECT
city,
max(weather) AS weather,
min(temperature) AS temperature,
to_char( reporttime, 'yyyy-MM-dd hh24' ) as thour
FROM
"dc_busi_real_weather_hours"
WHERE
city = '浑南区'
AND reporttime BETWEEN to_timestamp( #{beginTime}, 'yyyy-MM-dd hh24:mi:ss' )
AND to_timestamp( #{endTime}, 'yyyy-MM-dd hh24:mi:ss' )
GROUP BY
city, thour
ORDER BY
thour ASC
</select>
</mapper>
Loading…
Cancel
Save