114 lines
4.5 KiB
Java
114 lines
4.5 KiB
Java
package com.zhgd.xmgl.async;
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.zhgd.xmgl.modules.basicdata.entity.MessageRecord;
|
|
import com.zhgd.xmgl.modules.basicdata.entity.Notice;
|
|
import com.zhgd.xmgl.modules.basicdata.entity.NoticeAccept;
|
|
import com.zhgd.xmgl.modules.basicdata.entity.Policy;
|
|
import com.zhgd.xmgl.modules.basicdata.service.IMessageRecordService;
|
|
import com.zhgd.xmgl.modules.city.basicdata.service.ISystemUserService;
|
|
import com.zhgd.xmgl.modules.city.basicdata.entity.SystemUser;
|
|
import com.zhgd.xmgl.push.service.UniPushService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* @program: wisdomSite
|
|
* @description: 异步通知到前端的代码处理
|
|
* @author: Mr.Peng
|
|
* @create: 2022-04-20 14:09
|
|
**/
|
|
@Slf4j
|
|
@Component
|
|
public class AsyncAiAnalyse {
|
|
@Autowired
|
|
private UniPushService uniPushService;
|
|
|
|
@Autowired
|
|
private ISystemUserService systemUserService;
|
|
|
|
@Autowired
|
|
private IMessageRecordService messageRecordService;
|
|
|
|
@Value("${mqtt-scope}")
|
|
private String scope;
|
|
|
|
|
|
@Async("taskExecutor")
|
|
public String getTitleByAlarmType(Integer alarmType) {
|
|
//1-烟感、2-明火、3-人员倒地、4-未戴安全帽、5-区域入侵、6-越界入侵、7-人员聚集衣 8-反光衣、9-裸土覆盖,13口罩识别,14徘徊预警,15物体滞留监测,16绊线监测
|
|
String title = "";
|
|
if (alarmType == 1) {
|
|
title = "烟感报警";
|
|
} else if (alarmType == 2) {
|
|
title = "明火报警";
|
|
} else if (alarmType == 3) {
|
|
title = "人员倒地报警";
|
|
} else if (alarmType == 4) {
|
|
title = "未戴安全帽报警";
|
|
} else if (alarmType == 5) {
|
|
title = "区域入侵报警";
|
|
} else if (alarmType == 6) {
|
|
title = "越界入侵报警";
|
|
} else if (alarmType == 7) {
|
|
title = "人员聚集衣报警";
|
|
} else if (alarmType == 8) {
|
|
title = "反光衣报警";
|
|
} else if (alarmType == 9) {
|
|
title = "裸土覆盖报警";
|
|
} else if (alarmType == 13) {
|
|
title = "口罩识别报警";
|
|
} else if (alarmType == 14) {
|
|
title = "徘徊预警";
|
|
} else if (alarmType == 15) {
|
|
title = "物体滞留监测";
|
|
} else if (alarmType == 16) {
|
|
title = "绊线监测";
|
|
}
|
|
return title;
|
|
}
|
|
|
|
@Async("taskExecutor")
|
|
public void pushNotice(List<NoticeAccept> accepts, Notice notice) {
|
|
List<String> alias = new ArrayList<>();
|
|
List<String> snList = accepts.stream().filter(a -> a.getAcceptType() != 2).map(a -> a.getAccept()).collect(Collectors.toList());
|
|
List<String> userIdList = accepts.stream().filter(a -> a.getAcceptType() == 2).map(a -> a.getAccept()).collect(Collectors.toList());
|
|
if (snList.size() > 0) {
|
|
alias = systemUserService.list(Wrappers.<SystemUser>lambdaQuery().in(SystemUser::getSn, snList)).stream().map(u -> u.getUserId()).collect(Collectors.toList());
|
|
}
|
|
alias.addAll(userIdList);
|
|
if (alias.size() == 0) {
|
|
return;
|
|
}
|
|
uniPushService.pushListByAlias(alias, notice.getTitle(), notice.getContent(), "notice_" + notice.getNoticeId());
|
|
savePushRecord(notice.getNoticeId().toString(), 1, notice.getCreateTime(), notice.getTitle(), alias);
|
|
}
|
|
|
|
@Async("taskExecutor")
|
|
public void pushPolicy(String govSn, Policy policy) {
|
|
List<String> userIds = systemUserService.getUserIdsByGovAndType(govSn, policy.getAcceptType());
|
|
if (userIds.size() == 0) {
|
|
return;
|
|
}
|
|
uniPushService.pushListByAlias(userIds, policy.getTitle(), policy.getContent(), "policy_" + policy.getPolicyId());
|
|
savePushRecord(policy.getPolicyId().toString(), 2, policy.getCreateTime(), policy.getTitle(), userIds);
|
|
}
|
|
|
|
private void savePushRecord(String messageId, Integer type, Date createTime, String title, List<String> userIds) {
|
|
MessageRecord messageRecord = new MessageRecord();
|
|
messageRecord.setMessageId(messageId);
|
|
messageRecord.setType(type);
|
|
messageRecord.setLastTime(createTime);
|
|
messageRecord.setTitle(title);
|
|
messageRecordService.saveOrUpdateInfo(messageRecord, userIds);
|
|
}
|
|
}
|