diff --git a/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/config/constants/AlarmConstants.java b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/config/constants/AlarmConstants.java index 4a59622..0a05c3f 100644 --- a/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/config/constants/AlarmConstants.java +++ b/hzims-service-api/alarm-api/src/main/java/com/hnac/hzims/alarm/config/constants/AlarmConstants.java @@ -62,4 +62,6 @@ public interface AlarmConstants { String VIDEO_SCHEDULED_TASK= "VideoScheduledTask"; List HZ3000_TYPES = Arrays.asList("0","1","2","3","4","5","6","7","8","9","10","11","12"); + + String SMS_MESSAGE_TEMPLATE_CODE = "aliyun-alert-push"; } diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/DroolsAlarmService.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/DroolsAlarmService.java index 1b07084..8fbbefa 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/DroolsAlarmService.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/DroolsAlarmService.java @@ -10,7 +10,5 @@ import java.util.List; */ public interface DroolsAlarmService { - String message(); - List receiveMessage(String message); } \ No newline at end of file diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/DroolsAlarmServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/DroolsAlarmServiceImpl.java index de80b7a..8667adc 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/DroolsAlarmServiceImpl.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/DroolsAlarmServiceImpl.java @@ -3,11 +3,10 @@ package com.hnac.hzims.alarm.source.service.impl; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.hnac.hzims.alarm.config.entity.AlarmEntity; +import com.hnac.hzims.alarm.config.vo.ConditionAlarmVo; +import com.hnac.hzims.alarm.show.service.AlarmService; import com.hnac.hzims.alarm.source.service.DroolsAlarmService; import com.hnac.hzims.alarm.source.service.MessageService; -import com.hnac.hzims.alarm.show.service.AlarmService; -import com.hnac.hzims.alarm.config.vo.ConditionAlarmVo; -import com.hnac.hzims.equipment.feign.IEmInfoClient; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.feign.IStationClient; import lombok.RequiredArgsConstructor; @@ -39,21 +38,8 @@ public class DroolsAlarmServiceImpl implements DroolsAlarmService { private final RedisTemplate redisTemplate; - private final IEmInfoClient deviceClient; - private final IStationClient stationClient; - public final static String device_cache_cofig_final = "hzims:equipment:emInfo:deviceCode.emInfoList"; - - /** - * 发送websocket消息 - * @return - */ - @Override - public String message() { - return ""; - } - /** * 转换接收服务推送消息 diff --git a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java index 6a03596..124ccc4 100644 --- a/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java +++ b/hzims-service/hzims-alarm/src/main/java/com/hnac/hzims/alarm/source/service/impl/MessageServiceImpl.java @@ -1,11 +1,13 @@ package com.hnac.hzims.alarm.source.service.impl; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.hnac.hzims.alarm.config.constants.AlarmConstants; import com.hnac.hzims.alarm.config.service.AlarmConfigService; import com.hnac.hzims.alarm.config.entity.AlarmEntity; import com.hnac.hzims.alarm.source.service.MessageService; import com.hnac.hzims.message.MessageConstants; import com.hnac.hzims.message.dto.BusinessMessageDTO; +import com.hnac.hzims.message.dto.SmsImmediatelyPushDTO; import com.hnac.hzims.message.dto.SmsPushDto; import com.hnac.hzims.message.dto.WxMessageDTO; import com.hnac.hzims.message.fegin.IMessageClient; @@ -14,8 +16,10 @@ import com.hnac.hzims.operational.station.feign.IStationClient; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.api.R; +import org.springblade.core.tool.jackson.JsonUtil; 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.springblade.system.cache.DictCache; import org.springblade.system.feign.ISysClient; @@ -61,23 +65,29 @@ public class MessageServiceImpl implements MessageService { return; } //通知站点项目经理这个角色 - List users = userClient.relationUserListByRoleAlias("200000", station.getData().getRefDept(), PROJECT_MANAGER).getData(); + List users = userClient.relationUserListByRoleAlias(station.getData().getTenantId(), station.getData().getRefDept(), PROJECT_MANAGER).getData(); if(CollectionUtil.isEmpty(users)){ return; } - List phones = users.stream().map(User::getPhone).filter(phone -> !StringUtil.isEmpty(phone)).collect(Collectors.toList()); - if(CollectionUtil.isEmpty(phones)){ - return; - } - SmsPushDto sms = new SmsPushDto(); - sms.setPhones(phones); - Map params = new HashMap<>(); - params.put("projectName",entity.getStationName()); - params.put("deviceName",entity.getDeviceCode()); - params.put("ruleDefName",entity.getAlarmContext()); - params.put("ts", DateUtil.format(entity.getAlarmTime(),DateUtil.PATTERN_DATETIME)); - sms.setParams(params); - messageClient.sendSmsMessage(sms); + SmsImmediatelyPushDTO push = SmsImmediatelyPushDTO.builder() + .deptId(entity.getCreateDept()) + .taskId(entity.getId()) + .businessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey()) + .businessClassify(MessageConstants.BusinessClassifyEnum.WARNING.getKey()) + .content(entity.getAlarmContext()) + .subject("告警短信通知") + .tenantId(entity.getTenantId()) + .resourceCode(AlarmConstants.SMS_MESSAGE_TEMPLATE_CODE) + .pusher(users.stream().map(o->o.getId().toString()).collect(Collectors.joining(","))) + .createUser(station.getData().getCreateUser()) + .params(new HashMap(){{ + put("projectName",entity.getStationName()); + put("deviceName",entity.getDeviceName()); + put("ruleDefName",entity.getAlarmContext()); + put("ts", DateUtil.format(entity.getAlarmTime(),DateUtil.PATTERN_DATETIME)); + }}) + .build(); + messageClient.sendSmsImmediatelyMsg(push); } /** @@ -102,7 +112,7 @@ public class MessageServiceImpl implements MessageService { message.setBusinessClassify("warning"); message.setBusinessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey()); message.setSubject(MessageConstants.BusinessClassifyEnum.WARNING.getDescription()); - message.setTaskId(Long.valueOf(entity.getAlarmId())); + message.setTaskId(entity.getId()); message.setTenantId("200000"); message.setContent(entity.getAlarmContext()); message.setDeptId(dept); @@ -121,12 +131,12 @@ public class MessageServiceImpl implements MessageService { */ @Override public void weChatMessage(AlarmEntity entity) { - R stationByCode = stationClient.getStationByCode(entity.getStationId()); - if (!stationByCode.isSuccess() && ObjectUtils.isEmpty(stationByCode.getData())) { + R station = stationClient.getStationByCode(entity.getStationId()); + if (!station.isSuccess() && ObjectUtils.isEmpty(station.getData())) { log.error("消息发送失败:站点code获取失败 : {}",entity); return; } - Long dept = stationByCode.getData().getCreateDept(); + Long dept = station.getData().getCreateDept(); // 获取站点用户 R> result = userClient.userListByDeptId(dept); if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { @@ -162,9 +172,8 @@ public class MessageServiceImpl implements MessageService { message.setUserIds(result.getData().stream().map(o->String.valueOf(o.getId())).distinct().collect(Collectors.joining(","))); // 创建用户 message.setCreateUser(result.getData().get(0).getId()); - // 租户Id - message.setTenantId("200000"); + message.setTenantId(station.getData().getTenantId()); messageClient.sendWxMessage(message); } } \ No newline at end of file