Compare commits
73 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9fc3e126d9 | |||
| 498fbe930e | |||
| 200004913e | |||
| 71107fe36d | |||
| 216225f0cb | |||
| 2eeabddf5c | |||
| 6983cd39fe | |||
| 15f84c1bc0 | |||
| 2cad107c29 | |||
| 0f532033b0 | |||
| b418855d02 | |||
|
|
9774172c0b | ||
| da75f74218 | |||
|
|
7670793d5e | ||
|
|
6f87784ddf | ||
| 6dcee1f6c3 | |||
| 02d321d4d4 | |||
| f5b97d83b3 | |||
| 8041c5f27e | |||
| 48c79b721e | |||
| eaacce339e | |||
| fafcaf3bf0 | |||
| c2b48d6830 | |||
| 6b24e49651 | |||
| b3d2727a64 | |||
| 441b5d04fe | |||
| 292e8b58a5 | |||
| d20c869bad | |||
| 71b9bee182 | |||
| f227fe3c3f | |||
| 56c9c69fc9 | |||
| 004de8f307 | |||
| bda31ce52a | |||
| 4d1af87153 | |||
| e34b5ba46e | |||
| 33b9fae9ef | |||
| a369ae6160 | |||
| 6714a6f582 | |||
| 2910770be1 | |||
| cd8cf60683 | |||
| 528f376f6d | |||
| 1d29a03a3c | |||
| 9ea6a00cb5 | |||
| c33490c4fc | |||
| 0d4db672e1 | |||
| 37ffaa3ad4 | |||
| c4db053243 | |||
| 0fda2354eb | |||
| 1a3e443be1 | |||
| f88baa52be | |||
| 72351c612b | |||
| 1bb9ad1cf7 | |||
| 186eec4f7e | |||
| 0b32c09fdb | |||
| 28b23e9c52 | |||
| 7277299c66 | |||
| 49642066f5 | |||
| 826970357e | |||
| 11713e9b68 | |||
| 6d3a1dd735 | |||
| 72150a3acc | |||
| 19999a582e | |||
| 7293d9b84d | |||
| 40a6cd608c | |||
| 1fb08ab66c | |||
| c6e938e7a0 | |||
| 52d2dda01c | |||
| f9926d16f8 | |||
| 87fc735969 | |||
| cc22afd877 | |||
| 2ec0024d0f | |||
| f0a22192fb | |||
| 98b901e6ab |
@@ -20,6 +20,15 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-mq</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.tocrhz</groupId>
|
||||
<artifactId>mqtt-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-core</artifactId>
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
package com.njcn.access.api;
|
||||
|
||||
import com.njcn.access.api.fallback.AskDeviceDataClientFallbackFactory;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@@ -41,4 +34,7 @@ public interface AskDeviceDataFeignClient {
|
||||
@PostMapping("/askRealData")
|
||||
HttpResult<String> askRealData(@RequestParam("nDid") String nDid, @RequestParam("idx") Integer idx, @RequestParam("clDId") Integer clDId);
|
||||
|
||||
@PostMapping("/askCldRealData")
|
||||
HttpResult<String> askCldRealData(@RequestParam("devId") String devId, @RequestParam("lineId") String lineId, @RequestParam("nodeId") String nodeId, @RequestParam("idx") Integer idx);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.njcn.access.api;
|
||||
|
||||
import com.njcn.access.api.fallback.CsDeviceClientFallbackFactory;
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.ACCESS_BOOT, path = "/device", fallbackFactory = CsDeviceClientFallbackFactory.class,contextId = "device")
|
||||
|
||||
public interface CsDeviceFeignClient {
|
||||
|
||||
@PostMapping("/updateRunStatus")
|
||||
HttpResult<String> updateRunStatus(@RequestParam("nDid") String nDid, @RequestParam("runStatus") Integer runStatus);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.njcn.access.api;
|
||||
|
||||
import com.njcn.access.api.fallback.CsHeartbeatClientFallbackFactory;
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.mq.message.HeartbeatTimeoutMessage;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.ACCESS_BOOT, path = "/heartbeat", fallbackFactory = CsHeartbeatClientFallbackFactory.class,contextId = "heartbeat")
|
||||
public interface CsHeartbeatFeignClient {
|
||||
|
||||
@PostMapping("/handleHeartbeat")
|
||||
@ApiOperation("处理物联设备心跳")
|
||||
HttpResult<String> handleHeartbeat(@RequestBody HeartbeatTimeoutMessage message);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.njcn.access.api;
|
||||
|
||||
import com.njcn.access.api.fallback.CsLineLatestDataClientFallbackFactory;
|
||||
import com.njcn.access.pojo.po.CsLineLatestData;
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.ACCESS_BOOT, path = "/csLineLatestData", fallbackFactory = CsLineLatestDataClientFallbackFactory.class,contextId = "csLineLatestData")
|
||||
|
||||
public interface CsLineLatestDataFeignClient {
|
||||
|
||||
@PostMapping("/add")
|
||||
HttpResult<String> addData(@RequestBody CsLineLatestData csLineLatestData);
|
||||
|
||||
@PostMapping("/list")
|
||||
HttpResult<List<CsLineLatestData>> listData();
|
||||
|
||||
}
|
||||
@@ -73,6 +73,12 @@ public class AskDeviceDataClientFallbackFactory implements FallbackFactory<AskDe
|
||||
log.error("{}异常,降级处理,异常为:{}","询问装置实时数据",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<String> askCldRealData(String devId, String lineId, String nodeId, Integer idx) {
|
||||
log.error("{}异常,降级处理,异常为:{}","询问云前置实时数据",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.njcn.access.api.fallback;
|
||||
|
||||
import com.njcn.access.api.CsDeviceFeignClient;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class CsDeviceClientFallbackFactory implements FallbackFactory<CsDeviceFeignClient> {
|
||||
@Override
|
||||
public CsDeviceFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if (cause.getCause() instanceof BusinessException) {
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new CsDeviceFeignClient() {
|
||||
|
||||
@Override
|
||||
public HttpResult<String> updateRunStatus(String nDid, Integer runStatus) {
|
||||
log.error("{}异常,降级处理,异常为:{}","云设备状态调整异常",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.njcn.access.api.fallback;
|
||||
|
||||
import com.njcn.access.api.CsHeartbeatFeignClient;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.mq.message.HeartbeatTimeoutMessage;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class CsHeartbeatClientFallbackFactory implements FallbackFactory<CsHeartbeatFeignClient> {
|
||||
@Override
|
||||
public CsHeartbeatFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if (cause.getCause() instanceof BusinessException) {
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new CsHeartbeatFeignClient() {
|
||||
|
||||
@Override
|
||||
public HttpResult<String> handleHeartbeat(HeartbeatTimeoutMessage message) {
|
||||
log.error("{}异常,降级处理,异常为:{}","处理物联设备心跳数据异常",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.njcn.access.api.fallback;
|
||||
|
||||
import com.njcn.access.api.CsLineLatestDataFeignClient;
|
||||
import com.njcn.access.pojo.po.CsLineLatestData;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class CsLineLatestDataClientFallbackFactory implements FallbackFactory<CsLineLatestDataFeignClient> {
|
||||
@Override
|
||||
public CsLineLatestDataFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if (cause.getCause() instanceof BusinessException) {
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new CsLineLatestDataFeignClient() {
|
||||
|
||||
@Override
|
||||
public HttpResult<String> addData(CsLineLatestData csLineLatestData) {
|
||||
log.error("{}异常,降级处理,异常为:{}","新增治理设备最近数据时间",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<List<CsLineLatestData>> listData() {
|
||||
log.error("{}异常,降级处理,异常为:{}","查询整体数据",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public enum AccessResponseEnum {
|
||||
DEV_MODEL_NOT_FIND("A0303","装置型号未找到!"),
|
||||
DEV_IS_NOT_ZL("A0303","注册装置不是直连装置!"),
|
||||
DEV_IS_NOT_WG("A0303","注册装置不是网关!"),
|
||||
DEV_IS_NOT_PORTABLE("A0303","注册装置不是便携式装置!"),
|
||||
DEV_IS_NOT_PORTABLE("A0303","注册装置不是便携式装置或者在线监测设备!"),
|
||||
|
||||
REGISTER_RESPONSE_ERROR("A0304","装置注册,装置侧应答失败!"),
|
||||
ACCESS_RESPONSE_ERROR("A0304","装置注册,装置侧应答失败!"),
|
||||
@@ -56,7 +56,7 @@ public enum AccessResponseEnum {
|
||||
CTRL_DICT_MISSING("A0307","Ctrl字典数据缺失!"),
|
||||
WAVE_INFO_MISSING("A0307","波形参数缺失!"),
|
||||
|
||||
MODEL_MISS("A0308","模板信息缺失!"),
|
||||
MODEL_MISS("A0308","询问模板信息超时,设备未响应!"),
|
||||
MODEL_VERSION_ERROR("A0308","询问装置模板信息错误"),
|
||||
UPLOAD_ERROR("A0308","平台上送文件异常"),
|
||||
RELOAD_UPLOAD_ERROR("A0308","平台重新上送文件异常"),
|
||||
@@ -73,7 +73,17 @@ public enum AccessResponseEnum {
|
||||
PROCESS_ERROR("A0311","调试流程异常,请先进行功能调试、出厂调试!"),
|
||||
|
||||
FILE_CHECK_ERROR("A0312","文件校验码不一致!"),
|
||||
;
|
||||
|
||||
CLD_MODEL_EXIST("A0313","云前置模板已存在,请先删除再录入!"),
|
||||
|
||||
/**
|
||||
* A3001 ~ A3099 用于zlevent模块的枚举
|
||||
* <p>
|
||||
*/
|
||||
FILE_DOWNLOAD_FAIL("A3002", "文件下载失败!"),
|
||||
UNKNOWN_BUSINESS_TYPE_CODE("A3003", "未知业务type码"),
|
||||
FILE_UPLOAD_FAIL("A3004", "文件上传失败!"),
|
||||
TIME_OUT("A3005", "前置响应超时!"),;
|
||||
|
||||
private final String code;
|
||||
|
||||
|
||||
@@ -45,6 +45,19 @@ public enum TypeEnum {
|
||||
TYPE_29("9217","设备心跳请求"),
|
||||
TYPE_30("4865","设备数据主动上送"),
|
||||
TYPE_31("8503","设备控制命令"),
|
||||
READ_FILE_DIR("1101", "读取文件目录"),
|
||||
FILE_DOWNLOAD("1102", "文件下载"),
|
||||
FIXED_VALUE("1103", "定值读取/写入"),
|
||||
INNER_FIXED_VALUE("1104", "内部定值读取/写入"),
|
||||
|
||||
WORKING_LOG("1111","设备运行日志"),
|
||||
DEVICE_VERSION("1112","设备版本信息"),
|
||||
DEVICE_REBOOT("1114","设备重启"),
|
||||
DEVICE_UPGRADE("1115","设备升级"),
|
||||
FILE_UPLOAD("1116","文件上传"),
|
||||
FILE_DELETE("1117","文件删除"),
|
||||
MKDIR("1118","目录创建"),
|
||||
DIR_DELETE("1119","目录删除"),
|
||||
|
||||
/**
|
||||
* 数据类型
|
||||
|
||||
@@ -5,7 +5,6 @@ import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -18,6 +17,11 @@ import java.util.List;
|
||||
@Data
|
||||
public class DevAccessParam implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("工程id")
|
||||
private String engineeringId;
|
||||
|
||||
@ApiModelProperty("项目id")
|
||||
@NotNull(message = "项目id不能为空")
|
||||
private String projectId;
|
||||
@@ -68,6 +72,9 @@ public class DevAccessParam implements Serializable {
|
||||
@ApiModelProperty("中心点纬度")
|
||||
@NotNull(message = "中心点纬度不能为空")
|
||||
private Double lat;
|
||||
|
||||
@ApiModelProperty("拓扑图指标id")
|
||||
private String target;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.njcn.access.pojo.dto;
|
||||
|
||||
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -17,39 +18,49 @@ import java.util.List;
|
||||
public class AutoDataDto {
|
||||
|
||||
@SerializedName("Mid")
|
||||
@JsonProperty("Mid")
|
||||
private Integer mid;
|
||||
|
||||
@SerializedName("Did")
|
||||
@JsonProperty("Did")
|
||||
@ApiModelProperty("逻辑设备 治理逻辑设备为1 电能质量设备为2")
|
||||
private Integer did;
|
||||
|
||||
@SerializedName("Pri")
|
||||
@JsonProperty("Pri")
|
||||
private Integer pri;
|
||||
|
||||
@SerializedName("Type")
|
||||
@JsonProperty("Type")
|
||||
private Integer type;
|
||||
|
||||
@SerializedName("Msg")
|
||||
@JsonProperty("Msg")
|
||||
private Msg msg;
|
||||
|
||||
@Data
|
||||
public static class Msg{
|
||||
|
||||
@SerializedName("Cldid")
|
||||
@JsonProperty("Cldid")
|
||||
@ApiModelProperty("逻辑子设备 治理逻辑设备为0 电能质量设备为1、2")
|
||||
private Integer clDid;
|
||||
|
||||
@SerializedName("DataType")
|
||||
@JsonProperty("DataType")
|
||||
private Integer dataType;
|
||||
|
||||
@SerializedName("DataAttr")
|
||||
@JsonProperty("DataAttr")
|
||||
@ApiModelProperty("数据属性:无-0、实时-1、统计-2")
|
||||
private Integer dataAttr;
|
||||
|
||||
@SerializedName("DsNameIdx")
|
||||
@JsonProperty("DsNameIdx")
|
||||
private Integer dsNameIdx;
|
||||
|
||||
@SerializedName("DataArray")
|
||||
@JsonProperty("DataArray")
|
||||
private List<DataArray> dataArray;
|
||||
}
|
||||
|
||||
@@ -57,95 +68,119 @@ public class AutoDataDto {
|
||||
public static class DataArray{
|
||||
|
||||
@SerializedName("DataAttr")
|
||||
@JsonProperty("DataAttr")
|
||||
@ApiModelProperty("数据属性 -1-无 0-Rt(实时) 1-Max 2-Min 3-Avg 4-Cp95")
|
||||
private Integer dataAttr;
|
||||
|
||||
@SerializedName("DataTimeSec")
|
||||
@JsonProperty("DataTimeSec")
|
||||
private Long dataTimeSec;
|
||||
|
||||
@SerializedName("DataTimeUSec")
|
||||
@JsonProperty("DataTimeUSec")
|
||||
private Integer dataTimeUSec;
|
||||
|
||||
@SerializedName("DataTag")
|
||||
@JsonProperty("DataTag")
|
||||
@ApiModelProperty("数据是否参与合格率统计")
|
||||
private Integer dataTag;
|
||||
|
||||
@SerializedName("Code")
|
||||
@JsonProperty("Code")
|
||||
@ApiModelProperty("事件码")
|
||||
private Integer code;
|
||||
private String code;
|
||||
|
||||
@SerializedName("Data")
|
||||
@JsonProperty("Data")
|
||||
private String data;
|
||||
|
||||
@SerializedName("PrjName")
|
||||
@JsonProperty("PrjName")
|
||||
@ApiModelProperty("工程名称")
|
||||
private String prjName;
|
||||
|
||||
@SerializedName("PrjTimeStart")
|
||||
@JsonProperty("PrjTimeStart")
|
||||
@ApiModelProperty("装置启动时间")
|
||||
private Long prjTimeStart;
|
||||
|
||||
@SerializedName("PrjTimeEnd")
|
||||
@JsonProperty("PrjTimeEnd")
|
||||
@ApiModelProperty("装置结束时间")
|
||||
private Long prjTimeEnd;
|
||||
|
||||
@SerializedName("PrjDataPath")
|
||||
@JsonProperty("PrjDataPath")
|
||||
@ApiModelProperty("装置数据路径")
|
||||
private String prjDataPath;
|
||||
|
||||
@SerializedName("DevType")
|
||||
@JsonProperty("DevType")
|
||||
@ApiModelProperty("装置型号")
|
||||
private String devType;
|
||||
|
||||
@SerializedName("DevMac")
|
||||
@JsonProperty("DevMac")
|
||||
@ApiModelProperty("装置mac地址")
|
||||
private String devMac;
|
||||
|
||||
@SerializedName("AppVersion")
|
||||
@JsonProperty("AppVersion")
|
||||
@ApiModelProperty("装置程序版本")
|
||||
private String appVersion;
|
||||
|
||||
@SerializedName("Cldid")
|
||||
@JsonProperty("Cldid")
|
||||
@ApiModelProperty("逻辑子设备id")
|
||||
private Integer clDid;
|
||||
|
||||
@SerializedName("StatCycle")
|
||||
@JsonProperty("StatCycle")
|
||||
@ApiModelProperty("统计间隔")
|
||||
private Integer statCycle;
|
||||
|
||||
@SerializedName("VolGrade")
|
||||
@JsonProperty("VolGrade")
|
||||
@ApiModelProperty("电压等级")
|
||||
private Float volGrade;
|
||||
|
||||
@SerializedName("VolConType")
|
||||
@JsonProperty("VolConType")
|
||||
@ApiModelProperty("电压接线方式(0-星型, 1-角型, 2-V型)")
|
||||
private Integer volConType;
|
||||
|
||||
@SerializedName("CurConSel")
|
||||
@JsonProperty("CurConSel")
|
||||
@ApiModelProperty("电流接线方式(0-正常, 1-合成IB, 2-合成IC)")
|
||||
private Integer curConSel;
|
||||
|
||||
@SerializedName("PtRatio")
|
||||
@JsonProperty("PtRatio")
|
||||
@ApiModelProperty("PT变比")
|
||||
private Integer ptRatio;
|
||||
|
||||
@SerializedName("CtRatio")
|
||||
@JsonProperty("CtRatio")
|
||||
@ApiModelProperty("ct变比")
|
||||
private Integer ctRatio;
|
||||
|
||||
@SerializedName("CapacitySscb")
|
||||
@JsonProperty("CapacitySscb")
|
||||
@ApiModelProperty("基准短路容量")
|
||||
private Float capacitySscb;
|
||||
|
||||
@SerializedName("CapacitySscmin")
|
||||
@JsonProperty("CapacitySscmin")
|
||||
@ApiModelProperty("最小短路容量")
|
||||
private Float capacitySscmin;
|
||||
|
||||
@SerializedName("CapacitySt")
|
||||
@JsonProperty("CapacitySt")
|
||||
@ApiModelProperty("供电设备容量")
|
||||
private Float capacitySt;
|
||||
|
||||
@SerializedName("CapacitySi")
|
||||
@JsonProperty("CapacitySi")
|
||||
@ApiModelProperty("用户协议容量")
|
||||
private Float capacitySi;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.njcn.access.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 治理设备模块运行状态记录表
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-07-03
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@TableName("cs_line_latest_data")
|
||||
public class CsLineLatestData implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 监测点id
|
||||
*/
|
||||
@MppMultiId(value = "line_id")
|
||||
private String lineId;
|
||||
|
||||
/**
|
||||
* 最新数据时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime timeId;
|
||||
|
||||
|
||||
}
|
||||
@@ -51,6 +51,7 @@ public class FileCommonUtils {
|
||||
*/
|
||||
public void cleanRedisData(String nDid, String fileName) {
|
||||
redisUtil.deleteKeysByString("downloadFilePath:"+ nDid);
|
||||
redisUtil.deleteKeysByString("isWeb:"+ nDid);
|
||||
redisUtil.delete("fileDowning:"+nDid);
|
||||
redisUtil.delete("fileCheck" + nDid + fileName);
|
||||
redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(fileName));
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.njcn.access.utils;
|
||||
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author 徐扬
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class RedisSetUtil {
|
||||
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
/**
|
||||
* 向Redis Set中添加元素
|
||||
*/
|
||||
public void addToSet(String key, String value, long expireSeconds) {
|
||||
try {
|
||||
Object existing = redisUtil.getObjectByKey(key);
|
||||
Set<String> set = convertToSet(existing);
|
||||
set.add(value);
|
||||
redisUtil.saveByKeyWithExpire(key, set, expireSeconds);
|
||||
} catch (Exception e) {
|
||||
log.error("向Redis Set添加元素失败,key: {}", key, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从Redis Set中移除元素
|
||||
*/
|
||||
public void removeFromSet(String key, String value) {
|
||||
try {
|
||||
Object existing = redisUtil.getObjectByKey(key);
|
||||
if (existing != null) {
|
||||
Set<String> set = convertToSet(existing);
|
||||
set.remove(value);
|
||||
redisUtil.saveByKey(key, set);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("从Redis Set移除元素失败,key: {}", key, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全的对象到Set转换
|
||||
*/
|
||||
public Set<String> convertToSet(Object obj) {
|
||||
if (obj == null) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
if (obj instanceof Set) {
|
||||
return new HashSet<>((Set<String>) obj);
|
||||
}
|
||||
if (obj instanceof Collection) {
|
||||
return new HashSet<>((Collection<String>) obj);
|
||||
}
|
||||
log.warn("无法转换的对象类型: {}", obj.getClass().getName());
|
||||
return new HashSet<>();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,15 @@
|
||||
package com.njcn.access.utils;
|
||||
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.njcn.access.enums.AccessResponseEnum;
|
||||
import com.njcn.access.pojo.dto.NoticeUserDto;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@@ -20,13 +26,18 @@ import java.nio.charset.StandardCharsets;
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
public class SendMessageUtil {
|
||||
private final RedisUtil redisUtil;
|
||||
|
||||
@Value("${app.sendUrl:https://fc-mp-ff7b310f-94c9-4468-8260-109111c0a6b2.next.bspapp.com/push}")
|
||||
private String appSendUrl;
|
||||
|
||||
//App客户端消息推送
|
||||
public void sendEventToUser(NoticeUserDto noticeUserDto) {
|
||||
try {
|
||||
// 创建一个URL对象,指定目标HTTPS接口地址
|
||||
URL url = new URL("https://fc-mp-ff7b310f-94c9-4468-8260-109111c0a6b2.next.bspapp.com/push");
|
||||
URL url = new URL(appSendUrl);
|
||||
// 打开HTTPS连接
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
// 设置请求方法为POST
|
||||
@@ -60,4 +71,27 @@ public class SendMessageUtil {
|
||||
e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 轮询 Redis 等待响应
|
||||
*/
|
||||
public String waitForResponse(String guid, int timeoutSeconds) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
while (System.currentTimeMillis() - startTime < timeoutSeconds * 1000L) {
|
||||
String response = redisUtil.getStringByKey(AppRedisKey.COMMON_RESOPNSE + guid);
|
||||
if (response != null) {
|
||||
redisUtil.delete(AppRedisKey.COMMON_REQUEST + guid);
|
||||
redisUtil.delete(AppRedisKey.COMMON_RESOPNSE + guid);
|
||||
return response;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(100); // 100ms 轮询一次
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
throw new BusinessException(AccessResponseEnum.TIME_OUT);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,6 +20,16 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.tocrhz</groupId>
|
||||
<artifactId>mqtt-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.paho</groupId>
|
||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||
<version>1.2.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>access-api</artifactId>
|
||||
|
||||
@@ -123,5 +123,19 @@ public class AskDeviceDataController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/askCldRealData")
|
||||
@ApiOperation("询问云前置实时数据")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "devId", value = "装置id"),
|
||||
@ApiImplicitParam(name = "lineId", value = "监测点id"),
|
||||
@ApiImplicitParam(name = "nodeId", value = "前置id"),
|
||||
@ApiImplicitParam(name = "idx", value = "数据集编号")
|
||||
})
|
||||
public HttpResult<String> askCldRealData(@RequestParam("devId") String devId, @RequestParam("lineId") String lineId, @RequestParam("nodeId") String nodeId, @RequestParam("idx") Integer idx){
|
||||
String methodDescribe = getMethodDescribe("askCldRealData");
|
||||
askDeviceDataService.askCldRealData(devId,lineId,nodeId,idx);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.njcn.access.controller;
|
||||
|
||||
import com.njcn.access.param.DevAccessParam;
|
||||
import com.njcn.access.service.ICsDeviceService;
|
||||
import com.njcn.access.service.ICsEquipmentDeliveryService;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
@@ -34,6 +35,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
public class CsDeviceController extends BaseController {
|
||||
|
||||
private final ICsDeviceService csDeviceService;
|
||||
private final ICsEquipmentDeliveryService csEquipmentDeliveryService;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/register")
|
||||
@@ -120,4 +122,42 @@ public class CsDeviceController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, "success", methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/autoPortableLedger")
|
||||
@ApiOperation("调整便携式设备的台账信息")
|
||||
@ReturnMsg
|
||||
public HttpResult<String> autoPortableLedger(){
|
||||
String methodDescribe = getMethodDescribe("autoPortableLedger");
|
||||
csDeviceService.autoPortableLedger();
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, "success", methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/updateRunStatus")
|
||||
@ApiOperation("设备状态调整")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "nDid", value = "设备识别码", required = true),
|
||||
@ApiImplicitParam(name = "runStatus", value = "状态", required = true)
|
||||
})
|
||||
public HttpResult<String> updateRunStatus(@RequestParam String nDid, @RequestParam Integer runStatus){
|
||||
String methodDescribe = getMethodDescribe("updateRunStatus");
|
||||
csEquipmentDeliveryService.updateRunStatusBynDid(nDid,runStatus);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, "success", methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/onlineRegister")
|
||||
@ApiOperation("监测设备接入")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "projectId", value = "项目id", required = true),
|
||||
@ApiImplicitParam(name = "nDid", value = "设备识别码", required = true)
|
||||
})
|
||||
@ReturnMsg
|
||||
public HttpResult<String> onlineRegister(@RequestParam("projectId") String projectId,@RequestParam("nDid") String nDid){
|
||||
String methodDescribe = getMethodDescribe("onlineRegister");
|
||||
String result = csDeviceService.onlineRegister(projectId,nDid);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.njcn.access.controller;
|
||||
|
||||
import com.njcn.access.service.ICsHeartService;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.mq.message.HeartbeatTimeoutMessage;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/9/6 11:07
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/heartbeat")
|
||||
@Api(tags = "心跳")
|
||||
@AllArgsConstructor
|
||||
@ApiIgnore
|
||||
public class CsHeartController extends BaseController {
|
||||
|
||||
private final ICsHeartService csHeartService;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/handleHeartbeat")
|
||||
@ApiOperation("处理物联设备心跳")
|
||||
@ApiImplicitParam(name = "message", value = "message", required = true)
|
||||
public HttpResult<String> handleHeartbeat(@RequestBody HeartbeatTimeoutMessage message){
|
||||
String methodDescribe = getMethodDescribe("handleHeartbeat");
|
||||
csHeartService.handleHeartbeat(message);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.njcn.access.controller;
|
||||
|
||||
|
||||
import com.njcn.access.pojo.po.CsLineLatestData;
|
||||
import com.njcn.access.service.ICsLineLatestDataService;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 治理设备模块运行状态记录表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-07-03
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/csLineLatestData")
|
||||
@Api(tags = "治理设备模块运行状态记录")
|
||||
@AllArgsConstructor
|
||||
public class CsLineLatestDataController extends BaseController {
|
||||
|
||||
private final ICsLineLatestDataService csLineLatestDataService;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("新增")
|
||||
@ApiImplicitParam(name = "csLineLatestData", value = "实体", required = true)
|
||||
public HttpResult<String> addData(@RequestBody CsLineLatestData csLineLatestData) {
|
||||
String methodDescribe = getMethodDescribe("csLineLatestData");
|
||||
csLineLatestDataService.addData(csLineLatestData);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/list")
|
||||
@ApiOperation("查询")
|
||||
public HttpResult<List<CsLineLatestData>> listData() {
|
||||
String methodDescribe = getMethodDescribe("listData");
|
||||
List<CsLineLatestData> list = csLineLatestDataService.list();
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.njcn.access.handler;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.alibaba.csp.sentinel.util.StringUtil;
|
||||
import com.alibaba.excel.util.CollectionUtils;
|
||||
@@ -14,25 +15,22 @@ import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
import com.njcn.access.enums.AccessEnum;
|
||||
import com.njcn.access.enums.AccessResponseEnum;
|
||||
import com.njcn.access.enums.TypeEnum;
|
||||
import com.njcn.access.mapper.OverlimitMapper;
|
||||
import com.njcn.access.pojo.RspDataDto;
|
||||
import com.njcn.access.pojo.dto.*;
|
||||
import com.njcn.access.pojo.dto.file.FileDto;
|
||||
import com.njcn.access.pojo.dto.file.FileRedisDto;
|
||||
import com.njcn.access.pojo.param.ReqAndResParam;
|
||||
import com.njcn.access.pojo.po.CsDeviceOnlineLogs;
|
||||
import com.njcn.access.pojo.po.CsLineModel;
|
||||
import com.njcn.access.pojo.po.CsTopic;
|
||||
import com.njcn.access.service.ICsDeviceOnlineLogsService;
|
||||
import com.njcn.access.service.ICsEquipmentDeliveryService;
|
||||
import com.njcn.access.service.ICsLineModelService;
|
||||
import com.njcn.access.service.ICsTopicService;
|
||||
import com.njcn.access.service.*;
|
||||
import com.njcn.access.utils.ChannelObjectUtil;
|
||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.api.*;
|
||||
import com.njcn.csdevice.pojo.dto.PqsCommunicateDto;
|
||||
import com.njcn.csdevice.pojo.param.CsLineParam;
|
||||
import com.njcn.csdevice.pojo.po.*;
|
||||
import com.njcn.device.biz.mapper.OverLimitWlMapper;
|
||||
import com.njcn.device.biz.pojo.po.Overlimit;
|
||||
import com.njcn.device.biz.utils.COverlimitUtil;
|
||||
import com.njcn.mq.message.AppAutoDataMessage;
|
||||
@@ -58,7 +56,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.Validator;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeFormatterBuilder;
|
||||
@@ -68,6 +65,8 @@ import java.util.stream.Collectors;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
|
||||
;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
@@ -95,10 +94,12 @@ public class MqttMessageHandler {
|
||||
private final CsLineFeignClient csLineFeignClient;
|
||||
private final DevCapacityFeignClient devCapacityFeignClient;
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
private final OverlimitMapper overlimitMapper;
|
||||
private final OverLimitWlMapper overLimitWlMapper;
|
||||
private final ChannelObjectUtil channelObjectUtil;
|
||||
private final WaveFeignClient waveFeignClient;
|
||||
private final RtFeignClient rtFeignClient;
|
||||
private final CsCommunicateFeignClient csCommunicateFeignClient;
|
||||
private final IHeartbeatService heartbeatService;
|
||||
@Autowired
|
||||
Validator validator;
|
||||
|
||||
@@ -166,7 +167,7 @@ public class MqttMessageHandler {
|
||||
@MqttSubscribe(value = "/Dev/DevReg/{edgeId}",qos = 1)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void devOperation(String topic, MqttMessage message, @NamedValue("edgeId") String nDid, @Payload String payload){
|
||||
log.info("收到注册应答响应--->" + nDid);
|
||||
log.info("收到注册应答响应--->{}", nDid);
|
||||
//日志记录
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
try{
|
||||
@@ -308,37 +309,27 @@ public class MqttMessageHandler {
|
||||
if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){
|
||||
int mid = 1;
|
||||
//修改装置状态
|
||||
csEquipmentDeliveryService.updateStatusBynDid(nDid,AccessEnum.ACCESS.getCode());
|
||||
csEquipmentDeliveryService.updateStatusBynDid(nDid,AccessEnum.ACCESS.getCode(),null,null);
|
||||
csEquipmentDeliveryService.updateRunStatusBynDid(nDid,AccessEnum.ONLINE.getCode());
|
||||
//记录设备上线
|
||||
CsDeviceOnlineLogs record = onlineLogsService.findLastData(nDid);
|
||||
CsDeviceOnlineLogs csDeviceOnlineLogs = new CsDeviceOnlineLogs();
|
||||
if(Objects.isNull(record)) {
|
||||
csDeviceOnlineLogs.setNdid(nDid);
|
||||
csDeviceOnlineLogs.setOnlineTime(LocalDateTime.now());
|
||||
onlineLogsService.save(csDeviceOnlineLogs);
|
||||
} else {
|
||||
LocalDateTime time = record.getOfflineTime();
|
||||
if (!Objects.isNull(time)){
|
||||
csDeviceOnlineLogs.setNdid(nDid);
|
||||
csDeviceOnlineLogs.setOnlineTime(LocalDateTime.now());
|
||||
onlineLogsService.save(csDeviceOnlineLogs);
|
||||
} else {
|
||||
record.setOnlineTime(LocalDateTime.now());
|
||||
onlineLogsService.updateById(record);
|
||||
}
|
||||
}
|
||||
//接入后系统重置装置心跳
|
||||
redisUtil.saveByKeyWithExpire("MQTT:" + nDid, Instant.now().toEpochMilli(),180L);
|
||||
//修改redis的mid
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,1);
|
||||
redisUtil.saveByKeyWithExpire("online" + nDid,"online",10L);
|
||||
PqsCommunicateDto dto = new PqsCommunicateDto();
|
||||
dto.setTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN)));
|
||||
dto.setDevId(nDid);
|
||||
dto.setType(1);
|
||||
dto.setDescription("通讯正常");
|
||||
csCommunicateFeignClient.insertion(dto);
|
||||
//询问设备软件信息
|
||||
askDevData(nDid,version,1,mid);
|
||||
//更新治理监测点信息和设备容量
|
||||
askDevData(nDid,version,2,(res.getMid()+1));
|
||||
//更新电网侧、负载侧监测点信息
|
||||
askDevData(nDid,version,3,(res.getMid()+1));
|
||||
//接入后系统重置装置心跳
|
||||
heartbeatService.receiveHeartbeat(nDid);
|
||||
//修改redis的mid
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,1);
|
||||
//接入成功标识
|
||||
redisUtil.saveByKeyWithExpire("online" + nDid,"online",10L);
|
||||
//录波任务倒计时
|
||||
redisUtil.saveByKeyWithExpire("startFile:" + nDid,null,60L);
|
||||
} else {
|
||||
@@ -355,7 +346,6 @@ public class MqttMessageHandler {
|
||||
if (!Objects.isNull(rspDataDto.getDataType())) {
|
||||
switch (rspDataDto.getDataType()){
|
||||
case 1:
|
||||
log.info("{},设备数据应答--->更新设备软件信息", nDid);
|
||||
logDto.setOperate(nDid + "更新设备软件信息");
|
||||
RspDataDto.SoftInfo softInfo = JSON.parseObject(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.SoftInfo.class);
|
||||
//记录设备软件信息
|
||||
@@ -386,58 +376,49 @@ public class MqttMessageHandler {
|
||||
List<RspDataDto.LdevInfo> devInfo = JSON.parseArray(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.LdevInfo.class);
|
||||
if (CollectionUtil.isNotEmpty(devInfo)){
|
||||
if (Objects.equals(res.getDid(),1)){
|
||||
log.info("{},设备数据应答--->更新治理监测点信息和设备容量", nDid);
|
||||
List<CsDevCapacityPO> list3 = new ArrayList<>();
|
||||
devInfo.forEach(item->{
|
||||
//1.更新治理监测点信息
|
||||
CsLineParam csLineParam = new CsLineParam();
|
||||
if (Objects.equals(item.getClDid(),0)){
|
||||
csLineParam.setLineId(nDid.concat("0"));
|
||||
boolean hasZeroClDid = devInfo.stream().anyMatch(item -> item.getClDid() == 0);
|
||||
//治理设备
|
||||
if (hasZeroClDid) {
|
||||
devInfo.forEach(item->{
|
||||
if (Objects.equals(item.getClDid(),0)){
|
||||
updateLineInfo(nDid,item);
|
||||
}
|
||||
//2.录入各个模块设备容量
|
||||
CsDevCapacityPO csDevCapacity = new CsDevCapacityPO();
|
||||
csDevCapacity.setLineId(nDid.concat("0"));
|
||||
csDevCapacity.setCldid(item.getClDid());
|
||||
csDevCapacity.setCapacity(Objects.isNull(item.getCapacityA())?0.0:item.getCapacityA());
|
||||
list3.add(csDevCapacity);
|
||||
} else {
|
||||
csLineParam.setLineId(nDid.concat(item.getClDid().toString()));
|
||||
}
|
||||
csLineParam.setVolGrade(item.getVolGrade());
|
||||
csLineParam.setPtRatio(item.getPtRatio());
|
||||
csLineParam.setCtRatio(item.getCtRatio());
|
||||
csLineParam.setConType(item.getConType());
|
||||
csLineParam.setLineInterval(item.getStatCycle());
|
||||
csLineFeignClient.updateLine(csLineParam);
|
||||
//生成监测点限值
|
||||
Overlimit overlimit = COverlimitUtil.globalAssemble(item.getVolGrade().floatValue(),10f,10f,10f,0,0);
|
||||
overlimit.setId(nDid.concat(item.getClDid().toString()));
|
||||
overlimitMapper.deleteById(nDid.concat(item.getClDid().toString()));
|
||||
overlimitMapper.insert(overlimit);
|
||||
});
|
||||
});
|
||||
}
|
||||
//其余设备
|
||||
else {
|
||||
devInfo.forEach(item->{
|
||||
updateLineInfo(nDid,item);
|
||||
});
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(list3)) {
|
||||
devCapacityFeignClient.addList(list3);
|
||||
//3.更新设备模块个数
|
||||
equipmentFeignClient.updateModuleNumber(nDid,(devInfo.size()-1));
|
||||
}
|
||||
} else if (Objects.equals(res.getDid(),2)) {
|
||||
log.info("{},设备数据应答--->更新电网侧、负载侧监测点信息", nDid);
|
||||
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());
|
||||
csLineParam.setLineInterval(item.getStatCycle());
|
||||
csLineFeignClient.updateLine(csLineParam);
|
||||
updateLineInfo(nDid,item);
|
||||
});
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 15:
|
||||
JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(res));
|
||||
AppAutoDataMessage appAutoDataMessage = JSONObject.toJavaObject(jsonObject, AppAutoDataMessage.class);
|
||||
appAutoDataMessage.setId(nDid);
|
||||
rtFeignClient.apfRtAnalysis(appAutoDataMessage);
|
||||
break;
|
||||
case 48:
|
||||
log.info("询问装置项目列表");
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setOperate("监测点:" + (nDid + rspDataDto.getClDid()) + "询问项目列表");
|
||||
List<RspDataDto.ProjectInfo> projectInfoList = JSON.parseArray(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.ProjectInfo.class);
|
||||
@@ -450,7 +431,6 @@ public class MqttMessageHandler {
|
||||
}
|
||||
break;
|
||||
case 4663:
|
||||
log.info("装置操作应答");
|
||||
if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){
|
||||
String key4 = AppRedisKey.CONTROL + nDid;
|
||||
redisUtil.saveByKeyWithExpire(key4,"success",10L);
|
||||
@@ -459,10 +439,31 @@ public class MqttMessageHandler {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
//csLogsFeignClient.addUserLog(logDto);
|
||||
} else {
|
||||
String result = getEnum(res.getCode());
|
||||
log.info(result);
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(result);
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(result);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateLineInfo(String nDid,RspDataDto.LdevInfo 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());
|
||||
csLineParam.setLineInterval(item.getStatCycle());
|
||||
csLineFeignClient.updateLine(csLineParam);
|
||||
//生成监测点限值
|
||||
Overlimit overlimit = COverlimitUtil.globalAssemble(item.getVolGrade().floatValue(),10f,10f,10f,0,0);
|
||||
overlimit.setId(nDid.concat(item.getClDid().toString()));
|
||||
overLimitWlMapper.deleteById(nDid.concat(item.getClDid().toString()));
|
||||
overLimitWlMapper.insert(overlimit);
|
||||
}
|
||||
|
||||
/**
|
||||
* 装置心跳 && 主动数据上送
|
||||
@@ -482,33 +483,37 @@ public class MqttMessageHandler {
|
||||
//响应请求
|
||||
switch (res.getType()){
|
||||
case 4865:
|
||||
//设置心跳时间,超时改为掉线
|
||||
redisUtil.saveByKeyWithExpire("MQTT:" + nDid, Instant.now().toEpochMilli(),180L);
|
||||
heartbeatService.receiveHeartbeat(nDid);
|
||||
//有心跳,则将装置改成在线
|
||||
//csEquipmentDeliveryService.updateRunStatusBynDid(nDid,AccessEnum.ONLINE.getCode());
|
||||
//处理心跳
|
||||
ReqAndResDto.Res reqAndResParam = new ReqAndResDto.Res();
|
||||
reqAndResParam.setMid(res.getMid());
|
||||
reqAndResParam.setDid(0);
|
||||
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_29.getCode()));
|
||||
reqAndResParam.setCode(200);
|
||||
//fixme 前置处理的时间应该是UTC时间,所以需要加8小时。
|
||||
String json = "{Time:"+(System.currentTimeMillis()/1000+8*3600)+"}";
|
||||
net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(json);
|
||||
reqAndResParam.setMsg(jsonObject);
|
||||
publisher.send("/Dev/DataRsp/"+version+"/"+nDid,gson.toJson(reqAndResParam),1,false);
|
||||
//处理业务逻辑
|
||||
Object object = res.getMsg();
|
||||
if (!Objects.isNull(object)){
|
||||
List<String> abnormalList = new ArrayList<>();
|
||||
if (object instanceof ArrayList<?>){
|
||||
abnormalList.addAll((List<String>) object);
|
||||
//处理心跳 判断设备是否接入,如果设备已经接入则响应,不然忽略
|
||||
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(nDid).getData();
|
||||
if (Objects.nonNull(po)) {
|
||||
if (po.getUsageStatus() == 1 && po.getRunStatus() == 2 && po.getStatus() == 3) {
|
||||
ReqAndResDto.Res reqAndResParam = new ReqAndResDto.Res();
|
||||
reqAndResParam.setMid(res.getMid());
|
||||
reqAndResParam.setDid(0);
|
||||
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_29.getCode()));
|
||||
reqAndResParam.setCode(200);
|
||||
//fixme 前置处理的时间应该是UTC时间,所以需要加8小时。
|
||||
String json = "{Time:"+(System.currentTimeMillis()/1000+8*3600)+"}";
|
||||
net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(json);
|
||||
reqAndResParam.setMsg(jsonObject);
|
||||
publisher.send("/Dev/DataRsp/"+version+"/"+nDid,gson.toJson(reqAndResParam),1,false);
|
||||
//处理业务逻辑
|
||||
Object object = res.getMsg();
|
||||
if (!Objects.isNull(object)){
|
||||
List<String> abnormalList = new ArrayList<>();
|
||||
if (object instanceof ArrayList<?>){
|
||||
abnormalList.addAll((List<String>) object);
|
||||
}
|
||||
//todo APF设备不存在逻辑设备掉线的情况,网关下的设备会存在
|
||||
abnormalList.forEach(item->{
|
||||
System.out.println("异常设备ID:"+item);
|
||||
});
|
||||
}
|
||||
}
|
||||
//todo APF设备不存在逻辑设备掉线的情况,网关下的设备会存在
|
||||
abnormalList.forEach(item->{
|
||||
System.out.println("异常设备ID:"+item);
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 4866:
|
||||
@@ -521,15 +526,12 @@ public class MqttMessageHandler {
|
||||
response.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||
response.setType(Integer.parseInt(TypeEnum.TYPE_15.getCode()));
|
||||
response.setCode(200);
|
||||
log.info("应答事件:" + new Gson().toJson(response));
|
||||
publisher.send("/Dev/DataRsp/"+version+"/"+nDid,new Gson().toJson(response),1,false);
|
||||
}
|
||||
//判断事件类型
|
||||
switch (dataDto.getMsg().getDataAttr()) {
|
||||
//暂态事件、录波处理、工程信息
|
||||
case 0:
|
||||
log.info(nDid + "处理事件");
|
||||
//log.info(nDid + "事件报文为:" + new String(message.getPayload(), StandardCharsets.UTF_8));
|
||||
EventDto eventDto = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), EventDto.class);
|
||||
JSONObject jsonObject0 = JSONObject.parseObject(JSON.toJSONString(eventDto));
|
||||
AppEventMessage appEventMessage = JSONObject.toJavaObject(jsonObject0, AppEventMessage.class);
|
||||
@@ -538,7 +540,6 @@ public class MqttMessageHandler {
|
||||
break;
|
||||
//实时数据
|
||||
case 1:
|
||||
log.info(nDid + "处理实时数据");
|
||||
JSONObject jsonObject2 = JSONObject.parseObject(JSON.toJSONString(dataDto));
|
||||
AppAutoDataMessage appAutoDataMessage = JSONObject.toJavaObject(jsonObject2, AppAutoDataMessage.class);
|
||||
appAutoDataMessage.setId(nDid);
|
||||
@@ -549,9 +550,6 @@ public class MqttMessageHandler {
|
||||
JSONObject jsonObject3 = JSONObject.parseObject(JSON.toJSONString(dataDto));
|
||||
AppAutoDataMessage appAutoDataMessage2 = JSONObject.toJavaObject(jsonObject3, AppAutoDataMessage.class);
|
||||
appAutoDataMessage2.setId(nDid);
|
||||
appAutoDataMessage2.getMsg().getDataArray().forEach(item->{
|
||||
log.info(nDid + "处理统计数据" + item.getDataAttr());
|
||||
});
|
||||
appAutoDataMessageTemplate.sendMember(appAutoDataMessage2);
|
||||
break;
|
||||
default:
|
||||
@@ -583,7 +581,6 @@ public class MqttMessageHandler {
|
||||
//响应请求
|
||||
switch (fileDto.getType()){
|
||||
case 4657:
|
||||
log.info("获取文件信息" + fileDto);
|
||||
if (Objects.equals(fileDto.getCode(),AccessEnum.SUCCESS.getCode())) {
|
||||
String key = AppRedisKey.PROJECT_INFO + nDid;
|
||||
if (Objects.isNull(fileDto.getMsg().getType())) {
|
||||
@@ -616,7 +613,6 @@ public class MqttMessageHandler {
|
||||
}
|
||||
break;
|
||||
case 4658:
|
||||
log.info("获取文件流信息");
|
||||
FileRedisDto dto = new FileRedisDto();
|
||||
dto.setCode(fileDto.getCode());
|
||||
redisUtil.saveByKeyWithExpire(AppRedisKey.DOWNLOAD + fileDto.getMsg().getName() + fileDto.getMid(),dto,60L);
|
||||
@@ -664,7 +660,6 @@ public class MqttMessageHandler {
|
||||
public void devErrorInfo(String topic, MqttMessage message, @NamedValue("version") String version, @NamedValue("edgeId") String nDid, @Payload String payload) {
|
||||
//解析数据
|
||||
Gson gson = new Gson();
|
||||
//log.info(nDid + "事件报文为:" + new String(message.getPayload(), StandardCharsets.UTF_8));
|
||||
EventDto eventDto = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), EventDto.class);
|
||||
JSONObject jsonObject0 = JSONObject.parseObject(JSON.toJSONString(eventDto));
|
||||
AppEventMessage appEventMessage = JSONObject.toJavaObject(jsonObject0, AppEventMessage.class);
|
||||
@@ -737,8 +732,44 @@ public class MqttMessageHandler {
|
||||
break;
|
||||
}
|
||||
reqAndResParam.setMsg(askDataDto);
|
||||
//log.info("askDevData的请求报文:" + new Gson().toJson(reqAndResParam));
|
||||
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid, new Gson().toJson(reqAndResParam),1,false);
|
||||
}
|
||||
|
||||
public String getEnum(Integer code) {
|
||||
String result = null;
|
||||
switch (code) {
|
||||
case 201:
|
||||
result = AccessEnum.START_CHANNEL.getMessage();
|
||||
break;
|
||||
case 202:
|
||||
result = AccessEnum.WAIT_CHANNEL.getMessage();
|
||||
break;
|
||||
case 400:
|
||||
result = AccessEnum.FAIL.getMessage();
|
||||
break;
|
||||
case 401:
|
||||
result = AccessEnum.ERROR.getMessage();
|
||||
break;
|
||||
case 402:
|
||||
result = AccessEnum.REFUSE_WAIT.getMessage();
|
||||
break;
|
||||
case 403:
|
||||
result = AccessEnum.REFUSE_UNKNOWN.getMessage();
|
||||
break;
|
||||
case 404:
|
||||
result = AccessEnum.NOT_FIND.getMessage();
|
||||
break;
|
||||
case 405:
|
||||
result = AccessEnum.BUSY.getMessage();
|
||||
break;
|
||||
case 406:
|
||||
result = AccessEnum.TIME_OUT.getMessage();
|
||||
break;
|
||||
default:
|
||||
result = AccessEnum.OTHER_ERROR.getMessage();
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,26 +1,14 @@
|
||||
package com.njcn.access.listener;
|
||||
|
||||
import com.njcn.access.enums.AccessEnum;
|
||||
import com.njcn.access.pojo.dto.NoticeUserDto;
|
||||
import com.njcn.access.pojo.po.CsDeviceOnlineLogs;
|
||||
import com.njcn.access.service.ICsDeviceOnlineLogsService;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
import com.njcn.access.service.ICsEquipmentDeliveryService;
|
||||
import com.njcn.access.service.ICsTopicService;
|
||||
import com.njcn.access.service.impl.CsDeviceServiceImpl;
|
||||
import com.njcn.access.utils.MqttUtil;
|
||||
import com.njcn.access.utils.RedisSetUtil;
|
||||
import com.njcn.access.utils.SendMessageUtil;
|
||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||
import com.njcn.csdevice.api.CsDeviceUserFeignClient;
|
||||
import com.njcn.csdevice.api.CsLedgerFeignClient;
|
||||
import com.njcn.csdevice.api.CsLogsFeignClient;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
import com.njcn.csdevice.pojo.dto.DevDetailDTO;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.csdevice.api.*;
|
||||
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.rt.pojo.dto.BaseRealDataSet;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.redis.connection.Message;
|
||||
@@ -29,14 +17,7 @@ import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
@@ -47,43 +28,31 @@ import java.util.stream.Collectors;
|
||||
@Component
|
||||
public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {
|
||||
|
||||
@Resource
|
||||
private ICsTopicService csTopicService;
|
||||
@Resource
|
||||
private ICsEquipmentDeliveryService csEquipmentDeliveryService;
|
||||
@Resource
|
||||
private CsDeviceServiceImpl csDeviceService;
|
||||
@Resource
|
||||
private CsLogsFeignClient csLogsFeignClient;
|
||||
@Resource
|
||||
private ICsDeviceOnlineLogsService onlineLogsService;
|
||||
@Resource
|
||||
private MqttUtil mqttUtil;
|
||||
@Resource
|
||||
private CsLedgerFeignClient csLedgerFeignclient;
|
||||
@Resource
|
||||
private EquipmentFeignClient equipmentFeignClient;
|
||||
@Resource
|
||||
private AppUserFeignClient appUserFeignClient;
|
||||
@Resource
|
||||
private CsDeviceUserFeignClient csDeviceUserFeignClient;
|
||||
@Resource
|
||||
private UserFeignClient userFeignClient;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private SendMessageUtil sendMessageUtil;
|
||||
@Resource
|
||||
private CsDeviceServiceImpl csDeviceServiceImpl;
|
||||
private final Object lock = new Object();
|
||||
private CsCommunicateFeignClient csCommunicateFeignClient;
|
||||
@Resource
|
||||
private MqttPublisher publisher;
|
||||
@Resource
|
||||
private RedisSetUtil redisSetUtil;
|
||||
@Resource
|
||||
private DeviceMessageFeignClient deviceMessageFeignClient;
|
||||
|
||||
public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
|
||||
super(listenerContainer);
|
||||
}
|
||||
|
||||
//最大告警次数
|
||||
private static int MAX_WARNING_TIMES = 0;
|
||||
|
||||
/**
|
||||
* 针对redis数据失效事件,进行数据处理
|
||||
* 注意message.toString()可以获取失效的key
|
||||
@@ -95,217 +64,95 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
}
|
||||
//判断失效的key是否为MQTT消费端存入的
|
||||
String expiredKey = message.toString();
|
||||
if(expiredKey.startsWith("MQTT:")){
|
||||
String nDid = expiredKey.split(":")[1];
|
||||
executeMainTask(nDid);
|
||||
// if(expiredKey.startsWith("MQTT:")){
|
||||
// String nDid = expiredKey.split(":")[1];
|
||||
// executeMainTask(nDid);
|
||||
// }
|
||||
if(expiredKey.startsWith("cldRtDataOverTime:")){
|
||||
String lineId = expiredKey.split(":")[1];
|
||||
Object redisObject = redisUtil.getObjectByKey("rtDataUserId:"+lineId);
|
||||
if (ObjectUtil.isNotNull(redisObject)) {
|
||||
Set<String> userSet = redisSetUtil.convertToSet(redisObject);
|
||||
userSet.forEach(userId->{
|
||||
BaseRealDataSet baseRealDataSet = new BaseRealDataSet();
|
||||
baseRealDataSet.setUserId(userId);
|
||||
baseRealDataSet.setResult(false);
|
||||
baseRealDataSet.setContent("设备未响应,超时中断");
|
||||
publisher.send("/Web/RealData/" + lineId, new Gson().toJson(baseRealDataSet), 1, false);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//主任务
|
||||
//1.装置心跳断连
|
||||
//2.MQTT客户端不在线
|
||||
private void executeMainTask(String nDid) {
|
||||
log.info("{}->装置离线", nDid);
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
//装置下线
|
||||
csEquipmentDeliveryService.updateRunStatusBynDid(nDid, AccessEnum.OFFLINE.getCode());
|
||||
//装置调整为注册状态
|
||||
csEquipmentDeliveryService.updateStatusBynDid(nDid,AccessEnum.REGISTERED.getCode());
|
||||
logDto.setOperate(nDid +"装置离线");
|
||||
sendMessage(nDid);
|
||||
//记录装置掉线时间
|
||||
CsDeviceOnlineLogs record = onlineLogsService.findLastData(nDid);
|
||||
record.setOfflineTime(LocalDateTime.now());
|
||||
onlineLogsService.updateById(record);
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
}
|
||||
|
||||
//主任务
|
||||
//1.装置心跳断连
|
||||
//2.MQTT客户端不在线
|
||||
// private void executeMainTask(String nDid, String version) {
|
||||
// ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
// //主任务
|
||||
// //1.装置心跳断连
|
||||
// //2.MQTT客户端不在线
|
||||
// private void executeMainTask(String nDid) {
|
||||
// log.info("{}->装置离线", nDid);
|
||||
// DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
// logDto.setUserName("运维管理员");
|
||||
// logDto.setLoginName("njcnyw");
|
||||
// //判断mqtt
|
||||
// String clientName = "NJCN-" + nDid.substring(nDid.length() - 6);
|
||||
// boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
||||
// //心跳异常,但是客户端在线,则发送接入请求
|
||||
// if (mqttClient) {
|
||||
// csDeviceService.devAccessAskTemplate(nDid,version,1);
|
||||
// redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,1);
|
||||
// try {
|
||||
// Thread.sleep(5000);
|
||||
// Object object = redisUtil.getObjectByKey("online" + nDid);
|
||||
// if (Objects.nonNull(object)) {
|
||||
// scheduler.shutdown();
|
||||
// logDto.setOperate(nDid + "客户端在线重连成功");
|
||||
// } else {
|
||||
// //装置下线
|
||||
// csEquipmentDeliveryService.updateRunStatusBynDid(nDid, AccessEnum.OFFLINE.getCode());
|
||||
// //装置调整为注册状态
|
||||
// csEquipmentDeliveryService.updateStatusBynDid(nDid,AccessEnum.REGISTERED.getCode());
|
||||
// logDto.setOperate(nDid +"装置离线");
|
||||
// sendMessage(nDid);
|
||||
//
|
||||
// //记录装置掉线时间
|
||||
// CsDeviceOnlineLogs record = onlineLogsService.findLastData(nDid);
|
||||
// record.setOfflineTime(LocalDateTime.now());
|
||||
// onlineLogsService.updateById(record);
|
||||
//
|
||||
// scheduler.shutdown();
|
||||
// }
|
||||
// } catch (InterruptedException e) {
|
||||
// scheduler.shutdown();
|
||||
// throw new RuntimeException(e);
|
||||
// //装置下线
|
||||
// csEquipmentDeliveryService.updateRunStatusBynDid(nDid, AccessEnum.OFFLINE.getCode());
|
||||
// //装置调整为注册状态
|
||||
// csEquipmentDeliveryService.updateStatusBynDid(nDid,AccessEnum.REGISTERED.getCode(),null,null);
|
||||
// logDto.setOperate(nDid +"装置离线");
|
||||
// sendMessage(nDid);
|
||||
// //记录装置掉线时间
|
||||
// PqsCommunicateDto dto = new PqsCommunicateDto();
|
||||
// dto.setTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN)));
|
||||
// dto.setDevId(nDid);
|
||||
// dto.setType(0);
|
||||
// dto.setDescription("通讯中断");
|
||||
// csCommunicateFeignClient.insertion(dto);
|
||||
// csLogsFeignClient.addUserLog(logDto);
|
||||
// //清空缓存
|
||||
// redisUtil.deleteKeysByString(AppRedisKey.LINE_POSITION+nDid);
|
||||
// }
|
||||
|
||||
// //判断设备型号发送数据
|
||||
// private void sendMessage(String nDid) {
|
||||
// boolean devModel = equipmentFeignClient.judgeDevModel(nDid).getData();
|
||||
// if (devModel) {
|
||||
// NoticeUserDto dto = sendOffLine(nDid);
|
||||
// if (CollectionUtil.isNotEmpty(dto.getPushClientId())) {
|
||||
// sendMessageUtil.sendEventToUser(dto);
|
||||
// addLogs(dto);
|
||||
// }
|
||||
// csLogsFeignClient.addUserLog(logDto);
|
||||
// }
|
||||
// //客户端不在线则修改装置状态,进入定时任务
|
||||
// else {
|
||||
// //装置下线
|
||||
// csEquipmentDeliveryService.updateRunStatusBynDid(nDid, AccessEnum.OFFLINE.getCode());
|
||||
// //装置调整为注册状态
|
||||
// csEquipmentDeliveryService.updateStatusBynDid(nDid,AccessEnum.REGISTERED.getCode());
|
||||
// logDto.setOperate(nDid +"主任务执行失败,装置下线");
|
||||
// csLogsFeignClient.addUserLog(logDto);
|
||||
// sendMessage(nDid);
|
||||
//
|
||||
// //记录装置掉线时间
|
||||
// CsDeviceOnlineLogs record = onlineLogsService.findLastData(nDid);
|
||||
// record.setOfflineTime(LocalDateTime.now());
|
||||
// onlineLogsService.updateById(record);
|
||||
//
|
||||
// scheduler.shutdown();
|
||||
// }
|
||||
// }
|
||||
|
||||
private void startScheduledTask(ScheduledExecutorService scheduler, String nDid, String version) {
|
||||
synchronized (lock) {
|
||||
//判断是否推送消息
|
||||
boolean devModel = equipmentFeignClient.judgeDevModel(nDid).getData();
|
||||
if (devModel) {
|
||||
NoticeUserDto dto = sendOffLine(nDid);
|
||||
sendMessageUtil.sendEventToUser(dto);
|
||||
addLogs(dto);
|
||||
}
|
||||
String clientName = "NJCN-" + nDid.substring(nDid.length() - 6);
|
||||
ScheduledFuture<?> future = scheduler.scheduleAtFixedRate(() -> {
|
||||
log.info(nDid + "执行重连定时任务...");
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setOperate(nDid + "重连定时任务");
|
||||
//判断客户端
|
||||
boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
||||
if (mqttClient) {
|
||||
csDeviceService.devAccessAskTemplate(nDid,version,1);
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
Integer status = csEquipmentDeliveryService.queryEquipmentBynDid(nDid).getRunStatus();
|
||||
if (Objects.equals(status,AccessEnum.ONLINE.getCode())){
|
||||
logDto.setResult(1);
|
||||
scheduler.shutdown();
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,1);
|
||||
return;
|
||||
} else {
|
||||
logDto.setResult(0);
|
||||
//一个小时未连接上,则推送告警消息
|
||||
MAX_WARNING_TIMES++;
|
||||
if (MAX_WARNING_TIMES == 30 && devModel) {
|
||||
NoticeUserDto dto2 = sendConnectFail(nDid);
|
||||
sendMessageUtil.sendEventToUser(dto2);
|
||||
addLogs(dto2);
|
||||
}
|
||||
//记录装置掉线时间
|
||||
CsDeviceOnlineLogs record = onlineLogsService.findLastData(nDid);
|
||||
record.setOfflineTime(LocalDateTime.now());
|
||||
onlineLogsService.updateById(record);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
//一个小时未连接上,则推送告警消息
|
||||
MAX_WARNING_TIMES++;
|
||||
if (MAX_WARNING_TIMES == 30 && devModel) {
|
||||
NoticeUserDto dto2 = sendConnectFail(nDid);
|
||||
sendMessageUtil.sendEventToUser(dto2);
|
||||
addLogs(dto2);
|
||||
}
|
||||
logDto.setResult(0);
|
||||
//记录装置掉线时间
|
||||
CsDeviceOnlineLogs record = onlineLogsService.findLastData(nDid);
|
||||
record.setOfflineTime(LocalDateTime.now());
|
||||
onlineLogsService.updateById(record);
|
||||
}
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
}, 0, 2, TimeUnit.MINUTES);
|
||||
}
|
||||
}
|
||||
|
||||
//判断设备型号发送数据
|
||||
private void sendMessage(String nDid) {
|
||||
boolean devModel = equipmentFeignClient.judgeDevModel(nDid).getData();
|
||||
if (devModel) {
|
||||
NoticeUserDto dto = sendOffLine(nDid);
|
||||
sendMessageUtil.sendEventToUser(dto);
|
||||
addLogs(dto);
|
||||
}
|
||||
}
|
||||
|
||||
//掉线通知
|
||||
private NoticeUserDto sendOffLine(String nDid) {
|
||||
NoticeUserDto dto = new NoticeUserDto();
|
||||
dto.setTitle("设备离线");
|
||||
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(nDid).getData();
|
||||
DevDetailDTO devDetailDto = csLedgerFeignclient.queryDevDetail(po.getId()).getData();
|
||||
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
LocalDateTime localDateTime = LocalDateTime.now();
|
||||
String dateStr = localDateTime.format(fmt);
|
||||
String content = String.format(devDetailDto.getEngineeringName() + "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName() + "于" + dateStr + "离线");
|
||||
dto.setContent(content);
|
||||
dto.setPushClientId(getEventUser(po.getId(),true));
|
||||
return dto;
|
||||
}
|
||||
|
||||
//重连失败通知
|
||||
private NoticeUserDto sendConnectFail(String nDid) {
|
||||
NoticeUserDto dto = new NoticeUserDto();
|
||||
dto.setTitle("设备接入失败");
|
||||
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(nDid).getData();
|
||||
DevDetailDTO devDetailDto = csLedgerFeignclient.queryDevDetail(po.getId()).getData();
|
||||
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
LocalDateTime localDateTime = LocalDateTime.now();
|
||||
String dateStr = localDateTime.format(fmt);
|
||||
String content = String.format(devDetailDto.getEngineeringName() + "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName() + "于" + dateStr + "多次接入失败");
|
||||
dto.setContent(content);
|
||||
dto.setPushClientId(getEventUser(po.getId(),false));
|
||||
return dto;
|
||||
}
|
||||
|
||||
//日志记录
|
||||
private void addLogs(NoticeUserDto noticeUserDto) {
|
||||
DeviceLogDTO dto = new DeviceLogDTO();
|
||||
dto.setUserName("运维管理员");
|
||||
dto.setLoginName("njcnyw");
|
||||
dto.setOperate(noticeUserDto.getContent());
|
||||
csLogsFeignClient.addUserLog(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有需要推送的用户id
|
||||
*/
|
||||
public List<String> getEventUser(String devId, boolean isAdmin) {
|
||||
List<User> adminUser = appUserFeignClient.getAdminInfo().getData();
|
||||
List<String> adminList = adminUser.stream().map(User::getId).collect(Collectors.toList());
|
||||
if (isAdmin) {
|
||||
List<String> list = csDeviceUserFeignClient.findUserById(devId).getData();
|
||||
adminList.addAll(list);
|
||||
}
|
||||
List<User> users = userFeignClient.appuserByIdList(adminList).getData();
|
||||
return users.stream().map(User::getDevCode).filter(Objects::nonNull).filter(StringUtils::isNotBlank).distinct().collect(Collectors.toList());
|
||||
}
|
||||
// //掉线通知
|
||||
// private NoticeUserDto sendOffLine(String nDid) {
|
||||
// NoticeUserDto dto = new NoticeUserDto();
|
||||
// dto.setTitle("设备离线");
|
||||
// CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(nDid).getData();
|
||||
// DevDetailDTO devDetailDto = csLedgerFeignclient.queryDevDetail(po.getId()).getData();
|
||||
// DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
// LocalDateTime localDateTime = LocalDateTime.now();
|
||||
// String dateStr = localDateTime.format(fmt);
|
||||
// String content = String.format(devDetailDto.getEngineeringName() + "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName() + "于" + dateStr + "离线");
|
||||
// dto.setContent(content);
|
||||
// //获取设备关联的用户
|
||||
// List<String> eventUser = deviceMessageFeignClient.getEventUserByDeviceId(po.getId(),true).getData();
|
||||
// DeviceMessageParam param1 = new DeviceMessageParam();
|
||||
// param1.setUserList(eventUser);
|
||||
// param1.setEventType(2);
|
||||
// //获取打开推送的用户
|
||||
// List<User> users = deviceMessageFeignClient.getSendUserByType(param1).getData();
|
||||
// if (CollectionUtil.isNotEmpty(users)){
|
||||
// dto.setPushClientId(
|
||||
// users.stream().filter(Objects::nonNull).map(User::getDevCode).filter(StringUtils::isNotBlank).distinct().collect(Collectors.toList()));
|
||||
// }
|
||||
// return dto;
|
||||
// }
|
||||
//
|
||||
// //日志记录
|
||||
// private void addLogs(NoticeUserDto noticeUserDto) {
|
||||
// DeviceLogDTO dto = new DeviceLogDTO();
|
||||
// dto.setUserName("运维管理员");
|
||||
// dto.setLoginName("njcnyw");
|
||||
// dto.setOperate(noticeUserDto.getContent());
|
||||
// csLogsFeignClient.addUserLog(dto);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.njcn.access.mapper;
|
||||
|
||||
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
|
||||
import com.njcn.access.pojo.po.CsLineLatestData;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 治理设备模块运行状态记录表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-07-03
|
||||
*/
|
||||
public interface CsLineLatestDataMapper extends MppBaseMapper<CsLineLatestData> {
|
||||
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
package com.njcn.access.mapper;
|
||||
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.njcn.device.biz.pojo.po.Overlimit;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
*/
|
||||
@DS("sjzx")
|
||||
@Mapper
|
||||
public interface OverlimitMapper extends BaseMapper<Overlimit> {
|
||||
|
||||
}
|
||||
//package com.njcn.access.mapper;
|
||||
//
|
||||
//
|
||||
//import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
//import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
//import com.njcn.device.biz.pojo.po.Overlimit;
|
||||
//import org.apache.ibatis.annotations.Mapper;
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * <p>
|
||||
// * Mapper 接口
|
||||
// * </p>
|
||||
// *
|
||||
// * @author xy
|
||||
// */
|
||||
//@DS("sjzx")
|
||||
//@Mapper
|
||||
//public interface OverlimitMapper extends BaseMapper<Overlimit> {
|
||||
//
|
||||
//}
|
||||
|
||||
@@ -9,7 +9,6 @@ import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.system.api.DictTreeFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.enums.DicTreeEnum;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
@@ -88,20 +87,28 @@ public class AccessApplicationRunner implements ApplicationRunner {
|
||||
}
|
||||
|
||||
public void accessDev(List<CsEquipmentDeliveryPO> list) {
|
||||
list.forEach(item->{
|
||||
System.out.println(Thread.currentThread().getName() + ": reboot : nDid : " + item.getNdid());
|
||||
String version = csTopicService.getVersion(item.getNdid());
|
||||
if (!Objects.isNull(version)){
|
||||
//判断设备类型 便携式设备需要特殊处理 未注册的要先注册、再接入;已注册的直接重新接入
|
||||
String code = dictTreeFeignClient.queryById(item.getDevType()).getData().getCode();
|
||||
if (Objects.equals(code, DicDataEnum.PORTABLE.getCode()) && Objects.equals(item.getStatus(),1)) {
|
||||
csDeviceService.wlDevRegister(item.getNdid());
|
||||
} else {
|
||||
csDeviceService.devAccessAskTemplate(item.getNdid(),version,1);
|
||||
}
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + item.getNdid(),1);
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
try {
|
||||
list.forEach(item->{
|
||||
System.out.println(Thread.currentThread().getName() + ": reboot : nDid : " + item.getNdid());
|
||||
//判断设备类型 便携式设备需要特殊处理 未注册的要先注册、再接入;已注册的直接重新接入
|
||||
String code = dictTreeFeignClient.queryById(item.getDevType()).getData().getCode();
|
||||
if (Objects.equals(code, DicDataEnum.PORTABLE.getCode()) && Objects.equals(item.getStatus(),1)) {
|
||||
//csDeviceService.wlDevRegister(item.getNdid());
|
||||
log.info("请先手动注册、接入");
|
||||
} else {
|
||||
String version = csTopicService.getVersion(item.getNdid());
|
||||
if (Objects.isNull(version)) {
|
||||
version = "V1";
|
||||
}
|
||||
csDeviceService.autoAccess(item.getNdid(),version,1);
|
||||
}
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + item.getNdid(),1);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.system.api.DictTreeFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.enums.DicTreeEnum;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
@@ -39,63 +38,127 @@ public class AutoAccessTimer implements ApplicationRunner {
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
if (scheduler.isShutdown() || scheduler.isTerminated()) {
|
||||
scheduler = Executors.newScheduledThreadPool(1);
|
||||
}
|
||||
Runnable task = () -> {
|
||||
log.info("轮询定时任务执行中!");
|
||||
List<CsEquipmentDeliveryPO> list = csEquipmentDeliveryService.getOfflineDev();
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
ExecutorService executor = Executors.newFixedThreadPool(10);
|
||||
// 将任务平均分配给10个子列表
|
||||
List<List<CsEquipmentDeliveryPO>> subLists = new ArrayList<>();
|
||||
int partitionSize = list.size() / 10;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
int start = i * partitionSize;
|
||||
int end = (i == 9) ? list.size() : start + partitionSize;
|
||||
subLists.add(list.subList(start, end));
|
||||
}
|
||||
|
||||
// 创建一个ExecutorService来处理这些任务
|
||||
List<Future<Void>> futures = new ArrayList<>();
|
||||
// 提交任务给线程池执行
|
||||
for (int i = 0; i < 10; i++) {
|
||||
int index = i;
|
||||
futures.add(executor.submit(new Callable<Void>() {
|
||||
@Override
|
||||
public Void call() {
|
||||
accessDev(subLists.get(index));
|
||||
return null;
|
||||
}
|
||||
}));
|
||||
}
|
||||
// 等待所有任务完成
|
||||
for (Future<Void> future : futures) {
|
||||
try {
|
||||
future.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
// 关闭ExecutorService
|
||||
executor.shutdown();
|
||||
try {
|
||||
executeScheduledTask();
|
||||
}
|
||||
// 捕获所有Throwable,包括Error
|
||||
catch (Throwable t) {
|
||||
log.error("定时任务发生严重异常,尝试恢复", t);
|
||||
// 可以添加重启逻辑或告警
|
||||
}
|
||||
};
|
||||
//第一次执行的时间为120s,然后每隔120s执行一次
|
||||
scheduler.scheduleAtFixedRate(task,AUTO_TIME,AUTO_TIME,TimeUnit.SECONDS);
|
||||
ScheduledFuture<?> future = scheduler.scheduleWithFixedDelay(task, AUTO_TIME, AUTO_TIME, TimeUnit.SECONDS);
|
||||
// 添加监控,如果任务被取消则重新调度
|
||||
monitorScheduledTask(future);
|
||||
}
|
||||
|
||||
public void accessDev(List<CsEquipmentDeliveryPO> list) {
|
||||
list.forEach(item->{
|
||||
System.out.println(Thread.currentThread().getName() + ": auto : nDid : " + item.getNdid());
|
||||
String version = csTopicService.getVersion(item.getNdid());
|
||||
if (!Objects.isNull(version)){
|
||||
//判断设备类型 便携式设备需要特殊处理 未注册的要先注册、再接入;已注册的直接重新接入
|
||||
String code = dictTreeFeignClient.queryById(item.getDevType()).getData().getCode();
|
||||
if (Objects.equals(code, DicDataEnum.PORTABLE.getCode()) && Objects.equals(item.getStatus(),1)) {
|
||||
csDeviceService.wlDevRegister(item.getNdid());
|
||||
} else {
|
||||
csDeviceService.devAccessAskTemplate(item.getNdid(),version,1);
|
||||
//10分钟检查一下调度任务
|
||||
private void monitorScheduledTask(ScheduledFuture<?> future) {
|
||||
Thread monitorThread = new Thread(() -> {
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
try {
|
||||
//每10分钟检查一次
|
||||
Thread.sleep(600000);
|
||||
if (future.isCancelled() || future.isDone()) {
|
||||
log.warn("定时任务被取消或完成,重新调度...");
|
||||
// 重新启动任务
|
||||
run(null);
|
||||
break;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
log.warn("监控线程被中断");
|
||||
break;
|
||||
} catch (Exception e) {
|
||||
log.error("监控任务异常", e);
|
||||
}
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + item.getNdid(),1);
|
||||
}
|
||||
});
|
||||
}, "Schedule-Monitor-Thread");
|
||||
|
||||
monitorThread.setDaemon(true);
|
||||
monitorThread.start();
|
||||
}
|
||||
|
||||
private void executeScheduledTask() {
|
||||
log.info("轮询定时任务执行中!");
|
||||
List<CsEquipmentDeliveryPO> list = csEquipmentDeliveryService.getOfflineDev();
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
ExecutorService executor = Executors.newFixedThreadPool(10);
|
||||
try {
|
||||
List<List<CsEquipmentDeliveryPO>> subLists = CollUtil.split(list, 10);
|
||||
List<Future<Void>> futures = new ArrayList<>();
|
||||
for (List<CsEquipmentDeliveryPO> subList : subLists) {
|
||||
futures.add(executor.submit(() -> {
|
||||
try {
|
||||
accessDevSafely(subList); // 使用安全版本
|
||||
} catch (Exception e) {
|
||||
log.error("处理设备子列表异常", e);
|
||||
}
|
||||
return null;
|
||||
}));
|
||||
}
|
||||
for (Future<Void> future : futures) {
|
||||
try {
|
||||
future.get(5, TimeUnit.MINUTES);
|
||||
} catch (TimeoutException e) {
|
||||
log.error("任务执行超时", e);
|
||||
} catch (Exception e) {
|
||||
log.error("任务执行异常", e);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
executor.shutdown();
|
||||
try {
|
||||
if (!executor.awaitTermination(1, TimeUnit.MINUTES)) {
|
||||
executor.shutdownNow();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
executor.shutdownNow();
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//安全的accessDev版本
|
||||
private void accessDevSafely(List<CsEquipmentDeliveryPO> list) {
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
for (CsEquipmentDeliveryPO item : list) {
|
||||
try {
|
||||
processSingleDevice(item);
|
||||
} catch (Exception e) {
|
||||
log.error("处理设备 {} 失败: {}", item.getNdid(), e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void processSingleDevice(CsEquipmentDeliveryPO item) {
|
||||
System.out.println(Thread.currentThread().getName() + ": auto : nDid : " + item.getNdid());
|
||||
String code = dictTreeFeignClient.queryById(item.getDevType()).getData().getCode();
|
||||
if (Objects.equals(code, DicDataEnum.PORTABLE.getCode()) && Objects.equals(item.getStatus(), 1)) {
|
||||
log.info("设备 {} 需要手动注册、接入", item.getNdid());
|
||||
} else {
|
||||
String version = csTopicService.getVersion(item.getNdid());
|
||||
if (Objects.isNull(version)) {
|
||||
version = "V1";
|
||||
}
|
||||
// 使用try-catch确保单个设备失败不影响其他设备
|
||||
try {
|
||||
boolean success = csDeviceService.autoAccess2(item.getNdid(), version, 1);
|
||||
if (success) {
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + item.getNdid(), 1);
|
||||
} else {
|
||||
log.warn("设备 {} 接入失败", item.getNdid());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("设备 {} 接入异常: {}", item.getNdid(), e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
package com.njcn.access.runner;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.njcn.access.service.ICsEquipmentDeliveryService;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
import com.njcn.redis.pojo.enums.RedisKeyEnum;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
* 定时轮询离线设备接入
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class CldHeartTimer implements ApplicationRunner {
|
||||
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
private static final long OUT_TIME = 120L;
|
||||
private final RedisUtil redisUtil;
|
||||
private final ICsEquipmentDeliveryService csEquipmentDeliveryService;
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
if (scheduler.isShutdown() || scheduler.isTerminated()) {
|
||||
scheduler = Executors.newScheduledThreadPool(1);
|
||||
}
|
||||
Runnable task = () -> {
|
||||
try {
|
||||
executeScheduledTask();
|
||||
}
|
||||
// 捕获所有Throwable,包括Error
|
||||
catch (Throwable t) {
|
||||
log.error("定时任务发生严重异常,尝试恢复", t);
|
||||
// 可以添加重启逻辑或告警
|
||||
}
|
||||
};
|
||||
ScheduledFuture<?> future = scheduler.scheduleWithFixedDelay(task, OUT_TIME, OUT_TIME, TimeUnit.SECONDS);
|
||||
// 添加监控,如果任务被取消则重新调度
|
||||
monitorScheduledTask(future);
|
||||
}
|
||||
|
||||
//10分钟检查一下调度任务
|
||||
private void monitorScheduledTask(ScheduledFuture<?> future) {
|
||||
Thread monitorThread = new Thread(() -> {
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
try {
|
||||
//每10分钟检查一次
|
||||
Thread.sleep(600000);
|
||||
if (future.isCancelled() || future.isDone()) {
|
||||
log.warn("定时任务被取消或完成,重新调度...");
|
||||
// 重新启动任务
|
||||
run(null);
|
||||
break;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
log.warn("监控线程被中断");
|
||||
break;
|
||||
} catch (Exception e) {
|
||||
log.error("监控任务异常", e);
|
||||
}
|
||||
}
|
||||
}, "Schedule-Monitor-Thread");
|
||||
monitorThread.setDaemon(true);
|
||||
monitorThread.start();
|
||||
}
|
||||
|
||||
private void executeScheduledTask() {
|
||||
log.info("定时检查云前置心跳!");
|
||||
//获取在运设备的所有前置和进程号,循环查询redis里面是否存在,不存在则将所有前置下的设备翻转
|
||||
List<String> list = csEquipmentDeliveryService.getFrontAndProcess();
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
ExecutorService executor = Executors.newFixedThreadPool(2);
|
||||
try {
|
||||
List<List<String>> subLists = CollUtil.split(list, 2);
|
||||
List<Future<Void>> futures = new ArrayList<>();
|
||||
for (List<String> subList : subLists) {
|
||||
futures.add(executor.submit(() -> {
|
||||
try {
|
||||
accessDevSafely(subList);
|
||||
} catch (Exception e) {
|
||||
log.error("处理设备子列表异常", e);
|
||||
}
|
||||
return null;
|
||||
}));
|
||||
}
|
||||
for (Future<Void> future : futures) {
|
||||
try {
|
||||
future.get(5, TimeUnit.MINUTES);
|
||||
} catch (TimeoutException e) {
|
||||
log.error("任务执行超时", e);
|
||||
} catch (Exception e) {
|
||||
log.error("任务执行异常", e);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
executor.shutdown();
|
||||
try {
|
||||
if (!executor.awaitTermination(1, TimeUnit.MINUTES)) {
|
||||
executor.shutdownNow();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
executor.shutdownNow();
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//安全的accessDev版本
|
||||
private void accessDevSafely(List<String> list) {
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
for (String item : list) {
|
||||
try {
|
||||
processSingleDevice(item);
|
||||
} catch (Exception e) {
|
||||
log.error("处理设备 {} 失败: {}", item, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void processSingleDevice(String item) {
|
||||
Object object = redisUtil.getObjectByKey(RedisKeyEnum.CLD_HEART_BEAT_KEY.getKey() + item);
|
||||
if (Objects.isNull(object)) {
|
||||
String nodeId = item.substring(0, item.length() - 1);
|
||||
int processNo = Integer.parseInt(item.substring(item.length() - 1));
|
||||
equipmentFeignClient.updateCldDevStatus(nodeId,processNo);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,4 +21,6 @@ public interface AskDeviceDataService {
|
||||
* 实时数据请求报文
|
||||
*/
|
||||
void askRealData(String nDid, Integer idx, Integer size);
|
||||
|
||||
void askCldRealData(String devId, String lineId, String nodeId, Integer idx);
|
||||
}
|
||||
|
||||
@@ -54,4 +54,8 @@ public interface ICsDeviceService {
|
||||
* @param nDid 设备识别码
|
||||
*/
|
||||
void wlAccess(String nDid);
|
||||
|
||||
String autoPortableLedger();
|
||||
|
||||
String onlineRegister(String projectId,String nDid);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public interface ICsEquipmentDeliveryService extends IService<CsEquipmentDeliver
|
||||
* 根据网关id修改装置的状态
|
||||
* @param nDid 网关id
|
||||
*/
|
||||
void updateStatusBynDid(String nDid,Integer status);
|
||||
void updateStatusBynDid(String nDid,Integer status,String engineeringId, String projectId);
|
||||
|
||||
/**
|
||||
* 根据网关id修改软件信息
|
||||
@@ -65,8 +65,18 @@ public interface ICsEquipmentDeliveryService extends IService<CsEquipmentDeliver
|
||||
*/
|
||||
List<CsEquipmentDeliveryPO> getOnlineDev();
|
||||
|
||||
/**
|
||||
* 获取启用、系统在线、MQTT接入的装置
|
||||
*/
|
||||
List<CsEquipmentDeliveryPO> getUseOnlineDevice();
|
||||
|
||||
/**
|
||||
* 获取离线、启用、客户端在线的装置
|
||||
*/
|
||||
List<CsEquipmentDeliveryPO> getOfflineDev();
|
||||
|
||||
/**
|
||||
* 获取在运且在线的装置 所属前置和进程号
|
||||
*/
|
||||
List<String> getFrontAndProcess();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.njcn.access.service;
|
||||
|
||||
import com.njcn.mq.message.HeartbeatTimeoutMessage;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
public interface ICsHeartService {
|
||||
|
||||
void handleHeartbeat(HeartbeatTimeoutMessage message);
|
||||
|
||||
}
|
||||
@@ -24,4 +24,6 @@ public interface ICsLedgerService extends IService<CsLedger> {
|
||||
*/
|
||||
CsLedger addLedgerTree(CsLedgerParam csLedgerParam);
|
||||
|
||||
void updatePortableLedger(String engineeringId, String projectId);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.njcn.access.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.access.pojo.po.CsLineLatestData;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 治理设备模块运行状态记录表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-07-03
|
||||
*/
|
||||
public interface ICsLineLatestDataService extends IService<CsLineLatestData> {
|
||||
|
||||
void addData(CsLineLatestData csLineLatestData);
|
||||
|
||||
}
|
||||
@@ -28,5 +28,5 @@ public interface ICsTopicService extends IService<CsTopic> {
|
||||
*/
|
||||
String getVersion(String nDid);
|
||||
|
||||
|
||||
void deleteByNDid(String nDid);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.njcn.access.service;
|
||||
|
||||
public interface IHeartbeatService {
|
||||
|
||||
void receiveHeartbeat(String nDid);
|
||||
|
||||
Boolean isHeartbeatUpdated(String nDid, Long sendTime);
|
||||
}
|
||||
@@ -11,6 +11,8 @@ import com.njcn.access.pojo.dto.ReqAndResDto;
|
||||
import com.njcn.access.service.AskDeviceDataService;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
||||
import com.njcn.mq.message.RealDataMessage;
|
||||
import com.njcn.mq.template.RealDataMessageTemplate;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -32,6 +34,7 @@ public class AskDeviceDataServiceImpl implements AskDeviceDataService {
|
||||
private final MqttPublisher publisher;
|
||||
private final CsTopicFeignClient csTopicFeignClient;
|
||||
private final RedisUtil redisUtil;
|
||||
private final RealDataMessageTemplate realDataMessageTemplate;
|
||||
private static Integer mid = 1;
|
||||
private static Integer range = 51200;
|
||||
|
||||
@@ -84,6 +87,7 @@ public class AskDeviceDataServiceImpl implements AskDeviceDataService {
|
||||
public boolean downloadFile(String nDid, String name, Integer size, String fileCheck) {
|
||||
boolean result = true;
|
||||
try {
|
||||
redisUtil.saveByKeyWithExpire("isWeb:"+nDid,name,30L);
|
||||
redisUtil.saveByKeyWithExpire("fileDowning:"+nDid,"fileDowning",300L);
|
||||
redisUtil.saveByKey("fileCheck"+nDid+name,fileCheck);
|
||||
Object object = getDeviceMid(nDid);
|
||||
@@ -101,6 +105,7 @@ public class AskDeviceDataServiceImpl implements AskDeviceDataService {
|
||||
redisUtil.delete("fileDowning:"+nDid);
|
||||
redisUtil.delete("fileCheck"+nDid+name);
|
||||
redisUtil.delete("fileDownUserId"+nDid+name);
|
||||
redisUtil.deleteKeysByString("isWeb:"+ nDid);
|
||||
throw new BusinessException(AlgorithmResponseEnum.FILE_DOWNLOAD_ERROR);
|
||||
}
|
||||
return result;
|
||||
@@ -209,6 +214,18 @@ public class AskDeviceDataServiceImpl implements AskDeviceDataService {
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,mid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void askCldRealData(String devId, String lineId, String nodeId, Integer idx) {
|
||||
RealDataMessage realDataMessage = new RealDataMessage();
|
||||
realDataMessage.setDevSeries(devId);
|
||||
int lastDigit = Character.getNumericValue(lineId.charAt(lineId.length() - 1));
|
||||
realDataMessage.setLine(lastDigit);
|
||||
realDataMessage.setRealData(true);
|
||||
realDataMessage.setSoeData(true);
|
||||
realDataMessage.setLimit(20);
|
||||
realDataMessage.setIdx(idx);
|
||||
realDataMessageTemplate.sendMember(realDataMessage,nodeId);
|
||||
}
|
||||
|
||||
public Object getDeviceMid(String nDid) {
|
||||
return redisUtil.getObjectByKey(AppRedisKey.DEVICE_MID + nDid);
|
||||
|
||||
@@ -2,7 +2,9 @@ package com.njcn.access.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
import com.njcn.access.enums.AccessEnum;
|
||||
import com.njcn.access.enums.AccessResponseEnum;
|
||||
@@ -20,11 +22,13 @@ import com.njcn.access.utils.CRC32Utils;
|
||||
import com.njcn.access.utils.JsonUtil;
|
||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.api.CsLogsFeignClient;
|
||||
import com.njcn.csdevice.api.DevModelFeignClient;
|
||||
import com.njcn.csdevice.api.*;
|
||||
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
||||
import com.njcn.csdevice.pojo.param.CsDevModelAddParm;
|
||||
import com.njcn.csdevice.pojo.po.*;
|
||||
import com.njcn.csdevice.pojo.po.CsDataArray;
|
||||
import com.njcn.csdevice.pojo.po.CsDataSet;
|
||||
import com.njcn.csdevice.pojo.po.CsDevModelPO;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.oss.constant.OssPath;
|
||||
import com.njcn.oss.utils.FileStorageUtil;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
@@ -45,7 +49,6 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -77,6 +80,9 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
private final MqttPublisher publisher;
|
||||
private final ICsTopicService csTopicService;
|
||||
private final RedisUtil redisUtil;
|
||||
private final EquipmentFeignClient eequipmentFeignClient;
|
||||
private final DevModelRelationFeignClient devModelRelationFeignClient;
|
||||
private final CsLineFeignClient csLineFeignClient;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
@@ -91,6 +97,20 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
json = JsonUtil.convertStreamToString(file.getInputStream());
|
||||
Gson gson = new Gson();
|
||||
TemplateDto templateDto = gson.fromJson(json, TemplateDto.class);
|
||||
//判断设备型号
|
||||
String devType = templateDto.getDevType();
|
||||
DictTreeVO dictTreeVO = dictTreeFeignClient.queryByCode(devType).getData();
|
||||
if (Objects.isNull(dictTreeVO)){
|
||||
throw new BusinessException(AccessResponseEnum.DEV_TYPE_NOT_FIND);
|
||||
} else if (Objects.equals(devType,DicDataEnum.DEV_CLD.getCode())) {
|
||||
//查询是否已存在云前置模板
|
||||
LambdaQueryWrapper<CsDevModelPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(CsDevModelPO::getName,DicDataEnum.DEV_CLD.getCode()).eq(CsDevModelPO::getStatus,1);
|
||||
List<CsDevModelPO> list = csDevModelMapper.selectList(lambdaQueryWrapper);
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
throw new BusinessException(AccessResponseEnum.CLD_MODEL_EXIST);
|
||||
}
|
||||
}
|
||||
logDto.setOperate("新增设备模板,模板名称:" + templateDto.getDevType());
|
||||
//模板文件存入文件服务器
|
||||
String filePath = fileStorageUtil.uploadMultipart(file, OssPath.DEV_MODEL + templateDto.getDevType() + "_");
|
||||
@@ -100,6 +120,24 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
analysisDataSet(templateDto,csDevModelPo.getId());
|
||||
//3.录入监测点模板表(记录当前模板有几个监测点,治理类型的模板目前规定1个监测点,电能质量模板根据逻辑子设备来)
|
||||
addCsLineModel(templateDto,csDevModelPo.getId());
|
||||
//4.如果是云前置的模板录入,重新录入完需要将模板关系信息重新录入
|
||||
if (Objects.equals(devType,DicDataEnum.DEV_CLD.getCode())) {
|
||||
List<CsEquipmentDeliveryPO> list = eequipmentFeignClient.getAll().getData();
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
List<String> devList = list.stream()
|
||||
.filter(item -> Objects.equals(item.getDevAccessMethod(),"CLD"))
|
||||
.map(CsEquipmentDeliveryPO::getId)
|
||||
.collect(Collectors.toList());
|
||||
devModelRelationFeignClient.updateDataByList(devList,csDevModelPo.getId());
|
||||
Object object = redisUtil.getObjectByKey("setId:" + csDevModelPo.getId());
|
||||
if (ObjectUtil.isNotNull(object)) {
|
||||
csLineFeignClient.updateDataByList(devList,csDevModelPo.getId(),object.toString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//5.清空模板缓存
|
||||
redisUtil.deleteKeysByString(AppRedisKey.DEV_MODEL);
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
} catch (Exception e) {
|
||||
logDto.setResult(0);
|
||||
@@ -361,15 +399,15 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
eleEpdPqdParam.setStatMethod(apf.getStatMethod());
|
||||
eleEpdPqdParam.setDataType(id);
|
||||
if (Objects.isNull(apf.getPhase())){
|
||||
eleEpdPqdParam.setPhase("M");
|
||||
eleEpdPqdParam.setPhase("T");
|
||||
} else {
|
||||
eleEpdPqdParam.setPhase(apf.getPhase());
|
||||
}
|
||||
eleEpdPqdParam.setClassId(classId);
|
||||
if (!Objects.isNull(apf.getHarmStart())){
|
||||
if (Objects.equals(apf.getHarmStart(),0.5) && Objects.equals(apf.getHarmEnd(),49.5)){
|
||||
if (Objects.equals(apf.getHarmStart(),0.5)){
|
||||
eleEpdPqdParam.setHarmStart((int)(apf.getHarmStart()+0.5));
|
||||
eleEpdPqdParam.setHarmEnd((int)(apf.getHarmEnd()+49.5));
|
||||
eleEpdPqdParam.setHarmEnd((int)(apf.getHarmEnd()+0.5));
|
||||
} else {
|
||||
eleEpdPqdParam.setHarmStart((int)(apf.getHarmStart()*1.0));
|
||||
eleEpdPqdParam.setHarmEnd((int)(apf.getHarmEnd()*1.0));
|
||||
@@ -395,7 +433,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
eleEpdPqdParam.setEventType(evt.getEventType());
|
||||
eleEpdPqdParam.setDataType(id);
|
||||
if (Objects.isNull(evt.getPhase())){
|
||||
eleEpdPqdParam.setPhase("M");
|
||||
eleEpdPqdParam.setPhase("T");
|
||||
} else {
|
||||
eleEpdPqdParam.setPhase(evt.getPhase());
|
||||
}
|
||||
@@ -456,7 +494,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
//告警code,到时候推送给用户告警码+事件时间
|
||||
eleEpdPqdParam.setDefaultValue(alm.getCode());
|
||||
if (Objects.isNull(alm.getPhase())){
|
||||
eleEpdPqdParam.setPhase("M");
|
||||
eleEpdPqdParam.setPhase("T");
|
||||
} else {
|
||||
eleEpdPqdParam.setPhase(alm.getPhase());
|
||||
}
|
||||
@@ -483,7 +521,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
eleEpdPqdParam.setTranRule(sts.getTranRule());
|
||||
eleEpdPqdParam.setDataType(id);
|
||||
if (Objects.isNull(sts.getPhase())){
|
||||
eleEpdPqdParam.setPhase("M");
|
||||
eleEpdPqdParam.setPhase("T");
|
||||
} else {
|
||||
eleEpdPqdParam.setPhase(sts.getPhase());
|
||||
}
|
||||
@@ -515,7 +553,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
eleEpdPqdParam.setDefaultValue(parm.getDefaultValue());
|
||||
eleEpdPqdParam.setDataType(id);
|
||||
if (Objects.isNull(parm.getPhase())){
|
||||
eleEpdPqdParam.setPhase("M");
|
||||
eleEpdPqdParam.setPhase("T");
|
||||
} else {
|
||||
eleEpdPqdParam.setPhase(parm.getPhase());
|
||||
}
|
||||
@@ -544,7 +582,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
eleEpdPqdParam.setUnit(set.getUnit());
|
||||
eleEpdPqdParam.setDataType(id);
|
||||
if (Objects.isNull(set.getPhase())){
|
||||
eleEpdPqdParam.setPhase("M");
|
||||
eleEpdPqdParam.setPhase("T");
|
||||
} else {
|
||||
eleEpdPqdParam.setPhase(set.getPhase());
|
||||
}
|
||||
@@ -576,7 +614,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
eleEpdPqdParam.setMinNum(ctrl.getMinNum());
|
||||
eleEpdPqdParam.setDataType(id);
|
||||
if (Objects.isNull(ctrl.getPhase())){
|
||||
eleEpdPqdParam.setPhase("M");
|
||||
eleEpdPqdParam.setPhase("T");
|
||||
} else {
|
||||
eleEpdPqdParam.setPhase(ctrl.getPhase());
|
||||
}
|
||||
@@ -600,15 +638,15 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
eleEpdPqdParam.setSort(epd.getIdx());
|
||||
eleEpdPqdParam.setType(epd.getType());
|
||||
if (Objects.isNull(epd.getPhase())){
|
||||
eleEpdPqdParam.setPhase("M");
|
||||
eleEpdPqdParam.setPhase("T");
|
||||
} else {
|
||||
eleEpdPqdParam.setPhase(epd.getPhase());
|
||||
}
|
||||
eleEpdPqdParam.setUnit(epd.getUnit());
|
||||
if (!Objects.isNull(epd.getHarmStart())){
|
||||
if (Objects.equals(epd.getHarmStart(),0.5) && Objects.equals(epd.getHarmEnd(),49.5)){
|
||||
if (Objects.equals(epd.getHarmStart(),0.5)){
|
||||
eleEpdPqdParam.setHarmStart((int)(epd.getHarmStart()+0.5));
|
||||
eleEpdPqdParam.setHarmEnd((int)(epd.getHarmEnd()+49.5));
|
||||
eleEpdPqdParam.setHarmEnd((int)(epd.getHarmEnd()+0.5));
|
||||
} else {
|
||||
eleEpdPqdParam.setHarmStart((int)(epd.getHarmStart()*1.0));
|
||||
eleEpdPqdParam.setHarmEnd((int)(epd.getHarmEnd()*1.0));
|
||||
@@ -636,20 +674,21 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
eleEpdPqdParam.setSort(pqd.getIdx());
|
||||
eleEpdPqdParam.setType(pqd.getType());
|
||||
if (Objects.isNull(pqd.getPhase())){
|
||||
eleEpdPqdParam.setPhase("M");
|
||||
eleEpdPqdParam.setPhase("T");
|
||||
} else {
|
||||
eleEpdPqdParam.setPhase(pqd.getPhase());
|
||||
}
|
||||
eleEpdPqdParam.setUnit(pqd.getUnit());
|
||||
if (!Objects.isNull(pqd.getHarmStart())){
|
||||
if (Objects.equals(pqd.getHarmStart(),0.5) && Objects.equals(pqd.getHarmEnd(),49.5)){
|
||||
if (Objects.equals(pqd.getHarmStart(),0.5)){
|
||||
eleEpdPqdParam.setHarmStart((int)(pqd.getHarmStart()+0.5));
|
||||
eleEpdPqdParam.setHarmEnd((int)(pqd.getHarmEnd()+49.5));
|
||||
eleEpdPqdParam.setHarmEnd((int)(pqd.getHarmEnd()+0.5));
|
||||
} else {
|
||||
eleEpdPqdParam.setHarmStart((int)(pqd.getHarmStart()*1.0));
|
||||
eleEpdPqdParam.setHarmEnd((int)(pqd.getHarmEnd()*1.0));
|
||||
}
|
||||
}
|
||||
eleEpdPqdParam.setStatMethod(pqd.getStatMethod());
|
||||
eleEpdPqdParam.setDataType(id);
|
||||
eleEpdPqdParam.setClassId(classId);
|
||||
result.add(eleEpdPqdParam);
|
||||
@@ -671,7 +710,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
eleEpdPqdParam.setSort(bmd.getIdx());
|
||||
eleEpdPqdParam.setType(bmd.getType());
|
||||
if (Objects.isNull(bmd.getPhase())){
|
||||
eleEpdPqdParam.setPhase("M");
|
||||
eleEpdPqdParam.setPhase("T");
|
||||
} else {
|
||||
eleEpdPqdParam.setPhase(bmd.getPhase());
|
||||
}
|
||||
@@ -702,7 +741,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
eleEpdPqdParam.setTranFlag(di.getTranFlag());
|
||||
eleEpdPqdParam.setTranRule(di.getTranRule());
|
||||
if (Objects.isNull(di.getPhase())){
|
||||
eleEpdPqdParam.setPhase("M");
|
||||
eleEpdPqdParam.setPhase("T");
|
||||
} else {
|
||||
eleEpdPqdParam.setPhase(di.getPhase());
|
||||
}
|
||||
@@ -728,7 +767,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
eleEpdPqdParam.setCurSts(dto.getCurSts());
|
||||
eleEpdPqdParam.setCtlSts(dto.getCtlSts());
|
||||
if (Objects.isNull(dto.getPhase())){
|
||||
eleEpdPqdParam.setPhase("M");
|
||||
eleEpdPqdParam.setPhase("T");
|
||||
} else {
|
||||
eleEpdPqdParam.setPhase(dto.getPhase());
|
||||
}
|
||||
@@ -758,7 +797,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
eleEpdPqdParam.setUnit(inSet.getUnit());
|
||||
eleEpdPqdParam.setDataType(id);
|
||||
if (Objects.isNull(inSet.getPhase())){
|
||||
eleEpdPqdParam.setPhase("M");
|
||||
eleEpdPqdParam.setPhase("T");
|
||||
} else {
|
||||
eleEpdPqdParam.setPhase(inSet.getPhase());
|
||||
}
|
||||
@@ -781,7 +820,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
eleEpdPqdParam.setShowName(wave.getName());
|
||||
eleEpdPqdParam.setSort(wave.getIdx());
|
||||
eleEpdPqdParam.setDataType(id);
|
||||
eleEpdPqdParam.setPhase("M");
|
||||
eleEpdPqdParam.setPhase("T");
|
||||
eleEpdPqdParam.setClassId(classId);
|
||||
EleEpdPqd po = epdFeignClient.add(eleEpdPqdParam).getData();
|
||||
if (CollectionUtil.isNotEmpty(wave.getParam())){
|
||||
@@ -833,15 +872,18 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
* 解析数据集、详细数据
|
||||
*/
|
||||
private void analysisDataSet(TemplateDto templateDto,String pId){
|
||||
String code;
|
||||
List<CsDataSet> setList = new ArrayList<>();
|
||||
List<CsDataArray> arrayList = new ArrayList<>();
|
||||
List<DataSetDto> dataSetList = templateDto.getDataSet();
|
||||
String devType = templateDto.getDevType();
|
||||
DictTreeVO dictTreeVO = dictTreeFeignClient.queryByCode(devType).getData();
|
||||
if (Objects.isNull(dictTreeVO)){
|
||||
throw new BusinessException(AccessResponseEnum.DEV_TYPE_NOT_FIND);
|
||||
if (!DicDataEnum.DEV_CLD.getCode().equals(devType)){
|
||||
DictTreeVO dictTreeVO = dictTreeFeignClient.queryByCode(devType).getData();
|
||||
code = dictTreeFeignClient.queryById(dictTreeVO.getPid()).getData().getCode();
|
||||
} else {
|
||||
code = null;
|
||||
}
|
||||
String code = dictTreeFeignClient.queryById(dictTreeVO.getPid()).getData().getCode();
|
||||
|
||||
//逻辑设备录入
|
||||
if (CollectionUtil.isNotEmpty(dataSetList)){
|
||||
dataSetList.forEach(item1->{
|
||||
@@ -924,40 +966,46 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
}
|
||||
if(CollectionUtil.isNotEmpty(setList)) {
|
||||
csDataSetService.addList(setList);
|
||||
setList.forEach(item->{
|
||||
if (Objects.equals(item.getName(),"Ds$Pqd$Stat$01")) {
|
||||
redisUtil.saveByKeyWithExpire("setId:" + pId,item.getId(),30L);
|
||||
}
|
||||
});
|
||||
}
|
||||
if(CollectionUtil.isNotEmpty(arrayList)) {
|
||||
csDataArrayService.addList(arrayList);
|
||||
List<CsGroup> ls = new ArrayList<>();
|
||||
List<CsGroArr> groArrList = new ArrayList<>();
|
||||
Map<String,List<CsDataArray>> setMap = arrayList.stream().collect(Collectors.groupingBy(CsDataArray::getPid,LinkedHashMap::new,Collectors.toList()));
|
||||
setMap.forEach((k0,v0)->{
|
||||
AtomicReference<Integer> sort = new AtomicReference<>(0);
|
||||
Map<String,List<CsDataArray>> map = v0.stream().filter(a-> "avg".equals(a.getStatMethod()) || Objects.isNull(a.getStatMethod())).collect(Collectors.groupingBy(CsDataArray::getAnotherName,LinkedHashMap::new,Collectors.toList()));
|
||||
map.forEach((k,v)->{
|
||||
//录入组数据
|
||||
String groupId = IdUtil.simpleUUID();
|
||||
CsGroup csGroup = new CsGroup();
|
||||
csGroup.setId(groupId);
|
||||
csGroup.setDataSetId(k0);
|
||||
csGroup.setGroupName(k);
|
||||
csGroup.setSort(sort.getAndSet(sort.get() + 1));
|
||||
csGroup.setIsShow(1);
|
||||
ls.add(csGroup);
|
||||
//录入组和指标关系
|
||||
v.forEach(item->{
|
||||
CsGroArr csGroArr = new CsGroArr();
|
||||
csGroArr.setGroupId(groupId);
|
||||
csGroArr.setArrayId(item.getId());
|
||||
groArrList.add(csGroArr);
|
||||
});
|
||||
});
|
||||
});
|
||||
if(CollectionUtil.isNotEmpty(ls)) {
|
||||
csGroupService.addList(ls);
|
||||
}
|
||||
if(CollectionUtil.isNotEmpty(groArrList)) {
|
||||
csGroArrService.addGroArrList(groArrList);
|
||||
}
|
||||
//物联这边没有分组的要求,这部分代码先注释,用能那边用到这个代码
|
||||
// List<CsGroup> ls = new ArrayList<>();
|
||||
// List<CsGroArr> groArrList = new ArrayList<>();
|
||||
// Map<String,List<CsDataArray>> setMap = arrayList.stream().collect(Collectors.groupingBy(CsDataArray::getPid,LinkedHashMap::new,Collectors.toList()));
|
||||
// setMap.forEach((k0,v0)->{
|
||||
// AtomicReference<Integer> sort = new AtomicReference<>(0);
|
||||
// Map<String,List<CsDataArray>> map = v0.stream().filter(a-> "avg".equals(a.getStatMethod()) || Objects.isNull(a.getStatMethod())).collect(Collectors.groupingBy(CsDataArray::getAnotherName,LinkedHashMap::new,Collectors.toList()));
|
||||
// map.forEach((k,v)->{
|
||||
// //录入组数据
|
||||
// String groupId = IdUtil.simpleUUID();
|
||||
// CsGroup csGroup = new CsGroup();
|
||||
// csGroup.setId(groupId);
|
||||
// csGroup.setDataSetId(k0);
|
||||
// csGroup.setGroupName(k);
|
||||
// csGroup.setSort(sort.getAndSet(sort.get() + 1));
|
||||
// csGroup.setIsShow(1);
|
||||
// ls.add(csGroup);
|
||||
// //录入组和指标关系
|
||||
// v.forEach(item->{
|
||||
// CsGroArr csGroArr = new CsGroArr();
|
||||
// csGroArr.setGroupId(groupId);
|
||||
// csGroArr.setArrayId(item.getId());
|
||||
// groArrList.add(csGroArr);
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// if(CollectionUtil.isNotEmpty(ls)) {
|
||||
// csGroupService.addList(ls);
|
||||
// }
|
||||
// if(CollectionUtil.isNotEmpty(groArrList)) {
|
||||
// csGroArrService.addGroArrList(groArrList);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -977,91 +1025,91 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
List<ApfDto> apfList = templateDto.getApfDto();
|
||||
ApfDto apfDto = apfList.get(idx);
|
||||
name = apfDto.getName();
|
||||
phase = apfDto.getPhase() == null ? "M":apfDto.getPhase();
|
||||
phase = apfDto.getPhase() == null ? "T":apfDto.getPhase();
|
||||
break;
|
||||
case DataModel.EVT:
|
||||
log.info("查询evt字典数据");
|
||||
List<EvtDto> evtList = templateDto.getEvtDto();
|
||||
EvtDto evtDto = evtList.get(idx);
|
||||
name = evtDto.getName();
|
||||
phase = evtDto.getPhase() == null ? "M":evtDto.getPhase();
|
||||
phase = evtDto.getPhase() == null ? "T":evtDto.getPhase();
|
||||
break;
|
||||
case DataModel.ALM:
|
||||
log.info("查询alm字典数据");
|
||||
List<AlmDto> almList = templateDto.getAlmDto();
|
||||
AlmDto almDto = almList.get(idx);
|
||||
name = almDto.getName();
|
||||
phase = almDto.getPhase() == null ? "M":almDto.getPhase();
|
||||
phase = almDto.getPhase() == null ? "T":almDto.getPhase();
|
||||
break;
|
||||
case DataModel.STS:
|
||||
log.info("查询sts字典数据");
|
||||
List<StsDto> stsList = templateDto.getStsDto();
|
||||
StsDto stsDto = stsList.get(idx);
|
||||
name = stsDto.getName();
|
||||
phase = stsDto.getPhase() == null ? "M":stsDto.getPhase();
|
||||
phase = stsDto.getPhase() == null ? "T":stsDto.getPhase();
|
||||
break;
|
||||
case DataModel.PARM:
|
||||
log.info("查询parm字典数据");
|
||||
List<ParmDto> parmList = templateDto.getParmDto();
|
||||
ParmDto parmDto = parmList.get(idx);
|
||||
name = parmDto.getName();
|
||||
phase = parmDto.getPhase() == null ? "M":parmDto.getPhase();
|
||||
phase = parmDto.getPhase() == null ? "T":parmDto.getPhase();
|
||||
break;
|
||||
case DataModel.SET:
|
||||
log.info("查询set字典数据");
|
||||
List<SetDto> setList = templateDto.getSetDto();
|
||||
SetDto setDto = setList.get(idx);
|
||||
name = setDto.getName();
|
||||
phase = setDto.getPhase() == null ? "M":setDto.getPhase();
|
||||
phase = setDto.getPhase() == null ? "T":setDto.getPhase();
|
||||
break;
|
||||
case DataModel.CTRL:
|
||||
log.info("查询ctrl字典数据");
|
||||
List<CtrlDto> ctrlList = templateDto.getCtrlDto();
|
||||
CtrlDto ctrlDto = ctrlList.get(idx);
|
||||
name = ctrlDto.getName();
|
||||
phase = ctrlDto.getPhase() == null ? "M":ctrlDto.getPhase();
|
||||
phase = ctrlDto.getPhase() == null ? "T":ctrlDto.getPhase();
|
||||
break;
|
||||
case DataModel.EPD:
|
||||
log.info("查询epd字典数据");
|
||||
List<EpdPqdDto> epdList = templateDto.getEpdDto();
|
||||
EpdPqdDto epdDto = epdList.get(idx);
|
||||
name = epdDto.getName();
|
||||
phase = epdDto.getPhase() == null ? "M":epdDto.getPhase();
|
||||
phase = epdDto.getPhase() == null ? "T":epdDto.getPhase();
|
||||
break;
|
||||
case DataModel.PQD:
|
||||
log.info("查询pqd字典数据");
|
||||
List<EpdPqdDto> pqdList = templateDto.getPqdDto();
|
||||
EpdPqdDto pqdDto = pqdList.get(idx);
|
||||
name = pqdDto.getName();
|
||||
phase = pqdDto.getPhase() == null ? "M":pqdDto.getPhase();
|
||||
phase = pqdDto.getPhase() == null ? "T":pqdDto.getPhase();
|
||||
break;
|
||||
case DataModel.BMD:
|
||||
log.info("查询bmd字典数据");
|
||||
List<BmdDto> bmdList = templateDto.getBmdDto();
|
||||
BmdDto bmdDto = bmdList.get(idx);
|
||||
name = bmdDto.getName();
|
||||
phase = bmdDto.getPhase() == null ? "M":bmdDto.getPhase();
|
||||
phase = bmdDto.getPhase() == null ? "T":bmdDto.getPhase();
|
||||
break;
|
||||
case DataModel.DI:
|
||||
log.info("查询di字典数据");
|
||||
List<DiDto> diList = templateDto.getDiDto();
|
||||
DiDto diDto = diList.get(idx);
|
||||
name = diDto.getName();
|
||||
phase = diDto.getPhase() == null ? "M":diDto.getPhase();
|
||||
phase = diDto.getPhase() == null ? "T":diDto.getPhase();
|
||||
break;
|
||||
case DataModel.DO:
|
||||
log.info("查询do字典数据");
|
||||
List<DoDto> doList = templateDto.getDoDto();
|
||||
DoDto doDto = doList.get(idx);
|
||||
name = doDto.getName();
|
||||
phase = doDto.getPhase() == null ? "M":doDto.getPhase();
|
||||
phase = doDto.getPhase() == null ? "T":doDto.getPhase();
|
||||
break;
|
||||
case DataModel.INSET:
|
||||
log.info("查询inset字典数据");
|
||||
List<InSetDto> inSetList = templateDto.getInSetDto();
|
||||
InSetDto inSetDto = inSetList.get(idx);
|
||||
name = inSetDto.getName();
|
||||
phase = inSetDto.getPhase() == null ? "M":inSetDto.getPhase();
|
||||
phase = inSetDto.getPhase() == null ? "T":inSetDto.getPhase();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -1071,7 +1119,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
log.info("指标名称:"+name+",数据类型:"+id+",相别:"+phase);
|
||||
throw new BusinessException(AccessResponseEnum.DICT_MISSING);
|
||||
}
|
||||
// M 代表没有数据,因为influxDB要录入数据,此字段是主键,给个默认值
|
||||
// T 代表没有数据,因为influxDB要录入数据,此字段是主键,给个默认值
|
||||
if (!Objects.isNull(eleEpdPqd.getHarmStart()) && !Objects.isNull(eleEpdPqd.getHarmEnd())){
|
||||
if (Objects.equals(eleEpdPqd.getHarmStart(),1)){
|
||||
for (int i = eleEpdPqd.getHarmStart(); i <= eleEpdPqd.getHarmEnd(); i++) {
|
||||
@@ -1094,7 +1142,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
CsDataArray.setDataId(eleEpdPqd.getId());
|
||||
CsDataArray.setName(eleEpdPqd.getName() + "_" + i);
|
||||
CsDataArray.setAnotherName((i-0.5) + "次" +eleEpdPqd.getShowName());
|
||||
CsDataArray.setStatMethod("M");
|
||||
CsDataArray.setStatMethod("T");
|
||||
CsDataArray.setDataType(eleEpdPqd.getType());
|
||||
CsDataArray.setPhase(eleEpdPqd.getPhase());
|
||||
list.add(CsDataArray);
|
||||
@@ -1121,7 +1169,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
CsDataArray.setDataId(eleEpdPqd.getId());
|
||||
CsDataArray.setName(eleEpdPqd.getName() + "_" + i);
|
||||
CsDataArray.setAnotherName(i + "次" +eleEpdPqd.getShowName());
|
||||
CsDataArray.setStatMethod("M");
|
||||
CsDataArray.setStatMethod("T");
|
||||
CsDataArray.setDataType(eleEpdPqd.getType());
|
||||
CsDataArray.setPhase(eleEpdPqd.getPhase());
|
||||
list.add(CsDataArray);
|
||||
@@ -1148,7 +1196,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
CsDataArray.setDataId(eleEpdPqd.getId());
|
||||
CsDataArray.setName(eleEpdPqd.getName());
|
||||
CsDataArray.setAnotherName(eleEpdPqd.getShowName());
|
||||
CsDataArray.setStatMethod("M");
|
||||
CsDataArray.setStatMethod("T");
|
||||
CsDataArray.setDataType(eleEpdPqd.getType());
|
||||
CsDataArray.setPhase(eleEpdPqd.getPhase());
|
||||
list.add(CsDataArray);
|
||||
@@ -1226,19 +1274,26 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
showName = "APF模块8数据模板";
|
||||
break;
|
||||
case "Ds$Pqd$Stat$01":
|
||||
if (Objects.equals(code, DicDataEnum.CONNECT_DEV.getCode()) || Objects.isNull(code)){
|
||||
if (Objects.equals(code, DicDataEnum.CONNECT_DEV.getCode())){
|
||||
showName = "电网侧数据模板";
|
||||
} else if (Objects.equals(code, DicDataEnum.PORTABLE.getCode())){
|
||||
showName = "监测1#数据模板";
|
||||
} else {
|
||||
showName = "统计数据";
|
||||
}
|
||||
break;
|
||||
case "Ds$Pqd$Stat$02":
|
||||
if (Objects.equals(code, DicDataEnum.CONNECT_DEV.getCode()) || Objects.isNull(code)){
|
||||
if (Objects.equals(code, DicDataEnum.CONNECT_DEV.getCode())){
|
||||
showName = "负载侧数据模板";
|
||||
} else if (Objects.equals(code, DicDataEnum.PORTABLE.getCode())){
|
||||
showName = "监测2#数据模板";
|
||||
} else {
|
||||
showName = "统计数据";
|
||||
}
|
||||
break;
|
||||
case "Ds$Pqd$Rt$01":
|
||||
showName = "实时数据";
|
||||
break;
|
||||
//波形参数名称
|
||||
case "Wave_Param_Position":
|
||||
showName = "录波记录位置";
|
||||
|
||||
@@ -22,17 +22,20 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.api.*;
|
||||
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
||||
import com.njcn.csdevice.pojo.param.CsDevModelRelationAddParm;
|
||||
import com.njcn.csdevice.pojo.param.CsLedgerParam;
|
||||
import com.njcn.csdevice.pojo.param.CsLineParam;
|
||||
import com.njcn.csdevice.param.LineInfoParam;
|
||||
import com.njcn.csdevice.pojo.param.*;
|
||||
import com.njcn.csdevice.pojo.po.*;
|
||||
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
|
||||
import com.njcn.csharmonic.api.CsHarmonicPlanLineFeignClient;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.api.DictTreeFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.pojo.po.SysDicTreePO;
|
||||
import com.njcn.user.api.UserFeignClient;
|
||||
import com.njcn.user.enums.AppRoleEnum;
|
||||
import com.njcn.user.pojo.vo.UserVO;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -80,6 +83,12 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
private final ChannelObjectUtil channelObjectUtil;
|
||||
private final CsLineFeignClient csLineFeignClient;
|
||||
private final DataSetFeignClient dataSetFeignClient;
|
||||
private final CsMarketDataFeignClient csMarketDataFeignClient;
|
||||
private final UserFeignClient userFeignClient;
|
||||
private final EngineeringFeignClient engineeringFeignClient;
|
||||
private final AppProjectFeignClient appProjectFeignClient;
|
||||
private final DeviceMessageFeignClient deviceMessageFeignClient;
|
||||
private final CsHarmonicPlanLineFeignClient csHarmonicPlanLineFeignClient;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
@@ -130,15 +139,16 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
throw new BusinessException(AccessResponseEnum.MISSING_CLIENT);
|
||||
}
|
||||
//5.判断当前流程是否是合法的
|
||||
if (csEquipmentDeliveryVO.getProcess() > type){
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.PROCESS_SAME_ERROR.getMessage());
|
||||
throw new BusinessException(AccessResponseEnum.PROCESS_SAME_ERROR);
|
||||
} else if (csEquipmentDeliveryVO.getProcess() < type){
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.PROCESS_MISSING_ERROR.getMessage());
|
||||
throw new BusinessException(AccessResponseEnum.PROCESS_MISSING_ERROR);
|
||||
}
|
||||
//note(重要说明) 这边流程原先是三个阶段,在实际应用中嫌麻烦,简化为一个流程
|
||||
// if (csEquipmentDeliveryVO.getProcess() > type){
|
||||
// logDto.setResult(0);
|
||||
// logDto.setFailReason(AccessResponseEnum.PROCESS_SAME_ERROR.getMessage());
|
||||
// throw new BusinessException(AccessResponseEnum.PROCESS_SAME_ERROR);
|
||||
// } else if (csEquipmentDeliveryVO.getProcess() < type){
|
||||
// logDto.setResult(0);
|
||||
// logDto.setFailReason(AccessResponseEnum.PROCESS_MISSING_ERROR.getMessage());
|
||||
// throw new BusinessException(AccessResponseEnum.PROCESS_MISSING_ERROR);
|
||||
// }
|
||||
//6.询问设备支持的主题信息
|
||||
//将支持的主题入库
|
||||
askTopic(nDid);
|
||||
@@ -184,6 +194,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
//fixme 这边事务不起作用,中途出错会导致数据部分录入,再次接入会报主键冲突,所以暂时加了个重置按钮,清空台账数据的
|
||||
public void devAccess(DevAccessParam devAccessParam) {
|
||||
//日志实体
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
@@ -268,6 +279,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
appLineTopologyDiagramPo.setLat(item.getLat());
|
||||
appLineTopologyDiagramPo.setLng(item.getLng());
|
||||
appLineTopologyDiagramPo.setStatus("1");
|
||||
appLineTopologyDiagramPo.setTarget(item.getTarget());
|
||||
appLineTopologyDiagramPoList.add(appLineTopologyDiagramPo);
|
||||
}
|
||||
List<String> position = csLinePoList.stream().map(CsLinePO::getPosition).collect(Collectors.toList());
|
||||
@@ -278,8 +290,17 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AccessResponseEnum.LINE_POSITION_REPEAT);
|
||||
}
|
||||
//删除监测点稳态指标告警的默认指标配置
|
||||
List<String> lineIdList = csLinePoList.stream().map(CsLinePO::getLineId).collect(Collectors.toList());
|
||||
csHarmonicPlanLineFeignClient.deleteByLineIds(lineIdList);
|
||||
csLineService.saveBatch(csLinePoList);
|
||||
|
||||
redisUtil.saveByKeyWithExpire("accessLineInfo:" + devAccessParam.getNDid(),csLinePoList,30L);
|
||||
//缓存监测点信息
|
||||
LineInfoParam param = new LineInfoParam();
|
||||
param.setNDid(devAccessParam.getNDid());
|
||||
param.setList(csLinePoList);
|
||||
deviceMessageFeignClient.getLineInfo(param);
|
||||
//4.监测点拓扑图表录入关系
|
||||
appLineTopologyDiagramService.saveBatch(appLineTopologyDiagramPoList);
|
||||
//5.绑定装置和人的关系
|
||||
@@ -289,16 +310,16 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
po.setSubUserId(RequestUtil.getUserIndex());
|
||||
po.setDeviceId(vo.getId());
|
||||
csDeviceUserService.saveBatch(Collections.singletonList(po));
|
||||
//6.修改装置状态
|
||||
csEquipmentDeliveryService.updateStatusBynDid(devAccessParam.getNDid(), AccessEnum.REGISTERED.getCode());
|
||||
//6.修改装置状态;修改设备接入的工程、项目
|
||||
csEquipmentDeliveryService.updateStatusBynDid(devAccessParam.getNDid(), AccessEnum.REGISTERED.getCode(),devAccessParam.getEngineeringId(), devAccessParam.getProjectId());
|
||||
//7.发起自动接入请求
|
||||
devAccessAskTemplate(devAccessParam.getNDid(),version,1);
|
||||
//8.删除redis监测点模板信息
|
||||
redisUtil.delete(AppRedisKey.MODEL + devAccessParam.getNDid());
|
||||
redisUtil.delete(AppRedisKey.LINE + devAccessParam.getNDid());
|
||||
//存储日志
|
||||
//9.存储日志
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
//存储设备调试日志表
|
||||
//10.存储设备调试日志表
|
||||
CsEquipmentProcessPO csEquipmentProcess = new CsEquipmentProcessPO();
|
||||
csEquipmentProcess.setDevId(devAccessParam.getNDid());
|
||||
csEquipmentProcess.setOperator(RequestUtil.getUserIndex());
|
||||
@@ -309,6 +330,14 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
csEquipmentProcess.setStatus(1);
|
||||
}
|
||||
processFeignClient.add(csEquipmentProcess);
|
||||
//11.这里会出现工程用户接入设备时,如果当前工程用户并没有关注,接入之后应该将用户和工程关联起来
|
||||
List<UserVO> users = userFeignClient.getUserVOByIdList(Collections.singletonList(RequestUtil.getUserIndex())).getData();
|
||||
if (CollectionUtil.isNotEmpty(users)) {
|
||||
UserVO userVO = users.get(0);
|
||||
if (CollectionUtil.isNotEmpty(userVO.getRoleCode()) && userVO.getRoleCode().contains(AppRoleEnum.ENGINEERING_USER.getCode())) {
|
||||
csMarketDataFeignClient.insertData(userVO.getId(), devAccessParam.getEngineeringId());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(e.getMessage());
|
||||
@@ -327,7 +356,13 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
param.setNDid(nDid);
|
||||
param.setStatus(1);
|
||||
param.setRunStatus(1);
|
||||
param.setProcess(2);
|
||||
// boolean isConnectDev = DicDataEnum.CONNECT_DEV.getCode().equals(dictTreeFeignClient.queryById(csEquipmentDeliveryVO.getDevType()).getData().getCode());
|
||||
// if (isConnectDev) {
|
||||
// param.setProcess(2);
|
||||
// } else {
|
||||
// param.setProcess(4);
|
||||
// }
|
||||
param.setProcess(4);
|
||||
csEquipmentDeliveryService.devResetFactory(param);
|
||||
//清除关系表
|
||||
QueryWrapper<CsLedger> csLedgerQueryWrapper = new QueryWrapper<>();
|
||||
@@ -360,6 +395,10 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
appLineTopologyDiagramPOQueryWrapper.in("line_id",collect);
|
||||
appLineTopologyDiagramService.remove(appLineTopologyDiagramPOQueryWrapper);
|
||||
}
|
||||
//删除topic表
|
||||
csTopicService.deleteByNDid(nDid);
|
||||
//清空缓存
|
||||
redisUtil.deleteKeysByString(AppRedisKey.LINE_POSITION+nDid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -370,14 +409,9 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String wlDevRegister(String nDid) {
|
||||
String result = "fail";
|
||||
// 设备状态判断
|
||||
checkDeviceStatus(nDid);
|
||||
// 询问设备支持的主题信息,并将支持的主题入库
|
||||
askAndStoreTopics(nDid);
|
||||
// MQTT询问装置用的模板,并判断库中是否存在模板
|
||||
checkDeviceModel(nDid);
|
||||
// 根据模板接入设备
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName(RequestUtil.getUserNickname());
|
||||
@@ -385,15 +419,24 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
logDto.setOperate("便携式设备"+nDid+"注册、接入");
|
||||
logDto.setResult(1);
|
||||
try {
|
||||
// 设备状态判断
|
||||
checkDeviceStatus(nDid);
|
||||
// 询问设备支持的主题信息,并将支持的主题入库
|
||||
askAndStoreTopics(nDid);
|
||||
Thread.sleep(2000);
|
||||
// MQTT询问装置用的模板,并判断库中是否存在模板
|
||||
checkDeviceModel(nDid);
|
||||
Thread.sleep(2000);
|
||||
//获取版本
|
||||
String version = csTopicService.getVersion(nDid);
|
||||
CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(nDid).getData();
|
||||
List<CsLinePO> csLinePoList = new ArrayList<>();
|
||||
//1.录入装置台账信息
|
||||
//note 1、这边发现便携式设备注册时,如果没有工程 项目,后期特殊处理非常的麻烦,这边接入时,先查询工程 项目,如果没有则创建;如果存在则直接使用;
|
||||
//note 2、查询之前已经接入过的便携式设备,如果存在修改台账信息,添加工程、项目
|
||||
String projectId = this.autoPortableLedger();
|
||||
//新增便携式设备
|
||||
CsLedgerParam csLedgerParam = new CsLedgerParam();
|
||||
csLedgerParam.setId(vo.getId());
|
||||
csLedgerParam.setPid("0");
|
||||
csLedgerParam.setPid(projectId);
|
||||
csLedgerParam.setName(vo.getName());
|
||||
csLedgerParam.setLevel(2);
|
||||
csLedgerParam.setSort(0);
|
||||
@@ -402,7 +445,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
Thread.sleep(2000);
|
||||
List<CsModelDto> modelList = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + nDid),CsModelDto.class);
|
||||
if (CollUtil.isEmpty(modelList)) {
|
||||
throwExceptionAndLog(AccessResponseEnum.MODEL_ERROR, logDto);
|
||||
throwExceptionAndLog(nDid,AccessResponseEnum.MODEL_ERROR, logDto);
|
||||
}
|
||||
List<CsDataSet> list = csDataSetService.getDataSetData(modelList.get(0).getModelId());
|
||||
list.forEach(item->{
|
||||
@@ -431,6 +474,11 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
});
|
||||
csLineService.saveBatch(csLinePoList);
|
||||
redisUtil.saveByKeyWithExpire("accessLineInfo:" + nDid,csLinePoList,30L);
|
||||
//缓存监测点信息
|
||||
LineInfoParam param = new LineInfoParam();
|
||||
param.setNDid(nDid);
|
||||
param.setList(csLinePoList);
|
||||
deviceMessageFeignClient.getLineInfo(param);
|
||||
//4.生成装置和模板的关系表
|
||||
CsDevModelRelationAddParm csDevModelRelationAddParm = new CsDevModelRelationAddParm();
|
||||
csDevModelRelationAddParm.setDevId(vo.getId());
|
||||
@@ -439,20 +487,14 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
csDevModelRelationService.addDevModelRelation(csDevModelRelationAddParm);
|
||||
//5.发起自动接入请求
|
||||
Thread.sleep(2000);
|
||||
//先获取版本
|
||||
//String version = csTopicService.getVersion(nDid);
|
||||
String version = "V1";
|
||||
devAccessAskTemplate(nDid,version,1);
|
||||
//6.修改流程,便携式设备接入成功即为实际环境
|
||||
csEquipmentDeliveryService.updateProcessBynDid(nDid,4);
|
||||
//7.存储日志
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
//8.存储设备调试日志表
|
||||
CsEquipmentProcessPO csEquipmentProcess = new CsEquipmentProcessPO();
|
||||
csEquipmentProcess.setDevId(nDid);
|
||||
csEquipmentProcess.setOperator(RequestUtil.getUserIndex());
|
||||
csEquipmentProcess.setStartTime(LocalDateTime.now());
|
||||
csEquipmentProcess.setEndTime(LocalDateTime.now());
|
||||
csEquipmentProcess.setProcess(4);
|
||||
csEquipmentProcess.setStatus(1);
|
||||
processFeignClient.add(csEquipmentProcess);
|
||||
//9.删除redis监测点模板信息
|
||||
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
||||
redisUtil.delete(AppRedisKey.LINE + nDid);
|
||||
@@ -466,6 +508,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(e.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
resetFactory(nDid);
|
||||
throw new BusinessException(AccessResponseEnum.ACCESS_ERROR);
|
||||
}
|
||||
return result;
|
||||
@@ -481,22 +524,165 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
this.devAccessAskTemplate(nDid,version,1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String autoPortableLedger() {
|
||||
CsEngineeringPO csEngineeringPO = engineeringFeignClient.getEngineeringByName("便携式工程").getData();
|
||||
if (csEngineeringPO == null) {
|
||||
//新增便携式工程
|
||||
CsEngineeringAddParm param = new CsEngineeringAddParm();
|
||||
param.setName("便携式工程");
|
||||
param.setProvince("320000000000");
|
||||
param.setCity("320100000000");
|
||||
param.setDescription("便携式工程");
|
||||
param.setSort(Integer.MAX_VALUE);
|
||||
csEngineeringPO = engineeringFeignClient.addEngineering(param).getData();
|
||||
}
|
||||
|
||||
AppProjectPO csProjectPO = appProjectFeignClient.getProjectByName("便携式项目").getData();
|
||||
if (csProjectPO == null) {
|
||||
//新增便携式项目
|
||||
AppProjectAddParm param = new AppProjectAddParm();
|
||||
param.setEngineeringId(csEngineeringPO.getId());
|
||||
param.setName("便携式项目");
|
||||
param.setArea("园区");
|
||||
param.setDescription("便携式项目");
|
||||
param.setTopoIds(Collections.singletonList("99ed9b9c8cf9007cc4d2ac4c7127b7e4"));
|
||||
param.setSort(Integer.MAX_VALUE);
|
||||
csProjectPO = appProjectFeignClient.addPortableProject(param).getData();
|
||||
}
|
||||
//修改已存在的便携式设备
|
||||
csLedgerService.updatePortableLedger(csEngineeringPO.getId(),csProjectPO.getId());
|
||||
return csProjectPO.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String onlineRegister(String projectId,String nDid) {
|
||||
String result = "fail";
|
||||
// 根据模板接入设备
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName(RequestUtil.getUserNickname());
|
||||
logDto.setLoginName(RequestUtil.getUsername());
|
||||
logDto.setOperate("监测设备"+nDid+"注册、接入");
|
||||
logDto.setResult(1);
|
||||
try {
|
||||
// 设备状态判断
|
||||
checkDeviceStatus(nDid);
|
||||
// 询问设备支持的主题信息,并将支持的主题入库
|
||||
askAndStoreTopics(nDid);
|
||||
Thread.sleep(2000);
|
||||
// MQTT询问装置用的模板,并判断库中是否存在模板
|
||||
checkDeviceModel(nDid);
|
||||
Thread.sleep(2000);
|
||||
CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(nDid).getData();
|
||||
List<CsLinePO> csLinePoList = new ArrayList<>();
|
||||
//1.录入装置台账信息
|
||||
//新增监测设备
|
||||
CsLedgerParam csLedgerParam = new CsLedgerParam();
|
||||
csLedgerParam.setId(vo.getId());
|
||||
csLedgerParam.setPid(projectId);
|
||||
csLedgerParam.setName(vo.getName());
|
||||
csLedgerParam.setLevel(2);
|
||||
csLedgerParam.setSort(0);
|
||||
csLedgerService.addLedgerTree(csLedgerParam);
|
||||
//2.根据模板获取监测点个数,插入监测点表
|
||||
Thread.sleep(2000);
|
||||
List<CsModelDto> modelList = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + nDid),CsModelDto.class);
|
||||
if (CollUtil.isEmpty(modelList)) {
|
||||
throwExceptionAndLog(nDid,AccessResponseEnum.MODEL_ERROR, logDto);
|
||||
}
|
||||
List<CsDataSet> list = csDataSetService.getDataSetData(modelList.get(0).getModelId());
|
||||
list.forEach(item->{
|
||||
CsLinePO po = new CsLinePO();
|
||||
po.setLineId(nDid + item.getClDev().toString());
|
||||
po.setName(item.getClDev().toString() + "#监测点");
|
||||
po.setStatus(1);
|
||||
po.setClDid(item.getClDev());
|
||||
po.setLineNo(item.getClDev());
|
||||
po.setRunStatus(0);
|
||||
po.setDeviceId(vo.getId());
|
||||
po.setDataSetId(item.getId());
|
||||
po.setDataModelId(item.getPid());
|
||||
//防止主键重复
|
||||
QueryWrapper<CsLinePO> qw = new QueryWrapper<>();
|
||||
qw.eq("line_id",po.getLineId());
|
||||
if(csLineService.getBaseMapper().selectList(qw).isEmpty()){
|
||||
csLinePoList.add(po);
|
||||
}
|
||||
//3.生成台账树监测点数据
|
||||
CsLedgerParam param = new CsLedgerParam();
|
||||
param.setId(nDid + item.getClDev().toString());
|
||||
param.setPid(vo.getId());
|
||||
param.setName(item.getClDev().toString() + "#监测点");
|
||||
param.setLevel(3);
|
||||
param.setSort(0);
|
||||
csLedgerService.addLedgerTree(param);
|
||||
});
|
||||
csLineService.saveBatch(csLinePoList);
|
||||
redisUtil.saveByKeyWithExpire("accessLineInfo:" + nDid,csLinePoList,30L);
|
||||
//缓存监测点信息
|
||||
LineInfoParam param = new LineInfoParam();
|
||||
param.setNDid(nDid);
|
||||
param.setList(csLinePoList);
|
||||
deviceMessageFeignClient.getLineInfo(param);
|
||||
//4.生成装置和模板的关系表
|
||||
CsDevModelRelationAddParm csDevModelRelationAddParm = new CsDevModelRelationAddParm();
|
||||
csDevModelRelationAddParm.setDevId(vo.getId());
|
||||
csDevModelRelationAddParm.setModelId(modelList.get(0).getModelId());
|
||||
csDevModelRelationAddParm.setDid(modelList.get(0).getDid());
|
||||
csDevModelRelationService.addDevModelRelation(csDevModelRelationAddParm);
|
||||
//5.绑定装置和人的关系
|
||||
CsDeviceUserPO po = new CsDeviceUserPO();
|
||||
po.setPrimaryUserId(RequestUtil.getUserIndex());
|
||||
po.setStatus("1");
|
||||
po.setSubUserId(RequestUtil.getUserIndex());
|
||||
po.setDeviceId(vo.getId());
|
||||
csDeviceUserService.saveBatch(Collections.singletonList(po));
|
||||
|
||||
//发起自动接入请求
|
||||
Thread.sleep(2000);
|
||||
//先获取版本
|
||||
String version = "V1";
|
||||
devAccessAskTemplate(nDid,version,1);
|
||||
//6.修改流程,接入成功即为实际环境
|
||||
csEquipmentDeliveryService.updateProcessBynDid(nDid,4);
|
||||
//7.存储日志
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
//9.删除redis监测点模板信息
|
||||
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
||||
redisUtil.delete(AppRedisKey.LINE + nDid);
|
||||
//判断接入状态
|
||||
Thread.sleep(5000);
|
||||
Object object = redisUtil.getObjectByKey("online" + nDid);
|
||||
if (Objects.nonNull(object)) {
|
||||
result = "success";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(e.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
resetFactory(nDid);
|
||||
throw new BusinessException(e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void checkDeviceStatus(String nDid) {
|
||||
DeviceLogDTO logDto = createLogDto("当前设备"+nDid+"状态判断");
|
||||
CsEquipmentDeliveryVO csEquipmentDeliveryVO = csEquipmentDeliveryService.queryEquipmentBynDid(nDid);
|
||||
if (Objects.isNull(csEquipmentDeliveryVO.getNdid())) {
|
||||
throwExceptionAndLog(AccessResponseEnum.NDID_NO_FIND, logDto);
|
||||
throwExceptionAndLog(nDid,AccessResponseEnum.NDID_NO_FIND, logDto);
|
||||
}
|
||||
SysDicTreePO sysDicTreePo = dictTreeFeignClient.queryById(csEquipmentDeliveryVO.getDevType()).getData();
|
||||
if (Objects.isNull(sysDicTreePo)) {
|
||||
throwExceptionAndLog(AccessResponseEnum.DEV_NOT_FIND, logDto);
|
||||
throwExceptionAndLog(nDid,AccessResponseEnum.DEV_NOT_FIND, logDto);
|
||||
}
|
||||
String code = sysDicTreePo.getCode();
|
||||
if (!Objects.equals(code, DicDataEnum.PORTABLE.getCode())) {
|
||||
throwExceptionAndLog(AccessResponseEnum.DEV_IS_NOT_PORTABLE, logDto);
|
||||
if (!Objects.equals(code, DicDataEnum.PORTABLE.getCode()) && !Objects.equals(code, DicDataEnum.DEV_CLD.getCode())) {
|
||||
throwExceptionAndLog(nDid,AccessResponseEnum.DEV_IS_NOT_PORTABLE, logDto);
|
||||
}
|
||||
if (!mqttUtil.judgeClientOnline("NJCN-" + nDid.substring(nDid.length() - 6))) {
|
||||
throwExceptionAndLog(AccessResponseEnum.MISSING_CLIENT, logDto);
|
||||
throwExceptionAndLog(nDid,AccessResponseEnum.MISSING_CLIENT, logDto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -510,7 +696,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
CsEquipmentDeliveryVO csEquipmentDeliveryVO = csEquipmentDeliveryService.queryEquipmentBynDid(nDid);
|
||||
SysDicTreePO dictData = dictTreeFeignClient.queryById(csEquipmentDeliveryVO.getDevModel()).getData();
|
||||
if (Objects.isNull(dictData)) {
|
||||
throwExceptionAndLog(AccessResponseEnum.DEV_MODEL_NOT_FIND, logDto);
|
||||
throwExceptionAndLog(nDid,AccessResponseEnum.DEV_MODEL_NOT_FIND, logDto);
|
||||
}
|
||||
String devModel = dictData.getCode();
|
||||
zhiLianRegister(nDid,devModel);
|
||||
@@ -525,10 +711,11 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
return logDto;
|
||||
}
|
||||
|
||||
private void throwExceptionAndLog(AccessResponseEnum responseEnum, DeviceLogDTO logDto) {
|
||||
private void throwExceptionAndLog(String nDid,AccessResponseEnum responseEnum, DeviceLogDTO logDto) {
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(responseEnum.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
resetFactory(nDid);
|
||||
throw new BusinessException(responseEnum);
|
||||
}
|
||||
|
||||
@@ -604,6 +791,142 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 装置重新接入系统,需要校验所用的模板
|
||||
* @param nDid
|
||||
* @param version
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean autoAccess(String nDid,String version,Integer mid) {
|
||||
boolean result = false;
|
||||
try {
|
||||
String clientName = "NJCN-" + nDid.substring(nDid.length() - 6);
|
||||
boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
||||
if (!mqttClient) {
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
logDto.setResult(1);
|
||||
logDto.setOperate(nDid + "接入失败,装置客户端不在线");
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AlgorithmResponseEnum.DEV_OFFLINE);
|
||||
}
|
||||
Map<Integer,String> modelMap = new HashMap<>();
|
||||
//删除缓存数据
|
||||
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
||||
redisUtil.deleteKeysByString(AppRedisKey.DEV_MODEL);
|
||||
//询问装置当前所用模板
|
||||
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid,new Gson().toJson(getJson(mid,TypeEnum.TYPE_3.getCode())),1,false);
|
||||
//接收到模板,判断模板是否存在,替换模板,发起接入
|
||||
Thread.sleep(2000);
|
||||
List<CsModelDto> modelId = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + nDid),CsModelDto.class);
|
||||
if (CollUtil.isNotEmpty(modelId)) {
|
||||
CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(nDid).getData();
|
||||
//重新录入装置和模板关系信息
|
||||
for (CsModelDto item : modelId) {
|
||||
CsDevModelRelationPO po = new CsDevModelRelationPO();
|
||||
po.setDevId(vo.getId());
|
||||
po.setModelId(item.getModelId());
|
||||
po.setDid(item.getDid());
|
||||
po.setUpdateTime(LocalDateTime.now());
|
||||
csDevModelRelationService.addRelation(po);
|
||||
modelMap.put(item.getType(),item.getModelId());
|
||||
}
|
||||
//修改监测点使用的模板和数据集
|
||||
List<CsLinePO> lineList;
|
||||
Object object = redisUtil.getObjectByKey("accessLineInfo:" + nDid);
|
||||
if (Objects.isNull(object)) {
|
||||
lineList = csLineFeignClient.findByNdid(nDid).getData();
|
||||
for (CsLinePO item : lineList) {
|
||||
if (item.getClDid() == 0) {
|
||||
updateLineIds(modelMap.get(0),item.getClDid(),nDid);
|
||||
} else {
|
||||
updateLineIds(modelMap.get(1),item.getClDid(),nDid);
|
||||
}
|
||||
}
|
||||
}
|
||||
//发起接入
|
||||
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid, new Gson().toJson(getJson(mid,TypeEnum.TYPE_5.getCode())),1,false);
|
||||
//录波任务倒计时
|
||||
redisUtil.saveByKeyWithExpire("startFile:" + nDid,null,60L);
|
||||
result = true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
logDto.setResult(1);
|
||||
logDto.setOperate(nDid + "装置接入失败");
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean autoAccess2(String nDid, String version, Integer mid) {
|
||||
boolean result = false;
|
||||
try {
|
||||
String clientName = "NJCN-" + nDid.substring(nDid.length() - 6);
|
||||
boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
||||
if (!mqttClient) {
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
logDto.setResult(1);
|
||||
logDto.setOperate(nDid + "接入失败,装置客户端不在线");
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
// 改为返回false而不是抛出异常
|
||||
log.warn("设备 {} 客户端不在线", nDid);
|
||||
return false;
|
||||
}
|
||||
|
||||
Map<Integer, String> modelMap = new HashMap<>();
|
||||
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
||||
redisUtil.deleteKeysByString(AppRedisKey.DEV_MODEL);
|
||||
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid, new Gson().toJson(getJson(mid,TypeEnum.TYPE_3.getCode())), 1, false);
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
log.warn("线程休眠被中断: {}", e.getMessage());
|
||||
return false;
|
||||
}
|
||||
List<CsModelDto> modelId = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + nDid), CsModelDto.class);
|
||||
if (CollUtil.isEmpty(modelId)) {
|
||||
log.warn("设备 {} 未获取到模板信息", nDid);
|
||||
return false;
|
||||
}
|
||||
CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(nDid).getData();
|
||||
for (CsModelDto item : modelId) {
|
||||
CsDevModelRelationPO po = new CsDevModelRelationPO();
|
||||
po.setDevId(vo.getId());
|
||||
po.setModelId(item.getModelId());
|
||||
po.setDid(item.getDid());
|
||||
po.setUpdateTime(LocalDateTime.now());
|
||||
csDevModelRelationService.addRelation(po);
|
||||
modelMap.put(item.getType(), item.getModelId());
|
||||
}
|
||||
Object object = redisUtil.getObjectByKey("accessLineInfo:" + nDid);
|
||||
if (Objects.isNull(object)) {
|
||||
LineInfoParam param = new LineInfoParam();
|
||||
param.setNDid(nDid);
|
||||
deviceMessageFeignClient.getLineInfo(param);
|
||||
}
|
||||
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid, new Gson().toJson(getJson(mid,TypeEnum.TYPE_5.getCode())), 1, false);
|
||||
result = true;
|
||||
} catch (Exception e) {
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
logDto.setResult(1);
|
||||
logDto.setOperate(nDid + "装置接入失败");
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
log.error("设备 {} 接入失败: {}", nDid, e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装报文
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.njcn.access.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.access.enums.AccessEnum;
|
||||
@@ -15,9 +17,8 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -37,9 +38,15 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
||||
private final CsLogsFeignClient csLogsFeignClient;
|
||||
|
||||
@Override
|
||||
public void updateStatusBynDid(String nDid,Integer status) {
|
||||
public void updateStatusBynDid(String nDid,Integer status,String engineeringId, String projectId) {
|
||||
LambdaUpdateWrapper<CsEquipmentDeliveryPO> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||
lambdaUpdateWrapper.set(CsEquipmentDeliveryPO::getStatus,status).eq(CsEquipmentDeliveryPO::getNdid,nDid);
|
||||
if (engineeringId != null && !engineeringId.isEmpty()) {
|
||||
lambdaUpdateWrapper.set(CsEquipmentDeliveryPO::getAssociatedEngineering,engineeringId);
|
||||
}
|
||||
if (projectId != null && !projectId.isEmpty()) {
|
||||
lambdaUpdateWrapper.set(CsEquipmentDeliveryPO::getAssociatedProject,projectId);
|
||||
}
|
||||
this.update(lambdaUpdateWrapper);
|
||||
}
|
||||
|
||||
@@ -97,45 +104,73 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
||||
.ne(CsEquipmentDeliveryPO::getRunStatus,AccessEnum.DEL.getCode())
|
||||
.eq(CsEquipmentDeliveryPO::getUsageStatus,1)
|
||||
.list();
|
||||
list.forEach(item->{
|
||||
String clientName = "NJCN-" + item.getNdid().substring(item.getNdid().length() - 6);
|
||||
boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
||||
if (mqttClient) {
|
||||
result.add(item);
|
||||
} else {
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
logDto.setResult(1);
|
||||
logDto.setOperate(item.getNdid() + "接入失败,装置客户端不在线");
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
}
|
||||
});
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
list.forEach(item->{
|
||||
String clientName = "NJCN-" + item.getNdid().substring(item.getNdid().length() - 6);
|
||||
boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
||||
if (mqttClient) {
|
||||
result.add(item);
|
||||
} else {
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
logDto.setResult(1);
|
||||
logDto.setOperate(item.getNdid() + "接入失败,装置客户端不在线");
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CsEquipmentDeliveryPO> getUseOnlineDevice() {
|
||||
return this.lambdaQuery()
|
||||
.eq(CsEquipmentDeliveryPO::getRunStatus,AccessEnum.ONLINE.getCode())
|
||||
.eq(CsEquipmentDeliveryPO::getDevAccessMethod,"MQTT")
|
||||
.eq(CsEquipmentDeliveryPO::getUsageStatus,1)
|
||||
.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CsEquipmentDeliveryPO> getOfflineDev() {
|
||||
List<CsEquipmentDeliveryPO> result = new ArrayList<>();
|
||||
List<CsEquipmentDeliveryPO> list = this.lambdaQuery()
|
||||
.eq(CsEquipmentDeliveryPO::getRunStatus,AccessEnum.OFFLINE.getCode())
|
||||
.eq(CsEquipmentDeliveryPO::getUsageStatus,1)
|
||||
.in(CsEquipmentDeliveryPO::getStatus, Arrays.asList(2,3))
|
||||
.isNull(CsEquipmentDeliveryPO::getNodeId)
|
||||
.list();
|
||||
list.forEach(item->{
|
||||
String clientName = "NJCN-" + item.getNdid().substring(item.getNdid().length() - 6);
|
||||
boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
||||
if (mqttClient) {
|
||||
result.add(item);
|
||||
} else {
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
logDto.setResult(1);
|
||||
logDto.setOperate(item.getNdid() + "接入失败,装置客户端不在线");
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
}
|
||||
});
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
list.forEach(item->{
|
||||
String clientName = "NJCN-" + item.getNdid().substring(item.getNdid().length() - 6);
|
||||
boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
||||
if (mqttClient) {
|
||||
result.add(item);
|
||||
} else {
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
logDto.setResult(1);
|
||||
logDto.setOperate(item.getNdid() + "接入失败,装置客户端不在线");
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getFrontAndProcess() {
|
||||
QueryWrapper<CsEquipmentDeliveryPO> wrapper = new QueryWrapper<>();
|
||||
wrapper.select("DISTINCT CONCAT(node_id, node_process) as concatenated");
|
||||
wrapper.eq("usage_status", 1);
|
||||
wrapper.isNotNull("node_id");
|
||||
return baseMapper.selectObjs(wrapper)
|
||||
.stream()
|
||||
.map(obj -> (String) obj)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
package com.njcn.access.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import com.njcn.access.enums.AccessEnum;
|
||||
import com.njcn.access.pojo.dto.NoticeUserDto;
|
||||
import com.njcn.access.service.ICsEquipmentDeliveryService;
|
||||
import com.njcn.access.service.ICsHeartService;
|
||||
import com.njcn.access.service.IHeartbeatService;
|
||||
import com.njcn.access.utils.SendMessageUtil;
|
||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||
import com.njcn.csdevice.api.*;
|
||||
import com.njcn.csdevice.param.DeviceMessageParam;
|
||||
import com.njcn.csdevice.pojo.dto.DevDetailDTO;
|
||||
import com.njcn.csdevice.pojo.dto.PqsCommunicateDto;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.mq.message.HeartbeatTimeoutMessage;
|
||||
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 lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据集表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-08-01
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class CsHeartServiceImpl implements ICsHeartService {
|
||||
|
||||
@Resource
|
||||
private ICsEquipmentDeliveryService csEquipmentDeliveryService;
|
||||
@Resource
|
||||
private CsLogsFeignClient csLogsFeignClient;
|
||||
@Resource
|
||||
private EquipmentFeignClient equipmentFeignClient;
|
||||
@Resource
|
||||
private SendMessageUtil sendMessageUtil;
|
||||
@Resource
|
||||
private CsLedgerFeignClient csLedgerFeignclient;
|
||||
@Resource
|
||||
private AppUserFeignClient appUserFeignClient;
|
||||
@Resource
|
||||
private CsDeviceUserFeignClient csDeviceUserFeignClient;
|
||||
@Resource
|
||||
private UserFeignClient userFeignClient;
|
||||
@Resource
|
||||
private IHeartbeatService heartbeatService;
|
||||
@Resource
|
||||
private CsCommunicateFeignClient csCommunicateFeignClient;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private DeviceMessageFeignClient deviceMessageFeignClient;
|
||||
|
||||
@Override
|
||||
public void handleHeartbeat(HeartbeatTimeoutMessage message) {
|
||||
String nDid = message.getNDid();
|
||||
Long sendTime = message.getTimestamp();
|
||||
if (heartbeatService.isHeartbeatUpdated(nDid, sendTime)) {
|
||||
return;
|
||||
}
|
||||
log.info("{}->装置离线,执行业务处理", nDid);
|
||||
handleDeviceOffline(nDid);
|
||||
}
|
||||
|
||||
private void handleDeviceOffline(String nDid) {
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
//装置下线
|
||||
csEquipmentDeliveryService.updateRunStatusBynDid(nDid, AccessEnum.OFFLINE.getCode());
|
||||
//装置调整为注册状态
|
||||
csEquipmentDeliveryService.updateStatusBynDid(nDid,AccessEnum.REGISTERED.getCode(),null,null);
|
||||
logDto.setOperate(nDid +"装置离线");
|
||||
sendMessage(nDid);
|
||||
//记录装置掉线时间
|
||||
PqsCommunicateDto dto = new PqsCommunicateDto();
|
||||
dto.setTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN)));
|
||||
dto.setDevId(nDid);
|
||||
dto.setType(0);
|
||||
dto.setDescription("通讯中断");
|
||||
csCommunicateFeignClient.insertion(dto);
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
//清空缓存
|
||||
redisUtil.deleteKeysByString(AppRedisKey.LINE_POSITION+nDid);
|
||||
}
|
||||
|
||||
private void sendMessage(String nDid) {
|
||||
boolean devModel = equipmentFeignClient.judgeDevModel(nDid).getData();
|
||||
if (devModel) {
|
||||
NoticeUserDto dto = sendOffLine(nDid);
|
||||
if (CollectionUtil.isNotEmpty(dto.getPushClientId())) {
|
||||
sendMessageUtil.sendEventToUser(dto);
|
||||
addLogs(dto);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//掉线通知
|
||||
private NoticeUserDto sendOffLine(String nDid) {
|
||||
NoticeUserDto dto = new NoticeUserDto();
|
||||
dto.setTitle("设备离线");
|
||||
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(nDid).getData();
|
||||
DevDetailDTO devDetailDto = csLedgerFeignclient.queryDevDetail(po.getId()).getData();
|
||||
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
LocalDateTime localDateTime = LocalDateTime.now();
|
||||
String dateStr = localDateTime.format(fmt);
|
||||
String content = String.format(devDetailDto.getEngineeringName() + "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName() + "于" + dateStr + "离线");
|
||||
dto.setContent(content);
|
||||
//获取设备关联的用户
|
||||
List<String> eventUser = deviceMessageFeignClient.getEventUserByDeviceId(po.getId(),true).getData();
|
||||
DeviceMessageParam param1 = new DeviceMessageParam();
|
||||
param1.setUserList(eventUser);
|
||||
param1.setEventType(2);
|
||||
//获取打开推送的用户
|
||||
List<User> users = deviceMessageFeignClient.getSendUserByType(param1).getData();
|
||||
if (CollectionUtil.isNotEmpty(users)){
|
||||
dto.setPushClientId(
|
||||
users.stream().filter(Objects::nonNull).map(User::getDevCode).filter(org.apache.commons.lang3.StringUtils::isNotBlank).distinct().collect(Collectors.toList()));
|
||||
}
|
||||
return dto;
|
||||
}
|
||||
|
||||
private void addLogs(NoticeUserDto noticeUserDto) {
|
||||
DeviceLogDTO dto = new DeviceLogDTO();
|
||||
dto.setUserName("运维管理员");
|
||||
dto.setLoginName("njcnyw");
|
||||
dto.setOperate(noticeUserDto.getContent());
|
||||
csLogsFeignClient.addUserLog(dto);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.njcn.access.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.access.mapper.CsLedgerMapper;
|
||||
import com.njcn.access.service.ICsLedgerService;
|
||||
@@ -8,8 +10,11 @@ import com.njcn.csdevice.pojo.po.CsLedger;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -24,6 +29,7 @@ import java.util.Objects;
|
||||
public class CsLedgerServiceImpl extends ServiceImpl<CsLedgerMapper, CsLedger> implements ICsLedgerService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public CsLedger addLedgerTree(CsLedgerParam csLedgerParam) {
|
||||
CsLedger fatherCsLedger = this.lambdaQuery().eq(CsLedger::getId,csLedgerParam.getPid()).eq(CsLedger::getState,1).one();
|
||||
CsLedger csLedger = new CsLedger();
|
||||
@@ -43,4 +49,35 @@ public class CsLedgerServiceImpl extends ServiceImpl<CsLedgerMapper, CsLedger> i
|
||||
return csLedger;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public void updatePortableLedger(String engineeringId, String projectId) {
|
||||
//先查询有没有历史的便携式设备
|
||||
List<CsLedger> portableDevices = this.list(
|
||||
new LambdaQueryWrapper<CsLedger>()
|
||||
.eq(CsLedger::getPid, "0")
|
||||
.eq(CsLedger::getLevel, 2)
|
||||
.eq(CsLedger::getState, 1));
|
||||
if (CollectionUtil.isNotEmpty(portableDevices)) {
|
||||
portableDevices.forEach(item->{
|
||||
item.setPid(projectId);
|
||||
item.setPids("0," + engineeringId + "," + projectId);
|
||||
});
|
||||
this.updateBatchById(portableDevices);
|
||||
//获取监测点id
|
||||
List<String> devList = portableDevices.stream().map(CsLedger::getId).collect(Collectors.toList());
|
||||
LambdaQueryWrapper<CsLedger> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.in(CsLedger::getPid, devList).eq(CsLedger::getState,1).eq(CsLedger::getLevel,3);
|
||||
List<CsLedger> pointList = this.list(queryWrapper);
|
||||
if (CollectionUtil.isNotEmpty(pointList)) {
|
||||
pointList.forEach(item->{
|
||||
String pidS = item.getPids();
|
||||
String devPid = pidS.split(",")[1];
|
||||
item.setPids("0," + engineeringId + "," + projectId + "," + devPid);
|
||||
});
|
||||
this.updateBatchById(pointList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.njcn.access.service.impl;
|
||||
|
||||
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
|
||||
import com.njcn.access.mapper.CsLineLatestDataMapper;
|
||||
import com.njcn.access.pojo.po.CsLineLatestData;
|
||||
import com.njcn.access.service.ICsLineLatestDataService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 治理设备模块运行状态记录表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-07-03
|
||||
*/
|
||||
@Service
|
||||
public class CsLineLatestDataServiceImpl extends MppServiceImpl<CsLineLatestDataMapper, CsLineLatestData> implements ICsLineLatestDataService {
|
||||
|
||||
@Override
|
||||
public void addData(CsLineLatestData csLineLatestData) {
|
||||
this.saveOrUpdateByMultiId(csLineLatestData);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import com.njcn.access.mapper.CsTopicMapper;
|
||||
import com.njcn.access.pojo.po.CsTopic;
|
||||
import com.njcn.access.service.ICsTopicService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -42,4 +41,11 @@ public class CsTopicServiceImpl extends ServiceImpl<CsTopicMapper, CsTopic> impl
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByNDid(String nDid) {
|
||||
LambdaQueryWrapper<CsTopic> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(CsTopic::getNDid,nDid);
|
||||
this.remove(lambdaQueryWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.njcn.access.service.impl;
|
||||
|
||||
import com.njcn.access.service.IHeartbeatService;
|
||||
import com.njcn.mq.message.HeartbeatTimeoutMessage;
|
||||
import com.njcn.mq.template.HeartbeatTimeoutMessageTemplate;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class HeartbeatServiceImpl implements IHeartbeatService {
|
||||
|
||||
@Resource
|
||||
private HeartbeatTimeoutMessageTemplate heartbeatTimeoutMessageTemplate;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
private static final String HEARTBEAT_REDIS_KEY_PREFIX = "HEARTBEAT:";
|
||||
private static final int DELAY_LEVEL_4MIN = 7;
|
||||
private static final long HEARTBEAT_EXPIRE_SECONDS = 180;
|
||||
|
||||
@Override
|
||||
public void receiveHeartbeat(String nDid) {
|
||||
String redisKey = HEARTBEAT_REDIS_KEY_PREFIX + nDid;
|
||||
long currentTime = System.currentTimeMillis();
|
||||
|
||||
redisUtil.saveByKey(redisKey, currentTime);
|
||||
redisUtil.expire(redisKey, HEARTBEAT_EXPIRE_SECONDS);
|
||||
|
||||
HeartbeatTimeoutMessage message = new HeartbeatTimeoutMessage();
|
||||
|
||||
message.setNDid(nDid);
|
||||
message.setTimestamp(currentTime);
|
||||
message.setDelayLevel(DELAY_LEVEL_4MIN);
|
||||
heartbeatTimeoutMessageTemplate.sendMember(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isHeartbeatUpdated(String nDid, Long sendTime) {
|
||||
String redisKey = HEARTBEAT_REDIS_KEY_PREFIX + nDid;
|
||||
Object lastHeartbeat = redisUtil.getObjectByKey(redisKey);
|
||||
|
||||
if (lastHeartbeat == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
long lastUpdateTime = Long.parseLong(lastHeartbeat.toString());
|
||||
return lastUpdateTime > sendTime;
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,7 @@ logging:
|
||||
config: http://@nacos.url@/nacos/v1/cs/configs?tenant=@nacos.namespace@&group=DEFAULT_GROUP&dataId=logback.xml
|
||||
level:
|
||||
root: info
|
||||
com.njcn.middle.rocket.template.RocketMQEnhanceTemplate: ERROR
|
||||
|
||||
|
||||
#mybatis配置信息
|
||||
|
||||
@@ -1,49 +1,37 @@
|
||||
package com.njcn;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.alibaba.nacos.shaded.com.google.common.reflect.TypeToken;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
import com.graphbuilder.math.func.EFunction;
|
||||
import com.njcn.access.AccessBootApplication;
|
||||
import com.njcn.access.enums.AccessEnum;
|
||||
import com.njcn.access.enums.TypeEnum;
|
||||
import com.njcn.access.pojo.dto.ReqAndResDto;
|
||||
import com.njcn.access.pojo.dto.mqtt.MqttClientDto;
|
||||
import com.njcn.access.service.ICsEquipmentDeliveryService;
|
||||
import com.njcn.access.service.ICsTopicService;
|
||||
import com.njcn.access.service.impl.CsDeviceServiceImpl;
|
||||
import com.njcn.access.utils.MqttUtil;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.utils.PubUtils;
|
||||
import com.njcn.csdevice.pojo.po.CsLinePO;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.oss.utils.FileStorageUtil;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import io.lettuce.core.protocol.CompleteableCommand;
|
||||
import com.njcn.system.api.DictTreeFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.Credentials;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import org.eclipse.paho.client.mqttv3.*;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
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.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Array;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.CRC32;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
@@ -81,72 +69,410 @@ public class AppTest
|
||||
private MqttUtil mqttUtil;
|
||||
|
||||
@Test
|
||||
public void lossTest() {
|
||||
final int[] mid = {2};
|
||||
for (int i = 0; i < 2; i++) {
|
||||
mid[0] = mid[0] + 1;
|
||||
public void deleteRedis() {
|
||||
redisUtil.deleteKeysByString("devModelKey:00B78DA800B011avg");
|
||||
}
|
||||
ScheduledFuture<?> runnableFuture = null;
|
||||
@Resource
|
||||
private ICsTopicService csTopicService;
|
||||
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
ExecutorService executor = Executors.newFixedThreadPool(10);
|
||||
private static final long ACCESS_TIME = 20L;
|
||||
|
||||
@Resource
|
||||
private DictTreeFeignClient dictTreeFeignClient;
|
||||
|
||||
/**
|
||||
* 测试下载文件
|
||||
*/
|
||||
@Test
|
||||
public void run1() {
|
||||
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
Runnable task = () -> {
|
||||
System.out.println("轮询定时任务执行中!");
|
||||
};
|
||||
scheduler.scheduleAtFixedRate(task, 0, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void run() {
|
||||
Runnable task = () -> {
|
||||
log.info("轮询定时任务执行中!");
|
||||
|
||||
CsEquipmentDeliveryPO po = new CsEquipmentDeliveryPO();
|
||||
po.setNdid("00B78DA80103");
|
||||
po.setDevType("8b45cf6b7f5266e777d07c166ad5fa77");
|
||||
po.setStatus(2);
|
||||
List<CsEquipmentDeliveryPO> list = Collections.singletonList(po);
|
||||
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
ExecutorService executor = Executors.newFixedThreadPool(10);
|
||||
// 将任务平均分配给10个子列表
|
||||
List<List<CsEquipmentDeliveryPO>> subLists = new ArrayList<>();
|
||||
int partitionSize = list.size() / 10;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
int start = i * partitionSize;
|
||||
int end = (i == 9) ? list.size() : start + partitionSize;
|
||||
subLists.add(list.subList(start, end));
|
||||
}
|
||||
// 创建一个ExecutorService来处理这些任务
|
||||
List<Future<Void>> futures = new ArrayList<>();
|
||||
// 提交任务给线程池执行
|
||||
for (int i = 0; i < 10; i++) {
|
||||
int index = i;
|
||||
futures.add(executor.submit(new Callable<Void>() {
|
||||
@Override
|
||||
public Void call() {
|
||||
// accessDev(subLists.get(index));
|
||||
System.out.println("123");
|
||||
return null;
|
||||
}
|
||||
}));
|
||||
}
|
||||
// 等待所有任务完成
|
||||
for (Future<Void> future : futures) {
|
||||
try {
|
||||
future.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
// 关闭ExecutorService
|
||||
executor.shutdown();
|
||||
}
|
||||
};
|
||||
//第一次执行的时间为120s,然后每隔120s执行一次
|
||||
scheduler.scheduleAtFixedRate(task,0,20,TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public void accessDev(List<CsEquipmentDeliveryPO> list) {
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
list.forEach(item->{
|
||||
System.out.println(Thread.currentThread().getName() + ": auto : nDid : " + item.getNdid());
|
||||
//判断设备类型 便携式设备需要特殊处理 未注册的要先注册、再接入;已注册的直接重新接入
|
||||
String code = dictTreeFeignClient.queryById(item.getDevType()).getData().getCode();
|
||||
if (Objects.equals(code, DicDataEnum.PORTABLE.getCode()) && Objects.equals(item.getStatus(),1)) {
|
||||
//csDeviceService.wlDevRegister(item.getNdid());
|
||||
log.info("请先手动注册、接入");
|
||||
} else {
|
||||
String version = csTopicService.getVersion(item.getNdid());
|
||||
if (Objects.isNull(version)) {
|
||||
version = "V1";
|
||||
}
|
||||
csDeviceService.devAccessAskTemplate(item.getNdid(),version,1);
|
||||
}
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + item.getNdid(),1);
|
||||
});
|
||||
}
|
||||
System.out.println("mid==:" + mid[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test1() {
|
||||
String clientName = "NJCN-A801C8";
|
||||
boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
||||
System.out.println("mqttClient==:" + mqttClient);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
// ReqAndResDto reqAndResParam = new ReqAndResDto();
|
||||
// reqAndResParam.setMid(1);
|
||||
// reqAndResParam.setDid(0);
|
||||
// reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||
// reqAndResParam.setType(4866);
|
||||
// publisher.send("/Dev/Data1/V1/123", new Gson().toJson(reqAndResParam),1,false);
|
||||
|
||||
// String key = String.valueOf(IdUtil.getSnowflake().nextId());
|
||||
// System.out.println("key==:" + key);
|
||||
|
||||
// List<CsLinePO> csLinePoList = new ArrayList<>();
|
||||
// CsLinePO po1 = new CsLinePO();
|
||||
// po1.setPosition("1");
|
||||
// CsLinePO po2= new CsLinePO();
|
||||
// po2.setPosition("2");
|
||||
// CsLinePO po3= new CsLinePO();
|
||||
// po3.setPosition("3");
|
||||
// CsLinePO po4= new CsLinePO();
|
||||
// po4.setPosition("1");
|
||||
// @Test
|
||||
// public void lossTest() {
|
||||
// final int[] mid = {2};
|
||||
// for (int i = 0; i < 2; i++) {
|
||||
// mid[0] = mid[0] + 1;
|
||||
// }
|
||||
// System.out.println("mid==:" + mid[0]);
|
||||
// }
|
||||
//
|
||||
// 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);
|
||||
// @Test
|
||||
// public void test1() {
|
||||
// String clientName = "NJCN-016AB3";
|
||||
// boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
||||
// System.out.println("mqttClient==:" + mqttClient);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testAutoAccess() {
|
||||
// List<CsEquipmentDeliveryPO> list = new ArrayList<>();
|
||||
// //项目启动60s后发起自动接入
|
||||
// Runnable task = () -> {
|
||||
// long time1 = System.currentTimeMillis();
|
||||
// List<CsEquipmentDeliveryPO> list1 = csEquipmentDeliveryService.getAll();
|
||||
// for (int i = 0; i < 100; i++) {
|
||||
// list.addAll(list1);
|
||||
// }
|
||||
// if (CollUtil.isNotEmpty(list)) {
|
||||
// // 将任务平均分配给10个子列表
|
||||
// List<List<CsEquipmentDeliveryPO>> subLists = new ArrayList<>();
|
||||
// int partitionSize = list.size() / 10;
|
||||
// for (int i = 0; i < 10; i++) {
|
||||
// int start = i * partitionSize;
|
||||
// int end = (i == 9) ? list.size() : start + partitionSize;
|
||||
// subLists.add(list.subList(start, end));
|
||||
// }
|
||||
//
|
||||
// // 创建一个ExecutorService来处理这些任务
|
||||
// List<Future<Void>> futures = new ArrayList<>();
|
||||
// // 提交任务给线程池执行
|
||||
// for (int i = 0; i < 10; i++) {
|
||||
// int index = i;
|
||||
// futures.add(executor.submit(new Callable<Void>() {
|
||||
// @Override
|
||||
// public Void call() throws Exception {
|
||||
// accessDev(subLists.get(index));
|
||||
// return null;
|
||||
// }
|
||||
// }));
|
||||
// }
|
||||
// // 等待所有任务完成
|
||||
// for (Future<Void> future : futures) {
|
||||
// try {
|
||||
// future.get();
|
||||
// } catch (InterruptedException | ExecutionException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
// // 关闭ExecutorService
|
||||
// executor.shutdown();
|
||||
// scheduler.shutdown();
|
||||
// }
|
||||
// long time2 = System.currentTimeMillis();
|
||||
// System.out.println("执行时间==:" + (time2 - time1));
|
||||
// };
|
||||
// scheduler.schedule(task, ACCESS_TIME, TimeUnit.SECONDS);
|
||||
// }
|
||||
|
||||
// String text = "TkosUFEsMTk5OQ0KNiw2QSwwRA0KMSxBz+C159G5LEEstefRuSxWLDAuMDYyMjU2LDAuMDAwMDAwLDAuMDAwMDAwLC0zMjc2NywzMjc2NywzODAsMzgwLFMNCjIsQs/gtefRuSxCLLXn0bksViwwLjA2MjI1NiwwLjAwMDAwMCwwLjAwMDAwMCwtMzI3NjcsMzI3NjcsMzgwLDM4MCxTDQozLEPP4LXn0bksQyy159G5LFYsMC4wNjIyNTYsMC4wMDAwMDAsMC4wMDAwMDAsLTMyNzY3LDMyNzY3LDM4MCwzODAsUw0KNCxBz+C158H3LEEstefB9yxBLDAuMDE1MjU5LDAuMDAwMDAwLDAuMDAwMDAwLC0zMjc2NywzMjc2NywyMDAsNSxTDQo1LELP4LXnwfcsQiy158H3LEEsMC4wMTUyNTksMC4wMDAwMDAsMC4wMDAwMDAsLTMyNzY3LDMyNzY3LDIwMCw1LFMNCjYsQ8/gtefB9yxDLLXnwfcsQSwwLjAxNTI1OSwwLjAwMDAwMCwwLjAwMDAwMCwtMzI3NjcsMzI3NjcsMjAwLDUsUw0KNTANCjENCjEyODAwLDcxNjgNCjA1LzA5LzIwMjMsMTU6NTQ6MDIuMTM2MDAwDQowNS8wOS8yMDIzLDE1OjU0OjAyLjIzNjAwMA0KQklOQVJZDQoxDQo=";
|
||||
// byte[] byteArray = Base64.getDecoder().decode(text);
|
||||
// InputStream inputStream = new ByteArrayInputStream(byteArray);
|
||||
// fileStorageUtil.uploadStreamSpecifyName(inputStream, "configuration/","xuyang.cfg");
|
||||
// public void accessDev(List<CsEquipmentDeliveryPO> list) {
|
||||
// list.forEach(item->{
|
||||
// try {
|
||||
// System.out.println(Thread.currentThread().getName() + ": processing data " + item.getNdid());
|
||||
// Thread.sleep(2000);
|
||||
// String version = csTopicService.getVersion(item.getNdid());
|
||||
// if (!Objects.isNull(version)){
|
||||
// csDeviceService.devAccessAskTemplate(item.getNdid(),version,1);
|
||||
// redisUtil.saveByKey(AppRedisKey.DEVICE_MID + item.getNdid(),1);
|
||||
// }
|
||||
// } catch (InterruptedException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// @After
|
||||
// public void test() {
|
||||
// String nDid = "00B78D016AB5";
|
||||
// String version = "V1";
|
||||
// try {
|
||||
// inputStream.close();
|
||||
// } catch (IOException e) {
|
||||
//// //装置没有心跳,则立马发起接入请求
|
||||
//// csDeviceService.devAccessAskTemplate(nDid,version,1);
|
||||
//// log.info("装置掉线3分钟发送接入请求");
|
||||
//// Integer status = csEquipmentDeliveryService.queryEquipmentBynDid(nDid).getRunStatus();
|
||||
//// if (Objects.equals(status,AccessEnum.ONLINE.getCode())){
|
||||
//// throw new BusinessException(CommonResponseEnum.SUCCESS);
|
||||
//// }
|
||||
//// //心跳断连立马发起接入失败后,1分钟再次发起请求,请求3次
|
||||
//// for (int i = 2; i < 5; i++) {
|
||||
//// //接入再次失败,则定时发起接入请求
|
||||
//// Thread.sleep(1000 * 6);
|
||||
//// csDeviceService.devAccessAskTemplate(nDid,version,i);
|
||||
//// status = csEquipmentDeliveryService.queryEquipmentBynDid(nDid).getRunStatus();
|
||||
//// if (Objects.equals(status,AccessEnum.ONLINE.getCode())){
|
||||
//// break;
|
||||
//// }
|
||||
//// log.info("装置定时1分钟发送接入请求,第" + i + "次尝试");
|
||||
//// }
|
||||
// Integer status = csEquipmentDeliveryService.queryEquipmentBynDid(nDid).getRunStatus();
|
||||
// if (!Objects.isNull(status) && Objects.equals(status,AccessEnum.OFFLINE.getCode())){
|
||||
// final int[] mid = {5};
|
||||
// runnableFuture = executor.scheduleAtFixedRate(() -> {
|
||||
// csDeviceService.devAccessAskTemplate(nDid,version, mid[0]);
|
||||
// Integer status2 = csEquipmentDeliveryService.queryEquipmentBynDid(nDid).getRunStatus();
|
||||
// if (Objects.equals(status2,AccessEnum.ONLINE.getCode())){
|
||||
// runnableFuture.cancel(false);
|
||||
// } else {
|
||||
// mid[0] = mid[0] + 1;
|
||||
// }
|
||||
// //记录日志
|
||||
// log.info("装置掉线,定时10分钟发送接入请求,装置为:" + nDid + ",请求的时间戳为:" + System.currentTimeMillis());
|
||||
// }, 1, 1, TimeUnit.SECONDS);
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// @Test
|
||||
// @After
|
||||
// public void test2() {
|
||||
// String nDid = "00B78D016AB5";
|
||||
// String version = "V1";
|
||||
// try {
|
||||
// //装置没有心跳,则立马发起接入请求
|
||||
// csDeviceService.devAccessAskTemplate(nDid,version,1);
|
||||
// log.info("装置掉线3分钟发送接入请求");
|
||||
// Integer status = csEquipmentDeliveryService.queryEquipmentBynDid(nDid).getRunStatus();
|
||||
// if (Objects.equals(status,AccessEnum.ONLINE.getCode())){
|
||||
// throw new BusinessException(CommonResponseEnum.SUCCESS);
|
||||
// }
|
||||
// //心跳断连立马发起接入失败后,1分钟再次发起请求,请求3次
|
||||
// for (int i = 2; i < 5; i++) {
|
||||
// //接入再次失败,则定时发起接入请求
|
||||
// Thread.sleep(1000 * 6);
|
||||
// csDeviceService.devAccessAskTemplate(nDid,version,i);
|
||||
// status = csEquipmentDeliveryService.queryEquipmentBynDid(nDid).getRunStatus();
|
||||
// if (Objects.equals(status,AccessEnum.ONLINE.getCode())){
|
||||
// break;
|
||||
// }
|
||||
// log.info("装置定时1分钟发送接入请求,第" + i + "次尝试");
|
||||
// }
|
||||
// if (!Objects.isNull(status) && Objects.equals(status,AccessEnum.OFFLINE.getCode())){
|
||||
// final int[] mid = {5};
|
||||
// ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
|
||||
// runnableFuture = executor.scheduleAtFixedRate(() -> {
|
||||
// csDeviceService.devAccessAskTemplate(nDid,version, mid[0]);
|
||||
// Integer status2 = csEquipmentDeliveryService.queryEquipmentBynDid(nDid).getRunStatus();
|
||||
// if (Objects.equals(status2,AccessEnum.ONLINE.getCode())){
|
||||
// runnableFuture.cancel(true);
|
||||
// } else {
|
||||
// mid[0] = mid[0] + 1;
|
||||
// }
|
||||
// //记录日志
|
||||
// log.info("装置掉线,定时10分钟发送接入请求,装置为:" + nDid + ",请求的时间戳为:" + System.currentTimeMillis());
|
||||
// }, 1, 1, TimeUnit.SECONDS);
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// @After
|
||||
// public void testDeviceAccess() {
|
||||
// String nDid = "00B78D016AB5";
|
||||
// String version = "V1";
|
||||
// try {
|
||||
// // 初次接入请求
|
||||
// initiateDeviceAccess(nDid, version, 1);
|
||||
// // 检查设备状态
|
||||
// Integer status = checkDeviceStatus(nDid);
|
||||
// if (status != null && Objects.equals(status, AccessEnum.ONLINE.getCode())) {
|
||||
// throw new BusinessException(CommonResponseEnum.SUCCESS);
|
||||
// }
|
||||
// // 重试接入请求,最多尝试3次
|
||||
// attemptReconnect(nDid, version);
|
||||
// // 如果设备仍然离线,开始定时任务发起接入请求
|
||||
// if (status != null && Objects.equals(status, AccessEnum.OFFLINE.getCode())) {
|
||||
// startScheduledReconnection(nDid, version);
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// log.error("Device access error", e);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private static final String BROKER_URL = "tcp://192.168.1.27:1885";
|
||||
// private static final String CLIENT_ID = "JavaAsyncPublisher";
|
||||
// private static final int QOS = 1; // Quality of Service
|
||||
// private static final int NUM_DEVICES = 10;
|
||||
// private static final String TOPIC_PREFIX = "/Dev/Data/V1/";
|
||||
// private static final int DEV_NUMS = 20;
|
||||
//
|
||||
// @Test
|
||||
// public void test11() {
|
||||
// MqttClient client = null;
|
||||
// ExecutorService executor = Executors.newFixedThreadPool(NUM_DEVICES);
|
||||
//
|
||||
// try {
|
||||
// client = new MqttClient(BROKER_URL, CLIENT_ID);
|
||||
// MqttConnectOptions options = new MqttConnectOptions();
|
||||
// options.setCleanSession(true);
|
||||
// client.connect(options);
|
||||
//
|
||||
// client.setCallback(new MqttCallback() {
|
||||
// @Override
|
||||
// public void connectionLost(Throwable cause) {
|
||||
// // Handle connection loss
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void messageArrived(String topic, MqttMessage message) throws Exception {
|
||||
// // Handle incoming messages (not used in this example)
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void deliveryComplete(IMqttDeliveryToken token) {
|
||||
// // Handle delivery completion
|
||||
// System.out.println("Message delivery completed for token: " + token.isComplete());
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// // Submit tasks to the executor service to send messages to each device
|
||||
// for (int i = 1; i <= DEV_NUMS; i++) {
|
||||
// final String deviceId = "00B78DA8000" + i;
|
||||
// MqttClient finalClient = client;
|
||||
// executor.submit(() -> {
|
||||
// try {
|
||||
// String topic = TOPIC_PREFIX + deviceId;
|
||||
// String payload = "Message for device " + deviceId;
|
||||
// MqttMessage message = new MqttMessage(payload.getBytes());
|
||||
// message.setQos(QOS);
|
||||
// finalClient.publish(topic, message);
|
||||
// System.out.println("Sent message to topic: " + topic + " Message: " + payload);
|
||||
// } catch (MqttException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// } catch (MqttException e) {
|
||||
// e.printStackTrace();
|
||||
// } finally {
|
||||
// if (client != null && client.isConnected()) {
|
||||
// try {
|
||||
// client.disconnect();
|
||||
// } catch (MqttException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void initiateDeviceAccess(String nDid, String version, int attempt) {
|
||||
// csDeviceService.devAccessAskTemplate(nDid, version, attempt);
|
||||
// log.info("装置掉线3分钟发送接入请求");
|
||||
// }
|
||||
//
|
||||
// private Integer checkDeviceStatus(String nDid) {
|
||||
// return csEquipmentDeliveryService.queryEquipmentBynDid(nDid).getRunStatus();
|
||||
// }
|
||||
//
|
||||
// private void attemptReconnect(String nDid, String version) throws InterruptedException {
|
||||
// for (int i = 2; i < 5; i++) {
|
||||
// Thread.sleep(1000 * 6); // 每 6 秒重试一次
|
||||
// initiateDeviceAccess(nDid, version, i);
|
||||
//
|
||||
// Integer status = checkDeviceStatus(nDid);
|
||||
// if (status != null && Objects.equals(status, AccessEnum.ONLINE.getCode())) {
|
||||
// break;
|
||||
// }
|
||||
// log.info("装置定时1分钟发送接入请求,第" + i + "次尝试");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void startScheduledReconnection(String nDid, String version) {
|
||||
// final int[] attemptCounter = {5};
|
||||
// ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
|
||||
//
|
||||
// Runnable reconnectTask = () -> {
|
||||
// initiateDeviceAccess(nDid, version, attemptCounter[0]);
|
||||
//
|
||||
// Integer status = checkDeviceStatus(nDid);
|
||||
// if (status != null && Objects.equals(status, AccessEnum.ONLINE.getCode())) {
|
||||
// executor.shutdown(); // 关闭调度器
|
||||
// } else {
|
||||
// attemptCounter[0]++;
|
||||
// }
|
||||
// log.info("装置掉线,定时10分钟发送接入请求,装置为:" + nDid
|
||||
// + ",请求的时间戳为:" + System.currentTimeMillis());
|
||||
// };
|
||||
//
|
||||
// executor.scheduleAtFixedRate(reconnectTask, 1, 1, TimeUnit.SECONDS);
|
||||
// }
|
||||
|
||||
// 要计算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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
191
iot-access/access-boot/src/test/java/com/njcn/Test.java
Normal file
191
iot-access/access-boot/src/test/java/com/njcn/Test.java
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,61 @@
|
||||
package com.njcn;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class TestXianCheng {
|
||||
|
||||
|
||||
private static final long AUTO_TIME = 120L;
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
Runnable task = () -> {
|
||||
log.info("轮询定时任务执行中!");
|
||||
ExecutorService executor = Executors.newFixedThreadPool(10);
|
||||
// 创建一个ExecutorService来处理这些任务
|
||||
List<Future<Void>> futures = new ArrayList<>();
|
||||
// 提交任务给线程池执行
|
||||
for (int i = 0; i < 10; i++) {
|
||||
int index = i;
|
||||
futures.add(executor.submit(new Callable<Void>() {
|
||||
@Override
|
||||
public Void call() {
|
||||
access();
|
||||
return null;
|
||||
}
|
||||
}));
|
||||
}
|
||||
// 等待所有任务完成
|
||||
for (Future<Void> future : futures) {
|
||||
try {
|
||||
future.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
// 关闭ExecutorService
|
||||
executor.shutdown();
|
||||
};
|
||||
//第一次执行的时间为120s,然后每隔120s执行一次
|
||||
scheduler.scheduleAtFixedRate(task,0,1,TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
|
||||
public static void access() {
|
||||
System.out.println("123");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,11 @@ import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.mq.message.AppAutoDataMessage;
|
||||
import com.njcn.rt.api.fallback.RtClientFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
@@ -15,4 +19,7 @@ public interface RtFeignClient {
|
||||
|
||||
@PostMapping("/rtAnalysis")
|
||||
HttpResult<String> analysis(AppAutoDataMessage appAutoDataMessage);
|
||||
|
||||
@PostMapping("/apfRtAnalysis")
|
||||
HttpResult<Map<String,Float>> apfRtAnalysis(@RequestBody @Validated AppAutoDataMessage appAutoDataMessage);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@@ -27,7 +29,13 @@ public class RtClientFallbackFactory implements FallbackFactory<RtFeignClient> {
|
||||
|
||||
@Override
|
||||
public HttpResult<String> analysis(AppAutoDataMessage appAutoDataMessage) {
|
||||
log.error("{}异常,降级处理,异常为:{}","实时数据解析",cause.toString());
|
||||
log.error("{}异常,降级处理,异常为:{}","便携式实时数据解析",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<Map<String,Float>> apfRtAnalysis(AppAutoDataMessage appAutoDataMessage) {
|
||||
log.error("{}异常,降级处理,异常为:{}","APF实时数据解析",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -14,6 +14,12 @@ public class BaseRealDataSet implements Serializable {
|
||||
@ApiModelProperty("用户ID")
|
||||
private String userId;
|
||||
|
||||
@ApiModelProperty("结果(仅超时使用)")
|
||||
private boolean result = true;
|
||||
|
||||
@ApiModelProperty("描述")
|
||||
private String content;
|
||||
|
||||
@ApiModelProperty("监测点id")
|
||||
private String lineId;
|
||||
|
||||
|
||||
@@ -21,6 +21,10 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.tocrhz</groupId>
|
||||
<artifactId>mqtt-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-web</artifactId>
|
||||
|
||||
@@ -19,6 +19,8 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
@@ -45,5 +47,14 @@ public class RtController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/apfRtAnalysis")
|
||||
@ApiOperation("APF实时数据解析")
|
||||
@ApiImplicitParam(name = "appAutoDataMessage", value = "数据实体", required = true)
|
||||
public HttpResult<String> apfRtAnalysis(@RequestBody @Validated AppAutoDataMessage appAutoDataMessage){
|
||||
String methodDescribe = getMethodDescribe("apfRtAnalysis");
|
||||
rtService.apfRtAnalysis(appAutoDataMessage);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,4 +8,10 @@ import com.njcn.mq.message.AppAutoDataMessage;
|
||||
public interface IRtService {
|
||||
|
||||
void analysis(AppAutoDataMessage appAutoDataMessage);
|
||||
|
||||
/**
|
||||
* APF数据解析
|
||||
* @param appAutoDataMessage
|
||||
*/
|
||||
void apfRtAnalysis(AppAutoDataMessage appAutoDataMessage);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
package com.njcn.rt.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
import com.njcn.access.utils.ChannelObjectUtil;
|
||||
import com.njcn.access.utils.RedisSetUtil;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.utils.PubUtils;
|
||||
import com.njcn.csdevice.api.CsLineFeignClient;
|
||||
import com.njcn.csdevice.api.DataArrayFeignClient;
|
||||
import com.njcn.csdevice.api.DataSetFeignClient;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
import com.njcn.csdevice.pojo.po.CsDataArray;
|
||||
import com.njcn.csdevice.pojo.po.CsDataSet;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.csdevice.pojo.po.CsLinePO;
|
||||
import com.njcn.mq.message.AppAutoDataMessage;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
@@ -19,8 +23,8 @@ import com.njcn.rt.pojo.dto.BaseRealDataSet;
|
||||
import com.njcn.rt.pojo.dto.HarmData;
|
||||
import com.njcn.rt.pojo.dto.HarmRealDataSet;
|
||||
import com.njcn.rt.service.IRtService;
|
||||
import com.njcn.web.utils.FloatUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@@ -36,6 +40,7 @@ import java.util.stream.Collectors;
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class RtServiceImpl implements IRtService {
|
||||
@@ -46,14 +51,15 @@ public class RtServiceImpl implements IRtService {
|
||||
private final RedisUtil redisUtil;
|
||||
private final ChannelObjectUtil channelObjectUtil;
|
||||
private final MqttPublisher publisher;
|
||||
private final RedisSetUtil redisSetUtil;
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
|
||||
@Override
|
||||
public void analysis(AppAutoDataMessage appAutoDataMessage) {
|
||||
List<CsDataArray> dataArrayList;
|
||||
//监测点id
|
||||
String lineId = appAutoDataMessage.getId() + appAutoDataMessage.getMsg().getClDid();
|
||||
//用户Id
|
||||
String userId = redisUtil.getObjectByKey("rtDataUserId:"+lineId).toString();
|
||||
redisUtil.delete("cldRtDataOverTime:"+lineId);
|
||||
//获取监测点基础信息
|
||||
CsLinePO po = csLineFeignClient.getById(lineId).getData();
|
||||
//获取数据集 dataSet
|
||||
@@ -70,33 +76,99 @@ public class RtServiceImpl implements IRtService {
|
||||
}
|
||||
//根据dataArray解析数据
|
||||
AppAutoDataMessage.DataArray item = appAutoDataMessage.getMsg().getDataArray().get(0);
|
||||
//获取设备类型
|
||||
CsEquipmentDeliveryPO po1 =equipmentFeignClient.getDevByLineId(lineId).getData();
|
||||
Float ct = po.getCtRatio().floatValue() / (po.getCt2Ratio() == null ? 1.0f:po.getCt2Ratio().floatValue());
|
||||
Float pt = po.getPtRatio().floatValue() / (po.getPt2Ratio() == null ? 1.0f:po.getPt2Ratio().floatValue());
|
||||
//fixme 这边先根据数据集的名称来返回对应实体,这边感觉不太合适,后期有好方案再调整
|
||||
//基础数据
|
||||
if (dataSet.getName().contains("Ds$Pqd$Rt$Basic$")) {
|
||||
BaseRealDataSet baseRealDataSet = assembleData(dataArrayList,item,po.getConType());
|
||||
baseRealDataSet.setUserId(userId);
|
||||
baseRealDataSet.setLineId(lineId);
|
||||
baseRealDataSet.setPt(po.getPtRatio().floatValue());
|
||||
baseRealDataSet.setCt(po.getCtRatio().floatValue());
|
||||
baseRealDataSet.setDataLevel(dataSet.getDataLevel());
|
||||
long timestamp = item.getDataTimeSec() - 8*3600;
|
||||
baseRealDataSet.setDataTime(getTime(timestamp));
|
||||
publisher.send("/Web/RealData/" + lineId, new Gson().toJson(baseRealDataSet), 1, false);
|
||||
//用户Id
|
||||
Object redisObject = redisUtil.getObjectByKey("rtDataUserId:"+lineId);
|
||||
if (ObjectUtil.isNotNull(redisObject)) {
|
||||
String userId = redisObject.toString();
|
||||
BaseRealDataSet baseRealDataSet = assembleData(dataArrayList,item,po.getConType(),po1.getDevAccessMethod());
|
||||
baseRealDataSet.setUserId(userId);
|
||||
baseRealDataSet.setLineId(lineId);
|
||||
baseRealDataSet.setPt(pt);
|
||||
baseRealDataSet.setCt(ct);
|
||||
baseRealDataSet.setDataLevel(dataSet.getDataLevel());
|
||||
long timestamp = item.getDataTimeSec() - 8*3600;
|
||||
baseRealDataSet.setDataTime(getTime(timestamp));
|
||||
publisher.send("/Web/RealData/" + lineId, new Gson().toJson(baseRealDataSet), 1, false);
|
||||
}
|
||||
} else if (dataSet.getName().contains("实时数据") || dataSet.getName().contains("Ds$Pqd$Rt$01")) {
|
||||
//用户Id
|
||||
Object redisObject = redisUtil.getObjectByKey("rtDataUserId:"+lineId);
|
||||
if (ObjectUtil.isNotNull(redisObject)) {
|
||||
Set<String> userSet = redisSetUtil.convertToSet(redisObject);
|
||||
userSet.forEach(userId->{
|
||||
BaseRealDataSet baseRealDataSet = assembleData(dataArrayList,item,po.getConType(),po1.getDevAccessMethod());
|
||||
baseRealDataSet.setUserId(userId);
|
||||
baseRealDataSet.setLineId(lineId);
|
||||
baseRealDataSet.setPt(pt);
|
||||
baseRealDataSet.setCt(ct);
|
||||
baseRealDataSet.setDataLevel(dataSet.getDataLevel());
|
||||
long timestamp = item.getDataTimeSec();
|
||||
baseRealDataSet.setDataTime(getTime(timestamp));
|
||||
publisher.send("/Web/RealData/" + lineId, new Gson().toJson(baseRealDataSet), 1, false);
|
||||
});
|
||||
}
|
||||
}
|
||||
//fixme 目前实时数据只有基础数据和谐波数据,后期拓展,这边需要再判断
|
||||
else {
|
||||
HarmRealDataSet harmRealDataSet = harmData(dataArrayList,item,dataSet.getDataLevel(),po.getCtRatio());
|
||||
harmRealDataSet.setUserId(userId);
|
||||
harmRealDataSet.setLineId(lineId);
|
||||
harmRealDataSet.setPt(po.getPtRatio().floatValue());
|
||||
harmRealDataSet.setCt(po.getCtRatio().floatValue());
|
||||
harmRealDataSet.setDataLevel(dataSet.getDataLevel());
|
||||
long timestamp = item.getDataTimeSec() - 8*3600;
|
||||
harmRealDataSet.setDataTime(getTime(timestamp));
|
||||
publisher.send("/Web/RealData/" + lineId, new Gson().toJson(harmRealDataSet), 1, false);
|
||||
long timestamp;
|
||||
//用户Id
|
||||
Object redisObject = redisUtil.getObjectByKey("rtDataUserId:"+lineId);
|
||||
if (ObjectUtil.isNotNull(redisObject)) {
|
||||
String userId = redisObject.toString();
|
||||
HarmRealDataSet harmRealDataSet = harmData(dataArrayList,item,dataSet.getDataLevel(),po.getCtRatio());
|
||||
harmRealDataSet.setUserId(userId);
|
||||
harmRealDataSet.setLineId(lineId);
|
||||
harmRealDataSet.setPt(pt);
|
||||
harmRealDataSet.setCt(ct);
|
||||
harmRealDataSet.setDataLevel(dataSet.getDataLevel());
|
||||
if (ObjectUtil.isNotNull(po.getLineNo())) {
|
||||
timestamp = item.getDataTimeSec();
|
||||
} else {
|
||||
timestamp = item.getDataTimeSec() - 8*3600;
|
||||
}
|
||||
harmRealDataSet.setDataTime(getTime(timestamp));
|
||||
publisher.send("/Web/RealData/" + lineId, new Gson().toJson(harmRealDataSet), 1, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apfRtAnalysis(AppAutoDataMessage appAutoDataMessage) {
|
||||
List<CsDataArray> dataArrayList;
|
||||
String lineId;
|
||||
//监测点id
|
||||
if (appAutoDataMessage.getDid() == 1){
|
||||
lineId = appAutoDataMessage.getId() + "0";
|
||||
} else {
|
||||
lineId = appAutoDataMessage.getId() + appAutoDataMessage.getMsg().getClDid();
|
||||
}
|
||||
//获取监测点基础信息
|
||||
CsLinePO po = csLineFeignClient.getById(lineId).getData();
|
||||
//获取数据集 dataSet
|
||||
Integer idx = appAutoDataMessage.getMsg().getDsNameIdx();
|
||||
CsDataSet dataSet = dataSetFeignClient.getDataSetByIdx(po.getDataModelId(),idx).getData();
|
||||
|
||||
String key = "BaseRealData:" + lineId + idx;
|
||||
Object object = redisUtil.getObjectByKey(key);
|
||||
if (Objects.isNull(object)){
|
||||
dataArrayList = saveBaseRealDataSet(key,dataSet.getId());
|
||||
} else {
|
||||
dataArrayList = channelObjectUtil.objectToList(object,CsDataArray.class);
|
||||
}
|
||||
//根据dataArray解析数据
|
||||
AppAutoDataMessage.DataArray item = appAutoDataMessage.getMsg().getDataArray().get(0);
|
||||
Map<String,Float> map = getData(dataArrayList,item);
|
||||
int data = Math.round(map.get("Apf_ModWorkingSts" + "M"));
|
||||
redisUtil.saveByKeyWithExpire("ApfRtData:" + appAutoDataMessage.getMid(),data,10L);
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间处理
|
||||
*/
|
||||
@@ -141,90 +213,194 @@ public class RtServiceImpl implements IRtService {
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
public BaseRealDataSet assembleData(List<CsDataArray> dataArrayList,AppAutoDataMessage.DataArray dataArray,Integer conType) {
|
||||
public BaseRealDataSet assembleData(List<CsDataArray> dataArrayList,AppAutoDataMessage.DataArray dataArray,Integer conType,String accessMethod) {
|
||||
Map<String,Float> dataMap = getData(dataArrayList,dataArray);
|
||||
return channelData(dataMap,conType);
|
||||
if (Objects.equals("CLD",accessMethod)) {
|
||||
return channelData(dataMap,conType);
|
||||
} else {
|
||||
return channelData2(dataMap);
|
||||
}
|
||||
}
|
||||
|
||||
public BaseRealDataSet channelData(Map<String,Float> map,Integer conType) {
|
||||
BaseRealDataSet baseRealDataSet = new BaseRealDataSet();
|
||||
//频率
|
||||
baseRealDataSet.setFreq(FloatUtils.get2Float(map.get("Pq_FreqM")));
|
||||
baseRealDataSet.setFreq(map.get("Pq_FreqT"));
|
||||
//频率偏差
|
||||
baseRealDataSet.setFreqDev(FloatUtils.get2Float(map.get("Pq_FreqDevM")));
|
||||
baseRealDataSet.setFreqDev(map.get("Pq_FreqDevT"));
|
||||
//判断监测点的接线方式,不同接线方式电压有效值取值不同
|
||||
//星型-相电压 角形、V型-线电压
|
||||
//电压有效值
|
||||
if (conType == 0) {
|
||||
baseRealDataSet.setVRmsA(FloatUtils.get2Float(map.get("Pq_RmsUA")));
|
||||
baseRealDataSet.setVRmsB(FloatUtils.get2Float(map.get("Pq_RmsUB")));
|
||||
baseRealDataSet.setVRmsC(FloatUtils.get2Float(map.get("Pq_RmsUC")));
|
||||
baseRealDataSet.setVRmsA(map.get("Pq_RmsUA"));
|
||||
baseRealDataSet.setVRmsB(map.get("Pq_RmsUB"));
|
||||
baseRealDataSet.setVRmsC(map.get("Pq_RmsUC"));
|
||||
} else {
|
||||
baseRealDataSet.setVRmsA(FloatUtils.get2Float(map.get("Pq_RmsLUAB")));
|
||||
baseRealDataSet.setVRmsB(FloatUtils.get2Float(map.get("Pq_RmsLUBC")));
|
||||
baseRealDataSet.setVRmsC(FloatUtils.get2Float(map.get("Pq_RmsLUCA")));
|
||||
baseRealDataSet.setVRmsA(map.get("Pq_RmsLUAB"));
|
||||
baseRealDataSet.setVRmsB(map.get("Pq_RmsLUBC"));
|
||||
baseRealDataSet.setVRmsC(map.get("Pq_RmsLUCA"));
|
||||
}
|
||||
//基波电压幅值
|
||||
baseRealDataSet.setV1A(FloatUtils.get2Float(map.get("Pq_RmsFundUA")));
|
||||
baseRealDataSet.setV1B(FloatUtils.get2Float(map.get("Pq_RmsFundUB")));
|
||||
baseRealDataSet.setV1C(FloatUtils.get2Float(map.get("Pq_RmsFundUC")));
|
||||
if (conType == 0) {
|
||||
baseRealDataSet.setV1A(map.get("Pq_RmsFundUA"));
|
||||
baseRealDataSet.setV1B(map.get("Pq_RmsFundUB"));
|
||||
baseRealDataSet.setV1C(map.get("Pq_RmsFundUC"));
|
||||
} else {
|
||||
baseRealDataSet.setV1A(map.get("Pq_RmsFundLUAB"));
|
||||
baseRealDataSet.setV1B(map.get("Pq_RmsFundLUBC"));
|
||||
baseRealDataSet.setV1C(map.get("Pq_RmsFundLUCA"));
|
||||
}
|
||||
//电流有效值
|
||||
baseRealDataSet.setIRmsA(FloatUtils.get2Float(map.get("Pq_RmsIA")));
|
||||
baseRealDataSet.setIRmsB(FloatUtils.get2Float(map.get("Pq_RmsIB")));
|
||||
baseRealDataSet.setIRmsC(FloatUtils.get2Float(map.get("Pq_RmsIC")));
|
||||
baseRealDataSet.setIRmsA(map.get("Pq_RmsIA"));
|
||||
baseRealDataSet.setIRmsB(map.get("Pq_RmsIB"));
|
||||
baseRealDataSet.setIRmsC(map.get("Pq_RmsIC"));
|
||||
//基波电流幅值
|
||||
baseRealDataSet.setI1A(FloatUtils.get2Float(map.get("Pq_RmsFundIA")));
|
||||
baseRealDataSet.setI1B(FloatUtils.get2Float(map.get("Pq_RmsFundIB")));
|
||||
baseRealDataSet.setI1C(FloatUtils.get2Float(map.get("Pq_RmsFundIC")));
|
||||
baseRealDataSet.setI1A(map.get("Pq_RmsFundIA"));
|
||||
baseRealDataSet.setI1B(map.get("Pq_RmsFundIB"));
|
||||
baseRealDataSet.setI1C(map.get("Pq_RmsFundIC"));
|
||||
//电压偏差
|
||||
baseRealDataSet.setVDevA(FloatUtils.get2Float(map.get("Pq_UDevA")));
|
||||
baseRealDataSet.setVDevB(FloatUtils.get2Float(map.get("Pq_UDevB")));
|
||||
baseRealDataSet.setVDevC(FloatUtils.get2Float(map.get("Pq_UDevC")));
|
||||
if (conType == 0) {
|
||||
baseRealDataSet.setVDevA(map.get("Pq_UDevA"));
|
||||
baseRealDataSet.setVDevB(map.get("Pq_UDevB"));
|
||||
baseRealDataSet.setVDevC(map.get("Pq_UDevC"));
|
||||
} else {
|
||||
baseRealDataSet.setVDevA(map.get("Pq_LUDevAB"));
|
||||
baseRealDataSet.setVDevB(map.get("Pq_LUDevBC"));
|
||||
baseRealDataSet.setVDevC(map.get("Pq_LUDevCA"));
|
||||
}
|
||||
//基波电压相位
|
||||
baseRealDataSet.setV1AngA(FloatUtils.get2Float(map.get("Pq_FundUAngA")));
|
||||
baseRealDataSet.setV1AngB(FloatUtils.get2Float(map.get("Pq_FundUAngB")));
|
||||
baseRealDataSet.setV1AngC(FloatUtils.get2Float(map.get("Pq_FundUAngC")));
|
||||
if (conType == 0) {
|
||||
baseRealDataSet.setV1AngA(map.get("Pq_FundUAngA"));
|
||||
baseRealDataSet.setV1AngB(map.get("Pq_FundUAngB"));
|
||||
baseRealDataSet.setV1AngC(map.get("Pq_FundUAngC"));
|
||||
} else {
|
||||
baseRealDataSet.setV1AngA(map.get("Pq_FundLUAngAB"));
|
||||
baseRealDataSet.setV1AngB(map.get("Pq_FundLUAngBC"));
|
||||
baseRealDataSet.setV1AngC(map.get("Pq_FundLUAngCA"));
|
||||
}
|
||||
//基波电流相位
|
||||
baseRealDataSet.setI1AngA(FloatUtils.get2Float(map.get("Pq_FundIAngA")));
|
||||
baseRealDataSet.setI1AngB(FloatUtils.get2Float(map.get("Pq_FundIAngB")));
|
||||
baseRealDataSet.setI1AngC(FloatUtils.get2Float(map.get("Pq_FundIAngC")));
|
||||
baseRealDataSet.setI1AngA(map.get("Pq_FundIAngA"));
|
||||
baseRealDataSet.setI1AngB(map.get("Pq_FundIAngB"));
|
||||
baseRealDataSet.setI1AngC(map.get("Pq_FundIAngC"));
|
||||
//电压总谐波畸变率
|
||||
baseRealDataSet.setVThdA(FloatUtils.get2Float(map.get("Pq_ThdUA")));
|
||||
baseRealDataSet.setVThdB(FloatUtils.get2Float(map.get("Pq_ThdUB")));
|
||||
baseRealDataSet.setVThdC(FloatUtils.get2Float(map.get("Pq_ThdUC")));
|
||||
if (conType == 0) {
|
||||
baseRealDataSet.setVThdA(map.get("Pq_ThdUA"));
|
||||
baseRealDataSet.setVThdB(map.get("Pq_ThdUB"));
|
||||
baseRealDataSet.setVThdC(map.get("Pq_ThdUC"));
|
||||
} else {
|
||||
baseRealDataSet.setVThdA(map.get("Pq_ThdLUAB"));
|
||||
baseRealDataSet.setVThdB(map.get("Pq_ThdLUBC"));
|
||||
baseRealDataSet.setVThdC(map.get("Pq_ThdLUCA"));
|
||||
}
|
||||
//电流总谐波畸变率
|
||||
baseRealDataSet.setIThdA(FloatUtils.get2Float(map.get("Pq_ThdIA")));
|
||||
baseRealDataSet.setIThdB(FloatUtils.get2Float(map.get("Pq_ThdIB")));
|
||||
baseRealDataSet.setIThdC(FloatUtils.get2Float(map.get("Pq_ThdIC")));
|
||||
baseRealDataSet.setIThdA(map.get("Pq_ThdIA"));
|
||||
baseRealDataSet.setIThdB(map.get("Pq_ThdIB"));
|
||||
baseRealDataSet.setIThdC(map.get("Pq_ThdIC"));
|
||||
//电压不平衡度
|
||||
baseRealDataSet.setVUnbalance(FloatUtils.get2Float(map.get("Pq_UnbalNegUM")));
|
||||
baseRealDataSet.setVUnbalance(map.get("Pq_UnbalNegUT"));
|
||||
//电流不平衡度
|
||||
baseRealDataSet.setIUnbalance(FloatUtils.get2Float(map.get("Pq_UnbalNegIM")));
|
||||
baseRealDataSet.setIUnbalance(map.get("Pq_UnbalNegIT"));
|
||||
//有功功率
|
||||
baseRealDataSet.setPA(FloatUtils.get2Float(map.get("Pq_PA")));
|
||||
baseRealDataSet.setPB(FloatUtils.get2Float(map.get("Pq_PB")));
|
||||
baseRealDataSet.setPC(FloatUtils.get2Float(map.get("Pq_PC")));
|
||||
baseRealDataSet.setPTot(FloatUtils.get2Float(map.get("Pq_TotPM")));
|
||||
baseRealDataSet.setPA(map.get("Pq_PA"));
|
||||
baseRealDataSet.setPB(map.get("Pq_PB"));
|
||||
baseRealDataSet.setPC(map.get("Pq_PC"));
|
||||
baseRealDataSet.setPTot(map.get("Pq_TotPT"));
|
||||
//无功功率
|
||||
baseRealDataSet.setQA(FloatUtils.get2Float(map.get("Pq_QA")));
|
||||
baseRealDataSet.setQB(FloatUtils.get2Float(map.get("Pq_QB")));
|
||||
baseRealDataSet.setQC(FloatUtils.get2Float(map.get("Pq_QC")));
|
||||
baseRealDataSet.setQTot(FloatUtils.get2Float(map.get("Pq_TotQM")));
|
||||
baseRealDataSet.setQA(map.get("Pq_QA"));
|
||||
baseRealDataSet.setQB(map.get("Pq_QB"));
|
||||
baseRealDataSet.setQC(map.get("Pq_QC"));
|
||||
baseRealDataSet.setQTot(map.get("Pq_TotQT"));
|
||||
//视在功率
|
||||
baseRealDataSet.setSA(FloatUtils.get2Float(map.get("Pq_SA")));
|
||||
baseRealDataSet.setSB(FloatUtils.get2Float(map.get("Pq_SB")));
|
||||
baseRealDataSet.setSC(FloatUtils.get2Float(map.get("Pq_SC")));
|
||||
baseRealDataSet.setSTot(FloatUtils.get2Float(map.get("Pq_TotSM")));
|
||||
//功率因数
|
||||
baseRealDataSet.setPfA(FloatUtils.get2Float(map.get("Pq_PFA")));
|
||||
baseRealDataSet.setPfB(FloatUtils.get2Float(map.get("Pq_PFB")));
|
||||
baseRealDataSet.setPfC(FloatUtils.get2Float(map.get("Pq_PFC")));
|
||||
baseRealDataSet.setPfTot(FloatUtils.get2Float(map.get("Pq_TotPFM")));
|
||||
//基波功率因数
|
||||
baseRealDataSet.setDpfA(FloatUtils.get2Float(map.get("Pq_DPFA")));
|
||||
baseRealDataSet.setDpfB(FloatUtils.get2Float(map.get("Pq_DPFB")));
|
||||
baseRealDataSet.setDpfC(FloatUtils.get2Float(map.get("Pq_DPFC")));
|
||||
baseRealDataSet.setDpfTot(FloatUtils.get2Float(map.get("Pq_TotDPFM")));
|
||||
baseRealDataSet.setSA(map.get("Pq_SA"));
|
||||
baseRealDataSet.setSB(map.get("Pq_SB"));
|
||||
baseRealDataSet.setSC(map.get("Pq_SC"));
|
||||
baseRealDataSet.setSTot(map.get("Pq_TotST"));
|
||||
//视在功率因数
|
||||
baseRealDataSet.setPfA(map.get("Pq_PFA"));
|
||||
baseRealDataSet.setPfB(map.get("Pq_PFB"));
|
||||
baseRealDataSet.setPfC(map.get("Pq_PFC"));
|
||||
baseRealDataSet.setPfTot(map.get("Pq_TotPFT"));
|
||||
//位移功率因数
|
||||
baseRealDataSet.setDpfA(map.get("Pq_DFA"));
|
||||
baseRealDataSet.setDpfB(map.get("Pq_DFB"));
|
||||
baseRealDataSet.setDpfC(map.get("Pq_DFC"));
|
||||
baseRealDataSet.setDpfTot(map.get("Pq_TotDFT"));
|
||||
return baseRealDataSet;
|
||||
}
|
||||
|
||||
public BaseRealDataSet channelData2(Map<String,Float> map) {
|
||||
BaseRealDataSet baseRealDataSet = new BaseRealDataSet();
|
||||
//频率
|
||||
baseRealDataSet.setFreq(map.get("Pq_FreqT"));
|
||||
//频率偏差
|
||||
baseRealDataSet.setFreqDev(map.get("Pq_FreqDevT"));
|
||||
//判断监测点的接线方式,不同接线方式电压有效值取值不同
|
||||
//星型-相电压 角形、V型-线电压
|
||||
//电压有效值
|
||||
baseRealDataSet.setVRmsA(map.get("Pq_RmsUA"));
|
||||
baseRealDataSet.setVRmsB(map.get("Pq_RmsUB"));
|
||||
baseRealDataSet.setVRmsC(map.get("Pq_RmsUC"));
|
||||
//基波电压幅值
|
||||
baseRealDataSet.setV1A(map.get("Pq_RmsFundUA"));
|
||||
baseRealDataSet.setV1B(map.get("Pq_RmsFundUB"));
|
||||
baseRealDataSet.setV1C(map.get("Pq_RmsFundUC"));
|
||||
//电流有效值
|
||||
baseRealDataSet.setIRmsA(map.get("Pq_RmsIA"));
|
||||
baseRealDataSet.setIRmsB(map.get("Pq_RmsIB"));
|
||||
baseRealDataSet.setIRmsC(map.get("Pq_RmsIC"));
|
||||
//基波电流幅值
|
||||
baseRealDataSet.setI1A(map.get("Pq_RmsFundIA"));
|
||||
baseRealDataSet.setI1B(map.get("Pq_RmsFundIB"));
|
||||
baseRealDataSet.setI1C(map.get("Pq_RmsFundIC"));
|
||||
//电压偏差
|
||||
baseRealDataSet.setVDevA(map.get("Pq_UDevA"));
|
||||
baseRealDataSet.setVDevB(map.get("Pq_UDevB"));
|
||||
baseRealDataSet.setVDevC(map.get("Pq_UDevC"));
|
||||
//基波电压相位
|
||||
baseRealDataSet.setV1AngA(map.get("Pq_FundUAngA"));
|
||||
baseRealDataSet.setV1AngB(map.get("Pq_FundUAngB"));
|
||||
baseRealDataSet.setV1AngC(map.get("Pq_FundUAngC"));
|
||||
//基波电流相位
|
||||
baseRealDataSet.setI1AngA(map.get("Pq_FundIAngA"));
|
||||
baseRealDataSet.setI1AngB(map.get("Pq_FundIAngB"));
|
||||
baseRealDataSet.setI1AngC(map.get("Pq_FundIAngC"));
|
||||
//电压总谐波畸变率
|
||||
baseRealDataSet.setVThdA(map.get("Pq_ThdUA"));
|
||||
baseRealDataSet.setVThdB(map.get("Pq_ThdUB"));
|
||||
baseRealDataSet.setVThdC(map.get("Pq_ThdUC"));
|
||||
//电流总谐波畸变率
|
||||
baseRealDataSet.setIThdA(map.get("Pq_ThdIA"));
|
||||
baseRealDataSet.setIThdB(map.get("Pq_ThdIB"));
|
||||
baseRealDataSet.setIThdC(map.get("Pq_ThdIC"));
|
||||
//电压不平衡度
|
||||
baseRealDataSet.setVUnbalance(map.get("Pq_UnbalNegUT"));
|
||||
//电流不平衡度
|
||||
baseRealDataSet.setIUnbalance(map.get("Pq_UnbalNegIT"));
|
||||
//有功功率
|
||||
baseRealDataSet.setPA(map.get("Pq_PA"));
|
||||
baseRealDataSet.setPB(map.get("Pq_PB"));
|
||||
baseRealDataSet.setPC(map.get("Pq_PC"));
|
||||
baseRealDataSet.setPTot(map.get("Pq_TotPT"));
|
||||
//无功功率
|
||||
baseRealDataSet.setQA(map.get("Pq_QA"));
|
||||
baseRealDataSet.setQB(map.get("Pq_QB"));
|
||||
baseRealDataSet.setQC(map.get("Pq_QC"));
|
||||
baseRealDataSet.setQTot(map.get("Pq_TotQT"));
|
||||
//视在功率
|
||||
baseRealDataSet.setSA(map.get("Pq_SA"));
|
||||
baseRealDataSet.setSB(map.get("Pq_SB"));
|
||||
baseRealDataSet.setSC(map.get("Pq_SC"));
|
||||
baseRealDataSet.setSTot(map.get("Pq_TotST"));
|
||||
//视在功率因数
|
||||
baseRealDataSet.setPfA(map.get("Pq_PFA"));
|
||||
baseRealDataSet.setPfB(map.get("Pq_PFB"));
|
||||
baseRealDataSet.setPfC(map.get("Pq_PFC"));
|
||||
baseRealDataSet.setPfTot(map.get("Pq_TotPFT"));
|
||||
//位移功率因数
|
||||
baseRealDataSet.setDpfA(map.get("Pq_DFA"));
|
||||
baseRealDataSet.setDpfB(map.get("Pq_DFB"));
|
||||
baseRealDataSet.setDpfC(map.get("Pq_DFC"));
|
||||
baseRealDataSet.setDpfTot(map.get("Pq_TotDFT"));
|
||||
return baseRealDataSet;
|
||||
}
|
||||
|
||||
@@ -262,12 +438,14 @@ public class RtServiceImpl implements IRtService {
|
||||
if (Objects.equals(item.getHarmName(),"Pq_RmsFundI")) {
|
||||
if ("Secondary".equals(dataLevel)) {
|
||||
double data = item.getData() * ct;
|
||||
harmRealDataSet.setData1(FloatUtils.get2Float((float)data));
|
||||
harmRealDataSet.setData1((float)data);
|
||||
} else {
|
||||
harmRealDataSet.setData1(FloatUtils.get2Float(item.getData()));
|
||||
harmRealDataSet.setData1(item.getData());
|
||||
}
|
||||
} else if (Objects.equals(item.getHarmName(),"Pq_RmsFundU")) {
|
||||
harmRealDataSet.setData1(FloatUtils.get2Float(item.getData()));
|
||||
harmRealDataSet.setData1(item.getData());
|
||||
} else if (Objects.equals(item.getHarmName(),"Pq_ThdU")) {
|
||||
harmRealDataSet.setData1(item.getData());
|
||||
} else {
|
||||
String numberStr = item.getHarmName().substring(item.getHarmName().lastIndexOf('_') + 1);
|
||||
String fieldName = "data" + numberStr;
|
||||
@@ -277,12 +455,12 @@ public class RtServiceImpl implements IRtService {
|
||||
if (item.getHarmName().contains("Pq_HarmI_")) {
|
||||
if ("Secondary".equals(dataLevel)) {
|
||||
double data = item.getData() * ct;
|
||||
field.set(harmRealDataSet,FloatUtils.get2Float((float)data));
|
||||
field.set(harmRealDataSet,(float)data);
|
||||
} else {
|
||||
field.set(harmRealDataSet,FloatUtils.get2Float(item.getData()));
|
||||
field.set(harmRealDataSet,item.getData());
|
||||
}
|
||||
} else {
|
||||
field.set(harmRealDataSet,FloatUtils.get2Float(item.getData()));
|
||||
field.set(harmRealDataSet,item.getData());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
@@ -21,6 +21,10 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.tocrhz</groupId>
|
||||
<artifactId>mqtt-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-web</artifactId>
|
||||
|
||||
@@ -1,16 +1,24 @@
|
||||
package com.njcn.stat.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.njcn.access.api.CsDeviceFeignClient;
|
||||
import com.njcn.access.api.CsLineLatestDataFeignClient;
|
||||
import com.njcn.access.enums.AccessEnum;
|
||||
import com.njcn.access.pojo.po.CsLineLatestData;
|
||||
import com.njcn.access.utils.ChannelObjectUtil;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.utils.PubUtils;
|
||||
import com.njcn.csdevice.api.CsCommunicateFeignClient;
|
||||
import com.njcn.csdevice.api.CsLineFeignClient;
|
||||
import com.njcn.csdevice.api.DataArrayFeignClient;
|
||||
import com.njcn.csdevice.api.DeviceMessageFeignClient;
|
||||
import com.njcn.csdevice.param.LineInfoParam;
|
||||
import com.njcn.csdevice.pojo.dto.PqsCommunicateDto;
|
||||
import com.njcn.csdevice.pojo.param.DataArrayParam;
|
||||
import com.njcn.csdevice.pojo.po.CsDataArray;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.csdevice.pojo.po.CsLinePO;
|
||||
import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
|
||||
import com.njcn.influx.utils.InfluxDbUtils;
|
||||
import com.njcn.mq.message.AppAutoDataMessage;
|
||||
@@ -18,9 +26,7 @@ import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.stat.enums.StatResponseEnum;
|
||||
import com.njcn.stat.service.IStatService;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.pojo.po.DictData;
|
||||
import com.njcn.system.pojo.po.SysDicTreePO;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -30,6 +36,10 @@ import org.influxdb.dto.Point;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -46,15 +56,19 @@ import java.util.concurrent.TimeUnit;
|
||||
public class StatServiceImpl implements IStatService {
|
||||
|
||||
private final DataArrayFeignClient dataArrayFeignClient;
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
private final InfluxDbUtils influxDbUtils;
|
||||
private final CsLineFeignClient csLineFeignClient;
|
||||
private final RedisUtil redisUtil;
|
||||
private final ChannelObjectUtil channelObjectUtil;
|
||||
private final CsLineLatestDataFeignClient csLineLatestDataFeignClient;
|
||||
private final CsDeviceFeignClient csDeviceFeignClient;
|
||||
private final DeviceMessageFeignClient deviceMessageFeignClient;
|
||||
private final CsCommunicateFeignClient csCommunicateFeignClient;
|
||||
private final CsLineFeignClient csLineFeignClient;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void analysis(AppAutoDataMessage appAutoDataMessage) {
|
||||
LocalDateTime time = null;
|
||||
log.info("开始消费{},发送时间{}",appAutoDataMessage.getKey(),appAutoDataMessage.getSendTime());
|
||||
//1.根据设备网络识别码获取设备id,查询到所用的模板,用来判断模板的类型(治理模板还是电能质量模板)
|
||||
//2.解析appAutoDataMessage的Did,来判断当前数据是治理数据还是电能质量数据
|
||||
@@ -71,13 +85,15 @@ public class StatServiceImpl implements IStatService {
|
||||
String lineId = null;
|
||||
Object object1 = redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appAutoDataMessage.getId());
|
||||
if (Objects.isNull(object1)){
|
||||
lineInfo(appAutoDataMessage.getId());
|
||||
LineInfoParam param = new LineInfoParam();
|
||||
param.setNDid(appAutoDataMessage.getId());
|
||||
deviceMessageFeignClient.getLineInfo(param);
|
||||
}
|
||||
//获取当前设备信息判断装置型号,来筛选监测点
|
||||
List<CsEquipmentDeliveryPO> poList = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.DEVICE_LIST),CsEquipmentDeliveryPO.class);
|
||||
CsEquipmentDeliveryPO po = poList.stream().filter(item->Objects.equals(item.getNdid(),appAutoDataMessage.getId())).findFirst().orElse(null);
|
||||
List<SysDicTreePO> dictTreeList = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.DICT_TREE),SysDicTreePO.class);
|
||||
String code = dictTreeList.stream().filter(item->Objects.equals(item.getId(),po.getDevType())).findFirst().orElse(null).getCode();
|
||||
String code = Objects.requireNonNull(dictTreeList.stream().filter(item -> Objects.equals(item.getId(), po.getDevType())).findFirst().orElse(null)).getCode();
|
||||
|
||||
//便携式设备
|
||||
if (Objects.equals(DicDataEnum.PORTABLE.getCode(),code)) {
|
||||
@@ -85,13 +101,20 @@ public class StatServiceImpl implements IStatService {
|
||||
}
|
||||
//直连设备
|
||||
else if (Objects.equals(DicDataEnum.CONNECT_DEV.getCode(),code)) {
|
||||
if (Objects.equals(appAutoDataMessage.getDid(),1)){lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appAutoDataMessage.getId())), Map.class).get("0").toString();
|
||||
} else if (Objects.equals(appAutoDataMessage.getDid(),2)){
|
||||
if (Objects.equals(appAutoDataMessage.getDid(),1)) {
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appAutoDataMessage.getId())), Map.class).get("0").toString();
|
||||
} else if (Objects.equals(appAutoDataMessage.getDid(),2)) {
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appAutoDataMessage.getId())), Map.class).get(appAutoDataMessage.getMsg().getClDid().toString()).toString();
|
||||
}
|
||||
}
|
||||
//云前置设备
|
||||
else if (Objects.equals(DicDataEnum.DEV_CLD.getCode(),code)) {
|
||||
lineId = appAutoDataMessage.getId() + appAutoDataMessage.getMsg().getClDid();
|
||||
}
|
||||
|
||||
//获取当前设备信息
|
||||
if (CollectionUtil.isNotEmpty(list)){
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
Map<String,String> map = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.ELE_EPD_PQD)), Map.class);
|
||||
List<String> recordList = new ArrayList<>();
|
||||
for (AppAutoDataMessage.DataArray item : list) {
|
||||
switch (item.getDataAttr()) {
|
||||
@@ -114,7 +137,10 @@ public class StatServiceImpl implements IStatService {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
String key = AppRedisKey.DEV_MODEL.concat(dataArrayParam.getId() + dataArrayParam.getDid() + dataArrayParam.getCldId() + dataArrayParam.getStatMethod() + dataArrayParam.getIdx());
|
||||
boolean flag = Objects.equals(DicDataEnum.DEV_CLD.getCode(), code) && Objects.equals(po.getDevAccessMethod(), "CLD");
|
||||
int clDid = flag?1:appAutoDataMessage.getMsg().getClDid();
|
||||
// String key = AppRedisKey.DEV_MODEL.concat(dataArrayParam.getId() + dataArrayParam.getDid() + clDid + dataArrayParam.getStatMethod() + dataArrayParam.getIdx());
|
||||
String key = AppRedisKey.DEV_MODEL.concat(dataArrayParam.getId() + dataArrayParam.getDid() + clDid + dataArrayParam.getIdx());
|
||||
Object object = redisUtil.getObjectByKey(key);
|
||||
List<CsDataArray> dataArrayList;
|
||||
if (Objects.isNull(object)){
|
||||
@@ -122,40 +148,37 @@ public class StatServiceImpl implements IStatService {
|
||||
} else {
|
||||
dataArrayList = objectToList(object);
|
||||
}
|
||||
List<String> result = assembleData(lineId,dataArrayList,item,appAutoDataMessage.getMsg().getClDid(),dataArrayParam.getStatMethod(),po.getProcess());
|
||||
List<String> result = assembleData(lineId,dataArrayList,item,appAutoDataMessage.getMsg().getClDid(),dataArrayParam.getStatMethod(),po.getProcess(),code,po.getDevAccessMethod(),map);
|
||||
recordList.addAll(result);
|
||||
//获取时间
|
||||
boolean timeFlag = Objects.equals(DicDataEnum.DEV_CLD.getCode(), code) && Objects.equals(po.getDevAccessMethod(), "CLD");
|
||||
long devTime = timeFlag?item.getDataTimeSec():item.getDataTimeSec()-8*3600;
|
||||
time = Instant.ofEpochSecond(devTime)
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.toLocalDateTime();
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(recordList)){
|
||||
//influx数据批量入库
|
||||
influxDbUtils.batchInsert(influxDbUtils.getDbName(), "", InfluxDB.ConsistencyLevel.ALL, TimeUnit.MILLISECONDS, recordList);
|
||||
influxDbUtils.batchInsert(influxDbUtils.getDbName(), "", InfluxDB.ConsistencyLevel.ALL, TimeUnit.SECONDS, recordList);
|
||||
//记录监测点最新数据时间
|
||||
CsLineLatestData csLineLatestData = new CsLineLatestData();
|
||||
csLineLatestData.setLineId(lineId);
|
||||
csLineLatestData.setTimeId(Objects.isNull(time) ? LocalDateTime.now() : time);
|
||||
csLineLatestDataFeignClient.addData(csLineLatestData);
|
||||
}
|
||||
//判断设备运行状态
|
||||
if (!Objects.isNull(po.getRunStatus()) && po.getRunStatus() == 1) {
|
||||
csDeviceFeignClient.updateRunStatus(appAutoDataMessage.getId(), AccessEnum.ONLINE.getCode());
|
||||
//记录设备上线
|
||||
PqsCommunicateDto dto = new PqsCommunicateDto();
|
||||
dto.setTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN)));
|
||||
dto.setDevId(appAutoDataMessage.getId());
|
||||
dto.setType(1);
|
||||
dto.setDescription("通讯正常");
|
||||
csCommunicateFeignClient.insertion(dto);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存监测点相关信息
|
||||
*/
|
||||
public void lineInfo(String id) {
|
||||
Map<Integer,String> map = new HashMap<>();
|
||||
List<CsLinePO> lineList = csLineFeignClient.findByNdid(id).getData();
|
||||
if (CollectionUtil.isEmpty(lineList)){
|
||||
throw new BusinessException(StatResponseEnum.LINE_NULL);
|
||||
}
|
||||
for (CsLinePO item : lineList) {
|
||||
if (Objects.isNull(item.getPosition())){
|
||||
map.put(item.getClDid(),item.getLineId());
|
||||
} else {
|
||||
DictData dictData = dicDataFeignClient.getDicDataById(item.getPosition()).getData();
|
||||
if (Objects.equals(dictData.getCode(), DicDataEnum.OUTPUT_SIDE.getCode())){
|
||||
map.put(0,item.getLineId());
|
||||
} else if (Objects.equals(dictData.getCode(), DicDataEnum.GRID_SIDE.getCode())){
|
||||
map.put(1,item.getLineId());
|
||||
} else if (Objects.equals(dictData.getCode(), DicDataEnum.LOAD_SIDE.getCode())){
|
||||
map.put(2,item.getLineId());
|
||||
}
|
||||
}
|
||||
}
|
||||
redisUtil.saveByKey(AppRedisKey.LINE_POSITION+id,map);
|
||||
System.gc();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,31 +197,55 @@ public class StatServiceImpl implements IStatService {
|
||||
/**
|
||||
* influxDB数据组装
|
||||
*/
|
||||
public List<String> assembleData(String lineId,List<CsDataArray> dataArrayList,AppAutoDataMessage.DataArray item,Integer clDid,String statMethod,Integer process) {
|
||||
public List<String> assembleData(String lineId,List<CsDataArray> dataArrayList,AppAutoDataMessage.DataArray item,Integer clDid,String statMethod,Integer process,String devType,String accessMethod, Map<String,String> map) {
|
||||
List<String> records = new ArrayList<String>();
|
||||
//解码
|
||||
List<Float> floats = PubUtils.byteArrayToFloatList(Base64.getDecoder().decode(item.getData()));
|
||||
if (CollectionUtil.isEmpty(floats)){
|
||||
throw new BusinessException(StatResponseEnum.AUTO_DATA_NULL);
|
||||
}
|
||||
//校验模板和解码数据数量能否对应上
|
||||
if (!Objects.equals(dataArrayList.size(),floats.size())){
|
||||
throw new BusinessException(StatResponseEnum.ARRAY_DATA_NOT_MATCH);
|
||||
}
|
||||
Map<String,String> map = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.ELE_EPD_PQD)), Map.class);
|
||||
|
||||
boolean flag = Objects.equals(DicDataEnum.DEV_CLD.getCode(), devType) && Objects.equals(accessMethod, "CLD");
|
||||
//fixme 捂脸设备上送的是北京时间,时序数据库录入时 需要utc时间,减去8小时
|
||||
long originalTimeSec = flag ? item.getDataTimeSec() : item.getDataTimeSec() - 8 * 3600;
|
||||
|
||||
for (int i = 0; i < dataArrayList.size(); i++) {
|
||||
String tableName = map.get(dataArrayList.get(i).getName());
|
||||
long adjustedTimeSec;
|
||||
|
||||
//短时闪变 || 电压波动 10分钟
|
||||
if (Objects.equals(tableName,"data_flicker") || Objects.equals(tableName,"data_fluc")) {
|
||||
adjustedTimeSec = (originalTimeSec / 600) * 600;
|
||||
}
|
||||
//长时闪变 2小时
|
||||
else if (Objects.equals(tableName,"data_plt")) {
|
||||
adjustedTimeSec = (originalTimeSec / 7200) * 7200;
|
||||
}
|
||||
else {
|
||||
adjustedTimeSec = originalTimeSec;
|
||||
}
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
tags.put(InfluxDBTableConstant.LINE_ID,lineId);
|
||||
tags.put(InfluxDBTableConstant.PHASIC_TYPE,dataArrayList.get(i).getPhase());
|
||||
tags.put(InfluxDBTableConstant.VALUE_TYPE,statMethod);
|
||||
tags.put(InfluxDBTableConstant.CL_DID,clDid.toString());
|
||||
tags.put(InfluxDBTableConstant.PROCESS,process.toString());
|
||||
tags.put(InfluxDBTableConstant.VALUE_TYPE,statMethod.toUpperCase());
|
||||
if (Objects.isNull(item.getDataTag())) {
|
||||
tags.put(InfluxDBTableConstant.QUALITY_FLAG,"0");
|
||||
} else {
|
||||
tags.put(InfluxDBTableConstant.QUALITY_FLAG,String.valueOf(item.getDataTag()));
|
||||
}
|
||||
Map<String,Object> fields = new HashMap<>();
|
||||
fields.put(dataArrayList.get(i).getName(),floats.get(i));
|
||||
fields.put(InfluxDBTableConstant.IS_ABNORMAL,item.getDataTag());
|
||||
//fixme 这边前置传递的应该是UTC时间,但是前置说是传递的北京时间,讨论了一下没太理解。这边暂时先这样处理,influx入库处理成北京时间,减去8小时。
|
||||
Point point = influxDbUtils.pointBuilder(tableName, item.getDataTimeSec()-8*3600, TimeUnit.SECONDS, tags, fields);
|
||||
//这边特殊处理,如果数据为3.14159,则将数据置为null
|
||||
if (Objects.isNull(dataArrayList.get(i).getInfluxDbName())) {
|
||||
fields.put(dataArrayList.get(i).getName(),Objects.equals(floats.get(i),3.14159f) ? null:floats.get(i));
|
||||
} else {
|
||||
fields.put(dataArrayList.get(i).getInfluxDbName(),Objects.equals(floats.get(i),3.14159f) ? null:floats.get(i));
|
||||
}
|
||||
fields.put(InfluxDBTableConstant.CL_DID,clDid.toString());
|
||||
fields.put(InfluxDBTableConstant.PROCESS,process.toString());
|
||||
|
||||
Point point = influxDbUtils.pointBuilder(tableName, adjustedTimeSec, TimeUnit.SECONDS, tags, fields);
|
||||
BatchPoints batchPoints = BatchPoints.database(influxDbUtils.getDbName()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
|
||||
batchPoints.point(point);
|
||||
records.add(batchPoints.lineProtocol());
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.njcn.zlevent.api;
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.mq.message.AppEventMessage;
|
||||
import com.njcn.mq.message.CldLogMessage;
|
||||
import com.njcn.zlevent.api.fallback.EventClientFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -20,4 +21,7 @@ public interface EventFeignClient {
|
||||
@PostMapping("/portableData")
|
||||
HttpResult<String> getPortableData(@RequestBody AppEventMessage appEventMessage);
|
||||
|
||||
@PostMapping("/cldEventData")
|
||||
HttpResult<String> getCldEventData(@RequestBody CldLogMessage cldLogMessage);
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.mq.message.AppEventMessage;
|
||||
import com.njcn.mq.message.CldLogMessage;
|
||||
import com.njcn.zlevent.api.EventFeignClient;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -37,6 +38,12 @@ public class EventClientFallbackFactory implements FallbackFactory<EventFeignCli
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<String> getCldEventData(CldLogMessage cldLogMessage) {
|
||||
log.error("{}异常,降级处理,异常为:{}","云前置事件处理",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,9 @@ public interface ZlConstant {
|
||||
*/
|
||||
String EVT_PARAM_TM = "Evt_Param_Tm";
|
||||
|
||||
|
||||
/**
|
||||
* 幅值
|
||||
*/
|
||||
String EVT_PARAM_VVADEPTH = "Evt_Param_VVaDepth";
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.njcn.zlevent.pojo.dto;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.fasterxml.jackson.annotation.JsonAlias;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.njcn.middle.rocket.domain.BaseMessage;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-31
|
||||
*/
|
||||
@Data
|
||||
public class CommonBaseMessage extends BaseMessage {
|
||||
/**
|
||||
* 消息请求的唯一标识
|
||||
*/
|
||||
@JsonProperty("guid")
|
||||
@JsonAlias({"guid"})
|
||||
private String guid;
|
||||
|
||||
/**
|
||||
* 设备Mac
|
||||
*/
|
||||
@JsonProperty("devMac")
|
||||
@JsonAlias({"Dev_mac"})
|
||||
private String devMac;
|
||||
|
||||
/**
|
||||
* 前置Id
|
||||
*/
|
||||
@JsonProperty("frontId")
|
||||
@JsonAlias({"FrontId"})
|
||||
private String frontId;
|
||||
|
||||
/**
|
||||
* 前置进程号
|
||||
*/
|
||||
@JsonProperty("node")
|
||||
@JsonAlias({"Node"})
|
||||
private Integer node;
|
||||
|
||||
@JsonProperty("detail")
|
||||
@JsonAlias({"Detail"})
|
||||
private Object detail;
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
package com.njcn.zlevent.pojo.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-16
|
||||
*/
|
||||
@Data
|
||||
public class DevVersionResponeDTO extends CommonBaseMessage {
|
||||
|
||||
@JsonProperty("Detail")
|
||||
private DevVersionResponeDTO.Detail detail;
|
||||
|
||||
@Data
|
||||
public static class Detail {
|
||||
/**
|
||||
* 数据类型,代表特定功能
|
||||
*/
|
||||
@JsonProperty("Type")
|
||||
private Integer type;
|
||||
|
||||
@JsonProperty("Msg")
|
||||
private DevVersionResponeDTO.Msg msg;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Msg {
|
||||
|
||||
@JsonProperty("Code")
|
||||
private Integer code;
|
||||
|
||||
|
||||
@JsonProperty("VersionInfo")
|
||||
private VersionInfo versionInfo;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class VersionInfo {
|
||||
/**
|
||||
* 装置基础型号(只用于程序升级鉴别)
|
||||
*/
|
||||
@JsonProperty("BaseModel")
|
||||
private String baseModel;
|
||||
|
||||
/**
|
||||
* 云服务协议版本
|
||||
*/
|
||||
@JsonProperty("CloudProtocolVer")
|
||||
private String cloudProtocolVer;
|
||||
|
||||
/**
|
||||
* 应用程序版本号
|
||||
*/
|
||||
@JsonProperty("AppVersion")
|
||||
private String appVersion;
|
||||
|
||||
/**
|
||||
* 应用程序版本日期
|
||||
*/
|
||||
@JsonProperty("AppDate")
|
||||
private LocalDate appDate;
|
||||
|
||||
/**
|
||||
* 应用程序校验码
|
||||
*/
|
||||
@JsonProperty("AppChecksum")
|
||||
private String appChecksum;
|
||||
|
||||
/**
|
||||
* 电压接线方式(0-星1-三角2-V)
|
||||
*/
|
||||
@JsonProperty("VoltageWiring")
|
||||
private String voltageWiring;
|
||||
|
||||
/**
|
||||
* 电流B相是否合成(0-否1-是)
|
||||
*/
|
||||
@JsonProperty("CurrentBSynthetic")
|
||||
private String currentBSynthetic;
|
||||
|
||||
/**
|
||||
* 数据统计时间间隔(单位分钟)
|
||||
*/
|
||||
@JsonProperty("DataStatInterval")
|
||||
private Integer dataStatInterval;
|
||||
|
||||
/**
|
||||
* 额定电压(二次值,单位V)
|
||||
*/
|
||||
@JsonProperty("RatedVoltage")
|
||||
private Double ratedVoltage;
|
||||
|
||||
/**
|
||||
* PT变比
|
||||
*/
|
||||
@JsonProperty("PTRatio")
|
||||
private Integer ptRatio;
|
||||
|
||||
/**
|
||||
* CT变比
|
||||
*/
|
||||
@JsonProperty("CTRatio")
|
||||
private Integer ctRatio;
|
||||
|
||||
/**
|
||||
* sntp对时IP
|
||||
*/
|
||||
@JsonProperty("SntpIP")
|
||||
private String sntpIP;
|
||||
|
||||
/**
|
||||
* sntp对时端口
|
||||
*/
|
||||
@JsonProperty("SntpPort")
|
||||
private Integer sntpPort;
|
||||
|
||||
/**
|
||||
* sntp对时间隔(单位分钟)
|
||||
*/
|
||||
@JsonProperty("SntpInterval")
|
||||
private Integer sntpInterval;
|
||||
|
||||
/**
|
||||
* Web端口
|
||||
*/
|
||||
@JsonProperty("WebPort")
|
||||
private Integer webPort;
|
||||
|
||||
/**
|
||||
* FTP端口
|
||||
*/
|
||||
@JsonProperty("FtpPort")
|
||||
private Integer ftpPort;
|
||||
|
||||
/**
|
||||
* Pqdif文件时间间隔(单位小时)
|
||||
*/
|
||||
@JsonProperty("PqdifInterval")
|
||||
private Integer pqdifInterval;
|
||||
|
||||
/**
|
||||
* 录波文件包含文件类型数
|
||||
*/
|
||||
@JsonProperty("WaveFileTypeCount")
|
||||
private Integer waveFileTypeCount;
|
||||
|
||||
/**
|
||||
* 特殊程序版本信息
|
||||
*/
|
||||
@JsonProperty("SpecialVersion")
|
||||
private String specialVersion;
|
||||
|
||||
/**
|
||||
* 装置型号(具体型号全称)
|
||||
*/
|
||||
@JsonProperty("DeviceModel")
|
||||
private String deviceModel;
|
||||
|
||||
/**
|
||||
* 谐波电度版本标志(0-否1-是)
|
||||
*/
|
||||
@JsonProperty("HarmonicEnergyFlag")
|
||||
private Integer harmonicEnergyFlag;
|
||||
|
||||
/**
|
||||
* 物理设备名称(仅用于上位机录波文件拼接)
|
||||
*/
|
||||
@JsonProperty("PhysicalName")
|
||||
private String physicalName;
|
||||
|
||||
/**
|
||||
* 录波LD名称(仅用于上位机录波文件拼接)
|
||||
*/
|
||||
@JsonProperty("WaveLDName")
|
||||
private String waveLDName;
|
||||
|
||||
/**
|
||||
* 高频谐波功能标志(0-否1-是)
|
||||
*/
|
||||
@JsonProperty("HighFreqHarmonicFlag")
|
||||
private Integer highFreqHarmonicFlag;
|
||||
|
||||
/**
|
||||
* 投入的通讯协议(2字节十六进制数)
|
||||
*/
|
||||
@JsonProperty("CommProtocols")
|
||||
private Integer commProtocols;
|
||||
|
||||
/**
|
||||
* 投入的对时方式选择(2字节十六进制数)
|
||||
*/
|
||||
@JsonProperty("TimeSyncMethods")
|
||||
private Integer timeSyncMethods;
|
||||
|
||||
/**
|
||||
* 装置功能配置(2字节十六进制数)
|
||||
*/
|
||||
@JsonProperty("DeviceFunctions")
|
||||
private Integer deviceFunctions;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.njcn.zlevent.pojo.dto;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-04-01
|
||||
*/
|
||||
@Data
|
||||
public class DeviceVersionRequestDTO {
|
||||
/**
|
||||
* 消息请求的唯一标识
|
||||
*/
|
||||
@JSONField(name = "guid")
|
||||
private String guid;
|
||||
|
||||
/**
|
||||
* 设备ID
|
||||
*/
|
||||
@JSONField(name = "Dev_id")
|
||||
private String devId;
|
||||
|
||||
/**
|
||||
* 前置Id
|
||||
*/
|
||||
@JSONField(name = "FrontId")
|
||||
private String frontId;
|
||||
|
||||
/**
|
||||
* 前置进程号
|
||||
*/
|
||||
@JSONField(name = "Node")
|
||||
private Integer node;
|
||||
|
||||
@JSONField(name = "Detail")
|
||||
private DeviceVersionRequestDTO.Detail detail;
|
||||
|
||||
@Data
|
||||
public static class Detail {
|
||||
/**
|
||||
* 数据类型,代表特定功能
|
||||
*/
|
||||
@JSONField(name = "Type")
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
@JSONField(name = "Msg")
|
||||
private Map<String, Object> msg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.njcn.zlevent.pojo.dto;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-16
|
||||
*/
|
||||
@Data
|
||||
public class FileDownloadRequestDTO {
|
||||
|
||||
/**
|
||||
* 消息请求的唯一标识
|
||||
*/
|
||||
@JSONField(name = "guid")
|
||||
private String guid;
|
||||
|
||||
/**
|
||||
* 设备ID
|
||||
*/
|
||||
@JSONField(name = "Dev_id")
|
||||
private String devId;
|
||||
|
||||
/**
|
||||
* 前置Id
|
||||
*/
|
||||
@JSONField(name = "FrontId")
|
||||
private String frontId;
|
||||
|
||||
/**
|
||||
* 前置进程号
|
||||
*/
|
||||
@JSONField(name = "Node")
|
||||
private Integer node;
|
||||
|
||||
@JSONField(name = "Detail")
|
||||
private FileDownloadRequestDTO.Detail detail;
|
||||
|
||||
@Data
|
||||
public static class Detail {
|
||||
/**
|
||||
* 数据类型,代表特定功能
|
||||
*/
|
||||
@JSONField(name = "Type")
|
||||
private Integer type;
|
||||
|
||||
@JSONField(name = "Msg")
|
||||
private FileDownloadRequestDTO.Msg msg;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Msg {
|
||||
/**
|
||||
* 设备的文件名,例如:/etc/vol1_stat.txt
|
||||
*/
|
||||
@JSONField(name = "Name")
|
||||
private String name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.njcn.zlevent.pojo.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-16
|
||||
*/
|
||||
@Data
|
||||
public class FileDownloadResponeDTO extends CommonBaseMessage {
|
||||
|
||||
@JsonProperty("Detail")
|
||||
private FileDownloadResponeDTO.Detail detail;
|
||||
|
||||
@Data
|
||||
public static class Detail {
|
||||
/**
|
||||
* 数据类型,代表特定功能
|
||||
*/
|
||||
@JsonProperty("Type")
|
||||
private Integer type;
|
||||
|
||||
@JsonProperty("Msg")
|
||||
private FileDownloadResponeDTO.Msg msg;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Msg {
|
||||
/**
|
||||
* 文件名称,例如 /etc/vol1_stat.txt
|
||||
*/
|
||||
@JsonProperty("Name")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 远端文件名,例如 /download/vol1_stat.txt
|
||||
*/
|
||||
@JsonProperty("RemoteName")
|
||||
private String remoteName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.njcn.zlevent.pojo.dto;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-18
|
||||
*/
|
||||
@Data
|
||||
public class FileInfoRequestDTO {
|
||||
/**
|
||||
* 消息请求的唯一标识
|
||||
*/
|
||||
@JSONField(name = "guid")
|
||||
private String guid;
|
||||
|
||||
/**
|
||||
* 设备ID
|
||||
*/
|
||||
@JSONField(name = "Dev_id")
|
||||
private String devId;
|
||||
|
||||
/**
|
||||
* 前置Id
|
||||
*/
|
||||
@JSONField(name = "FrontId")
|
||||
private String frontId;
|
||||
|
||||
/**
|
||||
* 前置进程号
|
||||
*/
|
||||
@JSONField(name = "Node")
|
||||
private Integer node;
|
||||
|
||||
@JSONField(name = "Detail")
|
||||
private FileInfoRequestDTO.Detail detail;
|
||||
|
||||
@Data
|
||||
public static class Detail {
|
||||
/**
|
||||
* 数据类型,代表特定功能
|
||||
*/
|
||||
@JSONField(name = "Type")
|
||||
private Integer type;
|
||||
|
||||
@JSONField(name = "Msg")
|
||||
private FileInfoRequestDTO.Msg msg;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Msg {
|
||||
|
||||
@JSONField(name = "Name")
|
||||
private String name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.njcn.zlevent.pojo.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAlias;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-18
|
||||
*/
|
||||
@Data
|
||||
public class FileInfoResponseDTO extends CommonBaseMessage {
|
||||
|
||||
@JsonProperty("detail")
|
||||
@JsonAlias({"Detail"})
|
||||
private FileInfoResponseDTO.Detail detail;
|
||||
|
||||
@Data
|
||||
public static class Detail {
|
||||
/**
|
||||
* 数据类型,代表特定功能
|
||||
*/
|
||||
@JsonProperty("type")
|
||||
@JsonAlias({"Type"})
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 消息主体
|
||||
*/
|
||||
@JsonProperty("msg")
|
||||
@JsonAlias({"Msg"})
|
||||
private FileInfoResponseDTO.Msg msg;
|
||||
|
||||
/**
|
||||
* 响应码
|
||||
*/
|
||||
@JsonProperty("code")
|
||||
@JsonAlias({"Code"})
|
||||
private Integer code;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Msg {
|
||||
/**
|
||||
* 目录信息数组
|
||||
*/
|
||||
@JsonProperty("dirInfo")
|
||||
@JsonAlias({"DirInfo"})
|
||||
private List<FileInfoResponseDTO.ResourceElement> dirInfo;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class ResourceElement {
|
||||
/**
|
||||
* 文件名/文件夹名称
|
||||
*/
|
||||
@JsonProperty("name")
|
||||
@JsonAlias({"Name"})
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 类型,文件/文件夹
|
||||
*/
|
||||
@JsonProperty("type")
|
||||
@JsonAlias({"Type"})
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 目录信息数组单个元素的数据成员大小
|
||||
*/
|
||||
@JsonProperty("size")
|
||||
@JsonAlias({"Size"})
|
||||
private Integer size;
|
||||
|
||||
private String prjDataPath;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.njcn.zlevent.pojo.dto;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-04-01
|
||||
*/
|
||||
@Data
|
||||
public class FileOrDirDeleteRequestDTO {
|
||||
|
||||
/**
|
||||
* 消息请求的唯一标识
|
||||
*/
|
||||
@JSONField(name = "guid")
|
||||
private String guid;
|
||||
|
||||
/**
|
||||
* 设备ID
|
||||
*/
|
||||
@JSONField(name = "Dev_id")
|
||||
private String devId;
|
||||
|
||||
/**
|
||||
* 前置Id
|
||||
*/
|
||||
@JSONField(name = "FrontId")
|
||||
private String frontId;
|
||||
|
||||
/**
|
||||
* 前置进程号
|
||||
*/
|
||||
@JSONField(name = "Node")
|
||||
private Integer node;
|
||||
|
||||
@JSONField(name = "Detail")
|
||||
private FileOrDirDeleteRequestDTO.Detail detail;
|
||||
|
||||
@Data
|
||||
public static class Detail {
|
||||
/**
|
||||
* 数据类型,代表特定功能
|
||||
*/
|
||||
@JSONField(name = "Type")
|
||||
private Integer type;
|
||||
|
||||
@JSONField(name = "Msg")
|
||||
private FileOrDirDeleteRequestDTO.Msg msg;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Msg {
|
||||
|
||||
@JSONField(name = "Name")
|
||||
private String name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.njcn.zlevent.pojo.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-30
|
||||
*/
|
||||
@Data
|
||||
public class FileOrDirDeleteResponeDTO extends CommonBaseMessage {
|
||||
|
||||
@JsonProperty("Detail")
|
||||
private FileOrDirDeleteResponeDTO.Detail detail;
|
||||
|
||||
@Data
|
||||
public static class Detail {
|
||||
/**
|
||||
* 数据类型,代表特定功能
|
||||
*/
|
||||
@JsonProperty("Type")
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 响应主体
|
||||
*/
|
||||
@JsonProperty("Msg")
|
||||
private Map<String, Object> msg;
|
||||
|
||||
/**
|
||||
* 响应码
|
||||
*/
|
||||
@JsonProperty("Code")
|
||||
private Integer code;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.njcn.zlevent.pojo.dto;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-18
|
||||
*/
|
||||
@Data
|
||||
public class FileUploadRequestDTO {
|
||||
/**
|
||||
* 消息请求的唯一标识
|
||||
*/
|
||||
@JSONField(name = "guid")
|
||||
private String guid;
|
||||
|
||||
/**
|
||||
* 设备ID
|
||||
*/
|
||||
@JSONField(name = "Dev_id")
|
||||
private String devId;
|
||||
|
||||
/**
|
||||
* 前置Id
|
||||
*/
|
||||
@JSONField(name = "FrontId")
|
||||
private String frontId;
|
||||
|
||||
/**
|
||||
* 前置进程号
|
||||
*/
|
||||
@JSONField(name = "Node")
|
||||
private Integer node;
|
||||
|
||||
@JSONField(name = "Detail")
|
||||
private FileUploadRequestDTO.Detail detail;
|
||||
|
||||
@Data
|
||||
public static class Detail {
|
||||
/**
|
||||
* 数据类型,代表特定功能
|
||||
*/
|
||||
@JSONField(name = "Type")
|
||||
private Integer type;
|
||||
|
||||
@JSONField(name = "Msg")
|
||||
private FileUploadRequestDTO.Msg msg;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Msg {
|
||||
|
||||
@JSONField(name = "Name")
|
||||
private String name;
|
||||
|
||||
@JSONField(name = "RemoteName")
|
||||
private String remoteName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.njcn.zlevent.pojo.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-30
|
||||
*/
|
||||
@Data
|
||||
public class FileUploadResponeDTO extends CommonBaseMessage {
|
||||
|
||||
@JsonProperty("Detail")
|
||||
private FileUploadResponeDTO.Detail detail;
|
||||
|
||||
@Data
|
||||
public static class Detail {
|
||||
/**
|
||||
* 数据类型,代表特定功能
|
||||
*/
|
||||
@JsonProperty("Type")
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 响应主体
|
||||
*/
|
||||
@JsonProperty("Msg")
|
||||
private Map<String, Object> msg;
|
||||
|
||||
/**
|
||||
* 响应码
|
||||
*/
|
||||
@JsonProperty("Code")
|
||||
private Integer code;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.njcn.zlevent.pojo.dto;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-18
|
||||
*/
|
||||
@Data
|
||||
public class MkdirRequestDTO {
|
||||
/**
|
||||
* 消息请求的唯一标识
|
||||
*/
|
||||
@JSONField(name = "guid")
|
||||
private String guid;
|
||||
|
||||
/**
|
||||
* 设备ID
|
||||
*/
|
||||
@JSONField(name = "Dev_id")
|
||||
private String devId;
|
||||
|
||||
/**
|
||||
* 前置Id
|
||||
*/
|
||||
@JSONField(name = "FrontId")
|
||||
private String frontId;
|
||||
|
||||
/**
|
||||
* 前置进程号
|
||||
*/
|
||||
@JSONField(name = "Node")
|
||||
private Integer node;
|
||||
|
||||
@JSONField(name = "Detail")
|
||||
private MkdirRequestDTO.Detail detail;
|
||||
|
||||
@Data
|
||||
public static class Detail {
|
||||
/**
|
||||
* 数据类型,代表特定功能
|
||||
*/
|
||||
@JSONField(name = "Type")
|
||||
private Integer type;
|
||||
|
||||
@JSONField(name = "Msg")
|
||||
private MkdirRequestDTO.Msg msg;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Msg {
|
||||
|
||||
@JSONField(name = "Name")
|
||||
private String name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.njcn.zlevent.pojo.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-30
|
||||
*/
|
||||
@Data
|
||||
public class MkdirResponeDTO extends CommonBaseMessage {
|
||||
|
||||
@JsonProperty("Detail")
|
||||
private MkdirResponeDTO.Detail detail;
|
||||
|
||||
@Data
|
||||
public static class Detail {
|
||||
/**
|
||||
* 数据类型,代表特定功能
|
||||
*/
|
||||
@JsonProperty("Type")
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 响应主体
|
||||
*/
|
||||
@JsonProperty("Msg")
|
||||
private Map<String, Object> msg;
|
||||
|
||||
/**
|
||||
* 响应码
|
||||
*/
|
||||
@JsonProperty("Code")
|
||||
private Integer code;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.njcn.zlevent.pojo.dto;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-04-01
|
||||
*/
|
||||
@Data
|
||||
public class RebootRequestDTO {
|
||||
/**
|
||||
* 消息请求的唯一标识
|
||||
*/
|
||||
@JSONField(name = "guid")
|
||||
private String guid;
|
||||
|
||||
/**
|
||||
* 设备ID
|
||||
*/
|
||||
@JSONField(name = "Dev_id")
|
||||
private String devId;
|
||||
|
||||
/**
|
||||
* 前置Id
|
||||
*/
|
||||
@JSONField(name = "FrontId")
|
||||
private String frontId;
|
||||
|
||||
/**
|
||||
* 前置进程号
|
||||
*/
|
||||
@JSONField(name = "Node")
|
||||
private Integer node;
|
||||
|
||||
@JSONField(name = "Detail")
|
||||
private RebootRequestDTO.Detail detail;
|
||||
|
||||
@Data
|
||||
public static class Detail {
|
||||
/**
|
||||
* 数据类型,代表特定功能
|
||||
*/
|
||||
@JSONField(name = "Type")
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
@JSONField(name = "Msg")
|
||||
private Map<String, Object> msg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.njcn.zlevent.pojo.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-30
|
||||
*/
|
||||
@Data
|
||||
public class RebootResponeDTO extends CommonBaseMessage {
|
||||
|
||||
@JsonProperty("Detail")
|
||||
private RebootResponeDTO.Detail detail;
|
||||
|
||||
@Data
|
||||
public static class Detail {
|
||||
/**
|
||||
* 数据类型,代表特定功能
|
||||
*/
|
||||
@JsonProperty("Type")
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 响应主体
|
||||
*/
|
||||
@JsonProperty("Msg")
|
||||
private Map<String, Object> msg;
|
||||
|
||||
/**
|
||||
* 响应码
|
||||
*/
|
||||
@JsonProperty("Code")
|
||||
private Integer code;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.njcn.zlevent.pojo.dto;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-04-27
|
||||
*/
|
||||
@Data
|
||||
public class TimeSyncRequestDTO {
|
||||
|
||||
/**
|
||||
* 消息请求的唯一标识
|
||||
*/
|
||||
@JSONField(name = "guid")
|
||||
private String guid;
|
||||
|
||||
/**
|
||||
* 设备ID
|
||||
*/
|
||||
@JSONField(name = "Dev_id")
|
||||
private String devId;
|
||||
|
||||
/**
|
||||
* 前置Id
|
||||
*/
|
||||
@JSONField(name = "FrontId")
|
||||
private String frontId;
|
||||
|
||||
/**
|
||||
* 前置进程号
|
||||
*/
|
||||
@JSONField(name = "Node")
|
||||
private Integer node;
|
||||
|
||||
@JSONField(name = "Detail")
|
||||
private TimeSyncRequestDTO.Detail detail;
|
||||
|
||||
@Data
|
||||
public static class Detail {
|
||||
/**
|
||||
* 数据类型,代表特定功能
|
||||
*/
|
||||
@JSONField(name = "Type")
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
@JSONField(name = "Msg")
|
||||
private Map<String, Object> msg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.njcn.zlevent.pojo.dto;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-04-01
|
||||
*/
|
||||
@Data
|
||||
public class UpgradeRequestDTO {
|
||||
/**
|
||||
* 消息请求的唯一标识
|
||||
*/
|
||||
@JSONField(name = "guid")
|
||||
private String guid;
|
||||
|
||||
/**
|
||||
* 设备ID
|
||||
*/
|
||||
@JSONField(name = "Dev_id")
|
||||
private String devId;
|
||||
|
||||
/**
|
||||
* 前置Id
|
||||
*/
|
||||
@JSONField(name = "FrontId")
|
||||
private String frontId;
|
||||
|
||||
/**
|
||||
* 前置进程号
|
||||
*/
|
||||
@JSONField(name = "Node")
|
||||
private Integer node;
|
||||
|
||||
@JSONField(name = "Detail")
|
||||
private UpgradeRequestDTO.Detail detail;
|
||||
|
||||
@Data
|
||||
public static class Detail {
|
||||
/**
|
||||
* 数据类型,代表特定功能
|
||||
*/
|
||||
@JSONField(name = "Type")
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
@JSONField(name = "Msg")
|
||||
private UpgradeRequestDTO.Msg msg;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Msg {
|
||||
@JSONField(name = "Name")
|
||||
private String name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.njcn.zlevent.pojo.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-30
|
||||
*/
|
||||
@Data
|
||||
public class UpgradeResponeDTO extends CommonBaseMessage {
|
||||
|
||||
@JsonProperty("Detail")
|
||||
private UpgradeResponeDTO.Detail detail;
|
||||
|
||||
@Data
|
||||
public static class Detail {
|
||||
/**
|
||||
* 数据类型,代表特定功能
|
||||
*/
|
||||
@JsonProperty("Type")
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 响应主体
|
||||
*/
|
||||
@JsonProperty("Msg")
|
||||
private Map<String, Object> msg;
|
||||
|
||||
/**
|
||||
* 响应码
|
||||
*/
|
||||
@JsonProperty("Code")
|
||||
private Integer code;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.njcn.zlevent.pojo.dto;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-30
|
||||
*/
|
||||
@Data
|
||||
public class WorkingLogRequestDTO {
|
||||
/**
|
||||
* 消息请求的唯一标识
|
||||
*/
|
||||
@JSONField(name = "guid")
|
||||
private String guid;
|
||||
|
||||
/**
|
||||
* 设备ID
|
||||
*/
|
||||
@JSONField(name = "Dev_id")
|
||||
private String devId;
|
||||
|
||||
/**
|
||||
* 前置Id
|
||||
*/
|
||||
@JSONField(name = "FrontId")
|
||||
private String frontId;
|
||||
|
||||
/**
|
||||
* 前置进程号
|
||||
*/
|
||||
@JSONField(name = "Node")
|
||||
private Integer node;
|
||||
|
||||
@JSONField(name = "Detail")
|
||||
private WorkingLogRequestDTO.Detail detail;
|
||||
|
||||
@Data
|
||||
public static class Detail {
|
||||
/**
|
||||
* 数据类型,代表特定功能
|
||||
*/
|
||||
@JSONField(name = "Type")
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
@JSONField(name = "Msg")
|
||||
private Map<String, Object> msg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.njcn.zlevent.pojo.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-30
|
||||
*/
|
||||
@Data
|
||||
public class WorkingLogResponeDTO extends CommonBaseMessage {
|
||||
|
||||
@JsonProperty("Detail")
|
||||
private WorkingLogResponeDTO.Detail detail;
|
||||
|
||||
@Data
|
||||
public static class Detail {
|
||||
/**
|
||||
* 数据类型,代表特定功能
|
||||
*/
|
||||
@JsonProperty("Type")
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 响应主体
|
||||
*/
|
||||
@JsonProperty("Msg")
|
||||
private WorkingLogResponeDTO.Msg msg;
|
||||
|
||||
/**
|
||||
* 响应码
|
||||
*/
|
||||
@JsonProperty("Code")
|
||||
private Integer code;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Msg {
|
||||
/**
|
||||
* 时标
|
||||
*/
|
||||
@JsonProperty("Time")
|
||||
private LocalDateTime time;
|
||||
|
||||
/**
|
||||
* CPU负荷(单位%) 39_38(双核,单核的为一个)
|
||||
*/
|
||||
@JsonProperty("CpuLoad")
|
||||
private String cpuLoad;
|
||||
|
||||
/**
|
||||
* 装置剩余内存(单位MB)
|
||||
*/
|
||||
@JsonProperty("FreeMemory")
|
||||
private String freeMemory;
|
||||
|
||||
/**
|
||||
* 装置总内存(单位MB)
|
||||
*/
|
||||
@JsonProperty("TotalMemory")
|
||||
private String totalMemory;
|
||||
|
||||
/**
|
||||
* 装置主存储器剩余空间(单位GB)
|
||||
*/
|
||||
@JsonProperty("FreeStorage")
|
||||
private String freeStorage;
|
||||
|
||||
/**
|
||||
* 装置主存储器总空间(单位GB)
|
||||
*/
|
||||
@JsonProperty("TotalStorage")
|
||||
private String totalStorage;
|
||||
|
||||
/**
|
||||
* 硬对时最后时标(B码或秒秒冲)
|
||||
*/
|
||||
@JsonProperty("HardTimeSync")
|
||||
private LocalDateTime hardTimeSync;
|
||||
|
||||
/**
|
||||
* Sntp对时最后时标
|
||||
*/
|
||||
@JsonProperty("SntpTimeSync")
|
||||
private LocalDateTime sntpTimeSync;
|
||||
|
||||
/**
|
||||
* 云服务协议对时最后时标
|
||||
*/
|
||||
@JsonProperty("CloudTimeSync")
|
||||
private LocalDateTime cloudTimeSync;
|
||||
|
||||
/**
|
||||
* 无线模块信号强度
|
||||
*/
|
||||
@JsonProperty("SignalStrength")
|
||||
private String signalStrength;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.njcn.zlevent.pojo.param;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-17
|
||||
*/
|
||||
@Data
|
||||
public class FileParam {
|
||||
private String filePath;
|
||||
private String devId;
|
||||
}
|
||||
@@ -20,6 +20,10 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.tocrhz</groupId>
|
||||
<artifactId>mqtt-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
|
||||
@@ -73,6 +77,11 @@
|
||||
<artifactId>system-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>cs-system-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>cs-harmonic-api</artifactId>
|
||||
@@ -94,6 +103,16 @@
|
||||
<artifactId>common-oss</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>event-common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||
<version>2.7.12</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
|
||||
/**
|
||||
@@ -18,6 +19,7 @@ import org.springframework.context.annotation.DependsOn;
|
||||
@MapperScan("com.njcn.**.mapper")
|
||||
@EnableFeignClients(basePackages = "com.njcn")
|
||||
@SpringBootApplication(scanBasePackages = "com.njcn")
|
||||
@EnableAsync
|
||||
public class ZlEventBootApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.njcn.zlevent.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.AsyncConfigurer;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class AsyncConfig implements AsyncConfigurer {
|
||||
|
||||
@Bean("eventNotificationExecutor")
|
||||
public Executor eventNotificationExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setCorePoolSize(10);
|
||||
executor.setMaxPoolSize(20);
|
||||
executor.setQueueCapacity(200);
|
||||
executor.setThreadNamePrefix("event-notify-");
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
|
||||
@Bean("smsNotificationExecutor")
|
||||
public Executor smsNotificationExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setCorePoolSize(5);
|
||||
executor.setMaxPoolSize(10);
|
||||
executor.setQueueCapacity(100);
|
||||
executor.setThreadNamePrefix("sms-notify-");
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.njcn.zlevent.config;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.njcn.zlevent.service.IDeviceService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class TaskSchedulerConfig {
|
||||
|
||||
@Autowired
|
||||
private IDeviceService deviceService;
|
||||
|
||||
private final Map<String, ScheduledFuture<?>> scheduledTasks = new ConcurrentHashMap<>();
|
||||
|
||||
private final TaskScheduler taskScheduler;
|
||||
|
||||
public TaskSchedulerConfig() {
|
||||
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
||||
scheduler.setPoolSize(3);
|
||||
scheduler.setThreadNamePrefix("device-task-");
|
||||
scheduler.setWaitForTasksToCompleteOnShutdown(true);
|
||||
scheduler.initialize();
|
||||
this.taskScheduler = scheduler;
|
||||
}
|
||||
|
||||
public void startTask(String devId, long intervalSeconds) {
|
||||
if (scheduledTasks.containsKey(devId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ScheduledFuture<?> future = taskScheduler.schedule(
|
||||
() -> deviceService.getWorkingLog(devId),
|
||||
triggerContext -> Date.from(Instant.now().plusSeconds(intervalSeconds))
|
||||
);
|
||||
|
||||
scheduledTasks.put(devId, future);
|
||||
log.info("启动设备 {} 的定时任务成功,间隔={}秒", devId, intervalSeconds);
|
||||
}
|
||||
|
||||
public void stopTask(String devId) {
|
||||
ScheduledFuture<?> future = scheduledTasks.remove(devId);
|
||||
if (ObjectUtil.isNotNull(future)) {
|
||||
future.cancel(false);
|
||||
log.info("停止设备 {} 的定时任务成功", devId);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isTaskRunning(String devId) {
|
||||
ScheduledFuture<?> future = scheduledTasks.get(devId);
|
||||
return ObjectUtil.isNotNull(future) && !future.isDone() && !future.isCancelled();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.njcn.zlevent.controller;
|
||||
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.zlevent.service.IDeviceService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-20
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/device")
|
||||
@Api(tags = "操作设备")
|
||||
@AllArgsConstructor
|
||||
public class DeviceController extends BaseController {
|
||||
|
||||
private IDeviceService deviceService;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@GetMapping("/workingLog")
|
||||
@ApiOperation("开始获取装置运行日志")
|
||||
public HttpResult<Boolean> startWorkingLog(@RequestParam("devId") String devId) {
|
||||
String methodDescribe = getMethodDescribe("startWorkingLog");
|
||||
deviceService.startWorkingLog(devId);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@GetMapping("/stopWorkingLog")
|
||||
@ApiOperation("停止获取装置运行日志")
|
||||
public HttpResult<Boolean> stopWorkingLog(@RequestParam("devId") String devId) {
|
||||
String methodDescribe = getMethodDescribe("stopWorkingLog");
|
||||
deviceService.stopWorkingLogTask(devId);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@GetMapping("/upgrade")
|
||||
@ApiOperation("装置升级")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "devId", value = "设备ID", required = true),
|
||||
@ApiImplicitParam(name = "edDataId", value = "程序版本Id", required = true)
|
||||
})
|
||||
public HttpResult<Boolean> upgrade(@RequestParam("devId") String devId, @RequestParam("edDataId") String edDataId) {
|
||||
String methodDescribe = getMethodDescribe("upgrade");
|
||||
boolean res = deviceService.upgrade(devId, edDataId);
|
||||
return HttpResultUtil.assembleCommonResponseResult(res ? CommonResponseEnum.SUCCESS : CommonResponseEnum.FAIL, res, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@GetMapping("/reboot")
|
||||
@ApiOperation("装置重启")
|
||||
public HttpResult<Boolean> reboot(@RequestParam("devId") String devId) {
|
||||
String methodDescribe = getMethodDescribe("reboot");
|
||||
boolean res = deviceService.reboot(devId);
|
||||
return HttpResultUtil.assembleCommonResponseResult(res ? CommonResponseEnum.SUCCESS : CommonResponseEnum.FAIL, res, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@GetMapping("/timeSync")
|
||||
@ApiOperation("装置对时")
|
||||
public HttpResult<Boolean> timeSync(@RequestParam("devId") String devId) {
|
||||
String methodDescribe = getMethodDescribe("listDir");
|
||||
boolean res = deviceService.timeSync(devId);
|
||||
return HttpResultUtil.assembleCommonResponseResult(res ? CommonResponseEnum.SUCCESS : CommonResponseEnum.FAIL, res, methodDescribe);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.mq.message.AppEventMessage;
|
||||
import com.njcn.mq.message.CldLogMessage;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.zlevent.service.IEventService;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -54,4 +55,14 @@ public class EventController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/cldEventData")
|
||||
@ApiOperation("云前置事件处理")
|
||||
@ApiImplicitParam(name = "cldLogMessage", value = "数据实体", required = true)
|
||||
public HttpResult<String> getCldEventData(@RequestBody CldLogMessage cldLogMessage){
|
||||
String methodDescribe = getMethodDescribe("getCldEventData");
|
||||
eventService.getCldEventData(cldLogMessage);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,13 +7,20 @@ import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.mq.message.AppFileMessage;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.zlevent.pojo.dto.FileInfoResponseDTO;
|
||||
import com.njcn.zlevent.pojo.param.FileParam;
|
||||
import com.njcn.zlevent.service.IFileService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
@@ -35,7 +42,7 @@ public class FileController extends BaseController {
|
||||
@PostMapping("/fileInfo")
|
||||
@ApiOperation("文件信息")
|
||||
@ApiImplicitParam(name = "appFileMessage", value = "数据实体", required = true)
|
||||
public HttpResult<String> fileInfo(@RequestBody AppFileMessage appFileMessage){
|
||||
public HttpResult<String> fileInfo(@RequestBody AppFileMessage appFileMessage) {
|
||||
String methodDescribe = getMethodDescribe("fileInfo");
|
||||
fileService.analysisFileInfo(appFileMessage);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
@@ -45,7 +52,7 @@ public class FileController extends BaseController {
|
||||
@PostMapping("/fileStream")
|
||||
@ApiOperation("解析文件")
|
||||
@ApiImplicitParam(name = "appFileMessage", value = "数据实体", required = true)
|
||||
public HttpResult<String> fileStream(@RequestBody AppFileMessage appFileMessage){
|
||||
public HttpResult<String> fileStream(@RequestBody AppFileMessage appFileMessage) {
|
||||
String methodDescribe = getMethodDescribe("fileStream");
|
||||
fileService.analysisFileStream(appFileMessage);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
@@ -55,10 +62,59 @@ public class FileController extends BaseController {
|
||||
@PostMapping("/downloadMakeUpFile")
|
||||
@ApiOperation("下载补召文件")
|
||||
@ApiImplicitParam(name = "nDid", value = "nDid", required = true)
|
||||
public HttpResult<String> downloadMakeUpFile(@RequestParam("nDid") String nDid){
|
||||
public HttpResult<String> downloadMakeUpFile(@RequestParam("nDid") String nDid) {
|
||||
String methodDescribe = getMethodDescribe("downloadMakeUpFile");
|
||||
fileService.downloadMakeUpFile(nDid);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/listDir")
|
||||
@ApiOperation("获取目录列表")
|
||||
@ApiImplicitParam(name = "fileParam", value = "文件路径", required = true)
|
||||
public HttpResult<List<FileInfoResponseDTO.ResourceElement>> listDir(@RequestBody FileParam fileParam) {
|
||||
String methodDescribe = getMethodDescribe("listDir");
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, fileService.listDir(fileParam.getFilePath(), fileParam.getDevId()), methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/downloadFileFromFront")
|
||||
@ApiOperation("下载文件")
|
||||
@ApiImplicitParam(name = "fileParam", value = "文件参数", required = true)
|
||||
public void downloadFileFromFront(@RequestBody FileParam fileParam, HttpServletResponse response) {
|
||||
fileService.downloadFileFromFront(fileParam.getFilePath(), fileParam.getDevId(), response);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/mkdir")
|
||||
@ApiOperation("创建目录")
|
||||
@ApiImplicitParam(name = "fileParam", value = "文件参数", required = true)
|
||||
public HttpResult<Boolean> mkdir(@RequestBody FileParam fileParam) {
|
||||
String methodDescribe = getMethodDescribe("mkdir");
|
||||
boolean res = fileService.mkdir(fileParam.getFilePath(), fileParam.getDevId());
|
||||
return HttpResultUtil.assembleCommonResponseResult(res ? CommonResponseEnum.SUCCESS : CommonResponseEnum.FAIL, res, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/uploadFileToFront")
|
||||
@ApiOperation("上传文件")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "file", value = "文件", required = true),
|
||||
@ApiImplicitParam(name = "devId", value = "设备ID", required = true),
|
||||
@ApiImplicitParam(name = "dirPath", value = "文件所在路径", required = true)
|
||||
})
|
||||
public HttpResult<Boolean> uploadFileToFront(@RequestPart("file") MultipartFile file, @RequestParam("devId") String devId, @RequestParam("dirPath") String dirPath) {
|
||||
boolean res = fileService.uploadFileToFront(file, devId, dirPath);
|
||||
return HttpResultUtil.assembleCommonResponseResult(res ? CommonResponseEnum.SUCCESS : CommonResponseEnum.FAIL, res, getMethodDescribe("uploadFileToFront"));
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation("删除文件/目录")
|
||||
@ApiImplicitParam(name = "fileParam", value = "文件参数", required = true)
|
||||
public HttpResult<Boolean> delete(@RequestBody FileParam fileParam) {
|
||||
boolean res = fileService.delete(fileParam.getFilePath(), fileParam.getDevId());
|
||||
return HttpResultUtil.assembleCommonResponseResult(res ? CommonResponseEnum.SUCCESS : CommonResponseEnum.FAIL, res, getMethodDescribe("delete"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package com.njcn.zlevent.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.njcn.csharmonic.pojo.po.CsEventUserPO;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 暂态事件表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-08-23
|
||||
*/
|
||||
public interface CsEventUserMapper extends BaseMapper<CsEventUserPO> {
|
||||
|
||||
}
|
||||
//package com.njcn.zlevent.mapper;
|
||||
//
|
||||
//import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
//import com.njcn.csharmonic.pojo.po.CsEventUserPO;
|
||||
//
|
||||
///**
|
||||
// * <p>
|
||||
// * 暂态事件表 Mapper 接口
|
||||
// * </p>
|
||||
// *
|
||||
// * @author xuyang
|
||||
// * @since 2023-08-23
|
||||
// */
|
||||
//public interface CsEventUserMapper extends BaseMapper<CsEventUserPO> {
|
||||
//
|
||||
//}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.njcn.zlevent.producer;
|
||||
|
||||
import com.njcn.middle.rocket.domain.BaseMessage;
|
||||
import com.njcn.middle.rocket.template.RocketMQEnhanceTemplate;
|
||||
import com.njcn.mq.constant.BusinessTopic;
|
||||
import org.apache.rocketmq.client.producer.SendResult;
|
||||
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-16
|
||||
*/
|
||||
@Component
|
||||
public class CommonProducer extends RocketMQEnhanceTemplate {
|
||||
|
||||
|
||||
public CommonProducer(RocketMQTemplate template) {
|
||||
super(template);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* @param frontId
|
||||
* @return
|
||||
*/
|
||||
public SendResult send(BaseMessage message, String frontId) {
|
||||
return send(BusinessTopic.CLOUD_TOPIC, frontId, message);
|
||||
}
|
||||
public SendResult send(BaseMessage message) {
|
||||
return send(BusinessTopic.CLOUD_REPLY_TOPIC, message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
//package com.njcn.zlevent.service;
|
||||
//
|
||||
//import cn.hutool.core.collection.CollectionUtil;
|
||||
//import cn.hutool.core.date.DatePattern;
|
||||
//import com.njcn.access.pojo.dto.NoticeUserDto;
|
||||
//import com.njcn.access.utils.SendMessageUtil;
|
||||
//import com.njcn.csdevice.api.CsLedgerFeignClient;
|
||||
//import com.njcn.csdevice.api.DeviceMessageFeignClient;
|
||||
//import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
//import com.njcn.csdevice.api.EventLogsFeignClient;
|
||||
//import com.njcn.csdevice.param.DeviceMessageParam;
|
||||
//import com.njcn.csdevice.pojo.dto.DevDetailDTO;
|
||||
//import com.njcn.csdevice.pojo.po.CsEventSendMsg;
|
||||
//import com.njcn.csharmonic.pojo.po.CsEventUserPO;
|
||||
//import com.njcn.system.api.EpdFeignClient;
|
||||
//import com.njcn.user.pojo.po.User;
|
||||
//import lombok.RequiredArgsConstructor;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.scheduling.annotation.Async;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//
|
||||
//import java.time.LocalDateTime;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//import java.util.Objects;
|
||||
//import java.util.stream.Collectors;
|
||||
//
|
||||
///**
|
||||
// * @author xy
|
||||
// */
|
||||
//@Service
|
||||
//@Slf4j
|
||||
//@RequiredArgsConstructor
|
||||
//public class AppNotificationService {
|
||||
//
|
||||
// private final DeviceMessageFeignClient deviceMessageFeignClient;
|
||||
// private final EquipmentFeignClient equipmentFeignClient;
|
||||
// private final EpdFeignClient epdFeignClient;
|
||||
// private final ICsEventUserService csEventUserService;
|
||||
// private final SendMessageUtil sendMessageUtil;
|
||||
// private final EventLogsFeignClient eventLogsFeignClient;
|
||||
// private final CsLedgerFeignClient csLedgerFeignClient;
|
||||
//
|
||||
// @Async("eventNotificationExecutor")
|
||||
// public void sendAppNotification(Integer eventType, String type, String devId,
|
||||
// String eventName, LocalDateTime eventTime,
|
||||
// String id, String nDid, Double amplitude, Double persistTime,String dropZone) {
|
||||
// int code;
|
||||
// List<User> users = new ArrayList<>();
|
||||
// List<String> eventUser;
|
||||
// List<String> devCodeList;
|
||||
// List<String> userList = new ArrayList<>();
|
||||
// List<CsEventSendMsg> csEventSendMsgList = new ArrayList<>();
|
||||
// NoticeUserDto noticeUserDto = new NoticeUserDto();
|
||||
// NoticeUserDto.Payload payload = new NoticeUserDto.Payload();
|
||||
// String content = null;
|
||||
// List<CsEventUserPO> result = new ArrayList<>();
|
||||
// //获取设备类型 true:治理设备 false:其他类型的设备
|
||||
// boolean devModel = equipmentFeignClient.judgeDevModel(nDid).getData();
|
||||
// if (devModel) {
|
||||
// DevDetailDTO devDetailDto = csLedgerFeignClient.queryDevDetail(devId).getData();
|
||||
// //事件处理
|
||||
// if (eventType == 1){
|
||||
// eventName = epdFeignClient.findByName(eventName).getData().getShowName();
|
||||
// switch (type) {
|
||||
// case "1":
|
||||
// code = 3;
|
||||
// //设备自身事件 不推送给用户,推送给业务管理
|
||||
// eventUser = deviceMessageFeignClient.getEventUserByDeviceId(devId,false).getData();
|
||||
// if (CollectionUtil.isNotEmpty(eventUser)) {
|
||||
// eventUser.forEach(item->{
|
||||
// CsEventUserPO csEventUser = new CsEventUserPO();
|
||||
// csEventUser.setUserId(item);
|
||||
// csEventUser.setStatus(0);
|
||||
// csEventUser.setEventId(id);
|
||||
// result.add(csEventUser);
|
||||
// });
|
||||
//
|
||||
// DeviceMessageParam param1 = new DeviceMessageParam();
|
||||
// param1.setUserList(eventUser);
|
||||
// param1.setEventType(2);
|
||||
// users = deviceMessageFeignClient.getSendUserByType(param1).getData();
|
||||
// if (CollectionUtil.isNotEmpty(users)){
|
||||
// for (User user : users){
|
||||
// userList.add(user.getDevCode());
|
||||
// }
|
||||
// noticeUserDto.setPushClientId(userList);
|
||||
// noticeUserDto.setTitle("运行事件");
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
// case "2":
|
||||
// code = 0;
|
||||
// //暂态事件
|
||||
// eventUser = deviceMessageFeignClient.getEventUserByDeviceId(devId,true).getData();
|
||||
// if (CollectionUtil.isNotEmpty(eventUser)) {
|
||||
// eventUser.forEach(item->{
|
||||
// CsEventUserPO csEventUser = new CsEventUserPO();
|
||||
// csEventUser.setUserId(item);
|
||||
// csEventUser.setStatus(0);
|
||||
// csEventUser.setEventId(id);
|
||||
// result.add(csEventUser);
|
||||
// });
|
||||
// DeviceMessageParam param1 = new DeviceMessageParam();
|
||||
// param1.setUserList(eventUser);
|
||||
// param1.setEventType(0);
|
||||
// users = deviceMessageFeignClient.getSendUserByType(param1).getData();
|
||||
// if (CollectionUtil.isNotEmpty(users)){
|
||||
// devCodeList = users.stream().map(User::getDevCode).distinct().collect(Collectors.toList());
|
||||
// noticeUserDto.setPushClientId(devCodeList);
|
||||
// noticeUserDto.setTitle("暂态事件");
|
||||
// content = devDetailDto.getEngineeringName() + "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName()
|
||||
// + "于" + eventTime.format(DatePattern.NORM_DATETIME_MS_FORMATTER) + "发生暂态事件,事件类型:"
|
||||
// + eventName
|
||||
// + ",特征幅值:" + amplitude + "%"
|
||||
// + ",持续时间:" + persistTime + "s"
|
||||
// + ",落点区域:" + (Objects.isNull(dropZone)?"未知":dropZone);
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
//// case "3":
|
||||
//// code = 1;
|
||||
//// //稳态事件
|
||||
//// eventUser = getEventUser(devId,true);
|
||||
//// if (CollectionUtil.isNotEmpty(eventUser)) {
|
||||
//// eventUser.forEach(item->{
|
||||
//// CsEventUserPO csEventUser = new CsEventUserPO();
|
||||
//// csEventUser.setUserId(item);
|
||||
//// csEventUser.setStatus(0);
|
||||
//// csEventUser.setEventId(id);
|
||||
//// result.add(csEventUser);
|
||||
//// });
|
||||
//// users = getSendUser(eventUser,1);
|
||||
//// if (CollectionUtil.isNotEmpty(users)){
|
||||
//// devCodeList = users.stream().map(User::getDevCode).distinct().collect(Collectors.toList());
|
||||
//// noticeUserDto.setPushClientId(devCodeList);
|
||||
//// noticeUserDto.setTitle("稳态事件");
|
||||
//// }
|
||||
//// }
|
||||
//// break;
|
||||
// default:
|
||||
// code = 0;
|
||||
// break;
|
||||
// }
|
||||
// //获取台账信息
|
||||
// if (Objects.isNull(content)) {
|
||||
// content = devDetailDto.getEngineeringName() + "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName() + "于" + eventTime.format(DatePattern.NORM_DATETIME_MS_FORMATTER) + "发生" + eventName;
|
||||
// }
|
||||
// noticeUserDto.setContent(content);
|
||||
// payload.setType(code);
|
||||
// payload.setPath("/pages/index/message1?type="+payload.getType());
|
||||
// noticeUserDto.setPayload(payload);
|
||||
// }
|
||||
//// //告警处理
|
||||
//// else if (eventType == 2){
|
||||
//// switch (type) {
|
||||
//// case "1":
|
||||
//// //Ⅰ级告警 不推送给用户,推送给业务管理
|
||||
//// eventUser = getEventUser(devId,false);
|
||||
//// if (CollectionUtil.isNotEmpty(eventUser)) {
|
||||
//// eventUser.forEach(item->{
|
||||
//// CsEventUserPO csEventUser = new CsEventUserPO();
|
||||
//// csEventUser.setUserId(item);
|
||||
//// csEventUser.setStatus(0);
|
||||
//// csEventUser.setEventId(id);
|
||||
//// result.add(csEventUser);
|
||||
//// });
|
||||
//// users = getSendUser(eventUser,3);
|
||||
//// if (CollectionUtil.isNotEmpty(users)){
|
||||
//// eventName = epdFeignClient.findByName(eventName).getData().getShowName();
|
||||
//// devCodeList = users.stream().map(User::getDevCode).distinct().collect(Collectors.toList());
|
||||
//// noticeUserDto.setPushClientId(devCodeList);
|
||||
//// }
|
||||
//// }
|
||||
//// break;
|
||||
//// case "2":
|
||||
//// eventName = epdFeignClient.findByName(eventName).getData().getShowName();
|
||||
//// case "3":
|
||||
//// //Ⅱ、Ⅲ级告警推送相关用户及业务管理员
|
||||
//// eventUser = getEventUser(devId,true);
|
||||
//// if (CollectionUtil.isNotEmpty(eventUser)) {
|
||||
//// eventUser.forEach(item->{
|
||||
//// CsEventUserPO csEventUser = new CsEventUserPO();
|
||||
//// csEventUser.setUserId(item);
|
||||
//// csEventUser.setStatus(0);
|
||||
//// csEventUser.setEventId(id);
|
||||
//// result.add(csEventUser);
|
||||
//// });
|
||||
//// users = getSendUser(eventUser,3);
|
||||
//// if (CollectionUtil.isNotEmpty(users)){
|
||||
//// devCodeList = users.stream().map(User::getDevCode).distinct().collect(Collectors.toList());
|
||||
//// noticeUserDto.setPushClientId(devCodeList);
|
||||
//// }
|
||||
//// }
|
||||
//// break;
|
||||
//// default:
|
||||
//// break;
|
||||
//// }
|
||||
//// noticeUserDto.setTitle("告警事件");
|
||||
//// DevDetailDTO devDetailDto = csLedgerFeignclient.queryDevDetail(devId).getData();
|
||||
//// content = devDetailDto.getEngineeringName() + "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName() + "于" + eventTime.format(DatePattern.NORM_DATETIME_MS_FORMATTER) + "发生告警,告警信息:" + eventName;
|
||||
//// noticeUserDto.setContent(content);
|
||||
//// payload.setType(3);
|
||||
//// payload.setPath("/pages/message/message?type="+payload.getType());
|
||||
//// noticeUserDto.setPayload(payload);
|
||||
//// }
|
||||
// if (CollectionUtil.isNotEmpty(noticeUserDto.getPushClientId())) {
|
||||
// List<String> filteredList = noticeUserDto.getPushClientId().stream()
|
||||
// .filter(Objects::nonNull)
|
||||
// .distinct()
|
||||
// .collect(Collectors.toList());
|
||||
// if (CollectionUtil.isNotEmpty(filteredList)) {
|
||||
// noticeUserDto.setPushClientId(filteredList);
|
||||
// sendMessageUtil.sendEventToUser(noticeUserDto);
|
||||
// }
|
||||
// }
|
||||
// //记录推送日志
|
||||
// for (User item : users) {
|
||||
// CsEventSendMsg csEventSendMsg = new CsEventSendMsg();
|
||||
// csEventSendMsg.setUserId(item.getId());
|
||||
// csEventSendMsg.setEventId(id);
|
||||
// csEventSendMsg.setSendTime(LocalDateTime.now());
|
||||
// if (Objects.isNull(item.getDevCode())){
|
||||
// csEventSendMsg.setStatus(0);
|
||||
// csEventSendMsg.setRemark("用户设备识别码为空");
|
||||
// } else {
|
||||
// csEventSendMsg.setDevCode(item.getDevCode());
|
||||
// csEventSendMsg.setStatus(1);
|
||||
// }
|
||||
// csEventSendMsgList.add(csEventSendMsg);
|
||||
// }
|
||||
// eventLogsFeignClient.addLogs(csEventSendMsgList);
|
||||
// //事件用户关系入库
|
||||
// if (CollectionUtil.isNotEmpty(result)){
|
||||
// csEventUserService.saveBatch(result);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -19,6 +19,14 @@ public interface ICsEventService extends IService<CsEventPO> {
|
||||
/**
|
||||
* 事件添加波形文件地址
|
||||
*/
|
||||
List<String> updateCsEvent(CsEventParam csEventParam);
|
||||
List<CsEventPO> updateCsEvent(CsEventParam csEventParam);
|
||||
|
||||
/**
|
||||
* 暂降事件添加原因和类型
|
||||
* 暂降原因(0:未知 1:短路故障 2:电压调节器 3:感动电机 4:电压跌落)
|
||||
* 暂降类型(0:BC相间故障 1:C相接地故障 2:AC相间故障 3:A相接地故障 4:AB相间故障
|
||||
* 5:B相接地故障 6:BC相间接地 7:AC相间接地 8:AB相间接地 9:三相故障 10:未知)
|
||||
*/
|
||||
void updateEventCauseAndType(String id, Integer cause, Integer type);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package com.njcn.zlevent.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.csharmonic.pojo.po.CsEventUserPO;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 暂态事件表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-08-23
|
||||
*/
|
||||
public interface ICsEventUserService extends IService<CsEventUserPO> {
|
||||
|
||||
}
|
||||
//package com.njcn.zlevent.service;
|
||||
//
|
||||
//import com.baomidou.mybatisplus.extension.service.IService;
|
||||
//import com.njcn.csharmonic.pojo.po.CsEventUserPO;
|
||||
//
|
||||
///**
|
||||
// * <p>
|
||||
// * 暂态事件表 服务类
|
||||
// * </p>
|
||||
// *
|
||||
// * @author xuyang
|
||||
// * @since 2023-08-23
|
||||
// */
|
||||
//public interface ICsEventUserService extends IService<CsEventUserPO> {
|
||||
//
|
||||
//}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.njcn.zlevent.service;
|
||||
|
||||
import com.njcn.zlevent.pojo.dto.DevVersionResponeDTO;
|
||||
import com.njcn.zlevent.pojo.dto.DeviceVersionRequestDTO;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2026-03-20
|
||||
*/
|
||||
public interface IDeviceService {
|
||||
|
||||
/**
|
||||
* 开始运行日志任务
|
||||
*
|
||||
* @param devId 设备id
|
||||
*/
|
||||
void startWorkingLog(String devId);
|
||||
|
||||
/**
|
||||
* 停止运行日志任务
|
||||
*
|
||||
* @param devId
|
||||
*/
|
||||
void stopWorkingLogTask(String devId);
|
||||
|
||||
/**
|
||||
* 运行日志任务是否正在运行
|
||||
*
|
||||
* @param devId
|
||||
* @return
|
||||
*/
|
||||
boolean isWorkingLogTaskRunning(String devId);
|
||||
|
||||
void getWorkingLog(String devId);
|
||||
|
||||
/**
|
||||
* 设备对时
|
||||
*
|
||||
* @param devId
|
||||
* @return
|
||||
*/
|
||||
boolean timeSync(String devId);
|
||||
|
||||
/**
|
||||
* 获取设备版本信息
|
||||
*
|
||||
* @param devId
|
||||
* @return
|
||||
*/
|
||||
DevVersionResponeDTO.VersionInfo getDeviceVersion(String devId);
|
||||
|
||||
/**
|
||||
* 设备升级
|
||||
*
|
||||
* @param devId
|
||||
* @param edDataId
|
||||
*/
|
||||
boolean upgrade(String devId, String edDataId);
|
||||
|
||||
/**
|
||||
* 重启设备
|
||||
*
|
||||
* @param devId
|
||||
*/
|
||||
boolean reboot(String devId);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.njcn.zlevent.service;
|
||||
|
||||
import com.njcn.mq.message.AppEventMessage;
|
||||
import com.njcn.mq.message.CldLogMessage;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
@@ -25,4 +26,11 @@ public interface IEventService {
|
||||
*/
|
||||
void getPortableData(AppEventMessage appEventMessage);
|
||||
|
||||
/**
|
||||
* 云前置设备基础数据
|
||||
* 1.装置发起数据记录开始动作,库中新增数据;
|
||||
* @param cldLogMessage
|
||||
*/
|
||||
void getCldEventData( CldLogMessage cldLogMessage);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package com.njcn.zlevent.service;
|
||||
|
||||
import com.njcn.mq.message.AppFileMessage;
|
||||
import com.njcn.zlevent.pojo.dto.FileInfoResponseDTO;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
@@ -16,12 +21,14 @@ public interface IFileService {
|
||||
* 解析文件流之前需要获取文件的信息,可能要特殊处理
|
||||
* 1.文件过大要分片获取(单次请求文件大小不超过50k)
|
||||
* 2.校验文件(md5或者crc)
|
||||
*
|
||||
* @param appFileMessage
|
||||
*/
|
||||
void analysisFileInfo(AppFileMessage appFileMessage);
|
||||
|
||||
/**
|
||||
* 获取文件流,解析文件
|
||||
*
|
||||
* @param appFileMessage
|
||||
*/
|
||||
void analysisFileStream(AppFileMessage appFileMessage);
|
||||
@@ -30,4 +37,35 @@ public interface IFileService {
|
||||
* 下载补召文件
|
||||
*/
|
||||
void downloadMakeUpFile(String nDid);
|
||||
|
||||
/**
|
||||
* 获取目录列表
|
||||
*
|
||||
* @param filePath
|
||||
* @param devId
|
||||
* @return
|
||||
*/
|
||||
List<FileInfoResponseDTO.ResourceElement> listDir(String filePath, String devId);
|
||||
|
||||
/**
|
||||
* 从前置下载文件
|
||||
*
|
||||
* @param filePath
|
||||
* @param devId
|
||||
* @param response
|
||||
*/
|
||||
void downloadFileFromFront(String filePath, String devId, HttpServletResponse response);
|
||||
|
||||
/**
|
||||
* 上传文件到文件服务器
|
||||
*
|
||||
* @param file
|
||||
* @param devId
|
||||
* @param dirPath
|
||||
*/
|
||||
boolean uploadFileToFront(MultipartFile file, String devId, String dirPath);
|
||||
|
||||
boolean mkdir(String filePath, String devId);
|
||||
|
||||
boolean delete(String filePath, String devId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
//package com.njcn.zlevent.service;
|
||||
//
|
||||
//import cn.hutool.core.collection.CollectionUtil;
|
||||
//import cn.hutool.core.date.DatePattern;
|
||||
//import cn.hutool.core.util.StrUtil;
|
||||
//import com.njcn.csdevice.api.CsLedgerFeignClient;
|
||||
//import com.njcn.csdevice.api.SmsSendFeignClient;
|
||||
//import com.njcn.csdevice.pojo.dto.DevDetailDTO;
|
||||
//import com.njcn.cssystem.api.AppMsgSetFeignClient;
|
||||
//import com.njcn.user.api.UserFeignClient;
|
||||
//import com.njcn.user.pojo.po.User;
|
||||
//import lombok.RequiredArgsConstructor;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.beans.factory.annotation.Value;
|
||||
//import org.springframework.scheduling.annotation.Async;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//
|
||||
//import java.time.LocalDateTime;
|
||||
//import java.util.List;
|
||||
//import java.util.Objects;
|
||||
//import java.util.stream.Collectors;
|
||||
//
|
||||
///**
|
||||
// * @author xy
|
||||
// */
|
||||
//@Service
|
||||
//@Slf4j
|
||||
//@RequiredArgsConstructor
|
||||
//public class SmsNotificationService {
|
||||
//
|
||||
// private final AppMsgSetFeignClient appMsgSetFeignClient;
|
||||
// private final UserFeignClient userFeignClient;
|
||||
// private final SmsSendFeignClient smsSendFeignClient;
|
||||
// private final CsLedgerFeignClient csLedgerFeignclient;
|
||||
//
|
||||
// @Value("${msg.msg_sign:南京灿能电力}")
|
||||
// private String msgSign;
|
||||
//
|
||||
// @Async("smsNotificationExecutor")
|
||||
// public void sendSmsForDipEvent(String deviceId, LocalDateTime eventTime,double amplitude,double persistTime,String dropZone) {
|
||||
// try {
|
||||
// List<String> userIdList = appMsgSetFeignClient.queryUserIdsByDeviceId(deviceId).getData();
|
||||
// if (CollectionUtil.isNotEmpty(userIdList)) {
|
||||
// List<User> userList = userFeignClient.getUserListByIds(userIdList).getData();
|
||||
// if (CollectionUtil.isNotEmpty(userList)) {
|
||||
// List<User> userList1 = userList.stream()
|
||||
// .filter(item -> StrUtil.isNotBlank(item.getPhone()) && Objects.equals(item.getSmsNotice(), 1))
|
||||
// .collect(Collectors.toList());
|
||||
// if (CollectionUtil.isNotEmpty(userList1)) {
|
||||
// DevDetailDTO devDetailDto = csLedgerFeignclient.queryDevDetail(deviceId).getData();
|
||||
// String msgContent = "【" + msgSign + "】" + devDetailDto.getEngineeringName()
|
||||
// + "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName()
|
||||
// + "于" + eventTime.format(DatePattern.NORM_DATETIME_MS_FORMATTER) + "发生暂降事件"
|
||||
// + ",特征幅值:" + amplitude + "%"
|
||||
// + ",持续时间:" + persistTime + "s"
|
||||
// + ",落点区域:" + (Objects.isNull(dropZone)?"未知":dropZone);
|
||||
// userList1.forEach(item -> {
|
||||
// try {
|
||||
// smsSendFeignClient.sendSmsSimple(item.getPhone(), msgContent, "verify_code");
|
||||
// } catch (Exception e) {
|
||||
// log.error("发送短信失败,手机号: {}", item.getPhone(), e);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// log.error("异步发送暂降事件短信失败,设备ID: {}", deviceId, e);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -2,20 +2,29 @@ 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.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.access.utils.ChannelObjectUtil;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.csharmonic.pojo.po.CsEventPO;
|
||||
import com.njcn.cssystem.api.MsgSendFeignClient;
|
||||
import com.njcn.cssystem.pojo.param.MsgSendParam;
|
||||
import com.njcn.mq.message.AppEventMessage;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.system.api.EpdFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.pojo.param.EleEpdPqdParam;
|
||||
import com.njcn.system.pojo.po.EleEpdPqd;
|
||||
import com.njcn.system.pojo.po.SysDicTreePO;
|
||||
import com.njcn.zlevent.mapper.CsEventMapper;
|
||||
import com.njcn.zlevent.pojo.po.CsEventLogs;
|
||||
//import com.njcn.zlevent.service.AppNotificationService;
|
||||
import com.njcn.zlevent.service.ICsAlarmService;
|
||||
import com.njcn.zlevent.service.ICsEventLogsService;
|
||||
import com.njcn.zlevent.service.ICsEventService;
|
||||
import com.njcn.zlevent.utils.SendEventUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -24,8 +33,11 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.njcn.csdevice.enums.AlgorithmResponseEnum.DATA_ERROR;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 告警事件表 服务实现类
|
||||
@@ -40,31 +52,71 @@ public class CsAlarmServiceImpl extends ServiceImpl<CsEventMapper, CsEventPO> im
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
private final EventServiceImpl eventService;
|
||||
private final ICsEventService csEventService;
|
||||
private final SendEventUtils sendEventUtils;
|
||||
private final ICsEventLogsService csEventLogsService;
|
||||
private final EpdFeignClient epdFeignClient;
|
||||
private final RedisUtil redisUtil;
|
||||
private final ChannelObjectUtil channelObjectUtil;
|
||||
// private final AppNotificationService appNotificationService;
|
||||
private final MsgSendFeignClient msgSendFeignClient;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void analysis(AppEventMessage appEventMessage) {
|
||||
List<CsEventPO> list1 = new ArrayList<>();
|
||||
LocalDateTime eventTime = null;
|
||||
String tag = null;
|
||||
String tag = null, lineId = null;
|
||||
String id = IdUtil.fastSimpleUUID();
|
||||
//获取装置id
|
||||
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(appEventMessage.getId()).getData();
|
||||
List<SysDicTreePO> dictTreeList = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.DICT_TREE),SysDicTreePO.class);
|
||||
String code = dictTreeList.stream().filter(item->Objects.equals(item.getId(),po.getDevType())).findFirst().orElse(null).getCode();
|
||||
|
||||
try {
|
||||
//便携式设备
|
||||
if (Objects.equals(DicDataEnum.PORTABLE.getCode(),code)) {
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get(appEventMessage.getMsg().getClDid().toString()).toString();
|
||||
}
|
||||
//直连设备
|
||||
else if (Objects.equals(DicDataEnum.CONNECT_DEV.getCode(),code)) {
|
||||
if (Objects.equals(appEventMessage.getDid(),1)){
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get("0").toString();
|
||||
} else if (Objects.equals(appEventMessage.getDid(),2)){
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get(appEventMessage.getMsg().getClDid().toString()).toString();
|
||||
}
|
||||
}
|
||||
|
||||
List<AppEventMessage.DataArray> dataArray = appEventMessage.getMsg().getDataArray();
|
||||
for (AppEventMessage.DataArray item : dataArray) {
|
||||
eventTime = eventService.timeFormat(item.getDataTimeSec(),item.getDataTimeUSec());
|
||||
tag = item.getName();
|
||||
//判断各模块事件,如果上次模块事件和这次一致,则不记录
|
||||
CsEventPO csEventPO = this.lambdaQuery().eq(CsEventPO::getLineId,lineId)
|
||||
.eq(CsEventPO::getClDid,appEventMessage.getMsg().getClDid())
|
||||
.eq(CsEventPO::getProcess,po.getProcess())
|
||||
.orderByDesc(CsEventPO::getStartTime).last("LIMIT 1").one();
|
||||
if (csEventPO != null) {
|
||||
if (Objects.equals(csEventPO.getTag(),tag)) {
|
||||
throw new BusinessException(DATA_ERROR);
|
||||
}
|
||||
}
|
||||
//判断是否有重复数据
|
||||
CsEventPO po2 = this.lambdaQuery().eq(CsEventPO::getLineId,lineId)
|
||||
.eq(CsEventPO::getStartTime,eventTime)
|
||||
.eq(CsEventPO::getClDid,appEventMessage.getMsg().getClDid())
|
||||
.eq(CsEventPO::getProcess,po.getProcess())
|
||||
.eq(CsEventPO::getTag,tag).one();
|
||||
if (po2 != null) {
|
||||
throw new BusinessException(DATA_ERROR);
|
||||
}
|
||||
|
||||
//事件入库
|
||||
CsEventPO csEvent = new CsEventPO();
|
||||
csEvent.setLineId(lineId);
|
||||
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());
|
||||
@@ -76,10 +128,21 @@ public class CsAlarmServiceImpl extends ServiceImpl<CsEventMapper, CsEventPO> im
|
||||
csEventService.saveBatch(list1);
|
||||
//推送事件逻辑处理 && cs_event_user入库 && 修改字典中告警事件的编码
|
||||
for (AppEventMessage.DataArray item : dataArray) {
|
||||
MsgSendParam msgSendParam = new MsgSendParam();
|
||||
msgSendParam.setEventType(2);
|
||||
msgSendParam.setType(item.getType());
|
||||
msgSendParam.setDevId(po.getId());
|
||||
msgSendParam.setEventTime(eventTime);
|
||||
msgSendParam.setId(id);
|
||||
msgSendParam.setNDid(po.getNdid());
|
||||
if (Objects.isNull(item.getCode())){
|
||||
sendEventUtils.sendUser(2,item.getType(),po.getId(),item.getName(),eventTime,id,po.getNdid());
|
||||
msgSendParam.setEventName(item.getName());
|
||||
msgSendFeignClient.appMsgSend(msgSendParam);
|
||||
// appNotificationService.sendAppNotification(2,item.getType(),po.getId(),item.getName(),eventTime,id,po.getNdid(),null,null,null);
|
||||
} else {
|
||||
sendEventUtils.sendUser(2,item.getType(),po.getId(),item.getCode(),eventTime,id,po.getNdid());
|
||||
msgSendParam.setEventName(item.getCode());
|
||||
msgSendFeignClient.appMsgSend(msgSendParam);
|
||||
// appNotificationService.sendAppNotification(2,item.getType(),po.getId(),item.getCode(),eventTime,id,po.getNdid(),null, null,null);
|
||||
//更新字典信息
|
||||
EleEpdPqd eleEpdPqd = epdFeignClient.findByName(item.getName()).getData();
|
||||
EleEpdPqdParam.EleEpdPqdUpdateParam updateParam = new EleEpdPqdParam.EleEpdPqdUpdateParam();
|
||||
@@ -91,6 +154,7 @@ public class CsAlarmServiceImpl extends ServiceImpl<CsEventMapper, CsEventPO> im
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CsEventLogs csEventLogs = new CsEventLogs();
|
||||
csEventLogs.setLineId(lineId);
|
||||
csEventLogs.setDeviceId(po.getId());
|
||||
csEventLogs.setStartTime(eventTime);
|
||||
csEventLogs.setTag(tag);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user