2023-02-16 15:28:15 +08:00
|
|
|
package com.zhgd.xmgl.async;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
import com.zhgd.mqtt.bean.PushPayload;
|
|
|
|
|
import com.zhgd.mqtt.server.IMqttSender;
|
2024-01-19 11:26:36 +08:00
|
|
|
import com.zhgd.xmgl.modules.basicdata.constant.DictionaryConstant;
|
2023-02-16 15:28:15 +08:00
|
|
|
import com.zhgd.xmgl.modules.basicdata.entity.CompanyConfig;
|
2024-01-19 11:26:36 +08:00
|
|
|
import com.zhgd.xmgl.modules.basicdata.entity.DictionaryItem;
|
2023-02-16 15:28:15 +08:00
|
|
|
import com.zhgd.xmgl.modules.basicdata.entity.SystemUser;
|
|
|
|
|
import com.zhgd.xmgl.modules.basicdata.mapper.SystemUserMapper;
|
|
|
|
|
import com.zhgd.xmgl.modules.basicdata.service.ICompanyConfigService;
|
|
|
|
|
import com.zhgd.xmgl.modules.basicdata.service.ISystemUserService;
|
2024-01-19 11:26:36 +08:00
|
|
|
import com.zhgd.xmgl.modules.basicdata.service.impl.DictionaryItemServiceImpl;
|
2023-02-16 15:28:15 +08:00
|
|
|
import com.zhgd.xmgl.modules.video.entity.AiAnalyseHardWareAlarmRecord;
|
|
|
|
|
import com.zhgd.xmgl.push.service.UniPushService;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
|
|
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;
|
2024-01-19 11:26:36 +08:00
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
2023-02-16 15:28:15 +08:00
|
|
|
|
2024-01-19 11:26:36 +08:00
|
|
|
import java.util.Arrays;
|
2023-02-16 15:28:15 +08:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @program: wisdomSite
|
|
|
|
|
* @description: 异步AI分析数据处理
|
|
|
|
|
* @author: Mr.Peng
|
|
|
|
|
* @create: 2022-04-20 14:09
|
|
|
|
|
**/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Component
|
|
|
|
|
public class AsyncAiAnalyse {
|
|
|
|
|
@Autowired
|
|
|
|
|
private IMqttSender mqttPushClient;
|
|
|
|
|
@Autowired
|
|
|
|
|
private SystemUserMapper systemUserMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISystemUserService systemUserService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ICompanyConfigService companyConfigService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private UniPushService uniPushService;
|
2024-01-19 11:26:36 +08:00
|
|
|
@Autowired
|
|
|
|
|
private DictionaryItemServiceImpl dictionaryItemService;
|
2023-02-16 15:28:15 +08:00
|
|
|
|
|
|
|
|
@Value("${mqtt-scope}")
|
|
|
|
|
private String scope;
|
|
|
|
|
|
|
|
|
|
@Async("taskExecutor")
|
|
|
|
|
public void sendAiAnalyse(AiAnalyseHardWareAlarmRecord aiAnalyseHardWareAlarmRecord) {
|
|
|
|
|
try {
|
|
|
|
|
String title = getTitleByAlarmType(aiAnalyseHardWareAlarmRecord.getAlarmType());
|
|
|
|
|
String msg = title + ",位置" + aiAnalyseHardWareAlarmRecord.getLocation();
|
2024-01-19 11:26:36 +08:00
|
|
|
List<SystemUser> systemUserList = systemUserService.list(Wrappers.<SystemUser>lambdaQuery().eq(SystemUser::getSn, aiAnalyseHardWareAlarmRecord.getProjectSn())
|
|
|
|
|
.in(SystemUser::getAccountType, Arrays.asList(5, 6)));
|
2023-02-16 15:28:15 +08:00
|
|
|
title = "AI分析" + title;
|
|
|
|
|
//向项目管理员和子账号推送通知
|
|
|
|
|
if (systemUserList.size() > 0) {
|
|
|
|
|
for (SystemUser systemUser : systemUserList) {
|
|
|
|
|
PushPayload pushMessage = PushPayload.getPushPayloadBuider().setAccountId(systemUser.getUserId().toString())
|
|
|
|
|
.setTitle(title)
|
|
|
|
|
.setContent(msg)
|
|
|
|
|
.setType("8")
|
|
|
|
|
.setItemType(aiAnalyseHardWareAlarmRecord.getAlarmType().toString())
|
|
|
|
|
.bulid();
|
|
|
|
|
String kdTopic = scope + systemUser.getUserId();
|
|
|
|
|
mqttPushClient.sendToMqtt(kdTopic, pushMessage.toString());
|
|
|
|
|
}
|
|
|
|
|
sendAppNotice(aiAnalyseHardWareAlarmRecord.getProjectSn(), title, msg, systemUserList, "/pages/potentialRisk/potentialRisk?id=" + aiAnalyseHardWareAlarmRecord.getId());
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getTitleByAlarmType(Integer alarmType) {
|
2024-01-19 11:26:36 +08:00
|
|
|
DictionaryItem dict = dictionaryItemService.getDict(DictionaryConstant.AI_ANALYSE_HARD_WARE_ALARM_RECORD_TYPE, alarmType + "");
|
|
|
|
|
return dict != null ? dict.getName() : null;
|
2023-02-16 15:28:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 向手机端推送通知
|
|
|
|
|
*
|
|
|
|
|
* @param projectSn
|
|
|
|
|
* @param title
|
|
|
|
|
* @param msg
|
|
|
|
|
* @param systemUserList
|
|
|
|
|
*/
|
|
|
|
|
public void sendAppNotice(String projectSn, String title, String msg, List<SystemUser> systemUserList, String payload) {
|
|
|
|
|
try {
|
|
|
|
|
CompanyConfig companyConfig = companyConfigService.getCompanyConfigByProjectSn(projectSn);
|
|
|
|
|
log.info("companyConfig-------------发送开关" + (companyConfig == null ? "" : companyConfig.getAppNoticeType()));
|
|
|
|
|
if (companyConfig != null && companyConfig.getAppNoticeType() != null && companyConfig.getAppNoticeType() == 1) {
|
|
|
|
|
for (SystemUser systemUser : systemUserList) {
|
|
|
|
|
if (systemUser.getAccountType() == 5 || systemUser.getAccountType() == 6) {
|
|
|
|
|
log.info("发送-----" + systemUser.getAccount() + "消息:" + msg);
|
|
|
|
|
uniPushService.pushToSingleByAlias(systemUser.getClientId(), title, msg, payload);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 责任人收到AI警告后推送消息给整改责任人
|
|
|
|
|
*
|
|
|
|
|
* @param record AI警告消息
|
|
|
|
|
* @param systemUserList 需要推送的人员集合
|
|
|
|
|
*/
|
|
|
|
|
public void sendCorrectAnalyse(AiAnalyseHardWareAlarmRecord record, List<SystemUser> systemUserList) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String msg = "你有一条待整改消息,位置-----" + record.getLocation();
|
|
|
|
|
String title = getTitleByAlarmType(record.getAlarmType());
|
|
|
|
|
if (CollectionUtils.isNotEmpty(systemUserList)) {
|
|
|
|
|
for (SystemUser systemUser : systemUserList) {
|
|
|
|
|
log.info(systemUser.getAccount() + "有一条消息,位置-----" + record.getLocation());
|
|
|
|
|
PushPayload pushMessage = PushPayload.getPushPayloadBuider().setAccountId(systemUser.getUserId().toString())
|
|
|
|
|
.setTitle(title)
|
|
|
|
|
.setContent(msg)
|
|
|
|
|
.setType("8")
|
|
|
|
|
.setItemType(record.getAlarmType().toString()).bulid();
|
|
|
|
|
String kdTopic = scope + systemUser.getUserId();
|
|
|
|
|
mqttPushClient.sendToMqtt(kdTopic, pushMessage.toString());
|
|
|
|
|
}
|
|
|
|
|
sendAppNotice(record.getProjectSn(), title, msg, systemUserList, "/pages/potentialRisk/potentialRisk?id=" + record.getId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 推送巡检信息到责任人
|
|
|
|
|
*/
|
|
|
|
|
public void sendMsgGotoPeople(List<SystemUser> systemUserList) {
|
|
|
|
|
String msg = "您有一条日常巡检信息待处理请及时处理";
|
|
|
|
|
String title = "日常巡检";
|
|
|
|
|
if (CollectionUtils.isNotEmpty(systemUserList)) {
|
|
|
|
|
for (SystemUser systemUser : systemUserList) {
|
|
|
|
|
log.info(systemUser.getAccount() + "有一条消息");
|
|
|
|
|
PushPayload pushMessage = PushPayload.getPushPayloadBuider().setAccountId(systemUser.getUserId().toString())
|
|
|
|
|
.setTitle(title)
|
|
|
|
|
.setContent(msg)
|
|
|
|
|
.setType("8")
|
|
|
|
|
.setItemType("日常巡检".toString()).bulid();
|
|
|
|
|
String kdTopic = scope + systemUser.getUserId();
|
|
|
|
|
mqttPushClient.sendToMqtt(kdTopic, pushMessage.toString());
|
|
|
|
|
}
|
|
|
|
|
sendMsgToApp(title, msg, systemUserList, "/pages/projectEnd/dailyCheck/index");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 巡检消息推送到责任人
|
|
|
|
|
*
|
|
|
|
|
* @param title
|
|
|
|
|
* @param msg
|
|
|
|
|
* @param systemUserList
|
|
|
|
|
* @param payload
|
|
|
|
|
*/
|
|
|
|
|
private void sendMsgToApp(String title, String msg, List<SystemUser> systemUserList, String payload) {
|
|
|
|
|
try {
|
|
|
|
|
for (SystemUser systemUser : systemUserList) {
|
|
|
|
|
if (systemUser.getAccountType() == 5 || systemUser.getAccountType() == 6) {
|
|
|
|
|
log.info("发送-----" + systemUser.getAccount() + "消息:" + msg);
|
|
|
|
|
uniPushService.pushToSingleByAlias(systemUser.getClientId(), title, msg, payload);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|