|
|
@ -15,6 +15,7 @@ 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; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
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.jackson.JsonUtil; |
|
|
|
import org.springblade.core.tool.jackson.JsonUtil; |
|
|
@ -27,6 +28,7 @@ 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.entity.UserInfo; |
|
|
|
import org.springblade.system.user.entity.UserInfo; |
|
|
|
import org.springblade.system.user.feign.IUserClient; |
|
|
|
import org.springblade.system.user.feign.IUserClient; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
@ -40,9 +42,10 @@ import static com.hnac.hzims.operational.main.constant.MainConstants.PROJECT_MAN |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
@Service |
|
|
|
@AllArgsConstructor |
|
|
|
@RequiredArgsConstructor |
|
|
|
public class MessageServiceImpl implements MessageService { |
|
|
|
public class MessageServiceImpl implements MessageService { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final ISysClient sysClient; |
|
|
|
private final ISysClient sysClient; |
|
|
|
|
|
|
|
|
|
|
|
private final IUserClient userClient; |
|
|
|
private final IUserClient userClient; |
|
|
@ -51,6 +54,14 @@ public class MessageServiceImpl implements MessageService { |
|
|
|
|
|
|
|
|
|
|
|
private final IStationClient stationClient; |
|
|
|
private final IStationClient stationClient; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${hzims.msg.template}") |
|
|
|
|
|
|
|
private String msgTemplate; |
|
|
|
|
|
|
|
@Value("${hzims.msg.enabled}") |
|
|
|
|
|
|
|
private Boolean msgEnabled; |
|
|
|
|
|
|
|
@Value("${hzims.wxPush.template}") |
|
|
|
|
|
|
|
private String wxPushTemplate; |
|
|
|
|
|
|
|
@Value("${hzims.wxPush.enabled}") |
|
|
|
|
|
|
|
private Boolean wxPushEnabled; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* web/app消息推送 |
|
|
|
* web/app消息推送 |
|
|
|
* @param entity : 告警对象 |
|
|
|
* @param entity : 告警对象 |
|
|
@ -106,14 +117,23 @@ public class MessageServiceImpl implements MessageService { |
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//写死传给固定用户
|
|
|
|
//写死传给固定用户
|
|
|
|
// List<String> phoneList=Arrays.asList("18351807087","18163793336","13725599914");
|
|
|
|
// List<String> phoneList=Arrays.asList("18351807087","18163793336","13725599914");
|
|
|
|
List<String> phoneList=Arrays.asList("18351807087","18163793336","18285121497"); |
|
|
|
if (msgEnabled){ |
|
|
|
for (String phone : phoneList) { |
|
|
|
users = userClient.relationUserListByRoleAlias(station.getData().getTenantId(), station.getData().getRefDept(), PROJECT_MANAGER).getData(); |
|
|
|
R<UserInfo> userByPhone = userClient.getUserByPhone("200000", phone); |
|
|
|
if(CollectionUtil.isEmpty(users)){ |
|
|
|
if (userByPhone.isSuccess()&&ObjectUtils.isNotEmpty(userByPhone.getData())){ |
|
|
|
log.error("短信发送失败:获取站点项目经理用户失败 : {}",entity); |
|
|
|
users.add(userByPhone.getData().getUser()); |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
log.info("短信发送用户列表",users); |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
List<String> phoneList = Arrays.asList("18351807087", "18163793336", "18285121497"); |
|
|
|
|
|
|
|
for (String phone : phoneList) { |
|
|
|
|
|
|
|
R<UserInfo> userByPhone = userClient.getUserByPhone("200000", phone); |
|
|
|
|
|
|
|
if (userByPhone.isSuccess() && ObjectUtils.isNotEmpty(userByPhone.getData())) { |
|
|
|
|
|
|
|
users.add(userByPhone.getData().getUser()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
log.info("短信发送用户列表",users); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
SmsImmediatelyPushDTO push = SmsImmediatelyPushDTO.builder() |
|
|
|
SmsImmediatelyPushDTO push = SmsImmediatelyPushDTO.builder() |
|
|
|
.deptId(entity.getCreateDept()) |
|
|
|
.deptId(entity.getCreateDept()) |
|
|
|
.taskId(entity.getId()) |
|
|
|
.taskId(entity.getId()) |
|
|
@ -122,7 +142,7 @@ public class MessageServiceImpl implements MessageService { |
|
|
|
.content(entity.getAlarmContext()) |
|
|
|
.content(entity.getAlarmContext()) |
|
|
|
.subject("告警短信通知") |
|
|
|
.subject("告警短信通知") |
|
|
|
.tenantId(entity.getTenantId()) |
|
|
|
.tenantId(entity.getTenantId()) |
|
|
|
.resourceCode(AlarmConstants.SMS_MESSAGE_TEMPLATE_CODE) |
|
|
|
.resourceCode(msgTemplate) |
|
|
|
.pusher(users.stream().map(o->o.getId().toString()).collect(Collectors.joining(","))) |
|
|
|
.pusher(users.stream().map(o->o.getId().toString()).collect(Collectors.joining(","))) |
|
|
|
.createUser(CommonConstant.SYSTEM_USER) |
|
|
|
.createUser(CommonConstant.SYSTEM_USER) |
|
|
|
.params(new HashMap<String,String>(){{ |
|
|
|
.params(new HashMap<String,String>(){{ |
|
|
@ -146,19 +166,35 @@ public class MessageServiceImpl implements MessageService { |
|
|
|
log.error("微信消息发送失败:站点code获取失败 : {}",entity); |
|
|
|
log.error("微信消息发送失败:站点code获取失败 : {}",entity); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
List<User> userList=new ArrayList<>(); |
|
|
|
// 获取站点用户
|
|
|
|
// 获取站点用户
|
|
|
|
R<List<User>> result = userClient.userByDeptIdLevel(station.getData().getRefDept(),0); |
|
|
|
if (wxPushEnabled){ |
|
|
|
if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { |
|
|
|
R<List<User>> result = userClient.userByDeptIdLevel(station.getData().getRefDept(),1); |
|
|
|
log.error("微信消息发送失败:用户获取失败 : {}",entity); |
|
|
|
if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { |
|
|
|
return; |
|
|
|
log.error("微信公众号消息发送失败:用户获取失败 : {}",entity); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
userList.addAll(result.getData()); |
|
|
|
|
|
|
|
log.info("短信发送用户列表",userList); |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
//内测只推给对应的3个用户
|
|
|
|
|
|
|
|
List<String> phoneList = Arrays.asList("18351807087", "18163793336", "18285121497"); |
|
|
|
|
|
|
|
for (String phone : phoneList) { |
|
|
|
|
|
|
|
R<UserInfo> userByPhone = userClient.getUserByPhone("200000", phone); |
|
|
|
|
|
|
|
if (userByPhone.isSuccess() && ObjectUtils.isNotEmpty(userByPhone.getData())) { |
|
|
|
|
|
|
|
userList.add(userByPhone.getData().getUser()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
log.info("短信发送用户列表",userList); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
String userIds = userList.stream().map(o -> String.valueOf(o.getId())).distinct().collect(Collectors.joining(",")); |
|
|
|
WxMessageDTO message = new WxMessageDTO(); |
|
|
|
WxMessageDTO message = new WxMessageDTO(); |
|
|
|
// 模板Id
|
|
|
|
// 模板Id
|
|
|
|
message.setTemplateId("hIgINCsjpG-gyCKh8wzwBeRL9tanTLqRDgv-X8B9vyc"); |
|
|
|
message.setTemplateId(wxPushTemplate); |
|
|
|
// // 微信消息跳转地址
|
|
|
|
// // 微信消息跳转地址
|
|
|
|
// message.setSkipUrl("http://baidu.com");
|
|
|
|
// message.setSkipUrl("http://baidu.com");
|
|
|
|
// 机构Id
|
|
|
|
// 机构Id
|
|
|
|
message.setDeptId(result.getData().get(0).getId()); |
|
|
|
message.setDeptId(station.getData().getRefDept()); |
|
|
|
// 业务关键字
|
|
|
|
// 业务关键字
|
|
|
|
message.setBusinessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey()); |
|
|
|
message.setBusinessKey(MessageConstants.BusinessClassifyEnum.WARNING.getKey()); |
|
|
|
// 业务分类关键字
|
|
|
|
// 业务分类关键字
|
|
|
@ -178,9 +214,9 @@ public class MessageServiceImpl implements MessageService { |
|
|
|
// 消息主题
|
|
|
|
// 消息主题
|
|
|
|
message.setSubject(MessageConstants.BusinessClassifyEnum.WARNING.getDescription()); |
|
|
|
message.setSubject(MessageConstants.BusinessClassifyEnum.WARNING.getDescription()); |
|
|
|
// 推送用户
|
|
|
|
// 推送用户
|
|
|
|
message.setUserIds(result.getData().stream().map(o->String.valueOf(o.getId())).distinct().collect(Collectors.joining(","))); |
|
|
|
message.setUserIds(userIds); |
|
|
|
// 创建用户
|
|
|
|
// 创建用户
|
|
|
|
message.setCreateUser(result.getData().get(0).getId()); |
|
|
|
message.setCreateUser(userList.get(0).getId()); |
|
|
|
// 租户Id
|
|
|
|
// 租户Id
|
|
|
|
message.setTenantId(station.getData().getTenantId()); |
|
|
|
message.setTenantId(station.getData().getTenantId()); |
|
|
|
messageClient.sendWxMessage(message); |
|
|
|
messageClient.sendWxMessage(message); |
|
|
|