|
|
@ -2,11 +2,12 @@ package com.hnac.hzims.alarm.handle.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
|
|
|
import com.hnac.hzims.alarm.config.service.AlarmConfigService; |
|
|
|
import com.hnac.hzims.alarm.config.service.AlarmConfigService; |
|
|
|
import com.hnac.hzims.alarm.constants.AlarmConstants; |
|
|
|
|
|
|
|
import com.hnac.hzims.alarm.entity.AlarmEntity; |
|
|
|
import com.hnac.hzims.alarm.entity.AlarmEntity; |
|
|
|
import com.hnac.hzims.alarm.handle.service.MessageService; |
|
|
|
import com.hnac.hzims.alarm.handle.service.MessageService; |
|
|
|
import com.hnac.hzims.message.MessageConstants; |
|
|
|
import com.hnac.hzims.message.MessageConstants; |
|
|
|
import com.hnac.hzims.message.dto.BusinessMessageDTO; |
|
|
|
import com.hnac.hzims.message.dto.BusinessMessageDTO; |
|
|
|
|
|
|
|
import com.hnac.hzims.message.dto.SmsPushDto; |
|
|
|
|
|
|
|
import com.hnac.hzims.message.dto.WxMessageDTO; |
|
|
|
import com.hnac.hzims.message.fegin.IMessageClient; |
|
|
|
import com.hnac.hzims.message.fegin.IMessageClient; |
|
|
|
import com.hnac.hzims.operational.station.entity.StationEntity; |
|
|
|
import com.hnac.hzims.operational.station.entity.StationEntity; |
|
|
|
import com.hnac.hzims.operational.station.feign.IStationClient; |
|
|
|
import com.hnac.hzims.operational.station.feign.IStationClient; |
|
|
@ -14,14 +15,21 @@ import lombok.AllArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
import org.springblade.core.tool.utils.CollectionUtil; |
|
|
|
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.cache.DictCache; |
|
|
|
import org.springblade.system.feign.ISysClient; |
|
|
|
import org.springblade.system.feign.ISysClient; |
|
|
|
import org.springblade.system.user.entity.User; |
|
|
|
import org.springblade.system.user.entity.User; |
|
|
|
import org.springblade.system.user.feign.IUserClient; |
|
|
|
import org.springblade.system.user.feign.IUserClient; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static com.hnac.hzims.operational.main.constant.MainConstants.PROJECT_MANAGER; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 消息推送实现类 |
|
|
|
* 消息推送实现类 |
|
|
|
* @author ysj |
|
|
|
* @author ysj |
|
|
@ -41,7 +49,29 @@ public class MessageServiceImpl implements MessageService { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void shortMessage(AlarmEntity entity) { |
|
|
|
public void shortMessage(AlarmEntity entity) { |
|
|
|
|
|
|
|
R<StationEntity> station = stationClient.getStationByCode(entity.getStationId()); |
|
|
|
|
|
|
|
if (!station.isSuccess() && ObjectUtils.isEmpty(station.getData())) { |
|
|
|
|
|
|
|
log.error("消息发送失败:站点code获取失败 : {}",entity); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//通知站点项目经理这个角色
|
|
|
|
|
|
|
|
List<User> users = userClient.relationUserListByRoleAlias("200000", station.getData().getRefDept(), PROJECT_MANAGER).getData(); |
|
|
|
|
|
|
|
if(CollectionUtil.isEmpty(users)){ |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
List<String> 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<String, String> 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); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -50,7 +80,6 @@ public class MessageServiceImpl implements MessageService { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void webAppMessage(AlarmEntity entity) { |
|
|
|
public void webAppMessage(AlarmEntity entity) { |
|
|
|
boolean support = alarmConfigService.isSupport(entity.getStationId(), entity.getAlarmSource(), entity.getAlarmType(), AlarmConstants.IS_PLATFORM_MESSAGE); |
|
|
|
|
|
|
|
R<StationEntity> stationByCode = stationClient.getStationByCode(entity.getStationId()); |
|
|
|
R<StationEntity> stationByCode = stationClient.getStationByCode(entity.getStationId()); |
|
|
|
if (!stationByCode.isSuccess() && ObjectUtils.isEmpty(stationByCode.getData())) { |
|
|
|
if (!stationByCode.isSuccess() && ObjectUtils.isEmpty(stationByCode.getData())) { |
|
|
|
log.error("消息发送失败:站点code获取失败 : {}",entity); |
|
|
|
log.error("消息发送失败:站点code获取失败 : {}",entity); |
|
|
@ -63,26 +92,21 @@ public class MessageServiceImpl implements MessageService { |
|
|
|
log.error("消息发送失败:用户获取失败 : {}",entity); |
|
|
|
log.error("消息发送失败:用户获取失败 : {}",entity); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (support) { |
|
|
|
BusinessMessageDTO message = new BusinessMessageDTO(); |
|
|
|
BusinessMessageDTO message = new BusinessMessageDTO(); |
|
|
|
message.setBusinessClassify("warning"); |
|
|
|
message.setBusinessClassify("warning"); |
|
|
|
message.setBusinessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey()); |
|
|
|
message.setBusinessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey()); |
|
|
|
message.setSubject(MessageConstants.BusinessClassifyEnum.WARNING.getDescription()); |
|
|
|
message.setSubject(MessageConstants.BusinessClassifyEnum.WARNING.getDescription()); |
|
|
|
message.setTaskId(Long.valueOf(entity.getAlarmId())); |
|
|
|
message.setTaskId(Long.valueOf(entity.getAlarmId())); |
|
|
|
message.setTenantId("200000"); |
|
|
|
message.setTenantId("200000"); |
|
|
|
message.setContent(entity.getAlarmContext()); |
|
|
|
message.setContent(entity.getAlarmContext()); |
|
|
|
message.setDeptId(dept); |
|
|
|
message.setDeptId(dept); |
|
|
|
R<String> deptName = sysClient.getDeptName(dept); |
|
|
|
R<String> deptName = sysClient.getDeptName(dept); |
|
|
|
if (deptName.isSuccess()) { |
|
|
|
if (deptName.isSuccess()) { |
|
|
|
message.setDeptName(deptName.getData()); |
|
|
|
message.setDeptName(deptName.getData()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
message.setUserIds(result.getData().stream().map(o->String.valueOf(o.getId())).distinct().collect(Collectors.joining(","))); |
|
|
|
|
|
|
|
message.setCreateUser(result.getData().get(0).getId()); |
|
|
|
|
|
|
|
messageClient.sendAppAndWsMsgByUsers(message); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
message.setUserIds(result.getData().stream().map(o->String.valueOf(o.getId())).distinct().collect(Collectors.joining(","))); |
|
|
|
|
|
|
|
message.setCreateUser(result.getData().get(0).getId()); |
|
|
|
|
|
|
|
messageClient.sendAppAndWsMsgByUsers(message); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -91,6 +115,49 @@ public class MessageServiceImpl implements MessageService { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void weChatMessage(AlarmEntity entity) { |
|
|
|
public void weChatMessage(AlarmEntity entity) { |
|
|
|
|
|
|
|
R<StationEntity> stationByCode = stationClient.getStationByCode(entity.getStationId()); |
|
|
|
|
|
|
|
if (!stationByCode.isSuccess() && ObjectUtils.isEmpty(stationByCode.getData())) { |
|
|
|
|
|
|
|
log.error("消息发送失败:站点code获取失败 : {}",entity); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Long dept = stationByCode.getData().getCreateDept(); |
|
|
|
|
|
|
|
// 获取站点用户
|
|
|
|
|
|
|
|
R<List<User>> result = userClient.userListByDeptId(dept); |
|
|
|
|
|
|
|
if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { |
|
|
|
|
|
|
|
log.error("消息发送失败:用户获取失败 : {}",entity); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
WxMessageDTO message = new WxMessageDTO(); |
|
|
|
|
|
|
|
// 模板Id
|
|
|
|
|
|
|
|
message.setTemplateId("hIgINCsjpG-gyCKh8wzwBWjR-hkbjkNLFTXQEsnR_Z8"); |
|
|
|
|
|
|
|
// 微信消息跳转地址
|
|
|
|
|
|
|
|
message.setSkipUrl("http://baidu.com"); |
|
|
|
|
|
|
|
// 机构Id
|
|
|
|
|
|
|
|
message.setDeptId(result.getData().get(0).getId()); |
|
|
|
|
|
|
|
// 业务关键字
|
|
|
|
|
|
|
|
message.setBusinessKey("wx_message_test"); |
|
|
|
|
|
|
|
// 业务分类关键字
|
|
|
|
|
|
|
|
message.setBusinessClassify("wx_message_test"); |
|
|
|
|
|
|
|
// 任务Id
|
|
|
|
|
|
|
|
message.setTaskId(Long.valueOf(entity.getAlarmId())); |
|
|
|
|
|
|
|
// 微信参数键值对
|
|
|
|
|
|
|
|
HashMap<String,Object> map = new HashMap<>(); |
|
|
|
|
|
|
|
map.put("thing18",entity.getStationName()); |
|
|
|
|
|
|
|
map.put("thing5",entity.getDeviceCode()); |
|
|
|
|
|
|
|
map.put("thing11",entity.getAlarmContext()); |
|
|
|
|
|
|
|
map.put("thing14", DictCache.getValue("alarm_source", entity.getAlarmType())); |
|
|
|
|
|
|
|
map.put("time2",entity.getAlarmTime()); |
|
|
|
|
|
|
|
message.setMap(map); |
|
|
|
|
|
|
|
// 消息内容
|
|
|
|
|
|
|
|
message.setContent(entity.getAlarmContext()); |
|
|
|
|
|
|
|
// 消息主题
|
|
|
|
|
|
|
|
message.setSubject(MessageConstants.BusinessClassifyEnum.WARNING.getDescription()); |
|
|
|
|
|
|
|
// 推送用户
|
|
|
|
|
|
|
|
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"); |
|
|
|
|
|
|
|
messageClient.sendWxMessage(message); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |