代码优化
1.推送消息屏蔽,只推送治理设备信息; 2.文件下载优化 3.公共方法提取
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package com.njcn.zlevent.pojo.dto;
|
||||
package com.njcn.access.pojo.dto;
|
||||
|
||||
import com.njcn.access.annotation.ParamName;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.njcn.access.utils;
|
||||
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.njcn.access.pojo.dto.NoticeUserDto;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* 推送消息
|
||||
* @author xy
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class SendMessageUtil {
|
||||
|
||||
public void sendEventToUser(NoticeUserDto noticeUserDto) {
|
||||
try {
|
||||
// 创建一个URL对象,指定目标HTTPS接口地址
|
||||
URL url = new URL("https://fc-mp-ff7b310f-94c9-4468-8260-109111c0a6b2.next.bspapp.com/push");
|
||||
// 打开HTTPS连接
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
// 设置请求方法为POST
|
||||
connection.setRequestMethod("POST");
|
||||
// 设置请求头,指定Content-Type为application/json
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
// 启用输出流以发送JSON数据
|
||||
connection.setDoOutput(true);
|
||||
// 将JSON数据写入输出流
|
||||
OutputStream outputStream = connection.getOutputStream();
|
||||
log.info(new Gson().toJson(noticeUserDto).replace("pushClientId", "push_clientid"));
|
||||
outputStream.write(new Gson().toJson(noticeUserDto).replace("pushClientId", "push_clientid").getBytes(StandardCharsets.UTF_8));
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
// 获取响应代码
|
||||
int responseCode = connection.getResponseCode();
|
||||
log.info("Response Code: " + responseCode);
|
||||
// 读取响应数据
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String inputLine;
|
||||
StringBuilder response = new StringBuilder();
|
||||
while ((inputLine = reader.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
}
|
||||
reader.close();
|
||||
// 打印响应内容
|
||||
log.info("Response Content: " + response.toString());
|
||||
// 关闭连接
|
||||
connection.disconnect();
|
||||
} catch (IOException e) {
|
||||
e.getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -339,7 +339,7 @@ public class MqttMessageHandler {
|
||||
//更新电网侧、负载侧监测点信息
|
||||
askDevData(nDid,version,3,(res.getMid()+1));
|
||||
//录波任务倒计时
|
||||
redisUtil.saveByKeyWithExpire("startFile",null,120L);
|
||||
redisUtil.saveByKeyWithExpire("startFile:" + nDid,null,60L);
|
||||
} else {
|
||||
log.info(AccessResponseEnum.ACCESS_RESPONSE_ERROR.getMessage());
|
||||
logDto.setResult(0);
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package com.njcn.access.listener;
|
||||
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.njcn.access.enums.AccessEnum;
|
||||
import com.njcn.access.pojo.dto.NoticeUserDto;
|
||||
import com.njcn.access.pojo.po.CsDeviceOnlineLogs;
|
||||
import com.njcn.access.service.ICsDeviceOnlineLogsService;
|
||||
import com.njcn.access.service.ICsEquipmentDeliveryService;
|
||||
import com.njcn.access.service.ICsTopicService;
|
||||
import com.njcn.access.service.impl.CsDeviceServiceImpl;
|
||||
import com.njcn.access.utils.MqttUtil;
|
||||
import com.njcn.access.utils.SendMessageUtil;
|
||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||
import com.njcn.csdevice.api.CsDeviceUserFeignClient;
|
||||
import com.njcn.csdevice.api.CsLedgerFeignClient;
|
||||
@@ -20,7 +21,6 @@ import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.user.api.AppUserFeignClient;
|
||||
import com.njcn.user.api.UserFeignClient;
|
||||
import com.njcn.user.pojo.po.User;
|
||||
import com.njcn.zlevent.pojo.dto.NoticeUserDto;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.redis.connection.Message;
|
||||
@@ -29,13 +29,6 @@ import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
@@ -79,6 +72,8 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
private UserFeignClient userFeignClient;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private SendMessageUtil sendMessageUtil;
|
||||
private final Object lock = new Object();
|
||||
|
||||
public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
|
||||
@@ -153,7 +148,7 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
private void startScheduledTask(ScheduledExecutorService scheduler, String nDid, String version) {
|
||||
synchronized (lock) {
|
||||
NoticeUserDto dto = sendOffLine(nDid);
|
||||
sendEventToUser(dto);
|
||||
sendMessageUtil.sendEventToUser(dto);
|
||||
addLogs(dto);
|
||||
String clientName = "NJCN-" + nDid.substring(nDid.length() - 6);
|
||||
ScheduledFuture<?> future = scheduler.scheduleAtFixedRate(() -> {
|
||||
@@ -178,7 +173,7 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
MAX_WARNING_TIMES++;
|
||||
if (MAX_WARNING_TIMES == 30) {
|
||||
NoticeUserDto dto2 = sendConnectFail(nDid);
|
||||
sendEventToUser(dto2);
|
||||
sendMessageUtil.sendEventToUser(dto2);
|
||||
addLogs(dto2);
|
||||
}
|
||||
//记录装置掉线时间
|
||||
@@ -194,7 +189,7 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
MAX_WARNING_TIMES++;
|
||||
if (MAX_WARNING_TIMES == 30) {
|
||||
NoticeUserDto dto2 = sendConnectFail(nDid);
|
||||
sendEventToUser(dto2);
|
||||
sendMessageUtil.sendEventToUser(dto2);
|
||||
addLogs(dto2);
|
||||
}
|
||||
logDto.setResult(0);
|
||||
@@ -260,42 +255,4 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
List<User> users = userFeignClient.appuserByIdList(adminList).getData();
|
||||
return users.stream().map(User::getDevCode).filter(Objects::nonNull).filter(StringUtils::isNotBlank).distinct().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void sendEventToUser(NoticeUserDto noticeUserDto) {
|
||||
try {
|
||||
// 创建一个URL对象,指定目标HTTPS接口地址
|
||||
URL url = new URL("https://fc-mp-ff7b310f-94c9-4468-8260-109111c0a6b2.next.bspapp.com/push");
|
||||
// 打开HTTPS连接
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
// 设置请求方法为POST
|
||||
connection.setRequestMethod("POST");
|
||||
// 设置请求头,指定Content-Type为application/json
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
// 启用输出流以发送JSON数据
|
||||
connection.setDoOutput(true);
|
||||
// 将JSON数据写入输出流
|
||||
OutputStream outputStream = connection.getOutputStream();
|
||||
log.info(new Gson().toJson(noticeUserDto).replace("pushClientId", "push_clientid"));
|
||||
outputStream.write(new Gson().toJson(noticeUserDto).replace("pushClientId", "push_clientid").getBytes(StandardCharsets.UTF_8));
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
// 获取响应代码
|
||||
int responseCode = connection.getResponseCode();
|
||||
log.info("Response Code: " + responseCode);
|
||||
// 读取响应数据
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String inputLine;
|
||||
StringBuilder response = new StringBuilder();
|
||||
while ((inputLine = reader.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
}
|
||||
reader.close();
|
||||
// 打印响应内容
|
||||
log.info("Response Content: " + response.toString());
|
||||
// 关闭连接
|
||||
connection.disconnect();
|
||||
} catch (IOException e) {
|
||||
e.getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.pojo.po.SysDicTreePO;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -52,6 +53,7 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
@Slf4j
|
||||
public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CsDeviceServiceImpl.class);
|
||||
@@ -575,7 +577,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
//发起接入
|
||||
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid, new Gson().toJson(getJson(mid,TypeEnum.TYPE_5.getCode())),1,false);
|
||||
//录波任务倒计时
|
||||
redisUtil.saveByKeyWithExpire("startFile",null,120L);
|
||||
redisUtil.saveByKeyWithExpire("startFile:" + nDid,null,60L);
|
||||
result = true;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
@@ -98,6 +98,12 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
downloadFile(missingList,dto.getNDid(),fileName);
|
||||
}
|
||||
}
|
||||
//重新接入之后,装置60s后开始消费缓存的录波文件
|
||||
else if (expiredKey.startsWith("startFile:")) {
|
||||
String nDid = expiredKey.split(":")[1];
|
||||
//处理缓存数据
|
||||
csWaveAnalysisService.channelWave(nDid);
|
||||
}
|
||||
//手动文件下载
|
||||
else if (expiredKey.startsWith(AppRedisKey.FILE_DOWN_TIME)) {
|
||||
List<Integer> missingList = new ArrayList<>();
|
||||
|
||||
@@ -77,9 +77,9 @@ public class CsAlarmServiceImpl extends ServiceImpl<CsEventMapper, CsEventPO> im
|
||||
//推送事件逻辑处理 && cs_event_user入库 && 修改字典中告警事件的编码
|
||||
for (AppEventMessage.DataArray item : dataArray) {
|
||||
if (Objects.isNull(item.getCode())){
|
||||
sendEventUtils.sendUser(2,item.getType(),po.getId(),item.getName(),eventTime,id);
|
||||
sendEventUtils.sendUser(2,item.getType(),po.getId(),item.getName(),eventTime,id,po.getNdid());
|
||||
} else {
|
||||
sendEventUtils.sendUser(2,item.getType(),po.getId(),item.getCode(),eventTime,id);
|
||||
sendEventUtils.sendUser(2,item.getType(),po.getId(),item.getCode(),eventTime,id,po.getNdid());
|
||||
//更新字典信息
|
||||
EleEpdPqd eleEpdPqd = epdFeignClient.findByName(item.getName()).getData();
|
||||
EleEpdPqdParam.EleEpdPqdUpdateParam updateParam = new EleEpdPqdParam.EleEpdPqdUpdateParam();
|
||||
|
||||
@@ -129,6 +129,8 @@ public class CsWaveAnalysisServiceImpl implements ICsWaveAnalysisService {
|
||||
} else {
|
||||
throw new BusinessException(AlgorithmResponseEnum.FILE_DOWNLOADING);
|
||||
}
|
||||
} else {
|
||||
throw new BusinessException(AlgorithmResponseEnum.DEV_OFFLINE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -169,7 +169,7 @@ public class EventServiceImpl implements IEventService {
|
||||
csEventService.saveBatch(list1);
|
||||
//推送事件逻辑处理 && cs_event_user入库
|
||||
for (AppEventMessage.DataArray item : dataArray) {
|
||||
sendEventUtils.sendUser(1,item.getType(),po.getId(),item.getName(),eventTime,id);
|
||||
sendEventUtils.sendUser(1,item.getType(),po.getId(),item.getName(),eventTime,id,po.getNdid());
|
||||
}
|
||||
}
|
||||
//evt_data入库
|
||||
|
||||
@@ -16,7 +16,6 @@ import com.njcn.access.utils.ChannelObjectUtil;
|
||||
import com.njcn.common.config.GeneralInfo;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.csharmonic.api.WavePicFeignClient;
|
||||
import com.njcn.mq.message.AppFileMessage;
|
||||
import com.njcn.oss.constant.GeneralConstant;
|
||||
@@ -24,15 +23,16 @@ import com.njcn.oss.constant.OssPath;
|
||||
import com.njcn.oss.utils.FileStorageUtil;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.system.api.DictTreeFeignClient;
|
||||
import com.njcn.system.enums.DicTreeEnum;
|
||||
import com.njcn.zlevent.param.CsEventParam;
|
||||
import com.njcn.zlevent.pojo.dto.FileInfoDto;
|
||||
import com.njcn.zlevent.pojo.dto.FileStreamDto;
|
||||
import com.njcn.zlevent.pojo.dto.WaveTimeDto;
|
||||
import com.njcn.zlevent.pojo.po.CsEventFileLogs;
|
||||
import com.njcn.zlevent.pojo.po.CsWave;
|
||||
import com.njcn.zlevent.service.*;
|
||||
import com.njcn.zlevent.service.ICsEventFileLogsService;
|
||||
import com.njcn.zlevent.service.ICsEventService;
|
||||
import com.njcn.zlevent.service.ICsWaveService;
|
||||
import com.njcn.zlevent.service.IFileService;
|
||||
import com.njcn.zlevent.utils.RemoveInfoUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -65,11 +65,9 @@ public class FileServiceImpl implements IFileService {
|
||||
private final WavePicFeignClient wavePicFeignClient;
|
||||
private final ICsWaveService csWaveService;
|
||||
private final GeneralInfo generalInfo;
|
||||
private final ICsWaveAnalysisService iCsWaveAnalysisService;
|
||||
private final ChannelObjectUtil channelObjectUtil;
|
||||
private final RemoveInfoUtils removeInfoUtils;
|
||||
private static Integer mid = 1;
|
||||
private final DictTreeFeignClient dictTreeFeignClient;
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
|
||||
@Override
|
||||
@@ -141,10 +139,8 @@ public class FileServiceImpl implements IFileService {
|
||||
csEventLogs.setNdid(appFileMessage.getId());
|
||||
csEventLogs.setFileName(appFileMessage.getMsg().getName());
|
||||
csEventLogs.setStatus(0);
|
||||
//获取装置id
|
||||
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(appFileMessage.getId()).getData();
|
||||
//设备型号
|
||||
String code = dictTreeFeignClient.queryById(po.getDevModel()).getData().getCode();
|
||||
//判断设备类型 true:治理设备 false:其他设备
|
||||
boolean devModel = equipmentFeignClient.judgeDevModel(appFileMessage.getId()).getData();
|
||||
try {
|
||||
//todo 目前文件先只处理波形事件的,后续有其他文件再做处理
|
||||
String fileName = appFileMessage.getMsg().getName();
|
||||
@@ -266,7 +262,7 @@ public class FileServiceImpl implements IFileService {
|
||||
filePath = filePath.replaceAll(GeneralConstant.CFG,"").replaceAll(GeneralConstant.DAT,"");
|
||||
List<String> eventList = correlateEvents(fileInfoDto,filePath,fileName);
|
||||
//波形文件解析成图片
|
||||
if (CollectionUtil.isNotEmpty(eventList) && Objects.equals(DicTreeEnum.PQ_COM.getCode(),code)){
|
||||
if (CollectionUtil.isNotEmpty(eventList) && devModel){
|
||||
eventList.forEach(wavePicFeignClient::getWavePics);
|
||||
}
|
||||
//解析完删除、处理缓存
|
||||
@@ -312,7 +308,7 @@ public class FileServiceImpl implements IFileService {
|
||||
filePath = filePath.replaceAll(GeneralConstant.CFG, "").replaceAll(GeneralConstant.DAT, "");
|
||||
List<String> eventList = correlateEvents(fileInfoDto, filePath, fileName);
|
||||
//波形文件解析成图片
|
||||
if (CollectionUtil.isNotEmpty(eventList) && Objects.equals(DicTreeEnum.PQ_COM.getCode(),code)) {
|
||||
if (CollectionUtil.isNotEmpty(eventList) && devModel) {
|
||||
eventList.forEach(wavePicFeignClient::getWavePics);
|
||||
}
|
||||
redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(appFileMessage.getMsg().getName()));
|
||||
@@ -357,6 +353,18 @@ public class FileServiceImpl implements IFileService {
|
||||
csEventLogs.setCompleteTime(LocalDateTime.now());
|
||||
//记录日志
|
||||
csEventLogsService.save(csEventLogs);
|
||||
//清空缓存
|
||||
redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(appFileMessage.getMsg().getName()));
|
||||
redisUtil.delete(AppRedisKey.FILE_PART.concat(appFileMessage.getMsg().getName()));
|
||||
//删除临时文件
|
||||
String fileName = appFileMessage.getMsg().getName();
|
||||
String lsFileName = generalInfo.getBusinessTempPath() + File.separator + fileName.split(StrUtil.SLASH)[fileName.split(StrUtil.SLASH).length - 1];
|
||||
File file = new File(lsFileName);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
//继续消费
|
||||
removeInfoUtils.deleteEventInfo(appFileMessage.getId(),appFileMessage.getMsg().getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public class RemoveInfoUtils {
|
||||
// 删除相关的 Redis 键
|
||||
deleteRelatedKeys(nDid, fileName);
|
||||
// 处理重试逻辑
|
||||
if (retryTimes < 3) {
|
||||
if (retryTimes < 4) {
|
||||
// 增加重试次数并保存
|
||||
redisUtil.saveByKey(("retryEvent:" + nDid + fileName), retryTimes + 1);
|
||||
// 重排文件列表
|
||||
@@ -54,6 +54,8 @@ public class RemoveInfoUtils {
|
||||
} else {
|
||||
// 从列表中移除文件
|
||||
removeFileFromList(nDid, fileName);
|
||||
// 清空计数
|
||||
redisUtil.delete(("retryEvent:" + nDid + fileName));
|
||||
}
|
||||
// 检查是否还有其他文件需要处理
|
||||
List<WaveTimeDto> fileDto = channelObjectUtil.objectToList(redisUtil.getObjectByKey("eventFile:" + nDid), WaveTimeDto.class);
|
||||
|
||||
@@ -2,9 +2,11 @@ package com.njcn.zlevent.utils;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.njcn.access.pojo.dto.NoticeUserDto;
|
||||
import com.njcn.access.utils.SendMessageUtil;
|
||||
import com.njcn.csdevice.api.CsDeviceUserFeignClient;
|
||||
import com.njcn.csdevice.api.CsLedgerFeignClient;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
import com.njcn.csdevice.api.EventLogsFeignClient;
|
||||
import com.njcn.csdevice.pojo.dto.DevDetailDTO;
|
||||
import com.njcn.csdevice.pojo.po.CsEventSendMsg;
|
||||
@@ -15,20 +17,12 @@ import com.njcn.user.api.AppUserFeignClient;
|
||||
import com.njcn.user.api.UserFeignClient;
|
||||
import com.njcn.user.pojo.po.User;
|
||||
import com.njcn.user.pojo.po.app.AppInfoSet;
|
||||
import com.njcn.zlevent.pojo.dto.NoticeUserDto;
|
||||
import com.njcn.zlevent.service.ICsEventUserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -48,27 +42,24 @@ public class SendEventUtils {
|
||||
|
||||
@Resource
|
||||
private UserFeignClient userFeignClient;
|
||||
|
||||
@Resource
|
||||
private AppUserFeignClient appUserFeignClient;
|
||||
|
||||
@Resource
|
||||
private CsDeviceUserFeignClient csDeviceUserFeignClient;
|
||||
|
||||
@Resource
|
||||
private AppInfoSetFeignClient appInfoSetFeignClient;
|
||||
|
||||
@Resource
|
||||
private EventLogsFeignClient eventLogsFeignClient;
|
||||
|
||||
@Resource
|
||||
private EpdFeignClient epdFeignClient;
|
||||
|
||||
@Resource
|
||||
private ICsEventUserService csEventUserService;
|
||||
|
||||
@Resource
|
||||
private CsLedgerFeignClient csLedgerFeignclient;
|
||||
@Resource
|
||||
private SendMessageUtil sendMessageUtil;
|
||||
@Resource
|
||||
private EquipmentFeignClient equipmentFeignClient;
|
||||
|
||||
/**
|
||||
* 事件推送给相关用户
|
||||
@@ -80,7 +71,7 @@ public class SendEventUtils {
|
||||
* @param id 事件id
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
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, String nDid) {
|
||||
int code;
|
||||
List<User> users = new ArrayList<>();
|
||||
List<String> eventUser;
|
||||
@@ -91,6 +82,9 @@ public class SendEventUtils {
|
||||
NoticeUserDto.Payload payload = new NoticeUserDto.Payload();
|
||||
String content;
|
||||
List<CsEventUserPO> result = new ArrayList<>();
|
||||
//获取设备类型 true:治理设备 false:其他类型的设备
|
||||
boolean devModel = equipmentFeignClient.judgeDevModel(nDid).getData();
|
||||
if (devModel) {
|
||||
//事件处理
|
||||
if (eventType == 1){
|
||||
eventName = epdFeignClient.findByName(eventName).getData().getShowName();
|
||||
@@ -230,7 +224,7 @@ public class SendEventUtils {
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(filteredList)) {
|
||||
noticeUserDto.setPushClientId(filteredList);
|
||||
sendEventToUser(noticeUserDto);
|
||||
sendMessageUtil.sendEventToUser(noticeUserDto);
|
||||
}
|
||||
}
|
||||
//记录推送日志
|
||||
@@ -254,47 +248,6 @@ public class SendEventUtils {
|
||||
csEventUserService.saveBatch(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送通知消息
|
||||
*/
|
||||
public void sendEventToUser(NoticeUserDto noticeUserDto) {
|
||||
try {
|
||||
// 创建一个URL对象,指定目标HTTPS接口地址
|
||||
//URL url = new URL("https://fc-mp-b46c4dff-7244-4f7c-ae8b-7c1194d8cce8.next.bspapp.com/push");
|
||||
URL url = new URL("https://fc-mp-ff7b310f-94c9-4468-8260-109111c0a6b2.next.bspapp.com/push");
|
||||
// 打开HTTPS连接
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
// 设置请求方法为POST
|
||||
connection.setRequestMethod("POST");
|
||||
// 设置请求头,指定Content-Type为application/json
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
// 启用输出流以发送JSON数据
|
||||
connection.setDoOutput(true);
|
||||
// 将JSON数据写入输出流
|
||||
OutputStream outputStream = connection.getOutputStream();
|
||||
log.info(new Gson().toJson(noticeUserDto).replace("pushClientId", "push_clientid"));
|
||||
outputStream.write(new Gson().toJson(noticeUserDto).replace("pushClientId", "push_clientid").getBytes(StandardCharsets.UTF_8));
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
// 获取响应代码
|
||||
int responseCode = connection.getResponseCode();
|
||||
log.info("Response Code: " + responseCode);
|
||||
// 读取响应数据
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String inputLine;
|
||||
StringBuilder response = new StringBuilder();
|
||||
while ((inputLine = reader.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
}
|
||||
reader.close();
|
||||
// 打印响应内容
|
||||
log.info("Response Content: " + response.toString());
|
||||
// 关闭连接
|
||||
connection.disconnect();
|
||||
} catch (IOException e) {
|
||||
e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.njcn.message;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
|
||||
|
||||
/**
|
||||
@@ -13,9 +13,9 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
* @date 2021年12月09日 20:59
|
||||
*/
|
||||
@Slf4j
|
||||
//@MapperScan("com.njcn.**.mapper")
|
||||
@EnableFeignClients(basePackages = "com.njcn")
|
||||
@SpringBootApplication(scanBasePackages = "com.njcn")
|
||||
@DependsOn("proxyMapperRegister")
|
||||
public class MessageBootApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Reference in New Issue
Block a user