1.设备注册接入优化

2.波形文件接收、解析功能调整
This commit is contained in:
2023-10-13 10:49:43 +08:00
parent 340e7dc75f
commit 6e12027e69
27 changed files with 894 additions and 662 deletions

View File

@@ -59,7 +59,7 @@ public class RspDataDto {
} }
/** /**
* 软件信息 * 监测点信息
*/ */
@Data @Data
public static class LdevInfo { public static class LdevInfo {
@@ -79,6 +79,9 @@ public class RspDataDto {
@SerializedName("CtRatio") @SerializedName("CtRatio")
private Double ctRatio; private Double ctRatio;
@SerializedName("Capacity_A")
private Double capacity;
} }
} }

View File

@@ -72,6 +72,10 @@ public class EventDto {
@ApiModelProperty("事件类型") @ApiModelProperty("事件类型")
private String type; private String type;
@SerializedName("Code")
@ApiModelProperty("告警故障编码一般显示为Hex")
private String code;
@SerializedName("Parm") @SerializedName("Parm")
private List<Param> param; private List<Param> param;
} }

View File

@@ -1,40 +0,0 @@
package com.njcn.access.pojo.dto.devModel;
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2022/3/13 12:09
*/
@Data
public class CpuInfoDto implements Serializable {
@SerializedName("OpAttr")
@ApiModelProperty("读写操作属性")
private String opAttr;
@SerializedName("CpuCore")
@ApiModelProperty("CPU核心数")
private Integer cpuCore;
@SerializedName("CpuFreq")
@ApiModelProperty("CPU主频(单位MHz)")
private Float cpuFreq;
@SerializedName("Arch")
@ApiModelProperty("CPU架构")
private String arch;
@SerializedName("CpuLmt")
@ApiModelProperty("CPU监控阈值(单位%)")
private Float cpuLmt;
}

View File

@@ -1,36 +0,0 @@
package com.njcn.access.pojo.dto.devModel;
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2022/3/13 12:08
*/
@Data
public class DevInfoDto implements Serializable {
@SerializedName("OpAttr")
@ApiModelProperty("读写操作属性")
private String opAttr;
@SerializedName("DevType")
@ApiModelProperty("设备型号")
private String devType;
@SerializedName("DevName ")
@ApiModelProperty("设备名称")
private String devName;
@SerializedName("MsgInfo")
@ApiModelProperty("设备厂商信息")
private String msgInfo;
}

View File

@@ -1,30 +0,0 @@
package com.njcn.access.pojo.dto.devModel;
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2022/3/13 12:09
*/
@Data
public class DiskInfoDto implements Serializable {
@SerializedName("OpAttr")
@ApiModelProperty("读写操作属性")
private String opAttr;
@SerializedName("DiskPhy")
@ApiModelProperty("磁盘空间(单位MB)")
private Float diskPhy;
@SerializedName("DiskLmt")
@ApiModelProperty("内存监控阈值(单位%)")
private Float diskLmt;
}

View File

@@ -1,45 +0,0 @@
package com.njcn.access.pojo.dto.devModel;
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.poi.hpsf.Decimal;
import javax.validation.constraints.NotEmpty;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/5/4 10:04
*/
@Data
public class LDevInfoDto implements Serializable {
@SerializedName("OpAttr")
private String opAttr;
@SerializedName("Cldid")
@ApiModelProperty(value = "逻辑子设备Id")
private Integer cldId;
@SerializedName("VolGrade")
@ApiModelProperty(value = "电压等级")
private Double volGrade;
@SerializedName("ConType")
@ApiModelProperty(value = "接线方式")
private Integer conType;
@SerializedName("PtRatio")
@ApiModelProperty(value = "PT变比")
private BigDecimal ptRatio;
@SerializedName("CtRatio")
@ApiModelProperty(value = "CT变比")
private BigDecimal ctRatio;
}

View File

@@ -1,29 +0,0 @@
package com.njcn.access.pojo.dto.devModel;
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2022/3/13 12:09
*/
@Data
public class MemInfoDto implements Serializable {
@SerializedName("OpAttr")
@ApiModelProperty("读写操作属性")
private String opAttr;
@SerializedName("MemPhy")
@ApiModelProperty("物理内存(单位MB)")
private Float memPhy;
@SerializedName("MemLmt")
@ApiModelProperty("内存监控阈值(单位%)")
private Float memLmt;
}

View File

@@ -1,43 +0,0 @@
package com.njcn.access.pojo.dto.devModel;
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import java.io.Serializable;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/5/16 15:30
*/
@Data
public class PrjInfoDto implements Serializable {
@SerializedName("OpAttr")
@NotEmpty(message = "读写操作属性不可为空")
private String opAttr;
@SerializedName("Province")
@NotEmpty(message = "安装区域省,不可为空")
private String province;
@SerializedName("City")
@NotEmpty(message = "安装区域市,不可为空")
private String city;
@SerializedName("County")
@NotEmpty(message = "安装区域县或区,不可为空")
private String county;
@SerializedName("Address")
@NotEmpty(message = "安装地址(厂区或变电站),不可为空")
private String address;
@SerializedName("Position")
@NotEmpty(message = "安装位置,不可为空")
private String position;
}

View File

@@ -1,49 +0,0 @@
package com.njcn.access.pojo.dto.devModel;
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Null;
import java.io.Serializable;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2022/3/13 12:09
*/
@Data
public class SoftInfoDto implements Serializable {
@SerializedName("OpAttr")
@NotEmpty(message = "读写操作属性不可为空")
private String opAttr;
@SerializedName("OsName")
@NotEmpty(message = "操作系统名称,裸机系统填Null,不可为空")
private String osName;
@SerializedName("OsVersion")
@NotEmpty(message = "操作系统版本,裸机系统填Null,不可为空")
private String osVersion;
@SerializedName("AppVersion")
@NotEmpty(message = "应用程序版本号,不可为空")
private String appVersion;
@SerializedName("AppDate")
@NotEmpty(message = "应用程序发布日期,不可为空")
private String appDate;
@SerializedName("AppCheck")
@NotEmpty(message = "应用程序校验码,不可为空")
private String appCheck;
@SerializedName("Softupdate")
@NotEmpty(message = "是否支持远程升级程序,不可为空")
private String softUpdate;
}

View File

@@ -50,6 +50,21 @@ public class FileDto implements Serializable {
@SerializedName("Name") @SerializedName("Name")
private String name; private String name;
@SerializedName("FrameCurr")
@ApiModelProperty("当前帧")
private Integer frameCurr;
@SerializedName("FrameTotal")
@ApiModelProperty("总帧数")
private Integer frameTotal;
@SerializedName("FrameLen")
@ApiModelProperty("单帧大小")
private Integer frameLen;
@SerializedName("Offset")
private Integer offset;
} }
@Data @Data

View File

