Compare commits
15 Commits
2026-02
...
6dcee1f6c3
| Author | SHA1 | Date | |
|---|---|---|---|
| 6dcee1f6c3 | |||
| 02d321d4d4 | |||
| f5b97d83b3 | |||
| 8041c5f27e | |||
| 48c79b721e | |||
| eaacce339e | |||
| fafcaf3bf0 | |||
| c2b48d6830 | |||
| 6b24e49651 | |||
| b3d2727a64 | |||
| 441b5d04fe | |||
| 292e8b58a5 | |||
| d20c869bad | |||
| 71b9bee182 | |||
| f227fe3c3f |
@@ -20,6 +20,10 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.tocrhz</groupId>
|
||||
<artifactId>mqtt-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-core</artifactId>
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.njcn.access.api;
|
||||
|
||||
import com.njcn.access.api.fallback.CsDeviceClientFallbackFactory;
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.ACCESS_BOOT, path = "/device", fallbackFactory = CsDeviceClientFallbackFactory.class,contextId = "device")
|
||||
|
||||
public interface CsDeviceFeignClient {
|
||||
|
||||
@PostMapping("/updateRunStatus")
|
||||
HttpResult<String> updateRunStatus(@RequestParam("nDid") String nDid, @RequestParam("runStatus") Integer runStatus);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.njcn.access.api.fallback;
|
||||
|
||||
import com.njcn.access.api.CsDeviceFeignClient;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class CsDeviceClientFallbackFactory implements FallbackFactory<CsDeviceFeignClient> {
|
||||
@Override
|
||||
public CsDeviceFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if (cause.getCause() instanceof BusinessException) {
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new CsDeviceFeignClient() {
|
||||
|
||||
@Override
|
||||
public HttpResult<String> updateRunStatus(String nDid, Integer runStatus) {
|
||||
log.error("{}异常,降级处理,异常为:{}","云设备状态调整异常",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public enum AccessResponseEnum {
|
||||
DEV_MODEL_NOT_FIND("A0303","装置型号未找到!"),
|
||||
DEV_IS_NOT_ZL("A0303","注册装置不是直连装置!"),
|
||||
DEV_IS_NOT_WG("A0303","注册装置不是网关!"),
|
||||
DEV_IS_NOT_PORTABLE("A0303","注册装置不是便携式装置!"),
|
||||
DEV_IS_NOT_PORTABLE("A0303","注册装置不是便携式装置或者在线监测设备!"),
|
||||
|
||||
REGISTER_RESPONSE_ERROR("A0304","装置注册,装置侧应答失败!"),
|
||||
ACCESS_RESPONSE_ERROR("A0304","装置注册,装置侧应答失败!"),
|
||||
|
||||
@@ -5,7 +5,6 @@ import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -18,6 +17,11 @@ import java.util.List;
|
||||
@Data
|
||||
public class DevAccessParam implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("工程id")
|
||||
private String engineeringId;
|
||||
|
||||
@ApiModelProperty("项目id")
|
||||
@NotNull(message = "项目id不能为空")
|
||||
private String projectId;
|
||||
|
||||
@@ -51,6 +51,7 @@ public class FileCommonUtils {
|
||||
*/
|
||||
public void cleanRedisData(String nDid, String fileName) {
|
||||
redisUtil.deleteKeysByString("downloadFilePath:"+ nDid);
|
||||
redisUtil.deleteKeysByString("isWeb:"+ nDid);
|
||||
redisUtil.delete("fileDowning:"+nDid);
|
||||
redisUtil.delete("fileCheck" + nDid + fileName);
|
||||
redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(fileName));
|
||||
|
||||
@@ -3,7 +3,9 @@ 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.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@@ -21,12 +23,17 @@ import java.nio.charset.StandardCharsets;
|
||||
@Component
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
public class SendMessageUtil {
|
||||
|
||||
@Value("${app.sendUrl:https://fc-mp-ff7b310f-94c9-4468-8260-109111c0a6b2.next.bspapp.com/push}")
|
||||
private String appSendUrl;
|
||||
|
||||
//App客户端消息推送
|
||||
public void sendEventToUser(NoticeUserDto noticeUserDto) {
|
||||
try {
|
||||
// 创建一个URL对象,指定目标HTTPS接口地址
|
||||
URL url = new URL("https://fc-mp-ff7b310f-94c9-4468-8260-109111c0a6b2.next.bspapp.com/push");
|
||||
URL url = new URL(appSendUrl);
|
||||
// 打开HTTPS连接
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
// 设置请求方法为POST
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.njcn.access.controller;
|
||||
|
||||
import com.njcn.access.param.DevAccessParam;
|
||||
import com.njcn.access.service.ICsDeviceService;
|
||||
import com.njcn.access.service.ICsEquipmentDeliveryService;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
@@ -34,6 +35,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
public class CsDeviceController extends BaseController {
|
||||
|
||||
private final ICsDeviceService csDeviceService;
|
||||
private final ICsEquipmentDeliveryService csEquipmentDeliveryService;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/register")
|
||||
@@ -120,4 +122,42 @@ public class CsDeviceController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, "success", methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/autoPortableLedger")
|
||||
@ApiOperation("调整便携式设备的台账信息")
|
||||
@ReturnMsg
|
||||
public HttpResult<String> autoPortableLedger(){
|
||||
String methodDescribe = getMethodDescribe("autoPortableLedger");
|
||||
csDeviceService.autoPortableLedger();
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, "success", methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/updateRunStatus")
|
||||
@ApiOperation("设备状态调整")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "nDid", value = "设备识别码", required = true),
|
||||
@ApiImplicitParam(name = "runStatus", value = "状态", required = true)
|
||||
})
|
||||
public HttpResult<String> updateRunStatus(@RequestParam String nDid, @RequestParam Integer runStatus){
|
||||
String methodDescribe = getMethodDescribe("updateRunStatus");
|
||||
csEquipmentDeliveryService.updateRunStatusBynDid(nDid,runStatus);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, "success", methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/onlineRegister")
|
||||
@ApiOperation("监测设备接入")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "projectId", value = "项目id", required = true),
|
||||
@ApiImplicitParam(name = "nDid", value = "设备识别码", required = true)
|
||||
})
|
||||
@ReturnMsg
|
||||
public HttpResult<String> onlineRegister(@RequestParam("projectId") String projectId,@RequestParam("nDid") String nDid){
|
||||
String methodDescribe = getMethodDescribe("onlineRegister");
|
||||
String result = csDeviceService.onlineRegister(projectId,nDid);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.util.List;
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/csLineLatestData")
|
||||
@Api(tags = "暂降事件")
|
||||
@Api(tags = "治理设备模块运行状态记录")
|
||||
@AllArgsConstructor
|
||||
public class CsLineLatestDataController extends BaseController {
|
||||
|
||||
|
||||
@@ -312,7 +312,7 @@ public class MqttMessageHandler {
|
||||
if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){
|
||||
int mid = 1;
|
||||
//修改装置状态
|
||||
csEquipmentDeliveryService.updateStatusBynDid(nDid,AccessEnum.ACCESS.getCode());
|
||||
csEquipmentDeliveryService.updateStatusBynDid(nDid,AccessEnum.ACCESS.getCode(),null,null);
|
||||
csEquipmentDeliveryService.updateRunStatusBynDid(nDid,AccessEnum.ONLINE.getCode());
|
||||
//记录设备上线
|
||||
PqsCommunicateDto dto = new PqsCommunicateDto();
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.njcn.access.listener;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
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.impl.CsDeviceServiceImpl;
|
||||
@@ -15,12 +15,14 @@ import com.njcn.access.utils.RedisSetUtil;
|
||||
import com.njcn.access.utils.SendMessageUtil;
|
||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||
import com.njcn.csdevice.api.*;
|
||||
import com.njcn.csdevice.param.DeviceMessageParam;
|
||||
import com.njcn.csdevice.pojo.dto.DevDetailDTO;
|
||||
import com.njcn.csdevice.pojo.dto.PqsCommunicateDto;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.rt.pojo.dto.BaseRealDataSet;
|
||||
import com.njcn.user.api.AppInfoSetFeignClient;
|
||||
import com.njcn.user.api.AppUserFeignClient;
|
||||
import com.njcn.user.api.UserFeignClient;
|
||||
import com.njcn.user.pojo.po.User;
|
||||
@@ -37,9 +39,6 @@ import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -81,6 +80,11 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
private MqttPublisher publisher;
|
||||
@Resource
|
||||
private RedisSetUtil redisSetUtil;
|
||||
@Resource
|
||||
private AppInfoSetFeignClient appInfoSetFeignClient;
|
||||
@Resource
|
||||
private DeviceMessageFeignClient deviceMessageFeignClient;
|
||||
|
||||
|
||||
private final Object lock = new Object();
|
||||
|
||||
@@ -140,7 +144,7 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
//装置下线
|
||||
csEquipmentDeliveryService.updateRunStatusBynDid(nDid, AccessEnum.OFFLINE.getCode());
|
||||
//装置调整为注册状态
|
||||
csEquipmentDeliveryService.updateStatusBynDid(nDid,AccessEnum.REGISTERED.getCode());
|
||||
csEquipmentDeliveryService.updateStatusBynDid(nDid,AccessEnum.REGISTERED.getCode(),null,null);
|
||||
logDto.setOperate(nDid +"装置离线");
|
||||
sendMessage(nDid);
|
||||
//记录装置掉线时间
|
||||
@@ -151,68 +155,8 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
dto.setDescription("通讯中断");
|
||||
csCommunicateFeignClient.insertion(dto);
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
}
|
||||
|
||||
private void startScheduledTask(ScheduledExecutorService scheduler, String nDid, String version) {
|
||||
synchronized (lock) {
|
||||
//判断是否推送消息
|
||||
boolean devModel = equipmentFeignClient.judgeDevModel(nDid).getData();
|
||||
if (devModel) {
|
||||
NoticeUserDto dto = sendOffLine(nDid);
|
||||
sendMessageUtil.sendEventToUser(dto);
|
||||
addLogs(dto);
|
||||
}
|
||||
String clientName = "NJCN-" + nDid.substring(nDid.length() - 6);
|
||||
ScheduledFuture<?> future = scheduler.scheduleAtFixedRate(() -> {
|
||||
log.info(nDid + "执行重连定时任务...");
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setOperate(nDid + "重连定时任务");
|
||||
//判断客户端
|
||||
boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
||||
if (mqttClient) {
|
||||
csDeviceService.devAccessAskTemplate(nDid,version,1);
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
Integer status = csEquipmentDeliveryService.queryEquipmentBynDid(nDid).getRunStatus();
|
||||
if (Objects.equals(status,AccessEnum.ONLINE.getCode())){
|
||||
logDto.setResult(1);
|
||||
scheduler.shutdown();
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,1);
|
||||
return;
|
||||
} else {
|
||||
logDto.setResult(0);
|
||||
//一个小时未连接上,则推送告警消息
|
||||
MAX_WARNING_TIMES++;
|
||||
if (MAX_WARNING_TIMES == 30 && devModel) {
|
||||
NoticeUserDto dto2 = sendConnectFail(nDid);
|
||||
sendMessageUtil.sendEventToUser(dto2);
|
||||
addLogs(dto2);
|
||||
}
|
||||
//记录装置掉线时间
|
||||
CsDeviceOnlineLogs record = onlineLogsService.findLastData(nDid);
|
||||
record.setOfflineTime(LocalDateTime.now());
|
||||
onlineLogsService.updateById(record);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
//一个小时未连接上,则推送告警消息
|
||||
MAX_WARNING_TIMES++;
|
||||
if (MAX_WARNING_TIMES == 30 && devModel) {
|
||||
NoticeUserDto dto2 = sendConnectFail(nDid);
|
||||
sendMessageUtil.sendEventToUser(dto2);
|
||||
addLogs(dto2);
|
||||
}
|
||||
logDto.setResult(0);
|
||||
//记录装置掉线时间
|
||||
CsDeviceOnlineLogs record = onlineLogsService.findLastData(nDid);
|
||||
record.setOfflineTime(LocalDateTime.now());
|
||||
onlineLogsService.updateById(record);
|
||||
}
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
}, 0, 2, TimeUnit.MINUTES);
|
||||
}
|
||||
//清空缓存
|
||||
redisUtil.deleteKeysByString(AppRedisKey.LINE_POSITION+nDid);
|
||||
}
|
||||
|
||||
//判断设备型号发送数据
|
||||
@@ -220,8 +164,10 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
boolean devModel = equipmentFeignClient.judgeDevModel(nDid).getData();
|
||||
if (devModel) {
|
||||
NoticeUserDto dto = sendOffLine(nDid);
|
||||
sendMessageUtil.sendEventToUser(dto);
|
||||
addLogs(dto);
|
||||
if (CollectionUtil.isNotEmpty(dto.getPushClientId())) {
|
||||
sendMessageUtil.sendEventToUser(dto);
|
||||
addLogs(dto);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,22 +182,17 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
String dateStr = localDateTime.format(fmt);
|
||||
String content = String.format(devDetailDto.getEngineeringName() + "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName() + "于" + dateStr + "离线");
|
||||
dto.setContent(content);
|
||||
dto.setPushClientId(getEventUser(po.getId(),true));
|
||||
return dto;
|
||||
}
|
||||
|
||||
//重连失败通知
|
||||
private NoticeUserDto sendConnectFail(String nDid) {
|
||||
NoticeUserDto dto = new NoticeUserDto();
|
||||
dto.setTitle("设备接入失败");
|
||||
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(nDid).getData();
|
||||
DevDetailDTO devDetailDto = csLedgerFeignclient.queryDevDetail(po.getId()).getData();
|
||||
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
LocalDateTime localDateTime = LocalDateTime.now();
|
||||
String dateStr = localDateTime.format(fmt);
|
||||
String content = String.format(devDetailDto.getEngineeringName() + "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName() + "于" + dateStr + "多次接入失败");
|
||||
dto.setContent(content);
|
||||
dto.setPushClientId(getEventUser(po.getId(),false));
|
||||
//获取设备关联的用户
|
||||
List<String> eventUser = deviceMessageFeignClient.getEventUserByDeviceId(po.getId(),true).getData();
|
||||
DeviceMessageParam param1 = new DeviceMessageParam();
|
||||
param1.setUserList(eventUser);
|
||||
param1.setEventType(2);
|
||||
//获取打开推送的用户
|
||||
List<User> users = deviceMessageFeignClient.getSendUserByType(param1).getData();
|
||||
if (CollectionUtil.isNotEmpty(users)){
|
||||
dto.setPushClientId(
|
||||
users.stream().filter(Objects::nonNull).map(User::getDevCode).filter(StringUtils::isNotBlank).distinct().collect(Collectors.toList()));
|
||||
}
|
||||
return dto;
|
||||
}
|
||||
|
||||
@@ -263,18 +204,4 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
dto.setOperate(noticeUserDto.getContent());
|
||||
csLogsFeignClient.addUserLog(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有需要推送的用户id
|
||||
*/
|
||||
public List<String> getEventUser(String devId, boolean isAdmin) {
|
||||
List<User> adminUser = appUserFeignClient.getAdminInfo().getData();
|
||||
List<String> adminList = adminUser.stream().map(User::getId).collect(Collectors.toList());
|
||||
if (isAdmin) {
|
||||
List<String> list = csDeviceUserFeignClient.findUserById(devId).getData();
|
||||
adminList.addAll(list);
|
||||
}
|
||||
List<User> users = userFeignClient.appuserByIdList(adminList).getData();
|
||||
return users.stream().map(User::getDevCode).filter(Objects::nonNull).filter(StringUtils::isNotBlank).distinct().collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,4 +54,8 @@ public interface ICsDeviceService {
|
||||
* @param nDid 设备识别码
|
||||
*/
|
||||
void wlAccess(String nDid);
|
||||
|
||||
String autoPortableLedger();
|
||||
|
||||
String onlineRegister(String projectId,String nDid);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public interface ICsEquipmentDeliveryService extends IService<CsEquipmentDeliver
|
||||
* 根据网关id修改装置的状态
|
||||
* @param nDid 网关id
|
||||
*/
|
||||
void updateStatusBynDid(String nDid,Integer status);
|
||||
void updateStatusBynDid(String nDid,Integer status,String engineeringId, String projectId);
|
||||
|
||||
/**
|
||||
* 根据网关id修改软件信息
|
||||
|
||||
@@ -24,4 +24,6 @@ public interface ICsLedgerService extends IService<CsLedger> {
|
||||
*/
|
||||
CsLedger addLedgerTree(CsLedgerParam csLedgerParam);
|
||||
|
||||
void updatePortableLedger(String engineeringId, String projectId);
|
||||
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ public class AskDeviceDataServiceImpl implements AskDeviceDataService {
|
||||
public boolean downloadFile(String nDid, String name, Integer size, String fileCheck) {
|
||||
boolean result = true;
|
||||
try {
|
||||
redisUtil.saveByKeyWithExpire("isWeb:"+nDid,name,30L);
|
||||
redisUtil.saveByKeyWithExpire("fileDowning:"+nDid,"fileDowning",300L);
|
||||
redisUtil.saveByKey("fileCheck"+nDid+name,fileCheck);
|
||||
Object object = getDeviceMid(nDid);
|
||||
@@ -104,6 +105,7 @@ public class AskDeviceDataServiceImpl implements AskDeviceDataService {
|
||||
redisUtil.delete("fileDowning:"+nDid);
|
||||
redisUtil.delete("fileCheck"+nDid+name);
|
||||
redisUtil.delete("fileDownUserId"+nDid+name);
|
||||
redisUtil.deleteKeysByString("isWeb:"+ nDid);
|
||||
throw new BusinessException(AlgorithmResponseEnum.FILE_DOWNLOAD_ERROR);
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -22,9 +22,7 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.api.*;
|
||||
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
||||
import com.njcn.csdevice.pojo.param.CsDevModelRelationAddParm;
|
||||
import com.njcn.csdevice.pojo.param.CsLedgerParam;
|
||||
import com.njcn.csdevice.pojo.param.CsLineParam;
|
||||
import com.njcn.csdevice.pojo.param.*;
|
||||
import com.njcn.csdevice.pojo.po.*;
|
||||
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
@@ -32,7 +30,11 @@ import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.api.DictTreeFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.pojo.po.DictData;
|
||||
import com.njcn.system.pojo.po.SysDicTreePO;
|
||||
import com.njcn.user.api.UserFeignClient;
|
||||
import com.njcn.user.enums.AppRoleEnum;
|
||||
import com.njcn.user.pojo.vo.UserVO;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -80,6 +82,10 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
private final ChannelObjectUtil channelObjectUtil;
|
||||
private final CsLineFeignClient csLineFeignClient;
|
||||
private final DataSetFeignClient dataSetFeignClient;
|
||||
private final CsMarketDataFeignClient csMarketDataFeignClient;
|
||||
private final UserFeignClient userFeignClient;
|
||||
private final EngineeringFeignClient engineeringFeignClient;
|
||||
private final AppProjectFeignClient appProjectFeignClient;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
@@ -130,15 +136,16 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
throw new BusinessException(AccessResponseEnum.MISSING_CLIENT);
|
||||
}
|
||||
//5.判断当前流程是否是合法的
|
||||
if (csEquipmentDeliveryVO.getProcess() > type){
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.PROCESS_SAME_ERROR.getMessage());
|
||||
throw new BusinessException(AccessResponseEnum.PROCESS_SAME_ERROR);
|
||||
} else if (csEquipmentDeliveryVO.getProcess() < type){
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.PROCESS_MISSING_ERROR.getMessage());
|
||||
throw new BusinessException(AccessResponseEnum.PROCESS_MISSING_ERROR);
|
||||
}
|
||||
//note(重要说明) 这边流程原先是三个阶段,在实际应用中嫌麻烦,简化为一个流程
|
||||
// if (csEquipmentDeliveryVO.getProcess() > type){
|
||||
// logDto.setResult(0);
|
||||
// logDto.setFailReason(AccessResponseEnum.PROCESS_SAME_ERROR.getMessage());
|
||||
// throw new BusinessException(AccessResponseEnum.PROCESS_SAME_ERROR);
|
||||
// } else if (csEquipmentDeliveryVO.getProcess() < type){
|
||||
// logDto.setResult(0);
|
||||
// logDto.setFailReason(AccessResponseEnum.PROCESS_MISSING_ERROR.getMessage());
|
||||
// throw new BusinessException(AccessResponseEnum.PROCESS_MISSING_ERROR);
|
||||
// }
|
||||
//6.询问设备支持的主题信息
|
||||
//将支持的主题入库
|
||||
askTopic(nDid);
|
||||
@@ -184,6 +191,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
//fixme 这边事务不起作用,中途出错会导致数据部分录入,再次接入会报主键冲突,所以暂时加了个重置按钮,清空台账数据的
|
||||
public void devAccess(DevAccessParam devAccessParam) {
|
||||
//日志实体
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
@@ -280,6 +288,23 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
}
|
||||
csLineService.saveBatch(csLinePoList);
|
||||
redisUtil.saveByKeyWithExpire("accessLineInfo:" + devAccessParam.getNDid(),csLinePoList,30L);
|
||||
//缓存监测点信息
|
||||
Map<Integer,String> map = new HashMap<>();
|
||||
for (CsLinePO item : csLinePoList) {
|
||||
if (Objects.isNull(item.getPosition())){
|
||||
map.put(item.getClDid(),item.getLineId());
|
||||
} else {
|
||||
DictData dictData = dicDataFeignClient.getDicDataById(item.getPosition()).getData();
|
||||
if (Objects.equals(dictData.getCode(), DicDataEnum.OUTPUT_SIDE.getCode())){
|
||||
map.put(0,item.getLineId());
|
||||
} else if (Objects.equals(dictData.getCode(), DicDataEnum.GRID_SIDE.getCode())){
|
||||
map.put(1,item.getLineId());
|
||||
} else if (Objects.equals(dictData.getCode(), DicDataEnum.LOAD_SIDE.getCode())){
|
||||
map.put(2,item.getLineId());
|
||||
}
|
||||
}
|
||||
}
|
||||
redisUtil.saveByKey(AppRedisKey.LINE_POSITION+devAccessParam.getNDid(),map);
|
||||
//4.监测点拓扑图表录入关系
|
||||
appLineTopologyDiagramService.saveBatch(appLineTopologyDiagramPoList);
|
||||
//5.绑定装置和人的关系
|
||||
@@ -289,16 +314,16 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
po.setSubUserId(RequestUtil.getUserIndex());
|
||||
po.setDeviceId(vo.getId());
|
||||
csDeviceUserService.saveBatch(Collections.singletonList(po));
|
||||
//6.修改装置状态
|
||||
csEquipmentDeliveryService.updateStatusBynDid(devAccessParam.getNDid(), AccessEnum.REGISTERED.getCode());
|
||||
//6.修改装置状态;修改设备接入的工程、项目
|
||||
csEquipmentDeliveryService.updateStatusBynDid(devAccessParam.getNDid(), AccessEnum.REGISTERED.getCode(),devAccessParam.getEngineeringId(), devAccessParam.getProjectId());
|
||||
//7.发起自动接入请求
|
||||
devAccessAskTemplate(devAccessParam.getNDid(),version,1);
|
||||
//8.删除redis监测点模板信息
|
||||
redisUtil.delete(AppRedisKey.MODEL + devAccessParam.getNDid());
|
||||
redisUtil.delete(AppRedisKey.LINE + devAccessParam.getNDid());
|
||||
//存储日志
|
||||
//9.存储日志
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
//存储设备调试日志表
|
||||
//10.存储设备调试日志表
|
||||
CsEquipmentProcessPO csEquipmentProcess = new CsEquipmentProcessPO();
|
||||
csEquipmentProcess.setDevId(devAccessParam.getNDid());
|
||||
csEquipmentProcess.setOperator(RequestUtil.getUserIndex());
|
||||
@@ -309,6 +334,14 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
csEquipmentProcess.setStatus(1);
|
||||
}
|
||||
processFeignClient.add(csEquipmentProcess);
|
||||
//11.这里会出现工程用户接入设备时,如果当前工程用户并没有关注,接入之后应该将用户和工程关联起来
|
||||
List<UserVO> users = userFeignClient.getUserVOByIdList(Collections.singletonList(RequestUtil.getUserIndex())).getData();
|
||||
if (CollectionUtil.isNotEmpty(users)) {
|
||||
UserVO userVO = users.get(0);
|
||||
if (CollectionUtil.isNotEmpty(userVO.getRoleCode()) && userVO.getRoleCode().contains(AppRoleEnum.ENGINEERING_USER.getCode())) {
|
||||
csMarketDataFeignClient.insertData(userVO.getId(), devAccessParam.getEngineeringId());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(e.getMessage());
|
||||
@@ -327,12 +360,13 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
param.setNDid(nDid);
|
||||
param.setStatus(1);
|
||||
param.setRunStatus(1);
|
||||
boolean isConnectDev = DicDataEnum.CONNECT_DEV.getCode().equals(dictTreeFeignClient.queryById(csEquipmentDeliveryVO.getDevType()).getData().getCode());
|
||||
if (isConnectDev) {
|
||||
param.setProcess(2);
|
||||
} else {
|
||||
param.setProcess(4);
|
||||
}
|
||||
// boolean isConnectDev = DicDataEnum.CONNECT_DEV.getCode().equals(dictTreeFeignClient.queryById(csEquipmentDeliveryVO.getDevType()).getData().getCode());
|
||||
// if (isConnectDev) {
|
||||
// param.setProcess(2);
|
||||
// } else {
|
||||
// param.setProcess(4);
|
||||
// }
|
||||
param.setProcess(4);
|
||||
csEquipmentDeliveryService.devResetFactory(param);
|
||||
//清除关系表
|
||||
QueryWrapper<CsLedger> csLedgerQueryWrapper = new QueryWrapper<>();
|
||||
@@ -365,6 +399,8 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
appLineTopologyDiagramPOQueryWrapper.in("line_id",collect);
|
||||
appLineTopologyDiagramService.remove(appLineTopologyDiagramPOQueryWrapper);
|
||||
}
|
||||
//清空缓存
|
||||
redisUtil.deleteKeysByString(AppRedisKey.LINE_POSITION+nDid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -396,9 +432,13 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(nDid).getData();
|
||||
List<CsLinePO> csLinePoList = new ArrayList<>();
|
||||
//1.录入装置台账信息
|
||||
//note 1、这边发现便携式设备注册时,如果没有工程 项目,后期特殊处理非常的麻烦,这边接入时,先查询工程 项目,如果没有则创建;如果存在则直接使用;
|
||||
//note 2、查询之前已经接入过的便携式设备,如果存在修改台账信息,添加工程、项目
|
||||
String projectId = this.autoPortableLedger();
|
||||
//新增便携式设备
|
||||
CsLedgerParam csLedgerParam = new CsLedgerParam();
|
||||
csLedgerParam.setId(vo.getId());
|
||||
csLedgerParam.setPid("0");
|
||||
csLedgerParam.setPid(projectId);
|
||||
csLedgerParam.setName(vo.getName());
|
||||
csLedgerParam.setLevel(2);
|
||||
csLedgerParam.setSort(0);
|
||||
@@ -436,6 +476,23 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
});
|
||||
csLineService.saveBatch(csLinePoList);
|
||||
redisUtil.saveByKeyWithExpire("accessLineInfo:" + nDid,csLinePoList,30L);
|
||||
//缓存监测点信息
|
||||
Map<Integer,String> map = new HashMap<>();
|
||||
for (CsLinePO item : csLinePoList) {
|
||||
if (Objects.isNull(item.getPosition())){
|
||||
map.put(item.getClDid(),item.getLineId());
|
||||
} else {
|
||||
DictData dictData = dicDataFeignClient.getDicDataById(item.getPosition()).getData();
|
||||
if (Objects.equals(dictData.getCode(), DicDataEnum.OUTPUT_SIDE.getCode())){
|
||||
map.put(0,item.getLineId());
|
||||
} else if (Objects.equals(dictData.getCode(), DicDataEnum.GRID_SIDE.getCode())){
|
||||
map.put(1,item.getLineId());
|
||||
} else if (Objects.equals(dictData.getCode(), DicDataEnum.LOAD_SIDE.getCode())){
|
||||
map.put(2,item.getLineId());
|
||||
}
|
||||
}
|
||||
}
|
||||
redisUtil.saveByKey(AppRedisKey.LINE_POSITION+nDid,map);
|
||||
//4.生成装置和模板的关系表
|
||||
CsDevModelRelationAddParm csDevModelRelationAddParm = new CsDevModelRelationAddParm();
|
||||
csDevModelRelationAddParm.setDevId(vo.getId());
|
||||
@@ -445,7 +502,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
//5.发起自动接入请求
|
||||
Thread.sleep(2000);
|
||||
//先获取版本
|
||||
// String version = csTopicService.getVersion(nDid);
|
||||
//String version = csTopicService.getVersion(nDid);
|
||||
String version = "V1";
|
||||
devAccessAskTemplate(nDid,version,1);
|
||||
//6.修改流程,便携式设备接入成功即为实际环境
|
||||
@@ -481,6 +538,162 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
this.devAccessAskTemplate(nDid,version,1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String autoPortableLedger() {
|
||||
CsEngineeringPO csEngineeringPO = engineeringFeignClient.getEngineeringByName("便携式工程").getData();
|
||||
if (csEngineeringPO == null) {
|
||||
//新增便携式工程
|
||||
CsEngineeringAddParm param = new CsEngineeringAddParm();
|
||||
param.setName("便携式工程");
|
||||
param.setProvince("320000000000");
|
||||
param.setCity("320100000000");
|
||||
param.setDescription("便携式工程");
|
||||
param.setSort(Integer.MAX_VALUE);
|
||||
csEngineeringPO = engineeringFeignClient.addEngineering(param).getData();
|
||||
}
|
||||
|
||||
AppProjectPO csProjectPO = appProjectFeignClient.getProjectByName("便携式项目").getData();
|
||||
if (csProjectPO == null) {
|
||||
//新增便携式项目
|
||||
AppProjectAddParm param = new AppProjectAddParm();
|
||||
param.setEngineeringId(csEngineeringPO.getId());
|
||||
param.setName("便携式项目");
|
||||
param.setArea("园区");
|
||||
param.setDescription("便携式项目");
|
||||
param.setTopoIds(Collections.singletonList("99ed9b9c8cf9007cc4d2ac4c7127b7e4"));
|
||||
param.setSort(Integer.MAX_VALUE);
|
||||
csProjectPO = appProjectFeignClient.addPortableProject(param).getData();
|
||||
}
|
||||
//修改已存在的便携式设备
|
||||
csLedgerService.updatePortableLedger(csEngineeringPO.getId(),csProjectPO.getId());
|
||||
return csProjectPO.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String onlineRegister(String projectId,String nDid) {
|
||||
String result = "fail";
|
||||
// 根据模板接入设备
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName(RequestUtil.getUserNickname());
|
||||
logDto.setLoginName(RequestUtil.getUsername());
|
||||
logDto.setOperate("监测设备"+nDid+"注册、接入");
|
||||
logDto.setResult(1);
|
||||
try {
|
||||
// 设备状态判断
|
||||
checkDeviceStatus(nDid);
|
||||
// 询问设备支持的主题信息,并将支持的主题入库
|
||||
askAndStoreTopics(nDid);
|
||||
Thread.sleep(2000);
|
||||
// MQTT询问装置用的模板,并判断库中是否存在模板
|
||||
checkDeviceModel(nDid);
|
||||
Thread.sleep(2000);
|
||||
CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(nDid).getData();
|
||||
List<CsLinePO> csLinePoList = new ArrayList<>();
|
||||
//1.录入装置台账信息
|
||||
//新增监测设备
|
||||
CsLedgerParam csLedgerParam = new CsLedgerParam();
|
||||
csLedgerParam.setId(vo.getId());
|
||||
csLedgerParam.setPid(projectId);
|
||||
csLedgerParam.setName(vo.getName());
|
||||
csLedgerParam.setLevel(2);
|
||||
csLedgerParam.setSort(0);
|
||||
csLedgerService.addLedgerTree(csLedgerParam);
|
||||
//2.根据模板获取监测点个数,插入监测点表
|
||||
Thread.sleep(2000);
|
||||
List<CsModelDto> modelList = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + nDid),CsModelDto.class);
|
||||
if (CollUtil.isEmpty(modelList)) {
|
||||
throwExceptionAndLog(nDid,AccessResponseEnum.MODEL_ERROR, logDto);
|
||||
}
|
||||
List<CsDataSet> list = csDataSetService.getDataSetData(modelList.get(0).getModelId());
|
||||
list.forEach(item->{
|
||||
CsLinePO po = new CsLinePO();
|
||||
po.setLineId(nDid + item.getClDev().toString());
|
||||
po.setName(item.getClDev().toString() + "#监测点");
|
||||
po.setStatus(1);
|
||||
po.setClDid(item.getClDev());
|
||||
po.setLineNo(item.getClDev());
|
||||
po.setRunStatus(0);
|
||||
po.setDeviceId(vo.getId());
|
||||
po.setDataSetId(item.getId());
|
||||
po.setDataModelId(item.getPid());
|
||||
//防止主键重复
|
||||
QueryWrapper<CsLinePO> qw = new QueryWrapper<>();
|
||||
qw.eq("line_id",po.getLineId());
|
||||
if(csLineService.getBaseMapper().selectList(qw).isEmpty()){
|
||||
csLinePoList.add(po);
|
||||
}
|
||||
//3.生成台账树监测点数据
|
||||
CsLedgerParam param = new CsLedgerParam();
|
||||
param.setId(nDid + item.getClDev().toString());
|
||||
param.setPid(vo.getId());
|
||||
param.setName(item.getClDev().toString() + "#监测点");
|
||||
param.setLevel(3);
|
||||
param.setSort(0);
|
||||
csLedgerService.addLedgerTree(param);
|
||||
});
|
||||
csLineService.saveBatch(csLinePoList);
|
||||
redisUtil.saveByKeyWithExpire("accessLineInfo:" + nDid,csLinePoList,30L);
|
||||
//缓存监测点信息
|
||||
//缓存监测点信息
|
||||
Map<Integer,String> map = new HashMap<>();
|
||||
for (CsLinePO item : csLinePoList) {
|
||||
if (Objects.isNull(item.getPosition())){
|
||||
map.put(item.getClDid(),item.getLineId());
|
||||
} else {
|
||||
DictData dictData = dicDataFeignClient.getDicDataById(item.getPosition()).getData();
|
||||
if (Objects.equals(dictData.getCode(), DicDataEnum.OUTPUT_SIDE.getCode())){
|
||||
map.put(0,item.getLineId());
|
||||
} else if (Objects.equals(dictData.getCode(), DicDataEnum.GRID_SIDE.getCode())){
|
||||
map.put(1,item.getLineId());
|
||||
} else if (Objects.equals(dictData.getCode(), DicDataEnum.LOAD_SIDE.getCode())){
|
||||
map.put(2,item.getLineId());
|
||||
}
|
||||
}
|
||||
}
|
||||
redisUtil.saveByKey(AppRedisKey.LINE_POSITION+nDid,map);
|
||||
//4.生成装置和模板的关系表
|
||||
CsDevModelRelationAddParm csDevModelRelationAddParm = new CsDevModelRelationAddParm();
|
||||
csDevModelRelationAddParm.setDevId(vo.getId());
|
||||
csDevModelRelationAddParm.setModelId(modelList.get(0).getModelId());
|
||||
csDevModelRelationAddParm.setDid(modelList.get(0).getDid());
|
||||
csDevModelRelationService.addDevModelRelation(csDevModelRelationAddParm);
|
||||
//5.绑定装置和人的关系
|
||||
CsDeviceUserPO po = new CsDeviceUserPO();
|
||||
po.setPrimaryUserId(RequestUtil.getUserIndex());
|
||||
po.setStatus("1");
|
||||
po.setSubUserId(RequestUtil.getUserIndex());
|
||||
po.setDeviceId(vo.getId());
|
||||
csDeviceUserService.saveBatch(Collections.singletonList(po));
|
||||
|
||||
//发起自动接入请求
|
||||
Thread.sleep(2000);
|
||||
//先获取版本
|
||||
String version = "V1";
|
||||
devAccessAskTemplate(nDid,version,1);
|
||||
//6.修改流程,接入成功即为实际环境
|
||||
csEquipmentDeliveryService.updateProcessBynDid(nDid,4);
|
||||
//7.存储日志
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
//9.删除redis监测点模板信息
|
||||
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
||||
redisUtil.delete(AppRedisKey.LINE + nDid);
|
||||
//判断接入状态
|
||||
Thread.sleep(5000);
|
||||
Object object = redisUtil.getObjectByKey("online" + nDid);
|
||||
if (Objects.nonNull(object)) {
|
||||
result = "success";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(e.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
resetFactory(nDid);
|
||||
throw new BusinessException(e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void checkDeviceStatus(String nDid) {
|
||||
DeviceLogDTO logDto = createLogDto("当前设备"+nDid+"状态判断");
|
||||
CsEquipmentDeliveryVO csEquipmentDeliveryVO = csEquipmentDeliveryService.queryEquipmentBynDid(nDid);
|
||||
@@ -492,7 +705,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
throwExceptionAndLog(nDid,AccessResponseEnum.DEV_NOT_FIND, logDto);
|
||||
}
|
||||
String code = sysDicTreePo.getCode();
|
||||
if (!Objects.equals(code, DicDataEnum.PORTABLE.getCode())) {
|
||||
if (!Objects.equals(code, DicDataEnum.PORTABLE.getCode()) && !Objects.equals(code, DicDataEnum.DEV_CLD.getCode())) {
|
||||
throwExceptionAndLog(nDid,AccessResponseEnum.DEV_IS_NOT_PORTABLE, logDto);
|
||||
}
|
||||
if (!mqttUtil.judgeClientOnline("NJCN-" + nDid.substring(nDid.length() - 6))) {
|
||||
@@ -724,6 +937,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
List<CsLinePO> lineList;
|
||||
Object object = redisUtil.getObjectByKey("accessLineInfo:" + nDid);
|
||||
if (Objects.isNull(object)) {
|
||||
Map<Integer,String> map = new HashMap<>();
|
||||
lineList = csLineFeignClient.findByNdid(nDid).getData();
|
||||
for (CsLinePO item : lineList) {
|
||||
if (item.getClDid() == 0) {
|
||||
@@ -731,10 +945,23 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
} else {
|
||||
updateLineIds(modelMap.get(1), item.getClDid(), nDid);
|
||||
}
|
||||
//缓存监测点信息
|
||||
if (Objects.isNull(item.getPosition())){
|
||||
map.put(item.getClDid(),item.getLineId());
|
||||
} else {
|
||||
DictData dictData = dicDataFeignClient.getDicDataById(item.getPosition()).getData();
|
||||
if (Objects.equals(dictData.getCode(), DicDataEnum.OUTPUT_SIDE.getCode())){
|
||||
map.put(0,item.getLineId());
|
||||
} else if (Objects.equals(dictData.getCode(), DicDataEnum.GRID_SIDE.getCode())){
|
||||
map.put(1,item.getLineId());
|
||||
} else if (Objects.equals(dictData.getCode(), DicDataEnum.LOAD_SIDE.getCode())){
|
||||
map.put(2,item.getLineId());
|
||||
}
|
||||
}
|
||||
}
|
||||
redisUtil.saveByKey(AppRedisKey.LINE_POSITION+nDid,map);
|
||||
}
|
||||
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid, new Gson().toJson(getJson(mid,TypeEnum.TYPE_5.getCode())), 1, false);
|
||||
// redisUtil.saveByKeyWithExpire("startFile:" + nDid, null, 60L);
|
||||
result = true;
|
||||
} catch (Exception e) {
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
|
||||
@@ -41,9 +41,15 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
||||
private final CsLogsFeignClient csLogsFeignClient;
|
||||
|
||||
@Override
|
||||
public void updateStatusBynDid(String nDid,Integer status) {
|
||||
public void updateStatusBynDid(String nDid,Integer status,String engineeringId, String projectId) {
|
||||
LambdaUpdateWrapper<CsEquipmentDeliveryPO> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||
lambdaUpdateWrapper.set(CsEquipmentDeliveryPO::getStatus,status).eq(CsEquipmentDeliveryPO::getNdid,nDid);
|
||||
if (engineeringId != null && !engineeringId.isEmpty()) {
|
||||
lambdaUpdateWrapper.set(CsEquipmentDeliveryPO::getAssociatedEngineering,engineeringId);
|
||||
}
|
||||
if (projectId != null && !projectId.isEmpty()) {
|
||||
lambdaUpdateWrapper.set(CsEquipmentDeliveryPO::getAssociatedProject,projectId);
|
||||
}
|
||||
this.update(lambdaUpdateWrapper);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.njcn.access.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.access.mapper.CsLedgerMapper;
|
||||
import com.njcn.access.service.ICsLedgerService;
|
||||
@@ -8,8 +10,11 @@ import com.njcn.csdevice.pojo.po.CsLedger;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -24,6 +29,7 @@ import java.util.Objects;
|
||||
public class CsLedgerServiceImpl extends ServiceImpl<CsLedgerMapper, CsLedger> implements ICsLedgerService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public CsLedger addLedgerTree(CsLedgerParam csLedgerParam) {
|
||||
CsLedger fatherCsLedger = this.lambdaQuery().eq(CsLedger::getId,csLedgerParam.getPid()).eq(CsLedger::getState,1).one();
|
||||
CsLedger csLedger = new CsLedger();
|
||||
@@ -43,4 +49,35 @@ public class CsLedgerServiceImpl extends ServiceImpl<CsLedgerMapper, CsLedger> i
|
||||
return csLedger;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public void updatePortableLedger(String engineeringId, String projectId) {
|
||||
//先查询有没有历史的便携式设备
|
||||
List<CsLedger> portableDevices = this.list(
|
||||
new LambdaQueryWrapper<CsLedger>()
|
||||
.eq(CsLedger::getPid, "0")
|
||||
.eq(CsLedger::getLevel, 2)
|
||||
.eq(CsLedger::getState, 1));
|
||||
if (CollectionUtil.isNotEmpty(portableDevices)) {
|
||||
portableDevices.forEach(item->{
|
||||
item.setPid(projectId);
|
||||
item.setPids("0," + engineeringId + "," + projectId);
|
||||
});
|
||||
this.updateBatchById(portableDevices);
|
||||
//获取监测点id
|
||||
List<String> devList = portableDevices.stream().map(CsLedger::getId).collect(Collectors.toList());
|
||||
LambdaQueryWrapper<CsLedger> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.in(CsLedger::getPid, devList).eq(CsLedger::getState,1).eq(CsLedger::getLevel,3);
|
||||
List<CsLedger> pointList = this.list(queryWrapper);
|
||||
if (CollectionUtil.isNotEmpty(pointList)) {
|
||||
pointList.forEach(item->{
|
||||
String pidS = item.getPids();
|
||||
String devPid = pidS.split(",")[1];
|
||||
item.setPids("0," + engineeringId + "," + projectId + "," + devPid);
|
||||
});
|
||||
this.updateBatchById(pointList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -299,12 +299,12 @@ public class RtServiceImpl implements IRtService {
|
||||
baseRealDataSet.setSB(FloatUtils.get2Float(map.get("Pq_SB")));
|
||||
baseRealDataSet.setSC(FloatUtils.get2Float(map.get("Pq_SC")));
|
||||
baseRealDataSet.setSTot(FloatUtils.get2Float(map.get("Pq_TotSM")));
|
||||
//功率因数
|
||||
//视在功率因数
|
||||
baseRealDataSet.setPfA(FloatUtils.get2Float(map.get("Pq_PFA")));
|
||||
baseRealDataSet.setPfB(FloatUtils.get2Float(map.get("Pq_PFB")));
|
||||
baseRealDataSet.setPfC(FloatUtils.get2Float(map.get("Pq_PFC")));
|
||||
baseRealDataSet.setPfTot(FloatUtils.get2Float(map.get("Pq_TotPFM")));
|
||||
//基波功率因数
|
||||
//位移功率因数
|
||||
baseRealDataSet.setDpfA(FloatUtils.get2Float(map.get("Pq_DFA")));
|
||||
baseRealDataSet.setDpfB(FloatUtils.get2Float(map.get("Pq_DFB")));
|
||||
baseRealDataSet.setDpfC(FloatUtils.get2Float(map.get("Pq_DFC")));
|
||||
|
||||
@@ -2,13 +2,16 @@ package com.njcn.stat.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.njcn.access.api.CsDeviceFeignClient;
|
||||
import com.njcn.access.api.CsLineLatestDataFeignClient;
|
||||
import com.njcn.access.enums.AccessEnum;
|
||||
import com.njcn.access.pojo.po.CsLineLatestData;
|
||||
import com.njcn.access.utils.ChannelObjectUtil;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.utils.PubUtils;
|
||||
import com.njcn.csdevice.api.CsLineFeignClient;
|
||||
import com.njcn.csdevice.api.DataArrayFeignClient;
|
||||
import com.njcn.csdevice.api.DeviceMessageFeignClient;
|
||||
import com.njcn.csdevice.pojo.param.DataArrayParam;
|
||||
import com.njcn.csdevice.pojo.po.CsDataArray;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
@@ -51,12 +54,12 @@ import java.util.concurrent.TimeUnit;
|
||||
public class StatServiceImpl implements IStatService {
|
||||
|
||||
private final DataArrayFeignClient dataArrayFeignClient;
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
private final InfluxDbUtils influxDbUtils;
|
||||
private final CsLineFeignClient csLineFeignClient;
|
||||
private final RedisUtil redisUtil;
|
||||
private final ChannelObjectUtil channelObjectUtil;
|
||||
private final CsLineLatestDataFeignClient csLineLatestDataFeignClient;
|
||||
private final CsDeviceFeignClient csDeviceFeignClient;
|
||||
private final DeviceMessageFeignClient deviceMessageFeignClient;
|
||||
private static final Map<String, String> PHASE_MAPPING = new HashMap<String, String>() {{
|
||||
put("AB", "A");
|
||||
put("BC", "B");
|
||||
@@ -83,7 +86,7 @@ public class StatServiceImpl implements IStatService {
|
||||
String lineId = null;
|
||||
Object object1 = redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appAutoDataMessage.getId());
|
||||
if (Objects.isNull(object1)){
|
||||
lineInfo(appAutoDataMessage.getId());
|
||||
deviceMessageFeignClient.getLineInfo(appAutoDataMessage.getId());
|
||||
}
|
||||
//获取当前设备信息判断装置型号,来筛选监测点
|
||||
List<CsEquipmentDeliveryPO> poList = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.DEVICE_LIST),CsEquipmentDeliveryPO.class);
|
||||
@@ -106,7 +109,6 @@ public class StatServiceImpl implements IStatService {
|
||||
//云前置设备
|
||||
else if (Objects.equals(DicDataEnum.DEV_CLD.getCode(),code)) {
|
||||
lineId = appAutoDataMessage.getId() + appAutoDataMessage.getMsg().getClDid();
|
||||
|
||||
}
|
||||
|
||||
//获取当前设备信息
|
||||
@@ -133,7 +135,8 @@ public class StatServiceImpl implements IStatService {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
int clDid = Objects.equals(DicDataEnum.DEV_CLD.getCode(),code)?1:appAutoDataMessage.getMsg().getClDid();
|
||||
boolean flag = Objects.equals(DicDataEnum.DEV_CLD.getCode(), code) && Objects.equals(po.getDevAccessMethod(), "CLD");
|
||||
int clDid = flag?1:appAutoDataMessage.getMsg().getClDid();
|
||||
String key = AppRedisKey.DEV_MODEL.concat(dataArrayParam.getId() + dataArrayParam.getDid() + clDid + dataArrayParam.getStatMethod() + dataArrayParam.getIdx());
|
||||
Object object = redisUtil.getObjectByKey(key);
|
||||
List<CsDataArray> dataArrayList;
|
||||
@@ -142,10 +145,11 @@ public class StatServiceImpl implements IStatService {
|
||||
} else {
|
||||
dataArrayList = objectToList(object);
|
||||
}
|
||||
List<String> result = assembleData(lineId,dataArrayList,item,appAutoDataMessage.getMsg().getClDid(),dataArrayParam.getStatMethod(),po.getProcess(),code);
|
||||
List<String> result = assembleData(lineId,dataArrayList,item,appAutoDataMessage.getMsg().getClDid(),dataArrayParam.getStatMethod(),po.getProcess(),code,po.getDevAccessMethod());
|
||||
recordList.addAll(result);
|
||||
//获取时间
|
||||
long devTime = Objects.equals(DicDataEnum.DEV_CLD.getCode(),code)?item.getDataTimeSec():item.getDataTimeSec()-8*3600;
|
||||
boolean timeFlag = Objects.equals(DicDataEnum.DEV_CLD.getCode(), code) && Objects.equals(po.getDevAccessMethod(), "CLD");
|
||||
long devTime = timeFlag?item.getDataTimeSec():item.getDataTimeSec()-8*3600;
|
||||
time = Instant.ofEpochSecond(devTime)
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.toLocalDateTime();
|
||||
@@ -159,33 +163,12 @@ public class StatServiceImpl implements IStatService {
|
||||
csLineLatestData.setTimeId(Objects.isNull(time) ? LocalDateTime.now() : time);
|
||||
csLineLatestDataFeignClient.addData(csLineLatestData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存监测点相关信息
|
||||
*/
|
||||
public void lineInfo(String id) {
|
||||
Map<Integer,String> map = new HashMap<>();
|
||||
List<CsLinePO> lineList = csLineFeignClient.findByNdid(id).getData();
|
||||
if (CollectionUtil.isEmpty(lineList)){
|
||||
throw new BusinessException(StatResponseEnum.LINE_NULL);
|
||||
}
|
||||
for (CsLinePO item : lineList) {
|
||||
if (Objects.isNull(item.getPosition())){
|
||||
map.put(item.getClDid(),item.getLineId());
|
||||
} else {
|
||||
DictData dictData = dicDataFeignClient.getDicDataById(item.getPosition()).getData();
|
||||
if (Objects.equals(dictData.getCode(), DicDataEnum.OUTPUT_SIDE.getCode())){
|
||||
map.put(0,item.getLineId());
|
||||
} else if (Objects.equals(dictData.getCode(), DicDataEnum.GRID_SIDE.getCode())){
|
||||
map.put(1,item.getLineId());
|
||||
} else if (Objects.equals(dictData.getCode(), DicDataEnum.LOAD_SIDE.getCode())){
|
||||
map.put(2,item.getLineId());
|
||||
}
|
||||
//判断设备运行状态
|
||||
if (!Objects.isNull(po.getRunStatus()) && po.getRunStatus() == 1) {
|
||||
csDeviceFeignClient.updateRunStatus(appAutoDataMessage.getId(), AccessEnum.ONLINE.getCode());
|
||||
}
|
||||
}
|
||||
redisUtil.saveByKeyWithExpire(AppRedisKey.LINE_POSITION+id,map,30L);
|
||||
System.gc();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -204,7 +187,7 @@ public class StatServiceImpl implements IStatService {
|
||||
/**
|
||||
* influxDB数据组装
|
||||
*/
|
||||
public List<String> assembleData(String lineId,List<CsDataArray> dataArrayList,AppAutoDataMessage.DataArray item,Integer clDid,String statMethod,Integer process,String devType) {
|
||||
public List<String> assembleData(String lineId,List<CsDataArray> dataArrayList,AppAutoDataMessage.DataArray item,Integer clDid,String statMethod,Integer process,String devType,String accessMethod) {
|
||||
List<String> records = new ArrayList<String>();
|
||||
//解码
|
||||
List<Float> floats = PubUtils.byteArrayToFloatList(Base64.getDecoder().decode(item.getData()));
|
||||
@@ -231,8 +214,9 @@ public class StatServiceImpl implements IStatService {
|
||||
//这边特殊处理,如果数据为3.14159,则将数据置为null
|
||||
fields.put(dataArrayList.get(i).getName(),Objects.equals(floats.get(i),3.14159f) ? null:floats.get(i));
|
||||
fields.put(InfluxDBTableConstant.IS_ABNORMAL,item.getDataTag());
|
||||
//fixme 这边前置传递的应该是UTC时间,但是前置说是传递的北京时间,讨论了一下没太理解。这边暂时先这样处理,influx入库处理成北京时间,减去8小时。
|
||||
Point point = influxDbUtils.pointBuilder(tableName, Objects.equals(DicDataEnum.DEV_CLD.getCode(),devType)?item.getDataTimeSec():item.getDataTimeSec()-8*3600, TimeUnit.SECONDS, tags, fields);
|
||||
//fixme 设备上送的是北京时间,时序数据库录入时 需要utc时间,减去8小时
|
||||
boolean flag = Objects.equals(DicDataEnum.DEV_CLD.getCode(), devType) && Objects.equals(accessMethod, "CLD");
|
||||
Point point = influxDbUtils.pointBuilder(tableName, flag?item.getDataTimeSec():item.getDataTimeSec()-8*3600, TimeUnit.SECONDS, tags, fields);
|
||||
BatchPoints batchPoints = BatchPoints.database(influxDbUtils.getDbName()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
|
||||
batchPoints.point(point);
|
||||
records.add(batchPoints.lineProtocol());
|
||||
|
||||
@@ -41,6 +41,9 @@ public interface ZlConstant {
|
||||
*/
|
||||
String EVT_PARAM_TM = "Evt_Param_Tm";
|
||||
|
||||
|
||||
/**
|
||||
* 幅值
|
||||
*/
|
||||
String EVT_PARAM_VVADEPTH = "Evt_Param_VVaDepth";
|
||||
|
||||
}
|
||||
|
||||
@@ -73,6 +73,11 @@
|
||||
<artifactId>system-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>cs-system-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>cs-harmonic-api</artifactId>
|
||||
@@ -94,6 +99,16 @@
|
||||
<artifactId>common-oss</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>event-common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||
<version>2.7.12</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
|
||||
/**
|
||||
@@ -18,6 +19,7 @@ import org.springframework.context.annotation.DependsOn;
|
||||
@MapperScan("com.njcn.**.mapper")
|
||||
@EnableFeignClients(basePackages = "com.njcn")
|
||||
@SpringBootApplication(scanBasePackages = "com.njcn")
|
||||
@EnableAsync
|
||||
public class ZlEventBootApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.njcn.zlevent.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.AsyncConfigurer;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class AsyncConfig implements AsyncConfigurer {
|
||||
|
||||
@Bean("eventNotificationExecutor")
|
||||
public Executor eventNotificationExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setCorePoolSize(10);
|
||||
executor.setMaxPoolSize(20);
|
||||
executor.setQueueCapacity(200);
|
||||
executor.setThreadNamePrefix("event-notify-");
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
|
||||
@Bean("smsNotificationExecutor")
|
||||
public Executor smsNotificationExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setCorePoolSize(5);
|
||||
executor.setMaxPoolSize(10);
|
||||
executor.setQueueCapacity(100);
|
||||
executor.setThreadNamePrefix("sms-notify-");
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
package com.njcn.zlevent.service;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import com.njcn.access.pojo.dto.NoticeUserDto;
|
||||
import com.njcn.access.utils.SendMessageUtil;
|
||||
import com.njcn.csdevice.api.CsLedgerFeignClient;
|
||||
import com.njcn.csdevice.api.DeviceMessageFeignClient;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
import com.njcn.csdevice.api.EventLogsFeignClient;
|
||||
import com.njcn.csdevice.param.DeviceMessageParam;
|
||||
import com.njcn.csdevice.pojo.dto.DevDetailDTO;
|
||||
import com.njcn.csdevice.pojo.po.CsEventSendMsg;
|
||||
import com.njcn.csharmonic.pojo.po.CsEventUserPO;
|
||||
import com.njcn.system.api.EpdFeignClient;
|
||||
import com.njcn.user.pojo.po.User;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class AppNotificationService {
|
||||
|
||||
private final DeviceMessageFeignClient deviceMessageFeignClient;
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
private final EpdFeignClient epdFeignClient;
|
||||
private final ICsEventUserService csEventUserService;
|
||||
private final SendMessageUtil sendMessageUtil;
|
||||
private final EventLogsFeignClient eventLogsFeignClient;
|
||||
private final CsLedgerFeignClient csLedgerFeignClient;
|
||||
|
||||
@Async("eventNotificationExecutor")
|
||||
public void sendAppNotification(Integer eventType, String type, String devId,
|
||||
String eventName, LocalDateTime eventTime,
|
||||
String id, String nDid, Double amplitude, Double persistTime) {
|
||||
int code;
|
||||
List<User> users = new ArrayList<>();
|
||||
List<String> eventUser;
|
||||
List<String> devCodeList;
|
||||
List<String> userList = new ArrayList<>();
|
||||
List<CsEventSendMsg> csEventSendMsgList = new ArrayList<>();
|
||||
NoticeUserDto noticeUserDto = new NoticeUserDto();
|
||||
NoticeUserDto.Payload payload = new NoticeUserDto.Payload();
|
||||
String content = null;
|
||||
List<CsEventUserPO> result = new ArrayList<>();
|
||||
//获取设备类型 true:治理设备 false:其他类型的设备
|
||||
boolean devModel = equipmentFeignClient.judgeDevModel(nDid).getData();
|
||||
if (devModel) {
|
||||
DevDetailDTO devDetailDto = csLedgerFeignClient.queryDevDetail(devId).getData();
|
||||
//事件处理
|
||||
if (eventType == 1){
|
||||
eventName = epdFeignClient.findByName(eventName).getData().getShowName();
|
||||
switch (type) {
|
||||
case "1":
|
||||
code = 3;
|
||||
//设备自身事件 不推送给用户,推送给业务管理
|
||||
eventUser = deviceMessageFeignClient.getEventUserByDeviceId(devId,false).getData();
|
||||
if (CollectionUtil.isNotEmpty(eventUser)) {
|
||||
eventUser.forEach(item->{
|
||||
CsEventUserPO csEventUser = new CsEventUserPO();
|
||||
csEventUser.setUserId(item);
|
||||
csEventUser.setStatus(0);
|
||||
csEventUser.setEventId(id);
|
||||
result.add(csEventUser);
|
||||
});
|
||||
|
||||
DeviceMessageParam param1 = new DeviceMessageParam();
|
||||
param1.setUserList(eventUser);
|
||||
param1.setEventType(2);
|
||||
users = deviceMessageFeignClient.getSendUserByType(param1).getData();
|
||||
if (CollectionUtil.isNotEmpty(users)){
|
||||
for (User user : users){
|
||||
userList.add(user.getDevCode());
|
||||
}
|
||||
noticeUserDto.setPushClientId(userList);
|
||||
noticeUserDto.setTitle("运行事件");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "2":
|
||||
code = 0;
|
||||
//暂态事件
|
||||
eventUser = deviceMessageFeignClient.getEventUserByDeviceId(devId,true).getData();
|
||||
if (CollectionUtil.isNotEmpty(eventUser)) {
|
||||
eventUser.forEach(item->{
|
||||
CsEventUserPO csEventUser = new CsEventUserPO();
|
||||
csEventUser.setUserId(item);
|
||||
csEventUser.setStatus(0);
|
||||
csEventUser.setEventId(id);
|
||||
result.add(csEventUser);
|
||||
});
|
||||
DeviceMessageParam param1 = new DeviceMessageParam();
|
||||
param1.setUserList(eventUser);
|
||||
param1.setEventType(0);
|
||||
users = deviceMessageFeignClient.getSendUserByType(param1).getData();
|
||||
if (CollectionUtil.isNotEmpty(users)){
|
||||
devCodeList = users.stream().map(User::getDevCode).distinct().collect(Collectors.toList());
|
||||
noticeUserDto.setPushClientId(devCodeList);
|
||||
noticeUserDto.setTitle("暂态事件");
|
||||
content = devDetailDto.getEngineeringName() + "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName()
|
||||
+ "于" + eventTime.format(DatePattern.NORM_DATETIME_MS_FORMATTER) + "发生暂态事件,事件类型:"
|
||||
+ eventName
|
||||
+ ",特征幅值:" + amplitude + "%"
|
||||
+ ",持续时间:" + persistTime + "s";
|
||||
}
|
||||
}
|
||||
break;
|
||||
// case "3":
|
||||
// code = 1;
|
||||
// //稳态事件
|
||||
// eventUser = getEventUser(devId,true);
|
||||
// if (CollectionUtil.isNotEmpty(eventUser)) {
|
||||
// eventUser.forEach(item->{
|
||||
// CsEventUserPO csEventUser = new CsEventUserPO();
|
||||
// csEventUser.setUserId(item);
|
||||
// csEventUser.setStatus(0);
|
||||
// csEventUser.setEventId(id);
|
||||
// result.add(csEventUser);
|
||||
// });
|
||||
// users = getSendUser(eventUser,1);
|
||||
// if (CollectionUtil.isNotEmpty(users)){
|
||||
// devCodeList = users.stream().map(User::getDevCode).distinct().collect(Collectors.toList());
|
||||
// noticeUserDto.setPushClientId(devCodeList);
|
||||
// noticeUserDto.setTitle("稳态事件");
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
default:
|
||||
code = 0;
|
||||
break;
|
||||
}
|
||||
//获取台账信息
|
||||
if (Objects.isNull(content)) {
|
||||
content = devDetailDto.getEngineeringName() + "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName() + "于" + eventTime.format(DatePattern.NORM_DATETIME_MS_FORMATTER) + "发生" + eventName;
|
||||
}
|
||||
noticeUserDto.setContent(content);
|
||||
payload.setType(code);
|
||||
payload.setPath("/pages/index/message1?type="+payload.getType());
|
||||
noticeUserDto.setPayload(payload);
|
||||
}
|
||||
// //告警处理
|
||||
// else if (eventType == 2){
|
||||
// switch (type) {
|
||||
// case "1":
|
||||
// //Ⅰ级告警 不推送给用户,推送给业务管理
|
||||
// eventUser = getEventUser(devId,false);
|
||||
// if (CollectionUtil.isNotEmpty(eventUser)) {
|
||||
// eventUser.forEach(item->{
|
||||
// CsEventUserPO csEventUser = new CsEventUserPO();
|
||||
// csEventUser.setUserId(item);
|
||||
// csEventUser.setStatus(0);
|
||||
// csEventUser.setEventId(id);
|
||||
// result.add(csEventUser);
|
||||
// });
|
||||
// users = getSendUser(eventUser,3);
|
||||
// if (CollectionUtil.isNotEmpty(users)){
|
||||
// eventName = epdFeignClient.findByName(eventName).getData().getShowName();
|
||||
// devCodeList = users.stream().map(User::getDevCode).distinct().collect(Collectors.toList());
|
||||
// noticeUserDto.setPushClientId(devCodeList);
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
// case "2":
|
||||
// eventName = epdFeignClient.findByName(eventName).getData().getShowName();
|
||||
// case "3":
|
||||
// //Ⅱ、Ⅲ级告警推送相关用户及业务管理员
|
||||
// eventUser = getEventUser(devId,true);
|
||||
// if (CollectionUtil.isNotEmpty(eventUser)) {
|
||||
// eventUser.forEach(item->{
|
||||
// CsEventUserPO csEventUser = new CsEventUserPO();
|
||||
// csEventUser.setUserId(item);
|
||||
// csEventUser.setStatus(0);
|
||||
// csEventUser.setEventId(id);
|
||||
// result.add(csEventUser);
|
||||
// });
|
||||
// users = getSendUser(eventUser,3);
|
||||
// if (CollectionUtil.isNotEmpty(users)){
|
||||
// devCodeList = users.stream().map(User::getDevCode).distinct().collect(Collectors.toList());
|
||||
// noticeUserDto.setPushClientId(devCodeList);
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// noticeUserDto.setTitle("告警事件");
|
||||
// DevDetailDTO devDetailDto = csLedgerFeignclient.queryDevDetail(devId).getData();
|
||||
// content = devDetailDto.getEngineeringName() + "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName() + "于" + eventTime.format(DatePattern.NORM_DATETIME_MS_FORMATTER) + "发生告警,告警信息:" + eventName;
|
||||
// noticeUserDto.setContent(content);
|
||||
// payload.setType(3);
|
||||
// payload.setPath("/pages/message/message?type="+payload.getType());
|
||||
// noticeUserDto.setPayload(payload);
|
||||
// }
|
||||
if (CollectionUtil.isNotEmpty(noticeUserDto.getPushClientId())) {
|
||||
List<String> filteredList = noticeUserDto.getPushClientId().stream()
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(filteredList)) {
|
||||
noticeUserDto.setPushClientId(filteredList);
|
||||
sendMessageUtil.sendEventToUser(noticeUserDto);
|
||||
}
|
||||
}
|
||||
//记录推送日志
|
||||
for (User item : users) {
|
||||
CsEventSendMsg csEventSendMsg = new CsEventSendMsg();
|
||||
csEventSendMsg.setUserId(item.getId());
|
||||
csEventSendMsg.setEventId(id);
|
||||
csEventSendMsg.setSendTime(LocalDateTime.now());
|
||||
if (Objects.isNull(item.getDevCode())){
|
||||
csEventSendMsg.setStatus(0);
|
||||
csEventSendMsg.setRemark("用户设备识别码为空");
|
||||
} else {
|
||||
csEventSendMsg.setDevCode(item.getDevCode());
|
||||
csEventSendMsg.setStatus(1);
|
||||
}
|
||||
csEventSendMsgList.add(csEventSendMsg);
|
||||
}
|
||||
eventLogsFeignClient.addLogs(csEventSendMsgList);
|
||||
//事件用户关系入库
|
||||
if (CollectionUtil.isNotEmpty(result)){
|
||||
csEventUserService.saveBatch(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.njcn.zlevent.service;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.njcn.csdevice.api.CsLedgerFeignClient;
|
||||
import com.njcn.csdevice.api.SmsSendFeignClient;
|
||||
import com.njcn.csdevice.pojo.dto.DevDetailDTO;
|
||||
import com.njcn.cssystem.api.AppMsgSetFeignClient;
|
||||
import com.njcn.user.api.UserFeignClient;
|
||||
import com.njcn.user.pojo.po.User;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class SmsNotificationService {
|
||||
|
||||
private final AppMsgSetFeignClient appMsgSetFeignClient;
|
||||
private final UserFeignClient userFeignClient;
|
||||
private final SmsSendFeignClient smsSendFeignClient;
|
||||
private final CsLedgerFeignClient csLedgerFeignclient;
|
||||
|
||||
@Value("${msg.msg_sign:南京灿能电力}")
|
||||
private String msgSign;
|
||||
|
||||
@Async("smsNotificationExecutor")
|
||||
public void sendSmsForDipEvent(String deviceId, LocalDateTime eventTime,double amplitude,double persistTime) {
|
||||
try {
|
||||
List<String> userIdList = appMsgSetFeignClient.queryUserIdsByDeviceId(deviceId).getData();
|
||||
if (CollectionUtil.isNotEmpty(userIdList)) {
|
||||
List<User> userList = userFeignClient.getUserListByIds(userIdList).getData();
|
||||
if (CollectionUtil.isNotEmpty(userList)) {
|
||||
List<User> userList1 = userList.stream()
|
||||
.filter(item -> StrUtil.isNotBlank(item.getPhone()) && Objects.equals(item.getSmsNotice(), 1))
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(userList1)) {
|
||||
DevDetailDTO devDetailDto = csLedgerFeignclient.queryDevDetail(deviceId).getData();
|
||||
String msgContent = "【" + msgSign + "】" + devDetailDto.getEngineeringName()
|
||||
+ "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName()
|
||||
+ "于" + eventTime.format(DatePattern.NORM_DATETIME_MS_FORMATTER) + "发生暂降事件"
|
||||
+ ",特征幅值:" + amplitude + "%"
|
||||
+ ",持续时间:" + persistTime + "s";
|
||||
userList1.forEach(item -> {
|
||||
try {
|
||||
smsSendFeignClient.sendSmsSimple(item.getPhone(), msgContent, "verify_code");
|
||||
} catch (Exception e) {
|
||||
log.error("发送短信失败,手机号: {}", item.getPhone(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("异步发送暂降事件短信失败,设备ID: {}", deviceId, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,7 @@ package com.njcn.zlevent.service.impl;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.access.pojo.po.CsDeviceOnlineLogs;
|
||||
import com.njcn.access.utils.ChannelObjectUtil;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
@@ -21,10 +19,10 @@ import com.njcn.system.pojo.po.EleEpdPqd;
|
||||
import com.njcn.system.pojo.po.SysDicTreePO;
|
||||
import com.njcn.zlevent.mapper.CsEventMapper;
|
||||
import com.njcn.zlevent.pojo.po.CsEventLogs;
|
||||
import com.njcn.zlevent.service.AppNotificationService;
|
||||
import com.njcn.zlevent.service.ICsAlarmService;
|
||||
import com.njcn.zlevent.service.ICsEventLogsService;
|
||||
import com.njcn.zlevent.service.ICsEventService;
|
||||
import com.njcn.zlevent.utils.SendEventUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -52,11 +50,11 @@ public class CsAlarmServiceImpl extends ServiceImpl<CsEventMapper, CsEventPO> im
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
private final EventServiceImpl eventService;
|
||||
private final ICsEventService csEventService;
|
||||
private final SendEventUtils sendEventUtils;
|
||||
private final ICsEventLogsService csEventLogsService;
|
||||
private final EpdFeignClient epdFeignClient;
|
||||
private final RedisUtil redisUtil;
|
||||
private final ChannelObjectUtil channelObjectUtil;
|
||||
private final AppNotificationService appNotificationService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@@ -128,9 +126,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,po.getNdid());
|
||||
appNotificationService.sendAppNotification(2,item.getType(),po.getId(),item.getName(),eventTime,id,po.getNdid(),null,null);
|
||||
} else {
|
||||
sendEventUtils.sendUser(2,item.getType(),po.getId(),item.getCode(),eventTime,id,po.getNdid());
|
||||
appNotificationService.sendAppNotification(2,item.getType(),po.getId(),item.getCode(),eventTime,id,po.getNdid(),null, null);
|
||||
//更新字典信息
|
||||
EleEpdPqd eleEpdPqd = epdFeignClient.findByName(item.getName()).getData();
|
||||
EleEpdPqdParam.EleEpdPqdUpdateParam updateParam = new EleEpdPqdParam.EleEpdPqdUpdateParam();
|
||||
|
||||
@@ -1,33 +1,28 @@
|
||||
package com.njcn.zlevent.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
import com.njcn.access.api.CsTopicFeignClient;
|
||||
import com.njcn.access.utils.ChannelObjectUtil;
|
||||
import com.njcn.access.utils.FileCommonUtils;
|
||||
import com.njcn.access.utils.MqttUtil;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.api.CsLineFeignClient;
|
||||
import com.njcn.csdevice.api.DeviceMessageFeignClient;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
||||
import com.njcn.csdevice.pojo.po.CsLinePO;
|
||||
import com.njcn.mq.message.AppEventMessage;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.stat.enums.StatResponseEnum;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.pojo.po.DictData;
|
||||
import com.njcn.zlevent.pojo.constant.ZlConstant;
|
||||
import com.njcn.zlevent.pojo.dto.WaveTimeDto;
|
||||
import com.njcn.zlevent.service.ICsWaveAnalysisService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -43,14 +38,11 @@ import java.util.stream.Collectors;
|
||||
public class CsWaveAnalysisServiceImpl implements ICsWaveAnalysisService {
|
||||
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
private final MqttPublisher publisher;
|
||||
private final CsTopicFeignClient csTopicFeignClient;
|
||||
private final RedisUtil redisUtil;
|
||||
private final CsLineFeignClient csLineFeignClient;
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
private final ChannelObjectUtil channelObjectUtil;
|
||||
private final MqttUtil mqttUtil;
|
||||
private final FileCommonUtils fileCommonUtils;
|
||||
private final DeviceMessageFeignClient deviceMessageFeignClient;
|
||||
private static Integer mid = 1;
|
||||
|
||||
@Override
|
||||
@@ -59,7 +51,7 @@ public class CsWaveAnalysisServiceImpl implements ICsWaveAnalysisService {
|
||||
List<WaveTimeDto> list = new ArrayList<>();
|
||||
Object object1 = redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId());
|
||||
if (Objects.isNull(object1)){
|
||||
lineInfo(appEventMessage.getId());
|
||||
deviceMessageFeignClient.getLineInfo(appEventMessage.getId());
|
||||
}
|
||||
//获取装置id
|
||||
String deviceId = equipmentFeignClient.findDevByNDid(appEventMessage.getId()).getData().getId();
|
||||
@@ -161,29 +153,4 @@ public class CsWaveAnalysisServiceImpl implements ICsWaveAnalysisService {
|
||||
waveTimeDto.setLocation(location);
|
||||
return waveTimeDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存监测点相关信息
|
||||
*/
|
||||
public void lineInfo(String id) {
|
||||
Map<Integer,String> map = new HashMap<>();
|
||||
List<CsLinePO> lineList = csLineFeignClient.findByNdid(id).getData();
|
||||
if (CollectionUtil.isEmpty(lineList)){
|
||||
throw new BusinessException(StatResponseEnum.LINE_NULL);
|
||||
}
|
||||
for (CsLinePO item : lineList) {
|
||||
DictData dictData = dicDataFeignClient.getDicDataById(item.getPosition()).getData();
|
||||
if (Objects.isNull(dictData)){
|
||||
throw new BusinessException(StatResponseEnum.DICT_NULL);
|
||||
}
|
||||
if (Objects.equals(dictData.getCode(), DicDataEnum.OUTPUT_SIDE.getCode())){
|
||||
map.put(0,item.getLineId());
|
||||
} else if (Objects.equals(dictData.getCode(), DicDataEnum.GRID_SIDE.getCode())){
|
||||
map.put(1,item.getLineId());
|
||||
} else if (Objects.equals(dictData.getCode(), DicDataEnum.LOAD_SIDE.getCode())){
|
||||
map.put(2,item.getLineId());
|
||||
}
|
||||
}
|
||||
redisUtil.saveByKeyWithExpire(AppRedisKey.LINE_POSITION+id,map,30L);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,13 @@ package com.njcn.zlevent.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.api.CsLineFeignClient;
|
||||
import com.njcn.csdevice.api.DeviceMessageFeignClient;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
import com.njcn.csdevice.api.WlRecordFeignClient;
|
||||
import com.njcn.csdevice.pojo.param.WlRecordParam;
|
||||
@@ -14,6 +17,8 @@ import com.njcn.csdevice.pojo.po.CsLinePO;
|
||||
import com.njcn.csdevice.pojo.po.WlRecord;
|
||||
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
|
||||
import com.njcn.csharmonic.pojo.po.CsEventPO;
|
||||
import com.njcn.event.common.mapper.WlRmpEventDetailMapper;
|
||||
import com.njcn.event.pojo.po.RmpEventDetailPO;
|
||||
import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
|
||||
import com.njcn.influx.utils.InfluxDbUtils;
|
||||
import com.njcn.mq.message.AppEventMessage;
|
||||
@@ -22,17 +27,17 @@ import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.stat.enums.StatResponseEnum;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.api.DictTreeFeignClient;
|
||||
import com.njcn.system.api.EpdFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.pojo.dto.EpdDTO;
|
||||
import com.njcn.system.pojo.po.DictData;
|
||||
import com.njcn.zlevent.pojo.constant.ZlConstant;
|
||||
import com.njcn.zlevent.pojo.po.CsEventLogs;
|
||||
import com.njcn.zlevent.service.ICsEventLogsService;
|
||||
import com.njcn.zlevent.service.AppNotificationService;
|
||||
import com.njcn.zlevent.service.ICsEventService;
|
||||
import com.njcn.zlevent.service.IEventService;
|
||||
import com.njcn.zlevent.utils.SendEventUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import com.njcn.zlevent.service.SmsNotificationService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.influxdb.InfluxDB;
|
||||
import org.influxdb.dto.BatchPoints;
|
||||
@@ -49,6 +54,7 @@ import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
@@ -59,7 +65,7 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
public class EventServiceImpl implements IEventService {
|
||||
|
||||
private final CsLineFeignClient csLineFeignClient;
|
||||
@@ -69,12 +75,15 @@ public class EventServiceImpl implements IEventService {
|
||||
private final ICsEventService csEventService;
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
private final InfluxDbUtils influxDbUtils;
|
||||
private final ICsEventLogsService csEventLogsService;
|
||||
private final SendEventUtils sendEventUtils;
|
||||
private final WlRecordFeignClient wlRecordFeignClient;
|
||||
private final WlRmpEventDetailMapper wlRmpEventDetailMapper;
|
||||
private final DictTreeFeignClient dictTreeFeignClient;
|
||||
private final DeviceMessageFeignClient deviceMessageFeignClient;
|
||||
private final AppNotificationService appNotificationService;
|
||||
private final SmsNotificationService smsNotificationService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@DSTransactional
|
||||
public void analysis(AppEventMessage appEventMessage) {
|
||||
List<CsEventPO> list1 = new ArrayList<>();
|
||||
List<String> records = new ArrayList<String>();
|
||||
@@ -87,21 +96,30 @@ public class EventServiceImpl implements IEventService {
|
||||
}
|
||||
//判断监测点是否存在
|
||||
if (Objects.isNull(object1)){
|
||||
lineInfo(appEventMessage.getId());
|
||||
deviceMessageFeignClient.getLineInfo(appEventMessage.getId());
|
||||
}
|
||||
//获取装置id
|
||||
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(appEventMessage.getId()).getData();
|
||||
//获取设备类型 true:治理设备 false:其他类型的设备
|
||||
boolean devModel = equipmentFeignClient.judgeDevModel(appEventMessage.getId()).getData();
|
||||
//判断设备型号
|
||||
String code = dictTreeFeignClient.queryById(po.getDevType()).getData().getCode();
|
||||
try {
|
||||
if (devModel) {
|
||||
if (Objects.equals(DicDataEnum.CONNECT_DEV.getCode(),code)) {
|
||||
if (Objects.equals(appEventMessage.getDid(),1)){
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get("0").toString();
|
||||
Object object = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get("0");
|
||||
if (ObjectUtil.isNotNull(object)) {
|
||||
lineId = object.toString();
|
||||
}
|
||||
} else if (Objects.equals(appEventMessage.getDid(),2)){
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get(appEventMessage.getMsg().getClDid().toString()).toString();
|
||||
Object object = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get(appEventMessage.getMsg().getClDid().toString());
|
||||
if (ObjectUtil.isNotNull(object)) {
|
||||
lineId = object.toString();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get(appEventMessage.getMsg().getClDid().toString()).toString();
|
||||
Object object = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get(appEventMessage.getMsg().getClDid().toString());
|
||||
if (ObjectUtil.isNotNull(object)) {
|
||||
lineId = object.toString();
|
||||
}
|
||||
}
|
||||
|
||||
//处理事件数据
|
||||
@@ -111,9 +129,9 @@ public class EventServiceImpl implements IEventService {
|
||||
//判断事件是否存在,如果存在则不处理
|
||||
LambdaQueryWrapper<CsEventPO> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(CsEventPO::getDeviceId,po.getId())
|
||||
.eq(CsEventPO::getTag,tag)
|
||||
.eq(CsEventPO::getTag,item.getName())
|
||||
.eq(CsEventPO::getStartTime,eventTime)
|
||||
.eq(CsEventPO::getLineId,lineId);
|
||||
.eq(ObjectUtil.isNotNull(lineId),CsEventPO::getLineId,lineId);
|
||||
List<CsEventPO> eventList = csEventService.list(queryWrapper);
|
||||
if (CollectionUtil.isEmpty(eventList)) {
|
||||
id = IdUtil.fastSimpleUUID();
|
||||
@@ -150,10 +168,16 @@ public class EventServiceImpl implements IEventService {
|
||||
if (Objects.equals(param.getName(),ZlConstant.EVT_PARAM_TM)){
|
||||
csEvent.setPersistTime(Double.parseDouble(param.getData().toString()));
|
||||
}
|
||||
if (Objects.equals(param.getName(),ZlConstant.EVT_PARAM_VVADEPTH)) {
|
||||
csEvent.setAmplitude(Double.parseDouble(param.getData().toString()));
|
||||
}
|
||||
if (Objects.equals(param.getName(),"Evt_Param_Phase")) {
|
||||
csEvent.setPhase(param.getData().toString());
|
||||
}
|
||||
fields.put(param.getName(),param.getData());
|
||||
}
|
||||
//只有治理型号的设备有监测位置
|
||||
if (devModel) {
|
||||
if (Objects.equals(DicDataEnum.CONNECT_DEV.getCode(),code)) {
|
||||
if (appEventMessage.getMsg().getClDid() == 1) {
|
||||
fields.put("Evt_Param_Position","电网侧");
|
||||
csEvent.setLocation("grid");
|
||||
@@ -162,49 +186,108 @@ public class EventServiceImpl implements IEventService {
|
||||
csEvent.setLocation("load");
|
||||
}
|
||||
}
|
||||
//fixme 这边前置传递的应该是UTC时间,但是前置说是传递的北京时间,讨论了一下没太理解。这边暂时先这样处理,influx入库处理成北京时间,减去8小时。
|
||||
//fixme 设备上送的是北京时间,时序数据库录入时 需要utc时间,减去8小时
|
||||
Point point = influxDbUtils.pointBuilder(tableName, item.getDataTimeSec()-8*3600, TimeUnit.SECONDS, tags, fields);
|
||||
BatchPoints batchPoints = BatchPoints.database(influxDbUtils.getDbName()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
|
||||
batchPoints.point(point);
|
||||
records.add(batchPoints.lineProtocol());
|
||||
}
|
||||
list1.add(csEvent);
|
||||
//事件处理日志库
|
||||
CsEventLogs csEventLogs = new CsEventLogs();
|
||||
csEventLogs.setLineId(lineId);
|
||||
csEventLogs.setDeviceId(po.getId());
|
||||
csEventLogs.setStartTime(timeFormat(item.getDataTimeSec(),item.getDataTimeUSec()));
|
||||
csEventLogs.setTag(item.getName());
|
||||
csEventLogs.setStatus(1);
|
||||
csEventLogs.setTime(LocalDateTime.now());
|
||||
csEventLogsService.save(csEventLogs);
|
||||
}
|
||||
}
|
||||
//cs_event入库
|
||||
if (CollectionUtil.isNotEmpty(list1)){
|
||||
csEventService.saveBatch(list1);
|
||||
//推送事件逻辑处理 && cs_event_user入库
|
||||
for (AppEventMessage.DataArray item : dataArray) {
|
||||
sendEventUtils.sendUser(1,item.getType(),po.getId(),item.getName(),eventTime,id,po.getNdid());
|
||||
}
|
||||
}
|
||||
//evt_data入库
|
||||
if (CollectionUtil.isNotEmpty(records)) {
|
||||
influxDbUtils.batchInsert(influxDbUtils.getDbName(), "", InfluxDB.ConsistencyLevel.ALL, TimeUnit.MILLISECONDS, records);
|
||||
}
|
||||
//cs_event入库
|
||||
if (CollectionUtil.isNotEmpty(list1)){
|
||||
csEventService.saveBatch(list1);
|
||||
//同步数据到 r_mp_event_detail 只有暂态事件再同步
|
||||
List<CsEventPO> filterList = list1.stream().filter(csEvent -> Objects.equals(csEvent.getType(), 0)).collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(filterList)) {
|
||||
filterList.forEach(this::insertEvent);
|
||||
}
|
||||
//异步推送事件逻辑处理 && cs_event_user入库
|
||||
for (AppEventMessage.DataArray item : dataArray) {
|
||||
double amplitude = 0.0;
|
||||
double persistTime = 0.0;
|
||||
List<AppEventMessage.Param> params = item.getParam();
|
||||
if (CollectionUtil.isNotEmpty(params)) {
|
||||
for (AppEventMessage.Param param : params) {
|
||||
if (Objects.equals(param.getName(),ZlConstant.EVT_PARAM_VVADEPTH)) {
|
||||
amplitude = Double.parseDouble(String.format("%.2f", Double.parseDouble(param.getData().toString())));
|
||||
}
|
||||
if (Objects.equals(param.getName(),ZlConstant.EVT_PARAM_TM)) {
|
||||
persistTime = Double.parseDouble(String.format("%.2f", Double.parseDouble(param.getData().toString())));
|
||||
}
|
||||
}
|
||||
}
|
||||
appNotificationService.sendAppNotification(1, item.getType(), po.getId(), item.getName(), eventTime, id, po.getNdid(),amplitude,persistTime);
|
||||
//如果是暂降事件,则异步发送短信
|
||||
if (Objects.equals(item.getName(), "Evt_Sys_DipStr")) {
|
||||
smsNotificationService.sendSmsForDipEvent(po.getId(), eventTime,amplitude,persistTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CsEventLogs csEventLogs = new CsEventLogs();
|
||||
csEventLogs.setLineId(lineId);
|
||||
csEventLogs.setDeviceId(po.getId());
|
||||
csEventLogs.setStartTime(eventTime);
|
||||
csEventLogs.setTag(tag);
|
||||
csEventLogs.setStatus(0);
|
||||
csEventLogs.setTime(LocalDateTime.now());
|
||||
csEventLogs.setRemark(e.getMessage());
|
||||
csEventLogsService.save(csEventLogs);
|
||||
log.error("事件入库异常:{}",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void insertEvent(CsEventPO item) {
|
||||
RmpEventDetailPO rmpEventDetailPo = new RmpEventDetailPO();
|
||||
rmpEventDetailPo.setEventId(item.getId());
|
||||
rmpEventDetailPo.setMeasurementPointId(item.getLineId());
|
||||
rmpEventDetailPo.setStartTime(item.getStartTime());
|
||||
rmpEventDetailPo.setEventType(getEventType(item.getTag()));
|
||||
rmpEventDetailPo.setFeatureAmplitude(item.getAmplitude());
|
||||
rmpEventDetailPo.setDuration(item.getPersistTime());
|
||||
rmpEventDetailPo.setEventDescribe(getTag(item.getTag()));
|
||||
rmpEventDetailPo.setDealFlag(0);
|
||||
rmpEventDetailPo.setFileFlag(0);
|
||||
rmpEventDetailPo.setPhase(item.getPhase());
|
||||
wlRmpEventDetailMapper.insert(rmpEventDetailPo);
|
||||
}
|
||||
|
||||
public String getEventType(String tag) {
|
||||
switch (tag) {
|
||||
case "Evt_Sys_DipStr":
|
||||
DictData dip = dicDataFeignClient.getDicDataByCode(DicDataEnum.VOLTAGE_DIP.getCode()).getData();
|
||||
tag = dip.getId();
|
||||
break;
|
||||
case "Evt_Sys_SwlStr":
|
||||
DictData rise = dicDataFeignClient.getDicDataByCode(DicDataEnum.VOLTAGE_RISE.getCode()).getData();
|
||||
tag = rise.getId();
|
||||
break;
|
||||
case "Evt_Sys_IntrStr":
|
||||
DictData interruptions = dicDataFeignClient.getDicDataByCode(DicDataEnum.SHORT_INTERRUPTIONS.getCode()).getData();
|
||||
tag = interruptions.getId();
|
||||
break;
|
||||
default:
|
||||
tag = "Un_Know";
|
||||
break;
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
public String getTag(String tag) {
|
||||
switch (tag) {
|
||||
case "Evt_Sys_DipStr":
|
||||
tag = DicDataEnum.VOLTAGE_DIP.getCode();
|
||||
break;
|
||||
case "Evt_Sys_SwlStr":
|
||||
tag = DicDataEnum.VOLTAGE_RISE.getCode();
|
||||
break;
|
||||
case "Evt_Sys_IntrStr":
|
||||
tag = DicDataEnum.SHORT_INTERRUPTIONS.getCode();
|
||||
break;
|
||||
default:
|
||||
tag = "Un_Know";
|
||||
break;
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void getPortableData(AppEventMessage appEventMessage) {
|
||||
@@ -348,31 +431,6 @@ public class EventServiceImpl implements IEventService {
|
||||
return Objects.isNull(result)?null:result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存监测点相关信息
|
||||
*/
|
||||
public void lineInfo(String id) {
|
||||
Map<Integer,String> map = new HashMap<>();
|
||||
List<CsLinePO> lineList = csLineFeignClient.findByNdid(id).getData();
|
||||
if (CollectionUtil.isEmpty(lineList)){
|
||||
throw new BusinessException(StatResponseEnum.LINE_NULL);
|
||||
}
|
||||
for (CsLinePO item : lineList) {
|
||||
DictData dictData = dicDataFeignClient.getDicDataById(item.getPosition()).getData();
|
||||
if (Objects.isNull(dictData)){
|
||||
throw new BusinessException(StatResponseEnum.DICT_NULL);
|
||||
}
|
||||
if (Objects.equals(dictData.getCode(), DicDataEnum.OUTPUT_SIDE.getCode())){
|
||||
map.put(0,item.getLineId());
|
||||
} else if (Objects.equals(dictData.getCode(), DicDataEnum.GRID_SIDE.getCode())){
|
||||
map.put(1,item.getLineId());
|
||||
} else if (Objects.equals(dictData.getCode(), DicDataEnum.LOAD_SIDE.getCode())){
|
||||
map.put(2,item.getLineId());
|
||||
}
|
||||
}
|
||||
redisUtil.saveByKeyWithExpire(AppRedisKey.LINE_POSITION+id,map,30L);
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存字典和influxDB表关系
|
||||
*/
|
||||
|
||||
@@ -31,7 +31,6 @@ 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.user.api.UserFeignClient;
|
||||
import com.njcn.zlevent.param.CsEventParam;
|
||||
import com.njcn.zlevent.pojo.dto.FileInfoDto;
|
||||
import com.njcn.zlevent.pojo.dto.FileStreamDto;
|
||||
@@ -270,7 +269,7 @@ public class FileServiceImpl implements IFileService {
|
||||
+ ",nowStep:" + appFileMessage.getMsg().getFrameCurr()
|
||||
+ ",userId:" + userIndex
|
||||
+"}";
|
||||
publisher.send("/Web/Progress/" + appFileMessage.getId(), new Gson().toJson(json), 1, false);
|
||||
publisher.send("/Web/Progress/" + appFileMessage.getId(), new Gson().toJson(json), 2, false);
|
||||
if (!Objects.isNull(filePath)){
|
||||
redisUtil.saveByKeyWithExpire("downloadFilePath:" + appFileMessage.getId() + appFileMessage.getMsg().getName(),filePath,60L);
|
||||
}
|
||||
@@ -280,6 +279,7 @@ public class FileServiceImpl implements IFileService {
|
||||
//2.缓存了判断收到的报文个数是否和总个数一致,一致则解析文件;不一致则更新缓存
|
||||
//3.超时判断: 30s未收到相关文件信息,核查文件个数,看丢失哪些帧,重新请求
|
||||
else {
|
||||
Object isWeb = redisUtil.getObjectByKey("isWeb:" + appFileMessage.getId());
|
||||
redisUtil.saveByKey("handleEvent:" + appFileMessage.getId(),"doing");
|
||||
if (appFileMessage.getMsg().getFrameTotal() == 1){
|
||||
//解析文件入库
|
||||
@@ -289,14 +289,20 @@ public class FileServiceImpl implements IFileService {
|
||||
csEventLogs.setNowStep(1);
|
||||
csEventLogs.setAllStep(1);
|
||||
csEventLogs.setIsAll(1);
|
||||
//更新文件信息
|
||||
csWaveService.updateCsWave(fileName);
|
||||
//波形文件关联事件
|
||||
filePath = filePath.replaceAll(GeneralConstant.CFG,"").replaceAll(GeneralConstant.DAT,"");
|
||||
List<String> eventList = correlateEvents(fileInfoDto,filePath,fileName);
|
||||
//波形文件解析成图片
|
||||
if (CollectionUtil.isNotEmpty(eventList) && devModel){
|
||||
eventList.forEach(wavePicFeignClient::getWavePics);
|
||||
if (Objects.isNull(isWeb)) {
|
||||
//更新文件信息
|
||||
csWaveService.updateCsWave(fileName);
|
||||
//波形文件关联事件
|
||||
filePath = filePath.replaceAll(GeneralConstant.CFG,"").replaceAll(GeneralConstant.DAT,"");
|
||||
List<String> eventList = correlateEvents(fileInfoDto,filePath,fileName);
|
||||
if (CollectionUtil.isNotEmpty(eventList) && devModel){
|
||||
eventList.forEach(item -> {
|
||||
//波形文件解析成图片
|
||||
wavePicFeignClient.getWavePics(item);
|
||||
//同步更新r_mp_event_detail,将波形路径录入
|
||||
wavePicFeignClient.updateEventById(item);
|
||||
});
|
||||
}
|
||||
}
|
||||
//解析完删除、处理缓存
|
||||
removeInfoUtils.deleteEventInfo(appFileMessage.getId(),fileName);
|
||||
@@ -335,14 +341,20 @@ public class FileServiceImpl implements IFileService {
|
||||
csEventLogs.setAllStep(appFileMessage.getMsg().getFrameTotal());
|
||||
csEventLogs.setIsAll(1);
|
||||
log.info("当前文件 {} 帧,这是第 {} 帧报文,全部收到,解析成功!", appFileMessage.getMsg().getFrameTotal(), appFileMessage.getMsg().getFrameCurr());
|
||||
//修改文件信息
|
||||
csWaveService.updateCsWave(fileName);
|
||||
//波形文件关联事件
|
||||
filePath = filePath.replaceAll(GeneralConstant.CFG, "").replaceAll(GeneralConstant.DAT, "");
|
||||
List<String> eventList = correlateEvents(fileInfoDto, filePath, fileName);
|
||||
//波形文件解析成图片
|
||||
if (CollectionUtil.isNotEmpty(eventList) && devModel) {
|
||||
eventList.forEach(wavePicFeignClient::getWavePics);
|
||||
if (Objects.isNull(isWeb)) {
|
||||
//修改文件信息
|
||||
csWaveService.updateCsWave(fileName);
|
||||
//波形文件关联事件
|
||||
filePath = filePath.replaceAll(GeneralConstant.CFG, "").replaceAll(GeneralConstant.DAT, "");
|
||||
List<String> eventList = correlateEvents(fileInfoDto, filePath, fileName);
|
||||
if (CollectionUtil.isNotEmpty(eventList) && devModel){
|
||||
eventList.forEach(item -> {
|
||||
//波形文件解析成图片
|
||||
wavePicFeignClient.getWavePics(item);
|
||||
//同步更新r_mp_event_detail,将波形路径录入
|
||||
wavePicFeignClient.updateEventById(item);
|
||||
});
|
||||
}
|
||||
}
|
||||
redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(appFileMessage.getMsg().getName()));
|
||||
redisUtil.delete(AppRedisKey.FILE_PART.concat(appFileMessage.getMsg().getName()));
|
||||
|
||||
@@ -1,305 +0,0 @@
|
||||
package com.njcn.zlevent.utils;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
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;
|
||||
import com.njcn.csharmonic.pojo.po.CsEventUserPO;
|
||||
import com.njcn.system.api.EpdFeignClient;
|
||||
import com.njcn.user.api.AppInfoSetFeignClient;
|
||||
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.service.ICsEventUserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/9/25 16:08
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
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;
|
||||
|
||||
/**
|
||||
* 事件推送给相关用户
|
||||
* @param eventType 事件类型 1:事件 2:告警
|
||||
* @param type 等级 事件分为设备事件、暂态事件、稳态事件 告警分为Ⅰ级告警、Ⅱ级告警、Ⅲ级告警
|
||||
* @param devId 设备id
|
||||
* @param eventName 事件名称
|
||||
* @param eventTime 事件发生事件
|
||||
* @param id 事件id
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
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;
|
||||
List<String> devCodeList;
|
||||
List<String> userList = new ArrayList<>();
|
||||
List<CsEventSendMsg> csEventSendMsgList = new ArrayList<>();
|
||||
NoticeUserDto noticeUserDto = new NoticeUserDto();
|
||||
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();
|
||||
switch (type) {
|
||||
case "1":
|
||||
code = 2;
|
||||
//设备自身事件 不推送给用户,推送给业务管理
|
||||
eventUser = getEventUser(devId,false);
|
||||
if (CollectionUtil.isNotEmpty(eventUser)) {
|
||||
eventUser.forEach(item->{
|
||||
CsEventUserPO csEventUser = new CsEventUserPO();
|
||||
csEventUser.setUserId(item);
|
||||
csEventUser.setStatus(0);
|
||||
csEventUser.setEventId(id);
|
||||
result.add(csEventUser);
|
||||
});
|
||||
|
||||
users = getSendUser(eventUser,2);
|
||||
if (CollectionUtil.isNotEmpty(users)){
|
||||
for (User user : users){
|
||||
userList.add(user.getDevCode());
|
||||
}
|
||||
noticeUserDto.setPushClientId(userList);
|
||||
noticeUserDto.setTitle("设备事件");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "2":
|
||||
code = 0;
|
||||
//暂态事件
|
||||
eventUser = getEventUser(devId,true);
|
||||
if (CollectionUtil.isNotEmpty(eventUser)) {
|
||||
eventUser.forEach(item->{
|
||||
CsEventUserPO csEventUser = new CsEventUserPO();
|
||||
csEventUser.setUserId(item);
|
||||
csEventUser.setStatus(0);
|
||||
csEventUser.setEventId(id);
|
||||
result.add(csEventUser);
|
||||
});
|
||||
users = getSendUser(eventUser,0);
|
||||
if (CollectionUtil.isNotEmpty(users)){
|
||||
devCodeList = users.stream().map(User::getDevCode).distinct().collect(Collectors.toList());
|
||||
noticeUserDto.setPushClientId(devCodeList);
|
||||
noticeUserDto.setTitle("暂态事件");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "3":
|
||||
code = 1;
|
||||
//稳态事件
|
||||
eventUser = getEventUser(devId,true);
|
||||
if (CollectionUtil.isNotEmpty(eventUser)) {
|
||||
eventUser.forEach(item->{
|
||||
CsEventUserPO csEventUser = new CsEventUserPO();
|
||||
csEventUser.setUserId(item);
|
||||
csEventUser.setStatus(0);
|
||||
csEventUser.setEventId(id);
|
||||
result.add(csEventUser);
|
||||
});
|
||||
users = getSendUser(eventUser,1);
|
||||
if (CollectionUtil.isNotEmpty(users)){
|
||||
devCodeList = users.stream().map(User::getDevCode).distinct().collect(Collectors.toList());
|
||||
noticeUserDto.setPushClientId(devCodeList);
|
||||
noticeUserDto.setTitle("稳态事件");
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
code = 0;
|
||||
break;
|
||||
}
|
||||
//获取台账信息
|
||||
DevDetailDTO devDetailDto = csLedgerFeignclient.queryDevDetail(devId).getData();
|
||||
content = devDetailDto.getEngineeringName() + "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName() + "于" + eventTime.format(DatePattern.NORM_DATETIME_MS_FORMATTER) + "发生" + eventName;
|
||||
noticeUserDto.setContent(content);
|
||||
payload.setType(code);
|
||||
payload.setPath("/pages/message/message?type="+payload.getType());
|
||||
noticeUserDto.setPayload(payload);
|
||||
}
|
||||
//告警处理
|
||||
else if (eventType == 2){
|
||||
switch (type) {
|
||||
case "1":
|
||||
//Ⅰ级告警 不推送给用户,推送给业务管理
|
||||
eventUser = getEventUser(devId,false);
|
||||
if (CollectionUtil.isNotEmpty(eventUser)) {
|
||||
eventUser.forEach(item->{
|
||||
CsEventUserPO csEventUser = new CsEventUserPO();
|
||||
csEventUser.setUserId(item);
|
||||
csEventUser.setStatus(0);
|
||||
csEventUser.setEventId(id);
|
||||
result.add(csEventUser);
|
||||
});
|
||||
users = getSendUser(eventUser,3);
|
||||
if (CollectionUtil.isNotEmpty(users)){
|
||||
eventName = epdFeignClient.findByName(eventName).getData().getShowName();
|
||||
devCodeList = users.stream().map(User::getDevCode).distinct().collect(Collectors.toList());
|
||||
noticeUserDto.setPushClientId(devCodeList);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "2":
|
||||
eventName = epdFeignClient.findByName(eventName).getData().getShowName();
|
||||
case "3":
|
||||
//Ⅱ、Ⅲ级告警推送相关用户及业务管理员
|
||||
eventUser = getEventUser(devId,true);
|
||||
if (CollectionUtil.isNotEmpty(eventUser)) {
|
||||
eventUser.forEach(item->{
|
||||
CsEventUserPO csEventUser = new CsEventUserPO();
|
||||
csEventUser.setUserId(item);
|
||||
csEventUser.setStatus(0);
|
||||
csEventUser.setEventId(id);
|
||||
result.add(csEventUser);
|
||||
});
|
||||
users = getSendUser(eventUser,3);
|
||||
if (CollectionUtil.isNotEmpty(users)){
|
||||
devCodeList = users.stream().map(User::getDevCode).distinct().collect(Collectors.toList());
|
||||
noticeUserDto.setPushClientId(devCodeList);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
noticeUserDto.setTitle("告警事件");
|
||||
DevDetailDTO devDetailDto = csLedgerFeignclient.queryDevDetail(devId).getData();
|
||||
content = devDetailDto.getEngineeringName() + "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName() + "于" + eventTime.format(DatePattern.NORM_DATETIME_MS_FORMATTER) + "发生告警,告警信息:" + eventName;
|
||||
noticeUserDto.setContent(content);
|
||||
payload.setType(3);
|
||||
payload.setPath("/pages/message/message?type="+payload.getType());
|
||||
noticeUserDto.setPayload(payload);
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(noticeUserDto.getPushClientId())) {
|
||||
List<String> filteredList = noticeUserDto.getPushClientId().stream()
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(filteredList)) {
|
||||
noticeUserDto.setPushClientId(filteredList);
|
||||
sendMessageUtil.sendEventToUser(noticeUserDto);
|
||||
}
|
||||
}
|
||||
//记录推送日志
|
||||
for (User item : users) {
|
||||
CsEventSendMsg csEventSendMsg = new CsEventSendMsg();
|
||||
csEventSendMsg.setUserId(item.getId());
|
||||
csEventSendMsg.setEventId(id);
|
||||
csEventSendMsg.setSendTime(LocalDateTime.now());
|
||||
if (Objects.isNull(item.getDevCode())){
|
||||
csEventSendMsg.setStatus(0);
|
||||
csEventSendMsg.setRemark("用户设备识别码为空");
|
||||
} else {
|
||||
csEventSendMsg.setDevCode(item.getDevCode());
|
||||
csEventSendMsg.setStatus(1);
|
||||
}
|
||||
csEventSendMsgList.add(csEventSendMsg);
|
||||
}
|
||||
eventLogsFeignClient.addLogs(csEventSendMsgList);
|
||||
//事件用户关系入库
|
||||
if (CollectionUtil.isNotEmpty(result)){
|
||||
csEventUserService.saveBatch(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有需要推送的用户id
|
||||
*/
|
||||
public List<String> getEventUser(String devId,boolean isAdmin) {
|
||||
List<User> adminUser = appUserFeignClient.getAdminInfo().getData();
|
||||
List<String> adminList = adminUser.stream().map(User::getId).collect(Collectors.toList());
|
||||
if (isAdmin) {
|
||||
List<String> list = csDeviceUserFeignClient.findUserById(devId).getData();
|
||||
adminList.addAll(list);
|
||||
}
|
||||
return adminList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取所有打开推送的用户信息
|
||||
*/
|
||||
public List<User> getSendUser(List<String> userList,Integer type) {
|
||||
List<User> users = new ArrayList<>();
|
||||
List<String> result = new ArrayList<>();
|
||||
List<AppInfoSet> appInfoSet = appInfoSetFeignClient.getListById(userList).getData();
|
||||
|
||||
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 2:
|
||||
result = appInfoSet.stream()
|
||||
.filter(person -> person.getRunInfo() == 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(result)){
|
||||
users = userFeignClient.appuserByIdList(result).getData();
|
||||
}
|
||||
return users;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -42,7 +42,7 @@ logging:
|
||||
config: http://@nacos.url@/nacos/v1/cs/configs?tenant=@nacos.namespace@&group=DEFAULT_GROUP&dataId=logback.xml
|
||||
level:
|
||||
root: info
|
||||
|
||||
com.njcn.middle.rocket.handler.EnhanceConsumerMessageHandler: ERROR
|
||||
|
||||
#mybatis配置信息
|
||||
mybatis-plus:
|
||||
|
||||
23
pom.xml
23
pom.xml
@@ -34,11 +34,17 @@
|
||||
|
||||
<!--103本地-->
|
||||
<!-- <middle.server.url>192.168.1.103</middle.server.url>-->
|
||||
<!-- <service.server.url>192.168.1.126</service.server.url>-->
|
||||
<!-- <service.server.url>192.168.2.126</service.server.url>-->
|
||||
<!-- <docker.server.url>192.168.1.103</docker.server.url>-->
|
||||
<!-- <nacos.url>${middle.server.url}:18848</nacos.url>-->
|
||||
<!-- <nacos.namespace>72972c43-3c20-4452-a261-66624e17da97</nacos.namespace>-->
|
||||
|
||||
<!-- <middle.server.url>192.168.1.162</middle.server.url>-->
|
||||
<!-- <service.server.url>192.168.1.162</service.server.url>-->
|
||||
<!-- <docker.server.url>192.168.1.162</docker.server.url>-->
|
||||
<!-- <nacos.url>${middle.server.url}:18848</nacos.url>-->
|
||||
<!-- <nacos.namespace></nacos.namespace>-->
|
||||
|
||||
<!--103线上-->
|
||||
<middle.server.url>192.168.1.103</middle.server.url>
|
||||
<service.server.url>192.168.1.103</service.server.url>
|
||||
@@ -61,11 +67,24 @@
|
||||
|
||||
<!--102-->
|
||||
<!-- <middle.server.url>192.168.1.102</middle.server.url>-->
|
||||
<!-- <service.server.url>127.0.0.1</service.server.url>-->
|
||||
<!-- <service.server.url>192.168.1.126</service.server.url>-->
|
||||
<!-- <docker.server.url>192.168.1.102</docker.server.url>-->
|
||||
<!-- <nacos.url>${middle.server.url}:18848</nacos.url>-->
|
||||
<!-- <nacos.namespace>d99572a5-415e-480b-bb92-30f05c2f6d93</nacos.namespace>-->
|
||||
|
||||
|
||||
<!-- <middle.server.url>192.168.1.102</middle.server.url>-->
|
||||
<!-- <service.server.url>192.168.1.126</service.server.url>-->
|
||||
<!-- <docker.server.url>192.168.1.102</docker.server.url>-->
|
||||
<!-- <nacos.url>${middle.server.url}:18848</nacos.url>-->
|
||||
<!-- <nacos.namespace>c208a65e-1578-4372-b7c0-97fecd323fe6</nacos.namespace>-->
|
||||
|
||||
<!-- <middle.server.url>192.168.1.102</middle.server.url>-->
|
||||
<!-- <service.server.url>192.168.1.102</service.server.url>-->
|
||||
<!-- <docker.server.url>192.168.1.102</docker.server.url>-->
|
||||
<!-- <nacos.url>${middle.server.url}:18848</nacos.url>-->
|
||||
<!-- <nacos.namespace>c208a65e-1578-4372-b7c0-97fecd323fe6</nacos.namespace>-->
|
||||
|
||||
<!-- <middle.server.url>192.168.1.27</middle.server.url>-->
|
||||
<!-- <service.server.url>127.0.0.1</service.server.url>-->
|
||||
<!-- <docker.server.url>192.168.1.27</docker.server.url>-->
|
||||
|
||||
Reference in New Issue
Block a user