Compare commits
112 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 | |||
| da3b99f663 | |||
| 04fd2409cf | |||
| b014aa7c8c | |||
| 67be8404d5 | |||
| 19f1c54ade | |||
| f211713f2e | |||
| d9708580db | |||
| af96a91303 | |||
| 4006d26d5f | |||
| 885fc36739 | |||
| eed276c9b3 | |||
| 24cf6e8d56 | |||
| 4028bfbff3 | |||
| 3861726801 | |||
| b5267c24f4 | |||
| 0c2954b8ba | |||
| 5137565195 | |||
| 82b5cfcf8d | |||
| 5c6d05b307 | |||
| 9f6bb44b3b | |||
| c40cd44402 | |||
| fc73879c95 | |||
| de8242fbf0 | |||
| e7412d916a | |||
| 851404f62d | |||
| e2f46ebcde | |||
| 749a814bfd | |||
| 81c78278d8 | |||
| e6715a8d96 | |||
| d852eed635 | |||
| 37d369cefd | |||
| b49b40aa8b | |||
| d090fd4fc0 | |||
| 021d17e6e7 | |||
| 6d7000ddc2 | |||
| 4a20892ab3 | |||
| b904565982 | |||
| 0745ad2fba | |||
| 15b73a9337 | |||
|
|
1ef08ad393 | ||
| 30fddbf252 | |||
| 942eff2a06 | |||
| 515ae0107c | |||
| de0d35f23d | |||
| cfd395a11c | |||
| 68e28880d0 | |||
| dfa7ebe94f | |||
| 9f4793e276 | |||
| 6c1bf03c9c | |||
| 4bc00dad30 | |||
| 1804cf69bd | |||
| 0e7d12ab93 | |||
| 531a787c91 | |||
| 45d31a05ee | |||
| dfd035b908 | |||
| ab59d870d8 | |||
| 5a94b6d8b4 | |||
| cfc2b2b7ba | |||
| eec42f60c0 | |||
| 1d71006d3c | |||
| 1dc16ae071 | |||
| ef2ce8367d | |||
| b59c85e791 | |||
| 32520907d2 | |||
| 06c8ce2e29 | |||
| 0fed84b8e0 | |||
| c58f45019a | |||
| 2d5feb1ef2 | |||
| ff188c3928 | |||
| d5ad4a81c8 | |||
| b2da20cf62 | |||
| 848cc9c7de | |||
| dc7afcc240 | |||
| 421312d4c4 | |||
| 335997cdf6 | |||
| bb298501eb | |||
| 9509a59f16 | |||
| b79e612595 | |||
| b55fa84c17 | |||
| 107c6d2637 | |||
| 72e81b1b6d | |||
| 9dab90ab88 | |||
| 14d79d4fe8 |
@@ -0,0 +1,40 @@
|
||||
package com.njcn.access.api;
|
||||
|
||||
import com.njcn.access.api.fallback.AskDeviceDataClientFallbackFactory;
|
||||
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 = "/askDeviceData", fallbackFactory = AskDeviceDataClientFallbackFactory.class,contextId = "askDeviceData")
|
||||
public interface AskDeviceDataFeignClient {
|
||||
|
||||
@PostMapping("/askDeviceRootPath")
|
||||
HttpResult<String> askDeviceRootPath(@RequestParam("nDid") String nDid);
|
||||
|
||||
@PostMapping("/askDeviceFileOrDir")
|
||||
HttpResult<String> askDeviceFileOrDir(@RequestParam("nDid") String nDid, @RequestParam("name") String name);
|
||||
|
||||
@PostMapping("/downloadFile")
|
||||
HttpResult<Boolean> downloadFile(@RequestParam("nDid") String nDid, @RequestParam("name") String name, @RequestParam("size") Integer size, @RequestParam("fileCheck") String fileCheck);
|
||||
|
||||
@PostMapping("/rebootDevice")
|
||||
HttpResult<String> rebootDevice(@RequestParam("nDid") String nDid);
|
||||
|
||||
@PostMapping("/createFolder")
|
||||
HttpResult<String> createFolder(@RequestParam("nDid") String nDid, @RequestParam("path") String path);
|
||||
|
||||
@PostMapping("/deleteFolder")
|
||||
HttpResult<String> deleteFolder(@RequestParam("nDid") String nDid, @RequestParam("path") String path);
|
||||
|
||||
@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,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();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.njcn.access.api.fallback;
|
||||
|
||||
import com.njcn.access.api.AskDeviceDataFeignClient;
|
||||
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.redis.utils.RedisUtil;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class AskDeviceDataClientFallbackFactory implements FallbackFactory<AskDeviceDataFeignClient> {
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@Override
|
||||
public AskDeviceDataFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if (cause.getCause() instanceof BusinessException) {
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new AskDeviceDataFeignClient() {
|
||||
@Override
|
||||
public HttpResult<String> askDeviceRootPath(String nDid) {
|
||||
log.error("{}异常,降级处理,异常为:{}","平台询问装置报文",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<String> askDeviceFileOrDir(String nDid, String name) {
|
||||
log.error("{}异常,降级处理,异常为:{}","设备文件/目录信息询问",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<Boolean> downloadFile(String nDid, String name, Integer size, String fileCheck) {
|
||||
log.error("{}异常,降级处理,异常为:{}","文件下载",cause.toString());
|
||||
redisUtil.delete("fileDowning:" + nDid);
|
||||
redisUtil.delete("fileCheck"+nDid+name);
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<String> rebootDevice(String nDid) {
|
||||
log.error("{}异常,降级处理,异常为:{}","设备重启",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<String> createFolder(String nDid, String path) {
|
||||
log.error("{}异常,降级处理,异常为:{}","创建文件夹",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<String> deleteFolder(String nDid, String path) {
|
||||
log.error("{}异常,降级处理,异常为:{}","删除文件夹",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<String> askRealData(String nDid, Integer idx, Integer clDid) {
|
||||
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,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);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -14,10 +14,10 @@ public enum AccessResponseEnum {
|
||||
* A0301 ~ A0399 用于用户模块的枚举
|
||||
* <p>
|
||||
*/
|
||||
NDID_NO_FIND("A0301", "此设备未录入!"),
|
||||
NDID_SAME_STEP("A0301", "此设备已注册!"),
|
||||
NDID_NO_FIND("A0301", "此装置未录入!"),
|
||||
NDID_SAME_STEP("A0301", "此装置已注册!"),
|
||||
|
||||
MISSING_CLIENT("A0302","设备客户端不在线!"),
|
||||
MISSING_CLIENT("A0302","装置端不在线!"),
|
||||
MODEL_REPEAT("A0302", "模板存在,请勿重复录入!"),
|
||||
MODEL_NO_FIND("A0302", "模板不存在,请先录入模板数据!"),
|
||||
MODEL_ERROR("A0302", "模板未找到,生成监测点失败!"),
|
||||
@@ -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,13 +56,13 @@ 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","平台重新上送文件异常"),
|
||||
|
||||
CLDID_IS_NULL("A0309","逻辑子设备标识为空"),
|
||||
MODULE_NUMBER_IS_NULL("A0309","设备子模块个数为空"),
|
||||
MODULE_NUMBER_IS_NULL("A0309","装置子模块个数为空"),
|
||||
LDEVINFO_IS_NULL("A0309","逻辑设备信息为空"),
|
||||
SOFTINFO_IS_NULL("A0309","软件信息为空"),
|
||||
|
||||
@@ -71,6 +71,10 @@ public enum AccessResponseEnum {
|
||||
PROCESS_SAME_ERROR("A0311","当前调试已完成,请勿重复调试"),
|
||||
PROCESS_MISSING_ERROR("A0311","调试流程缺失,请核查功能调试、出厂调试"),
|
||||
PROCESS_ERROR("A0311","调试流程异常,请先进行功能调试、出厂调试!"),
|
||||
|
||||
FILE_CHECK_ERROR("A0312","文件校验码不一致!"),
|
||||
|
||||
CLD_MODEL_EXIST("A0313","云前置模板已存在,请先删除再录入!"),
|
||||
;
|
||||
|
||||
private final String code;
|
||||
|
||||
@@ -44,6 +44,7 @@ public enum TypeEnum {
|
||||
TYPE_28("4662","设备根目录查询应答"),
|
||||
TYPE_29("9217","设备心跳请求"),
|
||||
TYPE_30("4865","设备数据主动上送"),
|
||||
TYPE_31("8503","设备控制命令"),
|
||||
|
||||
/**
|
||||
* 数据类型
|
||||
@@ -63,6 +64,7 @@ public enum TypeEnum {
|
||||
DATA_13("13","内部定值InSet"),
|
||||
DATA_14("14","控制Ctrl"),
|
||||
DATA_16("16","波形文件"),
|
||||
DATA_48("48","工程信息"),
|
||||
|
||||
/**
|
||||
* 数据模型列表
|
||||
|
||||
@@ -82,6 +82,89 @@ public class RspDataDto {
|
||||
|
||||
@SerializedName("Capacity_A")
|
||||
private Double capacityA;
|
||||
|
||||
@SerializedName("StatCycle")
|
||||
@ApiModelProperty("接线方式")
|
||||
private Integer StatCycle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 工程信息
|
||||
*/
|
||||
@Data
|
||||
public static class ProjectInfo {
|
||||
|
||||
@SerializedName("PrjName")
|
||||
@ApiModelProperty("项目名称")
|
||||
private String prjName;
|
||||
|
||||
@SerializedName("PrjTimeStart")
|
||||
@ApiModelProperty("项目起始时间")
|
||||
private Long prjTimeStart;
|
||||
|
||||
@SerializedName("PrjTimeEnd")
|
||||
@ApiModelProperty("项目结束时间")
|
||||
private Long prjTimeEnd;
|
||||
|
||||
@SerializedName("PrjDataPath")
|
||||
@ApiModelProperty("文件路径")
|
||||
private String prjDataPath;
|
||||
|
||||
@SerializedName("DevType")
|
||||
@ApiModelProperty("装置型号")
|
||||
private String devType;
|
||||
|
||||
@SerializedName("DevMac")
|
||||
@ApiModelProperty("装置mac")
|
||||
private String devMac;
|
||||
|
||||
@SerializedName("AppVersion")
|
||||
@ApiModelProperty("设备应用程序版本信息")
|
||||
private String appVersion;
|
||||
|
||||
@SerializedName("Cldid")
|
||||
@ApiModelProperty("逻辑子设备ID(0-逻辑设备本身)")
|
||||
private Integer clDid;
|
||||
|
||||
@SerializedName("StatCycle")
|
||||
@ApiModelProperty("分钟数据统计时间间隔(1~10分钟)")
|
||||
private Integer statCycle;
|
||||
|
||||
@SerializedName("VolGrade")
|
||||
@ApiModelProperty("电压等级(kV)")
|
||||
private Double volGrade;
|
||||
|
||||
@SerializedName("VolConType")
|
||||
@ApiModelProperty("电压接线方式 (0-星型, 1-角型, 2-V型)")
|
||||
private Integer volConType;
|
||||
|
||||
@SerializedName("CurConSel")
|
||||
@ApiModelProperty("电流接线方式 (0-正常, 1-合成IB, 2-合成IC)")
|
||||
private Integer curConSel;
|
||||
|
||||
@SerializedName("PtRatio")
|
||||
@ApiModelProperty("PT变比")
|
||||
private Integer ptRatio;
|
||||
|
||||
@SerializedName("CtRatio")
|
||||
@ApiModelProperty("CT变比")
|
||||
private Integer ctRatio;
|
||||
|
||||
@SerializedName("CapacitySscb")
|
||||
@ApiModelProperty("基准短路容量(MVA)")
|
||||
private Double capacitySscb;
|
||||
|
||||
@SerializedName("CapacitySscmin")
|
||||
@ApiModelProperty("最小短路容量(MVA)")
|
||||
private Double capacitySscmin;
|
||||
|
||||
@SerializedName("CapacitySt")
|
||||
@ApiModelProperty("供电设备容量(MVA)")
|
||||
private Double capacitySt;
|
||||
|
||||
@SerializedName("CapacitySi")
|
||||
@ApiModelProperty("用户协议容量(MVA)")
|
||||
private Double capacitySi;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,6 +32,12 @@ public class AskDataDto {
|
||||
@ParamName("EndTime")
|
||||
private Integer EndTime;
|
||||
|
||||
@ParamName("RtDuration")
|
||||
private Integer RtDuration;
|
||||
|
||||
@ParamName("DsNameIdx")
|
||||
private Integer DsNameIdx;
|
||||
|
||||
@ParamName("DataArray")
|
||||
private DataArrayDto DataArray;
|
||||
}
|
||||
|
||||
@@ -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,21 +68,121 @@ 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 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,22 @@
|
||||
package com.njcn.access.pojo.dto;
|
||||
|
||||
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Data
|
||||
public class ControlDto implements Serializable {
|
||||
|
||||
@SerializedName("Cldid")
|
||||
private Integer clDid;
|
||||
|
||||
@SerializedName("CmdType")
|
||||
private String cmdType;
|
||||
|
||||
@SerializedName("CmdParm")
|
||||
private String cmdParm;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.njcn.access.pojo.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
* 装置缓存信息
|
||||
*/
|
||||
@Data
|
||||
public class DeviceRedisInfoDto {
|
||||
|
||||
@ApiModelProperty("装置id")
|
||||
private String deviceId;
|
||||
|
||||
@ApiModelProperty("装置nDid")
|
||||
private String nDid;
|
||||
|
||||
@ApiModelProperty("装置类型")
|
||||
private String deviceType;
|
||||
|
||||
@ApiModelProperty("装置模板id")
|
||||
private String modelId;
|
||||
|
||||
@ApiModelProperty("模板名称")
|
||||
private String modelName;
|
||||
|
||||
@ApiModelProperty("模板版本")
|
||||
private String modelVersion;
|
||||
|
||||
@ApiModelProperty("模板类型 0:治理模板 1:电能质量模板")
|
||||
private Integer modelType;
|
||||
|
||||
@ApiModelProperty("监测点信息")
|
||||
private List<LineRedisInfo> lineList;
|
||||
|
||||
@Data
|
||||
public static class LineRedisInfo {
|
||||
|
||||
@ApiModelProperty("监测点id")
|
||||
private String lineId;
|
||||
|
||||
@ApiModelProperty("监测点位置")
|
||||
private String location;
|
||||
|
||||
@ApiModelProperty("逻辑设备编码")
|
||||
private Integer clDid;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -76,8 +76,85 @@ public class EventDto {
|
||||
@ApiModelProperty("告警故障编码(一般显示为Hex)")
|
||||
private String code;
|
||||
|
||||
@SerializedName("DataTag")
|
||||
@ApiModelProperty("数据标识,1-标识数据异常")
|
||||
private Integer dataTag;
|
||||
|
||||
@SerializedName("Parm")
|
||||
private List<Param> param;
|
||||
|
||||
|
||||
@SerializedName("PrjName")
|
||||
@ApiModelProperty("工程名称")
|
||||
private String prjName;
|
||||
|
||||
@SerializedName("PrjTimeStart")
|
||||
@ApiModelProperty("装置启动时间")
|
||||
private Long prjTimeStart;
|
||||
|
||||
@SerializedName("PrjTimeEnd")
|
||||
@ApiModelProperty("装置结束时间")
|
||||
private Long prjTimeEnd;
|
||||
|
||||
@SerializedName("PrjDataPath")
|
||||
@ApiModelProperty("装置数据路径")
|
||||
private String prjDataPath;
|
||||
|
||||
@SerializedName("DevType")
|
||||
@ApiModelProperty("装置型号")
|
||||
private String devType;
|
||||
|
||||
@SerializedName("DevMac")
|
||||
@ApiModelProperty("装置mac地址")
|
||||
private String devMac;
|
||||
|
||||
@SerializedName("AppVersion")
|
||||
@ApiModelProperty("装置程序版本")
|
||||
private String appVersion;
|
||||
|
||||
@SerializedName("Cldid")
|
||||
@ApiModelProperty("逻辑子设备id")
|
||||
private Integer clDid;
|
||||
|
||||
@SerializedName("StatCycle")
|
||||
@ApiModelProperty("统计间隔")
|
||||
private Integer statCycle;
|
||||
|
||||
@SerializedName("VolGrade")
|
||||
@ApiModelProperty("电压等级")
|
||||
private Float volGrade;
|
||||
|
||||
@SerializedName("VolConType")
|
||||
@ApiModelProperty("电压接线方式(0-星型, 1-角型, 2-V型)")
|
||||
private Integer volConType;
|
||||
|
||||
@SerializedName("CurConSel")
|
||||
@ApiModelProperty("电流接线方式(0-正常, 1-合成IB, 2-合成IC)")
|
||||
private Integer curConSel;
|
||||
|
||||
@SerializedName("PtRatio")
|
||||
@ApiModelProperty("PT变比")
|
||||
private Integer ptRatio;
|
||||
|
||||
@SerializedName("CtRatio")
|
||||
@ApiModelProperty("ct变比")
|
||||
private Integer ctRatio;
|
||||
|
||||
@SerializedName("CapacitySscb")
|
||||
@ApiModelProperty("基准短路容量")
|
||||
private Float capacitySscb;
|
||||
|
||||
@SerializedName("CapacitySscmin")
|
||||
@ApiModelProperty("最小短路容量")
|
||||
private Float capacitySscmin;
|
||||
|
||||
@SerializedName("CapacitySt")
|
||||
@ApiModelProperty("供电设备容量")
|
||||
private Float capacitySt;
|
||||
|
||||
@SerializedName("CapacitySi")
|
||||
@ApiModelProperty("用户协议容量")
|
||||
private Float capacitySi;
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.njcn.access.pojo.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
* 模板缓存信息
|
||||
*/
|
||||
@Data
|
||||
public class ModelRedisInfoDto {
|
||||
|
||||
@ApiModelProperty("模板id")
|
||||
private String modelId;
|
||||
|
||||
@ApiModelProperty("模板名称")
|
||||
private String modelName;
|
||||
|
||||
@ApiModelProperty("模板时间")
|
||||
private LocalDate versionDate;
|
||||
|
||||
@ApiModelProperty("模板版本")
|
||||
private String version;
|
||||
|
||||
@ApiModelProperty("数据集集合")
|
||||
private List<DataSet> dataSetList;
|
||||
|
||||
@Data
|
||||
public static class DataSet {
|
||||
|
||||
@ApiModelProperty("数据集id")
|
||||
private String dataSetId;
|
||||
|
||||
@ApiModelProperty("数据集名称")
|
||||
private String dataSetName;
|
||||
|
||||
@ApiModelProperty("数据指标集合")
|
||||
private List<DataArray> dataArrayList;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class DataArray {
|
||||
|
||||
@ApiModelProperty("数据指标id")
|
||||
private String dataArrayId;
|
||||
|
||||
@ApiModelProperty("数据指标名称")
|
||||
private String dataArrayName;
|
||||
|
||||
@ApiModelProperty("数据指标别名")
|
||||
private String anotherName;
|
||||
|
||||
@ApiModelProperty("数据指标统计方式")
|
||||
private String statMethod;
|
||||
|
||||
@ApiModelProperty("数据指标相别")
|
||||
private String phase;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.njcn.zlevent.pojo.dto;
|
||||
package com.njcn.access.pojo.dto;
|
||||
|
||||
import com.njcn.access.annotation.ParamName;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
@@ -34,4 +34,8 @@ public class UploadFileDto {
|
||||
@ApiModelProperty("文件校验码")
|
||||
private String fileCheck;
|
||||
|
||||
@SerializedName("StepFileCheck")
|
||||
@ApiModelProperty("当前帧文件校验码")
|
||||
private String stepFileCheck;
|
||||
|
||||
}
|
||||
|
||||
@@ -36,11 +36,20 @@ public class DataSetDto implements Serializable {
|
||||
@ApiModelProperty("0-不存储;1-存储")
|
||||
private Integer storeFlag;
|
||||
|
||||
@SerializedName("DataAttr")
|
||||
@NotNull(message = "数据集类型")
|
||||
@ApiModelProperty("Stat-统计数据 Rt-实时数据")
|
||||
private String dataAttr;
|
||||
|
||||
@SerializedName("DataLevel")
|
||||
@NotNull(message = "数据标识(一次值、二次值),不可为空")
|
||||
@ApiModelProperty("Primary-一次值;Secondary-二次值")
|
||||
private String dataLevel;
|
||||
|
||||
@SerializedName("ConType")
|
||||
@ApiModelProperty("接线方式 (0-星型,1-角型,2-V型)")
|
||||
private Integer conType;
|
||||
|
||||
@SerializedName("DataArray")
|
||||
@NotEmpty(message = "数据集合描述,不可为空")
|
||||
private List<DataArrayDto> dataArrayDtoList;
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
@@ -42,7 +43,10 @@ public class FileDto implements Serializable {
|
||||
private String type;
|
||||
|
||||
@SerializedName("FileInfo")
|
||||
private FileDto.FileInfo fileInfo;
|
||||
private FileInfo fileInfo;
|
||||
|
||||
@SerializedName("DirInfo")
|
||||
private List<DirInfo> dirInfo;
|
||||
|
||||
@SerializedName("Data")
|
||||
private String data;
|
||||
@@ -86,4 +90,22 @@ public class FileDto implements Serializable {
|
||||
private String fileChkType;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class DirInfo{
|
||||
|
||||
@SerializedName("Name")
|
||||
private String name;
|
||||
|
||||
@SerializedName("Type")
|
||||
private String type;
|
||||
|
||||
@SerializedName("Size")
|
||||
@ApiModelProperty("文件大小,单位KB")
|
||||
private Integer size;
|
||||
|
||||
@SerializedName("Time")
|
||||
@ApiModelProperty("时间")
|
||||
private Long time;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package com.njcn.access.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.db.bo.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 系统软件表
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-05-17
|
||||
*/
|
||||
@Data
|
||||
@TableName("cs_soft_info")
|
||||
public class CsSoftInfoPO {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 读写操作属性:“r”
|
||||
*/
|
||||
private String opAttr;
|
||||
|
||||
/**
|
||||
* 操作系统名称,裸机系统填Null
|
||||
*/
|
||||
private String osName;
|
||||
|
||||
/**
|
||||
* 操作系统版本,裸机系统填Null
|
||||
*/
|
||||
private String osVersion;
|
||||
|
||||
/**
|
||||
* 应用程序版本号
|
||||
*/
|
||||
private String appVersion;
|
||||
|
||||
/**
|
||||
* 应用程序发布日期
|
||||
*/
|
||||
private Date appDate;
|
||||
|
||||
/**
|
||||
* 应用程序校验码
|
||||
*/
|
||||
private String appCheck;
|
||||
|
||||
/**
|
||||
* 是否支持远程升级程序
|
||||
*/
|
||||
private String softUpdate;
|
||||
|
||||
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.njcn.access.utils;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Component
|
||||
public class CRC32Utils {
|
||||
|
||||
// CRC-32/MPEG-2 多项式, x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.njcn.access.utils;
|
||||
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Component
|
||||
public class ChannelObjectUtil {
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
/**
|
||||
* 将list转成对应实体
|
||||
* @param object
|
||||
* @param clazz
|
||||
* @return
|
||||
* @param <T>
|
||||
*/
|
||||
public <T> List<T> objectToList(Object object, Class<T> clazz) {
|
||||
List<T> resultList = new ArrayList<>();
|
||||
if (object instanceof List<?>) {
|
||||
for (Object o : (List<?>) object) {
|
||||
resultList.add(clazz.cast(o));
|
||||
}
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将object转成对应实体
|
||||
* @param object
|
||||
* @param clazz
|
||||
* @return
|
||||
* @param <T>
|
||||
*/
|
||||
public <T> T objectToSingleObject(Object object, Class<T> clazz) {
|
||||
if (clazz.isInstance(object)) {
|
||||
return clazz.cast(object);
|
||||
}
|
||||
// 或者抛出异常,根据您的需求
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object getDeviceMid(String nDid) {
|
||||
return redisUtil.getObjectByKey(AppRedisKey.DEVICE_MID + nDid);
|
||||
}
|
||||
|
||||
|
||||
public Map<String, List<String>> objectToMap(Object obj) {
|
||||
// 创建并填充 Map
|
||||
Map<String, List<String>> resultMap = new HashMap<>();
|
||||
String json = obj.toString();
|
||||
// 移除首尾的 {}
|
||||
json = json.substring(1, json.length() - 1);
|
||||
// 找到键和值的分隔符位置
|
||||
int keyEndIndex = json.indexOf("=[");
|
||||
String key = json.substring(0, keyEndIndex);
|
||||
String valuesStr = json.substring(keyEndIndex + 2, json.length() - 1);
|
||||
// 将值字符串分割成列表
|
||||
String[] valuesArray = valuesStr.split(", ");
|
||||
List<String> valuesList = Arrays.asList(valuesArray);
|
||||
resultMap.put(key, valuesList);
|
||||
return resultMap;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.njcn.access.utils;
|
||||
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
import com.njcn.access.api.CsTopicFeignClient;
|
||||
import com.njcn.access.enums.AccessEnum;
|
||||
import com.njcn.access.enums.TypeEnum;
|
||||
import com.njcn.access.pojo.dto.ReqAndResDto;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class FileCommonUtils {
|
||||
|
||||
@Resource
|
||||
private CsTopicFeignClient csTopicFeignClient;
|
||||
@Resource
|
||||
private MqttPublisher publisher;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
/**
|
||||
* 询问文件信息
|
||||
*/
|
||||
public void askFileInfo(String nDid, Integer mid, String fileName) {
|
||||
String version = csTopicFeignClient.find(nDid).getData();
|
||||
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
|
||||
reqAndResParam.setMid(mid);
|
||||
reqAndResParam.setDid(0);
|
||||
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_8.getCode()));
|
||||
reqAndResParam.setExpire(-1);
|
||||
String json = "{Name:\""+fileName+"\"}";
|
||||
JSONObject jsonObject = JSONObject.fromObject(json);
|
||||
reqAndResParam.setMsg(jsonObject);
|
||||
log.info("请求文件信息报文:" + new Gson().toJson(reqAndResParam));
|
||||
publisher.send("/Pfm/DevFileCmd/"+version+"/"+nDid,new Gson().toJson(reqAndResParam),1,false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空下载缓存
|
||||
*/
|
||||
public void cleanRedisData(String nDid, String fileName) {
|
||||
redisUtil.deleteKeysByString("downloadFilePath:"+ nDid);
|
||||
redisUtil.delete("fileDowning:"+nDid);
|
||||
redisUtil.delete("fileCheck" + nDid + fileName);
|
||||
redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(fileName));
|
||||
redisUtil.delete(AppRedisKey.FILE_PART.concat(fileName));
|
||||
redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(fileName));
|
||||
redisUtil.delete(AppRedisKey.FILE_DOWN_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<>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.njcn.access.utils;
|
||||
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.njcn.access.pojo.dto.NoticeUserDto;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* 推送消息
|
||||
* @author xy
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class SendMessageUtil {
|
||||
|
||||
public void sendEventToUser(NoticeUserDto noticeUserDto) {
|
||||
try {
|
||||
// 创建一个URL对象,指定目标HTTPS接口地址
|
||||
URL url = new URL("https://fc-mp-ff7b310f-94c9-4468-8260-109111c0a6b2.next.bspapp.com/push");
|
||||
// 打开HTTPS连接
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
// 设置请求方法为POST
|
||||
connection.setRequestMethod("POST");
|
||||
// 设置请求头,指定Content-Type为application/json
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
// 启用输出流以发送JSON数据
|
||||
connection.setDoOutput(true);
|
||||
// 将JSON数据写入输出流
|
||||
OutputStream outputStream = connection.getOutputStream();
|
||||
log.info(new Gson().toJson(noticeUserDto).replace("pushClientId", "push_clientid"));
|
||||
outputStream.write(new Gson().toJson(noticeUserDto).replace("pushClientId", "push_clientid").getBytes(StandardCharsets.UTF_8));
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
// 获取响应代码
|
||||
int responseCode = connection.getResponseCode();
|
||||
log.info("Response Code: " + responseCode);
|
||||
// 读取响应数据
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String inputLine;
|
||||
StringBuilder response = new StringBuilder();
|
||||
while ((inputLine = reader.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
}
|
||||
reader.close();
|
||||
// 打印响应内容
|
||||
log.info("Response Content: " + response.toString());
|
||||
// 关闭连接
|
||||
connection.disconnect();
|
||||
} catch (IOException e) {
|
||||
e.getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,12 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<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>
|
||||
@@ -63,7 +69,22 @@
|
||||
<artifactId>common-mq</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>zl-event-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-device-biz</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>rt-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.mybatis.spring.annotation.MapperScan;
|
||||
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.EnableScheduling;
|
||||
|
||||
|
||||
@@ -14,6 +15,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
* @date 2021年12月09日 20:59
|
||||
*/
|
||||
@Slf4j
|
||||
@DependsOn("proxyMapperRegister")
|
||||
@MapperScan("com.njcn.**.mapper")
|
||||
@EnableFeignClients(basePackages = "com.njcn")
|
||||
@SpringBootApplication(scanBasePackages = "com.njcn")
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
package com.njcn.access.controller;
|
||||
|
||||
import com.njcn.access.service.AskDeviceDataService;
|
||||
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.ApiImplicitParams;
|
||||
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.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/askDeviceData")
|
||||
@Api(tags = "平台操作装置报文")
|
||||
@AllArgsConstructor
|
||||
//@ApiIgnore
|
||||
public class AskDeviceDataController extends BaseController {
|
||||
|
||||
private final AskDeviceDataService askDeviceDataService;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/askDeviceRootPath")
|
||||
@ApiOperation("设备根目录询问")
|
||||
@ApiImplicitParam(name = "nDid", value = "nDid", required = true)
|
||||
public HttpResult<String> askDeviceRootPath(@RequestParam("nDid") String nDid){
|
||||
String methodDescribe = getMethodDescribe("askDeviceRootPath");
|
||||
askDeviceDataService.askDeviceRootPath(nDid);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/askDeviceFileOrDir")
|
||||
@ApiOperation("设备文件/目录信息询问")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "nDid", value = "nDid", required = true),
|
||||
@ApiImplicitParam(name = "name", value = "name", required = true)
|
||||
})
|
||||
public HttpResult<String> askDeviceFileOrDir(@RequestParam("nDid") String nDid, @RequestParam("name") String name){
|
||||
String methodDescribe = getMethodDescribe("askDeviceFileOrDir");
|
||||
askDeviceDataService.askDeviceFileOrDir(nDid,name);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/downloadFile")
|
||||
@ApiOperation("设备文件下载")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "nDid", value = "nDid", required = true),
|
||||
@ApiImplicitParam(name = "name", value = "文件路径名", required = true),
|
||||
@ApiImplicitParam(name = "size", value = "文件大小(单位byte)", required = true),
|
||||
@ApiImplicitParam(name = "fileCheck", value = "文件校验码", required = true)
|
||||
})
|
||||
public HttpResult<Boolean> downloadFile(@RequestParam("nDid") String nDid, @RequestParam("name") String name, @RequestParam("size") Integer size, @RequestParam("fileCheck") String fileCheck){
|
||||
String methodDescribe = getMethodDescribe("downloadFile");
|
||||
boolean result = askDeviceDataService.downloadFile(nDid,name,size,fileCheck);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/rebootDevice")
|
||||
@ApiOperation("重启设备")
|
||||
@ApiImplicitParam(name = "nDid", value = "nDid", required = true)
|
||||
public HttpResult<String> rebootDevice(@RequestParam("nDid") String nDid){
|
||||
String methodDescribe = getMethodDescribe("rebootDevice");
|
||||
askDeviceDataService.rebootDevice(nDid);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/createFolder")
|
||||
@ApiOperation("创建文件")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "nDid", value = "nDid", required = true),
|
||||
@ApiImplicitParam(name = "path", value = "文件路径", required = true)
|
||||
})
|
||||
public HttpResult<String> createFolder(@RequestParam("nDid") String nDid, @RequestParam("path") String path){
|
||||
String methodDescribe = getMethodDescribe("createFolder");
|
||||
askDeviceDataService.createFolder(nDid,path);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/deleteFolder")
|
||||
@ApiOperation("删除文件")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "nDid", value = "nDid", required = true),
|
||||
@ApiImplicitParam(name = "path", value = "文件路径", required = true)
|
||||
})
|
||||
public HttpResult<String> deleteFolder(@RequestParam("nDid") String nDid, @RequestParam("path") String path){
|
||||
String methodDescribe = getMethodDescribe("deleteFolder");
|
||||
askDeviceDataService.deleteFolder(nDid,path);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/askRealData")
|
||||
@ApiOperation("询问装置实时数据")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "nDid", value = "装置nDid"),
|
||||
@ApiImplicitParam(name = "idx", value = "数据集编号"),
|
||||
@ApiImplicitParam(name = "clDId", value = "逻辑子设备id")
|
||||
})
|
||||
public HttpResult<String> askRealData(@RequestParam("nDid") String nDid, @RequestParam("idx") Integer idx, @RequestParam("clDId") Integer clDId){
|
||||
String methodDescribe = getMethodDescribe("askRealData");
|
||||
askDeviceDataService.askRealData(nDid,idx,clDId);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public class CsDeviceController extends BaseController {
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/register")
|
||||
@ApiOperation("直连设备状态判断")
|
||||
@ApiOperation("直连设备注册")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "nDid", value = "设备识别码", required = true),
|
||||
@ApiImplicitParam(name = "type", value = "流程标识(2:功能调试 3:出厂调试 4:设备注册)", required = true)
|
||||
@@ -62,7 +62,7 @@ public class CsDeviceController extends BaseController {
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/access")
|
||||
@ApiOperation("直连设备注册")
|
||||
@ApiOperation("直连设备接入")
|
||||
@ApiImplicitParam(name = "devAccessParam", value = "接入参数", required = true)
|
||||
public HttpResult<String> devAccess(@RequestBody @Validated DevAccessParam devAccessParam){
|
||||
String methodDescribe = getMethodDescribe("devAccess");
|
||||
@@ -96,7 +96,7 @@ public class CsDeviceController extends BaseController {
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/wlRegister")
|
||||
@ApiOperation("便携式设备注册")
|
||||
@ApiOperation("便携式设备接入")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "nDid", value = "设备识别码", required = true)
|
||||
})
|
||||
@@ -109,7 +109,7 @@ public class CsDeviceController extends BaseController {
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/wlAccess")
|
||||
@ApiOperation("便携式设备接入")
|
||||
@ApiOperation("便携式设备手动接入")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "nDid", value = "设备识别码", required = true)
|
||||
})
|
||||
|
||||
@@ -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,22 +0,0 @@
|
||||
package com.njcn.access.controller;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 系统软件表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-08-09
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/csSoftInfo")
|
||||
public class CsSoftInfoController extends BaseController {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.njcn.access.controller;
|
||||
|
||||
import com.njcn.access.pojo.po.CsLineModel;
|
||||
import com.njcn.access.service.ICsTopicService;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
@@ -13,7 +12,10 @@ import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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,24 +15,27 @@ 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.CsSoftInfoPO;
|
||||
import com.njcn.access.pojo.po.CsTopic;
|
||||
import com.njcn.access.service.*;
|
||||
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.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.CsDataSet;
|
||||
import com.njcn.csdevice.pojo.po.CsDevCapacityPO;
|
||||
import com.njcn.csdevice.pojo.po.CsDevModelPO;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.csdevice.pojo.po.*;
|
||||
import com.njcn.device.biz.pojo.po.Overlimit;
|
||||
import com.njcn.device.biz.utils.COverlimitUtil;
|
||||
import com.njcn.mq.message.AppAutoDataMessage;
|
||||
import com.njcn.mq.message.AppEventMessage;
|
||||
import com.njcn.mq.message.AppFileMessage;
|
||||
@@ -41,7 +45,9 @@ import com.njcn.mq.template.AppFileMessageTemplate;
|
||||
import com.njcn.mq.template.AppFileStreamMessageTemplate;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
import com.njcn.rt.api.RtFeignClient;
|
||||
import com.njcn.zlevent.api.WaveFeignClient;
|
||||
import com.njcn.zlevent.pojo.dto.WaveTimeDto;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
@@ -53,13 +59,16 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.Validator;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeFormatterBuilder;
|
||||
import java.time.temporal.ChronoField;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
@@ -71,39 +80,27 @@ import java.util.stream.Collectors;
|
||||
public class MqttMessageHandler {
|
||||
|
||||
private final DevModelFeignClient devModelFeignClient;
|
||||
|
||||
private final ICsLineModelService csLineModelService;
|
||||
|
||||
private final ICsTopicService csTopicService;
|
||||
|
||||
private final MqttPublisher publisher;
|
||||
|
||||
private final RedisUtil redisUtil;
|
||||
|
||||
private final ICsEquipmentDeliveryService csEquipmentDeliveryService;
|
||||
|
||||
private final DataSetFeignClient dataSetFeignClient;
|
||||
|
||||
private final AppAutoDataMessageTemplate appAutoDataMessageTemplate;
|
||||
|
||||
private final AppEventMessageTemplate appEventMessageTemplate;
|
||||
|
||||
private final CsLogsFeignClient csLogsFeignClient;
|
||||
|
||||
private final AppFileMessageTemplate appFileMessageTemplate;
|
||||
|
||||
private final AppFileStreamMessageTemplate appFileStreamMessageTemplate;
|
||||
|
||||
private final ICsDeviceOnlineLogsService onlineLogsService;
|
||||
|
||||
private final ICsSoftInfoService csSoftInfoService;
|
||||
|
||||
private final CsSoftInfoFeignClient csSoftInfoFeignClient;
|
||||
private final CsLineFeignClient csLineFeignClient;
|
||||
|
||||
private final DevCapacityFeignClient devCapacityFeignClient;
|
||||
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
|
||||
private final OverlimitMapper overlimitMapper;
|
||||
private final ChannelObjectUtil channelObjectUtil;
|
||||
private final WaveFeignClient waveFeignClient;
|
||||
private final RtFeignClient rtFeignClient;
|
||||
private final CsCommunicateFeignClient csCommunicateFeignClient;
|
||||
@Autowired
|
||||
Validator validator;
|
||||
|
||||
@@ -113,11 +110,11 @@ public class MqttMessageHandler {
|
||||
//日志记录
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
try{
|
||||
logDto.setUserName(RequestUtil.getUsername());
|
||||
logDto.setLoginName(RequestUtil.getLoginName());
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
} catch (Exception e) {
|
||||
logDto.setUserName("设备主题录入");
|
||||
logDto.setLoginName(null);
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
}
|
||||
logDto.setOperate(nDid + "设备主题录入");
|
||||
logDto.setResult(1);
|
||||
@@ -171,15 +168,15 @@ 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{
|
||||
logDto.setUserName(RequestUtil.getUsername());
|
||||
logDto.setLoginName(RequestUtil.getLoginName());
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
} catch (Exception e) {
|
||||
logDto.setUserName("设备注册应答响应");
|
||||
logDto.setLoginName(null);
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
}
|
||||
logDto.setOperate("收到设备"+nDid+"注册应答响应");
|
||||
logDto.setResult(1);
|
||||
@@ -213,96 +210,7 @@ public class MqttMessageHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* 装置类型模板应答
|
||||
* 1.判断网关的类型
|
||||
* 2.直联设备的DevCfg和DevMod是以直联设备为准,上送平台端,平台端保存。通过校验DevMod模板信息来从平台端模板池中选取对应的模板,如果找不到匹配模板需告警提示人工干预处理。
|
||||
* 3.平台端需读取装置的DevMod来判断网关支持的设备模板(包含设备型号和模板版本),根据app提交的接入子设备DID匹配数据模板(型号及版本),生成DevCfg下发给网关,网关根据下发信息生成就地设备点表。
|
||||
* @param topic
|
||||
* @param message
|
||||
* @param nDid
|
||||
* @param payload
|
||||
*/
|
||||
@MqttSubscribe(value = "/Pfm/DevRsp/{version}/{edgeId}",qos = 1)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void devModelOperation(String topic, MqttMessage message, @NamedValue("version") String version, @NamedValue("edgeId") String nDid, @Payload String payload){
|
||||
log.info("收到当前设备所用模板响应--->" + nDid);
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
try{
|
||||
logDto.setUserName(RequestUtil.getUsername());
|
||||
logDto.setLoginName(RequestUtil.getLoginName());
|
||||
} catch (Exception e) {
|
||||
logDto.setUserName("系统重启或定时任务创建");
|
||||
logDto.setLoginName(null);
|
||||
}
|
||||
logDto.setOperate(nDid + "设备类型模板应答");
|
||||
logDto.setResult(1);
|
||||
//业务处理
|
||||
Gson gson = new Gson();
|
||||
ModelDto modelDto = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), ModelDto.class);
|
||||
if (Objects.equals(modelDto.getType(),Integer.parseInt(TypeEnum.TYPE_18.getCode()))){
|
||||
List<DevModInfoDto> list = modelDto.getMsg().getDevMod();
|
||||
List<DevCfgDto> list2 = modelDto.getMsg().getDevCfg();
|
||||
if (CollectionUtils.isEmpty(list)){
|
||||
log.error(AccessResponseEnum.MODEL_VERSION_ERROR.getMessage());
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.MODEL_VERSION_ERROR.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
//有异常删除缓存的模板信息
|
||||
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
||||
throw new BusinessException(AccessResponseEnum.MODEL_VERSION_ERROR);
|
||||
}
|
||||
//校验前置传递的装置模板库中是否存在
|
||||
List<CsModelDto> modelList = new ArrayList<>();
|
||||
list.forEach(item->{
|
||||
Integer did = null;
|
||||
for (DevCfgDto item2 : list2) {
|
||||
if (Objects.equals(item.getDevType(),item2.getDevType())){
|
||||
did = item2.getDid();
|
||||
}
|
||||
}
|
||||
CsModelDto csModelDto = new CsModelDto();
|
||||
CsDevModelPO po = devModelFeignClient.findModel(item.getDevType(),item.getVersionNo(),item.getVersionDate()).getData();
|
||||
if (Objects.isNull(po)){
|
||||
log.error(AccessResponseEnum.MODEL_NO_FIND.getMessage());
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.MODEL_NO_FIND.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
//有异常删除缓存的模板信息
|
||||
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
||||
throw new BusinessException(AccessResponseEnum.MODEL_NO_FIND);
|
||||
}
|
||||
if (Objects.equals(po.getType(),0)){
|
||||
List<CsDataSet> dataSetList = dataSetFeignClient.getModuleDataSet(po.getId()).getData();
|
||||
if (CollectionUtils.isEmpty(dataSetList)){
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.MODULE_NUMBER_IS_NULL.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
//有异常删除缓存的模板信息
|
||||
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
||||
throw new BusinessException(AccessResponseEnum.MODULE_NUMBER_IS_NULL);
|
||||
}
|
||||
csModelDto.setModuleNumber(dataSetList.size());
|
||||
}
|
||||
csModelDto.setDevType(po.getDevTypeName());
|
||||
csModelDto.setModelId(po.getId());
|
||||
csModelDto.setDid(did);
|
||||
csModelDto.setType(po.getType());
|
||||
modelList.add(csModelDto);
|
||||
});
|
||||
//存储模板id
|
||||
String key2 = AppRedisKey.MODEL + nDid;
|
||||
redisUtil.saveByKeyWithExpire(key2,modelList,600L);
|
||||
//存储监测点模板信息,用于界面回显
|
||||
List<String> modelId = modelList.stream().map(CsModelDto::getModelId).collect(Collectors.toList());
|
||||
List<CsLineModel> lineList = csLineModelService.getMonitorNumByModelId(modelId);
|
||||
String key = AppRedisKey.LINE + nDid;
|
||||
redisUtil.saveByKeyWithExpire(key,lineList,600L);
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备接入平台应答
|
||||
* 设备响应
|
||||
* @param topic
|
||||
* @param message
|
||||
* @param version
|
||||
@@ -315,47 +223,116 @@ public class MqttMessageHandler {
|
||||
//日志实体
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
try{
|
||||
logDto.setUserName(RequestUtil.getUsername());
|
||||
logDto.setLoginName(RequestUtil.getLoginName());
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
} catch (Exception e) {
|
||||
logDto.setUserName("系统重启或定时任务创建");
|
||||
logDto.setLoginName(null);
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
}
|
||||
logDto.setResult(1);
|
||||
//业务处理
|
||||
Gson gson = new Gson();
|
||||
ReqAndResDto.Res res = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), ReqAndResDto.Res.class);
|
||||
redisUtil.saveByKeyWithExpire("devResponse",res.getCode(),5L);
|
||||
if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){
|
||||
switch (res.getType()){
|
||||
/**
|
||||
* 装置类型模板应答
|
||||
* 1.判断网关的类型
|
||||
* 2.直联设备的DevCfg和DevMod是以直联设备为准,上送平台端,平台端保存。通过校验DevMod模板信息来从平台端模板池中选取对应的模板,如果找不到匹配模板需告警提示人工干预处理。
|
||||
* 3.平台端需读取装置的DevMod来判断网关支持的设备模板(包含设备型号和模板版本),根据app提交的接入子设备DID匹配数据模板(型号及版本),生成DevCfg下发给网关,网关根据下发信息生成就地设备点表。
|
||||
*/
|
||||
case 4611:
|
||||
log.info("{},装置模板应答,应答code {}",nDid,res.getCode());
|
||||
ModelDto modelDto = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), ModelDto.class);
|
||||
List<DevModInfoDto> list = modelDto.getMsg().getDevMod();
|
||||
List<DevCfgDto> list2 = modelDto.getMsg().getDevCfg();
|
||||
if (CollectionUtils.isEmpty(list)){
|
||||
log.error(AccessResponseEnum.MODEL_VERSION_ERROR.getMessage());
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.MODEL_VERSION_ERROR.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
//有异常删除缓存的模板信息
|
||||
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
||||
throw new BusinessException(AccessResponseEnum.MODEL_VERSION_ERROR);
|
||||
}
|
||||
//校验前置传递的装置模板库中是否存在
|
||||
List<CsModelDto> modelList = new ArrayList<>();
|
||||
list.forEach(item->{
|
||||
Integer did = null;
|
||||
for (DevCfgDto item2 : list2) {
|
||||
if (Objects.equals(item.getDevType(),item2.getDevType())){
|
||||
did = item2.getDid();
|
||||
}
|
||||
}
|
||||
CsModelDto csModelDto = new CsModelDto();
|
||||
CsDevModelPO po = devModelFeignClient.findModel(item.getDevType(),item.getVersionNo(),item.getVersionDate()).getData();
|
||||
if (Objects.isNull(po)){
|
||||
log.error(AccessResponseEnum.MODEL_NO_FIND.getMessage());
|
||||
logDto.setOperate(nDid + "模板缺失");
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.MODEL_NO_FIND.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
//有异常删除缓存的模板信息
|
||||
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
||||
throw new BusinessException(AccessResponseEnum.MODEL_NO_FIND);
|
||||
}
|
||||
if (Objects.equals(po.getType(),0)){
|
||||
List<CsDataSet> dataSetList = dataSetFeignClient.getModuleDataSet(po.getId()).getData();
|
||||
if (CollectionUtils.isEmpty(dataSetList)){
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.MODULE_NUMBER_IS_NULL.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
//有异常删除缓存的模板信息
|
||||
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
||||
throw new BusinessException(AccessResponseEnum.MODULE_NUMBER_IS_NULL);
|
||||
}
|
||||
csModelDto.setModuleNumber(dataSetList.size());
|
||||
}
|
||||
csModelDto.setDevType(po.getDevTypeName());
|
||||
csModelDto.setModelId(po.getId());
|
||||
csModelDto.setDid(did);
|
||||
csModelDto.setType(po.getType());
|
||||
modelList.add(csModelDto);
|
||||
});
|
||||
//存储模板id
|
||||
String key2 = AppRedisKey.MODEL + nDid;
|
||||
redisUtil.saveByKeyWithExpire(key2,modelList,600L);
|
||||
//存储监测点模板信息,用于界面回显
|
||||
List<String> modelId = modelList.stream().map(CsModelDto::getModelId).collect(Collectors.toList());
|
||||
List<CsLineModel> lineList = csLineModelService.getMonitorNumByModelId(modelId);
|
||||
String key = AppRedisKey.LINE + nDid;
|
||||
redisUtil.saveByKeyWithExpire(key,lineList,600L);
|
||||
break;
|
||||
case 4613:
|
||||
logDto.setOperate(nDid + "设备接入");
|
||||
log.info("{}收到接入应答响应,应答code {}",nDid,res.getCode());
|
||||
log.info("{},收到接入应答响应,应答code {}",nDid,res.getCode());
|
||||
if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){
|
||||
int mid = 1;
|
||||
//修改装置状态
|
||||
csEquipmentDeliveryService.updateStatusBynDid(nDid,AccessEnum.ACCESS.getCode());
|
||||
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);
|
||||
}
|
||||
}
|
||||
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));
|
||||
//接入后系统重置装置心跳
|
||||
redisUtil.saveByKeyWithExpire("MQTT:" + nDid, Instant.now().toEpochMilli(),180L);
|
||||
//修改redis的mid
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,1);
|
||||
//接入成功标识
|
||||
redisUtil.saveByKeyWithExpire("online" + nDid,"online",10L);
|
||||
//录波任务倒计时
|
||||
redisUtil.saveByKeyWithExpire("startFile:" + nDid,null,60L);
|
||||
} else {
|
||||
log.info(AccessResponseEnum.ACCESS_RESPONSE_ERROR.getMessage());
|
||||
logDto.setResult(0);
|
||||
@@ -363,91 +340,134 @@ public class MqttMessageHandler {
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AccessResponseEnum.ACCESS_RESPONSE_ERROR);
|
||||
}
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
break;
|
||||
case 4614:
|
||||
log.info("设备数据应答--->" + nDid);
|
||||
RspDataDto rspDataDto = JSON.parseObject(JSON.toJSONString(res.getMsg()), RspDataDto.class);
|
||||
switch (rspDataDto.getDataType()){
|
||||
case 1:
|
||||
logDto.setOperate(nDid + "更新设备软件信息");
|
||||
RspDataDto.SoftInfo softInfo = JSON.parseObject(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.SoftInfo.class);
|
||||
//记录设备软件信息
|
||||
CsSoftInfoPO csSoftInfoPo = new CsSoftInfoPO();
|
||||
BeanUtils.copyProperties(softInfo,csSoftInfoPo);
|
||||
try {
|
||||
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);
|
||||
//记录设备软件信息
|
||||
CsSoftInfoPO csSoftInfoPo = new CsSoftInfoPO();
|
||||
BeanUtils.copyProperties(softInfo,csSoftInfoPo);
|
||||
String id = IdUtil.fastSimpleUUID();
|
||||
csSoftInfoPo.setId(id);
|
||||
csSoftInfoPo.setAppDate(new SimpleDateFormat("yyyy-MM-dd").parse(softInfo.getAppDate()));
|
||||
csSoftInfoService.save(csSoftInfoPo);
|
||||
DateTimeFormatter formatter = new DateTimeFormatterBuilder()
|
||||
.appendPattern("yyyy-MM-dd[[HH][:mm][:ss]]")
|
||||
.parseDefaulting(ChronoField.HOUR_OF_DAY, 0)
|
||||
.parseDefaulting(ChronoField.MINUTE_OF_HOUR, 0)
|
||||
.parseDefaulting(ChronoField.SECOND_OF_MINUTE, 0)
|
||||
.parseDefaulting(ChronoField.MILLI_OF_SECOND, 0)
|
||||
.toFormatter();
|
||||
LocalDateTime localDateTime = LocalDateTime.parse(softInfo.getAppDate(), formatter);
|
||||
assertThat(localDateTime).isNotNull();
|
||||
csSoftInfoPo.setAppDate(localDateTime);
|
||||
csSoftInfoFeignClient.saveSoftInfo(csSoftInfoPo);
|
||||
//更新设备软件id 先看是否存在软件信息,删除 然后在录入
|
||||
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(nDid).getData();
|
||||
String soft = po.getSoftinfoId();
|
||||
if (StringUtil.isNotBlank(soft)){
|
||||
csSoftInfoService.removeById(soft);
|
||||
csSoftInfoFeignClient.removeSoftInfo(soft);
|
||||
}
|
||||
equipmentFeignClient.updateSoftInfo(nDid,csSoftInfoPo.getId());
|
||||
//询问设备容量信息
|
||||
//askDevData(nDid,version,2,(res.getMid()+1));
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
List<RspDataDto.LdevInfo> devInfo = JSON.parseArray(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.LdevInfo.class);
|
||||
if (CollectionUtil.isNotEmpty(devInfo)){
|
||||
if (Objects.equals(res.getDid(),1)){
|
||||
logDto.setOperate(nDid + "更新治理监测点信息和设备容量");
|
||||
List<CsDevCapacityPO> list = new ArrayList<>();
|
||||
devInfo.forEach(item->{
|
||||
//1.更新治理监测点信息
|
||||
if (Objects.equals(item.getClDid(),0)){
|
||||
break;
|
||||
case 2:
|
||||
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();
|
||||
csLineParam.setLineId(nDid.concat("0"));
|
||||
if (Objects.equals(item.getClDid(),0)){
|
||||
csLineParam.setLineId(nDid.concat("0"));
|
||||
//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);
|
||||
});
|
||||
if (CollectionUtil.isNotEmpty(list3)) {
|
||||
devCapacityFeignClient.addList(list3);
|
||||
//3.更新设备模块个数
|
||||
equipmentFeignClient.updateModuleNumber(nDid,(devInfo.size()-1));
|
||||
}
|
||||
//2.录入各个模块设备容量
|
||||
CsDevCapacityPO csDevCapacity = new CsDevCapacityPO();
|
||||
csDevCapacity.setLineId(nDid.concat("0"));
|
||||
csDevCapacity.setCldid(item.getClDid());
|
||||
csDevCapacity.setCapacity(item.getCapacityA());
|
||||
list.add(csDevCapacity);
|
||||
});
|
||||
devCapacityFeignClient.addList(list);
|
||||
//3.更新设备模块个数
|
||||
equipmentFeignClient.updateModuleNumber(nDid,(devInfo.size()-1));
|
||||
//4.询问监测点pt/ct信息
|
||||
//askDevData(nDid,version,3,(res.getMid()+1));
|
||||
} else if (Objects.equals(res.getDid(),2)) {
|
||||
logDto.setOperate(nDid + "更新电网侧、负载侧监测点信息");
|
||||
//1.更新电网侧、负载侧监测点相关信息
|
||||
devInfo.forEach(item->{
|
||||
CsLineParam csLineParam = new CsLineParam();
|
||||
csLineParam.setLineId(nDid.concat(item.getClDid().toString()));
|
||||
csLineParam.setVolGrade(item.getVolGrade());
|
||||
csLineParam.setPtRatio(item.getPtRatio());
|
||||
csLineParam.setCtRatio(item.getCtRatio());
|
||||
csLineParam.setConType(item.getConType());
|
||||
csLineFeignClient.updateLine(csLineParam);
|
||||
});
|
||||
} 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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
break;
|
||||
case 15:
|
||||
log.info("{}模块{}:处理实时数据", nDid, rspDataDto.getClDid());
|
||||
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);
|
||||
String key3 = AppRedisKey.PROJECT_INFO + nDid + rspDataDto.getClDid();
|
||||
redisUtil.saveByKeyWithExpire(key3,projectInfoList,60L);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 4663:
|
||||
log.info("装置操作应答");
|
||||
if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){
|
||||
String key4 = AppRedisKey.CONTROL + nDid;
|
||||
redisUtil.saveByKeyWithExpire(key4,"success",10L);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
String result = getEnum(res.getCode());
|
||||
log.info(result);
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(result);
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 装置心跳 && 主动数据上送
|
||||
* fixme 这边由于接收文件数据时间跨度会很长,途中有其他请求进来会中断之前的程序,目前是记录中断的位置,等处理完成再继续请求接收文件
|
||||
@@ -505,14 +525,15 @@ 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));
|
||||
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 + "事件报文为:" + new String(message.getPayload(), StandardCharsets.UTF_8));
|
||||
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);
|
||||
@@ -521,17 +542,21 @@ public class MqttMessageHandler {
|
||||
break;
|
||||
//实时数据
|
||||
case 1:
|
||||
log.info(nDid + "处理实时数据");
|
||||
break;
|
||||
//处理主动上送的统计数据
|
||||
case 2:
|
||||
log.info("{}处理实时数据", nDid);
|
||||
JSONObject jsonObject2 = JSONObject.parseObject(JSON.toJSONString(dataDto));
|
||||
AppAutoDataMessage appAutoDataMessage = JSONObject.toJavaObject(jsonObject2, AppAutoDataMessage.class);
|
||||
appAutoDataMessage.setId(nDid);
|
||||
appAutoDataMessage.getMsg().getDataArray().forEach(item->{
|
||||
log.info(nDid + "处理统计数据" + item.getDataAttr());
|
||||
rtFeignClient.analysis(appAutoDataMessage);
|
||||
break;
|
||||
//处理主动上送的统计数据
|
||||
case 2:
|
||||
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(appAutoDataMessage);
|
||||
appAutoDataMessageTemplate.sendMember(appAutoDataMessage2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -562,12 +587,43 @@ public class MqttMessageHandler {
|
||||
//响应请求
|
||||
switch (fileDto.getType()){
|
||||
case 4657:
|
||||
log.info("获取文件信息");
|
||||
log.info("文件信息响应:" + fileDto);
|
||||
appFileMessageTemplate.sendMember(appFileMessage);
|
||||
log.info("获取文件信息{}", fileDto);
|
||||
if (Objects.equals(fileDto.getCode(),AccessEnum.SUCCESS.getCode())) {
|
||||
String key = AppRedisKey.PROJECT_INFO + nDid;
|
||||
if (Objects.isNull(fileDto.getMsg().getType())) {
|
||||
handleDefaultCase(fileDto, nDid);
|
||||
} else {
|
||||
if (Objects.equals("dir", fileDto.getMsg().getType())) {
|
||||
saveDirectoryInfo(fileDto.getMsg().getDirInfo(), key);
|
||||
} else if (Objects.equals("file", fileDto.getMsg().getType())){
|
||||
saveFileInfo(fileDto.getMsg().getFileInfo(), key);
|
||||
appFileMessageTemplate.sendMember(appFileMessage);
|
||||
}
|
||||
}
|
||||
} else if (Objects.equals(fileDto.getCode(),AccessEnum.NOT_FIND.getCode())) {
|
||||
Object object = redisUtil.getObjectByKey("fileMid:" + nDid);
|
||||
if (Objects.nonNull(object)) {
|
||||
String data = redisUtil.getObjectByKey("fileMid:" + nDid).toString();
|
||||
String [] arr = data.split("concat");
|
||||
Integer mid = Integer.parseInt(arr[0]);
|
||||
String fileName = arr[1];
|
||||
if (Objects.equals(mid,fileDto.getMid())) {
|
||||
List<WaveTimeDto> list = channelObjectUtil.objectToList( redisUtil.getObjectByKey("eventFile:" + nDid),WaveTimeDto.class);
|
||||
list.removeIf(item -> item.getFileName().equals(fileName));
|
||||
redisUtil.saveByKey("eventFile:" + nDid, list);
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
redisUtil.delete("handleEvent:" + nDid);
|
||||
waveFeignClient.channelWave(nDid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 4658:
|
||||
log.info("获取文件流信息");
|
||||
FileRedisDto dto = new FileRedisDto();
|
||||
dto.setCode(fileDto.getCode());
|
||||
redisUtil.saveByKeyWithExpire(AppRedisKey.DOWNLOAD + fileDto.getMsg().getName() + fileDto.getMid(),dto,60L);
|
||||
if (Objects.equals(fileDto.getCode(),AccessEnum.SUCCESS.getCode())){
|
||||
appFileStreamMessageTemplate.sendMember(appFileMessage);
|
||||
}
|
||||
@@ -576,17 +632,70 @@ public class MqttMessageHandler {
|
||||
log.info("需要缓存请求的文件信息");
|
||||
}
|
||||
break;
|
||||
case 4659:
|
||||
log.info("装置收到系统上传的文件");
|
||||
FileRedisDto fileRedisDto = new FileRedisDto();
|
||||
fileRedisDto.setCode(fileDto.getCode());
|
||||
redisUtil.saveByKeyWithExpire("uploadFileStep",fileRedisDto,10L);
|
||||
break;
|
||||
case 4659:
|
||||
log.info("装置收到系统上传的文件");
|
||||
FileRedisDto fileRedisDto = new FileRedisDto();
|
||||
fileRedisDto.setCode(fileDto.getCode());
|
||||
redisUtil.saveByKeyWithExpire(AppRedisKey.UPLOAD.concat(nDid).concat(String.valueOf(fileDto.getMid())),fileRedisDto,10L);
|
||||
redisUtil.saveByKeyWithExpire("uploading","uploading",20L);
|
||||
break;
|
||||
case 4660:
|
||||
log.info("设备目录/文件删除应答");
|
||||
redisUtil.saveByKeyWithExpire( "deleteDir"+ nDid,fileDto.getCode(),10L);
|
||||
break;
|
||||
case 4661:
|
||||
log.info("设备目录创建应答");
|
||||
redisUtil.saveByKeyWithExpire( "createDir"+ nDid,fileDto.getCode(),10L);
|
||||
break;
|
||||
case 4662:
|
||||
log.info("装置根目录应答");
|
||||
redisUtil.saveByKeyWithExpire(AppRedisKey.DEVICE_ROOT_PATH + nDid,fileDto.getMsg().getName(),10L);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 装置异常事件记录
|
||||
* @param topic
|
||||
* @param message
|
||||
* @param version
|
||||
* @param nDid
|
||||
* @param payload
|
||||
*/
|
||||
@MqttSubscribe(value = "/Dev/Error/{edgeId}",qos = 1)
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void devErrorInfo(String topic, MqttMessage message, @NamedValue("version") String version, @NamedValue("edgeId") String nDid, @Payload String payload) {
|
||||
//解析数据
|
||||
Gson gson = new Gson();
|
||||
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);
|
||||
appEventMessage.setId(nDid);
|
||||
appEventMessageTemplate.sendMember(appEventMessage);
|
||||
}
|
||||
|
||||
private void saveDirectoryInfo(List<FileDto.DirInfo> dirInfo, String key) {
|
||||
if (!CollectionUtil.isEmpty(dirInfo)) {
|
||||
redisUtil.saveByKeyWithExpire(key, dirInfo, 60L);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveFileInfo(FileDto.FileInfo fileInfo, String key) {
|
||||
if (!Objects.isNull(fileInfo)) {
|
||||
redisUtil.saveByKeyWithExpire(key, fileInfo, 60L);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleDefaultCase(FileDto fileDto, String nDid) {
|
||||
List<FileDto.DirInfo> list = fileDto.getMsg().getDirInfo();
|
||||
String keyDir = AppRedisKey.PROJECT_INFO + nDid;
|
||||
saveDirectoryInfo(list, keyDir);
|
||||
|
||||
FileDto.FileInfo fileInfo = fileDto.getMsg().getFileInfo();
|
||||
String keyFile = AppRedisKey.FILE_INFO + nDid;
|
||||
saveFileInfo(fileInfo, keyFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* type含义
|
||||
@@ -607,7 +716,7 @@ public class MqttMessageHandler {
|
||||
askDataDto.setEndTime(-1);
|
||||
switch (type) {
|
||||
case 1:
|
||||
reqAndResParam.setDid(2);
|
||||
reqAndResParam.setDid(0);
|
||||
askDataDto.setCldid(0);
|
||||
askDataDto.setDataType(1);
|
||||
break;
|
||||
@@ -631,9 +740,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,12 +1,29 @@
|
||||
package com.njcn.access.listener;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
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.enums.AccessEnum;
|
||||
import com.njcn.access.pojo.dto.NoticeUserDto;
|
||||
import com.njcn.access.pojo.po.CsDeviceOnlineLogs;
|
||||
import com.njcn.access.service.ICsDeviceOnlineLogsService;
|
||||
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.CsLogsFeignClient;
|
||||
import com.njcn.csdevice.api.*;
|
||||
import com.njcn.csdevice.pojo.dto.DevDetailDTO;
|
||||
import com.njcn.csdevice.pojo.dto.PqsCommunicateDto;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.rt.pojo.dto.BaseRealDataSet;
|
||||
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.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.redis.connection.Message;
|
||||
@@ -15,11 +32,15 @@ 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.Executors;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
@@ -30,29 +51,45 @@ import java.util.concurrent.TimeUnit;
|
||||
@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 CsCommunicateFeignClient csCommunicateFeignClient;
|
||||
@Resource
|
||||
private MqttPublisher publisher;
|
||||
@Resource
|
||||
private RedisSetUtil redisSetUtil;
|
||||
|
||||
private final Object lock = new Object();
|
||||
|
||||
public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
|
||||
super(listenerContainer);
|
||||
}
|
||||
|
||||
// 最大尝试次数
|
||||
private static final int MAX_ATTEMPTS = 4;
|
||||
// 当前尝试次数
|
||||
private static int attemptCount = 1;
|
||||
//最大告警次数
|
||||
private static int MAX_WARNING_TIMES = 0;
|
||||
|
||||
/**
|
||||
* 针对redis数据失效事件,进行数据处理
|
||||
@@ -67,73 +104,177 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
String expiredKey = message.toString();
|
||||
if(expiredKey.startsWith("MQTT:")){
|
||||
String nDid = expiredKey.split(":")[1];
|
||||
String version = csTopicService.getVersion(nDid);
|
||||
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
executeMainTask(scheduler,nDid,version);
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
//云前置设备心跳丢失处理
|
||||
// if(expiredKey.startsWith(RedisKeyEnum.CLD_HEART_BEAT_KEY.getKey())){
|
||||
// String node = expiredKey.split(":")[1];
|
||||
// String nodeId = node.substring(0, node.length() - 1);
|
||||
// int processNo = Integer.parseInt(node.substring(node.length() - 1));
|
||||
// equipmentFeignClient.updateCldDevStatus(nodeId,processNo);
|
||||
// }
|
||||
}
|
||||
|
||||
//主任务
|
||||
private void executeMainTask(ScheduledExecutorService scheduler, String nDid, String version) {
|
||||
System.out.println("正在执行主任务...");
|
||||
//1.装置心跳断连
|
||||
//2.MQTT客户端不在线
|
||||
private void executeMainTask(String nDid) {
|
||||
log.info("{}->装置离线", nDid);
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName("装置失去心跳触发");
|
||||
logDto.setOperate(nDid + "重连");
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
//装置下线
|
||||
csEquipmentDeliveryService.updateRunStatusBynDid(nDid, AccessEnum.OFFLINE.getCode());
|
||||
//装置没有心跳,则立马发起接入请求
|
||||
csDeviceService.devAccessAskTemplate(nDid,version,1);
|
||||
Integer status = csEquipmentDeliveryService.queryEquipmentBynDid(nDid).getRunStatus();
|
||||
if (Objects.equals(status,AccessEnum.ONLINE.getCode())){
|
||||
logDto.setResult(1);
|
||||
scheduler.shutdown();
|
||||
} else {
|
||||
logDto.setResult(0);
|
||||
startScheduledTask(scheduler,nDid,version);
|
||||
}
|
||||
//装置调整为注册状态
|
||||
csEquipmentDeliveryService.updateStatusBynDid(nDid,AccessEnum.REGISTERED.getCode());
|
||||
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);
|
||||
}
|
||||
|
||||
//启动第一次定时任务
|
||||
private void startScheduledTask(ScheduledExecutorService scheduler, String nDid, String version) {
|
||||
ScheduledFuture<?> future = scheduler.scheduleAtFixedRate(() -> {
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setOperate(nDid + "第一阶段重连定时任务");
|
||||
if (attemptCount < MAX_ATTEMPTS) {
|
||||
System.out.println(nDid + "执行第一阶段重连定时任务,第 " + attemptCount + " 次尝试...");
|
||||
attemptCount++;
|
||||
csDeviceService.devAccessAskTemplate(nDid,version,attemptCount);
|
||||
int status = csEquipmentDeliveryService.queryEquipmentBynDid(nDid).getRunStatus();
|
||||
if (Objects.equals(status,AccessEnum.ONLINE.getCode())){
|
||||
logDto.setResult(1);
|
||||
scheduler.shutdown();
|
||||
}
|
||||
} else {
|
||||
scheduler.shutdown();
|
||||
attemptCount++;
|
||||
logDto.setResult(0);
|
||||
startSecondScheduledTask(nDid,version);
|
||||
synchronized (lock) {
|
||||
//判断是否推送消息
|
||||
boolean devModel = equipmentFeignClient.judgeDevModel(nDid).getData();
|
||||
if (devModel) {
|
||||
NoticeUserDto dto = sendOffLine(nDid);
|
||||
sendMessageUtil.sendEventToUser(dto);
|
||||
addLogs(dto);
|
||||
}
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
}, 0, 1, TimeUnit.MINUTES);
|
||||
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 startSecondScheduledTask(String nDid, String version) {
|
||||
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
ScheduledFuture<?> future = scheduler.scheduleAtFixedRate(() -> {
|
||||
System.out.println(nDid + "执行第二阶段重连定时任务...");
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setOperate(nDid + "第二阶段重连定时任务");
|
||||
csDeviceService.devAccessAskTemplate(nDid,version,attemptCount++);
|
||||
int status = csEquipmentDeliveryService.queryEquipmentBynDid(nDid).getRunStatus();
|
||||
if (Objects.equals(status,AccessEnum.ONLINE.getCode())) {
|
||||
logDto.setResult(1);
|
||||
scheduler.shutdown();
|
||||
} else {
|
||||
logDto.setResult(0);
|
||||
}
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
}, 0, 10, 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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,16 +0,0 @@
|
||||
package com.njcn.access.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.njcn.access.pojo.po.CsSoftInfoPO;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 系统软件表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-08-09
|
||||
*/
|
||||
public interface CsSoftInfoMapper extends BaseMapper<CsSoftInfoPO> {
|
||||
|
||||
}
|
||||
@@ -0,0 +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> {
|
||||
|
||||
}
|
||||
@@ -1,47 +1,114 @@
|
||||
//package com.njcn.access.runner;
|
||||
//
|
||||
//import com.njcn.access.service.ICsEquipmentDeliveryService;
|
||||
//import com.njcn.access.service.ICsTopicService;
|
||||
//import com.njcn.access.service.impl.CsDeviceServiceImpl;
|
||||
//import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.boot.ApplicationArguments;
|
||||
//import org.springframework.boot.ApplicationRunner;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import javax.annotation.Resource;
|
||||
//import java.util.List;
|
||||
//import java.util.Objects;
|
||||
//
|
||||
///**
|
||||
// * 类的介绍:用来重新发起设备的接入,存在程序意外停止了,缓存失效导致无法更新装置的状态,所以需要在程序启动时发起设备的接入
|
||||
// *
|
||||
// * @author xuyang
|
||||
// * @version 1.0.0
|
||||
// * @createTime 2023/8/28 13:57
|
||||
// */
|
||||
//@Component
|
||||
//@Slf4j
|
||||
//public class AccessApplicationRunner implements ApplicationRunner {
|
||||
//
|
||||
// @Resource
|
||||
// private CsDeviceServiceImpl csDeviceService;
|
||||
//
|
||||
// @Resource
|
||||
// private ICsTopicService csTopicService;
|
||||
//
|
||||
// @Resource
|
||||
// private ICsEquipmentDeliveryService csEquipmentDeliveryService;
|
||||
//
|
||||
// @Override
|
||||
// public void run(ApplicationArguments args){
|
||||
// List<CsEquipmentDeliveryPO> list = csEquipmentDeliveryService.getAll();
|
||||
// list.forEach(item->{
|
||||
// String version = csTopicService.getVersion(item.getNdid());
|
||||
// if (!Objects.isNull(version)){
|
||||
// csDeviceService.devAccess(item.getNdid(),version,1);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
//}
|
||||
package com.njcn.access.runner;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.njcn.access.service.ICsEquipmentDeliveryService;
|
||||
import com.njcn.access.service.ICsTopicService;
|
||||
import com.njcn.access.service.impl.CsDeviceServiceImpl;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
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 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 xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/8/28 13:57
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class AccessApplicationRunner implements ApplicationRunner {
|
||||
|
||||
private final RedisUtil redisUtil;
|
||||
private final ICsEquipmentDeliveryService csEquipmentDeliveryService;
|
||||
private final ICsTopicService csTopicService;
|
||||
private final CsDeviceServiceImpl csDeviceService;
|
||||
private final DictTreeFeignClient dictTreeFeignClient;
|
||||
|
||||
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
private static final long ACCESS_TIME = 60L;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
//项目启动60s后发起自动接入
|
||||
Runnable task = () -> {
|
||||
log.info("系统重启,所有符合条件的装置发起接入!");
|
||||
List<CsEquipmentDeliveryPO> list = csEquipmentDeliveryService.getOnlineDev();
|
||||
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();
|
||||
}
|
||||
};
|
||||
scheduler.schedule(task,ACCESS_TIME,TimeUnit.SECONDS);
|
||||
scheduler.shutdown();
|
||||
}
|
||||
|
||||
public void accessDev(List<CsEquipmentDeliveryPO> list) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
//package com.njcn.access.runner;
|
||||
//
|
||||
//import cn.hutool.core.collection.CollUtil;
|
||||
//import cn.hutool.core.collection.CollectionUtil;
|
||||
//import com.njcn.access.service.ICsEquipmentDeliveryService;
|
||||
//import com.njcn.access.service.ICsTopicService;
|
||||
//import com.njcn.access.service.impl.CsDeviceServiceImpl;
|
||||
//import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.scheduling.annotation.Scheduled;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import javax.annotation.Resource;
|
||||
//import java.util.List;
|
||||
//import java.util.Objects;
|
||||
//
|
||||
///**
|
||||
// * 类的介绍:防止设备掉线 系统未能调整,做一个定时任务,每天凌晨将所有设备重新接入
|
||||
// *
|
||||
// * @author xuyang
|
||||
// * @version 1.0.0
|
||||
// * @createTime 2023/8/28 14:21
|
||||
// */
|
||||
//@Component
|
||||
//@Slf4j
|
||||
//public class AccessScheduledTask {
|
||||
//
|
||||
// @Resource
|
||||
// private CsDeviceServiceImpl csDeviceService;
|
||||
//
|
||||
// @Resource
|
||||
// private ICsTopicService csTopicService;
|
||||
//
|
||||
// @Resource
|
||||
// private ICsEquipmentDeliveryService csEquipmentDeliveryService;
|
||||
//
|
||||
// /**
|
||||
// * {秒数} {分钟} {小时} {日期} {月份} {星期} {年份(可为空)}
|
||||
// */
|
||||
// @Scheduled(cron = "0 0 0 * * ?")
|
||||
// public void executeTask() {
|
||||
// log.info("每日凌晨定时任务执行");
|
||||
// List<CsEquipmentDeliveryPO> list = csEquipmentDeliveryService.getAll();
|
||||
// if (CollUtil.isNotEmpty(list)) {
|
||||
// for (int i = 0; i < list.size(); i++) {
|
||||
// String version = csTopicService.getVersion(list.get(i).getNdid());
|
||||
// if (!Objects.isNull(version)){
|
||||
// csDeviceService.devAccess(list.get(i).getNdid(),version,i);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,234 @@
|
||||
package com.njcn.access.runner;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.njcn.access.service.ICsEquipmentDeliveryService;
|
||||
import com.njcn.access.service.ICsTopicService;
|
||||
import com.njcn.access.service.impl.CsDeviceServiceImpl;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
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 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 AutoAccessTimer implements ApplicationRunner {
|
||||
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
private static final long AUTO_TIME = 120L;
|
||||
private final RedisUtil redisUtil;
|
||||
private final ICsEquipmentDeliveryService csEquipmentDeliveryService;
|
||||
private final ICsTopicService csTopicService;
|
||||
private final CsDeviceServiceImpl csDeviceService;
|
||||
private final DictTreeFeignClient dictTreeFeignClient;
|
||||
|
||||
@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, AUTO_TIME, AUTO_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("轮询定时任务执行中!");
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @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 = CollUtil.split(list, 10);
|
||||
// // 创建一个ExecutorService来处理这些任务
|
||||
// List<Future<Void>> futures = new ArrayList<>();
|
||||
// for (List<CsEquipmentDeliveryPO> subList : subLists) {
|
||||
// futures.add(executor.submit(() -> {
|
||||
// try {
|
||||
// accessDev(subList);
|
||||
// } catch (Exception e) {
|
||||
// log.error("处理设备子列表异常,但继续处理其他任务", e);
|
||||
// }
|
||||
// return null;
|
||||
// }));
|
||||
// }
|
||||
// // 等待所有任务完成
|
||||
// for (Future<Void> future : futures) {
|
||||
// try {
|
||||
// future.get();
|
||||
// } catch (InterruptedException e) {
|
||||
// Thread.currentThread().interrupt();
|
||||
// log.error("任务被中断", e);
|
||||
// } catch (ExecutionException e) {
|
||||
// log.error("任务执行异常", e.getCause());
|
||||
// } catch (Exception e) {
|
||||
// log.error("系统异常", e.getCause());
|
||||
// }
|
||||
// }
|
||||
// // 关闭ExecutorService
|
||||
// executor.shutdown();
|
||||
// }
|
||||
// };
|
||||
// //第一次执行的时间为120s,然后在前一个任务执行完毕后,等待120s再执行下一个任务
|
||||
// scheduler.scheduleWithFixedDelay(task, AUTO_TIME, AUTO_TIME, TimeUnit.SECONDS);
|
||||
// }
|
||||
//
|
||||
// public void accessDev(List<CsEquipmentDeliveryPO> list) {
|
||||
// if (CollUtil.isNotEmpty(list)) {
|
||||
// try {
|
||||
// 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.autoAccess(item.getNdid(), version, 1);
|
||||
// }
|
||||
// redisUtil.saveByKey(AppRedisKey.DEVICE_MID + item.getNdid(), 1);
|
||||
// });
|
||||
// } catch (Exception e) {
|
||||
// log.error(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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.njcn.access.service;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
public interface AskDeviceDataService {
|
||||
|
||||
void askDeviceRootPath(String nDid);
|
||||
|
||||
void askDeviceFileOrDir(String nDid, String name);
|
||||
|
||||
boolean downloadFile(String nDid, String name, Integer size, String fileCheck);
|
||||
|
||||
void rebootDevice(String nDid);
|
||||
|
||||
void createFolder(String nDid, String path);
|
||||
|
||||
void deleteFolder(String nDid, String path);
|
||||
|
||||
/**
|
||||
* 实时数据请求报文
|
||||
*/
|
||||
void askRealData(String nDid, Integer idx, Integer size);
|
||||
|
||||
void askCldRealData(String devId, String lineId, String nodeId, Integer idx);
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public interface ICsDeviceService {
|
||||
Object getModel(String nDid);
|
||||
|
||||
/**
|
||||
* MQTT连接成功,获取装置所用的模板信息
|
||||
* 直连设备接入
|
||||
* @param devAccessParam
|
||||
*/
|
||||
void devAccess(DevAccessParam devAccessParam);
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
package com.njcn.access.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.access.pojo.param.DeviceStatusParam;
|
||||
import com.njcn.csdevice.pojo.param.CsEquipmentDeliveryAddParm;
|
||||
import com.njcn.csdevice.pojo.param.CsEquipmentDeliveryAuditParm;
|
||||
import com.njcn.csdevice.pojo.param.CsEquipmentDeliveryQueryParm;
|
||||
import com.njcn.csdevice.pojo.param.ProjectEquipmentQueryParm;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
|
||||
import com.njcn.csdevice.pojo.vo.DeviceManagerVO;
|
||||
import com.njcn.csdevice.pojo.vo.ProjectEquipmentVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -44,6 +36,12 @@ public interface ICsEquipmentDeliveryService extends IService<CsEquipmentDeliver
|
||||
*/
|
||||
void updateRunStatusBynDid(String nDid,Integer id);
|
||||
|
||||
/**
|
||||
* 根据网关id修改设备当前流程
|
||||
* @param nDid 网关id
|
||||
*/
|
||||
void updateProcessBynDid(String nDid,Integer processId);
|
||||
|
||||
/**
|
||||
* 根据ndid查询装置信息
|
||||
* @param nDid
|
||||
@@ -61,4 +59,19 @@ public interface ICsEquipmentDeliveryService extends IService<CsEquipmentDeliver
|
||||
* 恢复出厂设置
|
||||
*/
|
||||
void devResetFactory(DeviceStatusParam param);
|
||||
|
||||
/**
|
||||
* 获取启用并且客户端在线的装置
|
||||
*/
|
||||
List<CsEquipmentDeliveryPO> getOnlineDev();
|
||||
|
||||
/**
|
||||
* 获取离线、启用、客户端在线的装置
|
||||
*/
|
||||
List<CsEquipmentDeliveryPO> getOfflineDev();
|
||||
|
||||
/**
|
||||
* 获取在运且在线的装置 所属前置和进程号
|
||||
*/
|
||||
List<String> getFrontAndProcess();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.njcn.access.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.access.pojo.po.CsSoftInfoPO;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 系统软件表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-08-09
|
||||
*/
|
||||
public interface ICsSoftInfoService extends IService<CsSoftInfoPO> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,270 @@
|
||||
package com.njcn.access.service.impl;
|
||||
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
import com.njcn.access.api.CsTopicFeignClient;
|
||||
import com.njcn.access.enums.AccessEnum;
|
||||
import com.njcn.access.enums.TypeEnum;
|
||||
import com.njcn.access.pojo.dto.AskDataDto;
|
||||
import com.njcn.access.pojo.dto.ControlDto;
|
||||
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;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AskDeviceDataServiceImpl implements AskDeviceDataService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(AskDeviceDataServiceImpl.class);
|
||||
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;
|
||||
|
||||
@Override
|
||||
public void askDeviceRootPath(String nDid) {
|
||||
Object object = getDeviceMid(nDid);
|
||||
if (!Objects.isNull(object)) {
|
||||
mid = (Integer) object;
|
||||
}
|
||||
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
|
||||
reqAndResParam.setMid(mid);
|
||||
reqAndResParam.setDid(1);
|
||||
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||
reqAndResParam.setExpire(-1);
|
||||
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_13.getCode()));
|
||||
String version = getVersion(nDid);
|
||||
publisher.send("/Pfm/DevFileCmd/" + version + "/" + nDid, new Gson().toJson(reqAndResParam), 1, false);
|
||||
mid = mid + 1;
|
||||
if (mid > 10000) {
|
||||
mid = 1;
|
||||
}
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,mid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void askDeviceFileOrDir(String nDid, String name) {
|
||||
Object object = getDeviceMid(nDid);
|
||||
if (!Objects.isNull(object)) {
|
||||
mid = (Integer) object;
|
||||
}
|
||||
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
|
||||
reqAndResParam.setMid(mid);
|
||||
reqAndResParam.setDid(1);
|
||||
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||
reqAndResParam.setExpire(-1);
|
||||
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_8.getCode()));
|
||||
String json = String.format("{\"Name\":\"%s\"}", name);
|
||||
JSONObject jsonObject = JSONObject.fromObject(json);
|
||||
reqAndResParam.setMsg(jsonObject);
|
||||
String version = getVersion(nDid);
|
||||
publisher.send("/Pfm/DevFileCmd/" + version + "/" + nDid, new Gson().toJson(reqAndResParam), 1, false);
|
||||
mid = mid + 1;
|
||||
if (mid > 10000) {
|
||||
mid = 1;
|
||||
}
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,mid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean downloadFile(String nDid, String name, Integer size, String fileCheck) {
|
||||
boolean result = true;
|
||||
try {
|
||||
redisUtil.saveByKeyWithExpire("fileDowning:"+nDid,"fileDowning",300L);
|
||||
redisUtil.saveByKey("fileCheck"+nDid+name,fileCheck);
|
||||
Object object = getDeviceMid(nDid);
|
||||
if (!Objects.isNull(object)) {
|
||||
mid = (Integer) object;
|
||||
}
|
||||
ReqAndResDto.Req reqAndResParam = getAllPojo(mid,name);
|
||||
publisher.send("/Pfm/DevFileCmd/V1/"+nDid,new Gson().toJson(reqAndResParam),1,false);
|
||||
mid = mid + 1;
|
||||
if (mid > 10000) {
|
||||
mid = 1;
|
||||
}
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,mid);
|
||||
} catch (Exception e) {
|
||||
redisUtil.delete("fileDowning:"+nDid);
|
||||
redisUtil.delete("fileCheck"+nDid+name);
|
||||
redisUtil.delete("fileDownUserId"+nDid+name);
|
||||
throw new BusinessException(AlgorithmResponseEnum.FILE_DOWNLOAD_ERROR);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebootDevice(String nDid) {
|
||||
Object object = getDeviceMid(nDid);
|
||||
if (!Objects.isNull(object)) {
|
||||
mid = (Integer) object;
|
||||
}
|
||||
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
|
||||
reqAndResParam.setMid(mid);
|
||||
reqAndResParam.setDid(0);
|
||||
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||
reqAndResParam.setExpire(-1);
|
||||
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_31.getCode()));
|
||||
ControlDto controlDto = new ControlDto();
|
||||
controlDto.setClDid(-1);
|
||||
controlDto.setCmdType("reboot");
|
||||
controlDto.setCmdParm("on");
|
||||
reqAndResParam.setMsg(controlDto);
|
||||
publisher.send("/Pfm/DevCmd/V1/" + nDid, new Gson().toJson(reqAndResParam), 1, false);
|
||||
mid = mid + 1;
|
||||
if (mid > 10000) {
|
||||
mid = 1;
|
||||
}
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,mid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createFolder(String nDid, String path) {
|
||||
Object object = getDeviceMid(nDid);
|
||||
if (!Objects.isNull(object)) {
|
||||
mid = (Integer) object;
|
||||
}
|
||||
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
|
||||
reqAndResParam.setMid(mid);
|
||||
reqAndResParam.setDid(0);
|
||||
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||
reqAndResParam.setExpire(-1);
|
||||
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_12.getCode()));
|
||||
String json = String.format("{\"Name\":\"%s\"}", path);
|
||||
JSONObject jsonObject = JSONObject.fromObject(json);
|
||||
reqAndResParam.setMsg(jsonObject);
|
||||
publisher.send("/Pfm/DevFileCmd/V1/" + nDid, new Gson().toJson(reqAndResParam), 1, false);
|
||||
mid = mid + 1;
|
||||
if (mid > 10000) {
|
||||
mid = 1;
|
||||
}
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,mid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFolder(String nDid, String path) {
|
||||
Object object = getDeviceMid(nDid);
|
||||
if (!Objects.isNull(object)) {
|
||||
mid = (Integer) object;
|
||||
}
|
||||
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
|
||||
reqAndResParam.setMid(mid);
|
||||
reqAndResParam.setDid(0);
|
||||
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||
reqAndResParam.setExpire(-1);
|
||||
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_11.getCode()));
|
||||
String json = String.format("{\"Name\":\"%s\"}", path);
|
||||
JSONObject jsonObject = JSONObject.fromObject(json);
|
||||
reqAndResParam.setMsg(jsonObject);
|
||||
publisher.send("/Pfm/DevFileCmd/V1/" + nDid, new Gson().toJson(reqAndResParam), 1, false);
|
||||
mid = mid + 1;
|
||||
if (mid > 10000) {
|
||||
mid = 1;
|
||||
}
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,mid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void askRealData(String nDid, Integer idx, Integer clDId) {
|
||||
Object object = getDeviceMid(nDid);
|
||||
if (!Objects.isNull(object)) {
|
||||
mid = (Integer) object;
|
||||
}
|
||||
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
|
||||
reqAndResParam.setMid(mid);
|
||||
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_6.getCode()));
|
||||
reqAndResParam.setExpire(-1);
|
||||
//fixme 目前设备都是直连设备,因此did就是其本身,默认为1,后期涉及网关,此did是需要动态变化的
|
||||
reqAndResParam.setDid(1);
|
||||
AskDataDto askDataDto = new AskDataDto();
|
||||
askDataDto.setCldid(clDId);
|
||||
askDataDto.setDataAttr(1);
|
||||
askDataDto.setDataType(4);
|
||||
askDataDto.setOperate(1);
|
||||
askDataDto.setStartTime(-1);
|
||||
askDataDto.setEndTime(-1);
|
||||
askDataDto.setRtDuration(30);
|
||||
askDataDto.setDsNameIdx(idx);
|
||||
reqAndResParam.setMsg(askDataDto);
|
||||
log.info("askDevData的请求报文:" + new Gson().toJson(reqAndResParam));
|
||||
publisher.send("/Pfm/DevCmd/V1/"+nDid, new Gson().toJson(reqAndResParam),1,false);
|
||||
mid = mid + 1;
|
||||
if (mid > 10000) {
|
||||
mid = 1;
|
||||
}
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,mid);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
public String getVersion(String nDid) {
|
||||
return csTopicFeignClient.find(nDid).getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 全文件下载请求报文
|
||||
*/
|
||||
public ReqAndResDto.Req getAllPojo(Integer mid, String fileName) {
|
||||
String json;
|
||||
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
|
||||
reqAndResParam.setMid(mid);
|
||||
reqAndResParam.setDid(0);
|
||||
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_9.getCode()));
|
||||
reqAndResParam.setExpire(-1);
|
||||
json = "{Name:\""+fileName+"\",TransferMode:"+(-1)+",Offset:"+(-1)+",Len:"+range+"}";
|
||||
JSONObject jsonObject = JSONObject.fromObject(json);
|
||||
reqAndResParam.setMsg(jsonObject);
|
||||
return reqAndResParam;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 文件下载请求报文
|
||||
*/
|
||||
public ReqAndResDto.Req getPojo(Integer mid, String fileName, Integer step) {
|
||||
String json;
|
||||
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
|
||||
reqAndResParam.setMid(mid);
|
||||
reqAndResParam.setDid(0);
|
||||
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_9.getCode()));
|
||||
reqAndResParam.setExpire(-1);
|
||||
json = "{Name:\""+fileName+"\",TransferMode:"+1+",Offset:"+(step*range)+",Len:"+range+"}";
|
||||
JSONObject jsonObject = JSONObject.fromObject(json);
|
||||
reqAndResParam.setMsg(jsonObject);
|
||||
return reqAndResParam;
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,10 @@ public class CsDataSetServiceImpl extends ServiceImpl<CsDataSetMapper, CsDataSet
|
||||
|
||||
@Override
|
||||
public List<CsDataSet> getDataSetData(String modelId) {
|
||||
return this.lambdaQuery().eq(CsDataSet::getPid, modelId).list();
|
||||
return this.lambdaQuery()
|
||||
.eq(CsDataSet::getPid, modelId)
|
||||
.and(item->item.eq(CsDataSet::getConType,1).or().isNull(CsDataSet::getConType))
|
||||
.and(item->item.eq(CsDataSet::getDataType,"Stat").or().isNull(CsDataSet::getDataType))
|
||||
.list();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,14 @@ 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;
|
||||
import com.njcn.access.enums.DataModel;
|
||||
import com.njcn.access.enums.TypeEnum;
|
||||
import com.njcn.access.handler.MqttMessageHandler;
|
||||
import com.njcn.access.mapper.CsDevModelMapper;
|
||||
import com.njcn.access.pojo.dto.ReqAndResDto;
|
||||
import com.njcn.access.pojo.dto.UploadFileDto;
|
||||
@@ -21,12 +22,16 @@ 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.pojo.po.*;
|
||||
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
|
||||
import com.njcn.csdevice.api.*;
|
||||
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
||||
import com.njcn.csdevice.pojo.param.CsDevModelAddParm;
|
||||
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;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.system.api.*;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
@@ -38,15 +43,12 @@ import com.njcn.system.pojo.vo.DictTreeVO;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bouncycastle.util.encoders.Hex;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Date;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -62,42 +64,25 @@ import java.util.stream.Collectors;
|
||||
public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
|
||||
private final FileStorageUtil fileStorageUtil;
|
||||
|
||||
private final DevModelFeignClient devModelFeignClient;
|
||||
|
||||
private final EpdFeignClient epdFeignClient;
|
||||
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
|
||||
private final EleEvtFeignClient eleEvtFeignClient;
|
||||
|
||||
private final ICsDataSetService csDataSetService;
|
||||
|
||||
private final ICsDataArrayService csDataArrayService;
|
||||
|
||||
private final CsDevModelMapper csDevModelMapper;
|
||||
|
||||
private final ICsLineModelService csLineModelService;
|
||||
|
||||
private final ICsGroupService csGroupService;
|
||||
|
||||
private final ICsGroArrService csGroArrService;
|
||||
|
||||
private final CsLogsFeignClient csLogsFeignClient;
|
||||
|
||||
private final EleWaveFeignClient waveFeignClient;
|
||||
|
||||
private final DictTreeFeignClient dictTreeFeignClient;
|
||||
|
||||
private final MqttPublisher publisher;
|
||||
|
||||
private final ICsTopicService csTopicService;
|
||||
|
||||
private final ICsEquipmentDeliveryService csEquipmentDeliveryService;
|
||||
|
||||
private final RedisUtil redisUtil;
|
||||
|
||||
private final MqttMessageHandler mqttMessageHandler;
|
||||
private final EquipmentFeignClient eequipmentFeignClient;
|
||||
private final DevModelRelationFeignClient devModelRelationFeignClient;
|
||||
private final CsLineFeignClient csLineFeignClient;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
@@ -112,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() + "_");
|
||||
@@ -121,6 +120,21 @@ 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
} catch (Exception e) {
|
||||
logDto.setResult(0);
|
||||
@@ -154,30 +168,22 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void uploadDevFile(MultipartFile file,String id,String path) {
|
||||
DeviceLogDTO logDto = null;
|
||||
Object object = redisUtil.getObjectByKey("uploading");
|
||||
if (Objects.nonNull(object)) {
|
||||
throw new BusinessException(AlgorithmResponseEnum.FILE_UPLOADING);
|
||||
}
|
||||
Object object2 = redisUtil.getObjectByKey("fileDowning:" + id);
|
||||
if (Objects.nonNull(object2)) {
|
||||
throw new BusinessException(AlgorithmResponseEnum.FILE_BUSY);
|
||||
}
|
||||
try {
|
||||
byte[] bytes = file.getBytes();
|
||||
int length = bytes.length;
|
||||
//生成文件校验码
|
||||
int crc = CRC32Utils.calculateCRC32(bytes,length,0xffffffff);
|
||||
String hexString = String.format("%08X", crc);
|
||||
//判断nDid是否存在
|
||||
CsEquipmentDeliveryVO csEquipmentDeliveryVO = csEquipmentDeliveryService.queryEquipmentBynDid(id);
|
||||
logDto = new DeviceLogDTO();
|
||||
logDto.setUserName(RequestUtil.getUserNickname());
|
||||
logDto.setLoginName(RequestUtil.getUsername());
|
||||
if (Objects.isNull(csEquipmentDeliveryVO.getNdid())) {
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.NDID_NO_FIND.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AccessResponseEnum.NDID_NO_FIND);
|
||||
}
|
||||
//存储文件至文件服务器
|
||||
fileStorageUtil.uploadMultipart(file, OssPath.SYSTEM_TO_DEV + file.getOriginalFilename() + "_");
|
||||
//获取版本
|
||||
@@ -188,6 +194,10 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
//需要循环的次数
|
||||
int times = bytes.length / cap + 1;
|
||||
for (int i = 1; i <= times; i++) {
|
||||
//发送数据给前端
|
||||
String json = "{fileName:"+file.getOriginalFilename()+",allStep:"+times+",nowStep:"+i+"}";
|
||||
publisher.send("/Web/Progress/" + id, new Gson().toJson(json), 1, false);
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
byte[] lsBytes;
|
||||
if (length > 50*1024) {
|
||||
lsBytes = Arrays.copyOfRange(bytes, (i - 1) * cap, i * cap);
|
||||
@@ -197,10 +207,11 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
logDto.setResult(1);
|
||||
length = length - cap;
|
||||
//判断是否重发
|
||||
sendNextStep(logDto,path,file,bytes.length,lsBytes,(i-1)*cap,version,id,i,hexString);
|
||||
FileRedisDto fileRedisDto = (FileRedisDto) redisUtil.getObjectByKey("uploadFileStep");
|
||||
sendNextStep(logDto,path,file,bytes.length,lsBytes,(i-1)*cap,version,id,i,hexString,false);
|
||||
FileRedisDto fileRedisDto = (FileRedisDto) redisUtil.getObjectByKey(AppRedisKey.UPLOAD.concat(id).concat(String.valueOf(i)));
|
||||
//重发之后判断继续循环还是跳出循环
|
||||
if (!Objects.equals(fileRedisDto.getCode(),200)) {
|
||||
if (!Objects.isNull(fileRedisDto) && !Objects.equals(fileRedisDto.getCode(),200)) {
|
||||
redisUtil.delete("uploading");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@@ -210,21 +221,24 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
logDto.setOperate(id + "设备上送文件,这是最后一帧,为第" + i + "帧");
|
||||
logDto.setResult(1);
|
||||
//判断是否重发
|
||||
sendNextStep(logDto,path,file,bytes.length,lsBytes,(i-1)*cap,version,id,i,hexString);
|
||||
sendNextStep(logDto,path,file,bytes.length,lsBytes,(i-1)*cap,version,id,i,hexString,true);
|
||||
}
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
}
|
||||
} else {
|
||||
String json = "{fileName:"+file.getOriginalFilename()+",allStep:\""+1+"\",nowStep:"+1+"}";
|
||||
publisher.send("/Web/Progress", new Gson().toJson(json), 1, false);
|
||||
ReqAndResDto.Req req = getPojo(1,path,file,length,bytes,0,hexString);
|
||||
publisher.send("/Pfm/DevFileCmd/" + version + "/" + id, new Gson().toJson(req), 1, false);
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setOperate(id + "系统上送文件,当前文件只有1帧");
|
||||
logDto.setResult(1);
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
//判断是否重发
|
||||
sendNextStep(logDto,path,file,length,bytes,0,version,id,1,hexString);
|
||||
sendNextStep(logDto,path,file,length,bytes,0,version,id,1,hexString,false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
assert logDto != null;
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.UPLOAD_ERROR.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
@@ -250,6 +264,10 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
uploadFileDto.setLen(bytes.length);
|
||||
uploadFileDto.setData(Base64.getEncoder().encodeToString(bytes));
|
||||
uploadFileDto.setFileCheck(fileCheck);
|
||||
//生成当前帧文件校验码
|
||||
int crc = CRC32Utils.calculateCRC32(bytes,bytes.length,0xffffffff);
|
||||
String hexString = String.format("%08X", crc);
|
||||
uploadFileDto.setStepFileCheck(hexString);
|
||||
reqAndResParam.setMsg(uploadFileDto);
|
||||
return reqAndResParam;
|
||||
}
|
||||
@@ -257,24 +275,33 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
/**
|
||||
* 根据装置响应来判断发送的内容
|
||||
*/
|
||||
public void sendNextStep(DeviceLogDTO logDto, String path, MultipartFile file, int length, byte[] bytes, Integer offset, String version, String id, int mid, String fileCheck) {
|
||||
public void sendNextStep(DeviceLogDTO logDto, String path, MultipartFile file, int length, byte[] bytes, Integer offset, String version, String id, int mid, String fileCheck, boolean result) {
|
||||
try {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Thread.sleep(300);
|
||||
FileRedisDto fileRedisDto = (FileRedisDto) redisUtil.getObjectByKey("uploadFileStep");
|
||||
FileRedisDto fileRedis = new FileRedisDto();
|
||||
if (Objects.nonNull(fileRedisDto.getCode()) && fileRedisDto.getCode().equals(200)) {
|
||||
fileRedis.setCode(200);
|
||||
break;
|
||||
for (int i = 0; i < 30; i++) {
|
||||
if (result) {
|
||||
Thread.sleep(10000);
|
||||
} else {
|
||||
ReqAndResDto.Req req = getPojo(mid,path,file,length,bytes,offset,fileCheck);
|
||||
publisher.send("/Pfm/DevFileCmd/" + version + "/" + id, new Gson().toJson(req), 1, false);
|
||||
logDto.setOperate(id + "系统上送文件,装置响应失败,重新发送,这是第" + (i+1) + "次");
|
||||
logDto.setResult(1);
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
fileRedis.setCode(fileRedisDto.getCode());
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
FileRedisDto fileRedisDto = (FileRedisDto) redisUtil.getObjectByKey(AppRedisKey.UPLOAD.concat(id).concat(String.valueOf(mid)));
|
||||
if (Objects.isNull(fileRedisDto)) {
|
||||
FileRedisDto fileRedis = new FileRedisDto();
|
||||
fileRedis.setCode(400);
|
||||
redisUtil.saveByKeyWithExpire(AppRedisKey.UPLOAD.concat(id).concat(String.valueOf(mid)),fileRedis,10L);
|
||||
} else {
|
||||
if (Objects.equals(fileRedisDto.getCode(),200)) {
|
||||
break;
|
||||
} else {
|
||||
FileRedisDto fileRedis = new FileRedisDto();
|
||||
fileRedis.setCode(400);
|
||||
redisUtil.saveByKeyWithExpire(AppRedisKey.UPLOAD.concat(id).concat(String.valueOf(mid)),fileRedis,10L);
|
||||
ReqAndResDto.Req req = getPojo(mid,path,file,length,bytes,offset,fileCheck);
|
||||
publisher.send("/Pfm/DevFileCmd/" + version + "/" + id, new Gson().toJson(req), 1, false);
|
||||
logDto.setOperate(id + "系统上送文件,装置响应失败,重新发送,这是第" + (i+1) + "次");
|
||||
logDto.setResult(1);
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
}
|
||||
}
|
||||
redisUtil.saveByKeyWithExpire("uploadFileStep",fileRedis,10L);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
assert logDto != null;
|
||||
@@ -303,20 +330,33 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AccessResponseEnum.MODEL_REPEAT);
|
||||
}
|
||||
CsDevModelPO model = new CsDevModelPO();
|
||||
model.setDevTypeName(templateDto.getDevType());
|
||||
model.setName(templateDto.getDevType());
|
||||
model.setVersionNo(templateDto.getVersion());
|
||||
model.setVersionDate(Date.valueOf(templateDto.getTime()));
|
||||
model.setFilePath(filePath);
|
||||
model.setStatus ("1");
|
||||
// CsDevModelPO model = new CsDevModelPO();
|
||||
// model.setDevTypeName(templateDto.getDevType());
|
||||
// model.setName(templateDto.getDevType());
|
||||
// model.setVersionNo(templateDto.getVersion());
|
||||
// model.setVersionDate(Date.valueOf(templateDto.getTime()));
|
||||
// model.setFilePath(filePath);
|
||||
// model.setStatus ("1");
|
||||
// //fixme 先用数据类型来区分模板的类型
|
||||
// if (templateDto.getDataList().contains("Apf") || templateDto.getDataList().contains("Dvr")){
|
||||
// model.setType(0);
|
||||
// } else {
|
||||
// model.setType(1);
|
||||
// }
|
||||
// csDevModelMapper.insert(model);
|
||||
CsDevModelAddParm csDevModelAddParm = new CsDevModelAddParm();
|
||||
csDevModelAddParm.setDevTypeName(templateDto.getDevType());
|
||||
csDevModelAddParm.setName(templateDto.getDevType());
|
||||
csDevModelAddParm.setVersionNo(templateDto.getVersion());
|
||||
csDevModelAddParm.setVersionDate(Date.valueOf(templateDto.getTime()));
|
||||
csDevModelAddParm.setFilePath(filePath);
|
||||
//fixme 先用数据类型来区分模板的类型
|
||||
if (templateDto.getDataList().contains("Apf") || templateDto.getDataList().contains("Dvr")){
|
||||
model.setType(0);
|
||||
csDevModelAddParm.setType(0);
|
||||
} else {
|
||||
model.setType(1);
|
||||
csDevModelAddParm.setType(1);
|
||||
}
|
||||
csDevModelMapper.insert(model);
|
||||
CsDevModelPO model = devModelFeignClient.addDevModel(csDevModelAddParm).getData();
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
return model;
|
||||
}
|
||||
@@ -362,9 +402,9 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
}
|
||||
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));
|
||||
@@ -601,9 +641,9 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
}
|
||||
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));
|
||||
@@ -637,14 +677,15 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
}
|
||||
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);
|
||||
@@ -828,15 +869,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->{
|
||||
@@ -850,9 +894,11 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
csDataSet.setPeriod(item1.getPeriod());
|
||||
csDataSet.setStoreFlag(item1.getStoreFlag());
|
||||
csDataSet.setDataList(String.join(",",templateDto.getDataList()));
|
||||
csDataSet.setDataType(item1.getDataAttr());
|
||||
csDataSet.setType(0);
|
||||
csDataSet.setClDev(0);
|
||||
csDataSet.setDataLevel(item1.getDataLevel());
|
||||
csDataSet.setConType(item1.getConType());
|
||||
setList.add(csDataSet);
|
||||
List<DataArrayDto> list = item1.getDataArrayDtoList();
|
||||
if(CollectionUtil.isNotEmpty(list)) {
|
||||
@@ -887,6 +933,8 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
csDataSet.setStoreFlag(item4.getStoreFlag());
|
||||
csDataSet.setDataList(String.join(",",item3.getDataList()));
|
||||
csDataSet.setDataLevel(item4.getDataLevel());
|
||||
csDataSet.setDataType(item4.getDataAttr());
|
||||
csDataSet.setConType(item4.getConType());
|
||||
//fixme 先用数据类型来区分模板的类型
|
||||
if (item3.getDataList().contains("Apf") || item3.getDataList().contains("Dvr")){
|
||||
csDataSet.setType(1);
|
||||
@@ -915,40 +963,46 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
}
|
||||
if(CollectionUtil.isNotEmpty(setList)) {
|
||||
csDataSetService.addList(setList);
|
||||
setList.forEach(item->{
|
||||
if (Objects.equals(item.getName(),"统计数据")) {
|
||||
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);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1186,48 +1240,48 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
* 数据集名称调整
|
||||
*/
|
||||
public String dataSetName(String name,String code){
|
||||
String showName = null;
|
||||
String showName = name;
|
||||
switch (name) {
|
||||
//数据集
|
||||
case "Ds$Apf$Master$01":
|
||||
showName = "APF模块数据";
|
||||
showName = "APF模块数据模板";
|
||||
break;
|
||||
case "Ds$Apf$module$01":
|
||||
showName = "APF模块1数据";
|
||||
showName = "APF模块1数据模板";
|
||||
break;
|
||||
case "Ds$Apf$module$02":
|
||||
showName = "APF模块2数据";
|
||||
showName = "APF模块2数据模板";
|
||||
break;
|
||||
case "Ds$Apf$module$03":
|
||||
showName = "APF模块3数据";
|
||||
showName = "APF模块3数据模板";
|
||||
break;
|
||||
case "Ds$Apf$module$04":
|
||||
showName = "APF模块4数据";
|
||||
showName = "APF模块4数据模板";
|
||||
break;
|
||||
case "Ds$Apf$module$05":
|
||||
showName = "APF模块5数据";
|
||||
showName = "APF模块5数据模板";
|
||||
break;
|
||||
case "Ds$Apf$module$06":
|
||||
showName = "APF模块6数据";
|
||||
showName = "APF模块6数据模板";
|
||||
break;
|
||||
case "Ds$Apf$module$07":
|
||||
showName = "APF模块7数据";
|
||||
showName = "APF模块7数据模板";
|
||||
break;
|
||||
case "Ds$Apf$module$08":
|
||||
showName = "APF模块8数据";
|
||||
showName = "APF模块8数据模板";
|
||||
break;
|
||||
case "Ds$Pqd$Stat$01":
|
||||
if (Objects.equals(code, DicDataEnum.CONNECT_DEV.getCode()) || Objects.isNull(code)){
|
||||
showName = "电网侧数据";
|
||||
showName = "电网侧数据模板";
|
||||
} else if (Objects.equals(code, DicDataEnum.PORTABLE.getCode())){
|
||||
showName = "监测1路数据";
|
||||
showName = "监测1#数据模板";
|
||||
}
|
||||
break;
|
||||
case "Ds$Pqd$Stat$02":
|
||||
if (Objects.equals(code, DicDataEnum.CONNECT_DEV.getCode()) || Objects.isNull(code)){
|
||||
showName = "负载侧数据";
|
||||
showName = "负载侧数据模板";
|
||||
} else if (Objects.equals(code, DicDataEnum.PORTABLE.getCode())){
|
||||
showName = "监测2路数据";
|
||||
showName = "监测2#数据模板";
|
||||
}
|
||||
break;
|
||||
//波形参数名称
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.njcn.access.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@@ -11,21 +10,21 @@ import com.njcn.access.enums.AccessEnum;
|
||||
import com.njcn.access.enums.AccessResponseEnum;
|
||||
import com.njcn.access.enums.TypeEnum;
|
||||
import com.njcn.access.param.DevAccessParam;
|
||||
import com.njcn.access.pojo.RspDataDto;
|
||||
import com.njcn.access.pojo.dto.AccessDto;
|
||||
import com.njcn.access.pojo.dto.CsModelDto;
|
||||
import com.njcn.access.pojo.dto.ReqAndResDto;
|
||||
import com.njcn.access.pojo.param.DeviceStatusParam;
|
||||
import com.njcn.access.service.*;
|
||||
import com.njcn.access.utils.ChannelObjectUtil;
|
||||
import com.njcn.access.utils.MqttUtil;
|
||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.api.CsLogsFeignClient;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
import com.njcn.csdevice.api.ProcessFeignClient;
|
||||
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.pojo.po.*;
|
||||
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
@@ -36,9 +35,10 @@ import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.pojo.po.SysDicTreePO;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.sf.cglib.core.Local;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -55,45 +55,32 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
@Slf4j
|
||||
public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CsDeviceServiceImpl.class);
|
||||
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
|
||||
private final ICsEquipmentDeliveryService csEquipmentDeliveryService;
|
||||
|
||||
private final DictTreeFeignClient dictTreeFeignClient;
|
||||
|
||||
private final ICsLedgerService csLedgerService;
|
||||
|
||||
private final ICsDevModelRelationService csDevModelRelationService;
|
||||
|
||||
private final ICsLineService csLineService;
|
||||
|
||||
private final IAppLineTopologyDiagramService appLineTopologyDiagramService;
|
||||
|
||||
private final ICsDeviceUserService csDeviceUserService;
|
||||
|
||||
private final MqttPublisher publisher;
|
||||
|
||||
private final RedisUtil redisUtil;
|
||||
|
||||
private final MqttUtil mqttUtil;
|
||||
|
||||
private final ICsTopicService csTopicService;
|
||||
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
|
||||
private final CsLogsFeignClient csLogsFeignClient;
|
||||
|
||||
private final ProcessFeignClient processFeignClient;
|
||||
|
||||
private final CsLinePOService csLinePOService;
|
||||
|
||||
private final CsDeviceUserPOService csDeviceUserPOService;
|
||||
|
||||
private final ICsDataSetService csDataSetService;
|
||||
private final ChannelObjectUtil channelObjectUtil;
|
||||
private final CsLineFeignClient csLineFeignClient;
|
||||
private final DataSetFeignClient dataSetFeignClient;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
@@ -102,7 +89,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName(RequestUtil.getUserNickname());
|
||||
logDto.setLoginName(RequestUtil.getUsername());
|
||||
logDto.setOperate("当前设备"+nDid+"状态判断");
|
||||
logDto.setOperate("直连设备"+nDid+"注册");
|
||||
logDto.setResult(1);
|
||||
//1.判断nDid是否存在
|
||||
CsEquipmentDeliveryVO csEquipmentDeliveryVO = csEquipmentDeliveryService.queryEquipmentBynDid(nDid);
|
||||
@@ -112,13 +99,6 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AccessResponseEnum.NDID_NO_FIND);
|
||||
}
|
||||
//判断是否已经注册过
|
||||
if (!Objects.isNull(csEquipmentDeliveryVO.getNdid()) && Objects.equals(type,csEquipmentDeliveryVO.getProcess()) && Objects.equals(AccessEnum.ACCESS.getCode(),csEquipmentDeliveryVO.getStatus())){
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.NDID_SAME_STEP.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AccessResponseEnum.NDID_SAME_STEP);
|
||||
}
|
||||
//2.判断设备是否是直连设备
|
||||
SysDicTreePO sysDicTreePo = dictTreeFeignClient.queryById(csEquipmentDeliveryVO.getDevType()).getData();
|
||||
if (Objects.isNull(sysDicTreePo)){
|
||||
@@ -134,7 +114,14 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AccessResponseEnum.DEV_IS_NOT_ZL);
|
||||
}
|
||||
//3.判断客户端是否在线
|
||||
//3.判断是否已经注册过
|
||||
if (!Objects.isNull(csEquipmentDeliveryVO.getNdid()) && Objects.equals(type,csEquipmentDeliveryVO.getProcess()) && Objects.equals(AccessEnum.ACCESS.getCode(),csEquipmentDeliveryVO.getStatus())){
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.NDID_SAME_STEP.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AccessResponseEnum.NDID_SAME_STEP);
|
||||
}
|
||||
//4.判断客户端是否在线
|
||||
String clientName = "NJCN-" + nDid.substring(nDid.length() - 6);
|
||||
boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
||||
if (!mqttClient){
|
||||
@@ -143,7 +130,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AccessResponseEnum.MISSING_CLIENT);
|
||||
}
|
||||
//4.判断当前流程是否是合法的
|
||||
//5.判断当前流程是否是合法的
|
||||
if (csEquipmentDeliveryVO.getProcess() > type){
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.PROCESS_SAME_ERROR.getMessage());
|
||||
@@ -153,10 +140,10 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
logDto.setFailReason(AccessResponseEnum.PROCESS_MISSING_ERROR.getMessage());
|
||||
throw new BusinessException(AccessResponseEnum.PROCESS_MISSING_ERROR);
|
||||
}
|
||||
//5.询问设备支持的主题信息
|
||||
//6.询问设备支持的主题信息
|
||||
//将支持的主题入库
|
||||
askTopic(nDid);
|
||||
//6.MQTT询问装置用的模板,并判断库中是否存在模板
|
||||
//7.MQTT询问装置用的模板,并判断库中是否存在模板
|
||||
//存在则建立关系;不存在则告警出来
|
||||
SysDicTreePO dictData = dictTreeFeignClient.queryById(csEquipmentDeliveryVO.getDevModel()).getData();
|
||||
if (Objects.isNull(dictData)){
|
||||
@@ -203,7 +190,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName(RequestUtil.getUserNickname());
|
||||
logDto.setLoginName(RequestUtil.getUsername());
|
||||
logDto.setOperate("设备"+devAccessParam.getNDid()+"注册");
|
||||
logDto.setOperate("设备"+devAccessParam.getNDid()+"接入");
|
||||
logDto.setResult(1);
|
||||
try {
|
||||
//获取版本
|
||||
@@ -219,7 +206,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
csLedgerParam.setLevel(2);
|
||||
csLedgerParam.setSort(0);
|
||||
csLedgerService.addLedgerTree(csLedgerParam);
|
||||
List<CsModelDto> modelId = objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + devAccessParam.getNDid()));
|
||||
List<CsModelDto> modelId = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + devAccessParam.getNDid()),CsModelDto.class);
|
||||
//2.新增装置-模板关系、获取电能质量的逻辑设备id
|
||||
for (CsModelDto item : modelId) {
|
||||
CsDevModelRelationAddParm csDevModelRelationAddParm = new CsDevModelRelationAddParm();
|
||||
@@ -240,16 +227,34 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
po.setClDid(0);
|
||||
if (Objects.equals(DicDataEnum.GRID_SIDE.getCode(),location)){
|
||||
po.setLineId(devAccessParam.getNDid() + "1");
|
||||
String id = Objects.requireNonNull(modelId.stream().filter(it -> Objects.equals(it.getDid(), 2)).findFirst().orElse(null)).getModelId();
|
||||
po.setDataModelId(id);
|
||||
//获取模板下数据集
|
||||
List<CsDataSet> dataSets = csDataSetService.getDataSetData(id);
|
||||
String dataSetId = Objects.requireNonNull(dataSets.stream().filter(it -> Objects.equals(it.getClDev(), 1)&&Objects.equals(it.getType(), 2)).findFirst().orElse(null)).getId();
|
||||
po.setDataSetId(dataSetId);
|
||||
param.setId(devAccessParam.getNDid() + "1");
|
||||
appLineTopologyDiagramPo.setLineId(devAccessParam.getNDid() + "1");
|
||||
po.setClDid(1);
|
||||
} else if (Objects.equals(DicDataEnum.LOAD_SIDE.getCode(),location)){
|
||||
po.setLineId(devAccessParam.getNDid() + "2");
|
||||
String id = Objects.requireNonNull(modelId.stream().filter(it -> Objects.equals(it.getDid(), 2)).findFirst().orElse(null)).getModelId();
|
||||
po.setDataModelId(id);
|
||||
//获取模板下数据集
|
||||
List<CsDataSet> dataSets = csDataSetService.getDataSetData(id);
|
||||
String dataSetId = Objects.requireNonNull(dataSets.stream().filter(it -> Objects.equals(it.getClDev(), 2)&&Objects.equals(it.getType(), 2)).findFirst().orElse(null)).getId();
|
||||
po.setDataSetId(dataSetId);
|
||||
param.setId(devAccessParam.getNDid() + "2");
|
||||
appLineTopologyDiagramPo.setLineId(devAccessParam.getNDid() + "2");
|
||||
po.setClDid(2);
|
||||
} else {
|
||||
po.setLineId(devAccessParam.getNDid() + "0");
|
||||
String id = Objects.requireNonNull(modelId.stream().filter(it -> Objects.equals(it.getDid(), 1)).findFirst().orElse(null)).getModelId();
|
||||
po.setDataModelId(id);
|
||||
//获取模板下数据集
|
||||
List<CsDataSet> dataSets = csDataSetService.getDataSetData(id);
|
||||
String dataSetId = Objects.requireNonNull(dataSets.stream().filter(it -> Objects.equals(it.getClDev(), 0)&&Objects.equals(it.getType(), 0)).findFirst().orElse(null)).getId();
|
||||
po.setDataSetId(dataSetId);
|
||||
param.setId(devAccessParam.getNDid() + "0");
|
||||
appLineTopologyDiagramPo.setLineId(devAccessParam.getNDid() + "0");
|
||||
}
|
||||
@@ -275,6 +280,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
throw new BusinessException(AccessResponseEnum.LINE_POSITION_REPEAT);
|
||||
}
|
||||
csLineService.saveBatch(csLinePoList);
|
||||
redisUtil.saveByKeyWithExpire("accessLineInfo:" + devAccessParam.getNDid(),csLinePoList,30L);
|
||||
//4.监测点拓扑图表录入关系
|
||||
appLineTopologyDiagramService.saveBatch(appLineTopologyDiagramPoList);
|
||||
//5.绑定装置和人的关系
|
||||
@@ -288,7 +294,6 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
csEquipmentDeliveryService.updateStatusBynDid(devAccessParam.getNDid(), AccessEnum.REGISTERED.getCode());
|
||||
//7.发起自动接入请求
|
||||
devAccessAskTemplate(devAccessParam.getNDid(),version,1);
|
||||
|
||||
//8.删除redis监测点模板信息
|
||||
redisUtil.delete(AppRedisKey.MODEL + devAccessParam.getNDid());
|
||||
redisUtil.delete(AppRedisKey.LINE + devAccessParam.getNDid());
|
||||
@@ -362,92 +367,102 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean manualAccess(String nDid) {
|
||||
String version = csTopicService.getVersion(nDid);
|
||||
return devAccessAskTemplate(nDid,version,new Random().nextInt(10000));
|
||||
return devAccessAskTemplate(nDid,version,1);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
@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());
|
||||
logDto.setLoginName(RequestUtil.getUsername());
|
||||
logDto.setOperate("便携式设备"+nDid+"注册、接入");
|
||||
logDto.setResult(1);
|
||||
try {
|
||||
// 设备状态判断
|
||||
checkDeviceStatus(nDid);
|
||||
// 询问设备支持的主题信息,并将支持的主题入库
|
||||
askAndStoreTopics(nDid);
|
||||
// MQTT询问装置用的模板,并判断库中是否存在模板
|
||||
checkDeviceModel(nDid);
|
||||
// 根据模板接入设备
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName(RequestUtil.getUserNickname());
|
||||
logDto.setLoginName(RequestUtil.getUsername());
|
||||
logDto.setOperate("设备"+nDid+"注册");
|
||||
logDto.setResult(1);
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
//获取版本
|
||||
String version = csTopicService.getVersion(nDid);
|
||||
CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(nDid).getData();
|
||||
List<CsLinePO> csLinePoList = new ArrayList<>();
|
||||
//1.根据模板获取监测点个数,插入监测点表
|
||||
Thread.sleep(1000);
|
||||
List<CsModelDto> modelList = objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + nDid));
|
||||
if (CollUtil.isEmpty(modelList)){
|
||||
try {
|
||||
throwExceptionAndLog(AccessResponseEnum.MODEL_ERROR, logDto);
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(e.getMessage());
|
||||
}
|
||||
}
|
||||
List<CsDataSet> list = csDataSetService.getDataSetData(modelList.get(0).getModelId());
|
||||
list.forEach(item->{
|
||||
CsLinePO po = new CsLinePO();
|
||||
po.setLineId(nDid + item.getClDev().toString());
|
||||
po.setName(item.getClDev().toString() + "号监测点");
|
||||
po.setStatus(1);
|
||||
po.setClDid(item.getClDev());
|
||||
po.setDeviceId(vo.getId());
|
||||
//防止主键重复
|
||||
QueryWrapper<CsLinePO> qw = new QueryWrapper();
|
||||
qw.eq("line_id",po.getLineId());
|
||||
if(csLineService.getBaseMapper().selectList(qw).isEmpty()){
|
||||
csLinePoList.add(po);
|
||||
}
|
||||
});
|
||||
csLineService.saveBatch(csLinePoList);
|
||||
//2.生成装置和模板的关系表
|
||||
CsDevModelRelationAddParm csDevModelRelationAddParm = new CsDevModelRelationAddParm();
|
||||
csDevModelRelationAddParm.setDevId(vo.getId());
|
||||
csDevModelRelationAddParm.setModelId(modelList.get(0).getModelId());
|
||||
csDevModelRelationAddParm.setDid(modelList.get(0).getDid());
|
||||
csDevModelRelationService.addDevModelRelation(csDevModelRelationAddParm);
|
||||
//3.修改装置状态为注册状态
|
||||
csEquipmentDeliveryService.updateStatusBynDid(nDid, AccessEnum.REGISTERED.getCode());
|
||||
//4.发起自动接入请求
|
||||
devAccessAskTemplate(nDid,version,1);
|
||||
//5.存储日志
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
//6.存储设备调试日志表
|
||||
CsEquipmentProcessPO csEquipmentProcess = new CsEquipmentProcessPO();
|
||||
csEquipmentProcess.setDevId(nDid);
|
||||
csEquipmentProcess.setOperator(RequestUtil.getUserIndex());
|
||||
csEquipmentProcess.setStartTime(LocalDateTime.now());
|
||||
csEquipmentProcess.setEndTime(LocalDateTime.now());
|
||||
csEquipmentProcess.setProcess(4);
|
||||
csEquipmentProcess.setStatus(1);
|
||||
processFeignClient.add(csEquipmentProcess);
|
||||
//7.删除redis监测点模板信息
|
||||
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
||||
redisUtil.delete(AppRedisKey.LINE + nDid);
|
||||
} catch (Exception e) {
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(e.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(CommonResponseEnum.FAIL);
|
||||
Thread.sleep(2000);
|
||||
//获取版本
|
||||
String version = csTopicService.getVersion(nDid);
|
||||
CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(nDid).getData();
|
||||
List<CsLinePO> csLinePoList = new ArrayList<>();
|
||||
//1.录入装置台账信息
|
||||
CsLedgerParam csLedgerParam = new CsLedgerParam();
|
||||
csLedgerParam.setId(vo.getId());
|
||||
csLedgerParam.setPid("0");
|
||||
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);
|
||||
}
|
||||
return "success";
|
||||
} catch (BusinessException e) {
|
||||
throw new BusinessException(e.getMessage());
|
||||
List<CsDataSet> list = csDataSetService.getDataSetData(modelList.get(0).getModelId());
|
||||
list.forEach(item->{
|
||||
CsLinePO po = new CsLinePO();
|
||||
po.setLineId(nDid + item.getClDev().toString());
|
||||
po.setName(item.getClDev().toString() + "#监测点");
|
||||
po.setStatus(1);
|
||||
po.setClDid(item.getClDev());
|
||||
po.setDeviceId(vo.getId());
|
||||
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);
|
||||
//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.发起自动接入请求
|
||||
Thread.sleep(2000);
|
||||
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(AccessResponseEnum.ACCESS_ERROR);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -464,18 +479,18 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,7 +504,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);
|
||||
@@ -497,17 +512,18 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
|
||||
private DeviceLogDTO createLogDto(String operate) {
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName(RequestUtil.getUserNickname());
|
||||
logDto.setLoginName(RequestUtil.getUsername());
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
logDto.setOperate(operate);
|
||||
logDto.setResult(1);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -518,20 +534,28 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean devAccessAskTemplate(String nDid,String version,Integer mid) {
|
||||
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);
|
||||
}
|
||||
boolean result = false;
|
||||
Map<Integer,String> modelMap = new HashMap<>();
|
||||
try {
|
||||
//删除缓存数据
|
||||
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
||||
redisUtil.deleteKeysByString(AppRedisKey.DEV_MODEL);
|
||||
//询问装置当前所用模板
|
||||
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
|
||||
reqAndResParam.setMid(mid);
|
||||
reqAndResParam.setDid(0);
|
||||
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_3.getCode()));
|
||||
reqAndResParam.setExpire(-1);
|
||||
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid,new Gson().toJson(reqAndResParam),1,false);
|
||||
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid,new Gson().toJson(getJson(mid,TypeEnum.TYPE_3.getCode())),1,false);
|
||||
//接收到模板,判断模板是否存在,替换模板,发起接入
|
||||
Thread.sleep(2000);
|
||||
List<CsModelDto> modelId = objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + nDid));
|
||||
List<CsModelDto> modelId = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + nDid),CsModelDto.class);
|
||||
if (CollUtil.isNotEmpty(modelId)) {
|
||||
CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(nDid).getData();
|
||||
//重新录入装置和模板关系信息
|
||||
@@ -542,18 +566,207 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
//发起接入
|
||||
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_5.getCode()));
|
||||
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid, new Gson().toJson(reqAndResParam),1,false);
|
||||
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 (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
} 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 装置重新接入系统,需要校验所用的模板
|
||||
* @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());
|
||||
}
|
||||
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);
|
||||
log.error("设备 {} 接入失败: {}", nDid, e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装报文
|
||||
*/
|
||||
public ReqAndResDto.Req getJson(Integer mid, String code) {
|
||||
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
|
||||
reqAndResParam.setMid(mid);
|
||||
reqAndResParam.setDid(0);
|
||||
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||
reqAndResParam.setExpire(-1);
|
||||
reqAndResParam.setType(Integer.parseInt(code));
|
||||
return reqAndResParam;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改监测点的模板id和数据集id
|
||||
*/
|
||||
public void updateLineIds(String modelId, Integer clDid, String nDid) {
|
||||
CsDataSet dataSet = dataSetFeignClient.getSetByModelId(modelId,clDid).getData().get(0);
|
||||
CsLineParam csLineParam = new CsLineParam();
|
||||
csLineParam.setLineId(nDid + clDid);
|
||||
csLineParam.setDataSetId(dataSet.getId());
|
||||
csLineParam.setModelId(modelId);
|
||||
csLineFeignClient.updateIds(csLineParam);
|
||||
}
|
||||
|
||||
/**
|
||||
* 平台对设备发起主题询问命令
|
||||
*/
|
||||
@@ -587,28 +800,4 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
logger.info("注册报文为:{}", new Gson().toJson(reqAndResParam));
|
||||
publisher.send("/Pfm/DevReg/"+nDid, new Gson().toJson(reqAndResParam),1,false);
|
||||
}
|
||||
|
||||
public List<CsModelDto> objectToList(Object object) {
|
||||
List<CsModelDto> urlList = new ArrayList<>();
|
||||
if (object != null) {
|
||||
if (object instanceof ArrayList<?>) {
|
||||
for (Object o : (List<?>) object) {
|
||||
urlList.add((CsModelDto) o);
|
||||
}
|
||||
}
|
||||
}
|
||||
return urlList;
|
||||
}
|
||||
|
||||
public List<RspDataDto.LdevInfo> objectToList2(Object object) {
|
||||
List<RspDataDto.LdevInfo> urlList = new ArrayList<>();
|
||||
if (object != null) {
|
||||
if (object instanceof ArrayList<?>) {
|
||||
for (Object o : (List<?>) object) {
|
||||
urlList.add((RspDataDto.LdevInfo) o);
|
||||
}
|
||||
}
|
||||
}
|
||||
return urlList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,25 @@
|
||||
package com.njcn.access.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
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;
|
||||
import com.njcn.access.mapper.CsEquipmentDeliveryMapper;
|
||||
import com.njcn.access.pojo.param.DeviceStatusParam;
|
||||
import com.njcn.access.service.ICsEquipmentDeliveryService;
|
||||
import com.njcn.access.utils.MqttUtil;
|
||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||
import com.njcn.csdevice.api.CsLogsFeignClient;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -27,10 +34,14 @@ import java.util.Objects;
|
||||
@RequiredArgsConstructor
|
||||
public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliveryMapper, CsEquipmentDeliveryPO> implements ICsEquipmentDeliveryService {
|
||||
|
||||
private final MqttUtil mqttUtil;
|
||||
|
||||
private final CsLogsFeignClient csLogsFeignClient;
|
||||
|
||||
@Override
|
||||
public void updateStatusBynDid(String nDId,Integer status) {
|
||||
public void updateStatusBynDid(String nDid,Integer status) {
|
||||
LambdaUpdateWrapper<CsEquipmentDeliveryPO> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||
lambdaUpdateWrapper.set(CsEquipmentDeliveryPO::getStatus,status).eq(CsEquipmentDeliveryPO::getNdid,nDId);
|
||||
lambdaUpdateWrapper.set(CsEquipmentDeliveryPO::getStatus,status).eq(CsEquipmentDeliveryPO::getNdid,nDid);
|
||||
this.update(lambdaUpdateWrapper);
|
||||
}
|
||||
|
||||
@@ -48,6 +59,13 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
||||
this.update(lambdaUpdateWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProcessBynDid(String nDid, Integer processId) {
|
||||
LambdaUpdateWrapper<CsEquipmentDeliveryPO> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||
lambdaUpdateWrapper.set(CsEquipmentDeliveryPO::getProcess,processId).eq(CsEquipmentDeliveryPO::getNdid,nDid);
|
||||
this.update(lambdaUpdateWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CsEquipmentDeliveryVO queryEquipmentBynDid(String nDid) {
|
||||
CsEquipmentDeliveryVO result = new CsEquipmentDeliveryVO();
|
||||
@@ -74,4 +92,72 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
||||
this.update(lambdaUpdateWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CsEquipmentDeliveryPO> getOnlineDev() {
|
||||
List<CsEquipmentDeliveryPO> result = new ArrayList<>();
|
||||
List<CsEquipmentDeliveryPO> list = this.lambdaQuery()
|
||||
.ne(CsEquipmentDeliveryPO::getRunStatus,AccessEnum.DEL.getCode())
|
||||
.eq(CsEquipmentDeliveryPO::getUsageStatus,1)
|
||||
.list();
|
||||
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> 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();
|
||||
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.eq("run_status", 2);
|
||||
wrapper.isNotNull("node_id");
|
||||
return baseMapper.selectObjs(wrapper)
|
||||
.stream()
|
||||
.map(obj -> (String) obj)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,11 @@ public class CsLedgerServiceImpl extends ServiceImpl<CsLedgerMapper, CsLedger> i
|
||||
csLedger.setPid("0");
|
||||
csLedger.setPids("0");
|
||||
} else {
|
||||
csLedger.setPids(fatherCsLedger.getPids() + "," + csLedgerParam.getPid());
|
||||
if (Objects.isNull(fatherCsLedger)) {
|
||||
csLedger.setPids("0");
|
||||
} else {
|
||||
csLedger.setPids(fatherCsLedger.getPids() + "," + csLedgerParam.getPid());
|
||||
}
|
||||
}
|
||||
this.save(csLedger);
|
||||
return csLedger;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.njcn.access.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.access.mapper.CsSoftInfoMapper;
|
||||
import com.njcn.access.pojo.po.CsSoftInfoPO;
|
||||
import com.njcn.access.service.ICsSoftInfoService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 系统软件表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author xuyang
|
||||
* @since 2023-08-09
|
||||
*/
|
||||
@Service
|
||||
public class CsSoftInfoServiceImpl extends ServiceImpl<CsSoftInfoMapper, CsSoftInfoPO> implements ICsSoftInfoService {
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.njcn;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class BatchProcessing {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 创建包含10000条数据的列表
|
||||
List<Integer> dataList = new ArrayList<>();
|
||||
for (int i = 1; i <= 20000; i++) {
|
||||
dataList.add(i);
|
||||
}
|
||||
|
||||
// 将数据分成10个子列表,每个子列表包含1000条数据
|
||||
List<List<Integer>> batches = new ArrayList<>();
|
||||
int batchSize = 1000;
|
||||
int batchCount = dataList.size() / batchSize;
|
||||
for (int i = 0; i < batchCount; i++) {
|
||||
int fromIndex = i * batchSize;
|
||||
int toIndex = fromIndex + batchSize;
|
||||
List<Integer> batch = dataList.subList(fromIndex, toIndex);
|
||||
batches.add(batch);
|
||||
}
|
||||
|
||||
// 使用多线程并发处理每个子列表
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(10);
|
||||
for (List<Integer> batch : batches) {
|
||||
executorService.submit(() -> processBatch(batch));
|
||||
}
|
||||
executorService.shutdown();
|
||||
}
|
||||
|
||||
private static void processBatch(List<Integer> batch) {
|
||||
for (Integer data : batch) {
|
||||
// 处理数据的逻辑
|
||||
System.out.println(Thread.currentThread().getName() + ": processing data " + data);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,11 +8,36 @@
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<name>rt-api</name>
|
||||
<artifactId>rt-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<name>rt-api</name>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-db</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-microservice</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-mq</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.njcn.rt.api;
|
||||
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
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
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.CS_RT_BOOT, path = "/rtData", fallbackFactory = RtClientFallbackFactory.class,contextId = "rtData")
|
||||
public interface RtFeignClient {
|
||||
|
||||
@PostMapping("/rtAnalysis")
|
||||
HttpResult<String> analysis(AppAutoDataMessage appAutoDataMessage);
|
||||
|
||||
@PostMapping("/apfRtAnalysis")
|
||||
HttpResult<Map<String,Float>> apfRtAnalysis(@RequestBody @Validated AppAutoDataMessage appAutoDataMessage);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.njcn.rt.api.fallback;
|
||||
|
||||
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.AppAutoDataMessage;
|
||||
import com.njcn.rt.api.RtFeignClient;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class RtClientFallbackFactory implements FallbackFactory<RtFeignClient> {
|
||||
@Override
|
||||
public RtFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if (cause.getCause() instanceof BusinessException) {
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new RtFeignClient() {
|
||||
|
||||
@Override
|
||||
public HttpResult<String> analysis(AppAutoDataMessage appAutoDataMessage) {
|
||||
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);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.njcn.rt.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @date 2023年04月17日 10:50
|
||||
*/
|
||||
@Getter
|
||||
public enum RtResponseEnum {
|
||||
|
||||
/**
|
||||
* A1001 ~ A1099 用于实时数据模块的枚举
|
||||
* <p>
|
||||
*/
|
||||
RT_ERROR("A10001","实时数据模块错误"),
|
||||
|
||||
DATA_ARRAY_NULL("A10002","详细数据为空"),
|
||||
AUTO_DATA_NULL("A10002","上送数据为空"),
|
||||
DICT_NULL("A10002","字典数据为空"),
|
||||
LINE_NULL("A10002","监测点为空"),
|
||||
|
||||
ARRAY_DATA_NOT_MATCH("A10003","上送数据与模板匹配失败"),
|
||||
|
||||
;
|
||||
|
||||
private final String code;
|
||||
|
||||
private final String message;
|
||||
|
||||
RtResponseEnum(String code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
package com.njcn.rt.pojo.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 实时数据-基础数据
|
||||
*/
|
||||
@Data
|
||||
public class BaseRealDataSet implements Serializable {
|
||||
|
||||
@ApiModelProperty("用户ID")
|
||||
private String userId;
|
||||
|
||||
@ApiModelProperty("结果(仅超时使用)")
|
||||
private boolean result = true;
|
||||
|
||||
@ApiModelProperty("描述")
|
||||
private String content;
|
||||
|
||||
@ApiModelProperty("监测点id")
|
||||
private String lineId;
|
||||
|
||||
@ApiModelProperty("数据时间")
|
||||
private String dataTime;
|
||||
|
||||
@ApiModelProperty("pt")
|
||||
private Float pt;
|
||||
|
||||
@ApiModelProperty("ct")
|
||||
private Float ct;
|
||||
|
||||
@ApiModelProperty("数据类型 Primary-一次值 Secondary-二次值")
|
||||
private String dataLevel;
|
||||
|
||||
@ApiModelProperty("频率")
|
||||
private Float freq;
|
||||
|
||||
@ApiModelProperty("频率偏差")
|
||||
private Float freqDev;
|
||||
|
||||
@ApiModelProperty("A相-电压有效值")
|
||||
private Float vRmsA;
|
||||
|
||||
@ApiModelProperty("B相-电压有效值")
|
||||
private Float vRmsB;
|
||||
|
||||
@ApiModelProperty("C相-电压有效值")
|
||||
private Float vRmsC;
|
||||
|
||||
// @ApiModelProperty("A相-相电压有效值")
|
||||
// private Float vuRmsA;
|
||||
//
|
||||
// @ApiModelProperty("B相-相电压有效值")
|
||||
// private Float vuRmsB;
|
||||
//
|
||||
// @ApiModelProperty("C相-相电压有效值")
|
||||
// private Float vuRmsC;
|
||||
//
|
||||
// @ApiModelProperty("A相-线电压有效值")
|
||||
// private Float vlRmsA;
|
||||
//
|
||||
// @ApiModelProperty("B相-线电压有效值")
|
||||
// private Float vlRmsB;
|
||||
//
|
||||
// @ApiModelProperty("C相-线电压有效值")
|
||||
// private Float vlRmsC;
|
||||
|
||||
@ApiModelProperty("A相-基波电压幅值")
|
||||
private Float v1A;
|
||||
|
||||
@ApiModelProperty("B相-基波电压幅值")
|
||||
private Float v1B;
|
||||
|
||||
@ApiModelProperty("C相-基波电压幅值")
|
||||
private Float v1C;
|
||||
|
||||
@ApiModelProperty("A相-电流有效值")
|
||||
private Float iRmsA;
|
||||
|
||||
@ApiModelProperty("B相-电流有效值")
|
||||
private Float iRmsB;
|
||||
|
||||
@ApiModelProperty("C相-电流有效值")
|
||||
private Float iRmsC;
|
||||
|
||||
@ApiModelProperty("A相-基波电流幅值")
|
||||
private Float i1A;
|
||||
|
||||
@ApiModelProperty("B相-基波电流幅值")
|
||||
private Float i1B;
|
||||
|
||||
@ApiModelProperty("C相-基波电流幅值")
|
||||
private Float i1C;
|
||||
|
||||
@ApiModelProperty("A相-电压偏差")
|
||||
private Float vDevA;
|
||||
|
||||
@ApiModelProperty("B相-电压偏差")
|
||||
private Float vDevB;
|
||||
|
||||
@ApiModelProperty("C相-电压偏差")
|
||||
private Float vDevC;
|
||||
|
||||
@ApiModelProperty("A相-基波电压相位")
|
||||
private Float v1AngA;
|
||||
|
||||
@ApiModelProperty("B相-基波电压相位")
|
||||
private Float v1AngB;
|
||||
|
||||
@ApiModelProperty("C相-基波电压相位")
|
||||
private Float v1AngC;
|
||||
|
||||
@ApiModelProperty("A相-基波电流相位")
|
||||
private Float i1AngA;
|
||||
|
||||
@ApiModelProperty("B相-基波电流相位")
|
||||
private Float i1AngB;
|
||||
|
||||
@ApiModelProperty("C相-基波电流相位")
|
||||
private Float i1AngC;
|
||||
|
||||
@ApiModelProperty("A相-电压总谐波畸变率")
|
||||
private Float vThdA;
|
||||
|
||||
@ApiModelProperty("B相-电压总谐波畸变率")
|
||||
private Float vThdB;
|
||||
|
||||
@ApiModelProperty("C相-电压总谐波畸变率")
|
||||
private Float vThdC;
|
||||
|
||||
@ApiModelProperty("A相-电流总谐波畸变率")
|
||||
private Float iThdA;
|
||||
|
||||
@ApiModelProperty("B相-电流总谐波畸变率")
|
||||
private Float iThdB;
|
||||
|
||||
@ApiModelProperty("C相-电流总谐波畸变率")
|
||||
private Float iThdC;
|
||||
|
||||
@ApiModelProperty("电压不平衡度")
|
||||
private Float vUnbalance;
|
||||
|
||||
@ApiModelProperty("电流不平衡度")
|
||||
private Float iUnbalance;
|
||||
|
||||
@ApiModelProperty("A相-有功功率")
|
||||
private Float pA;
|
||||
|
||||
@ApiModelProperty("B相-有功功率")
|
||||
private Float pB;
|
||||
|
||||
@ApiModelProperty("C相-有功功率")
|
||||
private Float pC;
|
||||
|
||||
@ApiModelProperty("A相-无功功率")
|
||||
private Float qA;
|
||||
|
||||
@ApiModelProperty("B相-无功功率")
|
||||
private Float qB;
|
||||
|
||||
@ApiModelProperty("C相-无功功率")
|
||||
private Float qC;
|
||||
|
||||
@ApiModelProperty("A相-视在功率")
|
||||
private Float sA;
|
||||
|
||||
@ApiModelProperty("B相-视在功率")
|
||||
private Float sB;
|
||||
|
||||
@ApiModelProperty("C相-视在功率")
|
||||
private Float sC;
|
||||
|
||||
@ApiModelProperty("A相-功率因数")
|
||||
private Float pfA;
|
||||
|
||||
@ApiModelProperty("B相-功率因数")
|
||||
private Float pfB;
|
||||
|
||||
@ApiModelProperty("C相-功率因数")
|
||||
private Float pfC;
|
||||
|
||||
@ApiModelProperty("A相-基波功率因数")
|
||||
private Float dpfA;
|
||||
|
||||
@ApiModelProperty("B相-基波功率因数")
|
||||
private Float dpfB;
|
||||
|
||||
@ApiModelProperty("C相-基波功率因数")
|
||||
private Float dpfC;
|
||||
|
||||
@ApiModelProperty("总-有功功率")
|
||||
private Float pTot;
|
||||
|
||||
@ApiModelProperty("总-无功功率")
|
||||
private Float qTot;
|
||||
|
||||
@ApiModelProperty("总-视在功率")
|
||||
private Float sTot;
|
||||
|
||||
@ApiModelProperty("总-功率因数")
|
||||
private Float pfTot;
|
||||
|
||||
@ApiModelProperty("总-基波功率因数")
|
||||
private Float dpfTot;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.njcn.rt.pojo.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Data
|
||||
public class HarmData implements Serializable {
|
||||
|
||||
@ApiModelProperty("指标名称")
|
||||
private String harmName;
|
||||
|
||||
@ApiModelProperty("相别")
|
||||
private String phase;
|
||||
|
||||
@ApiModelProperty("数据")
|
||||
private Float data;
|
||||
|
||||
@ApiModelProperty("排序")
|
||||
private Integer sort;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.njcn.rt.pojo.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 实时数据-谐波数据
|
||||
* @author xy
|
||||
*/
|
||||
@Data
|
||||
public class HarmRealDataSet implements Serializable {
|
||||
|
||||
@ApiModelProperty("用户ID")
|
||||
private String userId;
|
||||
|
||||
@ApiModelProperty("监测点id")
|
||||
private String lineId;
|
||||
|
||||
@ApiModelProperty("数据时间")
|
||||
private String dataTime;
|
||||
|
||||
@ApiModelProperty("pt")
|
||||
private Float pt;
|
||||
|
||||
@ApiModelProperty("ct")
|
||||
private Float ct;
|
||||
|
||||
@ApiModelProperty("数据类型 Primary-一次值 Secondary-二次值")
|
||||
private String dataLevel;
|
||||
|
||||
private Float data1;
|
||||
private Float data2;
|
||||
private Float data3;
|
||||
private Float data4;
|
||||
private Float data5;
|
||||
private Float data6;
|
||||
private Float data7;
|
||||
private Float data8;
|
||||
private Float data9;
|
||||
private Float data10;
|
||||
private Float data11;
|
||||
private Float data12;
|
||||
private Float data13;
|
||||
private Float data14;
|
||||
private Float data15;
|
||||
private Float data16;
|
||||
private Float data17;
|
||||
private Float data18;
|
||||
private Float data19;
|
||||
private Float data20;
|
||||
private Float data21;
|
||||
private Float data22;
|
||||
private Float data23;
|
||||
private Float data24;
|
||||
private Float data25;
|
||||
private Float data26;
|
||||
private Float data27;
|
||||
private Float data28;
|
||||
private Float data29;
|
||||
private Float data30;
|
||||
private Float data31;
|
||||
private Float data32;
|
||||
private Float data33;
|
||||
private Float data34;
|
||||
private Float data35;
|
||||
private Float data36;
|
||||
private Float data37;
|
||||
private Float data38;
|
||||
private Float data39;
|
||||
private Float data40;
|
||||
private Float data41;
|
||||
private Float data42;
|
||||
private Float data43;
|
||||
private Float data44;
|
||||
private Float data45;
|
||||
private Float data46;
|
||||
private Float data47;
|
||||
private Float data48;
|
||||
private Float data49;
|
||||
private Float data50;
|
||||
|
||||
}
|
||||
@@ -40,6 +40,27 @@
|
||||
<artifactId>common-db</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>common-mq</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>rt-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>cs-device-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>access-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
|
||||
|
||||
/**
|
||||
@@ -13,6 +14,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
* @date 2021年12月09日 20:59
|
||||
*/
|
||||
@Slf4j
|
||||
@DependsOn("proxyMapperRegister")
|
||||
@MapperScan("com.njcn.**.mapper")
|
||||
@EnableFeignClients(basePackages = "com.njcn")
|
||||
@SpringBootApplication(scanBasePackages = "com.njcn")
|
||||
|
||||
@@ -5,6 +5,8 @@ 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.AppAutoDataMessage;
|
||||
import com.njcn.rt.service.IRtService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
@@ -17,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;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
@@ -31,16 +35,26 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@AllArgsConstructor
|
||||
public class RtController extends BaseController {
|
||||
|
||||
// @OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
// @PostMapping("/analysis")
|
||||
// @ApiOperation("数据解析")
|
||||
// @ApiImplicitParam(name = "csDataEffectiveAddParm", value = "新增app数据有效性表参数", required = true)
|
||||
// public HttpResult<Boolean> addDataEffective(@RequestBody @Validated CsDataEffectiveAddParm csDataEffectiveAddParm){
|
||||
// String methodDescribe = getMethodDescribe("addDataEffective");
|
||||
//
|
||||
// boolean save = csDataEffectiveService.add (csDataEffectiveAddParm);
|
||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, save, methodDescribe);
|
||||
// }
|
||||
private final IRtService rtService;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/rtAnalysis")
|
||||
@ApiOperation("实时数据解析")
|
||||
@ApiImplicitParam(name = "appAutoDataMessage", value = "数据实体", required = true)
|
||||
public HttpResult<String> analysis(@RequestBody @Validated AppAutoDataMessage appAutoDataMessage){
|
||||
String methodDescribe = getMethodDescribe("analysis");
|
||||
rtService.analysis(appAutoDataMessage);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.njcn.rt.service;
|
||||
|
||||
import com.njcn.mq.message.AppAutoDataMessage;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
public interface IRtService {
|
||||
|
||||
void analysis(AppAutoDataMessage appAutoDataMessage);
|
||||
|
||||
/**
|
||||
* APF数据解析
|
||||
* @param appAutoDataMessage
|
||||
*/
|
||||
void apfRtAnalysis(AppAutoDataMessage appAutoDataMessage);
|
||||
}
|
||||
@@ -0,0 +1,379 @@
|
||||
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.pojo.po.CsDataArray;
|
||||
import com.njcn.csdevice.pojo.po.CsDataSet;
|
||||
import com.njcn.csdevice.pojo.po.CsLinePO;
|
||||
import com.njcn.mq.message.AppAutoDataMessage;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.rt.enums.RtResponseEnum;
|
||||
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;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.function.BinaryOperator;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class RtServiceImpl implements IRtService {
|
||||
|
||||
private final CsLineFeignClient csLineFeignClient;
|
||||
private final DataSetFeignClient dataSetFeignClient;
|
||||
private final DataArrayFeignClient dataArrayFeignClient;
|
||||
private final RedisUtil redisUtil;
|
||||
private final ChannelObjectUtil channelObjectUtil;
|
||||
private final MqttPublisher publisher;
|
||||
private final RedisSetUtil redisSetUtil;
|
||||
|
||||
@Override
|
||||
public void analysis(AppAutoDataMessage appAutoDataMessage) {
|
||||
List<CsDataArray> dataArrayList;
|
||||
//监测点id
|
||||
String lineId = appAutoDataMessage.getId() + appAutoDataMessage.getMsg().getClDid();
|
||||
redisUtil.delete("cldRtDataOverTime:"+lineId);
|
||||
//获取监测点基础信息
|
||||
CsLinePO po = csLineFeignClient.getById(lineId).getData();
|
||||
//获取数据集 dataSet
|
||||
Integer idx = appAutoDataMessage.getMsg().getDsNameIdx();
|
||||
CsDataSet dataSet = dataSetFeignClient.getDataSetByIdx(po.getDataModelId(),idx).getData();
|
||||
//根据数据集获取指标 dataArray
|
||||
//实时数据数据集不区分最大最小类型,因此数据集取平均值用于解析
|
||||
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);
|
||||
//fixme 这边先根据数据集的名称来返回对应实体,这边感觉不太合适,后期有好方案再调整
|
||||
//基础数据
|
||||
if (dataSet.getName().contains("Ds$Pqd$Rt$Basic$")) {
|
||||
//用户Id
|
||||
String userId = redisUtil.getObjectByKey("rtDataUserId:"+lineId).toString();
|
||||
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);
|
||||
} else if (dataSet.getName().contains("实时数据")) {
|
||||
//用户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());
|
||||
baseRealDataSet.setUserId(userId);
|
||||
baseRealDataSet.setLineId(lineId);
|
||||
baseRealDataSet.setPt(po.getPtRatio().floatValue());
|
||||
baseRealDataSet.setCt(po.getCtRatio().floatValue());
|
||||
baseRealDataSet.setDataLevel(dataSet.getDataLevel());
|
||||
long timestamp = item.getDataTimeSec();
|
||||
baseRealDataSet.setDataTime(getTime(timestamp));
|
||||
publisher.send("/Web/RealData/" + userId, new Gson().toJson(baseRealDataSet), 1, false);
|
||||
});
|
||||
}
|
||||
}
|
||||
//fixme 目前实时数据只有基础数据和谐波数据,后期拓展,这边需要再判断
|
||||
else {
|
||||
long timestamp;
|
||||
//用户Id
|
||||
String userId = redisUtil.getObjectByKey("rtDataUserId:"+lineId).toString();
|
||||
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());
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间处理
|
||||
*/
|
||||
public String getTime(long timestamp) {
|
||||
Instant instant = Instant.ofEpochSecond(timestamp);
|
||||
LocalDateTime dateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
return dateTime.format(formatter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存实时数据数据集
|
||||
* @param key
|
||||
* @param dataSetId
|
||||
* @return
|
||||
*/
|
||||
public List<CsDataArray> saveBaseRealDataSet(String key, String dataSetId) {
|
||||
List<CsDataArray> dataArrays = dataArrayFeignClient.getArrayBySet(dataSetId).getData();
|
||||
List<CsDataArray> dataArrayList = dataArrays.stream().filter(item->Objects.equals(item.getStatMethod(),"avg")).collect(Collectors.toList());
|
||||
redisUtil.saveByKeyWithExpire(key,dataArrayList,600L);
|
||||
return dataArrayList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据解码
|
||||
* @return
|
||||
*/
|
||||
public Map<String,Float> getData(List<CsDataArray> dataArrayList,AppAutoDataMessage.DataArray dataArray) {
|
||||
Map<String,Float> dataMap = new LinkedHashMap<>();
|
||||
//解码
|
||||
List<Float> floats = PubUtils.byteArrayToFloatList(Base64.getDecoder().decode(dataArray.getData()));
|
||||
if (CollectionUtil.isEmpty(floats)){
|
||||
throw new BusinessException(RtResponseEnum.AUTO_DATA_NULL);
|
||||
}
|
||||
//校验模板和解码数据数量能否对应上
|
||||
if (!Objects.equals(dataArrayList.size(),floats.size())){
|
||||
throw new BusinessException(RtResponseEnum.ARRAY_DATA_NOT_MATCH);
|
||||
}
|
||||
for (int i = 0; i < dataArrayList.size(); i++) {
|
||||
dataMap.put(dataArrayList.get(i).getName() + dataArrayList.get(i).getPhase(),floats.get(i));
|
||||
}
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
public BaseRealDataSet assembleData(List<CsDataArray> dataArrayList,AppAutoDataMessage.DataArray dataArray,Integer conType) {
|
||||
Map<String,Float> dataMap = getData(dataArrayList,dataArray);
|
||||
return channelData(dataMap,conType);
|
||||
}
|
||||
|
||||
public BaseRealDataSet channelData(Map<String,Float> map,Integer conType) {
|
||||
BaseRealDataSet baseRealDataSet = new BaseRealDataSet();
|
||||
//频率
|
||||
baseRealDataSet.setFreq(FloatUtils.get2Float(map.get("Pq_FreqM")));
|
||||
//频率偏差
|
||||
baseRealDataSet.setFreqDev(FloatUtils.get2Float(map.get("Pq_FreqDevM")));
|
||||
//判断监测点的接线方式,不同接线方式电压有效值取值不同
|
||||
//星型-相电压 角形、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")));
|
||||
} 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.setV1A(FloatUtils.get2Float(map.get("Pq_RmsFundUA")));
|
||||
baseRealDataSet.setV1B(FloatUtils.get2Float(map.get("Pq_RmsFundUB")));
|
||||
baseRealDataSet.setV1C(FloatUtils.get2Float(map.get("Pq_RmsFundUC")));
|
||||
//电流有效值
|
||||
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.setI1A(FloatUtils.get2Float(map.get("Pq_RmsFundIA")));
|
||||
baseRealDataSet.setI1B(FloatUtils.get2Float(map.get("Pq_RmsFundIB")));
|
||||
baseRealDataSet.setI1C(FloatUtils.get2Float(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")));
|
||||
//基波电压相位
|
||||
baseRealDataSet.setV1AngA(FloatUtils.get2Float(map.get("Pq_FundUAngA")));
|
||||
baseRealDataSet.setV1AngB(FloatUtils.get2Float(map.get("Pq_FundUAngB")));
|
||||
baseRealDataSet.setV1AngC(FloatUtils.get2Float(map.get("Pq_FundUAngC")));
|
||||
//基波电流相位
|
||||
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.setVThdA(FloatUtils.get2Float(map.get("Pq_ThdUA")));
|
||||
baseRealDataSet.setVThdB(FloatUtils.get2Float(map.get("Pq_ThdUB")));
|
||||
baseRealDataSet.setVThdC(FloatUtils.get2Float(map.get("Pq_ThdUC")));
|
||||
//电流总谐波畸变率
|
||||
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.setVUnbalance(FloatUtils.get2Float(map.get("Pq_UnbalNegUM")));
|
||||
//电流不平衡度
|
||||
baseRealDataSet.setIUnbalance(FloatUtils.get2Float(map.get("Pq_UnbalNegIM")));
|
||||
//有功功率
|
||||
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.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.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")));
|
||||
return baseRealDataSet;
|
||||
}
|
||||
|
||||
public HarmRealDataSet harmData(List<CsDataArray> dataArrayList, AppAutoDataMessage.DataArray dataArray, String dataLevel, Double ct) {
|
||||
HarmRealDataSet harmRealDataSet = new HarmRealDataSet();
|
||||
List<HarmData> harmDataList = new ArrayList<>();
|
||||
//解码
|
||||
List<Float> floats = PubUtils.byteArrayToFloatList(Base64.getDecoder().decode(dataArray.getData()));
|
||||
if (CollectionUtil.isEmpty(floats)){
|
||||
throw new BusinessException(RtResponseEnum.AUTO_DATA_NULL);
|
||||
}
|
||||
//校验模板和解码数据数量能否对应上
|
||||
if (!Objects.equals(dataArrayList.size(),floats.size())){
|
||||
throw new BusinessException(RtResponseEnum.ARRAY_DATA_NOT_MATCH);
|
||||
}
|
||||
for (int i = 0; i < dataArrayList.size(); i++) {
|
||||
HarmData harmData = new HarmData();
|
||||
harmData.setHarmName(dataArrayList.get(i).getName());
|
||||
harmData.setPhase(dataArrayList.get(i).getPhase());
|
||||
harmData.setSort(dataArrayList.get(i).getSort());
|
||||
harmData.setData(floats.get(i));
|
||||
harmDataList.add(harmData);
|
||||
}
|
||||
//根据名称分组,然后在不同相别的数据中取最大值
|
||||
List<HarmData> maxDataList = new ArrayList<>(harmDataList.stream()
|
||||
.collect(Collectors.toMap(
|
||||
HarmData::getHarmName,
|
||||
Function.identity(),
|
||||
BinaryOperator.maxBy(Comparator.comparingDouble(HarmData::getData))
|
||||
))
|
||||
.values());
|
||||
//通过反射将数据赋值
|
||||
Class<?> clazz = HarmRealDataSet.class;
|
||||
maxDataList.forEach(item->{
|
||||
if (Objects.equals(item.getHarmName(),"Pq_RmsFundI")) {
|
||||
if ("Secondary".equals(dataLevel)) {
|
||||
double data = item.getData() * ct;
|
||||
harmRealDataSet.setData1(FloatUtils.get2Float((float)data));
|
||||
} else {
|
||||
harmRealDataSet.setData1(FloatUtils.get2Float(item.getData()));
|
||||
}
|
||||
} else if (Objects.equals(item.getHarmName(),"Pq_RmsFundU")) {
|
||||
harmRealDataSet.setData1(FloatUtils.get2Float(item.getData()));
|
||||
} else if (Objects.equals(item.getHarmName(),"Pq_ThdU")) {
|
||||
harmRealDataSet.setData1(FloatUtils.get2Float(item.getData()));
|
||||
} else {
|
||||
String numberStr = item.getHarmName().substring(item.getHarmName().lastIndexOf('_') + 1);
|
||||
String fieldName = "data" + numberStr;
|
||||
try {
|
||||
Field field = clazz.getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
if (item.getHarmName().contains("Pq_HarmI_")) {
|
||||
if ("Secondary".equals(dataLevel)) {
|
||||
double data = item.getData() * ct;
|
||||
field.set(harmRealDataSet,FloatUtils.get2Float((float)data));
|
||||
} else {
|
||||
field.set(harmRealDataSet,FloatUtils.get2Float(item.getData()));
|
||||
}
|
||||
} else {
|
||||
field.set(harmRealDataSet,FloatUtils.get2Float(item.getData()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
return harmRealDataSet;
|
||||
}
|
||||
|
||||
private Set<String> convertObjectToSetSafe(Object obj) {
|
||||
if (obj == null) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
if (obj instanceof Set) {
|
||||
// 类型安全的转换
|
||||
Set<?> rawSet = (Set<?>) obj;
|
||||
return rawSet.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.toSet());
|
||||
} else if (obj instanceof Collection) {
|
||||
return ((Collection<?>) obj).stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.toSet());
|
||||
} else {
|
||||
log.warn("Redis中的对象类型不是Set或Collection: {}", obj.getClass().getName());
|
||||
return new HashSet<>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,67 +1,67 @@
|
||||
package com.njcn.stat.listener;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.stat.enums.StatResponseEnum;
|
||||
import com.njcn.system.api.EpdFeignClient;
|
||||
import com.njcn.system.pojo.dto.EpdDTO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.data.redis.connection.Message;
|
||||
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
|
||||
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2022年04月02日 14:31
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {
|
||||
|
||||
@Resource
|
||||
private EpdFeignClient epdFeignClient;
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
|
||||
super(listenerContainer);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 针对redis数据失效事件,进行数据处理
|
||||
* 注意message.toString()可以获取失效的key
|
||||
*/
|
||||
@Override
|
||||
@Order(0)
|
||||
public void onMessage(Message message, byte[] pattern) {
|
||||
if (StringUtils.isBlank(message.toString())) {
|
||||
return;
|
||||
}
|
||||
//判断失效的key
|
||||
String expiredKey = message.toString();
|
||||
if(expiredKey.equals(AppRedisKey.ELE_EPD_PQD)){
|
||||
Map<String,String> map = new HashMap<>();
|
||||
List<EpdDTO> list = epdFeignClient.findAll().getData();
|
||||
if (CollectionUtil.isEmpty(list)){
|
||||
throw new BusinessException(StatResponseEnum.DICT_NULL);
|
||||
}
|
||||
list.forEach(item->{
|
||||
map.put(item.getDictName(),item.getTableName());
|
||||
});
|
||||
redisUtil.saveByKeyWithExpire(AppRedisKey.ELE_EPD_PQD,map,3600L);
|
||||
}
|
||||
}
|
||||
}
|
||||
//package com.njcn.stat.listener;
|
||||
//
|
||||
//import cn.hutool.core.collection.CollectionUtil;
|
||||
//import com.njcn.common.pojo.exception.BusinessException;
|
||||
//import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
//import com.njcn.redis.utils.RedisUtil;
|
||||
//import com.njcn.stat.enums.StatResponseEnum;
|
||||
//import com.njcn.system.api.EpdFeignClient;
|
||||
//import com.njcn.system.pojo.dto.EpdDTO;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.apache.commons.lang3.StringUtils;
|
||||
//import org.springframework.core.annotation.Order;
|
||||
//import org.springframework.data.redis.connection.Message;
|
||||
//import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
|
||||
//import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import javax.annotation.Resource;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//
|
||||
///**
|
||||
// * @author hongawen
|
||||
// * @version 1.0.0
|
||||
// * @date 2022年04月02日 14:31
|
||||
// */
|
||||
//@Slf4j
|
||||
//@Component
|
||||
//public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {
|
||||
//
|
||||
// @Resource
|
||||
// private EpdFeignClient epdFeignClient;
|
||||
//
|
||||
// @Resource
|
||||
// private RedisUtil redisUtil;
|
||||
//
|
||||
// public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
|
||||
// super(listenerContainer);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 针对redis数据失效事件,进行数据处理
|
||||
// * 注意message.toString()可以获取失效的key
|
||||
// */
|
||||
// @Override
|
||||
// @Order(0)
|
||||
// public void onMessage(Message message, byte[] pattern) {
|
||||
// if (StringUtils.isBlank(message.toString())) {
|
||||
// return;
|
||||
// }
|
||||
// //判断失效的key
|
||||
// String expiredKey = message.toString();
|
||||
// if(expiredKey.equals(AppRedisKey.ELE_EPD_PQD)){
|
||||
// Map<String,String> map = new HashMap<>();
|
||||
// List<EpdDTO> list = epdFeignClient.findAll().getData();
|
||||
// if (CollectionUtil.isEmpty(list)){
|
||||
// throw new BusinessException(StatResponseEnum.DICT_NULL);
|
||||
// }
|
||||
// list.forEach(item->{
|
||||
// map.put(item.getDictName(),item.getTableName());
|
||||
// });
|
||||
// redisUtil.saveByKeyWithExpire(AppRedisKey.ELE_EPD_PQD,map,3600L);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -2,17 +2,17 @@ package com.njcn.stat.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.njcn.access.api.CsLineLatestDataFeignClient;
|
||||
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.CsLineFeignClient;
|
||||
import com.njcn.csdevice.api.DataArrayFeignClient;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
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.csdevice.pojo.vo.CsEquipmentDeliveryVO;
|
||||
import com.njcn.cswarn.api.CsEquipmentAlarmFeignClient;
|
||||
import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
|
||||
import com.njcn.influx.utils.InfluxDbUtils;
|
||||
import com.njcn.mq.message.AppAutoDataMessage;
|
||||
@@ -21,11 +21,9 @@ import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.stat.enums.StatResponseEnum;
|
||||
import com.njcn.stat.service.IStatService;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.api.DictTreeFeignClient;
|
||||
import com.njcn.system.api.EpdFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.pojo.dto.EpdDTO;
|
||||
import com.njcn.system.pojo.po.DictData;
|
||||
import com.njcn.system.pojo.po.SysDicTreePO;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.influxdb.InfluxDB;
|
||||
@@ -34,6 +32,9 @@ 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.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -50,24 +51,17 @@ import java.util.concurrent.TimeUnit;
|
||||
public class StatServiceImpl implements IStatService {
|
||||
|
||||
private final DataArrayFeignClient dataArrayFeignClient;
|
||||
|
||||
private final EpdFeignClient epdFeignClient;
|
||||
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
|
||||
private final InfluxDbUtils influxDbUtils;
|
||||
|
||||
private final CsLineFeignClient csLineFeignClient;
|
||||
|
||||
private final RedisUtil redisUtil;
|
||||
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
|
||||
private final DictTreeFeignClient dictTreeFeignClient;
|
||||
private final ChannelObjectUtil channelObjectUtil;
|
||||
private final CsLineLatestDataFeignClient csLineLatestDataFeignClient;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void analysis(AppAutoDataMessage appAutoDataMessage) {
|
||||
LocalDateTime time = null;
|
||||
log.info("开始消费{},发送时间{}",appAutoDataMessage.getKey(),appAutoDataMessage.getSendTime());
|
||||
//1.根据设备网络识别码获取设备id,查询到所用的模板,用来判断模板的类型(治理模板还是电能质量模板)
|
||||
//2.解析appAutoDataMessage的Did,来判断当前数据是治理数据还是电能质量数据
|
||||
@@ -78,6 +72,7 @@ public class StatServiceImpl implements IStatService {
|
||||
dataArrayParam.setId(appAutoDataMessage.getId());
|
||||
dataArrayParam.setDid(appAutoDataMessage.getDid());
|
||||
dataArrayParam.setCldId(appAutoDataMessage.getMsg().getClDid());
|
||||
dataArrayParam.setIdx(appAutoDataMessage.getMsg().getDsNameIdx());
|
||||
List<AppAutoDataMessage.DataArray> list = appAutoDataMessage.getMsg().getDataArray();
|
||||
//获取监测点id
|
||||
String lineId = null;
|
||||
@@ -86,61 +81,78 @@ public class StatServiceImpl implements IStatService {
|
||||
lineInfo(appAutoDataMessage.getId());
|
||||
}
|
||||
//获取当前设备信息判断装置型号,来筛选监测点
|
||||
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(appAutoDataMessage.getId()).getData();
|
||||
String code = dictTreeFeignClient.queryById(po.getDevType()).getData().getCode();
|
||||
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 = Objects.requireNonNull(dictTreeList.stream().filter(item -> Objects.equals(item.getId(), po.getDevType())).findFirst().orElse(null)).getCode();
|
||||
|
||||
//便携式设备
|
||||
if (Objects.equals(DicDataEnum.PORTABLE.getCode(),code)) {
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appAutoDataMessage.getId())), Map.class).get(appAutoDataMessage.getMsg().getClDid().toString()).toString();
|
||||
}
|
||||
//直连设备
|
||||
else if (Objects.equals(DicDataEnum.CONNECT_DEV.getCode(),code)) {
|
||||
if (Objects.equals(appAutoDataMessage.getDid(),1)){lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appAutoDataMessage.getId())), Map.class).get("0").toString();
|
||||
} else if (Objects.equals(appAutoDataMessage.getDid(),2)){
|
||||
if (Objects.equals(appAutoDataMessage.getDid(),1)) {
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appAutoDataMessage.getId())), Map.class).get("0").toString();
|
||||
} else if (Objects.equals(appAutoDataMessage.getDid(),2)) {
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appAutoDataMessage.getId())), Map.class).get(appAutoDataMessage.getMsg().getClDid().toString()).toString();
|
||||
}
|
||||
}
|
||||
//缓存指标和influxDB表关系
|
||||
Object object2 = redisUtil.getObjectByKey(AppRedisKey.ELE_EPD_PQD);
|
||||
if(Objects.isNull(object2)) {
|
||||
saveData();
|
||||
//云前置设备
|
||||
else if (Objects.equals(DicDataEnum.DEV_CLD.getCode(),code)) {
|
||||
lineId = appAutoDataMessage.getId() + appAutoDataMessage.getMsg().getClDid();
|
||||
|
||||
}
|
||||
|
||||
//获取当前设备信息
|
||||
if (CollectionUtil.isNotEmpty(list)){
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
List<String> recordList = new ArrayList<>();
|
||||
for (AppAutoDataMessage.DataArray item : list) {
|
||||
switch (item.getDataAttr()) {
|
||||
case 1:
|
||||
log.info("{}-->处理最大值", po.getNdid());
|
||||
log.info("{}-->处理最大值", po.getNdid() + appAutoDataMessage.getDid() + appAutoDataMessage.getMsg().getClDid());
|
||||
dataArrayParam.setStatMethod("max");
|
||||
break;
|
||||
case 2:
|
||||
log.info("{}-->处理最小值", po.getNdid());
|
||||
log.info("{}-->处理最小值", po.getNdid() + appAutoDataMessage.getDid() + appAutoDataMessage.getMsg().getClDid());
|
||||
dataArrayParam.setStatMethod("min");
|
||||
break;
|
||||
case 3:
|
||||
log.info("{}-->处理avg", po.getNdid());
|
||||
log.info("{}-->处理avg", po.getNdid() + appAutoDataMessage.getDid() + appAutoDataMessage.getMsg().getClDid());
|
||||
dataArrayParam.setStatMethod("avg");
|
||||
break;
|
||||
case 4:
|
||||
log.info("{}-->处理cp95", po.getNdid());
|
||||
log.info("{}-->处理cp95", po.getNdid() + appAutoDataMessage.getDid() + appAutoDataMessage.getMsg().getClDid());
|
||||
dataArrayParam.setStatMethod("cp95");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Object object = redisUtil.getObjectByKey(appAutoDataMessage.getId() + appAutoDataMessage.getDid() + appAutoDataMessage.getMsg().getClDid());
|
||||
int clDid = Objects.equals(DicDataEnum.DEV_CLD.getCode(),code)?1:appAutoDataMessage.getMsg().getClDid();
|
||||
String key = AppRedisKey.DEV_MODEL.concat(dataArrayParam.getId() + dataArrayParam.getDid() + clDid + dataArrayParam.getStatMethod() + dataArrayParam.getIdx());
|
||||
Object object = redisUtil.getObjectByKey(key);
|
||||
List<CsDataArray> dataArrayList;
|
||||
if (Objects.isNull(object)){
|
||||
dataArrayList = saveModelData(dataArrayParam);
|
||||
dataArrayList = saveModelData(dataArrayParam,key);
|
||||
} 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);
|
||||
recordList.addAll(result);
|
||||
//获取时间
|
||||
long devTime = Objects.equals(DicDataEnum.DEV_CLD.getCode(),code)?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);
|
||||
//记录监测点最新数据时间
|
||||
CsLineLatestData csLineLatestData = new CsLineLatestData();
|
||||
csLineLatestData.setLineId(lineId);
|
||||
csLineLatestData.setTimeId(Objects.isNull(time) ? LocalDateTime.now() : time);
|
||||
csLineLatestDataFeignClient.addData(csLineLatestData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,34 +180,18 @@ public class StatServiceImpl implements IStatService {
|
||||
}
|
||||
}
|
||||
}
|
||||
redisUtil.saveByKeyWithExpire(AppRedisKey.LINE_POSITION+id,map,600L);
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存字典和influxDB表关系
|
||||
*/
|
||||
public void saveData() {
|
||||
Map<String,String> map = new HashMap<>();
|
||||
List<EpdDTO> list = epdFeignClient.findAll().getData();
|
||||
if (CollectionUtil.isEmpty(list)){
|
||||
throw new BusinessException(StatResponseEnum.DICT_NULL);
|
||||
}
|
||||
list.forEach(item->{
|
||||
map.put(item.getDictName(),item.getTableName());
|
||||
});
|
||||
redisUtil.saveByKeyWithExpire(AppRedisKey.ELE_EPD_PQD,map,3600L);
|
||||
redisUtil.saveByKey(AppRedisKey.LINE_POSITION+id,map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存设备模板信息
|
||||
*/
|
||||
public List<CsDataArray> saveModelData(DataArrayParam dataArrayParam) {
|
||||
String key = dataArrayParam.getId() + dataArrayParam.getDid() + dataArrayParam.getCldId();
|
||||
public List<CsDataArray> saveModelData(DataArrayParam dataArrayParam,String key) {
|
||||
List<CsDataArray> dataArrayList = dataArrayFeignClient.findListByParam(dataArrayParam).getData();
|
||||
if (CollectionUtil.isEmpty(dataArrayList)){
|
||||
throw new BusinessException(StatResponseEnum.DATA_ARRAY_NULL);
|
||||
}
|
||||
redisUtil.saveByKeyWithExpire(key,dataArrayList,600L);
|
||||
redisUtil.saveByKey(key,dataArrayList);
|
||||
return dataArrayList;
|
||||
}
|
||||
|
||||
@@ -203,7 +199,7 @@ 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) {
|
||||
List<String> records = new ArrayList<String>();
|
||||
//解码
|
||||
List<Float> floats = PubUtils.byteArrayToFloatList(Base64.getDecoder().decode(item.getData()));
|
||||
@@ -214,10 +210,6 @@ public class StatServiceImpl implements IStatService {
|
||||
if (!Objects.equals(dataArrayList.size(),floats.size())){
|
||||
throw new BusinessException(StatResponseEnum.ARRAY_DATA_NOT_MATCH);
|
||||
}
|
||||
//判断字典数据是否存在
|
||||
if (Objects.isNull(redisUtil.getObjectByKey(AppRedisKey.ELE_EPD_PQD))){
|
||||
saveData();
|
||||
}
|
||||
Map<String,String> map = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.ELE_EPD_PQD)), Map.class);
|
||||
for (int i = 0; i < dataArrayList.size(); i++) {
|
||||
String tableName = map.get(dataArrayList.get(i).getName());
|
||||
@@ -228,10 +220,11 @@ public class StatServiceImpl implements IStatService {
|
||||
tags.put(InfluxDBTableConstant.CL_DID,clDid.toString());
|
||||
tags.put(InfluxDBTableConstant.PROCESS,process.toString());
|
||||
Map<String,Object> fields = new HashMap<>();
|
||||
fields.put(dataArrayList.get(i).getName(),floats.get(i));
|
||||
//这边特殊处理,如果数据为3.14159,则将数据置为null
|
||||
fields.put(dataArrayList.get(i).getName(),Objects.equals(floats.get(i),3.14159f) ? null: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);
|
||||
Point point = influxDbUtils.pointBuilder(tableName, Objects.equals(DicDataEnum.DEV_CLD.getCode(),devType)?item.getDataTimeSec():item.getDataTimeSec()-8*3600, TimeUnit.SECONDS, tags, fields);
|
||||
BatchPoints batchPoints = BatchPoints.database(influxDbUtils.getDbName()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
|
||||
batchPoints.point(point);
|
||||
records.add(batchPoints.lineProtocol());
|
||||
|
||||
@@ -3,9 +3,11 @@ 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;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
@@ -15,4 +17,11 @@ public interface EventFeignClient {
|
||||
|
||||
@PostMapping("/analysis")
|
||||
HttpResult<String> analysis(AppEventMessage appEventMessage);
|
||||
|
||||
@PostMapping("/portableData")
|
||||
HttpResult<String> getPortableData(@RequestBody AppEventMessage appEventMessage);
|
||||
|
||||
@PostMapping("/cldEventData")
|
||||
HttpResult<String> getCldEventData(@RequestBody CldLogMessage cldLogMessage);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
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.zlevent.api.fallback.EvtErrorClientFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.CS_ZL_EVENT_BOOT, path = "/csDevErrEvt", fallbackFactory = EvtErrorClientFallbackFactory.class,contextId = "csDevErrEvt")
|
||||
public interface EvtErrorFeignClient {
|
||||
|
||||
@PostMapping("/errorEvent")
|
||||
HttpResult<String> insertErrorEvent(AppEventMessage appEventMessage);
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import com.njcn.mq.message.AppFileMessage;
|
||||
import com.njcn.zlevent.api.fallback.FileClientFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
@@ -19,4 +19,7 @@ public interface FileFeignClient {
|
||||
|
||||
@PostMapping("/fileStream")
|
||||
HttpResult<String> fileStream(AppFileMessage appFileMessage);
|
||||
|
||||
@PostMapping("/downloadMakeUpFile")
|
||||
HttpResult<String> downloadMakeUpFile(@RequestParam("nDid") String nDid);
|
||||
}
|
||||
|
||||
@@ -3,16 +3,20 @@ 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.zlevent.api.fallback.EventClientFallbackFactory;
|
||||
import com.njcn.zlevent.api.fallback.WaveClientFallbackFactory;
|
||||
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.CS_ZL_EVENT_BOOT, path = "/wave", fallbackFactory = EventClientFallbackFactory.class,contextId = "wave")
|
||||
@FeignClient(value = ServerInfo.CS_ZL_EVENT_BOOT, path = "/wave", fallbackFactory = WaveClientFallbackFactory.class,contextId = "wave")
|
||||
public interface WaveFeignClient {
|
||||
|
||||
@PostMapping("/analysis")
|
||||
HttpResult<String> analysis(AppEventMessage appEventMessage);
|
||||
|
||||
@PostMapping("/channelWave")
|
||||
HttpResult<String> channelWave(@RequestParam("nDid") String nDid);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -30,6 +31,19 @@ public class EventClientFallbackFactory implements FallbackFactory<EventFeignCli
|
||||
log.error("{}异常,降级处理,异常为:{}","数据解析",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<String> getPortableData(AppEventMessage appEventMessage) {
|
||||
log.error("{}异常,降级处理,异常为:{}","便携式设备数据记录动作",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<String> getCldEventData(CldLogMessage cldLogMessage) {
|
||||
log.error("{}异常,降级处理,异常为:{}","云前置事件处理",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.njcn.zlevent.api.fallback;
|
||||
|
||||
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.zlevent.api.EvtErrorFeignClient;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class EvtErrorClientFallbackFactory implements FallbackFactory<EvtErrorFeignClient> {
|
||||
@Override
|
||||
public EvtErrorFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if (cause.getCause() instanceof BusinessException) {
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new EvtErrorFeignClient() {
|
||||
|
||||
@Override
|
||||
public HttpResult<String> insertErrorEvent(AppEventMessage appEventMessage) {
|
||||
log.error("{}异常,降级处理,异常为:{}","异常事件统计",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,12 @@ public class FileClientFallbackFactory implements FallbackFactory<FileFeignClien
|
||||
log.error("{}异常,降级处理,异常为:{}","解析文件流",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<String> downloadMakeUpFile(String nDid) {
|
||||
log.error("{}异常,降级处理,异常为:{}","下载补召文件",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +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.zlevent.api.EventFeignClient;
|
||||
import com.njcn.zlevent.api.WaveFeignClient;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -14,22 +14,28 @@ import org.springframework.stereotype.Component;
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class WaveClientFallbackFactory implements FallbackFactory<EventFeignClient> {
|
||||
public class WaveClientFallbackFactory implements FallbackFactory<WaveFeignClient> {
|
||||
@Override
|
||||
public EventFeignClient create(Throwable cause) {
|
||||
public WaveFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if (cause.getCause() instanceof BusinessException) {
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new EventFeignClient() {
|
||||
return new WaveFeignClient() {
|
||||
|
||||
@Override
|
||||
public HttpResult<String> analysis(AppEventMessage appEventMessage) {
|
||||
log.error("{}异常,降级处理,异常为:{}","波形报文解析",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<String> channelWave(String nDid) {
|
||||
log.error("{}异常,降级处理,异常为:{}","处理录波事件",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.njcn.zlevent.pojo.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
@@ -16,12 +18,16 @@ import java.util.List;
|
||||
@Data
|
||||
public class FileStreamDto implements Serializable {
|
||||
|
||||
@ApiModelProperty("总帧")
|
||||
private Integer total;
|
||||
|
||||
@ApiModelProperty("nDid")
|
||||
private String nDid;
|
||||
|
||||
@ApiModelProperty("帧大小")
|
||||
private Integer frameLen;
|
||||
|
||||
private List<Integer> list;
|
||||
@ApiModelProperty("帧集合")
|
||||
private Set<Integer> list;
|
||||
|
||||
}
|
||||
|
||||
@@ -12,8 +12,15 @@ import lombok.Data;
|
||||
@Data
|
||||
public class WaveTimeDto {
|
||||
|
||||
/**
|
||||
* 文件名
|
||||
*/
|
||||
private String fileName;
|
||||
|
||||
private String deviceId;
|
||||
|
||||
private String nDid;
|
||||
|
||||
private String lineId;
|
||||
|
||||
private String startTime;
|
||||
@@ -22,4 +29,9 @@ public class WaveTimeDto {
|
||||
|
||||
private String location;
|
||||
|
||||
/**
|
||||
* 等级
|
||||
*/
|
||||
private String level;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.njcn.zlevent.pojo.param;
|
||||
|
||||
import com.njcn.web.pojo.param.BaseParam;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Data
|
||||
public class ErrorEventParam extends BaseParam {
|
||||
|
||||
private String nDid;
|
||||
|
||||
private String startTime;
|
||||
|
||||
private String endTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.njcn.zlevent.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 装置异常事件统计
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2024-09-12
|
||||
*/
|
||||
@Data
|
||||
@TableName("cs_dev_err_evt")
|
||||
public class CsDevErrEvt implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 设备识别码
|
||||
*/
|
||||
private String ndid;
|
||||
|
||||
/**
|
||||
* 事件发生时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime evtTime;
|
||||
|
||||
/**
|
||||
* 事件code编码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.njcn.zlevent.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
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.common.utils.LogUtil;
|
||||
import com.njcn.mq.message.AppEventMessage;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.zlevent.pojo.param.ErrorEventParam;
|
||||
import com.njcn.zlevent.pojo.po.CsDevErrEvt;
|
||||
import com.njcn.zlevent.service.ICsDevErrEvtService;
|
||||
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.validation.annotation.Validated;
|
||||
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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 装置异常事件统计 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2024-09-12
|
||||
*/
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("/csDevErrEvt")
|
||||
@Api(tags = "装置异常事件处理")
|
||||
@AllArgsConstructor
|
||||
public class CsDevErrEvtController extends BaseController {
|
||||
|
||||
private final ICsDevErrEvtService csDevErrEvtService;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/errorEvent")
|
||||
@ApiOperation("异常事件统计")
|
||||
@ApiImplicitParam(name = "appEventMessage", value = "数据实体", required = true)
|
||||
public HttpResult<String> insertErrorEvent(@RequestBody AppEventMessage appEventMessage){
|
||||
String methodDescribe = getMethodDescribe("insertErrorEvent");
|
||||
csDevErrEvtService.insertErrorEvent(appEventMessage);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@PostMapping("/list")
|
||||
@ApiOperation("查询异常事件列表分页")
|
||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||
public HttpResult<Page<CsDevErrEvt>> getList(@RequestBody @Validated ErrorEventParam param) {
|
||||
String methodDescribe = getMethodDescribe("getList");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, param);
|
||||
Page<CsDevErrEvt> list = csDevErrEvtService.getList(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, 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;
|
||||
@@ -28,7 +29,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/event")
|
||||
@Api(tags = "暂态事件处理")
|
||||
@Api(tags = "事件处理")
|
||||
@AllArgsConstructor
|
||||
public class EventController extends BaseController {
|
||||
|
||||
@@ -44,4 +45,24 @@ public class EventController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/portableData")
|
||||
@ApiOperation("便携式数据事件")
|
||||
@ApiImplicitParam(name = "appEventMessage", value = "数据实体", required = true)
|
||||
public HttpResult<String> getPortableData(@RequestBody AppEventMessage appEventMessage){
|
||||
String methodDescribe = getMethodDescribe("getPortableData");
|
||||
eventService.getPortableData(appEventMessage);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,10 +13,7 @@ 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 org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
@@ -54,4 +51,14 @@ public class FileController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/downloadMakeUpFile")
|
||||
@ApiOperation("下载补召文件")
|
||||
@ApiImplicitParam(name = "nDid", value = "nDid", required = true)
|
||||
public HttpResult<String> downloadMakeUpFile(@RequestParam("nDid") String nDid){
|
||||
String methodDescribe = getMethodDescribe("downloadMakeUpFile");
|
||||
fileService.downloadMakeUpFile(nDid);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,10 +13,7 @@ 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 org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
@@ -36,7 +33,7 @@ public class WaveController extends BaseController {
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/analysis")
|
||||
@ApiOperation("录波解析")
|
||||
@ApiOperation("录波事件")
|
||||
@ApiImplicitParam(name = "appEventMessage", value = "数据实体", required = true)
|
||||
public HttpResult<String> analysis(@RequestBody AppEventMessage appEventMessage){
|
||||
String methodDescribe = getMethodDescribe("analysis");
|
||||
@@ -44,4 +41,14 @@ public class WaveController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/channelWave")
|
||||
@ApiOperation("处理录波事件")
|
||||
@ApiImplicitParam(name = "nDid", value = "nDid", required = true)
|
||||
public HttpResult<String> channelWave(@RequestParam("nDid") String nDid){
|
||||
String methodDescribe = getMethodDescribe("channelWave");
|
||||
csWaveService.channelWave(nDid);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,18 +4,21 @@ import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
import com.njcn.access.api.CsTopicFeignClient;
|
||||
import com.njcn.access.enums.AccessEnum;
|
||||
import com.njcn.access.enums.TypeEnum;
|
||||
import com.njcn.access.pojo.dto.ReqAndResDto;
|
||||
import com.njcn.access.pojo.dto.file.FileRedisDto;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.stat.enums.StatResponseEnum;
|
||||
import com.njcn.system.api.EpdFeignClient;
|
||||
import com.njcn.system.pojo.dto.EpdDTO;
|
||||
import com.njcn.zlevent.pojo.dto.FileStreamDto;
|
||||
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
|
||||
import com.njcn.zlevent.service.ICsWaveAnalysisService;
|
||||
import com.njcn.zlevent.utils.RemoveInfoUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -26,10 +29,7 @@ import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
@@ -43,21 +43,23 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
|
||||
@Resource
|
||||
private EpdFeignClient epdFeignClient;
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@Resource
|
||||
private CsTopicFeignClient csTopicFeignClient;
|
||||
|
||||
@Resource
|
||||
private MqttPublisher publisher;
|
||||
@Resource
|
||||
private RemoveInfoUtils removeInfoUtils;
|
||||
@Resource
|
||||
private ICsWaveAnalysisService csWaveAnalysisService;
|
||||
@Resource
|
||||
private EquipmentFeignClient equipmentFeignClient;
|
||||
private static Integer mid = 1;
|
||||
private static Integer range = 51200;
|
||||
|
||||
public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
|
||||
super(listenerContainer);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 针对redis数据失效事件,进行数据处理
|
||||
* 注意message.toString()可以获取失效的key
|
||||
@@ -91,35 +93,175 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
int end = dto.getTotal();
|
||||
IntStream.rangeClosed(start, end)
|
||||
.filter(i -> !dto.getList().contains(i))
|
||||
.forEach(missingNumber -> {
|
||||
log.info("缺失的数字:{}",missingNumber);
|
||||
missingList.add(missingNumber);
|
||||
});
|
||||
redisUtil.saveByKey(AppRedisKey.FILE_PART_MISSING.concat(fileName), missingList);
|
||||
Integer offset = (missingList.get(0) - 1) * dto.getFrameLen();
|
||||
askMissingFileStream(dto.getNDid(),missingList.get(0),fileName,offset,dto.getFrameLen());
|
||||
.forEach(missingList::add);
|
||||
if (CollectionUtil.isNotEmpty(missingList)) {
|
||||
downloadFile(missingList,dto.getNDid(),fileName);
|
||||
}
|
||||
}
|
||||
//重新接入之后,装置60s后开始消费缓存的录波文件
|
||||
else if (expiredKey.startsWith("startFile:")) {
|
||||
String nDid = expiredKey.split(":")[1];
|
||||
//处理缓存数据
|
||||
csWaveAnalysisService.channelWave(nDid);
|
||||
}
|
||||
//手动文件下载
|
||||
else if (expiredKey.startsWith(AppRedisKey.FILE_DOWN_TIME)) {
|
||||
List<Integer> missingList = new ArrayList<>();
|
||||
String fileName = expiredKey.split(AppRedisKey.FILE_DOWN_TIME)[1];
|
||||
Object object1 = redisUtil.getObjectByKey(AppRedisKey.FILE_PART.concat(fileName));
|
||||
FileStreamDto dto = JSON.parseObject(JSON.toJSONString(object1), FileStreamDto.class);
|
||||
int start = 1;
|
||||
int end = dto.getTotal();
|
||||
IntStream.rangeClosed(start, end)
|
||||
.filter(i -> !dto.getList().contains(i))
|
||||
.forEach(missingList::add);
|
||||
if (CollectionUtil.isNotEmpty(missingList)) {
|
||||
webDownloadFile(missingList,dto.getNDid(),fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//界面请求缺失的数据
|
||||
public void webDownloadFile( List<Integer> missingList, String nDid, String name) {
|
||||
for (Integer missingNumber : missingList) {
|
||||
int i = missingNumber - 1;
|
||||
Object object = getDeviceMid(nDid);
|
||||
if (!Objects.isNull(object)) {
|
||||
mid = (Integer) object;
|
||||
}
|
||||
ReqAndResDto.Req reqAndResParam = getPojo(mid,name,i);
|
||||
publisher.send("/Pfm/DevFileCmd/V1/"+nDid,new Gson().toJson(reqAndResParam),1,false);
|
||||
//判断是否重发
|
||||
webSendNextStep(name,nDid,mid,i);
|
||||
FileRedisDto fileRedisDto = (FileRedisDto) redisUtil.getObjectByKey(AppRedisKey.DOWNLOAD + name + mid);
|
||||
//重发之后判断继续循环还是跳出循环
|
||||
if (!Objects.isNull(fileRedisDto) && !Objects.equals(fileRedisDto.getCode(),200)) {
|
||||
break;
|
||||
}
|
||||
mid = mid + 1;
|
||||
if (mid > 10000) {
|
||||
mid = 1;
|
||||
}
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,mid);
|
||||
}
|
||||
}
|
||||
|
||||
public void askMissingFileStream(String nDid, Integer mid, String fileName, Integer offset, Integer len) {
|
||||
String version = csTopicFeignClient.find(nDid).getData();
|
||||
//录波文件请求缺失的数据
|
||||
public void downloadFile( List<Integer> missingList, String nDid, String name) {
|
||||
for (Integer missingNumber : missingList) {
|
||||
int i = missingNumber - 1;
|
||||
Object object = getDeviceMid(nDid);
|
||||
if (!Objects.isNull(object)) {
|
||||
mid = (Integer) object;
|
||||
}
|
||||
ReqAndResDto.Req reqAndResParam = getPojo(mid,name,i);
|
||||
publisher.send("/Pfm/DevFileCmd/V1/"+nDid,new Gson().toJson(reqAndResParam),1,false);
|
||||
//判断是否重发
|
||||
sendNextStep(name,nDid,mid,i);
|
||||
FileRedisDto fileRedisDto = (FileRedisDto) redisUtil.getObjectByKey(AppRedisKey.DOWNLOAD + name + mid);
|
||||
//重发之后判断继续循环还是跳出循环
|
||||
if (!Objects.isNull(fileRedisDto) && !Objects.equals(fileRedisDto.getCode(),200)) {
|
||||
//判断重读还是丢弃
|
||||
removeInfoUtils.retryEventInfo(nDid,name);
|
||||
break;
|
||||
}
|
||||
mid = mid + 1;
|
||||
if (mid > 10000) {
|
||||
mid = 1;
|
||||
}
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,mid);
|
||||
}
|
||||
}
|
||||
|
||||
public Object getDeviceMid(String nDid) {
|
||||
return redisUtil.getObjectByKey(AppRedisKey.DEVICE_MID + nDid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件下载请求报文
|
||||
*/
|
||||
public ReqAndResDto.Req getPojo(Integer mid, String fileName, Integer step) {
|
||||
String json;
|
||||
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
|
||||
reqAndResParam.setMid(mid);
|
||||
reqAndResParam.setDid(0);
|
||||
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_9.getCode()));
|
||||
reqAndResParam.setExpire(-1);
|
||||
String json = "{Name:\""+fileName+"\",Offset:"+offset+",Len:"+len+"}";
|
||||
json = "{Name:\""+fileName+"\",TransferMode:"+1+",Offset:"+(step*range)+",Len:"+range+"}";
|
||||
JSONObject jsonObject = JSONObject.fromObject(json);
|
||||
reqAndResParam.setMsg(jsonObject);
|
||||
publisher.send("/Pfm/DevFileCmd/"+version+"/"+nDid,new Gson().toJson(reqAndResParam),1,false);
|
||||
log.info("请求文件流报文:" + new Gson().toJson(reqAndResParam));
|
||||
return reqAndResParam;
|
||||
}
|
||||
|
||||
/**
|
||||
* web端根据装置响应来判断是否询问下一帧数据
|
||||
*/
|
||||
public void webSendNextStep(String fileName, String id, int mid,int step) {
|
||||
try {
|
||||
for (int i = 1; i <= 15; i++) {
|
||||
if (step == 0 ){
|
||||
Thread.sleep(8000);
|
||||
} else {
|
||||
Thread.sleep(4000);
|
||||
}
|
||||
FileRedisDto fileRedisDto = (FileRedisDto) redisUtil.getObjectByKey(AppRedisKey.DOWNLOAD + fileName + mid);
|
||||
if (Objects.isNull(fileRedisDto)) {
|
||||
FileRedisDto failDto = new FileRedisDto();
|
||||
failDto.setCode(400);
|
||||
redisUtil.saveByKeyWithExpire(AppRedisKey.DOWNLOAD + fileName + mid,failDto,10L);
|
||||
} else {
|
||||
if (Objects.equals(fileRedisDto.getCode(),200)) {
|
||||
break;
|
||||
} else {
|
||||
log.info("第" +i+"次尝试");
|
||||
//尝试失败则设置code为400,如果装置响应了,则会将code置为200
|
||||
FileRedisDto failDto = new FileRedisDto();
|
||||
failDto.setCode(400);
|
||||
redisUtil.saveByKeyWithExpire(AppRedisKey.DOWNLOAD + fileName + mid,failDto,10L);
|
||||
ReqAndResDto.Req req = getPojo(mid,fileName,step);
|
||||
publisher.send("/Pfm/DevFileCmd/V1/" + id, new Gson().toJson(req), 1, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(AlgorithmResponseEnum.FILE_DOWNLOAD_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 根据装置响应来判断是否询问下一帧数据
|
||||
*/
|
||||
public void sendNextStep(String fileName, String id, int mid,int step) {
|
||||
try {
|
||||
for (int i = 1; i <= 11; i++) {
|
||||
if (step == 0 ){
|
||||
Thread.sleep(5000 * i);
|
||||
} else {
|
||||
Thread.sleep(2000 * i);
|
||||
}
|
||||
FileRedisDto fileRedisDto = (FileRedisDto) redisUtil.getObjectByKey(AppRedisKey.DOWNLOAD + fileName + mid);
|
||||
if (Objects.isNull(fileRedisDto)) {
|
||||
FileRedisDto failDto = new FileRedisDto();
|
||||
failDto.setCode(400);
|
||||
redisUtil.saveByKeyWithExpire(AppRedisKey.DOWNLOAD + fileName + mid,failDto,10L);
|
||||
} else {
|
||||
if (Objects.equals(fileRedisDto.getCode(),200)) {
|
||||
break;
|
||||
} else {
|
||||
log.info("第" +i+"次尝试");
|
||||
//尝试失败则设置code为400,如果装置响应了,则会将code置为200
|
||||
FileRedisDto failDto = new FileRedisDto();
|
||||
failDto.setCode(400);
|
||||
redisUtil.saveByKeyWithExpire(AppRedisKey.DOWNLOAD + fileName + mid,failDto,4L*i);
|
||||
ReqAndResDto.Req req = getPojo(mid,fileName,step);
|
||||
publisher.send("/Pfm/DevFileCmd/V1/" + id, new Gson().toJson(req), 1, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(AlgorithmResponseEnum.FILE_DOWNLOAD_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.njcn.zlevent.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.user.pojo.vo.RoleVO;
|
||||
import com.njcn.zlevent.pojo.po.CsDevErrEvt;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 装置异常事件统计 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2024-09-12
|
||||
*/
|
||||
public interface CsDevErrEvtMapper extends BaseMapper<CsDevErrEvt> {
|
||||
|
||||
Page<CsDevErrEvt> page(@Param("page")Page<CsDevErrEvt> page, @Param("ew") QueryWrapper<CsDevErrEvt> queryWrapper);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.zlevent.mapper.CsDevErrEvtMapper">
|
||||
<select id="page" resultType="CsDevErrEvt">
|
||||
SELECT
|
||||
evt.*
|
||||
FROM cs_dev_err_evt evt
|
||||
WHERE ${ew.sqlSegment}
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.njcn.zlevent.runner;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.zlevent.service.ICsWaveAnalysisService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 类的介绍:项目重启或者接入,经过120s开始处理历史录波文件
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2024/9/18 13:57
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ZlEventApplicationRunner implements ApplicationRunner {
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private EquipmentFeignClient equipmentFeignClient;
|
||||
@Resource
|
||||
private ICsWaveAnalysisService csWaveAnalysisService;
|
||||
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
private static final long EVENT_TIME = 120L;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
//项目启动120s后开始消费缓存的波形文件
|
||||
Runnable task = () -> {
|
||||
log.info("开始消费缓存的波形文件");
|
||||
List<CsEquipmentDeliveryPO> list = equipmentFeignClient.getAll().getData();
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
list.forEach(item->{
|
||||
redisUtil.delete("handleEvent:" + item.getNdid());
|
||||
//处理缓存数据
|
||||
csWaveAnalysisService.channelWave(item.getNdid());
|
||||
});
|
||||
}
|
||||
};
|
||||
scheduler.schedule(task, EVENT_TIME, TimeUnit.SECONDS);
|
||||
// 关闭调度程序
|
||||
scheduler.shutdown();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.njcn.zlevent.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.mq.message.AppEventMessage;
|
||||
import com.njcn.zlevent.pojo.param.ErrorEventParam;
|
||||
import com.njcn.zlevent.pojo.po.CsDevErrEvt;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 装置异常事件统计 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2024-09-12
|
||||
*/
|
||||
public interface ICsDevErrEvtService extends IService<CsDevErrEvt> {
|
||||
|
||||
/**
|
||||
* 将装置推送的异常事件统计,目前先入库
|
||||
* @param appEventMessage
|
||||
*/
|
||||
void insertErrorEvent(AppEventMessage appEventMessage);
|
||||
|
||||
Page<CsDevErrEvt> getList(ErrorEventParam param);
|
||||
|
||||
}
|
||||
@@ -20,4 +20,6 @@ public interface ICsWaveAnalysisService {
|
||||
*/
|
||||
void analysis(AppEventMessage appEventMessage);
|
||||
|
||||
void channelWave(String nDid);
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public interface ICsWaveService extends IService<CsWave> {
|
||||
* @param fileName 文件名称
|
||||
* @return
|
||||
*/
|
||||
int findCountByName(String fileName);
|
||||
boolean findCountByName(String fileName);
|
||||
|
||||
/**
|
||||
* 修改文件状态
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.njcn.zlevent.service;
|
||||
|
||||
import com.njcn.mq.message.AppEventMessage;
|
||||
import com.njcn.mq.message.CldLogMessage;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
@@ -17,4 +18,19 @@ public interface IEventService {
|
||||
*/
|
||||
void analysis(AppEventMessage appEventMessage);
|
||||
|
||||
/**
|
||||
* 便携式设备基础数据
|
||||
* 1.装置发起数据记录开始动作,库中新增数据;
|
||||
* 2.装置发起数据记录结束动作,库中更新数据;
|
||||
* @param appEventMessage
|
||||
*/
|
||||
void getPortableData(AppEventMessage appEventMessage);
|
||||
|
||||
/**
|
||||
* 云前置设备基础数据
|
||||
* 1.装置发起数据记录开始动作,库中新增数据;
|
||||
* @param cldLogMessage
|
||||
*/
|
||||
void getCldEventData( CldLogMessage cldLogMessage);
|
||||
|
||||
}
|
||||
|
||||
@@ -26,4 +26,8 @@ public interface IFileService {
|
||||
*/
|
||||
void analysisFileStream(AppFileMessage appFileMessage);
|
||||
|
||||
/**
|
||||
* 下载补召文件
|
||||
*/
|
||||
void downloadMakeUpFile(String nDid);
|
||||
}
|
||||
|
||||
@@ -2,14 +2,23 @@ package com.njcn.zlevent.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.access.pojo.po.CsDeviceOnlineLogs;
|
||||
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.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.ICsAlarmService;
|
||||
@@ -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>
|
||||
* 告警事件表 服务实现类
|
||||
@@ -43,28 +55,67 @@ public class CsAlarmServiceImpl extends ServiceImpl<CsEventMapper, CsEventPO> im
|
||||
private final SendEventUtils sendEventUtils;
|
||||
private final ICsEventLogsService csEventLogsService;
|
||||
private final EpdFeignClient epdFeignClient;
|
||||
private final RedisUtil redisUtil;
|
||||
private final ChannelObjectUtil channelObjectUtil;
|
||||
|
||||
@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());
|
||||
eventTime = eventService.timeFormat(item.getDataTimeSec(),item.getDataTimeUSec());
|
||||
csEvent.setStartTime(eventTime);
|
||||
tag = item.getName();
|
||||
csEvent.setTag(tag);
|
||||
csEvent.setType(3);
|
||||
csEvent.setClDid(appEventMessage.getMsg().getClDid());
|
||||
@@ -74,23 +125,24 @@ public class CsAlarmServiceImpl extends ServiceImpl<CsEventMapper, CsEventPO> im
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(list1)){
|
||||
csEventService.saveBatch(list1);
|
||||
}
|
||||
//推送事件逻辑处理 && cs_event_user入库 && 修改字典中告警事件的编码
|
||||
for (AppEventMessage.DataArray item : dataArray) {
|
||||
if (Objects.isNull(item.getCode())){
|
||||
sendEventUtils.sendUser(2,item.getType(),po.getId(),item.getName(),eventTime,id);
|
||||
} else {
|
||||
sendEventUtils.sendUser(2,item.getType(),po.getId(),item.getCode(),eventTime,id);
|
||||
//更新字典信息
|
||||
EleEpdPqd eleEpdPqd = epdFeignClient.findByName(item.getName()).getData();
|
||||
EleEpdPqdParam.EleEpdPqdUpdateParam updateParam = new EleEpdPqdParam.EleEpdPqdUpdateParam();
|
||||
BeanUtils.copyProperties(eleEpdPqd,updateParam);
|
||||
updateParam.setDefaultValue(item.getCode());
|
||||
epdFeignClient.update(updateParam);
|
||||
//推送事件逻辑处理 && cs_event_user入库 && 修改字典中告警事件的编码
|
||||
for (AppEventMessage.DataArray item : dataArray) {
|
||||
if (Objects.isNull(item.getCode())){
|
||||
sendEventUtils.sendUser(2,item.getType(),po.getId(),item.getName(),eventTime,id,po.getNdid());
|
||||
} else {
|
||||
sendEventUtils.sendUser(2,item.getType(),po.getId(),item.getCode(),eventTime,id,po.getNdid());
|
||||
//更新字典信息
|
||||
EleEpdPqd eleEpdPqd = epdFeignClient.findByName(item.getName()).getData();
|
||||
EleEpdPqdParam.EleEpdPqdUpdateParam updateParam = new EleEpdPqdParam.EleEpdPqdUpdateParam();
|
||||
BeanUtils.copyProperties(eleEpdPqd,updateParam);
|
||||
updateParam.setDefaultValue(item.getCode());
|
||||
epdFeignClient.update(updateParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CsEventLogs csEventLogs = new CsEventLogs();
|
||||
csEventLogs.setLineId(lineId);
|
||||
csEventLogs.setDeviceId(po.getId());
|
||||
csEventLogs.setStartTime(eventTime);
|
||||
csEventLogs.setTag(tag);
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.njcn.zlevent.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.db.constant.DbConstant;
|
||||
import com.njcn.mq.message.AppEventMessage;
|
||||
import com.njcn.user.pojo.vo.RoleVO;
|
||||
import com.njcn.web.factory.PageFactory;
|
||||
import com.njcn.zlevent.mapper.CsDevErrEvtMapper;
|
||||
import com.njcn.zlevent.pojo.param.ErrorEventParam;
|
||||
import com.njcn.zlevent.pojo.po.CsDevErrEvt;
|
||||
import com.njcn.zlevent.service.ICsDevErrEvtService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 装置异常事件统计 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2024-09-12
|
||||
*/
|
||||
@Service
|
||||
public class CsDevErrEvtServiceImpl extends ServiceImpl<CsDevErrEvtMapper, CsDevErrEvt> implements ICsDevErrEvtService {
|
||||
|
||||
@Override
|
||||
public void insertErrorEvent(AppEventMessage appEventMessage) {
|
||||
List<CsDevErrEvt> list = new ArrayList<>();
|
||||
List<AppEventMessage.DataArray> dataArrayList = appEventMessage.getMsg().getDataArray();
|
||||
for (AppEventMessage.DataArray dataArray : dataArrayList) {
|
||||
CsDevErrEvt evt = new CsDevErrEvt();
|
||||
evt.setNdid(appEventMessage.getId());
|
||||
evt.setEvtTime(timeFormat(dataArray.getDataTimeSec(),dataArray.getDataTimeUSec()));
|
||||
evt.setCode(dataArray.getCode());
|
||||
list.add(evt);
|
||||
}
|
||||
this.saveBatch(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<CsDevErrEvt> getList(ErrorEventParam param) {
|
||||
// 构造时间字符串
|
||||
QueryWrapper<CsDevErrEvt> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.between("evt.evt_time",param.getStartTime() + " 00:00:00",param.getEndTime() + " 23:59:59");
|
||||
queryWrapper.orderBy(true, false, "evt.evt_time");
|
||||
if (ObjectUtil.isNotNull(param)) {
|
||||
//查询参数不为空,进行条件填充
|
||||
if (StrUtil.isNotBlank(param.getSearchValue())) {
|
||||
//用户表提供用户名、登录名 模糊查询
|
||||
queryWrapper
|
||||
.and(par -> par.like("evt.ndid", param.getSearchValue()));
|
||||
}
|
||||
}
|
||||
return this.baseMapper.page(new Page<>(PageFactory.getPageNum(param), PageFactory.getPageSize(param)), queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间转换
|
||||
*/
|
||||
public LocalDateTime timeFormat(Long time1, Long time2) {
|
||||
String time;
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
time1 = time1 - 8*3600;
|
||||
long t1 = time1 * 1000000 + time2;
|
||||
String time1String = String.valueOf(t1);
|
||||
String time11 = time1String.substring(time1String.length() - 6);
|
||||
String time111 = time1String.substring(0,time1String.length() - 6);
|
||||
String formatTime1 = format.format(Long.parseLong(time111) * 1000);
|
||||
if (time2 == 0){
|
||||
time = formatTime1 + ".000000";
|
||||
} else {
|
||||
time = formatTime1 + "." + time11;
|
||||
}
|
||||
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS");
|
||||
return LocalDateTime.parse(time, fmt);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user