@@ -1,5 +1,7 @@
package com.njcn.access.handler; package com.njcn.access.handler;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.excel.util.CollectionUtils; import com.alibaba.excel.util.CollectionUtils;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
@@ -17,18 +19,17 @@ import com.njcn.access.pojo.dto.file.FileDto;
import com.njcn.access.pojo.param.ReqAndResParam; import com.njcn.access.pojo.param.ReqAndResParam;
import com.njcn.access.pojo.po.CsDeviceOnlineLogs; import com.njcn.access.pojo.po.CsDeviceOnlineLogs;
import com.njcn.access.pojo.po.CsLineModel; import com.njcn.access.pojo.po.CsLineModel;
import com.njcn.access.pojo.po.CsSoftInfoPO;
import com.njcn.access.pojo.po.CsTopic; import com.njcn.access.pojo.po.CsTopic;
import com.njcn.access.service.ICsDeviceOnlineLogsService; import com.njcn.access.service.*;
import com.njcn.access.service.ICsEquipmentDeliveryService;
import com.njcn.access.service.ICsLineModelService;
import com.njcn.access.service.ICsTopicService;
import com.njcn.common.pojo.dto.DeviceLogDTO; import com.njcn.common.pojo.dto.DeviceLogDTO;
import com.njcn.common.pojo.exception.BusinessException; import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.csdevice.api.CsLogsFeignClient; import com.njcn.csdevice.api.*;
import com.njcn.csdevice.api.DataSetFeignClient; import com.njcn.csdevice.pojo.param.CsLineParam;
import com.njcn.csdevice.api.DevModelFeignClient;
import com.njcn.csdevice.pojo.po.CsDataSet; import com.njcn.csdevice.pojo.po.CsDataSet;
import com.njcn.csdevice.pojo.po.CsDevCapacityPO;
import com.njcn.csdevice.pojo.po.CsDevModelPO; import com.njcn.csdevice.pojo.po.CsDevModelPO;
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
import com.njcn.mq.message.AppAutoDataMessage; import com.njcn.mq.message.AppAutoDataMessage;
import com.njcn.mq.message.AppEventMessage; import com.njcn.mq.message.AppEventMessage;
import com.njcn.mq.message.AppFileMessage; import com.njcn.mq.message.AppFileMessage;
@@ -42,19 +43,19 @@ import com.njcn.web.utils.RequestUtil;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttMessage; import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.validation.ConstraintViolation; import javax.validation.ConstraintViolation;
import javax.validation.Validator; import javax.validation.Validator;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@@ -93,6 +94,14 @@ public class MqttMessageHandler {
private final ICsDeviceOnlineLogsService onlineLogsService; private final ICsDeviceOnlineLogsService onlineLogsService;
private final ICsSoftInfoService csSoftInfoService;
private final CsLineFeignClient csLineFeignClient;
private final DevCapacityFeignClient devCapacityFeignClient;
private final EquipmentFeignClient equipmentFeignClient;
@Autowired @Autowired
Validator validator; Validator validator;
@@ -292,6 +301,7 @@ public class MqttMessageHandler {
* @param payload * @param payload
*/ */
@MqttSubscribe(value = "/Pfm/DevRsp/{version}/{edgeId}",qos = 1) @MqttSubscribe(value = "/Pfm/DevRsp/{version}/{edgeId}",qos = 1)
@Transactional(rollbackFor = Exception.class)
public void devAccessOperation(String topic, MqttMessage message, @NamedValue("version") String version, @NamedValue("edgeId") String nDid, @Payload String payload){ public void devAccessOperation(String topic, MqttMessage message, @NamedValue("version") String version, @NamedValue("edgeId") String nDid, @Payload String payload){
//日志实体 //日志实体
DeviceLogDTO logDto = new DeviceLogDTO(); DeviceLogDTO logDto = new DeviceLogDTO();
@@ -306,59 +316,122 @@ public class MqttMessageHandler {
//业务处理 //业务处理
Gson gson = new Gson(); Gson gson = new Gson();
ReqAndResDto.Res res = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), ReqAndResDto.Res.class); ReqAndResDto.Res res = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), ReqAndResDto.Res.class);
switch (res.getType()){ if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){
case 4613: switch (res.getType()){
logDto.setOperate(nDid + "设备接入"); case 4613:
log.info("收到接入应答响应--->" + nDid); logDto.setOperate(nDid + "设备接入");
if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){ log.info("{}收到接入应答响应,应答code {}",nDid,res.getCode());
log.info("接入应答成功--->" + nDid); if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){
//修改装置状态 int mid = 1;
csEquipmentDeliveryService.updateStatusBynDid(nDid,AccessEnum.ACCESS.getCode()); //修改装置状态
csEquipmentDeliveryService.updateRunStatusBynDid(nDid,AccessEnum.ONLINE.getCode()); csEquipmentDeliveryService.updateStatusBynDid(nDid,AccessEnum.ACCESS.getCode());
//记录设备上线 csEquipmentDeliveryService.updateRunStatusBynDid(nDid,AccessEnum.ONLINE.getCode());
CsDeviceOnlineLogs record = onlineLogsService.findLastData(nDid); //记录设备上线
CsDeviceOnlineLogs csDeviceOnlineLogs = new CsDeviceOnlineLogs(); CsDeviceOnlineLogs record = onlineLogsService.findLastData(nDid);
if(Objects.isNull(record)) { CsDeviceOnlineLogs csDeviceOnlineLogs = new CsDeviceOnlineLogs();
csDeviceOnlineLogs.setNdid(nDid); if(Objects.isNull(record)) {
csDeviceOnlineLogs.setOnlineTime(LocalDateTime.now());
onlineLogsService.save(csDeviceOnlineLogs);
} else {
LocalDateTime time = record.getOfflineTime();
if (!Objects.isNull(time)){
csDeviceOnlineLogs.setNdid(nDid); csDeviceOnlineLogs.setNdid(nDid);
csDeviceOnlineLogs.setOnlineTime(LocalDateTime.now()); csDeviceOnlineLogs.setOnlineTime(LocalDateTime.now());
onlineLogsService.save(csDeviceOnlineLogs); onlineLogsService.save(csDeviceOnlineLogs);
} else {
LocalDateTime time = record.getOfflineTime();
if (!Objects.isNull(time)){
csDeviceOnlineLogs.setNdid(nDid);
csDeviceOnlineLogs.setOnlineTime(LocalDateTime.now());
onlineLogsService.save(csDeviceOnlineLogs);
}
} }
//询问设备软件信息
askDevData(nDid,version,1,mid);
mid++;
//询问设备容量信息
askDevData(nDid,version,2,mid);
mid++;
//询问监测点pt/ct信息
askDevData(nDid,version,3,mid);
} else {
log.info(AccessResponseEnum.ACCESS_RESPONSE_ERROR.getMessage());
logDto.setResult(0);
logDto.setFailReason(AccessResponseEnum.ACCESS_RESPONSE_ERROR.getMessage());
csLogsFeignClient.addUserLog(logDto);
throw new BusinessException(AccessResponseEnum.ACCESS_RESPONSE_ERROR);
} }
} else { break;
log.info(AccessResponseEnum.ACCESS_RESPONSE_ERROR.getMessage()); case 4614:
logDto.setResult(0); log.info("设备数据应答--->" + nDid);
logDto.setFailReason(AccessResponseEnum.ACCESS_RESPONSE_ERROR.getMessage()); RspDataDto rspDataDto = JSON.parseObject(JSON.toJSONString(res.getMsg()), RspDataDto.class);
csLogsFeignClient.addUserLog(logDto); switch (rspDataDto.getDataType()){
throw new BusinessException(AccessResponseEnum.ACCESS_RESPONSE_ERROR); case 1:
} logDto.setOperate(nDid + "更新设备软件信息");
break; RspDataDto.SoftInfo softInfo = JSON.parseObject(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.SoftInfo.class);
case 4614: //记录设备软件信息
logDto.setOperate(nDid + "设备数据应答"); CsSoftInfoPO csSoftInfoPo = new CsSoftInfoPO();
log.info("设备数据应答--->" + nDid); BeanUtils.copyProperties(softInfo,csSoftInfoPo);
RspDataDto rspDataDto = JSON.parseObject(JSON.toJSONString(res.getMsg()), RspDataDto.class); try {
switch (rspDataDto.getDataType()){ csSoftInfoPo.setAppDate(new SimpleDateFormat("yyyy-MM-dd").parse(softInfo.getAppDate()));
case 1: csSoftInfoService.save(csSoftInfoPo);
RspDataDto.SoftInfo softInfo = JSON.parseObject(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.SoftInfo.class); //更新设备软件id 先看是否存在软件信息,删除 然后在录入
redisUtil.saveByKeyWithExpire(AppRedisKey.SOFTINFO+nDid,softInfo,600L); CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(nDid).getData();
break; String soft = po.getSoftinfoId();
case 2: if (StringUtil.isNotBlank(soft)){
List<RspDataDto.LdevInfo> ldevInfo = JSON.parseArray(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.LdevInfo.class); csSoftInfoService.removeById(soft);
redisUtil.saveByKeyWithExpire(AppRedisKey.LINE_DATA+nDid,ldevInfo,600L); }
break; equipmentFeignClient.updateSoftInfo(nDid,csSoftInfoPo.getId());
default: } catch (ParseException e) {
break; e.printStackTrace();
} }
break; break;
default: case 2:
break; List<RspDataDto.LdevInfo> devInfo = JSON.parseArray(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.LdevInfo.class);
if (CollectionUtil.isNotEmpty(devInfo)){
if (Objects.equals(res.getDid(),1)){
logDto.setOperate(nDid + "更新治理监测点信息和设备容量");
List<CsDevCapacityPO> list = new ArrayList<>();
devInfo.forEach(item->{
//1.更新治理监测点信息
if (Objects.equals(item.getClDid(),0)){
CsLineParam csLineParam = new CsLineParam();
csLineParam.setLineId(nDid.concat("0"));
csLineParam.setVolGrade(item.getVolGrade());
csLineParam.setPtRatio(item.getPtRatio());
csLineParam.setCtRatio(item.getCtRatio());
csLineParam.setConType(item.getConType());
csLineFeignClient.updateLine(csLineParam);
}
//2.录入各个模块设备容量
CsDevCapacityPO csDevCapacity = new CsDevCapacityPO();
csDevCapacity.setLineId(nDid.concat("0"));
csDevCapacity.setCldid(item.getClDid());
csDevCapacity.setCapacity(item.getCapacity());
list.add(csDevCapacity);
});
devCapacityFeignClient.addList(list);
//3.更新设备模块个数
equipmentFeignClient.updateModuleNumber(nDid,(devInfo.size()-1));
} else if (Objects.equals(res.getDid(),2)) {
logDto.setOperate(nDid + "更新电网侧、负载侧监测点信息");
//1.更新电网侧、负载侧监测点相关信息
devInfo.forEach(item->{
CsLineParam csLineParam = new CsLineParam();
csLineParam.setLineId(nDid.concat(item.getClDid().toString()));
csLineParam.setVolGrade(item.getVolGrade());
csLineParam.setPtRatio(item.getPtRatio());
csLineParam.setCtRatio(item.getCtRatio());
csLineParam.setConType(item.getConType());
csLineFeignClient.updateLine(csLineParam);
});
}
}
break;
default:
break;
}
break;
default:
break;
}
csLogsFeignClient.addUserLog(logDto);
} }
csLogsFeignClient.addUserLog(logDto);
} }
@@ -481,11 +554,59 @@ public class MqttMessageHandler {
break; break;
case 4658: case 4658:
log.info("获取文件流信息"); log.info("获取文件流信息");
redisUtil.saveByKeyWithExpire(AppRedisKey.FILE_PART.concat(appFileMessage.getMsg().getName() + appFileMessage.getMid()), appFileMessage.getMid(),3600L); if (Objects.equals(fileDto.getCode(),AccessEnum.SUCCESS.getCode())){
appFileStreamMessageTemplate.sendMember(appFileMessage); appFileStreamMessageTemplate.sendMember(appFileMessage);
}
//todo 处理文件信息,先缓存起来,后期在询问
else if (Objects.equals(fileDto.getCode(),AccessEnum.REFUSE_WAIT.getCode())) {
log.info("需要缓存请求的文件信息");
}
break; break;
default: default:
break; break;
} }
} }
/**
* type含义
* 1询问设备软件信息
* 2模块信息
* 3监测点pt/ct信息
*/
public void askDevData(String nDid,String version,Integer type,Integer mid){
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);
AskDataDto askDataDto = new AskDataDto();
askDataDto.setDataAttr(0);
askDataDto.setOperate(1);
askDataDto.setStartTime(-1);
askDataDto.setEndTime(-1);
switch (type) {
case 1:
reqAndResParam.setDid(2);
askDataDto.setCldid(0);
askDataDto.setDataType(1);
break;
case 2:
reqAndResParam.setDid(1);
askDataDto.setCldid(-1);
askDataDto.setDataType(2);
break;
case 3:
reqAndResParam.setDid(2);
askDataDto.setCldid(-1);
askDataDto.setDataType(2);
break;
default:
break;
}
reqAndResParam.setMsg(askDataDto);
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid, new Gson().toJson(reqAndResParam),1,false);
}
} }

View File

@@ -1,47 +1,47 @@
package com.njcn.access.runner; //package com.njcn.access.runner;
//
import com.njcn.access.service.ICsEquipmentDeliveryService; //import com.njcn.access.service.ICsEquipmentDeliveryService;
import com.njcn.access.service.ICsTopicService; //import com.njcn.access.service.ICsTopicService;
import com.njcn.access.service.impl.CsDeviceServiceImpl; //import com.njcn.access.service.impl.CsDeviceServiceImpl;
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO; //import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments; //import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner; //import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component; //import org.springframework.stereotype.Component;
//
import javax.annotation.Resource; //import javax.annotation.Resource;
import java.util.List; //import java.util.List;
import java.util.Objects; //import java.util.Objects;
//
/** ///**
* 类的介绍:用来重新发起设备的接入,存在程序意外停止了,缓存失效导致无法更新装置的状态,所以需要在程序启动时发起设备的接入 // * 类的介绍:用来重新发起设备的接入,存在程序意外停止了,缓存失效导致无法更新装置的状态,所以需要在程序启动时发起设备的接入
* // *
* @author xuyang // * @author xuyang
* @version 1.0.0 // * @version 1.0.0
* @createTime 2023/8/28 13:57 // * @createTime 2023/8/28 13:57
*/ // */
@Component //@Component
@Slf4j //@Slf4j
public class AccessApplicationRunner implements ApplicationRunner { //public class AccessApplicationRunner implements ApplicationRunner {
//
@Resource // @Resource
private CsDeviceServiceImpl csDeviceService; // private CsDeviceServiceImpl csDeviceService;
//
@Resource // @Resource
private ICsTopicService csTopicService; // private ICsTopicService csTopicService;
//
@Resource // @Resource
private ICsEquipmentDeliveryService csEquipmentDeliveryService; // private ICsEquipmentDeliveryService csEquipmentDeliveryService;
//
@Override // @Override
public void run(ApplicationArguments args){ // public void run(ApplicationArguments args){
List<CsEquipmentDeliveryPO> list = csEquipmentDeliveryService.getAll(); // List<CsEquipmentDeliveryPO> list = csEquipmentDeliveryService.getAll();
list.forEach(item->{ // list.forEach(item->{
String version = csTopicService.getVersion(item.getNdid()); // String version = csTopicService.getVersion(item.getNdid());
if (!Objects.isNull(version)){ // if (!Objects.isNull(version)){
csDeviceService.devAccess(item.getNdid(),version); // csDeviceService.devAccess(item.getNdid(),version);
} // }
}); // });
} // }
//
} //}

View File

@@ -217,7 +217,6 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
csLedgerParam.setSort(0); csLedgerParam.setSort(0);
csLedgerService.addLedgerTree(csLedgerParam); csLedgerService.addLedgerTree(csLedgerParam);
List<CsModelDto> modelId = objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + devAccessParam.getNDid())); List<CsModelDto> modelId = objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + devAccessParam.getNDid()));
Integer clDid = null, moduleNumber = null;
//2.新增装置-模板关系、获取电能质量的逻辑设备id //2.新增装置-模板关系、获取电能质量的逻辑设备id
for (CsModelDto item : modelId) { for (CsModelDto item : modelId) {
CsDevModelRelationAddParm csDevModelRelationAddParm = new CsDevModelRelationAddParm(); CsDevModelRelationAddParm csDevModelRelationAddParm = new CsDevModelRelationAddParm();
@@ -225,36 +224,6 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
csDevModelRelationAddParm.setModelId(item.getModelId()); csDevModelRelationAddParm.setModelId(item.getModelId());
csDevModelRelationAddParm.setDid(item.getDid()); csDevModelRelationAddParm.setDid(item.getDid());
csDevModelRelationService.addDevModelRelation(csDevModelRelationAddParm); csDevModelRelationService.addDevModelRelation(csDevModelRelationAddParm);
if (Objects.equals(item.getType(),1)){
clDid = item.getDid();
}
if (Objects.equals(item.getType(),0)){
moduleNumber = item.getModuleNumber();
}
}
if (Objects.isNull(clDid)){
logDto.setResult(0);
logDto.setFailReason(AccessResponseEnum.CLDID_IS_NULL.getMessage());
csLogsFeignClient.addUserLog(logDto);
throw new BusinessException(AccessResponseEnum.CLDID_IS_NULL);
}
if (Objects.isNull(moduleNumber)){
logDto.setResult(0);
logDto.setFailReason(AccessResponseEnum.MODULE_NUMBER_IS_NULL.getMessage());
csLogsFeignClient.addUserLog(logDto);
throw new BusinessException(AccessResponseEnum.MODULE_NUMBER_IS_NULL);
}
askDevData(devAccessParam.getNDid(),AccessEnum.L_DEV_INFO.getCode(),version,clDid);
List<RspDataDto.LdevInfo> list = new ArrayList<>();
//等待mqtt数据
Thread.sleep(500);
String key = AppRedisKey.LINE_DATA + devAccessParam.getNDid();
list = objectToList2(redisUtil.getObjectByKey(key));
if (CollectionUtils.isEmpty(list)){
logDto.setResult(0);
logDto.setFailReason(AccessResponseEnum.LDEVINFO_IS_NULL.getMessage());
csLogsFeignClient.addUserLog(logDto);
throw new BusinessException(AccessResponseEnum.LDEVINFO_IS_NULL);
} }
//3.监测点表录入关系 //3.监测点表录入关系
for (DevAccessParam.LineParam item : devAccessParam.getList()) { for (DevAccessParam.LineParam item : devAccessParam.getList()) {
@@ -266,24 +235,14 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
po.setPosition(item.getPosition()); po.setPosition(item.getPosition());
po.setClDid(0); po.setClDid(0);
if (Objects.equals(DicDataEnum.GRID_SIDE.getCode(),location)){ if (Objects.equals(DicDataEnum.GRID_SIDE.getCode(),location)){
RspDataDto.LdevInfo po1 = list.stream().filter(s -> Objects.equals(s.getClDid(),1)).findFirst().orElse(null);
po.setLineId(devAccessParam.getNDid() + "1"); po.setLineId(devAccessParam.getNDid() + "1");
param.setId(devAccessParam.getNDid() + "1"); param.setId(devAccessParam.getNDid() + "1");
appLineTopologyDiagramPo.setLineId(devAccessParam.getNDid() + "1"); appLineTopologyDiagramPo.setLineId(devAccessParam.getNDid() + "1");
po.setVolGrade(po1.getVolGrade());
po.setPtRatio(po1.getPtRatio());
po.setCtRatio(po1.getCtRatio());
po.setConType(po1.getConType());
po.setClDid(1); po.setClDid(1);
} else if (Objects.equals(DicDataEnum.LOAD_SIDE.getCode(),location)){ } else if (Objects.equals(DicDataEnum.LOAD_SIDE.getCode(),location)){
RspDataDto.LdevInfo po1 = list.stream().filter(s -> Objects.equals(s.getClDid(),2)).findFirst().orElse(null);
po.setLineId(devAccessParam.getNDid() + "2"); po.setLineId(devAccessParam.getNDid() + "2");
param.setId(devAccessParam.getNDid() + "2"); param.setId(devAccessParam.getNDid() + "2");
appLineTopologyDiagramPo.setLineId(devAccessParam.getNDid() + "2"); appLineTopologyDiagramPo.setLineId(devAccessParam.getNDid() + "2");
po.setVolGrade(po1.getVolGrade());
po.setPtRatio(po1.getPtRatio());
po.setCtRatio(po1.getCtRatio());
po.setConType(po1.getConType());
po.setClDid(2); po.setClDid(2);
} else { } else {
po.setLineId(devAccessParam.getNDid() + "0"); po.setLineId(devAccessParam.getNDid() + "0");
@@ -321,34 +280,13 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
po.setSubUserId(RequestUtil.getUserIndex()); po.setSubUserId(RequestUtil.getUserIndex());
po.setDeviceId(vo.getId()); po.setDeviceId(vo.getId());
csDeviceUserService.saveBatch(Collections.singletonList(po)); csDeviceUserService.saveBatch(Collections.singletonList(po));
//6.录入软件信息 SoftInfo //6.修改装置状态
askDevData(devAccessParam.getNDid(),AccessEnum.SOFT_INFO.getCode(),version,0);
//等待mqtt数据
Thread.sleep(500);
String key2 = AppRedisKey.SOFTINFO + devAccessParam.getNDid();
RspDataDto.SoftInfo softInfo = JSON.parseObject(JSON.toJSONString(redisUtil.getObjectByKey(key2)), RspDataDto.SoftInfo.class);
if (Objects.isNull(softInfo)){
logDto.setResult(0);
logDto.setFailReason(AccessResponseEnum.SOFTINFO_IS_NULL.getMessage());
csLogsFeignClient.addUserLog(logDto);
throw new BusinessException(AccessResponseEnum.SOFTINFO_IS_NULL);
}
//记录设备软件信息
CsSoftInfoPO csSoftInfoPo = new CsSoftInfoPO();
BeanUtils.copyProperties(softInfo,csSoftInfoPo);
csSoftInfoPo.setAppDate(new SimpleDateFormat("yyyy-MM-dd").parse(softInfo.getAppDate()));
csSoftInfoService.save(csSoftInfoPo);
//更新设备表软件信息
csEquipmentDeliveryService.updateSoftInfoBynDid(devAccessParam.getNDid(),csSoftInfoPo.getId(),moduleNumber);
//修改装置状态
csEquipmentDeliveryService.updateStatusBynDid(devAccessParam.getNDid(), AccessEnum.REGISTERED.getCode()); csEquipmentDeliveryService.updateStatusBynDid(devAccessParam.getNDid(), AccessEnum.REGISTERED.getCode());
//7.发起自动接入请求 //7.发起自动接入请求
devAccess(devAccessParam.getNDid(),version); devAccess(devAccessParam.getNDid(),version);
//8.删除redis监测点模板信息 //8.删除redis监测点模板信息
redisUtil.delete(AppRedisKey.MODEL + devAccessParam.getNDid()); redisUtil.delete(AppRedisKey.MODEL + devAccessParam.getNDid());
redisUtil.delete(AppRedisKey.LINE + devAccessParam.getNDid()); redisUtil.delete(AppRedisKey.LINE + devAccessParam.getNDid());
redisUtil.delete(AppRedisKey.LINE_DATA + devAccessParam.getNDid());
redisUtil.delete(AppRedisKey.SOFTINFO + devAccessParam.getNDid());
//存储日志 //存储日志
csLogsFeignClient.addUserLog(logDto); csLogsFeignClient.addUserLog(logDto);
//存储设备调试日志表 //存储设备调试日志表
@@ -437,33 +375,4 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
} }
return urlList; return urlList;
} }
/**
* 平台向设备发送数据命令
*/
public void askDevData(String nDid,Integer dataType,String version,Integer did){
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
reqAndResParam.setMid(1);
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_6.getCode()));
reqAndResParam.setExpire(-1);
AskDataDto askDataDto = new AskDataDto();
askDataDto.setDataAttr(0);
askDataDto.setOperate(1);
askDataDto.setStartTime(-1);
askDataDto.setEndTime(-1);
if (Objects.equals(dataType,AccessEnum.SOFT_INFO.getCode())){
askDataDto.setCldid(0);
reqAndResParam.setDid(0);
askDataDto.setDataType(1);
} else if (Objects.equals(dataType,AccessEnum.L_DEV_INFO.getCode())){
askDataDto.setCldid(-1);
reqAndResParam.setDid(did);
askDataDto.setDataType(2);
}
reqAndResParam.setMsg(askDataDto);
logger.info("询问设备软件信息(监测点信息):" + new Gson().toJson(reqAndResParam));
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid, new Gson().toJson(reqAndResParam),1,false);
}
} }

View File

@@ -12,8 +12,16 @@ import com.njcn.access.enums.AccessEnum;
import com.njcn.access.enums.TypeEnum; import com.njcn.access.enums.TypeEnum;
import com.njcn.access.pojo.dto.ReqAndResDto; import com.njcn.access.pojo.dto.ReqAndResDto;
import com.njcn.access.pojo.dto.mqtt.MqttClientDto; import com.njcn.access.pojo.dto.mqtt.MqttClientDto;
import com.njcn.access.service.ICsEquipmentDeliveryService;
import com.njcn.access.service.impl.CsDeviceServiceImpl;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.utils.PubUtils;
import com.njcn.csdevice.pojo.po.CsLinePO; import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.oss.utils.FileStorageUtil;
import com.njcn.redis.utils.RedisUtil;
import io.lettuce.core.protocol.CompleteableCommand; import io.lettuce.core.protocol.CompleteableCommand;
import lombok.extern.slf4j.Slf4j;
import okhttp3.Credentials; import okhttp3.Credentials;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
@@ -26,15 +34,15 @@ import org.springframework.test.context.web.WebAppConfiguration;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.zip.CRC32;
/** /**
* Unit test for simple App. * Unit test for simple App.
@@ -42,6 +50,7 @@ import java.util.stream.Collectors;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@WebAppConfiguration @WebAppConfiguration
@SpringBootTest(classes = AccessBootApplication.class) @SpringBootTest(classes = AccessBootApplication.class)
@Slf4j
public class AppTest public class AppTest
{ {
/** /**
@@ -56,6 +65,35 @@ public class AppTest
@Resource @Resource
private MqttPublisher publisher; private MqttPublisher publisher;
@Resource
private FileStorageUtil fileStorageUtil;
@Resource
private ICsEquipmentDeliveryService csEquipmentDeliveryService;
@Resource
private CsDeviceServiceImpl csDeviceService;
@Resource
private RedisUtil redisUtil;
@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);
}
}
@Test @Test
public void test() { public void test() {
@@ -69,49 +107,43 @@ public class AppTest
// String key = String.valueOf(IdUtil.getSnowflake().nextId()); // String key = String.valueOf(IdUtil.getSnowflake().nextId());
// System.out.println("key==:" + key); // System.out.println("key==:" + key);
List<CsLinePO> csLinePoList = new ArrayList<>(); // List<CsLinePO> csLinePoList = new ArrayList<>();
CsLinePO po1 = new CsLinePO(); // CsLinePO po1 = new CsLinePO();
po1.setPosition("1"); // po1.setPosition("1");
CsLinePO po2= new CsLinePO(); // CsLinePO po2= new CsLinePO();
po2.setPosition("2"); // po2.setPosition("2");
CsLinePO po3= new CsLinePO(); // CsLinePO po3= new CsLinePO();
po3.setPosition("3"); // po3.setPosition("3");
CsLinePO po4= new CsLinePO(); // CsLinePO po4= new CsLinePO();
po4.setPosition("1"); // po4.setPosition("1");
//
// csLinePoList.add(po1);
// csLinePoList.add(po2);
// csLinePoList.add(po3);
// csLinePoList.add(po4);
// List<String> l = csLinePoList.stream().map(CsLinePO::getPosition).collect(Collectors.toList());
// System.out.println("l===:" + l);
// List<String> lineList = l.stream().filter(e-> Collections.frequency(l,e) > 1).distinct().collect(Collectors.toList());
// System.out.println("lineList==:" + lineList);
csLinePoList.add(po1); // String text = "TkosUFEsMTk5OQ0KNiw2QSwwRA0KMSxBz+C159G5LEEstefRuSxWLDAuMDYyMjU2LDAuMDAwMDAwLDAuMDAwMDAwLC0zMjc2NywzMjc2NywzODAsMzgwLFMNCjIsQs/gtefRuSxCLLXn0bksViwwLjA2MjI1NiwwLjAwMDAwMCwwLjAwMDAwMCwtMzI3NjcsMzI3NjcsMzgwLDM4MCxTDQozLEPP4LXn0bksQyy159G5LFYsMC4wNjIyNTYsMC4wMDAwMDAsMC4wMDAwMDAsLTMyNzY3LDMyNzY3LDM4MCwzODAsUw0KNCxBz+C158H3LEEstefB9yxBLDAuMDE1MjU5LDAuMDAwMDAwLDAuMDAwMDAwLC0zMjc2NywzMjc2NywyMDAsNSxTDQo1LELP4LXnwfcsQiy158H3LEEsMC4wMTUyNTksMC4wMDAwMDAsMC4wMDAwMDAsLTMyNzY3LDMyNzY3LDIwMCw1LFMNCjYsQ8/gtefB9yxDLLXnwfcsQSwwLjAxNTI1OSwwLjAwMDAwMCwwLjAwMDAwMCwtMzI3NjcsMzI3NjcsMjAwLDUsUw0KNTANCjENCjEyODAwLDcxNjgNCjA1LzA5LzIwMjMsMTU6NTQ6MDIuMTM2MDAwDQowNS8wOS8yMDIzLDE1OjU0OjAyLjIzNjAwMA0KQklOQVJZDQoxDQo=";
csLinePoList.add(po2); // byte[] byteArray = Base64.getDecoder().decode(text);
csLinePoList.add(po3); // InputStream inputStream = new ByteArrayInputStream(byteArray);
csLinePoList.add(po4); // fileStorageUtil.uploadStreamSpecifyName(inputStream, "configuration/","xuyang.cfg");
List<String> l = csLinePoList.stream().map(CsLinePO::getPosition).collect(Collectors.toList());
System.out.println("l===:" + l);
List<String> lineList = l.stream().filter(e-> Collections.frequency(l,e) > 1).distinct().collect(Collectors.toList());
System.out.println("lineList==:" + lineList);
}
// public static void main(String[] args) {
// try { // try {
// String username = "ac760c62395cecec"; // inputStream.close();
// String password = "k0vGfe5xOE2Bl4DCF73uahcknvcwoKOEDPnOkMvuSBB";
//
// OkHttpClient client = new OkHttpClient();
//
// Request request = new Request.Builder()
// .url("http://192.168.1.18:18083/api/v5/clients/access-boot123456")
// .header("Content-Type", "application/json")
// .header("Authorization", Credentials.basic(username, password))
// .build();
//
// Response response = client.newCall(request).execute();
// response.body();
// String res = Objects.requireNonNull(response.body()).string();
//
// Gson gson = new Gson();
// MqttClientDto mqttClientDto = gson.fromJson(res, new TypeToken<MqttClientDto>(){}.getType());
// System.out.println("mqttClientDto==:" + mqttClientDto.isConnected());
//
// } catch (IOException e) { // } catch (IOException e) {
// e.printStackTrace(); // e.printStackTrace();
// } // }
// }
// 要计算CRC32的数据
String data = "Hello, World!";
CRC32 crc32 = new CRC32();
crc32.update(data.getBytes());
long crc32Value = crc32.getValue();
// 将CRC32校验值转换为16进制字符串
String crc32Str = String.format("%08X", crc32Value);
System.out.println("CRC32校验值为: " + crc32Str);
}
} }

View File

@@ -6,9 +6,13 @@ import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.utils.PubUtils; import com.njcn.common.utils.PubUtils;
import com.njcn.csdevice.api.CsLineFeignClient; import com.njcn.csdevice.api.CsLineFeignClient;
import com.njcn.csdevice.api.DataArrayFeignClient; import com.njcn.csdevice.api.DataArrayFeignClient;
import com.njcn.csdevice.api.EquipmentFeignClient;
import com.njcn.csdevice.pojo.param.DataArrayParam; import com.njcn.csdevice.pojo.param.DataArrayParam;
import com.njcn.csdevice.pojo.po.CsDataArray; import com.njcn.csdevice.pojo.po.CsDataArray;
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
import com.njcn.csdevice.pojo.po.CsLinePO; import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
import com.njcn.cswarn.api.CsEquipmentAlarmFeignClient;
import com.njcn.influx.pojo.constant.InfluxDBTableConstant; import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
import com.njcn.influx.utils.InfluxDbUtils; import com.njcn.influx.utils.InfluxDbUtils;
import com.njcn.mq.message.AppAutoDataMessage; import com.njcn.mq.message.AppAutoDataMessage;
@@ -56,6 +60,8 @@ public class StatServiceImpl implements IStatService {
private final RedisUtil redisUtil; private final RedisUtil redisUtil;
private final EquipmentFeignClient equipmentFeignClient;
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void analysis(AppAutoDataMessage appAutoDataMessage) { public void analysis(AppAutoDataMessage appAutoDataMessage) {
@@ -86,6 +92,8 @@ public class StatServiceImpl implements IStatService {
if(Objects.isNull(object2)) { if(Objects.isNull(object2)) {
saveData(); saveData();
} }
//获取当前设备信息
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(appAutoDataMessage.getId()).getData();
if (CollectionUtil.isNotEmpty(list)){ if (CollectionUtil.isNotEmpty(list)){
List<String> recordList = new ArrayList<>(); List<String> recordList = new ArrayList<>();
for (AppAutoDataMessage.DataArray item : list) { for (AppAutoDataMessage.DataArray item : list) {
@@ -116,7 +124,7 @@ public class StatServiceImpl implements IStatService {
} else { } else {
dataArrayList = objectToList(object); dataArrayList = objectToList(object);
} }
List<String> result = assembleData(lineId,dataArrayList,item,appAutoDataMessage.getMsg().getClDid(),dataArrayParam.getStatMethod()); List<String> result = assembleData(lineId,dataArrayList,item,appAutoDataMessage.getMsg().getClDid(),dataArrayParam.getStatMethod(),po.getProcess());
recordList.addAll(result); recordList.addAll(result);
} }
if (CollectionUtil.isNotEmpty(recordList)){ if (CollectionUtil.isNotEmpty(recordList)){
@@ -183,7 +191,7 @@ public class StatServiceImpl implements IStatService {
/** /**
* influxDB数据组装 * influxDB数据组装
*/ */
public List<String> assembleData(String lineId,List<CsDataArray> dataArrayList,AppAutoDataMessage.DataArray item,Integer clDid,String statMethod) { public List<String> assembleData(String lineId,List<CsDataArray> dataArrayList,AppAutoDataMessage.DataArray item,Integer clDid,String statMethod,Integer process) {
List<String> records = new ArrayList<String>(); List<String> records = new ArrayList<String>();
//解码 //解码
List<Float> floats = PubUtils.byteArrayToFloatList(Base64.getDecoder().decode(item.getData())); List<Float> floats = PubUtils.byteArrayToFloatList(Base64.getDecoder().decode(item.getData()));
@@ -206,6 +214,7 @@ public class StatServiceImpl implements IStatService {
tags.put(InfluxDBTableConstant.PHASIC_TYPE,dataArrayList.get(i).getPhase()); tags.put(InfluxDBTableConstant.PHASIC_TYPE,dataArrayList.get(i).getPhase());
tags.put(InfluxDBTableConstant.VALUE_TYPE,statMethod); tags.put(InfluxDBTableConstant.VALUE_TYPE,statMethod);
tags.put(InfluxDBTableConstant.CL_DID,clDid.toString()); tags.put(InfluxDBTableConstant.CL_DID,clDid.toString());
tags.put(InfluxDBTableConstant.PROCESS,process.toString());
Map<String,Object> fields = new HashMap<>(); Map<String,Object> fields = new HashMap<>();
fields.put(dataArrayList.get(i).getName(),floats.get(i)); fields.put(dataArrayList.get(i).getName(),floats.get(i));
fields.put(InfluxDBTableConstant.IS_ABNORMAL,item.getDataTag()); fields.put(InfluxDBTableConstant.IS_ABNORMAL,item.getDataTag());

View File

@@ -1,29 +1,33 @@
package com.njcn; package com.njcn;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import com.alibaba.nacos.shaded.com.google.gson.Gson; import com.njcn.influx.utils.InfluxDbUtils;
import com.njcn.common.utils.PubUtils;
import com.njcn.csdevice.pojo.po.CsDataArray;
import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.mq.message.AppAutoDataMessage;
import com.njcn.redis.pojo.enums.AppRedisKey;
import com.njcn.redis.utils.RedisUtil; import com.njcn.redis.utils.RedisUtil;
import com.njcn.stat.StatBootApplication;
import org.influxdb.InfluxDB; import org.influxdb.InfluxDB;
import org.influxdb.dto.BatchPoints; import org.influxdb.dto.BatchPoints;
import org.influxdb.dto.Point; import org.influxdb.dto.Point;
import org.junit.Test; import org.junit.Test;
import org.springframework.web.bind.annotation.ResponseBody; import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.*; import java.util.ArrayList;
import java.util.concurrent.*; import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertTrue;
/** /**
* Unit test for simple App. * Unit test for simple App.
*/ */
@RunWith(SpringRunner.class)
@WebAppConfiguration
@SpringBootTest(classes = StatBootApplication.class)
public class AppTest public class AppTest
{ {
@@ -33,6 +37,7 @@ public class AppTest
@Resource @Resource
private InfluxDbUtils influxDbUtils; private InfluxDbUtils influxDbUtils;
/** /**
* Rigorous Test :-) * Rigorous Test :-)
*/ */
@@ -42,4 +47,39 @@ public class AppTest
assertTrue( true ); assertTrue( true );
} }
@Test
public void addRedis() {
Map<String, String> tags1 = new HashMap<>();
tags1.put("LineID", "4");
tags1.put("Phasic_Type", "A");
Map<String, Object> fields1 = new HashMap<>();
fields1.put("RMS", 4.1111);
fields1.put("RMS_AB", 4.1111);
fields1.put("RMS_BC", 4.1111);
fields1.put("RMS_CA", 4.1111);
Map<String, String> tags2 = new HashMap<>();
tags2.put("LineID", "5");
tags2.put("Phasic_Type", "A");
Map<String, Object> fields2 = new HashMap<>();
fields2.put("RMS", 5.1111);
fields2.put("RMS_AB", 5.1111);
fields2.put("RMS_BC", 5.1111);
// 一条记录值。注意生产环境不要用System.currentTimeMillis(),因为数据量大会产生重复时间戳,导致数据丢失,要用数据自己的时间戳,这里只做演示)
Point point1 = influxDbUtils.pointBuilder("Data_v", System.currentTimeMillis(), TimeUnit.MILLISECONDS, tags1, fields1);
Point point2 = influxDbUtils.pointBuilder("Data_v", System.currentTimeMillis(), TimeUnit.MILLISECONDS, tags2, fields2);
// BatchPoints batchPoints1 = BatchPoints.database("Data_v").tag("LineID", "4").tag("Phasic_Type","A").retentionPolicy("").consistency(ConsistencyLevel.ALL).precision(TimeUnit.MILLISECONDS).build();
BatchPoints batchPoints1 = BatchPoints.database("test").tag("LineID", "4").tag("Phasic_Type", "A").retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
batchPoints1.point(point1);
BatchPoints batchPoints2 = BatchPoints.database("test").tag("LineID", "5").tag("Phasic_Type", "A").retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
// 将两条记录添加到batchPoints中
batchPoints2.point(point2);
// 将不同的batchPoints序列化后一次性写入数据库提高写入速度
List<String> records = new ArrayList<String>();
records.add(batchPoints1.lineProtocol());
records.add(batchPoints2.lineProtocol());
// 将两条数据批量插入到数据库中
influxDbUtils.batchInsert("test", "", InfluxDB.ConsistencyLevel.ALL, TimeUnit.MILLISECONDS, records);
}
} }

View File

@@ -23,9 +23,6 @@ public class FileInfoDto {
private String fileChkType; private String fileChkType;
@ApiModelProperty("报文数量")
private Integer number;
private String startTime; private String startTime;
private String endTime; private String endTime;

View File

@@ -3,7 +3,8 @@ package com.njcn.zlevent.pojo.dto;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.util.Map; import java.util.HashSet;
import java.util.List;
/** /**
* 类的介绍: * 类的介绍:
@@ -15,6 +16,12 @@ import java.util.Map;
@Data @Data
public class FileStreamDto implements Serializable { public class FileStreamDto implements Serializable {
private Map<Integer,String> map; private Integer total;
private String nDid;
private Integer frameLen;
private List<Integer> list;
} }

View File

@@ -73,5 +73,10 @@ public class CsWave {
*/ */
private LocalDateTime createTime; private LocalDateTime createTime;
/**
* 文件获取状态 0:获取失败 1:获取成功)
*/
private Integer status;
} }

View File

@@ -1,13 +1,23 @@
package com.njcn.zlevent.listener; package com.njcn.zlevent.listener;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.shaded.com.google.gson.Gson;
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.ReqAndResDto;
import com.njcn.common.pojo.exception.BusinessException; import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.redis.pojo.enums.AppRedisKey; import com.njcn.redis.pojo.enums.AppRedisKey;
import com.njcn.redis.utils.RedisUtil; import com.njcn.redis.utils.RedisUtil;
import com.njcn.stat.enums.StatResponseEnum; import com.njcn.stat.enums.StatResponseEnum;
import com.njcn.system.api.EpdFeignClient; import com.njcn.system.api.EpdFeignClient;
import com.njcn.system.pojo.dto.EpdDTO; import com.njcn.system.pojo.dto.EpdDTO;
import com.njcn.zlevent.pojo.dto.FileStreamDto;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.data.redis.connection.Message; import org.springframework.data.redis.connection.Message;
@@ -16,9 +26,11 @@ import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.IntStream;
/** /**
* @author hongawen * @author hongawen
@@ -35,6 +47,12 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
@Resource @Resource
private RedisUtil redisUtil; private RedisUtil redisUtil;
@Resource
private CsTopicFeignClient csTopicFeignClient;
@Resource
private MqttPublisher publisher;
public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) { public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
super(listenerContainer); super(listenerContainer);
} }
@@ -63,5 +81,45 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
}); });
redisUtil.saveByKeyWithExpire(AppRedisKey.ELE_EPD_PQD,map,3600L); redisUtil.saveByKeyWithExpire(AppRedisKey.ELE_EPD_PQD,map,3600L);
} }
//文件流规定时间未收全,请求缺失数据,需要一帧一帧询问
else if (expiredKey.startsWith(AppRedisKey.FILE_PART_TIME)) {
List<Integer> missingList = new ArrayList<>();
String fileName = expiredKey.split(AppRedisKey.FILE_PART_TIME)[1];
Object object1 = redisUtil.getObjectByKey(AppRedisKey.FILE_PART.concat(fileName));
FileStreamDto dto = JSON.parseObject(JSON.toJSONString(object1), FileStreamDto.class);
int start = 1;
int end = dto.getTotal();
IntStream.rangeClosed(start, end)
.filter(i -> !dto.getList().contains(i))
.forEach(missingNumber -> {
log.info("缺失的数字:{}",missingNumber);
missingList.add(missingNumber);
});
redisUtil.saveByKey(AppRedisKey.FILE_PART_MISSING.concat(fileName), missingList);
Integer offset = (missingList.get(0) - 1) * dto.getFrameLen();
askMissingFileStream(dto.getNDid(),missingList.get(0),fileName,offset,dto.getFrameLen());
}
} }
public void askMissingFileStream(String nDid, Integer mid, String fileName, Integer offset, Integer len) {
String version = csTopicFeignClient.find(nDid).getData();
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
reqAndResParam.setMid(mid);
reqAndResParam.setDid(0);
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_9.getCode()));
reqAndResParam.setExpire(-1);
String json = "{Name:\""+fileName+"\",Offset:"+offset+",Len:"+len+"}";
JSONObject jsonObject = JSONObject.fromObject(json);
reqAndResParam.setMsg(jsonObject);
publisher.send("/Pfm/DevFileCmd/"+version+"/"+nDid,new Gson().toJson(reqAndResParam),1,false);
log.info("请求文件流报文:" + new Gson().toJson(reqAndResParam));
}
} }

View File

@@ -20,4 +20,10 @@ public interface ICsWaveService extends IService<CsWave> {
*/ */
int findCountByName(String fileName); int findCountByName(String fileName);
/**
* 修改文件状态
* @param fileName
*/
void updateCsWave(String fileName);
} }

View File

@@ -1,6 +1,7 @@
package com.njcn.zlevent.service.impl; package com.njcn.zlevent.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.zlevent.mapper.CsWaveMapper; import com.njcn.zlevent.mapper.CsWaveMapper;
import com.njcn.zlevent.pojo.po.CsWave; import com.njcn.zlevent.pojo.po.CsWave;
@@ -21,7 +22,14 @@ public class CsWaveServiceImpl extends ServiceImpl<CsWaveMapper, CsWave> impleme
@Override @Override
public int findCountByName(String fileName) { public int findCountByName(String fileName) {
LambdaQueryWrapper<CsWave> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<CsWave> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.like(CsWave::getRcdName,fileName); lambdaQueryWrapper.like(CsWave::getRcdName,fileName).eq(CsWave::getStatus,1);
return this.baseMapper.selectCount(lambdaQueryWrapper); return this.baseMapper.selectCount(lambdaQueryWrapper);
} }
@Override
public void updateCsWave(String fileName) {
LambdaUpdateWrapper<CsWave> lambdaQueryWrapper = new LambdaUpdateWrapper<>();
lambdaQueryWrapper.eq(CsWave::getRcdName,fileName).set(CsWave::getStatus,1);
this.update(lambdaQueryWrapper);
}
} }

View File

