diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java index 76cf599..4423f4f 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/alert/constants/AbnormalAlarmConstant.java @@ -10,6 +10,8 @@ public interface AbnormalAlarmConstant { List TYPE_LIST = Arrays.asList("3","2","5","10","13","14"); + List SEND_MESSSAGE_TYPE_LIST = Arrays.asList("2","13","14"); + String LEVEL_TYPE_LIST = "3,2,5,10,13,14"; /**通讯恢复*/ diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/entity/StationEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/entity/StationEntity.java index e596565..6e9450d 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/entity/StationEntity.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/entity/StationEntity.java @@ -156,4 +156,7 @@ public class StationEntity extends TenantEntity implements Serializable { @ApiModelProperty("实时画面绑定账号秘钥") private String secretKey; + + @ApiModelProperty("是否发送告警短信: 1-发送短信 0-不发送短信") + private Integer isSendMessage; } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AbnormalAlarmServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AbnormalAlarmServiceImpl.java index 50fc45e..e59097d 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AbnormalAlarmServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/AbnormalAlarmServiceImpl.java @@ -1,8 +1,12 @@ package com.hnac.hzims.operational.alert.service.impl; +import com.hnac.hzims.message.MessageConstants; +import com.hnac.hzims.message.dto.MessagePushRecordDto; +import com.hnac.hzims.message.fegin.IMessageClient; import com.hnac.hzims.operational.alert.constants.AbnormalAlarmConstant; import com.hnac.hzims.operational.alert.entity.AbnormalAlarmEntity; import com.hnac.hzims.operational.alert.entity.HistoryAbnormalAlarmEntity; +import com.hnac.hzims.operational.alert.entity.HistoryLevelAlarmEntity; import com.hnac.hzims.operational.alert.mapper.AbnormalAlarmMapper; import com.hnac.hzims.operational.alert.service.AbnormalAlarmService; import com.hnac.hzims.operational.alert.service.HistoryAbnormalAlarmService; @@ -18,9 +22,14 @@ import com.hnac.hzinfo.sdk.core.response.Result; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.mp.base.BaseServiceImpl; +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.feign.ISysClient; +import org.springblade.system.user.entity.User; +import org.springblade.system.user.feign.IUserClient; import org.springframework.stereotype.Service; import java.time.LocalDateTime; @@ -32,6 +41,7 @@ import java.util.stream.Collectors; /** * 告警实现类 + * @author ysj */ @Slf4j @Service @@ -42,8 +52,14 @@ public class AbnormalAlarmServiceImpl extends BaseServiceImpl o.getCode().equals(item.getStation())).collect(Collectors.toList())).map(o->o.get(0).getName()).orElse(null); if(ObjectUtil.isEmpty(queryEntity) || !flag){ HistoryAbnormalAlarmEntity entity = new HistoryAbnormalAlarmEntity(); @@ -153,6 +168,8 @@ public class AbnormalAlarmServiceImpl extends BaseServiceImpl entitys,List stations) { + if(CollectionUtil.isEmpty(entitys)){ + return; + } + // 告警等级 :事故、数据中断 + List alarms = entitys.stream().filter(entity -> AbnormalAlarmConstant.SEND_MESSSAGE_TYPE_LIST.contains(entity.getType())).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(alarms)){ + return; + } + // 查询站点用户 + entitys.forEach(entity->{ + if(StringUtil.isEmpty(entity.getStationId())){ + return; + } + List depts = stations.stream().filter(station -> station.getCode().equals(entity.getStationId())).map(StationEntity::getRefDept).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(depts)){ + return; + } + // 获取站点用户 + R> result = userClient.userListByDeptId(depts.get(0)); + if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ + return; + } + MessagePushRecordDto message = new MessagePushRecordDto(); + message.setBusinessClassify("warning"); + message.setBusinessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey()); + message.setSubject(MessageConstants.BusinessClassifyEnum.WARNING.getDescription()); + message.setTaskId(entity.getId()); + message.setTenantId("200000"); + message.setContent(entity.getSoeExplain()); + message.setTypes(Arrays.asList(MessageConstants.APP_PUSH, MessageConstants.WS_PUSH)); + message.setPushType(MessageConstants.IMMEDIATELY); + message.setDeptId(depts.get(0)); + R deptName = sysClient.getDeptName(depts.get(0)); + if (deptName.isSuccess()) { + message.setDeptName(deptName.getData()); + } + User admin = userClient.userByAccount("200000", "admin").getData(); + message.setCreateDept(admin.getCreateDept()); + message.setCreateUser(admin.getCreateUser()); + result.getData().forEach(user->{ + message.setPusher(String.valueOf(user.getId())); + message.setPusherName(user.getName()); + message.setAccount(String.valueOf(user.getId())); + messageClient.sendMessage(message); + }); + }); + } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/LevelAlarmServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/LevelAlarmServiceImpl.java index c544bb8..f7f5ef7 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/LevelAlarmServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/LevelAlarmServiceImpl.java @@ -3,6 +3,9 @@ package com.hnac.hzims.operational.alert.service.impl; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; +import com.hnac.hzims.message.MessageConstants; +import com.hnac.hzims.message.dto.MessagePushRecordDto; +import com.hnac.hzims.message.fegin.IMessageClient; import com.hnac.hzims.operational.alert.constants.AbnormalAlarmConstant; import com.hnac.hzims.operational.alert.entity.HistoryLevelAlarmEntity; import com.hnac.hzims.operational.alert.service.HistoryLevelAlarmService; @@ -15,13 +18,20 @@ import com.hnac.hzims.operational.station.service.IStationService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.log.exception.ServiceException; +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.StringUtil; +import org.springblade.system.feign.ISysClient; +import org.springblade.system.user.entity.User; +import org.springblade.system.user.feign.IUserClient; import org.springframework.stereotype.Service; +import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Map; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; @@ -40,6 +50,12 @@ public class LevelAlarmServiceImpl implements LevelAlarmService { private final HistoryLevelAlarmService historyLevelAlarmService; + private final IUserClient userClient; + + private final ISysClient sysClient; + + private final IMessageClient messageClient; + /** * 定时发送消息内容 * @return String @@ -121,13 +137,75 @@ public class LevelAlarmServiceImpl implements LevelAlarmService { historyLevelAlarmService.saveBatch(entitys); // 消息推送 - this.sendAlarmMessage(entitys); + CompletableFuture.runAsync(()->this.sendAlarmMessage(entitys,stations.stream().filter(station -> entitys.stream().filter(stationId -> !StringUtil.isEmpty(stationId)).map(HistoryLevelAlarmEntity::getStationId).collect(Collectors.toList()).contains(station.getCode())).collect(Collectors.toList()))); } /** * 告警消息推送 * @param entitys */ - private void sendAlarmMessage(List entitys) { + private void sendAlarmMessage(List entitys,List stations) { + if(CollectionUtil.isEmpty(entitys)){ + return; + } + // 告警等级 :一级、二级告警发送通知 + List alarms = entitys.stream().filter(entity -> AbnormalAlarmConstant.LEVEL_LIST.contains(entity.getAlarmLevel())).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(alarms)){ + return; + } + // 查询站点用户 + entitys.forEach(entity->{ + if(StringUtil.isEmpty(entity.getStationId())){ + return; + } + List depts = stations.stream().filter(station -> station.getCode().equals(entity.getStationId())).map(StationEntity::getRefDept).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(depts)){ + return; + } + // app,web消息推送 + this.sendMessageByWebApp(depts.get(0),entity); + // 短信推送 + this.message(depts.get(0),entity); + }); + } + + private void sendMessageByWebApp(Long dept,HistoryLevelAlarmEntity entity) { + // 获取站点用户 + R> result = userClient.userListByDeptId(dept); + if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ + return; + } + MessagePushRecordDto message = new MessagePushRecordDto(); + message.setBusinessClassify("warning"); + message.setBusinessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey()); + message.setSubject(MessageConstants.BusinessClassifyEnum.WARNING.getDescription()); + message.setTaskId(entity.getId()); + message.setTenantId("200000"); + message.setContent(entity.getSoeExplain()); + message.setTypes(Arrays.asList(MessageConstants.APP_PUSH, MessageConstants.WS_PUSH)); + message.setPushType(MessageConstants.IMMEDIATELY); + message.setDeptId(dept); + R deptName = sysClient.getDeptName(dept); + if (deptName.isSuccess()) { + message.setDeptName(deptName.getData()); + } + User admin = userClient.userByAccount("200000", "admin").getData(); + message.setCreateDept(admin.getCreateDept()); + message.setCreateUser(admin.getId()); + result.getData().forEach(user->{ + message.setPusher(String.valueOf(user.getId())); + message.setPusherName(user.getName()); + message.setAccount(String.valueOf(user.getId())); + messageClient.sendMessage(message); + }); + } + + /** + * 发送短信 + * @param dept + * @param entity + */ + private void message(Long dept,HistoryLevelAlarmEntity entity) { + } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/LevelAlarmRegular.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/LevelAlarmRegular.java index e0b4eb7..9975360 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/LevelAlarmRegular.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/ws/LevelAlarmRegular.java @@ -29,7 +29,7 @@ public class LevelAlarmRegular{ private LevelAlarmService levelAlarmService; // 定时发送消息 - @Scheduled(cron = "0/30 * * * * ?") + @Scheduled(cron = "0 0 1 * * ?") private void regular(){ // 检查链接存活状态 if(ObjectUtil.isNotEmpty(client) && client.isOpen()){ diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/scheduled/ScheduledCreateTask.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/scheduled/ScheduledCreateTask.java index 93f8261..7cb4cc8 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/scheduled/ScheduledCreateTask.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/scheduled/ScheduledCreateTask.java @@ -237,10 +237,9 @@ public class ScheduledCreateTask { * 水利-泵组实时加载 * @return ReturnT */ - //@XxlJob(LOAD_WATER_PUMP_REAL) - @Scheduled(cron = "0/10 * * * * ? ") - public ReturnT loadWaterPumpReal() throws Exception { - String param = ""; + @XxlJob(LOAD_WATER_PUMP_REAL) + //@Scheduled(cron = "0/10 * * * * ? ") + public ReturnT loadWaterPumpReal(String param) throws Exception { if (Func.isBlank(param)) { param = DateUtil.format(new Date(), "yyyy-MM"); } @@ -254,7 +253,7 @@ public class ScheduledCreateTask { * @return ReturnT */ @XxlJob(LOAD_WATER_PUMP_TARGET) - //@Scheduled(cron = "0/10 * * * * ? ") + //@Scheduled(cron = "0/40 * * * * ? ") public ReturnT loadWaterPumpTarget(String param) throws Exception { if (Func.isBlank(param)) { param = DateUtil.format(new Date(), "yyyy-MM"); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java index fabd144..d3dc3df 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HydropowerServiceImpl.java @@ -154,7 +154,7 @@ public class HydropowerServiceImpl implements HydropowerService { // 装机容量 real.setInstalledCapacity(device.getInstalledCapacity()); // 开关机状态 - real.setState(Math.abs(this.getSignageValue(device,map,HomePageConstant.JOINT_RELAY)) > 0); + real.setState(this.hydropowerState(device,map)); // 有功功率 real.setActivePower(this.getSignageValue(device,map,HomePageConstant.HYDROPOWER_ACTIVE_POWER)); // 无功功率 @@ -226,6 +226,19 @@ public class HydropowerServiceImpl implements HydropowerService { /** + * 设备状态 + * @param device + * @param map + * @return + */ + private Boolean hydropowerState(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 时间 diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/PhotovoltaicServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/PhotovoltaicServiceImpl.java index 775892a..a6f4cf8 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/PhotovoltaicServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/PhotovoltaicServiceImpl.java @@ -24,7 +24,6 @@ import com.hnac.hzinfo.sdk.core.response.HzPage; import com.hnac.hzinfo.sdk.core.response.Result; import lombok.RequiredArgsConstructor; import org.apache.commons.collections4.MapUtils; -import org.jsoup.helper.DataUtil; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.CollectionUtil; @@ -42,7 +41,6 @@ import java.math.BigDecimal; import java.time.Duration; import java.time.LocalDate; import java.time.LocalDateTime; -import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.concurrent.*; 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 6229c71..cd6d97e 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 @@ -2,19 +2,11 @@ package com.hnac.hzims.operational.maintenance.scheduled; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; -import com.google.common.collect.Lists; -import com.hnac.hzims.equipment.feign.IEmInfoClient; -import com.hnac.hzims.message.MessageConstants; -import com.hnac.hzims.message.dto.MessagePushRecordDto; 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.message.req.PushExtrasReq; -import com.hnac.hzims.operational.access.constants.AccessConstants; import com.hnac.hzims.operational.duty.entity.ImsDutyMainEntity; import com.hnac.hzims.operational.duty.service.IImsDutyMainService; -import com.hnac.hzims.operational.maintenance.OperationalContants; import com.hnac.hzims.operational.maintenance.entity.OperMaintenancePlanEntity; import com.hnac.hzims.operational.maintenance.entity.OperMaintenanceTaskEntity; import com.hnac.hzims.operational.maintenance.mapper.OperMaintenancePlanMapper; @@ -23,7 +15,6 @@ import com.hnac.hzims.operational.maintenance.template.service.TemplateService; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.annotation.XxlJob; import com.xxl.job.core.log.XxlJobLogger; -import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; @@ -31,17 +22,14 @@ import org.springblade.core.log.logger.BladeLogger; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.*; import org.springblade.flow.core.feign.IFlowClient; -import org.springblade.flow.core.utils.FlowUtil; -import org.springblade.flow.core.utils.TaskUtil; -import org.springblade.system.user.cache.UserCache; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; -import java.time.*; -import java.time.format.DateTimeFormatter; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java index 4fe1b37..49939a5 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java @@ -176,24 +176,27 @@ public class RealMonitorServiceImpl implements IRealMonitorService { return; } List objects = redisClient.getBatchRealDataByRealId(stationReal.getStation(),realIds); - if(CollectionUtil.isEmpty(objects)){ - return; - } - for(int i = 0; i < objects.size() ;i++){ + for(int i = 0; i < realIds.size() ;i++){ if(ObjectUtil.isEmpty(objects.get(i))){ + Map attribute = new ConcurrentHashMap<>(); + attribute.put("realId",realIds.get(i)); + attribute.put("value","0"); + attribute.put("time",DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss.s")); + valueMap.put(realIdArr[i],attribute.get("value")); + keyMap.put(realIdArr[i],attribute); log.error(realIds.get(i) + "is null"); - continue; + }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); } - 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(); @@ -377,6 +380,7 @@ public class RealMonitorServiceImpl implements IRealMonitorService { beginTime = System.currentTimeMillis(); // 获取所有设备重点属性 List list = attbtService.list(new LambdaQueryWrapper() {{ + isNotNull(StationAttributeEntity::getStationId); eq(StationAttributeEntity::getIsDeleted, "0"); orderByAsc(StationAttributeEntity::getSort); }});