装置文件夹新建、删除

This commit is contained in:
xy
2024-09-11 20:41:48 +08:00
parent b79e612595
commit 9509a59f16
11 changed files with 226 additions and 106 deletions

View File

@@ -24,4 +24,11 @@ public interface AskDeviceDataFeignClient {
@PostMapping("/rebootDevice")
HttpResult<String> rebootDevice(@RequestParam("nDid") String nDid);
@PostMapping("/createFolder")
HttpResult<String> createFolder(@RequestParam("nDid") String nDid, @RequestParam("path") String path);
@PostMapping("/deleteFolder")
HttpResult<String> deleteFolder(@RequestParam("nDid") String nDid, @RequestParam("path") String path);
}

View File

@@ -55,6 +55,18 @@ public class AskDeviceDataClientFallbackFactory implements FallbackFactory<AskDe
log.error("{}异常,降级处理,异常为:{}","设备重启",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<String> createFolder(String nDid, String path) {
log.error("{}异常,降级处理,异常为:{}","创建文件夹",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<String> deleteFolder(String nDid, String path) {
log.error("{}异常,降级处理,异常为:{}","删除文件夹",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}

View File

@@ -82,4 +82,32 @@ public class AskDeviceDataController extends BaseController {
askDeviceDataService.rebootDevice(nDid);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/createFolder")
@ApiOperation("创建文件")
@ApiImplicitParams({
@ApiImplicitParam(name = "nDid", value = "nDid", required = true),
@ApiImplicitParam(name = "path", value = "文件路径", required = true)
})
public HttpResult<String> createFolder(@RequestParam("nDid") String nDid, @RequestParam("path") String path){
String methodDescribe = getMethodDescribe("createFolder");
askDeviceDataService.createFolder(nDid,path);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/deleteFolder")
@ApiOperation("删除文件")
@ApiImplicitParams({
@ApiImplicitParam(name = "nDid", value = "nDid", required = true),
@ApiImplicitParam(name = "path", value = "文件路径", required = true)
})
public HttpResult<String> deleteFolder(@RequestParam("nDid") String nDid, @RequestParam("path") String path){
String methodDescribe = getMethodDescribe("deleteFolder");
askDeviceDataService.deleteFolder(nDid,path);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
}

View File

@@ -622,6 +622,14 @@ public class MqttMessageHandler {
redisUtil.saveByKeyWithExpire(AppRedisKey.UPLOAD,fileRedisDto,10L);
redisUtil.saveByKeyWithExpire("uploading","uploading",20L);
break;
case 4660:
log.info("设备目录/文件删除应答");
redisUtil.saveByKeyWithExpire( "deleteDir"+ nDid,fileDto.getCode(),10L);
break;
case 4661:
log.info("设备目录创建应答");
redisUtil.saveByKeyWithExpire( "createDir"+ nDid,fileDto.getCode(),10L);
break;
case 4662:
log.info("装置根目录应答");
redisUtil.saveByKeyWithExpire(AppRedisKey.DEVICE_ROOT_PATH + nDid,fileDto.getMsg().getName(),10L);

View File

@@ -12,4 +12,8 @@ public interface AskDeviceDataService {
boolean downloadFile(String nDid, String name, Integer size, String fileCheck);
void rebootDevice(String nDid);
void createFolder(String nDid, String path);
void deleteFolder(String nDid, String path);
}

View File

@@ -142,6 +142,52 @@ public class AskDeviceDataServiceImpl implements AskDeviceDataService {
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,mid);
}
@Override
public void createFolder(String nDid, String path) {
Object object = getDeviceMid(nDid);
if (!Objects.isNull(object)) {
mid = (Integer) object;
}
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
reqAndResParam.setMid(mid);
reqAndResParam.setDid(0);
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
reqAndResParam.setExpire(-1);
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_12.getCode()));
String json = String.format("{\"Name\":\"%s\"}", path);
JSONObject jsonObject = JSONObject.fromObject(json);
reqAndResParam.setMsg(jsonObject);
publisher.send("/Pfm/DevFileCmd/V1/" + nDid, new Gson().toJson(reqAndResParam), 1, false);
mid = mid + 1;
if (mid > 10000) {
mid = 1;
}
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,mid);
}
@Override
public void deleteFolder(String nDid, String path) {
Object object = getDeviceMid(nDid);
if (!Objects.isNull(object)) {
mid = (Integer) object;
}
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
reqAndResParam.setMid(mid);
reqAndResParam.setDid(0);
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
reqAndResParam.setExpire(-1);
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_11.getCode()));
String json = String.format("{\"Name\":\"%s\"}", path);
JSONObject jsonObject = JSONObject.fromObject(json);
reqAndResParam.setMsg(jsonObject);
publisher.send("/Pfm/DevFileCmd/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);
}

View File

@@ -268,9 +268,9 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
*/
public void sendNextStep(DeviceLogDTO logDto, String path, MultipartFile file, int length, byte[] bytes, Integer offset, String version, String id, int mid, String fileCheck, boolean result) {
try {
for (int i = 0; i < 3; i++) {
for (int i = 0; i < 30; i++) {
if (result) {
Thread.sleep(5000);
Thread.sleep(10000);
} else {
Thread.sleep(2000);
}

View File

@@ -2,6 +2,7 @@ package com.njcn.zlevent.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.csdevice.api.EquipmentFeignClient;
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
@@ -56,37 +57,46 @@ public class CsAlarmServiceImpl extends ServiceImpl<CsEventMapper, CsEventPO> im
try {
List<AppEventMessage.DataArray> dataArray = appEventMessage.getMsg().getDataArray();
for (AppEventMessage.DataArray item : dataArray) {
//事件入库
CsEventPO csEvent = new CsEventPO();
csEvent.setId(id);
csEvent.setDeviceId(po.getId());
csEvent.setProcess(po.getProcess());
csEvent.setCode(item.getCode());
eventTime = eventService.timeFormat(item.getDataTimeSec(),item.getDataTimeUSec());
csEvent.setStartTime(eventTime);
tag = item.getName();
csEvent.setTag(tag);
csEvent.setType(3);
csEvent.setClDid(appEventMessage.getMsg().getClDid());
csEvent.setLevel(Integer.parseInt(item.getType()));
csEvent.setCode(item.getCode());
list1.add(csEvent);
LambdaQueryWrapper<CsEventPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(CsEventPO::getDeviceId,po.getId())
.eq(CsEventPO::getProcess,po.getProcess())
.eq(CsEventPO::getCode,item.getCode())
.eq(CsEventPO::getStartTime,eventTime)
.eq(CsEventPO::getTag,item.getName());
List<CsEventPO> list = csEventService.list(wrapper);
if (CollectionUtil.isEmpty(list)) {
//事件入库
CsEventPO csEvent = new CsEventPO();
csEvent.setId(id);
csEvent.setDeviceId(po.getId());
csEvent.setProcess(po.getProcess());
csEvent.setCode(item.getCode());
csEvent.setStartTime(eventTime);
tag = item.getName();
csEvent.setTag(tag);
csEvent.setType(3);
csEvent.setClDid(appEventMessage.getMsg().getClDid());
csEvent.setLevel(Integer.parseInt(item.getType()));
csEvent.setCode(item.getCode());
list1.add(csEvent);
}
}
if (CollectionUtil.isNotEmpty(list1)){
csEventService.saveBatch(list1);
}
//推送事件逻辑处理 && cs_event_user入库 && 修改字典中告警事件的编码
for (AppEventMessage.DataArray item : dataArray) {
if (Objects.isNull(item.getCode())){
sendEventUtils.sendUser(2,item.getType(),po.getId(),item.getName(),eventTime,id);
} else {
sendEventUtils.sendUser(2,item.getType(),po.getId(),item.getCode(),eventTime,id);
//更新字典信息
EleEpdPqd eleEpdPqd = epdFeignClient.findByName(item.getName()).getData();
EleEpdPqdParam.EleEpdPqdUpdateParam updateParam = new EleEpdPqdParam.EleEpdPqdUpdateParam();
BeanUtils.copyProperties(eleEpdPqd,updateParam);
updateParam.setDefaultValue(item.getCode());
epdFeignClient.update(updateParam);
//推送事件逻辑处理 && cs_event_user入库 && 修改字典中告警事件的编码
for (AppEventMessage.DataArray item : dataArray) {
if (Objects.isNull(item.getCode())){
sendEventUtils.sendUser(2,item.getType(),po.getId(),item.getName(),eventTime,id);
} else {
sendEventUtils.sendUser(2,item.getType(),po.getId(),item.getCode(),eventTime,id);
//更新字典信息
EleEpdPqd eleEpdPqd = epdFeignClient.findByName(item.getName()).getData();
EleEpdPqdParam.EleEpdPqdUpdateParam updateParam = new EleEpdPqdParam.EleEpdPqdUpdateParam();
BeanUtils.copyProperties(eleEpdPqd,updateParam);
updateParam.setDefaultValue(item.getCode());
epdFeignClient.update(updateParam);
}
}
}
} catch (Exception e) {

View File

@@ -3,6 +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.njcn.common.pojo.exception.BusinessException;
import com.njcn.csdevice.api.CsLineFeignClient;
import com.njcn.csdevice.api.EquipmentFeignClient;
@@ -92,88 +93,99 @@ public class EventServiceImpl implements IEventService {
//处理事件数据
List<AppEventMessage.DataArray> dataArray = appEventMessage.getMsg().getDataArray();
for (AppEventMessage.DataArray item : dataArray) {
id = IdUtil.fastSimpleUUID();
//事件入库
CsEventPO csEvent = new CsEventPO();
csEvent.setId(id);
csEvent.setDeviceId(po.getId());
csEvent.setProcess(po.getProcess());
csEvent.setCode(item.getCode());
eventTime = timeFormat(item.getDataTimeSec(),item.getDataTimeUSec());
csEvent.setStartTime(eventTime);
tag = item.getName();
csEvent.setTag(tag);
if (Objects.equals(item.getType(),"2")){
csEvent.setType(0);
} else if (Objects.equals(item.getType(),"3")){
csEvent.setType(1);
} else if (Objects.equals(item.getType(),"1")){
csEvent.setType(2);
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get("0").toString();
csEvent.setClDid(appEventMessage.getMsg().getClDid());
}
csEvent.setLevel(Integer.parseInt(item.getType()));
//参数入库
Map<String,String> map = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.ELE_EPD_PQD)), Map.class);
if (!Objects.isNull(item.getParam())){
String tableName = map.get(item.getName());
List<AppEventMessage.Param> params = item.getParam();
for (AppEventMessage.Param param : params) {
Map<String, String> tags = new HashMap<>();
tags.put(InfluxDBTableConstant.UUID,id);
Map<String,Object> fields = new HashMap<>();
if (Objects.equals(ZlConstant.EVENT_POSITION,param.getName())){
if (Objects.equals(param.getData(),ZlConstant.GRID)){
fields.put(param.getName(),"电网侧");
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get("1").toString();
csEvent.setClDid(1);
} else if (Objects.equals(param.getData(),ZlConstant.LOAD)){
fields.put(param.getName(),"负载侧");
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get("2").toString();
csEvent.setClDid(2);
}
csEvent.setLocation(param.getData().toString());
} else {
if (Objects.equals(param.getName(),ZlConstant.EVT_PARAM_TM)){
csEvent.setPersistTime(Double.parseDouble(param.getData().toString()));
}
lineId = appEventMessage.getId() + appEventMessage.getMsg().getClDid();
fields.put(param.getName(),appEventMessage.getMsg().getClDid()==1?"电网侧":"负载侧");
csEvent.setLocation(appEventMessage.getMsg().getClDid()==1?ZlConstant.GRID:ZlConstant.LOAD);
csEvent.setClDid(appEventMessage.getMsg().getClDid());
fields.put(param.getName(),param.getData());
}
//fixme 这边前置传递的应该是UTC时间,但是前置说是传递的北京时间,讨论了一下没太理解。这边暂时先这样处理,influx入库处理成北京时间,减去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());
//此处做限制,如果已有事件则不在记录通知
LambdaQueryWrapper<CsEventPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(CsEventPO::getDeviceId,po.getId())
.eq(CsEventPO::getProcess,po.getProcess())
.eq(CsEventPO::getCode,item.getCode())
.eq(CsEventPO::getStartTime,eventTime)
.eq(CsEventPO::getTag,item.getName());
List<CsEventPO> list = csEventService.list(wrapper);
if (CollectionUtil.isEmpty(list)) {
id = IdUtil.fastSimpleUUID();
//事件入库
CsEventPO csEvent = new CsEventPO();
csEvent.setId(id);
csEvent.setDeviceId(po.getId());
csEvent.setProcess(po.getProcess());
csEvent.setCode(item.getCode());
eventTime = timeFormat(item.getDataTimeSec(),item.getDataTimeUSec());
csEvent.setStartTime(eventTime);
tag = item.getName();
csEvent.setTag(tag);
if (Objects.equals(item.getType(),"2")){
csEvent.setType(0);
} else if (Objects.equals(item.getType(),"3")){
csEvent.setType(1);
} else if (Objects.equals(item.getType(),"1")){
csEvent.setType(2);
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get("0").toString();
csEvent.setClDid(appEventMessage.getMsg().getClDid());
}
csEvent.setLevel(Integer.parseInt(item.getType()));
//参数入库
Map<String,String> map = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.ELE_EPD_PQD)), Map.class);
if (!Objects.isNull(item.getParam())){
String tableName = map.get(item.getName());
List<AppEventMessage.Param> params = item.getParam();
for (AppEventMessage.Param param : params) {
Map<String, String> tags = new HashMap<>();
tags.put(InfluxDBTableConstant.UUID,id);
Map<String,Object> fields = new HashMap<>();
if (Objects.equals(ZlConstant.EVENT_POSITION,param.getName())){
if (Objects.equals(param.getData(),ZlConstant.GRID)){
fields.put(param.getName(),"电网侧");
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get("1").toString();
csEvent.setClDid(1);
} else if (Objects.equals(param.getData(),ZlConstant.LOAD)){
fields.put(param.getName(),"负载侧");
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get("2").toString();
csEvent.setClDid(2);
}
csEvent.setLocation(param.getData().toString());
} else {
if (Objects.equals(param.getName(),ZlConstant.EVT_PARAM_TM)){
csEvent.setPersistTime(Double.parseDouble(param.getData().toString()));
}
lineId = appEventMessage.getId() + appEventMessage.getMsg().getClDid();
fields.put(param.getName(),appEventMessage.getMsg().getClDid()==1?"电网侧":"负载侧");
csEvent.setLocation(appEventMessage.getMsg().getClDid()==1?ZlConstant.GRID:ZlConstant.LOAD);
csEvent.setClDid(appEventMessage.getMsg().getClDid());
fields.put(param.getName(),param.getData());
}
//fixme 这边前置传递的应该是UTC时间,但是前置说是传递的北京时间,讨论了一下没太理解。这边暂时先这样处理,influx入库处理成北京时间,减去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());
}
}
csEvent.setLineId(lineId);
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);
}
csEvent.setLineId(lineId);
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);
}
}
//evt_data入库
if (CollectionUtil.isNotEmpty(records)) {
influxDbUtils.batchInsert(influxDbUtils.getDbName(), "", InfluxDB.ConsistencyLevel.ALL, TimeUnit.MILLISECONDS, records);
}
//推送事件逻辑处理 && cs_event_user入库
for (AppEventMessage.DataArray item : dataArray) {
sendEventUtils.sendUser(1,item.getType(),po.getId(),item.getName(),eventTime,id);
}
} catch (Exception e) {
CsEventLogs csEventLogs = new CsEventLogs();
csEventLogs.setLineId(lineId);

View File

@@ -258,11 +258,8 @@ public class FileServiceImpl implements IFileService {
csEventLogs.setAllStep(appFileMessage.getMsg().getFrameTotal());
csEventLogs.setIsAll(0);
redisUtil.saveByKey(AppRedisKey.FILE_PART.concat(appFileMessage.getMsg().getName()), dto);
long time1 = System.currentTimeMillis();
//将数据写入临时文件
appendFile(lsFileName, appFileMessage.getMsg().getFrameCurr(), appFileMessage.getMsg().getData());
long time2 = System.currentTimeMillis();
System.out.println("time==:" + (time2 - time1));
log.info("当前文件 {} 帧,这是第 {} 帧报文,记录成功", appFileMessage.getMsg().getFrameTotal(), appFileMessage.getMsg().getFrameCurr());
if (Objects.isNull(object2)) {
redisUtil.saveByKeyWithExpire(AppRedisKey.FILE_PART_TIME.concat(appFileMessage.getMsg().getName()), null, 10L);

View File

@@ -40,13 +40,10 @@ public class AppEventConsumer extends EnhanceConsumerMessageHandler<AppEventMess
@Resource
private RedisUtil redisUtil;
@Resource
private RocketMqLogFeignClient rocketMqLogFeignClient;
@Resource
private EventFeignClient eventFeignClient;
@Resource
private WaveFeignClient waveFeignClient;
@Resource
@@ -70,7 +67,6 @@ public class AppEventConsumer extends EnhanceConsumerMessageHandler<AppEventMess
break;
case 32:
log.info("分发至便携式基础数据处理");
break;
default:
break;