@@ -6,6 +6,7 @@ import com.alibaba.nacos.shaded.com.google.gson.Gson;
import com.njcn.common.pojo.exception.BusinessException; import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.csdevice.api.CsLineFeignClient; import com.njcn.csdevice.api.CsLineFeignClient;
import com.njcn.csdevice.api.EquipmentFeignClient; import com.njcn.csdevice.api.EquipmentFeignClient;
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
import com.njcn.csdevice.pojo.po.CsLinePO; import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csharmonic.pojo.po.CsEventPO; import com.njcn.csharmonic.pojo.po.CsEventPO;
import com.njcn.influx.pojo.constant.InfluxDBTableConstant; import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
@@ -86,7 +87,7 @@ public class EventServiceImpl implements IEventService {
lineInfo(appEventMessage.getId()); lineInfo(appEventMessage.getId());
} }
//获取装置id //获取装置id
String deviceId = equipmentFeignClient.findDevByNDid(appEventMessage.getId()).getData().getId(); CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(appEventMessage.getId()).getData();
try { try {
//处理事件数据 //处理事件数据
List<AppEventMessage.DataArray> dataArray = appEventMessage.getMsg().getDataArray(); List<AppEventMessage.DataArray> dataArray = appEventMessage.getMsg().getDataArray();
@@ -95,7 +96,9 @@ public class EventServiceImpl implements IEventService {
//事件入库 //事件入库
CsEventPO csEvent = new CsEventPO(); CsEventPO csEvent = new CsEventPO();
csEvent.setId(id); csEvent.setId(id);
csEvent.setDeviceId(deviceId); csEvent.setDeviceId(po.getId());
csEvent.setProcess(po.getProcess());
csEvent.setCode(item.getCode());
eventTime = timeFormat(item.getDataTimeSec(),item.getDataTimeUSec()); eventTime = timeFormat(item.getDataTimeSec(),item.getDataTimeUSec());
csEvent.setStartTime(eventTime); csEvent.setStartTime(eventTime);
tag = item.getName(); tag = item.getName();
@@ -145,7 +148,7 @@ public class EventServiceImpl implements IEventService {
//事件处理日志库 //事件处理日志库
CsEventLogs csEventLogs = new CsEventLogs(); CsEventLogs csEventLogs = new CsEventLogs();
csEventLogs.setLineId(lineId); csEventLogs.setLineId(lineId);
csEventLogs.setDeviceId(deviceId); csEventLogs.setDeviceId(po.getId());
csEventLogs.setStartTime(timeFormat(item.getDataTimeSec(),item.getDataTimeUSec())); csEventLogs.setStartTime(timeFormat(item.getDataTimeSec(),item.getDataTimeUSec()));
csEventLogs.setTag(item.getName()); csEventLogs.setTag(item.getName());
csEventLogs.setStatus(1); csEventLogs.setStatus(1);
@@ -162,12 +165,12 @@ public class EventServiceImpl implements IEventService {
} }
//推送事件逻辑处理 && cs_event_user入库 //推送事件逻辑处理 && cs_event_user入库
for (AppEventMessage.DataArray item : dataArray) { for (AppEventMessage.DataArray item : dataArray) {
sendEventUtils.sendUser(1,item.getType(),deviceId,item.getName(),eventTime,appEventMessage.getId(),id); sendEventUtils.sendUser(1,item.getType(),po.getId(),item.getName(),eventTime,appEventMessage.getId(),id);
} }
} catch (Exception e) { } catch (Exception e) {
CsEventLogs csEventLogs = new CsEventLogs(); CsEventLogs csEventLogs = new CsEventLogs();
csEventLogs.setLineId(lineId); csEventLogs.setLineId(lineId);
csEventLogs.setDeviceId(deviceId); csEventLogs.setDeviceId(po.getId());
csEventLogs.setStartTime(eventTime); csEventLogs.setStartTime(eventTime);
csEventLogs.setTag(tag); csEventLogs.setTag(tag);
csEventLogs.setStatus(0); csEventLogs.setStatus(0);

View File

@@ -4,7 +4,9 @@ import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.text.StrPool; import cn.hutool.core.text.StrPool;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.common.utils.ConcurrentHashSet;
import com.alibaba.nacos.shaded.com.google.gson.Gson; import com.alibaba.nacos.shaded.com.google.gson.Gson;
import com.alibaba.nacos.shaded.com.google.gson.GsonBuilder;
import com.github.tocrhz.mqtt.publisher.MqttPublisher; import com.github.tocrhz.mqtt.publisher.MqttPublisher;
import com.njcn.access.api.CsTopicFeignClient; import com.njcn.access.api.CsTopicFeignClient;
import com.njcn.access.enums.AccessEnum; import com.njcn.access.enums.AccessEnum;
@@ -34,9 +36,7 @@ import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.ByteArrayInputStream; import java.io.*;
import java.io.IOException;
import java.io.InputStream;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
@@ -73,9 +73,9 @@ public class FileServiceImpl implements IFileService {
@Override @Override
public void analysisFileInfo(AppFileMessage appFileMessage) { public void analysisFileInfo(AppFileMessage appFileMessage) {
if (Objects.equals(appFileMessage.getCode(), AccessEnum.SUCCESS.getCode())){ if (Objects.equals(appFileMessage.getCode(), AccessEnum.SUCCESS.getCode())){
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS");
int mid = 1; int mid = 1;
int range = 51200; int range = 51200;
Integer fileSize = appFileMessage.getMsg().getFileInfo().getFileSize();
String fileName = appFileMessage.getMsg().getFileInfo().getName(); String fileName = appFileMessage.getMsg().getFileInfo().getName();
//缓存文件信息用于文件流拼接 //缓存文件信息用于文件流拼接
FileInfoDto fileInfoDto = new FileInfoDto(); FileInfoDto fileInfoDto = new FileInfoDto();
@@ -95,18 +95,22 @@ public class FileServiceImpl implements IFileService {
fileInfoDto.setFileCheck(appFileMessage.getMsg().getFileInfo().getFileCheck()); fileInfoDto.setFileCheck(appFileMessage.getMsg().getFileInfo().getFileCheck());
fileInfoDto.setFileChkType(appFileMessage.getMsg().getFileInfo().getFileChkType()); fileInfoDto.setFileChkType(appFileMessage.getMsg().getFileInfo().getFileChkType());
fileInfoDto.setLocation(waveTimeDto.getLocation()); fileInfoDto.setLocation(waveTimeDto.getLocation());
//文件流请求 判断文件大小是否需要分片请求,单次文件大小为50k //存储波形文件
if (fileSize <= range){ CsWave csWave = new CsWave();
askFileStream(appFileMessage.getId(),mid,fileName,0,fileSize); csWave.setNdid(appFileMessage.getId());
fileInfoDto.setNumber(1); csWave.setCreateTime(LocalDateTime.now());
redisUtil.delete(AppRedisKey.FILE_PART.concat(fileInfoDto.getName() + mid)); csWave.setStartTime(LocalDateTime.parse(waveTimeDto.getStartTime(), fmt));
redisUtil.saveByKey(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileInfoDto.getName()), fileInfoDto); csWave.setEndTime(LocalDateTime.parse(waveTimeDto.getEndTime(), fmt));
} else { csWave.setRcdName(fileName);
int total = (int)Math.ceil(fileSize*1.0/range); csWave.setLocation(waveTimeDto.getLocation());
fileInfoDto.setNumber(total); csWave.setFileSize(appFileMessage.getMsg().getFileInfo().getFileSize());
redisUtil.saveByKey(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileInfoDto.getName()), fileInfoDto); csWave.setCheckType(appFileMessage.getMsg().getFileInfo().getFileChkType());
askFileStream(appFileMessage.getId(), 1, fileName, 0, range); csWave.setCheckNumber(appFileMessage.getMsg().getFileInfo().getFileCheck());
} csWave.setStatus(0);
csWaveService.save(csWave);
//请求当前文件的数据
askFileStream(appFileMessage.getId(),mid,fileName,-1,range);
redisUtil.saveByKey(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileInfoDto.getName()), fileInfoDto);
redisUtil.delete(AppRedisKey.TIME+fileName); redisUtil.delete(AppRedisKey.TIME+fileName);
} else { } else {
throw new BusinessException(AccessResponseEnum.RESPONSE_ERROR); throw new BusinessException(AccessResponseEnum.RESPONSE_ERROR);
@@ -115,7 +119,10 @@ public class FileServiceImpl implements IFileService {
@Override @Override
public void analysisFileStream(AppFileMessage appFileMessage) { public void analysisFileStream(AppFileMessage appFileMessage) {
int range = 51200; DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS");
String filePath;
List<Integer> list = new ArrayList<>();
FileStreamDto fileStreamDto = new FileStreamDto();
//波形文件上传成功后,将文件信息存储一下,方便后期查看 //波形文件上传成功后,将文件信息存储一下,方便后期查看
CsWave csWave = new CsWave(); CsWave csWave = new CsWave();
csWave.setNdid(appFileMessage.getId()); csWave.setNdid(appFileMessage.getId());
@@ -124,99 +131,112 @@ public class FileServiceImpl implements IFileService {
CsEventFileLogs csEventLogs = new CsEventFileLogs(); CsEventFileLogs csEventLogs = new CsEventFileLogs();
csEventLogs.setNdid(appFileMessage.getId()); csEventLogs.setNdid(appFileMessage.getId());
csEventLogs.setFileName(appFileMessage.getMsg().getName()); csEventLogs.setFileName(appFileMessage.getMsg().getName());
csEventLogs.setStatus(0);
try { try {
//todo 目前文件先只处理暂态事件的,后续有其他文件再做处理 //todo 目前文件先只处理波形事件的,后续有其他文件再做处理
String fileName = appFileMessage.getMsg().getName(); String fileName = appFileMessage.getMsg().getName();
String lsFileName =fileName.split(StrUtil.SLASH)[fileName.split(StrUtil.SLASH).length - 1];
//获取缓存的文件信息
Object fileInfo = redisUtil.getObjectByKey(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileName));
FileInfoDto fileInfoDto = JSON.parseObject(JSON.toJSONString(fileInfo), FileInfoDto.class);
//1.判断当前文件是否之前缓存过,没缓存,则先缓存(这边缓存两条记录,一条是用来判断超时的,还有一条记录文件数据,文件数据目前没有过期时间,文件数据收完才会删除)
//2.缓存了判断收到的报文个数是否和总个数一致,一致则解析文件;不一致则更新缓存
//3.超时判断: 30s分钟未收到相关文件信息核查文件个数看丢失哪些帧重新请求
if(fileName.contains(".cfg") || fileName.contains(".dat")) { if(fileName.contains(".cfg") || fileName.contains(".dat")) {
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS"); if (appFileMessage.getMsg().getFrameTotal() == 1){
FileStreamDto fileStreamDto = new FileStreamDto(); //解析文件入库
String filePath; filePath = fileStream(1,null,appFileMessage.getMsg().getData(),fileName,appFileMessage.getId());
Map<Integer,String> map = new HashMap<>(); csEventLogs.setStatus(1);
//获取缓存的文件信息 csEventLogs.setRemark("当前文件1帧,全部收到,解析成功!");
Object fileInfo = redisUtil.getObjectByKey(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileName)); csEventLogs.setNowStep(1);
FileInfoDto fileInfoDto = JSON.parseObject(JSON.toJSONString(fileInfo), FileInfoDto.class); csEventLogs.setAllStep(1);
//文件流 csEventLogs.setIsAll(1);
Object object = redisUtil.getObjectByKey(fileName); //更新文件信息
/* csWaveService.updateCsWave(fileName);
* 文件解析存储逻辑 //波形文件关联事件
* 1.如果文件只有1帧那就直接解析文件流 filePath = filePath.replaceAll(GeneralConstant.CFG,"").replaceAll(GeneralConstant.DAT,"");
* 2.如果文件有多帧,判断当前帧是否是最后一帧,是则直接解析文件,不是则先缓存起来,等收完全再开始解析文件 List<String> eventList = correlateEvents(fileInfoDto,filePath,fileName);
*/ //波形文件解析成图片
if (Objects.isNull(object)){ if (CollectionUtil.isNotEmpty(eventList)){
//第一次录入 eventList.forEach(wavePicFeignClient::getWavePics);
if(fileInfoDto.getNumber() == 1) {
//直接解析文件
filePath = fileStream(1,null,appFileMessage.getMsg().getData(),fileName,appFileMessage.getId());
csEventLogs.setStatus(1);
csEventLogs.setRemark("当前文件1帧,全部收到,解析成功!");
csEventLogs.setNowStep(1);
csEventLogs.setAllStep(1);
csEventLogs.setIsAll(1);
//记录文件信息
createCsWave(csWave,fileInfoDto,fmt,fileName);
//波形文件关联事件
filePath = filePath.replaceAll(GeneralConstant.CFG,"").replaceAll(GeneralConstant.DAT,"");
List<String> eventList = correlateEvents(fileInfoDto,filePath,fileName);
//波形文件解析成图片
if (CollectionUtil.isNotEmpty(eventList)){
eventList.forEach(wavePicFeignClient::getWavePics);
}
redisUtil.delete(fileName);
redisUtil.delete(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileInfoDto.getName()));
} else {
//缓存文件
map.put(appFileMessage.getMid(),appFileMessage.getMsg().getData());
fileStreamDto.setMap(map);
redisUtil.saveByKey(fileName, fileStreamDto);
csEventLogs.setStatus(1);
csEventLogs.setRemark("当前文件"+fileInfoDto.getNumber()+"帧,这是第"+appFileMessage.getMid()+"帧,记录成功!");
csEventLogs.setNowStep(appFileMessage.getMid());
csEventLogs.setAllStep(fileInfoDto.getNumber());
csEventLogs.setIsAll(0);
log.info("当前文件 {} 帧,这是第 {} 帧报文,记录成功", fileInfoDto.getNumber(), appFileMessage.getMid());
//收到文件后,继续请求下一帧报文
askFileStream(appFileMessage.getId(), appFileMessage.getMid()+1, fileName, appFileMessage.getMid() * range, range);
redisUtil.delete(AppRedisKey.FILE_PART.concat(fileInfoDto.getName() + appFileMessage.getMid()));
} }
redisUtil.delete(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileInfoDto.getName()));
} else { } else {
//分帧传递数据,需要校验收到的文件个数 Object object1 = redisUtil.getObjectByKey(AppRedisKey.FILE_PART.concat(fileName));
fileStreamDto = JSON.parseObject(JSON.toJSONString(object), FileStreamDto.class); if (Objects.isNull(object1)){
Map<Integer,String> l1 = fileStreamDto.getMap(); fileStreamDto.setTotal(appFileMessage.getMsg().getFrameTotal());
l1.put(appFileMessage.getMid(),appFileMessage.getMsg().getData()); fileStreamDto.setNDid(appFileMessage.getId());
if (l1.size() == fileInfoDto.getNumber()){ fileStreamDto.setFrameLen(appFileMessage.getMsg().getFrameLen());
//解析文件 list.add(appFileMessage.getMsg().getFrameCurr());
filePath = fileStream(fileInfoDto.getNumber(),l1,null,fileName,appFileMessage.getId()); fileStreamDto.setList(list);
csEventLogs.setStatus(1); csEventLogs.setStatus(1);
csEventLogs.setRemark("当前文件"+l1.size()+"帧,这是第"+l1.size()+"帧,全部收到,解析成功!"); csEventLogs.setRemark("当前文件"+appFileMessage.getMsg().getFrameTotal()+"帧,这是第"+appFileMessage.getMsg().getFrameCurr()+"帧,记录成功!");
csEventLogs.setNowStep(l1.size()); csEventLogs.setNowStep(appFileMessage.getMsg().getFrameCurr());
csEventLogs.setAllStep(l1.size()); csEventLogs.setAllStep(appFileMessage.getMsg().getFrameTotal());
csEventLogs.setIsAll(1);
log.info("当前文件 {} 帧,这是第 {} 帧报文,全部收到,解析成功!", l1.size(), l1.size());
//记录文件信息
createCsWave(csWave,fileInfoDto,fmt,fileName);
//波形文件关联事件
filePath = filePath.replaceAll(GeneralConstant.CFG,"").replaceAll(GeneralConstant.DAT,"");
List<String> eventList = correlateEvents(fileInfoDto,filePath,fileName);
//波形文件解析成图片
if (CollectionUtil.isNotEmpty(eventList)){
eventList.forEach(wavePicFeignClient::getWavePics);
}
redisUtil.delete(fileName);
redisUtil.delete(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileInfoDto.getName()));
} else {
//缓存
fileStreamDto = new FileStreamDto();
fileStreamDto.setMap(l1);
redisUtil.saveByKey(fileName, fileStreamDto);
csEventLogs.setStatus(1);
csEventLogs.setRemark("当前文件"+fileInfoDto.getNumber()+"帧,这是第"+appFileMessage.getMid()+"帧,记录成功!");
csEventLogs.setNowStep(appFileMessage.getMid());
csEventLogs.setAllStep(fileInfoDto.getNumber());
csEventLogs.setIsAll(0); csEventLogs.setIsAll(0);
log.info("当前文件 {} 帧,这是第 {} 帧报文,记录成功", fileInfoDto.getNumber(), appFileMessage.getMid()); redisUtil.saveByKeyWithExpire(AppRedisKey.FILE_PART_TIME.concat(appFileMessage.getMsg().getName()), null, 30L);
//收到文件后,继续请求下一帧报文 redisUtil.saveByKey(AppRedisKey.FILE_PART.concat(appFileMessage.getMsg().getName()), fileStreamDto);
askFileStream(appFileMessage.getId(), appFileMessage.getMid()+1, fileName, appFileMessage.getMid() * range, range); //将数据写入临时文件
redisUtil.delete(AppRedisKey.FILE_PART.concat(fileInfoDto.getName() + appFileMessage.getMid())); appendFile(lsFileName,appFileMessage.getMsg().getFrameCurr(),appFileMessage.getMsg().getData());
log.info("当前文件 {} 帧,这是第 {} 帧报文,记录成功", appFileMessage.getMsg().getFrameTotal(), appFileMessage.getMsg().getFrameCurr());
} else {
FileStreamDto dto = JSON.parseObject(JSON.toJSONString(object1), FileStreamDto.class);
//防止出现录入重复数据,做个判断
if (!dto.getList().contains(appFileMessage.getMsg().getFrameCurr())) {
dto.getList().add(appFileMessage.getMsg().getFrameCurr());
if (Objects.equals(dto.getTotal(), dto.getList().size())) {
Map<Integer, String> filePartMap = readFile(lsFileName);
filePartMap.put(appFileMessage.getMsg().getFrameCurr(), appFileMessage.getMsg().getData());
//解析文件
filePath = fileStream(appFileMessage.getMsg().getFrameTotal(), filePartMap, null, fileName, appFileMessage.getId());
csEventLogs.setStatus(1);
csEventLogs.setRemark("当前文件" + appFileMessage.getMsg().getFrameTotal() + "帧,这是第" + appFileMessage.getMsg().getFrameCurr() + "帧,全部收到,解析成功!");
csEventLogs.setNowStep(appFileMessage.getMsg().getFrameCurr());
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)) {
eventList.forEach(wavePicFeignClient::getWavePics);
}
redisUtil.delete(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileInfoDto.getName()));
redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(appFileMessage.getMsg().getName()));
redisUtil.delete(AppRedisKey.FILE_PART.concat(appFileMessage.getMsg().getName()));
redisUtil.delete(AppRedisKey.FILE_PART_MISSING.concat(appFileMessage.getMsg().getName()));
//删除临时文件
File file = new File(lsFileName);
if (file.exists()) {
file.delete();
}
} else {
Object object2 = redisUtil.getObjectByKey(AppRedisKey.FILE_PART_MISSING.concat(fileName));
csEventLogs.setStatus(1);
csEventLogs.setRemark("当前文件" + appFileMessage.getMsg().getFrameTotal() + "帧,这是第" + appFileMessage.getMsg().getFrameCurr() + "帧,记录成功!");
csEventLogs.setNowStep(appFileMessage.getMsg().getFrameCurr());
csEventLogs.setAllStep(appFileMessage.getMsg().getFrameTotal());
csEventLogs.setIsAll(0);
if (Objects.isNull(object2)) {
redisUtil.saveByKeyWithExpire(AppRedisKey.FILE_PART_TIME.concat(appFileMessage.getMsg().getName()), null, 30L);
} else {
redisUtil.saveByKeyWithExpire(AppRedisKey.FILE_PART_TIME.concat(appFileMessage.getMsg().getName()), null, 1L);
}
redisUtil.saveByKey(AppRedisKey.FILE_PART.concat(appFileMessage.getMsg().getName()), dto);
//将数据写入临时文件
appendFile(lsFileName, appFileMessage.getMsg().getFrameCurr(), appFileMessage.getMsg().getData());
log.info("当前文件 {} 帧,这是第 {} 帧报文,记录成功", appFileMessage.getMsg().getFrameTotal(), appFileMessage.getMsg().getFrameCurr());
}
} else {
csEventLogs.setStatus(1);
csEventLogs.setRemark("当前文件为重复帧,这是第" + appFileMessage.getMsg().getFrameCurr() + "帧,不做记录!");
csEventLogs.setNowStep(appFileMessage.getMsg().getFrameCurr());
csEventLogs.setAllStep(appFileMessage.getMsg().getFrameTotal());
csEventLogs.setIsAll(0);
}
} }
} }
csEventLogs.setCompleteTime(LocalDateTime.now()); csEventLogs.setCompleteTime(LocalDateTime.now());
@@ -238,7 +258,6 @@ public class FileServiceImpl implements IFileService {
} }
} }
/** /**
* 请求文件流信息 * 请求文件流信息
*/ */
@@ -254,6 +273,7 @@ public class FileServiceImpl implements IFileService {
JSONObject jsonObject = JSONObject.fromObject(json); JSONObject jsonObject = JSONObject.fromObject(json);
reqAndResParam.setMsg(jsonObject); reqAndResParam.setMsg(jsonObject);
publisher.send("/Pfm/DevFileCmd/"+version+"/"+nDid,new Gson().toJson(reqAndResParam),1,false); publisher.send("/Pfm/DevFileCmd/"+version+"/"+nDid,new Gson().toJson(reqAndResParam),1,false);
log.info("请求文件流报文:" + new Gson().toJson(reqAndResParam));
} }
/** /**
@@ -354,18 +374,81 @@ public class FileServiceImpl implements IFileService {
} }
/** /**
* 生成波形记录 * 数据写入文件
*/ */
public void createCsWave(CsWave csWave, FileInfoDto fileInfoDto, DateTimeFormatter fmt, String fileName) { public void appendFile(String filePath, Integer key, String value) {
csWave.setStartTime(LocalDateTime.parse(fileInfoDto.getStartTime(), fmt)); Map<Integer, String> map = new HashMap<>();
csWave.setEndTime(LocalDateTime.parse(fileInfoDto.getEndTime(), fmt)); map.put(key, value);
csWave.setRcdName(fileName); try {
csWave.setLocation(fileInfoDto.getLocation()); FileOutputStream fileOutputStream = new FileOutputStream(filePath, true);
csWave.setFileSize(fileInfoDto.getFileSize()); MyObjectOutputStream outputStream = new MyObjectOutputStream(fileOutputStream);
csWave.setCheckType(fileInfoDto.getFileChkType()); outputStream.writeObject(map);
csWave.setCheckNumber(fileInfoDto.getFileCheck()); outputStream.close();
csWaveService.save(csWave); fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
} }
/**
* 文件读取数据
*/
public Map<Integer, String> readFile(String filePath) {
Map<Integer, String> readMap = new HashMap<>();
List<Map<Integer, String>> mapList = new ArrayList<>();
MyObjectInputStream inputStream = null;
try {
inputStream = new MyObjectInputStream(new FileInputStream(filePath));
while (true) {
try {
Map<Integer, String> loadedMap = (Map<Integer, String>) inputStream.readObject();
mapList.add(loadedMap);
} catch (EOFException | ClassNotFoundException e) {
// 读取到文件末尾时退出循环
break;
}
}
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
for (Map<Integer, String> map : mapList) {
for (Map.Entry<Integer, String> entry : map.entrySet()) {
readMap.put(entry.getKey(),entry.getValue());
}
}
return readMap;
}
/**
* -----------------------------------------------
* 重写方法,因为每次文件追加会添加文件头部信息,导致读取错误
*/
class MyObjectOutputStream extends ObjectOutputStream {
public MyObjectOutputStream(OutputStream out) throws IOException {
super(out);
}
@Override
protected void writeStreamHeader() throws IOException {
//重写读取头部信息方法:不写入头部信息
super.reset();
}
}
class MyObjectInputStream extends ObjectInputStream {
public MyObjectInputStream(InputStream in) throws IOException {
super(in);
}
@Override
protected void readStreamHeader() throws IOException {
//重写读取头部信息方法:什么也不做
}
}
/**
* 重写方法结束
* -----------------------------------------------
*/
} }

