无线系统实时数据功能
This commit is contained in:
@@ -109,5 +109,19 @@ public class AskDeviceDataController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/askRealData")
|
||||
@ApiOperation("询问装置实时数据")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "nDid", value = "装置nDid"),
|
||||
@ApiImplicitParam(name = "idx", value = "数据集编号"),
|
||||
@ApiImplicitParam(name = "clDId", value = "逻辑子设备id")
|
||||
})
|
||||
public HttpResult<String> askRealData(@RequestParam("nDid") String nDid, @RequestParam("idx") Integer idx, @RequestParam("clDId") Integer clDId){
|
||||
String methodDescribe = getMethodDescribe("askRealData");
|
||||
askDeviceDataService.askRealData(nDid,idx,clDId);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.njcn.access.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.njcn.device.biz.pojo.po.Overlimit;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
*/
|
||||
public interface OverlimitMapper extends BaseMapper<Overlimit> {
|
||||
|
||||
}
|
||||
@@ -16,4 +16,9 @@ public interface AskDeviceDataService {
|
||||
void createFolder(String nDid, String path);
|
||||
|
||||
void deleteFolder(String nDid, String path);
|
||||
|
||||
/**
|
||||
* 实时数据请求报文
|
||||
*/
|
||||
void askRealData(String nDid, Integer idx, Integer size);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
import com.njcn.access.api.CsTopicFeignClient;
|
||||
import com.njcn.access.enums.AccessEnum;
|
||||
import com.njcn.access.enums.TypeEnum;
|
||||
import com.njcn.access.pojo.dto.AskDataDto;
|
||||
import com.njcn.access.pojo.dto.ControlDto;
|
||||
import com.njcn.access.pojo.dto.ReqAndResDto;
|
||||
import com.njcn.access.pojo.dto.file.FileRedisDto;
|
||||
@@ -96,8 +97,8 @@ public class AskDeviceDataServiceImpl implements AskDeviceDataService {
|
||||
ReqAndResDto.Req reqAndResParam = getAllPojo(mid,name);
|
||||
publisher.send("/Pfm/DevFileCmd/V1/"+nDid,new Gson().toJson(reqAndResParam),1,false);
|
||||
//这里使用简单的轮询,但建议考虑更高效的机制
|
||||
for (int i = 0; i < 120; i++) {
|
||||
Thread.sleep(2000);
|
||||
for (int i = 0; i < 12; i++) {
|
||||
Thread.sleep(10000);
|
||||
Object object2 = redisUtil.getObjectByKey("downloadFilePath:"+name);
|
||||
if (!Objects.isNull(object2)) {
|
||||
result = true;
|
||||
@@ -195,6 +196,39 @@ public class AskDeviceDataServiceImpl implements AskDeviceDataService {
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,mid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void askRealData(String nDid, Integer idx, Integer clDId) {
|
||||
Object object = getDeviceMid(nDid);
|
||||
if (!Objects.isNull(object)) {
|
||||
mid = (Integer) object;
|
||||
}
|
||||
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
|
||||
reqAndResParam.setMid(mid);
|
||||
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_6.getCode()));
|
||||
reqAndResParam.setExpire(-1);
|
||||
//fixme 目前设备都是直连设备,因此did就是其本身,默认为1,后期涉及网关,此did是需要动态变化的
|
||||
reqAndResParam.setDid(1);
|
||||
AskDataDto askDataDto = new AskDataDto();
|
||||
askDataDto.setCldid(clDId);
|
||||
askDataDto.setDataAttr(1);
|
||||
askDataDto.setDataType(4);
|
||||
askDataDto.setOperate(1);
|
||||
askDataDto.setStartTime(-1);
|
||||
askDataDto.setEndTime(-1);
|
||||
askDataDto.setRtDuration(30);
|
||||
askDataDto.setDsNameIdx(idx);
|
||||
reqAndResParam.setMsg(askDataDto);
|
||||
log.info("askDevData的请求报文:" + new Gson().toJson(reqAndResParam));
|
||||
publisher.send("/Pfm/DevCmd/V1/"+nDid, new Gson().toJson(reqAndResParam),1,false);
|
||||
mid = mid + 1;
|
||||
if (mid > 10000) {
|
||||
mid = 1;
|
||||
}
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,mid);
|
||||
}
|
||||
|
||||
|
||||
public Object getDeviceMid(String nDid) {
|
||||
return redisUtil.getObjectByKey(AppRedisKey.DEVICE_MID + nDid);
|
||||
}
|
||||
@@ -203,7 +237,6 @@ public class AskDeviceDataServiceImpl implements AskDeviceDataService {
|
||||
return csTopicFeignClient.find(nDid).getData();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 全文件下载请求报文
|
||||
*/
|
||||
@@ -238,39 +271,4 @@ public class AskDeviceDataServiceImpl implements AskDeviceDataService {
|
||||
reqAndResParam.setMsg(jsonObject);
|
||||
return reqAndResParam;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据装置响应来判断是否询问下一帧数据
|
||||
*/
|
||||
public void sendNextStep(String fileName, String id, int mid,int step) {
|
||||
try {
|
||||
for (int i = 1; i < 4; i++) {
|
||||
if (step == 0 ){
|
||||
Thread.sleep(5000);
|
||||
} else {
|
||||
Thread.sleep(2000);
|
||||
}
|
||||
FileRedisDto fileRedisDto = (FileRedisDto) redisUtil.getObjectByKey(AppRedisKey.DOWNLOAD + fileName + mid);
|
||||
if (Objects.isNull(fileRedisDto)) {
|
||||
FileRedisDto failDto = new FileRedisDto();
|
||||
failDto.setCode(400);
|
||||
redisUtil.saveByKeyWithExpire(AppRedisKey.DOWNLOAD + fileName + mid,failDto,10L);
|
||||
} else {
|
||||
if (Objects.equals(fileRedisDto.getCode(),200)) {
|
||||
break;
|
||||
} else {
|
||||
log.info("第" +i+"次尝试");
|
||||
//尝试失败则设置code为400,如果装置响应了,则会将code置为200
|
||||
FileRedisDto failDto = new FileRedisDto();
|
||||
failDto.setCode(400);
|
||||
redisUtil.saveByKeyWithExpire(AppRedisKey.DOWNLOAD + fileName + mid,failDto,10L);
|
||||
ReqAndResDto.Req req = getPojo(mid,fileName,step);
|
||||
publisher.send("/Pfm/DevFileCmd/V1/" + id, new Gson().toJson(req), 1, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(AlgorithmResponseEnum.ASK_DEVICE_DIR_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
import com.njcn.access.enums.AccessEnum;
|
||||
import com.njcn.access.enums.AccessResponseEnum;
|
||||
import com.njcn.access.enums.TypeEnum;
|
||||
import com.njcn.access.mapper.OverlimitMapper;
|
||||
import com.njcn.access.param.DevAccessParam;
|
||||
import com.njcn.access.pojo.dto.AccessDto;
|
||||
import com.njcn.access.pojo.dto.CsModelDto;
|
||||
@@ -26,6 +27,8 @@ import com.njcn.csdevice.pojo.param.CsLedgerParam;
|
||||
import com.njcn.csdevice.pojo.param.CsLineParam;
|
||||
import com.njcn.csdevice.pojo.po.*;
|
||||
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
|
||||
import com.njcn.device.biz.pojo.po.Overlimit;
|
||||
import com.njcn.device.biz.utils.COverlimitUtil;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
@@ -77,6 +80,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
private final ChannelObjectUtil channelObjectUtil;
|
||||
private final CsLineFeignClient csLineFeignClient;
|
||||
private final DataSetFeignClient dataSetFeignClient;
|
||||
private final OverlimitMapper overlimitMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
@@ -365,7 +369,6 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
return devAccessAskTemplate(nDid,version,1);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public String wlDevRegister(String nDid) {
|
||||
@@ -432,6 +435,13 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
csLedgerService.addLedgerTree(param);
|
||||
});
|
||||
csLineService.saveBatch(csLinePoList);
|
||||
//生成监测点限值
|
||||
for(CsLinePO csLinePO: csLinePoList){
|
||||
Overlimit overlimit = COverlimitUtil.globalAssemble(csLinePO.getVolGrade().floatValue(),10f,10f,10f,0,1);
|
||||
overlimit.setId(csLinePO.getLineId());
|
||||
overlimitMapper.deleteById(csLinePO.getLineId());
|
||||
overlimitMapper.insert(overlimit);
|
||||
}
|
||||
//4.生成装置和模板的关系表
|
||||
CsDevModelRelationAddParm csDevModelRelationAddParm = new CsDevModelRelationAddParm();
|
||||
csDevModelRelationAddParm.setDevId(vo.getId());
|
||||
|
||||
Reference in New Issue
Block a user