1、新增云协议设备台账录入功能;
2、新增云协议设备实时数据请求功能
This commit is contained in:
@@ -7,6 +7,7 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.csdevice.pojo.vo.DataGroupEventVO;
|
||||
import com.njcn.csharmonic.param.CldEventParam;
|
||||
import com.njcn.csharmonic.param.CsEventUserQueryPage;
|
||||
import com.njcn.csharmonic.param.CsEventUserQueryParam;
|
||||
import com.njcn.csharmonic.param.DataParam;
|
||||
@@ -42,7 +43,6 @@ public class CsEventController extends BaseController {
|
||||
|
||||
private final CsEventPOService csEventPOService;
|
||||
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/queryEventList")
|
||||
@ApiOperation("暂降事件列表查询")
|
||||
@@ -53,7 +53,6 @@ public class CsEventController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/pageQueryByLineId")
|
||||
@ApiOperation("根据监测点分页查询暂降事件")
|
||||
@@ -121,4 +120,14 @@ public class CsEventController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/addCldEvent")
|
||||
@ApiOperation("新增云前置事件")
|
||||
@ApiImplicitParam(name = "param", value = "事件信息", required = true)
|
||||
public HttpResult<String> addCldEvent(@RequestBody CldEventParam param) {
|
||||
String methodDescribe = getMethodDescribe("addCldEvent");
|
||||
csEventPOService.addCldEvent(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -70,4 +70,14 @@ public class RealDataController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/getCldBaseRealData")
|
||||
@ApiOperation("获取云前置基础实时数据")
|
||||
@ApiImplicitParam(name = "lineId", value = "监测点id")
|
||||
public HttpResult<String> getCldBaseRealData(@RequestParam("lineId") String lineId) {
|
||||
String methodDescribe = getMethodDescribe("getCldBaseRealData");
|
||||
realDataService.getCldBaseRealData(lineId);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, "平台下发指令成功", methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.njcn.csharmonic.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.csdevice.pojo.vo.DataGroupEventVO;
|
||||
import com.njcn.csharmonic.param.CldEventParam;
|
||||
import com.njcn.csharmonic.param.CsEventUserQueryPage;
|
||||
import com.njcn.csharmonic.param.CsEventUserQueryParam;
|
||||
import com.njcn.csharmonic.param.DataParam;
|
||||
import com.njcn.csharmonic.pojo.po.CsEventPO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.csharmonic.pojo.vo.CsEventVO;
|
||||
import com.njcn.csharmonic.pojo.vo.EventDetailVO;
|
||||
import com.njcn.event.file.pojo.dto.WaveDataDTO;
|
||||
@@ -56,4 +57,6 @@ public interface CsEventPOService extends IService<CsEventPO>{
|
||||
|
||||
List<CsEventPO> queryByModelId(DataParam param);
|
||||
|
||||
void addCldEvent(CldEventParam param);
|
||||
|
||||
}
|
||||
|
||||
@@ -17,4 +17,6 @@ public interface RealDataService {
|
||||
*/
|
||||
boolean getHarmRealData(String lineId,Integer target);
|
||||
|
||||
void getCldBaseRealData(String lineId);
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,9 @@ import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
||||
import com.njcn.csdevice.pojo.dto.DevDetailDTO;
|
||||
import com.njcn.csdevice.pojo.po.CsLinePO;
|
||||
import com.njcn.csdevice.pojo.vo.DataGroupEventVO;
|
||||
import com.njcn.csharmonic.enums.CsHarmonicResponseEnum;
|
||||
import com.njcn.csharmonic.mapper.CsEventPOMapper;
|
||||
import com.njcn.csharmonic.param.CldEventParam;
|
||||
import com.njcn.csharmonic.param.CsEventUserQueryPage;
|
||||
import com.njcn.csharmonic.param.CsEventUserQueryParam;
|
||||
import com.njcn.csharmonic.param.DataParam;
|
||||
@@ -57,6 +59,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@@ -74,21 +77,13 @@ import java.util.stream.Stream;
|
||||
public class CsEventPOServiceImpl extends ServiceImpl<CsEventPOMapper, CsEventPO> implements CsEventPOService {
|
||||
|
||||
private final EvtDataService evtDataService;
|
||||
|
||||
private final FileStorageUtil fileStorageUtil;
|
||||
|
||||
private final WaveFileComponent waveFileComponent;
|
||||
|
||||
private final CsLineFeignClient csLineFeignClient;
|
||||
|
||||
private final CsLedgerFeignClient csLedgerFeignClient;
|
||||
|
||||
private final EpdFeignClient epdFeignClient;
|
||||
|
||||
private final CsEventUserPOService csEventUserPOService;
|
||||
|
||||
private final EleEvtFeignClient eleEvtFeignClient;
|
||||
|
||||
private final WavePicComponent wavePicComponent;
|
||||
private final MinIossProperties minIossProperties;
|
||||
|
||||
@@ -245,6 +240,71 @@ public class CsEventPOServiceImpl extends ServiceImpl<CsEventPOMapper, CsEventPO
|
||||
return pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCldEvent(CldEventParam param) {
|
||||
//校验是新增时间还是更新文件信息
|
||||
LambdaQueryWrapper<CsEventPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(CsEventPO::getLineId,param.getMonitorId()).eq(CsEventPO::getStartTime,param.getStartTime());
|
||||
CsEventPO event = this.getOne(lambdaQueryWrapper);
|
||||
if (Objects.isNull(event)) {
|
||||
//首次录入
|
||||
//根据监测点获取装置信息
|
||||
CsLinePO po = csLineFeignClient.getById(param.getMonitorId()).getData();
|
||||
CsEventPO eventPo = new CsEventPO();
|
||||
eventPo.setLineId(param.getMonitorId());
|
||||
eventPo.setDeviceId(po.getDeviceId());
|
||||
LocalDateTime time = LocalDateTime.parse(param.getStartTime(), DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_MS_PATTERN));
|
||||
eventPo.setStartTime(time);
|
||||
eventPo.setTag(getTag(param.getEventType()));
|
||||
eventPo.setType(0);
|
||||
eventPo.setClDid(Integer.parseInt(param.getMonitorId().substring(param.getMonitorId().length() - 1)));
|
||||
eventPo.setLevel(2);
|
||||
eventPo.setProcess(4);
|
||||
eventPo.setPersistTime(param.getDuration()/1000);
|
||||
eventPo.setAmplitude(param.getAmplitude());
|
||||
this.baseMapper.insert(eventPo);
|
||||
} else {
|
||||
if (StrUtil.isNotBlank(param.getWavePathCfg()) && StrUtil.isNotBlank(param.getWavePathDat())) {
|
||||
//更新文件信息
|
||||
//先校验两份文件的名称是否一致
|
||||
String cfgFileName = param.getWavePathCfg().split("\\.")[0];
|
||||
String datFileName = param.getWavePathDat().split("\\.")[0];
|
||||
if (!Objects.equals(cfgFileName, datFileName)) {
|
||||
throw new BusinessException(CsHarmonicResponseEnum.EVENT_FILE_NOT_SAME);
|
||||
}
|
||||
this.lambdaUpdate()
|
||||
.eq(CsEventPO::getLineId,param.getMonitorId())
|
||||
.eq(CsEventPO::getStartTime,param.getStartTime())
|
||||
.set(CsEventPO::getWavePath,cfgFileName)
|
||||
.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getTag(Integer type) {
|
||||
String tag;
|
||||
switch (type) {
|
||||
case 1:
|
||||
tag = "Evt_Sys_DipStr";
|
||||
break;
|
||||
case 2:
|
||||
tag = "Evt_Sys_SwlStr";
|
||||
break;
|
||||
case 3:
|
||||
tag = "Evt_Sys_IntrStr";
|
||||
break;
|
||||
case 4:
|
||||
tag = "Transient";
|
||||
break;
|
||||
default:
|
||||
tag = "Un_Know";
|
||||
break;
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return WaveDataDTO
|
||||
|
||||
@@ -3,42 +3,37 @@ package com.njcn.csharmonic.service.impl;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.common.pojo.constant.LogInfo;
|
||||
import com.njcn.csdevice.api.CsLedgerFeignClient;
|
||||
import com.njcn.csdevice.constant.DataParam;
|
||||
import com.njcn.csdevice.pojo.dto.DevDetailDTO;
|
||||
|
||||
import com.njcn.csdevice.pojo.vo.CsLedgerVO;
|
||||
import com.njcn.csharmonic.mapper.CsEventPOMapper;
|
||||
import com.njcn.csharmonic.mapper.CsEventUserPOMapper;
|
||||
import com.njcn.csharmonic.param.CsEventUserQueryPage;
|
||||
import com.njcn.csharmonic.param.CsEventUserQueryParam;
|
||||
import com.njcn.csharmonic.pojo.po.CsEventUserPO;
|
||||
import com.njcn.csharmonic.pojo.vo.EventDetailVO;
|
||||
import com.njcn.csharmonic.service.CsEventPOService;
|
||||
import com.njcn.csharmonic.service.CsEventUserPOService;
|
||||
import com.njcn.influx.pojo.dto.EventDataSetDTO;
|
||||
import com.njcn.influx.service.EvtDataService;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.api.EleEvtFeignClient;
|
||||
import com.njcn.system.api.EpdFeignClient;
|
||||
|
||||
import com.njcn.system.pojo.po.EleEpdPqd;
|
||||
import com.njcn.system.pojo.po.EleEvtParm;
|
||||
import com.njcn.user.enums.AppRoleEnum;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.csharmonic.pojo.po.CsEventUserPO;
|
||||
import com.njcn.csharmonic.mapper.CsEventUserPOMapper;
|
||||
import com.njcn.csharmonic.service.CsEventUserPOService;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* Description:
|
||||
|
||||
@@ -1,22 +1,30 @@
|
||||
package com.njcn.csharmonic.service.impl;
|
||||
|
||||
import com.alibaba.cloud.commons.lang.StringUtils;
|
||||
import com.njcn.access.api.AskDeviceDataFeignClient;
|
||||
import com.njcn.access.utils.MqttUtil;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.api.CsLineFeignClient;
|
||||
import com.njcn.csdevice.api.DataSetFeignClient;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
import com.njcn.csdevice.pojo.po.CsDataSet;
|
||||
import com.njcn.csdevice.pojo.po.CsLinePO;
|
||||
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
|
||||
import com.njcn.csharmonic.service.RealDataService;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author xuyang
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class RealDataServiceImpl implements RealDataService {
|
||||
@@ -24,6 +32,7 @@ public class RealDataServiceImpl implements RealDataService {
|
||||
private final CsLineFeignClient csLineFeignClient;
|
||||
private final DataSetFeignClient dataSetFeignClient;
|
||||
private final AskDeviceDataFeignClient askDeviceDataFeignClient;
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
private final RedisUtil redisUtil;
|
||||
private final MqttUtil mqttUtil;
|
||||
|
||||
@@ -93,4 +102,116 @@ public class RealDataServiceImpl implements RealDataService {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getCldBaseRealData(String lineId) {
|
||||
try {
|
||||
// 参数校验
|
||||
if (StringUtils.isBlank(lineId) || lineId.length() <= 1) {
|
||||
throw new BusinessException("线路ID格式错误");
|
||||
}
|
||||
String nDid = lineId.substring(0, lineId.length() - 1);
|
||||
CsEquipmentDeliveryVO csEquipmentDeliveryVO = equipmentFeignClient.queryEquipmentByndid(nDid).getData();
|
||||
if (Objects.isNull(csEquipmentDeliveryVO)) {
|
||||
log.warn("未找到对应的设备信息,nDid: {}", nDid);
|
||||
return;
|
||||
}
|
||||
// 检查设备运行状态
|
||||
if (csEquipmentDeliveryVO.getRunStatus() == 1) {
|
||||
throw new BusinessException("装置离线,无法获取实时数据");
|
||||
}
|
||||
// 请求设备数据
|
||||
askDeviceDataFeignClient.askCldRealData(csEquipmentDeliveryVO.getId(), lineId);
|
||||
// 更新Redis中的用户集合 - 使用工具方法消除重复代码
|
||||
updateRedisUserSet("rtDataUserId:" + lineId, RequestUtil.getUserIndex(), 600L);
|
||||
updateRedisUserSet("cldRtDataOverTime:" + lineId, RequestUtil.getUserIndex(), 5L);
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
log.error("获取CLD基础实时数据失败,lineId: {}", lineId, e);
|
||||
throw new BusinessException("获取实时数据失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新Redis中的用户集合
|
||||
*/
|
||||
private void updateRedisUserSet(String redisKey, String userIndex, Long expireSeconds) {
|
||||
try {
|
||||
Object redisObject = redisUtil.getObjectByKey(redisKey);
|
||||
Set<String> userSet = convertObjectToSetSafe(redisObject);
|
||||
userSet.add(userIndex);
|
||||
redisUtil.saveByKeyWithExpire(redisKey, userSet, expireSeconds);
|
||||
} catch (Exception e) {
|
||||
log.error("更新Redis用户集合失败,key: {}", redisKey, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全的对象到Set转换方法
|
||||
*/
|
||||
private Set<String> convertObjectToSetSafe(Object obj) {
|
||||
if (obj == null) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
if (obj instanceof Set) {
|
||||
// 类型安全的转换
|
||||
Set<?> rawSet = (Set<?>) obj;
|
||||
return rawSet.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.toSet());
|
||||
} else if (obj instanceof Collection) {
|
||||
return ((Collection<?>) obj).stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.toSet());
|
||||
} else {
|
||||
log.warn("Redis中的对象类型不是Set或Collection: {}", obj.getClass().getName());
|
||||
return new HashSet<>();
|
||||
}
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void getCldBaseRealData(String lineId) {
|
||||
// String nDid = lineId.substring(0, lineId.length() - 1);
|
||||
// CsEquipmentDeliveryVO csEquipmentDeliveryVO = equipmentFeignClient.queryEquipmentByndid(nDid).getData();
|
||||
// if (Objects.nonNull(csEquipmentDeliveryVO)) {
|
||||
// if (csEquipmentDeliveryVO.getRunStatus() == 1) {
|
||||
// throw new BusinessException("装置离线");
|
||||
// }
|
||||
// askDeviceDataFeignClient.askCldRealData(csEquipmentDeliveryVO.getId(),lineId);
|
||||
//
|
||||
// Object object1 = redisUtil.getObjectByKey("rtDataUserId:"+lineId);
|
||||
// Set<String> users1;
|
||||
// if (Objects.isNull(object1)) {
|
||||
// users1 = new HashSet<>();
|
||||
// } else {
|
||||
// users1 = convertObjectToSet(object1);
|
||||
// }
|
||||
// users1.add(RequestUtil.getUserIndex());
|
||||
// redisUtil.saveByKeyWithExpire("rtDataUserId:"+lineId, users1,600L);
|
||||
//
|
||||
// Object object2 = redisUtil.getObjectByKey("cldRtDataOverTime:"+lineId);
|
||||
// Set<String> users2;
|
||||
// if (Objects.isNull(object2)) {
|
||||
// users2 = new HashSet<>();
|
||||
// } else {
|
||||
// users2 = convertObjectToSet(object2);
|
||||
// }
|
||||
// users2.add(RequestUtil.getUserIndex());
|
||||
// redisUtil.saveByKeyWithExpire("cldRtDataOverTime:"+lineId, users2,5L);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public Set<String> convertObjectToSet(Object obj) {
|
||||
// if (obj instanceof Collection) {
|
||||
// return ((Collection<?>) obj).stream()
|
||||
// .filter(Objects::nonNull)
|
||||
// .map(Object::toString)
|
||||
// .collect(Collectors.toSet());
|
||||
// }
|
||||
// return Collections.emptySet();
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user