View File

@@ -1,14 +1,64 @@
package com.njcn; package com.njcn;
import static org.junit.Assert.assertTrue; import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.shaded.com.google.gson.Gson;
import com.njcn.csharmonic.api.WavePicFeignClient;
import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
import com.njcn.influx.utils.InfluxDbUtils;
import com.njcn.oss.utils.FileStorageUtil;
import com.njcn.redis.pojo.enums.AppRedisKey;
import com.njcn.redis.utils.RedisUtil;
import com.njcn.user.api.AppUserFeignClient;
import com.njcn.user.api.UserFeignClient;
import com.njcn.user.pojo.po.User;
import com.njcn.zlevent.ZlEventBootApplication;
import com.njcn.zlevent.pojo.constant.ZlConstant;
import com.njcn.zlevent.pojo.dto.FileStreamDto;
import com.njcn.zlevent.pojo.dto.WaveTimeDto;
import org.influxdb.InfluxDB;
import org.influxdb.dto.BatchPoints;
import org.influxdb.dto.Point;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import javax.annotation.Resource;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;
import static org.junit.Assert.assertTrue;
/** /**
* Unit test for simple App. * Unit test for simple App.
*/ */
public class AppTest @RunWith(SpringRunner.class)
{ @WebAppConfiguration
@SpringBootTest(classes = ZlEventBootApplication.class)
public class AppTest {
@Resource
private RedisUtil redisUtil;
@Resource
private FileStorageUtil fileStorageUtil;
@Resource
private WavePicFeignClient wavePicFeignClient;
@Resource
private AppUserFeignClient appUserFeignClient;
@Resource
private InfluxDbUtils influxDbUtils;
/** /**
* Rigorous Test :-) * Rigorous Test :-)
*/ */
@@ -17,4 +67,160 @@ public class AppTest
{ {
assertTrue( true ); assertTrue( true );
} }
@Test
public void test3() {
List<String> records = new ArrayList<String>();
long timeSec = 1695892557L;
Map<String, String> tags = new HashMap<>();
tags.put(InfluxDBTableConstant.UUID,"000002");
Map<String,Object> fields = new HashMap<>();
fields.put("location","电网侧");
//fixme 这边前置传递的应该是UTC时间,但是前置说是传递的北京时间,讨论了一下没太理解。这边暂时先这样处理,influx入库处理成北京时间,减去8小时。
Point point = influxDbUtils.pointBuilder("zl_test", System.currentTimeMillis(), TimeUnit.MILLISECONDS, tags, fields);
BatchPoints batchPoints = BatchPoints.database(influxDbUtils.getDbName()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
batchPoints.point(point);
records.add(batchPoints.lineProtocol());
influxDbUtils.batchInsert(influxDbUtils.getDbName(), "", InfluxDB.ConsistencyLevel.ALL, TimeUnit.MILLISECONDS, records);
}
@Test
public void test2() throws IOException {
String localPath = "C:\\Users\\徐扬\\Desktop\\123.dat";
FileOutputStream fileOut = new FileOutputStream(localPath,true);
ObjectOutputStream objectOut = new ObjectOutputStream(fileOut);
Map<Integer, String> mapToWrite = new HashMap<>();
mapToWrite.put(1, "value1");
mapToWrite.put(2, "value2");
mapToWrite.put(3, "value3");
Map<Integer, String> mapToWrite2 = new HashMap<>();
mapToWrite2.put(11, "value1");
mapToWrite2.put(22, "value2");
mapToWrite2.put(33, "value3");
objectOut.writeObject(mapToWrite);
objectOut.writeObject(mapToWrite2);
objectOut.close();
fileOut.close();
}
@Test
public void test222() throws IOException {
List<Map<String, Integer>> mapList = new ArrayList<>();
String localPath = "C:\\Users\\徐扬\\Desktop\\123.dat";
ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(localPath));
while (true) {
try {
Map<String, Integer> loadedMap = (Map<String, Integer>) inputStream.readObject();
mapList.add(loadedMap);
} catch (EOFException | ClassNotFoundException e) {
// 读取到文件末尾时退出循环
break;
}
}
System.out.println("list集合为" + mapList);
}
@Test
public void test22() {
String filePath = "C:\\Users\\徐扬\\Desktop\\PQS_PQM1_000005_20231007_141638_348.dat";
Map<Integer, String> readMap = new HashMap<>();
try {
BufferedReader reader = new BufferedReader(new FileReader(filePath));
Gson gson = new Gson();
String line;
while ((line = reader.readLine()) != null) {
readMap = gson.fromJson(line, Map.class);
}
// 关闭流
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("从文件读取的Map: " + readMap.size());
}
@Test
public void test4() {
String fileName = "/sd0:1/comtrade/PQS_PQM1_000005_20231007_141638_348.dat";
Object object1 = redisUtil.getObjectByKey(AppRedisKey.FILE_PART.concat(fileName));
FileStreamDto dto = JSON.parseObject(JSON.toJSONString(object1), FileStreamDto.class);
System.out.println("数据个数:" + dto.getList().size());
System.out.println("总个数:" + dto.getTotal());
IntStream.rangeClosed(1, 476)
.filter(i -> !dto.getList().contains(i))
.forEach(missingNumber -> System.out.println("缺失的数字: " + missingNumber));
}
@Test
public void test5() {
String name = "/sd0:1/comtrade/PQS_PQM1_000005_20231007_141638_348.dat";
redisUtil.saveByKeyWithExpire(AppRedisKey.FILE_PART_TIME.concat(name), null, 10L);
}
@Test
public void test() {
long time = 1694598894;
Double millisecond = 60000.0;
long subtleTime = 99000L;
long millisecondValue = millisecond.longValue() * 1000;
long time1 = time * 1000000 + subtleTime;
long time2 = time * 1000000 + subtleTime + millisecondValue;
String time1String = String.valueOf(time1);
String time2String = String.valueOf(time2);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time11 = time1String.substring(time1String.length() - 6);
String time111 = time1String.substring(0,time1String.length() - 6);
String formatTime1 = format.format(Long.parseLong(time111) * 1000);
String time22 = time2String.substring(time2String.length() - 6);
String time222 = time2String.substring(0,time2String.length() - 6);
String formatTime2 = format.format(Long.parseLong(time222) * 1000);
WaveTimeDto waveTimeDto = new WaveTimeDto();
waveTimeDto.setStartTime(formatTime1 + "." + time11);
waveTimeDto.setEndTime(formatTime2 + "." + time22);
System.out.println("waveTimeDto===:" + waveTimeDto);
// long endTime;
// //开始时间
// time = (time - 8*3600) * 1000000;
// //结束时间
// long millisecondValue = millisecond.longValue() * 1000;
// endTime = time + subtleTime + millisecondValue;
// System.out.println("endTime==:" + endTime);
// String endTimeString = String.valueOf(endTime);
// String time1 = endTimeString.substring(endTimeString.length() - 6);
// String time2 = endTimeString.substring(0,endTimeString.length() - 6);
// System.out.println("time1==:" + time1);
// System.out.println("time2==:" + time2);
// long longTime2 = Long.parseLong(time2)/1000;
// SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// System.out.println("time==:" + time);
// System.out.println("longTime2==:" + longTime2);
// String formatTime1 = format.format(time/1000000);
// String formatTime2 = format.format(longTime2);
// System.out.println("formatTime1==:" + formatTime1);
// System.out.println("formatTime2==:" + formatTime2);
// WaveTimeDto waveTimeDto = new WaveTimeDto();
// waveTimeDto.setStartTime(formatTime1 + "." + subtleTime);
// waveTimeDto.setEndTime(formatTime2 + "." + time1);
// System.out.println("waveTimeDto==:" + waveTimeDto);
}
} }

View File

@@ -4,12 +4,10 @@ import com.njcn.middle.rocket.constant.EnhanceMessageConstant;
import com.njcn.middle.rocket.handler.EnhanceConsumerMessageHandler; import com.njcn.middle.rocket.handler.EnhanceConsumerMessageHandler;
import com.njcn.mq.constant.BusinessTopic; import com.njcn.mq.constant.BusinessTopic;
import com.njcn.mq.constant.MessageStatus; import com.njcn.mq.constant.MessageStatus;
import com.njcn.mq.message.AppAutoDataMessage;
import com.njcn.mq.message.AppFileMessage; import com.njcn.mq.message.AppFileMessage;
import com.njcn.redis.pojo.enums.AppRedisKey; import com.njcn.redis.pojo.enums.AppRedisKey;
import com.njcn.redis.pojo.enums.RedisKeyEnum; import com.njcn.redis.pojo.enums.RedisKeyEnum;
import com.njcn.redis.utils.RedisUtil; import com.njcn.redis.utils.RedisUtil;
import com.njcn.stat.api.StatFeignClient;
import com.njcn.system.api.RocketMqLogFeignClient; import com.njcn.system.api.RocketMqLogFeignClient;
import com.njcn.system.pojo.po.RocketmqMsgErrorLog; import com.njcn.system.pojo.po.RocketmqMsgErrorLog;
import com.njcn.zlevent.api.FileFeignClient; import com.njcn.zlevent.api.FileFeignClient;

View File

@@ -34,7 +34,7 @@
<!--中间件目标地址--> <!--中间件目标地址-->
<middle.server.url>192.168.1.13</middle.server.url> <middle.server.url>192.168.1.13</middle.server.url>
<!--微服务模块发布地址--> <!--微服务模块发布地址-->
<service.server.url>192.168.1.139</service.server.url> <service.server.url>127.0.0.1</service.server.url>
<!--docker仓库地址--> <!--docker仓库地址-->
<docker.server.url>192.168.1.13</docker.server.url> <docker.server.url>192.168.1.13</docker.server.url>
<!--nacos的ip:port--> <!--nacos的ip:port-->
@@ -54,7 +54,7 @@
<docker.registry.name>njcn</docker.registry.name> <docker.registry.name>njcn</docker.registry.name>
<!--切换阿里&华为的配置sdk--> <!--切换阿里&华为的配置sdk-->
<micro.sdk>common-microservice</micro.sdk> <micro.sdk>common-microservice</micro.sdk>
<!--<micro.sdk>common-huawei</micro.sdk>--> <!-- <micro.sdk>common-huawei</micro.sdk>-->
<docker.operate>site</docker.operate> <docker.operate>site</docker.operate>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<maven.compiler.source>8</maven.compiler.source> <maven.compiler.source>8</maven.compiler.source>