便携式设备接入代码兼容
This commit is contained in:
@@ -19,6 +19,7 @@ public enum AccessResponseEnum {
|
||||
MISSING_CLIENT("A0302","设备客户端不在线!"),
|
||||
MODEL_REPEAT("A0302", "模板存在,请勿重复录入!"),
|
||||
MODEL_NO_FIND("A0302", "模板不存在,请先录入模板数据!"),
|
||||
MODEL_ERROR("A0302", "模板未找到,生成监测点失败!"),
|
||||
|
||||
DICT_ANALYSIS_ERROR("A0303","字典解析错误!"),
|
||||
MODEL_ANALYSIS_ERROR("A0303","模板解析错误!"),
|
||||
@@ -28,6 +29,7 @@ public enum AccessResponseEnum {
|
||||
DEV_MODEL_NOT_FIND("A0303","装置型号未找到!"),
|
||||
DEV_IS_NOT_ZL("A0303","注册装置不是直连装置!"),
|
||||
DEV_IS_NOT_WG("A0303","注册装置不是网关!"),
|
||||
DEV_IS_NOT_PORTABLE("A0303","注册装置不是便携式设备!"),
|
||||
|
||||
REGISTER_RESPONSE_ERROR("A0304","装置注册,装置侧应答失败!"),
|
||||
ACCESS_RESPONSE_ERROR("A0304","装置注册,装置侧应答失败!"),
|
||||
|
||||
@@ -78,4 +78,29 @@ public class CsDeviceController extends BaseController {
|
||||
csDeviceService.resetFactory(nDid);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/wlRegister")
|
||||
@ApiOperation("便携式设备注册")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "nDid", value = "设备识别码", required = true)
|
||||
})
|
||||
@ReturnMsg
|
||||
public HttpResult<String> wlRegister(@RequestParam String nDid){
|
||||
String result = csDeviceService.wlDevRegister(nDid);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, "设备注册成功!");
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/wlAccess")
|
||||
@ApiOperation("便携式设备接入")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "nDid", value = "设备识别码", required = true)
|
||||
})
|
||||
@ReturnMsg
|
||||
public HttpResult<String> wlAccess(@RequestParam String nDid){
|
||||
csDeviceService.wlAccess(nDid);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, "success", "设备接入成功!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -56,7 +56,6 @@ import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -225,6 +224,7 @@ public class MqttMessageHandler {
|
||||
@MqttSubscribe(value = "/Pfm/DevRsp/{version}/{edgeId}",qos = 1)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void devModelOperation(String topic, MqttMessage message, @NamedValue("version") String version, @NamedValue("edgeId") String nDid, @Payload String payload){
|
||||
log.info("收到当前设备所用模板响应--->" + nDid);
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
try{
|
||||
logDto.setUserName(RequestUtil.getUsername());
|
||||
|
||||
@@ -26,4 +26,10 @@ public interface ICsDataSetService extends IService<CsDataSet> {
|
||||
*/
|
||||
void addList(List<CsDataSet> list);
|
||||
|
||||
/**
|
||||
* 根据模板id获取模板的数据集
|
||||
* @param modelId 模板ID
|
||||
*/
|
||||
List<CsDataSet> getDataSetData(String modelId);
|
||||
|
||||
}
|
||||
|
||||
@@ -36,4 +36,16 @@ public interface ICsDeviceService {
|
||||
* @param nDid
|
||||
*/
|
||||
void resetFactory(String nDid);
|
||||
|
||||
/**
|
||||
* 直连设备注册
|
||||
* @param nDid 设备识别码
|
||||
*/
|
||||
String wlDevRegister(String nDid);
|
||||
|
||||
/**
|
||||
* 直连设备接入
|
||||
* @param nDid 设备识别码
|
||||
*/
|
||||
void wlAccess(String nDid);
|
||||
}
|
||||
|
||||
@@ -28,4 +28,9 @@ public class CsDataSetServiceImpl extends ServiceImpl<CsDataSetMapper, CsDataSet
|
||||
public void addList(List<CsDataSet> list) {
|
||||
this.saveBatch(list,1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CsDataSet> getDataSetData(String modelId) {
|
||||
return this.lambdaQuery().eq(CsDataSet::getPid, modelId).list();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,15 +19,14 @@ import com.njcn.csdevice.api.DevModelFeignClient;
|
||||
import com.njcn.csdevice.pojo.po.*;
|
||||
import com.njcn.oss.constant.OssPath;
|
||||
import com.njcn.oss.utils.FileStorageUtil;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.api.EleEvtFeignClient;
|
||||
import com.njcn.system.api.EleWaveFeignClient;
|
||||
import com.njcn.system.api.EpdFeignClient;
|
||||
import com.njcn.system.api.*;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.enums.DicTreeEnum;
|
||||
import com.njcn.system.pojo.param.CsWaveParam;
|
||||
import com.njcn.system.pojo.param.EleEpdPqdParam;
|
||||
import com.njcn.system.pojo.param.EleEvtParam;
|
||||
import com.njcn.system.pojo.po.EleEpdPqd;
|
||||
import com.njcn.system.pojo.vo.DictTreeVO;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -78,6 +77,8 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
|
||||
private final EleWaveFeignClient waveFeignClient;
|
||||
|
||||
private final DictTreeFeignClient dictTreeFeignClient;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public void addModel(MultipartFile file) {
|
||||
@@ -96,7 +97,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
String filePath = fileStorageUtil.uploadMultipart(file, OssPath.DEV_MODEL + templateDto.getDevType() + "_");
|
||||
//1.录入cs_dev_model表,记录装置型号和模板记录
|
||||
CsDevModelPO csDevModelPo = addCsDevModel(templateDto,filePath);
|
||||
//2.录入数据集、详细数据(主设备、模块、监测设备)
|
||||
//2.录入数据集、详细数据(主设备、模块、监测设备、便携式设备...)
|
||||
analysisDataSet(templateDto,csDevModelPo.getId());
|
||||
//3.录入监测点模板表(记录当前模板有几个监测点,治理类型的模板目前规定1个监测点,电能质量模板根据逻辑子设备来)
|
||||
addCsLineModel(templateDto,csDevModelPo.getId());
|
||||
@@ -267,7 +268,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
eleEvtParam.setPid(dictId);
|
||||
eleEvtParam.setData(param.getData());
|
||||
eleEvtParam.setName(param.getName());
|
||||
String showName = dataSetName(param.getName());
|
||||
String showName = dataSetName(param.getName(),null);
|
||||
if (Objects.isNull(showName)){
|
||||
eleEvtParam.setShowName(param.getName());
|
||||
} else {
|
||||
@@ -647,7 +648,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
CsWaveParam csWaveParam = new CsWaveParam();
|
||||
csWaveParam.setPid(dictId);
|
||||
csWaveParam.setName(param.getName());
|
||||
String showName = dataSetName(param.getName());
|
||||
String showName = dataSetName(param.getName(),null);
|
||||
if (Objects.isNull(showName)){
|
||||
csWaveParam.setShowName(param.getName());
|
||||
} else {
|
||||
@@ -678,6 +679,12 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
List<CsDataSet> setList = new ArrayList<>();
|
||||
List<CsDataArray> arrayList = new ArrayList<>();
|
||||
List<DataSetDto> dataSetList = templateDto.getDataSet();
|
||||
String devType = templateDto.getDevType();
|
||||
DictTreeVO dictTreeVO = dictTreeFeignClient.queryByCode(devType).getData();
|
||||
if (Objects.isNull(dictTreeVO)){
|
||||
throw new BusinessException(AccessResponseEnum.DEV_TYPE_NOT_FIND);
|
||||
}
|
||||
String code = dictTreeFeignClient.queryById(dictTreeVO.getPid()).getData().getCode();
|
||||
//逻辑设备录入
|
||||
if (CollectionUtil.isNotEmpty(dataSetList)){
|
||||
dataSetList.forEach(item1->{
|
||||
@@ -686,7 +693,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
CsDataSet.setId(id);
|
||||
CsDataSet.setPid(pId);
|
||||
CsDataSet.setName(item1.getName());
|
||||
CsDataSet.setAnotherName(dataSetName(item1.getName()));
|
||||
CsDataSet.setAnotherName(dataSetName(item1.getName(),code));
|
||||
CsDataSet.setIdx(item1.getIdx());
|
||||
CsDataSet.setPeriod(item1.getPeriod());
|
||||
CsDataSet.setStoreFlag(item1.getStoreFlag());
|
||||
@@ -721,7 +728,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
CsDataSet.setId(id);
|
||||
CsDataSet.setPid(pId);
|
||||
CsDataSet.setName(item4.getName());
|
||||
CsDataSet.setAnotherName(dataSetName(item4.getName()));
|
||||
CsDataSet.setAnotherName(dataSetName(item4.getName(),code));
|
||||
CsDataSet.setIdx(item4.getIdx());
|
||||
CsDataSet.setPeriod(item4.getPeriod());
|
||||
CsDataSet.setStoreFlag(item4.getStoreFlag());
|
||||
@@ -1024,7 +1031,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
/**
|
||||
* 数据集名称调整
|
||||
*/
|
||||
public String dataSetName(String name){
|
||||
public String dataSetName(String name,String code){
|
||||
String showName = null;
|
||||
switch (name) {
|
||||
//数据集
|
||||
@@ -1056,10 +1063,18 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
showName = "APF模块8数据";
|
||||
break;
|
||||
case "Ds$Pqd$Stat$01":
|
||||
showName = "电网侧数据";
|
||||
if (Objects.isNull(code)){
|
||||
showName = "电网侧数据";
|
||||
} else if (Objects.equals(code, DicDataEnum.PORTABLE.getCode())){
|
||||
showName = "监测1路数据";
|
||||
}
|
||||
break;
|
||||
case "Ds$Pqd$Stat$02":
|
||||
showName = "负载侧数据";
|
||||
if (Objects.isNull(code)){
|
||||
showName = "负载侧数据";
|
||||
} else if (Objects.equals(code, DicDataEnum.PORTABLE.getCode())){
|
||||
showName = "监测2路数据";
|
||||
}
|
||||
break;
|
||||
//波形参数名称
|
||||
case "Wave_Param_Position":
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.njcn.access.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@@ -13,11 +12,9 @@ import com.njcn.access.enums.TypeEnum;
|
||||
import com.njcn.access.param.DevAccessParam;
|
||||
import com.njcn.access.pojo.RspDataDto;
|
||||
import com.njcn.access.pojo.dto.AccessDto;
|
||||
import com.njcn.access.pojo.dto.AskDataDto;
|
||||
import com.njcn.access.pojo.dto.CsModelDto;
|
||||
import com.njcn.access.pojo.dto.ReqAndResDto;
|
||||
import com.njcn.access.pojo.param.DeviceStatusParam;
|
||||
import com.njcn.access.pojo.po.CsSoftInfoPO;
|
||||
import com.njcn.access.service.*;
|
||||
import com.njcn.access.utils.MqttUtil;
|
||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||
@@ -40,13 +37,9 @@ import com.njcn.web.utils.RequestUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -101,6 +94,8 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
|
||||
private final CsDeviceUserPOService csDeviceUserPOService;
|
||||
|
||||
private final ICsDataSetService csDataSetService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public void devRegister(String nDid,Integer type) {
|
||||
@@ -356,6 +351,143 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public String wlDevRegister(String nDid) {
|
||||
try {
|
||||
// 设备状态判断
|
||||
checkDeviceStatus(nDid);
|
||||
// 询问设备支持的主题信息,并将支持的主题入库
|
||||
askAndStoreTopics(nDid);
|
||||
// MQTT询问装置用的模板,并判断库中是否存在模板
|
||||
checkDeviceModel(nDid);
|
||||
// 根据模板接入设备
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName(RequestUtil.getUserNickname());
|
||||
logDto.setLoginName(RequestUtil.getUsername());
|
||||
logDto.setOperate("设备"+nDid+"注册");
|
||||
logDto.setResult(1);
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
//获取版本
|
||||
String version = csTopicService.getVersion(nDid);
|
||||
CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(nDid).getData();
|
||||
List<CsLinePO> csLinePoList = new ArrayList<>();
|
||||
//1.根据模板获取监测点个数,插入监测点表
|
||||
Thread.sleep(1000);
|
||||
List<CsModelDto> modelList = objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + nDid));
|
||||
if (CollUtil.isEmpty(modelList)){
|
||||
throwExceptionAndLog(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.setDeviceId(vo.getId());
|
||||
csLinePoList.add(po);
|
||||
});
|
||||
csLineService.saveBatch(csLinePoList);
|
||||
//2.生成装置和模板的关系表
|
||||
CsDevModelRelationAddParm csDevModelRelationAddParm = new CsDevModelRelationAddParm();
|
||||
csDevModelRelationAddParm.setDevId(vo.getId());
|
||||
csDevModelRelationAddParm.setModelId(modelList.get(0).getModelId());
|
||||
csDevModelRelationAddParm.setDid(modelList.get(0).getDid());
|
||||
csDevModelRelationService.addDevModelRelation(csDevModelRelationAddParm);
|
||||
//3.修改装置状态为注册状态
|
||||
csEquipmentDeliveryService.updateStatusBynDid(nDid, AccessEnum.REGISTERED.getCode());
|
||||
//4.发起自动接入请求
|
||||
devAccess(nDid,version);
|
||||
//5.存储日志
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
//6.存储设备调试日志表
|
||||
CsEquipmentProcessPO csEquipmentProcess = new CsEquipmentProcessPO();
|
||||
csEquipmentProcess.setDevId(nDid);
|
||||
csEquipmentProcess.setOperator(RequestUtil.getUserIndex());
|
||||
csEquipmentProcess.setStartTime(LocalDateTime.now());
|
||||
csEquipmentProcess.setEndTime(LocalDateTime.now());
|
||||
csEquipmentProcess.setProcess(4);
|
||||
csEquipmentProcess.setStatus(1);
|
||||
processFeignClient.add(csEquipmentProcess);
|
||||
//7.删除redis监测点模板信息
|
||||
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
||||
redisUtil.delete(AppRedisKey.LINE + nDid);
|
||||
} catch (Exception e) {
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(e.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(CommonResponseEnum.FAIL);
|
||||
}
|
||||
return "success";
|
||||
} catch (BusinessException e) {
|
||||
return e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void wlAccess(String nDid) {
|
||||
//设备状态判断
|
||||
checkDeviceStatus(nDid);
|
||||
//获取版本
|
||||
String version = csTopicService.getVersion(nDid);
|
||||
//发起接入请求
|
||||
this.devAccess(nDid,version);
|
||||
}
|
||||
|
||||
private void checkDeviceStatus(String nDid) {
|
||||
DeviceLogDTO logDto = createLogDto("当前设备"+nDid+"状态判断");
|
||||
CsEquipmentDeliveryVO csEquipmentDeliveryVO = csEquipmentDeliveryService.queryEquipmentBynDid(nDid);
|
||||
if (Objects.isNull(csEquipmentDeliveryVO.getNdid())) {
|
||||
throwExceptionAndLog(AccessResponseEnum.NDID_NO_FIND, logDto);
|
||||
}
|
||||
SysDicTreePO sysDicTreePo = dictTreeFeignClient.queryById(csEquipmentDeliveryVO.getDevType()).getData();
|
||||
if (Objects.isNull(sysDicTreePo)) {
|
||||
throwExceptionAndLog(AccessResponseEnum.DEV_NOT_FIND, logDto);
|
||||
}
|
||||
String code = sysDicTreePo.getCode();
|
||||
if (!Objects.equals(code, DicDataEnum.PORTABLE.getCode())) {
|
||||
throwExceptionAndLog(AccessResponseEnum.DEV_IS_NOT_PORTABLE, logDto);
|
||||
}
|
||||
if (!mqttUtil.judgeClientOnline("NJCN-" + nDid.substring(nDid.length() - 6))) {
|
||||
throwExceptionAndLog(AccessResponseEnum.MISSING_CLIENT, logDto);
|
||||
}
|
||||
}
|
||||
|
||||
private void askAndStoreTopics(String nDid) {
|
||||
// 询问设备支持的主题信息
|
||||
this.askTopic(nDid);
|
||||
}
|
||||
|
||||
private void checkDeviceModel(String nDid) {
|
||||
DeviceLogDTO logDto = createLogDto("MQTT询问装置用的模板,并判断库中是否存在模板");
|
||||
CsEquipmentDeliveryVO csEquipmentDeliveryVO = csEquipmentDeliveryService.queryEquipmentBynDid(nDid);
|
||||
SysDicTreePO dictData = dictTreeFeignClient.queryById(csEquipmentDeliveryVO.getDevModel()).getData();
|
||||
if (Objects.isNull(dictData)) {
|
||||
throwExceptionAndLog(AccessResponseEnum.DEV_MODEL_NOT_FIND, logDto);
|
||||
}
|
||||
String devModel = dictData.getCode();
|
||||
zhiLianRegister(nDid,"PQV-500");
|
||||
}
|
||||
|
||||
private DeviceLogDTO createLogDto(String operate) {
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName(RequestUtil.getUserNickname());
|
||||
logDto.setLoginName(RequestUtil.getUsername());
|
||||
logDto.setOperate(operate);
|
||||
logDto.setResult(1);
|
||||
return logDto;
|
||||
}
|
||||
|
||||
private void throwExceptionAndLog(AccessResponseEnum responseEnum, DeviceLogDTO logDto) {
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(responseEnum.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(responseEnum);
|
||||
}
|
||||
|
||||
public void devAccess(String nDid,String version) {
|
||||
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
|
||||
reqAndResParam.setMid(1);
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.njcn.access.pojo.dto.ReqAndResDto;
|
||||
import com.njcn.access.pojo.dto.mqtt.MqttClientDto;
|
||||
import com.njcn.access.service.ICsEquipmentDeliveryService;
|
||||
import com.njcn.access.service.impl.CsDeviceServiceImpl;
|
||||
import com.njcn.access.utils.MqttUtil;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.utils.PubUtils;
|
||||
@@ -74,23 +75,25 @@ public class AppTest
|
||||
@Resource
|
||||
private CsDeviceServiceImpl csDeviceService;
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@Resource
|
||||
private MqttUtil mqttUtil;
|
||||
|
||||
@Test
|
||||
public void lossTest() {
|
||||
String nDid = "0008C0A801C8";
|
||||
Integer status = csEquipmentDeliveryService.queryEquipmentByndid(nDid).getRunStatus();
|
||||
if (!Objects.isNull(status) && Objects.equals(status,AccessEnum.ONLINE.getCode())){
|
||||
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(2);
|
||||
ScheduledFuture<?> runnableFuture = executor.scheduleAtFixedRate(() -> {
|
||||
log.info("定时发送接入请求...");
|
||||
Integer status2 = csEquipmentDeliveryService.queryEquipmentByndid(nDid).getRunStatus();
|
||||
if (Objects.equals(status2,AccessEnum.OFFLINE.getCode())){
|
||||
throw new BusinessException(CommonResponseEnum.SUCCESS);
|
||||
}
|
||||
}, 1, 5, TimeUnit.SECONDS);
|
||||
final int[] mid = {2};
|
||||
for (int i = 0; i < 2; i++) {
|
||||
mid[0] = mid[0] + 1;
|
||||
}
|
||||
System.out.println("mid==:" + mid[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test1() {
|
||||
String clientName = "NJCN-A801C8";
|
||||
boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
||||
System.out.println("mqttClient==:" + mqttClient);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.stat.enums.StatResponseEnum;
|
||||
import com.njcn.stat.service.IStatService;
|
||||
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;
|
||||
@@ -62,6 +63,8 @@ public class StatServiceImpl implements IStatService {
|
||||
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
|
||||
private final DictTreeFeignClient dictTreeFeignClient;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void analysis(AppAutoDataMessage appAutoDataMessage) {
|
||||
@@ -82,18 +85,27 @@ public class StatServiceImpl implements IStatService {
|
||||
if (Objects.isNull(object1)){
|
||||
lineInfo(appAutoDataMessage.getId());
|
||||
}
|
||||
if (Objects.equals(appAutoDataMessage.getDid(),1)){
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appAutoDataMessage.getId())), Map.class).get("0").toString();
|
||||
} else if (Objects.equals(appAutoDataMessage.getDid(),2)){
|
||||
//获取当前设备信息判断装置型号,来筛选监测点
|
||||
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(appAutoDataMessage.getId()).getData();
|
||||
String code = dictTreeFeignClient.queryById(po.getDevType()).getData().getCode();
|
||||
//便携式设备
|
||||
if (Objects.equals(DicDataEnum.PORTABLE.getCode(),code)) {
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appAutoDataMessage.getId())), Map.class).get(appAutoDataMessage.getMsg().getClDid().toString()).toString();
|
||||
}
|
||||
//直连设备
|
||||
else if (Objects.equals(DicDataEnum.CONNECT_DEV.getCode(),code)) {
|
||||
if (Objects.equals(appAutoDataMessage.getDid(),1)){
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appAutoDataMessage.getId())), Map.class).get("0").toString();
|
||||
} else if (Objects.equals(appAutoDataMessage.getDid(),2)){
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appAutoDataMessage.getId())), Map.class).get(appAutoDataMessage.getMsg().getClDid().toString()).toString();
|
||||
}
|
||||
}
|
||||
//缓存指标和influxDB表关系
|
||||
Object object2 = redisUtil.getObjectByKey(AppRedisKey.ELE_EPD_PQD);
|
||||
if(Objects.isNull(object2)) {
|
||||
saveData();
|
||||
}
|
||||
//获取当前设备信息
|
||||
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(appAutoDataMessage.getId()).getData();
|
||||
if (CollectionUtil.isNotEmpty(list)){
|
||||
List<String> recordList = new ArrayList<>();
|
||||
for (AppAutoDataMessage.DataArray item : list) {
|
||||
@@ -144,16 +156,17 @@ public class StatServiceImpl implements IStatService {
|
||||
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());
|
||||
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.saveByKeyWithExpire(AppRedisKey.LINE_POSITION+id,map,600L);
|
||||
|
||||
Reference in New Issue
Block a user