消息推送调整

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