diff --git a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/feign/IThreeElectricClient.java b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/feign/IThreeElectricClient.java new file mode 100644 index 0000000..5c6f309 --- /dev/null +++ b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/feign/IThreeElectricClient.java @@ -0,0 +1,36 @@ +package com.hnac.hzims.electric.feign; + +import com.hnac.hzims.EquipmentConstants; +import com.hnac.hzims.electric.entity.ThreeEntity; +import com.hnac.hzims.equipment.entity.ThreeGenerationEntity; +import com.hnac.hzims.monitor.feign.IMonitorClientBack; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import java.util.List; + +/** + * @author ysj + */ +@FeignClient( + value = EquipmentConstants.APP_NAME, + fallback = IMonitorClientBack.class +) +public interface IThreeElectricClient { + + String API_PREFIX = "/threeElectric"; + String ELECTRICS = API_PREFIX + "/electrics"; + + /** + * 设备运行时长 + * @param stationId + * @param startTime + * @param endTime + * @return + */ + @GetMapping(ELECTRICS) + List electrics(@RequestParam(value = "stationId") String stationId, + @RequestParam(value = "year") String year); + +} diff --git a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/feign/IThreeElectricClientBack.java b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/feign/IThreeElectricClientBack.java new file mode 100644 index 0000000..69a92e6 --- /dev/null +++ b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/electric/feign/IThreeElectricClientBack.java @@ -0,0 +1,21 @@ +package com.hnac.hzims.electric.feign; + +import com.hnac.hzims.electric.entity.ThreeEntity; +import com.hnac.hzims.equipment.entity.ThreeGenerationEntity; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author ysj + */ +@Component +public class IThreeElectricClientBack implements IThreeElectricClient { + + + @Override + public List electrics(String stationId, String year) { + return new ArrayList<>(); + } +} diff --git a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/vo/StartStopGenerateVO.java b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/vo/StartStopGenerateVO.java new file mode 100644 index 0000000..18eb28e --- /dev/null +++ b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/vo/StartStopGenerateVO.java @@ -0,0 +1,28 @@ +package com.hnac.hzims.equipment.vo; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.NullSerializer; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + + +/** + * @author ysj + */ +@Data +public class StartStopGenerateVO{ + + @ApiModelProperty(value = "站点编码集合") + @JsonSerialize(nullsUsing = NullSerializer.class) + private List stations; + + @ApiModelProperty(value = "开始时间") + @JsonSerialize(nullsUsing = NullSerializer.class) + private String start; + + @ApiModelProperty(value = "结束时间") + @JsonSerialize(nullsUsing = NullSerializer.class) + private String end; +} \ No newline at end of file diff --git a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/entity/StartStopDurationEntity.java b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/startStop/entity/StartStopDurationEntity.java similarity index 96% rename from hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/entity/StartStopDurationEntity.java rename to hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/startStop/entity/StartStopDurationEntity.java index 815fcb3..009971d 100644 --- a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/equipment/entity/StartStopDurationEntity.java +++ b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/startStop/entity/StartStopDurationEntity.java @@ -1,4 +1,4 @@ -package com.hnac.hzims.equipment.entity; +package com.hnac.hzims.startStop.entity; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; diff --git a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/startStop/feign/IStartStopClient.java b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/startStop/feign/IStartStopClient.java new file mode 100644 index 0000000..d46706f --- /dev/null +++ b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/startStop/feign/IStartStopClient.java @@ -0,0 +1,33 @@ +package com.hnac.hzims.startStop.feign; + +import com.hnac.hzims.EquipmentConstants; +import com.hnac.hzims.monitor.feign.IMonitorClientBack; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * @author ysj + */ +@FeignClient( + value = EquipmentConstants.APP_NAME, + fallback = IMonitorClientBack.class +) +public interface IStartStopClient { + + String API_PREFIX = "/startStop"; + String DEVICE_START_STOP_DURATION = API_PREFIX + "/deviceDuration"; + + /** + * 设备运行时长 + * @param deviceCode + * @param startTime + * @param endTime + * @return + */ + @GetMapping(DEVICE_START_STOP_DURATION) + Double deviceDuration(@RequestParam(value = "deviceCode") String deviceCode, + @RequestParam(value = "startTime") String startTime, + @RequestParam(value = "endTime") String endTime); + +} diff --git a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/startStop/feign/IStartStopClientBack.java b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/startStop/feign/IStartStopClientBack.java new file mode 100644 index 0000000..ce2085a --- /dev/null +++ b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/startStop/feign/IStartStopClientBack.java @@ -0,0 +1,15 @@ +package com.hnac.hzims.startStop.feign; + +import org.springframework.stereotype.Component; + +/** + * @author ysj + */ +@Component +public class IStartStopClientBack implements IStartStopClient { + + @Override + public Double deviceDuration(String deviceCode, String startTime, String endTime) { + return 0.0; + } +} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/HomePageConstant.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/HomePageConstant.java index 89db1fa..f69b8e2 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/HomePageConstant.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/HomePageConstant.java @@ -152,7 +152,7 @@ public interface HomePageConstant { // 水利-泵组实时属性名称 String JOINT_RELAY = "joint_relay"; // 开机状态 - String START_STOP_STATUS = "power_on"; // 开关机状态 + String START_STOP_STATUS = "dlqhw"; // 断路器合位 String SWITCH_ON_OFF = "switch_on_off"; // 开机状态 String OFF = "1.0"; // 开机 String OFF_COMPLEX = "1"; // 开机 diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/feign/ThreeElectricClient.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/feign/ThreeElectricClient.java new file mode 100644 index 0000000..4c93dba --- /dev/null +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/feign/ThreeElectricClient.java @@ -0,0 +1,30 @@ +package com.hnac.hzims.electric.feign; + +import com.hnac.hzims.electric.entity.ThreeEntity; +import com.hnac.hzims.electric.service.ThreeService; +import com.hnac.hzims.equipment.entity.ThreeGenerationEntity; +import com.hnac.hzims.startStop.feign.IStartStopClient; +import com.hnac.hzims.startStop.service.IStartStopDurationService; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * @author ysj + */ +@RestController +@AllArgsConstructor +public class ThreeElectricClient implements IThreeElectricClient { + + + private final ThreeService service; + + + @Override + @GetMapping(ELECTRICS) + public List electrics(String stationId, String year) { + return service.electrics(stationId,year); + } +} diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/ThreeService.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/ThreeService.java index 77e6ab2..cd9e8a3 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/ThreeService.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/ThreeService.java @@ -1,11 +1,15 @@ package com.hnac.hzims.electric.service; import com.hnac.hzims.electric.entity.ThreeEntity; +import com.hnac.hzims.equipment.entity.ThreeGenerationEntity; import org.springblade.core.mp.base.BaseService; +import java.util.List; + /** * @author ysj */ public interface ThreeService extends BaseService { + List electrics(String stationId, String year); } \ No newline at end of file diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/impl/ThreeServiceImpl.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/impl/ThreeServiceImpl.java index 9f3be12..3394e44 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/impl/ThreeServiceImpl.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/electric/service/impl/ThreeServiceImpl.java @@ -1,13 +1,17 @@ package com.hnac.hzims.electric.service.impl; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hnac.hzims.electric.entity.ThreeEntity; import com.hnac.hzims.electric.mapper.ThreeMapper; import com.hnac.hzims.electric.service.ThreeService; +import com.hnac.hzims.equipment.entity.ThreeGenerationEntity; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.mp.base.BaseServiceImpl; import org.springframework.stereotype.Service; +import java.util.List; + /** * @author ysj */ @@ -17,4 +21,17 @@ import org.springframework.stereotype.Service; public class ThreeServiceImpl extends BaseServiceImpl implements ThreeService { + /** + * 查询站点年发电量 + * @param stationId + * @param year + * @return + */ + @Override + public List electrics(String stationId, String year) { + return this.list(Wrappers.lambdaQuery() + .eq(ThreeEntity::getStationId,stationId) + .like(ThreeEntity::getStrMonth,year) + ); + } } diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/startStop/feign/StartStopClient.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/startStop/feign/StartStopClient.java new file mode 100644 index 0000000..a9f28c4 --- /dev/null +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/startStop/feign/StartStopClient.java @@ -0,0 +1,24 @@ +package com.hnac.hzims.startStop.feign; + +import com.hnac.hzims.startStop.service.IStartStopDurationService; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author ysj + */ +@RestController +@AllArgsConstructor +public class StartStopClient implements IStartStopClient { + + + private final IStartStopDurationService service; + + + @Override + @GetMapping(DEVICE_START_STOP_DURATION) + public Double deviceDuration(String deviceCode, String startTime, String endTime) { + return service.deviceDuration(deviceCode,startTime,endTime); + } +} diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/startStop/mapper/StartStopDurationMapper.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/startStop/mapper/StartStopDurationMapper.java new file mode 100644 index 0000000..8e405ad --- /dev/null +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/startStop/mapper/StartStopDurationMapper.java @@ -0,0 +1,13 @@ +package com.hnac.hzims.startStop.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hnac.hzims.startStop.entity.StartStopDurationEntity; +import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; + + +/** + * @author ysj + */ +public interface StartStopDurationMapper extends BaseMapper { + +} diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/startStop/mapper/StartStopDurationMapper.xml b/hzims-service/equipment/src/main/java/com/hnac/hzims/startStop/mapper/StartStopDurationMapper.xml new file mode 100644 index 0000000..5f68e24 --- /dev/null +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/startStop/mapper/StartStopDurationMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/startStop/service/IStartStopDurationService.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/startStop/service/IStartStopDurationService.java new file mode 100644 index 0000000..04372d8 --- /dev/null +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/startStop/service/IStartStopDurationService.java @@ -0,0 +1,13 @@ +package com.hnac.hzims.startStop.service; + + +import com.baomidou.mybatisplus.extension.service.IService; +import com.hnac.hzims.startStop.entity.StartStopDurationEntity; + +/** + * @author ysj + */ +public interface IStartStopDurationService extends IService { + + Double deviceDuration(String deviceCode, String startTime, String endTime); +} diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/startStop/service/impl/StartStopDurationServiceImpl.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/startStop/service/impl/StartStopDurationServiceImpl.java new file mode 100644 index 0000000..64ee64e --- /dev/null +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/startStop/service/impl/StartStopDurationServiceImpl.java @@ -0,0 +1,44 @@ +package com.hnac.hzims.startStop.service.impl; + + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.hnac.hzims.startStop.entity.StartStopDurationEntity; +import com.hnac.hzims.startStop.mapper.StartStopDurationMapper; +import com.hnac.hzims.startStop.service.IStartStopDurationService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springframework.stereotype.Service; + +import java.util.List; + + +/** + * @author ysj + */ +@Service +@AllArgsConstructor +@Slf4j +public class StartStopDurationServiceImpl extends ServiceImpl implements IStartStopDurationService { + + /** + * 查询设备开停机时长 + * @param deviceCode + * @param startTime + * @param endTime + * @return + */ + @Override + public Double deviceDuration(String deviceCode, String startTime, String endTime) { + List durations = this.list(Wrappers.lambdaQuery() + .eq(StartStopDurationEntity::getDeviceCode,deviceCode) + .ge(StartStopDurationEntity::getStrDay,startTime) + .le(StartStopDurationEntity::getStrDay,endTime) + ); + if(CollectionUtil.isEmpty(durations)){ + return 0.0; + } + return durations.stream().mapToDouble(StartStopDurationEntity::getStartDuration).sum(); + } +} diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/service/impl/AlarmConfigDetailServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/service/impl/AlarmConfigDetailServiceImpl.java index b3dd0b6..2a34deb 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/service/impl/AlarmConfigDetailServiceImpl.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/config/service/impl/AlarmConfigDetailServiceImpl.java @@ -91,19 +91,6 @@ public class AlarmConfigDetailServiceImpl extends ServiceImpl com.hnac.hzims alarm-api - 4.0.0-SNAPSHOT com.hnac.hzims diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/ScheduledApplication.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/ScheduledApplication.java index a14fbe8..9d10145 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/ScheduledApplication.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/ScheduledApplication.java @@ -1,16 +1,9 @@ package com.hnac.hzims.scheduled; import org.mybatis.spring.annotation.MapperScan; -import org.springblade.core.cloud.feign.EnableBladeFeign; import org.springblade.core.launch.BladeApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -import org.springframework.cloud.client.SpringCloudApplication; import org.springframework.cloud.openfeign.EnableFeignClients; -import org.springframework.context.annotation.ComponentScan; - -import javax.annotation.Resource; /** @@ -21,7 +14,7 @@ import javax.annotation.Resource; @EnableFeignClients(basePackages = {"org.springblade", "com.hnac"}) public class ScheduledApplication { public static void main(String[] args) { - BladeApplication.run("hzims-scheduled", ScheduledApplication.class, args); + BladeApplication.run("hzims-scheduled-ysj", ScheduledApplication.class, args); } -} +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/controller/ScheduledController.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/controller/ScheduledController.java new file mode 100644 index 0000000..14dbb84 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/controller/ScheduledController.java @@ -0,0 +1,34 @@ +package com.hnac.hzims.scheduled.controller; + + +import com.hnac.hzims.equipment.vo.StartStopGenerateVO; +import com.hnac.hzims.scheduled.service.equipment.StartStopDurationService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.*; + + +/** + * @author ysj + */ +@Slf4j +@RequestMapping("/scheduled") +@RestController +@RequiredArgsConstructor +public class ScheduledController { + + private final StartStopDurationService service; + + /** + * 开停机时长统计接口 + * @param param + * @return + */ + @PostMapping("/startStopGenerate") + public R startStopGenerate(@RequestBody StartStopGenerateVO param) { + return R.status(service.startStopGenerate(param)); + } + + +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/alarm/ConfigDetailMapper.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/alarm/ConfigDetailMapper.java new file mode 100644 index 0000000..eed4292 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/alarm/ConfigDetailMapper.java @@ -0,0 +1,11 @@ +package com.hnac.hzims.scheduled.mapper.alarm; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hnac.hzims.alarm.config.entity.AlarmConfigDetailEntity; + +/** + * @author ysj + */ +public interface ConfigDetailMapper extends BaseMapper { + +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/alarm/ConfigMapper.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/alarm/ConfigMapper.java new file mode 100644 index 0000000..2cc5e35 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/alarm/ConfigMapper.java @@ -0,0 +1,11 @@ +package com.hnac.hzims.scheduled.mapper.alarm; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hnac.hzims.alarm.config.entity.AlarmConfigEntity; + +/** + * @author ysj + */ +public interface ConfigMapper extends BaseMapper { + +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/alarm/HandleMapper.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/alarm/HandleMapper.java index 4e6a789..a6845de 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/alarm/HandleMapper.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/alarm/HandleMapper.java @@ -12,5 +12,10 @@ import java.util.List; * @version 4.0.0 */ public interface HandleMapper extends UserDataScopeBaseMapper { + List handles(@Param("start") String start,@Param("end") String end); + + List sameDayContent(@Param("start") String start,@Param("end") String end,@Param("code") String code); + + List incompleteContent(@Param("end") String end,@Param("code") String code); } diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/equipment/StartStopDurationMapper.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/equipment/StartStopDurationMapper.java index 56cbb06..e44e5bd 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/equipment/StartStopDurationMapper.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/equipment/StartStopDurationMapper.java @@ -1,7 +1,7 @@ package com.hnac.hzims.scheduled.mapper.equipment; -import com.hnac.hzims.equipment.entity.StartStopDurationEntity; +import com.hnac.hzims.startStop.entity.StartStopDurationEntity; import org.apache.ibatis.annotations.Param; import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/AlarmScheduledTask.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/AlarmScheduledTask.java index 4e502cc..e656371 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/AlarmScheduledTask.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/AlarmScheduledTask.java @@ -11,7 +11,8 @@ import org.springframework.stereotype.Component; import java.util.Date; -import static com.hnac.hzims.operational.main.constant.MainConstants.*; +import static com.hnac.hzims.operational.main.constant.MainConstants.CLEAR_HISTORY_ALARM; +import static com.hnac.hzims.operational.main.constant.MainConstants.INTERRUPT_ALARM; /** @@ -41,28 +42,12 @@ public class AlarmScheduledTask { } /** - * 开停机告警 - * @return ReturnT - */ - @XxlJob(START_STOP_ALARM) - //@Scheduled(cron = "0/40 * * * * ? ") - - public ReturnT startStopAlarm(String param) { - if (Func.isBlank(param)) { - param = DateUtil.format(new Date(), "yyyy-MM"); - } - alarmService.startStopAlarm(param); - return new ReturnT<>("SUCCESS"); - } - - /** * 数据通讯中断 * @param param * @return */ @XxlJob(INTERRUPT_ALARM) //@Scheduled(cron = "0/40 * * * * ? ") - public ReturnT interruption(String param) { if (Func.isBlank(param)) { param = DateUtil.format(new Date(), "yyyy-MM"); diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/AlarmDefaulConfigService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/AlarmDefaulConfigService.java deleted file mode 100644 index f9fbe25..0000000 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/AlarmDefaulConfigService.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.hnac.hzims.scheduled.service.alarm; - -import com.baomidou.mybatisplus.extension.service.IService; -import com.hnac.hzims.alarm.config.entity.AlarmDefaultConfigEntity; - - -/** - * @author ysj - */ -public interface AlarmDefaulConfigService extends IService { - -} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/AlarmService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/AlarmService.java index bb58700..17ffd20 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/AlarmService.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/AlarmService.java @@ -5,8 +5,6 @@ package com.hnac.hzims.scheduled.service.alarm; */ public interface AlarmService { - void startStopAlarm(String param); - void clearHistoryAlarm(String param); void interruption(String param); diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/ConfigDetailService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/ConfigDetailService.java new file mode 100644 index 0000000..04137fb --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/ConfigDetailService.java @@ -0,0 +1,16 @@ +package com.hnac.hzims.scheduled.service.alarm; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.hnac.hzims.alarm.config.entity.AlarmConfigDetailEntity; +import com.hnac.hzims.alarm.config.entity.AlarmConfigEntity; +import com.hnac.hzims.alarm.config.vo.AlarmConfigSourceVo; +import com.hnac.hzims.alarm.config.vo.AlarmHandleMarkVo; + +import java.util.List; + +/** + * @author ysj + */ +public interface ConfigDetailService extends IService { + +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/ConfigService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/ConfigService.java new file mode 100644 index 0000000..72ba60d --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/ConfigService.java @@ -0,0 +1,13 @@ +package com.hnac.hzims.scheduled.service.alarm; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.hnac.hzims.alarm.config.entity.AlarmConfigEntity; +import com.hnac.hzims.alarm.config.vo.AlarmHandleMarkVo; + +/** + * @author ysj + */ +public interface ConfigService extends IService { + + AlarmHandleMarkVo mark(String code,Integer source,Integer type); +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/DefaulConfigService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/DefaulConfigService.java new file mode 100644 index 0000000..cf7d93d --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/DefaulConfigService.java @@ -0,0 +1,14 @@ +package com.hnac.hzims.scheduled.service.alarm; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.hnac.hzims.alarm.config.entity.AlarmDefaultConfigEntity; +import com.hnac.hzims.alarm.config.vo.AlarmHandleMarkVo; + + +/** + * @author ysj + */ +public interface DefaulConfigService extends IService { + + AlarmHandleMarkVo defaultMark(Integer source, Integer type); +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/HandleService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/HandleService.java index 65b2524..8a1e0bd 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/HandleService.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/HandleService.java @@ -19,4 +19,8 @@ import java.util.List; public interface HandleService extends BaseService { List handles(); + + List sameDayContent(String code); + + List incompleteContent(String code); } diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/AlarmQueryService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/QueryService.java similarity index 80% rename from hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/AlarmQueryService.java rename to hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/QueryService.java index fe68a2d..f42015d 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/AlarmQueryService.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/QueryService.java @@ -9,7 +9,7 @@ import java.util.List; /** * @author ysj */ -public interface AlarmQueryService extends IService { +public interface QueryService extends IService { void clear(String param); diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/AlarmServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/AlarmServiceImpl.java index fd8b449..9c76de1 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/AlarmServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/AlarmServiceImpl.java @@ -1,19 +1,16 @@ package com.hnac.hzims.scheduled.service.alarm.impl; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hnac.hzims.alarm.config.constants.AlarmConstants; import com.hnac.hzims.alarm.config.entity.AlarmDefaultConfigEntity; import com.hnac.hzims.alarm.config.entity.AlarmEntity; -import com.hnac.hzims.alarm.config.vo.SystemAlarmVo; +import com.hnac.hzims.alarm.config.vo.AlarmHandleMarkVo; import com.hnac.hzims.business.interruption.constants.InterruptionConstants; import com.hnac.hzims.business.interruption.entity.InterruptionEntity; -import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.main.vo.HydropowerUnitRealVo; import com.hnac.hzims.operational.station.entity.StationEntity; -import com.hnac.hzims.scheduled.service.alarm.AlarmDefaulConfigService; -import com.hnac.hzims.scheduled.service.alarm.AlarmQueryService; -import com.hnac.hzims.scheduled.service.alarm.AlarmService; +import com.hnac.hzims.scheduled.service.alarm.*; import com.hnac.hzims.scheduled.service.operation.station.StationService; import com.hnac.hzinfo.datasearch.soe.ISoeClient; import com.hnac.hzinfo.datasearch.soe.domian.SoeData; @@ -22,15 +19,16 @@ import com.hnac.hzinfo.sdk.core.response.HzPage; import com.hnac.hzinfo.sdk.core.response.Result; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springblade.core.tool.jackson.JsonUtil; import org.springblade.core.tool.utils.*; import org.springblade.mqtt.producer.IMqttSender; import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; /** @@ -41,11 +39,13 @@ import java.util.stream.Collectors; @Slf4j public class AlarmServiceImpl implements AlarmService { + private final HandleService handleService; + private final StationService stationService; - private final AlarmQueryService alarmQueryService; + private final QueryService queryService; - private final AlarmDefaulConfigService defaulConfigService; + private final ConfigService alarmConfigService; private final InterruptionAlarmServiceImpl interruptionAlarmService; @@ -53,84 +53,13 @@ public class AlarmServiceImpl implements AlarmService { private final RedisTemplate redisTemplate; + private final StringRedisTemplate stringRedisTemplate; + private final IMqttSender mqttSender; private final static String start_stop_cache_final = "hzims:operation:start:stop:key"; private final static String load_hydropower_unit_real_key = "hzims:operation:loadhydropowerunit:real:key"; - /** - * 开停机告警 - * @param param - */ - @Override - public void startStopAlarm(String param) { - // 获取站点开关机状态 - Map startStopMap = (HashMap) redisTemplate.opsForValue().get(start_stop_cache_final); - - // 查询接入水电站点 - List stations = stationService.list(new LambdaQueryWrapper() - .eq(StationEntity::getDataOrigin,0) - .eq(StationEntity::getType, HomePageConstant.HYDROPOWER) - ); - if(CollectionUtil.isEmpty(stations)){ - return; - } - // 查询开关机默认告警配置 - AlarmDefaultConfigEntity start = defaulConfigService.getOne(Wrappers.lambdaQuery() - .eq(AlarmDefaultConfigEntity::getSource,6) - .eq(AlarmDefaultConfigEntity::getAlarmChiledType,60) - ); - AlarmDefaultConfigEntity stop = defaulConfigService.getOne(Wrappers.lambdaQuery() - .eq(AlarmDefaultConfigEntity::getSource,6) - .eq(AlarmDefaultConfigEntity::getAlarmChiledType,61) - ); - // 获取站点设备实时数据 - List reals = (List) redisTemplate.opsForValue().get(load_hydropower_unit_real_key); - if(CollectionUtil.isEmpty(reals)){ - return; - } - Map refresh = new HashMap<>(); - // 实时设备遍历 - reals.forEach(real->{ - // 过滤站点 - List list = stations.stream().filter(item -> item.getRefDept().equals(real.getDeptId())).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(list)){ - return; - } - // 确定站点 - StationEntity station = list.get(0); - - // 数据初始化记录 - if(CollectionUtil.isEmpty(startStopMap)){ - if(Math.abs(real.getActivePower()) > 0){ - refresh.put(real.getDeviceCode(),1); - }else{ - refresh.put(real.getDeviceCode(),0); - } - return; - } - // 比对开机状态 - if(real.getActivePower() > 0){ - if(startStopMap.containsKey(real.getDeviceCode()) && startStopMap.get(real.getDeviceCode()) == 0){ - refresh.put(real.getDeviceCode(),1); - // 记录开机告警 - this.saveStartStopAlarm(station,real,start,1); - }else{ - refresh.put(real.getDeviceCode(),1); - } - }else{ - if(startStopMap.containsKey(real.getDeviceCode()) && startStopMap.get(real.getDeviceCode()) == 1){ - refresh.put(real.getDeviceCode(),0); - // 记录关机告警 - this.saveStartStopAlarm(station,real,stop,0); - }else{ - refresh.put(real.getDeviceCode(),0); - } - } - }); - redisTemplate.opsForValue().set(start_stop_cache_final,refresh); - } - /** * 清理历史告警数据 @@ -138,7 +67,7 @@ public class AlarmServiceImpl implements AlarmService { */ @Override public void clearHistoryAlarm(String param) { - this.alarmQueryService.clear(param); + this.queryService.clear(param); } /** @@ -147,7 +76,7 @@ public class AlarmServiceImpl implements AlarmService { * @param real * @param state */ - private void saveStartStopAlarm(StationEntity station, HydropowerUnitRealVo real,AlarmDefaultConfigEntity defaultConfig, int state) { + private void saveStartStopAlarm(StationEntity station, HydropowerUnitRealVo real, AlarmDefaultConfigEntity defaultConfig, int state) { AlarmEntity alarm = new AlarmEntity(); alarm.setStationId(station.getCode()); alarm.setStationName(station.getName()); @@ -187,7 +116,7 @@ public class AlarmServiceImpl implements AlarmService { alarm.setCreateUser(station.getCreateUser()); alarm.setUpdateUser(station.getUpdateUser()); alarm.setUpdateTime(station.getUpdateTime()); - this.alarmQueryService.save(alarm); + this.queryService.save(alarm); } @@ -226,7 +155,7 @@ public class AlarmServiceImpl implements AlarmService { // 查询当天数据中断告警记录 List saves = this.saveInterruptions(stations.stream().map(StationEntity::getCode).collect(Collectors.toList())); List entities = soes.stream().filter( - o -> (CollectionUtil.isEmpty(saves) || !saves.stream().map(itr -> itr.getStationId() + itr.getRealId() + itr.getAlarmTime()).collect(Collectors.toList()).contains(o.getStation() + o.getRealId() + o.getTs())) + o -> (CollectionUtil.isEmpty(saves) || !saves.stream().map(InterruptionEntity::getAlarmId).collect(Collectors.toList()).contains(o.getId())) && StringUtil.isNotBlank(o.getStation())).map(soe->{ InterruptionEntity entity = new InterruptionEntity(); Optional optional = stations.stream().filter(o->o.getCode().equals(soe.getStation())).findFirst(); @@ -256,30 +185,96 @@ public class AlarmServiceImpl implements AlarmService { } // 批量保存中断告警数据 this.interruptionAlarmService.saveBatch(entities); - // 发送HZ3000中通讯告警 - this.sendInterruptionMsg(entities); + + // 保存通讯中断告警 + entities.forEach(this::alarmSave); } - /** - * 发送HZ3000中通讯告警 - * @param entities - */ - private void sendInterruptionMsg(List entities) { - entities.forEach(entity->{ - SystemAlarmVo alarm = new SystemAlarmVo(); - if(ObjectUtil.isEmpty(entity.getId())){ - alarm.setId(DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME_MINI)); - }else{ - alarm.setId(String.valueOf(entity.getId())); + + public Boolean alarmSave(InterruptionEntity entity) { + AlarmEntity alarm = new AlarmEntity(); + alarm.setAlarmId(entity.getAlarmId().toString()); + ZoneId zoneId = ZoneId.systemDefault(); + LocalDateTime localDateTime = LocalDateTime.ofInstant(entity.getAlarmTime().toInstant(), zoneId); + alarm.setAlarmTime(localDateTime); + alarm.setAlarmContext(entity.getSoeExplain()); + alarm.setAlarmType(Integer.valueOf(entity.getType())); + alarm.setAlarmStatus(entity.getStatus()); + alarm.setStationId(entity.getStationId()); + alarm.setRealId(entity.getRealId()); + alarm.setAlarmSource(AlarmConstants.HZ3000_ALARM); + + // 步骤1.查询告警数据对应站点 + StationEntity station = stationService.getOne(Wrappers.lambdaQuery().eq(StationEntity::getCode,alarm.getStationId())); + if(ObjectUtil.isEmpty(station)){ + return false; + } + + // 步骤2.查询当天处理的告警 + List handlers = handleService.sameDayContent(station.getCode()); + // 步骤3.查询延后未完成的告警 + List delays = handleService.incompleteContent(station.getCode()); + // 步骤4.近5分钟内告警 + Set keys = stringRedisTemplate.keys("hzims:queue:filter:alarm" + "*"); + // 步骤5.遍历保存告警数据 + // 告警已处理 + if(CollectionUtil.isNotEmpty(handlers) && handlers.contains(alarm.getAlarmContext())){ + return false; + } + // 告警已延后处理 + if(CollectionUtil.isNotEmpty(delays) && delays.contains(alarm.getAlarmContext())){ + return false; + } + // 告警站点名称截取 + if(StringUtil.isNotBlank(alarm.getAlarmContext()) && !AlarmConstants.CONDITION_ALARM.equals(alarm.getAlarmSource()) && !AlarmConstants.INTERRUPT.equals(alarm.getAlarmType()) + && !AlarmConstants.ABNORMAL.equals(alarm.getAlarmType())){ + String[] countext = alarm.getAlarmContext().split("\\."); + alarm.setAlarmContext(countext[countext.length - 1]); + } + // 近5分钟内告警重复 + if(CollectionUtil.isNotEmpty(keys)){ + for (String key : keys) { + String value = stringRedisTemplate.opsForValue().get(key); + if (value.equals(station.getName()+alarm.getAlarmContext())){ + return false; + } } - alarm.setTs(entity.getAlarmTime().getTime()); - alarm.setType(Integer.parseInt(entity.getType())); - alarm.setStation(entity.getStationId()); - alarm.setRealId(entity.getRealId()); - alarm.setContext(entity.getSoeExplain()); - alarm.setState(entity.getStatus()); - mqttSender.sendToMqtt(InterruptionConstants.HZ3000_TOPIC_PREFIX + entity.getStationId(), JsonUtil.toJson(alarm)); - }); + } + // 步骤3.站点参数设置 + alarm.setCreateDept(station.getCreateDept()); + alarm.setStationName(station.getName()); + alarm.setTenantId(station.getTenantId()); + if(StringUtil.isNotBlank(alarm.getAlarmValue()) && alarm.getAlarmValue().length() > 2048){ + alarm.setAlarmValue(alarm.getAlarmValue().substring(0,2048)); + } + alarm.setStatus(0); + // 步骤4.根据站点查询配置标识 + AlarmHandleMarkVo mark = alarmConfigService.mark(alarm.getStationId(),alarm.getAlarmSource(),alarm.getAlarmType()); + if(ObjectUtil.isEmpty(mark)){ + log.error("alarm_obtain_mark_is_null : {}",alarm.getAlarmId()); + return false; + } + // 步骤5.告警处理标识赋值 + alarm.setIsRightTabulation(mark.getIsRightTabulation()); + alarm.setIsBroadcast(mark.getIsBroadcast()); + alarm.setIsMask(mark.getIsMask()); + alarm.setIsPlatformMessage(mark.getIsPlatformMessage()); + alarm.setIsShowAlert(mark.getIsShowAlert()); + alarm.setIsSmallBell(mark.getIsSmallBell()); + alarm.setIsShortMessage(mark.getIsShortMessage()); + alarm.setIsWxMessage(mark.getIsWxMessage()); + // 步骤6.保存当日告警数据 + boolean isSave = queryService.save(alarm); + if(!isSave){ + log.error("alarm_save_fail : {}",alarm.getAlarmId()); + return false; + } + String key="hzims:queue:filter:alarm"+alarm.getAlarmId(); + stringRedisTemplate.opsForValue().set(key,station.getName()+alarm.getAlarmContext()); + stringRedisTemplate.expire(key,5, TimeUnit.MINUTES); + // 步骤7.发生数据至redis告警队列 + stringRedisTemplate.opsForList().rightPush("hzims:queue:alarm", JSON.toJSONString(alarm)); + return true; } /** diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/AlarmDefaulConfigServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/ConfigDetailServiceImpl.java similarity index 50% rename from hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/AlarmDefaulConfigServiceImpl.java rename to hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/ConfigDetailServiceImpl.java index 02432db..d63f693 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/AlarmDefaulConfigServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/ConfigDetailServiceImpl.java @@ -1,12 +1,12 @@ package com.hnac.hzims.scheduled.service.alarm.impl; import com.baomidou.dynamic.datasource.annotation.DS; -import com.hnac.hzims.alarm.config.entity.AlarmDefaultConfigEntity; -import com.hnac.hzims.scheduled.mapper.alarm.AlarmDefaulConfigMapper; -import com.hnac.hzims.scheduled.service.alarm.AlarmDefaulConfigService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.hnac.hzims.alarm.config.entity.AlarmConfigDetailEntity; +import com.hnac.hzims.scheduled.mapper.alarm.ConfigDetailMapper; +import com.hnac.hzims.scheduled.service.alarm.ConfigDetailService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; /** @@ -16,6 +16,6 @@ import org.springframework.stereotype.Service; @Service @Slf4j @DS("alarm") -public class AlarmDefaulConfigServiceImpl extends ServiceImpl implements AlarmDefaulConfigService { +public class ConfigDetailServiceImpl extends ServiceImpl implements ConfigDetailService { } \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/ConfigServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/ConfigServiceImpl.java new file mode 100644 index 0000000..545804b --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/ConfigServiceImpl.java @@ -0,0 +1,62 @@ +package com.hnac.hzims.scheduled.service.alarm.impl; + +import com.baomidou.dynamic.datasource.annotation.DS; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.hnac.hzims.alarm.config.entity.AlarmConfigDetailEntity; +import com.hnac.hzims.alarm.config.entity.AlarmConfigEntity; +import com.hnac.hzims.alarm.config.vo.AlarmHandleMarkVo; +import com.hnac.hzims.scheduled.mapper.alarm.ConfigMapper; +import com.hnac.hzims.scheduled.service.alarm.ConfigDetailService; +import com.hnac.hzims.scheduled.service.alarm.ConfigService; +import com.hnac.hzims.scheduled.service.alarm.DefaulConfigService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.utils.ObjectUtil; +import org.springframework.stereotype.Service; + +/** + * @author ysj + */ +@AllArgsConstructor +@Service +@Slf4j +@DS("alarm") +public class ConfigServiceImpl extends ServiceImpl implements ConfigService { + + private final ConfigDetailService configDetailService; + + private final DefaulConfigService detailService; + + /** + * 查询站点告警标识 + * @param code + * @return + */ + @Override + public AlarmHandleMarkVo mark(String code, Integer source,Integer type) { + AlarmConfigEntity config = this.getOne(Wrappers.lambdaQuery() + .eq(AlarmConfigEntity::getStationId,code)); + if(ObjectUtil.isEmpty(config)){ + return detailService.defaultMark(source,type); + } + AlarmConfigDetailEntity detail = configDetailService.getOne(Wrappers.lambdaQuery() + .eq(AlarmConfigDetailEntity::getStrategyId,config.getId()) + .eq(AlarmConfigDetailEntity::getAlarmType,source) + .eq(AlarmConfigDetailEntity::getAlarmChiledType,type) + ); + if(ObjectUtil.isEmpty(detail)){ + return detailService.defaultMark(source,type); + } + AlarmHandleMarkVo mark = new AlarmHandleMarkVo(); + mark.setIsRightTabulation(detail.getIsRightTabulation()); + mark.setIsBroadcast(detail.getIsBroadcast()); + mark.setIsMask(detail.getIsMask()); + mark.setIsPlatformMessage(detail.getIsPlatformMessage()); + mark.setIsShowAlert(detail.getIsShowAlert()); + mark.setIsSmallBell(detail.getIsSmallBell()); + mark.setIsShortMessage(detail.getIsShortMessage()); + mark.setIsWxMessage(detail.getIsWxMessage()); + return mark; + } +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/DefaulConfigServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/DefaulConfigServiceImpl.java new file mode 100644 index 0000000..00be9f8 --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/DefaulConfigServiceImpl.java @@ -0,0 +1,48 @@ +package com.hnac.hzims.scheduled.service.alarm.impl; + +import com.baomidou.dynamic.datasource.annotation.DS; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.hnac.hzims.alarm.config.entity.AlarmDefaultConfigEntity; +import com.hnac.hzims.alarm.config.vo.AlarmHandleMarkVo; +import com.hnac.hzims.scheduled.mapper.alarm.AlarmDefaulConfigMapper; +import com.hnac.hzims.scheduled.service.alarm.DefaulConfigService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; + +/** + * @author ysj + */ +@AllArgsConstructor +@Service +@Slf4j +@DS("alarm") +public class DefaulConfigServiceImpl extends ServiceImpl implements DefaulConfigService { + + private final AlarmDefaulConfigMapper alarmDefaulConfigMapper; + + @Override + public AlarmHandleMarkVo defaultMark(Integer source,Integer type) { + // 告警来源 : 0- HZ3000告警 1 -等级告警 2 -条件告警 3-FDP智能预警 4-视频预警 5-开关机告警 + // 子类告警 + // HZ3000告警 : 2-告警 3-故障 5-遥测越限 13-通讯中断 14-数据异常 + // 等级告警 : 21-一级告警 22-二级告警 23-三级告警 + // 智能预警 : 30-智能预警 + // 条件告警 : 40-条件告警 + // 开关机告警 : 50-开机告警 51-关机告警 + AlarmDefaultConfigEntity alarmDefaultConfigEntity = alarmDefaulConfigMapper.selectOne(new LambdaQueryWrapper() {{ + eq(AlarmDefaultConfigEntity::getSource, source); + eq(AlarmDefaultConfigEntity::getAlarmChiledType, type); + last("limit 1;"); + }}); + if (ObjectUtils.isNotEmpty(alarmDefaultConfigEntity)){ + AlarmHandleMarkVo alarmHandleMarkVo = new AlarmHandleMarkVo(); + BeanUtils.copyProperties(alarmDefaultConfigEntity,alarmHandleMarkVo); + return alarmHandleMarkVo; + } + return new AlarmHandleMarkVo(); + } +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/HandleServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/HandleServiceImpl.java index 7e17a2e..5d203b3 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/HandleServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/HandleServiceImpl.java @@ -10,6 +10,7 @@ import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.tool.utils.DateUtil; import org.springframework.stereotype.Service; +import java.util.Calendar; import java.util.Date; import java.util.List; @@ -36,4 +37,27 @@ public class HandleServiceImpl extends BaseServiceImpl sameDayContent(String code) { + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.HOUR_OF_DAY,-1); + String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); + String end = DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME); + return this.baseMapper.sameDayContent(start,end,code); + } + + /** + * 查询未到延后期限告警的内容 + * @return + */ + @Override + public List incompleteContent(String code) { + String end = DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME); + return this.baseMapper.incompleteContent(end,code); + } } \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/AlarmQueryServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/QueryServiceImpl.java similarity index 68% rename from hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/AlarmQueryServiceImpl.java rename to hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/QueryServiceImpl.java index b54216c..9208118 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/AlarmQueryServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/alarm/impl/QueryServiceImpl.java @@ -1,26 +1,16 @@ package com.hnac.hzims.scheduled.service.alarm.impl; import com.baomidou.dynamic.datasource.annotation.DS; -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.hnac.hzims.alarm.config.constants.AlarmConstants; import com.hnac.hzims.alarm.config.entity.AlarmEntity; -import com.hnac.hzims.operational.main.constant.HomePageConstant; -import com.hnac.hzims.operational.main.vo.HydropowerUnitRealVo; -import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.scheduled.mapper.alarm.AlarmQueryMapper; -import com.hnac.hzims.scheduled.service.alarm.AlarmQueryService; +import com.hnac.hzims.scheduled.service.alarm.QueryService; import com.hnac.hzims.scheduled.service.alarm.HandleService; -import com.hnac.hzims.scheduled.service.operation.station.StationService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.DateUtil; -import org.springblade.core.tool.utils.Func; -import org.springblade.core.tool.utils.StringUtil; -import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import java.util.*; @@ -33,7 +23,7 @@ import java.util.stream.Collectors; @Service @Slf4j @DS("alarm") -public class AlarmQueryServiceImpl extends ServiceImpl implements AlarmQueryService { +public class QueryServiceImpl extends ServiceImpl implements QueryService { private HandleService handleService; diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/StartStopDurationService.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/StartStopDurationService.java index 5db1340..6c8eba7 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/StartStopDurationService.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/StartStopDurationService.java @@ -1,7 +1,8 @@ package com.hnac.hzims.scheduled.service.equipment; import com.baomidou.mybatisplus.extension.service.IService; -import com.hnac.hzims.equipment.entity.StartStopDurationEntity; +import com.hnac.hzims.startStop.entity.StartStopDurationEntity; +import com.hnac.hzims.equipment.vo.StartStopGenerateVO; /** * @author ysj @@ -11,4 +12,6 @@ public interface StartStopDurationService extends IService { void deletemMonthGenerate(@Param("month") String month); + + List threes(List codes, String year); } \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/impl/StartStopDurationServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/impl/StartStopDurationServiceImpl.java index d84636e..43a4a3d 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/impl/StartStopDurationServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/impl/StartStopDurationServiceImpl.java @@ -7,8 +7,9 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.hnac.hzims.common.logs.utils.StringUtils; -import com.hnac.hzims.equipment.entity.StartStopDurationEntity; +import com.hnac.hzims.startStop.entity.StartStopDurationEntity; import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; +import com.hnac.hzims.equipment.vo.StartStopGenerateVO; import com.hnac.hzims.equipment.vo.StartStopTimeVO; import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.station.entity.StationEntity; @@ -21,17 +22,14 @@ import com.hnac.hzinfo.datasearch.PointData; import com.hnac.hzinfo.datasearch.analyse.domain.FieldsData; 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.core.response.HzPage; import com.hnac.hzinfo.sdk.core.response.Result; import com.hnac.hzinfo.sdk.v5.device.DeviceDataClient; import com.hnac.hzinfo.sdk.v5.device.source.dto.HisDeviceSourceDataDTO; -import com.hnac.hzinfo.sdk.v5.device.source.dto.HisFacSourceDataDTO; -import lombok.AllArgsConstructor; 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.log.exception.ServiceException; import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.ObjectUtil; @@ -66,6 +64,8 @@ public class StartStopDurationServiceImpl extends ServiceImpl stations = stationService.list(Wrappers.lambdaQuery() + .eq(StationEntity::getType, HomePageConstant.HYDROPOWER) + .in(StationEntity::getCode,param.getStations()) + ); + if(CollectionUtil.isEmpty(stations)){ + throw new ServiceException("无可统计开关机时长站点!"); + } + + // 查询设备信息 + List eminfos = JSONObject.parseObject(redisTemplate.opsForValue().get(device_cache_cofig_final).toString(), new TypeReference>() {}); + if(CollectionUtil.isEmpty(eminfos)){ + throw new ServiceException("未查询到设备信息!"); + } + + // 查询时间 + Calendar calendar = Calendar.getInstance(); + calendar.setTime(start); + + while (start.compareTo(end) <= 0){ + calendar.add(Calendar.HOUR_OF_DAY,+1); + Date complete = calendar.getTime(); + // 删除日期开关机记录 + this.baseMapper.deleteThisDayStartStopRecord(DateUtil.format(start,DateUtil.PATTERN_DATETIME)); + + // 遍历站点记录当日开停机时间 + for(StationEntity station:stations){ + List devices = eminfos.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(devices)){ + continue; + } + // 遍历设备 + for(EminfoAndEmParamVo device:devices){ + // 设备开关机状态监测点 + Map point = device.getPoint(); + if(MapUtils.isEmpty(point)){ + continue; + } + // 监测点 + String realId = point.get(HomePageConstant.START_STOP_STATUS); + if(StringUtil.isBlank(realId)){ + continue; + } + // 查询时间范围开关机监测点历史数据 + HisDeviceSourceDataDTO source = new HisDeviceSourceDataDTO(); + source.setProjectId(station.getCode()); + source.setDeviceCode(device.getEmCode()); + source.setAttrSignages(Collections.singletonList(HomePageConstant.START_STOP_STATUS)); + source.setBeginTime(LocalDateTime.parse(DateUtil.format(new Date(), DateUtil.format(start,DateUtil.PATTERN_DATETIME)), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME))); + source.setFinishTime(LocalDateTime.parse(DateUtil.format(new Date(), DateUtil.format(complete,DateUtil.PATTERN_DATETIME)), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME))); + source.setIsPage(false); + source.setCurrent(1); + source.setPageSize(100000); + Result>> sources = deviceDataClient.hisDeviceSourceData(source); + if(!sources.isSuccess() || CollectionUtil.isEmpty(sources.getData())){ + continue; + } + // 相邻数据处理 + List adjacents = this.adjacents(sources.getData()); + // 开机时长 + long runTimes = this.runTimes(adjacents,start,complete); + StartStopDurationEntity duration = new StartStopDurationEntity(); + duration.setTenantId(station.getTenantId()); + duration.setCreateDept(station.getRefDept()); + duration.setCreateUser(station.getCreateUser()); + duration.setUpdateUser(station.getUpdateUser()); + duration.setStationId(station.getCode()); + duration.setStationName(station.getName()); + duration.setDeviceCode(device.getEmCode()); + duration.setDeviceName(device.getName()); + duration.setStartDuration(BigDecimal.valueOf(runTimes / (1000 * 60 * 60.00)).setScale(2, RoundingMode.HALF_UP).doubleValue()); + duration.setStopDuration(BigDecimal.valueOf((complete.getTime() - start.getTime() - runTimes) / (1000 * 60 * 60.00)).setScale(2, RoundingMode.HALF_UP).doubleValue()); + duration.setStrDay(DateUtil.format(start,DateUtil.PATTERN_DATETIME)); + this.save(duration); + } + + } + start = calendar.getTime(); + } + return true; + } } diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/impl/ThreeGenerateServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/impl/ThreeGenerateServiceImpl.java index 2cb6103..68a4235 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/impl/ThreeGenerateServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/equipment/impl/ThreeGenerateServiceImpl.java @@ -1,6 +1,7 @@ package com.hnac.hzims.scheduled.service.equipment.impl; import com.baomidou.dynamic.datasource.annotation.DS; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hnac.hzims.common.utils.DateUtil; import com.hnac.hzims.equipment.entity.ThreeGenerationEntity; import com.hnac.hzims.scheduled.mapper.equipment.ThreeGenerateMapper; @@ -11,6 +12,7 @@ import org.springblade.core.mp.base.BaseServiceImpl; import org.springframework.stereotype.Service; import java.util.Calendar; +import java.util.List; /** * @author ysj @@ -35,4 +37,18 @@ public class ThreeGenerateServiceImpl extends BaseServiceImpl threes(List codes, String year) { + return this.list(Wrappers.lambdaQuery() + .in(ThreeGenerationEntity::getStationId,codes) + .like(ThreeGenerationEntity::getStrMonth,year) + ); + } + } 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 index b7c7dd0..055b73f 100644 --- 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 @@ -7,7 +7,7 @@ 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.EmParamEntity; -import com.hnac.hzims.equipment.entity.StartStopDurationEntity; +import com.hnac.hzims.startStop.entity.StartStopDurationEntity; import com.hnac.hzims.equipment.entity.ThirtyGenerationEntity; import com.hnac.hzims.equipment.entity.ThreeGenerationEntity; import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; 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 index 3dc8b79..f731840 100644 --- 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 @@ -17,7 +17,7 @@ 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.alarm.AlarmQueryService; +import com.hnac.hzims.scheduled.service.alarm.QueryService; import com.hnac.hzims.scheduled.service.alarm.InterruptionAlarmService; import com.hnac.hzims.scheduled.service.equipment.WorkshopInfoService; import com.hnac.hzims.scheduled.service.operation.alarm.RecordService; @@ -63,7 +63,7 @@ public class MonitorServiceImpl implements MonitorService { private final StationService stationService; - private final AlarmQueryService alarmQueryService; + private final QueryService queryService; private final StationAttributeService attbtService; @@ -328,7 +328,7 @@ public class MonitorServiceImpl implements MonitorService { Map sorts = this.monitorDeptSorts(); List operations = stations.stream().filter(o->HomePageConstant.HYDROPOWER_SERVETYPE_STRING.equals(o.getServeType())).map(StationEntity::getCode).collect(Collectors.toList()); // 告警铃铛(代运维) - List bells = alarmQueryService.bells(operations); + List bells = queryService.bells(operations); // 数据中断(代运维) List aborts = interruptionAlarmService.aborts(operations); // 设备状态分类 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 index ab656e0..b07d1ed 100644 --- 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 @@ -8,6 +8,7 @@ import com.hnac.hzims.alarm.config.constants.AlarmHandleConstant; import com.hnac.hzims.common.logs.utils.StringUtils; import com.hnac.hzims.equipment.entity.EmInfoEntity; import com.hnac.hzims.equipment.entity.PlanGenerationEntity; +import com.hnac.hzims.equipment.entity.ThreeGenerationEntity; import com.hnac.hzims.equipment.vo.RideDeviceVo; import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.main.vo.AreaMonthReportVo; @@ -19,6 +20,7 @@ import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.safeproduct.dto.SafeEquipmentTrialDTO; import com.hnac.hzims.scheduled.service.equipment.DeviceService; import com.hnac.hzims.scheduled.service.equipment.PlanService; +import com.hnac.hzims.scheduled.service.equipment.ThreeGenerateService; 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; @@ -101,11 +103,12 @@ public class ReportServiceImpl implements ReportService { private final StationService stationService; - private final PhenomenonService phenomenonService; private final MaintenanceService maintenanceService; + private final ThreeGenerateService threeGenerateService; + private final ISysClient sysClient; private final IUserClient userClient; @@ -624,6 +627,8 @@ public class ReportServiceImpl implements ReportService { // 计划发电量 List plans = planService.planGeneration(stations.stream().map(StationEntity::getCode).collect(Collectors.toList()), null ,DateUtil.format(new Date(),"yyyy")); + // 实际发电量 + List threes = threeGenerateService.threes(stations.stream().map(StationEntity::getCode).collect(Collectors.toList()),DateUtil.format(new Date(),"yyyy")); // 查询站点设备 List devices = deviceService.rideDevices(stations.stream().map(StationEntity::getRefDept).collect(Collectors.toList())); stations.forEach(station->{ @@ -643,13 +648,11 @@ public class ReportServiceImpl implements ReportService { return; } // 运行数据 - run.setRunData(this.runData(station.getCode(),stationDevices,plans)); + run.setRunData(this.runData(station.getCode(),stationDevices,plans,threes)); // 告警数据 run.setAlarmData(this.alarmData(station.getCode())); // 月度运行曲线 run.setCurveData(this.curveData(stationDevices)); - // TODO 运行数据分析 - // TODO 运行建议及其他 runMonService.save(run); }); @@ -678,7 +681,10 @@ public class ReportServiceImpl implements ReportService { * @param devices * @return */ - private String runData(String stationCode,List devices,List plans) { + private String runData(String stationCode,List devices,List plans,List threes) { + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.DAY_OF_MONTH,-calendar.get(Calendar.DAY_OF_MONTH)); + String month = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); List runs = new ArrayList<>(); devices.forEach(device->{ RunDataVo run = new RunDataVo(); @@ -686,66 +692,54 @@ public class ReportServiceImpl implements ReportService { run.setDeviceName(device.getName()); // 运行时长 run.setRunHours(this.runHours(device)); - // 月发电量 - Double day = this.generate(0,device.getNumber(),device.getRide()); - if(ObjectUtil.isEmpty(day)){ + // 发电量 以万kwh为单位 + if(CollectionUtil.isEmpty(threes)){ run.setGenerate(0.0); + run.setGenerateYear(0.0); }else{ - run.setGenerate(day/10000); + // 月发电量 以万kwh为单位 + double generate = threes.stream().filter(o-> StringUtils.isNotEmpty(o.getDeviceCode()) && stationCode.equals(o.getStationId()) && device.getNumber().equals(o.getDeviceCode()) && month.contains(o.getStrMonth())).mapToDouble(o->o.getGenerate().doubleValue()).sum(); + if(generate > 0){ + run.setGenerate(generate / 10000); + }else{ + run.setGenerate(0.0); + } + + // 年发电量 以万kwh为单位 + double year = threes.stream().filter(o->stationCode.equals(o.getStationId())).mapToDouble(o->o.getGenerate().doubleValue()).sum(); + if(year > 0){ + run.setGenerateYear(year / 10000); + }else{ + run.setGenerateYear(0.0); + } } - // 年发电量 - Double year = this.generate(1,device.getNumber(),device.getRide()); - if(ObjectUtil.isEmpty(day)){ - run.setGenerateYear(0.0); + // 计划发电量 以万kwh为单位 + if(CollectionUtil.isEmpty(plans)){ + run.setPlan(0.0); + run.setPlanYear(0.0); }else{ - run.setGenerateYear(year/10000); + // 月计划发电量 以万kwh为单位 + double generate = plans.stream().filter(o-> stationCode.equals(o.getStationId()) && month.contains(o.getDateTime())).mapToDouble(o->o.getPlanGeneration().doubleValue()).sum(); + if(generate > 0){ + run.setPlan(generate / 10000); + }else{ + run.setPlan(0.0); + } + + // 年计划发电量 以万kwh为单位 + double year = plans.stream().filter(o-> stationCode.equals(o.getStationId())).mapToDouble(PlanGenerationEntity::getPlanGeneration).sum(); + if(year > 0){ + run.setPlanYear(year / 10000); + }else{ + run.setPlanYear(0.0); + } } - // 计划发电量 - run.setPlan(this.planGenerate(0,stationCode,plans)/10000); - // 年计划发电量 - run.setPlanYear(this.planGenerate(1,stationCode,plans)/10000); runs.add(run); }); return JSONObject.toJSONString(runs); } - /** - * 实际发电量 - * @param type - * @param deviceCode - * @param ride - * @return - */ - private Double generate(int type,String deviceCode,double ride) { - Calendar calendar = Calendar.getInstance(); - calendar.setTime(new Date()); - String end = null,start = null; - int cycleType = 5; - switch (type){ - case 0 : - 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)); - end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); - calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); - start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); - break; - case 1 : - cycleType = 6; - end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); - calendar.add(Calendar.MONTH,-calendar.get(Calendar.MONTH)); - calendar.add(Calendar.DAY_OF_MONTH,-calendar.get(Calendar.DAY_OF_MONTH)); - 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)); - calendar.add(Calendar.DAY_OF_MONTH,1); - start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); - break; - } - return Double.valueOf(dataService.periodTargetFloat(start,end,5,cycleType,deviceCode,ride,HomePageConstant.HYDROPOWER_GENERATE_POWER)); - } /** * 计划发电量 diff --git a/hzims-service/hzims-scheduled/src/main/resources/mapper/alarm/ConfigDetailMapper.xml b/hzims-service/hzims-scheduled/src/main/resources/mapper/alarm/ConfigDetailMapper.xml new file mode 100644 index 0000000..3869dde --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/resources/mapper/alarm/ConfigDetailMapper.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/resources/mapper/alarm/ConfigMapper.xml b/hzims-service/hzims-scheduled/src/main/resources/mapper/alarm/ConfigMapper.xml new file mode 100644 index 0000000..009252c --- /dev/null +++ b/hzims-service/hzims-scheduled/src/main/resources/mapper/alarm/ConfigMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/hzims-service/hzims-scheduled/src/main/resources/mapper/alarm/HandleMapper.xml b/hzims-service/hzims-scheduled/src/main/resources/mapper/alarm/HandleMapper.xml index ab99010..facd566 100644 --- a/hzims-service/hzims-scheduled/src/main/resources/mapper/alarm/HandleMapper.xml +++ b/hzims-service/hzims-scheduled/src/main/resources/mapper/alarm/HandleMapper.xml @@ -13,5 +13,33 @@ AND (HANDLER.DELAY_TIME > #{end} OR HANDLER.DELAY_TIME IS NULL) + + diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java index ba65083..91d9996 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java @@ -7,11 +7,13 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.google.common.collect.Lists; import com.google.common.util.concurrent.ThreadFactoryBuilder; -import com.hnac.hzims.alarm.config.constants.AlarmConstants; -import com.hnac.hzims.alarm.config.constants.AlarmHandleConstant; import com.hnac.gglm.bigmodel.api.feign.IDataAnalyseClient; import com.hnac.gglm.bigmodel.business.dto.*; +import com.hnac.hzims.alarm.config.constants.AlarmConstants; +import com.hnac.hzims.alarm.config.constants.AlarmHandleConstant; import com.hnac.hzims.common.logs.utils.StringUtils; +import com.hnac.hzims.electric.entity.ThreeEntity; +import com.hnac.hzims.electric.feign.IThreeElectricClient; import com.hnac.hzims.equipment.entity.EmInfoEntity; import com.hnac.hzims.equipment.entity.PlanGenerationEntity; import com.hnac.hzims.equipment.feign.IEmInfoClient; @@ -29,17 +31,14 @@ import com.hnac.hzims.operational.report.vo.*; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.service.IStationService; import com.hnac.hzims.operational.station.vo.StationVO; -import com.hnac.hzinfo.datasearch.PointData; +import com.hnac.hzims.startStop.feign.IStartStopClient; 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.history.IHistoryDataSearchClient; -import com.hnac.hzinfo.datasearch.history.OriginalDataQuery; import com.hnac.hzinfo.datasearch.soe.ISoeClient; import com.hnac.hzinfo.datasearch.soe.domian.SoeData; import com.hnac.hzinfo.datasearch.soe.domian.SoeQueryConditionByStation; import com.hnac.hzinfo.exception.HzServiceException; -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 com.hnac.hzinfo.sdk.v5.soe.SoeDataClient; @@ -101,6 +100,10 @@ public class RunMonthServiceImpl extends ServiceImpl plans = planClient.getPlanGenerationByParam(param); + + // 实际发电量 + List threes = threeElectricClient.electrics(stationCode,DateUtil.format(calendar.getTime(), "yyyy")); + RunMonthEntity run = new RunMonthEntity(); run.setTenantId(station.getTenantId()); run.setCreateDept(station.getRefDept()); @@ -249,8 +259,6 @@ public class RunMonthServiceImpl extends ServiceImpl curveEcharts = new ArrayList<>(); for (RideDeviceVo device : devices) { // 运行数据 - runDatas.add(this.runData(station.getCode(), device, plans, start, end)); + runDatas.add(this.runData(station.getCode(), device, plans,threes,start,end)); // 月度运行曲线 curveEcharts.add(this.curveData(device, start, end)); } - /*CountDownLatch countDownLatch = new CountDownLatch(devices.size()); - List runDatas = new CopyOnWriteArrayList<>(); - List curveEcharts = new CopyOnWriteArrayList<>(); - for (RideDeviceVo device : devices){ - pool.submit(()->{ - // 运行数据 - runDatas.add(this.runData(station.getCode(),device,plans,start,end)); - // 月度运行曲线 - curveEcharts.add(this.curveData(device,start,end)); - countDownLatch.countDown(); - }); - } - //所有模板数据获取完成后释放锁 - try { - countDownLatch.await(); - } catch (InterruptedException e) { - e.printStackTrace(); - Thread.currentThread().interrupt(); - }*/ if (!CollectionUtil.isEmpty(runDatas)) { run.setRunData(JSONObject.toJSONString(runDatas)); } if (!CollectionUtil.isEmpty(curveEcharts)) { run.setCurveData(JSONObject.toJSONString(curveEcharts)); } - // TODO 运行数据分析 - // TODO 运行建议及其他 // 先删除原先月报数据 this.deleteRunReport(mon, stationCode); // 保存生成月报数据 @@ -473,53 +460,55 @@ public class RunMonthServiceImpl extends ServiceImpl plans, String start, String end) { + private RunDataVo runData(String stationCode, RideDeviceVo device, List plans,List threes, String start, String end) { RunDataVo run = new RunDataVo(); run.setDeviceCode(device.getNumber()); run.setDeviceName(device.getName()); // 运行时长 - run.setRunHours(this.runHours(device, DateUtil.parse(start, DateUtil.PATTERN_DATETIME), DateUtil.parse(end, DateUtil.PATTERN_DATETIME))); - // 月发电量 - Double day = this.generates(0, device.getNumber(), device.getRide(), start, end); - if (ObjectUtil.isEmpty(day)) { + run.setRunHours(startStopClient.deviceDuration(device.getNumber(),start,end)); + // 发电量 以万kwh为单位 + if(CollectionUtil.isEmpty(threes)){ run.setGenerate(0.0); - } else { - run.setGenerate(day / 10000); - } - // 年发电量 - Double year = this.generates(1, device.getNumber(), device.getRide(), start, end); - if (ObjectUtil.isEmpty(day)) { run.setGenerateYear(0.0); - } else { - run.setGenerateYear(year / 10000); + }else{ + // 月发电量 以万kwh为单位 + double generate = threes.stream().filter(o-> StringUtils.isNotEmpty(o.getDeviceCode()) && device.getNumber().equals(o.getDeviceCode()) && start.contains(o.getStrMonth())).mapToDouble(o->o.getGenerate().doubleValue()).sum(); + if(generate > 0){ + run.setGenerate(generate / 10000); + }else{ + run.setGenerate(0.0); + } + + // 年发电量 以万kwh为单位 + double year = threes.stream().mapToDouble(o->o.getGenerate().doubleValue()).sum(); + if(year > 0){ + run.setGenerateYear(year / 10000); + }else{ + run.setGenerateYear(0.0); + } } - // 计划发电量 - run.setPlan(this.planGenerate(0, stationCode, plans) / 10000); - // 年计划发电量 - run.setPlanYear(this.planGenerate(1, stationCode, plans) / 10000); - return run; - } + // 计划发电量 以万kwh为单位 + if(CollectionUtil.isEmpty(plans)){ + run.setPlan(0.0); + run.setPlanYear(0.0); + }else{ + // 月计划发电量 以万kwh为单位 + double generate = plans.stream().filter(o-> start.contains(o.getDateTime())).mapToDouble(o->o.getPlanGeneration().doubleValue()).sum(); + if(generate > 0){ + run.setPlan(generate / 10000); + }else{ + run.setPlan(0.0); + } - /** - * 实际发电量 - * - * @param type - * @param deviceCode - * @param ride - * @return - */ - private Double generates(int type, String deviceCode, double ride, String start, String end) { - if (type == 0) { - return Double.valueOf(dataService.periodTargetFloat(start, end, 5, 5, deviceCode, ride, HomePageConstant.HYDROPOWER_GENERATE_POWER)); + // 年计划发电量 以万kwh为单位 + double year = plans.stream().mapToDouble(PlanGenerationEntity::getPlanGeneration).sum(); + if(year > 0){ + run.setPlanYear(year / 10000); + }else{ + run.setPlanYear(0.0); + } } - Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); - calendar.add(Calendar.DAY_OF_MONTH, -calendar.get(Calendar.DAY_OF_MONTH)); - 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)); - calendar.add(Calendar.DAY_OF_MONTH, 1); - return Double.valueOf(dataService.periodTargetFloat(DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME), end, 5, 6, deviceCode, ride, HomePageConstant.HYDROPOWER_GENERATE_POWER)); + return run; } /** @@ -547,86 +536,6 @@ public class RunMonthServiceImpl extends ServiceImpl signages = dataService.analyzeCodeBySignages(Collections.singletonList(analyze)); - if (CollectionUtil.isEmpty(signages)) { - return 0.0; - } - // 监测点 - String realId = signages.get(0).getRealId(); - if (StringUtils.isEmpty(realId)) { - return 0.0; - } - return this.getRunConvertData(realId, startDate, endDate); - } - - /** - * 获取时间范围内运行时长 - * - * @param realId - * @param startDate - * @param endDate - * @return - */ - private Double getRunConvertData(String realId, Date startDate, Date endDate) { - OriginalDataQuery originalDataQuery = new OriginalDataQuery(); - originalDataQuery.setRealId(realId); - originalDataQuery.setBeginTime(startDate); - originalDataQuery.setEndTime(endDate); - originalDataQuery.setLimit(100000); - originalDataQuery.setPage(1); - // 查询时间范围开关机监测点历史数据 - Result> result = historyDataSearchClient.getOriginalDataByRealIds(originalDataQuery); - if (!result.isSuccess() || ObjectUtil.isEmpty(result.getData())) { - return 0.0; - } - // 开机运行时长 - long time = this.getRunTime(result.getData().getRecords(), startDate, endDate); - return BigDecimal.valueOf(time / (1000 * 60 * 60.00)).setScale(2, RoundingMode.HALF_UP).doubleValue(); - } - - /** - * 获取运行时长 - * - * @param result - * @return - */ - private long getRunTime(List result, Date startDate, Date endDate) { - if (result.size() == 1) { - // 一直开机 - if (Double.parseDouble(result.get(0).getValue()) > 0) { - return endDate.getTime() - startDate.getTime(); - } - // 一直关机 - return 0; - } - long time = 0; - // 遍历累计开机时长 - for (int i = 0; i < result.size(); i++) { - // 记录为开机状态 就计算到下次关机的时间差 - if (Double.parseDouble(result.get(i).getValue()) <= 0) { - 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; - } /** * 告警数据