From fae4de653ee7f667a2ab44f940b4ec4e0b525b02 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Thu, 3 Aug 2023 15:31:09 +0800 Subject: [PATCH] =?UTF-8?q?#=E6=97=A5=E5=B8=B8=E7=BB=B4=E6=8A=A4=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=B4=BE=E5=8F=91=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vo/OperMaintenanceTaskEntityVo.java | 222 +++ .../com/hnac/hzinfo/inspect/task/TaskContants.java | 8 +- .../mapper/operation/MaintenancePlanMapper.java | 11 + .../scheduled/scheduled/BusinessScheduledTask.java | 21 +- .../scheduled/scheduled/MonitorScheduledTask.java | 2 +- .../scheduled/RealTargetScheduledTask.java | 3 +- .../scheduled/scheduled/ReportScheduledTask.java | 2 +- .../scheduled/scheduled/ShowScheduledTask.java | 3 +- .../service/inspect/impl/TaskServiceImpl.java | 2 +- .../service/operation/AbnormalAlarmService.java | 15 - .../scheduled/service/operation/AccessService.java | 17 - .../scheduled/service/operation/DataService.java | 27 - .../scheduled/service/operation/DefectService.java | 14 - .../service/operation/DutyMainService.java | 13 - .../scheduled/service/operation/DutyService.java | 15 - .../service/operation/GenerateService.java | 25 - .../service/operation/MaintenanceService.java | 22 - .../service/operation/ModelStationService.java | 12 - .../service/operation/MonitorService.java | 21 - .../scheduled/service/operation/OtherService.java | 11 - .../service/operation/OverDetailsService.java | 12 - .../scheduled/service/operation/OverService.java | 11 - .../service/operation/PhenomenonService.java | 18 - .../scheduled/service/operation/PowerService.java | 17 - .../service/operation/RealTargetService.java | 37 - .../scheduled/service/operation/RecordService.java | 13 - .../scheduled/service/operation/ReportService.java | 9 - .../scheduled/service/operation/ShowService.java | 13 - .../scheduled/service/operation/SolveService.java | 11 - .../operation/StationAttrConfigService.java | 14 - .../service/operation/StationAttributeService.java | 14 - .../service/operation/StationService.java | 12 - .../scheduled/service/operation/UseService.java | 29 - .../operation/alarm/AbnormalAlarmService.java | 15 + .../service/operation/alarm/RecordService.java | 13 + .../alarm/impl/AbnormalAlarmServiceImpl.java | 33 + .../operation/alarm/impl/RecordServiceImpl.java | 36 + .../service/operation/business/AccessService.java | 17 + .../service/operation/business/DefectService.java | 14 + .../operation/business/DutyMainService.java | 13 + .../service/operation/business/DutyService.java | 15 + .../operation/business/MaintenancePlanService.java | 11 + .../operation/business/MaintenanceService.java | 23 + .../operation/business/PhenomenonService.java | 18 + .../operation/business/impl/AccessServiceImpl.java | 86 ++ .../operation/business/impl/DefectServiceImpl.java | 55 + .../business/impl/DutyMainServiceImpl.java | 44 + .../operation/business/impl/DutyServiceImpl.java | 176 +++ .../business/impl/MaintenancePlanServiceImpl.java | 19 + .../business/impl/MaintenanceServiceImpl.java | 294 ++++ .../business/impl/PhenomenonServiceImpl.java | 99 ++ .../service/operation/fill/GenerateService.java | 25 + .../service/operation/fill/OtherService.java | 11 + .../service/operation/fill/OverDetailsService.java | 12 + .../service/operation/fill/OverService.java | 11 + .../service/operation/fill/PowerService.java | 17 + .../service/operation/fill/SolveService.java | 11 + .../service/operation/fill/UseService.java | 29 + .../operation/fill/impl/GenerateServiceImpl.java | 112 ++ .../operation/fill/impl/OtherServiceImpl.java | 19 + .../fill/impl/OverDetailsServiceImpl.java | 19 + .../operation/fill/impl/OverServiceImpl.java | 19 + .../operation/fill/impl/PowerServiceImpl.java | 77 + .../operation/fill/impl/SolveServiceImpl.java | 20 + .../operation/fill/impl/UseServiceImpl.java | 99 ++ .../operation/home/ModelStationService.java | 12 + .../service/operation/home/RealTargetService.java | 37 + .../service/operation/home/ShowService.java | 13 + .../home/impl/ModelStationServiceImpl.java | 16 + .../operation/home/impl/RealTargetServiceImpl.java | 1580 ++++++++++++++++++++ .../operation/home/impl/ShowServiceImpl.java | 1275 ++++++++++++++++ .../operation/impl/AbnormalAlarmServiceImpl.java | 33 - .../service/operation/impl/AccessServiceImpl.java | 86 -- .../service/operation/impl/DataServiceImpl.java | 161 -- .../service/operation/impl/DefectServiceImpl.java | 55 - .../operation/impl/DutyMainServiceImpl.java | 44 - .../service/operation/impl/DutyServiceImpl.java | 176 --- .../operation/impl/GenerateServiceImpl.java | 112 -- .../operation/impl/MaintenanceServiceImpl.java | 124 -- .../operation/impl/ModelStationServiceImpl.java | 16 - .../service/operation/impl/MonitorServiceImpl.java | 747 --------- .../service/operation/impl/OtherServiceImpl.java | 19 - .../operation/impl/OverDetailsServiceImpl.java | 19 - .../service/operation/impl/OverServiceImpl.java | 19 - .../operation/impl/PhenomenonServiceImpl.java | 99 -- .../service/operation/impl/PowerServiceImpl.java | 77 - .../operation/impl/RealTargetServiceImpl.java | 1573 ------------------- .../service/operation/impl/RecordServiceImpl.java | 36 - .../service/operation/impl/ReportServiceImpl.java | 527 ------- .../service/operation/impl/ShowServiceImpl.java | 1271 ---------------- .../service/operation/impl/SolveServiceImpl.java | 20 - .../impl/StationAttrConfigServiceImpl.java | 34 - .../impl/StationAttributeServiceImpl.java | 36 - .../service/operation/impl/StationServiceImpl.java | 19 - .../service/operation/impl/UseServiceImpl.java | 99 -- .../service/operation/monitor/MonitorService.java | 21 + .../operation/monitor/impl/MonitorServiceImpl.java | 752 ++++++++++ .../service/operation/plate/DataService.java | 27 + .../operation/plate/impl/DataServiceImpl.java | 161 ++ .../service/operation/report/ReportService.java | 9 + .../operation/report/impl/ReportServiceImpl.java | 531 +++++++ .../station/StationAttrConfigService.java | 14 + .../operation/station/StationAttributeService.java | 14 + .../service/operation/station/StationService.java | 12 + .../station/impl/StationAttrConfigServiceImpl.java | 34 + .../station/impl/StationAttributeServiceImpl.java | 36 + .../operation/station/impl/StationServiceImpl.java | 19 + .../mapper/operation/MaintenancePlanMapper.xml | 5 + .../main/service/impl/WindHomeServiceImpl.java | 1 - .../scheduled/MaintenanceTaskCreateTask.java | 2 +- .../vo/OperMaintenanceTaskEntityVo.java | 222 --- 111 files changed, 6291 insertions(+), 6042 deletions(-) create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/vo/OperMaintenanceTaskEntityVo.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/operation/MaintenancePlanMapper.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/AbnormalAlarmService.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/AccessService.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/DataService.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/DefectService.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/DutyMainService.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/DutyService.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/GenerateService.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/MaintenanceService.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/ModelStationService.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/MonitorService.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/OtherService.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/OverDetailsService.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/OverService.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/PhenomenonService.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/PowerService.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/RealTargetService.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/RecordService.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/ReportService.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/ShowService.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/SolveService.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/StationAttrConfigService.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/StationAttributeService.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/StationService.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/UseService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/alarm/AbnormalAlarmService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/alarm/RecordService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/alarm/impl/AbnormalAlarmServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/alarm/impl/RecordServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/AccessService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/DefectService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/DutyMainService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/DutyService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/MaintenancePlanService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/MaintenanceService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/PhenomenonService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/AccessServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/DefectServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/DutyMainServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/DutyServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/MaintenancePlanServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/MaintenanceServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/PhenomenonServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/GenerateService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/OtherService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/OverDetailsService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/OverService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/PowerService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/SolveService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/UseService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/GenerateServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/OtherServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/OverDetailsServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/OverServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/PowerServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/SolveServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/UseServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/ModelStationService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/RealTargetService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/ShowService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ModelStationServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ShowServiceImpl.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/AbnormalAlarmServiceImpl.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/AccessServiceImpl.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/DataServiceImpl.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/DefectServiceImpl.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/DutyMainServiceImpl.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/DutyServiceImpl.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/GenerateServiceImpl.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/MaintenanceServiceImpl.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/ModelStationServiceImpl.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/MonitorServiceImpl.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/OtherServiceImpl.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/OverDetailsServiceImpl.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/OverServiceImpl.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/PhenomenonServiceImpl.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/PowerServiceImpl.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/RealTargetServiceImpl.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/RecordServiceImpl.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/ReportServiceImpl.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/ShowServiceImpl.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/SolveServiceImpl.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/StationAttrConfigServiceImpl.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/StationAttributeServiceImpl.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/StationServiceImpl.java delete mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/UseServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/MonitorService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/plate/DataService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/plate/impl/DataServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/report/ReportService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/report/impl/ReportServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/station/StationAttrConfigService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/station/StationAttributeService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/station/StationService.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/station/impl/StationAttrConfigServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/station/impl/StationAttributeServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/station/impl/StationServiceImpl.java create mode 100644 hzims-service/hzims-scheduled/src/main/resources/mapper/operation/MaintenancePlanMapper.xml delete mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/vo/OperMaintenanceTaskEntityVo.java diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/vo/OperMaintenanceTaskEntityVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/vo/OperMaintenanceTaskEntityVo.java new file mode 100644 index 0000000..67d23bb --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/maintenance/vo/OperMaintenanceTaskEntityVo.java @@ -0,0 +1,222 @@ +package com.hnac.hzims.operational.maintenance.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springblade.core.tool.utils.DateUtil; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; +import java.util.Date; + +/** + * 日常维护对象 + * @Author WL + * @Version v1.0 + * @Serial 1.0 + * @Date 2023/6/13 17:20 + */ +@Data +public class OperMaintenanceTaskEntityVo { + + + private static final long serialVersionUID = 1L; + + + /** + * 主键id + */ + @ApiModelProperty(value = "主键id") + private Long id; + + /** + * 创建人 + */ + private Long createUser; + + /** + * 创建部门 + */ + @ApiModelProperty(value = "创建部门") + private Long createDept; + + /** + * 创建时间 + */ + @DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME) + @JsonFormat(pattern = DateUtil.PATTERN_DATETIME) + @ApiModelProperty(value = "创建时间") + private Date createTime; + + /** + * 更新人 + */ + private Long updateUser; + + /** + * 更新时间 + */ + @DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME) + @JsonFormat(pattern = DateUtil.PATTERN_DATETIME) + @ApiModelProperty(value = "更新时间") + private Date updateTime; + + /** + * 状态[1:正常] + */ + @ApiModelProperty(value = "业务状态") + private Integer status; + + + /** + * 设备编码 + */ + @ApiModelProperty(value = "设备编码") + private String emCode; + /** + * 维护类型 01=定期试验 02=定期保养 03=定期操作 04=其他 + */ + @ApiModelProperty(value = "维护类型 01=定期试验 02=定期保养 03=定期操作 04=其他") + private String typeCode; + /** + * 任务编码 + */ + @ApiModelProperty(value = "任务编码,后台自动生成") + private String taskCode; + /** + * 维护项目 + */ + @ApiModelProperty(value = "维护项目") + private Long refLibraryId; + + /** + * 维护标题 + */ + @ApiModelProperty(value = "维护标题") + private String title; + /** + * 工作流实例ID + */ + @ApiModelProperty(value = "工作流实例ID") + private String processInstanceId; + + + /** + * 执行人 + */ + @ApiModelProperty(value = "执行人") + private String disposer; + /** + * 执行日期 + */ + @ApiModelProperty(value = "任务按周期生成计划时间") + private Date disposeTime; + + @ApiModelProperty(value = "执行时间") + private LocalDateTime executeTime; + /** + * 标准工时 + */ + @ApiModelProperty(value = "标准工时") + private Integer hours; + /** + * 实际工时 + */ + @ApiModelProperty(value = "实际工时") + private Integer actHours; + /** + * 维护内容 + */ + @ApiModelProperty(value = "维护内容") + private String content; + /** + * 操作规范 + */ + @ApiModelProperty(value = "操作规范") + private String workStandards; + /** + * 安全警告 + */ + @ApiModelProperty(value = "安全警告") + private String safo; + /** + * 是否异常 0=否 1=是 + */ + @ApiModelProperty(value = "是否异常 0=否 1=是") + private Integer isAnomaly; + /** + * 遗留问题 + */ + @ApiModelProperty(value = "遗留问题") + private String legacy; + /** + * 问题描述 + */ + @ApiModelProperty(value = "问题描述") + private String description; + + @ApiModelProperty(value = "任务类型") + private String taskType; + + @ApiModelProperty(value = "票据ID") + private Long ticketId; + + @ApiModelProperty(value = "延期状态") + private Integer delayStatus; + + @ApiModelProperty(value = "延期时间") + private LocalDateTime delayDate; + + @ApiModelProperty(value = "计划结束时间") + @DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME) + @JsonFormat(pattern = DateUtil.PATTERN_DATETIME) + private LocalDateTime planEndTime; + + @ApiModelProperty("计划ID") + private Long planId; + + @ApiModelProperty(value = "消息推送模板ID") + private Long messageTemplateId; + + + /** + * 流程状态' + */ + @ApiModelProperty("流程状态") + private Integer flowStatus; + + /** + * 流程描述 + */ + @ApiModelProperty("流程描述") + private String flowDescription; + + + + /** + * 下一个审批人 + */ + @ApiModelProperty("下一个审批人") + private String nextStepOperator; + + + /** + * 用户Id + */ + @ApiModelProperty("用户Id") + private String flowUserId; + + + /** + * 当前任务名 + */ + @ApiModelProperty("当前任务名") + private String flowTaskName; + + + /** + * 当前任务名 + */ + @ApiModelProperty("当前任务名") + private String flowTaskId; +} diff --git a/hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/task/TaskContants.java b/hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/task/TaskContants.java index 3d1e0b2..8dbc67e 100644 --- a/hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/task/TaskContants.java +++ b/hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/task/TaskContants.java @@ -5,18 +5,18 @@ package com.hnac.hzinfo.inspect.task; import lombok.Getter; -import java.util.HashSet; -import java.util.Set; - /** * @author ninglong * */ public interface TaskContants { - // 巡检任务派发 定时任务 + // 巡检任务派发 String INSPECT_TASK_DISTRIBUTE = "taskJobDistribute"; + // 日常维护任务派发 + String MAINTENANCE_TASK_DISTRIBUTE = "maintenanceTaskDistribute"; + /** * 处理同时开启几个任务的 */ diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/operation/MaintenancePlanMapper.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/operation/MaintenancePlanMapper.java new file mode 100644 index 0000000..58f1b12 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/operation/MaintenancePlanMapper.java @@ -0,0 +1,11 @@ +package com.hnac.hzims.scheduled.mapper.operation; + +import com.hnac.hzims.operational.maintenance.entity.OperMaintenancePlanEntity; +import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; + +/** + * @author ysj + */ +public interface MaintenancePlanMapper extends UserDataScopeBaseMapper { + +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/BusinessScheduledTask.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/BusinessScheduledTask.java index 1c353d9..f908b36 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/BusinessScheduledTask.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/BusinessScheduledTask.java @@ -1,6 +1,7 @@ package com.hnac.hzims.scheduled.scheduled; import com.hnac.hzims.scheduled.service.inspect.TaskService; +import com.hnac.hzims.scheduled.service.operation.business.MaintenanceService; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.annotation.XxlJob; import lombok.extern.slf4j.Slf4j; @@ -9,8 +10,7 @@ import org.springblade.core.tool.utils.Func; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.Date; - -import static com.hnac.hzinfo.inspect.task.TaskContants.INSPECT_TASK_DISTRIBUTE; +import static com.hnac.hzinfo.inspect.task.TaskContants.*; /** @@ -24,8 +24,10 @@ public class BusinessScheduledTask { @Autowired private TaskService service; + private MaintenanceService maintenanceService; + /** - * 首页-指标数据加载 + * 巡检任务派发 : 一分钟执行一次 */ @XxlJob(INSPECT_TASK_DISTRIBUTE) //@Scheduled(cron = "0/40 * * * * ? ") @@ -37,4 +39,17 @@ public class BusinessScheduledTask { return new ReturnT<>("SUCCESS"); } + /** + * 巡检任务派发 : 一天执行一次 凌晨0时执行 + */ + @XxlJob(MAINTENANCE_TASK_DISTRIBUTE) + //@Scheduled(cron = "0/40 * * * * ? ") + public ReturnT maintenanceTaskDistribute(String param) { + if (Func.isBlank(param)) { + param = DateUtil.format(new Date(), "yyyy-MM"); + } + maintenanceService.maintenanceTaskDistribute(param); + return new ReturnT<>("SUCCESS"); + } + } \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/MonitorScheduledTask.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/MonitorScheduledTask.java index 78cb8d8..3000218 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/MonitorScheduledTask.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/MonitorScheduledTask.java @@ -1,6 +1,6 @@ package com.hnac.hzims.scheduled.scheduled; -import com.hnac.hzims.scheduled.service.operation.MonitorService; +import com.hnac.hzims.scheduled.service.operation.monitor.MonitorService; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.annotation.XxlJob; import lombok.extern.slf4j.Slf4j; diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java index 6a55529..878486f 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java @@ -1,14 +1,13 @@ package com.hnac.hzims.scheduled.scheduled; import com.hnac.hzims.operational.main.constant.HomePageConstant; -import com.hnac.hzims.scheduled.service.operation.RealTargetService; +import com.hnac.hzims.scheduled.service.operation.home.RealTargetService; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.annotation.XxlJob; import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.Func; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.util.Arrays; diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/ReportScheduledTask.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/ReportScheduledTask.java index 5146c24..7010e3b 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/ReportScheduledTask.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/ReportScheduledTask.java @@ -1,6 +1,6 @@ package com.hnac.hzims.scheduled.scheduled; -import com.hnac.hzims.scheduled.service.operation.ReportService; +import com.hnac.hzims.scheduled.service.operation.report.ReportService; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.annotation.XxlJob; import lombok.extern.slf4j.Slf4j; diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/ShowScheduledTask.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/ShowScheduledTask.java index e10c021..6c0a431 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/ShowScheduledTask.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/ShowScheduledTask.java @@ -1,13 +1,12 @@ package com.hnac.hzims.scheduled.scheduled; -import com.hnac.hzims.scheduled.service.operation.ShowService; +import com.hnac.hzims.scheduled.service.operation.home.ShowService; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.annotation.XxlJob; import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.Func; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.util.Date; diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/inspect/impl/TaskServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/inspect/impl/TaskServiceImpl.java index bbebe02..0aea939 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/inspect/impl/TaskServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/inspect/impl/TaskServiceImpl.java @@ -12,7 +12,7 @@ import com.google.common.collect.Lists; import com.hnac.hzims.operational.duty.vo.ImsDutyMainFeignVO; import com.hnac.hzims.scheduled.mapper.inspect.TaskMapper; import com.hnac.hzims.scheduled.service.inspect.*; -import com.hnac.hzims.scheduled.service.operation.DutyMainService; +import com.hnac.hzims.scheduled.service.operation.business.DutyMainService; import com.hnac.hzinfo.inspect.obj.entity.*; import com.hnac.hzinfo.inspect.plan.PlanContants; import com.hnac.hzinfo.inspect.plan.entity.*; diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/AbnormalAlarmService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/AbnormalAlarmService.java deleted file mode 100644 index 53997ff..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/AbnormalAlarmService.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation; - -import com.hnac.hzims.operational.alert.entity.AbnormalAlarmEntity; -import org.springblade.core.mp.base.BaseService; - -import java.util.List; - -/** - * 告警处理接口 - * @author ysj - */ -public interface AbnormalAlarmService extends BaseService { - - List abnormalAlarms(); -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/AccessService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/AccessService.java deleted file mode 100644 index 9a2d858..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/AccessService.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation; - -import com.hnac.hzims.operational.access.entity.OperAccessTaskEntity; -import com.hnac.hzims.operational.main.vo.OverhaulVo; -import org.springblade.core.mp.base.BaseService; - -import java.util.List; - -/** - * @author ysj - */ -public interface AccessService extends BaseService { - - double accessCount(List areas); - - OverhaulVo overhaul(String start, String end, List areas); -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/DataService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/DataService.java deleted file mode 100644 index 166658f..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/DataService.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation; - -import com.hnac.hzinfo.datasearch.analyse.domain.FieldsData; -import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO; -import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeCodeBySignagesVO; -import com.hnac.hzinfo.sdk.analyse.po.MultiAnalyzeCodePO; -import org.springblade.core.tool.api.R; - -import java.util.List; -import java.util.function.Function; - - -/** - * @author ysj - */ -public interface DataService { - - List getAnalyzeCodeBySignages(Function convert, T resource); - - List analyzeCodeBySignages(List list); - - List getRealDataByAnalyzeCode(String instanceCode, List signages); - - List periodTargetData(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode, String signages); - - Float periodTargetFloat(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode, Integer ride ,String signages); -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/DefectService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/DefectService.java deleted file mode 100644 index 929732f..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/DefectService.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation; - -import com.hnac.hzims.operational.defect.entity.OperDefectEntity; -import org.springblade.core.mp.base.BaseService; - -import java.util.List; - -/** - * @author Lch - */ -public interface DefectService extends BaseService { - - Double defectCount(List areas); -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/DutyMainService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/DutyMainService.java deleted file mode 100644 index 1fe0e7e..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/DutyMainService.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation; - -import com.hnac.hzims.operational.duty.entity.ImsDutyMainEntity; -import com.hnac.hzims.operational.duty.vo.ImsDutyMainFeignVO; -import org.springblade.core.mp.base.BaseService; - - -/** - * @author ysj - */ -public interface DutyMainService extends BaseService { - ImsDutyMainFeignVO mainPerson(Long classId, String date); -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/DutyService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/DutyService.java deleted file mode 100644 index 08efdcd..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/DutyService.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation; - -import com.hnac.hzims.operational.duty.entity.ImsDutyMainEntity; -import com.hnac.hzims.operational.duty.vo.DutyInfoVo; -import org.springblade.core.mp.base.BaseService; - -import java.util.List; - -/** - * @author ysj - */ -public interface DutyService extends BaseService { - - List dutyData(List collect); -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/GenerateService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/GenerateService.java deleted file mode 100644 index 8f9e1b1..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/GenerateService.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation; - -import com.hnac.hzims.operational.fill.entity.GenerateEntity; -import com.hnac.hzims.operational.main.vo.GenerationPowerVo; -import com.hnac.hzims.operational.main.vo.PowerMonthVo; -import org.springblade.core.mp.base.BaseService; - -import java.util.List; - -/** - * @author ysj - * @date 2023/04/10 11:16:07 - * @version 4.0.0 - */ -public interface GenerateService extends BaseService { - - // 查询填报用电量 - Float generate(String date,String station); - - // 查询30天填报用电量 - List generate30Day(String day, String station); - - // 获取站点填报发电量 - List generateThreeYear(String start, String end, String station); -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/MaintenanceService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/MaintenanceService.java deleted file mode 100644 index b193f91..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/MaintenanceService.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation; - -import com.hnac.hzims.operational.main.vo.MaintainVo; -import com.hnac.hzims.operational.main.vo.RegularWorkVO; -import com.hnac.hzims.operational.maintenance.entity.OperMaintenanceTaskEntity; -import org.springblade.core.mp.base.BaseService; - -import java.util.Date; -import java.util.List; - -/** - * @author ysj - */ -public interface MaintenanceService extends BaseService { - - // 查询当年日常维护数量 - Integer maintenanceCount(List areas); - - MaintainVo maintain(String start, String end, List areas); - - RegularWorkVO regularWork(Date start, Date end, List areas); -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/ModelStationService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/ModelStationService.java deleted file mode 100644 index e8e4560..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/ModelStationService.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation; - - -import com.hnac.hzims.operational.station.entity.HzimsAnalyzeModelStationEntity; -import org.springblade.core.mp.base.BaseService; - -/** - * @author ysj - */ -public interface ModelStationService extends BaseService { - -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/MonitorService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/MonitorService.java deleted file mode 100644 index 5df3786..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/MonitorService.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation; - -import org.springblade.core.tool.api.R; - -import java.util.Map; - -/** - * WEB水电站首页接口 - * @author ysj - */ -public interface MonitorService { - - // realId刷新 - void loadRealId(String param); - - // 实时数据刷新 - void loadRealData(String param); - - // 集中监控数据处理 - void loadMonitoring(String param); -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/OtherService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/OtherService.java deleted file mode 100644 index 50451a4..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/OtherService.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation; - -import com.hnac.hzims.operational.fill.entity.OtherEntity; -import org.springblade.core.mp.base.BaseService; - -/** - * @author ysj - */ -public interface OtherService extends BaseService { - -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/OverDetailsService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/OverDetailsService.java deleted file mode 100644 index 13e6eab..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/OverDetailsService.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation; - - -import com.hnac.hzims.operational.fill.entity.OverDetailsEntity; -import org.springblade.core.mp.base.BaseService; - -/** - * @author ysj - */ -public interface OverDetailsService extends BaseService { - -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/OverService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/OverService.java deleted file mode 100644 index 3412374..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/OverService.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation; - -import com.hnac.hzims.operational.fill.entity.OverEntity; -import org.springblade.core.mp.base.BaseService; - -/** - * @author ysj - */ -public interface OverService extends BaseService { - -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/PhenomenonService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/PhenomenonService.java deleted file mode 100644 index 362fbe9..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/PhenomenonService.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation; - -import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity; -import com.hnac.hzims.operational.main.vo.ShortagesVo; -import com.hnac.hzims.operational.report.vo.DutyDefectVO; -import org.springblade.core.mp.base.BaseService; - -import java.util.List; - -/** - * @author ysj - */ -public interface PhenomenonService extends BaseService { - - DutyDefectVO defect(String start, String end, List areas); - - ShortagesVo defectMonth(String start, String end, List list); -} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/PowerService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/PowerService.java deleted file mode 100644 index d6d3007..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/PowerService.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation; - -import com.hnac.hzims.operational.fill.entity.PowerEntity; -import com.hnac.hzims.operational.main.vo.PowerMonthVo; -import org.springblade.core.mp.base.BaseService; - -import java.util.List; - -/** - * @author ysj - */ -public interface PowerService extends BaseService { - - Double generate(String date,Long station); - - List generateThreeYear(String start,String end,Long station); -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/RealTargetService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/RealTargetService.java deleted file mode 100644 index 042f5d2..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/RealTargetService.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation; - -import java.util.List; - -/** - * WEB水电站首页接口 - * @author ysj - */ -public interface RealTargetService { - - - void loadEmInfo(); - - // 水电站实时数据加载 - void loadHydropowerReal(String param); - - // 水电站指标数据加载 - void loadHydropowerTarget(String param); - - // 泵站实时数据加载 - void loadWaterPumpReal(String param); - - // 泵站指标数据加载 - void loadWaterPumpTarget(String param); - - // 站点水位指标数据 - void loadWaterLevel(String param); - - // 光伏站实时数据加载 - void loadPhotovoltaicReal(String param); - - // 光伏站指标数据加载 - void loadPhotovoltaicTarget(String param); - - // 光伏、水电站近3年发电量 - void loadPowerData(String param, List types, Integer serveType, int year); -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/RecordService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/RecordService.java deleted file mode 100644 index 00da41d..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/RecordService.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation; - - -import com.hnac.hzims.operational.config.entity.StAlarmRecordEntity; -import org.springblade.core.mp.base.BaseService; - -/** - * @author ysj - */ -public interface RecordService extends BaseService { - - Long insertAlert(String stationId, String monitorId); -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/ReportService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/ReportService.java deleted file mode 100644 index 2fe62ac..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/ReportService.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation; - -/** - * @author ysj - */ -public interface ReportService { - - void loadMonthReport(String param, int i); -} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/ShowService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/ShowService.java deleted file mode 100644 index 8bef00c..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/ShowService.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation; - -/** - * @author ysj - */ -public interface ShowService { - - void loadHomeTarget(String param); - - void loadRegionalDuty(String param); - - void loaddDeviceClassify(String param); -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/SolveService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/SolveService.java deleted file mode 100644 index 5888433..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/SolveService.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation; - -import com.hnac.hzims.operational.fill.entity.SolveEntity; -import org.springblade.core.mp.base.BaseService; - -/** - * @author ysj - */ -public interface SolveService extends BaseService { - -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/StationAttrConfigService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/StationAttrConfigService.java deleted file mode 100644 index 47dce3f..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/StationAttrConfigService.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation; - -import com.hnac.hzims.operational.station.entity.StationAttrConfigEntity; -import org.springblade.core.mp.base.BaseService; - -import java.util.List; - -/** - * @author ysj - */ -public interface StationAttrConfigService extends BaseService { - - List getHideList(); -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/StationAttributeService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/StationAttributeService.java deleted file mode 100644 index 53479ba..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/StationAttributeService.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation; - -import com.hnac.hzims.operational.station.entity.StationAttributeEntity; -import org.springblade.core.mp.base.BaseService; - -import java.util.Map; - -/** - * @author hx - */ -public interface StationAttributeService extends BaseService { - - Map PointUnit(); -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/StationService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/StationService.java deleted file mode 100644 index 2757282..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/StationService.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation; - -import com.hnac.hzims.operational.station.entity.StationEntity; -import org.springblade.core.mp.base.BaseService; - -/** - * @author ysj - */ -public interface StationService extends BaseService { - - -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/UseService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/UseService.java deleted file mode 100644 index 72dc927..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/UseService.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation; - -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.hnac.hzims.operational.fill.entity.UseEntity; -import com.hnac.hzims.operational.fill.vo.QueryVo; -import com.hnac.hzims.operational.fill.vo.UseVo; -import com.hnac.hzims.operational.main.vo.UsrPowerVo; -import org.springblade.core.mp.base.BaseService; -import org.springblade.core.mp.support.Query; -import org.springblade.core.tool.api.R; - -import java.util.List; -import java.util.Map; - -/** - * @author ysj - * @date 2023/04/10 11:16:07 - * @version 4.0.0 - */ -public interface UseService extends BaseService { - - // 查询填报用电量 - Float use(String date,String station); - - // 查询30天填报用电量 - List use30Day(String day, String station); - - Map generateThreeYear(String start, String end, String station); -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/alarm/AbnormalAlarmService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/alarm/AbnormalAlarmService.java new file mode 100644 index 0000000..3151c43 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/alarm/AbnormalAlarmService.java @@ -0,0 +1,15 @@ +package com.hnac.hzims.scheduled.service.operation.alarm; + +import com.hnac.hzims.operational.alert.entity.AbnormalAlarmEntity; +import org.springblade.core.mp.base.BaseService; + +import java.util.List; + +/** + * 告警处理接口 + * @author ysj + */ +public interface AbnormalAlarmService extends BaseService { + + List abnormalAlarms(); +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/alarm/RecordService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/alarm/RecordService.java new file mode 100644 index 0000000..6710773 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/alarm/RecordService.java @@ -0,0 +1,13 @@ +package com.hnac.hzims.scheduled.service.operation.alarm; + + +import com.hnac.hzims.operational.config.entity.StAlarmRecordEntity; +import org.springblade.core.mp.base.BaseService; + +/** + * @author ysj + */ +public interface RecordService extends BaseService { + + Long insertAlert(String stationId, String monitorId); +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/alarm/impl/AbnormalAlarmServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/alarm/impl/AbnormalAlarmServiceImpl.java new file mode 100644 index 0000000..4fe12b2 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/alarm/impl/AbnormalAlarmServiceImpl.java @@ -0,0 +1,33 @@ +package com.hnac.hzims.scheduled.service.operation.alarm.impl; + +import com.hnac.hzims.operational.alert.entity.AbnormalAlarmEntity; +import com.hnac.hzims.scheduled.mapper.operation.AbnormalAlarmMapper; +import com.hnac.hzims.scheduled.service.operation.alarm.AbnormalAlarmService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +/** + * 告警实现类 + * @author ysj + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class AbnormalAlarmServiceImpl extends BaseServiceImpl implements AbnormalAlarmService { + + + @Override + public List abnormalAlarms() { + List alarmList = this.baseMapper.abnormalAlarms(); + if(CollectionUtil.isEmpty(alarmList)){ + return new ArrayList<>(); + } + return alarmList; + } +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/alarm/impl/RecordServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/alarm/impl/RecordServiceImpl.java new file mode 100644 index 0000000..b6e6f67 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/alarm/impl/RecordServiceImpl.java @@ -0,0 +1,36 @@ +package com.hnac.hzims.scheduled.service.operation.alarm.impl; + +import com.hnac.hzims.operational.config.entity.StAlarmRecordEntity; +import com.hnac.hzims.scheduled.mapper.operation.RecordMapper; +import com.hnac.hzims.scheduled.service.operation.alarm.RecordService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +import java.util.Date; + +/** + * @author ysj + */ +@Service +@RequiredArgsConstructor +@Slf4j +public class RecordServiceImpl extends BaseServiceImpl implements RecordService { + + /** + * 添加告警 + * @param stationId + * @param realId + * @return + */ + @Override + public Long insertAlert(String stationId, String realId) { + StAlarmRecordEntity record = new StAlarmRecordEntity(); + record.setStationId(stationId); + record.setRealId(realId); + record.setStatus(0); + record.setCreateTime(new Date()); + return this.baseMapper.insertReturnId(record); + } +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/AccessService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/AccessService.java new file mode 100644 index 0000000..f3a92cf --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/AccessService.java @@ -0,0 +1,17 @@ +package com.hnac.hzims.scheduled.service.operation.business; + +import com.hnac.hzims.operational.access.entity.OperAccessTaskEntity; +import com.hnac.hzims.operational.main.vo.OverhaulVo; +import org.springblade.core.mp.base.BaseService; + +import java.util.List; + +/** + * @author ysj + */ +public interface AccessService extends BaseService { + + double accessCount(List areas); + + OverhaulVo overhaul(String start, String end, List areas); +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/DefectService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/DefectService.java new file mode 100644 index 0000000..8b58712 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/DefectService.java @@ -0,0 +1,14 @@ +package com.hnac.hzims.scheduled.service.operation.business; + +import com.hnac.hzims.operational.defect.entity.OperDefectEntity; +import org.springblade.core.mp.base.BaseService; + +import java.util.List; + +/** + * @author Lch + */ +public interface DefectService extends BaseService { + + Double defectCount(List areas); +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/DutyMainService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/DutyMainService.java new file mode 100644 index 0000000..192ed9a --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/DutyMainService.java @@ -0,0 +1,13 @@ +package com.hnac.hzims.scheduled.service.operation.business; + +import com.hnac.hzims.operational.duty.entity.ImsDutyMainEntity; +import com.hnac.hzims.operational.duty.vo.ImsDutyMainFeignVO; +import org.springblade.core.mp.base.BaseService; + + +/** + * @author ysj + */ +public interface DutyMainService extends BaseService { + ImsDutyMainFeignVO mainPerson(Long classId, String date); +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/DutyService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/DutyService.java new file mode 100644 index 0000000..a0b20b1 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/DutyService.java @@ -0,0 +1,15 @@ +package com.hnac.hzims.scheduled.service.operation.business; + +import com.hnac.hzims.operational.duty.entity.ImsDutyMainEntity; +import com.hnac.hzims.operational.duty.vo.DutyInfoVo; +import org.springblade.core.mp.base.BaseService; + +import java.util.List; + +/** + * @author ysj + */ +public interface DutyService extends BaseService { + + List dutyData(List collect); +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/MaintenancePlanService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/MaintenancePlanService.java new file mode 100644 index 0000000..f8c1181 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/MaintenancePlanService.java @@ -0,0 +1,11 @@ +package com.hnac.hzims.scheduled.service.operation.business; + +import com.hnac.hzims.operational.maintenance.entity.OperMaintenancePlanEntity; +import org.springblade.core.mp.base.BaseService; + +/** + * @author ysj + */ +public interface MaintenancePlanService extends BaseService { + +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/MaintenanceService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/MaintenanceService.java new file mode 100644 index 0000000..2e2de53 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/MaintenanceService.java @@ -0,0 +1,23 @@ +package com.hnac.hzims.scheduled.service.operation.business; + +import com.hnac.hzims.operational.main.vo.MaintainVo; +import com.hnac.hzims.operational.main.vo.RegularWorkVO; +import com.hnac.hzims.operational.maintenance.entity.OperMaintenanceTaskEntity; +import org.springblade.core.mp.base.BaseService; + +import java.util.Date; +import java.util.List; + +/** + * @author ysj + */ +public interface MaintenanceService extends BaseService { + + void maintenanceTaskDistribute(String param); + + Integer maintenanceCount(List areas); + + MaintainVo maintain(String start, String end, List areas); + + RegularWorkVO regularWork(Date start, Date end, List areas); +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/PhenomenonService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/PhenomenonService.java new file mode 100644 index 0000000..26a354e --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/PhenomenonService.java @@ -0,0 +1,18 @@ +package com.hnac.hzims.scheduled.service.operation.business; + +import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity; +import com.hnac.hzims.operational.main.vo.ShortagesVo; +import com.hnac.hzims.operational.report.vo.DutyDefectVO; +import org.springblade.core.mp.base.BaseService; + +import java.util.List; + +/** + * @author ysj + */ +public interface PhenomenonService extends BaseService { + + DutyDefectVO defect(String start, String end, List areas); + + ShortagesVo defectMonth(String start, String end, List list); +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/AccessServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/AccessServiceImpl.java new file mode 100644 index 0000000..9788a7d --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/AccessServiceImpl.java @@ -0,0 +1,86 @@ +package com.hnac.hzims.scheduled.service.operation.business.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.hnac.hzims.operational.access.constants.AccessConstants; +import com.hnac.hzims.operational.access.entity.OperAccessTaskEntity; +import com.hnac.hzims.operational.main.vo.OverhaulVo; +import com.hnac.hzims.scheduled.mapper.operation.AccessMapper; +import com.hnac.hzims.scheduled.service.operation.business.AccessService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.Func; +import org.springframework.stereotype.Service; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author ysj + */ +@Service +@Slf4j +@AllArgsConstructor +public class AccessServiceImpl extends BaseServiceImpl implements AccessService { + + /** + * 查询当年检修任务数量 + * @param areas + * @return + */ + @Override + public double accessCount(List areas) { + if(CollectionUtil.isEmpty(areas)) { + return 0; + } + LocalDate firstDay = LocalDate.now().withDayOfYear(1); + LocalDateTime firstDateTime = LocalDateTime.of(firstDay, LocalTime.MIN); + LocalDateTime now = LocalDateTime.now(); + //日常维护 + List accesss = this.list(new LambdaQueryWrapper(){{ + ge(OperAccessTaskEntity::getPlanStartTime,firstDateTime); + le(OperAccessTaskEntity::getPlanStartTime,now); + in(OperAccessTaskEntity::getCreateDept,areas); + }}); + if(CollectionUtil.isEmpty(accesss)){ + return 0; + } + return accesss.size(); + } + + /** + * 时间区间机构的巡检数据查询 + * @param start + * @param end + * @param areas + * @return + */ + @Override + public OverhaulVo overhaul(String start, String end, List areas) { + OverhaulVo overhaulVo = new OverhaulVo(); + // 检修总数 + List overhaulList = this.list(new LambdaQueryWrapper(){{ + ge(OperAccessTaskEntity::getPlanStartTime,start); + le(OperAccessTaskEntity::getPlanStartTime,end); + in(OperAccessTaskEntity::getCreateDept,areas); + }}); + if(CollectionUtil.isEmpty(overhaulList)){ + overhaulVo.setOverhaul(0); + overhaulVo.setOverhaulFinish(0); + return overhaulVo; + } + overhaulVo.setOverhaul(overhaulList.size()); + // 检修完成数量 + List overhaulFinishTask = overhaulList.stream().filter(task-> Func.isNotEmpty(task.getStatus()) && AccessConstants.ACCESS_TASK_STATUS_4 == task.getStatus()) + .map(OperAccessTaskEntity::getId).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(overhaulFinishTask)){ + overhaulVo.setOverhaulFinish(0); + } + overhaulVo.setOverhaulFinish(overhaulFinishTask.size()); + return overhaulVo; + } +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/DefectServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/DefectServiceImpl.java new file mode 100644 index 0000000..fdf8987 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/DefectServiceImpl.java @@ -0,0 +1,55 @@ +package com.hnac.hzims.scheduled.service.operation.business.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.hnac.hzims.operational.defect.entity.OperDefectEntity; +import com.hnac.hzims.scheduled.mapper.operation.DefectMapper; +import com.hnac.hzims.scheduled.service.operation.business.DefectService; +import lombok.AllArgsConstructor; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author ysj + */ +@Service +@AllArgsConstructor +public class DefectServiceImpl extends BaseServiceImpl implements DefectService { + + /** + * 获取消缺率 + * @param areas + * @return + */ + @Override + public Double defectCount(List areas) { + if(CollectionUtil.isEmpty(areas)) { + return 100.00; + } + LocalDate firstDay = LocalDate.now().withDayOfYear(1); + LocalDateTime firstDateTime = LocalDateTime.of(firstDay, LocalTime.MIN); + LocalDateTime now = LocalDateTime.now(); + List pTaskList = this.list(new LambdaQueryWrapper(){{ + ge(OperDefectEntity::getCreateTime,firstDateTime); + le(OperDefectEntity::getCreateTime,now); + in(OperDefectEntity::getCreateDept,areas); + }}); + if(CollectionUtil.isEmpty(pTaskList)){ + return 0.0; + } + // 缺陷处理完成数 + List finishTask = pTaskList.stream().filter(defect -> "1".equals(defect.getHandleStatus())).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(finishTask)){ + return 0.0; + } + // 消缺率 = (缺陷数 / 总数) * 100 + return BigDecimal.valueOf(finishTask.size() / (double) pTaskList.size() * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + } +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/DutyMainServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/DutyMainServiceImpl.java new file mode 100644 index 0000000..626bcc0 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/DutyMainServiceImpl.java @@ -0,0 +1,44 @@ +package com.hnac.hzims.scheduled.service.operation.business.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.hnac.hzims.operational.duty.entity.ImsDutyMainEntity; +import com.hnac.hzims.operational.duty.vo.ImsDutyMainFeignVO; +import com.hnac.hzims.scheduled.mapper.operation.DutyMainMapper; +import com.hnac.hzims.scheduled.service.operation.business.DutyMainService; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.tool.utils.ObjectUtil; +import org.springframework.stereotype.Service; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 服务实现类 + * + * @author Chill + */ +@Service +@Slf4j +public class DutyMainServiceImpl extends BaseServiceImpl implements DutyMainService { + + + @Override + public ImsDutyMainFeignVO mainPerson(Long classId, String date) { + ImsDutyMainEntity entity = this.getOne(new LambdaQueryWrapper() {{ + eq(ImsDutyMainEntity::getDutyDate, date); + eq(ImsDutyMainEntity::getClassId, classId); + }}); + if(ObjectUtil.isEmpty(entity)){ + return new ImsDutyMainFeignVO(); + } + ImsDutyMainFeignVO main = new ImsDutyMainFeignVO(); + main.setMainId(entity.getId()); + String[] persons = entity.getDutyPersonIds().split("\\^"); + //string 转为 long + List personList = Arrays.stream(persons).map(person -> Long.parseLong(person.trim())).collect(Collectors.toList()); + main.setPersons(personList); + return main; + } +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/DutyServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/DutyServiceImpl.java new file mode 100644 index 0000000..7fe1682 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/DutyServiceImpl.java @@ -0,0 +1,176 @@ +package com.hnac.hzims.scheduled.service.operation.business.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.hnac.hzims.operational.duty.entity.ImsDutyGroupEntity; +import com.hnac.hzims.operational.duty.entity.ImsDutyMainEntity; +import com.hnac.hzims.operational.duty.entity.ImsDutyMainPersonEntity; +import com.hnac.hzims.operational.duty.vo.DutyInfoVo; +import com.hnac.hzims.operational.duty.vo.DutyMainInfoVo; +import com.hnac.hzims.operational.duty.vo.NextDutyInfoVo; +import com.hnac.hzims.scheduled.mapper.operation.DutyGroupMapper; +import com.hnac.hzims.scheduled.mapper.operation.DutyMapper; +import com.hnac.hzims.scheduled.mapper.operation.DutyPersonMapper; +import com.hnac.hzims.scheduled.service.operation.business.DutyService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.ObjectUtil; +import org.springblade.system.user.cache.UserCache; +import org.springblade.system.user.entity.User; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author ysj + */ +@Service +@AllArgsConstructor +@Slf4j +public class DutyServiceImpl extends BaseServiceImpl implements DutyService { + + private final DutyPersonMapper dutyPersonMapper; + private final DutyGroupMapper dutyGroupMapper; + + @Override + public List dutyData(List collect) { + if (CollectionUtil.isEmpty(collect)) { + return null; + } + // 查询区域当前值班 + List dutyInfoVoList = this.baseMapper.dutyData(collect); + if (CollectionUtil.isEmpty(dutyInfoVoList)) { + return null; + } + //修改数据结构后:分灵活排班和班组排班拿负责人 + dutyInfoVoList = dutyInfoVoList.stream().peek(s -> { + if (null == s.getGroupId()) { + ImsDutyMainPersonEntity imsDutyMainPersonEntity = dutyPersonMapper.selectOne(new LambdaQueryWrapper() {{ + eq(ImsDutyMainPersonEntity::getDutyMainId, s.getId()); + last(" limit 1"); + }}); + s.setManagerId(imsDutyMainPersonEntity.getDutyChargePerson().toString()); + } else { + ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(s.getGroupId()); + s.setGroupName(imsDutyGroupEntity.getGroupName()); + s.setManagerId(imsDutyGroupEntity.getManagerId().toString()); + } + }).collect(Collectors.toList()); + dutyInfoVoList.forEach(item -> { + // 负责人 + User user = UserCache.getUser(Long.valueOf(item.getManagerId())); + if (ObjectUtil.isNotEmpty(user)) { + item.setManagerName(user.getName()); + item.setManagerPhone(user.getPhone()); + } + // FIXME 上网 + item.setOnlineCapacity(0.0); + // 发电量 + item.setGeneratingCapacity(0); + // 上一班组 + NextDutyInfoVo upDutyInfoVo = this.getUpDutyInfo(item); + item.setUpDutyInfoVo(upDutyInfoVo); + // 下一班组 + NextDutyInfoVo nextDutyInfoVo = this.getNextDutyInfo(item); + item.setNextDutyInfoVo(nextDutyInfoVo); + }); + return dutyInfoVoList; + } + + + /** + * 获取上一班组 + * + * @param item + * @return + */ + private NextDutyInfoVo getUpDutyInfo(DutyInfoVo item) { + if(ObjectUtil.isEmpty(item.getPreDutyId())){ + return null; + } + DutyMainInfoVo dutyMainInfoVo = this.baseMapper.queryDuty(item.getPreDutyId()); + if (null == dutyMainInfoVo.getDutyGroupId()) { + ImsDutyMainPersonEntity imsDutyMainPersonEntity = dutyPersonMapper.selectOne(new LambdaQueryWrapper() {{ + eq(ImsDutyMainPersonEntity::getDutyMainId, dutyMainInfoVo.getId()); + last(" LIMIT 1"); + }}); + dutyMainInfoVo.setManagerId(imsDutyMainPersonEntity.getDutyChargePerson().toString()); + } else { + ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(dutyMainInfoVo.getDutyGroupId()); + dutyMainInfoVo.setGroupName(imsDutyGroupEntity.getGroupName()); + dutyMainInfoVo.setDutyGroupId(imsDutyGroupEntity.getId()); + dutyMainInfoVo.setManagerId(imsDutyGroupEntity.getManagerId().toString()); + } + if (ObjectUtil.isEmpty(dutyMainInfoVo)) { + return null; + } + // 赋值 + NextDutyInfoVo dutyInfoVo = new NextDutyInfoVo(); + dutyInfoVo.setGroupName(dutyMainInfoVo.getGroupName()); + dutyInfoVo.setClassName(dutyMainInfoVo.getClassName()); + dutyInfoVo.setDateTime(dutyMainInfoVo.getDateTime()); + dutyInfoVo.setStartTime(dutyMainInfoVo.getStartTime()); + dutyInfoVo.setEndTime(dutyMainInfoVo.getEndTime()); + // 负责人 + User user = UserCache.getUser(Long.valueOf(dutyMainInfoVo.getManagerId())); + if (ObjectUtil.isNotEmpty(user)) { + dutyInfoVo.setManagerName(user.getName()); + dutyInfoVo.setManagerPhone(user.getPhone()); + } + // 发电量 + dutyInfoVo.setGeneratingCapacity(0); + return dutyInfoVo; + } + + /** + * 获取下一班组 + * + * @param item + * @return + */ + private NextDutyInfoVo getNextDutyInfo(DutyInfoVo item) { + DutyMainInfoVo dutyMainInfoVo = this.nextDuty(item.getId()); + if (ObjectUtil.isEmpty(dutyMainInfoVo)) { + return null; + } + // 赋值 + NextDutyInfoVo dutyInfoVo = new NextDutyInfoVo(); + dutyInfoVo.setGroupName(dutyMainInfoVo.getGroupName()); + dutyInfoVo.setClassName(dutyMainInfoVo.getClassName()); + // 负责人 + User user = UserCache.getUser(Long.valueOf(dutyMainInfoVo.getManagerId())); + if (ObjectUtil.isNotEmpty(user)) { + dutyInfoVo.setManagerName(user.getName()); + dutyInfoVo.setManagerPhone(user.getPhone()); + } + dutyInfoVo.setGeneratingCapacity(0); + return dutyInfoVo; + } + + /** + * 下一班组 + * @param parentId + * @return + */ + public DutyMainInfoVo nextDuty(Long parentId) { + DutyMainInfoVo dutyMainInfoVo = this.baseMapper.selectDuty(parentId); + if(ObjectUtil.isEmpty(dutyMainInfoVo)){ + return new DutyMainInfoVo(); + } + if (null == dutyMainInfoVo.getDutyGroupId()) { + ImsDutyMainPersonEntity imsDutyMainPersonEntity = dutyPersonMapper.selectOne(new LambdaQueryWrapper() {{ + eq(ImsDutyMainPersonEntity::getDutyMainId, dutyMainInfoVo.getId()); + last("limit 1"); + }}); + dutyMainInfoVo.setManagerId(imsDutyMainPersonEntity.getDutyChargePerson().toString()); + } else { + ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(dutyMainInfoVo.getDutyGroupId()); + dutyMainInfoVo.setGroupName(imsDutyGroupEntity.getGroupName()); + dutyMainInfoVo.setDutyGroupId(imsDutyGroupEntity.getId()); + dutyMainInfoVo.setManagerId(imsDutyGroupEntity.getManagerId().toString()); + } + return dutyMainInfoVo; + } +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/MaintenancePlanServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/MaintenancePlanServiceImpl.java new file mode 100644 index 0000000..3de2980 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/MaintenancePlanServiceImpl.java @@ -0,0 +1,19 @@ +package com.hnac.hzims.scheduled.service.operation.business.impl; + +import com.hnac.hzims.operational.maintenance.entity.OperMaintenancePlanEntity; +import com.hnac.hzims.scheduled.mapper.operation.MaintenancePlanMapper; +import com.hnac.hzims.scheduled.service.operation.business.MaintenancePlanService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +/** + * @author ysj + */ +@Service +@AllArgsConstructor +@Slf4j +public class MaintenancePlanServiceImpl extends BaseServiceImpl implements MaintenancePlanService { + +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/MaintenanceServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/MaintenanceServiceImpl.java new file mode 100644 index 0000000..ba446b0 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/MaintenanceServiceImpl.java @@ -0,0 +1,294 @@ +package com.hnac.hzims.scheduled.service.operation.business.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.hnac.hzims.message.dto.PlanMsgRecordDto; +import com.hnac.hzims.message.entity.config.MessageTemplateEntity; +import com.hnac.hzims.message.fegin.IMessageClient; +import com.hnac.hzims.operational.duty.entity.ImsDutyMainEntity; +import com.hnac.hzims.operational.main.vo.MaintainVo; +import com.hnac.hzims.operational.main.vo.RegularWorkVO; +import com.hnac.hzims.operational.maintenance.constants.MaintenanceConstant; +import com.hnac.hzims.operational.maintenance.entity.OperMaintenancePlanEntity; +import com.hnac.hzims.operational.maintenance.entity.OperMaintenanceTaskEntity; +import com.hnac.hzims.operational.maintenance.vo.OperMaintenanceTaskEntityVo; +import com.hnac.hzims.scheduled.mapper.operation.MaintenanceMapper; +import com.hnac.hzims.scheduled.service.operation.business.MaintenancePlanService; +import com.hnac.hzims.scheduled.service.operation.business.MaintenanceService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.*; +import org.springblade.flow.core.feign.IFlowClient; +import org.springframework.beans.BeanUtils; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.stereotype.Service; +import org.springframework.transaction.TransactionDefinition; +import org.springframework.transaction.TransactionStatus; +import org.springframework.transaction.support.DefaultTransactionDefinition; + +import java.beans.Transient; +import java.time.*; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.springblade.core.tool.utils.DateUtil.PATTERN_DATE; + +/** + * @author ysj + */ +@Service +@RequiredArgsConstructor +@Slf4j +public class MaintenanceServiceImpl extends BaseServiceImpl implements MaintenanceService { + + private final MaintenancePlanService planService; + + private final DutyMainServiceImpl dutyMainService; + + private final IFlowClient flowClient; + + private final IMessageClient messageClient; + + private final DataSourceTransactionManager manager; + + private final ThreadPoolExecutor executor; + + /** + * 日常维护任务派发 + * @param param + */ + @Override + @Transient + public void maintenanceTaskDistribute(String param) { + // 开始时间 + Date start = DateUtil.parse(DateUtil.formatDate(DateUtil.now()), DateUtil.PATTERN_DATE); + // 结束时间 + Date end = DateUtil.parse(DateUtil.formatDate(DateUtil.plusDays(start, 1)), DateUtil.PATTERN_DATE); + // 查询日常维护计划 + List plans = planService.list(Wrappers.lambdaQuery() + .ge(OperMaintenancePlanEntity::getDisposeTime,start) + .lt(OperMaintenancePlanEntity::getDisposeTime,end) + .isNotNull(OperMaintenancePlanEntity::getCreateTaskTime) + ); + // 遍历计划列表生成相应任务 + if(CollectionUtil.isEmpty(plans)){ + return; + } + plans.forEach(plan -> { + // 生成日常任务对象 + OperMaintenanceTaskEntity task = BeanUtil.copy(plan,OperMaintenanceTaskEntity.class); + if(StringUtil.isEmpty(task.getEmCode())){ + this.taskDistribute(task,plan); + }else{ + for (String code : plan.getEmCode().split(",")) { + task.setEmCode(code); + this.taskDistribute(task,plan); + } + } + }); + } + + /** + * 日常维护任务派发 + * @param task + * @param plan + */ + private void taskDistribute(OperMaintenanceTaskEntity task, OperMaintenancePlanEntity plan) { + DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition(); + defaultTransactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); + TransactionStatus transaction = manager.getTransaction(defaultTransactionDefinition); + task.setId(null); + task.setCreateTime(new Date()); + task.setUpdateTime(new Date()); + task.setPlanId(plan.getId()); + task.setTaskCode(UUID.randomUUID().toString()); + if (task.getRefLibraryId() != 0) { + task.setCreateTime(DateUtil.now()); + } + if(ObjectUtil.isNotEmpty(plan.getDisposer())){ + task.setDisposer(plan.getDisposer().toString()); + } + //补充计划结束时间 + Instant instant = task.getDisposeTime().toInstant(); + ZoneId zoneId = ZoneId.systemDefault(); + LocalDateTime disposeTime = instant.atZone(zoneId).toLocalDateTime(); + task.setPlanEndTime(disposeTime.plusHours(task.getHours())); + //获取值班人员 + if (ObjectUtil.isNotEmpty(plan.getMaintenanceModel()) && plan.getMaintenanceModel() == 2) { + //查询值班信息 + LambdaQueryWrapper dutyWrapper = new LambdaQueryWrapper<>(); + dutyWrapper.eq(ImsDutyMainEntity::getDutyDate, DateTimeFormatter.ofPattern(PATTERN_DATE).format(disposeTime)); + dutyWrapper.eq(ImsDutyMainEntity::getClassId, plan.getImsDutyClassId()); + ImsDutyMainEntity entity = dutyMainService.getOne(dutyWrapper); + if (ObjectUtil.isEmpty(entity) || StringUtils.isEmpty(entity.getDutyPersonIds())) { + log.error("计划ID为:{}未查询到排班记录", plan.getId()); + return; + } + String userId = entity.getDutyPersonIds(); + task.setDisposer(userId.replaceAll("\\^", ",")); + } + this.save(task); + // 事务提交 + manager.commit(transaction); + //启动流程 + String processInstanceId = this.startProcess(plan.getProcDefId(), task); + //推送消息 + CompletableFuture operMaintenanceTaskEntityCompletableFuture = + CompletableFuture.runAsync(() -> { + task.setProcessInstanceId(processInstanceId); + this.updateById(task); + plan.setCreateTaskTime(new Date()); + planService.updateById(plan); + //推送消息 + this.pushTaskMessage(task.getId()); + }, executor); + //启动队列 + try { + CompletableFuture.allOf(operMaintenanceTaskEntityCompletableFuture).get(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 开启一个流程实例 + **/ + private String startProcess(String processDefinitionKey, OperMaintenanceTaskEntity taskEntity) { + OperMaintenanceTaskEntityVo operMaintenanceTaskEntityVo = new OperMaintenanceTaskEntityVo(); + BeanUtils.copyProperties(taskEntity, operMaintenanceTaskEntityVo); + Map params = new HashMap<>(); + params.put("taskId", taskEntity.getId()); + List userIdList = Stream.of(taskEntity.getDisposer().split(",")).collect(Collectors.toList()); + String taskUsers = userIdList.stream().filter(StringUtils::isNotBlank).map("taskUser_"::concat).collect(Collectors.joining(",")); + params.put("initUserIds", taskUsers); + params.put("operMaintenanceTaskEntityVo", operMaintenanceTaskEntityVo); + return flowClient.startProcessInstanceContainNameByKey(processDefinitionKey, String.valueOf(taskEntity.getId()), taskEntity.getTitle(), params).getData().getProcessInstanceId(); + } + + /** + * 推送消息 + */ + private void pushTaskMessage(Long taskId) { + OperMaintenanceTaskEntity task = this.getById(taskId); + if(ObjectUtil.isEmpty(task)){ + return; + } + // 根据消息模板Id查询模板 + R result = messageClient.getMsgTemplateById(task.getMessageTemplateId()); + if (result.isSuccess() && ObjectUtil.isNotEmpty(result.getData())) { + Func.toLongList(",", task.getDisposer()).forEach(userId -> { + //推送消息 + ZoneId zoneId = ZoneId.systemDefault(); + PlanMsgRecordDto msg = new PlanMsgRecordDto(); + msg.setTemplateId(task.getMessageTemplateId()); + msg.setCreateUser(task.getCreateUser()); + msg.setPlanTime(LocalDateTime.ofInstant(task.getDisposeTime().toInstant(), zoneId)); + msg.setTaskId(task.getId()); + msg.setDeptId(task.getCreateDept()); + msg.setReceiver(userId); + msg.setContent("距离任务执行时间已不满一小时,请及时处理"); + messageClient.planSendMessage(msg); + }); + } + } + + /** + * 获取日常维护数量 + * @param departList + * @return + */ + @Override + public Integer maintenanceCount(List departList) { + if(CollectionUtil.isEmpty(departList)){ + return 0; + } + LocalDate firstDay = LocalDate.now().withDayOfYear(1); + LocalDateTime firstDateTime = LocalDateTime.of(firstDay, LocalTime.MIN); + LocalDateTime now = LocalDateTime.now(); + //日常维护 + List mTaskList = this.list(new LambdaQueryWrapper(){{ + ge(OperMaintenanceTaskEntity::getDisposeTime,firstDateTime); + le(OperMaintenanceTaskEntity::getDisposeTime,now); + in(OperMaintenanceTaskEntity::getCreateDept,departList); + }}); + if(CollectionUtil.isEmpty(mTaskList)){ + return 0; + } + return mTaskList.size(); + } + + /** + * 时间区间机构的日常维护数据查询 + * @param start + * @param end + * @param areas + * @return + */ + @Override + public MaintainVo maintain(String start, String end, List areas) { + MaintainVo maintainVo = new MaintainVo(); + //日常维护 + List maintainList = this.list(new LambdaQueryWrapper(){{ + ge(OperMaintenanceTaskEntity::getDisposeTime,start); + le(OperMaintenanceTaskEntity::getDisposeTime,end); + in(OperMaintenanceTaskEntity::getCreateDept,areas); + }}); + if(CollectionUtil.isEmpty(maintainList)){ + maintainVo.setMaintain(0); + maintainVo.setMaintainFinish(0); + return maintainVo; + } + // 日常维护完成数 + maintainVo.setMaintain(maintainList.size()); + List maintainFinish = maintainList.stream().filter(o-> Func.isNotEmpty(o.getStatus()) && MaintenanceConstant.TASK_STATUS_5 == o.getStatus()) + .map(OperMaintenanceTaskEntity::getId).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(maintainFinish)){ + maintainVo.setMaintainFinish(0); + } + maintainVo.setMaintainFinish(maintainFinish.size()); + return maintainVo; + } + + /** + * 查询日常维护-定期工作类型数据 + * @param start + * @param end + * @param areas + * @return + */ + @Override + public RegularWorkVO regularWork(Date start, Date end, List areas) { + RegularWorkVO regularWorkVO = new RegularWorkVO(); + // 查询定期工作任务 + List regularWorkList = this.list(new LambdaQueryWrapper() {{ + ge(OperMaintenanceTaskEntity::getDisposeTime, start) + .le(OperMaintenanceTaskEntity::getDisposeTime, end) + .eq(OperMaintenanceTaskEntity::getTypeCode, "05") + .in(OperMaintenanceTaskEntity::getCreateDept, areas); + }}); + if (CollectionUtil.isEmpty(regularWorkList)) { + regularWorkVO.setRegularWorkSum(0); + regularWorkVO.setRegularWork(0); + return regularWorkVO; + } + regularWorkVO.setMainTaskIds(regularWorkList.stream().map(OperMaintenanceTaskEntity::getId).map(Object::toString).collect(Collectors.joining(","))); + regularWorkVO.setRegularWorkSum(regularWorkList.size()); + // 定期工作任务完成数量 + List regularWorkFinishList = regularWorkList.stream().filter(o -> MaintenanceConstant.TASK_STATUS_5 == o.getStatus()).collect(Collectors.toList()); + if (CollectionUtil.isEmpty(regularWorkFinishList)) { + regularWorkVO.setRegularWork(0); + return regularWorkVO; + } + regularWorkVO.setRegularWork(regularWorkFinishList.size()); + return regularWorkVO; + } + + +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/PhenomenonServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/PhenomenonServiceImpl.java new file mode 100644 index 0000000..1dc8019 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/business/impl/PhenomenonServiceImpl.java @@ -0,0 +1,99 @@ +package com.hnac.hzims.scheduled.service.operation.business.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity; +import com.hnac.hzims.operational.main.vo.ShortagesVo; +import com.hnac.hzims.operational.report.vo.DutyDefectVO; +import com.hnac.hzims.scheduled.mapper.operation.PhenomenonMapper; +import com.hnac.hzims.scheduled.service.operation.business.PhenomenonService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.Func; +import org.springframework.stereotype.Service; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author ysj + */ +@Service +@Slf4j +@AllArgsConstructor +public class PhenomenonServiceImpl extends BaseServiceImpl implements PhenomenonService { + + /** + * 时间范围内机构缺陷数据查询 + * @param start + * @param end + * @param areas + * @return + */ + @Override + public DutyDefectVO defect(String start, String end, List areas) { + DutyDefectVO defectVO = new DutyDefectVO(); + // 查询缺陷现象总数 + List operPhenomenonList = this.list(new LambdaQueryWrapper(){{ + ge(OperPhenomenonEntity::getCreateTime,start); + le(OperPhenomenonEntity::getCreateTime,end); + in(OperPhenomenonEntity::getCreateDept,areas); + }}); + if(CollectionUtil.isEmpty(operPhenomenonList)){ + defectVO.setDefectSum(0); + defectVO.setDefect(0); + return defectVO; + } + defectVO.setTotalIds(operPhenomenonList.stream().map(o->String.valueOf(o.getId())).collect(Collectors.joining(","))); + defectVO.setDefectSum(operPhenomenonList.size()); + // 消缺数 + List defectList = operPhenomenonList.stream().filter(o -> (Func.isNotEmpty(o.getIsDefect()) && o.getIsDefect() == 0) || "1".equals(o.getConclusionStatus())). + map(OperPhenomenonEntity::getId).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(defectList)){ + defectVO.setDefect(0); + return defectVO; + } + // 缺陷总数 + defectVO.setDefect(defectList.size()); + return defectVO; + } + + /** + * 查询当月机构缺陷数据 + * @param start + * @param end + * @param list + * @return + */ + @Override + public ShortagesVo defectMonth(String start, String end, List list) { + ShortagesVo shortagesVo = new ShortagesVo(); + LocalDate firstDay = LocalDate.now().withDayOfMonth(1); + LocalDateTime firstDateTime = LocalDateTime.of(firstDay, LocalTime.MIN); + LocalDateTime now = LocalDateTime.now(); + // 消缺总数 + List defects = this.list(new LambdaQueryWrapper(){{ + ge(OperPhenomenonEntity::getCreateTime,firstDateTime); + le(OperPhenomenonEntity::getCreateTime,now); + in(OperPhenomenonEntity::getCreateDept,list); + }}); + if(CollectionUtil.isEmpty(defects)){ + shortagesVo.setShortagesSum(0); + shortagesVo.setShortages(0); + return shortagesVo; + } + // 消缺数 + shortagesVo.setShortagesSum(defects.size()); + List shortagesList = defects.stream().filter(o -> (Func.isNotEmpty(o.getIsDefect()) && o.getIsDefect() == 0) || "1".equals(o.getConclusionStatus())). + map(OperPhenomenonEntity::getId).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(shortagesList)){ + shortagesVo.setShortages(0); + } + shortagesVo.setShortages(shortagesList.size()); + return shortagesVo; + } +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/GenerateService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/GenerateService.java new file mode 100644 index 0000000..440ce60 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/GenerateService.java @@ -0,0 +1,25 @@ +package com.hnac.hzims.scheduled.service.operation.fill; + +import com.hnac.hzims.operational.fill.entity.GenerateEntity; +import com.hnac.hzims.operational.main.vo.GenerationPowerVo; +import com.hnac.hzims.operational.main.vo.PowerMonthVo; +import org.springblade.core.mp.base.BaseService; + +import java.util.List; + +/** + * @author ysj + * @date 2023/04/10 11:16:07 + * @version 4.0.0 + */ +public interface GenerateService extends BaseService { + + // 查询填报用电量 + Float generate(String date,String station); + + // 查询30天填报用电量 + List generate30Day(String day, String station); + + // 获取站点填报发电量 + List generateThreeYear(String start, String end, String station); +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/OtherService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/OtherService.java new file mode 100644 index 0000000..13ee8ab --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/OtherService.java @@ -0,0 +1,11 @@ +package com.hnac.hzims.scheduled.service.operation.fill; + +import com.hnac.hzims.operational.fill.entity.OtherEntity; +import org.springblade.core.mp.base.BaseService; + +/** + * @author ysj + */ +public interface OtherService extends BaseService { + +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/OverDetailsService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/OverDetailsService.java new file mode 100644 index 0000000..efa4b86 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/OverDetailsService.java @@ -0,0 +1,12 @@ +package com.hnac.hzims.scheduled.service.operation.fill; + + +import com.hnac.hzims.operational.fill.entity.OverDetailsEntity; +import org.springblade.core.mp.base.BaseService; + +/** + * @author ysj + */ +public interface OverDetailsService extends BaseService { + +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/OverService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/OverService.java new file mode 100644 index 0000000..d83b731 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/OverService.java @@ -0,0 +1,11 @@ +package com.hnac.hzims.scheduled.service.operation.fill; + +import com.hnac.hzims.operational.fill.entity.OverEntity; +import org.springblade.core.mp.base.BaseService; + +/** + * @author ysj + */ +public interface OverService extends BaseService { + +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/PowerService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/PowerService.java new file mode 100644 index 0000000..c26957a --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/PowerService.java @@ -0,0 +1,17 @@ +package com.hnac.hzims.scheduled.service.operation.fill; + +import com.hnac.hzims.operational.fill.entity.PowerEntity; +import com.hnac.hzims.operational.main.vo.PowerMonthVo; +import org.springblade.core.mp.base.BaseService; + +import java.util.List; + +/** + * @author ysj + */ +public interface PowerService extends BaseService { + + Double generate(String date,Long station); + + List generateThreeYear(String start,String end,Long station); +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/SolveService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/SolveService.java new file mode 100644 index 0000000..c3b8ee2 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/SolveService.java @@ -0,0 +1,11 @@ +package com.hnac.hzims.scheduled.service.operation.fill; + +import com.hnac.hzims.operational.fill.entity.SolveEntity; +import org.springblade.core.mp.base.BaseService; + +/** + * @author ysj + */ +public interface SolveService extends BaseService { + +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/UseService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/UseService.java new file mode 100644 index 0000000..11be788 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/UseService.java @@ -0,0 +1,29 @@ +package com.hnac.hzims.scheduled.service.operation.fill; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.hnac.hzims.operational.fill.entity.UseEntity; +import com.hnac.hzims.operational.fill.vo.QueryVo; +import com.hnac.hzims.operational.fill.vo.UseVo; +import com.hnac.hzims.operational.main.vo.UsrPowerVo; +import org.springblade.core.mp.base.BaseService; +import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.api.R; + +import java.util.List; +import java.util.Map; + +/** + * @author ysj + * @date 2023/04/10 11:16:07 + * @version 4.0.0 + */ +public interface UseService extends BaseService { + + // 查询填报用电量 + Float use(String date,String station); + + // 查询30天填报用电量 + List use30Day(String day, String station); + + Map generateThreeYear(String start, String end, String station); +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/GenerateServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/GenerateServiceImpl.java new file mode 100644 index 0000000..6f5ee6f --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/GenerateServiceImpl.java @@ -0,0 +1,112 @@ +package com.hnac.hzims.scheduled.service.operation.fill.impl; + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.hnac.hzims.operational.fill.entity.GenerateEntity; +import com.hnac.hzims.operational.main.vo.GenerationPowerVo; +import com.hnac.hzims.operational.main.vo.PowerMonthVo; +import com.hnac.hzims.scheduled.mapper.operation.GenerateMapper; +import com.hnac.hzims.scheduled.service.operation.fill.GenerateService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author ysj + * @date 2023/04/10 11:16:07 + * @version 4.0.0 + */ +@Slf4j +@Service +@AllArgsConstructor +public class GenerateServiceImpl extends BaseServiceImpl implements GenerateService { + + /** + * 根据时间、机构查询用电量 + * @param date 时间: 年 - yyyy/月 yyyy-mm/日 yyyy-mm-dd + * @param station 所属机构 + * @return + */ + @Override + public Float generate(String date, String station) { + List powers = this.list(Wrappers.lambdaQuery() + .likeRight(GenerateEntity::getFillDate,date) + .eq(GenerateEntity::getStationCode,station) + ); + if(CollectionUtil.isEmpty(powers)){ + return 0f; + } + return (float) powers.stream().mapToDouble(GenerateEntity::getGenerate).sum(); + } + + /** + * 查询30天填报用电量 + * @param day : 结束日期 yyyy-MM-dd + * @param station 站点编码 + * @return + */ + @Override + public List generate30Day(String day, String station) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(DateUtil.parse(day,DateUtil.PATTERN_DATE)); + String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + calendar.add(Calendar.DAY_OF_MONTH,-29); + String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + List records = this.list(Wrappers.lambdaQuery() + .between(GenerateEntity::getFillDate,start,end) + .eq(GenerateEntity::getStationCode,station) + ); + if(CollectionUtil.isEmpty(records)){ + return new ArrayList<>(); + } + return records.stream().map(record->{ + GenerationPowerVo generate = new GenerationPowerVo(); + generate.setDate(record.getFillDate()); + if(Math.abs(record.getGenerate()) <= 0){ + generate.setGenerate(0f); + }else{ + generate.setGenerate(Float.parseFloat(record.getGenerate().toString())); + } + return generate; + }).collect(Collectors.toList()); + } + + /** + * + * @param start 时间: 年 - yyyy/月 yyyy-mm/日 yyyy-mm-dd + * @param end 时间: 年 - yyyy/月 yyyy-mm/日 yyyy-mm-dd + * @param station 站点编码 + * @return + */ + @Override + public List generateThreeYear(String start, String end, String station) { + List records = this.list(Wrappers.lambdaQuery() + .eq(GenerateEntity::getStationCode,station) + .between(GenerateEntity::getFillDate,start,end) + ); + if(CollectionUtil.isEmpty(records)){ + return new ArrayList<>(); + } + // 返回结果 + return records.stream().peek( + record-> record.setFillDate(DateUtil.format(DateUtil.parse(record.getFillDate(),"yyyy-MM"),"yyyy-MM") + "-01") + ).collect(Collectors.toMap(GenerateEntity::getFillDate,GenerateEntity::getGenerate,Double::sum)). + entrySet().stream().map(entry->{ + PowerMonthVo mon = new PowerMonthVo(); + mon.setStrMonth(entry.getKey()); + if(Math.abs(entry.getValue()) <= 0){ + mon.setPower(0f); + }else{ + mon.setPower(Float.parseFloat(entry.getValue().toString())); + } + return mon; + }).collect(Collectors.toList()); + } +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/OtherServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/OtherServiceImpl.java new file mode 100644 index 0000000..11da8ed --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/OtherServiceImpl.java @@ -0,0 +1,19 @@ +package com.hnac.hzims.scheduled.service.operation.fill.impl; + +import com.hnac.hzims.operational.fill.entity.OtherEntity; +import com.hnac.hzims.scheduled.mapper.operation.OtherMapper; +import com.hnac.hzims.scheduled.service.operation.fill.OtherService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +/** + * @author ysj + */ +@Slf4j +@Service +@AllArgsConstructor +public class OtherServiceImpl extends BaseServiceImpl implements OtherService { + +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/OverDetailsServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/OverDetailsServiceImpl.java new file mode 100644 index 0000000..18d3513 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/OverDetailsServiceImpl.java @@ -0,0 +1,19 @@ +package com.hnac.hzims.scheduled.service.operation.fill.impl; + +import com.hnac.hzims.operational.fill.entity.OverDetailsEntity; +import com.hnac.hzims.scheduled.mapper.operation.OverDetailsMapper; +import com.hnac.hzims.scheduled.service.operation.fill.OverDetailsService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +/** + * @author ysj + */ +@Slf4j +@Service +@AllArgsConstructor +public class OverDetailsServiceImpl extends BaseServiceImpl implements OverDetailsService { + +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/OverServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/OverServiceImpl.java new file mode 100644 index 0000000..c009008 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/OverServiceImpl.java @@ -0,0 +1,19 @@ +package com.hnac.hzims.scheduled.service.operation.fill.impl; + +import com.hnac.hzims.operational.fill.entity.OverEntity; +import com.hnac.hzims.scheduled.mapper.operation.OverMapper; +import com.hnac.hzims.scheduled.service.operation.fill.OverService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +/** + * @author ysj + */ +@Slf4j +@Service +@AllArgsConstructor +public class OverServiceImpl extends BaseServiceImpl implements OverService { + +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/PowerServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/PowerServiceImpl.java new file mode 100644 index 0000000..b0028ca --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/PowerServiceImpl.java @@ -0,0 +1,77 @@ +package com.hnac.hzims.scheduled.service.operation.fill.impl; + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.hnac.hzims.operational.fill.entity.PowerEntity; +import com.hnac.hzims.operational.main.vo.PowerMonthVo; +import com.hnac.hzims.scheduled.mapper.operation.PowerMapper; +import com.hnac.hzims.scheduled.service.operation.fill.PowerService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + + +@Slf4j +@Service +@AllArgsConstructor +public class PowerServiceImpl extends BaseServiceImpl implements PowerService { + + + /** + * 根据时间、机构查询发电量 + * @param date 时间: 年 - yyyy/月 yyyy-mm/日 yyyy-mm-dd + * @param station 所属机构 + * @return + */ + @Override + public Double generate(String date, Long station) { + List powers = this.list(Wrappers.lambdaQuery() + .likeRight(PowerEntity::getMon,date) + .eq(PowerEntity::getCreateDept,station) + // 类型: 光伏 + .eq(PowerEntity::getType,1) + ); + if(CollectionUtil.isEmpty(powers)){ + return 0.0; + } + return powers.stream().mapToDouble(PowerEntity::getPowerMon).sum(); + } + + /** + * + * @param start 开始时间 : yyyy-mm + * @param end 结束时间 : yyyy-mm + * @param station 所属机构 + * @return + */ + @Override + public List generateThreeYear(String start, String end, Long station) { + List fills = this.list(Wrappers.lambdaQuery() + .between(PowerEntity::getMon,start,end) + .eq(PowerEntity::getCreateDept,station) + // 类型: 光伏 + .eq(PowerEntity::getType,1) + ); + if(CollectionUtil.isEmpty(fills)){ + return new ArrayList<>(); + + } + return fills.stream().map(fill->{ + PowerMonthVo mon = new PowerMonthVo(); + mon.setStrMonth(DateUtil.format(DateUtil.parse(fill.getMon(),"yyyy-MM"),DateUtil.PATTERN_DATE)); + if(Math.abs(fill.getPowerMon()) <= 0){ + mon.setPower(0f); + }else{ + mon.setPower(Float.parseFloat(fill.getPowerMon().toString())); + } + return mon; + }).collect(Collectors.toList()); + } + +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/SolveServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/SolveServiceImpl.java new file mode 100644 index 0000000..22f0b10 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/SolveServiceImpl.java @@ -0,0 +1,20 @@ +package com.hnac.hzims.scheduled.service.operation.fill.impl; + +import com.hnac.hzims.operational.fill.entity.SolveEntity; +import com.hnac.hzims.scheduled.mapper.operation.SolveMapper; +import com.hnac.hzims.scheduled.service.operation.fill.SolveService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +/** + * @author ysj + */ +@Slf4j +@Service +@AllArgsConstructor +public class SolveServiceImpl extends BaseServiceImpl implements SolveService { + + +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/UseServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/UseServiceImpl.java new file mode 100644 index 0000000..58ba3dc --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/UseServiceImpl.java @@ -0,0 +1,99 @@ +package com.hnac.hzims.scheduled.service.operation.fill.impl; + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.hnac.hzims.operational.fill.entity.UseEntity; +import com.hnac.hzims.operational.main.vo.UsrPowerVo; +import com.hnac.hzims.scheduled.mapper.operation.UseMapper; +import com.hnac.hzims.scheduled.service.operation.fill.UseService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springframework.stereotype.Service; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * @author ysj + * @date 2023/04/10 11:16:07 + * @version 4.0.0 + */ +@Slf4j +@Service +@AllArgsConstructor +public class UseServiceImpl extends BaseServiceImpl implements UseService { + + /** + * 根据时间、机构查询用电量 + * @param date 时间: 年 - yyyy/月 yyyy-mm/日 yyyy-mm-dd + * @param station 所属机构 + * @return + */ + @Override + public Float use(String date, String station) { + List powers = this.list(Wrappers.lambdaQuery() + .likeRight(UseEntity::getFillDate,date) + .eq(UseEntity::getStationCode,station) + ); + if(CollectionUtil.isEmpty(powers)){ + return 0f; + } + return (float) powers.stream().mapToDouble(UseEntity::getEmploy).sum(); + } + + /** + * 查询30天填报用电量 + * @param day : 结束日期 yyyy-MM-dd + * @param station 站点编码 + * @return + */ + @Override + public List use30Day(String day, String station) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(DateUtil.parse(day,DateUtil.PATTERN_DATE)); + String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + calendar.add(Calendar.DAY_OF_MONTH,-29); + String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + List records = this.list(Wrappers.lambdaQuery() + .between(UseEntity::getFillDate,start,end) + .eq(UseEntity::getStationCode,station) + ); + if(CollectionUtil.isEmpty(records)){ + return new ArrayList<>(); + } + return records.stream().map(record->{ + UsrPowerVo use = new UsrPowerVo(); + use.setDate(record.getFillDate()); + if(Math.abs(record.getEmploy()) <= 0){ + use.setUsrPower(0f); + }else{ + use.setUsrPower(Float.parseFloat(record.getEmploy().toString())); + } + return use; + }).collect(Collectors.toList()); + } + + /** + * 查询近3年的填报用电量 + * @param start + * @param end + * @param station + * @return + */ + @Override + public Map generateThreeYear(String start, String end, String station) { + List records = this.list(Wrappers.lambdaQuery() + .between(UseEntity::getFillDate,start,end) + .eq(UseEntity::getStationCode,station) + ); + if(CollectionUtil.isEmpty(records)){ + return new HashMap<>(); + + } + return records.stream().peek(record-> record.setFillDate(DateUtil.format(DateUtil.parse(record.getFillDate(),"yyyy-MM"),"yyyy-MM") + "-01")). + collect(Collectors.toMap(UseEntity::getFillDate, value->Float.parseFloat(value.getEmploy().toString()),Float::sum)); + } + +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/ModelStationService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/ModelStationService.java new file mode 100644 index 0000000..9d626b0 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/ModelStationService.java @@ -0,0 +1,12 @@ +package com.hnac.hzims.scheduled.service.operation.home; + + +import com.hnac.hzims.operational.station.entity.HzimsAnalyzeModelStationEntity; +import org.springblade.core.mp.base.BaseService; + +/** + * @author ysj + */ +public interface ModelStationService extends BaseService { + +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/RealTargetService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/RealTargetService.java new file mode 100644 index 0000000..a675773 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/RealTargetService.java @@ -0,0 +1,37 @@ +package com.hnac.hzims.scheduled.service.operation.home; + +import java.util.List; + +/** + * WEB水电站首页接口 + * @author ysj + */ +public interface RealTargetService { + + + void loadEmInfo(); + + // 水电站实时数据加载 + void loadHydropowerReal(String param); + + // 水电站指标数据加载 + void loadHydropowerTarget(String param); + + // 泵站实时数据加载 + void loadWaterPumpReal(String param); + + // 泵站指标数据加载 + void loadWaterPumpTarget(String param); + + // 站点水位指标数据 + void loadWaterLevel(String param); + + // 光伏站实时数据加载 + void loadPhotovoltaicReal(String param); + + // 光伏站指标数据加载 + void loadPhotovoltaicTarget(String param); + + // 光伏、水电站近3年发电量 + void loadPowerData(String param, List types, Integer serveType, int year); +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/ShowService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/ShowService.java new file mode 100644 index 0000000..0c07de4 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/ShowService.java @@ -0,0 +1,13 @@ +package com.hnac.hzims.scheduled.service.operation.home; + +/** + * @author ysj + */ +public interface ShowService { + + void loadHomeTarget(String param); + + void loadRegionalDuty(String param); + + void loaddDeviceClassify(String param); +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ModelStationServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ModelStationServiceImpl.java new file mode 100644 index 0000000..19215c1 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ModelStationServiceImpl.java @@ -0,0 +1,16 @@ +package com.hnac.hzims.scheduled.service.operation.home.impl; + + +import com.hnac.hzims.operational.station.entity.HzimsAnalyzeModelStationEntity; +import com.hnac.hzims.scheduled.mapper.operation.ModelStationMapper; +import com.hnac.hzims.scheduled.service.operation.home.ModelStationService; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +/** + * @author ysj + */ +@Service +public class ModelStationServiceImpl extends BaseServiceImpl implements ModelStationService { + +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java new file mode 100644 index 0000000..5c8fc01 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java @@ -0,0 +1,1580 @@ +package com.hnac.hzims.scheduled.service.operation.home.impl; + +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.hnac.hzims.EquipmentConstants; +import com.hnac.hzims.equipment.entity.EmParamEntity; +import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; +import com.hnac.hzims.operational.main.constant.HomePageConstant; +import com.hnac.hzims.operational.main.vo.*; +import com.hnac.hzims.operational.station.StationConstants; +import com.hnac.hzims.operational.station.entity.HzimsAnalyzeModelStationEntity; +import com.hnac.hzims.operational.station.entity.StationEntity; +import com.hnac.hzims.scheduled.service.equipment.DeviceParamService; +import com.hnac.hzims.scheduled.service.equipment.DeviceService; +import com.hnac.hzims.scheduled.service.operation.home.ModelStationService; +import com.hnac.hzims.scheduled.service.operation.home.RealTargetService; +import com.hnac.hzims.scheduled.service.operation.fill.GenerateService; +import com.hnac.hzims.scheduled.service.operation.fill.PowerService; +import com.hnac.hzims.scheduled.service.operation.fill.UseService; +import com.hnac.hzims.scheduled.service.operation.station.StationAttributeService; +import com.hnac.hzims.scheduled.service.operation.station.StationService; +import com.hnac.hzims.scheduled.service.operation.plate.DataService; +import com.hnac.hzinfo.datasearch.PointData; +import com.hnac.hzinfo.datasearch.analyse.domain.FieldsData; +import com.hnac.hzinfo.datasearch.analyse.po.AnalyseCodeByAnalyseDataPO; +import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO; +import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeCodeBySignagesVO; +import com.hnac.hzinfo.datasearch.history.IHistoryDataSearchClient; +import com.hnac.hzinfo.datasearch.history.OriginalDataQuery; +import com.hnac.hzinfo.datasearch.real.po.RealDataSearchPO; +import com.hnac.hzinfo.sdk.analyse.po.MultiAnalyzeCodePO; +import com.hnac.hzinfo.sdk.core.response.HzPage; +import com.hnac.hzinfo.sdk.core.response.Result; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.MapUtils; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springblade.core.tool.utils.ObjectUtil; +import org.springblade.core.tool.utils.StringUtil; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * APP首页实现类 + * @author ysj + */ +@Service +@RequiredArgsConstructor +@Slf4j +public class RealTargetServiceImpl implements RealTargetService { + + private final UseService useService; + + private final DataService dataService; + + private final PowerService powerService; + + private final DeviceService deviceService; + + private final StationService stationService; + + private final GenerateService generateService; + + private final DeviceParamService deviceParamService; + + private final StationAttributeService attributeService; + + private final ModelStationService modelStationService; + + private final RedisTemplate redisTemplate; + + private final IHistoryDataSearchClient historyDataSearchClient; + + @Value("${hzims.equipment.emInfo.emInfoList}") + public String device_cache_cofig_final; + + @Value("${hzims.operation.realIdKey}") + public String real_id_cofig_final; + + private final static String recent_year_power_data = "hzims:operation:key:power:data"; + private final static String load_hydropower_unit_real_key = "hzims:operation:loadhydropowerunit:real:key"; + private final static String load_hydropower_unit_target_key = "hzims:operation:loadhydropowerunit:target:key"; + private final static String loadwaterpump_target_key = "hzims:operation:loadwaterpump:target:key"; + private final static String loadwaterpump_real_key = "hzims:operation:loadwaterpump:real:key"; + private final static String loadwater_level_key = "hzims:operation:loadwater:level:key"; + private final static String load_photovoltaic_real_key = "hzims:operation:photovoltaic:real:key"; + private final static String load_photovoltaic_target_key = "hzims:operation:photovoltaic:target:key"; + + + @Override + public void loadEmInfo() { + // 查询所有首页展示/状态非删除设备 + List devices = deviceService.device(); + // 查询所有设备(ct、pt、installedCapacity)配置参数 + List paramList = deviceParamService.params(); + // 获取设备监测点位:未配置监测点位不进行统计设备 + List multiAnalyzeCodePOList = devices.stream().map(o->{ + MultiAnalyzeCodePO multiAnalyzeCodePO = new MultiAnalyzeCodePO(); + multiAnalyzeCodePO.setDeviceCode(o.getEmCode()); + multiAnalyzeCodePO.setSignages(HomePageConstant.SIGNAGES); + return multiAnalyzeCodePO; + }).collect(Collectors.toList()); + // 切割 + int limit = countStep(multiAnalyzeCodePOList.size()); + List> lists = Stream.iterate(0, n -> n + 1).limit(limit).parallel().map(a -> multiAnalyzeCodePOList.stream().skip((long) a * 3).limit(3).parallel().collect(Collectors.toList())).collect(Collectors.toList()); + // 接收数据 + List analys = new ArrayList<>(); + lists.forEach(list->{ + List result = dataService.analyzeCodeBySignages(list); + if(CollectionUtil.isEmpty(result)){ + return; + } + analys.addAll(result); + }); + // 设备遍历 + devices.forEach(item->{ + item.setRideCount(1); + item.setInstalledCapacity(0.0); + List signages = analys.stream().filter(o-> item.getEmCode().equals(o.getDeviceCode()) && !StringUtil.isEmpty(o.getSignage()) && !StringUtil.isEmpty(o.getRealId())).collect(Collectors.toList()); + if(CollectionUtil.isNotEmpty(signages)){ + // list -> map + item.setPoint(signages.stream().collect(Collectors.toMap(AnalyzeCodeBySignagesVO::getSignage,AnalyzeCodeBySignagesVO::getRealId))); + } + // 寻找设备配置参数 + List itemParamList = paramList.stream().filter(o->item.getId().equals(o.getInfoId())).collect(Collectors.toList()); + if(CollectionUtil.isNotEmpty(itemParamList)){ + // 遍历设备配置参数 + for(EmParamEntity param : itemParamList){ + String param_name = param.getParamName(); + switch (param_name){ + case "ct": + item.setCt(Integer.valueOf(param.getParamValue())); + break; + case "pt": + item.setPt(Integer.valueOf(param.getParamValue())); + break; + case "installedCapacity": + item.setInstalledCapacity(Double.valueOf(param.getParamValue())); + break; + default: + break; + } + } + // 设置ct * pt + if(null != item.getCt() && null != item.getPt()){ + item.setRideCount(item.getCt() * item.getPt()); + } + } + }); + // 设置缓存 + redisTemplate.opsForValue().set(device_cache_cofig_final, JSONObject.toJSONString(devices.stream().filter(o-> Math.abs(o.getInstalledCapacity()) > 0 || MapUtils.isNotEmpty(o.getPoint())).collect(Collectors.toList()))); + } + + + /** + * 加载水电站机组实时数据 + * @param param + */ + @Override + public void loadHydropowerReal(String param) { + // 水电站站点 + List stations = stationService.list(Wrappers.lambdaQuery() + .eq(StationEntity::getType,HomePageConstant.HYDROPOWER) + ); + if(CollectionUtil.isEmpty(stations)){ + return; + } + // 水电站设备 + List devices = this.pumpDevices(stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())); + if(CollectionUtil.isEmpty(devices)){ + return; + } + // 实时数据 + Map map = this.getRealMap(); + // 单位 + Map unitMap = this.attributeService.PointUnit(); + // 实时数据 + List reals = devices.stream().map(device->{ + HydropowerUnitRealVo real = new HydropowerUnitRealVo(); + real.setDeptId(device.getCreateDept()); + real.setDeviceCode(device.getEmCode()); + real.setDeptName(device.getName()); + real.setDeviceName(device.getName()); + // 装机容量 + real.setInstalledCapacity(device.getInstalledCapacity()); + // 开关机状态 + real.setState(this.state(device,map)); + // 有功功率 + real.setActivePower(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_ACTIVE_POWER)); + // 无功功率 + real.setReactivePower(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_REACTIVE_POWER)); + // 功率因数 + real.setPowerFactor(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_POWERFACTOR)); + // 机组频率 + real.setFrequency(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_FREQUENCY)); + // 导叶开度 + real.setGuideOpen(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_GUIDEOPEN)); + // 定子电压 + real.setStatorVoltage(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_VOLTAGE)); + // 定子电流 + real.setStatorCurrent(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_CURRENT)); + // 单位设置 + this.setttingUnit(device,unitMap,real); + return real; + }).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(reals)){ + return; + } + redisTemplate.opsForValue().set(load_hydropower_unit_real_key,reals); + } + + /** + * 加载水电站机组指标数据 + * @param param + */ + @Override + public void loadHydropowerTarget(String param) { + // 水电站站点 + List stations = stationService.list(Wrappers.lambdaQuery() + //.eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) + .eq(StationEntity::getType,HomePageConstant.HYDROPOWER) + ); + if(CollectionUtil.isEmpty(stations)){ + return; + } + // 补充填补发电指标 + List targets = this.generteFill(stations); + // 水电站设备 + List devices = this.pumpDevices(stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())); + if(CollectionUtil.isNotEmpty(devices)){ + targets.addAll(devices.stream().map(device->{ + HydropowerUnitTargetVo target = new HydropowerUnitTargetVo(); + target.setDeptId(device.getCreateDept()); + target.setDeviceCode(device.getEmCode()); + target.setDeviceName(device.getName()); + target.setDeptName(device.getName()); + // 当年发电量 + target.setPowerYear(this.getGenerationPower(device,0)); + // 当月发电量 + target.setPowerMon(this.getGenerationPower(device,1)); + // 当日发电量 + target.setPowerDay(this.getGenerationPower(device,2)); + // 当天有功功率 + target.setActivePowerVoList(this.getLoadsByDay(device)); + // 30天发电量 + target.setGenerationPowerVoList(this.getGenerationPowerList(device)); + return target; + }).collect(Collectors.toList())); + } + // 站点指标数据为空 + if(CollectionUtil.isEmpty(targets)){ + return; + } + redisTemplate.opsForValue().set(load_hydropower_unit_target_key,targets); + } + + /** + * 水利-泵组实时加载 + * @param param + */ + @Override + public void loadWaterPumpReal(String param) { + // 水利站点 + List stations = stationService.list(Wrappers.lambdaQuery() + .eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) + .in(StationEntity::getType,HomePageConstant.waterList) + ); + if(CollectionUtil.isEmpty(stations)){ + return; + } + // 泵站设备 + List devices = this.pumpDevices(stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())); + if(CollectionUtil.isEmpty(devices)){ + return; + } + // 实时数据 + Map map = this.getRealMap(); + List list = devices.stream().map(device->{ + WaterPumpRealVo real = new WaterPumpRealVo(); + real.setDeptId(device.getCreateDept()); + real.setDeviceCode(device.getEmCode()); + real.setDeptName(device.getName()); + // 装机容量 + real.setInstalledCapacity(device.getInstalledCapacity()); + // 开机状态 + real.setState(this.pumpState(device,map)); + // 功率因数 + real.setPowerFactor(this.getSignageValue(device,map,HomePageConstant.POWER_FACTOR)); + // 有功功率 + real.setActivePower(this.floatValue(device,map,HomePageConstant.ACTIVE_POWER)); + // 无功功率 + real.setReactivePower(this.floatValue(device,map,HomePageConstant.REACTIVE_POWER)); + // 电压 + real.setVoltage(this.getSignageValue(device,map,HomePageConstant.VOLTAGE)); + // 电流 + real.setCurrent(this.getSignageValue(device,map,HomePageConstant.CURRENT)); + return real; + }).collect(Collectors.toList()); + redisTemplate.opsForValue().set(loadwaterpump_real_key,list); + } + + /** + * 水利-泵组指标加载 + * @param param + */ + @Override + public void loadWaterPumpTarget(String param) { + // 水利站点 + List stations = stationService.list(Wrappers.lambdaQuery() + .eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) + .in(StationEntity::getType,HomePageConstant.waterList) + ); + if(CollectionUtil.isEmpty(stations)){ + return; + } + // 泵站设备 + List devices = this.pumpDevices(stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())); + // 补充站点填报发电量 + List list = this.useFill(stations); + // 站点设备数据统计 + if(CollectionUtil.isNotEmpty(devices)){ + list.addAll(devices.stream().map(device->{ + WaterPumpTargetVo target = new WaterPumpTargetVo(); + target.setDeptId(device.getCreateDept()); + target.setDeviceCode(device.getEmCode()); + target.setDeptName(device.getName()); + // 当年用电量 + target.setUsrPowerYear(this.getUsrPowerYear(device)); + // 当月用电量 + target.setUsrPowerMon(this.getUsrPowerMon(device)); + // 当日用电量 + target.setUsrPowerDay(this.getUsrPowerDay(device)); + // 当日机组有功功率 + target.setActivePowerVoList(this.getActivePowerVoList(device)); + // 近30天用电量 + target.setUsrPowerVoList(this.getUsrPowerVoList(device)); + // 近3年用电量 + target.setUsrYearMap(this.getUsrYearMap(device)); + // 月运行次数、时长 + WaterRunVo runMon = this.getRunData(device,1); + target.setRunCountMon(runMon.getCount()); + target.setRunDurationMon(runMon.getHour()); + // 年运行次数、时长 + WaterRunVo runYear = this.getRunData(device,0); + target.setRunCountYear(runYear.getCount()); + target.setRunDurationYear(runYear.getHour()); + return target; + }).collect(Collectors.toList())); + } + redisTemplate.opsForValue().set(loadwaterpump_target_key,list); + } + + /** + * 水利-站点水位数据 + * @param param + */ + @Override + public void loadWaterLevel(String param) { + // 有效站点模型 + List modelList = getModelStationList(); + if(CollectionUtil.isEmpty(modelList)){ + return; + } + List list = new ArrayList<>(); + modelList.forEach(item -> { + WaterLevelVo waterLevelVo = new WaterLevelVo(); + waterLevelVo.setStationCode(item.getStationId()); + // 前水位 + double frontWaterLevel = this.getWaterLevel(item.getInstanceCode(),HomePageConstant.FRONT_WATER_LEVEL); + waterLevelVo.setFrontWaterLevel(frontWaterLevel); + // 后水位 + double rearWaterLevel = this.getWaterLevel(item.getInstanceCode(),HomePageConstant.REAR_WATER_LEVEL); + waterLevelVo.setRearWaterLevel(rearWaterLevel); + // 前水位当日曲线 + Map frontCurveMap = this.getWaterLevelMap(item.getInstanceCode(),HomePageConstant.FRONT_WATER_LEVEL); + waterLevelVo.setFrontCurveMap(frontCurveMap); + // 后水位当日曲线 + Map rearCurveMap = this.getWaterLevelMap(item.getInstanceCode(),HomePageConstant.REAR_WATER_LEVEL); + waterLevelVo.setRearCurveMap(rearCurveMap); + list.add(waterLevelVo); + }); + redisTemplate.opsForValue().set(loadwater_level_key,list); + } + + /** + * 光伏站-逆变器实时加载 + * + * @param param + */ + + @Override + public void loadPhotovoltaicReal(String param) { + // 查询设备 + List devices = this.getPhotovoltaicDevice(); + if (CollectionUtil.isEmpty(devices)) { + return; + } + // 取redis实时数据 + Map map = this.getRealMap(); + if (MapUtils.isEmpty(map)) { + return; + } + // redis缓存设备实时数据 + List history = (List) redisTemplate.opsForValue().get(load_photovoltaic_real_key); + // 设备实时数据 + List list = devices.stream().map(device -> { + PhotovoltaicRealVo real = new PhotovoltaicRealVo(); + real.setDeptId(device.getCreateDept()); + real.setDeviceCode(device.getEmCode()); + real.setDeviceName(device.getName()); + real.setState(this.getPhotovoltaicState(device, map)); + // 容量 + real.setCapacity(device.getInstalledCapacity()); + // 发电量 + real.setGenerate(this.getSignageValue(device, map, HomePageConstant.PV_GENERATION_CAPACITY)); + // 功率 + real.setLoad(this.getSignageValue(device, map, HomePageConstant.PV_LOAD)); + // 交流电压 + real.setVoltage(this.getSignageValue(device, map, HomePageConstant.PV_VOLTAGE)); + // 交流电流 + real.setCurrent(this.getSignageValue(device, map, HomePageConstant.PV_CURRENT)); + // 交流电压2 + real.setVoltage_two(this.getSignageValue(device, map, HomePageConstant.PV_VOLTAGE_TWO)); + // 交流电流2 + real.setCurrent_two(this.getSignageValue(device, map, HomePageConstant.PV_CURRENT_TWO)); + // 交流电压3 + real.setVoltage_three(this.getSignageValue(device, map, HomePageConstant.PV_VOLTAGE_THREE)); + // 交流电流3 + real.setCurrent_three(this.getSignageValue(device, map, HomePageConstant.PV_CURRENT_THREE)); + // 直流电流1 + real.setDirect_one(this.getSignageValue(device, map, HomePageConstant.DIRECT_ONE)); + // 直流电流2 + real.setDirect_two(this.getSignageValue(device, map, HomePageConstant.DIRECT_TWO)); + // 直流电流3 + real.setDirect_three(this.getSignageValue(device, map, HomePageConstant.DIRECT_THREE)); + // 直流电流4 + real.setDirect_four(this.getSignageValue(device, map, HomePageConstant.DIRECT_FOUR)); + // 直流电流5 + real.setDirect_five(this.getSignageValue(device, map, HomePageConstant.DIRECT_FIVE)); + // 直流电流6 + real.setDirect_six(this.getSignageValue(device, map, HomePageConstant.DIRECT_SIX)); + // 直流电流7 + real.setDirect_seven(this.getSignageValue(device, map, HomePageConstant.DIRECT_SEVEN)); + // 直流电流8 + real.setDirect_eight(this.getSignageValue(device, map, HomePageConstant.DIRECT_EIGHT)); + // 直流电流9 + real.setDirect_nine(this.getSignageValue(device, map, HomePageConstant.DIRECT_NINE)); + // 直流电流10 + real.setDirect_ten(this.getSignageValue(device, map, HomePageConstant.DIRECT_TEN)); + // 直流电流11 + real.setDirect_eleven(this.getSignageValue(device, map, HomePageConstant.DIRECT_ELEVEN)); + // 直流电流12 + real.setDirect_twelve(this.getSignageValue(device, map, HomePageConstant.DIRECT_TWELVE)); + // 直流电压1 + real.setDc_voltage_one(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_ONE)); + // 直流电压2 + real.setDc_voltage_two(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_TWO)); + // 直流电压3 + real.setDc_voltage_three(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_THREE)); + // 直流电压4 + real.setDc_voltage_four(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_FOUR)); + // 直流电压5 + real.setDc_voltage_five(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_FIVE)); + // 直流电压6 + real.setDc_voltage_six(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_SIX)); + // 直流电压7 + real.setDc_voltage_seven(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_SEVEN)); + // 直流电压8 + real.setDc_voltage_eight(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_EIGHT)); + // 直流电压9 + real.setDc_voltage_nine(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_NINE)); + // 直流电压10 + real.setDc_voltage_ten(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_TEN)); + // 直流电压11 + real.setDc_voltage_eleven(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_ELEVEN)); + // 直流电压12 + real.setDc_voltage_twelve(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_TWELVE)); + // 串流电流1 + real.setDirect_one(this.getSignageValue(device, map, HomePageConstant.DIRECT_ONE)); + // 串流电流2 + real.setSeries_two(this.getSignageValue(device, map, HomePageConstant.SERIES_TWO)); + // 串流电流3 + real.setSeries_three(this.getSignageValue(device, map, HomePageConstant.SERIES_THREE)); + // 串流电流4 + real.setSeries_four(this.getSignageValue(device, map, HomePageConstant.SERIES_FOUR)); + // 串流电流5 + real.setSeries_five(this.getSignageValue(device, map, HomePageConstant.SERIES_FIVE)); + // 串流电流6 + real.setSeries_six(this.getSignageValue(device, map, HomePageConstant.SERIES_SIX)); + // 串流电流7 + real.setSeries_seven(this.getSignageValue(device, map, HomePageConstant.SERIES_SEVEN)); + // 串流电流8 + real.setSeries_eight(this.getSignageValue(device, map, HomePageConstant.SERIES_EIGHT)); + // 串流电流9 + real.setSeries_nine(this.getSignageValue(device, map, HomePageConstant.SERIES_NINE)); + // 串流电流10 + real.setSeries_ten(this.getSignageValue(device, map, HomePageConstant.SERIES_TEN)); + // 串流电流11 + real.setSeries_eleven(this.getSignageValue(device, map, HomePageConstant.SERIES_ELEVEN)); + // 串流电流12 + real.setSeries_twelve(this.getSignageValue(device, map, HomePageConstant.SERIES_TWELVE)); + // 串流电压1 + real.setSe_voltage_one(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_ONE)); + // 串流电压2 + real.setSe_voltage_two(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_TWO)); + // 串流电压3 + real.setSe_voltage_three(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_THREE)); + // 串流电压4 + real.setSe_voltage_four(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_FOUR)); + // 串流电压5 + real.setSe_voltage_five(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_FIVE)); + // 串流电压6 + real.setSe_voltage_six(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_SIX)); + // 串流电压7 + real.setSe_voltage_seven(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_SEVEN)); + // 串流电压8 + real.setSe_voltage_eight(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_EIGHT)); + // 串流电压9 + real.setSe_voltage_nine(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_NINE)); + // 串流电压10 + real.setSe_voltage_ten(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_TEN)); + // 串流电压11 + real.setSe_voltage_eleven(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_ELEVEN)); + // 串流电压12 + real.setSe_voltage_twelve(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_TWELVE)); + // 上次功率 + real.setLastLoad(this.getLastLoad(device, history)); + return real; + }).collect(Collectors.toList()); + // 存储redis + redisTemplate.opsForValue().set(load_photovoltaic_real_key, list); + } + + + + /** + * 光伏站-逆变器指标加载 + * + * @param param + */ + @Override + public void loadPhotovoltaicTarget(String param) { + // 有效设备 + List devices = this.getPhotovoltaicDevice(); + if (CollectionUtil.isEmpty(devices)) { + return; + } + List list = new ArrayList<>(); + // 接入站点设备统计 + devices.forEach(device -> { + PhotovoltaicTargetVo target = new PhotovoltaicTargetVo(); + target.setDeptId(device.getCreateDept()); + target.setDeviceCode(device.getEmCode()); + target.setDeviceName(device.getName()); + target.setDeptName(device.getName()); + // 当日运行时长 + target.setRunHours(this.runHours(device.getPoint().get(HomePageConstant.PV_JOINT_RELAY))); + // 年发电量 + target.setGenerationYear((double) this.sumValueByTime(device.getEmCode(), device.getRideCount(), "0")); + // 月发电量 + target.setGenerationMon((double) this.sumValueByTime(device.getEmCode(), device.getRideCount(), "1")); + // 日发电量 + target.setGenerationDay((double) this.sumValueByTime(device.getEmCode(), device.getRideCount(), "2")); + // 昨日发电量 + target.setGenerationYesterday((double) this.sumValueByTime(device.getEmCode(), device.getRideCount(), "3")); + // 收益 + target.setIncome(target.getGenerationDay() * 0.34); + // 节约标准煤 + target.setTec(target.getGenerationMon() * 0.0001229); + // 二氧化碳减排 + target.setCo2(target.getGenerationMon() * 0.000997); + // 减少森林砍伐 + target.setDeforest(target.getGenerationMon() * 0.000553); + // 当天有功功率 + target.setActivePowerVoList(this.photovoltaicLoadsByDay(device)); + // 30天发电量 + target.setGenerationPowerVoList(this.getGenerateByMon(device)); + list.add(target); + }); + // 补充站点填报发电量 + List stations = stationService.list(Wrappers.lambdaQuery() + .eq(StationEntity::getType, HomePageConstant.PHOTOVOLTAIC) + .eq(StationEntity::getServeType, HomePageConstant.HYDROPOWER_SERVETYPE) + ); + if(CollectionUtil.isNotEmpty(stations)){ + list.addAll(this.generateFill(stations)); + } + redisTemplate.opsForValue().set(load_photovoltaic_target_key, list); + } + + + /** + * 当日用电量 + * @param device + * @return + */ + private float getUsrPowerDay(EminfoAndEmParamVo device) { + String time = DateUtil.format(new Date(),DateUtil.PATTERN_DATE); + // 当日用电量 + return dataService.periodTargetFloat(time + " 00:00:00",time + " 23:59:59",5,3,device.getEmCode(),device.getRideCount(),HomePageConstant.ELECTRICITY_CONSUMPTION); + + } + + /** + * 当月用电量 + * @param device + * @return + */ + private float getUsrPowerMon(EminfoAndEmParamVo device) { + String start = DateUtil.format(new Date(), "yyyy-MM") + "-01 00:00:00"; + String end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); + // 当月用电量 + return dataService.periodTargetFloat(start,end,5,5,device.getEmCode(),device.getRideCount(),HomePageConstant.ELECTRICITY_CONSUMPTION); + } + + /** + * 当年用电量 + * @param device + * @return + */ + private float getUsrPowerYear(EminfoAndEmParamVo device) { + Calendar calendar = Calendar.getInstance(); + String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); + calendar.setTime(new Date()); + calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); + calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); + String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); + // 当年用电量 + return dataService.periodTargetFloat(start,end,5,6,device.getEmCode(),device.getRideCount(),HomePageConstant.ELECTRICITY_CONSUMPTION); + } + + /** + * 当日机组有功功率 + * @param device + * @return + */ + public List getActivePowerVoList(EminfoAndEmParamVo device) { + String startTime = DateUtil.format(new Date(), "yyyy-MM-dd 00:00:00"); + String endTime = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"); + List datas = dataService.periodTargetData(startTime,endTime,2,6,device.getEmCode(),HomePageConstant.ACTIVE_POWER); + if(CollectionUtil.isEmpty(datas)){ + return new ArrayList<>(); + } + return datas.stream().map(data->{ + ActivePowerVo active = new ActivePowerVo(); + Date dateTime = DateUtil.parse(data.getTs(), "yyyy-MM-dd HH:mm:ss.s"); + active.setHour(dateTime.getHours()); + if (StringUtil.isBlank(data.getVal())) { + active.setActivePower("0"); + }else { + active.setActivePower(data.getVal()); + } + return active; + }).collect(Collectors.toList()); + } + + /** + * 近30天用电量 + * @param device + * @return + */ + private List getUsrPowerVoList(EminfoAndEmParamVo device) { + String start = DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00"; + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.DAY_OF_MONTH,-29); + String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); + List records = dataService.periodTargetData(start,end,5,EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(),device.getEmCode(),HomePageConstant.ELECTRICITY_CONSUMPTION); + if(CollectionUtil.isEmpty(records)){ + return new ArrayList<>(); + } + return records.stream().map(record -> { + UsrPowerVo usr = new UsrPowerVo(); + Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); + usr.setDate(DateUtil.format(time,DateUtil.PATTERN_DATE)); + usr.setUsrPower(Float.valueOf(Optional.ofNullable(record.getVal()).orElse("0"))); + return usr; + }).collect(Collectors.toList()); + } + + /** + * 近3年发电量 + * + * @param device + * @return + */ + private Map getUsrYearMap(EminfoAndEmParamVo device) { + // 开始时间 + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH) + 12); + calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); + String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; + // 结束日期 + calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - 3); + calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); + String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; + // 查询数据 + List records = dataService.periodTargetData(start,end,5,5,device.getEmCode(),HomePageConstant.ELECTRICITY_CONSUMPTION); + if(CollectionUtil.isEmpty(records)){ + return new HashMap<>(); + } + return records.stream().map(record -> { + PowerMonthVo generate = new PowerMonthVo(); + Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); + generate.setStrMonth(DateUtil.format(time, DateUtil.PATTERN_DATE)); + generate.setPower(Float.parseFloat(Optional.ofNullable(record.getVal()).orElse("0")) * device.getRideCount()); + return generate; + }).collect(Collectors.toMap(PowerMonthVo::getStrMonth,PowerMonthVo::getPower)); + } + + /** + * 获取运行数据 + * @param device + * @param type + * @return + */ + private WaterRunVo getRunData(EminfoAndEmParamVo device, int type) { + // 默认返回运行数据 + WaterRunVo waterRunVo = new WaterRunVo(); + waterRunVo.setCount(0); + waterRunVo.setHour(0.0); + Map point = device.getPoint(); + if(MapUtils.isEmpty(point)){ + return waterRunVo; + } + // 监测点 + String realId = point.get(HomePageConstant.SWITCH_ON_OFF); + if(StringUtil.isBlank(realId)){ + return waterRunVo; + } + // 确定查询时间范围: 年、月 + Date startDate,endDate; + Calendar calendar = Calendar.getInstance(); + calendar.setTime(new Date()); + switch (type){ + case 0: + endDate = calendar.getTime(); + calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); + calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); + startDate = calendar.getTime(); + break; + case 1: + endDate = calendar.getTime(); + calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); + calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); + calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); + calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); + startDate = calendar.getTime(); + break; + default: + throw new IllegalStateException("Unexpected value: " + type); + } + return this.getRunConvertData(realId,startDate,endDate,waterRunVo); + } + + /** + * 获取时间范围内开机次数、运行时长 + * @param realId + * @param startDate + * @param endDate + * @param waterRunVo + * @return + */ + private WaterRunVo getRunConvertData(String realId, Date startDate, Date endDate, WaterRunVo waterRunVo) { + OriginalDataQuery originalDataQuery = new OriginalDataQuery(); + originalDataQuery.setRealId(realId); + originalDataQuery.setBeginTime(startDate); + originalDataQuery.setEndTime(endDate); + originalDataQuery.setLimit(100000); + originalDataQuery.setPage(1); + // 查询时间范围开关机监测点历史数据 + Result> R = historyDataSearchClient.getOriginalDataByRealIds(originalDataQuery); + if(!R.isSuccess() || ObjectUtil.isEmpty(R.getData())){ + return waterRunVo; + } + // 过滤相邻开关机状态相同数据 + List result = this.getFilterList(R.getData().getRecords()); + if(CollectionUtil.isEmpty(result)){ + return waterRunVo; + } + // 开机次数 + int count = (int) result.stream().filter(o->HomePageConstant.OFF.equals(o.getValue())).count(); + waterRunVo.setCount(count); + // 开机运行时长 + long time = this.getRunTime(result,startDate,endDate); + waterRunVo.setHour(BigDecimal.valueOf(time / (1000 * 60 * 60.00)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); + return waterRunVo; + } + + /** + * 过滤相邻开关机状态相同数据 + * @param list + * @return + */ + private List getFilterList(List list) { + if(CollectionUtil.isEmpty(list)){ + return null; + } + List result = new ArrayList<>(); + // 遍历数据 + for(int i = 0; i< list.size() ; i++){ + // 第一个数据保存下来 + if(i == 0){ + result.add(list.get(i)); + continue; + } + // 遍历数据状态 + String value = list.get(i).getValue(); + if(StringUtil.isBlank(value)){ + continue; + } + // 上一条数据状态 + String up_value = list.get(i-1).getValue(); + if(value.equals(up_value)){ + continue; + } + result.add(list.get(i)); + } + return result; + } + + /** + * 获取运行时长 + * @param result + * @return + */ + private long getRunTime(List result,Date startDate,Date endDate) { + if(result.size() == 1){ + // 一直开机 + if(HomePageConstant.OFF.equals(result.get(0).getValue())){ + return endDate.getTime() - startDate.getTime(); + } + // 一直关机 + return 0; + } + long time=0; + // 遍历累计开机时长 + for(int i = 0; i< result.size() ; i++){ + // 记录为开机状态 就计算到下次关机的时间差 + if(HomePageConstant.ON.equals(result.get(i).getValue())){ + continue; + } + Date endTime,startTime = DateUtil.parse(result.get(i).getTime(), DateUtil.PATTERN_DATETIME); + // 遍历至最后一条数据,累计至当前时间 + if(i == result.size() - 1){ + endTime = endDate; + } + else { + endTime = DateUtil.parse(result.get(i+1).getTime(), DateUtil.PATTERN_DATETIME); + } + time += endTime.getTime() - startTime.getTime(); + } + return time; + } + + /** + * 获取填报用电量 + * @param stations + * @return + */ + private List useFill(List stations) { + Calendar calendar = Calendar.getInstance(); + String day = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + String mon = DateUtil.format(calendar.getTime(),"yyyy-MM"); + String year = String.valueOf(calendar.get(Calendar.YEAR)); + return stations.stream().map(station ->{ + WaterPumpTargetVo target = new WaterPumpTargetVo(); + target.setDeptId(station.getRefDept()); + target.setDeptName(station.getName()); + // 月运行次数、时长 + target.setRunCountMon(0); + target.setRunDurationMon(0.0); + // 年运行次数、时长 + target.setRunCountYear(0); + target.setRunDurationYear(0.0); + // 当年用电量 + target.setUsrPowerYear(useService.use(year,station.getCode())); + // 当月用电量 + target.setUsrPowerMon(useService.use(mon,station.getCode())); + // 当日用电量 + target.setUsrPowerDay(useService.use(day,station.getCode())); + if(StationConstants.DATA_ORIGIN_FILL.equals(station.getDataOrigin())){ + // 30天用电量 + target.setUsrPowerVoList(useService.use30Day(day,station.getCode())); + } + // 近3年用电量 + target.setUsrYearMap(this.useThreeYear(station.getCode())); + return target; + }).collect(Collectors.toList()); + } + + /** + * 获取水位实时数据 + * @param instanceCode + * @param signage + * @return + */ + private double getWaterLevel(String instanceCode, String signage) { + RealDataSearchPO realData = new RealDataSearchPO(); + realData.setAnalyzeCode(instanceCode); + List signages = Collections.singletonList(signage); + realData.setSignages(signages); + // 调用fegin接口查询实时数据 + List fields = dataService.getRealDataByAnalyzeCode(instanceCode,signages); + if(CollectionUtil.isEmpty(fields)){ + return 0.0; + } + // 时间限制 + String time = fields.get(0).getTime(); + if(StringUtil.isEmpty(time) || "-".equals(time)){ + return 0.0; + } + Date date = DateUtil.parse(time, "yyyy-MM-dd HH:mm:ss.sss"); + if(System.currentTimeMillis() - date.getTime() > 30 * 60 * 1000L){ + return 0.0; + } + return Double.parseDouble(fields.get(0).getValue()); + } + + /** + * 获取水位当年数据 + * @param instanceCode + * @param signage + * @return + */ + private Map getWaterLevelMap(String instanceCode, String signage) { + String beginTime = DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00"; + String endTime = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); + AnalyseCodeByAnalyseDataPO po = new AnalyseCodeByAnalyseDataPO(); + List datas = dataService.periodTargetData(beginTime, endTime,2, 6,instanceCode,signage); + if(CollectionUtil.isEmpty(datas)){ + return new HashMap<>(); + } + return datas.stream().collect(Collectors.toMap( + key-> { + Date dateTime = DateUtil.parse(key.getTs(), "yyyy-MM-dd HH:mm:ss.s"); + return dateTime.getHours(); + }, + value -> { + if(StringUtil.isBlank(value.getVal())){ + return "0"; + } + return value.getVal(); + }) + ); + } + + /** + * 填报近3年发电量 + * @param station + * @return + */ + private Map useThreeYear(String station) { + // 开始时间 + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH) + 12); + calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); + String end = DateUtil.format(calendar.getTime(),"yyyy-MM"); + // 结束日期 + calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - 3); + calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); + String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + return useService.generateThreeYear(start,end,station); + } + + + /** + * 获取有效站点模型 + * @return + */ + private List getModelStationList() { + // 水利站点(All) + List stations = stationService.list(new LambdaQueryWrapper() {{ + eq(StationEntity::getServeType, HomePageConstant.HYDROPOWER_SERVETYPE); + }}); + if(CollectionUtil.isEmpty(stations)){ + return new ArrayList<>(); + } + // 站点code集合 + List codes = stations.stream().map(StationEntity::getCode).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(codes)){ + return new ArrayList<>(); + } + // 查询站点模型列表 + List list = modelStationService.list(new LambdaQueryWrapper() {{ + in(HzimsAnalyzeModelStationEntity::getStationId, codes); + }}); + if(CollectionUtil.isEmpty(list)){ + return new ArrayList<>(); + } + return list; + } + + /** + * 获取开机状态 + * @param device + * @return + */ + private int pumpState(EminfoAndEmParamVo device,Map map) { + // 获取开关机监测点实时数据 + double value = this.getSignageValue(device,map,HomePageConstant.SWITCH_ON_OFF); + // 开机状态 + if (Math.abs(value) <= 0) { + return 0; + } + return 1; + } + + /** + * 有功功率 + * @param device + * @return + */ + private float floatValue(EminfoAndEmParamVo device,Map map,String target) { + // 获取有功功率监测点实时数据 + double value = this.getSignageValue(device,map,target); + // 转换float + return Float.parseFloat(String.valueOf(value)); + } + + /** + * 设备状态 + * @param device + * @param map + * @return + */ + private Boolean state(EminfoAndEmParamVo device, Map map) { + if(Math.abs(this.getSignageValue(device,map,HomePageConstant.JOINT_RELAY)) > 0){ + return true; + } + return Math.abs(this.getSignageValue(device, map, HomePageConstant.ACTIVE_POWER)) > 0; + } + + /** + * 近年发电量数据 + * + * @param param 时间 + * @param serveType 站点类型 + * @param year 近几年 + */ + @Override + public void loadPowerData(String param, List types, Integer serveType, int year) { + // 站点查询 + List stationList = stationService.list(new LambdaQueryWrapper() {{ + if (ObjectUtil.isNotEmpty(serveType)) { + eq(StationEntity::getServeType, serveType); + } + if (CollectionUtil.isNotEmpty(types)) { + in(StationEntity::getType, types); + } + }}); + // 设备信息 + List devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(), new TypeReference>() { + }); + // 开始时间 + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH) + 12); + calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); + String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; + // 结束日期 + calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - year); + calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); + String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; + // 存储数据map :<站点id,<月份,发电量>> + Map> powerMap = new HashMap<>(); + stationList.forEach(station -> { + // 站点设备集合 + List stationDevices = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); + log.error("load_power_data station :" + station.getCode() + "==== device :" + stationDevices ); + Map generateMap = this.getGenerateYear(station,stationDevices,start,end); + if(MapUtils.isEmpty(generateMap)){ + return; + } + powerMap.put(station.getId(),generateMap); + }); + redisTemplate.opsForValue().set(recent_year_power_data, powerMap); + } + + + /** + * 当天有功功率 + * @param device + * @return + */ + private List getLoadsByDay(EminfoAndEmParamVo device) { + String start = DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00"; + String end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); + List records = dataService.periodTargetData(start, end, 3, 2, device.getEmCode(), HomePageConstant.PV_LOAD); + if (CollectionUtil.isEmpty(records)) { + return new ArrayList<>(); + } + return records.stream().map(record -> { + ActivePowerVo load = new ActivePowerVo(); + Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); + load.setHour(time.getHours()); + load.setActivePower(Optional.ofNullable(record.getVal()).orElse("0")); + return load; + }).sorted(Comparator.comparing(ActivePowerVo::getHour)).collect(Collectors.toList()); + } + + /** + * 获取年发电量 + * @param devices + * @param start + * @param end + * @return + */ + private Map getGenerateYear(StationEntity station,List devices, String start, String end) { + List datas = new ArrayList<>(); + // 设备采集发电量 + if(CollectionUtil.isNotEmpty(devices)){ + devices.forEach(device->{ + List records = dataService.periodTargetData(start,end,5,5,device.getEmCode(),HomePageConstant.HYDROPOWER_GENERATE_POWER); + if(CollectionUtil.isEmpty(records)){ + return; + } + datas.addAll(records.stream().map(record -> { + PowerMonthVo generate = new PowerMonthVo(); + Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); + generate.setStrMonth(DateUtil.format(time,DateUtil.PATTERN_DATE)); + generate.setPower(Float.parseFloat(Optional.ofNullable(record.getVal()).orElse("0")) * device.getRideCount()); + return generate; + }).collect(Collectors.toList())); + }); + } + // 补充填报数据 + datas.addAll(this.generateFill(station,start,end)); + if(CollectionUtil.isEmpty(datas)){ + return null; + } + return datas.stream().collect(Collectors.toMap(PowerMonthVo::getStrMonth, PowerMonthVo::getPower, Float::sum)); + } + + + /** + * 获取填报用电量 + * @param stations + * @return + */ + private List generteFill(List stations) { + Calendar calendar = Calendar.getInstance(); + String day = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + String mon = DateUtil.format(calendar.getTime(),"yyyy-MM"); + String year = String.valueOf(calendar.get(Calendar.YEAR)); + return stations.stream().map(station ->{ + HydropowerUnitTargetVo target = new HydropowerUnitTargetVo(); + target.setDeptId(station.getRefDept()); + target.setDeptName(station.getName()); + // 当年发电量 + target.setPowerYear(generateService.generate(year,station.getCode())); + // 当月发电量 + target.setPowerMon(generateService.generate(mon,station.getCode())); + // 当日发电量 + target.setPowerDay(generateService.generate(day,station.getCode())); + // 30天发电量 + target.setGenerationPowerVoList(generateService.generate30Day(day,station.getCode())); + return target; + }).collect(Collectors.toList()); + } + + + /** + * 补充填报数据 + * @param station + * @param start + * @param end + */ + private List generateFill(StationEntity station, String start, String end) { + start = DateUtil.format(DateUtil.parse(start,DateUtil.PATTERN_DATETIME),"yyyy-MM"); + end = DateUtil.format(DateUtil.parse(end,DateUtil.PATTERN_DATETIME),"yyyy-MM"); + // 光伏 + if(HomePageConstant.PHOTOVOLTAIC.equals(station.getType())){ + return powerService.generateThreeYear(start,end,station.getRefDept()); + } + // 水电 + return generateService.generateThreeYear(start,end,station.getCode()); + } + + /** + * 获取开机状态 + * + * @param device + * @return + */ + private int getPhotovoltaicState(EminfoAndEmParamVo device, Map map) { + // 获取开关机监测点实时数据 + double value = this.getSignageValue(device, map, HomePageConstant.PV_JOINT_RELAY); + // 开机状态 + if (Math.abs(value) <= 0) { + return 0; + } + return 1; + } + + /** + * 获取上一次功率 + * + * @param device + * @param history + * @return + */ + private Double getLastLoad(EminfoAndEmParamVo device, List history) { + if (CollectionUtil.isEmpty(history)) { + return 0.0; + } + List historyDevice = history.stream().filter(o -> o.getDeviceCode().equals(device.getEmCode())).collect(Collectors.toList()); + if (CollectionUtil.isEmpty(historyDevice)) { + return 0.0; + } + return historyDevice.get(0).getLoad(); + } + + /** + * 获取光伏设备 + * + * @return + */ + private List getPhotovoltaicDevice() { + // 光伏站点 + List stations = stationService.list(Wrappers.lambdaQuery() + .eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) + .eq(StationEntity::getType,HomePageConstant.PHOTOVOLTAIC) + ); + if (CollectionUtil.isEmpty(stations)) { + return new ArrayList<>(); + } + // 设备 + List devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(), new TypeReference>() { + }); + if (CollectionUtil.isEmpty(devices)) { + return new ArrayList<>(); + } + return devices.stream().filter(device -> + stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(device.getCreateDept()) + ).collect(Collectors.toList()); + } + + /** + * 当天运行时长 + * + * @param realId + * @return + */ + private Double runHours(String realId) { + Calendar calendar = Calendar.getInstance(); + Date end = calendar.getTime(); + calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); + calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); + calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); + Date start = calendar.getTime(); + OriginalDataQuery originalDataQuery = new OriginalDataQuery(); + originalDataQuery.setRealId(realId); + originalDataQuery.setBeginTime(start); + originalDataQuery.setEndTime(end); + originalDataQuery.setLimit(100000); + originalDataQuery.setPage(1); + // 查询时间范围开关机监测点历史数据 + Result> R = historyDataSearchClient.getOriginalDataByRealIds(originalDataQuery); + if (!R.isSuccess() || ObjectUtil.isEmpty(R.getData())) { + return 0.0; + } + // 过滤相邻开关机状态相同数据 + List result = this.getFilterList(R.getData().getRecords()); + if (CollectionUtil.isEmpty(result)) { + return 0.0; + } + // 开机运行时长 + long time = this.getRunTime(result, start, end); + return BigDecimal.valueOf(time / (1000 * 60 * 60.00)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + } + + /** + * 根据事件查询数据值 + * + * @param deviceCode + * @param rideCount + * @param type + * @return + */ + private float sumValueByTime(String deviceCode, int rideCount, String type) { + Calendar calendar = Calendar.getInstance(); + String start, end; + int cycleType = 3; + switch (type) { + //年 + case "0": + calendar.add(Calendar.HOUR_OF_DAY, +1); + end = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME); + calendar.setTime(new Date()); + calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); + calendar.add(Calendar.DAY_OF_MONTH, -calendar.get(Calendar.DATE) + 1); + calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); + calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); + calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); + start = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME); + cycleType = 6; + break; + //月 + case "1": + start = DateUtil.format(new Date(), "yyyy-MM") + "-01 00:00:00"; + end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); + cycleType = 5; + break; + //日 + case "2": + start = DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00"; + end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); + break; + //昨日 + case "3": + calendar.add(Calendar.DAY_OF_MONTH, -1); + calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); + calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); + calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); + start = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME); + end = DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00"; + break; + default: + throw new ServiceException("无效查询类型!"); + } + return dataService.periodTargetFloat(start, end, 5, cycleType, deviceCode, rideCount, HomePageConstant.PV_GENERATION_CAPACITY); + } + + /** + * 当天有功功率 + * + * @param device + * @return + */ + private List photovoltaicLoadsByDay(EminfoAndEmParamVo device) { + String start = DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00"; + String end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); + List records = dataService.periodTargetData(start, end, 1, 2, device.getEmCode(), HomePageConstant.PV_LOAD); + if (CollectionUtil.isEmpty(records)) { + return new ArrayList<>(); + } + return records.stream().map(record -> { + PhotovoltaicPowerVo load = new PhotovoltaicPowerVo(); + Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); + load.setHour(time.getHours()); + load.setActivePower(Optional.ofNullable(record.getVal()).orElse("0")); + return load; + }).sorted(Comparator.comparing(PhotovoltaicPowerVo::getHour)).collect(Collectors.toList()); + } + + /** + * 近30天发电量 + * + * @param device + * @return + */ + private List getGenerateByMon(EminfoAndEmParamVo device) { + Calendar calendar = Calendar.getInstance(); + String end = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME); + calendar.add(Calendar.DAY_OF_MONTH, -29); + calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); + calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); + calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); + String start = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME); + List records = dataService.periodTargetData(start, end, 5, 3, device.getEmCode(), HomePageConstant.PV_GENERATION_CAPACITY); + if (CollectionUtil.isEmpty(records)) { + return new ArrayList<>(); + } + return records.stream().map(record -> { + GenerationPowerVo generate = new GenerationPowerVo(); + Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); + generate.setDate(DateUtil.format(time, DateUtil.PATTERN_DATE)); + generate.setGenerate(Float.valueOf(Optional.ofNullable(record.getVal()).orElse("0"))); + return generate; + }).sorted(Comparator.comparing(GenerationPowerVo::getDate)).collect(Collectors.toList()); + } + + /** + * 获取光伏站点填报数据 + * @param stations + * @return + */ + private List generateFill(List stations) { + Calendar calendar = Calendar.getInstance(); + String mon = DateUtil.format(calendar.getTime(),"yyyy-MM"); + String year = String.valueOf(calendar.get(Calendar.YEAR)); + return stations.stream().map(station ->{ + PhotovoltaicTargetVo target = new PhotovoltaicTargetVo(); + target.setDeptId(station.getRefDept()); + target.setDeptName(station.getName()); + // 当日运行时长 + target.setRunHours(0.0); + // 日发电量 + target.setGenerationDay(0.0); + // 昨日发电量 + target.setGenerationYesterday(0.0); + // 收益 + target.setIncome(0.0); + // 日发电量 + // 月发电量 + target.setGenerationMon(powerService.generate(mon,station.getRefDept())); + // 节约标准煤 + target.setTec(target.getGenerationMon() * 0.0001229); + // 二氧化碳减排 + target.setCo2(target.getGenerationMon() * 0.000997); + // 减少森林砍伐 + target.setDeforest(target.getGenerationMon() * 0.000553); + // 年发电量 + target.setGenerationYear(powerService.generate(year,station.getRefDept())); + // 30天发电量 + return target; + }).collect(Collectors.toList()); + } + + /** + * 计算切分次数 + */ + private static Integer countStep(Integer size) { + return (size + 3 - 1) / 3; + } + + /** + * 泵站设备 + * @param stations + * @return + */ + private List pumpDevices(List stations){ + if(CollectionUtil.isEmpty(stations)){ + return new ArrayList<>(); + } + List devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(),new TypeReference>() {}); + if(CollectionUtil.isEmpty(devices)){ + return new ArrayList<>(); + } + return devices.stream().filter(device->stations.contains(device.getCreateDept())).collect(Collectors.toList()); + } + + /** + * 获取实时数据 + * @return + */ + private Map getRealMap() { + String json = (String) redisTemplate.opsForValue().get(real_id_cofig_final); + if(StringUtil.isBlank(json)){ + return null; + } + return JSONObject.parseObject(json, new TypeReference>() {}); + } + + + /** + * 获取监测点实时数据 + * @param device + * @param targets + * @return + */ + private double getSignageValue(EminfoAndEmParamVo device,Map map, String targets) { + if(ObjectUtil.isEmpty(device) || MapUtils.isEmpty(map)){ + return 0.0; + } + Map point = device.getPoint(); + if(MapUtils.isEmpty(point)){ + return 0.0; + } + String realId = point.get(targets); + if(StringUtil.isBlank(realId)){ + return 0.0; + } + String value = map.get(realId); + if(StringUtil.isBlank(value)){ + return 0.0; + } + // 获取value + return Double.parseDouble(value); + } + + /** + * 单位设置 + * @param device + * @param unitMap + * @param realVo + */ + private void setttingUnit(EminfoAndEmParamVo device, Map unitMap, HydropowerUnitRealVo realVo) { + if(MapUtils.isEmpty(unitMap)){ + return; + } + // 有功功率单位 + String power = unitMap.get(device.getId()+HomePageConstant.CONCAT_P); + if(StringUtil.isNotBlank(power)){ + realVo.setPowerUnit(power); + } else { + realVo.setPowerUnit("kW"); + } + // 无功功率 + String reactivePowerUnit = unitMap.get(device.getId()+HomePageConstant.CONCAT_Q); + if(StringUtil.isNotBlank(reactivePowerUnit)){ + realVo.setReactivePowerUnit(reactivePowerUnit); + } else { + realVo.setReactivePowerUnit("kVa r"); + } + // 定子电压单位 + String voltage = unitMap.get(device.getId()+HomePageConstant.CONCAT_UAB); + if(StringUtil.isNotBlank(voltage)){ + realVo.setVoltageUnit(voltage); + } else { + realVo.setVoltageUnit("V"); + } + // 定子电流单位 + String current = unitMap.get(device.getId()+HomePageConstant.CONCAT_IA); + if(StringUtil.isNotBlank(current)){ + realVo.setCurrentUnit(current); + } else { + realVo.setCurrentUnit("A"); + } + } + + /** + * 获取年、月、日发电量 + * @param device + * @param scope + * @return + */ + private float getGenerationPower(EminfoAndEmParamVo device,int scope) { + String start,end; + int accessRules; + Calendar calendar = Calendar.getInstance(); + switch (scope){ + // 年 + case 0: + end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); + calendar.setTime(new Date()); + calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); + calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); + start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; + accessRules = EquipmentConstants.CycleTypeEnum.YEAR_CYCLE.getType(); + break; + // 月 + case 1: + start = DateUtil.format(new Date(), "yyyy-MM") + "-01 00:00:00"; + end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); + accessRules = EquipmentConstants.CycleTypeEnum.MONTH_CYCLE.getType(); + break; + // 日 + case 2: + String time = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + start = time + " 00:00:00"; + end = time + " 23:59:59"; + accessRules = EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(); + break; + default: + throw new IllegalStateException("Unexpected value: " + scope); + } + return dataService.periodTargetFloat(start,end,5,accessRules,device.getEmCode(),device.getRideCount(),HomePageConstant.HYDROPOWER_GENERATE_POWER); + } + + /** + * 近30天发电量 + * @param device + * @return + */ + private List getGenerationPowerList(EminfoAndEmParamVo device) { + String start = DateUtil.format(new Date(), "yyyy-MM") + "-01 00:00:00"; + String end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); + List records = dataService.periodTargetData(start,end,5,EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(),device.getEmCode(),HomePageConstant.HYDROPOWER_GENERATE_POWER); + if(CollectionUtil.isEmpty(records)){ + return new ArrayList<>(); + } + return records.stream().map(record -> { + GenerationPowerVo generate = new GenerationPowerVo(); + Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); + generate.setDate(DateUtil.format(time,DateUtil.PATTERN_DATE)); + generate.setGenerate(Float.parseFloat(Optional.ofNullable(record.getVal()).orElse("0")) * device.getRideCount()); + return generate; + }).collect(Collectors.toList()); + } +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ShowServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ShowServiceImpl.java new file mode 100644 index 0000000..43539bd --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/ShowServiceImpl.java @@ -0,0 +1,1275 @@ +package com.hnac.hzims.scheduled.service.operation.home.impl; + +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.google.common.util.concurrent.ThreadFactoryBuilder; +import com.hnac.hzims.EquipmentConstants; +import com.hnac.hzims.equipment.entity.PlanGenerationEntity; +import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; +import com.hnac.hzims.operational.access.constants.AccessConstants; +import com.hnac.hzims.operational.access.entity.OperAccessTaskEntity; +import com.hnac.hzims.operational.defect.constants.DefectConstant; +import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity; +import com.hnac.hzims.operational.duty.vo.DutyInfoVo; +import com.hnac.hzims.operational.duty.vo.DutyTaskVo; +import com.hnac.hzims.operational.duty.vo.NextDutyInfoVo; +import com.hnac.hzims.operational.fill.entity.*; +import com.hnac.hzims.operational.main.constant.HomePageConstant; +import com.hnac.hzims.operational.main.vo.*; +import com.hnac.hzims.operational.report.vo.DutyDefectVO; +import com.hnac.hzims.operational.station.entity.StationEntity; +import com.hnac.hzims.scheduled.service.equipment.PlanService; +import com.hnac.hzims.scheduled.service.inspect.TaskService; +import com.hnac.hzims.scheduled.service.operation.business.*; +import com.hnac.hzims.scheduled.service.operation.home.ShowService; +import com.hnac.hzims.scheduled.service.operation.fill.*; +import com.hnac.hzims.scheduled.service.operation.station.StationService; +import com.hnac.hzims.scheduled.service.operation.plate.DataService; +import com.hnac.hzims.scheduled.service.ticket.TicketService; +import com.hnac.hzims.scheduled.service.ticket.WorkTicketService; +import com.hnac.hzims.ticket.allTicket.vo.DoublePassRateVO; +import com.hnac.hzims.ticket.workTicket.vo.TicketMonthVO; +import com.hnac.hzims.ticket.workTicket.vo.WorkTicketStatisticVO; +import com.hnac.hzinfo.datasearch.analyse.IAnalyseInstanceClient; +import com.hnac.hzinfo.inspect.task.vo.DutyInspectTaskVO; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.MapUtils; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.*; +import org.springblade.system.cache.DictCache; +import org.springblade.system.entity.Dept; +import org.springblade.system.feign.ISysClient; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.math.BigDecimal; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.sql.Time; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.*; +import java.util.concurrent.*; +import java.util.stream.Collectors; + +/** + * @author ysj + */ +@Service +@RequiredArgsConstructor +@Slf4j +public class ShowServiceImpl implements ShowService { + + private final TaskService taskService; + private final OverService overService; + private final PlanService planService; + private final PowerService powerService; + private final SolveService solveService; + private final OtherService otherService; + private final AccessService accessService; + private final TicketService ticketService; + private final DefectService defectService; + private final DutyService dutyService; + private final StationService stationService; + private final OverDetailsService detailsService; + private final WorkTicketService workTicketService; + private final PhenomenonService phenomenonService; + private final DataService dataService; + private final MaintenanceService maintenanceService; + private final RedisTemplate redisTemplate; + private final ISysClient sysClient; + private final IAnalyseInstanceClient deviceInstanceClient; + + private final static String charge = "hzims:operation:key:charge"; + private final static String home_target_cache_final = "load:operation:home:target:key"; + private final static String hydropower_real_cache_final = "hzims:operation:loadhydropowerunit:real:key"; + private final static String hydropower_target_cache_final = "hzims:operation:loadhydropowerunit:target:key"; + private final static String photovoltaic_real_cache_final = "hzims:operation:photovoltaic:real:key"; + private final static String photovoltaic_target_cache_final = "hzims:operation:photovoltaic:target:key"; + + @Value("${hzims.operation.homePage.charge.url}") + public String charge_url; + + @Value("${hzims.equipment.emInfo.emInfoList}") + public String device_cache_cofig_final; + + @Value("${hzims.operation.region.areaDutyInfoKey}") + private String area_duty_cache_final; + + @Value("${hzims.operation.region.deviceClassifyKey}") + private String device_classify_cache_final; + + @Value("${hzims.operation.realIdKey}") + public String real_cache_final; + + /** + * 集团总指标-首页数据 + */ + @Override + public void loadHomeTarget(String param) { + List targets = HomePageConstant.HOME_TYPES.stream().map(type->{ + if(type == 0) { + return this.hydropowerTaget(); + } + if (type == 1) { + return this.windTaget(); + } + if (type == 2) { + return this.waterStorageTaget(true); + } + if (type == 3) { + return this.waterStorageTaget(false); + } + if (type == 4) { + return this.networkTaget(); + } + if (type == 5) { + return this.photovoltaicTaget(); + } + if (type == 6) { + return this.affairsTaget(); + } + if(type == 7) { + return this.chargeTarget(); + } + return new TargetVo(); + }).collect(Collectors.toList()); + redisTemplate.opsForValue().set(home_target_cache_final,targets.stream().filter(( target -> ObjectUtil.isNotEmpty(target.getType()))).collect(Collectors.toList())); + } + + + /** + * 智能生产-值班数据 + * @param param + */ + @Override + public void loadRegionalDuty(String param) { + R> R = sysClient.getDeptList(); + if (!R.isSuccess() || CollectionUtil.isEmpty(R.getData())) { + return; + } + Map> map = this.area(R.getData(),null, Collections.singletonList(HomePageConstant.HYDROPOWER),HomePageConstant.HYDROPOWER_SERVETYPE); + if (MapUtils.isEmpty(map)) { + return; + } + // 查询所有区域值班/接班数据 + List dutyInfoVoList = dutyService.dutyData(map.keySet().stream().map(Dept::getId).collect(Collectors.toList())); + if(CollectionUtil.isEmpty(dutyInfoVoList)){ + return; + } + // 所有设备 + List devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(), new TypeReference>() {}); + List areaDutyVoList = new ArrayList<>(); + map.forEach((key,value) -> { + List singlet = Collections.singletonList(key.getId()); + AreaDutyVo areaDutyVo = new AreaDutyVo(); + areaDutyVo.setDepartId(key.getId()); + areaDutyVo.setDepartName(key.getDeptName()); + areaDutyVo.setSort(key.getSort()); + // 值班情况 + this.dutySituation(dutyInfoVoList, key, areaDutyVo); + // 厂站运行情况 + this.factoryStationRun(devices, value, areaDutyVo); + // 当月任务执行情况 + this.executeTaskMonth(singlet, areaDutyVo); + // 获取区域当班时间 + List dutyList = dutyInfoVoList.stream().filter(o -> key.getId().equals(o.getCreateDept())).collect(Collectors.toList()); + if (CollectionUtil.isEmpty(dutyList)) { + areaDutyVoList.add(areaDutyVo); + return; + } + Date startDate = this.dutyStartTime(dutyList.get(0).getDateTime(),dutyList.get(0).getStartTime()); + Date endDate = this.dutyEndTime(dutyList.get(0).getDateTime(),dutyList.get(0).getStartTime(),dutyList.get(0).getEndTime()); + areaDutyVo.setStartTimeDuty(DateUtil.format(startDate,DateUtil.PATTERN_DATETIME)); + areaDutyVo.setEndTimeDuty(DateUtil.format(endDate,DateUtil.PATTERN_DATETIME)); + // 上一班组发电量 + this.upDutyPower(dutyList,devices,key.getId(),value,areaDutyVo); + // 班组实时发电量 + this.dutyPower(startDate,endDate,devices,value,areaDutyVo,false); + // 当班双票 + this.dutyDoubleTicket(startDate,endDate,singlet,areaDutyVo); + // 当班运行数据 + this.dutyRunCondition(startDate,endDate,singlet,areaDutyVo); + areaDutyVoList.add(areaDutyVo); + }); + redisTemplate.opsForValue().set(area_duty_cache_final, areaDutyVoList); + } + + /** + * 水电站指标 + * @return + */ + private TargetVo hydropowerTaget() { + TargetVo target = new TargetVo(); + target.setType(HomePageConstant.HYDROPOWER); + target.setTypeName(DictCache.getValue("stationType", HomePageConstant.HYDROPOWER)); + // 实时数据 + List reals = (List) redisTemplate.opsForValue().get(hydropower_real_cache_final); + // 指标数据 + List targets = (List) redisTemplate.opsForValue().get(hydropower_target_cache_final); + if(CollectionUtil.isNotEmpty(reals)){ + // 装机容量 + target.setTaget_one(reals.stream().mapToDouble(HydropowerUnitRealVo::getInstalledCapacity).sum()); + } + if(CollectionUtil.isNotEmpty(targets)){ + // 发电量 + target.setTaget_two(targets.stream().mapToDouble(HydropowerUnitTargetVo::getPowerYear).sum()); + } + // 计划发电量 + List stations = stationService.list(Wrappers.lambdaQuery() + .eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) + .eq(StationEntity::getType,HomePageConstant.HYDROPOWER)); + if(CollectionUtil.isNotEmpty(stations)){ + List plans = planService.planGeneration(stations.stream().map(StationEntity::getCode).collect(Collectors.toList()), null, DateUtil.format(new Date(), "yyyy")); + if(CollectionUtil.isNotEmpty(plans)){ + double plan = plans.stream().mapToDouble(PlanGenerationEntity::getPlanGeneration).sum(); + if(Math.abs(plan) > 0){ + target.setTaget_three(BigDecimal.valueOf(target.getTaget_two() / plan * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); + } + } + } + // 双票合格率 + R> result = sysClient.getDeptList(); + if(result.isSuccess() && CollectionUtil.isNotEmpty(result.getData()) && CollectionUtil.isNotEmpty(stations)){ + List areas = result.getData().stream().filter(dept -> stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(dept.getId())).map(Dept::getParentId).collect(Collectors.toList()); + if(CollectionUtil.isNotEmpty(areas)){ + LocalDateTime firstDateTime = LocalDateTime.of(LocalDate.now().withDayOfYear(1), LocalTime.MIN); + DoublePassRateVO pass = ticketService.doublePassRate(areas, firstDateTime, LocalDateTime.now()); + if(ObjectUtil.isNotEmpty(pass)){ + target.setTaget_four(Double.valueOf(pass.getDoublePassRate())); + } + } + } + return target; + } + + + /** + * 设备分类 + * + * @param param + */ + @Override + public void loaddDeviceClassify(String param) { + // 获取所有设备 + List devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(), new TypeReference>() {}); + // 实时数据 + String json = (String) redisTemplate.opsForValue().get(real_cache_final); + Map realMap = null; + if (StringUtil.isNotBlank(json)) { + realMap = JSONObject.parseObject(json, new TypeReference>() {}); + } + Map> deviceClassifyMap = new HashMap<>(); + List deviceCodeList = devices.stream().map(EminfoAndEmParamVo::getEmCode).collect(Collectors.toList()); + // 故障 + List operPhenomenonEntityList = phenomenonService.list(new QueryWrapper() {{ + in("EM_CODE", deviceCodeList); + ne("IS_DEFECT", DefectConstant.IsDefectStatusEnum.IS_DEFECT.getStatus()); + ne("CONCLUSION_STATUS", DefectConstant.HandlerStatusEnum.FINISH_STATUS.getStatus()); + }}); + List faultList = operPhenomenonEntityList.stream().map(OperPhenomenonEntity::getEmCode).distinct().collect(Collectors.toList()); + deviceClassifyMap.put(HomePageConstant.FAULT,faultList); + // 检修 + List operAccessTaskEntityList = accessService.list(new QueryWrapper() {{ + in("EM_CODE", deviceCodeList); + ne("STATUS", AccessConstants.ACCESS_TASK_STATUS_4); + }}); + List overhaulList = operAccessTaskEntityList.stream().map(OperAccessTaskEntity::getEmCode).distinct().collect(Collectors.toList()); + List overhaulOldList = devices.stream().filter(o-> !faultList.contains(o.getEmCode()) && !overhaulList.contains(o.getEmCode()) && (Func.isNotEmpty(o.getRunStatus()) && EquipmentConstants.RunStatus.access.getStatus().equals(o.getRunStatus()))) + .map(EminfoAndEmParamVo::getEmCode).collect(Collectors.toList()); + overhaulList.addAll(overhaulOldList); + deviceClassifyMap.put(HomePageConstant.OVERHAUL,overhaulList); + // 运行 + List runDeviceList = devices.stream().filter(o-> !faultList.contains(o.getEmCode()) && !overhaulList.contains(o.getEmCode())).distinct().collect(Collectors.toList()); + List runList = this.runDevice(runDeviceList,realMap); + deviceClassifyMap.put(HomePageConstant.RUN,runList); + // 备用 + List spareList = devices.stream().filter(o-> !faultList.contains(o.getEmCode()) && !overhaulList.contains(o.getEmCode()) && !runList.contains(o.getEmCode()) && Func.isNotEmpty(o.getRunStatus()) + && EquipmentConstants.RunStatus.spare.getStatus().equals(o.getRunStatus())) + .map(EminfoAndEmParamVo::getEmCode).distinct().collect(Collectors.toList()); + deviceClassifyMap.put(HomePageConstant.SPARE,spareList); + redisTemplate.opsForValue().set(device_classify_cache_final, deviceClassifyMap); + } + + + /** + * 风电指标 + * @return + */ + private TargetVo windTaget() { + TargetVo target = new TargetVo(); + target.setType(HomePageConstant.WIND_POWER); + target.setTypeName(DictCache.getValue("stationType", HomePageConstant.WIND_POWER)); + // 填报发电量 + List stations = stationService.list(Wrappers.lambdaQuery() + .eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) + .eq(StationEntity::getType,HomePageConstant.WIND_POWER)); + if(CollectionUtil.isEmpty(stations)){ + return target; + } + QueryWrapper queryWrapper = new QueryWrapper() {{ + in("create_dept", stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())); + eq("type", HomePageConstant.WIND_POWER_TYPE); + likeRight("mon", DateUtil.format(new Date(),"yyyy")); + }}; + List list = powerService.list(queryWrapper); + if(CollectionUtil.isEmpty(list)){ + return target; + } + double plan = list.stream().mapToDouble(PowerEntity::getPlannedPowerMon).sum(); + double pass = list.stream().mapToDouble(power -> Double.parseDouble(power.getDoubleQualifyRate())).sum(); + // 装机容量 + target.setTaget_one(list.stream().map(PowerEntity::getInstalledCapacity).collect(Collectors.toSet()).stream().mapToDouble(Double::valueOf).sum()); + // 发电量 + target.setTaget_two(list.stream().mapToDouble(PowerEntity::getPowerMon).sum()); + if(Math.abs(plan) > 0){ + // 发电完成率 + target.setTaget_three(BigDecimal.valueOf(target.getTaget_two() / plan * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); + } + // 双票合格率 + target.setTaget_four(BigDecimal.valueOf(pass / list.size()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); + return target; + } + + /** + * 储能指标 + * @param flag : true - 水利 false - 储能 + * @return + */ + private TargetVo waterStorageTaget(boolean flag) { + TargetVo target = new TargetVo(); + if(flag){ + target.setType(HomePageConstant.WATER_CONSERVANCY); + target.setTypeName(DictCache.getValue("stationType", HomePageConstant.WATER_CONSERVANCY)); + }else{ + target.setType(HomePageConstant.ENERGY_STORAGE); + target.setTypeName(DictCache.getValue("stationType", HomePageConstant.ENERGY_STORAGE)); + } + // 查询储能站点 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE); + if(flag){ + wrapper.eq(StationEntity::getType,HomePageConstant.WATER_CONSERVANCY); + }else{ + wrapper.eq(StationEntity::getType,HomePageConstant.ENERGY_STORAGE); + } + List stations = stationService.list(wrapper); + if(CollectionUtil.isEmpty(stations)){ + return target; + } + // 获取储能区域级别机构 + R> result = sysClient.getDeptList(); + if(result.isSuccess() && CollectionUtil.isNotEmpty(result.getData()) && CollectionUtil.isNotEmpty(stations)){ + List areas = result.getData().stream().filter(dept -> stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(dept.getId())).map(Dept::getParentId).collect(Collectors.toList()); + if(CollectionUtil.isNotEmpty(areas)){ + ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("storage-taget-pool-%d").build(); + ScheduledExecutorService exe = new ScheduledThreadPoolExecutor(4, namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); + // 监控线程执行完后返回结果 + CountDownLatch countDownLatch = new CountDownLatch(4); + // 日常维护 + exe.execute(() -> { + target.setTaget_one(Double.valueOf(maintenanceService.maintenanceCount(areas))); + countDownLatch.countDown(); + }); + // 检修任务 + exe.execute(() -> { + target.setTaget_two(accessService.accessCount(areas)); + countDownLatch.countDown(); + }); + // 消缺率 + exe.execute(() -> { + target.setTaget_three(defectService.defectCount(areas)); + countDownLatch.countDown(); + }); + // 双票合格率 + exe.execute(() -> { + LocalDate firstDay = LocalDate.now().withDayOfYear(1); + LocalDateTime firstDateTime = LocalDateTime.of(firstDay, LocalTime.MIN); + DoublePassRateVO pass = ticketService.doublePassRate(areas, firstDateTime, LocalDateTime.now()); + if (ObjectUtil.isNotEmpty(pass)) { + target.setTaget_four(Double.valueOf(pass.getDoublePassRate())); + } + countDownLatch.countDown(); + }); + try { + countDownLatch.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + Thread.currentThread().interrupt(); + } + exe.shutdown(); + } + } + return target; + } + + /** + * 配网 + * @return + */ + private TargetVo networkTaget() { + TargetVo target = new TargetVo(); + target.setType(HomePageConstant.DISTRIBUTION_NETWORK); + target.setTypeName(DictCache.getValue("stationType", HomePageConstant.DISTRIBUTION_NETWORK)); + // 线程池 + ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("network-taget-pool-%d").build(); + ScheduledExecutorService exe = new ScheduledThreadPoolExecutor(3, namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); + // 监控线程执行完后返回结果 + CountDownLatch countDownLatch = new CountDownLatch(3); + // 当月 + LocalDate firstDay = LocalDate.now().withDayOfYear(1); + LocalDateTime firstDateTime = LocalDateTime.of(firstDay, LocalTime.MIN); + // 检修卡 + exe.execute(()->{ + List overs = overService.list(new QueryWrapper() {{ + ge("create_time", firstDateTime); + le("create_time", LocalDateTime.now()); + }}); + if(CollectionUtil.isEmpty(overs)){ + countDownLatch.countDown(); + return; + } + List details = detailsService.list(new QueryWrapper() {{ + ge("create_time", firstDateTime); + le("create_time", LocalDateTime.now()); + in("over_id",overs.stream().map(OverEntity::getId).collect(Collectors.toList())); + }}); + if(CollectionUtil.isEmpty(details)){ + countDownLatch.countDown(); + return; + } + target.setTaget_one(details.stream().mapToDouble(OverDetailsEntity::getQuantity).sum()); + countDownLatch.countDown(); + }); + // 消缺 + exe.execute(()->{ + List solves = solveService.list(new QueryWrapper() {{ + ge("create_time", firstDateTime); + le("create_time", LocalDateTime.now()); + }}); + if(CollectionUtil.isEmpty(solves)){ + countDownLatch.countDown(); + return; + } + target.setTaget_two(solves.stream().mapToDouble(SolveEntity::getSolveQuantity).sum()); + countDownLatch.countDown(); + }); + // 其他 + exe.execute(()->{ + List others = otherService.list(new QueryWrapper() {{ + ge("create_time", firstDateTime); + le("create_time", LocalDateTime.now()); + }}); + if(CollectionUtil.isEmpty(others)){ + countDownLatch.countDown(); + return; + } + // FA上线率 + double online = others.stream().mapToDouble(o-> Double.parseDouble(o.getOnlineRate())).sum(); + if(Math.abs(online) > 0){ + target.setTaget_three(BigDecimal.valueOf(online / others.size()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); + } + // FA投入条数 + target.setTaget_four(others.stream().mapToDouble(OtherEntity::getFaQuantity).sum()); + countDownLatch.countDown(); + }); + // 等待所有线程执行完成 + try { + countDownLatch.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + Thread.currentThread().interrupt(); + } + return target; + } + + /** + * 光伏指标 + * @return + */ + private TargetVo photovoltaicTaget() { + TargetVo target = new TargetVo(); + target.setType(HomePageConstant.PHOTOVOLTAIC); + target.setTypeName(DictCache.getValue("stationType", HomePageConstant.PHOTOVOLTAIC)); + // 实时数据 + List reals = (List) redisTemplate.opsForValue().get(photovoltaic_real_cache_final); + // 指标数据 + List targets = (List) redisTemplate.opsForValue().get(photovoltaic_target_cache_final); + if(CollectionUtil.isNotEmpty(reals)){ + // 装机容量 + target.setTaget_one(reals.stream().mapToDouble(PhotovoltaicRealVo::getCapacity).sum()); + } + if(CollectionUtil.isNotEmpty(targets)){ + // 发电量 + target.setTaget_two(targets.stream().mapToDouble(PhotovoltaicTargetVo::getGenerationYear).sum()); + } + // 计划发电量、双票合格率 + List stations = stationService.list(Wrappers.lambdaQuery() + .eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) + .eq(StationEntity::getType,HomePageConstant.PHOTOVOLTAIC)); + if(CollectionUtil.isNotEmpty(stations)){ + QueryWrapper queryWrapper = new QueryWrapper() {{ + in("create_dept", stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())); + eq("type", HomePageConstant.PHOTOVOLTAIC_TYPE); + likeRight("mon", DateUtil.format(new Date(),"yyyy")); + }}; + List list = powerService.list(queryWrapper); + if(CollectionUtil.isEmpty(list)){ + return target; + } + double plan = list.stream().mapToDouble(PowerEntity::getPlannedPowerMon).sum(); + double pass = list.stream().mapToDouble(power -> Double.parseDouble(power.getDoubleQualifyRate())).sum(); + if(Math.abs(plan) > 0){ + // 发电完成率 + target.setTaget_three(BigDecimal.valueOf(target.getTaget_two() / plan * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); + } + // 双票合格率 + target.setTaget_four(BigDecimal.valueOf(pass / list.size()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); + } + return target; + } + + /** + * 水务指标 + * @return + */ + private TargetVo affairsTaget() { + TargetVo target = new TargetVo(); + target.setType(HomePageConstant.WATER_AFFAIRS); + target.setTypeName(DictCache.getValue("stationType", HomePageConstant.WATER_AFFAIRS)); + // TODO 统计业务数据 + return target; + } + + /** + * 充电桩 + * @return + */ + private TargetVo chargeTarget() { + TargetVo target = (TargetVo) redisTemplate.opsForValue().get(charge); + if(ObjectUtil.isNotEmpty(target)){ + return target; + } + target = new TargetVo(); + try { + URL serverUrl = new URL(charge_url); + HttpURLConnection conn = (HttpURLConnection) serverUrl.openConnection(); + conn.setRequestMethod("GET"); + conn.setRequestProperty("Content-type", "application/json"); + //必须设置false,否则会自动redirect到重定向后的地址 + conn.setInstanceFollowRedirects(false); + conn.connect(); + String result = responseFormat(conn); + if (StringUtil.isBlank(result)) { + return new TargetVo(); + } + JSONObject jsonObject = JSONObject.parseObject(result); + JSONObject data = JSONObject.parseObject(jsonObject.get("data").toString()); + target.setType(HomePageConstant.CHARGE); + target.setTypeName(DictCache.getValue("stationType", HomePageConstant.CHARGE)); + target.setTaget_one(Double.valueOf(data.get("ordersCount").toString())); + target.setTaget_two(Double.valueOf(data.get("todayDegree").toString())); + target.setTaget_three(Double.valueOf(data.get("income").toString())); + target.setTaget_four(Double.valueOf(data.get("kilowatt").toString())); + target.setCharge(Integer.valueOf(data.get("stationNum").toString())); + redisTemplate.opsForValue().set(charge,target); + redisTemplate.expire(charge,30, TimeUnit.MINUTES); + } catch (Exception e) { + target.setType(HomePageConstant.CHARGE); + target.setTypeName(DictCache.getValue("stationType", HomePageConstant.CHARGE)); + target.setTaget_one(0.0); + target.setTaget_two(0.0); + target.setTaget_three(0.0); + target.setTaget_four(0.0); + target.setCharge(0); + log.error("charge_target_exception: {} ", e.getMessage()); + } + return target; + } + + /*** + * 获取返回的内容 + * @param connection + * @return + */ + private String responseFormat(HttpURLConnection connection) { + StringBuilder stringBuilder = new StringBuilder(); + //将返回的输入流转换成字符串 + try ( + InputStream inputStream = connection.getInputStream(); + InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8); + BufferedReader bufferedReader = new BufferedReader(inputStreamReader) + ) { + String str; + while ((str = bufferedReader.readLine()) != null) { + stringBuilder.append(str); + } + } catch (IOException e) { + return null; + } + return stringBuilder.toString(); + } + + /** + * 获取权限区域 + * @param list : 机构列表 + * @param deptId : 起始过滤权限机构 + * @param typeList : 查询站点类型-水电、水利、光伏.... + * @param serveType : 站点服务类型 + * @return Map> + */ + private Map> area(List list,Long deptId, List typeList, Integer serveType) { + // 未传入机构列表,使用用户权限机构过滤 + if(CollectionUtil.isEmpty(list)){ + R> R = sysClient.getDeptByCurrentUser(); + if(!R.isSuccess() || CollectionUtil.isEmpty(R.getData())){ + return null; + } + list = R.getData(); + } + // 根据参数查询有效站点 + List stationList = this.stationByParams(list,deptId,typeList,serveType); + if(CollectionUtil.isEmpty(stationList)){ + return null; + } + // 有效站点归属机构Id集合 + List refDeptList = stationList.stream().map(StationEntity::getRefDept).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(refDeptList)){ + return null; + } + // 有效站点归属机构集合 + List vaildDeptList = list.stream().filter(o->refDeptList.contains(o.getId())).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(vaildDeptList)){ + return null; + } + // 根据有效站点归属机构向上区域Id + List areaIdList = vaildDeptList.stream().map(Dept::getParentId).distinct().collect(Collectors.toList()); + if(CollectionUtil.isEmpty(areaIdList)){ + return null; + } + // 根据区域Id查询区域机构 + List areaList = list.stream().filter(o->o.getDeptCategory().equals(HomePageConstant.AREA) && areaIdList.contains(o.getId())).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(areaList)){ + return null; + } + // 返回结构 + Map> result = new HashMap<>(); + for(Dept area : areaList){ + List childDeptIdList = list.stream().filter(o->o.getParentId().equals(area.getId())).map(Dept::getId).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(childDeptIdList)){ + continue; + } + List resultList = stationList.stream().filter(o->childDeptIdList.contains(o.getRefDept())).collect(Collectors.toList()); + result.put(area,resultList); + } + return result; + } + + /** + * 获取站点集合 + * @param authList + * @param deptId + * @param types + * @param servrType + * @return + */ + private List stationByParams(List authList, Long deptId, List types, Integer servrType) { + Dept dept; + if (null == deptId) { + // 最小类型机构 + Optional min = authList.stream().min(Comparator.comparing(Dept::getDeptCategory)); + dept = min.orElse(null); + if (ObjectUtil.isEmpty(dept)) { + return null; + } + } else { + // 检查是否存在传入机构 + List list = authList.stream().filter(o -> deptId.equals(o.getId())).collect(Collectors.toList()); + if (CollectionUtil.isEmpty(list)) { + return null; + } + // 传入机构为站点 + dept = list.get(0); + } + List depts; + if (dept.getDeptCategory().equals(4)) { + depts = Collections.singletonList(dept.getId()); + // 传入机构为区域、省子公司、集团 + } else { + // 递归权限机构获取站点级机构 + depts = this.stationDept(authList, dept.getId(), new ArrayList<>()); + } + // 获取水利站点(过滤其他站点类型) + return stationService.list(new LambdaQueryWrapper() {{ + eq(StationEntity::getIsDeleted, 0); + if (ObjectUtil.isNotEmpty(servrType)) { + eq(StationEntity::getServeType, servrType); + } + if (CollectionUtil.isNotEmpty(types)) { + in(StationEntity::getType, types); + } + if (CollectionUtil.isNotEmpty(depts)) { + in(StationEntity::getRefDept, depts); + } + }}); + } + + /** + * 递归权限机构获取站点级机构 + * + * @param departList + * @param deptId + * @param list + * @return + */ + private List stationDept(List departList, Long deptId, List list) { + if (null == deptId || CollectionUtil.isEmpty(departList)) { + return null; + } + departList.forEach(dept -> { + if (dept.getParentId().equals(deptId)) { + if (dept.getDeptCategory().equals(4)) { + list.add(dept.getId()); + } + stationDept(departList, dept.getId(), list); + } + }); + return list; + } + + /** + * 获取开始时间 + * @param date + * @param time + * @return + */ + private Date dutyStartTime(Date date, Time time){ + Calendar dateCal = Calendar.getInstance(); + dateCal.setTime(date); + Calendar timeCal = Calendar.getInstance(); + timeCal.setTime(time); + dateCal.set(Calendar.HOUR_OF_DAY, timeCal.get(Calendar.HOUR_OF_DAY)); + dateCal.set(Calendar.MINUTE, timeCal.get(Calendar.MINUTE)); + dateCal.set(Calendar.SECOND, timeCal.get(Calendar.SECOND)); + return dateCal.getTime(); + } + + /** + * 获取结束时间 + * @param date + * @param time + * @return + */ + private Date dutyEndTime(Date date, Time time,Time endTime){ + Calendar dateCal = Calendar.getInstance(); + dateCal.setTime(date); + Calendar timeCal = Calendar.getInstance(); + timeCal.setTime(time); + Calendar endCal = Calendar.getInstance(); + endCal.setTime(endTime); + // 结束时间 < 开始时间 + if(timeCal.after(endCal)){ + dateCal.set(Calendar.DAY_OF_MONTH, dateCal.get(Calendar.DAY_OF_MONTH) + 1 ); + } + dateCal.set(Calendar.HOUR_OF_DAY, endCal.get(Calendar.HOUR_OF_DAY)); + dateCal.set(Calendar.MINUTE, endCal.get(Calendar.MINUTE)); + dateCal.set(Calendar.SECOND, endCal.get(Calendar.SECOND)); + return dateCal.getTime(); + } + + /** + * 值班情况 + * + * @param dutyInfoVoList + * @param dept + * @param areaDutyVo + */ + private void dutySituation(List dutyInfoVoList, Dept dept, AreaDutyVo areaDutyVo) { + if (CollectionUtil.isEmpty(dutyInfoVoList) || ObjectUtil.isEmpty(dept)) { + return; + } + Long deptId = dept.getId(); + List filterList = dutyInfoVoList.stream().filter(o -> o.getCreateDept().equals(deptId)).collect(Collectors.toList()); + if (CollectionUtil.isEmpty(filterList)) { + return; + } + DutyInfoVo dutyInfoVo = filterList.get(0); + areaDutyVo.setGeneratingCapacity(dutyInfoVo.getGeneratingCapacity()); + areaDutyVo.setOnlineCapacity(dutyInfoVo.getOnlineCapacity()); + areaDutyVo.setClassName(dutyInfoVo.getClassName()); + areaDutyVo.setGroupName(dutyInfoVo.getGroupName()); + areaDutyVo.setManagerName(dutyInfoVo.getManagerName()); + areaDutyVo.setManagerPhone(dutyInfoVo.getManagerPhone()); + areaDutyVo.setNextDutyInfoVo(dutyInfoVo.getNextDutyInfoVo()); + // 当班任务 + + String taskCount = this.taskCount(dutyInfoVo.getDateTime(),dutyInfoVo.getStartTime(),dutyInfoVo.getEndTime(),dutyInfoVo.getCreateDept()); + String[] task = taskCount.split("\\|"); + areaDutyVo.setTaskCount(Integer.valueOf(task[0])); + areaDutyVo.setFinishTaskCount(Integer.valueOf(task[1])); + NextDutyInfoVo upDutyInfoVo = dutyInfoVo.getUpDutyInfoVo(); + if(ObjectUtil.isEmpty(upDutyInfoVo)){ + return; + } + // 上一班组当班任务 + String upTaskCount = this.taskCount(upDutyInfoVo.getDateTime(),upDutyInfoVo.getStartTime(),upDutyInfoVo.getEndTime(),dutyInfoVo.getCreateDept()); + String[] upTask = upTaskCount.split("\\|"); + upDutyInfoVo.setTaskCount(Integer.valueOf(upTask[0])); + upDutyInfoVo.setFinishTaskCount(Integer.valueOf(upTask[1])); + areaDutyVo.setUpDutyInfoVo(upDutyInfoVo); + } + + + /** + * 获取当班任务 + * @param dateTime + * @param startTime + * @param endTime + * @param createDept + * @return + */ + private String taskCount(Date dateTime, Time startTime, Time endTime, Long createDept) { + DutyTaskVo task = new DutyTaskVo(); + //通过线程池异步获取月报各模块内容 主要分为五块内容 + ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("duty-task-count-pool-%d").build(); + ExecutorService exe = new ThreadPoolExecutor(4, 4, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); + //监控线程执行完后返回结果 + CountDownLatch countDownLatch = new CountDownLatch(4); + List list = Collections.singletonList(createDept); + String start = DateUtil.format(this.dutyStartTime(dateTime,startTime),DateUtil.PATTERN_DATETIME); + String end = DateUtil.format(this.dutyEndTime(dateTime,startTime,endTime),DateUtil.PATTERN_DATETIME); + // 日常维护 + exe.execute(()->{ + MaintainVo maintainVo = maintenanceService.maintain(start,end,list); + int maintainSum = maintainVo.getMaintain(); + int maintainFinish = maintainVo.getMaintainFinish(); + task.setMaintainSum(maintainSum); + task.setMaintainFinish(maintainFinish); + countDownLatch.countDown(); + }); + + // 消缺 + exe.execute(()->{ + ShortagesVo shortagesVo = phenomenonService.defectMonth(start,end,list); + int shortagesSum = shortagesVo.getShortagesSum(); + int shortages = shortagesVo.getShortages(); + task.setShortagesSum(shortagesSum); + task.setShortages(shortages); + countDownLatch.countDown(); + }); + // 检修 + exe.execute(()->{ + OverhaulVo overhaulVo = accessService.overhaul(start,end,list); + int overhaul = overhaulVo.getOverhaul(); + int overhaulFinish = overhaulVo.getOverhaulFinish(); + task.setOverhaul(overhaul); + task.setOverhaulFinish(overhaulFinish); + countDownLatch.countDown(); + }); + // 巡检 + exe.execute(()->{ + // 巡检任务 + DutyInspectTaskVO inspectTask = taskService.task(start,end,list); + if(ObjectUtil.isEmpty(inspectTask)){ + task.setInspect(0); + task.setInspectFinish(0); + }else{ + int inspect = inspectTask.getInspectTaskSum(); + int inspectFinish = inspectTask.getInspectTaskFinish(); + task.setInspect(inspect); + task.setInspectFinish(inspectFinish); + } + countDownLatch.countDown(); + }); + // 等待所有线程执行完成 + try { + countDownLatch.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + Thread.currentThread().interrupt(); + } + exe.shutdown(); + return (task.getMaintainSum() + task.getShortagesSum() + task.getOverhaul() + task.getInspect()) + "|" + + (task.getMaintainFinish() + task.getShortages() + task.getOverhaulFinish() + task.getInspectFinish()); + } + + /** + * 厂站运行情况 + * + * @param list + * @param areaDutyVo + */ + private void factoryStationRun(List deviceList,List list, AreaDutyVo areaDutyVo) { + areaDutyVo.setStationSum(0); + areaDutyVo.setStationRun(0); + if (CollectionUtil.isEmpty(list) || CollectionUtil.isEmpty(deviceList)) { + return; + } + areaDutyVo.setStationSum(list.size()); + List deptList = list.stream().map(StationEntity::getRefDept).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(deptList)){ + log.info("run_station_dept_list_null : {}",areaDutyVo.getDepartName()); + return; + } + // 过滤未绑定设备 + List codes = deviceList.stream().filter(o->deptList.contains(o.getCreateDept())).map(EminfoAndEmParamVo::getEmCode).collect(Collectors.toList()); + R> R = deviceInstanceClient.getListAnalyseCode(codes); + if (!R.isSuccess() || CollectionUtil.isEmpty(R.getData())) { + log.info("run_station_valid_device_null : {}",areaDutyVo.getDepartName()); + return; + } + // 根据机构分组 + Map> map = deviceList.stream().filter(o->R.getData().contains(o.getEmCode())).collect(Collectors.groupingBy(EminfoAndEmParamVo::getCreateDept)); + if(CollectionUtil.isEmpty(map)){ + log.info("run_station_group_by_valid_null : {}",areaDutyVo.getDepartName()); + return; + } + int runCount = 0; + // 遍历分组设备 + for(Map.Entry> entry : map.entrySet()){ + // 运行设备code集合 + List runCodes = entry.getValue().stream().filter(o -> (Func.isEmpty(o.getRunStatus()) || "1".equals(o.getRunStatus()))).map(EminfoAndEmParamVo::getEmCode).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(runCodes)){ + return; + } + runCount++; + } + areaDutyVo.setStationRun(runCount); + areaDutyVo.setStationSum(list.size()); + } + + /** + * 当月任务执行情况 + * + * @param list + * @param areaDutyVo + */ + private void executeTaskMonth(List list, AreaDutyVo areaDutyVo) { + if (CollectionUtil.isEmpty(list)) { + areaDutyVo.setMaintainSumMoth(0); + areaDutyVo.setMaintainFinishSumMoth(0); + areaDutyVo.setMaintainRateMoth("0"); + areaDutyVo.setShortagesSumMoth(0); + areaDutyVo.setShortagesMoth(0); + areaDutyVo.setShortagesRateMoth("0"); + areaDutyVo.setOverhaulSumMoth(0); + areaDutyVo.setOverhaulFinishSumMoth(0); + areaDutyVo.setOverhaulRateMoth("0"); + areaDutyVo.setOperateSumMoth(0); + areaDutyVo.setOperateQualifySumMoth(0); + areaDutyVo.setOperateRateMoth("0"); + areaDutyVo.setWorkSumMoth(0); + areaDutyVo.setWorkQualifySumMoth(0); + areaDutyVo.setWorkRateMoth("0"); + return; + } + LocalDate firstDay = LocalDate.now().withDayOfMonth(1); + String start = DateUtil.format(new Date(),"yyyy-MM") + "-01 00:00:00"; + String end = DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME); + //通过线程池异步获取月报各模块内容 主要分为五块内容 + ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("month-task-pool-%d").build(); + ScheduledExecutorService exe = new ScheduledThreadPoolExecutor(4, namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); + //监控线程执行完后返回结果 + CountDownLatch countDownLatch = new CountDownLatch(4); + // 日常维护 + exe.execute(()->{ + MaintainVo maintainVo = maintenanceService.maintain(start,end,list); + int maintainSum = maintainVo.getMaintain(); + int maintainFinish = maintainVo.getMaintainFinish(); + areaDutyVo.setMaintainSumMoth(maintainSum); + areaDutyVo.setMaintainFinishSumMoth(maintainFinish); + if (maintainFinish == 0) { + areaDutyVo.setMaintainRateMoth("0"); + } else { + double maintainRate = BigDecimal.valueOf(maintainFinish / (double)maintainSum * 100L).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + areaDutyVo.setMaintainRateMoth(String.valueOf(maintainRate)); + } + countDownLatch.countDown(); + }); + + // 消缺 + exe.execute(()->{ + ShortagesVo shortagesVo = phenomenonService.defectMonth(start,end,list); + int shortagesSum = shortagesVo.getShortagesSum(); + int shortages = shortagesVo.getShortages(); + areaDutyVo.setShortagesSumMoth(shortagesSum); + areaDutyVo.setShortagesMoth(shortages); + if (Math.abs(shortagesSum) <= 0) { + areaDutyVo.setShortagesRateMoth("0"); + } else { + double shortagesRate = BigDecimal.valueOf(shortages / (double)shortagesSum * 100L).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + areaDutyVo.setShortagesRateMoth(String.valueOf(shortagesRate)); + } + countDownLatch.countDown(); + }); + // 检修 + exe.execute(()->{ + OverhaulVo overhaulVo = accessService.overhaul(start,end,list); + int overhaul = overhaulVo.getOverhaul(); + int overhaulFinish = overhaulVo.getOverhaulFinish(); + areaDutyVo.setOverhaulSumMoth(overhaul); + areaDutyVo.setOverhaulFinishSumMoth(overhaulFinish); + if (overhaulFinish == 0) { + areaDutyVo.setOverhaulRateMoth("0"); + } else { + double overhaulRate = BigDecimal.valueOf(overhaulFinish / (double)overhaul * 100L).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + areaDutyVo.setOverhaulRateMoth(String.valueOf(overhaulRate)); + } + countDownLatch.countDown(); + }); + // 操作票&工作票 + exe.execute(()->{ + TicketMonthVO ticket = ticketService.operateWork(start,end,list); + if (ObjectUtil.isEmpty(ticket)) { + areaDutyVo.setOperateSumMoth(0); + areaDutyVo.setOperateQualifySumMoth(0); + areaDutyVo.setOperateRateMoth("0"); + areaDutyVo.setWorkSumMoth(0); + areaDutyVo.setWorkQualifySumMoth(0); + areaDutyVo.setWorkRateMoth("0"); + countDownLatch.countDown(); + return; + } + int operate = ticket.getOperate(); + int operateQualify = ticket.getOperateQualify(); + areaDutyVo.setOperateSumMoth(operate); + areaDutyVo.setOperateQualifySumMoth(operateQualify); + if (operateQualify == 0) { + areaDutyVo.setOperateRateMoth("0"); + } else { + double operateRate = BigDecimal.valueOf(operateQualify / (double)operate * 100L).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + areaDutyVo.setOperateRateMoth(String.valueOf(operateRate)); + } + // 工作票 + int work = ticket.getWork(); + int workQualify = ticket.getWorkQualify(); + areaDutyVo.setWorkSumMoth(work); + areaDutyVo.setWorkQualifySumMoth(workQualify); + if (workQualify == 0) { + areaDutyVo.setWorkRateMoth("0"); + } else { + double workRate = BigDecimal.valueOf(workQualify / (double)work * 100L).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + areaDutyVo.setWorkRateMoth(String.valueOf(workRate)); + } + countDownLatch.countDown(); + }); + + // 等待所有线程执行完成 + try { + countDownLatch.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + Thread.currentThread().interrupt(); + } + exe.shutdown(); + } + + /** + * 上一班组发电量 + * @param dutyList + * @param deviceList + * @param value + * @param areaDutyVo + */ + private void upDutyPower(List dutyList, List deviceList,Long deptId, List value, AreaDutyVo areaDutyVo) { + List list = dutyList.stream().filter(o -> deptId.equals(o.getCreateDept())).collect(Collectors.toList()); + if (CollectionUtil.isEmpty(list)) { + return; + } + NextDutyInfoVo upDutyInfoVo = dutyList.get(0).getUpDutyInfoVo(); + if(ObjectUtil.isEmpty(upDutyInfoVo)){ + return; + } + // 上一班组开始时间、结束时间 + Date startDate = this.dutyStartTime(upDutyInfoVo.getDateTime(),upDutyInfoVo.getStartTime()); + Date endDate = this.dutyEndTime(upDutyInfoVo.getDateTime(),upDutyInfoVo.getStartTime(),upDutyInfoVo.getEndTime()); + // 获取时间断内发电量 + this.dutyPower(startDate,endDate,deviceList,value,areaDutyVo,true); + } + + /** + * 班组实时发电量 + * @param startDate + * @param endDate + * @param deviceList + * @param list + * @param areaDutyVo + */ + private void dutyPower(Date startDate, Date endDate, List deviceList,List list,AreaDutyVo areaDutyVo,boolean flag) { + areaDutyVo.setGeneratingCapacity(0); + List deptList = list.stream().map(StationEntity::getRefDept).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(deptList)){ + return; + } + // 区域站点下设备 + List devices = deviceList.stream().filter(o->deptList.contains(o.getCreateDept())).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(devices)){ + return; + } + // 获取当班时间内发电量 + float generatingCapacity = this.generateByDuty(devices,startDate,endDate); + // 是否为查询上一班组发电量 + if(flag){ + NextDutyInfoVo upDutyInfoVo = areaDutyVo.getUpDutyInfoVo(); + upDutyInfoVo.setGeneratingCapacity(generatingCapacity); + areaDutyVo.setUpDutyInfoVo(upDutyInfoVo); + return; + } + areaDutyVo.setGeneratingCapacity(generatingCapacity); + } + + /*** + * 根据当班时间查询发电量 + * @param devices + * @param start + * @param end + * @return + */ + private float generateByDuty(List devices, Date start, Date end) { + float generate = 0f; + if(CollectionUtil.isEmpty(devices)){ + return generate; + } + for(EminfoAndEmParamVo device : devices ){ + generate += dataService.periodTargetFloat(DateUtil.format(start,DateUtil.PATTERN_DATETIME),DateUtil.format(end,DateUtil.PATTERN_DATETIME),5,3,device.getEmCode(),device.getRideCount(),HomePageConstant.HYDROPOWER_GENERATE_POWER); + } + return generate; + } + + /** + * 当班双票 + * @param startDate + * @param endDate + * @param list + * @param areaDutyVo + */ + private void dutyDoubleTicket(Date startDate,Date endDate, List list,AreaDutyVo areaDutyVo) { + String start = DateUtil.format(startDate,"yyyy-MM") + "-01 00:00:00"; + String end = DateUtil.format(endDate,DateUtil.PATTERN_DATETIME); + if (CollectionUtil.isEmpty(list)) { + areaDutyVo.setWorkTicketCount(0); + areaDutyVo.setHandoverTicketCount(0); + areaDutyVo.setVoidTicketCount(0); + areaDutyVo.setDeferredTicketCount(0); + areaDutyVo.setCloseTicketCount(0); + areaDutyVo.setOperationTicketCount(0); + return; + } + WorkTicketStatisticVO work = workTicketService.work(start,end,list); + if (ObjectUtil.isEmpty(work)) { + areaDutyVo.setWorkTicketCount(0); + areaDutyVo.setHandoverTicketCount(0); + areaDutyVo.setVoidTicketCount(0); + areaDutyVo.setDeferredTicketCount(0); + areaDutyVo.setCloseTicketCount(0); + }else{ + areaDutyVo.setWorkTicketCount(work.getTotal()); + areaDutyVo.setHandoverTicketCount(work.getTransfer()); + areaDutyVo.setVoidTicketCount(work.getInvalid()); + areaDutyVo.setDeferredTicketCount(work.getDelay()); + areaDutyVo.setCloseTicketCount(work.getComplete()); + } + // 查询操作票 + Integer operater = ticketService.operate(start,end,list); + areaDutyVo.setOperationTicketCount(operater); + } + + /** + * 当班运行数据 + * @param startTime + * @param endTime + * @param areas + * @param areaDutyVo + */ + private void dutyRunCondition(Date startTime, Date endTime, List areas,AreaDutyVo areaDutyVo) { + String start = DateUtil.format(startTime,DateUtil.PATTERN_DATETIME); + String end = DateUtil.format(endTime,DateUtil.PATTERN_DATETIME); + // 巡检任务 + DutyInspectTaskVO task = taskService.task(start,end,areas); + areaDutyVo.setInspectionSum(0); + areaDutyVo.setInspectionFinish(0); + if(ObjectUtil.isNotEmpty(task)){ + areaDutyVo.setInspectionSum(task.getInspectTaskSum()); + areaDutyVo.setInspectionFinish(task.getInspectTaskFinish()); + if(Math.abs(task.getInspectTaskSum()) <= 0){ + areaDutyVo.setInspectionFinishRate(0.0); + }else{ + double inspectionFinishRate = BigDecimal.valueOf(task.getInspectTaskFinish() / (double)task.getInspectTaskSum() * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + areaDutyVo.setInspectionFinishRate(inspectionFinishRate); + } + areaDutyVo.setInspectTaskIds(task.getInspectTaskIds()); + } + + // 消缺 + DutyDefectVO defect = phenomenonService.defect(start,end,areas); + areaDutyVo.setShortagesSum(0); + areaDutyVo.setShortages(0); + if(ObjectUtil.isNotEmpty(defect)){ + areaDutyVo.setShortagesSum(defect.getDefectSum()); + areaDutyVo.setShortages(defect.getDefect()); + areaDutyVo.setPhenomenonIds(defect.getTotalIds()); + if(Math.abs(defect.getDefectSum()) <= 0){ + areaDutyVo.setShortagesRate(0.0); + }else{ + double shortagesRate = BigDecimal.valueOf(defect.getDefect() / (double)defect.getDefectSum() * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + areaDutyVo.setShortagesRate(shortagesRate); + } + } + // 定期工作 + RegularWorkVO regular = maintenanceService.regularWork(startTime,endTime,areas); + areaDutyVo.setWorkRegularlySum(0); + areaDutyVo.setWorkRegularly(0); + if(ObjectUtil.isNotEmpty(regular)){ + areaDutyVo.setWorkRegularlySum(regular.getRegularWorkSum()); + areaDutyVo.setWorkRegularly(regular.getRegularWork()); + areaDutyVo.setMainTaskIds(regular.getMainTaskIds()); + if(Math.abs(areaDutyVo.getWorkRegularlySum()) <= 0){ + areaDutyVo.setWorkRegularlyRate(0.0); + }else{ + double workRegularlyRate = BigDecimal.valueOf(areaDutyVo.getWorkRegularly() / (double)areaDutyVo.getWorkRegularlySum() * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + areaDutyVo.setWorkRegularlyRate(workRegularlyRate); + } + } + } + + /** + * 获取运行设备列表 + * @param runDeviceList + * @param realMap + * @return + */ + private List runDevice(List runDeviceList, Map realMap) { + return runDeviceList.stream().map(o ->{ + Map points = o.getPoint(); + if(CollectionUtil.isEmpty(points)){ + return "0"; + } + String realId = points.get(HomePageConstant.JOINT_RELAY); + if(StringUtil.isEmpty(realId)){ + return "0"; + } + if(MapUtils.isEmpty(realMap)){ + return "0"; + } + String value = realMap.get(realId); + if(StringUtil.isEmpty(value)){ + return "0"; + } + if (value.contains("1") || "1.0".equals(value)) { + return o.getEmCode(); + } + return "0"; + }).distinct().collect(Collectors.toList()); + } +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/AbnormalAlarmServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/AbnormalAlarmServiceImpl.java deleted file mode 100644 index fa8ef8a..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/AbnormalAlarmServiceImpl.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation.impl; - -import com.hnac.hzims.operational.alert.entity.AbnormalAlarmEntity; -import com.hnac.hzims.scheduled.mapper.operation.AbnormalAlarmMapper; -import com.hnac.hzims.scheduled.service.operation.AbnormalAlarmService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springframework.stereotype.Service; - -import java.util.ArrayList; -import java.util.List; - -/** - * 告警实现类 - * @author ysj - */ -@Slf4j -@Service -@RequiredArgsConstructor -public class AbnormalAlarmServiceImpl extends BaseServiceImpl implements AbnormalAlarmService { - - - @Override - public List abnormalAlarms() { - List alarmList = this.baseMapper.abnormalAlarms(); - if(CollectionUtil.isEmpty(alarmList)){ - return new ArrayList<>(); - } - return alarmList; - } -} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/AccessServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/AccessServiceImpl.java deleted file mode 100644 index da01d8e..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/AccessServiceImpl.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation.impl; - -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.hnac.hzims.operational.access.constants.AccessConstants; -import com.hnac.hzims.operational.access.entity.OperAccessTaskEntity; -import com.hnac.hzims.operational.main.vo.OverhaulVo; -import com.hnac.hzims.scheduled.mapper.operation.AccessMapper; -import com.hnac.hzims.scheduled.service.operation.AccessService; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.Func; -import org.springframework.stereotype.Service; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.util.List; -import java.util.stream.Collectors; - -/** - * @author ysj - */ -@Service -@Slf4j -@AllArgsConstructor -public class AccessServiceImpl extends BaseServiceImpl implements AccessService { - - /** - * 查询当年检修任务数量 - * @param areas - * @return - */ - @Override - public double accessCount(List areas) { - if(CollectionUtil.isEmpty(areas)) { - return 0; - } - LocalDate firstDay = LocalDate.now().withDayOfYear(1); - LocalDateTime firstDateTime = LocalDateTime.of(firstDay, LocalTime.MIN); - LocalDateTime now = LocalDateTime.now(); - //日常维护 - List accesss = this.list(new LambdaQueryWrapper(){{ - ge(OperAccessTaskEntity::getPlanStartTime,firstDateTime); - le(OperAccessTaskEntity::getPlanStartTime,now); - in(OperAccessTaskEntity::getCreateDept,areas); - }}); - if(CollectionUtil.isEmpty(accesss)){ - return 0; - } - return accesss.size(); - } - - /** - * 时间区间机构的巡检数据查询 - * @param start - * @param end - * @param areas - * @return - */ - @Override - public OverhaulVo overhaul(String start, String end, List areas) { - OverhaulVo overhaulVo = new OverhaulVo(); - // 检修总数 - List overhaulList = this.list(new LambdaQueryWrapper(){{ - ge(OperAccessTaskEntity::getPlanStartTime,start); - le(OperAccessTaskEntity::getPlanStartTime,end); - in(OperAccessTaskEntity::getCreateDept,areas); - }}); - if(CollectionUtil.isEmpty(overhaulList)){ - overhaulVo.setOverhaul(0); - overhaulVo.setOverhaulFinish(0); - return overhaulVo; - } - overhaulVo.setOverhaul(overhaulList.size()); - // 检修完成数量 - List overhaulFinishTask = overhaulList.stream().filter(task-> Func.isNotEmpty(task.getStatus()) && AccessConstants.ACCESS_TASK_STATUS_4 == task.getStatus()) - .map(OperAccessTaskEntity::getId).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(overhaulFinishTask)){ - overhaulVo.setOverhaulFinish(0); - } - overhaulVo.setOverhaulFinish(overhaulFinishTask.size()); - return overhaulVo; - } -} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/DataServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/DataServiceImpl.java deleted file mode 100644 index 6d42bb3..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/DataServiceImpl.java +++ /dev/null @@ -1,161 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation.impl; - -import com.google.common.collect.Lists; -import com.hnac.hzims.scheduled.service.operation.DataService; -import com.hnac.hzinfo.datasearch.analyse.IAnalyseDataSearchClient; -import com.hnac.hzinfo.datasearch.analyse.domain.FieldsData; -import com.hnac.hzinfo.datasearch.analyse.po.AnalyseCodeByAnalyseDataPO; -import com.hnac.hzinfo.datasearch.analyse.po.AnalyzeDataConditionPO; -import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO; -import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeCodeBySignagesVO; -import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeDataConditionVO; -import com.hnac.hzinfo.datasearch.real.po.RealDataSearchPO; -import com.hnac.hzinfo.sdk.analyse.po.MultiAnalyzeCodePO; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.DateUtil; -import org.springblade.core.tool.utils.ObjectUtil; -import org.springblade.core.tool.utils.StringUtil; -import org.springframework.stereotype.Service; - -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.*; -import java.util.function.Function; -import java.util.stream.Collectors; - -/** - * @author hx - */ -@Service -@AllArgsConstructor -@Slf4j -public class DataServiceImpl implements DataService { - - private final IAnalyseDataSearchClient analyseDataSearchClient; - - @Override - public List getAnalyzeCodeBySignages(Function convert, T resource) { - List result = Lists.newArrayList(); - List multiAnalyzeCodePOList = Lists.newArrayList(resource).stream().map(convert).collect(Collectors.toList()); - R> analyzeCodeBySignResult = analyseDataSearchClient.getAnalyzeCodeBySignages(multiAnalyzeCodePOList); - if(analyzeCodeBySignResult.isSuccess() && CollectionUtil.isNotEmpty(analyzeCodeBySignResult.getData())) { - result = analyzeCodeBySignResult.getData(); - } - return result; - } - - @Override - public List analyzeCodeBySignages(List list) { - R> result = analyseDataSearchClient.getAnalyzeCodeBySignages(list); - if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ - return new ArrayList<>(); - } - return result.getData(); - } - - @Override - public List getRealDataByAnalyzeCode(String instanceCode, List signages) { - RealDataSearchPO realData = new RealDataSearchPO(); - realData.setAnalyzeCode(instanceCode); - realData.setSignages(signages); - // 调用fegin接口查询实时数据 - R> result = analyseDataSearchClient.getRealDataByAnalyzeCode(realData); - if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ - return new ArrayList<>(); - } - return result.getData(); - } - - - /*** - * 指标数据列表查询 - * @param startTime 开始时间 - * @param endTime 结束时间 - * @param accessRules 取数规则 : 0=最早值 1=最大值 2=最小值 3=平均值 4=和值 5=差值 6=最新值 - * @param cycleType 间隔周期 : 0-> 秒 1-> 分 2-> 小时 3->天 4-> 周 5-> 月 6-> 年 - * @param deviceCode 设备编号 - * @param signages 指标 - * @return - */ - @Override - public List periodTargetData(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode, String signages) { - AnalyseCodeByAnalyseDataPO po = new AnalyseCodeByAnalyseDataPO(); - List signboardConditions = new ArrayList<>(); - AnalyzeDataConditionPO analyzeDataConditionPO = new AnalyzeDataConditionPO(); - analyzeDataConditionPO.setFull(1); - po.setDeviceCode(deviceCode); - analyzeDataConditionPO.setSignages(signages); - analyzeDataConditionPO.setKeepFigures(2); - analyzeDataConditionPO.setAccessRules(accessRules); - analyzeDataConditionPO.setSaveTimeType(cycleType); - // 间隔 - analyzeDataConditionPO.setTimeInterval(1); - analyzeDataConditionPO.setBeginTime(LocalDateTime.parse(DateUtil.format(new Date(), startTime), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME))); - analyzeDataConditionPO.setEndTime(LocalDateTime.parse(DateUtil.format(new Date(), endTime), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME))); - signboardConditions.add(analyzeDataConditionPO); - po.setSignboardConditions(signboardConditions); - log.error("period_target_data_request {}",po); - R> result = analyseDataSearchClient.getAnalyzeDataByAnalyzeCodeAndSignages(po); - if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { - return new ArrayList<>(); - } - log.error("period_target_data_resp {}",result); - return result.getData().get(0).getList(); - } - - /*** - * 指标数据列表查询 - * @param startTime 开始时间 - * @param endTime 结束时间 - * @param accessRules 取数规则 : 0=最早值 1=最大值 2=最小值 3=平均值 4=和值 5=差值 6=最新值 - * @param cycleType 间隔周期 : 0-> 秒 1-> 分 2-> 小时 3->天 4-> 周 5-> 月 6-> 年 - * @param deviceCode 设备编号 - * @param ride 配电比 - * @param signages 指标 - * @return - */ - @Override - public Float periodTargetFloat(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode,Integer ride,String signages) { - AnalyseCodeByAnalyseDataPO po = new AnalyseCodeByAnalyseDataPO(); - List signboardConditions = new ArrayList<>(); - AnalyzeDataConditionPO analyzeDataConditionPO = new AnalyzeDataConditionPO(); - analyzeDataConditionPO.setFull(1); - po.setDeviceCode(deviceCode); - analyzeDataConditionPO.setSignages(signages); - analyzeDataConditionPO.setKeepFigures(2); - analyzeDataConditionPO.setAccessRules(accessRules); - analyzeDataConditionPO.setSaveTimeType(cycleType); - // 间隔 - analyzeDataConditionPO.setTimeInterval(1); - analyzeDataConditionPO.setBeginTime(LocalDateTime.parse(DateUtil.format(new Date(), startTime), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME))); - analyzeDataConditionPO.setEndTime(LocalDateTime.parse(DateUtil.format(new Date(), endTime), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME))); - signboardConditions.add(analyzeDataConditionPO); - po.setSignboardConditions(signboardConditions); - R> result = analyseDataSearchClient.getAnalyzeDataByAnalyzeCodeAndSignages(po); - if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { - return 0f; - } - List records = result.getData(); - if(CollectionUtil.isEmpty(records)){ - return 0f; - } - AnalyzeDataConditionVO analyzeDataConditionVO = records.get(0); - if (ObjectUtil.isEmpty(analyzeDataConditionVO)) { - return 0f; - } - List analyseDataTaosVOList = analyzeDataConditionVO.getList(); - if (CollectionUtil.isEmpty(analyseDataTaosVOList)) { - return 0f; - } - AnalyseDataTaosVO analyseDataTaosVO = analyzeDataConditionVO.getList().get(0); - if (ObjectUtil.isEmpty(analyseDataTaosVO) || StringUtil.isBlank(analyseDataTaosVO.getVal())) { - return 0f; - } - return Float.parseFloat(Optional.ofNullable(analyseDataTaosVO.getVal()).orElse("0")) * ride; - } - - -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/DefectServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/DefectServiceImpl.java deleted file mode 100644 index 84af907..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/DefectServiceImpl.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation.impl; - -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.hnac.hzims.operational.defect.entity.OperDefectEntity; -import com.hnac.hzims.scheduled.mapper.operation.DefectMapper; -import com.hnac.hzims.scheduled.service.operation.DefectService; -import lombok.AllArgsConstructor; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springframework.stereotype.Service; - -import java.math.BigDecimal; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.util.List; -import java.util.stream.Collectors; - -/** - * @author ysj - */ -@Service -@AllArgsConstructor -public class DefectServiceImpl extends BaseServiceImpl implements DefectService { - - /** - * 获取消缺率 - * @param areas - * @return - */ - @Override - public Double defectCount(List areas) { - if(CollectionUtil.isEmpty(areas)) { - return 100.00; - } - LocalDate firstDay = LocalDate.now().withDayOfYear(1); - LocalDateTime firstDateTime = LocalDateTime.of(firstDay, LocalTime.MIN); - LocalDateTime now = LocalDateTime.now(); - List pTaskList = this.list(new LambdaQueryWrapper(){{ - ge(OperDefectEntity::getCreateTime,firstDateTime); - le(OperDefectEntity::getCreateTime,now); - in(OperDefectEntity::getCreateDept,areas); - }}); - if(CollectionUtil.isEmpty(pTaskList)){ - return 0.0; - } - // 缺陷处理完成数 - List finishTask = pTaskList.stream().filter(defect -> "1".equals(defect.getHandleStatus())).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(finishTask)){ - return 0.0; - } - // 消缺率 = (缺陷数 / 总数) * 100 - return BigDecimal.valueOf(finishTask.size() / (double) pTaskList.size() * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - } -} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/DutyMainServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/DutyMainServiceImpl.java deleted file mode 100644 index a49a30d..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/DutyMainServiceImpl.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation.impl; - -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.hnac.hzims.operational.duty.entity.ImsDutyMainEntity; -import com.hnac.hzims.operational.duty.vo.ImsDutyMainFeignVO; -import com.hnac.hzims.scheduled.mapper.operation.DutyMainMapper; -import com.hnac.hzims.scheduled.service.operation.DutyMainService; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springblade.core.tool.utils.ObjectUtil; -import org.springframework.stereotype.Service; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -/** - * 服务实现类 - * - * @author Chill - */ -@Service -@Slf4j -public class DutyMainServiceImpl extends BaseServiceImpl implements DutyMainService { - - - @Override - public ImsDutyMainFeignVO mainPerson(Long classId, String date) { - ImsDutyMainEntity entity = this.getOne(new LambdaQueryWrapper() {{ - eq(ImsDutyMainEntity::getDutyDate, date); - eq(ImsDutyMainEntity::getClassId, classId); - }}); - if(ObjectUtil.isEmpty(entity)){ - return new ImsDutyMainFeignVO(); - } - ImsDutyMainFeignVO main = new ImsDutyMainFeignVO(); - main.setMainId(entity.getId()); - String[] persons = entity.getDutyPersonIds().split("\\^"); - //string 转为 long - List personList = Arrays.stream(persons).map(person -> Long.parseLong(person.trim())).collect(Collectors.toList()); - main.setPersons(personList); - return main; - } -} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/DutyServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/DutyServiceImpl.java deleted file mode 100644 index cbaf723..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/DutyServiceImpl.java +++ /dev/null @@ -1,176 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation.impl; - -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.hnac.hzims.operational.duty.entity.ImsDutyGroupEntity; -import com.hnac.hzims.operational.duty.entity.ImsDutyMainEntity; -import com.hnac.hzims.operational.duty.entity.ImsDutyMainPersonEntity; -import com.hnac.hzims.operational.duty.vo.DutyInfoVo; -import com.hnac.hzims.operational.duty.vo.DutyMainInfoVo; -import com.hnac.hzims.operational.duty.vo.NextDutyInfoVo; -import com.hnac.hzims.scheduled.mapper.operation.DutyGroupMapper; -import com.hnac.hzims.scheduled.mapper.operation.DutyMapper; -import com.hnac.hzims.scheduled.mapper.operation.DutyPersonMapper; -import com.hnac.hzims.scheduled.service.operation.DutyService; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.ObjectUtil; -import org.springblade.system.user.cache.UserCache; -import org.springblade.system.user.entity.User; -import org.springframework.stereotype.Service; - -import java.util.List; -import java.util.stream.Collectors; - -/** - * @author ysj - */ -@Service -@AllArgsConstructor -@Slf4j -public class DutyServiceImpl extends BaseServiceImpl implements DutyService { - - private final DutyPersonMapper dutyPersonMapper; - private final DutyGroupMapper dutyGroupMapper; - - @Override - public List dutyData(List collect) { - if (CollectionUtil.isEmpty(collect)) { - return null; - } - // 查询区域当前值班 - List dutyInfoVoList = this.baseMapper.dutyData(collect); - if (CollectionUtil.isEmpty(dutyInfoVoList)) { - return null; - } - //修改数据结构后:分灵活排班和班组排班拿负责人 - dutyInfoVoList = dutyInfoVoList.stream().peek(s -> { - if (null == s.getGroupId()) { - ImsDutyMainPersonEntity imsDutyMainPersonEntity = dutyPersonMapper.selectOne(new LambdaQueryWrapper() {{ - eq(ImsDutyMainPersonEntity::getDutyMainId, s.getId()); - last(" limit 1"); - }}); - s.setManagerId(imsDutyMainPersonEntity.getDutyChargePerson().toString()); - } else { - ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(s.getGroupId()); - s.setGroupName(imsDutyGroupEntity.getGroupName()); - s.setManagerId(imsDutyGroupEntity.getManagerId().toString()); - } - }).collect(Collectors.toList()); - dutyInfoVoList.forEach(item -> { - // 负责人 - User user = UserCache.getUser(Long.valueOf(item.getManagerId())); - if (ObjectUtil.isNotEmpty(user)) { - item.setManagerName(user.getName()); - item.setManagerPhone(user.getPhone()); - } - // FIXME 上网 - item.setOnlineCapacity(0.0); - // 发电量 - item.setGeneratingCapacity(0); - // 上一班组 - NextDutyInfoVo upDutyInfoVo = this.getUpDutyInfo(item); - item.setUpDutyInfoVo(upDutyInfoVo); - // 下一班组 - NextDutyInfoVo nextDutyInfoVo = this.getNextDutyInfo(item); - item.setNextDutyInfoVo(nextDutyInfoVo); - }); - return dutyInfoVoList; - } - - - /** - * 获取上一班组 - * - * @param item - * @return - */ - private NextDutyInfoVo getUpDutyInfo(DutyInfoVo item) { - if(ObjectUtil.isEmpty(item.getPreDutyId())){ - return null; - } - DutyMainInfoVo dutyMainInfoVo = this.baseMapper.queryDuty(item.getPreDutyId()); - if (null == dutyMainInfoVo.getDutyGroupId()) { - ImsDutyMainPersonEntity imsDutyMainPersonEntity = dutyPersonMapper.selectOne(new LambdaQueryWrapper() {{ - eq(ImsDutyMainPersonEntity::getDutyMainId, dutyMainInfoVo.getId()); - last(" LIMIT 1"); - }}); - dutyMainInfoVo.setManagerId(imsDutyMainPersonEntity.getDutyChargePerson().toString()); - } else { - ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(dutyMainInfoVo.getDutyGroupId()); - dutyMainInfoVo.setGroupName(imsDutyGroupEntity.getGroupName()); - dutyMainInfoVo.setDutyGroupId(imsDutyGroupEntity.getId()); - dutyMainInfoVo.setManagerId(imsDutyGroupEntity.getManagerId().toString()); - } - if (ObjectUtil.isEmpty(dutyMainInfoVo)) { - return null; - } - // 赋值 - NextDutyInfoVo dutyInfoVo = new NextDutyInfoVo(); - dutyInfoVo.setGroupName(dutyMainInfoVo.getGroupName()); - dutyInfoVo.setClassName(dutyMainInfoVo.getClassName()); - dutyInfoVo.setDateTime(dutyMainInfoVo.getDateTime()); - dutyInfoVo.setStartTime(dutyMainInfoVo.getStartTime()); - dutyInfoVo.setEndTime(dutyMainInfoVo.getEndTime()); - // 负责人 - User user = UserCache.getUser(Long.valueOf(dutyMainInfoVo.getManagerId())); - if (ObjectUtil.isNotEmpty(user)) { - dutyInfoVo.setManagerName(user.getName()); - dutyInfoVo.setManagerPhone(user.getPhone()); - } - // 发电量 - dutyInfoVo.setGeneratingCapacity(0); - return dutyInfoVo; - } - - /** - * 获取下一班组 - * - * @param item - * @return - */ - private NextDutyInfoVo getNextDutyInfo(DutyInfoVo item) { - DutyMainInfoVo dutyMainInfoVo = this.nextDuty(item.getId()); - if (ObjectUtil.isEmpty(dutyMainInfoVo)) { - return null; - } - // 赋值 - NextDutyInfoVo dutyInfoVo = new NextDutyInfoVo(); - dutyInfoVo.setGroupName(dutyMainInfoVo.getGroupName()); - dutyInfoVo.setClassName(dutyMainInfoVo.getClassName()); - // 负责人 - User user = UserCache.getUser(Long.valueOf(dutyMainInfoVo.getManagerId())); - if (ObjectUtil.isNotEmpty(user)) { - dutyInfoVo.setManagerName(user.getName()); - dutyInfoVo.setManagerPhone(user.getPhone()); - } - dutyInfoVo.setGeneratingCapacity(0); - return dutyInfoVo; - } - - /** - * 下一班组 - * @param parentId - * @return - */ - public DutyMainInfoVo nextDuty(Long parentId) { - DutyMainInfoVo dutyMainInfoVo = this.baseMapper.selectDuty(parentId); - if(ObjectUtil.isEmpty(dutyMainInfoVo)){ - return new DutyMainInfoVo(); - } - if (null == dutyMainInfoVo.getDutyGroupId()) { - ImsDutyMainPersonEntity imsDutyMainPersonEntity = dutyPersonMapper.selectOne(new LambdaQueryWrapper() {{ - eq(ImsDutyMainPersonEntity::getDutyMainId, dutyMainInfoVo.getId()); - last("limit 1"); - }}); - dutyMainInfoVo.setManagerId(imsDutyMainPersonEntity.getDutyChargePerson().toString()); - } else { - ImsDutyGroupEntity imsDutyGroupEntity = dutyGroupMapper.selectById(dutyMainInfoVo.getDutyGroupId()); - dutyMainInfoVo.setGroupName(imsDutyGroupEntity.getGroupName()); - dutyMainInfoVo.setDutyGroupId(imsDutyGroupEntity.getId()); - dutyMainInfoVo.setManagerId(imsDutyGroupEntity.getManagerId().toString()); - } - return dutyMainInfoVo; - } -} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/GenerateServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/GenerateServiceImpl.java deleted file mode 100644 index 470f95e..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/GenerateServiceImpl.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation.impl; - -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.hnac.hzims.operational.fill.entity.GenerateEntity; -import com.hnac.hzims.operational.main.vo.GenerationPowerVo; -import com.hnac.hzims.operational.main.vo.PowerMonthVo; -import com.hnac.hzims.scheduled.mapper.operation.GenerateMapper; -import com.hnac.hzims.scheduled.service.operation.GenerateService; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.DateUtil; -import org.springframework.stereotype.Service; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.List; -import java.util.stream.Collectors; - -/** - * @author ysj - * @date 2023/04/10 11:16:07 - * @version 4.0.0 - */ -@Slf4j -@Service -@AllArgsConstructor -public class GenerateServiceImpl extends BaseServiceImpl implements GenerateService { - - /** - * 根据时间、机构查询用电量 - * @param date 时间: 年 - yyyy/月 yyyy-mm/日 yyyy-mm-dd - * @param station 所属机构 - * @return - */ - @Override - public Float generate(String date, String station) { - List powers = this.list(Wrappers.lambdaQuery() - .likeRight(GenerateEntity::getFillDate,date) - .eq(GenerateEntity::getStationCode,station) - ); - if(CollectionUtil.isEmpty(powers)){ - return 0f; - } - return (float) powers.stream().mapToDouble(GenerateEntity::getGenerate).sum(); - } - - /** - * 查询30天填报用电量 - * @param day : 结束日期 yyyy-MM-dd - * @param station 站点编码 - * @return - */ - @Override - public List generate30Day(String day, String station) { - Calendar calendar = Calendar.getInstance(); - calendar.setTime(DateUtil.parse(day,DateUtil.PATTERN_DATE)); - String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); - calendar.add(Calendar.DAY_OF_MONTH,-29); - String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); - List records = this.list(Wrappers.lambdaQuery() - .between(GenerateEntity::getFillDate,start,end) - .eq(GenerateEntity::getStationCode,station) - ); - if(CollectionUtil.isEmpty(records)){ - return new ArrayList<>(); - } - return records.stream().map(record->{ - GenerationPowerVo generate = new GenerationPowerVo(); - generate.setDate(record.getFillDate()); - if(Math.abs(record.getGenerate()) <= 0){ - generate.setGenerate(0f); - }else{ - generate.setGenerate(Float.parseFloat(record.getGenerate().toString())); - } - return generate; - }).collect(Collectors.toList()); - } - - /** - * - * @param start 时间: 年 - yyyy/月 yyyy-mm/日 yyyy-mm-dd - * @param end 时间: 年 - yyyy/月 yyyy-mm/日 yyyy-mm-dd - * @param station 站点编码 - * @return - */ - @Override - public List generateThreeYear(String start, String end, String station) { - List records = this.list(Wrappers.lambdaQuery() - .eq(GenerateEntity::getStationCode,station) - .between(GenerateEntity::getFillDate,start,end) - ); - if(CollectionUtil.isEmpty(records)){ - return new ArrayList<>(); - } - // 返回结果 - return records.stream().peek( - record-> record.setFillDate(DateUtil.format(DateUtil.parse(record.getFillDate(),"yyyy-MM"),"yyyy-MM") + "-01") - ).collect(Collectors.toMap(GenerateEntity::getFillDate,GenerateEntity::getGenerate,Double::sum)). - entrySet().stream().map(entry->{ - PowerMonthVo mon = new PowerMonthVo(); - mon.setStrMonth(entry.getKey()); - if(Math.abs(entry.getValue()) <= 0){ - mon.setPower(0f); - }else{ - mon.setPower(Float.parseFloat(entry.getValue().toString())); - } - return mon; - }).collect(Collectors.toList()); - } -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/MaintenanceServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/MaintenanceServiceImpl.java deleted file mode 100644 index 47abb2b..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/MaintenanceServiceImpl.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation.impl; - -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.hnac.hzims.operational.main.vo.MaintainVo; -import com.hnac.hzims.operational.main.vo.RegularWorkVO; -import com.hnac.hzims.operational.maintenance.constants.MaintenanceConstant; -import com.hnac.hzims.operational.maintenance.entity.OperMaintenanceTaskEntity; -import com.hnac.hzims.scheduled.mapper.operation.MaintenanceMapper; -import com.hnac.hzims.scheduled.service.operation.MaintenanceService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.Func; -import org.springframework.stereotype.Service; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.util.Date; -import java.util.List; -import java.util.stream.Collectors; - -/** - * @author ysj - */ -@Service -@RequiredArgsConstructor -@Slf4j -public class MaintenanceServiceImpl extends BaseServiceImpl implements MaintenanceService { - - /** - * 获取日常维护数量 - * @param departList - * @return - */ - @Override - public Integer maintenanceCount(List departList) { - if(CollectionUtil.isEmpty(departList)){ - return 0; - } - LocalDate firstDay = LocalDate.now().withDayOfYear(1); - LocalDateTime firstDateTime = LocalDateTime.of(firstDay, LocalTime.MIN); - LocalDateTime now = LocalDateTime.now(); - //日常维护 - List mTaskList = this.list(new LambdaQueryWrapper(){{ - ge(OperMaintenanceTaskEntity::getDisposeTime,firstDateTime); - le(OperMaintenanceTaskEntity::getDisposeTime,now); - in(OperMaintenanceTaskEntity::getCreateDept,departList); - }}); - if(CollectionUtil.isEmpty(mTaskList)){ - return 0; - } - return mTaskList.size(); - } - - /** - * 时间区间机构的日常维护数据查询 - * @param start - * @param end - * @param areas - * @return - */ - @Override - public MaintainVo maintain(String start, String end, List areas) { - MaintainVo maintainVo = new MaintainVo(); - //日常维护 - List maintainList = this.list(new LambdaQueryWrapper(){{ - ge(OperMaintenanceTaskEntity::getDisposeTime,start); - le(OperMaintenanceTaskEntity::getDisposeTime,end); - in(OperMaintenanceTaskEntity::getCreateDept,areas); - }}); - if(CollectionUtil.isEmpty(maintainList)){ - maintainVo.setMaintain(0); - maintainVo.setMaintainFinish(0); - return maintainVo; - } - // 日常维护完成数 - maintainVo.setMaintain(maintainList.size()); - List maintainFinish = maintainList.stream().filter(o-> Func.isNotEmpty(o.getStatus()) && MaintenanceConstant.TASK_STATUS_5 == o.getStatus()) - .map(OperMaintenanceTaskEntity::getId).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(maintainFinish)){ - maintainVo.setMaintainFinish(0); - } - maintainVo.setMaintainFinish(maintainFinish.size()); - return maintainVo; - } - - /** - * 查询日常维护-定期工作类型数据 - * @param start - * @param end - * @param areas - * @return - */ - @Override - public RegularWorkVO regularWork(Date start, Date end, List areas) { - RegularWorkVO regularWorkVO = new RegularWorkVO(); - // 查询定期工作任务 - List regularWorkList = this.list(new LambdaQueryWrapper() {{ - ge(OperMaintenanceTaskEntity::getDisposeTime, start) - .le(OperMaintenanceTaskEntity::getDisposeTime, end) - .eq(OperMaintenanceTaskEntity::getTypeCode, "05") - .in(OperMaintenanceTaskEntity::getCreateDept, areas); - }}); - if (CollectionUtil.isEmpty(regularWorkList)) { - regularWorkVO.setRegularWorkSum(0); - regularWorkVO.setRegularWork(0); - return regularWorkVO; - } - regularWorkVO.setMainTaskIds(regularWorkList.stream().map(OperMaintenanceTaskEntity::getId).map(Object::toString).collect(Collectors.joining(","))); - regularWorkVO.setRegularWorkSum(regularWorkList.size()); - // 定期工作任务完成数量 - List regularWorkFinishList = regularWorkList.stream().filter(o -> MaintenanceConstant.TASK_STATUS_5 == o.getStatus()).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(regularWorkFinishList)) { - regularWorkVO.setRegularWork(0); - return regularWorkVO; - } - regularWorkVO.setRegularWork(regularWorkFinishList.size()); - return regularWorkVO; - } - - -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/ModelStationServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/ModelStationServiceImpl.java deleted file mode 100644 index 946fdab..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/ModelStationServiceImpl.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation.impl; - - -import com.hnac.hzims.operational.station.entity.HzimsAnalyzeModelStationEntity; -import com.hnac.hzims.scheduled.mapper.operation.ModelStationMapper; -import com.hnac.hzims.scheduled.service.operation.ModelStationService; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springframework.stereotype.Service; - -/** - * @author ysj - */ -@Service -public class ModelStationServiceImpl extends BaseServiceImpl implements ModelStationService { - -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/MonitorServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/MonitorServiceImpl.java deleted file mode 100644 index 07df760..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/MonitorServiceImpl.java +++ /dev/null @@ -1,747 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation.impl; - -import com.alibaba.fastjson.JSONObject; -import com.alibaba.fastjson.TypeReference; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.google.common.collect.Lists; -import com.google.common.util.concurrent.ThreadFactoryBuilder; -import com.hnac.hzims.equipment.entity.WorkshopInfoEntity; -import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; -import com.hnac.hzims.fdp.vo.FdpFaultStatusVo; -import com.hnac.hzims.operational.config.entity.StAlarmRecordEntity; -import com.hnac.hzims.operational.config.enume.ConfigStatus; -import com.hnac.hzims.operational.config.vo.StationRealVo; -import com.hnac.hzims.operational.main.constant.HomePageConstant; -import com.hnac.hzims.operational.main.vo.RealAttributeVo; -import com.hnac.hzims.operational.main.vo.RealDeviceVo; -import com.hnac.hzims.operational.main.vo.RealStationVo; -import com.hnac.hzims.operational.station.entity.StationAttributeEntity; -import com.hnac.hzims.operational.station.entity.StationEntity; -import com.hnac.hzims.scheduled.service.equipment.WorkshopInfoService; -import com.hnac.hzims.scheduled.service.operation.*; -import com.hnac.hzinfo.datasearch.analyse.IAnalyseDataSearchClient; -import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeCodeBySignagesVO; -import com.hnac.hzinfo.sdk.analyse.po.MultiAnalyzeCodePO; -import com.hnac.hzinfo.sdk.v5.redis.RedisClient; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections4.MapUtils; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.*; -import org.springblade.system.entity.Dept; -import org.springblade.system.feign.ISysClient; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Service; - -import java.util.*; -import java.util.concurrent.*; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -/** - * 集中监控数据获取实现类 - * @author ysj - */ -@Service -@RequiredArgsConstructor -@Slf4j -public class MonitorServiceImpl implements MonitorService { - - private final RecordService alertService; - private final StationService stationService; - private final StationAttributeService attbtService; - private final WorkshopInfoService workshopInfoService; - private final AbnormalAlarmService abnormalAlarmService; - private final StationAttrConfigService attrConfigService; - private final RedisTemplate redisTemplate; - private final ISysClient sysClient; - private final RedisClient redisClient; - private final IAnalyseDataSearchClient analyseDataSearchClient; - - @Value("${hzims.equipment.emInfo.emInfoList}") - public String device_cache_final; - - @Value("${hzims.operation.realIdKey}") - public String real_cache_final; - - @Value("${hzims.operation.realIdKeyGather}") - public String real_gather_cache_final; - - @Value("${hzims.operation.realIdKeyGather}") - public String real_data_cache_final; - - @Value("${hzims.equipment.fdp.redisData}") - public String fdp_fault_cache_final; - - @Value("${hzims.equipment.fdp.lessThan}") - public Double less_than_cache_final; - - @Value("${hzims.equipment.fdp.greaterThan}") - public Double greater_than_cache_final; - - @Value("${hzims.operation.monitor.realId}") - public String moniter_realId_cache_final; - - @Value("${hzims.operation.monitor.station}") - public String moniter_station_cache_final; - - @Value("${hzims.equipment.fdp.beEqualOrGreaterThan}") - public Double be_equa_cache_final; - - @Value("${hzims.operation.region.deviceClassifyKey}") - private String device_classify_cache_final; - - @Override - public void loadRealId(String param) { - // 所有站点 - List stationList = stationService.list(); - if(CollectionUtil.isEmpty(stationList)){ - return; - } - // 设备监测点list - Object json = redisTemplate.opsForValue().get(device_cache_final); - List eminfoAndEmParams = JSONObject.parseObject(json.toString(), new TypeReference>() {}); - // 厂房监测点list - List wsMonitorList = this.getRealIdByWsCodeAndSign(); - // 实时监控监测点list - List timeList = attbtService.list(new LambdaQueryWrapper() {{ - eq(StationAttributeEntity::getIsDeleted, "0"); - isNotNull(StationAttributeEntity::getMonitorId); - orderByAsc(StationAttributeEntity::getSort); - }}); - // 监测点存储list - List list = new ArrayList<>(); - stationList.forEach(station->{ - StationRealVo stationRealVo = new StationRealVo(); - stationRealVo.setStation(station.getCode()); - List realDeviceList = this.getRealDeviceList(station.getRefDept(),eminfoAndEmParams); - // 厂站匹配站点监测点集合 - List realWsList = wsMonitorList.stream().filter( - o -> Func.isNotEmpty(o.getStation()) && o.getStation().equals(station.getCode()) - ).map(AnalyzeCodeBySignagesVO::getRealId).collect(Collectors.toList()); - // 实时监控匹配站点监测点集合 - List realTimeList = timeList.stream().filter(o -> null != o.getStationId() && o.getStationId().equals(station.getCode())).map(StationAttributeEntity::getMonitorId).collect(Collectors.toList()); - if(CollectionUtil.isNotEmpty(realTimeList)){ - realDeviceList.addAll(realTimeList); - } - if(CollectionUtil.isNotEmpty(realWsList)) { - realDeviceList.addAll(realWsList); - } - if(CollectionUtil.isEmpty(realDeviceList)){ - return; - } - List realList = realDeviceList.stream().distinct().collect(Collectors.toList()); - String[] realArr = StringUtil.join(realList,",").split(","); - stationRealVo.setRealId(realArr); - list.add(stationRealVo); - }); - redisTemplate.opsForValue().set(moniter_realId_cache_final,list); - } - - @Override - public void loadRealData(String param) { - // 获取设备 - List devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_final).toString(),new TypeReference>() {});; - // 设备开关机集合监测点 - List switchOnOff = devices.stream().map(o->{ - Map points = o.getPoint(); - if(CollectionUtil.isEmpty(points)){ - return ""; - } - String jointRelay = points.get(HomePageConstant.JOINT_RELAY); - if(!StringUtil.isEmpty(jointRelay)){ - return jointRelay; - } - String onOff = points.get(HomePageConstant.SWITCH_ON_OFF); - if(!StringUtil.isEmpty(onOff)){ - return onOff; - } - return ""; - }).collect(Collectors.toList()); - // 获取站点缓存数据 - List stationRealVos = (List) redisTemplate.opsForValue().get(moniter_realId_cache_final); - if(CollectionUtil.isEmpty(stationRealVos)){ - return; - } - // 数据切割 - int limit = countStep(stationRealVos.size()); - List> list = Stream.iterate(0, n -> n + 1).limit(limit).parallel().map(a -> stationRealVos.stream().skip((long) a * 5).limit(5).parallel().collect(Collectors.toList())).collect(Collectors.toList()); - ExecutorService pool = Executors.newFixedThreadPool(limit); - // - Map valueMap = new ConcurrentHashMap<>(); - // > - Map> keyMap = new ConcurrentHashMap<>(); - CountDownLatch countDownLatch = new CountDownLatch(limit); - pool.execute(()-> list.forEach(stations -> { - stations.forEach(stationReal -> { - String[] realIdArr = stationReal.getRealId(); - List realIds = Stream.of(realIdArr).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(realIds)){ - return; - } - log.error("real_time_data: {},{}",stationReal.getStation(),realIds); - List objects = redisClient.getBatchRealDataByRealId(stationReal.getStation(),realIds); - for(int i = 0; i < realIds.size() ;i++){ - if(ObjectUtil.isEmpty(objects.get(i))){ - log.error(realIds.get(i) + "is null"); - }else{ - Map attribute = (Map) JSONObject.parse(objects.get(i)); - attribute.put("realId",attribute.get("k")); - attribute.put("value",attribute.get("v")); - attribute.put("time",attribute.get("t")); - attribute.remove("v"); - attribute.remove("k"); - attribute.remove("t"); - this.getCheckMap(attribute,switchOnOff); - valueMap.put(realIdArr[i],attribute.get("value")); - keyMap.put(realIdArr[i],attribute); - } - } - }); - countDownLatch.countDown(); - })); - // 等待所有线程执行完成 - try { - countDownLatch.await(); - } catch (InterruptedException e) { - e.printStackTrace(); - Thread.currentThread().interrupt(); - } - pool.shutdown(); - // redis 存储 - redisTemplate.opsForValue().set(real_cache_final,JSONObject.toJSONString(valueMap)); - redisTemplate.opsForValue().set(real_gather_cache_final,JSONObject.toJSONString(keyMap)); - } - - /** - * 计算切分次数 - */ - private static Integer countStep(Integer size) { - return (size + 5 - 1) / 5; - } - - /** - * 监测点过期数据检查 - * @param value - * @return - */ - private void getCheckMap(Map value,List switchOnOff){ - // 不处理开机状态监测点 - if(switchOnOff.contains(value.get("realId"))){ - return; - } - String time = value.get("time"); - if(StringUtil.isEmpty(time)){ - return; - } - Date date = DateUtil.parse(time,DateUtil.PATTERN_DATETIME); - // 实时数据超出10分钟未刷新,值置为 0 显示 - if(System.currentTimeMillis() - date.getTime() > 10 * 60 * 1000L){ - value.put("value","0"); - } - } - - /** - * 集中监控数据处理 - * @param param - */ - @Override - public void loadMonitoring(String param) { - Thread thread = Thread.currentThread(); - Object json = redisTemplate.opsForValue().get(real_data_cache_final); - if (ObjectUtil.isEmpty(json)) { - return; - } - Map> map = JSONObject.parseObject(json.toString(), new TypeReference>>() { - }); - if (MapUtils.isEmpty(map)) { - return; - } - // 获取所有设备重点属性 - List list = attbtService.list(new LambdaQueryWrapper() {{ - isNotNull(StationAttributeEntity::getStationId); - eq(StationAttributeEntity::getIsDeleted, "0"); - orderByAsc(StationAttributeEntity::getSort); - }}); - if (CollectionUtil.isEmpty(list)) { - return; - } - // 获取所有告警记录 - List alertList = alertService.list(new LambdaQueryWrapper() {{ - orderByDesc(StAlarmRecordEntity::getCreateTime); - }}); - List alarmList = abnormalAlarmService.abnormalAlarms(); - // 获取所有故障记录 - List faultList = this.getFdpFaultAll(); - // 所有设备分类 - Map> deviceClassifyMap = (Map>) redisTemplate.opsForValue().get(device_classify_cache_final); - // 所有设备 - List devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_final).toString(),new TypeReference>() {}); - // 根据站点分组 - Map> stationAttbtMap = list.stream().collect(Collectors.groupingBy(StationAttributeEntity::getStationId)); - // 获取站点列表 - List stationEntityList = stationService.list(Wrappers.lambdaQuery() - .in(StationEntity::getCode,new ArrayList<>(stationAttbtMap.keySet()))); - // 隐藏设备列表 - List hideList = attrConfigService.getHideList(); - // 分割,每个map限制10个长度 - List>> handleList = this.mapChunk(stationAttbtMap); - // 创建线程池 - ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("load-monitoring-pool-%d").build(); - ExecutorService pool = new ThreadPoolExecutor(5, 5, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); - CountDownLatch countDownLatch = new CountDownLatch(handleList.size()); - // 所有机构 - R> deptAll = sysClient.getDeptList(); - // 存储数据节点 - List stationList = new CopyOnWriteArrayList<>(); - pool.execute(()->{ - // 线程处理数据 - for(Map> item : handleList){ - item.forEach((key,value)->{ - RealStationVo station = new RealStationVo(); - // 站点编码 - station.setStationCode(key); - // 设置站点状态 - this.setStationStatus(alarmList,station,key); - // 名称、限制水位、服务类型、机构、排序 - this.stationParam(stationEntityList,station,deptAll.getData()); - // 根据设备名称分组 - Map> deviceAttbtMap = value.stream().filter(o -> !hideList.contains(o.getEmName())).collect(Collectors.groupingBy(StationAttributeEntity::getEmName)); - List deviceList = new ArrayList<>(); - // device - 设备,arrbt - 设备重点属性 - deviceAttbtMap.forEach((device, attbt) -> { - RealDeviceVo deviceVo = new RealDeviceVo(); - // 设备名称 - deviceVo.setDeviceName(device); - deviceVo.setDeviceCode(attbt.get(0).getEmCode()); - // 设备处理 - this.handleDevice(attbt, map, deviceVo, alertList, faultList); - deviceList.add(deviceVo); - }); - // 设备状态 - this.getDeviceParam(devices, deviceClassifyMap, deviceList); - station.setDeviceList(deviceList.stream().sorted(Comparator.comparing((RealDeviceVo::getDeviceName))).collect(Collectors.toList())); - stationList.add(station); - }); - countDownLatch.countDown(); - } - }); - // 等待所有线程执行完成 - try { - countDownLatch.await(); - } catch (InterruptedException e) { - e.printStackTrace(); - Thread.currentThread().interrupt(); - } - pool.shutdown(); - redisTemplate.opsForValue().set(moniter_station_cache_final, stationList); - } - - /** - * 设备处理 - * - * @param list - * @param map - * @param device - */ - private void handleDevice(List list, Map> map, - RealDeviceVo device, List alertList, - List faultList) { - if (CollectionUtil.isEmpty(list) || MapUtils.isEmpty(map)) { - return; - } - List attbtList = new ArrayList<>(); - list.forEach(item -> { - RealAttributeVo realAttributeVo = new RealAttributeVo(); - // 设备重点属性处理 : 单条-item - Map real = map.get(item.getMonitorId()); - if(MapUtils.isEmpty(real)){ - realAttributeVo.setName(item.getAttributes()); - realAttributeVo.setType(item.getAttributeType()); - realAttributeVo.setRealId(item.getMonitorId()); - realAttributeVo.setQuality(-1); - realAttributeVo.setStatus(0); - realAttributeVo.setValue("0"); - realAttributeVo.setUnit(item.getUnit()); - attbtList.add(realAttributeVo); - return; - } - realAttributeVo = handleAttbt(item, real, alertList, faultList); - if (ObjectUtil.isEmpty(realAttributeVo)) { - return; - } - attbtList.add(realAttributeVo); - }); - device.setAttbtList(attbtList); - } - - /** - * 获取站点属性 - * @param stationEntityList - * @param item - */ - private void stationParam(List stationEntityList, RealStationVo item,List deptAll) { - if(CollectionUtil.isEmpty(stationEntityList)){ - return; - } - List filterList = stationEntityList.stream().filter(o->item.getStationCode().equals(o.getCode())).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(filterList)){ - return; - } - StationEntity station = filterList.get(0); - if(ObjectUtil.isEmpty(station)){ - return; - } - item.setStationName(station.getName()); - item.setWaterLevelMax(station.getLimitWaterLevel()); - item.setServerType(station.getServeType()); - item.setStationDeptId(station.getRefDept()); - // 排序 - List list = deptAll.stream().filter(o-> station.getRefDept().equals(o.getId())).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(list)){ - return; - } - item.setSort(list.get(0).getSort()); - } - - /** - * 设备参数设置 - * - * @param devices - * @param deviceClassifyMap - * @param deviceList - */ - private void getDeviceParam(List devices, Map> deviceClassifyMap, List deviceList) { - if (CollectionUtil.isEmpty(devices) || CollectionUtil.isEmpty(deviceList) || MapUtils.isEmpty(deviceClassifyMap)) { - return; - } - List faultList = deviceClassifyMap.get(HomePageConstant.FAULT); - List maintaintList = deviceClassifyMap.get(HomePageConstant.MAINTAIN); - List overhaultList = deviceClassifyMap.get(HomePageConstant.OVERHAUL); - List runtList = deviceClassifyMap.get(HomePageConstant.RUN); - List sparetList = deviceClassifyMap.get(HomePageConstant.SPARE); - deviceList.forEach(device -> { - if (StringUtil.isBlank(device.getDeviceCode())) { - device.setState(-1); - return; - } - List list = devices.stream().filter(o -> null != o.getId() && o.getId().toString().equals(device.getDeviceCode())).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(list)) { - device.setState(-1); - return; - } - String deviceCode = list.get(0).getEmCode(); - if (StringUtil.isBlank(deviceCode)) { - device.setState(-1); - return; - } - // 故障 - if (CollectionUtil.isNotEmpty(faultList) && faultList.contains(deviceCode)) { - device.setState(4); - // 保养 - } else if (CollectionUtil.isNotEmpty(maintaintList) && maintaintList.contains(deviceCode)) { - device.setState(3); - // 备用 - } else if (CollectionUtil.isNotEmpty(sparetList) && sparetList.contains(deviceCode)) { - device.setState(2); - // 运行 - } else if (CollectionUtil.isNotEmpty(runtList) && runtList.contains(deviceCode)) { - device.setState(1); - // 检修 - } else if (CollectionUtil.isNotEmpty(overhaultList) && overhaultList.contains(deviceCode)) { - device.setState(0); - // 未知 - } else { - device.setState(-1); - } - }); - } - - /** - * 设备单条重点属性处理 - * - * @param item - * @param real - * @return - */ - private RealAttributeVo handleAttbt(StationAttributeEntity item, Map real, - List alertList, List faultList) { - RealAttributeVo attest = new RealAttributeVo(); - this.setAttbtParam(attest, real); - attest.setRealId(item.getMonitorId()); - attest.setName(item.getAttributes()); - attest.setUnit(item.getUnit()); - attest.setType(item.getAttributeType()); - String value = Optional.ofNullable(attest.getValue()).orElse("-"); - // 正常状态 - attest.setStatus(ConfigStatus.ConfigStatusEnum.NORMAL.getStatus()); - int quality = Optional.ofNullable(attest.getQuality()).orElse(-1); - String time = Optional.ofNullable(attest.getTime()).orElse(""); - // 延时状态 :质量为空 && 时间为空 - if (-1 == quality && StringUtil.isEmpty(time)) { - attest.setStatus(ConfigStatus.ConfigStatusEnum.GRAY.getStatus()); - } - int type = item.getAttributeType(); - switch (type) { - case 1://遥测 - // 预警状态 :value值为"1" && quality值为0 - if ("1".equals(value) && 0 == quality) { - attest.setStatus(ConfigStatus.ConfigStatusEnum.RED.getStatus()); - } - break; - case 2://遥信 - signalyRemote(item, attest, quality, value, alertList); - //处理 - break; - default: - throw new IllegalStateException("Unexpected type: " + type); - } - // 故障信息设置 - accidentDetails(attest, faultList, value); - return attest; - } - - /** - * 设置重点属性参数 - * - * @param attest - * @param real - */ - private void setAttbtParam(RealAttributeVo attest, Map real) { - if (CollectionUtil.isEmpty(real)) { - return; - } - real.forEach((key, value) -> { - if (StringUtil.isBlank(value)) { - return; - } - switch (key) { - case "q": - attest.setQuality(Integer.parseInt(value)); - break; - case "realId": - attest.setRealId(value); - break; - case "value": - attest.setValue(Optional.ofNullable(value).orElse("-")); - break; - case "time": - attest.setTime(value); - break; - default: - break; - } - }); - } - - /** - * 故障信息设置 - * - * @param attest - * @param faultList - * @param value - */ - private void accidentDetails(RealAttributeVo attest, List faultList, String value) { - if (CollectionUtil.isEmpty(faultList) || "-".equals(value)) { - return; - } - List fault = faultList.stream().filter(o -> o.getRealId().equals(attest.getRealId())).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(fault)) { - return; - } - FdpFaultStatusVo fdpFaultStatusVo = fault.get(0); - // 黄色 - if (fdpFaultStatusVo.getValue() > greater_than_cache_final && fdpFaultStatusVo.getValue() < less_than_cache_final) { - attest.setStatus(ConfigStatus.ConfigStatusEnum.YELLOW.getStatus()); - // 橙色 - } else if (fdpFaultStatusVo.getValue() >= be_equa_cache_final) { - attest.setStatus(ConfigStatus.ConfigStatusEnum.ORANGE.getStatus()); - } - attest.setFdpRate(fdpFaultStatusVo.getValue()); - attest.setFdpFaultId(fdpFaultStatusVo.getFaultId()); - attest.setFdpMonitorId(fdpFaultStatusVo.getMonitorId()); - } - - /** - * 重点属性类型-遥信 :数据逻辑处理 - * - * @param attest - */ - private void signalyRemote(StationAttributeEntity item, RealAttributeVo attest, int quality, String strValue, List alertList) { - //需要所有值的数据不为null,并且满足条件才会进去添加数据返回id - if (null == item.getUpUpLimit() || null == item.getDownDownLimit() || null == item.getUpLimit() || null == item.getDownLimit()) { - return; - } - if (-1 == quality) { - return; - } - if (quality != 0) { - return; - } - if ("-".equals(strValue)) { - return; - } - double upup = item.getUpUpLimit(); - double lwlw = item.getDownDownLimit(); - double up = item.getUpLimit(); - double lw = item.getDownLimit(); - //查询出来已处理告警记录 - List handleList = alertList.stream().filter(o -> o.getStationId().equals(item.getStationId()) && o.getRealId().equals(attest.getRealId()) && o.getStatus() == 1).collect(Collectors.toList()); - //查询出来未处理告警记录 - List recordList = alertList.stream().filter(o -> o.getStationId().equals(item.getStationId()) && o.getRealId().equals(attest.getRealId()) && o.getStatus() == 0).collect(Collectors.toList()); - long past = 0L; - double value = Double.parseDouble(strValue); - if (value > upup || value < lwlw) { - if (CollectionUtil.isNotEmpty(handleList)) { - // 现在时间 - 处理时间 - past = System.currentTimeMillis() - handleList.get(0).getProcessTime().getTime(); - } - boolean isOverrun = ((CollectionUtil.isEmpty(handleList) && CollectionUtil.isEmpty(recordList)) || (past / 1000 / 60 > 30 && CollectionUtil.isEmpty(recordList))); - if (isOverrun) { - Long alertId = alertService.insertAlert(item.getStationId(), item.getMonitorId()); - attest.setId(alertId); - attest.setStatus(ConfigStatus.ConfigStatusEnum.YELLOW.getStatus()); - } else if (CollectionUtil.isNotEmpty(recordList)) { - StAlarmRecordEntity record = recordList.get(0); - attest.setId(record.getId()); - // 告警处理完成 - if (record.getProcessTime() != null && record.getStatus() == (byte) 1) { - attest.setStatus(ConfigStatus.ConfigStatusEnum.NORMAL.getStatus()); - // 告警未处理 - } else if (record.getProcessTime() == null && record.getStatus() == (byte) 0) { - attest.setStatus(ConfigStatus.ConfigStatusEnum.HAND_DELAY_STATUS.getStatus()); - } - } - } else if (value > up && value < upup || value < lw && value > lwlw) { - if (CollectionUtil.isNotEmpty(handleList)) { - // 现在时间 - 处理时间 - past = System.currentTimeMillis() - handleList.get(0).getProcessTime().getTime(); - } - boolean exist = ((CollectionUtil.isEmpty(handleList) && CollectionUtil.isEmpty(recordList)) || (past / 1000 / 60 > 30 && CollectionUtil.isEmpty(recordList))); - if (exist){ - Long alertId = alertService.insertAlert(item.getStationId(), item.getMonitorId()); - attest.setId(alertId); - attest.setStatus(ConfigStatus.ConfigStatusEnum.YELLOW.getStatus()); - // 存在告警记录 - } else if (CollectionUtil.isNotEmpty(recordList)) { - StAlarmRecordEntity record = recordList.get(0); - if (recordList.get(0).getStatus() == (byte) 0 && recordList.get(0).getCreateTime() != null) { - attest.setId(record.getId()); - attest.setStatus(ConfigStatus.ConfigStatusEnum.RED.getStatus()); - } else { - attest.setId(recordList.get(0).getId()); - attest.setStatus(ConfigStatus.ConfigStatusEnum.NORMAL.getStatus()); - } - } - } - } - - /** - * 设置站点状态 - * @param alarmList - * @param station - * @param key - */ - private void setStationStatus(List alarmList, RealStationVo station, String key) { - station.setStatus(0); - if(alarmList.contains(key)){ - station.setStatus(1); - } - } - - /** - * 获取所有告警记录 - * - * @return - */ - private List getFdpFaultAll() { - Object json = redisTemplate.opsForValue().get(fdp_fault_cache_final); - if (ObjectUtil.isEmpty(json)) { - return new ArrayList<>(); - } - return (List) json; - } - - /** - * map分割 - * - * @param - * @param - * @param chunkMap - * @return - */ - private List> mapChunk(Map chunkMap) { - if (chunkMap == null) { - return Lists.newArrayList(); - } - Set keySet = chunkMap.keySet(); - Iterator iterator = keySet.iterator(); - int i = 1; - List> total = new ArrayList<>(); - Map tem = new HashMap<>(); - while (iterator.hasNext()) { - k next = iterator.next(); - tem.put(next, chunkMap.get(next)); - if (i == 5) { - total.add(tem); - tem = new HashMap<>(); - i = 0; - } - i++; - } - if (!CollectionUtil.isEmpty(tem)) { - total.add(tem); - } - return total; - } - - /** - * 获取厂房监测点 - * @return - */ - private List getRealIdByWsCodeAndSign() { - List wsInfoList = workshopInfoService.list(); - if(CollectionUtil.isEmpty(wsInfoList)) { - return Lists.newArrayList(); - } - Function getAnalyzeCodePO = wsCode -> { - MultiAnalyzeCodePO multiAnalyzeCodePO = new MultiAnalyzeCodePO(); - multiAnalyzeCodePO.setDeviceCode(wsCode); - multiAnalyzeCodePO.setSignages(Lists.newArrayList(HomePageConstant.PV_JOINT_RELAY,HomePageConstant.PV_REACTIVE_POWER,HomePageConstant.PV_GENERATION_CAPACITY)); - return multiAnalyzeCodePO; - }; - List analyzeCodePOList = wsInfoList.stream().map(WorkshopInfoEntity::getNumber).map(getAnalyzeCodePO).collect(Collectors.toList()); - R> analyzeCodeBySignages = analyseDataSearchClient.getAnalyzeCodeBySignages(analyzeCodePOList); - return Optional.ofNullable(analyzeCodeBySignages).filter(r -> r.isSuccess()).map(R::getData).orElse(Lists.newArrayList()); - } - - /** - * 获取站点realId - * @param refDept - * @param eminfoAndEmParams - * @return - */ - private List getRealDeviceList(Long refDept, List eminfoAndEmParams) { - // 参数检查 - if(CollectionUtil.isEmpty(eminfoAndEmParams) || ObjectUtil.isEmpty(refDept)){ - return new ArrayList<>(); - } - // 有效设备 - List filters = eminfoAndEmParams.stream().filter(o-> o.getCreateDept().equals(refDept)).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(filters)){ - return new ArrayList<>(); - } - // 遍历设备 - List result = new ArrayList<>(); - for(EminfoAndEmParamVo device : filters){ - if(CollectionUtil.isEmpty(device.getPoint())){ - continue; - } - result.addAll(device.getPoint().values()); - } - return result; - } -} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/OtherServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/OtherServiceImpl.java deleted file mode 100644 index 202c396..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/OtherServiceImpl.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation.impl; - -import com.hnac.hzims.operational.fill.entity.OtherEntity; -import com.hnac.hzims.scheduled.mapper.operation.OtherMapper; -import com.hnac.hzims.scheduled.service.operation.OtherService; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springframework.stereotype.Service; - -/** - * @author ysj - */ -@Slf4j -@Service -@AllArgsConstructor -public class OtherServiceImpl extends BaseServiceImpl implements OtherService { - -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/OverDetailsServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/OverDetailsServiceImpl.java deleted file mode 100644 index dc69ec3..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/OverDetailsServiceImpl.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation.impl; - -import com.hnac.hzims.operational.fill.entity.OverDetailsEntity; -import com.hnac.hzims.scheduled.mapper.operation.OverDetailsMapper; -import com.hnac.hzims.scheduled.service.operation.OverDetailsService; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springframework.stereotype.Service; - -/** - * @author ysj - */ -@Slf4j -@Service -@AllArgsConstructor -public class OverDetailsServiceImpl extends BaseServiceImpl implements OverDetailsService { - -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/OverServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/OverServiceImpl.java deleted file mode 100644 index f629fc7..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/OverServiceImpl.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation.impl; - -import com.hnac.hzims.operational.fill.entity.OverEntity; -import com.hnac.hzims.scheduled.mapper.operation.OverMapper; -import com.hnac.hzims.scheduled.service.operation.OverService; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springframework.stereotype.Service; - -/** - * @author ysj - */ -@Slf4j -@Service -@AllArgsConstructor -public class OverServiceImpl extends BaseServiceImpl implements OverService { - -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/PhenomenonServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/PhenomenonServiceImpl.java deleted file mode 100644 index d993192..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/PhenomenonServiceImpl.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation.impl; - -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity; -import com.hnac.hzims.operational.main.vo.ShortagesVo; -import com.hnac.hzims.operational.report.vo.DutyDefectVO; -import com.hnac.hzims.scheduled.mapper.operation.PhenomenonMapper; -import com.hnac.hzims.scheduled.service.operation.PhenomenonService; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.Func; -import org.springframework.stereotype.Service; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.util.List; -import java.util.stream.Collectors; - -/** - * @author ysj - */ -@Service -@Slf4j -@AllArgsConstructor -public class PhenomenonServiceImpl extends BaseServiceImpl implements PhenomenonService { - - /** - * 时间范围内机构缺陷数据查询 - * @param start - * @param end - * @param areas - * @return - */ - @Override - public DutyDefectVO defect(String start, String end, List areas) { - DutyDefectVO defectVO = new DutyDefectVO(); - // 查询缺陷现象总数 - List operPhenomenonList = this.list(new LambdaQueryWrapper(){{ - ge(OperPhenomenonEntity::getCreateTime,start); - le(OperPhenomenonEntity::getCreateTime,end); - in(OperPhenomenonEntity::getCreateDept,areas); - }}); - if(CollectionUtil.isEmpty(operPhenomenonList)){ - defectVO.setDefectSum(0); - defectVO.setDefect(0); - return defectVO; - } - defectVO.setTotalIds(operPhenomenonList.stream().map(o->String.valueOf(o.getId())).collect(Collectors.joining(","))); - defectVO.setDefectSum(operPhenomenonList.size()); - // 消缺数 - List defectList = operPhenomenonList.stream().filter(o -> (Func.isNotEmpty(o.getIsDefect()) && o.getIsDefect() == 0) || "1".equals(o.getConclusionStatus())). - map(OperPhenomenonEntity::getId).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(defectList)){ - defectVO.setDefect(0); - return defectVO; - } - // 缺陷总数 - defectVO.setDefect(defectList.size()); - return defectVO; - } - - /** - * 查询当月机构缺陷数据 - * @param start - * @param end - * @param list - * @return - */ - @Override - public ShortagesVo defectMonth(String start, String end, List list) { - ShortagesVo shortagesVo = new ShortagesVo(); - LocalDate firstDay = LocalDate.now().withDayOfMonth(1); - LocalDateTime firstDateTime = LocalDateTime.of(firstDay, LocalTime.MIN); - LocalDateTime now = LocalDateTime.now(); - // 消缺总数 - List defects = this.list(new LambdaQueryWrapper(){{ - ge(OperPhenomenonEntity::getCreateTime,firstDateTime); - le(OperPhenomenonEntity::getCreateTime,now); - in(OperPhenomenonEntity::getCreateDept,list); - }}); - if(CollectionUtil.isEmpty(defects)){ - shortagesVo.setShortagesSum(0); - shortagesVo.setShortages(0); - return shortagesVo; - } - // 消缺数 - shortagesVo.setShortagesSum(defects.size()); - List shortagesList = defects.stream().filter(o -> (Func.isNotEmpty(o.getIsDefect()) && o.getIsDefect() == 0) || "1".equals(o.getConclusionStatus())). - map(OperPhenomenonEntity::getId).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(shortagesList)){ - shortagesVo.setShortages(0); - } - shortagesVo.setShortages(shortagesList.size()); - return shortagesVo; - } -} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/PowerServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/PowerServiceImpl.java deleted file mode 100644 index 265a8b7..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/PowerServiceImpl.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation.impl; - -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.hnac.hzims.operational.fill.entity.PowerEntity; -import com.hnac.hzims.operational.main.vo.PowerMonthVo; -import com.hnac.hzims.scheduled.mapper.operation.PowerMapper; -import com.hnac.hzims.scheduled.service.operation.PowerService; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.DateUtil; -import org.springframework.stereotype.Service; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - - -@Slf4j -@Service -@AllArgsConstructor -public class PowerServiceImpl extends BaseServiceImpl implements PowerService { - - - /** - * 根据时间、机构查询发电量 - * @param date 时间: 年 - yyyy/月 yyyy-mm/日 yyyy-mm-dd - * @param station 所属机构 - * @return - */ - @Override - public Double generate(String date, Long station) { - List powers = this.list(Wrappers.lambdaQuery() - .likeRight(PowerEntity::getMon,date) - .eq(PowerEntity::getCreateDept,station) - // 类型: 光伏 - .eq(PowerEntity::getType,1) - ); - if(CollectionUtil.isEmpty(powers)){ - return 0.0; - } - return powers.stream().mapToDouble(PowerEntity::getPowerMon).sum(); - } - - /** - * - * @param start 开始时间 : yyyy-mm - * @param end 结束时间 : yyyy-mm - * @param station 所属机构 - * @return - */ - @Override - public List generateThreeYear(String start, String end, Long station) { - List fills = this.list(Wrappers.lambdaQuery() - .between(PowerEntity::getMon,start,end) - .eq(PowerEntity::getCreateDept,station) - // 类型: 光伏 - .eq(PowerEntity::getType,1) - ); - if(CollectionUtil.isEmpty(fills)){ - return new ArrayList<>(); - - } - return fills.stream().map(fill->{ - PowerMonthVo mon = new PowerMonthVo(); - mon.setStrMonth(DateUtil.format(DateUtil.parse(fill.getMon(),"yyyy-MM"),DateUtil.PATTERN_DATE)); - if(Math.abs(fill.getPowerMon()) <= 0){ - mon.setPower(0f); - }else{ - mon.setPower(Float.parseFloat(fill.getPowerMon().toString())); - } - return mon; - }).collect(Collectors.toList()); - } - -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/RealTargetServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/RealTargetServiceImpl.java deleted file mode 100644 index a008be8..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/RealTargetServiceImpl.java +++ /dev/null @@ -1,1573 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation.impl; - -import com.alibaba.fastjson.JSONObject; -import com.alibaba.fastjson.TypeReference; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.hnac.hzims.EquipmentConstants; -import com.hnac.hzims.equipment.entity.EmParamEntity; -import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; -import com.hnac.hzims.operational.main.constant.HomePageConstant; -import com.hnac.hzims.operational.main.vo.*; -import com.hnac.hzims.operational.station.StationConstants; -import com.hnac.hzims.operational.station.entity.HzimsAnalyzeModelStationEntity; -import com.hnac.hzims.operational.station.entity.StationEntity; -import com.hnac.hzims.scheduled.service.equipment.DeviceParamService; -import com.hnac.hzims.scheduled.service.equipment.DeviceService; -import com.hnac.hzims.scheduled.service.operation.*; -import com.hnac.hzinfo.datasearch.PointData; -import com.hnac.hzinfo.datasearch.analyse.domain.FieldsData; -import com.hnac.hzinfo.datasearch.analyse.po.AnalyseCodeByAnalyseDataPO; -import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO; -import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeCodeBySignagesVO; -import com.hnac.hzinfo.datasearch.history.IHistoryDataSearchClient; -import com.hnac.hzinfo.datasearch.history.OriginalDataQuery; -import com.hnac.hzinfo.datasearch.real.po.RealDataSearchPO; -import com.hnac.hzinfo.sdk.analyse.po.MultiAnalyzeCodePO; -import com.hnac.hzinfo.sdk.core.response.HzPage; -import com.hnac.hzinfo.sdk.core.response.Result; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections4.MapUtils; -import org.springblade.core.log.exception.ServiceException; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.DateUtil; -import org.springblade.core.tool.utils.ObjectUtil; -import org.springblade.core.tool.utils.StringUtil; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Service; - -import java.math.BigDecimal; -import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -/** - * APP首页实现类 - * @author ysj - */ -@Service -@RequiredArgsConstructor -@Slf4j -public class RealTargetServiceImpl implements RealTargetService { - - private final UseService useService; - - private final DataService dataService; - - private final PowerService powerService; - - private final DeviceService deviceService; - - private final StationService stationService; - - private final GenerateService generateService; - - private final DeviceParamService deviceParamService; - - private final StationAttributeService attributeService; - - private final ModelStationService modelStationService; - - private final RedisTemplate redisTemplate; - - private final IHistoryDataSearchClient historyDataSearchClient; - - @Value("${hzims.equipment.emInfo.emInfoList}") - public String device_cache_cofig_final; - - @Value("${hzims.operation.realIdKey}") - public String real_id_cofig_final; - - private final static String recent_year_power_data = "hzims:operation:key:power:data"; - private final static String load_hydropower_unit_real_key = "hzims:operation:loadhydropowerunit:real:key"; - private final static String load_hydropower_unit_target_key = "hzims:operation:loadhydropowerunit:target:key"; - private final static String loadwaterpump_target_key = "hzims:operation:loadwaterpump:target:key"; - private final static String loadwaterpump_real_key = "hzims:operation:loadwaterpump:real:key"; - private final static String loadwater_level_key = "hzims:operation:loadwater:level:key"; - private final static String load_photovoltaic_real_key = "hzims:operation:photovoltaic:real:key"; - private final static String load_photovoltaic_target_key = "hzims:operation:photovoltaic:target:key"; - - - @Override - public void loadEmInfo() { - // 查询所有首页展示/状态非删除设备 - List devices = deviceService.device(); - // 查询所有设备(ct、pt、installedCapacity)配置参数 - List paramList = deviceParamService.params(); - // 获取设备监测点位:未配置监测点位不进行统计设备 - List multiAnalyzeCodePOList = devices.stream().map(o->{ - MultiAnalyzeCodePO multiAnalyzeCodePO = new MultiAnalyzeCodePO(); - multiAnalyzeCodePO.setDeviceCode(o.getEmCode()); - multiAnalyzeCodePO.setSignages(HomePageConstant.SIGNAGES); - return multiAnalyzeCodePO; - }).collect(Collectors.toList()); - // 切割 - int limit = countStep(multiAnalyzeCodePOList.size()); - List> lists = Stream.iterate(0, n -> n + 1).limit(limit).parallel().map(a -> multiAnalyzeCodePOList.stream().skip((long) a * 3).limit(3).parallel().collect(Collectors.toList())).collect(Collectors.toList()); - // 接收数据 - List analys = new ArrayList<>(); - lists.forEach(list->{ - List result = dataService.analyzeCodeBySignages(list); - if(CollectionUtil.isEmpty(result)){ - return; - } - analys.addAll(result); - }); - // 设备遍历 - devices.forEach(item->{ - item.setRideCount(1); - item.setInstalledCapacity(0.0); - List signages = analys.stream().filter(o-> item.getEmCode().equals(o.getDeviceCode()) && !StringUtil.isEmpty(o.getSignage()) && !StringUtil.isEmpty(o.getRealId())).collect(Collectors.toList()); - if(CollectionUtil.isNotEmpty(signages)){ - // list -> map - item.setPoint(signages.stream().collect(Collectors.toMap(AnalyzeCodeBySignagesVO::getSignage,AnalyzeCodeBySignagesVO::getRealId))); - } - // 寻找设备配置参数 - List itemParamList = paramList.stream().filter(o->item.getId().equals(o.getInfoId())).collect(Collectors.toList()); - if(CollectionUtil.isNotEmpty(itemParamList)){ - // 遍历设备配置参数 - for(EmParamEntity param : itemParamList){ - String param_name = param.getParamName(); - switch (param_name){ - case "ct": - item.setCt(Integer.valueOf(param.getParamValue())); - break; - case "pt": - item.setPt(Integer.valueOf(param.getParamValue())); - break; - case "installedCapacity": - item.setInstalledCapacity(Double.valueOf(param.getParamValue())); - break; - default: - break; - } - } - // 设置ct * pt - if(null != item.getCt() && null != item.getPt()){ - item.setRideCount(item.getCt() * item.getPt()); - } - } - }); - // 设置缓存 - redisTemplate.opsForValue().set(device_cache_cofig_final, JSONObject.toJSONString(devices.stream().filter(o-> Math.abs(o.getInstalledCapacity()) > 0 || MapUtils.isNotEmpty(o.getPoint())).collect(Collectors.toList()))); - } - - - /** - * 加载水电站机组实时数据 - * @param param - */ - @Override - public void loadHydropowerReal(String param) { - // 水电站站点 - List stations = stationService.list(Wrappers.lambdaQuery() - .eq(StationEntity::getType,HomePageConstant.HYDROPOWER) - ); - if(CollectionUtil.isEmpty(stations)){ - return; - } - // 水电站设备 - List devices = this.pumpDevices(stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())); - if(CollectionUtil.isEmpty(devices)){ - return; - } - // 实时数据 - Map map = this.getRealMap(); - // 单位 - Map unitMap = this.attributeService.PointUnit(); - // 实时数据 - List reals = devices.stream().map(device->{ - HydropowerUnitRealVo real = new HydropowerUnitRealVo(); - real.setDeptId(device.getCreateDept()); - real.setDeviceCode(device.getEmCode()); - real.setDeptName(device.getName()); - real.setDeviceName(device.getName()); - // 装机容量 - real.setInstalledCapacity(device.getInstalledCapacity()); - // 开关机状态 - real.setState(this.state(device,map)); - // 有功功率 - real.setActivePower(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_ACTIVE_POWER)); - // 无功功率 - real.setReactivePower(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_REACTIVE_POWER)); - // 功率因数 - real.setPowerFactor(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_POWERFACTOR)); - // 机组频率 - real.setFrequency(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_FREQUENCY)); - // 导叶开度 - real.setGuideOpen(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_GUIDEOPEN)); - // 定子电压 - real.setStatorVoltage(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_VOLTAGE)); - // 定子电流 - real.setStatorCurrent(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_CURRENT)); - // 单位设置 - this.setttingUnit(device,unitMap,real); - return real; - }).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(reals)){ - return; - } - redisTemplate.opsForValue().set(load_hydropower_unit_real_key,reals); - } - - /** - * 加载水电站机组指标数据 - * @param param - */ - @Override - public void loadHydropowerTarget(String param) { - // 水电站站点 - List stations = stationService.list(Wrappers.lambdaQuery() - //.eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) - .eq(StationEntity::getType,HomePageConstant.HYDROPOWER) - ); - if(CollectionUtil.isEmpty(stations)){ - return; - } - // 补充填补发电指标 - List targets = this.generteFill(stations); - // 水电站设备 - List devices = this.pumpDevices(stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())); - if(CollectionUtil.isNotEmpty(devices)){ - targets.addAll(devices.stream().map(device->{ - HydropowerUnitTargetVo target = new HydropowerUnitTargetVo(); - target.setDeptId(device.getCreateDept()); - target.setDeviceCode(device.getEmCode()); - target.setDeviceName(device.getName()); - target.setDeptName(device.getName()); - // 当年发电量 - target.setPowerYear(this.getGenerationPower(device,0)); - // 当月发电量 - target.setPowerMon(this.getGenerationPower(device,1)); - // 当日发电量 - target.setPowerDay(this.getGenerationPower(device,2)); - // 当天有功功率 - target.setActivePowerVoList(this.getLoadsByDay(device)); - // 30天发电量 - target.setGenerationPowerVoList(this.getGenerationPowerList(device)); - return target; - }).collect(Collectors.toList())); - } - // 站点指标数据为空 - if(CollectionUtil.isEmpty(targets)){ - return; - } - redisTemplate.opsForValue().set(load_hydropower_unit_target_key,targets); - } - - /** - * 水利-泵组实时加载 - * @param param - */ - @Override - public void loadWaterPumpReal(String param) { - // 水利站点 - List stations = stationService.list(Wrappers.lambdaQuery() - .eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) - .in(StationEntity::getType,HomePageConstant.waterList) - ); - if(CollectionUtil.isEmpty(stations)){ - return; - } - // 泵站设备 - List devices = this.pumpDevices(stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())); - if(CollectionUtil.isEmpty(devices)){ - return; - } - // 实时数据 - Map map = this.getRealMap(); - List list = devices.stream().map(device->{ - WaterPumpRealVo real = new WaterPumpRealVo(); - real.setDeptId(device.getCreateDept()); - real.setDeviceCode(device.getEmCode()); - real.setDeptName(device.getName()); - // 装机容量 - real.setInstalledCapacity(device.getInstalledCapacity()); - // 开机状态 - real.setState(this.pumpState(device,map)); - // 功率因数 - real.setPowerFactor(this.getSignageValue(device,map,HomePageConstant.POWER_FACTOR)); - // 有功功率 - real.setActivePower(this.floatValue(device,map,HomePageConstant.ACTIVE_POWER)); - // 无功功率 - real.setReactivePower(this.floatValue(device,map,HomePageConstant.REACTIVE_POWER)); - // 电压 - real.setVoltage(this.getSignageValue(device,map,HomePageConstant.VOLTAGE)); - // 电流 - real.setCurrent(this.getSignageValue(device,map,HomePageConstant.CURRENT)); - return real; - }).collect(Collectors.toList()); - redisTemplate.opsForValue().set(loadwaterpump_real_key,list); - } - - /** - * 水利-泵组指标加载 - * @param param - */ - @Override - public void loadWaterPumpTarget(String param) { - // 水利站点 - List stations = stationService.list(Wrappers.lambdaQuery() - .eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) - .in(StationEntity::getType,HomePageConstant.waterList) - ); - if(CollectionUtil.isEmpty(stations)){ - return; - } - // 泵站设备 - List devices = this.pumpDevices(stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())); - // 补充站点填报发电量 - List list = this.useFill(stations); - // 站点设备数据统计 - if(CollectionUtil.isNotEmpty(devices)){ - list.addAll(devices.stream().map(device->{ - WaterPumpTargetVo target = new WaterPumpTargetVo(); - target.setDeptId(device.getCreateDept()); - target.setDeviceCode(device.getEmCode()); - target.setDeptName(device.getName()); - // 当年用电量 - target.setUsrPowerYear(this.getUsrPowerYear(device)); - // 当月用电量 - target.setUsrPowerMon(this.getUsrPowerMon(device)); - // 当日用电量 - target.setUsrPowerDay(this.getUsrPowerDay(device)); - // 当日机组有功功率 - target.setActivePowerVoList(this.getActivePowerVoList(device)); - // 近30天用电量 - target.setUsrPowerVoList(this.getUsrPowerVoList(device)); - // 近3年用电量 - target.setUsrYearMap(this.getUsrYearMap(device)); - // 月运行次数、时长 - WaterRunVo runMon = this.getRunData(device,1); - target.setRunCountMon(runMon.getCount()); - target.setRunDurationMon(runMon.getHour()); - // 年运行次数、时长 - WaterRunVo runYear = this.getRunData(device,0); - target.setRunCountYear(runYear.getCount()); - target.setRunDurationYear(runYear.getHour()); - return target; - }).collect(Collectors.toList())); - } - redisTemplate.opsForValue().set(loadwaterpump_target_key,list); - } - - /** - * 水利-站点水位数据 - * @param param - */ - @Override - public void loadWaterLevel(String param) { - // 有效站点模型 - List modelList = getModelStationList(); - if(CollectionUtil.isEmpty(modelList)){ - return; - } - List list = new ArrayList<>(); - modelList.forEach(item -> { - WaterLevelVo waterLevelVo = new WaterLevelVo(); - waterLevelVo.setStationCode(item.getStationId()); - // 前水位 - double frontWaterLevel = this.getWaterLevel(item.getInstanceCode(),HomePageConstant.FRONT_WATER_LEVEL); - waterLevelVo.setFrontWaterLevel(frontWaterLevel); - // 后水位 - double rearWaterLevel = this.getWaterLevel(item.getInstanceCode(),HomePageConstant.REAR_WATER_LEVEL); - waterLevelVo.setRearWaterLevel(rearWaterLevel); - // 前水位当日曲线 - Map frontCurveMap = this.getWaterLevelMap(item.getInstanceCode(),HomePageConstant.FRONT_WATER_LEVEL); - waterLevelVo.setFrontCurveMap(frontCurveMap); - // 后水位当日曲线 - Map rearCurveMap = this.getWaterLevelMap(item.getInstanceCode(),HomePageConstant.REAR_WATER_LEVEL); - waterLevelVo.setRearCurveMap(rearCurveMap); - list.add(waterLevelVo); - }); - redisTemplate.opsForValue().set(loadwater_level_key,list); - } - - /** - * 光伏站-逆变器实时加载 - * - * @param param - */ - - @Override - public void loadPhotovoltaicReal(String param) { - // 查询设备 - List devices = this.getPhotovoltaicDevice(); - if (CollectionUtil.isEmpty(devices)) { - return; - } - // 取redis实时数据 - Map map = this.getRealMap(); - if (MapUtils.isEmpty(map)) { - return; - } - // redis缓存设备实时数据 - List history = (List) redisTemplate.opsForValue().get(load_photovoltaic_real_key); - // 设备实时数据 - List list = devices.stream().map(device -> { - PhotovoltaicRealVo real = new PhotovoltaicRealVo(); - real.setDeptId(device.getCreateDept()); - real.setDeviceCode(device.getEmCode()); - real.setDeviceName(device.getName()); - real.setState(this.getPhotovoltaicState(device, map)); - // 容量 - real.setCapacity(device.getInstalledCapacity()); - // 发电量 - real.setGenerate(this.getSignageValue(device, map, HomePageConstant.PV_GENERATION_CAPACITY)); - // 功率 - real.setLoad(this.getSignageValue(device, map, HomePageConstant.PV_LOAD)); - // 交流电压 - real.setVoltage(this.getSignageValue(device, map, HomePageConstant.PV_VOLTAGE)); - // 交流电流 - real.setCurrent(this.getSignageValue(device, map, HomePageConstant.PV_CURRENT)); - // 交流电压2 - real.setVoltage_two(this.getSignageValue(device, map, HomePageConstant.PV_VOLTAGE_TWO)); - // 交流电流2 - real.setCurrent_two(this.getSignageValue(device, map, HomePageConstant.PV_CURRENT_TWO)); - // 交流电压3 - real.setVoltage_three(this.getSignageValue(device, map, HomePageConstant.PV_VOLTAGE_THREE)); - // 交流电流3 - real.setCurrent_three(this.getSignageValue(device, map, HomePageConstant.PV_CURRENT_THREE)); - // 直流电流1 - real.setDirect_one(this.getSignageValue(device, map, HomePageConstant.DIRECT_ONE)); - // 直流电流2 - real.setDirect_two(this.getSignageValue(device, map, HomePageConstant.DIRECT_TWO)); - // 直流电流3 - real.setDirect_three(this.getSignageValue(device, map, HomePageConstant.DIRECT_THREE)); - // 直流电流4 - real.setDirect_four(this.getSignageValue(device, map, HomePageConstant.DIRECT_FOUR)); - // 直流电流5 - real.setDirect_five(this.getSignageValue(device, map, HomePageConstant.DIRECT_FIVE)); - // 直流电流6 - real.setDirect_six(this.getSignageValue(device, map, HomePageConstant.DIRECT_SIX)); - // 直流电流7 - real.setDirect_seven(this.getSignageValue(device, map, HomePageConstant.DIRECT_SEVEN)); - // 直流电流8 - real.setDirect_eight(this.getSignageValue(device, map, HomePageConstant.DIRECT_EIGHT)); - // 直流电流9 - real.setDirect_nine(this.getSignageValue(device, map, HomePageConstant.DIRECT_NINE)); - // 直流电流10 - real.setDirect_ten(this.getSignageValue(device, map, HomePageConstant.DIRECT_TEN)); - // 直流电流11 - real.setDirect_eleven(this.getSignageValue(device, map, HomePageConstant.DIRECT_ELEVEN)); - // 直流电流12 - real.setDirect_twelve(this.getSignageValue(device, map, HomePageConstant.DIRECT_TWELVE)); - // 直流电压1 - real.setDc_voltage_one(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_ONE)); - // 直流电压2 - real.setDc_voltage_two(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_TWO)); - // 直流电压3 - real.setDc_voltage_three(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_THREE)); - // 直流电压4 - real.setDc_voltage_four(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_FOUR)); - // 直流电压5 - real.setDc_voltage_five(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_FIVE)); - // 直流电压6 - real.setDc_voltage_six(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_SIX)); - // 直流电压7 - real.setDc_voltage_seven(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_SEVEN)); - // 直流电压8 - real.setDc_voltage_eight(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_EIGHT)); - // 直流电压9 - real.setDc_voltage_nine(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_NINE)); - // 直流电压10 - real.setDc_voltage_ten(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_TEN)); - // 直流电压11 - real.setDc_voltage_eleven(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_ELEVEN)); - // 直流电压12 - real.setDc_voltage_twelve(this.getSignageValue(device, map, HomePageConstant.DC_VOLTAGE_TWELVE)); - // 串流电流1 - real.setDirect_one(this.getSignageValue(device, map, HomePageConstant.DIRECT_ONE)); - // 串流电流2 - real.setSeries_two(this.getSignageValue(device, map, HomePageConstant.SERIES_TWO)); - // 串流电流3 - real.setSeries_three(this.getSignageValue(device, map, HomePageConstant.SERIES_THREE)); - // 串流电流4 - real.setSeries_four(this.getSignageValue(device, map, HomePageConstant.SERIES_FOUR)); - // 串流电流5 - real.setSeries_five(this.getSignageValue(device, map, HomePageConstant.SERIES_FIVE)); - // 串流电流6 - real.setSeries_six(this.getSignageValue(device, map, HomePageConstant.SERIES_SIX)); - // 串流电流7 - real.setSeries_seven(this.getSignageValue(device, map, HomePageConstant.SERIES_SEVEN)); - // 串流电流8 - real.setSeries_eight(this.getSignageValue(device, map, HomePageConstant.SERIES_EIGHT)); - // 串流电流9 - real.setSeries_nine(this.getSignageValue(device, map, HomePageConstant.SERIES_NINE)); - // 串流电流10 - real.setSeries_ten(this.getSignageValue(device, map, HomePageConstant.SERIES_TEN)); - // 串流电流11 - real.setSeries_eleven(this.getSignageValue(device, map, HomePageConstant.SERIES_ELEVEN)); - // 串流电流12 - real.setSeries_twelve(this.getSignageValue(device, map, HomePageConstant.SERIES_TWELVE)); - // 串流电压1 - real.setSe_voltage_one(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_ONE)); - // 串流电压2 - real.setSe_voltage_two(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_TWO)); - // 串流电压3 - real.setSe_voltage_three(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_THREE)); - // 串流电压4 - real.setSe_voltage_four(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_FOUR)); - // 串流电压5 - real.setSe_voltage_five(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_FIVE)); - // 串流电压6 - real.setSe_voltage_six(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_SIX)); - // 串流电压7 - real.setSe_voltage_seven(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_SEVEN)); - // 串流电压8 - real.setSe_voltage_eight(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_EIGHT)); - // 串流电压9 - real.setSe_voltage_nine(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_NINE)); - // 串流电压10 - real.setSe_voltage_ten(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_TEN)); - // 串流电压11 - real.setSe_voltage_eleven(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_ELEVEN)); - // 串流电压12 - real.setSe_voltage_twelve(this.getSignageValue(device, map, HomePageConstant.SE_VOLTAGE_TWELVE)); - // 上次功率 - real.setLastLoad(this.getLastLoad(device, history)); - return real; - }).collect(Collectors.toList()); - // 存储redis - redisTemplate.opsForValue().set(load_photovoltaic_real_key, list); - } - - - - /** - * 光伏站-逆变器指标加载 - * - * @param param - */ - @Override - public void loadPhotovoltaicTarget(String param) { - // 有效设备 - List devices = this.getPhotovoltaicDevice(); - if (CollectionUtil.isEmpty(devices)) { - return; - } - List list = new ArrayList<>(); - // 接入站点设备统计 - devices.forEach(device -> { - PhotovoltaicTargetVo target = new PhotovoltaicTargetVo(); - target.setDeptId(device.getCreateDept()); - target.setDeviceCode(device.getEmCode()); - target.setDeviceName(device.getName()); - target.setDeptName(device.getName()); - // 当日运行时长 - target.setRunHours(this.runHours(device.getPoint().get(HomePageConstant.PV_JOINT_RELAY))); - // 年发电量 - target.setGenerationYear((double) this.sumValueByTime(device.getEmCode(), device.getRideCount(), "0")); - // 月发电量 - target.setGenerationMon((double) this.sumValueByTime(device.getEmCode(), device.getRideCount(), "1")); - // 日发电量 - target.setGenerationDay((double) this.sumValueByTime(device.getEmCode(), device.getRideCount(), "2")); - // 昨日发电量 - target.setGenerationYesterday((double) this.sumValueByTime(device.getEmCode(), device.getRideCount(), "3")); - // 收益 - target.setIncome(target.getGenerationDay() * 0.34); - // 节约标准煤 - target.setTec(target.getGenerationMon() * 0.0001229); - // 二氧化碳减排 - target.setCo2(target.getGenerationMon() * 0.000997); - // 减少森林砍伐 - target.setDeforest(target.getGenerationMon() * 0.000553); - // 当天有功功率 - target.setActivePowerVoList(this.photovoltaicLoadsByDay(device)); - // 30天发电量 - target.setGenerationPowerVoList(this.getGenerateByMon(device)); - list.add(target); - }); - // 补充站点填报发电量 - List stations = stationService.list(Wrappers.lambdaQuery() - .eq(StationEntity::getType, HomePageConstant.PHOTOVOLTAIC) - .eq(StationEntity::getServeType, HomePageConstant.HYDROPOWER_SERVETYPE) - ); - if(CollectionUtil.isNotEmpty(stations)){ - list.addAll(this.generateFill(stations)); - } - redisTemplate.opsForValue().set(load_photovoltaic_target_key, list); - } - - - /** - * 当日用电量 - * @param device - * @return - */ - private float getUsrPowerDay(EminfoAndEmParamVo device) { - String time = DateUtil.format(new Date(),DateUtil.PATTERN_DATE); - // 当日用电量 - return dataService.periodTargetFloat(time + " 00:00:00",time + " 23:59:59",5,3,device.getEmCode(),device.getRideCount(),HomePageConstant.ELECTRICITY_CONSUMPTION); - - } - - /** - * 当月用电量 - * @param device - * @return - */ - private float getUsrPowerMon(EminfoAndEmParamVo device) { - String start = DateUtil.format(new Date(), "yyyy-MM") + "-01 00:00:00"; - String end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); - // 当月用电量 - return dataService.periodTargetFloat(start,end,5,5,device.getEmCode(),device.getRideCount(),HomePageConstant.ELECTRICITY_CONSUMPTION); - } - - /** - * 当年用电量 - * @param device - * @return - */ - private float getUsrPowerYear(EminfoAndEmParamVo device) { - Calendar calendar = Calendar.getInstance(); - String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); - calendar.setTime(new Date()); - calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); - calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); - String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); - // 当年用电量 - return dataService.periodTargetFloat(start,end,5,6,device.getEmCode(),device.getRideCount(),HomePageConstant.ELECTRICITY_CONSUMPTION); - } - - /** - * 当日机组有功功率 - * @param device - * @return - */ - public List getActivePowerVoList(EminfoAndEmParamVo device) { - String startTime = DateUtil.format(new Date(), "yyyy-MM-dd 00:00:00"); - String endTime = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"); - List datas = dataService.periodTargetData(startTime,endTime,2,6,device.getEmCode(),HomePageConstant.ACTIVE_POWER); - if(CollectionUtil.isEmpty(datas)){ - return new ArrayList<>(); - } - return datas.stream().map(data->{ - ActivePowerVo active = new ActivePowerVo(); - Date dateTime = DateUtil.parse(data.getTs(), "yyyy-MM-dd HH:mm:ss.s"); - active.setHour(dateTime.getHours()); - if (StringUtil.isBlank(data.getVal())) { - active.setActivePower("0"); - }else { - active.setActivePower(data.getVal()); - } - return active; - }).collect(Collectors.toList()); - } - - /** - * 近30天用电量 - * @param device - * @return - */ - private List getUsrPowerVoList(EminfoAndEmParamVo device) { - String start = DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00"; - Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.DAY_OF_MONTH,-29); - String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); - List records = dataService.periodTargetData(start,end,5,EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(),device.getEmCode(),HomePageConstant.ELECTRICITY_CONSUMPTION); - if(CollectionUtil.isEmpty(records)){ - return new ArrayList<>(); - } - return records.stream().map(record -> { - UsrPowerVo usr = new UsrPowerVo(); - Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); - usr.setDate(DateUtil.format(time,DateUtil.PATTERN_DATE)); - usr.setUsrPower(Float.valueOf(Optional.ofNullable(record.getVal()).orElse("0"))); - return usr; - }).collect(Collectors.toList()); - } - - /** - * 近3年发电量 - * - * @param device - * @return - */ - private Map getUsrYearMap(EminfoAndEmParamVo device) { - // 开始时间 - Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH) + 12); - calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); - String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; - // 结束日期 - calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - 3); - calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); - String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; - // 查询数据 - List records = dataService.periodTargetData(start,end,5,5,device.getEmCode(),HomePageConstant.ELECTRICITY_CONSUMPTION); - if(CollectionUtil.isEmpty(records)){ - return new HashMap<>(); - } - return records.stream().map(record -> { - PowerMonthVo generate = new PowerMonthVo(); - Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); - generate.setStrMonth(DateUtil.format(time, DateUtil.PATTERN_DATE)); - generate.setPower(Float.parseFloat(Optional.ofNullable(record.getVal()).orElse("0")) * device.getRideCount()); - return generate; - }).collect(Collectors.toMap(PowerMonthVo::getStrMonth,PowerMonthVo::getPower)); - } - - /** - * 获取运行数据 - * @param device - * @param type - * @return - */ - private WaterRunVo getRunData(EminfoAndEmParamVo device, int type) { - // 默认返回运行数据 - WaterRunVo waterRunVo = new WaterRunVo(); - waterRunVo.setCount(0); - waterRunVo.setHour(0.0); - Map point = device.getPoint(); - if(MapUtils.isEmpty(point)){ - return waterRunVo; - } - // 监测点 - String realId = point.get(HomePageConstant.SWITCH_ON_OFF); - if(StringUtil.isBlank(realId)){ - return waterRunVo; - } - // 确定查询时间范围: 年、月 - Date startDate,endDate; - Calendar calendar = Calendar.getInstance(); - calendar.setTime(new Date()); - switch (type){ - case 0: - endDate = calendar.getTime(); - calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); - calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); - startDate = calendar.getTime(); - break; - case 1: - endDate = calendar.getTime(); - calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); - calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); - calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); - calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); - startDate = calendar.getTime(); - break; - default: - throw new IllegalStateException("Unexpected value: " + type); - } - return this.getRunConvertData(realId,startDate,endDate,waterRunVo); - } - - /** - * 获取时间范围内开机次数、运行时长 - * @param realId - * @param startDate - * @param endDate - * @param waterRunVo - * @return - */ - private WaterRunVo getRunConvertData(String realId, Date startDate, Date endDate, WaterRunVo waterRunVo) { - OriginalDataQuery originalDataQuery = new OriginalDataQuery(); - originalDataQuery.setRealId(realId); - originalDataQuery.setBeginTime(startDate); - originalDataQuery.setEndTime(endDate); - originalDataQuery.setLimit(100000); - originalDataQuery.setPage(1); - // 查询时间范围开关机监测点历史数据 - Result> R = historyDataSearchClient.getOriginalDataByRealIds(originalDataQuery); - if(!R.isSuccess() || ObjectUtil.isEmpty(R.getData())){ - return waterRunVo; - } - // 过滤相邻开关机状态相同数据 - List result = this.getFilterList(R.getData().getRecords()); - if(CollectionUtil.isEmpty(result)){ - return waterRunVo; - } - // 开机次数 - int count = (int) result.stream().filter(o->HomePageConstant.OFF.equals(o.getValue())).count(); - waterRunVo.setCount(count); - // 开机运行时长 - long time = this.getRunTime(result,startDate,endDate); - waterRunVo.setHour(BigDecimal.valueOf(time / (1000 * 60 * 60.00)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); - return waterRunVo; - } - - /** - * 过滤相邻开关机状态相同数据 - * @param list - * @return - */ - private List getFilterList(List list) { - if(CollectionUtil.isEmpty(list)){ - return null; - } - List result = new ArrayList<>(); - // 遍历数据 - for(int i = 0; i< list.size() ; i++){ - // 第一个数据保存下来 - if(i == 0){ - result.add(list.get(i)); - continue; - } - // 遍历数据状态 - String value = list.get(i).getValue(); - if(StringUtil.isBlank(value)){ - continue; - } - // 上一条数据状态 - String up_value = list.get(i-1).getValue(); - if(value.equals(up_value)){ - continue; - } - result.add(list.get(i)); - } - return result; - } - - /** - * 获取运行时长 - * @param result - * @return - */ - private long getRunTime(List result,Date startDate,Date endDate) { - if(result.size() == 1){ - // 一直开机 - if(HomePageConstant.OFF.equals(result.get(0).getValue())){ - return endDate.getTime() - startDate.getTime(); - } - // 一直关机 - return 0; - } - long time=0; - // 遍历累计开机时长 - for(int i = 0; i< result.size() ; i++){ - // 记录为开机状态 就计算到下次关机的时间差 - if(HomePageConstant.ON.equals(result.get(i).getValue())){ - continue; - } - Date endTime,startTime = DateUtil.parse(result.get(i).getTime(), DateUtil.PATTERN_DATETIME); - // 遍历至最后一条数据,累计至当前时间 - if(i == result.size() - 1){ - endTime = endDate; - } - else { - endTime = DateUtil.parse(result.get(i+1).getTime(), DateUtil.PATTERN_DATETIME); - } - time += endTime.getTime() - startTime.getTime(); - } - return time; - } - - /** - * 获取填报用电量 - * @param stations - * @return - */ - private List useFill(List stations) { - Calendar calendar = Calendar.getInstance(); - String day = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); - String mon = DateUtil.format(calendar.getTime(),"yyyy-MM"); - String year = String.valueOf(calendar.get(Calendar.YEAR)); - return stations.stream().map(station ->{ - WaterPumpTargetVo target = new WaterPumpTargetVo(); - target.setDeptId(station.getRefDept()); - target.setDeptName(station.getName()); - // 月运行次数、时长 - target.setRunCountMon(0); - target.setRunDurationMon(0.0); - // 年运行次数、时长 - target.setRunCountYear(0); - target.setRunDurationYear(0.0); - // 当年用电量 - target.setUsrPowerYear(useService.use(year,station.getCode())); - // 当月用电量 - target.setUsrPowerMon(useService.use(mon,station.getCode())); - // 当日用电量 - target.setUsrPowerDay(useService.use(day,station.getCode())); - if(StationConstants.DATA_ORIGIN_FILL.equals(station.getDataOrigin())){ - // 30天用电量 - target.setUsrPowerVoList(useService.use30Day(day,station.getCode())); - } - // 近3年用电量 - target.setUsrYearMap(this.useThreeYear(station.getCode())); - return target; - }).collect(Collectors.toList()); - } - - /** - * 获取水位实时数据 - * @param instanceCode - * @param signage - * @return - */ - private double getWaterLevel(String instanceCode, String signage) { - RealDataSearchPO realData = new RealDataSearchPO(); - realData.setAnalyzeCode(instanceCode); - List signages = Collections.singletonList(signage); - realData.setSignages(signages); - // 调用fegin接口查询实时数据 - List fields = dataService.getRealDataByAnalyzeCode(instanceCode,signages); - if(CollectionUtil.isEmpty(fields)){ - return 0.0; - } - // 时间限制 - String time = fields.get(0).getTime(); - if(StringUtil.isEmpty(time) || "-".equals(time)){ - return 0.0; - } - Date date = DateUtil.parse(time, "yyyy-MM-dd HH:mm:ss.sss"); - if(System.currentTimeMillis() - date.getTime() > 30 * 60 * 1000L){ - return 0.0; - } - return Double.parseDouble(fields.get(0).getValue()); - } - - /** - * 获取水位当年数据 - * @param instanceCode - * @param signage - * @return - */ - private Map getWaterLevelMap(String instanceCode, String signage) { - String beginTime = DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00"; - String endTime = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); - AnalyseCodeByAnalyseDataPO po = new AnalyseCodeByAnalyseDataPO(); - List datas = dataService.periodTargetData(beginTime, endTime,2, 6,instanceCode,signage); - if(CollectionUtil.isEmpty(datas)){ - return new HashMap<>(); - } - return datas.stream().collect(Collectors.toMap( - key-> { - Date dateTime = DateUtil.parse(key.getTs(), "yyyy-MM-dd HH:mm:ss.s"); - return dateTime.getHours(); - }, - value -> { - if(StringUtil.isBlank(value.getVal())){ - return "0"; - } - return value.getVal(); - }) - ); - } - - /** - * 填报近3年发电量 - * @param station - * @return - */ - private Map useThreeYear(String station) { - // 开始时间 - Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH) + 12); - calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); - String end = DateUtil.format(calendar.getTime(),"yyyy-MM"); - // 结束日期 - calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - 3); - calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); - String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); - return useService.generateThreeYear(start,end,station); - } - - - /** - * 获取有效站点模型 - * @return - */ - private List getModelStationList() { - // 水利站点(All) - List stations = stationService.list(new LambdaQueryWrapper() {{ - eq(StationEntity::getServeType, HomePageConstant.HYDROPOWER_SERVETYPE); - }}); - if(CollectionUtil.isEmpty(stations)){ - return new ArrayList<>(); - } - // 站点code集合 - List codes = stations.stream().map(StationEntity::getCode).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(codes)){ - return new ArrayList<>(); - } - // 查询站点模型列表 - List list = modelStationService.list(new LambdaQueryWrapper() {{ - in(HzimsAnalyzeModelStationEntity::getStationId, codes); - }}); - if(CollectionUtil.isEmpty(list)){ - return new ArrayList<>(); - } - return list; - } - - /** - * 获取开机状态 - * @param device - * @return - */ - private int pumpState(EminfoAndEmParamVo device,Map map) { - // 获取开关机监测点实时数据 - double value = this.getSignageValue(device,map,HomePageConstant.SWITCH_ON_OFF); - // 开机状态 - if (Math.abs(value) <= 0) { - return 0; - } - return 1; - } - - /** - * 有功功率 - * @param device - * @return - */ - private float floatValue(EminfoAndEmParamVo device,Map map,String target) { - // 获取有功功率监测点实时数据 - double value = this.getSignageValue(device,map,target); - // 转换float - return Float.parseFloat(String.valueOf(value)); - } - - /** - * 设备状态 - * @param device - * @param map - * @return - */ - private Boolean state(EminfoAndEmParamVo device, Map map) { - if(Math.abs(this.getSignageValue(device,map,HomePageConstant.JOINT_RELAY)) > 0){ - return true; - } - return Math.abs(this.getSignageValue(device, map, HomePageConstant.ACTIVE_POWER)) > 0; - } - - /** - * 近年发电量数据 - * - * @param param 时间 - * @param serveType 站点类型 - * @param year 近几年 - */ - @Override - public void loadPowerData(String param, List types, Integer serveType, int year) { - // 站点查询 - List stationList = stationService.list(new LambdaQueryWrapper() {{ - if (ObjectUtil.isNotEmpty(serveType)) { - eq(StationEntity::getServeType, serveType); - } - if (CollectionUtil.isNotEmpty(types)) { - in(StationEntity::getType, types); - } - }}); - // 设备信息 - List devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(), new TypeReference>() { - }); - // 开始时间 - Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH) + 12); - calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); - String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; - // 结束日期 - calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - year); - calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); - String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; - // 存储数据map :<站点id,<月份,发电量>> - Map> powerMap = new HashMap<>(); - stationList.forEach(station -> { - // 站点设备集合 - List stationDevices = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); - log.error("load_power_data station :" + station.getCode() + "==== device :" + stationDevices ); - Map generateMap = this.getGenerateYear(station,stationDevices,start,end); - if(MapUtils.isEmpty(generateMap)){ - return; - } - powerMap.put(station.getId(),generateMap); - }); - redisTemplate.opsForValue().set(recent_year_power_data, powerMap); - } - - - /** - * 当天有功功率 - * @param device - * @return - */ - private List getLoadsByDay(EminfoAndEmParamVo device) { - String start = DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00"; - String end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); - List records = dataService.periodTargetData(start, end, 3, 2, device.getEmCode(), HomePageConstant.PV_LOAD); - if (CollectionUtil.isEmpty(records)) { - return new ArrayList<>(); - } - return records.stream().map(record -> { - ActivePowerVo load = new ActivePowerVo(); - Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); - load.setHour(time.getHours()); - load.setActivePower(Optional.ofNullable(record.getVal()).orElse("0")); - return load; - }).sorted(Comparator.comparing(ActivePowerVo::getHour)).collect(Collectors.toList()); - } - - /** - * 获取年发电量 - * @param devices - * @param start - * @param end - * @return - */ - private Map getGenerateYear(StationEntity station,List devices, String start, String end) { - List datas = new ArrayList<>(); - // 设备采集发电量 - if(CollectionUtil.isNotEmpty(devices)){ - devices.forEach(device->{ - List records = dataService.periodTargetData(start,end,5,5,device.getEmCode(),HomePageConstant.HYDROPOWER_GENERATE_POWER); - if(CollectionUtil.isEmpty(records)){ - return; - } - datas.addAll(records.stream().map(record -> { - PowerMonthVo generate = new PowerMonthVo(); - Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); - generate.setStrMonth(DateUtil.format(time,DateUtil.PATTERN_DATE)); - generate.setPower(Float.parseFloat(Optional.ofNullable(record.getVal()).orElse("0")) * device.getRideCount()); - return generate; - }).collect(Collectors.toList())); - }); - } - // 补充填报数据 - datas.addAll(this.generateFill(station,start,end)); - if(CollectionUtil.isEmpty(datas)){ - return null; - } - return datas.stream().collect(Collectors.toMap(PowerMonthVo::getStrMonth, PowerMonthVo::getPower, Float::sum)); - } - - - /** - * 获取填报用电量 - * @param stations - * @return - */ - private List generteFill(List stations) { - Calendar calendar = Calendar.getInstance(); - String day = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); - String mon = DateUtil.format(calendar.getTime(),"yyyy-MM"); - String year = String.valueOf(calendar.get(Calendar.YEAR)); - return stations.stream().map(station ->{ - HydropowerUnitTargetVo target = new HydropowerUnitTargetVo(); - target.setDeptId(station.getRefDept()); - target.setDeptName(station.getName()); - // 当年发电量 - target.setPowerYear(generateService.generate(year,station.getCode())); - // 当月发电量 - target.setPowerMon(generateService.generate(mon,station.getCode())); - // 当日发电量 - target.setPowerDay(generateService.generate(day,station.getCode())); - // 30天发电量 - target.setGenerationPowerVoList(generateService.generate30Day(day,station.getCode())); - return target; - }).collect(Collectors.toList()); - } - - - /** - * 补充填报数据 - * @param station - * @param start - * @param end - */ - private List generateFill(StationEntity station, String start, String end) { - start = DateUtil.format(DateUtil.parse(start,DateUtil.PATTERN_DATETIME),"yyyy-MM"); - end = DateUtil.format(DateUtil.parse(end,DateUtil.PATTERN_DATETIME),"yyyy-MM"); - // 光伏 - if(HomePageConstant.PHOTOVOLTAIC.equals(station.getType())){ - return powerService.generateThreeYear(start,end,station.getRefDept()); - } - // 水电 - return generateService.generateThreeYear(start,end,station.getCode()); - } - - /** - * 获取开机状态 - * - * @param device - * @return - */ - private int getPhotovoltaicState(EminfoAndEmParamVo device, Map map) { - // 获取开关机监测点实时数据 - double value = this.getSignageValue(device, map, HomePageConstant.PV_JOINT_RELAY); - // 开机状态 - if (Math.abs(value) <= 0) { - return 0; - } - return 1; - } - - /** - * 获取上一次功率 - * - * @param device - * @param history - * @return - */ - private Double getLastLoad(EminfoAndEmParamVo device, List history) { - if (CollectionUtil.isEmpty(history)) { - return 0.0; - } - List historyDevice = history.stream().filter(o -> o.getDeviceCode().equals(device.getEmCode())).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(historyDevice)) { - return 0.0; - } - return historyDevice.get(0).getLoad(); - } - - /** - * 获取光伏设备 - * - * @return - */ - private List getPhotovoltaicDevice() { - // 光伏站点 - List stations = stationService.list(Wrappers.lambdaQuery() - .eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) - .eq(StationEntity::getType,HomePageConstant.PHOTOVOLTAIC) - ); - if (CollectionUtil.isEmpty(stations)) { - return new ArrayList<>(); - } - // 设备 - List devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(), new TypeReference>() { - }); - if (CollectionUtil.isEmpty(devices)) { - return new ArrayList<>(); - } - return devices.stream().filter(device -> - stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(device.getCreateDept()) - ).collect(Collectors.toList()); - } - - /** - * 当天运行时长 - * - * @param realId - * @return - */ - private Double runHours(String realId) { - Calendar calendar = Calendar.getInstance(); - Date end = calendar.getTime(); - calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); - calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); - calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); - Date start = calendar.getTime(); - OriginalDataQuery originalDataQuery = new OriginalDataQuery(); - originalDataQuery.setRealId(realId); - originalDataQuery.setBeginTime(start); - originalDataQuery.setEndTime(end); - originalDataQuery.setLimit(100000); - originalDataQuery.setPage(1); - // 查询时间范围开关机监测点历史数据 - Result> R = historyDataSearchClient.getOriginalDataByRealIds(originalDataQuery); - if (!R.isSuccess() || ObjectUtil.isEmpty(R.getData())) { - return 0.0; - } - // 过滤相邻开关机状态相同数据 - List result = this.getFilterList(R.getData().getRecords()); - if (CollectionUtil.isEmpty(result)) { - return 0.0; - } - // 开机运行时长 - long time = this.getRunTime(result, start, end); - return BigDecimal.valueOf(time / (1000 * 60 * 60.00)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - } - - /** - * 根据事件查询数据值 - * - * @param deviceCode - * @param rideCount - * @param type - * @return - */ - private float sumValueByTime(String deviceCode, int rideCount, String type) { - Calendar calendar = Calendar.getInstance(); - String start, end; - int cycleType = 3; - switch (type) { - //年 - case "0": - calendar.add(Calendar.HOUR_OF_DAY, +1); - end = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME); - calendar.setTime(new Date()); - calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); - calendar.add(Calendar.DAY_OF_MONTH, -calendar.get(Calendar.DATE) + 1); - calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); - calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); - calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); - start = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME); - cycleType = 6; - break; - //月 - case "1": - start = DateUtil.format(new Date(), "yyyy-MM") + "-01 00:00:00"; - end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); - cycleType = 5; - break; - //日 - case "2": - start = DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00"; - end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); - break; - //昨日 - case "3": - calendar.add(Calendar.DAY_OF_MONTH, -1); - calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); - calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); - calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); - start = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME); - end = DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00"; - break; - default: - throw new ServiceException("无效查询类型!"); - } - return dataService.periodTargetFloat(start, end, 5, cycleType, deviceCode, rideCount, HomePageConstant.PV_GENERATION_CAPACITY); - } - - /** - * 当天有功功率 - * - * @param device - * @return - */ - private List photovoltaicLoadsByDay(EminfoAndEmParamVo device) { - String start = DateUtil.format(new Date(), DateUtil.PATTERN_DATE) + " 00:00:00"; - String end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); - List records = dataService.periodTargetData(start, end, 1, 2, device.getEmCode(), HomePageConstant.PV_LOAD); - if (CollectionUtil.isEmpty(records)) { - return new ArrayList<>(); - } - return records.stream().map(record -> { - PhotovoltaicPowerVo load = new PhotovoltaicPowerVo(); - Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); - load.setHour(time.getHours()); - load.setActivePower(Optional.ofNullable(record.getVal()).orElse("0")); - return load; - }).sorted(Comparator.comparing(PhotovoltaicPowerVo::getHour)).collect(Collectors.toList()); - } - - /** - * 近30天发电量 - * - * @param device - * @return - */ - private List getGenerateByMon(EminfoAndEmParamVo device) { - Calendar calendar = Calendar.getInstance(); - String end = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME); - calendar.add(Calendar.DAY_OF_MONTH, -29); - calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); - calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); - calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); - String start = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME); - List records = dataService.periodTargetData(start, end, 5, 3, device.getEmCode(), HomePageConstant.PV_GENERATION_CAPACITY); - if (CollectionUtil.isEmpty(records)) { - return new ArrayList<>(); - } - return records.stream().map(record -> { - GenerationPowerVo generate = new GenerationPowerVo(); - Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); - generate.setDate(DateUtil.format(time, DateUtil.PATTERN_DATE)); - generate.setGenerate(Float.valueOf(Optional.ofNullable(record.getVal()).orElse("0"))); - return generate; - }).sorted(Comparator.comparing(GenerationPowerVo::getDate)).collect(Collectors.toList()); - } - - /** - * 获取光伏站点填报数据 - * @param stations - * @return - */ - private List generateFill(List stations) { - Calendar calendar = Calendar.getInstance(); - String mon = DateUtil.format(calendar.getTime(),"yyyy-MM"); - String year = String.valueOf(calendar.get(Calendar.YEAR)); - return stations.stream().map(station ->{ - PhotovoltaicTargetVo target = new PhotovoltaicTargetVo(); - target.setDeptId(station.getRefDept()); - target.setDeptName(station.getName()); - // 当日运行时长 - target.setRunHours(0.0); - // 日发电量 - target.setGenerationDay(0.0); - // 昨日发电量 - target.setGenerationYesterday(0.0); - // 收益 - target.setIncome(0.0); - // 日发电量 - // 月发电量 - target.setGenerationMon(powerService.generate(mon,station.getRefDept())); - // 节约标准煤 - target.setTec(target.getGenerationMon() * 0.0001229); - // 二氧化碳减排 - target.setCo2(target.getGenerationMon() * 0.000997); - // 减少森林砍伐 - target.setDeforest(target.getGenerationMon() * 0.000553); - // 年发电量 - target.setGenerationYear(powerService.generate(year,station.getRefDept())); - // 30天发电量 - return target; - }).collect(Collectors.toList()); - } - - /** - * 计算切分次数 - */ - private static Integer countStep(Integer size) { - return (size + 3 - 1) / 3; - } - - /** - * 泵站设备 - * @param stations - * @return - */ - private List pumpDevices(List stations){ - if(CollectionUtil.isEmpty(stations)){ - return new ArrayList<>(); - } - List devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(),new TypeReference>() {}); - if(CollectionUtil.isEmpty(devices)){ - return new ArrayList<>(); - } - return devices.stream().filter(device->stations.contains(device.getCreateDept())).collect(Collectors.toList()); - } - - /** - * 获取实时数据 - * @return - */ - private Map getRealMap() { - String json = (String) redisTemplate.opsForValue().get(real_id_cofig_final); - if(StringUtil.isBlank(json)){ - return null; - } - return JSONObject.parseObject(json, new TypeReference>() {}); - } - - - /** - * 获取监测点实时数据 - * @param device - * @param targets - * @return - */ - private double getSignageValue(EminfoAndEmParamVo device,Map map, String targets) { - if(ObjectUtil.isEmpty(device) || MapUtils.isEmpty(map)){ - return 0.0; - } - Map point = device.getPoint(); - if(MapUtils.isEmpty(point)){ - return 0.0; - } - String realId = point.get(targets); - if(StringUtil.isBlank(realId)){ - return 0.0; - } - String value = map.get(realId); - if(StringUtil.isBlank(value)){ - return 0.0; - } - // 获取value - return Double.parseDouble(value); - } - - /** - * 单位设置 - * @param device - * @param unitMap - * @param realVo - */ - private void setttingUnit(EminfoAndEmParamVo device, Map unitMap, HydropowerUnitRealVo realVo) { - if(MapUtils.isEmpty(unitMap)){ - return; - } - // 有功功率单位 - String power = unitMap.get(device.getId()+HomePageConstant.CONCAT_P); - if(StringUtil.isNotBlank(power)){ - realVo.setPowerUnit(power); - } else { - realVo.setPowerUnit("kW"); - } - // 无功功率 - String reactivePowerUnit = unitMap.get(device.getId()+HomePageConstant.CONCAT_Q); - if(StringUtil.isNotBlank(reactivePowerUnit)){ - realVo.setReactivePowerUnit(reactivePowerUnit); - } else { - realVo.setReactivePowerUnit("kVa r"); - } - // 定子电压单位 - String voltage = unitMap.get(device.getId()+HomePageConstant.CONCAT_UAB); - if(StringUtil.isNotBlank(voltage)){ - realVo.setVoltageUnit(voltage); - } else { - realVo.setVoltageUnit("V"); - } - // 定子电流单位 - String current = unitMap.get(device.getId()+HomePageConstant.CONCAT_IA); - if(StringUtil.isNotBlank(current)){ - realVo.setCurrentUnit(current); - } else { - realVo.setCurrentUnit("A"); - } - } - - /** - * 获取年、月、日发电量 - * @param device - * @param scope - * @return - */ - private float getGenerationPower(EminfoAndEmParamVo device,int scope) { - String start,end; - int accessRules; - Calendar calendar = Calendar.getInstance(); - switch (scope){ - // 年 - case 0: - end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); - calendar.setTime(new Date()); - calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); - calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); - start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; - accessRules = EquipmentConstants.CycleTypeEnum.YEAR_CYCLE.getType(); - break; - // 月 - case 1: - start = DateUtil.format(new Date(), "yyyy-MM") + "-01 00:00:00"; - end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); - accessRules = EquipmentConstants.CycleTypeEnum.MONTH_CYCLE.getType(); - break; - // 日 - case 2: - String time = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); - start = time + " 00:00:00"; - end = time + " 23:59:59"; - accessRules = EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(); - break; - default: - throw new IllegalStateException("Unexpected value: " + scope); - } - return dataService.periodTargetFloat(start,end,5,accessRules,device.getEmCode(),device.getRideCount(),HomePageConstant.HYDROPOWER_GENERATE_POWER); - } - - /** - * 近30天发电量 - * @param device - * @return - */ - private List getGenerationPowerList(EminfoAndEmParamVo device) { - String start = DateUtil.format(new Date(), "yyyy-MM") + "-01 00:00:00"; - String end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); - List records = dataService.periodTargetData(start,end,5,EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(),device.getEmCode(),HomePageConstant.HYDROPOWER_GENERATE_POWER); - if(CollectionUtil.isEmpty(records)){ - return new ArrayList<>(); - } - return records.stream().map(record -> { - GenerationPowerVo generate = new GenerationPowerVo(); - Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); - generate.setDate(DateUtil.format(time,DateUtil.PATTERN_DATE)); - generate.setGenerate(Float.parseFloat(Optional.ofNullable(record.getVal()).orElse("0")) * device.getRideCount()); - return generate; - }).collect(Collectors.toList()); - } -} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/RecordServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/RecordServiceImpl.java deleted file mode 100644 index d5489b8..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/RecordServiceImpl.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation.impl; - -import com.hnac.hzims.operational.config.entity.StAlarmRecordEntity; -import com.hnac.hzims.scheduled.mapper.operation.RecordMapper; -import com.hnac.hzims.scheduled.service.operation.RecordService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springframework.stereotype.Service; - -import java.util.Date; - -/** - * @author ysj - */ -@Service -@RequiredArgsConstructor -@Slf4j -public class RecordServiceImpl extends BaseServiceImpl implements RecordService { - - /** - * 添加告警 - * @param stationId - * @param realId - * @return - */ - @Override - public Long insertAlert(String stationId, String realId) { - StAlarmRecordEntity record = new StAlarmRecordEntity(); - record.setStationId(stationId); - record.setRealId(realId); - record.setStatus(0); - record.setCreateTime(new Date()); - return this.baseMapper.insertReturnId(record); - } -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/ReportServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/ReportServiceImpl.java deleted file mode 100644 index 67695dd..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/ReportServiceImpl.java +++ /dev/null @@ -1,527 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation.impl; - -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.google.common.util.concurrent.ThreadFactoryBuilder; -import com.hnac.hzims.equipment.entity.PlanGenerationEntity; -import com.hnac.hzims.message.dto.MailPushDto; -import com.hnac.hzims.message.fegin.IPushMsgClient; -import com.hnac.hzims.operational.main.constant.HomePageConstant; -import com.hnac.hzims.operational.main.vo.AreaMonthReportVo; -import com.hnac.hzims.operational.main.vo.MaintainVo; -import com.hnac.hzims.operational.main.vo.OverhaulVo; -import com.hnac.hzims.operational.report.vo.DutyDefectVO; -import com.hnac.hzims.operational.station.entity.StationEntity; -import com.hnac.hzims.safeproduct.dto.SafeEquipmentTrialDTO; -import com.hnac.hzims.scheduled.service.equipment.PlanService; -import com.hnac.hzims.scheduled.service.inspect.TaskService; -import com.hnac.hzims.scheduled.service.operation.*; -import com.hnac.hzims.scheduled.service.safeproduct.MonthService; -import com.hnac.hzims.scheduled.service.safeproduct.TrialService; -import com.hnac.hzims.scheduled.service.ticket.TicketService; -import com.hnac.hzims.ticket.workTicket.vo.TicketMonthVO; -import com.hnac.hzinfo.inspect.task.vo.DutyInspectTaskVO; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections4.MapUtils; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.DateUtil; -import org.springblade.core.tool.utils.ObjectUtil; -import org.springblade.core.tool.utils.StringUtil; -import org.springblade.system.entity.Dept; -import org.springblade.system.feign.ISysClient; -import org.springblade.system.user.entity.User; -import org.springblade.system.user.feign.IUserClient; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Service; - -import java.math.BigDecimal; -import java.text.SimpleDateFormat; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.util.*; -import java.util.concurrent.*; -import java.util.stream.Collectors; - -/** - * @author ysj - */ -@Service -@RequiredArgsConstructor -@Slf4j -public class ReportServiceImpl implements ReportService { - - private final PlanService planService; - private final TaskService taskService; - private final TrialService trialService; - private final AccessService accessService; - private final TicketService ticketService; - private final StationService stationService; - private final MonthService monthService; - private final PhenomenonService phenomenonService; - private final MaintenanceService maintenanceService; - private final RedisTemplate redisTemplate; - private final ISysClient sysClient; - private final IUserClient userClient; - private final IPushMsgClient pushMsgClient; - - private final static String recent_year_cache_final = "hzims:operation:key:power:data"; - - @Value("${hzims.operation.area.report}") - private String report_month_cache_final; - - - /** - * 区域-月报 - * @param param - * @param year - */ - @Override - public void loadMonthReport(String param, int year) { - // 获取所有机构 - R> R = sysClient.getDeptList(); - if (!R.isSuccess() || CollectionUtil.isEmpty(R.getData())) { - return; - } - // 查询所有服务类型——"运维服务"、站点类型——"水电站" - List stations = stationService.list(Wrappers.lambdaQuery() - .eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) - .eq(StationEntity::getType,HomePageConstant.HYDROPOWER) - ); - if (CollectionUtil.isEmpty(stations)) { - return; - } - // 站点近年发电数据 - Map> powerMap = (Map>) redisTemplate.opsForValue().get(recent_year_cache_final); - // 存储数据节点 key - 月份 value - 区域数据集合 - Map> map = new HashMap<>(); - // 月份集合 - List monthList = getMonthList(year, Calendar.getInstance().get(Calendar.MONTH)); - monthList.forEach(mon -> { - List list = this.getAreaReportByMon(R.getData(), powerMap, stations, mon); - if (CollectionUtil.isEmpty(list)) { - return; - } - map.put(mon, list); - }); - // 推送当月报表邮件 - this.sendMonthReport(map, R.getData()); - redisTemplate.opsForValue().set(report_month_cache_final, map); - } - - /** - * 获取近年月份集合 - * - * @param year - * @return - */ - public static List getMonthList(int year, int endMoth) { - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM"); - // 开始日期 - Calendar endCal = Calendar.getInstance(); - endCal.setTime(new Date()); - endCal.add(Calendar.MONTH, -endCal.get(Calendar.MONTH) + endMoth); - endCal.add(Calendar.DATE, -endCal.get(Calendar.DATE) + 1); - - // 结束日期 - Calendar startCal = Calendar.getInstance(); - startCal.setTime(new Date()); - startCal.set(Calendar.YEAR, startCal.get(Calendar.YEAR) - year); - startCal.add(Calendar.MONTH, -startCal.get(Calendar.MONTH)); - startCal.add(Calendar.DATE, -startCal.get(Calendar.DATE) + 1); - // 获取日期之间的月份 - List list = new ArrayList<>(); - while (endCal.after(startCal)) { - list.add(format.format(startCal.getTime())); - startCal.add(Calendar.MONTH, 1); - } - list.add(format.format(endCal.getTime())); - return list; - } - - /** - * 区域月报数据加载 - * @param deptList - * @param powerMap - * @param stationList - * @param mon - * @return - */ - private List getAreaReportByMon(List deptList, Map> powerMap, List stationList, String mon) { - LocalDateTime startTime = LocalDateTime.parse(mon + "-01 00:00:00", DateUtil.DATETIME_FORMATTER); - LocalDateTime endTime = getEndTime(mon); - // 查询所有站点的计划发电量 - List planList = this.planPower(stationList, mon); - // 站点实际发电量 - Map actualMap = this.actualPower(powerMap, stationList, mon + "-01"); - // 站点去年发电量 - Map oldActualMap = this.actualPower(powerMap, stationList, lastyear(1,mon)); - // 站点前发电量 - Map oldOldActualMap = this.actualPower(powerMap, stationList, lastyear(2,mon)); - // 取机构中区域部分 - List areaList = deptList.stream().filter(o -> o.getDeptCategory().equals(3)).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(areaList)) { - return null; - } - List areaMonthReportVoList = new ArrayList<>(); - areaList.forEach(area -> { - AreaMonthReportVo areaMonthReport = new AreaMonthReportVo(); - areaMonthReport.setAreaId(area.getId()); - areaMonthReport.setAreaName(area.getDeptName()); - // 获取区域下的站点 - List stationIdList = deptList.stream().filter(o -> o.getParentId().equals(area.getId()) && o.getDeptCategory().equals(4)).map(Dept::getId).collect(Collectors.toList()); - List areaStationList = stationList.stream().filter(o -> stationIdList.contains(o.getRefDept())).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(areaStationList)) { - return; - } - // 计划发电量、实际发电量、发电完成率 - this.powerMonth(planList, actualMap, oldActualMap, areaStationList, areaMonthReport); - // 操作票、操作票合格率/ 工作票、工作票合格率 - this.doubleMonth(area, areaMonthReport, mon + "-01 00:00:00", this.strEndTime(mon)); - // 日常维护、巡检任务、缺陷数、消缺率、检修任务 - this.taskMonth(Collections.singletonList(area.getId()), areaMonthReport, mon + "-01 00:00:00", strEndTime(mon)); - // 预测 - this.predictPlanPower(oldActualMap,oldOldActualMap,areaStationList,areaMonthReport); - // 安全生产会议次数、月度检查报告、技能培训、安全大检查 - this.securityCheck(Collections.singletonList(area.getId()),areaMonthReport,mon + "-01 00:00:00", strEndTime(mon)); - // 设备试验 - this.getDeviceTry(mon + "-01 00:00:00", strEndTime(mon), Collections.singletonList(area.getId()),areaMonthReport); - areaMonthReportVoList.add(areaMonthReport); - }); - return areaMonthReportVoList; - } - - /** - * 获取结束时间 - */ - private LocalDateTime getEndTime(String mon) { - Date date = DateUtil.parse(mon + "-01 00:00:00",DateUtil.DATETIME_FORMAT); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - calendar.add(Calendar.MONTH, 1); - return calendar.getTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); - } - - /** - * 获取站点计划发电量 - */ - private List planPower(List stationList, String mon) { - List list = stationList.stream().map(StationEntity::getCode).collect(Collectors.toList()); - return planService.planGeneration(list, null, mon); - } - - /** - * 获取站点月份实际发电量 - */ - private Map actualPower(Map> powerMap, List stationList, String month) { - if (MapUtils.isEmpty(powerMap)) { - return null; - } - // 站点Id集合 - List stationIdList = stationList.stream().map(StationEntity::getId).collect(Collectors.toList()); - // 存储站点实际发电量 - Map actualPowerMap = new HashMap<>(); - stationIdList.forEach(key -> { - Map monthMap = powerMap.get(key); - if (MapUtils.isEmpty(monthMap)) { - return; - } - float actualPower = 0f; - if(ObjectUtil.isNotEmpty(monthMap.get(month))){ - actualPower = monthMap.get(month); - } - actualPowerMap.put(key, actualPower); - }); - return actualPowerMap; - } - - /** - * 获取去年时间 - */ - private String lastyear(int year,String mon) { - Date date = DateUtil.parse(mon + "-01 00:00:00",DateUtil.DATETIME_FORMAT); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - year); - calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); - return DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); - } - - /** - * 获取结束时间 - */ - private String strEndTime(String mon) { - Date date = DateUtil.parse(mon + "-01 00:00:00",DateUtil.DATETIME_FORMAT); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - calendar.add(Calendar.MONTH, 1); - return DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); - } - - /** - * 区域-月计划发电量、月实际发电量、月发电完成率、同比 - * - * @param planList - * @param actualMap - * @param oldActualMap - * @param areaStationList - * @param areaMonthReport - */ - private void powerMonth(List planList, Map actualMap, Map oldActualMap, List areaStationList, AreaMonthReportVo areaMonthReport) { - // 计划发电量 - List codeList = areaStationList.stream().map(StationEntity::getCode).collect(Collectors.toList()); - double planPower = planList.stream().filter(o -> codeList.contains(o.getStationId())).mapToDouble(PlanGenerationEntity::getPlanGeneration).sum(); - areaMonthReport.setPlanPower(Float.parseFloat(String.valueOf(planPower))); - if (MapUtils.isEmpty(actualMap)) { - areaMonthReport.setActualPower(0f); - areaMonthReport.setPowerFinishRate(0.0); - return; - } - // 实际发电量 - List ids = areaStationList.stream().map(StationEntity::getId).collect(Collectors.toList()); - double actualPower = actualMap.entrySet().stream().filter(e -> ids.contains(e.getKey())).mapToDouble(Map.Entry::getValue).sum(); - areaMonthReport.setActualPower(Float.parseFloat(String.valueOf(actualPower))); - if (Math.abs(planPower) <= 0) { - areaMonthReport.setPowerFinishRate(0.0); - } else { - // 发电完成率 - double powerFinishRate = BigDecimal.valueOf(actualPower / planPower * 100).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); - areaMonthReport.setPowerFinishRate(powerFinishRate); - } - // 同比 - double oldActualPower = oldActualMap.entrySet().stream().filter(e -> ids.contains(e.getKey())).mapToDouble(Map.Entry::getValue).sum(); - if (Math.abs(actualPower) <= 0 || Math.abs(oldActualPower) <= 0) { - areaMonthReport.setComparePowerRate(0.0); - return; - } - double comparePowerRate = BigDecimal.valueOf(actualPower / oldActualPower).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - areaMonthReport.setComparePowerRate(comparePowerRate); - } - - /** - * 区域-操作票、操作票合格率/ 工作票、工作票合格率 - * - * @param area - * @param areaMonthReport - */ - private void doubleMonth(Dept area, AreaMonthReportVo areaMonthReport, String startTime, String endTime) { - // 站点归属机构集合 - TicketMonthVO ticket = ticketService.operateWork(startTime,endTime,Collections.singletonList(area.getId())); - if (ObjectUtil.isEmpty(ticket)) { - areaMonthReport.setOperate(0); - areaMonthReport.setOperaQualifyRate(0.0); - areaMonthReport.setWork(0); - areaMonthReport.setWorkQualifyRate(0.0); - return; - } - // 操作票 - int operate = ticket.getOperate(); - int operateQualify = ticket.getOperateQualify(); - areaMonthReport.setOperate(operate); - if (operateQualify <= 0) { - areaMonthReport.setOperaQualifyRate(0.0); - } else { - double operateQualifyRate = BigDecimal.valueOf(operateQualify / (double) operate * 100L).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); - areaMonthReport.setOperaQualifyRate(operateQualifyRate); - } - //工作票 - int work = ticket.getWork(); - int workQualify = ticket.getWorkQualify(); - areaMonthReport.setWork(work); - if (workQualify <= 0) { - areaMonthReport.setWorkQualifyRate(0.0); - } else { - double workQualifyRate = BigDecimal.valueOf(workQualify / (double) work * 100L).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); - areaMonthReport.setWorkQualifyRate(workQualifyRate); - } - } - - /** - * 任务月报-日常维护、巡检任务、缺陷数、消缺率、检修任务 - * - * @param areas - * @param areaMonthReport - */ - private void taskMonth(List areas, AreaMonthReportVo areaMonthReport, String startTime, String endTime) { - //通过线程池异步获取月报各模块内容 主要分为五块内容 - ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("area_month_report-pool-%d").build(); - ExecutorService exe = new ThreadPoolExecutor(4, 4, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); - //监控线程执行完后返回结果 - CountDownLatch countDownLatch = new CountDownLatch(4); - // 日常维护 - exe.execute(() -> { - MaintainVo maintainVo = maintenanceService.maintain(startTime, endTime, areas); - int maintainSum = maintainVo.getMaintain(); - areaMonthReport.setRoutineMaintenance(maintainSum); - countDownLatch.countDown(); - }); - - // 巡检任务 - exe.execute(() -> { - DutyInspectTaskVO task = taskService.task(startTime,endTime,areas); - if (ObjectUtil.isEmpty(task)) { - areaMonthReport.setInspect(0); - } else { - int inspect = task.getInspectTaskSum(); - areaMonthReport.setInspect(inspect); - } - countDownLatch.countDown(); - }); - - // 消缺 - exe.execute(() -> { - DutyDefectVO defectVO = phenomenonService.defect(startTime, endTime, areas); - int defectSum = defectVO.getDefectSum(); - int defect = defectVO.getDefect(); - areaMonthReport.setDefect(defectSum); - if (defectSum <= 0) { - areaMonthReport.setDefectRate(0.0); - } else { - double deletionRate = BigDecimal.valueOf(defect / defectSum * 100L).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); - areaMonthReport.setDefectRate(deletionRate); - } - countDownLatch.countDown(); - }); - - // 检修 - exe.execute(() -> { - OverhaulVo overhaulVo = accessService.overhaul(startTime, endTime, areas); - int overhaul = overhaulVo.getOverhaul(); - areaMonthReport.setMaintenanceTasks(overhaul); - countDownLatch.countDown(); - }); - - //所有模板数据获取完成后释放锁 - try { - countDownLatch.await(); - } catch (InterruptedException e) { - e.printStackTrace(); - Thread.currentThread().interrupt(); - } - exe.shutdown(); - } - - /** - * 预测发电量 - * @param oldActualMap - * @param oldOldActualMap - * @param areaStationList - * @param areaMonthReport - */ - private void predictPlanPower(Map oldActualMap, Map oldOldActualMap, List areaStationList, AreaMonthReportVo areaMonthReport) { - areaMonthReport.setPredictPlanPower(0.0); - // 实际发电量 - List ids = areaStationList.stream().map(StationEntity::getId).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(ids)){ - return; - } - double oldActualPower = oldActualMap.entrySet().stream().filter(e -> ids.contains(e.getKey())).mapToDouble(Map.Entry::getValue).sum(); - double oldOldActualPower = oldOldActualMap.entrySet().stream().filter(e -> ids.contains(e.getKey())).mapToDouble(Map.Entry::getValue).sum(); - if(Math.abs(oldActualPower) <= 0 && Math.abs(oldOldActualPower) <= 0 ){ - return; - } - double predictPlanPower = BigDecimal.valueOf((oldActualPower + oldOldActualPower) / 2).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - areaMonthReport.setPredictPlanPower(predictPlanPower); - } - - /** - * 安全检查 - * @param areas - * @param areaMonthReport - * @param startTime - * @param endTime - */ - private void securityCheck(List areas, AreaMonthReportVo areaMonthReport,String startTime,String endTime) { - areaMonthReport.setSafetyMeeting(0); - areaMonthReport.setSelfReport(0); - areaMonthReport.setSkillTrainy(0); - areaMonthReport.setSecurityCheck(0); - // 站点归属机构集合 - Map map = new HashMap<>(); - map.put("startDate", startTime); - map.put("endDate", endTime); - map.put("deptList", areas); - // 调用安全大检查fegin接口 - Map count = monthService.check(map); - if(MapUtils.isEmpty(count)){ - return; - } - // 安全生产会议 - areaMonthReport.setSafetyMeeting((Integer) count.get("safetyMeetingNum")); - // 月度自查报告 - areaMonthReport.setSelfReport((Integer) count.get("monthCheckNum")); - // 技能培训 - areaMonthReport.setSkillTrainy((Integer) count.get("skillsTrainingNum")); - // 安全大检查 - areaMonthReport.setSecurityCheck((Integer) count.get("bigCheckNum")); - } - - /** - * 获取设备试验数据 - * @param startTime - * @param endTime - * @param areas - * @param areaMonthReport - */ - private void getDeviceTry(String startTime,String endTime,List areas,AreaMonthReportVo areaMonthReport) { - areaMonthReport.setDeviceTry(0); - SafeEquipmentTrialDTO request = new SafeEquipmentTrialDTO(); - request.setDeptList(areas); - request.setStartTime(startTime); - request.setEndTime(endTime); - areaMonthReport.setDeviceTry(trialService.count(request)); - } - - /** - * 推送当月月报 - * - * @param map - * @param list - */ - private void sendMonthReport(Map> map, List list) { - if (MapUtils.isEmpty(map) || CollectionUtil.isEmpty(list)) { - return; - } - // 获取邮件接收人 - Dept dept = list.stream().min(Comparator.comparing(Dept::getDeptCategory)).get(); - if(ObjectUtil.isEmpty(dept)){ - return; - } - R> userR = userClient.userListByDeptAndChildrenWithAuth(dept.getId()); - if(!userR.isSuccess() && CollectionUtil.isEmpty(userR.getData())){ - return; - } - List userList = userR.getData().stream().filter(o->dept.getId().equals(o.getCreateDept())).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(userList)){ - return; - } - List mailList = userList.stream().map(User::getEmail).filter(StringUtil::isNotBlank).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(mailList)){ - return; - } - // 获取月报数据 - List entityList = map.get(DateUtil.format(new Date(),"yyyy-MM")); - if (CollectionUtil.isEmpty(entityList)) { - return; - } - // 发送邮件 - MailPushDto pushDto = new MailPushDto(); - pushDto.setBusinessClassify("system"); - pushDto.setBusinessKey("Month_Report"); - pushDto.setSubject("水电站生产运行"); - Map param = new HashMap<>(); - param.put("templatePath", "/data/hzims/message/mail/template/stationRunMonthReport.html"); - Map parameters = new HashMap<>(); - parameters.put("data",entityList); - param.put("parameters", parameters); - pushDto.setExtras(param); - pushDto.setText("水电站生产运行月报内容"); - pushDto.setToAccount(mailList.toArray(new String[0])); - pushDto.setHtml(true); - pushDto.setCreateUser(userR.getData().get(0).getCreateUser()); - pushDto.setTenantId(dept.getTenantId()); - pushDto.setCreateDept(dept.getId()); - pushMsgClient.sendMail(pushDto); - } -} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/ShowServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/ShowServiceImpl.java deleted file mode 100644 index 9d2f707..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/ShowServiceImpl.java +++ /dev/null @@ -1,1271 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation.impl; - -import com.alibaba.fastjson.JSONObject; -import com.alibaba.fastjson.TypeReference; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.google.common.util.concurrent.ThreadFactoryBuilder; -import com.hnac.hzims.EquipmentConstants; -import com.hnac.hzims.equipment.entity.PlanGenerationEntity; -import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; -import com.hnac.hzims.operational.access.constants.AccessConstants; -import com.hnac.hzims.operational.access.entity.OperAccessTaskEntity; -import com.hnac.hzims.operational.defect.constants.DefectConstant; -import com.hnac.hzims.operational.defect.entity.OperPhenomenonEntity; -import com.hnac.hzims.operational.duty.vo.DutyInfoVo; -import com.hnac.hzims.operational.duty.vo.DutyTaskVo; -import com.hnac.hzims.operational.duty.vo.NextDutyInfoVo; -import com.hnac.hzims.operational.fill.entity.*; -import com.hnac.hzims.operational.main.constant.HomePageConstant; -import com.hnac.hzims.operational.main.vo.*; -import com.hnac.hzims.operational.report.vo.DutyDefectVO; -import com.hnac.hzims.operational.station.entity.StationEntity; -import com.hnac.hzims.scheduled.service.equipment.PlanService; -import com.hnac.hzims.scheduled.service.inspect.TaskService; -import com.hnac.hzims.scheduled.service.operation.*; -import com.hnac.hzims.scheduled.service.ticket.TicketService; -import com.hnac.hzims.scheduled.service.ticket.WorkTicketService; -import com.hnac.hzims.ticket.allTicket.vo.DoublePassRateVO; -import com.hnac.hzims.ticket.workTicket.vo.TicketMonthVO; -import com.hnac.hzims.ticket.workTicket.vo.WorkTicketStatisticVO; -import com.hnac.hzinfo.datasearch.analyse.IAnalyseInstanceClient; -import com.hnac.hzinfo.inspect.task.vo.DutyInspectTaskVO; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections4.MapUtils; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.*; -import org.springblade.system.cache.DictCache; -import org.springblade.system.entity.Dept; -import org.springblade.system.feign.ISysClient; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Service; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.math.BigDecimal; -import java.net.HttpURLConnection; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.sql.Time; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.util.*; -import java.util.concurrent.*; -import java.util.stream.Collectors; - -/** - * @author ysj - */ -@Service -@RequiredArgsConstructor -@Slf4j -public class ShowServiceImpl implements ShowService { - - private final TaskService taskService; - private final OverService overService; - private final PlanService planService; - private final PowerService powerService; - private final SolveService solveService; - private final OtherService otherService; - private final AccessService accessService; - private final TicketService ticketService; - private final DefectService defectService; - private final DutyService dutyService; - private final StationService stationService; - private final OverDetailsService detailsService; - private final WorkTicketService workTicketService; - private final PhenomenonService phenomenonService; - private final DataService dataService; - private final MaintenanceService maintenanceService; - private final RedisTemplate redisTemplate; - private final ISysClient sysClient; - private final IAnalyseInstanceClient deviceInstanceClient; - - private final static String charge = "hzims:operation:key:charge"; - private final static String home_target_cache_final = "load:operation:home:target:key"; - private final static String hydropower_real_cache_final = "hzims:operation:loadhydropowerunit:real:key"; - private final static String hydropower_target_cache_final = "hzims:operation:loadhydropowerunit:target:key"; - private final static String photovoltaic_real_cache_final = "hzims:operation:photovoltaic:real:key"; - private final static String photovoltaic_target_cache_final = "hzims:operation:photovoltaic:target:key"; - - @Value("${hzims.operation.homePage.charge.url}") - public String charge_url; - - @Value("${hzims.equipment.emInfo.emInfoList}") - public String device_cache_cofig_final; - - @Value("${hzims.operation.region.areaDutyInfoKey}") - private String area_duty_cache_final; - - @Value("${hzims.operation.region.deviceClassifyKey}") - private String device_classify_cache_final; - - @Value("${hzims.operation.realIdKey}") - public String real_cache_final; - - /** - * 集团总指标-首页数据 - */ - @Override - public void loadHomeTarget(String param) { - List targets = HomePageConstant.HOME_TYPES.stream().map(type->{ - if(type == 0) { - return this.hydropowerTaget(); - } - if (type == 1) { - return this.windTaget(); - } - if (type == 2) { - return this.waterStorageTaget(true); - } - if (type == 3) { - return this.waterStorageTaget(false); - } - if (type == 4) { - return this.networkTaget(); - } - if (type == 5) { - return this.photovoltaicTaget(); - } - if (type == 6) { - return this.affairsTaget(); - } - if(type == 7) { - return this.chargeTarget(); - } - return new TargetVo(); - }).collect(Collectors.toList()); - redisTemplate.opsForValue().set(home_target_cache_final,targets.stream().filter(( target -> ObjectUtil.isNotEmpty(target.getType()))).collect(Collectors.toList())); - } - - - /** - * 智能生产-值班数据 - * @param param - */ - @Override - public void loadRegionalDuty(String param) { - R> R = sysClient.getDeptList(); - if (!R.isSuccess() || CollectionUtil.isEmpty(R.getData())) { - return; - } - Map> map = this.area(R.getData(),null, Collections.singletonList(HomePageConstant.HYDROPOWER),HomePageConstant.HYDROPOWER_SERVETYPE); - if (MapUtils.isEmpty(map)) { - return; - } - // 查询所有区域值班/接班数据 - List dutyInfoVoList = dutyService.dutyData(map.keySet().stream().map(Dept::getId).collect(Collectors.toList())); - if(CollectionUtil.isEmpty(dutyInfoVoList)){ - return; - } - // 所有设备 - List devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(), new TypeReference>() {}); - List areaDutyVoList = new ArrayList<>(); - map.forEach((key,value) -> { - List singlet = Collections.singletonList(key.getId()); - AreaDutyVo areaDutyVo = new AreaDutyVo(); - areaDutyVo.setDepartId(key.getId()); - areaDutyVo.setDepartName(key.getDeptName()); - areaDutyVo.setSort(key.getSort()); - // 值班情况 - this.dutySituation(dutyInfoVoList, key, areaDutyVo); - // 厂站运行情况 - this.factoryStationRun(devices, value, areaDutyVo); - // 当月任务执行情况 - this.executeTaskMonth(singlet, areaDutyVo); - // 获取区域当班时间 - List dutyList = dutyInfoVoList.stream().filter(o -> key.getId().equals(o.getCreateDept())).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(dutyList)) { - areaDutyVoList.add(areaDutyVo); - return; - } - Date startDate = this.dutyStartTime(dutyList.get(0).getDateTime(),dutyList.get(0).getStartTime()); - Date endDate = this.dutyEndTime(dutyList.get(0).getDateTime(),dutyList.get(0).getStartTime(),dutyList.get(0).getEndTime()); - areaDutyVo.setStartTimeDuty(DateUtil.format(startDate,DateUtil.PATTERN_DATETIME)); - areaDutyVo.setEndTimeDuty(DateUtil.format(endDate,DateUtil.PATTERN_DATETIME)); - // 上一班组发电量 - this.upDutyPower(dutyList,devices,key.getId(),value,areaDutyVo); - // 班组实时发电量 - this.dutyPower(startDate,endDate,devices,value,areaDutyVo,false); - // 当班双票 - this.dutyDoubleTicket(startDate,endDate,singlet,areaDutyVo); - // 当班运行数据 - this.dutyRunCondition(startDate,endDate,singlet,areaDutyVo); - areaDutyVoList.add(areaDutyVo); - }); - redisTemplate.opsForValue().set(area_duty_cache_final, areaDutyVoList); - } - - /** - * 水电站指标 - * @return - */ - private TargetVo hydropowerTaget() { - TargetVo target = new TargetVo(); - target.setType(HomePageConstant.HYDROPOWER); - target.setTypeName(DictCache.getValue("stationType", HomePageConstant.HYDROPOWER)); - // 实时数据 - List reals = (List) redisTemplate.opsForValue().get(hydropower_real_cache_final); - // 指标数据 - List targets = (List) redisTemplate.opsForValue().get(hydropower_target_cache_final); - if(CollectionUtil.isNotEmpty(reals)){ - // 装机容量 - target.setTaget_one(reals.stream().mapToDouble(HydropowerUnitRealVo::getInstalledCapacity).sum()); - } - if(CollectionUtil.isNotEmpty(targets)){ - // 发电量 - target.setTaget_two(targets.stream().mapToDouble(HydropowerUnitTargetVo::getPowerYear).sum()); - } - // 计划发电量 - List stations = stationService.list(Wrappers.lambdaQuery() - .eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) - .eq(StationEntity::getType,HomePageConstant.HYDROPOWER)); - if(CollectionUtil.isNotEmpty(stations)){ - List plans = planService.planGeneration(stations.stream().map(StationEntity::getCode).collect(Collectors.toList()), null, DateUtil.format(new Date(), "yyyy")); - if(CollectionUtil.isNotEmpty(plans)){ - double plan = plans.stream().mapToDouble(PlanGenerationEntity::getPlanGeneration).sum(); - if(Math.abs(plan) > 0){ - target.setTaget_three(BigDecimal.valueOf(target.getTaget_two() / plan * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); - } - } - } - // 双票合格率 - R> result = sysClient.getDeptList(); - if(result.isSuccess() && CollectionUtil.isNotEmpty(result.getData()) && CollectionUtil.isNotEmpty(stations)){ - List areas = result.getData().stream().filter(dept -> stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(dept.getId())).map(Dept::getParentId).collect(Collectors.toList()); - if(CollectionUtil.isNotEmpty(areas)){ - LocalDateTime firstDateTime = LocalDateTime.of(LocalDate.now().withDayOfYear(1), LocalTime.MIN); - DoublePassRateVO pass = ticketService.doublePassRate(areas, firstDateTime, LocalDateTime.now()); - if(ObjectUtil.isNotEmpty(pass)){ - target.setTaget_four(Double.valueOf(pass.getDoublePassRate())); - } - } - } - return target; - } - - - /** - * 设备分类 - * - * @param param - */ - @Override - public void loaddDeviceClassify(String param) { - // 获取所有设备 - List devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(), new TypeReference>() {}); - // 实时数据 - String json = (String) redisTemplate.opsForValue().get(real_cache_final); - Map realMap = null; - if (StringUtil.isNotBlank(json)) { - realMap = JSONObject.parseObject(json, new TypeReference>() {}); - } - Map> deviceClassifyMap = new HashMap<>(); - List deviceCodeList = devices.stream().map(EminfoAndEmParamVo::getEmCode).collect(Collectors.toList()); - // 故障 - List operPhenomenonEntityList = phenomenonService.list(new QueryWrapper() {{ - in("EM_CODE", deviceCodeList); - ne("IS_DEFECT", DefectConstant.IsDefectStatusEnum.IS_DEFECT.getStatus()); - ne("CONCLUSION_STATUS", DefectConstant.HandlerStatusEnum.FINISH_STATUS.getStatus()); - }}); - List faultList = operPhenomenonEntityList.stream().map(OperPhenomenonEntity::getEmCode).distinct().collect(Collectors.toList()); - deviceClassifyMap.put(HomePageConstant.FAULT,faultList); - // 检修 - List operAccessTaskEntityList = accessService.list(new QueryWrapper() {{ - in("EM_CODE", deviceCodeList); - ne("STATUS", AccessConstants.ACCESS_TASK_STATUS_4); - }}); - List overhaulList = operAccessTaskEntityList.stream().map(OperAccessTaskEntity::getEmCode).distinct().collect(Collectors.toList()); - List overhaulOldList = devices.stream().filter(o-> !faultList.contains(o.getEmCode()) && !overhaulList.contains(o.getEmCode()) && (Func.isNotEmpty(o.getRunStatus()) && EquipmentConstants.RunStatus.access.getStatus().equals(o.getRunStatus()))) - .map(EminfoAndEmParamVo::getEmCode).collect(Collectors.toList()); - overhaulList.addAll(overhaulOldList); - deviceClassifyMap.put(HomePageConstant.OVERHAUL,overhaulList); - // 运行 - List runDeviceList = devices.stream().filter(o-> !faultList.contains(o.getEmCode()) && !overhaulList.contains(o.getEmCode())).distinct().collect(Collectors.toList()); - List runList = this.runDevice(runDeviceList,realMap); - deviceClassifyMap.put(HomePageConstant.RUN,runList); - // 备用 - List spareList = devices.stream().filter(o-> !faultList.contains(o.getEmCode()) && !overhaulList.contains(o.getEmCode()) && !runList.contains(o.getEmCode()) && Func.isNotEmpty(o.getRunStatus()) - && EquipmentConstants.RunStatus.spare.getStatus().equals(o.getRunStatus())) - .map(EminfoAndEmParamVo::getEmCode).distinct().collect(Collectors.toList()); - deviceClassifyMap.put(HomePageConstant.SPARE,spareList); - redisTemplate.opsForValue().set(device_classify_cache_final, deviceClassifyMap); - } - - - /** - * 风电指标 - * @return - */ - private TargetVo windTaget() { - TargetVo target = new TargetVo(); - target.setType(HomePageConstant.WIND_POWER); - target.setTypeName(DictCache.getValue("stationType", HomePageConstant.WIND_POWER)); - // 填报发电量 - List stations = stationService.list(Wrappers.lambdaQuery() - .eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) - .eq(StationEntity::getType,HomePageConstant.WIND_POWER)); - if(CollectionUtil.isEmpty(stations)){ - return target; - } - QueryWrapper queryWrapper = new QueryWrapper() {{ - in("create_dept", stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())); - eq("type", HomePageConstant.WIND_POWER_TYPE); - likeRight("mon", DateUtil.format(new Date(),"yyyy")); - }}; - List list = powerService.list(queryWrapper); - if(CollectionUtil.isEmpty(list)){ - return target; - } - double plan = list.stream().mapToDouble(PowerEntity::getPlannedPowerMon).sum(); - double pass = list.stream().mapToDouble(power -> Double.parseDouble(power.getDoubleQualifyRate())).sum(); - // 装机容量 - target.setTaget_one(list.stream().map(PowerEntity::getInstalledCapacity).collect(Collectors.toSet()).stream().mapToDouble(Double::valueOf).sum()); - // 发电量 - target.setTaget_two(list.stream().mapToDouble(PowerEntity::getPowerMon).sum()); - if(Math.abs(plan) > 0){ - // 发电完成率 - target.setTaget_three(BigDecimal.valueOf(target.getTaget_two() / plan * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); - } - // 双票合格率 - target.setTaget_four(BigDecimal.valueOf(pass / list.size()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); - return target; - } - - /** - * 储能指标 - * @param flag : true - 水利 false - 储能 - * @return - */ - private TargetVo waterStorageTaget(boolean flag) { - TargetVo target = new TargetVo(); - if(flag){ - target.setType(HomePageConstant.WATER_CONSERVANCY); - target.setTypeName(DictCache.getValue("stationType", HomePageConstant.WATER_CONSERVANCY)); - }else{ - target.setType(HomePageConstant.ENERGY_STORAGE); - target.setTypeName(DictCache.getValue("stationType", HomePageConstant.ENERGY_STORAGE)); - } - // 查询储能站点 - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE); - if(flag){ - wrapper.eq(StationEntity::getType,HomePageConstant.WATER_CONSERVANCY); - }else{ - wrapper.eq(StationEntity::getType,HomePageConstant.ENERGY_STORAGE); - } - List stations = stationService.list(wrapper); - if(CollectionUtil.isEmpty(stations)){ - return target; - } - // 获取储能区域级别机构 - R> result = sysClient.getDeptList(); - if(result.isSuccess() && CollectionUtil.isNotEmpty(result.getData()) && CollectionUtil.isNotEmpty(stations)){ - List areas = result.getData().stream().filter(dept -> stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList()).contains(dept.getId())).map(Dept::getParentId).collect(Collectors.toList()); - if(CollectionUtil.isNotEmpty(areas)){ - ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("storage-taget-pool-%d").build(); - ScheduledExecutorService exe = new ScheduledThreadPoolExecutor(4, namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); - // 监控线程执行完后返回结果 - CountDownLatch countDownLatch = new CountDownLatch(4); - // 日常维护 - exe.execute(() -> { - target.setTaget_one(Double.valueOf(maintenanceService.maintenanceCount(areas))); - countDownLatch.countDown(); - }); - // 检修任务 - exe.execute(() -> { - target.setTaget_two(accessService.accessCount(areas)); - countDownLatch.countDown(); - }); - // 消缺率 - exe.execute(() -> { - target.setTaget_three(defectService.defectCount(areas)); - countDownLatch.countDown(); - }); - // 双票合格率 - exe.execute(() -> { - LocalDate firstDay = LocalDate.now().withDayOfYear(1); - LocalDateTime firstDateTime = LocalDateTime.of(firstDay, LocalTime.MIN); - DoublePassRateVO pass = ticketService.doublePassRate(areas, firstDateTime, LocalDateTime.now()); - if (ObjectUtil.isNotEmpty(pass)) { - target.setTaget_four(Double.valueOf(pass.getDoublePassRate())); - } - countDownLatch.countDown(); - }); - try { - countDownLatch.await(); - } catch (InterruptedException e) { - e.printStackTrace(); - Thread.currentThread().interrupt(); - } - exe.shutdown(); - } - } - return target; - } - - /** - * 配网 - * @return - */ - private TargetVo networkTaget() { - TargetVo target = new TargetVo(); - target.setType(HomePageConstant.DISTRIBUTION_NETWORK); - target.setTypeName(DictCache.getValue("stationType", HomePageConstant.DISTRIBUTION_NETWORK)); - // 线程池 - ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("network-taget-pool-%d").build(); - ScheduledExecutorService exe = new ScheduledThreadPoolExecutor(3, namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); - // 监控线程执行完后返回结果 - CountDownLatch countDownLatch = new CountDownLatch(3); - // 当月 - LocalDate firstDay = LocalDate.now().withDayOfYear(1); - LocalDateTime firstDateTime = LocalDateTime.of(firstDay, LocalTime.MIN); - // 检修卡 - exe.execute(()->{ - List overs = overService.list(new QueryWrapper() {{ - ge("create_time", firstDateTime); - le("create_time", LocalDateTime.now()); - }}); - if(CollectionUtil.isEmpty(overs)){ - countDownLatch.countDown(); - return; - } - List details = detailsService.list(new QueryWrapper() {{ - ge("create_time", firstDateTime); - le("create_time", LocalDateTime.now()); - in("over_id",overs.stream().map(OverEntity::getId).collect(Collectors.toList())); - }}); - if(CollectionUtil.isEmpty(details)){ - countDownLatch.countDown(); - return; - } - target.setTaget_one(details.stream().mapToDouble(OverDetailsEntity::getQuantity).sum()); - countDownLatch.countDown(); - }); - // 消缺 - exe.execute(()->{ - List solves = solveService.list(new QueryWrapper() {{ - ge("create_time", firstDateTime); - le("create_time", LocalDateTime.now()); - }}); - if(CollectionUtil.isEmpty(solves)){ - countDownLatch.countDown(); - return; - } - target.setTaget_two(solves.stream().mapToDouble(SolveEntity::getSolveQuantity).sum()); - countDownLatch.countDown(); - }); - // 其他 - exe.execute(()->{ - List others = otherService.list(new QueryWrapper() {{ - ge("create_time", firstDateTime); - le("create_time", LocalDateTime.now()); - }}); - if(CollectionUtil.isEmpty(others)){ - countDownLatch.countDown(); - return; - } - // FA上线率 - double online = others.stream().mapToDouble(o-> Double.parseDouble(o.getOnlineRate())).sum(); - if(Math.abs(online) > 0){ - target.setTaget_three(BigDecimal.valueOf(online / others.size()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); - } - // FA投入条数 - target.setTaget_four(others.stream().mapToDouble(OtherEntity::getFaQuantity).sum()); - countDownLatch.countDown(); - }); - // 等待所有线程执行完成 - try { - countDownLatch.await(); - } catch (InterruptedException e) { - e.printStackTrace(); - Thread.currentThread().interrupt(); - } - return target; - } - - /** - * 光伏指标 - * @return - */ - private TargetVo photovoltaicTaget() { - TargetVo target = new TargetVo(); - target.setType(HomePageConstant.PHOTOVOLTAIC); - target.setTypeName(DictCache.getValue("stationType", HomePageConstant.PHOTOVOLTAIC)); - // 实时数据 - List reals = (List) redisTemplate.opsForValue().get(photovoltaic_real_cache_final); - // 指标数据 - List targets = (List) redisTemplate.opsForValue().get(photovoltaic_target_cache_final); - if(CollectionUtil.isNotEmpty(reals)){ - // 装机容量 - target.setTaget_one(reals.stream().mapToDouble(PhotovoltaicRealVo::getCapacity).sum()); - } - if(CollectionUtil.isNotEmpty(targets)){ - // 发电量 - target.setTaget_two(targets.stream().mapToDouble(PhotovoltaicTargetVo::getGenerationYear).sum()); - } - // 计划发电量、双票合格率 - List stations = stationService.list(Wrappers.lambdaQuery() - .eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) - .eq(StationEntity::getType,HomePageConstant.PHOTOVOLTAIC)); - if(CollectionUtil.isNotEmpty(stations)){ - QueryWrapper queryWrapper = new QueryWrapper() {{ - in("create_dept", stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())); - eq("type", HomePageConstant.PHOTOVOLTAIC_TYPE); - likeRight("mon", DateUtil.format(new Date(),"yyyy")); - }}; - List list = powerService.list(queryWrapper); - if(CollectionUtil.isEmpty(list)){ - return target; - } - double plan = list.stream().mapToDouble(PowerEntity::getPlannedPowerMon).sum(); - double pass = list.stream().mapToDouble(power -> Double.parseDouble(power.getDoubleQualifyRate())).sum(); - if(Math.abs(plan) > 0){ - // 发电完成率 - target.setTaget_three(BigDecimal.valueOf(target.getTaget_two() / plan * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); - } - // 双票合格率 - target.setTaget_four(BigDecimal.valueOf(pass / list.size()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); - } - return target; - } - - /** - * 水务指标 - * @return - */ - private TargetVo affairsTaget() { - TargetVo target = new TargetVo(); - target.setType(HomePageConstant.WATER_AFFAIRS); - target.setTypeName(DictCache.getValue("stationType", HomePageConstant.WATER_AFFAIRS)); - // TODO 统计业务数据 - return target; - } - - /** - * 充电桩 - * @return - */ - private TargetVo chargeTarget() { - TargetVo target = (TargetVo) redisTemplate.opsForValue().get(charge); - if(ObjectUtil.isNotEmpty(target)){ - return target; - } - target = new TargetVo(); - try { - URL serverUrl = new URL(charge_url); - HttpURLConnection conn = (HttpURLConnection) serverUrl.openConnection(); - conn.setRequestMethod("GET"); - conn.setRequestProperty("Content-type", "application/json"); - //必须设置false,否则会自动redirect到重定向后的地址 - conn.setInstanceFollowRedirects(false); - conn.connect(); - String result = responseFormat(conn); - if (StringUtil.isBlank(result)) { - return new TargetVo(); - } - JSONObject jsonObject = JSONObject.parseObject(result); - JSONObject data = JSONObject.parseObject(jsonObject.get("data").toString()); - target.setType(HomePageConstant.CHARGE); - target.setTypeName(DictCache.getValue("stationType", HomePageConstant.CHARGE)); - target.setTaget_one(Double.valueOf(data.get("ordersCount").toString())); - target.setTaget_two(Double.valueOf(data.get("todayDegree").toString())); - target.setTaget_three(Double.valueOf(data.get("income").toString())); - target.setTaget_four(Double.valueOf(data.get("kilowatt").toString())); - target.setCharge(Integer.valueOf(data.get("stationNum").toString())); - redisTemplate.opsForValue().set(charge,target); - redisTemplate.expire(charge,30, TimeUnit.MINUTES); - } catch (Exception e) { - target.setType(HomePageConstant.CHARGE); - target.setTypeName(DictCache.getValue("stationType", HomePageConstant.CHARGE)); - target.setTaget_one(0.0); - target.setTaget_two(0.0); - target.setTaget_three(0.0); - target.setTaget_four(0.0); - target.setCharge(0); - log.error("charge_target_exception: {} ", e.getMessage()); - } - return target; - } - - /*** - * 获取返回的内容 - * @param connection - * @return - */ - private String responseFormat(HttpURLConnection connection) { - StringBuilder stringBuilder = new StringBuilder(); - //将返回的输入流转换成字符串 - try ( - InputStream inputStream = connection.getInputStream(); - InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8); - BufferedReader bufferedReader = new BufferedReader(inputStreamReader) - ) { - String str; - while ((str = bufferedReader.readLine()) != null) { - stringBuilder.append(str); - } - } catch (IOException e) { - return null; - } - return stringBuilder.toString(); - } - - /** - * 获取权限区域 - * @param list : 机构列表 - * @param deptId : 起始过滤权限机构 - * @param typeList : 查询站点类型-水电、水利、光伏.... - * @param serveType : 站点服务类型 - * @return Map> - */ - private Map> area(List list,Long deptId, List typeList, Integer serveType) { - // 未传入机构列表,使用用户权限机构过滤 - if(CollectionUtil.isEmpty(list)){ - R> R = sysClient.getDeptByCurrentUser(); - if(!R.isSuccess() || CollectionUtil.isEmpty(R.getData())){ - return null; - } - list = R.getData(); - } - // 根据参数查询有效站点 - List stationList = this.stationByParams(list,deptId,typeList,serveType); - if(CollectionUtil.isEmpty(stationList)){ - return null; - } - // 有效站点归属机构Id集合 - List refDeptList = stationList.stream().map(StationEntity::getRefDept).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(refDeptList)){ - return null; - } - // 有效站点归属机构集合 - List vaildDeptList = list.stream().filter(o->refDeptList.contains(o.getId())).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(vaildDeptList)){ - return null; - } - // 根据有效站点归属机构向上区域Id - List areaIdList = vaildDeptList.stream().map(Dept::getParentId).distinct().collect(Collectors.toList()); - if(CollectionUtil.isEmpty(areaIdList)){ - return null; - } - // 根据区域Id查询区域机构 - List areaList = list.stream().filter(o->o.getDeptCategory().equals(HomePageConstant.AREA) && areaIdList.contains(o.getId())).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(areaList)){ - return null; - } - // 返回结构 - Map> result = new HashMap<>(); - for(Dept area : areaList){ - List childDeptIdList = list.stream().filter(o->o.getParentId().equals(area.getId())).map(Dept::getId).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(childDeptIdList)){ - continue; - } - List resultList = stationList.stream().filter(o->childDeptIdList.contains(o.getRefDept())).collect(Collectors.toList()); - result.put(area,resultList); - } - return result; - } - - /** - * 获取站点集合 - * @param authList - * @param deptId - * @param types - * @param servrType - * @return - */ - private List stationByParams(List authList, Long deptId, List types, Integer servrType) { - Dept dept; - if (null == deptId) { - // 最小类型机构 - Optional min = authList.stream().min(Comparator.comparing(Dept::getDeptCategory)); - dept = min.orElse(null); - if (ObjectUtil.isEmpty(dept)) { - return null; - } - } else { - // 检查是否存在传入机构 - List list = authList.stream().filter(o -> deptId.equals(o.getId())).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(list)) { - return null; - } - // 传入机构为站点 - dept = list.get(0); - } - List depts; - if (dept.getDeptCategory().equals(4)) { - depts = Collections.singletonList(dept.getId()); - // 传入机构为区域、省子公司、集团 - } else { - // 递归权限机构获取站点级机构 - depts = this.stationDept(authList, dept.getId(), new ArrayList<>()); - } - // 获取水利站点(过滤其他站点类型) - return stationService.list(new LambdaQueryWrapper() {{ - eq(StationEntity::getIsDeleted, 0); - if (ObjectUtil.isNotEmpty(servrType)) { - eq(StationEntity::getServeType, servrType); - } - if (CollectionUtil.isNotEmpty(types)) { - in(StationEntity::getType, types); - } - if (CollectionUtil.isNotEmpty(depts)) { - in(StationEntity::getRefDept, depts); - } - }}); - } - - /** - * 递归权限机构获取站点级机构 - * - * @param departList - * @param deptId - * @param list - * @return - */ - private List stationDept(List departList, Long deptId, List list) { - if (null == deptId || CollectionUtil.isEmpty(departList)) { - return null; - } - departList.forEach(dept -> { - if (dept.getParentId().equals(deptId)) { - if (dept.getDeptCategory().equals(4)) { - list.add(dept.getId()); - } - stationDept(departList, dept.getId(), list); - } - }); - return list; - } - - /** - * 获取开始时间 - * @param date - * @param time - * @return - */ - private Date dutyStartTime(Date date, Time time){ - Calendar dateCal = Calendar.getInstance(); - dateCal.setTime(date); - Calendar timeCal = Calendar.getInstance(); - timeCal.setTime(time); - dateCal.set(Calendar.HOUR_OF_DAY, timeCal.get(Calendar.HOUR_OF_DAY)); - dateCal.set(Calendar.MINUTE, timeCal.get(Calendar.MINUTE)); - dateCal.set(Calendar.SECOND, timeCal.get(Calendar.SECOND)); - return dateCal.getTime(); - } - - /** - * 获取结束时间 - * @param date - * @param time - * @return - */ - private Date dutyEndTime(Date date, Time time,Time endTime){ - Calendar dateCal = Calendar.getInstance(); - dateCal.setTime(date); - Calendar timeCal = Calendar.getInstance(); - timeCal.setTime(time); - Calendar endCal = Calendar.getInstance(); - endCal.setTime(endTime); - // 结束时间 < 开始时间 - if(timeCal.after(endCal)){ - dateCal.set(Calendar.DAY_OF_MONTH, dateCal.get(Calendar.DAY_OF_MONTH) + 1 ); - } - dateCal.set(Calendar.HOUR_OF_DAY, endCal.get(Calendar.HOUR_OF_DAY)); - dateCal.set(Calendar.MINUTE, endCal.get(Calendar.MINUTE)); - dateCal.set(Calendar.SECOND, endCal.get(Calendar.SECOND)); - return dateCal.getTime(); - } - - /** - * 值班情况 - * - * @param dutyInfoVoList - * @param dept - * @param areaDutyVo - */ - private void dutySituation(List dutyInfoVoList, Dept dept, AreaDutyVo areaDutyVo) { - if (CollectionUtil.isEmpty(dutyInfoVoList) || ObjectUtil.isEmpty(dept)) { - return; - } - Long deptId = dept.getId(); - List filterList = dutyInfoVoList.stream().filter(o -> o.getCreateDept().equals(deptId)).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(filterList)) { - return; - } - DutyInfoVo dutyInfoVo = filterList.get(0); - areaDutyVo.setGeneratingCapacity(dutyInfoVo.getGeneratingCapacity()); - areaDutyVo.setOnlineCapacity(dutyInfoVo.getOnlineCapacity()); - areaDutyVo.setClassName(dutyInfoVo.getClassName()); - areaDutyVo.setGroupName(dutyInfoVo.getGroupName()); - areaDutyVo.setManagerName(dutyInfoVo.getManagerName()); - areaDutyVo.setManagerPhone(dutyInfoVo.getManagerPhone()); - areaDutyVo.setNextDutyInfoVo(dutyInfoVo.getNextDutyInfoVo()); - // 当班任务 - - String taskCount = this.taskCount(dutyInfoVo.getDateTime(),dutyInfoVo.getStartTime(),dutyInfoVo.getEndTime(),dutyInfoVo.getCreateDept()); - String[] task = taskCount.split("\\|"); - areaDutyVo.setTaskCount(Integer.valueOf(task[0])); - areaDutyVo.setFinishTaskCount(Integer.valueOf(task[1])); - NextDutyInfoVo upDutyInfoVo = dutyInfoVo.getUpDutyInfoVo(); - if(ObjectUtil.isEmpty(upDutyInfoVo)){ - return; - } - // 上一班组当班任务 - String upTaskCount = this.taskCount(upDutyInfoVo.getDateTime(),upDutyInfoVo.getStartTime(),upDutyInfoVo.getEndTime(),dutyInfoVo.getCreateDept()); - String[] upTask = upTaskCount.split("\\|"); - upDutyInfoVo.setTaskCount(Integer.valueOf(upTask[0])); - upDutyInfoVo.setFinishTaskCount(Integer.valueOf(upTask[1])); - areaDutyVo.setUpDutyInfoVo(upDutyInfoVo); - } - - - /** - * 获取当班任务 - * @param dateTime - * @param startTime - * @param endTime - * @param createDept - * @return - */ - private String taskCount(Date dateTime, Time startTime, Time endTime, Long createDept) { - DutyTaskVo task = new DutyTaskVo(); - //通过线程池异步获取月报各模块内容 主要分为五块内容 - ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("duty-task-count-pool-%d").build(); - ExecutorService exe = new ThreadPoolExecutor(4, 4, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); - //监控线程执行完后返回结果 - CountDownLatch countDownLatch = new CountDownLatch(4); - List list = Collections.singletonList(createDept); - String start = DateUtil.format(this.dutyStartTime(dateTime,startTime),DateUtil.PATTERN_DATETIME); - String end = DateUtil.format(this.dutyEndTime(dateTime,startTime,endTime),DateUtil.PATTERN_DATETIME); - // 日常维护 - exe.execute(()->{ - MaintainVo maintainVo = maintenanceService.maintain(start,end,list); - int maintainSum = maintainVo.getMaintain(); - int maintainFinish = maintainVo.getMaintainFinish(); - task.setMaintainSum(maintainSum); - task.setMaintainFinish(maintainFinish); - countDownLatch.countDown(); - }); - - // 消缺 - exe.execute(()->{ - ShortagesVo shortagesVo = phenomenonService.defectMonth(start,end,list); - int shortagesSum = shortagesVo.getShortagesSum(); - int shortages = shortagesVo.getShortages(); - task.setShortagesSum(shortagesSum); - task.setShortages(shortages); - countDownLatch.countDown(); - }); - // 检修 - exe.execute(()->{ - OverhaulVo overhaulVo = accessService.overhaul(start,end,list); - int overhaul = overhaulVo.getOverhaul(); - int overhaulFinish = overhaulVo.getOverhaulFinish(); - task.setOverhaul(overhaul); - task.setOverhaulFinish(overhaulFinish); - countDownLatch.countDown(); - }); - // 巡检 - exe.execute(()->{ - // 巡检任务 - DutyInspectTaskVO inspectTask = taskService.task(start,end,list); - if(ObjectUtil.isEmpty(inspectTask)){ - task.setInspect(0); - task.setInspectFinish(0); - }else{ - int inspect = inspectTask.getInspectTaskSum(); - int inspectFinish = inspectTask.getInspectTaskFinish(); - task.setInspect(inspect); - task.setInspectFinish(inspectFinish); - } - countDownLatch.countDown(); - }); - // 等待所有线程执行完成 - try { - countDownLatch.await(); - } catch (InterruptedException e) { - e.printStackTrace(); - Thread.currentThread().interrupt(); - } - exe.shutdown(); - return (task.getMaintainSum() + task.getShortagesSum() + task.getOverhaul() + task.getInspect()) + "|" + - (task.getMaintainFinish() + task.getShortages() + task.getOverhaulFinish() + task.getInspectFinish()); - } - - /** - * 厂站运行情况 - * - * @param list - * @param areaDutyVo - */ - private void factoryStationRun(List deviceList,List list, AreaDutyVo areaDutyVo) { - areaDutyVo.setStationSum(0); - areaDutyVo.setStationRun(0); - if (CollectionUtil.isEmpty(list) || CollectionUtil.isEmpty(deviceList)) { - return; - } - areaDutyVo.setStationSum(list.size()); - List deptList = list.stream().map(StationEntity::getRefDept).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(deptList)){ - log.info("run_station_dept_list_null : {}",areaDutyVo.getDepartName()); - return; - } - // 过滤未绑定设备 - List codes = deviceList.stream().filter(o->deptList.contains(o.getCreateDept())).map(EminfoAndEmParamVo::getEmCode).collect(Collectors.toList()); - R> R = deviceInstanceClient.getListAnalyseCode(codes); - if (!R.isSuccess() || CollectionUtil.isEmpty(R.getData())) { - log.info("run_station_valid_device_null : {}",areaDutyVo.getDepartName()); - return; - } - // 根据机构分组 - Map> map = deviceList.stream().filter(o->R.getData().contains(o.getEmCode())).collect(Collectors.groupingBy(EminfoAndEmParamVo::getCreateDept)); - if(CollectionUtil.isEmpty(map)){ - log.info("run_station_group_by_valid_null : {}",areaDutyVo.getDepartName()); - return; - } - int runCount = 0; - // 遍历分组设备 - for(Map.Entry> entry : map.entrySet()){ - // 运行设备code集合 - List runCodes = entry.getValue().stream().filter(o -> (Func.isEmpty(o.getRunStatus()) || "1".equals(o.getRunStatus()))).map(EminfoAndEmParamVo::getEmCode).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(runCodes)){ - return; - } - runCount++; - } - areaDutyVo.setStationRun(runCount); - areaDutyVo.setStationSum(list.size()); - } - - /** - * 当月任务执行情况 - * - * @param list - * @param areaDutyVo - */ - private void executeTaskMonth(List list, AreaDutyVo areaDutyVo) { - if (CollectionUtil.isEmpty(list)) { - areaDutyVo.setMaintainSumMoth(0); - areaDutyVo.setMaintainFinishSumMoth(0); - areaDutyVo.setMaintainRateMoth("0"); - areaDutyVo.setShortagesSumMoth(0); - areaDutyVo.setShortagesMoth(0); - areaDutyVo.setShortagesRateMoth("0"); - areaDutyVo.setOverhaulSumMoth(0); - areaDutyVo.setOverhaulFinishSumMoth(0); - areaDutyVo.setOverhaulRateMoth("0"); - areaDutyVo.setOperateSumMoth(0); - areaDutyVo.setOperateQualifySumMoth(0); - areaDutyVo.setOperateRateMoth("0"); - areaDutyVo.setWorkSumMoth(0); - areaDutyVo.setWorkQualifySumMoth(0); - areaDutyVo.setWorkRateMoth("0"); - return; - } - LocalDate firstDay = LocalDate.now().withDayOfMonth(1); - String start = DateUtil.format(new Date(),"yyyy-MM") + "-01 00:00:00"; - String end = DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME); - //通过线程池异步获取月报各模块内容 主要分为五块内容 - ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("month-task-pool-%d").build(); - ScheduledExecutorService exe = new ScheduledThreadPoolExecutor(4, namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); - //监控线程执行完后返回结果 - CountDownLatch countDownLatch = new CountDownLatch(4); - // 日常维护 - exe.execute(()->{ - MaintainVo maintainVo = maintenanceService.maintain(start,end,list); - int maintainSum = maintainVo.getMaintain(); - int maintainFinish = maintainVo.getMaintainFinish(); - areaDutyVo.setMaintainSumMoth(maintainSum); - areaDutyVo.setMaintainFinishSumMoth(maintainFinish); - if (maintainFinish == 0) { - areaDutyVo.setMaintainRateMoth("0"); - } else { - double maintainRate = BigDecimal.valueOf(maintainFinish / (double)maintainSum * 100L).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - areaDutyVo.setMaintainRateMoth(String.valueOf(maintainRate)); - } - countDownLatch.countDown(); - }); - - // 消缺 - exe.execute(()->{ - ShortagesVo shortagesVo = phenomenonService.defectMonth(start,end,list); - int shortagesSum = shortagesVo.getShortagesSum(); - int shortages = shortagesVo.getShortages(); - areaDutyVo.setShortagesSumMoth(shortagesSum); - areaDutyVo.setShortagesMoth(shortages); - if (Math.abs(shortagesSum) <= 0) { - areaDutyVo.setShortagesRateMoth("0"); - } else { - double shortagesRate = BigDecimal.valueOf(shortages / (double)shortagesSum * 100L).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - areaDutyVo.setShortagesRateMoth(String.valueOf(shortagesRate)); - } - countDownLatch.countDown(); - }); - // 检修 - exe.execute(()->{ - OverhaulVo overhaulVo = accessService.overhaul(start,end,list); - int overhaul = overhaulVo.getOverhaul(); - int overhaulFinish = overhaulVo.getOverhaulFinish(); - areaDutyVo.setOverhaulSumMoth(overhaul); - areaDutyVo.setOverhaulFinishSumMoth(overhaulFinish); - if (overhaulFinish == 0) { - areaDutyVo.setOverhaulRateMoth("0"); - } else { - double overhaulRate = BigDecimal.valueOf(overhaulFinish / (double)overhaul * 100L).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - areaDutyVo.setOverhaulRateMoth(String.valueOf(overhaulRate)); - } - countDownLatch.countDown(); - }); - // 操作票&工作票 - exe.execute(()->{ - TicketMonthVO ticket = ticketService.operateWork(start,end,list); - if (ObjectUtil.isEmpty(ticket)) { - areaDutyVo.setOperateSumMoth(0); - areaDutyVo.setOperateQualifySumMoth(0); - areaDutyVo.setOperateRateMoth("0"); - areaDutyVo.setWorkSumMoth(0); - areaDutyVo.setWorkQualifySumMoth(0); - areaDutyVo.setWorkRateMoth("0"); - countDownLatch.countDown(); - return; - } - int operate = ticket.getOperate(); - int operateQualify = ticket.getOperateQualify(); - areaDutyVo.setOperateSumMoth(operate); - areaDutyVo.setOperateQualifySumMoth(operateQualify); - if (operateQualify == 0) { - areaDutyVo.setOperateRateMoth("0"); - } else { - double operateRate = BigDecimal.valueOf(operateQualify / (double)operate * 100L).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - areaDutyVo.setOperateRateMoth(String.valueOf(operateRate)); - } - // 工作票 - int work = ticket.getWork(); - int workQualify = ticket.getWorkQualify(); - areaDutyVo.setWorkSumMoth(work); - areaDutyVo.setWorkQualifySumMoth(workQualify); - if (workQualify == 0) { - areaDutyVo.setWorkRateMoth("0"); - } else { - double workRate = BigDecimal.valueOf(workQualify / (double)work * 100L).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - areaDutyVo.setWorkRateMoth(String.valueOf(workRate)); - } - countDownLatch.countDown(); - }); - - // 等待所有线程执行完成 - try { - countDownLatch.await(); - } catch (InterruptedException e) { - e.printStackTrace(); - Thread.currentThread().interrupt(); - } - exe.shutdown(); - } - - /** - * 上一班组发电量 - * @param dutyList - * @param deviceList - * @param value - * @param areaDutyVo - */ - private void upDutyPower(List dutyList, List deviceList,Long deptId, List value, AreaDutyVo areaDutyVo) { - List list = dutyList.stream().filter(o -> deptId.equals(o.getCreateDept())).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(list)) { - return; - } - NextDutyInfoVo upDutyInfoVo = dutyList.get(0).getUpDutyInfoVo(); - if(ObjectUtil.isEmpty(upDutyInfoVo)){ - return; - } - // 上一班组开始时间、结束时间 - Date startDate = this.dutyStartTime(upDutyInfoVo.getDateTime(),upDutyInfoVo.getStartTime()); - Date endDate = this.dutyEndTime(upDutyInfoVo.getDateTime(),upDutyInfoVo.getStartTime(),upDutyInfoVo.getEndTime()); - // 获取时间断内发电量 - this.dutyPower(startDate,endDate,deviceList,value,areaDutyVo,true); - } - - /** - * 班组实时发电量 - * @param startDate - * @param endDate - * @param deviceList - * @param list - * @param areaDutyVo - */ - private void dutyPower(Date startDate, Date endDate, List deviceList,List list,AreaDutyVo areaDutyVo,boolean flag) { - areaDutyVo.setGeneratingCapacity(0); - List deptList = list.stream().map(StationEntity::getRefDept).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(deptList)){ - return; - } - // 区域站点下设备 - List devices = deviceList.stream().filter(o->deptList.contains(o.getCreateDept())).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(devices)){ - return; - } - // 获取当班时间内发电量 - float generatingCapacity = this.generateByDuty(devices,startDate,endDate); - // 是否为查询上一班组发电量 - if(flag){ - NextDutyInfoVo upDutyInfoVo = areaDutyVo.getUpDutyInfoVo(); - upDutyInfoVo.setGeneratingCapacity(generatingCapacity); - areaDutyVo.setUpDutyInfoVo(upDutyInfoVo); - return; - } - areaDutyVo.setGeneratingCapacity(generatingCapacity); - } - - /*** - * 根据当班时间查询发电量 - * @param devices - * @param start - * @param end - * @return - */ - private float generateByDuty(List devices, Date start, Date end) { - float generate = 0f; - if(CollectionUtil.isEmpty(devices)){ - return generate; - } - for(EminfoAndEmParamVo device : devices ){ - generate += dataService.periodTargetFloat(DateUtil.format(start,DateUtil.PATTERN_DATETIME),DateUtil.format(end,DateUtil.PATTERN_DATETIME),5,3,device.getEmCode(),device.getRideCount(),HomePageConstant.HYDROPOWER_GENERATE_POWER); - } - return generate; - } - - /** - * 当班双票 - * @param startDate - * @param endDate - * @param list - * @param areaDutyVo - */ - private void dutyDoubleTicket(Date startDate,Date endDate, List list,AreaDutyVo areaDutyVo) { - String start = DateUtil.format(startDate,"yyyy-MM") + "-01 00:00:00"; - String end = DateUtil.format(endDate,DateUtil.PATTERN_DATETIME); - if (CollectionUtil.isEmpty(list)) { - areaDutyVo.setWorkTicketCount(0); - areaDutyVo.setHandoverTicketCount(0); - areaDutyVo.setVoidTicketCount(0); - areaDutyVo.setDeferredTicketCount(0); - areaDutyVo.setCloseTicketCount(0); - areaDutyVo.setOperationTicketCount(0); - return; - } - WorkTicketStatisticVO work = workTicketService.work(start,end,list); - if (ObjectUtil.isEmpty(work)) { - areaDutyVo.setWorkTicketCount(0); - areaDutyVo.setHandoverTicketCount(0); - areaDutyVo.setVoidTicketCount(0); - areaDutyVo.setDeferredTicketCount(0); - areaDutyVo.setCloseTicketCount(0); - }else{ - areaDutyVo.setWorkTicketCount(work.getTotal()); - areaDutyVo.setHandoverTicketCount(work.getTransfer()); - areaDutyVo.setVoidTicketCount(work.getInvalid()); - areaDutyVo.setDeferredTicketCount(work.getDelay()); - areaDutyVo.setCloseTicketCount(work.getComplete()); - } - // 查询操作票 - Integer operater = ticketService.operate(start,end,list); - areaDutyVo.setOperationTicketCount(operater); - } - - /** - * 当班运行数据 - * @param startTime - * @param endTime - * @param areas - * @param areaDutyVo - */ - private void dutyRunCondition(Date startTime, Date endTime, List areas,AreaDutyVo areaDutyVo) { - String start = DateUtil.format(startTime,DateUtil.PATTERN_DATETIME); - String end = DateUtil.format(endTime,DateUtil.PATTERN_DATETIME); - // 巡检任务 - DutyInspectTaskVO task = taskService.task(start,end,areas); - areaDutyVo.setInspectionSum(0); - areaDutyVo.setInspectionFinish(0); - if(ObjectUtil.isNotEmpty(task)){ - areaDutyVo.setInspectionSum(task.getInspectTaskSum()); - areaDutyVo.setInspectionFinish(task.getInspectTaskFinish()); - if(Math.abs(task.getInspectTaskSum()) <= 0){ - areaDutyVo.setInspectionFinishRate(0.0); - }else{ - double inspectionFinishRate = BigDecimal.valueOf(task.getInspectTaskFinish() / (double)task.getInspectTaskSum() * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - areaDutyVo.setInspectionFinishRate(inspectionFinishRate); - } - areaDutyVo.setInspectTaskIds(task.getInspectTaskIds()); - } - - // 消缺 - DutyDefectVO defect = phenomenonService.defect(start,end,areas); - areaDutyVo.setShortagesSum(0); - areaDutyVo.setShortages(0); - if(ObjectUtil.isNotEmpty(defect)){ - areaDutyVo.setShortagesSum(defect.getDefectSum()); - areaDutyVo.setShortages(defect.getDefect()); - areaDutyVo.setPhenomenonIds(defect.getTotalIds()); - if(Math.abs(defect.getDefectSum()) <= 0){ - areaDutyVo.setShortagesRate(0.0); - }else{ - double shortagesRate = BigDecimal.valueOf(defect.getDefect() / (double)defect.getDefectSum() * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - areaDutyVo.setShortagesRate(shortagesRate); - } - } - // 定期工作 - RegularWorkVO regular = maintenanceService.regularWork(startTime,endTime,areas); - areaDutyVo.setWorkRegularlySum(0); - areaDutyVo.setWorkRegularly(0); - if(ObjectUtil.isNotEmpty(regular)){ - areaDutyVo.setWorkRegularlySum(regular.getRegularWorkSum()); - areaDutyVo.setWorkRegularly(regular.getRegularWork()); - areaDutyVo.setMainTaskIds(regular.getMainTaskIds()); - if(Math.abs(areaDutyVo.getWorkRegularlySum()) <= 0){ - areaDutyVo.setWorkRegularlyRate(0.0); - }else{ - double workRegularlyRate = BigDecimal.valueOf(areaDutyVo.getWorkRegularly() / (double)areaDutyVo.getWorkRegularlySum() * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - areaDutyVo.setWorkRegularlyRate(workRegularlyRate); - } - } - } - - /** - * 获取运行设备列表 - * @param runDeviceList - * @param realMap - * @return - */ - private List runDevice(List runDeviceList, Map realMap) { - return runDeviceList.stream().map(o ->{ - Map points = o.getPoint(); - if(CollectionUtil.isEmpty(points)){ - return "0"; - } - String realId = points.get(HomePageConstant.JOINT_RELAY); - if(StringUtil.isEmpty(realId)){ - return "0"; - } - if(MapUtils.isEmpty(realMap)){ - return "0"; - } - String value = realMap.get(realId); - if(StringUtil.isEmpty(value)){ - return "0"; - } - if (value.contains("1") || "1.0".equals(value)) { - return o.getEmCode(); - } - return "0"; - }).distinct().collect(Collectors.toList()); - } -} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/SolveServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/SolveServiceImpl.java deleted file mode 100644 index 6d5238a..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/SolveServiceImpl.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation.impl; - -import com.hnac.hzims.operational.fill.entity.SolveEntity; -import com.hnac.hzims.scheduled.mapper.operation.SolveMapper; -import com.hnac.hzims.scheduled.service.operation.SolveService; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springframework.stereotype.Service; - -/** - * @author ysj - */ -@Slf4j -@Service -@AllArgsConstructor -public class SolveServiceImpl extends BaseServiceImpl implements SolveService { - - -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/StationAttrConfigServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/StationAttrConfigServiceImpl.java deleted file mode 100644 index d928365..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/StationAttrConfigServiceImpl.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation.impl; - -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.hnac.hzims.operational.station.entity.StationAttrConfigEntity; -import com.hnac.hzims.scheduled.mapper.operation.StationAttrConfigMapper; -import com.hnac.hzims.scheduled.service.operation.StationAttrConfigService; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springframework.stereotype.Service; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -/** - * @author ysj - */ -@Service -@Slf4j -public class StationAttrConfigServiceImpl extends BaseServiceImpl implements StationAttrConfigService { - - @Override - public List getHideList() { - List list = this.list(new QueryWrapper() {{ - eq("ENABLE_SHOW", false); - eq("IS_DELETED",0); - }}); - if(CollectionUtil.isEmpty(list)){ - return new ArrayList<>(); - } - return list.stream().map(StationAttrConfigEntity::getEmName).collect(Collectors.toList()); - } -} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/StationAttributeServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/StationAttributeServiceImpl.java deleted file mode 100644 index 122278e..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/StationAttributeServiceImpl.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation.impl; - -import com.hnac.hzims.operational.station.entity.StationAttributeEntity; -import com.hnac.hzims.scheduled.mapper.operation.StationAttributeMapper; -import com.hnac.hzims.scheduled.service.operation.StationAttributeService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springframework.stereotype.Service; - -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * @author hx - */ -@Service -@Slf4j -@RequiredArgsConstructor -public class StationAttributeServiceImpl extends BaseServiceImpl implements StationAttributeService { - - /** - * 获取集中监控监测点单位 - * @return - */ - @Override - public Map PointUnit() { - List list = this.baseMapper.PointUnit(); - if(CollectionUtil.isEmpty(list)){ - return null; - } - return list.stream().collect(Collectors.toMap(StationAttributeEntity::getAttributes, StationAttributeEntity::getUnit)); - } -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/StationServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/StationServiceImpl.java deleted file mode 100644 index 8735909..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/StationServiceImpl.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation.impl; - -import com.hnac.hzims.operational.station.entity.StationEntity; -import com.hnac.hzims.scheduled.mapper.operation.StationMapper; -import com.hnac.hzims.scheduled.service.operation.StationService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springframework.stereotype.Service; - -/** - * @author hx - */ -@Service -@RequiredArgsConstructor -@Slf4j -public class StationServiceImpl extends BaseServiceImpl implements StationService { - -} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/UseServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/UseServiceImpl.java deleted file mode 100644 index 82ba5b1..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/impl/UseServiceImpl.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.hnac.hzims.scheduled.service.operation.impl; - -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.hnac.hzims.operational.fill.entity.UseEntity; -import com.hnac.hzims.operational.main.vo.UsrPowerVo; -import com.hnac.hzims.scheduled.mapper.operation.UseMapper; -import com.hnac.hzims.scheduled.service.operation.UseService; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.mp.base.BaseServiceImpl; -import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.DateUtil; -import org.springframework.stereotype.Service; - -import java.util.*; -import java.util.stream.Collectors; - -/** - * @author ysj - * @date 2023/04/10 11:16:07 - * @version 4.0.0 - */ -@Slf4j -@Service -@AllArgsConstructor -public class UseServiceImpl extends BaseServiceImpl implements UseService { - - /** - * 根据时间、机构查询用电量 - * @param date 时间: 年 - yyyy/月 yyyy-mm/日 yyyy-mm-dd - * @param station 所属机构 - * @return - */ - @Override - public Float use(String date, String station) { - List powers = this.list(Wrappers.lambdaQuery() - .likeRight(UseEntity::getFillDate,date) - .eq(UseEntity::getStationCode,station) - ); - if(CollectionUtil.isEmpty(powers)){ - return 0f; - } - return (float) powers.stream().mapToDouble(UseEntity::getEmploy).sum(); - } - - /** - * 查询30天填报用电量 - * @param day : 结束日期 yyyy-MM-dd - * @param station 站点编码 - * @return - */ - @Override - public List use30Day(String day, String station) { - Calendar calendar = Calendar.getInstance(); - calendar.setTime(DateUtil.parse(day,DateUtil.PATTERN_DATE)); - String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); - calendar.add(Calendar.DAY_OF_MONTH,-29); - String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); - List records = this.list(Wrappers.lambdaQuery() - .between(UseEntity::getFillDate,start,end) - .eq(UseEntity::getStationCode,station) - ); - if(CollectionUtil.isEmpty(records)){ - return new ArrayList<>(); - } - return records.stream().map(record->{ - UsrPowerVo use = new UsrPowerVo(); - use.setDate(record.getFillDate()); - if(Math.abs(record.getEmploy()) <= 0){ - use.setUsrPower(0f); - }else{ - use.setUsrPower(Float.parseFloat(record.getEmploy().toString())); - } - return use; - }).collect(Collectors.toList()); - } - - /** - * 查询近3年的填报用电量 - * @param start - * @param end - * @param station - * @return - */ - @Override - public Map generateThreeYear(String start, String end, String station) { - List records = this.list(Wrappers.lambdaQuery() - .between(UseEntity::getFillDate,start,end) - .eq(UseEntity::getStationCode,station) - ); - if(CollectionUtil.isEmpty(records)){ - return new HashMap<>(); - - } - return records.stream().peek(record-> record.setFillDate(DateUtil.format(DateUtil.parse(record.getFillDate(),"yyyy-MM"),"yyyy-MM") + "-01")). - collect(Collectors.toMap(UseEntity::getFillDate, value->Float.parseFloat(value.getEmploy().toString()),Float::sum)); - } - -} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/MonitorService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/MonitorService.java new file mode 100644 index 0000000..f99ee9e --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/MonitorService.java @@ -0,0 +1,21 @@ +package com.hnac.hzims.scheduled.service.operation.monitor; + +import org.springblade.core.tool.api.R; + +import java.util.Map; + +/** + * WEB水电站首页接口 + * @author ysj + */ +public interface MonitorService { + + // realId刷新 + void loadRealId(String param); + + // 实时数据刷新 + void loadRealData(String param); + + // 集中监控数据处理 + void loadMonitoring(String param); +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java new file mode 100644 index 0000000..f50b250 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java @@ -0,0 +1,752 @@ +package com.hnac.hzims.scheduled.service.operation.monitor.impl; + +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.google.common.collect.Lists; +import com.google.common.util.concurrent.ThreadFactoryBuilder; +import com.hnac.hzims.equipment.entity.WorkshopInfoEntity; +import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; +import com.hnac.hzims.fdp.vo.FdpFaultStatusVo; +import com.hnac.hzims.operational.config.entity.StAlarmRecordEntity; +import com.hnac.hzims.operational.config.enume.ConfigStatus; +import com.hnac.hzims.operational.config.vo.StationRealVo; +import com.hnac.hzims.operational.main.constant.HomePageConstant; +import com.hnac.hzims.operational.main.vo.RealAttributeVo; +import com.hnac.hzims.operational.main.vo.RealDeviceVo; +import com.hnac.hzims.operational.main.vo.RealStationVo; +import com.hnac.hzims.operational.station.entity.StationAttributeEntity; +import com.hnac.hzims.operational.station.entity.StationEntity; +import com.hnac.hzims.scheduled.service.equipment.WorkshopInfoService; +import com.hnac.hzims.scheduled.service.operation.alarm.AbnormalAlarmService; +import com.hnac.hzims.scheduled.service.operation.alarm.RecordService; +import com.hnac.hzims.scheduled.service.operation.monitor.MonitorService; +import com.hnac.hzims.scheduled.service.operation.station.StationAttrConfigService; +import com.hnac.hzims.scheduled.service.operation.station.StationAttributeService; +import com.hnac.hzims.scheduled.service.operation.station.StationService; +import com.hnac.hzinfo.datasearch.analyse.IAnalyseDataSearchClient; +import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeCodeBySignagesVO; +import com.hnac.hzinfo.sdk.analyse.po.MultiAnalyzeCodePO; +import com.hnac.hzinfo.sdk.v5.redis.RedisClient; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.MapUtils; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.*; +import org.springblade.system.entity.Dept; +import org.springblade.system.feign.ISysClient; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; + +import java.util.*; +import java.util.concurrent.*; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * 集中监控数据获取实现类 + * @author ysj + */ +@Service +@RequiredArgsConstructor +@Slf4j +public class MonitorServiceImpl implements MonitorService { + + private final RecordService alertService; + private final StationService stationService; + private final StationAttributeService attbtService; + private final WorkshopInfoService workshopInfoService; + private final AbnormalAlarmService abnormalAlarmService; + private final StationAttrConfigService attrConfigService; + private final RedisTemplate redisTemplate; + private final ISysClient sysClient; + private final RedisClient redisClient; + private final IAnalyseDataSearchClient analyseDataSearchClient; + + @Value("${hzims.equipment.emInfo.emInfoList}") + public String device_cache_final; + + @Value("${hzims.operation.realIdKey}") + public String real_cache_final; + + @Value("${hzims.operation.realIdKeyGather}") + public String real_gather_cache_final; + + @Value("${hzims.operation.realIdKeyGather}") + public String real_data_cache_final; + + @Value("${hzims.equipment.fdp.redisData}") + public String fdp_fault_cache_final; + + @Value("${hzims.equipment.fdp.lessThan}") + public Double less_than_cache_final; + + @Value("${hzims.equipment.fdp.greaterThan}") + public Double greater_than_cache_final; + + @Value("${hzims.operation.monitor.realId}") + public String moniter_realId_cache_final; + + @Value("${hzims.operation.monitor.station}") + public String moniter_station_cache_final; + + @Value("${hzims.equipment.fdp.beEqualOrGreaterThan}") + public Double be_equa_cache_final; + + @Value("${hzims.operation.region.deviceClassifyKey}") + private String device_classify_cache_final; + + @Override + public void loadRealId(String param) { + // 所有站点 + List stationList = stationService.list(); + if(CollectionUtil.isEmpty(stationList)){ + return; + } + // 设备监测点list + Object json = redisTemplate.opsForValue().get(device_cache_final); + List eminfoAndEmParams = JSONObject.parseObject(json.toString(), new TypeReference>() {}); + // 厂房监测点list + List wsMonitorList = this.getRealIdByWsCodeAndSign(); + // 实时监控监测点list + List timeList = attbtService.list(new LambdaQueryWrapper() {{ + eq(StationAttributeEntity::getIsDeleted, "0"); + isNotNull(StationAttributeEntity::getMonitorId); + orderByAsc(StationAttributeEntity::getSort); + }}); + // 监测点存储list + List list = new ArrayList<>(); + stationList.forEach(station->{ + StationRealVo stationRealVo = new StationRealVo(); + stationRealVo.setStation(station.getCode()); + List realDeviceList = this.getRealDeviceList(station.getRefDept(),eminfoAndEmParams); + // 厂站匹配站点监测点集合 + List realWsList = wsMonitorList.stream().filter( + o -> Func.isNotEmpty(o.getStation()) && o.getStation().equals(station.getCode()) + ).map(AnalyzeCodeBySignagesVO::getRealId).collect(Collectors.toList()); + // 实时监控匹配站点监测点集合 + List realTimeList = timeList.stream().filter(o -> null != o.getStationId() && o.getStationId().equals(station.getCode())).map(StationAttributeEntity::getMonitorId).collect(Collectors.toList()); + if(CollectionUtil.isNotEmpty(realTimeList)){ + realDeviceList.addAll(realTimeList); + } + if(CollectionUtil.isNotEmpty(realWsList)) { + realDeviceList.addAll(realWsList); + } + if(CollectionUtil.isEmpty(realDeviceList)){ + return; + } + List realList = realDeviceList.stream().distinct().collect(Collectors.toList()); + String[] realArr = StringUtil.join(realList,",").split(","); + stationRealVo.setRealId(realArr); + list.add(stationRealVo); + }); + redisTemplate.opsForValue().set(moniter_realId_cache_final,list); + } + + @Override + public void loadRealData(String param) { + // 获取设备 + List devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_final).toString(),new TypeReference>() {});; + // 设备开关机集合监测点 + List switchOnOff = devices.stream().map(o->{ + Map points = o.getPoint(); + if(CollectionUtil.isEmpty(points)){ + return ""; + } + String jointRelay = points.get(HomePageConstant.JOINT_RELAY); + if(!StringUtil.isEmpty(jointRelay)){ + return jointRelay; + } + String onOff = points.get(HomePageConstant.SWITCH_ON_OFF); + if(!StringUtil.isEmpty(onOff)){ + return onOff; + } + return ""; + }).collect(Collectors.toList()); + // 获取站点缓存数据 + List stationRealVos = (List) redisTemplate.opsForValue().get(moniter_realId_cache_final); + if(CollectionUtil.isEmpty(stationRealVos)){ + return; + } + // 数据切割 + int limit = countStep(stationRealVos.size()); + List> list = Stream.iterate(0, n -> n + 1).limit(limit).parallel().map(a -> stationRealVos.stream().skip((long) a * 5).limit(5).parallel().collect(Collectors.toList())).collect(Collectors.toList()); + ExecutorService pool = Executors.newFixedThreadPool(limit); + // + Map valueMap = new ConcurrentHashMap<>(); + // > + Map> keyMap = new ConcurrentHashMap<>(); + CountDownLatch countDownLatch = new CountDownLatch(limit); + pool.execute(()-> list.forEach(stations -> { + stations.forEach(stationReal -> { + String[] realIdArr = stationReal.getRealId(); + List realIds = Stream.of(realIdArr).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(realIds)){ + return; + } + log.error("real_time_data: {},{}",stationReal.getStation(),realIds); + List objects = redisClient.getBatchRealDataByRealId(stationReal.getStation(),realIds); + for(int i = 0; i < realIds.size() ;i++){ + if(ObjectUtil.isEmpty(objects.get(i))){ + log.error(realIds.get(i) + "is null"); + }else{ + Map attribute = (Map) JSONObject.parse(objects.get(i)); + attribute.put("realId",attribute.get("k")); + attribute.put("value",attribute.get("v")); + attribute.put("time",attribute.get("t")); + attribute.remove("v"); + attribute.remove("k"); + attribute.remove("t"); + this.getCheckMap(attribute,switchOnOff); + valueMap.put(realIdArr[i],attribute.get("value")); + keyMap.put(realIdArr[i],attribute); + } + } + }); + countDownLatch.countDown(); + })); + // 等待所有线程执行完成 + try { + countDownLatch.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + Thread.currentThread().interrupt(); + } + pool.shutdown(); + // redis 存储 + redisTemplate.opsForValue().set(real_cache_final,JSONObject.toJSONString(valueMap)); + redisTemplate.opsForValue().set(real_gather_cache_final,JSONObject.toJSONString(keyMap)); + } + + /** + * 计算切分次数 + */ + private static Integer countStep(Integer size) { + return (size + 5 - 1) / 5; + } + + /** + * 监测点过期数据检查 + * @param value + * @return + */ + private void getCheckMap(Map value,List switchOnOff){ + // 不处理开机状态监测点 + if(switchOnOff.contains(value.get("realId"))){ + return; + } + String time = value.get("time"); + if(StringUtil.isEmpty(time)){ + return; + } + Date date = DateUtil.parse(time,DateUtil.PATTERN_DATETIME); + // 实时数据超出10分钟未刷新,值置为 0 显示 + if(System.currentTimeMillis() - date.getTime() > 10 * 60 * 1000L){ + value.put("value","0"); + } + } + + /** + * 集中监控数据处理 + * @param param + */ + @Override + public void loadMonitoring(String param) { + Thread thread = Thread.currentThread(); + Object json = redisTemplate.opsForValue().get(real_data_cache_final); + if (ObjectUtil.isEmpty(json)) { + return; + } + Map> map = JSONObject.parseObject(json.toString(), new TypeReference>>() { + }); + if (MapUtils.isEmpty(map)) { + return; + } + // 获取所有设备重点属性 + List list = attbtService.list(new LambdaQueryWrapper() {{ + isNotNull(StationAttributeEntity::getStationId); + eq(StationAttributeEntity::getIsDeleted, "0"); + orderByAsc(StationAttributeEntity::getSort); + }}); + if (CollectionUtil.isEmpty(list)) { + return; + } + // 获取所有告警记录 + List alertList = alertService.list(new LambdaQueryWrapper() {{ + orderByDesc(StAlarmRecordEntity::getCreateTime); + }}); + List alarmList = abnormalAlarmService.abnormalAlarms(); + // 获取所有故障记录 + List faultList = this.getFdpFaultAll(); + // 所有设备分类 + Map> deviceClassifyMap = (Map>) redisTemplate.opsForValue().get(device_classify_cache_final); + // 所有设备 + List devices = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_final).toString(),new TypeReference>() {}); + // 根据站点分组 + Map> stationAttbtMap = list.stream().collect(Collectors.groupingBy(StationAttributeEntity::getStationId)); + // 获取站点列表 + List stationEntityList = stationService.list(Wrappers.lambdaQuery() + .in(StationEntity::getCode,new ArrayList<>(stationAttbtMap.keySet()))); + // 隐藏设备列表 + List hideList = attrConfigService.getHideList(); + // 分割,每个map限制10个长度 + List>> handleList = this.mapChunk(stationAttbtMap); + // 创建线程池 + ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("load-monitoring-pool-%d").build(); + ExecutorService pool = new ThreadPoolExecutor(5, 5, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); + CountDownLatch countDownLatch = new CountDownLatch(handleList.size()); + // 所有机构 + R> deptAll = sysClient.getDeptList(); + // 存储数据节点 + List stationList = new CopyOnWriteArrayList<>(); + pool.execute(()->{ + // 线程处理数据 + for(Map> item : handleList){ + item.forEach((key,value)->{ + RealStationVo station = new RealStationVo(); + // 站点编码 + station.setStationCode(key); + // 设置站点状态 + this.setStationStatus(alarmList,station,key); + // 名称、限制水位、服务类型、机构、排序 + this.stationParam(stationEntityList,station,deptAll.getData()); + // 根据设备名称分组 + Map> deviceAttbtMap = value.stream().filter(o -> !hideList.contains(o.getEmName())).collect(Collectors.groupingBy(StationAttributeEntity::getEmName)); + List deviceList = new ArrayList<>(); + // device - 设备,arrbt - 设备重点属性 + deviceAttbtMap.forEach((device, attbt) -> { + RealDeviceVo deviceVo = new RealDeviceVo(); + // 设备名称 + deviceVo.setDeviceName(device); + deviceVo.setDeviceCode(attbt.get(0).getEmCode()); + // 设备处理 + this.handleDevice(attbt, map, deviceVo, alertList, faultList); + deviceList.add(deviceVo); + }); + // 设备状态 + this.getDeviceParam(devices, deviceClassifyMap, deviceList); + station.setDeviceList(deviceList.stream().sorted(Comparator.comparing((RealDeviceVo::getDeviceName))).collect(Collectors.toList())); + stationList.add(station); + }); + countDownLatch.countDown(); + } + }); + // 等待所有线程执行完成 + try { + countDownLatch.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + Thread.currentThread().interrupt(); + } + pool.shutdown(); + redisTemplate.opsForValue().set(moniter_station_cache_final, stationList); + } + + /** + * 设备处理 + * + * @param list + * @param map + * @param device + */ + private void handleDevice(List list, Map> map, + RealDeviceVo device, List alertList, + List faultList) { + if (CollectionUtil.isEmpty(list) || MapUtils.isEmpty(map)) { + return; + } + List attbtList = new ArrayList<>(); + list.forEach(item -> { + RealAttributeVo realAttributeVo = new RealAttributeVo(); + // 设备重点属性处理 : 单条-item + Map real = map.get(item.getMonitorId()); + if(MapUtils.isEmpty(real)){ + realAttributeVo.setName(item.getAttributes()); + realAttributeVo.setType(item.getAttributeType()); + realAttributeVo.setRealId(item.getMonitorId()); + realAttributeVo.setQuality(-1); + realAttributeVo.setStatus(0); + realAttributeVo.setValue("0"); + realAttributeVo.setUnit(item.getUnit()); + attbtList.add(realAttributeVo); + return; + } + realAttributeVo = handleAttbt(item, real, alertList, faultList); + if (ObjectUtil.isEmpty(realAttributeVo)) { + return; + } + attbtList.add(realAttributeVo); + }); + device.setAttbtList(attbtList); + } + + /** + * 获取站点属性 + * @param stationEntityList + * @param item + */ + private void stationParam(List stationEntityList, RealStationVo item,List deptAll) { + if(CollectionUtil.isEmpty(stationEntityList)){ + return; + } + List filterList = stationEntityList.stream().filter(o->item.getStationCode().equals(o.getCode())).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(filterList)){ + return; + } + StationEntity station = filterList.get(0); + if(ObjectUtil.isEmpty(station)){ + return; + } + item.setStationName(station.getName()); + item.setWaterLevelMax(station.getLimitWaterLevel()); + item.setServerType(station.getServeType()); + item.setStationDeptId(station.getRefDept()); + // 排序 + List list = deptAll.stream().filter(o-> station.getRefDept().equals(o.getId())).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(list)){ + return; + } + item.setSort(list.get(0).getSort()); + } + + /** + * 设备参数设置 + * + * @param devices + * @param deviceClassifyMap + * @param deviceList + */ + private void getDeviceParam(List devices, Map> deviceClassifyMap, List deviceList) { + if (CollectionUtil.isEmpty(devices) || CollectionUtil.isEmpty(deviceList) || MapUtils.isEmpty(deviceClassifyMap)) { + return; + } + List faultList = deviceClassifyMap.get(HomePageConstant.FAULT); + List maintaintList = deviceClassifyMap.get(HomePageConstant.MAINTAIN); + List overhaultList = deviceClassifyMap.get(HomePageConstant.OVERHAUL); + List runtList = deviceClassifyMap.get(HomePageConstant.RUN); + List sparetList = deviceClassifyMap.get(HomePageConstant.SPARE); + deviceList.forEach(device -> { + if (StringUtil.isBlank(device.getDeviceCode())) { + device.setState(-1); + return; + } + List list = devices.stream().filter(o -> null != o.getId() && o.getId().toString().equals(device.getDeviceCode())).collect(Collectors.toList()); + if (CollectionUtil.isEmpty(list)) { + device.setState(-1); + return; + } + String deviceCode = list.get(0).getEmCode(); + if (StringUtil.isBlank(deviceCode)) { + device.setState(-1); + return; + } + // 故障 + if (CollectionUtil.isNotEmpty(faultList) && faultList.contains(deviceCode)) { + device.setState(4); + // 保养 + } else if (CollectionUtil.isNotEmpty(maintaintList) && maintaintList.contains(deviceCode)) { + device.setState(3); + // 备用 + } else if (CollectionUtil.isNotEmpty(sparetList) && sparetList.contains(deviceCode)) { + device.setState(2); + // 运行 + } else if (CollectionUtil.isNotEmpty(runtList) && runtList.contains(deviceCode)) { + device.setState(1); + // 检修 + } else if (CollectionUtil.isNotEmpty(overhaultList) && overhaultList.contains(deviceCode)) { + device.setState(0); + // 未知 + } else { + device.setState(-1); + } + }); + } + + /** + * 设备单条重点属性处理 + * + * @param item + * @param real + * @return + */ + private RealAttributeVo handleAttbt(StationAttributeEntity item, Map real, + List alertList, List faultList) { + RealAttributeVo attest = new RealAttributeVo(); + this.setAttbtParam(attest, real); + attest.setRealId(item.getMonitorId()); + attest.setName(item.getAttributes()); + attest.setUnit(item.getUnit()); + attest.setType(item.getAttributeType()); + String value = Optional.ofNullable(attest.getValue()).orElse("-"); + // 正常状态 + attest.setStatus(ConfigStatus.ConfigStatusEnum.NORMAL.getStatus()); + int quality = Optional.ofNullable(attest.getQuality()).orElse(-1); + String time = Optional.ofNullable(attest.getTime()).orElse(""); + // 延时状态 :质量为空 && 时间为空 + if (-1 == quality && StringUtil.isEmpty(time)) { + attest.setStatus(ConfigStatus.ConfigStatusEnum.GRAY.getStatus()); + } + int type = item.getAttributeType(); + switch (type) { + case 1://遥测 + // 预警状态 :value值为"1" && quality值为0 + if ("1".equals(value) && 0 == quality) { + attest.setStatus(ConfigStatus.ConfigStatusEnum.RED.getStatus()); + } + break; + case 2://遥信 + signalyRemote(item, attest, quality, value, alertList); + //处理 + break; + default: + throw new IllegalStateException("Unexpected type: " + type); + } + // 故障信息设置 + accidentDetails(attest, faultList, value); + return attest; + } + + /** + * 设置重点属性参数 + * + * @param attest + * @param real + */ + private void setAttbtParam(RealAttributeVo attest, Map real) { + if (CollectionUtil.isEmpty(real)) { + return; + } + real.forEach((key, value) -> { + if (StringUtil.isBlank(value)) { + return; + } + switch (key) { + case "q": + attest.setQuality(Integer.parseInt(value)); + break; + case "realId": + attest.setRealId(value); + break; + case "value": + attest.setValue(Optional.ofNullable(value).orElse("-")); + break; + case "time": + attest.setTime(value); + break; + default: + break; + } + }); + } + + /** + * 故障信息设置 + * + * @param attest + * @param faultList + * @param value + */ + private void accidentDetails(RealAttributeVo attest, List faultList, String value) { + if (CollectionUtil.isEmpty(faultList) || "-".equals(value)) { + return; + } + List fault = faultList.stream().filter(o -> o.getRealId().equals(attest.getRealId())).collect(Collectors.toList()); + if (CollectionUtil.isEmpty(fault)) { + return; + } + FdpFaultStatusVo fdpFaultStatusVo = fault.get(0); + // 黄色 + if (fdpFaultStatusVo.getValue() > greater_than_cache_final && fdpFaultStatusVo.getValue() < less_than_cache_final) { + attest.setStatus(ConfigStatus.ConfigStatusEnum.YELLOW.getStatus()); + // 橙色 + } else if (fdpFaultStatusVo.getValue() >= be_equa_cache_final) { + attest.setStatus(ConfigStatus.ConfigStatusEnum.ORANGE.getStatus()); + } + attest.setFdpRate(fdpFaultStatusVo.getValue()); + attest.setFdpFaultId(fdpFaultStatusVo.getFaultId()); + attest.setFdpMonitorId(fdpFaultStatusVo.getMonitorId()); + } + + /** + * 重点属性类型-遥信 :数据逻辑处理 + * + * @param attest + */ + private void signalyRemote(StationAttributeEntity item, RealAttributeVo attest, int quality, String strValue, List alertList) { + //需要所有值的数据不为null,并且满足条件才会进去添加数据返回id + if (null == item.getUpUpLimit() || null == item.getDownDownLimit() || null == item.getUpLimit() || null == item.getDownLimit()) { + return; + } + if (-1 == quality) { + return; + } + if (quality != 0) { + return; + } + if ("-".equals(strValue)) { + return; + } + double upup = item.getUpUpLimit(); + double lwlw = item.getDownDownLimit(); + double up = item.getUpLimit(); + double lw = item.getDownLimit(); + //查询出来已处理告警记录 + List handleList = alertList.stream().filter(o -> o.getStationId().equals(item.getStationId()) && o.getRealId().equals(attest.getRealId()) && o.getStatus() == 1).collect(Collectors.toList()); + //查询出来未处理告警记录 + List recordList = alertList.stream().filter(o -> o.getStationId().equals(item.getStationId()) && o.getRealId().equals(attest.getRealId()) && o.getStatus() == 0).collect(Collectors.toList()); + long past = 0L; + double value = Double.parseDouble(strValue); + if (value > upup || value < lwlw) { + if (CollectionUtil.isNotEmpty(handleList)) { + // 现在时间 - 处理时间 + past = System.currentTimeMillis() - handleList.get(0).getProcessTime().getTime(); + } + boolean isOverrun = ((CollectionUtil.isEmpty(handleList) && CollectionUtil.isEmpty(recordList)) || (past / 1000 / 60 > 30 && CollectionUtil.isEmpty(recordList))); + if (isOverrun) { + Long alertId = alertService.insertAlert(item.getStationId(), item.getMonitorId()); + attest.setId(alertId); + attest.setStatus(ConfigStatus.ConfigStatusEnum.YELLOW.getStatus()); + } else if (CollectionUtil.isNotEmpty(recordList)) { + StAlarmRecordEntity record = recordList.get(0); + attest.setId(record.getId()); + // 告警处理完成 + if (record.getProcessTime() != null && record.getStatus() == (byte) 1) { + attest.setStatus(ConfigStatus.ConfigStatusEnum.NORMAL.getStatus()); + // 告警未处理 + } else if (record.getProcessTime() == null && record.getStatus() == (byte) 0) { + attest.setStatus(ConfigStatus.ConfigStatusEnum.HAND_DELAY_STATUS.getStatus()); + } + } + } else if (value > up && value < upup || value < lw && value > lwlw) { + if (CollectionUtil.isNotEmpty(handleList)) { + // 现在时间 - 处理时间 + past = System.currentTimeMillis() - handleList.get(0).getProcessTime().getTime(); + } + boolean exist = ((CollectionUtil.isEmpty(handleList) && CollectionUtil.isEmpty(recordList)) || (past / 1000 / 60 > 30 && CollectionUtil.isEmpty(recordList))); + if (exist){ + Long alertId = alertService.insertAlert(item.getStationId(), item.getMonitorId()); + attest.setId(alertId); + attest.setStatus(ConfigStatus.ConfigStatusEnum.YELLOW.getStatus()); + // 存在告警记录 + } else if (CollectionUtil.isNotEmpty(recordList)) { + StAlarmRecordEntity record = recordList.get(0); + if (recordList.get(0).getStatus() == (byte) 0 && recordList.get(0).getCreateTime() != null) { + attest.setId(record.getId()); + attest.setStatus(ConfigStatus.ConfigStatusEnum.RED.getStatus()); + } else { + attest.setId(recordList.get(0).getId()); + attest.setStatus(ConfigStatus.ConfigStatusEnum.NORMAL.getStatus()); + } + } + } + } + + /** + * 设置站点状态 + * @param alarmList + * @param station + * @param key + */ + private void setStationStatus(List alarmList, RealStationVo station, String key) { + station.setStatus(0); + if(alarmList.contains(key)){ + station.setStatus(1); + } + } + + /** + * 获取所有告警记录 + * + * @return + */ + private List getFdpFaultAll() { + Object json = redisTemplate.opsForValue().get(fdp_fault_cache_final); + if (ObjectUtil.isEmpty(json)) { + return new ArrayList<>(); + } + return (List) json; + } + + /** + * map分割 + * + * @param + * @param + * @param chunkMap + * @return + */ + private List> mapChunk(Map chunkMap) { + if (chunkMap == null) { + return Lists.newArrayList(); + } + Set keySet = chunkMap.keySet(); + Iterator iterator = keySet.iterator(); + int i = 1; + List> total = new ArrayList<>(); + Map tem = new HashMap<>(); + while (iterator.hasNext()) { + k next = iterator.next(); + tem.put(next, chunkMap.get(next)); + if (i == 5) { + total.add(tem); + tem = new HashMap<>(); + i = 0; + } + i++; + } + if (!CollectionUtil.isEmpty(tem)) { + total.add(tem); + } + return total; + } + + /** + * 获取厂房监测点 + * @return + */ + private List getRealIdByWsCodeAndSign() { + List wsInfoList = workshopInfoService.list(); + if(CollectionUtil.isEmpty(wsInfoList)) { + return Lists.newArrayList(); + } + Function getAnalyzeCodePO = wsCode -> { + MultiAnalyzeCodePO multiAnalyzeCodePO = new MultiAnalyzeCodePO(); + multiAnalyzeCodePO.setDeviceCode(wsCode); + multiAnalyzeCodePO.setSignages(Lists.newArrayList(HomePageConstant.PV_JOINT_RELAY,HomePageConstant.PV_REACTIVE_POWER,HomePageConstant.PV_GENERATION_CAPACITY)); + return multiAnalyzeCodePO; + }; + List analyzeCodePOList = wsInfoList.stream().map(WorkshopInfoEntity::getNumber).map(getAnalyzeCodePO).collect(Collectors.toList()); + R> analyzeCodeBySignages = analyseDataSearchClient.getAnalyzeCodeBySignages(analyzeCodePOList); + return Optional.ofNullable(analyzeCodeBySignages).filter(r -> r.isSuccess()).map(R::getData).orElse(Lists.newArrayList()); + } + + /** + * 获取站点realId + * @param refDept + * @param eminfoAndEmParams + * @return + */ + private List getRealDeviceList(Long refDept, List eminfoAndEmParams) { + // 参数检查 + if(CollectionUtil.isEmpty(eminfoAndEmParams) || ObjectUtil.isEmpty(refDept)){ + return new ArrayList<>(); + } + // 有效设备 + List filters = eminfoAndEmParams.stream().filter(o-> o.getCreateDept().equals(refDept)).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(filters)){ + return new ArrayList<>(); + } + // 遍历设备 + List result = new ArrayList<>(); + for(EminfoAndEmParamVo device : filters){ + if(CollectionUtil.isEmpty(device.getPoint())){ + continue; + } + result.addAll(device.getPoint().values()); + } + return result; + } +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/plate/DataService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/plate/DataService.java new file mode 100644 index 0000000..b92f9b8 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/plate/DataService.java @@ -0,0 +1,27 @@ +package com.hnac.hzims.scheduled.service.operation.plate; + +import com.hnac.hzinfo.datasearch.analyse.domain.FieldsData; +import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO; +import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeCodeBySignagesVO; +import com.hnac.hzinfo.sdk.analyse.po.MultiAnalyzeCodePO; +import org.springblade.core.tool.api.R; + +import java.util.List; +import java.util.function.Function; + + +/** + * @author ysj + */ +public interface DataService { + + List getAnalyzeCodeBySignages(Function convert, T resource); + + List analyzeCodeBySignages(List list); + + List getRealDataByAnalyzeCode(String instanceCode, List signages); + + List periodTargetData(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode, String signages); + + Float periodTargetFloat(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode, Integer ride ,String signages); +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/plate/impl/DataServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/plate/impl/DataServiceImpl.java new file mode 100644 index 0000000..8deff01 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/plate/impl/DataServiceImpl.java @@ -0,0 +1,161 @@ +package com.hnac.hzims.scheduled.service.operation.plate.impl; + +import com.google.common.collect.Lists; +import com.hnac.hzims.scheduled.service.operation.plate.DataService; +import com.hnac.hzinfo.datasearch.analyse.IAnalyseDataSearchClient; +import com.hnac.hzinfo.datasearch.analyse.domain.FieldsData; +import com.hnac.hzinfo.datasearch.analyse.po.AnalyseCodeByAnalyseDataPO; +import com.hnac.hzinfo.datasearch.analyse.po.AnalyzeDataConditionPO; +import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO; +import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeCodeBySignagesVO; +import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeDataConditionVO; +import com.hnac.hzinfo.datasearch.real.po.RealDataSearchPO; +import com.hnac.hzinfo.sdk.analyse.po.MultiAnalyzeCodePO; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springblade.core.tool.utils.ObjectUtil; +import org.springblade.core.tool.utils.StringUtil; +import org.springframework.stereotype.Service; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * @author hx + */ +@Service +@AllArgsConstructor +@Slf4j +public class DataServiceImpl implements DataService { + + private final IAnalyseDataSearchClient analyseDataSearchClient; + + @Override + public List getAnalyzeCodeBySignages(Function convert, T resource) { + List result = Lists.newArrayList(); + List multiAnalyzeCodePOList = Lists.newArrayList(resource).stream().map(convert).collect(Collectors.toList()); + R> analyzeCodeBySignResult = analyseDataSearchClient.getAnalyzeCodeBySignages(multiAnalyzeCodePOList); + if(analyzeCodeBySignResult.isSuccess() && CollectionUtil.isNotEmpty(analyzeCodeBySignResult.getData())) { + result = analyzeCodeBySignResult.getData(); + } + return result; + } + + @Override + public List analyzeCodeBySignages(List list) { + R> result = analyseDataSearchClient.getAnalyzeCodeBySignages(list); + if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ + return new ArrayList<>(); + } + return result.getData(); + } + + @Override + public List getRealDataByAnalyzeCode(String instanceCode, List signages) { + RealDataSearchPO realData = new RealDataSearchPO(); + realData.setAnalyzeCode(instanceCode); + realData.setSignages(signages); + // 调用fegin接口查询实时数据 + R> result = analyseDataSearchClient.getRealDataByAnalyzeCode(realData); + if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ + return new ArrayList<>(); + } + return result.getData(); + } + + + /*** + * 指标数据列表查询 + * @param startTime 开始时间 + * @param endTime 结束时间 + * @param accessRules 取数规则 : 0=最早值 1=最大值 2=最小值 3=平均值 4=和值 5=差值 6=最新值 + * @param cycleType 间隔周期 : 0-> 秒 1-> 分 2-> 小时 3->天 4-> 周 5-> 月 6-> 年 + * @param deviceCode 设备编号 + * @param signages 指标 + * @return + */ + @Override + public List periodTargetData(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode, String signages) { + AnalyseCodeByAnalyseDataPO po = new AnalyseCodeByAnalyseDataPO(); + List signboardConditions = new ArrayList<>(); + AnalyzeDataConditionPO analyzeDataConditionPO = new AnalyzeDataConditionPO(); + analyzeDataConditionPO.setFull(1); + po.setDeviceCode(deviceCode); + analyzeDataConditionPO.setSignages(signages); + analyzeDataConditionPO.setKeepFigures(2); + analyzeDataConditionPO.setAccessRules(accessRules); + analyzeDataConditionPO.setSaveTimeType(cycleType); + // 间隔 + analyzeDataConditionPO.setTimeInterval(1); + analyzeDataConditionPO.setBeginTime(LocalDateTime.parse(DateUtil.format(new Date(), startTime), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME))); + analyzeDataConditionPO.setEndTime(LocalDateTime.parse(DateUtil.format(new Date(), endTime), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME))); + signboardConditions.add(analyzeDataConditionPO); + po.setSignboardConditions(signboardConditions); + log.error("period_target_data_request {}",po); + R> result = analyseDataSearchClient.getAnalyzeDataByAnalyzeCodeAndSignages(po); + if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { + return new ArrayList<>(); + } + log.error("period_target_data_resp {}",result); + return result.getData().get(0).getList(); + } + + /*** + * 指标数据列表查询 + * @param startTime 开始时间 + * @param endTime 结束时间 + * @param accessRules 取数规则 : 0=最早值 1=最大值 2=最小值 3=平均值 4=和值 5=差值 6=最新值 + * @param cycleType 间隔周期 : 0-> 秒 1-> 分 2-> 小时 3->天 4-> 周 5-> 月 6-> 年 + * @param deviceCode 设备编号 + * @param ride 配电比 + * @param signages 指标 + * @return + */ + @Override + public Float periodTargetFloat(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode,Integer ride,String signages) { + AnalyseCodeByAnalyseDataPO po = new AnalyseCodeByAnalyseDataPO(); + List signboardConditions = new ArrayList<>(); + AnalyzeDataConditionPO analyzeDataConditionPO = new AnalyzeDataConditionPO(); + analyzeDataConditionPO.setFull(1); + po.setDeviceCode(deviceCode); + analyzeDataConditionPO.setSignages(signages); + analyzeDataConditionPO.setKeepFigures(2); + analyzeDataConditionPO.setAccessRules(accessRules); + analyzeDataConditionPO.setSaveTimeType(cycleType); + // 间隔 + analyzeDataConditionPO.setTimeInterval(1); + analyzeDataConditionPO.setBeginTime(LocalDateTime.parse(DateUtil.format(new Date(), startTime), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME))); + analyzeDataConditionPO.setEndTime(LocalDateTime.parse(DateUtil.format(new Date(), endTime), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME))); + signboardConditions.add(analyzeDataConditionPO); + po.setSignboardConditions(signboardConditions); + R> result = analyseDataSearchClient.getAnalyzeDataByAnalyzeCodeAndSignages(po); + if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { + return 0f; + } + List records = result.getData(); + if(CollectionUtil.isEmpty(records)){ + return 0f; + } + AnalyzeDataConditionVO analyzeDataConditionVO = records.get(0); + if (ObjectUtil.isEmpty(analyzeDataConditionVO)) { + return 0f; + } + List analyseDataTaosVOList = analyzeDataConditionVO.getList(); + if (CollectionUtil.isEmpty(analyseDataTaosVOList)) { + return 0f; + } + AnalyseDataTaosVO analyseDataTaosVO = analyzeDataConditionVO.getList().get(0); + if (ObjectUtil.isEmpty(analyseDataTaosVO) || StringUtil.isBlank(analyseDataTaosVO.getVal())) { + return 0f; + } + return Float.parseFloat(Optional.ofNullable(analyseDataTaosVO.getVal()).orElse("0")) * ride; + } + + +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/report/ReportService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/report/ReportService.java new file mode 100644 index 0000000..2612f12 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/report/ReportService.java @@ -0,0 +1,9 @@ +package com.hnac.hzims.scheduled.service.operation.report; + +/** + * @author ysj + */ +public interface ReportService { + + void loadMonthReport(String param, int i); +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/report/impl/ReportServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/report/impl/ReportServiceImpl.java new file mode 100644 index 0000000..c257cbf --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/report/impl/ReportServiceImpl.java @@ -0,0 +1,531 @@ +package com.hnac.hzims.scheduled.service.operation.report.impl; + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.google.common.util.concurrent.ThreadFactoryBuilder; +import com.hnac.hzims.equipment.entity.PlanGenerationEntity; +import com.hnac.hzims.message.dto.MailPushDto; +import com.hnac.hzims.message.fegin.IPushMsgClient; +import com.hnac.hzims.operational.main.constant.HomePageConstant; +import com.hnac.hzims.operational.main.vo.AreaMonthReportVo; +import com.hnac.hzims.operational.main.vo.MaintainVo; +import com.hnac.hzims.operational.main.vo.OverhaulVo; +import com.hnac.hzims.operational.report.vo.DutyDefectVO; +import com.hnac.hzims.operational.station.entity.StationEntity; +import com.hnac.hzims.safeproduct.dto.SafeEquipmentTrialDTO; +import com.hnac.hzims.scheduled.service.equipment.PlanService; +import com.hnac.hzims.scheduled.service.inspect.TaskService; +import com.hnac.hzims.scheduled.service.operation.business.AccessService; +import com.hnac.hzims.scheduled.service.operation.business.MaintenanceService; +import com.hnac.hzims.scheduled.service.operation.business.PhenomenonService; +import com.hnac.hzims.scheduled.service.operation.station.StationService; +import com.hnac.hzims.scheduled.service.operation.report.ReportService; +import com.hnac.hzims.scheduled.service.safeproduct.MonthService; +import com.hnac.hzims.scheduled.service.safeproduct.TrialService; +import com.hnac.hzims.scheduled.service.ticket.TicketService; +import com.hnac.hzims.ticket.workTicket.vo.TicketMonthVO; +import com.hnac.hzinfo.inspect.task.vo.DutyInspectTaskVO; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.MapUtils; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springblade.core.tool.utils.ObjectUtil; +import org.springblade.core.tool.utils.StringUtil; +import org.springblade.system.entity.Dept; +import org.springblade.system.feign.ISysClient; +import org.springblade.system.user.entity.User; +import org.springblade.system.user.feign.IUserClient; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.*; +import java.util.concurrent.*; +import java.util.stream.Collectors; + +/** + * @author ysj + */ +@Service +@RequiredArgsConstructor +@Slf4j +public class ReportServiceImpl implements ReportService { + + private final PlanService planService; + private final TaskService taskService; + private final TrialService trialService; + private final AccessService accessService; + private final TicketService ticketService; + private final StationService stationService; + private final MonthService monthService; + private final PhenomenonService phenomenonService; + private final MaintenanceService maintenanceService; + private final RedisTemplate redisTemplate; + private final ISysClient sysClient; + private final IUserClient userClient; + private final IPushMsgClient pushMsgClient; + + private final static String recent_year_cache_final = "hzims:operation:key:power:data"; + + @Value("${hzims.operation.area.report}") + private String report_month_cache_final; + + + /** + * 区域-月报 + * @param param + * @param year + */ + @Override + public void loadMonthReport(String param, int year) { + // 获取所有机构 + R> R = sysClient.getDeptList(); + if (!R.isSuccess() || CollectionUtil.isEmpty(R.getData())) { + return; + } + // 查询所有服务类型——"运维服务"、站点类型——"水电站" + List stations = stationService.list(Wrappers.lambdaQuery() + .eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE) + .eq(StationEntity::getType,HomePageConstant.HYDROPOWER) + ); + if (CollectionUtil.isEmpty(stations)) { + return; + } + // 站点近年发电数据 + Map> powerMap = (Map>) redisTemplate.opsForValue().get(recent_year_cache_final); + // 存储数据节点 key - 月份 value - 区域数据集合 + Map> map = new HashMap<>(); + // 月份集合 + List monthList = getMonthList(year, Calendar.getInstance().get(Calendar.MONTH)); + monthList.forEach(mon -> { + List list = this.getAreaReportByMon(R.getData(), powerMap, stations, mon); + if (CollectionUtil.isEmpty(list)) { + return; + } + map.put(mon, list); + }); + // 推送当月报表邮件 + this.sendMonthReport(map, R.getData()); + redisTemplate.opsForValue().set(report_month_cache_final, map); + } + + /** + * 获取近年月份集合 + * + * @param year + * @return + */ + public static List getMonthList(int year, int endMoth) { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM"); + // 开始日期 + Calendar endCal = Calendar.getInstance(); + endCal.setTime(new Date()); + endCal.add(Calendar.MONTH, -endCal.get(Calendar.MONTH) + endMoth); + endCal.add(Calendar.DATE, -endCal.get(Calendar.DATE) + 1); + + // 结束日期 + Calendar startCal = Calendar.getInstance(); + startCal.setTime(new Date()); + startCal.set(Calendar.YEAR, startCal.get(Calendar.YEAR) - year); + startCal.add(Calendar.MONTH, -startCal.get(Calendar.MONTH)); + startCal.add(Calendar.DATE, -startCal.get(Calendar.DATE) + 1); + // 获取日期之间的月份 + List list = new ArrayList<>(); + while (endCal.after(startCal)) { + list.add(format.format(startCal.getTime())); + startCal.add(Calendar.MONTH, 1); + } + list.add(format.format(endCal.getTime())); + return list; + } + + /** + * 区域月报数据加载 + * @param deptList + * @param powerMap + * @param stationList + * @param mon + * @return + */ + private List getAreaReportByMon(List deptList, Map> powerMap, List stationList, String mon) { + LocalDateTime startTime = LocalDateTime.parse(mon + "-01 00:00:00", DateUtil.DATETIME_FORMATTER); + LocalDateTime endTime = getEndTime(mon); + // 查询所有站点的计划发电量 + List planList = this.planPower(stationList, mon); + // 站点实际发电量 + Map actualMap = this.actualPower(powerMap, stationList, mon + "-01"); + // 站点去年发电量 + Map oldActualMap = this.actualPower(powerMap, stationList, lastyear(1,mon)); + // 站点前发电量 + Map oldOldActualMap = this.actualPower(powerMap, stationList, lastyear(2,mon)); + // 取机构中区域部分 + List areaList = deptList.stream().filter(o -> o.getDeptCategory().equals(3)).collect(Collectors.toList()); + if (CollectionUtil.isEmpty(areaList)) { + return null; + } + List areaMonthReportVoList = new ArrayList<>(); + areaList.forEach(area -> { + AreaMonthReportVo areaMonthReport = new AreaMonthReportVo(); + areaMonthReport.setAreaId(area.getId()); + areaMonthReport.setAreaName(area.getDeptName()); + // 获取区域下的站点 + List stationIdList = deptList.stream().filter(o -> o.getParentId().equals(area.getId()) && o.getDeptCategory().equals(4)).map(Dept::getId).collect(Collectors.toList()); + List areaStationList = stationList.stream().filter(o -> stationIdList.contains(o.getRefDept())).collect(Collectors.toList()); + if (CollectionUtil.isEmpty(areaStationList)) { + return; + } + // 计划发电量、实际发电量、发电完成率 + this.powerMonth(planList, actualMap, oldActualMap, areaStationList, areaMonthReport); + // 操作票、操作票合格率/ 工作票、工作票合格率 + this.doubleMonth(area, areaMonthReport, mon + "-01 00:00:00", this.strEndTime(mon)); + // 日常维护、巡检任务、缺陷数、消缺率、检修任务 + this.taskMonth(Collections.singletonList(area.getId()), areaMonthReport, mon + "-01 00:00:00", strEndTime(mon)); + // 预测 + this.predictPlanPower(oldActualMap,oldOldActualMap,areaStationList,areaMonthReport); + // 安全生产会议次数、月度检查报告、技能培训、安全大检查 + this.securityCheck(Collections.singletonList(area.getId()),areaMonthReport,mon + "-01 00:00:00", strEndTime(mon)); + // 设备试验 + this.getDeviceTry(mon + "-01 00:00:00", strEndTime(mon), Collections.singletonList(area.getId()),areaMonthReport); + areaMonthReportVoList.add(areaMonthReport); + }); + return areaMonthReportVoList; + } + + /** + * 获取结束时间 + */ + private LocalDateTime getEndTime(String mon) { + Date date = DateUtil.parse(mon + "-01 00:00:00",DateUtil.DATETIME_FORMAT); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + calendar.add(Calendar.MONTH, 1); + return calendar.getTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); + } + + /** + * 获取站点计划发电量 + */ + private List planPower(List stationList, String mon) { + List list = stationList.stream().map(StationEntity::getCode).collect(Collectors.toList()); + return planService.planGeneration(list, null, mon); + } + + /** + * 获取站点月份实际发电量 + */ + private Map actualPower(Map> powerMap, List stationList, String month) { + if (MapUtils.isEmpty(powerMap)) { + return null; + } + // 站点Id集合 + List stationIdList = stationList.stream().map(StationEntity::getId).collect(Collectors.toList()); + // 存储站点实际发电量 + Map actualPowerMap = new HashMap<>(); + stationIdList.forEach(key -> { + Map monthMap = powerMap.get(key); + if (MapUtils.isEmpty(monthMap)) { + return; + } + float actualPower = 0f; + if(ObjectUtil.isNotEmpty(monthMap.get(month))){ + actualPower = monthMap.get(month); + } + actualPowerMap.put(key, actualPower); + }); + return actualPowerMap; + } + + /** + * 获取去年时间 + */ + private String lastyear(int year,String mon) { + Date date = DateUtil.parse(mon + "-01 00:00:00",DateUtil.DATETIME_FORMAT); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - year); + calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); + return DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + } + + /** + * 获取结束时间 + */ + private String strEndTime(String mon) { + Date date = DateUtil.parse(mon + "-01 00:00:00",DateUtil.DATETIME_FORMAT); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + calendar.add(Calendar.MONTH, 1); + return DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE); + } + + /** + * 区域-月计划发电量、月实际发电量、月发电完成率、同比 + * + * @param planList + * @param actualMap + * @param oldActualMap + * @param areaStationList + * @param areaMonthReport + */ + private void powerMonth(List planList, Map actualMap, Map oldActualMap, List areaStationList, AreaMonthReportVo areaMonthReport) { + // 计划发电量 + List codeList = areaStationList.stream().map(StationEntity::getCode).collect(Collectors.toList()); + double planPower = planList.stream().filter(o -> codeList.contains(o.getStationId())).mapToDouble(PlanGenerationEntity::getPlanGeneration).sum(); + areaMonthReport.setPlanPower(Float.parseFloat(String.valueOf(planPower))); + if (MapUtils.isEmpty(actualMap)) { + areaMonthReport.setActualPower(0f); + areaMonthReport.setPowerFinishRate(0.0); + return; + } + // 实际发电量 + List ids = areaStationList.stream().map(StationEntity::getId).collect(Collectors.toList()); + double actualPower = actualMap.entrySet().stream().filter(e -> ids.contains(e.getKey())).mapToDouble(Map.Entry::getValue).sum(); + areaMonthReport.setActualPower(Float.parseFloat(String.valueOf(actualPower))); + if (Math.abs(planPower) <= 0) { + areaMonthReport.setPowerFinishRate(0.0); + } else { + // 发电完成率 + double powerFinishRate = BigDecimal.valueOf(actualPower / planPower * 100).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); + areaMonthReport.setPowerFinishRate(powerFinishRate); + } + // 同比 + double oldActualPower = oldActualMap.entrySet().stream().filter(e -> ids.contains(e.getKey())).mapToDouble(Map.Entry::getValue).sum(); + if (Math.abs(actualPower) <= 0 || Math.abs(oldActualPower) <= 0) { + areaMonthReport.setComparePowerRate(0.0); + return; + } + double comparePowerRate = BigDecimal.valueOf(actualPower / oldActualPower).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + areaMonthReport.setComparePowerRate(comparePowerRate); + } + + /** + * 区域-操作票、操作票合格率/ 工作票、工作票合格率 + * + * @param area + * @param areaMonthReport + */ + private void doubleMonth(Dept area, AreaMonthReportVo areaMonthReport, String startTime, String endTime) { + // 站点归属机构集合 + TicketMonthVO ticket = ticketService.operateWork(startTime,endTime,Collections.singletonList(area.getId())); + if (ObjectUtil.isEmpty(ticket)) { + areaMonthReport.setOperate(0); + areaMonthReport.setOperaQualifyRate(0.0); + areaMonthReport.setWork(0); + areaMonthReport.setWorkQualifyRate(0.0); + return; + } + // 操作票 + int operate = ticket.getOperate(); + int operateQualify = ticket.getOperateQualify(); + areaMonthReport.setOperate(operate); + if (operateQualify <= 0) { + areaMonthReport.setOperaQualifyRate(0.0); + } else { + double operateQualifyRate = BigDecimal.valueOf(operateQualify / (double) operate * 100L).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); + areaMonthReport.setOperaQualifyRate(operateQualifyRate); + } + //工作票 + int work = ticket.getWork(); + int workQualify = ticket.getWorkQualify(); + areaMonthReport.setWork(work); + if (workQualify <= 0) { + areaMonthReport.setWorkQualifyRate(0.0); + } else { + double workQualifyRate = BigDecimal.valueOf(workQualify / (double) work * 100L).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); + areaMonthReport.setWorkQualifyRate(workQualifyRate); + } + } + + /** + * 任务月报-日常维护、巡检任务、缺陷数、消缺率、检修任务 + * + * @param areas + * @param areaMonthReport + */ + private void taskMonth(List areas, AreaMonthReportVo areaMonthReport, String startTime, String endTime) { + //通过线程池异步获取月报各模块内容 主要分为五块内容 + ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("area_month_report-pool-%d").build(); + ExecutorService exe = new ThreadPoolExecutor(4, 4, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); + //监控线程执行完后返回结果 + CountDownLatch countDownLatch = new CountDownLatch(4); + // 日常维护 + exe.execute(() -> { + MaintainVo maintainVo = maintenanceService.maintain(startTime, endTime, areas); + int maintainSum = maintainVo.getMaintain(); + areaMonthReport.setRoutineMaintenance(maintainSum); + countDownLatch.countDown(); + }); + + // 巡检任务 + exe.execute(() -> { + DutyInspectTaskVO task = taskService.task(startTime,endTime,areas); + if (ObjectUtil.isEmpty(task)) { + areaMonthReport.setInspect(0); + } else { + int inspect = task.getInspectTaskSum(); + areaMonthReport.setInspect(inspect); + } + countDownLatch.countDown(); + }); + + // 消缺 + exe.execute(() -> { + DutyDefectVO defectVO = phenomenonService.defect(startTime, endTime, areas); + int defectSum = defectVO.getDefectSum(); + int defect = defectVO.getDefect(); + areaMonthReport.setDefect(defectSum); + if (defectSum <= 0) { + areaMonthReport.setDefectRate(0.0); + } else { + double deletionRate = BigDecimal.valueOf(defect / defectSum * 100L).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); + areaMonthReport.setDefectRate(deletionRate); + } + countDownLatch.countDown(); + }); + + // 检修 + exe.execute(() -> { + OverhaulVo overhaulVo = accessService.overhaul(startTime, endTime, areas); + int overhaul = overhaulVo.getOverhaul(); + areaMonthReport.setMaintenanceTasks(overhaul); + countDownLatch.countDown(); + }); + + //所有模板数据获取完成后释放锁 + try { + countDownLatch.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + Thread.currentThread().interrupt(); + } + exe.shutdown(); + } + + /** + * 预测发电量 + * @param oldActualMap + * @param oldOldActualMap + * @param areaStationList + * @param areaMonthReport + */ + private void predictPlanPower(Map oldActualMap, Map oldOldActualMap, List areaStationList, AreaMonthReportVo areaMonthReport) { + areaMonthReport.setPredictPlanPower(0.0); + // 实际发电量 + List ids = areaStationList.stream().map(StationEntity::getId).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(ids)){ + return; + } + double oldActualPower = oldActualMap.entrySet().stream().filter(e -> ids.contains(e.getKey())).mapToDouble(Map.Entry::getValue).sum(); + double oldOldActualPower = oldOldActualMap.entrySet().stream().filter(e -> ids.contains(e.getKey())).mapToDouble(Map.Entry::getValue).sum(); + if(Math.abs(oldActualPower) <= 0 && Math.abs(oldOldActualPower) <= 0 ){ + return; + } + double predictPlanPower = BigDecimal.valueOf((oldActualPower + oldOldActualPower) / 2).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + areaMonthReport.setPredictPlanPower(predictPlanPower); + } + + /** + * 安全检查 + * @param areas + * @param areaMonthReport + * @param startTime + * @param endTime + */ + private void securityCheck(List areas, AreaMonthReportVo areaMonthReport,String startTime,String endTime) { + areaMonthReport.setSafetyMeeting(0); + areaMonthReport.setSelfReport(0); + areaMonthReport.setSkillTrainy(0); + areaMonthReport.setSecurityCheck(0); + // 站点归属机构集合 + Map map = new HashMap<>(); + map.put("startDate", startTime); + map.put("endDate", endTime); + map.put("deptList", areas); + // 调用安全大检查fegin接口 + Map count = monthService.check(map); + if(MapUtils.isEmpty(count)){ + return; + } + // 安全生产会议 + areaMonthReport.setSafetyMeeting((Integer) count.get("safetyMeetingNum")); + // 月度自查报告 + areaMonthReport.setSelfReport((Integer) count.get("monthCheckNum")); + // 技能培训 + areaMonthReport.setSkillTrainy((Integer) count.get("skillsTrainingNum")); + // 安全大检查 + areaMonthReport.setSecurityCheck((Integer) count.get("bigCheckNum")); + } + + /** + * 获取设备试验数据 + * @param startTime + * @param endTime + * @param areas + * @param areaMonthReport + */ + private void getDeviceTry(String startTime,String endTime,List areas,AreaMonthReportVo areaMonthReport) { + areaMonthReport.setDeviceTry(0); + SafeEquipmentTrialDTO request = new SafeEquipmentTrialDTO(); + request.setDeptList(areas); + request.setStartTime(startTime); + request.setEndTime(endTime); + areaMonthReport.setDeviceTry(trialService.count(request)); + } + + /** + * 推送当月月报 + * + * @param map + * @param list + */ + private void sendMonthReport(Map> map, List list) { + if (MapUtils.isEmpty(map) || CollectionUtil.isEmpty(list)) { + return; + } + // 获取邮件接收人 + Dept dept = list.stream().min(Comparator.comparing(Dept::getDeptCategory)).get(); + if(ObjectUtil.isEmpty(dept)){ + return; + } + R> userR = userClient.userListByDeptAndChildrenWithAuth(dept.getId()); + if(!userR.isSuccess() && CollectionUtil.isEmpty(userR.getData())){ + return; + } + List userList = userR.getData().stream().filter(o->dept.getId().equals(o.getCreateDept())).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(userList)){ + return; + } + List mailList = userList.stream().map(User::getEmail).filter(StringUtil::isNotBlank).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(mailList)){ + return; + } + // 获取月报数据 + List entityList = map.get(DateUtil.format(new Date(),"yyyy-MM")); + if (CollectionUtil.isEmpty(entityList)) { + return; + } + // 发送邮件 + MailPushDto pushDto = new MailPushDto(); + pushDto.setBusinessClassify("system"); + pushDto.setBusinessKey("Month_Report"); + pushDto.setSubject("水电站生产运行"); + Map param = new HashMap<>(); + param.put("templatePath", "/data/hzims/message/mail/template/stationRunMonthReport.html"); + Map parameters = new HashMap<>(); + parameters.put("data",entityList); + param.put("parameters", parameters); + pushDto.setExtras(param); + pushDto.setText("水电站生产运行月报内容"); + pushDto.setToAccount(mailList.toArray(new String[0])); + pushDto.setHtml(true); + pushDto.setCreateUser(userR.getData().get(0).getCreateUser()); + pushDto.setTenantId(dept.getTenantId()); + pushDto.setCreateDept(dept.getId()); + pushMsgClient.sendMail(pushDto); + } +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/station/StationAttrConfigService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/station/StationAttrConfigService.java new file mode 100644 index 0000000..88e090d --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/station/StationAttrConfigService.java @@ -0,0 +1,14 @@ +package com.hnac.hzims.scheduled.service.operation.station; + +import com.hnac.hzims.operational.station.entity.StationAttrConfigEntity; +import org.springblade.core.mp.base.BaseService; + +import java.util.List; + +/** + * @author ysj + */ +public interface StationAttrConfigService extends BaseService { + + List getHideList(); +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/station/StationAttributeService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/station/StationAttributeService.java new file mode 100644 index 0000000..ea2bd01 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/station/StationAttributeService.java @@ -0,0 +1,14 @@ +package com.hnac.hzims.scheduled.service.operation.station; + +import com.hnac.hzims.operational.station.entity.StationAttributeEntity; +import org.springblade.core.mp.base.BaseService; + +import java.util.Map; + +/** + * @author hx + */ +public interface StationAttributeService extends BaseService { + + Map PointUnit(); +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/station/StationService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/station/StationService.java new file mode 100644 index 0000000..2ff95b0 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/station/StationService.java @@ -0,0 +1,12 @@ +package com.hnac.hzims.scheduled.service.operation.station; + +import com.hnac.hzims.operational.station.entity.StationEntity; +import org.springblade.core.mp.base.BaseService; + +/** + * @author ysj + */ +public interface StationService extends BaseService { + + +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/station/impl/StationAttrConfigServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/station/impl/StationAttrConfigServiceImpl.java new file mode 100644 index 0000000..ccb7340 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/station/impl/StationAttrConfigServiceImpl.java @@ -0,0 +1,34 @@ +package com.hnac.hzims.scheduled.service.operation.station.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.hnac.hzims.operational.station.entity.StationAttrConfigEntity; +import com.hnac.hzims.scheduled.mapper.operation.StationAttrConfigMapper; +import com.hnac.hzims.scheduled.service.operation.station.StationAttrConfigService; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author ysj + */ +@Service +@Slf4j +public class StationAttrConfigServiceImpl extends BaseServiceImpl implements StationAttrConfigService { + + @Override + public List getHideList() { + List list = this.list(new QueryWrapper() {{ + eq("ENABLE_SHOW", false); + eq("IS_DELETED",0); + }}); + if(CollectionUtil.isEmpty(list)){ + return new ArrayList<>(); + } + return list.stream().map(StationAttrConfigEntity::getEmName).collect(Collectors.toList()); + } +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/station/impl/StationAttributeServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/station/impl/StationAttributeServiceImpl.java new file mode 100644 index 0000000..629e2c6 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/station/impl/StationAttributeServiceImpl.java @@ -0,0 +1,36 @@ +package com.hnac.hzims.scheduled.service.operation.station.impl; + +import com.hnac.hzims.operational.station.entity.StationAttributeEntity; +import com.hnac.hzims.scheduled.mapper.operation.StationAttributeMapper; +import com.hnac.hzims.scheduled.service.operation.station.StationAttributeService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * @author hx + */ +@Service +@Slf4j +@RequiredArgsConstructor +public class StationAttributeServiceImpl extends BaseServiceImpl implements StationAttributeService { + + /** + * 获取集中监控监测点单位 + * @return + */ + @Override + public Map PointUnit() { + List list = this.baseMapper.PointUnit(); + if(CollectionUtil.isEmpty(list)){ + return null; + } + return list.stream().collect(Collectors.toMap(StationAttributeEntity::getAttributes, StationAttributeEntity::getUnit)); + } +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/station/impl/StationServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/station/impl/StationServiceImpl.java new file mode 100644 index 0000000..e93135d --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/station/impl/StationServiceImpl.java @@ -0,0 +1,19 @@ +package com.hnac.hzims.scheduled.service.operation.station.impl; + +import com.hnac.hzims.operational.station.entity.StationEntity; +import com.hnac.hzims.scheduled.mapper.operation.StationMapper; +import com.hnac.hzims.scheduled.service.operation.station.StationService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +/** + * @author hx + */ +@Service +@RequiredArgsConstructor +@Slf4j +public class StationServiceImpl extends BaseServiceImpl implements StationService { + +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/resources/mapper/operation/MaintenancePlanMapper.xml b/hzims-service/hzims-scheduled/src/main/resources/mapper/operation/MaintenancePlanMapper.xml new file mode 100644 index 0000000..55abbd2 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/resources/mapper/operation/MaintenancePlanMapper.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WindHomeServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WindHomeServiceImpl.java index a7143b1..b286fdb 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WindHomeServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WindHomeServiceImpl.java @@ -43,7 +43,6 @@ import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.StringUtil; import org.springblade.system.entity.Dept; -import org.springblade.system.entity.Region; import org.springblade.system.feign.ISysClient; import org.springblade.system.user.cache.UserCache; import org.springblade.system.user.entity.User; diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskCreateTask.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskCreateTask.java index a85c2f0..f721f5c 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskCreateTask.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/scheduled/MaintenanceTaskCreateTask.java @@ -59,7 +59,7 @@ public class MaintenanceTaskCreateTask { private final IOperMaintenanceTaskService taskService; private final IImsDutyMainService mainService; private final RedisTemplate redisTemplate; - private final IMessageClient messageClient; + 1 private final BladeLogger logger; diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/vo/OperMaintenanceTaskEntityVo.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/vo/OperMaintenanceTaskEntityVo.java deleted file mode 100644 index 67d23bb..0000000 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/maintenance/vo/OperMaintenanceTaskEntityVo.java +++ /dev/null @@ -1,222 +0,0 @@ -package com.hnac.hzims.operational.maintenance.vo; - -import com.fasterxml.jackson.annotation.JsonFormat; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import org.springblade.core.tool.utils.DateUtil; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; -import java.util.Date; - -/** - * 日常维护对象 - * @Author WL - * @Version v1.0 - * @Serial 1.0 - * @Date 2023/6/13 17:20 - */ -@Data -public class OperMaintenanceTaskEntityVo { - - - private static final long serialVersionUID = 1L; - - - /** - * 主键id - */ - @ApiModelProperty(value = "主键id") - private Long id; - - /** - * 创建人 - */ - private Long createUser; - - /** - * 创建部门 - */ - @ApiModelProperty(value = "创建部门") - private Long createDept; - - /** - * 创建时间 - */ - @DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME) - @JsonFormat(pattern = DateUtil.PATTERN_DATETIME) - @ApiModelProperty(value = "创建时间") - private Date createTime; - - /** - * 更新人 - */ - private Long updateUser; - - /** - * 更新时间 - */ - @DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME) - @JsonFormat(pattern = DateUtil.PATTERN_DATETIME) - @ApiModelProperty(value = "更新时间") - private Date updateTime; - - /** - * 状态[1:正常] - */ - @ApiModelProperty(value = "业务状态") - private Integer status; - - - /** - * 设备编码 - */ - @ApiModelProperty(value = "设备编码") - private String emCode; - /** - * 维护类型 01=定期试验 02=定期保养 03=定期操作 04=其他 - */ - @ApiModelProperty(value = "维护类型 01=定期试验 02=定期保养 03=定期操作 04=其他") - private String typeCode; - /** - * 任务编码 - */ - @ApiModelProperty(value = "任务编码,后台自动生成") - private String taskCode; - /** - * 维护项目 - */ - @ApiModelProperty(value = "维护项目") - private Long refLibraryId; - - /** - * 维护标题 - */ - @ApiModelProperty(value = "维护标题") - private String title; - /** - * 工作流实例ID - */ - @ApiModelProperty(value = "工作流实例ID") - private String processInstanceId; - - - /** - * 执行人 - */ - @ApiModelProperty(value = "执行人") - private String disposer; - /** - * 执行日期 - */ - @ApiModelProperty(value = "任务按周期生成计划时间") - private Date disposeTime; - - @ApiModelProperty(value = "执行时间") - private LocalDateTime executeTime; - /** - * 标准工时 - */ - @ApiModelProperty(value = "标准工时") - private Integer hours; - /** - * 实际工时 - */ - @ApiModelProperty(value = "实际工时") - private Integer actHours; - /** - * 维护内容 - */ - @ApiModelProperty(value = "维护内容") - private String content; - /** - * 操作规范 - */ - @ApiModelProperty(value = "操作规范") - private String workStandards; - /** - * 安全警告 - */ - @ApiModelProperty(value = "安全警告") - private String safo; - /** - * 是否异常 0=否 1=是 - */ - @ApiModelProperty(value = "是否异常 0=否 1=是") - private Integer isAnomaly; - /** - * 遗留问题 - */ - @ApiModelProperty(value = "遗留问题") - private String legacy; - /** - * 问题描述 - */ - @ApiModelProperty(value = "问题描述") - private String description; - - @ApiModelProperty(value = "任务类型") - private String taskType; - - @ApiModelProperty(value = "票据ID") - private Long ticketId; - - @ApiModelProperty(value = "延期状态") - private Integer delayStatus; - - @ApiModelProperty(value = "延期时间") - private LocalDateTime delayDate; - - @ApiModelProperty(value = "计划结束时间") - @DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME) - @JsonFormat(pattern = DateUtil.PATTERN_DATETIME) - private LocalDateTime planEndTime; - - @ApiModelProperty("计划ID") - private Long planId; - - @ApiModelProperty(value = "消息推送模板ID") - private Long messageTemplateId; - - - /** - * 流程状态' - */ - @ApiModelProperty("流程状态") - private Integer flowStatus; - - /** - * 流程描述 - */ - @ApiModelProperty("流程描述") - private String flowDescription; - - - - /** - * 下一个审批人 - */ - @ApiModelProperty("下一个审批人") - private String nextStepOperator; - - - /** - * 用户Id - */ - @ApiModelProperty("用户Id") - private String flowUserId; - - - /** - * 当前任务名 - */ - @ApiModelProperty("当前任务名") - private String flowTaskName; - - - /** - * 当前任务名 - */ - @ApiModelProperty("当前任务名") - private String flowTaskId; -}