消息推送调整

This commit is contained in:
2023-11-09 09:12:26 +08:00
parent 14817411aa
commit 9988efc501

View File

@@ -22,6 +22,7 @@ import com.njcn.zlevent.service.ICsEventUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.io.BufferedReader;
@@ -86,7 +87,7 @@ public class SendEventUtils {
public void sendUser(Integer eventType,String type,String devId, String eventName, LocalDateTime eventTime, String id) {
int code;
List<User> users = new ArrayList<>();
List<String> devCodeList = new ArrayList<>();
List<String> devCodeList;
List<CsEventSendMsg> csEventSendMsgList = new ArrayList<>();
NoticeUserDto noticeUserDto = new NoticeUserDto();
NoticeUserDto.Payload payload = new NoticeUserDto.Payload();
@@ -99,20 +100,22 @@ public class SendEventUtils {
case "1":
code = 2;
//设备自身事件 不推送给用户,推送给业务管理
users = appUserFeignClient.getAdminInfo().getData();
noticeUserDto.setPushClientId(Collections.singletonList(users.get(0).getDevCode()));
noticeUserDto.setTitle("设备事件");
//记录需要通知的用户和事件关系
CsEventUserPO csEventUser = new CsEventUserPO();
csEventUser.setUserId(users.get(0).getId());
csEventUser.setStatus(0);
csEventUser.setEventId(id);
result.add(csEventUser);
users = getAdminUser();
if (CollectionUtil.isNotEmpty(users)){
noticeUserDto.setPushClientId(Collections.singletonList(users.get(0).getDevCode()));
noticeUserDto.setTitle("设备事件");
//记录需要通知的用户和事件关系
CsEventUserPO csEventUser = new CsEventUserPO();
csEventUser.setUserId(users.get(0).getId());
csEventUser.setStatus(0);
csEventUser.setEventId(id);
result.add(csEventUser);
}
break;
case "2":
code = 0;
//暂态事件
users = getEventUser(devId);
users = getEventUser(devId,0);
devCodeList = users.stream().map(User::getDevCode).collect(Collectors.toList());
noticeUserDto.setPushClientId(devCodeList);
noticeUserDto.setTitle("暂态事件");
@@ -129,7 +132,7 @@ public class SendEventUtils {
case "3":
code = 1;
//稳态事件
users = getEventUser(devId);
users = getEventUser(devId,1);
devCodeList = users.stream().map(User::getDevCode).collect(Collectors.toList());
noticeUserDto.setPushClientId(devCodeList);
noticeUserDto.setTitle("稳态事件");
@@ -159,24 +162,26 @@ public class SendEventUtils {
else if (eventType == 2){
switch (type) {
case "1":
eventName = epdFeignClient.findByName(eventName).getData().getShowName();
//Ⅰ级告警 不推送给用户,推送给业务管理
users = appUserFeignClient.getAdminInfo().getData();
noticeUserDto.setPushClientId(Collections.singletonList(users.get(0).getDevCode()));
//记录需要通知的用户和事件关系
users.forEach(item->{
CsEventUserPO csEventUser = new CsEventUserPO();
csEventUser.setUserId(item.getId());
csEventUser.setStatus(0);
csEventUser.setEventId(id);
result.add(csEventUser);
});
users = getAdminUser();
if (CollectionUtil.isNotEmpty(users)){
eventName = epdFeignClient.findByName(eventName).getData().getShowName();
noticeUserDto.setPushClientId(Collections.singletonList(users.get(0).getDevCode()));
//记录需要通知的用户和事件关系
users.forEach(item->{
CsEventUserPO csEventUser = new CsEventUserPO();
csEventUser.setUserId(item.getId());
csEventUser.setStatus(0);
csEventUser.setEventId(id);
result.add(csEventUser);
});
}
break;
case "2":
eventName = epdFeignClient.findByName(eventName).getData().getShowName();
case "3":
//Ⅱ、Ⅲ级告警推送相关用户及业务管理员
users = getEventUser(devId);
users = getEventUser(devId,3);
devCodeList = users.stream().map(User::getDevCode).collect(Collectors.toList());
noticeUserDto.setPushClientId(devCodeList);
//记录需要通知的用户和事件关系
@@ -265,25 +270,58 @@ public class SendEventUtils {
}
/**
* 获取需要通知暂态事件的用户
* 获取需要通知事件的用户
*/
public List<User> getEventUser(String devId) {
public List<User> getEventUser(String devId,Integer type) {
List<User> users = new ArrayList<>();
List<String> result = new ArrayList<>();
//获取设备下主用户和子用户集合
List<String> list = csDeviceUserFeignClient.findUserById(devId).getData();
List<User> adminUser = appUserFeignClient.getAdminInfo().getData();
List<String> adminList = adminUser.stream().map(User::getId).collect(Collectors.toList());
list.addAll(adminList);
//查询哪些用户打开了事件提示
if (CollectionUtil.isNotEmpty(list)){
List<AppInfoSet> appInfoSet = appInfoSetFeignClient.getListById(list).getData();
result = appInfoSet.stream()
.filter(person -> person.getEventInfo() == 1)
.map(AppInfoSet::getUserId).collect(Collectors.toList());
switch (type) {
case 0:
result = appInfoSet.stream()
.filter(person -> person.getEventInfo() == 1)
.map(AppInfoSet::getUserId).collect(Collectors.toList());
break;
case 1:
result = appInfoSet.stream()
.filter(person -> person.getHarmonicInfo() == 1)
.map(AppInfoSet::getUserId).collect(Collectors.toList());
break;
case 3:
result = appInfoSet.stream()
.filter(person -> person.getAlarmInfo() == 1)
.map(AppInfoSet::getUserId).collect(Collectors.toList());
break;
default:
break;
}
}
if (CollectionUtil.isNotEmpty(list)){
if (CollectionUtil.isNotEmpty(result)){
users = userFeignClient.getUserByIdList(result).getData();
}
return users;
}
public List<User> getAdminUser() {
List<User> users = appUserFeignClient.getAdminInfo().getData();
List<String> result = new ArrayList<>();
List<String> adminList = users.stream().map(User::getId).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(adminList)){
List<AppInfoSet> appInfoSet = appInfoSetFeignClient.getListById(adminList).getData();
result = appInfoSet.stream()
.filter(person -> person.getRunInfo() == 1)
.map(AppInfoSet::getUserId).collect(Collectors.toList());
}
if (CollectionUtil.isNotEmpty(result)){
users = userFeignClient.getUserByIdList(result).getData();
}
List<User> adminUser = appUserFeignClient.getAdminInfo().getData();
users.addAll(adminUser);
return users;
}