From bf9733d8a3e3b950d8eb89356e5cfeba40eb53e8 Mon Sep 17 00:00:00 2001 From: bobol Date: Tue, 9 Apr 2024 17:52:00 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BF=AE=E6=94=B9=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=202=E3=80=81=E5=90=88=E5=8A=9B=E7=9A=84aj-re?= =?UTF-8?q?port=E6=8A=A5=E8=A1=A8=E6=9F=A5=E8=AF=A2=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-dev.yml | 2 +- .../lzbi/common/constant/BizConstants.java | 9 + .../com/lzbi/common/utils/NumberUtils.java | 21 +++ .../DcBusiWorkReadConfigController.java | 2 +- .../controller/DcBusiHisReportController.java | 16 +- .../bi/domain/LogTimeThreeQueryParamVo.java | 9 +- .../controller/IOTCommonDataControler.java | 2 +- .../DcBusiBillModelMasterController.java | 2 +- ...DcBusiTargetAdjustDayMasterController.java | 6 +- .../draft/domain/DcBusiParamDraftDay.java | 39 +++++ .../DcBusiTargetAdjustDayMasterService.java | 9 + .../external/controller/ParamsController.java | 6 +- .../lzbi/external/service/ParamsService.java | 2 +- .../report/controller/AjReportController.java | 25 +++ .../com/lzbi/report/domain/dto/ReportDTO.java | 36 ++++ .../lzbi/report/domain/query/ReportQuery.java | 34 ++++ .../com/lzbi/report/domain/req/ReportReq.java | 19 +++ .../com/lzbi/report/domain/vo/ReportVO.java | 28 +++ .../lzbi/report/mapper/AjReportMapper.java | 23 +++ .../lzbi/report/service/AjReportService.java | 159 ++++++++++++++++++ .../com/lzbi/task/TaskParamDfratProcess.java | 77 ++++++--- .../java/com/lzbi/task/TaskWorkParamRead.java | 46 +++-- .../com/lzbi/task/domain/ReadQueryParams.java | 6 +- .../mapper/asset/DcBusiWorkReadLogMapper.xml | 2 +- .../mapper/report/AjReportMapper.xml | 60 +++++++ .../lzbi/quartz/task/SyncIotSystemTask.java | 5 +- 26 files changed, 590 insertions(+), 55 deletions(-) create mode 100644 lzbi-common/src/main/java/com/lzbi/common/utils/NumberUtils.java create mode 100644 lzbi-module/src/main/java/com/lzbi/report/controller/AjReportController.java create mode 100644 lzbi-module/src/main/java/com/lzbi/report/domain/dto/ReportDTO.java create mode 100644 lzbi-module/src/main/java/com/lzbi/report/domain/query/ReportQuery.java create mode 100644 lzbi-module/src/main/java/com/lzbi/report/domain/req/ReportReq.java create mode 100644 lzbi-module/src/main/java/com/lzbi/report/domain/vo/ReportVO.java create mode 100644 lzbi-module/src/main/java/com/lzbi/report/mapper/AjReportMapper.java create mode 100644 lzbi-module/src/main/java/com/lzbi/report/service/AjReportService.java create mode 100644 lzbi-module/src/main/resources/mapper/report/AjReportMapper.xml diff --git a/lzbi-admin/src/main/resources/application-dev.yml b/lzbi-admin/src/main/resources/application-dev.yml index 47d95b8..fe903be 100644 --- a/lzbi-admin/src/main/resources/application-dev.yml +++ b/lzbi-admin/src/main/resources/application-dev.yml @@ -49,7 +49,7 @@ spring: # 配置一个连接在池中最大生存的时间,单位是毫秒 maxEvictableIdleTimeMillis: 900000 # 查询等待时间 - # query-timeout: 60000 + # ReportQuery-timeout: 60000 # 配置检测连接是否有效 validationQuery: SELECT 1 testWhileIdle: true diff --git a/lzbi-common/src/main/java/com/lzbi/common/constant/BizConstants.java b/lzbi-common/src/main/java/com/lzbi/common/constant/BizConstants.java index 20a3930..962fcd7 100644 --- a/lzbi-common/src/main/java/com/lzbi/common/constant/BizConstants.java +++ b/lzbi-common/src/main/java/com/lzbi/common/constant/BizConstants.java @@ -5,6 +5,15 @@ package com.lzbi.common.constant; */ public interface BizConstants { + /** + * T指标P参数 + */ + interface ColumnType { + String TARGET = "T"; + + String PARAM = "P"; + } + /** * 数据来源;生产IOT:work;计费:charge;Erp:erp */ diff --git a/lzbi-common/src/main/java/com/lzbi/common/utils/NumberUtils.java b/lzbi-common/src/main/java/com/lzbi/common/utils/NumberUtils.java new file mode 100644 index 0000000..a2e1896 --- /dev/null +++ b/lzbi-common/src/main/java/com/lzbi/common/utils/NumberUtils.java @@ -0,0 +1,21 @@ +package com.lzbi.common.utils; + +import java.math.BigDecimal; +import java.math.RoundingMode; + +public class NumberUtils { + + public static Double doubleScaleToDouble(Double number, int scale) { + if (null == number || scale < 0) { + return null; + } + return BigDecimal.valueOf(number).setScale(scale, RoundingMode.HALF_EVEN).doubleValue(); + } + + public static BigDecimal doubleScaleToBigDecimal(Double number, int scale) { + if (null == number || scale < 0) { + return null; + } + return BigDecimal.valueOf(number).setScale(scale, RoundingMode.HALF_EVEN); + } +} diff --git a/lzbi-module/src/main/java/com/lzbi/asset/controller/DcBusiWorkReadConfigController.java b/lzbi-module/src/main/java/com/lzbi/asset/controller/DcBusiWorkReadConfigController.java index b0e38bf..7b2bba3 100644 --- a/lzbi-module/src/main/java/com/lzbi/asset/controller/DcBusiWorkReadConfigController.java +++ b/lzbi-module/src/main/java/com/lzbi/asset/controller/DcBusiWorkReadConfigController.java @@ -79,7 +79,7 @@ public class DcBusiWorkReadConfigController extends BaseController { /** * 获取互联参数读取数据对照详细信息 */ - //@PreAuthorize("@ss.hasPermi('asset:assetExtConfig:query')") + //@PreAuthorize("@ss.hasPermi('asset:assetExtConfig:ReportQuery')") @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { return success(dcBusiWorkReadConfigService.selectDcBusiWorkReadConfigById(id)); diff --git a/lzbi-module/src/main/java/com/lzbi/bi/controller/DcBusiHisReportController.java b/lzbi-module/src/main/java/com/lzbi/bi/controller/DcBusiHisReportController.java index 77a3ff1..9bb4c0c 100644 --- a/lzbi-module/src/main/java/com/lzbi/bi/controller/DcBusiHisReportController.java +++ b/lzbi-module/src/main/java/com/lzbi/bi/controller/DcBusiHisReportController.java @@ -25,6 +25,9 @@ import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import javax.validation.constraints.NotNull; import java.io.IOException; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; @@ -239,7 +242,18 @@ public class DcBusiHisReportController extends BaseController { //获取excel数据 1 excel设备参数为列模式 2 excel时间为列模式 3 浏览器设备参数为列模式 //注意 excel有最大列数显示255 ,超出列数会报错 private List> getExcellData(LogTimeThreeQueryParamVo queryVo, int type) { - // 设置头部数据, + // 设置头部数据 + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + LocalDateTime startTime = LocalDateTime.parse(queryVo.getBeginTime(), dateTimeFormatter); + LocalDateTime endTime = LocalDateTime.parse(queryVo.getEndTime(), dateTimeFormatter); + LocalDate startDate = startTime.toLocalDate(); + LocalDate endDate = endTime.toLocalDate(); + if (endDate.isBefore(startDate)) { + throw new RuntimeException("结束日期不能小于开始日期"); + } + if (startDate.plusMonths(1L).isBefore(endDate)) { + throw new RuntimeException("日期间隔不能大于1个月"); + } DcDymicHeaderQueryVo dcDymicHeaderQueryVo = new DcDymicHeaderQueryVo(); dcDymicHeaderQueryVo.setParamModels(queryVo.getQueryParamClass()); dcDymicHeaderQueryVo.setDeviceUuids(queryVo.getDeviceUuids()); diff --git a/lzbi-module/src/main/java/com/lzbi/bi/domain/LogTimeThreeQueryParamVo.java b/lzbi-module/src/main/java/com/lzbi/bi/domain/LogTimeThreeQueryParamVo.java index 380269b..de23dd6 100644 --- a/lzbi-module/src/main/java/com/lzbi/bi/domain/LogTimeThreeQueryParamVo.java +++ b/lzbi-module/src/main/java/com/lzbi/bi/domain/LogTimeThreeQueryParamVo.java @@ -7,6 +7,8 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.experimental.Accessors; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; import java.util.List; /** @@ -18,20 +20,25 @@ import java.util.List; @Accessors(chain = true) @ApiModel(value = "level3 日志查询参数",description = "") public class LogTimeThreeQueryParamVo { + /** 开始时间 */ @ApiModelProperty(name = "开始时间",notes = "") + @NotBlank(message = "请选择开始时间") private String beginTime; /** 结束时间 */ - @ApiModelProperty(name = "开始时间",notes = "") + @ApiModelProperty(name = "结束时间",notes = "") + @NotBlank(message = "请选择结束时间") private String endTime; /** 中台设备UUID */ @ApiModelProperty(name = "中台设备UUID",notes = "") + @NotNull(message = "请选择设备") private List deviceUuids ; /** 参数列表 */ @ApiModelProperty(name = "参数列表",notes = "") private List queryParamCodes ; /** 参数模版列表 */ @ApiModelProperty(name = "参数模版列表",notes = "") + @NotNull(message = "请选择统计参数") private List queryParamClass ; //private Integer pageNum; // private Integer pageSize; diff --git a/lzbi-module/src/main/java/com/lzbi/common/controller/IOTCommonDataControler.java b/lzbi-module/src/main/java/com/lzbi/common/controller/IOTCommonDataControler.java index 8a37873..a276879 100644 --- a/lzbi-module/src/main/java/com/lzbi/common/controller/IOTCommonDataControler.java +++ b/lzbi-module/src/main/java/com/lzbi/common/controller/IOTCommonDataControler.java @@ -45,7 +45,7 @@ public class IOTCommonDataControler extends BaseController{ /** * 根据部门编号获取详细信息 */ - //@PreAuthorize("@ss.hasPermi('system:dept:query')") + //@PreAuthorize("@ss.hasPermi('system:dept:ReportQuery')") @GetMapping(value = "/{deptId}") public AjaxResult getInfo(@PathVariable Long deptId) { diff --git a/lzbi-module/src/main/java/com/lzbi/draft/controller/DcBusiBillModelMasterController.java b/lzbi-module/src/main/java/com/lzbi/draft/controller/DcBusiBillModelMasterController.java index 3d7e4bb..5eef2c9 100644 --- a/lzbi-module/src/main/java/com/lzbi/draft/controller/DcBusiBillModelMasterController.java +++ b/lzbi-module/src/main/java/com/lzbi/draft/controller/DcBusiBillModelMasterController.java @@ -76,7 +76,7 @@ public class DcBusiBillModelMasterController extends BaseController @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "", dataType = "Long", dataTypeClass = Long.class), }) - // @PreAuthorize("@ss.hasPermi('draft:billModel:query')") + // @PreAuthorize("@ss.hasPermi('draft:billModel:ReportQuery')") @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { diff --git a/lzbi-module/src/main/java/com/lzbi/draft/controller/DcBusiTargetAdjustDayMasterController.java b/lzbi-module/src/main/java/com/lzbi/draft/controller/DcBusiTargetAdjustDayMasterController.java index 033a979..fc8ce1a 100644 --- a/lzbi-module/src/main/java/com/lzbi/draft/controller/DcBusiTargetAdjustDayMasterController.java +++ b/lzbi-module/src/main/java/com/lzbi/draft/controller/DcBusiTargetAdjustDayMasterController.java @@ -127,7 +127,7 @@ public class DcBusiTargetAdjustDayMasterController extends BaseController } @ApiOperation("驳回") - @PreAuthorize("@ss.hasPermi('bill:dayPlanBill:check')") + @PreAuthorize("@ss.hasPermi('asset:targetDayAdjustBill:check')") @ApiImplicitParams({ @ApiImplicitParam(name = "billNo", value = "", dataType = "String", dataTypeClass = String.class), }) @@ -137,7 +137,7 @@ public class DcBusiTargetAdjustDayMasterController extends BaseController } @ApiOperation("审核") - @PreAuthorize("@ss.hasPermi('bill:dayPlanBill:check')") + @PreAuthorize("@ss.hasPermi('asset:targetDayAdjustBill:check')") @ApiImplicitParams({ @ApiImplicitParam(name = "billNo", value = "", dataType = "String", dataTypeClass = String.class), }) @@ -148,7 +148,7 @@ public class DcBusiTargetAdjustDayMasterController extends BaseController } @ApiOperation("反审核") - @PreAuthorize("@ss.hasPermi('bill:dayPlanBill:check')") + @PreAuthorize("@ss.hasPermi('asset:targetDayAdjustBill:check')") @ApiImplicitParams({ @ApiImplicitParam(name = "billNo", value = "", dataType = "String", dataTypeClass = String.class), }) diff --git a/lzbi-module/src/main/java/com/lzbi/draft/domain/DcBusiParamDraftDay.java b/lzbi-module/src/main/java/com/lzbi/draft/domain/DcBusiParamDraftDay.java index 0035333..a9864a2 100644 --- a/lzbi-module/src/main/java/com/lzbi/draft/domain/DcBusiParamDraftDay.java +++ b/lzbi-module/src/main/java/com/lzbi/draft/domain/DcBusiParamDraftDay.java @@ -1,6 +1,9 @@ package com.lzbi.draft.domain; +import java.lang.reflect.Field; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.Date; import lombok.Data; import com.lzbi.common.annotation.Excel; @@ -190,6 +193,42 @@ public class DcBusiParamDraftDay extends BaseModuleEntity private String assetName; /**最后值 */ private Double valLast; + + public void calculate() { + Class clazz = DcBusiParamDraftDay.class; + valSum = 0D; + valMax = 0D; + valMin = Double.MAX_VALUE; + valTotal = 0; + try { + for (int i = 1; i <= 24; i++) { + String fieldName = "val" + String.format("%02d", i); + Field field = clazz.getDeclaredField(fieldName); + field.setAccessible(true); + Object o = field.get(this); + if (null != o) { + valTotal ++; + Double v = (Double) o; + if (valMax.compareTo(v) < 0) { + valMax = v; + } + if (valMin.compareTo(v) > 0) { + valMin = v; + } + valLast = v; + valSum += v; + } + } + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new RuntimeException(e); + } + valSum = BigDecimal.valueOf(valSum).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); + valAvg = BigDecimal.valueOf(valSum / 24).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); + if (valMin.equals(Double.MAX_VALUE)) { + valMin = 0D; + } + } + public void setValForSeq(int key,Double value){ switch (key){ case 0: diff --git a/lzbi-module/src/main/java/com/lzbi/draft/service/DcBusiTargetAdjustDayMasterService.java b/lzbi-module/src/main/java/com/lzbi/draft/service/DcBusiTargetAdjustDayMasterService.java index b7a34c9..fa618c1 100644 --- a/lzbi-module/src/main/java/com/lzbi/draft/service/DcBusiTargetAdjustDayMasterService.java +++ b/lzbi-module/src/main/java/com/lzbi/draft/service/DcBusiTargetAdjustDayMasterService.java @@ -226,6 +226,9 @@ public class DcBusiTargetAdjustDayMasterService extends ServiceImpl assetCodeList) { - return AjaxResult.success(paramsService.getGasSupplyArea(assetCodeList)); + public AjaxResult getMultipleAssetSupplyArea(@RequestBody List assetCodeList) { + return AjaxResult.success(paramsService.getMultipleAssetSupplyArea(assetCodeList)); } } diff --git a/lzbi-module/src/main/java/com/lzbi/external/service/ParamsService.java b/lzbi-module/src/main/java/com/lzbi/external/service/ParamsService.java index 59b5b4a..c2efcc1 100644 --- a/lzbi-module/src/main/java/com/lzbi/external/service/ParamsService.java +++ b/lzbi-module/src/main/java/com/lzbi/external/service/ParamsService.java @@ -23,7 +23,7 @@ public class ParamsService { return dcBusiParamDraftDay.getValLast(); } - public Map getGasSupplyArea(List assetCodeList) { + public Map getMultipleAssetSupplyArea(List assetCodeList) { if (CollectionUtils.isEmpty(assetCodeList)) { throw new RuntimeException("资产编码列表不能为空"); } diff --git a/lzbi-module/src/main/java/com/lzbi/report/controller/AjReportController.java b/lzbi-module/src/main/java/com/lzbi/report/controller/AjReportController.java new file mode 100644 index 0000000..2a39476 --- /dev/null +++ b/lzbi-module/src/main/java/com/lzbi/report/controller/AjReportController.java @@ -0,0 +1,25 @@ +package com.lzbi.report.controller; + +import com.lzbi.report.domain.req.ReportReq; +import com.lzbi.report.domain.vo.ReportVO; +import com.lzbi.report.service.AjReportService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; +import java.util.Map; + +@RestController +@RequestMapping("/report/aj") +public class AjReportController { + + @Autowired + private AjReportService ajReportService; + + @GetMapping("/heatExchangeStation/data") + public List> getReportDataList(ReportReq reportReq) { + return ajReportService.getReportDataList(reportReq); + } +} diff --git a/lzbi-module/src/main/java/com/lzbi/report/domain/dto/ReportDTO.java b/lzbi-module/src/main/java/com/lzbi/report/domain/dto/ReportDTO.java new file mode 100644 index 0000000..efce723 --- /dev/null +++ b/lzbi-module/src/main/java/com/lzbi/report/domain/dto/ReportDTO.java @@ -0,0 +1,36 @@ +package com.lzbi.report.domain.dto; + +import lombok.Data; + +@Data +public class ReportDTO { + + /** + * 统计单元编码 + */ + private String assetCode; + /** + * 统计单元名称 + */ + private String assetName; + /** + * 指标/参数编码 + */ + private String targetModelCode; + /** + * 分区 + */ + private String partition; + /** + * 和值 + */ + private Double valSum; + /** + * 有效值数量 + */ + private Integer valTotal; + /** + * 最新值 + */ + private Double valLast; +} diff --git a/lzbi-module/src/main/java/com/lzbi/report/domain/query/ReportQuery.java b/lzbi-module/src/main/java/com/lzbi/report/domain/query/ReportQuery.java new file mode 100644 index 0000000..dcfffeb --- /dev/null +++ b/lzbi-module/src/main/java/com/lzbi/report/domain/query/ReportQuery.java @@ -0,0 +1,34 @@ +package com.lzbi.report.domain.query; + +import lombok.Data; + +import java.util.List; + +@Data +public class ReportQuery { + + /** + * 组织id + */ + private Long orgId; + /** + * 查询日期 + */ + private String countDate; + /** + * 统计单元类别 + */ + private String assetType; + /** + * 统计单元级别 + */ + private String assetLevel; + /** + * 指标/参数模板编码列表 + */ + private List targetModelCodeList; + /** + * T指标P参数 + */ + private String columnType; +} diff --git a/lzbi-module/src/main/java/com/lzbi/report/domain/req/ReportReq.java b/lzbi-module/src/main/java/com/lzbi/report/domain/req/ReportReq.java new file mode 100644 index 0000000..33dfe36 --- /dev/null +++ b/lzbi-module/src/main/java/com/lzbi/report/domain/req/ReportReq.java @@ -0,0 +1,19 @@ +package com.lzbi.report.domain.req; + +import lombok.Data; + +/** + * 报表查询参数 + */ +@Data +public class ReportReq { + + /** + * 组织id + */ + private Long orgId; + /** + * 查询日期 + */ + private String countDate; +} diff --git a/lzbi-module/src/main/java/com/lzbi/report/domain/vo/ReportVO.java b/lzbi-module/src/main/java/com/lzbi/report/domain/vo/ReportVO.java new file mode 100644 index 0000000..2ceefd3 --- /dev/null +++ b/lzbi-module/src/main/java/com/lzbi/report/domain/vo/ReportVO.java @@ -0,0 +1,28 @@ +package com.lzbi.report.domain.vo; + +import lombok.Data; + +import java.util.Map; + +@Data +public class ReportVO { + + /** + * 统计单元编码 + */ + private String assetCode; + /** + * 统计单元名称 + */ + private String assetName; + /** + * 分区 + */ + private String partition; + /** + * 供热面积 + */ + private Double supplyArea; + + private Map values; +} diff --git a/lzbi-module/src/main/java/com/lzbi/report/mapper/AjReportMapper.java b/lzbi-module/src/main/java/com/lzbi/report/mapper/AjReportMapper.java new file mode 100644 index 0000000..ba7f13c --- /dev/null +++ b/lzbi-module/src/main/java/com/lzbi/report/mapper/AjReportMapper.java @@ -0,0 +1,23 @@ +package com.lzbi.report.mapper; + +import com.lzbi.report.domain.dto.ReportDTO; +import com.lzbi.report.domain.query.ReportQuery; + +import java.util.List; + +public interface AjReportMapper { + + /** + * 获取统计单元和分区组合字符串列表 + * @param reportQuery + * @return concat(assetCode, -, partition) + */ + List getAssetAndPartitionList(ReportQuery reportQuery); + + /** + * 获取报表数据列表 + * @param reportQuery + * @return + */ + List getReportDataList(ReportQuery reportQuery); +} diff --git a/lzbi-module/src/main/java/com/lzbi/report/service/AjReportService.java b/lzbi-module/src/main/java/com/lzbi/report/service/AjReportService.java new file mode 100644 index 0000000..7fc734b --- /dev/null +++ b/lzbi-module/src/main/java/com/lzbi/report/service/AjReportService.java @@ -0,0 +1,159 @@ +package com.lzbi.report.service; + +import com.lzbi.common.constant.BizConstants; +import com.lzbi.common.constant.ParamsModelCodeConstants; +import com.lzbi.common.constant.PartitionConstants; +import com.lzbi.common.utils.NumberUtils; +import com.lzbi.external.service.ParamsService; +import com.lzbi.report.domain.dto.ReportDTO; +import com.lzbi.report.domain.query.ReportQuery; +import com.lzbi.report.domain.req.ReportReq; +import com.lzbi.report.mapper.AjReportMapper; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Service +public class AjReportService { + + @Resource + private AjReportMapper ajReportMapper; + + @Autowired + private ParamsService paramsService; + + public List> getReportDataList(ReportReq reportReq) { + List> list = new ArrayList<>(); + if (StringUtils.isBlank(reportReq.getCountDate())) { + reportReq.setCountDate(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); + } + List targetModelCodeList = new ArrayList<>(14); + targetModelCodeList.add(ParamsModelCodeConstants.瞬时流量); + targetModelCodeList.add(ParamsModelCodeConstants.瞬时热量); + targetModelCodeList.add(ParamsModelCodeConstants.累计热量); + targetModelCodeList.add(ParamsModelCodeConstants.一次网供温); + targetModelCodeList.add(ParamsModelCodeConstants.一次网回温); + targetModelCodeList.add(ParamsModelCodeConstants.一次网供压); + targetModelCodeList.add(ParamsModelCodeConstants.一次网回压); + targetModelCodeList.add(ParamsModelCodeConstants.二次网供水温); + targetModelCodeList.add(ParamsModelCodeConstants.二次网回水温); + targetModelCodeList.add(ParamsModelCodeConstants.二次网供水压力); + targetModelCodeList.add(ParamsModelCodeConstants.二次网回水压力); + targetModelCodeList.add(ParamsModelCodeConstants.电调阀开度给定); + targetModelCodeList.add(ParamsModelCodeConstants.电调阀开度反馈); + targetModelCodeList.add(ParamsModelCodeConstants.水箱水位计); + ReportQuery reportQuery = new ReportQuery(); + reportQuery.setOrgId(reportReq.getOrgId()); + reportQuery.setCountDate(reportReq.getCountDate()); + reportQuery.setAssetLevel(BizConstants.DcAssetLevel.HEAT_EXCHANGE_STATION); + reportQuery.setAssetType(BizConstants.DcAssetType.COMPUTE); + reportQuery.setColumnType(BizConstants.ColumnType.PARAM); + reportQuery.setTargetModelCodeList(targetModelCodeList); + List assetAndPartitionList = ajReportMapper.getAssetAndPartitionList(reportQuery); + if (CollectionUtils.isEmpty(assetAndPartitionList)) { + throw new RuntimeException("未配置统计单元"); + } + List reportDataList = ajReportMapper.getReportDataList(reportQuery); + if (CollectionUtils.isEmpty(reportDataList)) { + throw new RuntimeException("无数据"); + } + Map> reportDataMap = reportDataList.stream().collect(Collectors.groupingBy(item -> StringUtils.join(item.getAssetCode(), "-", item.getPartition()))); + List assetCodeList = reportDataList.stream().map(ReportDTO::getAssetCode).collect(Collectors.toList()); + // 获取供热面积 + Map multipleAssetSupplyArea = paramsService.getMultipleAssetSupplyArea(assetCodeList); + assetAndPartitionList.forEach(assetAndPartition -> { + if (reportDataMap.containsKey(assetAndPartition)) { + Map reportVO = new HashMap<>(); + List reportDTOList = reportDataMap.get(assetAndPartition); + String assetCode = reportDTOList.get(0).getAssetCode(); + reportVO.put("assetCode", assetCode); + reportVO.put("assetName", reportDTOList.get(0).getAssetName()); + reportVO.put("partition", PartitionConstants.partition.get(reportDTOList.get(0).getPartition())); + if (!CollectionUtils.isEmpty(multipleAssetSupplyArea) && multipleAssetSupplyArea.containsKey(assetCode)) { + reportVO.put("supplyArea", multipleAssetSupplyArea.get(assetCode)); + } + Map targetDataMap = reportDTOList.stream().collect(Collectors.toMap(ReportDTO::getTargetModelCode, item -> item, (v1, v2) -> v2)); + targetModelCodeList.forEach(targetModelCode -> getValue(reportVO, targetDataMap.get(targetModelCode), targetModelCode)); + this.calculateExtraCellValue(reportVO); + list.add(reportVO); + } + }); + + return list; + } + + /** + * 计算其他单元格数值 + * @param reportVO + */ + private void calculateExtraCellValue(Map reportVO) { + if (CollectionUtils.isEmpty(reportVO)) { + return; + } + Object b = reportVO.get("supplyArea"); + Object d = reportVO.get(ParamsModelCodeConstants.瞬时流量); + Object e = reportVO.get(ParamsModelCodeConstants.瞬时热量); + Object g = reportVO.get(ParamsModelCodeConstants.一次网供温); + Object h = reportVO.get(ParamsModelCodeConstants.一次网回温); + Object i = reportVO.get(ParamsModelCodeConstants.一次网供压); + Object j = reportVO.get(ParamsModelCodeConstants.一次网回压); + Object k = reportVO.get(ParamsModelCodeConstants.二次网供水温); + Object l = reportVO.get(ParamsModelCodeConstants.二次网回水温); + Object m = reportVO.get(ParamsModelCodeConstants.二次网供水压力); + Object n = reportVO.get(ParamsModelCodeConstants.二次网回水压力); + if (null != d && null != e && !e.equals(0D)) { + BigDecimal d1 = BigDecimal.valueOf((Double) d * 1000D); + BigDecimal e1 = BigDecimal.valueOf((Double) e); + reportVO.put("c1", d1.divide(e1, 8, RoundingMode.HALF_EVEN)); + } + if (null != b && null != e && !e.equals(0D)) { + BigDecimal b1 = BigDecimal.valueOf((Double) b); + BigDecimal e1 = BigDecimal.valueOf((Double) e); + reportVO.put("c2", e1.divide(b1, 8, RoundingMode.HALF_EVEN).toPlainString()); + } + if (null != i && null != j) { + reportVO.put("c3", NumberUtils.doubleScaleToBigDecimal((Double) i - (Double) j, 2)); + } + if (null != g && null != h) { + reportVO.put("c4", NumberUtils.doubleScaleToBigDecimal((Double) g - (Double) h, 2)); + reportVO.put("c5", NumberUtils.doubleScaleToBigDecimal(((Double) g + (Double) h) / 2, 2)); + } + if (null != k && null != l) { + reportVO.put("c6", NumberUtils.doubleScaleToBigDecimal((Double) k - (Double) l, 2)); + reportVO.put("c7", NumberUtils.doubleScaleToBigDecimal(((Double) k + (Double) l) / 2, 2)); + } + if (null != m && null != n) { + reportVO.put("c8", NumberUtils.doubleScaleToBigDecimal((Double) m - (Double) n, 2)); + } + } + + private void getValue(Map reportVO, ReportDTO reportDTO, String targetModelCode) { + Double value = null; + if (null != reportDTO) { + switch (reportDTO.getTargetModelCode()) { + case ParamsModelCodeConstants.累计热量: + value = reportDTO.getValLast(); + break; + default: + if (null != reportDTO.getValSum() && null != reportDTO.getValTotal() && reportDTO.getValTotal() > 0) { + value = NumberUtils.doubleScaleToDouble(reportDTO.getValSum()/reportDTO.getValTotal(), 2); + } + break; + } + } + reportVO.put(targetModelCode, value); + } + +} diff --git a/lzbi-module/src/main/java/com/lzbi/task/TaskParamDfratProcess.java b/lzbi-module/src/main/java/com/lzbi/task/TaskParamDfratProcess.java index a4579a9..3ad5e7a 100644 --- a/lzbi-module/src/main/java/com/lzbi/task/TaskParamDfratProcess.java +++ b/lzbi-module/src/main/java/com/lzbi/task/TaskParamDfratProcess.java @@ -1,6 +1,8 @@ package com.lzbi.task; +import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.lzbi.common.utils.StringUtils; import com.lzbi.common.utils.spring.SpringUtils; import com.lzbi.draft.domain.DcBusiParamBillMaster; @@ -10,12 +12,11 @@ import com.lzbi.draft.domain.ParamDraftQueryVo; import com.lzbi.draft.service.DcBusiParamBillMasterService; import com.lzbi.draft.service.DcBusiParamBillSubService; import com.lzbi.draft.service.DcBusiParamDraftDayService; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.stream.Collectors; /** @@ -24,6 +25,7 @@ import java.util.stream.Collectors; * TaskParamDfratProcess * 处理参数底稿表数据 */ +@Slf4j @Component public class TaskParamDfratProcess { @@ -34,23 +36,48 @@ public class TaskParamDfratProcess { DcBusiParamDraftDayService dBusiParamDraftDayService = SpringUtils.getBean(DcBusiParamDraftDayService.class); public void doBill(DcBusiParamBillMaster billMasterDao) { + if (Objects.isNull(billMasterDao)) { + log.error("单据不存在"); + return; + } + DateTime date = DateUtil.date(); DcBusiParamBillSub billSub = new DcBusiParamBillSub(); billSub.setBillNo(billMasterDao.getBillNo()); List dcBusiParamBillSubs = dcBusiParamBillSubService.selectByVo(billSub); - Map> collect = dcBusiParamBillSubs.stream().collect(Collectors.groupingBy(gp -> gp.getAssetCode() + ":" + gp.getParamCode() + ":" + gp.getFieldCode() + ":" + gp.getCountDate())); - collect.forEach((key, value) -> { - String[] s = key.split(":"); - DcBusiParamDraftDay queryVo = new DcBusiParamDraftDay(); - queryVo.setAssetCode(s[0]); - queryVo.setParamCode(s[1]); - queryVo.setParamFieldCode(s[2]); - queryVo.setCountDate(s[3]); - DcBusiParamDraftDay dcBusiParamDraftDay = Optional.ofNullable(dBusiParamDraftDayService.selectOneByParam(queryVo)).orElse(new DcBusiParamDraftDay()); + if (CollectionUtils.isEmpty(dcBusiParamBillSubs)) { + log.error("单据无数据"); + return; + } + List assetCodeList = dcBusiParamBillSubs.stream().map(DcBusiParamBillSub::getAssetCode).collect(Collectors.toList()); + List paramCodeList = dcBusiParamBillSubs.stream().map(DcBusiParamBillSub::getParamCode).collect(Collectors.toList()); + List paramFieldCodeList = dcBusiParamBillSubs.stream().map(DcBusiParamBillSub::getFieldCode).collect(Collectors.toList()); + List countDateList = dcBusiParamBillSubs.stream().map(DcBusiParamBillSub::getCountDate).collect(Collectors.toList()); + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.in("param_code", paramCodeList); + queryWrapper.in("asset_code", assetCodeList); + queryWrapper.in("param_field_code", paramFieldCodeList); + queryWrapper.in("count_date", countDateList); + List paramDraftDayList = dBusiParamDraftDayService.list(queryWrapper); + Map paramDraftDayMap; + if (CollectionUtils.isEmpty(paramDraftDayList)) { + log.info("底稿表无数据"); + paramDraftDayMap = new HashMap<>(); + } else { + paramDraftDayMap = paramDraftDayList.stream().collect(Collectors.toMap(gp -> gp.getAssetCode() + ":" + gp.getParamCode() + ":" + gp.getParamFieldCode() + ":" + gp.getCountDate(), gp -> gp)); + } + Map> paramBillSubMap = dcBusiParamBillSubs.stream().collect(Collectors.groupingBy(gp -> gp.getAssetCode() + ":" + gp.getParamCode() + ":" + gp.getFieldCode() + ":" + gp.getCountDate())); + List insertDataList = new ArrayList<>(); + List updateDataList = new ArrayList<>(); + paramBillSubMap.forEach((key, value) -> { + DcBusiParamDraftDay dcBusiParamDraftDay = Optional.ofNullable(paramDraftDayMap.get(key)).orElse(new DcBusiParamDraftDay()); + if (null == dcBusiParamDraftDay.getId()) { + insertDataList.add(dcBusiParamDraftDay); + } else { + updateDataList.add(dcBusiParamDraftDay); + } List subs = value.stream().sorted(Comparator.comparing(DcBusiParamBillSub::getCountHour)).collect(Collectors.toList()); subs.forEach(val -> { - if (StringUtils.isNull(dcBusiParamDraftDay.getId())) { - dcBusiParamDraftDay.setCreatedTime(DateUtil.date()); - dcBusiParamDraftDay.setCreatedBy("task"); + if (null == dcBusiParamDraftDay.getId()) { dcBusiParamDraftDay.setParamFieldCode(val.getFieldCode()); dcBusiParamDraftDay.setParamCode(val.getParamCode()); dcBusiParamDraftDay.setCountDate(val.getCountDate()); @@ -63,17 +90,21 @@ public class TaskParamDfratProcess { dcBusiParamDraftDay.setAssetName(val.getAssetName()); dcBusiParamDraftDay.setCompanyId(billMasterDao.getCompanyId()); dcBusiParamDraftDay.setCompanyName(billMasterDao.getCompanyName()); - dcBusiParamDraftDay.setValLast(val.getParamValue()); + dcBusiParamDraftDay.setCreatedBy("task"); + dcBusiParamDraftDay.setCreatedTime(date); } - dcBusiParamDraftDay.setUpdatedBy("task"); - dcBusiParamDraftDay.setUpdatedTime(DateUtil.date()); dcBusiParamDraftDay.setValForSeq(val.getCountHour(), val.getParamValue()); - dcBusiParamDraftDay.setValLast(val.getParamValue()); - + dcBusiParamDraftDay.setUpdatedBy("task"); + dcBusiParamDraftDay.setUpdatedTime(date); }); - dBusiParamDraftDayService.saveOrUpdate(dcBusiParamDraftDay); + dcBusiParamDraftDay.calculate(); }); - + if (!CollectionUtils.isEmpty(insertDataList)) { + dBusiParamDraftDayService.saveBatch(insertDataList); + } + if (!CollectionUtils.isEmpty(updateDataList)) { + dBusiParamDraftDayService.updateBatchById(updateDataList); + } } public void doBills() { diff --git a/lzbi-module/src/main/java/com/lzbi/task/TaskWorkParamRead.java b/lzbi-module/src/main/java/com/lzbi/task/TaskWorkParamRead.java index a622e49..050657d 100644 --- a/lzbi-module/src/main/java/com/lzbi/task/TaskWorkParamRead.java +++ b/lzbi-module/src/main/java/com/lzbi/task/TaskWorkParamRead.java @@ -21,10 +21,7 @@ import com.lzbi.task.service.WorkParamReadService; import org.apache.commons.lang3.ObjectUtils; import org.springframework.stereotype.Component; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Optional; +import java.util.*; import java.util.stream.Collectors; /** @@ -48,6 +45,14 @@ public class TaskWorkParamRead { DcBusiParamBillMasterService dcBusiParamBillMasterService = SpringUtils.getBean(DcBusiParamBillMasterService.class); boolean ifLog = false; + public void runTask(Boolean ifLog, String dateStr) { + this.ifLog = ifLog; + if (StringUtils.isBlank(dateStr)) { + dateStr = DateUtil.format(DateUtil.offsetDay(DateUtil.date(), -1), DatePattern.NORM_DATE_PATTERN); + } + createParamBill(dateStr); + } + public void runTask(Boolean ifLog) { this.ifLog = ifLog; String inDate = DateUtil.format(DateUtil.offsetDay(DateUtil.date(), -1), DatePattern.NORM_DATE_PATTERN); @@ -63,13 +68,28 @@ public class TaskWorkParamRead { * 从生产数据库获取配置的参数的值 * 按小时及性能分区统计"work" */ - public List getWorkReadVo(String inComeDate, List pcl, List dcl) { + public List getWorkReadVo(String inComeDate, Set pcl) { + List dcBusiWorkReadLogs = new ArrayList<>(); ReadQueryParams readQueryParams = new ReadQueryParams(); readQueryParams.setBeginTime(inComeDate + " 00:00:00"); readQueryParams.setEndTime(inComeDate + " 23:59:59"); - readQueryParams.setParamCodes(pcl); - readQueryParams.setDeviceCodes(dcl); - List dcBusiWorkReadLogs = workParamReadService.readWorkValue(readQueryParams); +// readQueryParams.setParamCodes(pcl); +// readQueryParams.setDeviceCodes(dcl); + List paramList = new ArrayList<>(pcl); + int len = paramList.size(); + int range = 1000; + int count = len / range; + for (long i = 0; i <= count; i++) { + List partParamList; + if (i < count) { + partParamList = paramList.stream().skip(i * range).limit((i + 1) * range).collect(Collectors.toList()); + } else { + partParamList = paramList.stream().skip(i * range).collect(Collectors.toList()); + } + readQueryParams.setParamCodes(new HashSet<>(partParamList)); + List partBusiWorkReadLogs = workParamReadService.readWorkValue(readQueryParams); + dcBusiWorkReadLogs.addAll(partBusiWorkReadLogs); + } if (ifLog) { readQueryParams.setBeginTime(inComeDate); saveRealLog(dcBusiWorkReadLogs, readQueryParams); @@ -105,16 +125,16 @@ public class TaskWorkParamRead { billm.setBillIncomeDate(inComeDate); billm.setBillType("2"); billm.setCheckType("1"); - billm.setCheckStatus("1"); + billm.setCheckStatus("0"); List billSub = new ArrayList<>(); DcBusiWorkReadConfig dwrc = new DcBusiWorkReadConfig(); dwrc.setGoalSource(SOURCE); List dcBusiWorkReadConfigs = dcBusiWorkReadConfigService.selectDcBusiWorkReadConfigList(dwrc); - List pcl = dcBusiWorkReadConfigs.parallelStream().filter(o -> StringUtils.isNotEmpty(o.getGoalParamCode())).map(DcBusiWorkReadConfig::getGoalParamCode).collect(Collectors.toList()); - List dcl = dcBusiWorkReadConfigs.parallelStream().filter(o -> StringUtils.isNotEmpty(o.getGoalParamExt1())).map(DcBusiWorkReadConfig::getGoalParamExt1).collect(Collectors.toList()); - List listRow = getWorkReadVo(inComeDate, pcl, dcl); + Set pcl = dcBusiWorkReadConfigs.parallelStream().filter(o -> StringUtils.isNotEmpty(o.getGoalParamCode())).map(DcBusiWorkReadConfig::getGoalParamCode).collect(Collectors.toSet()); +// Set dcl = dcBusiWorkReadConfigs.parallelStream().filter(o -> StringUtils.isNotEmpty(o.getGoalParamExt1())).map(DcBusiWorkReadConfig::getGoalParamExt1).collect(Collectors.toSet()); + List listRow = getWorkReadVo(inComeDate, pcl); final String billNo_c = billNo; - listRow.stream().forEach(item -> { + listRow.forEach(item -> { Optional find = dcBusiWorkReadConfigs.parallelStream().filter(info -> { if (info.getGoalParamCode().equals(item.getParamCode())) { // && info.getGoalParamExt1().equals(item.getDeviceCode()) return true; 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 b28fe8c..0e3090f 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 @@ -5,7 +5,7 @@ import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; import javax.validation.constraints.NotNull; -import java.util.List; +import java.util.Set; /** * @auth create by Administrator @@ -25,7 +25,7 @@ public class ReadQueryParams { @DateTimeFormat(pattern = "yyyy-MM-dd HH") private String endTime; - private List deviceCodes; + private Set deviceCodes; - private List paramCodes; + private Set paramCodes; } diff --git a/lzbi-module/src/main/resources/mapper/asset/DcBusiWorkReadLogMapper.xml b/lzbi-module/src/main/resources/mapper/asset/DcBusiWorkReadLogMapper.xml index 681cd9f..ecade91 100644 --- a/lzbi-module/src/main/resources/mapper/asset/DcBusiWorkReadLogMapper.xml +++ b/lzbi-module/src/main/resources/mapper/asset/DcBusiWorkReadLogMapper.xml @@ -121,7 +121,7 @@ delete from dc_busi_work_read_log where date_count=#{beginTime} - and device_uuid in + and device_code in #{item} diff --git a/lzbi-module/src/main/resources/mapper/report/AjReportMapper.xml b/lzbi-module/src/main/resources/mapper/report/AjReportMapper.xml new file mode 100644 index 0000000..85e8a66 --- /dev/null +++ b/lzbi-module/src/main/resources/mapper/report/AjReportMapper.xml @@ -0,0 +1,60 @@ + + + + + + + + \ No newline at end of file diff --git a/lzbi-quartz/src/main/java/com/lzbi/quartz/task/SyncIotSystemTask.java b/lzbi-quartz/src/main/java/com/lzbi/quartz/task/SyncIotSystemTask.java index f0ebb09..53b9f12 100644 --- a/lzbi-quartz/src/main/java/com/lzbi/quartz/task/SyncIotSystemTask.java +++ b/lzbi-quartz/src/main/java/com/lzbi/quartz/task/SyncIotSystemTask.java @@ -18,10 +18,11 @@ public class SyncIotSystemTask { /** * 同步参数 * @param ifLog 是否存入日志 + * @param dateStr 同步数据的日期字符串 */ - public void syncIotParams(Boolean ifLog) { + public void syncIotParams(Boolean ifLog, String dateStr) { log.info("===========同步IOT参数开始,是否存入日志:{}============", ifLog); - taskWorkParamRead.runTask(ifLog); + taskWorkParamRead.runTask(ifLog, dateStr); log.info("===========同步IOT参数结束,是否存入日志:{}============", ifLog); } }