Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 |
@@ -1,8 +1,15 @@
|
|||||||
package com.njcn.access.api;
|
package com.njcn.access.api;
|
||||||
|
|
||||||
import com.njcn.access.api.fallback.AskDeviceDataClientFallbackFactory;
|
import com.njcn.access.api.fallback.AskDeviceDataClientFallbackFactory;
|
||||||
|
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||||
import com.njcn.common.pojo.constant.ServerInfo;
|
import com.njcn.common.pojo.constant.ServerInfo;
|
||||||
|
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||||
|
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||||
import com.njcn.common.pojo.response.HttpResult;
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
|
import com.njcn.common.utils.HttpResultUtil;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiImplicitParams;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
@@ -31,4 +38,7 @@ public interface AskDeviceDataFeignClient {
|
|||||||
@PostMapping("/deleteFolder")
|
@PostMapping("/deleteFolder")
|
||||||
HttpResult<String> deleteFolder(@RequestParam("nDid") String nDid, @RequestParam("path") String path);
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class AskDeviceDataClientFallbackFactory implements FallbackFactory<AskDe
|
|||||||
public HttpResult<Boolean> downloadFile(String nDid, String name, Integer size, String fileCheck) {
|
public HttpResult<Boolean> downloadFile(String nDid, String name, Integer size, String fileCheck) {
|
||||||
log.error("{}异常,降级处理,异常为:{}","文件下载",cause.toString());
|
log.error("{}异常,降级处理,异常为:{}","文件下载",cause.toString());
|
||||||
redisUtil.delete("fileDowning:" + nDid);
|
redisUtil.delete("fileDowning:" + nDid);
|
||||||
redisUtil.delete("fileCheck"+name);
|
redisUtil.delete("fileCheck"+nDid+name);
|
||||||
throw new BusinessException(finalExceptionEnum);
|
throw new BusinessException(finalExceptionEnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,6 +67,12 @@ public class AskDeviceDataClientFallbackFactory implements FallbackFactory<AskDe
|
|||||||
log.error("{}异常,降级处理,异常为:{}","删除文件夹",cause.toString());
|
log.error("{}异常,降级处理,异常为:{}","删除文件夹",cause.toString());
|
||||||
throw new BusinessException(finalExceptionEnum);
|
throw new BusinessException(finalExceptionEnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HttpResult<String> askRealData(String nDid, Integer idx, Integer clDid) {
|
||||||
|
log.error("{}异常,降级处理,异常为:{}","询问装置实时数据",cause.toString());
|
||||||
|
throw new BusinessException(finalExceptionEnum);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,12 @@ public class AskDataDto {
|
|||||||
@ParamName("EndTime")
|
@ParamName("EndTime")
|
||||||
private Integer EndTime;
|
private Integer EndTime;
|
||||||
|
|
||||||
|
@ParamName("RtDuration")
|
||||||
|
private Integer RtDuration;
|
||||||
|
|
||||||
|
@ParamName("DsNameIdx")
|
||||||
|
private Integer DsNameIdx;
|
||||||
|
|
||||||
@ParamName("DataArray")
|
@ParamName("DataArray")
|
||||||
private DataArrayDto DataArray;
|
private DataArrayDto DataArray;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,6 +82,79 @@ public class EventDto {
|
|||||||
|
|
||||||
@SerializedName("Parm")
|
@SerializedName("Parm")
|
||||||
private List<Param> param;
|
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
|
@Data
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.njcn.zlevent.pojo.dto;
|
package com.njcn.access.pojo.dto;
|
||||||
|
|
||||||
import com.njcn.access.annotation.ParamName;
|
import com.njcn.access.annotation.ParamName;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
@@ -36,6 +36,11 @@ public class DataSetDto implements Serializable {
|
|||||||
@ApiModelProperty("0-不存储;1-存储")
|
@ApiModelProperty("0-不存储;1-存储")
|
||||||
private Integer storeFlag;
|
private Integer storeFlag;
|
||||||
|
|
||||||
|
@SerializedName("DataAttr")
|
||||||
|
@NotNull(message = "数据集类型")
|
||||||
|
@ApiModelProperty("Stat-统计数据 Rt-实时数据")
|
||||||
|
private String dataAttr;
|
||||||
|
|
||||||
@SerializedName("DataLevel")
|
@SerializedName("DataLevel")
|
||||||
@NotNull(message = "数据标识(一次值、二次值),不可为空")
|
@NotNull(message = "数据标识(一次值、二次值),不可为空")
|
||||||
@ApiModelProperty("Primary-一次值;Secondary-二次值")
|
@ApiModelProperty("Primary-一次值;Secondary-二次值")
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package com.njcn.access.utils;
|
package com.njcn.access.utils;
|
||||||
|
|
||||||
|
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||||
|
import com.njcn.redis.utils.RedisUtil;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -11,6 +14,9 @@ import java.util.List;
|
|||||||
@Component
|
@Component
|
||||||
public class ChannelObjectUtil {
|
public class ChannelObjectUtil {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RedisUtil redisUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将list转成对应实体
|
* 将list转成对应实体
|
||||||
* @param object
|
* @param object
|
||||||
@@ -42,4 +48,8 @@ public class ChannelObjectUtil {
|
|||||||
// 或者抛出异常,根据您的需求
|
// 或者抛出异常,根据您的需求
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object getDeviceMid(String nDid) {
|
||||||
|
return redisUtil.getObjectByKey(AppRedisKey.DEVICE_MID + nDid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -66,6 +66,16 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.njcn</groupId>
|
<groupId>com.njcn</groupId>
|
||||||
<artifactId>zl-event-api</artifactId>
|
<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>
|
<version>1.0.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import org.mybatis.spring.annotation.MapperScan;
|
|||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
import org.springframework.context.annotation.DependsOn;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
|
|
||||||
@@ -14,6 +15,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|||||||
* @date 2021年12月09日 20:59
|
* @date 2021年12月09日 20:59
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@DependsOn("proxyMapperRegister")
|
||||||
@MapperScan("com.njcn.**.mapper")
|
@MapperScan("com.njcn.**.mapper")
|
||||||
@EnableFeignClients(basePackages = "com.njcn")
|
@EnableFeignClients(basePackages = "com.njcn")
|
||||||
@SpringBootApplication(scanBasePackages = "com.njcn")
|
@SpringBootApplication(scanBasePackages = "com.njcn")
|
||||||
|
|||||||
@@ -109,5 +109,19 @@ public class AskDeviceDataController extends BaseController {
|
|||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ public class CsDeviceController extends BaseController {
|
|||||||
|
|
||||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||||
@PostMapping("/wlRegister")
|
@PostMapping("/wlRegister")
|
||||||
@ApiOperation("便携式设备注册")
|
@ApiOperation("便携式设备接入")
|
||||||
@ApiImplicitParams({
|
@ApiImplicitParams({
|
||||||
@ApiImplicitParam(name = "nDid", value = "设备识别码", required = true)
|
@ApiImplicitParam(name = "nDid", value = "设备识别码", required = true)
|
||||||
})
|
})
|
||||||
@@ -109,7 +109,7 @@ public class CsDeviceController extends BaseController {
|
|||||||
|
|
||||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||||
@PostMapping("/wlAccess")
|
@PostMapping("/wlAccess")
|
||||||
@ApiOperation("便携式设备接入")
|
@ApiOperation("便携式设备手动接入")
|
||||||
@ApiImplicitParams({
|
@ApiImplicitParams({
|
||||||
@ApiImplicitParam(name = "nDid", value = "设备识别码", required = true)
|
@ApiImplicitParam(name = "nDid", value = "设备识别码", required = true)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
|||||||
import com.njcn.access.enums.AccessEnum;
|
import com.njcn.access.enums.AccessEnum;
|
||||||
import com.njcn.access.enums.AccessResponseEnum;
|
import com.njcn.access.enums.AccessResponseEnum;
|
||||||
import com.njcn.access.enums.TypeEnum;
|
import com.njcn.access.enums.TypeEnum;
|
||||||
|
import com.njcn.access.mapper.OverlimitMapper;
|
||||||
import com.njcn.access.pojo.RspDataDto;
|
import com.njcn.access.pojo.RspDataDto;
|
||||||
import com.njcn.access.pojo.dto.*;
|
import com.njcn.access.pojo.dto.*;
|
||||||
import com.njcn.access.pojo.dto.file.FileDto;
|
import com.njcn.access.pojo.dto.file.FileDto;
|
||||||
@@ -26,11 +27,14 @@ import com.njcn.access.service.ICsDeviceOnlineLogsService;
|
|||||||
import com.njcn.access.service.ICsEquipmentDeliveryService;
|
import com.njcn.access.service.ICsEquipmentDeliveryService;
|
||||||
import com.njcn.access.service.ICsLineModelService;
|
import com.njcn.access.service.ICsLineModelService;
|
||||||
import com.njcn.access.service.ICsTopicService;
|
import com.njcn.access.service.ICsTopicService;
|
||||||
|
import com.njcn.access.utils.ChannelObjectUtil;
|
||||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.csdevice.api.*;
|
import com.njcn.csdevice.api.*;
|
||||||
import com.njcn.csdevice.pojo.param.CsLineParam;
|
import com.njcn.csdevice.pojo.param.CsLineParam;
|
||||||
import com.njcn.csdevice.pojo.po.*;
|
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.AppAutoDataMessage;
|
||||||
import com.njcn.mq.message.AppEventMessage;
|
import com.njcn.mq.message.AppEventMessage;
|
||||||
import com.njcn.mq.message.AppFileMessage;
|
import com.njcn.mq.message.AppFileMessage;
|
||||||
@@ -40,7 +44,9 @@ import com.njcn.mq.template.AppFileMessageTemplate;
|
|||||||
import com.njcn.mq.template.AppFileStreamMessageTemplate;
|
import com.njcn.mq.template.AppFileStreamMessageTemplate;
|
||||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||||
import com.njcn.redis.utils.RedisUtil;
|
import com.njcn.redis.utils.RedisUtil;
|
||||||
import com.njcn.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.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||||
@@ -73,40 +79,26 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
|||||||
public class MqttMessageHandler {
|
public class MqttMessageHandler {
|
||||||
|
|
||||||
private final DevModelFeignClient devModelFeignClient;
|
private final DevModelFeignClient devModelFeignClient;
|
||||||
|
|
||||||
private final ICsLineModelService csLineModelService;
|
private final ICsLineModelService csLineModelService;
|
||||||
|
|
||||||
private final ICsTopicService csTopicService;
|
private final ICsTopicService csTopicService;
|
||||||
|
|
||||||
private final MqttPublisher publisher;
|
private final MqttPublisher publisher;
|
||||||
|
|
||||||
private final RedisUtil redisUtil;
|
private final RedisUtil redisUtil;
|
||||||
|
|
||||||
private final ICsEquipmentDeliveryService csEquipmentDeliveryService;
|
private final ICsEquipmentDeliveryService csEquipmentDeliveryService;
|
||||||
|
|
||||||
private final DataSetFeignClient dataSetFeignClient;
|
private final DataSetFeignClient dataSetFeignClient;
|
||||||
|
|
||||||
private final AppAutoDataMessageTemplate appAutoDataMessageTemplate;
|
private final AppAutoDataMessageTemplate appAutoDataMessageTemplate;
|
||||||
|
|
||||||
private final AppEventMessageTemplate appEventMessageTemplate;
|
private final AppEventMessageTemplate appEventMessageTemplate;
|
||||||
|
|
||||||
private final CsLogsFeignClient csLogsFeignClient;
|
private final CsLogsFeignClient csLogsFeignClient;
|
||||||
|
|
||||||
private final AppFileMessageTemplate appFileMessageTemplate;
|
private final AppFileMessageTemplate appFileMessageTemplate;
|
||||||
|
|
||||||
private final AppFileStreamMessageTemplate appFileStreamMessageTemplate;
|
private final AppFileStreamMessageTemplate appFileStreamMessageTemplate;
|
||||||
|
|
||||||
private final ICsDeviceOnlineLogsService onlineLogsService;
|
private final ICsDeviceOnlineLogsService onlineLogsService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private final CsSoftInfoFeignClient csSoftInfoFeignClient;
|
private final CsSoftInfoFeignClient csSoftInfoFeignClient;
|
||||||
|
|
||||||
private final CsLineFeignClient csLineFeignClient;
|
private final CsLineFeignClient csLineFeignClient;
|
||||||
|
|
||||||
private final DevCapacityFeignClient devCapacityFeignClient;
|
private final DevCapacityFeignClient devCapacityFeignClient;
|
||||||
|
|
||||||
private final EquipmentFeignClient equipmentFeignClient;
|
private final EquipmentFeignClient equipmentFeignClient;
|
||||||
|
private final OverlimitMapper overlimitMapper;
|
||||||
|
private final ChannelObjectUtil channelObjectUtil;
|
||||||
|
private final WaveFeignClient waveFeignClient;
|
||||||
|
private final RtFeignClient rtFeignClient;
|
||||||
@Autowired
|
@Autowired
|
||||||
Validator validator;
|
Validator validator;
|
||||||
|
|
||||||
@@ -116,11 +108,11 @@ public class MqttMessageHandler {
|
|||||||
//日志记录
|
//日志记录
|
||||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||||
try{
|
try{
|
||||||
logDto.setUserName(RequestUtil.getUsername());
|
logDto.setUserName("运维管理员");
|
||||||
logDto.setLoginName(RequestUtil.getLoginName());
|
logDto.setLoginName("njcnyw");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logDto.setUserName("设备主题录入");
|
logDto.setUserName("运维管理员");
|
||||||
logDto.setLoginName(null);
|
logDto.setLoginName("njcnyw");
|
||||||
}
|
}
|
||||||
logDto.setOperate(nDid + "设备主题录入");
|
logDto.setOperate(nDid + "设备主题录入");
|
||||||
logDto.setResult(1);
|
logDto.setResult(1);
|
||||||
@@ -178,11 +170,11 @@ public class MqttMessageHandler {
|
|||||||
//日志记录
|
//日志记录
|
||||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||||
try{
|
try{
|
||||||
logDto.setUserName(RequestUtil.getUsername());
|
logDto.setUserName("运维管理员");
|
||||||
logDto.setLoginName(RequestUtil.getLoginName());
|
logDto.setLoginName("njcnyw");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logDto.setUserName("设备注册应答响应");
|
logDto.setUserName("运维管理员");
|
||||||
logDto.setLoginName(null);
|
logDto.setLoginName("njcnyw");
|
||||||
}
|
}
|
||||||
logDto.setOperate("收到设备"+nDid+"注册应答响应");
|
logDto.setOperate("收到设备"+nDid+"注册应答响应");
|
||||||
logDto.setResult(1);
|
logDto.setResult(1);
|
||||||
@@ -216,33 +208,41 @@ public class MqttMessageHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 装置类型模板应答
|
* 设备响应
|
||||||
* 1.判断网关的类型
|
|
||||||
* 2.直联设备的DevCfg和DevMod是以直联设备为准,上送平台端,平台端保存。通过校验DevMod模板信息来从平台端模板池中选取对应的模板,如果找不到匹配模板需告警提示人工干预处理。
|
|
||||||
* 3.平台端需读取装置的DevMod来判断网关支持的设备模板(包含设备型号和模板版本),根据app提交的接入子设备DID匹配数据模板(型号及版本),生成DevCfg下发给网关,网关根据下发信息生成就地设备点表。
|
|
||||||
* @param topic
|
* @param topic
|
||||||
* @param message
|
* @param message
|
||||||
|
* @param version
|
||||||
* @param nDid
|
* @param nDid
|
||||||
* @param payload
|
* @param payload
|
||||||
*/
|
*/
|
||||||
@MqttSubscribe(value = "/Pfm/DevRsp/{version}/{edgeId}",qos = 1)
|
@MqttSubscribe(value = "/Pfm/DevRsp/{version}/{edgeId}",qos = 1)
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void devModelOperation(String topic, MqttMessage message, @NamedValue("version") String version, @NamedValue("edgeId") String nDid, @Payload String payload){
|
public void devAccessOperation(String topic, MqttMessage message, @NamedValue("version") String version, @NamedValue("edgeId") String nDid, @Payload String payload){
|
||||||
log.info("收到当前设备所用模板响应--->" + nDid);
|
//日志实体
|
||||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||||
try{
|
try{
|
||||||
logDto.setUserName(RequestUtil.getUsername());
|
logDto.setUserName("运维管理员");
|
||||||
logDto.setLoginName(RequestUtil.getLoginName());
|
logDto.setLoginName("njcnyw");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logDto.setUserName("系统重启或定时任务创建");
|
logDto.setUserName("运维管理员");
|
||||||
logDto.setLoginName(null);
|
logDto.setLoginName("njcnyw");
|
||||||
}
|
}
|
||||||
logDto.setOperate(nDid + "设备类型模板应答");
|
|
||||||
logDto.setResult(1);
|
logDto.setResult(1);
|
||||||
//业务处理
|
//业务处理
|
||||||
Gson gson = new Gson();
|
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);
|
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<DevModInfoDto> list = modelDto.getMsg().getDevMod();
|
||||||
List<DevCfgDto> list2 = modelDto.getMsg().getDevCfg();
|
List<DevCfgDto> list2 = modelDto.getMsg().getDevCfg();
|
||||||
if (CollectionUtils.isEmpty(list)){
|
if (CollectionUtils.isEmpty(list)){
|
||||||
@@ -300,40 +300,10 @@ public class MqttMessageHandler {
|
|||||||
List<CsLineModel> lineList = csLineModelService.getMonitorNumByModelId(modelId);
|
List<CsLineModel> lineList = csLineModelService.getMonitorNumByModelId(modelId);
|
||||||
String key = AppRedisKey.LINE + nDid;
|
String key = AppRedisKey.LINE + nDid;
|
||||||
redisUtil.saveByKeyWithExpire(key,lineList,600L);
|
redisUtil.saveByKeyWithExpire(key,lineList,600L);
|
||||||
csLogsFeignClient.addUserLog(logDto);
|
break;
|
||||||
System.out.println(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设备接入平台应答
|
|
||||||
* @param topic
|
|
||||||
* @param message
|
|
||||||
* @param version
|
|
||||||
* @param nDid
|
|
||||||
* @param payload
|
|
||||||
*/
|
|
||||||
@MqttSubscribe(value = "/Pfm/DevRsp/{version}/{edgeId}",qos = 1)
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public void devAccessOperation(String topic, MqttMessage message, @NamedValue("version") String version, @NamedValue("edgeId") String nDid, @Payload String payload){
|
|
||||||
//日志实体
|
|
||||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
|
||||||
try{
|
|
||||||
logDto.setUserName(RequestUtil.getUsername());
|
|
||||||
logDto.setLoginName(RequestUtil.getLoginName());
|
|
||||||
} catch (Exception e) {
|
|
||||||
logDto.setUserName("系统重启或定时任务创建");
|
|
||||||
logDto.setLoginName(null);
|
|
||||||
}
|
|
||||||
logDto.setResult(1);
|
|
||||||
//业务处理
|
|
||||||
Gson gson = new Gson();
|
|
||||||
ReqAndResDto.Res res = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), ReqAndResDto.Res.class);
|
|
||||||
if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){
|
|
||||||
switch (res.getType()){
|
|
||||||
case 4613:
|
case 4613:
|
||||||
logDto.setOperate(nDid + "设备接入");
|
logDto.setOperate(nDid + "设备接入");
|
||||||
log.info("{}收到接入应答响应,应答code {}",nDid,res.getCode());
|
log.info("{},收到接入应答响应,应答code {}",nDid,res.getCode());
|
||||||
if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){
|
if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){
|
||||||
int mid = 1;
|
int mid = 1;
|
||||||
//修改装置状态
|
//修改装置状态
|
||||||
@@ -352,8 +322,13 @@ public class MqttMessageHandler {
|
|||||||
csDeviceOnlineLogs.setNdid(nDid);
|
csDeviceOnlineLogs.setNdid(nDid);
|
||||||
csDeviceOnlineLogs.setOnlineTime(LocalDateTime.now());
|
csDeviceOnlineLogs.setOnlineTime(LocalDateTime.now());
|
||||||
onlineLogsService.save(csDeviceOnlineLogs);
|
onlineLogsService.save(csDeviceOnlineLogs);
|
||||||
|
} else {
|
||||||
|
record.setOnlineTime(LocalDateTime.now());
|
||||||
|
onlineLogsService.updateById(record);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//接入后系统重置装置心跳
|
||||||
|
redisUtil.saveByKeyWithExpire("MQTT:" + nDid, Instant.now().toEpochMilli(),180L);
|
||||||
//修改redis的mid
|
//修改redis的mid
|
||||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,1);
|
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,1);
|
||||||
redisUtil.saveByKeyWithExpire("online" + nDid,"online",10L);
|
redisUtil.saveByKeyWithExpire("online" + nDid,"online",10L);
|
||||||
@@ -363,6 +338,8 @@ public class MqttMessageHandler {
|
|||||||
askDevData(nDid,version,2,(res.getMid()+1));
|
askDevData(nDid,version,2,(res.getMid()+1));
|
||||||
//更新电网侧、负载侧监测点信息
|
//更新电网侧、负载侧监测点信息
|
||||||
askDevData(nDid,version,3,(res.getMid()+1));
|
askDevData(nDid,version,3,(res.getMid()+1));
|
||||||
|
//录波任务倒计时
|
||||||
|
redisUtil.saveByKeyWithExpire("startFile:" + nDid,null,60L);
|
||||||
} else {
|
} else {
|
||||||
log.info(AccessResponseEnum.ACCESS_RESPONSE_ERROR.getMessage());
|
log.info(AccessResponseEnum.ACCESS_RESPONSE_ERROR.getMessage());
|
||||||
logDto.setResult(0);
|
logDto.setResult(0);
|
||||||
@@ -370,12 +347,14 @@ public class MqttMessageHandler {
|
|||||||
csLogsFeignClient.addUserLog(logDto);
|
csLogsFeignClient.addUserLog(logDto);
|
||||||
throw new BusinessException(AccessResponseEnum.ACCESS_RESPONSE_ERROR);
|
throw new BusinessException(AccessResponseEnum.ACCESS_RESPONSE_ERROR);
|
||||||
}
|
}
|
||||||
|
csLogsFeignClient.addUserLog(logDto);
|
||||||
break;
|
break;
|
||||||
case 4614:
|
case 4614:
|
||||||
log.info("设备数据应答--->" + nDid);
|
|
||||||
RspDataDto rspDataDto = JSON.parseObject(JSON.toJSONString(res.getMsg()), RspDataDto.class);
|
RspDataDto rspDataDto = JSON.parseObject(JSON.toJSONString(res.getMsg()), RspDataDto.class);
|
||||||
|
if (!Objects.isNull(rspDataDto.getDataType())) {
|
||||||
switch (rspDataDto.getDataType()){
|
switch (rspDataDto.getDataType()){
|
||||||
case 1:
|
case 1:
|
||||||
|
log.info("{},设备数据应答--->更新设备软件信息", nDid);
|
||||||
logDto.setOperate(nDid + "更新设备软件信息");
|
logDto.setOperate(nDid + "更新设备软件信息");
|
||||||
RspDataDto.SoftInfo softInfo = JSON.parseObject(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.SoftInfo.class);
|
RspDataDto.SoftInfo softInfo = JSON.parseObject(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.SoftInfo.class);
|
||||||
//记录设备软件信息
|
//记录设备软件信息
|
||||||
@@ -401,39 +380,45 @@ public class MqttMessageHandler {
|
|||||||
csSoftInfoFeignClient.removeSoftInfo(soft);
|
csSoftInfoFeignClient.removeSoftInfo(soft);
|
||||||
}
|
}
|
||||||
equipmentFeignClient.updateSoftInfo(nDid,csSoftInfoPo.getId());
|
equipmentFeignClient.updateSoftInfo(nDid,csSoftInfoPo.getId());
|
||||||
//询问设备容量信息
|
|
||||||
//askDevData(nDid,version,2,(res.getMid()+1));
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
List<RspDataDto.LdevInfo> devInfo = JSON.parseArray(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.LdevInfo.class);
|
List<RspDataDto.LdevInfo> devInfo = JSON.parseArray(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.LdevInfo.class);
|
||||||
if (CollectionUtil.isNotEmpty(devInfo)){
|
if (CollectionUtil.isNotEmpty(devInfo)){
|
||||||
if (Objects.equals(res.getDid(),1)){
|
if (Objects.equals(res.getDid(),1)){
|
||||||
logDto.setOperate(nDid + "更新治理监测点信息和设备容量");
|
log.info("{},设备数据应答--->更新治理监测点信息和设备容量", nDid);
|
||||||
List<CsDevCapacityPO> list = new ArrayList<>();
|
List<CsDevCapacityPO> list3 = new ArrayList<>();
|
||||||
devInfo.forEach(item->{
|
devInfo.forEach(item->{
|
||||||
//1.更新治理监测点信息
|
//1.更新治理监测点信息
|
||||||
if (Objects.equals(item.getClDid(),0)){
|
|
||||||
CsLineParam csLineParam = new CsLineParam();
|
CsLineParam csLineParam = new CsLineParam();
|
||||||
|
if (Objects.equals(item.getClDid(),0)){
|
||||||
csLineParam.setLineId(nDid.concat("0"));
|
csLineParam.setLineId(nDid.concat("0"));
|
||||||
csLineParam.setVolGrade(item.getVolGrade());
|
|
||||||
csLineParam.setPtRatio(item.getPtRatio());
|
|
||||||
csLineParam.setCtRatio(item.getCtRatio());
|
|
||||||
csLineParam.setConType(item.getConType());
|
|
||||||
csLineFeignClient.updateLine(csLineParam);
|
|
||||||
}
|
|
||||||
//2.录入各个模块设备容量
|
//2.录入各个模块设备容量
|
||||||
CsDevCapacityPO csDevCapacity = new CsDevCapacityPO();
|
CsDevCapacityPO csDevCapacity = new CsDevCapacityPO();
|
||||||
csDevCapacity.setLineId(nDid.concat("0"));
|
csDevCapacity.setLineId(nDid.concat("0"));
|
||||||
csDevCapacity.setCldid(item.getClDid());
|
csDevCapacity.setCldid(item.getClDid());
|
||||||
csDevCapacity.setCapacity(Objects.isNull(item.getCapacityA())?0.0:item.getCapacityA());
|
csDevCapacity.setCapacity(Objects.isNull(item.getCapacityA())?0.0:item.getCapacityA());
|
||||||
list.add(csDevCapacity);
|
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());
|
||||||
|
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);
|
||||||
});
|
});
|
||||||
devCapacityFeignClient.addList(list);
|
if (CollectionUtil.isNotEmpty(list3)) {
|
||||||
|
devCapacityFeignClient.addList(list3);
|
||||||
//3.更新设备模块个数
|
//3.更新设备模块个数
|
||||||
equipmentFeignClient.updateModuleNumber(nDid,(devInfo.size()-1));
|
equipmentFeignClient.updateModuleNumber(nDid,(devInfo.size()-1));
|
||||||
//4.询问监测点pt/ct信息
|
}
|
||||||
//askDevData(nDid,version,3,(res.getMid()+1));
|
|
||||||
} else if (Objects.equals(res.getDid(),2)) {
|
} else if (Objects.equals(res.getDid(),2)) {
|
||||||
|
log.info("{},设备数据应答--->更新电网侧、负载侧监测点信息", nDid);
|
||||||
logDto.setOperate(nDid + "更新电网侧、负载侧监测点信息");
|
logDto.setOperate(nDid + "更新电网侧、负载侧监测点信息");
|
||||||
//1.更新电网侧、负载侧监测点相关信息
|
//1.更新电网侧、负载侧监测点相关信息
|
||||||
devInfo.forEach(item->{
|
devInfo.forEach(item->{
|
||||||
@@ -450,26 +435,28 @@ public class MqttMessageHandler {
|
|||||||
break;
|
break;
|
||||||
case 48:
|
case 48:
|
||||||
log.info("询问装置项目列表");
|
log.info("询问装置项目列表");
|
||||||
|
logDto.setUserName("运维管理员");
|
||||||
logDto.setOperate("监测点:" + (nDid + rspDataDto.getClDid()) + "询问项目列表");
|
logDto.setOperate("监测点:" + (nDid + rspDataDto.getClDid()) + "询问项目列表");
|
||||||
List<RspDataDto.ProjectInfo> projectInfoList = JSON.parseArray(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.ProjectInfo.class);
|
List<RspDataDto.ProjectInfo> projectInfoList = JSON.parseArray(JSON.toJSONString(rspDataDto.getDataArray()), RspDataDto.ProjectInfo.class);
|
||||||
String key = AppRedisKey.PROJECT_INFO + nDid + rspDataDto.getClDid();
|
String key3 = AppRedisKey.PROJECT_INFO + nDid + rspDataDto.getClDid();
|
||||||
redisUtil.saveByKeyWithExpire(key,projectInfoList,60L);
|
redisUtil.saveByKeyWithExpire(key3,projectInfoList,60L);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 4663:
|
case 4663:
|
||||||
log.info("装置操作应答");
|
log.info("装置操作应答");
|
||||||
if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){
|
if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){
|
||||||
String key = AppRedisKey.CONTROL + nDid;
|
String key4 = AppRedisKey.CONTROL + nDid;
|
||||||
redisUtil.saveByKeyWithExpire(key,"success",10L);
|
redisUtil.saveByKeyWithExpire(key4,"success",10L);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
csLogsFeignClient.addUserLog(logDto);
|
//csLogsFeignClient.addUserLog(logDto);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -493,7 +480,7 @@ public class MqttMessageHandler {
|
|||||||
switch (res.getType()){
|
switch (res.getType()){
|
||||||
case 4865:
|
case 4865:
|
||||||
//设置心跳时间,超时改为掉线
|
//设置心跳时间,超时改为掉线
|
||||||
redisUtil.saveByKeyWithExpire("MQTT:" + nDid, Instant.now().toEpochMilli(),300L);
|
redisUtil.saveByKeyWithExpire("MQTT:" + nDid, Instant.now().toEpochMilli(),180L);
|
||||||
//有心跳,则将装置改成在线
|
//有心跳,则将装置改成在线
|
||||||
//csEquipmentDeliveryService.updateRunStatusBynDid(nDid,AccessEnum.ONLINE.getCode());
|
//csEquipmentDeliveryService.updateRunStatusBynDid(nDid,AccessEnum.ONLINE.getCode());
|
||||||
//处理心跳
|
//处理心跳
|
||||||
@@ -538,7 +525,8 @@ public class MqttMessageHandler {
|
|||||||
switch (dataDto.getMsg().getDataAttr()) {
|
switch (dataDto.getMsg().getDataAttr()) {
|
||||||
//暂态事件、录波处理、工程信息
|
//暂态事件、录波处理、工程信息
|
||||||
case 0:
|
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);
|
EventDto eventDto = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), EventDto.class);
|
||||||
JSONObject jsonObject0 = JSONObject.parseObject(JSON.toJSONString(eventDto));
|
JSONObject jsonObject0 = JSONObject.parseObject(JSON.toJSONString(eventDto));
|
||||||
AppEventMessage appEventMessage = JSONObject.toJavaObject(jsonObject0, AppEventMessage.class);
|
AppEventMessage appEventMessage = JSONObject.toJavaObject(jsonObject0, AppEventMessage.class);
|
||||||
@@ -548,16 +536,20 @@ public class MqttMessageHandler {
|
|||||||
//实时数据
|
//实时数据
|
||||||
case 1:
|
case 1:
|
||||||
log.info(nDid + "处理实时数据");
|
log.info(nDid + "处理实时数据");
|
||||||
break;
|
|
||||||
//处理主动上送的统计数据
|
|
||||||
case 2:
|
|
||||||
JSONObject jsonObject2 = JSONObject.parseObject(JSON.toJSONString(dataDto));
|
JSONObject jsonObject2 = JSONObject.parseObject(JSON.toJSONString(dataDto));
|
||||||
AppAutoDataMessage appAutoDataMessage = JSONObject.toJavaObject(jsonObject2, AppAutoDataMessage.class);
|
AppAutoDataMessage appAutoDataMessage = JSONObject.toJavaObject(jsonObject2, AppAutoDataMessage.class);
|
||||||
appAutoDataMessage.setId(nDid);
|
appAutoDataMessage.setId(nDid);
|
||||||
appAutoDataMessage.getMsg().getDataArray().forEach(item->{
|
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());
|
log.info(nDid + "处理统计数据" + item.getDataAttr());
|
||||||
});
|
});
|
||||||
appAutoDataMessageTemplate.sendMember(appAutoDataMessage);
|
appAutoDataMessageTemplate.sendMember(appAutoDataMessage2);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -589,6 +581,7 @@ public class MqttMessageHandler {
|
|||||||
switch (fileDto.getType()){
|
switch (fileDto.getType()){
|
||||||
case 4657:
|
case 4657:
|
||||||
log.info("获取文件信息" + fileDto);
|
log.info("获取文件信息" + fileDto);
|
||||||
|
if (Objects.equals(fileDto.getCode(),AccessEnum.SUCCESS.getCode())) {
|
||||||
String key = AppRedisKey.PROJECT_INFO + nDid;
|
String key = AppRedisKey.PROJECT_INFO + nDid;
|
||||||
if (Objects.isNull(fileDto.getMsg().getType())) {
|
if (Objects.isNull(fileDto.getMsg().getType())) {
|
||||||
handleDefaultCase(fileDto, nDid);
|
handleDefaultCase(fileDto, nDid);
|
||||||
@@ -600,12 +593,30 @@ public class MqttMessageHandler {
|
|||||||
appFileMessageTemplate.sendMember(appFileMessage);
|
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;
|
break;
|
||||||
case 4658:
|
case 4658:
|
||||||
log.info("获取文件流信息");
|
log.info("获取文件流信息");
|
||||||
FileRedisDto dto = new FileRedisDto();
|
FileRedisDto dto = new FileRedisDto();
|
||||||
dto.setCode(fileDto.getCode());
|
dto.setCode(fileDto.getCode());
|
||||||
redisUtil.saveByKeyWithExpire(AppRedisKey.DOWNLOAD + fileDto.getMsg().getName() + fileDto.getMid(),dto,10L);
|
redisUtil.saveByKeyWithExpire(AppRedisKey.DOWNLOAD + fileDto.getMsg().getName() + fileDto.getMid(),dto,60L);
|
||||||
if (Objects.equals(fileDto.getCode(),AccessEnum.SUCCESS.getCode())){
|
if (Objects.equals(fileDto.getCode(),AccessEnum.SUCCESS.getCode())){
|
||||||
appFileStreamMessageTemplate.sendMember(appFileMessage);
|
appFileStreamMessageTemplate.sendMember(appFileMessage);
|
||||||
}
|
}
|
||||||
@@ -618,7 +629,7 @@ public class MqttMessageHandler {
|
|||||||
log.info("装置收到系统上传的文件");
|
log.info("装置收到系统上传的文件");
|
||||||
FileRedisDto fileRedisDto = new FileRedisDto();
|
FileRedisDto fileRedisDto = new FileRedisDto();
|
||||||
fileRedisDto.setCode(fileDto.getCode());
|
fileRedisDto.setCode(fileDto.getCode());
|
||||||
redisUtil.saveByKeyWithExpire(AppRedisKey.UPLOAD,fileRedisDto,10L);
|
redisUtil.saveByKeyWithExpire(AppRedisKey.UPLOAD.concat(nDid).concat(String.valueOf(fileDto.getMid())),fileRedisDto,10L);
|
||||||
redisUtil.saveByKeyWithExpire("uploading","uploading",20L);
|
redisUtil.saveByKeyWithExpire("uploading","uploading",20L);
|
||||||
break;
|
break;
|
||||||
case 4660:
|
case 4660:
|
||||||
@@ -650,7 +661,7 @@ public class MqttMessageHandler {
|
|||||||
public void devErrorInfo(String topic, MqttMessage message, @NamedValue("version") String version, @NamedValue("edgeId") String nDid, @Payload String payload) {
|
public void devErrorInfo(String topic, MqttMessage message, @NamedValue("version") String version, @NamedValue("edgeId") String nDid, @Payload String payload) {
|
||||||
//解析数据
|
//解析数据
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
log.info(nDid + "事件报文为:" + new String(message.getPayload(), StandardCharsets.UTF_8));
|
//log.info(nDid + "事件报文为:" + new String(message.getPayload(), StandardCharsets.UTF_8));
|
||||||
EventDto eventDto = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), EventDto.class);
|
EventDto eventDto = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), EventDto.class);
|
||||||
JSONObject jsonObject0 = JSONObject.parseObject(JSON.toJSONString(eventDto));
|
JSONObject jsonObject0 = JSONObject.parseObject(JSON.toJSONString(eventDto));
|
||||||
AppEventMessage appEventMessage = JSONObject.toJavaObject(jsonObject0, AppEventMessage.class);
|
AppEventMessage appEventMessage = JSONObject.toJavaObject(jsonObject0, AppEventMessage.class);
|
||||||
@@ -660,13 +671,13 @@ public class MqttMessageHandler {
|
|||||||
|
|
||||||
private void saveDirectoryInfo(List<FileDto.DirInfo> dirInfo, String key) {
|
private void saveDirectoryInfo(List<FileDto.DirInfo> dirInfo, String key) {
|
||||||
if (!CollectionUtil.isEmpty(dirInfo)) {
|
if (!CollectionUtil.isEmpty(dirInfo)) {
|
||||||
redisUtil.saveByKeyWithExpire(key, dirInfo, 10L);
|
redisUtil.saveByKeyWithExpire(key, dirInfo, 60L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveFileInfo(FileDto.FileInfo fileInfo, String key) {
|
private void saveFileInfo(FileDto.FileInfo fileInfo, String key) {
|
||||||
if (!Objects.isNull(fileInfo)) {
|
if (!Objects.isNull(fileInfo)) {
|
||||||
redisUtil.saveByKeyWithExpire(key, fileInfo, 10L);
|
redisUtil.saveByKeyWithExpire(key, fileInfo, 60L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -699,7 +710,7 @@ public class MqttMessageHandler {
|
|||||||
askDataDto.setEndTime(-1);
|
askDataDto.setEndTime(-1);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 1:
|
case 1:
|
||||||
reqAndResParam.setDid(2);
|
reqAndResParam.setDid(0);
|
||||||
askDataDto.setCldid(0);
|
askDataDto.setCldid(0);
|
||||||
askDataDto.setDataType(1);
|
askDataDto.setDataType(1);
|
||||||
break;
|
break;
|
||||||
@@ -723,7 +734,7 @@ public class MqttMessageHandler {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
reqAndResParam.setMsg(askDataDto);
|
reqAndResParam.setMsg(askDataDto);
|
||||||
log.info("askDevData的请求报文:" + new Gson().toJson(reqAndResParam));
|
//log.info("askDevData的请求报文:" + new Gson().toJson(reqAndResParam));
|
||||||
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid, new Gson().toJson(reqAndResParam),1,false);
|
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid, new Gson().toJson(reqAndResParam),1,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
package com.njcn.access.listener;
|
package com.njcn.access.listener;
|
||||||
|
|
||||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
|
||||||
import com.njcn.access.enums.AccessEnum;
|
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.ICsDeviceOnlineLogsService;
|
||||||
import com.njcn.access.service.ICsEquipmentDeliveryService;
|
import com.njcn.access.service.ICsEquipmentDeliveryService;
|
||||||
import com.njcn.access.service.ICsTopicService;
|
import com.njcn.access.service.ICsTopicService;
|
||||||
import com.njcn.access.service.impl.CsDeviceServiceImpl;
|
import com.njcn.access.service.impl.CsDeviceServiceImpl;
|
||||||
import com.njcn.access.utils.MqttUtil;
|
import com.njcn.access.utils.MqttUtil;
|
||||||
|
import com.njcn.access.utils.SendMessageUtil;
|
||||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||||
import com.njcn.csdevice.api.CsDeviceUserFeignClient;
|
import com.njcn.csdevice.api.CsDeviceUserFeignClient;
|
||||||
import com.njcn.csdevice.api.CsLedgerFeignClient;
|
import com.njcn.csdevice.api.CsLedgerFeignClient;
|
||||||
@@ -14,11 +16,11 @@ import com.njcn.csdevice.api.CsLogsFeignClient;
|
|||||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||||
import com.njcn.csdevice.pojo.dto.DevDetailDTO;
|
import com.njcn.csdevice.pojo.dto.DevDetailDTO;
|
||||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||||
|
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||||
import com.njcn.redis.utils.RedisUtil;
|
import com.njcn.redis.utils.RedisUtil;
|
||||||
import com.njcn.user.api.AppUserFeignClient;
|
import com.njcn.user.api.AppUserFeignClient;
|
||||||
import com.njcn.user.api.UserFeignClient;
|
import com.njcn.user.api.UserFeignClient;
|
||||||
import com.njcn.user.pojo.po.User;
|
import com.njcn.user.pojo.po.User;
|
||||||
import com.njcn.zlevent.pojo.dto.NoticeUserDto;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.data.redis.connection.Message;
|
import org.springframework.data.redis.connection.Message;
|
||||||
@@ -27,13 +29,6 @@ import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.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;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -77,14 +72,14 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
|||||||
private UserFeignClient userFeignClient;
|
private UserFeignClient userFeignClient;
|
||||||
@Resource
|
@Resource
|
||||||
private RedisUtil redisUtil;
|
private RedisUtil redisUtil;
|
||||||
|
@Resource
|
||||||
|
private SendMessageUtil sendMessageUtil;
|
||||||
private final Object lock = new Object();
|
private final Object lock = new Object();
|
||||||
|
|
||||||
public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
|
public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
|
||||||
super(listenerContainer);
|
super(listenerContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 当前尝试次数
|
|
||||||
private static int attemptCount = 1;
|
|
||||||
//最大告警次数
|
//最大告警次数
|
||||||
private static int MAX_WARNING_TIMES = 0;
|
private static int MAX_WARNING_TIMES = 0;
|
||||||
|
|
||||||
@@ -111,59 +106,66 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
|||||||
//1.装置心跳断连
|
//1.装置心跳断连
|
||||||
//2.MQTT客户端不在线
|
//2.MQTT客户端不在线
|
||||||
private void executeMainTask(ScheduledExecutorService scheduler, String nDid, String version) {
|
private void executeMainTask(ScheduledExecutorService scheduler, String nDid, String version) {
|
||||||
System.out.println("正在执行主任务...");
|
log.info("正在执行主任务...");
|
||||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||||
logDto.setUserName("装置失去心跳触发");
|
logDto.setUserName("运维管理员");
|
||||||
|
logDto.setLoginName("njcnyw");
|
||||||
//判断mqtt
|
//判断mqtt
|
||||||
String clientName = "NJCN-" + nDid.substring(nDid.length() - 6);
|
String clientName = "NJCN-" + nDid.substring(nDid.length() - 6);
|
||||||
boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
||||||
//心跳异常,但是客户端在线,则发送接入请求
|
//心跳异常,但是客户端在线,则发送接入请求
|
||||||
//这边可能存在装置已经掉线,但是客户端仍然在线的情况
|
|
||||||
if (mqttClient) {
|
if (mqttClient) {
|
||||||
csDeviceService.devAccessAskTemplate(nDid,version,1);
|
csDeviceService.devAccessAskTemplate(nDid,version,1);
|
||||||
|
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,1);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(2000);
|
Thread.sleep(5000);
|
||||||
Object object = redisUtil.getObjectByKey("online" + nDid);
|
Object object = redisUtil.getObjectByKey("online" + nDid);
|
||||||
if (Objects.nonNull(object)) {
|
if (Objects.nonNull(object)) {
|
||||||
scheduler.shutdown();
|
scheduler.shutdown();
|
||||||
logDto.setOperate("客户端在线重连成功");
|
logDto.setOperate(nDid + "客户端在线重连成功");
|
||||||
} else {
|
} else {
|
||||||
//装置下线
|
//装置下线
|
||||||
csEquipmentDeliveryService.updateRunStatusBynDid(nDid, AccessEnum.OFFLINE.getCode());
|
csEquipmentDeliveryService.updateRunStatusBynDid(nDid, AccessEnum.OFFLINE.getCode());
|
||||||
startScheduledTask(scheduler,nDid,version);
|
startScheduledTask(scheduler,nDid,version);
|
||||||
logDto.setOperate("客户端离线进入定时任务");
|
logDto.setOperate(nDid +"客户端离线进入定时任务");
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
csLogsFeignClient.addUserLog(logDto);
|
||||||
}
|
}
|
||||||
//客户端不在线则修改装置状态,进入定时任务
|
//客户端不在线则修改装置状态,进入定时任务
|
||||||
else {
|
else {
|
||||||
//装置下线
|
//装置下线
|
||||||
csEquipmentDeliveryService.updateRunStatusBynDid(nDid, AccessEnum.OFFLINE.getCode());
|
csEquipmentDeliveryService.updateRunStatusBynDid(nDid, AccessEnum.OFFLINE.getCode());
|
||||||
|
logDto.setOperate(nDid +"主任务执行失败,装置下线,进入定时任务");
|
||||||
|
csLogsFeignClient.addUserLog(logDto);
|
||||||
|
log.info("客户端离线进入定时任务...");
|
||||||
startScheduledTask(scheduler,nDid,version);
|
startScheduledTask(scheduler,nDid,version);
|
||||||
}
|
}
|
||||||
csLogsFeignClient.addUserLog(logDto);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startScheduledTask(ScheduledExecutorService scheduler, String nDid, String version) {
|
private void startScheduledTask(ScheduledExecutorService scheduler, String nDid, String version) {
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
NoticeUserDto dto = sendOffLine(nDid);
|
NoticeUserDto dto = sendOffLine(nDid);
|
||||||
sendEventToUser(dto);
|
sendMessageUtil.sendEventToUser(dto);
|
||||||
addLogs(dto);
|
addLogs(dto);
|
||||||
String clientName = "NJCN-" + nDid.substring(nDid.length() - 6);
|
String clientName = "NJCN-" + nDid.substring(nDid.length() - 6);
|
||||||
ScheduledFuture<?> future = scheduler.scheduleAtFixedRate(() -> {
|
ScheduledFuture<?> future = scheduler.scheduleAtFixedRate(() -> {
|
||||||
System.out.println(nDid + "执行重连定时任务...");
|
log.info(nDid + "执行重连定时任务...");
|
||||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||||
logDto.setOperate(nDid + "重连定时任务");
|
logDto.setOperate(nDid + "重连定时任务");
|
||||||
//判断客户端
|
//判断客户端
|
||||||
boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
||||||
if (mqttClient) {
|
if (mqttClient) {
|
||||||
csDeviceService.devAccessAskTemplate(nDid,version,attemptCount++);
|
csDeviceService.devAccessAskTemplate(nDid,version,1);
|
||||||
|
try {
|
||||||
|
Thread.sleep(5000);
|
||||||
Integer status = csEquipmentDeliveryService.queryEquipmentBynDid(nDid).getRunStatus();
|
Integer status = csEquipmentDeliveryService.queryEquipmentBynDid(nDid).getRunStatus();
|
||||||
if (Objects.equals(status,AccessEnum.ONLINE.getCode())){
|
if (Objects.equals(status,AccessEnum.ONLINE.getCode())){
|
||||||
logDto.setResult(1);
|
logDto.setResult(1);
|
||||||
scheduler.shutdown();
|
scheduler.shutdown();
|
||||||
|
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,1);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
logDto.setResult(0);
|
logDto.setResult(0);
|
||||||
@@ -171,19 +173,30 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
|||||||
MAX_WARNING_TIMES++;
|
MAX_WARNING_TIMES++;
|
||||||
if (MAX_WARNING_TIMES == 30) {
|
if (MAX_WARNING_TIMES == 30) {
|
||||||
NoticeUserDto dto2 = sendConnectFail(nDid);
|
NoticeUserDto dto2 = sendConnectFail(nDid);
|
||||||
sendEventToUser(dto2);
|
sendMessageUtil.sendEventToUser(dto2);
|
||||||
addLogs(dto2);
|
addLogs(dto2);
|
||||||
}
|
}
|
||||||
|
//记录装置掉线时间
|
||||||
|
CsDeviceOnlineLogs record = onlineLogsService.findLastData(nDid);
|
||||||
|
record.setOfflineTime(LocalDateTime.now());
|
||||||
|
onlineLogsService.updateById(record);
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//一个小时未连接上,则推送告警消息
|
//一个小时未连接上,则推送告警消息
|
||||||
MAX_WARNING_TIMES++;
|
MAX_WARNING_TIMES++;
|
||||||
if (MAX_WARNING_TIMES == 30) {
|
if (MAX_WARNING_TIMES == 30) {
|
||||||
NoticeUserDto dto2 = sendConnectFail(nDid);
|
NoticeUserDto dto2 = sendConnectFail(nDid);
|
||||||
sendEventToUser(dto2);
|
sendMessageUtil.sendEventToUser(dto2);
|
||||||
addLogs(dto2);
|
addLogs(dto2);
|
||||||
}
|
}
|
||||||
logDto.setResult(0);
|
logDto.setResult(0);
|
||||||
|
//记录装置掉线时间
|
||||||
|
CsDeviceOnlineLogs record = onlineLogsService.findLastData(nDid);
|
||||||
|
record.setOfflineTime(LocalDateTime.now());
|
||||||
|
onlineLogsService.updateById(record);
|
||||||
}
|
}
|
||||||
csLogsFeignClient.addUserLog(logDto);
|
csLogsFeignClient.addUserLog(logDto);
|
||||||
}, 0, 2, TimeUnit.MINUTES);
|
}, 0, 2, TimeUnit.MINUTES);
|
||||||
@@ -193,7 +206,6 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
|||||||
//掉线通知
|
//掉线通知
|
||||||
private NoticeUserDto sendOffLine(String nDid) {
|
private NoticeUserDto sendOffLine(String nDid) {
|
||||||
NoticeUserDto dto = new NoticeUserDto();
|
NoticeUserDto dto = new NoticeUserDto();
|
||||||
// NoticeUserDto.Payload payload = new NoticeUserDto.Payload();
|
|
||||||
dto.setTitle("设备离线");
|
dto.setTitle("设备离线");
|
||||||
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(nDid).getData();
|
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(nDid).getData();
|
||||||
DevDetailDTO devDetailDto = csLedgerFeignclient.queryDevDetail(po.getId()).getData();
|
DevDetailDTO devDetailDto = csLedgerFeignclient.queryDevDetail(po.getId()).getData();
|
||||||
@@ -203,16 +215,12 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
|||||||
String content = String.format(devDetailDto.getEngineeringName() + "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName() + "于" + dateStr + "离线");
|
String content = String.format(devDetailDto.getEngineeringName() + "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName() + "于" + dateStr + "离线");
|
||||||
dto.setContent(content);
|
dto.setContent(content);
|
||||||
dto.setPushClientId(getEventUser(po.getId(),true));
|
dto.setPushClientId(getEventUser(po.getId(),true));
|
||||||
// payload.setType(3);
|
|
||||||
// payload.setPath("/pages/message/message?type="+payload.getType());
|
|
||||||
// dto.setPayload(payload);
|
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
//重连失败通知
|
//重连失败通知
|
||||||
private NoticeUserDto sendConnectFail(String nDid) {
|
private NoticeUserDto sendConnectFail(String nDid) {
|
||||||
NoticeUserDto dto = new NoticeUserDto();
|
NoticeUserDto dto = new NoticeUserDto();
|
||||||
// NoticeUserDto.Payload payload = new NoticeUserDto.Payload();
|
|
||||||
dto.setTitle("设备接入失败");
|
dto.setTitle("设备接入失败");
|
||||||
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(nDid).getData();
|
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(nDid).getData();
|
||||||
DevDetailDTO devDetailDto = csLedgerFeignclient.queryDevDetail(po.getId()).getData();
|
DevDetailDTO devDetailDto = csLedgerFeignclient.queryDevDetail(po.getId()).getData();
|
||||||
@@ -222,16 +230,14 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
|||||||
String content = String.format(devDetailDto.getEngineeringName() + "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName() + "于" + dateStr + "多次接入失败");
|
String content = String.format(devDetailDto.getEngineeringName() + "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName() + "于" + dateStr + "多次接入失败");
|
||||||
dto.setContent(content);
|
dto.setContent(content);
|
||||||
dto.setPushClientId(getEventUser(po.getId(),false));
|
dto.setPushClientId(getEventUser(po.getId(),false));
|
||||||
// payload.setType(3);
|
|
||||||
// payload.setPath("/pages/message/message?type="+payload.getType());
|
|
||||||
// dto.setPayload(payload);
|
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
//日志记录
|
//日志记录
|
||||||
private void addLogs(NoticeUserDto noticeUserDto) {
|
private void addLogs(NoticeUserDto noticeUserDto) {
|
||||||
DeviceLogDTO dto = new DeviceLogDTO();
|
DeviceLogDTO dto = new DeviceLogDTO();
|
||||||
dto.setUserName(noticeUserDto.getTitle());
|
dto.setUserName("运维管理员");
|
||||||
|
dto.setLoginName("njcnyw");
|
||||||
dto.setOperate(noticeUserDto.getContent());
|
dto.setOperate(noticeUserDto.getContent());
|
||||||
csLogsFeignClient.addUserLog(dto);
|
csLogsFeignClient.addUserLog(dto);
|
||||||
}
|
}
|
||||||
@@ -249,44 +255,4 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
|||||||
List<User> users = userFeignClient.appuserByIdList(adminList).getData();
|
List<User> users = userFeignClient.appuserByIdList(adminList).getData();
|
||||||
return users.stream().map(User::getDevCode).filter(Objects::nonNull).filter(StringUtils::isNotBlank).distinct().collect(Collectors.toList());
|
return users.stream().map(User::getDevCode).filter(Objects::nonNull).filter(StringUtils::isNotBlank).distinct().collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,6 +4,8 @@ import com.njcn.access.service.ICsEquipmentDeliveryService;
|
|||||||
import com.njcn.access.service.ICsTopicService;
|
import com.njcn.access.service.ICsTopicService;
|
||||||
import com.njcn.access.service.impl.CsDeviceServiceImpl;
|
import com.njcn.access.service.impl.CsDeviceServiceImpl;
|
||||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||||
|
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||||
|
import com.njcn.redis.utils.RedisUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.boot.ApplicationArguments;
|
import org.springframework.boot.ApplicationArguments;
|
||||||
import org.springframework.boot.ApplicationRunner;
|
import org.springframework.boot.ApplicationRunner;
|
||||||
@@ -12,6 +14,9 @@ import org.springframework.stereotype.Component;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 类的介绍:用来重新发起设备的接入,存在程序意外停止了,缓存失效导致无法更新装置的状态,所以需要在程序启动时发起设备的接入
|
* 类的介绍:用来重新发起设备的接入,存在程序意外停止了,缓存失效导致无法更新装置的状态,所以需要在程序启动时发起设备的接入
|
||||||
@@ -25,21 +30,31 @@ import java.util.Objects;
|
|||||||
public class AccessApplicationRunner implements ApplicationRunner {
|
public class AccessApplicationRunner implements ApplicationRunner {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private CsDeviceServiceImpl csDeviceService;
|
private RedisUtil redisUtil;
|
||||||
|
@Resource
|
||||||
|
private ICsEquipmentDeliveryService csEquipmentDeliveryService;
|
||||||
@Resource
|
@Resource
|
||||||
private ICsTopicService csTopicService;
|
private ICsTopicService csTopicService;
|
||||||
@Resource
|
@Resource
|
||||||
private ICsEquipmentDeliveryService csEquipmentDeliveryService;
|
private CsDeviceServiceImpl csDeviceService;
|
||||||
|
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||||
|
private static final long ACCESS_TIME = 60L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(ApplicationArguments args) {
|
public void run(ApplicationArguments args) {
|
||||||
|
//项目启动60s后发起自动接入
|
||||||
|
Runnable task = () -> {
|
||||||
List<CsEquipmentDeliveryPO> list = csEquipmentDeliveryService.getAll();
|
List<CsEquipmentDeliveryPO> list = csEquipmentDeliveryService.getAll();
|
||||||
list.forEach(item->{
|
list.forEach(item->{
|
||||||
String version = csTopicService.getVersion(item.getNdid());
|
String version = csTopicService.getVersion(item.getNdid());
|
||||||
if (!Objects.isNull(version)){
|
if (!Objects.isNull(version)){
|
||||||
csDeviceService.devAccessAskTemplate(item.getNdid(),version,1);
|
csDeviceService.devAccessAskTemplate(item.getNdid(),version,1);
|
||||||
|
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + item.getNdid(),1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
scheduler.schedule(task, ACCESS_TIME, TimeUnit.SECONDS);
|
||||||
|
// 关闭调度程序
|
||||||
|
scheduler.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
@@ -16,4 +16,9 @@ public interface AskDeviceDataService {
|
|||||||
void createFolder(String nDid, String path);
|
void createFolder(String nDid, String path);
|
||||||
|
|
||||||
void deleteFolder(String nDid, String path);
|
void deleteFolder(String nDid, String path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实时数据请求报文
|
||||||
|
*/
|
||||||
|
void askRealData(String nDid, Integer idx, Integer size);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,11 +14,6 @@ import java.util.List;
|
|||||||
|
|
||||||
public interface ICsDevModelService {
|
public interface ICsDevModelService {
|
||||||
|
|
||||||
/**
|
|
||||||
* 初始化缓存模板信息
|
|
||||||
*/
|
|
||||||
void refreshDevModelCache();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析模板文件->入库
|
* 解析模板文件->入库
|
||||||
* @param file
|
* @param file
|
||||||
|
|||||||
@@ -36,6 +36,12 @@ public interface ICsEquipmentDeliveryService extends IService<CsEquipmentDeliver
|
|||||||
*/
|
*/
|
||||||
void updateRunStatusBynDid(String nDid,Integer id);
|
void updateRunStatusBynDid(String nDid,Integer id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据网关id修改设备当前流程
|
||||||
|
* @param nDid 网关id
|
||||||
|
*/
|
||||||
|
void updateProcessBynDid(String nDid,Integer processId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据ndid查询装置信息
|
* 根据ndid查询装置信息
|
||||||
* @param nDid
|
* @param nDid
|
||||||
|
|||||||
@@ -1,23 +1,18 @@
|
|||||||
package com.njcn.access.service.impl;
|
package com.njcn.access.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||||
import com.njcn.access.api.CsTopicFeignClient;
|
import com.njcn.access.api.CsTopicFeignClient;
|
||||||
import com.njcn.access.enums.AccessEnum;
|
import com.njcn.access.enums.AccessEnum;
|
||||||
import com.njcn.access.enums.TypeEnum;
|
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.ControlDto;
|
||||||
import com.njcn.access.pojo.dto.ReqAndResDto;
|
import com.njcn.access.pojo.dto.ReqAndResDto;
|
||||||
import com.njcn.access.pojo.dto.file.FileRedisDto;
|
|
||||||
import com.njcn.access.service.AskDeviceDataService;
|
import com.njcn.access.service.AskDeviceDataService;
|
||||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
||||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||||
import com.njcn.redis.utils.RedisUtil;
|
import com.njcn.redis.utils.RedisUtil;
|
||||||
import com.njcn.zlevent.pojo.dto.FileStreamDto;
|
|
||||||
import com.njcn.zlevent.pojo.dto.NoticeUserDto;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import net.sf.json.JSONObject;
|
import net.sf.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -25,11 +20,6 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.ScheduledFuture;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author xy
|
* @author xy
|
||||||
@@ -92,32 +82,16 @@ public class AskDeviceDataServiceImpl implements AskDeviceDataService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean downloadFile(String nDid, String name, Integer size, String fileCheck) {
|
public boolean downloadFile(String nDid, String name, Integer size, String fileCheck) {
|
||||||
boolean result = false;
|
boolean result = true;
|
||||||
try {
|
try {
|
||||||
redisUtil.saveByKeyWithExpire("fileDowning:"+nDid,"fileDowning",300L);
|
redisUtil.saveByKeyWithExpire("fileDowning:"+nDid,"fileDowning",120L);
|
||||||
redisUtil.saveByKeyWithExpire("fileCheck"+name,fileCheck,300L);
|
redisUtil.saveByKeyWithExpire("fileCheck"+nDid+name,fileCheck,120L);
|
||||||
Object object = getDeviceMid(nDid);
|
Object object = getDeviceMid(nDid);
|
||||||
if (!Objects.isNull(object)) {
|
if (!Objects.isNull(object)) {
|
||||||
mid = (Integer) object;
|
mid = (Integer) object;
|
||||||
}
|
}
|
||||||
ReqAndResDto.Req reqAndResParam = getAllPojo(mid,name);
|
ReqAndResDto.Req reqAndResParam = getAllPojo(mid,name);
|
||||||
publisher.send("/Pfm/DevFileCmd/V1/"+nDid,new Gson().toJson(reqAndResParam),1,false);
|
publisher.send("/Pfm/DevFileCmd/V1/"+nDid,new Gson().toJson(reqAndResParam),1,false);
|
||||||
//这里使用简单的轮询,但建议考虑更高效的机制
|
|
||||||
for (int i = 0; i < 120; i++) {
|
|
||||||
Thread.sleep(2000);
|
|
||||||
Object object2 = redisUtil.getObjectByKey("downloadFilePath:"+name);
|
|
||||||
if (!Objects.isNull(object2)) {
|
|
||||||
result = true;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
Object object3 = redisUtil.getObjectByKey(AppRedisKey.FILE_PART.concat(name));
|
|
||||||
if (!Objects.isNull(object3)) {
|
|
||||||
FileStreamDto dto = JSON.parseObject(JSON.toJSONString(object3), FileStreamDto.class);
|
|
||||||
String json = "{allStep:"+dto.getTotal()+",nowStep:"+ (CollectionUtil.isEmpty(dto.getList())?0:dto.getList().size())+"}";
|
|
||||||
publisher.send("/Web/Progress/" + nDid, new Gson().toJson(json), 1, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mid = mid + 1;
|
mid = mid + 1;
|
||||||
if (mid > 10000) {
|
if (mid > 10000) {
|
||||||
mid = 1;
|
mid = 1;
|
||||||
@@ -125,7 +99,7 @@ public class AskDeviceDataServiceImpl implements AskDeviceDataService {
|
|||||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,mid);
|
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,mid);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
redisUtil.delete("fileDowning:"+nDid);
|
redisUtil.delete("fileDowning:"+nDid);
|
||||||
redisUtil.delete("fileCheck"+name);
|
redisUtil.delete("fileCheck"+nDid+name);
|
||||||
throw new BusinessException(AlgorithmResponseEnum.FILE_DOWNLOAD_ERROR);
|
throw new BusinessException(AlgorithmResponseEnum.FILE_DOWNLOAD_ERROR);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -202,6 +176,39 @@ public class AskDeviceDataServiceImpl implements AskDeviceDataService {
|
|||||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,mid);
|
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,mid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void askRealData(String nDid, Integer idx, Integer clDId) {
|
||||||
|
Object object = getDeviceMid(nDid);
|
||||||
|
if (!Objects.isNull(object)) {
|
||||||
|
mid = (Integer) object;
|
||||||
|
}
|
||||||
|
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
|
||||||
|
reqAndResParam.setMid(mid);
|
||||||
|
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||||
|
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_6.getCode()));
|
||||||
|
reqAndResParam.setExpire(-1);
|
||||||
|
//fixme 目前设备都是直连设备,因此did就是其本身,默认为1,后期涉及网关,此did是需要动态变化的
|
||||||
|
reqAndResParam.setDid(1);
|
||||||
|
AskDataDto askDataDto = new AskDataDto();
|
||||||
|
askDataDto.setCldid(clDId);
|
||||||
|
askDataDto.setDataAttr(1);
|
||||||
|
askDataDto.setDataType(4);
|
||||||
|
askDataDto.setOperate(1);
|
||||||
|
askDataDto.setStartTime(-1);
|
||||||
|
askDataDto.setEndTime(-1);
|
||||||
|
askDataDto.setRtDuration(30);
|
||||||
|
askDataDto.setDsNameIdx(idx);
|
||||||
|
reqAndResParam.setMsg(askDataDto);
|
||||||
|
log.info("askDevData的请求报文:" + new Gson().toJson(reqAndResParam));
|
||||||
|
publisher.send("/Pfm/DevCmd/V1/"+nDid, new Gson().toJson(reqAndResParam),1,false);
|
||||||
|
mid = mid + 1;
|
||||||
|
if (mid > 10000) {
|
||||||
|
mid = 1;
|
||||||
|
}
|
||||||
|
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,mid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public Object getDeviceMid(String nDid) {
|
public Object getDeviceMid(String nDid) {
|
||||||
return redisUtil.getObjectByKey(AppRedisKey.DEVICE_MID + nDid);
|
return redisUtil.getObjectByKey(AppRedisKey.DEVICE_MID + nDid);
|
||||||
}
|
}
|
||||||
@@ -210,7 +217,6 @@ public class AskDeviceDataServiceImpl implements AskDeviceDataService {
|
|||||||
return csTopicFeignClient.find(nDid).getData();
|
return csTopicFeignClient.find(nDid).getData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全文件下载请求报文
|
* 全文件下载请求报文
|
||||||
*/
|
*/
|
||||||
@@ -245,39 +251,4 @@ public class AskDeviceDataServiceImpl implements AskDeviceDataService {
|
|||||||
reqAndResParam.setMsg(jsonObject);
|
reqAndResParam.setMsg(jsonObject);
|
||||||
return reqAndResParam;
|
return reqAndResParam;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据装置响应来判断是否询问下一帧数据
|
|
||||||
*/
|
|
||||||
public void sendNextStep(String fileName, String id, int mid,int step) {
|
|
||||||
try {
|
|
||||||
for (int i = 1; i < 4; i++) {
|
|
||||||
if (step == 0 ){
|
|
||||||
Thread.sleep(5000);
|
|
||||||
} else {
|
|
||||||
Thread.sleep(2000);
|
|
||||||
}
|
|
||||||
FileRedisDto fileRedisDto = (FileRedisDto) redisUtil.getObjectByKey(AppRedisKey.DOWNLOAD + fileName + mid);
|
|
||||||
if (Objects.isNull(fileRedisDto)) {
|
|
||||||
FileRedisDto failDto = new FileRedisDto();
|
|
||||||
failDto.setCode(400);
|
|
||||||
redisUtil.saveByKeyWithExpire(AppRedisKey.DOWNLOAD + fileName + mid,failDto,10L);
|
|
||||||
} else {
|
|
||||||
if (Objects.equals(fileRedisDto.getCode(),200)) {
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
log.info("第" +i+"次尝试");
|
|
||||||
//尝试失败则设置code为400,如果装置响应了,则会将code置为200
|
|
||||||
FileRedisDto failDto = new FileRedisDto();
|
|
||||||
failDto.setCode(400);
|
|
||||||
redisUtil.saveByKeyWithExpire(AppRedisKey.DOWNLOAD + fileName + mid,failDto,10L);
|
|
||||||
ReqAndResDto.Req req = getPojo(mid,fileName,step);
|
|
||||||
publisher.send("/Pfm/DevFileCmd/V1/" + id, new Gson().toJson(req), 1, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new BusinessException(AlgorithmResponseEnum.ASK_DEVICE_DIR_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ public class CsDataSetServiceImpl extends ServiceImpl<CsDataSetMapper, CsDataSet
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<CsDataSet> getDataSetData(String modelId) {
|
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::getDataType,"Stat").or().isNull(CsDataSet::getDataType))
|
||||||
|
.list();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,12 @@ package com.njcn.access.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
|
||||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||||
import com.njcn.access.enums.AccessEnum;
|
import com.njcn.access.enums.AccessEnum;
|
||||||
import com.njcn.access.enums.AccessResponseEnum;
|
import com.njcn.access.enums.AccessResponseEnum;
|
||||||
import com.njcn.access.enums.DataModel;
|
import com.njcn.access.enums.DataModel;
|
||||||
import com.njcn.access.enums.TypeEnum;
|
import com.njcn.access.enums.TypeEnum;
|
||||||
import com.njcn.access.handler.MqttMessageHandler;
|
|
||||||
import com.njcn.access.mapper.CsDevModelMapper;
|
import com.njcn.access.mapper.CsDevModelMapper;
|
||||||
import com.njcn.access.pojo.dto.ReqAndResDto;
|
import com.njcn.access.pojo.dto.ReqAndResDto;
|
||||||
import com.njcn.access.pojo.dto.UploadFileDto;
|
import com.njcn.access.pojo.dto.UploadFileDto;
|
||||||
@@ -21,13 +19,12 @@ import com.njcn.access.service.*;
|
|||||||
import com.njcn.access.utils.CRC32Utils;
|
import com.njcn.access.utils.CRC32Utils;
|
||||||
import com.njcn.access.utils.JsonUtil;
|
import com.njcn.access.utils.JsonUtil;
|
||||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
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.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.csdevice.api.CsLogsFeignClient;
|
import com.njcn.csdevice.api.CsLogsFeignClient;
|
||||||
import com.njcn.csdevice.api.DevModelFeignClient;
|
import com.njcn.csdevice.api.DevModelFeignClient;
|
||||||
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
||||||
|
import com.njcn.csdevice.pojo.param.CsDevModelAddParm;
|
||||||
import com.njcn.csdevice.pojo.po.*;
|
import com.njcn.csdevice.pojo.po.*;
|
||||||
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
|
|
||||||
import com.njcn.oss.constant.OssPath;
|
import com.njcn.oss.constant.OssPath;
|
||||||
import com.njcn.oss.utils.FileStorageUtil;
|
import com.njcn.oss.utils.FileStorageUtil;
|
||||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||||
@@ -64,51 +61,23 @@ import java.util.stream.Collectors;
|
|||||||
public class CsDevModelServiceImpl implements ICsDevModelService {
|
public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||||
|
|
||||||
private final FileStorageUtil fileStorageUtil;
|
private final FileStorageUtil fileStorageUtil;
|
||||||
|
|
||||||
private final DevModelFeignClient devModelFeignClient;
|
private final DevModelFeignClient devModelFeignClient;
|
||||||
|
|
||||||
private final EpdFeignClient epdFeignClient;
|
private final EpdFeignClient epdFeignClient;
|
||||||
|
|
||||||
private final DicDataFeignClient dicDataFeignClient;
|
private final DicDataFeignClient dicDataFeignClient;
|
||||||
|
|
||||||
private final EleEvtFeignClient eleEvtFeignClient;
|
private final EleEvtFeignClient eleEvtFeignClient;
|
||||||
|
|
||||||
private final ICsDataSetService csDataSetService;
|
private final ICsDataSetService csDataSetService;
|
||||||
|
|
||||||
private final ICsDataArrayService csDataArrayService;
|
private final ICsDataArrayService csDataArrayService;
|
||||||
|
|
||||||
private final CsDevModelMapper csDevModelMapper;
|
private final CsDevModelMapper csDevModelMapper;
|
||||||
|
|
||||||
private final ICsLineModelService csLineModelService;
|
private final ICsLineModelService csLineModelService;
|
||||||
|
|
||||||
private final ICsGroupService csGroupService;
|
private final ICsGroupService csGroupService;
|
||||||
|
|
||||||
private final ICsGroArrService csGroArrService;
|
private final ICsGroArrService csGroArrService;
|
||||||
|
|
||||||
private final CsLogsFeignClient csLogsFeignClient;
|
private final CsLogsFeignClient csLogsFeignClient;
|
||||||
|
|
||||||
private final EleWaveFeignClient waveFeignClient;
|
private final EleWaveFeignClient waveFeignClient;
|
||||||
|
|
||||||
private final DictTreeFeignClient dictTreeFeignClient;
|
private final DictTreeFeignClient dictTreeFeignClient;
|
||||||
|
|
||||||
private final MqttPublisher publisher;
|
private final MqttPublisher publisher;
|
||||||
|
|
||||||
private final ICsTopicService csTopicService;
|
private final ICsTopicService csTopicService;
|
||||||
|
|
||||||
private final ICsEquipmentDeliveryService csEquipmentDeliveryService;
|
|
||||||
|
|
||||||
private final RedisUtil redisUtil;
|
private final RedisUtil redisUtil;
|
||||||
|
|
||||||
private final MqttMessageHandler mqttMessageHandler;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void refreshDevModelCache() {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = {Exception.class})
|
@Transactional(rollbackFor = {Exception.class})
|
||||||
public void addModel(MultipartFile file) {
|
public void addModel(MultipartFile file) {
|
||||||
@@ -191,7 +160,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
|||||||
int times = bytes.length / cap + 1;
|
int times = bytes.length / cap + 1;
|
||||||
for (int i = 1; i <= times; i++) {
|
for (int i = 1; i <= times; i++) {
|
||||||
//发送数据给前端
|
//发送数据给前端
|
||||||
String json = "{allStep:"+times+",nowStep:"+i+"}";
|
String json = "{fileName:"+file.getOriginalFilename()+",allStep:"+times+",nowStep:"+i+"}";
|
||||||
publisher.send("/Web/Progress/" + id, new Gson().toJson(json), 1, false);
|
publisher.send("/Web/Progress/" + id, new Gson().toJson(json), 1, false);
|
||||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||||
byte[] lsBytes;
|
byte[] lsBytes;
|
||||||
@@ -204,7 +173,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
|||||||
length = length - cap;
|
length = length - cap;
|
||||||
//判断是否重发
|
//判断是否重发
|
||||||
sendNextStep(logDto,path,file,bytes.length,lsBytes,(i-1)*cap,version,id,i,hexString,false);
|
sendNextStep(logDto,path,file,bytes.length,lsBytes,(i-1)*cap,version,id,i,hexString,false);
|
||||||
FileRedisDto fileRedisDto = (FileRedisDto) redisUtil.getObjectByKey(AppRedisKey.UPLOAD);
|
FileRedisDto fileRedisDto = (FileRedisDto) redisUtil.getObjectByKey(AppRedisKey.UPLOAD.concat(id).concat(String.valueOf(i)));
|
||||||
//重发之后判断继续循环还是跳出循环
|
//重发之后判断继续循环还是跳出循环
|
||||||
if (!Objects.isNull(fileRedisDto) && !Objects.equals(fileRedisDto.getCode(),200)) {
|
if (!Objects.isNull(fileRedisDto) && !Objects.equals(fileRedisDto.getCode(),200)) {
|
||||||
redisUtil.delete("uploading");
|
redisUtil.delete("uploading");
|
||||||
@@ -222,7 +191,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
|||||||
csLogsFeignClient.addUserLog(logDto);
|
csLogsFeignClient.addUserLog(logDto);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String json = "{allStep:\""+1+"\",nowStep:"+1+"}";
|
String json = "{fileName:"+file.getOriginalFilename()+",allStep:\""+1+"\",nowStep:"+1+"}";
|
||||||
publisher.send("/Web/Progress", new Gson().toJson(json), 1, false);
|
publisher.send("/Web/Progress", new Gson().toJson(json), 1, false);
|
||||||
ReqAndResDto.Req req = getPojo(1,path,file,length,bytes,0,hexString);
|
ReqAndResDto.Req req = getPojo(1,path,file,length,bytes,0,hexString);
|
||||||
publisher.send("/Pfm/DevFileCmd/" + version + "/" + id, new Gson().toJson(req), 1, false);
|
publisher.send("/Pfm/DevFileCmd/" + version + "/" + id, new Gson().toJson(req), 1, false);
|
||||||
@@ -277,20 +246,20 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
|||||||
if (result) {
|
if (result) {
|
||||||
Thread.sleep(10000);
|
Thread.sleep(10000);
|
||||||
} else {
|
} else {
|
||||||
Thread.sleep(2000);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
FileRedisDto fileRedisDto = (FileRedisDto) redisUtil.getObjectByKey(AppRedisKey.UPLOAD);
|
FileRedisDto fileRedisDto = (FileRedisDto) redisUtil.getObjectByKey(AppRedisKey.UPLOAD.concat(id).concat(String.valueOf(mid)));
|
||||||
if (Objects.isNull(fileRedisDto)) {
|
if (Objects.isNull(fileRedisDto)) {
|
||||||
FileRedisDto fileRedis = new FileRedisDto();
|
FileRedisDto fileRedis = new FileRedisDto();
|
||||||
fileRedis.setCode(400);
|
fileRedis.setCode(400);
|
||||||
redisUtil.saveByKeyWithExpire(AppRedisKey.UPLOAD,fileRedis,10L);
|
redisUtil.saveByKeyWithExpire(AppRedisKey.UPLOAD.concat(id).concat(String.valueOf(mid)),fileRedis,10L);
|
||||||
} else {
|
} else {
|
||||||
if (Objects.equals(fileRedisDto.getCode(),200)) {
|
if (Objects.equals(fileRedisDto.getCode(),200)) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
FileRedisDto fileRedis = new FileRedisDto();
|
FileRedisDto fileRedis = new FileRedisDto();
|
||||||
fileRedis.setCode(400);
|
fileRedis.setCode(400);
|
||||||
redisUtil.saveByKeyWithExpire(AppRedisKey.UPLOAD,fileRedis,10L);
|
redisUtil.saveByKeyWithExpire(AppRedisKey.UPLOAD.concat(id).concat(String.valueOf(mid)),fileRedis,10L);
|
||||||
ReqAndResDto.Req req = getPojo(mid,path,file,length,bytes,offset,fileCheck);
|
ReqAndResDto.Req req = getPojo(mid,path,file,length,bytes,offset,fileCheck);
|
||||||
publisher.send("/Pfm/DevFileCmd/" + version + "/" + id, new Gson().toJson(req), 1, false);
|
publisher.send("/Pfm/DevFileCmd/" + version + "/" + id, new Gson().toJson(req), 1, false);
|
||||||
logDto.setOperate(id + "系统上送文件,装置响应失败,重新发送,这是第" + (i+1) + "次");
|
logDto.setOperate(id + "系统上送文件,装置响应失败,重新发送,这是第" + (i+1) + "次");
|
||||||
@@ -326,20 +295,33 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
|||||||
csLogsFeignClient.addUserLog(logDto);
|
csLogsFeignClient.addUserLog(logDto);
|
||||||
throw new BusinessException(AccessResponseEnum.MODEL_REPEAT);
|
throw new BusinessException(AccessResponseEnum.MODEL_REPEAT);
|
||||||
}
|
}
|
||||||
CsDevModelPO model = new CsDevModelPO();
|
// CsDevModelPO model = new CsDevModelPO();
|
||||||
model.setDevTypeName(templateDto.getDevType());
|
// model.setDevTypeName(templateDto.getDevType());
|
||||||
model.setName(templateDto.getDevType());
|
// model.setName(templateDto.getDevType());
|
||||||
model.setVersionNo(templateDto.getVersion());
|
// model.setVersionNo(templateDto.getVersion());
|
||||||
model.setVersionDate(Date.valueOf(templateDto.getTime()));
|
// model.setVersionDate(Date.valueOf(templateDto.getTime()));
|
||||||
model.setFilePath(filePath);
|
// model.setFilePath(filePath);
|
||||||
model.setStatus ("1");
|
// 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 先用数据类型来区分模板的类型
|
//fixme 先用数据类型来区分模板的类型
|
||||||
if (templateDto.getDataList().contains("Apf") || templateDto.getDataList().contains("Dvr")){
|
if (templateDto.getDataList().contains("Apf") || templateDto.getDataList().contains("Dvr")){
|
||||||
model.setType(0);
|
csDevModelAddParm.setType(0);
|
||||||
} else {
|
} else {
|
||||||
model.setType(1);
|
csDevModelAddParm.setType(1);
|
||||||
}
|
}
|
||||||
csDevModelMapper.insert(model);
|
CsDevModelPO model = devModelFeignClient.addDevModel(csDevModelAddParm).getData();
|
||||||
csLogsFeignClient.addUserLog(logDto);
|
csLogsFeignClient.addUserLog(logDto);
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
@@ -873,6 +855,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
|||||||
csDataSet.setPeriod(item1.getPeriod());
|
csDataSet.setPeriod(item1.getPeriod());
|
||||||
csDataSet.setStoreFlag(item1.getStoreFlag());
|
csDataSet.setStoreFlag(item1.getStoreFlag());
|
||||||
csDataSet.setDataList(String.join(",",templateDto.getDataList()));
|
csDataSet.setDataList(String.join(",",templateDto.getDataList()));
|
||||||
|
csDataSet.setDataType(item1.getDataAttr());
|
||||||
csDataSet.setType(0);
|
csDataSet.setType(0);
|
||||||
csDataSet.setClDev(0);
|
csDataSet.setClDev(0);
|
||||||
csDataSet.setDataLevel(item1.getDataLevel());
|
csDataSet.setDataLevel(item1.getDataLevel());
|
||||||
@@ -910,6 +893,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
|||||||
csDataSet.setStoreFlag(item4.getStoreFlag());
|
csDataSet.setStoreFlag(item4.getStoreFlag());
|
||||||
csDataSet.setDataList(String.join(",",item3.getDataList()));
|
csDataSet.setDataList(String.join(",",item3.getDataList()));
|
||||||
csDataSet.setDataLevel(item4.getDataLevel());
|
csDataSet.setDataLevel(item4.getDataLevel());
|
||||||
|
csDataSet.setDataType(item4.getDataAttr());
|
||||||
//fixme 先用数据类型来区分模板的类型
|
//fixme 先用数据类型来区分模板的类型
|
||||||
if (item3.getDataList().contains("Apf") || item3.getDataList().contains("Dvr")){
|
if (item3.getDataList().contains("Apf") || item3.getDataList().contains("Dvr")){
|
||||||
csDataSet.setType(1);
|
csDataSet.setType(1);
|
||||||
@@ -1209,48 +1193,48 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
|||||||
* 数据集名称调整
|
* 数据集名称调整
|
||||||
*/
|
*/
|
||||||
public String dataSetName(String name,String code){
|
public String dataSetName(String name,String code){
|
||||||
String showName = null;
|
String showName = name;
|
||||||
switch (name) {
|
switch (name) {
|
||||||
//数据集
|
//数据集
|
||||||
case "Ds$Apf$Master$01":
|
case "Ds$Apf$Master$01":
|
||||||
showName = "APF模块数据";
|
showName = "APF模块数据模板";
|
||||||
break;
|
break;
|
||||||
case "Ds$Apf$module$01":
|
case "Ds$Apf$module$01":
|
||||||
showName = "APF模块1数据";
|
showName = "APF模块1数据模板";
|
||||||
break;
|
break;
|
||||||
case "Ds$Apf$module$02":
|
case "Ds$Apf$module$02":
|
||||||
showName = "APF模块2数据";
|
showName = "APF模块2数据模板";
|
||||||
break;
|
break;
|
||||||
case "Ds$Apf$module$03":
|
case "Ds$Apf$module$03":
|
||||||
showName = "APF模块3数据";
|
showName = "APF模块3数据模板";
|
||||||
break;
|
break;
|
||||||
case "Ds$Apf$module$04":
|
case "Ds$Apf$module$04":
|
||||||
showName = "APF模块4数据";
|
showName = "APF模块4数据模板";
|
||||||
break;
|
break;
|
||||||
case "Ds$Apf$module$05":
|
case "Ds$Apf$module$05":
|
||||||
showName = "APF模块5数据";
|
showName = "APF模块5数据模板";
|
||||||
break;
|
break;
|
||||||
case "Ds$Apf$module$06":
|
case "Ds$Apf$module$06":
|
||||||
showName = "APF模块6数据";
|
showName = "APF模块6数据模板";
|
||||||
break;
|
break;
|
||||||
case "Ds$Apf$module$07":
|
case "Ds$Apf$module$07":
|
||||||
showName = "APF模块7数据";
|
showName = "APF模块7数据模板";
|
||||||
break;
|
break;
|
||||||
case "Ds$Apf$module$08":
|
case "Ds$Apf$module$08":
|
||||||
showName = "APF模块8数据";
|
showName = "APF模块8数据模板";
|
||||||
break;
|
break;
|
||||||
case "Ds$Pqd$Stat$01":
|
case "Ds$Pqd$Stat$01":
|
||||||
if (Objects.equals(code, DicDataEnum.CONNECT_DEV.getCode()) || Objects.isNull(code)){
|
if (Objects.equals(code, DicDataEnum.CONNECT_DEV.getCode()) || Objects.isNull(code)){
|
||||||
showName = "电网侧数据";
|
showName = "电网侧数据模板";
|
||||||
} else if (Objects.equals(code, DicDataEnum.PORTABLE.getCode())){
|
} else if (Objects.equals(code, DicDataEnum.PORTABLE.getCode())){
|
||||||
showName = "监测1路数据";
|
showName = "监测1#数据模板";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "Ds$Pqd$Stat$02":
|
case "Ds$Pqd$Stat$02":
|
||||||
if (Objects.equals(code, DicDataEnum.CONNECT_DEV.getCode()) || Objects.isNull(code)){
|
if (Objects.equals(code, DicDataEnum.CONNECT_DEV.getCode()) || Objects.isNull(code)){
|
||||||
showName = "负载侧数据";
|
showName = "负载侧数据模板";
|
||||||
} else if (Objects.equals(code, DicDataEnum.PORTABLE.getCode())){
|
} else if (Objects.equals(code, DicDataEnum.PORTABLE.getCode())){
|
||||||
showName = "监测2路数据";
|
showName = "监测2#数据模板";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//波形参数名称
|
//波形参数名称
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package com.njcn.access.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
|
||||||
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
|
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
|
||||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
@@ -11,7 +10,6 @@ import com.njcn.access.enums.AccessEnum;
|
|||||||
import com.njcn.access.enums.AccessResponseEnum;
|
import com.njcn.access.enums.AccessResponseEnum;
|
||||||
import com.njcn.access.enums.TypeEnum;
|
import com.njcn.access.enums.TypeEnum;
|
||||||
import com.njcn.access.param.DevAccessParam;
|
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.AccessDto;
|
||||||
import com.njcn.access.pojo.dto.CsModelDto;
|
import com.njcn.access.pojo.dto.CsModelDto;
|
||||||
import com.njcn.access.pojo.dto.ReqAndResDto;
|
import com.njcn.access.pojo.dto.ReqAndResDto;
|
||||||
@@ -22,11 +20,10 @@ import com.njcn.access.utils.MqttUtil;
|
|||||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.csdevice.api.CsLogsFeignClient;
|
import com.njcn.csdevice.api.*;
|
||||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
|
||||||
import com.njcn.csdevice.api.ProcessFeignClient;
|
|
||||||
import com.njcn.csdevice.pojo.param.CsDevModelRelationAddParm;
|
import com.njcn.csdevice.pojo.param.CsDevModelRelationAddParm;
|
||||||
import com.njcn.csdevice.pojo.param.CsLedgerParam;
|
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.po.*;
|
||||||
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
|
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
|
||||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||||
@@ -37,7 +34,7 @@ import com.njcn.system.enums.DicDataEnum;
|
|||||||
import com.njcn.system.pojo.po.SysDicTreePO;
|
import com.njcn.system.pojo.po.SysDicTreePO;
|
||||||
import com.njcn.web.utils.RequestUtil;
|
import com.njcn.web.utils.RequestUtil;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import net.sf.cglib.core.Local;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -56,6 +53,7 @@ import java.util.stream.Collectors;
|
|||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@Slf4j
|
||||||
public class CsDeviceServiceImpl implements ICsDeviceService {
|
public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(CsDeviceServiceImpl.class);
|
private static final Logger logger = LoggerFactory.getLogger(CsDeviceServiceImpl.class);
|
||||||
@@ -79,6 +77,8 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
|||||||
private final CsDeviceUserPOService csDeviceUserPOService;
|
private final CsDeviceUserPOService csDeviceUserPOService;
|
||||||
private final ICsDataSetService csDataSetService;
|
private final ICsDataSetService csDataSetService;
|
||||||
private final ChannelObjectUtil channelObjectUtil;
|
private final ChannelObjectUtil channelObjectUtil;
|
||||||
|
private final CsLineFeignClient csLineFeignClient;
|
||||||
|
private final DataSetFeignClient dataSetFeignClient;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = {Exception.class})
|
@Transactional(rollbackFor = {Exception.class})
|
||||||
@@ -225,16 +225,34 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
|||||||
po.setClDid(0);
|
po.setClDid(0);
|
||||||
if (Objects.equals(DicDataEnum.GRID_SIDE.getCode(),location)){
|
if (Objects.equals(DicDataEnum.GRID_SIDE.getCode(),location)){
|
||||||
po.setLineId(devAccessParam.getNDid() + "1");
|
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");
|
param.setId(devAccessParam.getNDid() + "1");
|
||||||
appLineTopologyDiagramPo.setLineId(devAccessParam.getNDid() + "1");
|
appLineTopologyDiagramPo.setLineId(devAccessParam.getNDid() + "1");
|
||||||
po.setClDid(1);
|
po.setClDid(1);
|
||||||
} else if (Objects.equals(DicDataEnum.LOAD_SIDE.getCode(),location)){
|
} else if (Objects.equals(DicDataEnum.LOAD_SIDE.getCode(),location)){
|
||||||
po.setLineId(devAccessParam.getNDid() + "2");
|
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");
|
param.setId(devAccessParam.getNDid() + "2");
|
||||||
appLineTopologyDiagramPo.setLineId(devAccessParam.getNDid() + "2");
|
appLineTopologyDiagramPo.setLineId(devAccessParam.getNDid() + "2");
|
||||||
po.setClDid(2);
|
po.setClDid(2);
|
||||||
} else {
|
} else {
|
||||||
po.setLineId(devAccessParam.getNDid() + "0");
|
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");
|
param.setId(devAccessParam.getNDid() + "0");
|
||||||
appLineTopologyDiagramPo.setLineId(devAccessParam.getNDid() + "0");
|
appLineTopologyDiagramPo.setLineId(devAccessParam.getNDid() + "0");
|
||||||
}
|
}
|
||||||
@@ -260,6 +278,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
|||||||
throw new BusinessException(AccessResponseEnum.LINE_POSITION_REPEAT);
|
throw new BusinessException(AccessResponseEnum.LINE_POSITION_REPEAT);
|
||||||
}
|
}
|
||||||
csLineService.saveBatch(csLinePoList);
|
csLineService.saveBatch(csLinePoList);
|
||||||
|
redisUtil.saveByKeyWithExpire("accessLineInfo:" + devAccessParam.getNDid(),csLinePoList,30L);
|
||||||
//4.监测点拓扑图表录入关系
|
//4.监测点拓扑图表录入关系
|
||||||
appLineTopologyDiagramService.saveBatch(appLineTopologyDiagramPoList);
|
appLineTopologyDiagramService.saveBatch(appLineTopologyDiagramPoList);
|
||||||
//5.绑定装置和人的关系
|
//5.绑定装置和人的关系
|
||||||
@@ -346,14 +365,13 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
|||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean manualAccess(String nDid) {
|
public boolean manualAccess(String nDid) {
|
||||||
String version = csTopicService.getVersion(nDid);
|
String version = csTopicService.getVersion(nDid);
|
||||||
return devAccessAskTemplate(nDid,version,new Random().nextInt(10000));
|
return devAccessAskTemplate(nDid,version,1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = {Exception.class})
|
@Transactional(rollbackFor = {Exception.class})
|
||||||
public String wlDevRegister(String nDid) {
|
public String wlDevRegister(String nDid) {
|
||||||
try {
|
String result = "fail";
|
||||||
// 设备状态判断
|
// 设备状态判断
|
||||||
checkDeviceStatus(nDid);
|
checkDeviceStatus(nDid);
|
||||||
// 询问设备支持的主题信息,并将支持的主题入库
|
// 询问设备支持的主题信息,并将支持的主题入库
|
||||||
@@ -364,7 +382,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
|||||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||||
logDto.setUserName(RequestUtil.getUserNickname());
|
logDto.setUserName(RequestUtil.getUserNickname());
|
||||||
logDto.setLoginName(RequestUtil.getUsername());
|
logDto.setLoginName(RequestUtil.getUsername());
|
||||||
logDto.setOperate("设备"+nDid+"注册");
|
logDto.setOperate("便携式设备"+nDid+"注册、接入");
|
||||||
logDto.setResult(1);
|
logDto.setResult(1);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
@@ -372,45 +390,60 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
|||||||
String version = csTopicService.getVersion(nDid);
|
String version = csTopicService.getVersion(nDid);
|
||||||
CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(nDid).getData();
|
CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(nDid).getData();
|
||||||
List<CsLinePO> csLinePoList = new ArrayList<>();
|
List<CsLinePO> csLinePoList = new ArrayList<>();
|
||||||
//1.根据模板获取监测点个数,插入监测点表
|
//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);
|
Thread.sleep(2000);
|
||||||
List<CsModelDto> modelList = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + nDid),CsModelDto.class);
|
List<CsModelDto> modelList = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + nDid),CsModelDto.class);
|
||||||
if (CollUtil.isEmpty(modelList)) {
|
if (CollUtil.isEmpty(modelList)) {
|
||||||
try {
|
|
||||||
throwExceptionAndLog(AccessResponseEnum.MODEL_ERROR, logDto);
|
throwExceptionAndLog(AccessResponseEnum.MODEL_ERROR, logDto);
|
||||||
} catch (Exception e) {
|
|
||||||
throw new BusinessException(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
List<CsDataSet> list = csDataSetService.getDataSetData(modelList.get(0).getModelId());
|
List<CsDataSet> list = csDataSetService.getDataSetData(modelList.get(0).getModelId());
|
||||||
list.forEach(item->{
|
list.forEach(item->{
|
||||||
CsLinePO po = new CsLinePO();
|
CsLinePO po = new CsLinePO();
|
||||||
po.setLineId(nDid + item.getClDev().toString());
|
po.setLineId(nDid + item.getClDev().toString());
|
||||||
po.setName(item.getClDev().toString() + "号监测点");
|
po.setName(item.getClDev().toString() + "#监测点");
|
||||||
po.setStatus(1);
|
po.setStatus(1);
|
||||||
po.setClDid(item.getClDev());
|
po.setClDid(item.getClDev());
|
||||||
po.setDeviceId(vo.getId());
|
po.setDeviceId(vo.getId());
|
||||||
|
po.setDataSetId(item.getId());
|
||||||
|
po.setDataModelId(item.getPid());
|
||||||
//防止主键重复
|
//防止主键重复
|
||||||
QueryWrapper<CsLinePO> qw = new QueryWrapper();
|
QueryWrapper<CsLinePO> qw = new QueryWrapper<>();
|
||||||
qw.eq("line_id",po.getLineId());
|
qw.eq("line_id",po.getLineId());
|
||||||
if(csLineService.getBaseMapper().selectList(qw).isEmpty()){
|
if(csLineService.getBaseMapper().selectList(qw).isEmpty()){
|
||||||
csLinePoList.add(po);
|
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);
|
csLineService.saveBatch(csLinePoList);
|
||||||
//2.生成装置和模板的关系表
|
redisUtil.saveByKeyWithExpire("accessLineInfo:" + nDid,csLinePoList,30L);
|
||||||
|
//4.生成装置和模板的关系表
|
||||||
CsDevModelRelationAddParm csDevModelRelationAddParm = new CsDevModelRelationAddParm();
|
CsDevModelRelationAddParm csDevModelRelationAddParm = new CsDevModelRelationAddParm();
|
||||||
csDevModelRelationAddParm.setDevId(vo.getId());
|
csDevModelRelationAddParm.setDevId(vo.getId());
|
||||||
csDevModelRelationAddParm.setModelId(modelList.get(0).getModelId());
|
csDevModelRelationAddParm.setModelId(modelList.get(0).getModelId());
|
||||||
csDevModelRelationAddParm.setDid(modelList.get(0).getDid());
|
csDevModelRelationAddParm.setDid(modelList.get(0).getDid());
|
||||||
csDevModelRelationService.addDevModelRelation(csDevModelRelationAddParm);
|
csDevModelRelationService.addDevModelRelation(csDevModelRelationAddParm);
|
||||||
//3.修改装置状态为注册状态
|
//5.发起自动接入请求
|
||||||
csEquipmentDeliveryService.updateStatusBynDid(nDid, AccessEnum.REGISTERED.getCode());
|
|
||||||
//4.发起自动接入请求
|
|
||||||
devAccessAskTemplate(nDid,version,1);
|
devAccessAskTemplate(nDid,version,1);
|
||||||
//5.存储日志
|
//6.修改流程,便携式设备接入成功即为实际环境
|
||||||
|
csEquipmentDeliveryService.updateProcessBynDid(nDid,4);
|
||||||
|
//7.存储日志
|
||||||
csLogsFeignClient.addUserLog(logDto);
|
csLogsFeignClient.addUserLog(logDto);
|
||||||
//6.存储设备调试日志表
|
//8.存储设备调试日志表
|
||||||
CsEquipmentProcessPO csEquipmentProcess = new CsEquipmentProcessPO();
|
CsEquipmentProcessPO csEquipmentProcess = new CsEquipmentProcessPO();
|
||||||
csEquipmentProcess.setDevId(nDid);
|
csEquipmentProcess.setDevId(nDid);
|
||||||
csEquipmentProcess.setOperator(RequestUtil.getUserIndex());
|
csEquipmentProcess.setOperator(RequestUtil.getUserIndex());
|
||||||
@@ -419,19 +452,22 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
|||||||
csEquipmentProcess.setProcess(4);
|
csEquipmentProcess.setProcess(4);
|
||||||
csEquipmentProcess.setStatus(1);
|
csEquipmentProcess.setStatus(1);
|
||||||
processFeignClient.add(csEquipmentProcess);
|
processFeignClient.add(csEquipmentProcess);
|
||||||
//7.删除redis监测点模板信息
|
//9.删除redis监测点模板信息
|
||||||
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
||||||
redisUtil.delete(AppRedisKey.LINE + nDid);
|
redisUtil.delete(AppRedisKey.LINE + nDid);
|
||||||
|
//判断接入状态
|
||||||
|
Thread.sleep(5000);
|
||||||
|
Object object = redisUtil.getObjectByKey("online" + nDid);
|
||||||
|
if (Objects.nonNull(object)) {
|
||||||
|
result = "success";
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logDto.setResult(0);
|
logDto.setResult(0);
|
||||||
logDto.setFailReason(e.getMessage());
|
logDto.setFailReason(e.getMessage());
|
||||||
csLogsFeignClient.addUserLog(logDto);
|
csLogsFeignClient.addUserLog(logDto);
|
||||||
throw new BusinessException(CommonResponseEnum.FAIL);
|
throw new BusinessException(AccessResponseEnum.ACCESS_ERROR);
|
||||||
}
|
|
||||||
return "success";
|
|
||||||
} catch (BusinessException e) {
|
|
||||||
throw new BusinessException(e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -481,8 +517,8 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
|||||||
|
|
||||||
private DeviceLogDTO createLogDto(String operate) {
|
private DeviceLogDTO createLogDto(String operate) {
|
||||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||||
logDto.setUserName(RequestUtil.getUserNickname());
|
logDto.setUserName("运维管理员");
|
||||||
logDto.setLoginName(RequestUtil.getUsername());
|
logDto.setLoginName("njcnyw");
|
||||||
logDto.setOperate(operate);
|
logDto.setOperate(operate);
|
||||||
logDto.setResult(1);
|
logDto.setResult(1);
|
||||||
return logDto;
|
return logDto;
|
||||||
@@ -503,16 +539,13 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
|||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean devAccessAskTemplate(String nDid,String version,Integer mid) {
|
public boolean devAccessAskTemplate(String nDid,String version,Integer mid) {
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
|
Map<Integer,String> modelMap = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
|
//删除缓存数据
|
||||||
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
||||||
|
redisUtil.deleteKeysByString(AppRedisKey.DEV_MODEL);
|
||||||
//询问装置当前所用模板
|
//询问装置当前所用模板
|
||||||
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
|
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid,new Gson().toJson(getJson(mid,TypeEnum.TYPE_3.getCode())),1,false);
|
||||||
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);
|
|
||||||
//接收到模板,判断模板是否存在,替换模板,发起接入
|
//接收到模板,判断模板是否存在,替换模板,发起接入
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
List<CsModelDto> modelId = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + nDid),CsModelDto.class);
|
List<CsModelDto> modelId = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + nDid),CsModelDto.class);
|
||||||
@@ -526,12 +559,25 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
|||||||
po.setDid(item.getDid());
|
po.setDid(item.getDid());
|
||||||
po.setUpdateTime(LocalDateTime.now());
|
po.setUpdateTime(LocalDateTime.now());
|
||||||
csDevModelRelationService.addRelation(po);
|
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(getJson(mid,TypeEnum.TYPE_5.getCode())),1,false);
|
||||||
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid, new Gson().toJson(reqAndResParam),1,false);
|
|
||||||
//录波任务倒计时
|
//录波任务倒计时
|
||||||
redisUtil.saveByKeyWithExpire("startFile",null,120L);
|
redisUtil.saveByKeyWithExpire("startFile:" + nDid,null,60L);
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
@@ -540,6 +586,31 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
|||||||
return result;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 平台对设备发起主题询问命令
|
* 平台对设备发起主题询问命令
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ import java.util.Objects;
|
|||||||
public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliveryMapper, CsEquipmentDeliveryPO> implements ICsEquipmentDeliveryService {
|
public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliveryMapper, CsEquipmentDeliveryPO> implements ICsEquipmentDeliveryService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateStatusBynDid(String nDId,Integer status) {
|
public void updateStatusBynDid(String nDid,Integer status) {
|
||||||
LambdaUpdateWrapper<CsEquipmentDeliveryPO> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
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);
|
this.update(lambdaUpdateWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,6 +48,13 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
|||||||
this.update(lambdaUpdateWrapper);
|
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
|
@Override
|
||||||
public CsEquipmentDeliveryVO queryEquipmentBynDid(String nDid) {
|
public CsEquipmentDeliveryVO queryEquipmentBynDid(String nDid) {
|
||||||
CsEquipmentDeliveryVO result = new CsEquipmentDeliveryVO();
|
CsEquipmentDeliveryVO result = new CsEquipmentDeliveryVO();
|
||||||
|
|||||||
@@ -32,9 +32,13 @@ public class CsLedgerServiceImpl extends ServiceImpl<CsLedgerMapper, CsLedger> i
|
|||||||
if (Objects.equals(csLedgerParam.getPid(),"9999999")){
|
if (Objects.equals(csLedgerParam.getPid(),"9999999")){
|
||||||
csLedger.setPid("0");
|
csLedger.setPid("0");
|
||||||
csLedger.setPids("0");
|
csLedger.setPids("0");
|
||||||
|
} else {
|
||||||
|
if (Objects.isNull(fatherCsLedger)) {
|
||||||
|
csLedger.setPids("0");
|
||||||
} else {
|
} else {
|
||||||
csLedger.setPids(fatherCsLedger.getPids() + "," + csLedgerParam.getPid());
|
csLedger.setPids(fatherCsLedger.getPids() + "," + csLedgerParam.getPid());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
this.save(csLedger);
|
this.save(csLedger);
|
||||||
return csLedger;
|
return csLedger;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,11 +8,36 @@
|
|||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<name>rt-api</name>
|
||||||
<artifactId>rt-api</artifactId>
|
<artifactId>rt-api</artifactId>
|
||||||
<version>1.0.0</version>
|
<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>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
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.web.bind.annotation.PostMapping;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,200 @@
|
|||||||
|
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 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,81 @@
|
|||||||
|
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 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>
|
<artifactId>common-db</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</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>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import org.mybatis.spring.annotation.MapperScan;
|
|||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
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
|
* @date 2021年12月09日 20:59
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@DependsOn("proxyMapperRegister")
|
||||||
@MapperScan("com.njcn.**.mapper")
|
@MapperScan("com.njcn.**.mapper")
|
||||||
@EnableFeignClients(basePackages = "com.njcn")
|
@EnableFeignClients(basePackages = "com.njcn")
|
||||||
@SpringBootApplication(scanBasePackages = "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.enums.response.CommonResponseEnum;
|
||||||
import com.njcn.common.pojo.response.HttpResult;
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
import com.njcn.common.utils.HttpResultUtil;
|
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 com.njcn.web.controller.BaseController;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
@@ -31,16 +33,17 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class RtController extends BaseController {
|
public class RtController extends BaseController {
|
||||||
|
|
||||||
// @OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
private final IRtService rtService;
|
||||||
// @PostMapping("/analysis")
|
|
||||||
// @ApiOperation("数据解析")
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||||
// @ApiImplicitParam(name = "csDataEffectiveAddParm", value = "新增app数据有效性表参数", required = true)
|
@PostMapping("/rtAnalysis")
|
||||||
// public HttpResult<Boolean> addDataEffective(@RequestBody @Validated CsDataEffectiveAddParm csDataEffectiveAddParm){
|
@ApiOperation("实时数据解析")
|
||||||
// String methodDescribe = getMethodDescribe("addDataEffective");
|
@ApiImplicitParam(name = "appAutoDataMessage", value = "数据实体", required = true)
|
||||||
//
|
public HttpResult<String> analysis(@RequestBody @Validated AppAutoDataMessage appAutoDataMessage){
|
||||||
// boolean save = csDataEffectiveService.add (csDataEffectiveAddParm);
|
String methodDescribe = getMethodDescribe("analysis");
|
||||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, save, methodDescribe);
|
rtService.analysis(appAutoDataMessage);
|
||||||
// }
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.njcn.rt.service;
|
||||||
|
|
||||||
|
import com.njcn.mq.message.AppAutoDataMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xy
|
||||||
|
*/
|
||||||
|
public interface IRtService {
|
||||||
|
|
||||||
|
void analysis(AppAutoDataMessage appAutoDataMessage);
|
||||||
|
}
|
||||||
@@ -0,0 +1,275 @@
|
|||||||
|
package com.njcn.rt.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
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.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 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
|
||||||
|
*/
|
||||||
|
@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;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void analysis(AppAutoDataMessage appAutoDataMessage) {
|
||||||
|
List<CsDataArray> dataArrayList;
|
||||||
|
//监测点id
|
||||||
|
String 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();
|
||||||
|
//根据数据集获取指标 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$")) {
|
||||||
|
BaseRealDataSet baseRealDataSet = assembleData(dataArrayList,item,po.getConType());
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
//fixme 目前实时数据只有基础数据和谐波数据,后期拓展,这边需要再判断
|
||||||
|
else {
|
||||||
|
HarmRealDataSet harmRealDataSet = harmData(dataArrayList,item);
|
||||||
|
harmRealDataSet.setLineId(lineId);
|
||||||
|
harmRealDataSet.setPt(po.getPtRatio().floatValue());
|
||||||
|
harmRealDataSet.setCt(po.getCtRatio().floatValue());
|
||||||
|
harmRealDataSet.setDataLevel(dataSet.getDataLevel());
|
||||||
|
long timestamp = item.getDataTimeSec() - 8*3600;
|
||||||
|
harmRealDataSet.setDataTime(getTime(timestamp));
|
||||||
|
publisher.send("/Web/RealData/" + lineId, new Gson().toJson(harmRealDataSet), 1, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时间处理
|
||||||
|
*/
|
||||||
|
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) {
|
||||||
|
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") || Objects.equals(item.getHarmName(),"Pq_RmsFundU")) {
|
||||||
|
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);
|
||||||
|
field.set(harmRealDataSet,FloatUtils.get2Float(item.getData()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return harmRealDataSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
//package com.njcn.stat.api;
|
|
||||||
//
|
|
||||||
//import com.njcn.common.pojo.constant.ServerInfo;
|
|
||||||
//import com.njcn.common.pojo.response.HttpResult;
|
|
||||||
//import com.njcn.mq.message.AppAutoDataMessage;
|
|
||||||
//import com.njcn.stat.api.fallback.WlRecordClientFallbackFactory;
|
|
||||||
//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;
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// * @author xy
|
|
||||||
// */
|
|
||||||
//@FeignClient(value = ServerInfo.CS_STAT_BOOT, path = "/record", fallbackFactory = WlRecordClientFallbackFactory.class,contextId = "record")
|
|
||||||
//public interface WlRecordFeignClient {
|
|
||||||
//
|
|
||||||
// @PostMapping("/addOrUpdateBaseData")
|
|
||||||
// HttpResult<String> addOrUpdateBaseData(@RequestBody @Validated AppAutoDataMessage appAutoDataMessage);
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
//package com.njcn.stat.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.stat.api.WlRecordFeignClient;
|
|
||||||
//import feign.hystrix.FallbackFactory;
|
|
||||||
//import lombok.extern.slf4j.Slf4j;
|
|
||||||
//import org.springframework.stereotype.Component;
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// * @author xy
|
|
||||||
// */
|
|
||||||
//@Slf4j
|
|
||||||
//@Component
|
|
||||||
//public class WlRecordClientFallbackFactory implements FallbackFactory<WlRecordFeignClient> {
|
|
||||||
// @Override
|
|
||||||
// public WlRecordFeignClient create(Throwable cause) {
|
|
||||||
// //判断抛出异常是否为解码器抛出的业务异常
|
|
||||||
// Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
|
||||||
// if (cause.getCause() instanceof BusinessException) {
|
|
||||||
// BusinessException businessException = (BusinessException) cause.getCause();
|
|
||||||
// }
|
|
||||||
// Enum<?> finalExceptionEnum = exceptionEnum;
|
|
||||||
// return new WlRecordFeignClient() {
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public HttpResult<String> addOrUpdateBaseData(AppAutoDataMessage appAutoDataMessage) {
|
|
||||||
// log.error("{}异常,降级处理,异常为:{}","新增或更新装置基础数据",cause.toString());
|
|
||||||
// throw new BusinessException(finalExceptionEnum);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
//package com.njcn.stat.controller;
|
|
||||||
//
|
|
||||||
//import com.njcn.common.pojo.annotation.OperateInfo;
|
|
||||||
//import com.njcn.common.pojo.enums.common.LogEnum;
|
|
||||||
//import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
|
||||||
//import com.njcn.common.pojo.response.HttpResult;
|
|
||||||
//import com.njcn.common.utils.HttpResultUtil;
|
|
||||||
//import com.njcn.mq.message.AppAutoDataMessage;
|
|
||||||
//import com.njcn.stat.service.IWlRecordService;
|
|
||||||
//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.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;
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// * 类的介绍:
|
|
||||||
// *
|
|
||||||
// * @author xuyang
|
|
||||||
// * @version 1.0.0
|
|
||||||
// * @createTime 2024/9/10 9:23
|
|
||||||
// */
|
|
||||||
//@Slf4j
|
|
||||||
//@RestController
|
|
||||||
//@RequestMapping("/record")
|
|
||||||
//@Api(tags = "便携式基础数据录入")
|
|
||||||
//@AllArgsConstructor
|
|
||||||
//public class WlRecordController extends BaseController {
|
|
||||||
//
|
|
||||||
// private final IWlRecordService wlRecordService;
|
|
||||||
//
|
|
||||||
// @OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
|
||||||
// @PostMapping("/addOrUpdateBaseData")
|
|
||||||
// @ApiOperation("新增或更新装置基础数据")
|
|
||||||
// @ApiImplicitParam(name = "appAutoDataMessage", value = "数据实体", required = true)
|
|
||||||
// public HttpResult<String> addOrUpdateBaseData(@RequestBody @Validated AppAutoDataMessage appAutoDataMessage){
|
|
||||||
// String methodDescribe = getMethodDescribe("addOrUpdateBaseData");
|
|
||||||
// wlRecordService.addOrUpdateBaseData(appAutoDataMessage);
|
|
||||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
//package com.njcn.stat.service;
|
|
||||||
//
|
|
||||||
//import com.njcn.mq.message.AppAutoDataMessage;
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// * @author xy
|
|
||||||
// */
|
|
||||||
//public interface IWlRecordService {
|
|
||||||
//
|
|
||||||
// void addOrUpdateBaseData(AppAutoDataMessage appAutoDataMessage);
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
@@ -2,17 +2,15 @@ package com.njcn.stat.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||||
|
import com.njcn.access.utils.ChannelObjectUtil;
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.common.utils.PubUtils;
|
import com.njcn.common.utils.PubUtils;
|
||||||
import com.njcn.csdevice.api.CsLineFeignClient;
|
import com.njcn.csdevice.api.CsLineFeignClient;
|
||||||
import com.njcn.csdevice.api.DataArrayFeignClient;
|
import com.njcn.csdevice.api.DataArrayFeignClient;
|
||||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
|
||||||
import com.njcn.csdevice.pojo.param.DataArrayParam;
|
import com.njcn.csdevice.pojo.param.DataArrayParam;
|
||||||
import com.njcn.csdevice.pojo.po.CsDataArray;
|
import com.njcn.csdevice.pojo.po.CsDataArray;
|
||||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||||
import com.njcn.csdevice.pojo.po.CsLinePO;
|
import com.njcn.csdevice.pojo.po.CsLinePO;
|
||||||
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
|
|
||||||
import com.njcn.cswarn.api.CsEquipmentAlarmFeignClient;
|
|
||||||
import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
|
import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
|
||||||
import com.njcn.influx.utils.InfluxDbUtils;
|
import com.njcn.influx.utils.InfluxDbUtils;
|
||||||
import com.njcn.mq.message.AppAutoDataMessage;
|
import com.njcn.mq.message.AppAutoDataMessage;
|
||||||
@@ -21,11 +19,9 @@ import com.njcn.redis.utils.RedisUtil;
|
|||||||
import com.njcn.stat.enums.StatResponseEnum;
|
import com.njcn.stat.enums.StatResponseEnum;
|
||||||
import com.njcn.stat.service.IStatService;
|
import com.njcn.stat.service.IStatService;
|
||||||
import com.njcn.system.api.DicDataFeignClient;
|
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.enums.DicDataEnum;
|
||||||
import com.njcn.system.pojo.dto.EpdDTO;
|
|
||||||
import com.njcn.system.pojo.po.DictData;
|
import com.njcn.system.pojo.po.DictData;
|
||||||
|
import com.njcn.system.pojo.po.SysDicTreePO;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.influxdb.InfluxDB;
|
import org.influxdb.InfluxDB;
|
||||||
@@ -50,20 +46,11 @@ import java.util.concurrent.TimeUnit;
|
|||||||
public class StatServiceImpl implements IStatService {
|
public class StatServiceImpl implements IStatService {
|
||||||
|
|
||||||
private final DataArrayFeignClient dataArrayFeignClient;
|
private final DataArrayFeignClient dataArrayFeignClient;
|
||||||
|
|
||||||
private final EpdFeignClient epdFeignClient;
|
|
||||||
|
|
||||||
private final DicDataFeignClient dicDataFeignClient;
|
private final DicDataFeignClient dicDataFeignClient;
|
||||||
|
|
||||||
private final InfluxDbUtils influxDbUtils;
|
private final InfluxDbUtils influxDbUtils;
|
||||||
|
|
||||||
private final CsLineFeignClient csLineFeignClient;
|
private final CsLineFeignClient csLineFeignClient;
|
||||||
|
|
||||||
private final RedisUtil redisUtil;
|
private final RedisUtil redisUtil;
|
||||||
|
private final ChannelObjectUtil channelObjectUtil;
|
||||||
private final EquipmentFeignClient equipmentFeignClient;
|
|
||||||
|
|
||||||
private final DictTreeFeignClient dictTreeFeignClient;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@@ -86,8 +73,11 @@ public class StatServiceImpl implements IStatService {
|
|||||||
lineInfo(appAutoDataMessage.getId());
|
lineInfo(appAutoDataMessage.getId());
|
||||||
}
|
}
|
||||||
//获取当前设备信息判断装置型号,来筛选监测点
|
//获取当前设备信息判断装置型号,来筛选监测点
|
||||||
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(appAutoDataMessage.getId()).getData();
|
List<CsEquipmentDeliveryPO> poList = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.DEVICE_LIST),CsEquipmentDeliveryPO.class);
|
||||||
String code = dictTreeFeignClient.queryById(po.getDevType()).getData().getCode();
|
CsEquipmentDeliveryPO po = poList.stream().filter(item->Objects.equals(item.getNdid(),appAutoDataMessage.getId())).findFirst().orElse(null);
|
||||||
|
List<SysDicTreePO> dictTreeList = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.DICT_TREE),SysDicTreePO.class);
|
||||||
|
String code = dictTreeList.stream().filter(item->Objects.equals(item.getId(),po.getDevType())).findFirst().orElse(null).getCode();
|
||||||
|
|
||||||
//便携式设备
|
//便携式设备
|
||||||
if (Objects.equals(DicDataEnum.PORTABLE.getCode(),code)) {
|
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();
|
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appAutoDataMessage.getId())), Map.class).get(appAutoDataMessage.getMsg().getClDid().toString()).toString();
|
||||||
@@ -99,11 +89,6 @@ public class StatServiceImpl implements IStatService {
|
|||||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appAutoDataMessage.getId())), Map.class).get(appAutoDataMessage.getMsg().getClDid().toString()).toString();
|
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();
|
|
||||||
// }
|
|
||||||
//获取当前设备信息
|
//获取当前设备信息
|
||||||
if (CollectionUtil.isNotEmpty(list)){
|
if (CollectionUtil.isNotEmpty(list)){
|
||||||
List<String> recordList = new ArrayList<>();
|
List<String> recordList = new ArrayList<>();
|
||||||
@@ -128,10 +113,11 @@ public class StatServiceImpl implements IStatService {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Object object = redisUtil.getObjectByKey(appAutoDataMessage.getId() + appAutoDataMessage.getDid() + appAutoDataMessage.getMsg().getClDid() + dataArrayParam.getStatMethod());
|
String key = AppRedisKey.DEV_MODEL.concat(dataArrayParam.getId() + dataArrayParam.getDid() + dataArrayParam.getCldId() + dataArrayParam.getStatMethod());
|
||||||
|
Object object = redisUtil.getObjectByKey(key);
|
||||||
List<CsDataArray> dataArrayList;
|
List<CsDataArray> dataArrayList;
|
||||||
if (Objects.isNull(object)){
|
if (Objects.isNull(object)){
|
||||||
dataArrayList = saveModelData(dataArrayParam);
|
dataArrayList = saveModelData(dataArrayParam,key);
|
||||||
} else {
|
} else {
|
||||||
dataArrayList = objectToList(object);
|
dataArrayList = objectToList(object);
|
||||||
}
|
}
|
||||||
@@ -171,31 +157,15 @@ public class StatServiceImpl implements IStatService {
|
|||||||
redisUtil.saveByKey(AppRedisKey.LINE_POSITION+id,map);
|
redisUtil.saveByKey(AppRedisKey.LINE_POSITION+id,map);
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * 缓存字典和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);
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 缓存设备模板信息
|
* 缓存设备模板信息
|
||||||
*/
|
*/
|
||||||
public List<CsDataArray> saveModelData(DataArrayParam dataArrayParam) {
|
public List<CsDataArray> saveModelData(DataArrayParam dataArrayParam,String key) {
|
||||||
String key = dataArrayParam.getId() + dataArrayParam.getDid() + dataArrayParam.getCldId() + dataArrayParam.getStatMethod();
|
|
||||||
List<CsDataArray> dataArrayList = dataArrayFeignClient.findListByParam(dataArrayParam).getData();
|
List<CsDataArray> dataArrayList = dataArrayFeignClient.findListByParam(dataArrayParam).getData();
|
||||||
if (CollectionUtil.isEmpty(dataArrayList)){
|
if (CollectionUtil.isEmpty(dataArrayList)){
|
||||||
throw new BusinessException(StatResponseEnum.DATA_ARRAY_NULL);
|
throw new BusinessException(StatResponseEnum.DATA_ARRAY_NULL);
|
||||||
}
|
}
|
||||||
redisUtil.saveByKeyWithExpire(key,dataArrayList,600L);
|
redisUtil.saveByKey(key,dataArrayList);
|
||||||
return dataArrayList;
|
return dataArrayList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,10 +184,6 @@ public class StatServiceImpl implements IStatService {
|
|||||||
if (!Objects.equals(dataArrayList.size(),floats.size())){
|
if (!Objects.equals(dataArrayList.size(),floats.size())){
|
||||||
throw new BusinessException(StatResponseEnum.ARRAY_DATA_NOT_MATCH);
|
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);
|
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++) {
|
for (int i = 0; i < dataArrayList.size(); i++) {
|
||||||
String tableName = map.get(dataArrayList.get(i).getName());
|
String tableName = map.get(dataArrayList.get(i).getName());
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
//package com.njcn.stat.service.impl;
|
|
||||||
//
|
|
||||||
//import com.njcn.csdevice.api.EquipmentFeignClient;
|
|
||||||
//import com.njcn.csdevice.api.WlRecordFeignClient;
|
|
||||||
//import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
|
||||||
//import com.njcn.csdevice.pojo.po.WlRecord;
|
|
||||||
//import com.njcn.mq.message.AppAutoDataMessage;
|
|
||||||
//import com.njcn.stat.service.IWlRecordService;
|
|
||||||
//import lombok.AllArgsConstructor;
|
|
||||||
//import lombok.extern.slf4j.Slf4j;
|
|
||||||
//import org.springframework.beans.BeanUtils;
|
|
||||||
//import org.springframework.stereotype.Service;
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// * 类的介绍:
|
|
||||||
// *
|
|
||||||
// * @author xuyang
|
|
||||||
// * @version 1.0.0
|
|
||||||
// * @createTime 2023/8/14 9:32
|
|
||||||
// */
|
|
||||||
//@Service
|
|
||||||
//@Slf4j
|
|
||||||
//@AllArgsConstructor
|
|
||||||
//public class WlRecordServiceImpl implements IWlRecordService{
|
|
||||||
//
|
|
||||||
// private final EquipmentFeignClient equipmentFeignClient;
|
|
||||||
//
|
|
||||||
// private final WlRecordFeignClient wlRecordFeignClient;
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void addOrUpdateBaseData(AppAutoDataMessage appAutoDataMessage) {
|
|
||||||
// WlRecord wlRecord = new WlRecord();
|
|
||||||
// CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(appAutoDataMessage.getId()).getData();
|
|
||||||
// AppAutoDataMessage.DataArray dataArray = appAutoDataMessage.getMsg().getDataArray().get(0);
|
|
||||||
// BeanUtils.copyProperties(dataArray, wlRecord);
|
|
||||||
// wlRecord.setDevId(po.getId());
|
|
||||||
// wlRecord.setLineId(po.getNdid() + appAutoDataMessage.getMsg().getClDid());
|
|
||||||
// wlRecord.setGcDataPath(dataArray.getPrjDataPath());
|
|
||||||
// if (dataArray.getPrjTimeEnd() == -1) {
|
|
||||||
// wlRecord.setEndTime(null);
|
|
||||||
// }
|
|
||||||
// wlRecordFeignClient.addBaseData(wlRecord);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
@@ -6,6 +6,7 @@ import com.njcn.mq.message.AppEventMessage;
|
|||||||
import com.njcn.zlevent.api.fallback.EventClientFallbackFactory;
|
import com.njcn.zlevent.api.fallback.EventClientFallbackFactory;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author xy
|
* @author xy
|
||||||
@@ -16,7 +17,7 @@ public interface EventFeignClient {
|
|||||||
@PostMapping("/analysis")
|
@PostMapping("/analysis")
|
||||||
HttpResult<String> analysis(AppEventMessage appEventMessage);
|
HttpResult<String> analysis(AppEventMessage appEventMessage);
|
||||||
|
|
||||||
@PostMapping("/errorEvent")
|
@PostMapping("/portableData")
|
||||||
HttpResult<String> insertErrorEvent(AppEventMessage appEventMessage);
|
HttpResult<String> getPortableData(@RequestBody AppEventMessage appEventMessage);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.njcn.mq.message.AppEventMessage;
|
|||||||
import com.njcn.zlevent.api.fallback.WaveClientFallbackFactory;
|
import com.njcn.zlevent.api.fallback.WaveClientFallbackFactory;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author xy
|
* @author xy
|
||||||
@@ -15,4 +16,7 @@ public interface WaveFeignClient {
|
|||||||
|
|
||||||
@PostMapping("/analysis")
|
@PostMapping("/analysis")
|
||||||
HttpResult<String> analysis(AppEventMessage appEventMessage);
|
HttpResult<String> analysis(AppEventMessage appEventMessage);
|
||||||
|
|
||||||
|
@PostMapping("/channelWave")
|
||||||
|
HttpResult<String> channelWave(@RequestParam("nDid") String nDid);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,10 +32,11 @@ public class EventClientFallbackFactory implements FallbackFactory<EventFeignCli
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HttpResult<String> insertErrorEvent(AppEventMessage appEventMessage) {
|
public HttpResult<String> getPortableData(AppEventMessage appEventMessage) {
|
||||||
log.error("{}异常,降级处理,异常为:{}","异常事件统计",cause.toString());
|
log.error("{}异常,降级处理,异常为:{}","便携式设备数据记录动作",cause.toString());
|
||||||
throw new BusinessException(finalExceptionEnum);
|
throw new BusinessException(finalExceptionEnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
|||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.common.pojo.response.HttpResult;
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
import com.njcn.mq.message.AppEventMessage;
|
import com.njcn.mq.message.AppEventMessage;
|
||||||
import com.njcn.zlevent.api.EventFeignClient;
|
|
||||||
import com.njcn.zlevent.api.WaveFeignClient;
|
import com.njcn.zlevent.api.WaveFeignClient;
|
||||||
import feign.hystrix.FallbackFactory;
|
import feign.hystrix.FallbackFactory;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -31,6 +30,12 @@ public class WaveClientFallbackFactory implements FallbackFactory<WaveFeignClien
|
|||||||
log.error("{}异常,降级处理,异常为:{}","波形报文解析",cause.toString());
|
log.error("{}异常,降级处理,异常为:{}","波形报文解析",cause.toString());
|
||||||
throw new BusinessException(finalExceptionEnum);
|
throw new BusinessException(finalExceptionEnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HttpResult<String> channelWave(String nDid) {
|
||||||
|
log.error("{}异常,降级处理,异常为:{}","处理录波事件",cause.toString());
|
||||||
|
throw new BusinessException(finalExceptionEnum);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.njcn.zlevent.pojo.dto;
|
package com.njcn.zlevent.pojo.dto;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
@@ -17,12 +18,16 @@ import java.util.Set;
|
|||||||
@Data
|
@Data
|
||||||
public class FileStreamDto implements Serializable {
|
public class FileStreamDto implements Serializable {
|
||||||
|
|
||||||
|
@ApiModelProperty("总帧")
|
||||||
private Integer total;
|
private Integer total;
|
||||||
|
|
||||||
|
@ApiModelProperty("nDid")
|
||||||
private String nDid;
|
private String nDid;
|
||||||
|
|
||||||
|
@ApiModelProperty("帧大小")
|
||||||
private Integer frameLen;
|
private Integer frameLen;
|
||||||
|
|
||||||
|
@ApiModelProperty("帧集合")
|
||||||
private Set<Integer> list;
|
private Set<Integer> list;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/event")
|
@RequestMapping("/event")
|
||||||
@Api(tags = "暂态事件处理")
|
@Api(tags = "事件处理")
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class EventController extends BaseController {
|
public class EventController extends BaseController {
|
||||||
|
|
||||||
@@ -44,4 +44,14 @@ public class EventController extends BaseController {
|
|||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,7 @@ import io.swagger.annotations.ApiImplicitParam;
|
|||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 类的介绍:
|
* 类的介绍:
|
||||||
@@ -44,4 +41,14 @@ public class WaveController extends BaseController {
|
|||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,26 @@
|
|||||||
package com.njcn.zlevent.init;
|
//package com.njcn.zlevent.init;
|
||||||
|
//
|
||||||
import com.njcn.redis.utils.RedisUtil;
|
//import com.njcn.redis.utils.RedisUtil;
|
||||||
import lombok.AllArgsConstructor;
|
//import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
//import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.boot.CommandLineRunner;
|
//import org.springframework.boot.CommandLineRunner;
|
||||||
import org.springframework.stereotype.Component;
|
//import org.springframework.stereotype.Component;
|
||||||
|
//
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* @author xy
|
// * @author xy
|
||||||
*
|
// *
|
||||||
* 程序重启设置任务,消费历史录波文件
|
// * 程序重启设置任务,消费历史录波文件
|
||||||
*/
|
// */
|
||||||
@Slf4j
|
//@Slf4j
|
||||||
@Component
|
//@Component
|
||||||
@AllArgsConstructor
|
//@AllArgsConstructor
|
||||||
public class InitEventFiles implements CommandLineRunner {
|
//public class InitEventFiles implements CommandLineRunner {
|
||||||
|
//
|
||||||
private final RedisUtil redisUtil;
|
// private final RedisUtil redisUtil;
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void run(String... args) {
|
// public void run(String... args) {
|
||||||
redisUtil.saveByKeyWithExpire("startFile",null,120L);
|
// redisUtil.saveByKeyWithExpire("startFile",null,120L);
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import com.njcn.access.pojo.dto.file.FileRedisDto;
|
|||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||||
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
||||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
|
||||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||||
import com.njcn.redis.utils.RedisUtil;
|
import com.njcn.redis.utils.RedisUtil;
|
||||||
import com.njcn.stat.enums.StatResponseEnum;
|
import com.njcn.stat.enums.StatResponseEnum;
|
||||||
@@ -99,16 +98,11 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
|||||||
downloadFile(missingList,dto.getNDid(),fileName);
|
downloadFile(missingList,dto.getNDid(),fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//项目重启或者接入,经过120s开始处理历史录波文件
|
//重新接入之后,装置60s后开始消费缓存的录波文件
|
||||||
else if (expiredKey.startsWith("startFile")) {
|
else if (expiredKey.startsWith("startFile:")) {
|
||||||
List<CsEquipmentDeliveryPO> list = equipmentFeignClient.getAll().getData();
|
String nDid = expiredKey.split(":")[1];
|
||||||
if (CollectionUtil.isNotEmpty(list)) {
|
|
||||||
list.forEach(item->{
|
|
||||||
redisUtil.delete("handleEvent:" + item.getNdid());
|
|
||||||
//处理缓存数据
|
//处理缓存数据
|
||||||
csWaveAnalysisService.channelWave(item.getNdid());
|
csWaveAnalysisService.channelWave(nDid);
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//手动文件下载
|
//手动文件下载
|
||||||
else if (expiredKey.startsWith(AppRedisKey.FILE_DOWN_TIME)) {
|
else if (expiredKey.startsWith(AppRedisKey.FILE_DOWN_TIME)) {
|
||||||
@@ -205,11 +199,11 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
|||||||
*/
|
*/
|
||||||
public void webSendNextStep(String fileName, String id, int mid,int step) {
|
public void webSendNextStep(String fileName, String id, int mid,int step) {
|
||||||
try {
|
try {
|
||||||
for (int i = 1; i <= 30; i++) {
|
for (int i = 1; i <= 15; i++) {
|
||||||
if (step == 0 ){
|
if (step == 0 ){
|
||||||
Thread.sleep(5000);
|
Thread.sleep(8000);
|
||||||
} else {
|
} else {
|
||||||
Thread.sleep(2000);
|
Thread.sleep(4000);
|
||||||
}
|
}
|
||||||
FileRedisDto fileRedisDto = (FileRedisDto) redisUtil.getObjectByKey(AppRedisKey.DOWNLOAD + fileName + mid);
|
FileRedisDto fileRedisDto = (FileRedisDto) redisUtil.getObjectByKey(AppRedisKey.DOWNLOAD + fileName + mid);
|
||||||
if (Objects.isNull(fileRedisDto)) {
|
if (Objects.isNull(fileRedisDto)) {
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,4 +17,12 @@ public interface IEventService {
|
|||||||
*/
|
*/
|
||||||
void analysis(AppEventMessage appEventMessage);
|
void analysis(AppEventMessage appEventMessage);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 便携式设备基础数据
|
||||||
|
* 1.装置发起数据记录开始动作,库中新增数据;
|
||||||
|
* 2.装置发起数据记录结束动作,库中更新数据;
|
||||||
|
* @param appEventMessage
|
||||||
|
*/
|
||||||
|
void getPortableData(AppEventMessage appEventMessage);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,9 +77,9 @@ public class CsAlarmServiceImpl extends ServiceImpl<CsEventMapper, CsEventPO> im
|
|||||||
//推送事件逻辑处理 && cs_event_user入库 && 修改字典中告警事件的编码
|
//推送事件逻辑处理 && cs_event_user入库 && 修改字典中告警事件的编码
|
||||||
for (AppEventMessage.DataArray item : dataArray) {
|
for (AppEventMessage.DataArray item : dataArray) {
|
||||||
if (Objects.isNull(item.getCode())){
|
if (Objects.isNull(item.getCode())){
|
||||||
sendEventUtils.sendUser(2,item.getType(),po.getId(),item.getName(),eventTime,id);
|
sendEventUtils.sendUser(2,item.getType(),po.getId(),item.getName(),eventTime,id,po.getNdid());
|
||||||
} else {
|
} else {
|
||||||
sendEventUtils.sendUser(2,item.getType(),po.getId(),item.getCode(),eventTime,id);
|
sendEventUtils.sendUser(2,item.getType(),po.getId(),item.getCode(),eventTime,id,po.getNdid());
|
||||||
//更新字典信息
|
//更新字典信息
|
||||||
EleEpdPqd eleEpdPqd = epdFeignClient.findByName(item.getName()).getData();
|
EleEpdPqd eleEpdPqd = epdFeignClient.findByName(item.getName()).getData();
|
||||||
EleEpdPqdParam.EleEpdPqdUpdateParam updateParam = new EleEpdPqdParam.EleEpdPqdUpdateParam();
|
EleEpdPqdParam.EleEpdPqdUpdateParam updateParam = new EleEpdPqdParam.EleEpdPqdUpdateParam();
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,8 +38,10 @@ public class CsEventServiceImpl extends ServiceImpl<CsEventMapper, CsEventPO> im
|
|||||||
lambdaUpdateWrapper.set(CsEventPO::getWavePath,csEventParam.getPath()).eq(CsEventPO::getLineId,csEventParam.getLineId())
|
lambdaUpdateWrapper.set(CsEventPO::getWavePath,csEventParam.getPath()).eq(CsEventPO::getLineId,csEventParam.getLineId())
|
||||||
.eq(CsEventPO::getDeviceId,csEventParam.getDeviceId())
|
.eq(CsEventPO::getDeviceId,csEventParam.getDeviceId())
|
||||||
.in(CsEventPO::getType, Arrays.asList(0,1))
|
.in(CsEventPO::getType, Arrays.asList(0,1))
|
||||||
.eq(CsEventPO::getLocation,csEventParam.getLocation())
|
|
||||||
.between(CsEventPO::getStartTime,csEventParam.getStartTime(),csEventParam.getEndTime());
|
.between(CsEventPO::getStartTime,csEventParam.getStartTime(),csEventParam.getEndTime());
|
||||||
|
if (Objects.nonNull(csEventParam.getLocation())) {
|
||||||
|
lambdaUpdateWrapper.eq(CsEventPO::getLocation, csEventParam.getLocation());
|
||||||
|
}
|
||||||
this.update(lambdaUpdateWrapper);
|
this.update(lambdaUpdateWrapper);
|
||||||
List<CsEventPO> list = this.baseMapper.selectList(lambdaUpdateWrapper);
|
List<CsEventPO> list = this.baseMapper.selectList(lambdaUpdateWrapper);
|
||||||
if (CollectionUtil.isNotEmpty(list)){
|
if (CollectionUtil.isNotEmpty(list)){
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ public class CsWaveAnalysisServiceImpl implements ICsWaveAnalysisService {
|
|||||||
private final DicDataFeignClient dicDataFeignClient;
|
private final DicDataFeignClient dicDataFeignClient;
|
||||||
private final ChannelObjectUtil channelObjectUtil;
|
private final ChannelObjectUtil channelObjectUtil;
|
||||||
private final MqttUtil mqttUtil;
|
private final MqttUtil mqttUtil;
|
||||||
|
private static Integer mid = 1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void analysis(AppEventMessage appEventMessage) {
|
public void analysis(AppEventMessage appEventMessage) {
|
||||||
@@ -70,16 +71,16 @@ public class CsWaveAnalysisServiceImpl implements ICsWaveAnalysisService {
|
|||||||
if (CollectionUtil.isNotEmpty(dataArrayList)){
|
if (CollectionUtil.isNotEmpty(dataArrayList)){
|
||||||
for (AppEventMessage.DataArray item : dataArrayList) {
|
for (AppEventMessage.DataArray item : dataArrayList) {
|
||||||
List<AppEventMessage.Param> paramList = item.getParam();
|
List<AppEventMessage.Param> paramList = item.getParam();
|
||||||
Object object = paramList.stream().filter(item2 -> ZlConstant.WAVE_NAME.equals(item2.getName())).findFirst().get().getData();
|
Object object = paramList.stream().filter(item2 -> ZlConstant.WAVE_NAME.equals(item2.getName())).findFirst().map(AppEventMessage.Param::getData).orElse(null);
|
||||||
Object object2 = paramList.stream().filter(item2 -> ZlConstant.WAVE_PARAM_RCDKEEPTIME.equals(item2.getName())).findFirst().get().getData();
|
Object object2 = paramList.stream().filter(item2 -> ZlConstant.WAVE_PARAM_RCDKEEPTIME.equals(item2.getName())).findFirst().map(AppEventMessage.Param::getData).orElse(null);
|
||||||
Object object3 = paramList.stream().filter(item2 -> ZlConstant.WAVE_POSITION.equals(item2.getName())).findFirst().get().getData();
|
Object object3 = paramList.stream().filter(item2->ZlConstant.WAVE_POSITION.equals(item2.getName())).findFirst().map(AppEventMessage.Param::getData).orElse(null);
|
||||||
String lineId = appEventMessage.getId() + appEventMessage.getMsg().getClDid();
|
String lineId = appEventMessage.getId() + appEventMessage.getMsg().getClDid();
|
||||||
String fileName = object.toString().replaceAll("\\[","").replaceAll("]","");
|
String fileName = object.toString().replaceAll("\\[","").replaceAll("]","");
|
||||||
List<String> fileList = Arrays.stream(fileName.split(",")).collect(Collectors.toList());
|
List<String> fileList = Arrays.stream(fileName.split(",")).collect(Collectors.toList());
|
||||||
//获取到录波文件,将文件信息存储起来
|
//获取到录波文件,将文件信息存储起来
|
||||||
for (String file : fileList) {
|
for (String file : fileList) {
|
||||||
file = file.trim();
|
file = file.trim();
|
||||||
WaveTimeDto dto = channelTimeRange(file,appEventMessage.getId(),item.getDataTimeSec(),item.getDataTimeUSec(),(Double)object2,deviceId,lineId,object3.toString());
|
WaveTimeDto dto = channelTimeRange(file,appEventMessage.getId(),item.getDataTimeSec(),item.getDataTimeUSec(),(Double)object2,deviceId,lineId,Objects.isNull(object3)?null:object3.toString());
|
||||||
list.add(dto);
|
list.add(dto);
|
||||||
}
|
}
|
||||||
Object obj = redisUtil.getObjectByKey("eventFile:" + appEventMessage.getId());
|
Object obj = redisUtil.getObjectByKey("eventFile:" + appEventMessage.getId());
|
||||||
@@ -112,12 +113,24 @@ public class CsWaveAnalysisServiceImpl implements ICsWaveAnalysisService {
|
|||||||
if (Objects.isNull(obj)) {
|
if (Objects.isNull(obj)) {
|
||||||
List<WaveTimeDto> list = channelObjectUtil.objectToList( redisUtil.getObjectByKey("eventFile:" + nDid),WaveTimeDto.class);
|
List<WaveTimeDto> list = channelObjectUtil.objectToList( redisUtil.getObjectByKey("eventFile:" + nDid),WaveTimeDto.class);
|
||||||
if (CollectionUtil.isNotEmpty(list)) {
|
if (CollectionUtil.isNotEmpty(list)) {
|
||||||
|
Object object = channelObjectUtil.getDeviceMid(nDid);
|
||||||
|
if (!Objects.isNull(object)) {
|
||||||
|
mid = (Integer) object;
|
||||||
|
}
|
||||||
WaveTimeDto dto = list.get(0);
|
WaveTimeDto dto = list.get(0);
|
||||||
askFileInfo(nDid,1,dto.getFileName());
|
redisUtil.saveByKeyWithExpire("fileMid:" + nDid,mid + "concat" +dto.getFileName(),60L);
|
||||||
|
askFileInfo(nDid,mid,dto.getFileName());
|
||||||
|
mid = mid + 1;
|
||||||
|
if (mid > 10000) {
|
||||||
|
mid = 1;
|
||||||
|
}
|
||||||
|
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,mid);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new BusinessException(AlgorithmResponseEnum.FILE_DOWNLOADING);
|
throw new BusinessException(AlgorithmResponseEnum.FILE_DOWNLOADING);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
throw new BusinessException(AlgorithmResponseEnum.DEV_OFFLINE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,12 @@ import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
|||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.csdevice.api.CsLineFeignClient;
|
import com.njcn.csdevice.api.CsLineFeignClient;
|
||||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||||
|
import com.njcn.csdevice.api.WlRecordFeignClient;
|
||||||
|
import com.njcn.csdevice.pojo.param.WlRecordParam;
|
||||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||||
import com.njcn.csdevice.pojo.po.CsLinePO;
|
import com.njcn.csdevice.pojo.po.CsLinePO;
|
||||||
|
import com.njcn.csdevice.pojo.po.WlRecord;
|
||||||
|
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
|
||||||
import com.njcn.csharmonic.pojo.po.CsEventPO;
|
import com.njcn.csharmonic.pojo.po.CsEventPO;
|
||||||
import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
|
import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
|
||||||
import com.njcn.influx.utils.InfluxDbUtils;
|
import com.njcn.influx.utils.InfluxDbUtils;
|
||||||
@@ -34,8 +38,11 @@ import org.influxdb.dto.Point;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.Instant;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@@ -53,22 +60,15 @@ import java.util.concurrent.TimeUnit;
|
|||||||
public class EventServiceImpl implements IEventService {
|
public class EventServiceImpl implements IEventService {
|
||||||
|
|
||||||
private final CsLineFeignClient csLineFeignClient;
|
private final CsLineFeignClient csLineFeignClient;
|
||||||
|
|
||||||
private final DicDataFeignClient dicDataFeignClient;
|
private final DicDataFeignClient dicDataFeignClient;
|
||||||
|
|
||||||
private final EpdFeignClient epdFeignClient;
|
private final EpdFeignClient epdFeignClient;
|
||||||
|
|
||||||
private final RedisUtil redisUtil;
|
private final RedisUtil redisUtil;
|
||||||
|
|
||||||
private final ICsEventService csEventService;
|
private final ICsEventService csEventService;
|
||||||
|
|
||||||
private final EquipmentFeignClient equipmentFeignClient;
|
private final EquipmentFeignClient equipmentFeignClient;
|
||||||
|
|
||||||
private final InfluxDbUtils influxDbUtils;
|
private final InfluxDbUtils influxDbUtils;
|
||||||
|
|
||||||
private final ICsEventLogsService csEventLogsService;
|
private final ICsEventLogsService csEventLogsService;
|
||||||
|
|
||||||
private final SendEventUtils sendEventUtils;
|
private final SendEventUtils sendEventUtils;
|
||||||
|
private final WlRecordFeignClient wlRecordFeignClient;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@@ -123,6 +123,7 @@ public class EventServiceImpl implements IEventService {
|
|||||||
Map<String, String> tags = new HashMap<>();
|
Map<String, String> tags = new HashMap<>();
|
||||||
tags.put(InfluxDBTableConstant.UUID,id);
|
tags.put(InfluxDBTableConstant.UUID,id);
|
||||||
Map<String,Object> fields = new HashMap<>();
|
Map<String,Object> fields = new HashMap<>();
|
||||||
|
//只有治理型号的设备有监测位置
|
||||||
if (Objects.equals(ZlConstant.EVENT_POSITION,param.getName())){
|
if (Objects.equals(ZlConstant.EVENT_POSITION,param.getName())){
|
||||||
if (Objects.equals(param.getData(),ZlConstant.GRID)){
|
if (Objects.equals(param.getData(),ZlConstant.GRID)){
|
||||||
fields.put(param.getName(),"电网侧");
|
fields.put(param.getName(),"电网侧");
|
||||||
@@ -139,8 +140,8 @@ public class EventServiceImpl implements IEventService {
|
|||||||
csEvent.setPersistTime(Double.parseDouble(param.getData().toString()));
|
csEvent.setPersistTime(Double.parseDouble(param.getData().toString()));
|
||||||
}
|
}
|
||||||
lineId = appEventMessage.getId() + appEventMessage.getMsg().getClDid();
|
lineId = appEventMessage.getId() + appEventMessage.getMsg().getClDid();
|
||||||
fields.put(param.getName(),appEventMessage.getMsg().getClDid()==1?"电网侧":"负载侧");
|
fields.put(param.getName(),null);
|
||||||
csEvent.setLocation(appEventMessage.getMsg().getClDid()==1?ZlConstant.GRID:ZlConstant.LOAD);
|
csEvent.setLocation(null);
|
||||||
csEvent.setClDid(appEventMessage.getMsg().getClDid());
|
csEvent.setClDid(appEventMessage.getMsg().getClDid());
|
||||||
fields.put(param.getName(),param.getData());
|
fields.put(param.getName(),param.getData());
|
||||||
}
|
}
|
||||||
@@ -168,7 +169,7 @@ public class EventServiceImpl implements IEventService {
|
|||||||
csEventService.saveBatch(list1);
|
csEventService.saveBatch(list1);
|
||||||
//推送事件逻辑处理 && cs_event_user入库
|
//推送事件逻辑处理 && cs_event_user入库
|
||||||
for (AppEventMessage.DataArray item : dataArray) {
|
for (AppEventMessage.DataArray item : dataArray) {
|
||||||
sendEventUtils.sendUser(1,item.getType(),po.getId(),item.getName(),eventTime,id);
|
sendEventUtils.sendUser(1,item.getType(),po.getId(),item.getName(),eventTime,id,po.getNdid());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//evt_data入库
|
//evt_data入库
|
||||||
@@ -188,6 +189,93 @@ public class EventServiceImpl implements IEventService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void getPortableData(AppEventMessage appEventMessage) {
|
||||||
|
CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(appEventMessage.getId()).getData();
|
||||||
|
//根据报文判断是新增还是更新
|
||||||
|
List<AppEventMessage.DataArray> dataArrays = appEventMessage.getMsg().getDataArray();
|
||||||
|
dataArrays.forEach(item->{
|
||||||
|
WlRecordParam.Record param = new WlRecordParam.Record();
|
||||||
|
param.setDevId(vo.getId());
|
||||||
|
param.setLineId(appEventMessage.getId() + item.getClDid().toString());
|
||||||
|
param.setProName(item.getPrjName());
|
||||||
|
param.setProStartTime(timestampToDatetime((item.getPrjTimeStart() - 8*3600)));
|
||||||
|
WlRecord record = wlRecordFeignClient.findDevBaseData(param).getData();
|
||||||
|
if (!Objects.isNull(record)) {
|
||||||
|
if (!Objects.equals(item.getPrjTimeEnd(),-1L)) {
|
||||||
|
WlRecordParam.UpdateRecord wlRecord = new WlRecordParam.UpdateRecord();
|
||||||
|
wlRecord.setId(record.getId());
|
||||||
|
wlRecord.setProEndTime(timestampToDatetime((item.getPrjTimeEnd() - 8*3600)));
|
||||||
|
wlRecordFeignClient.updateTestRecord(wlRecord);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//新项目入库
|
||||||
|
WlRecord wlRecord = new WlRecord();
|
||||||
|
wlRecord.setId(IdUtil.simpleUUID());
|
||||||
|
wlRecord.setItemName("基础数据");
|
||||||
|
wlRecord.setGcName(item.getPrjName());
|
||||||
|
wlRecord.setDevId(vo.getId());
|
||||||
|
wlRecord.setLineId(appEventMessage.getId() + item.getClDid().toString());
|
||||||
|
wlRecord.setStatisticalInterval(item.getStatCycle());
|
||||||
|
wlRecord.setPt(item.getPtRatio());
|
||||||
|
wlRecord.setCt(item.getCtRatio());
|
||||||
|
//电压等级
|
||||||
|
DictData dictData = dicDataFeignClient.getDicDataByCodeAndType(channelVol(item.getVolGrade()) + "kV","Dev_Voltage_Stand").getData();
|
||||||
|
wlRecord.setVoltageLevel(Objects.isNull(dictData)?null:dictData.getId());
|
||||||
|
wlRecord.setCapacitySscb(item.getCapacitySscb());
|
||||||
|
wlRecord.setCapacitySscmin(item.getCapacitySscmin());
|
||||||
|
wlRecord.setCapacitySt(item.getCapacitySt());
|
||||||
|
wlRecord.setCapacitySi(item.getCapacitySi());
|
||||||
|
//电压接线方式
|
||||||
|
wlRecord.setVolConType(getVolConType(item.getVolConType()));
|
||||||
|
//fixme 电流接线方式 这边系统没有字典,录入字典通用性不强,采用装置上送值存储
|
||||||
|
wlRecord.setCurConSel(item.getCurConSel().toString());
|
||||||
|
wlRecord.setStartTime(timestampToDatetime((item.getPrjTimeStart() - 8*3600)));
|
||||||
|
wlRecord.setType(1);
|
||||||
|
wlRecord.setState(1);
|
||||||
|
wlRecord.setGcDataPath(item.getPrjDataPath());
|
||||||
|
wlRecordFeignClient.addBaseData(wlRecord);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理电压
|
||||||
|
* @param vol
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String channelVol(Float vol) {
|
||||||
|
BigDecimal value = new BigDecimal(vol);
|
||||||
|
BigDecimal noZeros = value.stripTrailingZeros();
|
||||||
|
return noZeros.toPlainString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 0-星型, 1-角型, 2-V型
|
||||||
|
// star-星型、Star_Triangle-星三角、Open_Delta-开口三角
|
||||||
|
public String getVolConType(Integer volConType) {
|
||||||
|
String result = null;
|
||||||
|
String dictDataCode = null;
|
||||||
|
switch (volConType) {
|
||||||
|
case 0:
|
||||||
|
dictDataCode = "star";
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
dictDataCode = "Star_Triangle";
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
dictDataCode = "Open_Delta";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!Objects.isNull(dictDataCode)) {
|
||||||
|
DictData dictData = dicDataFeignClient.getDicDataByCodeAndType(dictDataCode,"Dev_Connect").getData();
|
||||||
|
result = dictData.getId();
|
||||||
|
}
|
||||||
|
return Objects.isNull(result)?null:result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 缓存监测点相关信息
|
* 缓存监测点相关信息
|
||||||
*/
|
*/
|
||||||
@@ -248,4 +336,9 @@ public class EventServiceImpl implements IEventService {
|
|||||||
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS");
|
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS");
|
||||||
return LocalDateTime.parse(time, fmt);
|
return LocalDateTime.parse(time, fmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LocalDateTime timestampToDatetime(long timestamp){
|
||||||
|
Instant instant = Instant.ofEpochSecond(timestamp);
|
||||||
|
return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import com.njcn.access.utils.CRC32Utils;
|
|||||||
import com.njcn.access.utils.ChannelObjectUtil;
|
import com.njcn.access.utils.ChannelObjectUtil;
|
||||||
import com.njcn.common.config.GeneralInfo;
|
import com.njcn.common.config.GeneralInfo;
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
|
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||||
import com.njcn.csharmonic.api.WavePicFeignClient;
|
import com.njcn.csharmonic.api.WavePicFeignClient;
|
||||||
import com.njcn.mq.message.AppFileMessage;
|
import com.njcn.mq.message.AppFileMessage;
|
||||||
import com.njcn.oss.constant.GeneralConstant;
|
import com.njcn.oss.constant.GeneralConstant;
|
||||||
@@ -28,7 +29,10 @@ import com.njcn.zlevent.pojo.dto.FileStreamDto;
|
|||||||
import com.njcn.zlevent.pojo.dto.WaveTimeDto;
|
import com.njcn.zlevent.pojo.dto.WaveTimeDto;
|
||||||
import com.njcn.zlevent.pojo.po.CsEventFileLogs;
|
import com.njcn.zlevent.pojo.po.CsEventFileLogs;
|
||||||
import com.njcn.zlevent.pojo.po.CsWave;
|
import com.njcn.zlevent.pojo.po.CsWave;
|
||||||
import com.njcn.zlevent.service.*;
|
import com.njcn.zlevent.service.ICsEventFileLogsService;
|
||||||
|
import com.njcn.zlevent.service.ICsEventService;
|
||||||
|
import com.njcn.zlevent.service.ICsWaveService;
|
||||||
|
import com.njcn.zlevent.service.IFileService;
|
||||||
import com.njcn.zlevent.utils.RemoveInfoUtils;
|
import com.njcn.zlevent.utils.RemoveInfoUtils;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -61,15 +65,15 @@ public class FileServiceImpl implements IFileService {
|
|||||||
private final WavePicFeignClient wavePicFeignClient;
|
private final WavePicFeignClient wavePicFeignClient;
|
||||||
private final ICsWaveService csWaveService;
|
private final ICsWaveService csWaveService;
|
||||||
private final GeneralInfo generalInfo;
|
private final GeneralInfo generalInfo;
|
||||||
private final ICsWaveAnalysisService iCsWaveAnalysisService;
|
|
||||||
private final ChannelObjectUtil channelObjectUtil;
|
private final ChannelObjectUtil channelObjectUtil;
|
||||||
private final RemoveInfoUtils removeInfoUtils;
|
private final RemoveInfoUtils removeInfoUtils;
|
||||||
|
private static Integer mid = 1;
|
||||||
|
private final EquipmentFeignClient equipmentFeignClient;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void analysisFileInfo(AppFileMessage appFileMessage) {
|
public void analysisFileInfo(AppFileMessage appFileMessage) {
|
||||||
if (Objects.equals(appFileMessage.getCode(), AccessEnum.SUCCESS.getCode())){
|
if (Objects.equals(appFileMessage.getCode(), AccessEnum.SUCCESS.getCode())){
|
||||||
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS");
|
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS");
|
||||||
int mid = 1;
|
|
||||||
int range = 51200;
|
int range = 51200;
|
||||||
String fileName = appFileMessage.getMsg().getFileInfo().getName();
|
String fileName = appFileMessage.getMsg().getFileInfo().getName();
|
||||||
//缓存文件信息用于文件流拼接
|
//缓存文件信息用于文件流拼接
|
||||||
@@ -100,10 +104,20 @@ public class FileServiceImpl implements IFileService {
|
|||||||
csWave.setCheckNumber(appFileMessage.getMsg().getFileInfo().getFileCheck());
|
csWave.setCheckNumber(appFileMessage.getMsg().getFileInfo().getFileCheck());
|
||||||
csWave.setStatus(0);
|
csWave.setStatus(0);
|
||||||
csWaveService.save(csWave);
|
csWaveService.save(csWave);
|
||||||
|
//获取mid
|
||||||
|
Object object = channelObjectUtil.getDeviceMid(appFileMessage.getId());
|
||||||
|
if (!Objects.isNull(object)) {
|
||||||
|
mid = (Integer) object;
|
||||||
|
}
|
||||||
//请求当前文件的数据
|
//请求当前文件的数据
|
||||||
askFileStream(appFileMessage.getId(),mid,fileName,-1,range);
|
askFileStream(appFileMessage.getId(),mid,fileName,-1,range);
|
||||||
redisUtil.saveByKey(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileInfoDto.getName()), fileInfoDto);
|
redisUtil.saveByKey(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileInfoDto.getName()), fileInfoDto);
|
||||||
redisUtil.delete(AppRedisKey.TIME+fileName);
|
redisUtil.delete(AppRedisKey.TIME+fileName);
|
||||||
|
mid = mid + 1;
|
||||||
|
if (mid > 10000) {
|
||||||
|
mid = 1;
|
||||||
|
}
|
||||||
|
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + appFileMessage.getId(),mid);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new BusinessException(AccessResponseEnum.RESPONSE_ERROR);
|
throw new BusinessException(AccessResponseEnum.RESPONSE_ERROR);
|
||||||
@@ -125,6 +139,8 @@ public class FileServiceImpl implements IFileService {
|
|||||||
csEventLogs.setNdid(appFileMessage.getId());
|
csEventLogs.setNdid(appFileMessage.getId());
|
||||||
csEventLogs.setFileName(appFileMessage.getMsg().getName());
|
csEventLogs.setFileName(appFileMessage.getMsg().getName());
|
||||||
csEventLogs.setStatus(0);
|
csEventLogs.setStatus(0);
|
||||||
|
//判断设备类型 true:治理设备 false:其他设备
|
||||||
|
boolean devModel = equipmentFeignClient.judgeDevModel(appFileMessage.getId()).getData();
|
||||||
try {
|
try {
|
||||||
//todo 目前文件先只处理波形事件的,后续有其他文件再做处理
|
//todo 目前文件先只处理波形事件的,后续有其他文件再做处理
|
||||||
String fileName = appFileMessage.getMsg().getName();
|
String fileName = appFileMessage.getMsg().getName();
|
||||||
@@ -138,7 +154,7 @@ public class FileServiceImpl implements IFileService {
|
|||||||
Object fileInfo = redisUtil.getObjectByKey(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileName));
|
Object fileInfo = redisUtil.getObjectByKey(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileName));
|
||||||
FileInfoDto fileInfoDto = JSON.parseObject(JSON.toJSONString(fileInfo), FileInfoDto.class);
|
FileInfoDto fileInfoDto = JSON.parseObject(JSON.toJSONString(fileInfo), FileInfoDto.class);
|
||||||
if (Objects.isNull(fileInfoDto)) {
|
if (Objects.isNull(fileInfoDto)) {
|
||||||
String fileCheck = redisUtil.getObjectByKey("fileCheck"+fileName).toString();
|
String fileCheck = redisUtil.getObjectByKey("fileCheck"+appFileMessage.getId()+fileName).toString();
|
||||||
if (appFileMessage.getMsg().getFrameTotal() == 1) {
|
if (appFileMessage.getMsg().getFrameTotal() == 1) {
|
||||||
//解析文件入库
|
//解析文件入库
|
||||||
filePath = fileStream(1,null,appFileMessage.getMsg().getData(),fileName,appFileMessage.getId(),fileCheck,"download");
|
filePath = fileStream(1,null,appFileMessage.getMsg().getData(),fileName,appFileMessage.getId(),fileCheck,"download");
|
||||||
@@ -148,8 +164,14 @@ public class FileServiceImpl implements IFileService {
|
|||||||
csEventLogs.setAllStep(1);
|
csEventLogs.setAllStep(1);
|
||||||
csEventLogs.setIsAll(1);
|
csEventLogs.setIsAll(1);
|
||||||
redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(appFileMessage.getMsg().getName()));
|
redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(appFileMessage.getMsg().getName()));
|
||||||
redisUtil.delete(AppRedisKey.FILE_PART.concat(appFileMessage.getMsg().getName()));
|
|
||||||
redisUtil.delete(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileName));
|
redisUtil.delete(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileName));
|
||||||
|
//存储文件信息
|
||||||
|
fileStreamDto.setTotal(appFileMessage.getMsg().getFrameTotal());
|
||||||
|
fileStreamDto.setNDid(appFileMessage.getId());
|
||||||
|
fileStreamDto.setFrameLen(appFileMessage.getMsg().getFrameLen());
|
||||||
|
list.add(appFileMessage.getMsg().getFrameCurr());
|
||||||
|
fileStreamDto.setList(list);
|
||||||
|
redisUtil.saveByKey(AppRedisKey.FILE_PART.concat(appFileMessage.getMsg().getName()), fileStreamDto);
|
||||||
} else {
|
} else {
|
||||||
//收到数据就刷新缓存值
|
//收到数据就刷新缓存值
|
||||||
redisUtil.saveByKeyWithExpire(AppRedisKey.FILE_DOWN_TIME.concat(appFileMessage.getMsg().getName()), null, 60L);
|
redisUtil.saveByKeyWithExpire(AppRedisKey.FILE_DOWN_TIME.concat(appFileMessage.getMsg().getName()), null, 60L);
|
||||||
@@ -191,7 +213,6 @@ public class FileServiceImpl implements IFileService {
|
|||||||
file.delete();
|
file.delete();
|
||||||
}
|
}
|
||||||
redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(appFileMessage.getMsg().getName()));
|
redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(appFileMessage.getMsg().getName()));
|
||||||
redisUtil.delete(AppRedisKey.FILE_PART.concat(appFileMessage.getMsg().getName()));
|
|
||||||
redisUtil.delete(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileName));
|
redisUtil.delete(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileName));
|
||||||
redisUtil.delete(AppRedisKey.FILE_DOWN_TIME.concat(appFileMessage.getMsg().getName()));
|
redisUtil.delete(AppRedisKey.FILE_DOWN_TIME.concat(appFileMessage.getMsg().getName()));
|
||||||
} else {
|
} else {
|
||||||
@@ -214,8 +235,11 @@ public class FileServiceImpl implements IFileService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//推送mqtt
|
||||||
|
String json = "{fileName:"+appFileMessage.getMsg().getName()+",allStep:"+appFileMessage.getMsg().getFrameTotal()+",nowStep:"+ appFileMessage.getMsg().getFrameCurr() +"}";
|
||||||
|
publisher.send("/Web/Progress/" + appFileMessage.getId(), new Gson().toJson(json), 1, false);
|
||||||
if (!Objects.isNull(filePath)){
|
if (!Objects.isNull(filePath)){
|
||||||
redisUtil.saveByKey("downloadFilePath:"+appFileMessage.getMsg().getName(),filePath);
|
redisUtil.saveByKey("downloadFilePath:" + appFileMessage.getId() + appFileMessage.getMsg().getName(),filePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//录波文件下载
|
//录波文件下载
|
||||||
@@ -238,7 +262,7 @@ public class FileServiceImpl implements IFileService {
|
|||||||
filePath = filePath.replaceAll(GeneralConstant.CFG,"").replaceAll(GeneralConstant.DAT,"");
|
filePath = filePath.replaceAll(GeneralConstant.CFG,"").replaceAll(GeneralConstant.DAT,"");
|
||||||
List<String> eventList = correlateEvents(fileInfoDto,filePath,fileName);
|
List<String> eventList = correlateEvents(fileInfoDto,filePath,fileName);
|
||||||
//波形文件解析成图片
|
//波形文件解析成图片
|
||||||
if (CollectionUtil.isNotEmpty(eventList)){
|
if (CollectionUtil.isNotEmpty(eventList) && devModel){
|
||||||
eventList.forEach(wavePicFeignClient::getWavePics);
|
eventList.forEach(wavePicFeignClient::getWavePics);
|
||||||
}
|
}
|
||||||
//解析完删除、处理缓存
|
//解析完删除、处理缓存
|
||||||
@@ -284,7 +308,7 @@ public class FileServiceImpl implements IFileService {
|
|||||||
filePath = filePath.replaceAll(GeneralConstant.CFG, "").replaceAll(GeneralConstant.DAT, "");
|
filePath = filePath.replaceAll(GeneralConstant.CFG, "").replaceAll(GeneralConstant.DAT, "");
|
||||||
List<String> eventList = correlateEvents(fileInfoDto, filePath, fileName);
|
List<String> eventList = correlateEvents(fileInfoDto, filePath, fileName);
|
||||||
//波形文件解析成图片
|
//波形文件解析成图片
|
||||||
if (CollectionUtil.isNotEmpty(eventList)) {
|
if (CollectionUtil.isNotEmpty(eventList) && devModel) {
|
||||||
eventList.forEach(wavePicFeignClient::getWavePics);
|
eventList.forEach(wavePicFeignClient::getWavePics);
|
||||||
}
|
}
|
||||||
redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(appFileMessage.getMsg().getName()));
|
redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(appFileMessage.getMsg().getName()));
|
||||||
@@ -329,6 +353,18 @@ public class FileServiceImpl implements IFileService {
|
|||||||
csEventLogs.setCompleteTime(LocalDateTime.now());
|
csEventLogs.setCompleteTime(LocalDateTime.now());
|
||||||
//记录日志
|
//记录日志
|
||||||
csEventLogsService.save(csEventLogs);
|
csEventLogsService.save(csEventLogs);
|
||||||
|
//清空缓存
|
||||||
|
redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(appFileMessage.getMsg().getName()));
|
||||||
|
redisUtil.delete(AppRedisKey.FILE_PART.concat(appFileMessage.getMsg().getName()));
|
||||||
|
//删除临时文件
|
||||||
|
String fileName = appFileMessage.getMsg().getName();
|
||||||
|
String lsFileName = generalInfo.getBusinessTempPath() + File.separator + fileName.split(StrUtil.SLASH)[fileName.split(StrUtil.SLASH).length - 1];
|
||||||
|
File file = new File(lsFileName);
|
||||||
|
if (file.exists()) {
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
//继续消费
|
||||||
|
removeInfoUtils.deleteEventInfo(appFileMessage.getId(),appFileMessage.getMsg().getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class RemoveInfoUtils {
|
|||||||
// 删除相关的 Redis 键
|
// 删除相关的 Redis 键
|
||||||
deleteRelatedKeys(nDid, fileName);
|
deleteRelatedKeys(nDid, fileName);
|
||||||
// 处理重试逻辑
|
// 处理重试逻辑
|
||||||
if (retryTimes < 3) {
|
if (retryTimes < 4) {
|
||||||
// 增加重试次数并保存
|
// 增加重试次数并保存
|
||||||
redisUtil.saveByKey(("retryEvent:" + nDid + fileName), retryTimes + 1);
|
redisUtil.saveByKey(("retryEvent:" + nDid + fileName), retryTimes + 1);
|
||||||
// 重排文件列表
|
// 重排文件列表
|
||||||
@@ -54,6 +54,8 @@ public class RemoveInfoUtils {
|
|||||||
} else {
|
} else {
|
||||||
// 从列表中移除文件
|
// 从列表中移除文件
|
||||||
removeFileFromList(nDid, fileName);
|
removeFileFromList(nDid, fileName);
|
||||||
|
// 清空计数
|
||||||
|
redisUtil.delete(("retryEvent:" + nDid + fileName));
|
||||||
}
|
}
|
||||||
// 检查是否还有其他文件需要处理
|
// 检查是否还有其他文件需要处理
|
||||||
List<WaveTimeDto> fileDto = channelObjectUtil.objectToList(redisUtil.getObjectByKey("eventFile:" + nDid), WaveTimeDto.class);
|
List<WaveTimeDto> fileDto = channelObjectUtil.objectToList(redisUtil.getObjectByKey("eventFile:" + nDid), WaveTimeDto.class);
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ package com.njcn.zlevent.utils;
|
|||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.date.DatePattern;
|
import cn.hutool.core.date.DatePattern;
|
||||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
import com.njcn.access.pojo.dto.NoticeUserDto;
|
||||||
|
import com.njcn.access.utils.SendMessageUtil;
|
||||||
import com.njcn.csdevice.api.CsDeviceUserFeignClient;
|
import com.njcn.csdevice.api.CsDeviceUserFeignClient;
|
||||||
import com.njcn.csdevice.api.CsLedgerFeignClient;
|
import com.njcn.csdevice.api.CsLedgerFeignClient;
|
||||||
|
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||||
import com.njcn.csdevice.api.EventLogsFeignClient;
|
import com.njcn.csdevice.api.EventLogsFeignClient;
|
||||||
import com.njcn.csdevice.pojo.dto.DevDetailDTO;
|
import com.njcn.csdevice.pojo.dto.DevDetailDTO;
|
||||||
import com.njcn.csdevice.pojo.po.CsEventSendMsg;
|
import com.njcn.csdevice.pojo.po.CsEventSendMsg;
|
||||||
@@ -15,20 +17,12 @@ import com.njcn.user.api.AppUserFeignClient;
|
|||||||
import com.njcn.user.api.UserFeignClient;
|
import com.njcn.user.api.UserFeignClient;
|
||||||
import com.njcn.user.pojo.po.User;
|
import com.njcn.user.pojo.po.User;
|
||||||
import com.njcn.user.pojo.po.app.AppInfoSet;
|
import com.njcn.user.pojo.po.app.AppInfoSet;
|
||||||
import com.njcn.zlevent.pojo.dto.NoticeUserDto;
|
|
||||||
import com.njcn.zlevent.service.ICsEventUserService;
|
import com.njcn.zlevent.service.ICsEventUserService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
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;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -48,27 +42,24 @@ public class SendEventUtils {
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private UserFeignClient userFeignClient;
|
private UserFeignClient userFeignClient;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private AppUserFeignClient appUserFeignClient;
|
private AppUserFeignClient appUserFeignClient;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private CsDeviceUserFeignClient csDeviceUserFeignClient;
|
private CsDeviceUserFeignClient csDeviceUserFeignClient;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private AppInfoSetFeignClient appInfoSetFeignClient;
|
private AppInfoSetFeignClient appInfoSetFeignClient;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private EventLogsFeignClient eventLogsFeignClient;
|
private EventLogsFeignClient eventLogsFeignClient;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private EpdFeignClient epdFeignClient;
|
private EpdFeignClient epdFeignClient;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ICsEventUserService csEventUserService;
|
private ICsEventUserService csEventUserService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private CsLedgerFeignClient csLedgerFeignclient;
|
private CsLedgerFeignClient csLedgerFeignclient;
|
||||||
|
@Resource
|
||||||
|
private SendMessageUtil sendMessageUtil;
|
||||||
|
@Resource
|
||||||
|
private EquipmentFeignClient equipmentFeignClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 事件推送给相关用户
|
* 事件推送给相关用户
|
||||||
@@ -80,7 +71,7 @@ public class SendEventUtils {
|
|||||||
* @param id 事件id
|
* @param id 事件id
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void sendUser(Integer eventType,String type,String devId, String eventName, LocalDateTime eventTime, String id) {
|
public void sendUser(Integer eventType,String type,String devId, String eventName, LocalDateTime eventTime, String id, String nDid) {
|
||||||
int code;
|
int code;
|
||||||
List<User> users = new ArrayList<>();
|
List<User> users = new ArrayList<>();
|
||||||
List<String> eventUser;
|
List<String> eventUser;
|
||||||
@@ -91,6 +82,9 @@ public class SendEventUtils {
|
|||||||
NoticeUserDto.Payload payload = new NoticeUserDto.Payload();
|
NoticeUserDto.Payload payload = new NoticeUserDto.Payload();
|
||||||
String content;
|
String content;
|
||||||
List<CsEventUserPO> result = new ArrayList<>();
|
List<CsEventUserPO> result = new ArrayList<>();
|
||||||
|
//获取设备类型 true:治理设备 false:其他类型的设备
|
||||||
|
boolean devModel = equipmentFeignClient.judgeDevModel(nDid).getData();
|
||||||
|
if (devModel) {
|
||||||
//事件处理
|
//事件处理
|
||||||
if (eventType == 1){
|
if (eventType == 1){
|
||||||
eventName = epdFeignClient.findByName(eventName).getData().getShowName();
|
eventName = epdFeignClient.findByName(eventName).getData().getShowName();
|
||||||
@@ -230,7 +224,7 @@ public class SendEventUtils {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
if (CollectionUtil.isNotEmpty(filteredList)) {
|
if (CollectionUtil.isNotEmpty(filteredList)) {
|
||||||
noticeUserDto.setPushClientId(filteredList);
|
noticeUserDto.setPushClientId(filteredList);
|
||||||
sendEventToUser(noticeUserDto);
|
sendMessageUtil.sendEventToUser(noticeUserDto);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//记录推送日志
|
//记录推送日志
|
||||||
@@ -254,47 +248,6 @@ public class SendEventUtils {
|
|||||||
csEventUserService.saveBatch(result);
|
csEventUserService.saveBatch(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送通知消息
|
|
||||||
*/
|
|
||||||
public void sendEventToUser(NoticeUserDto noticeUserDto) {
|
|
||||||
try {
|
|
||||||
// 创建一个URL对象,指定目标HTTPS接口地址
|
|
||||||
//URL url = new URL("https://fc-mp-b46c4dff-7244-4f7c-ae8b-7c1194d8cce8.next.bspapp.com/push");
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -61,6 +61,11 @@
|
|||||||
<artifactId>stat-api</artifactId>
|
<artifactId>stat-api</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.njcn</groupId>
|
||||||
|
<artifactId>rt-api</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.njcn</groupId>
|
<groupId>com.njcn</groupId>
|
||||||
<artifactId>system-api</artifactId>
|
<artifactId>system-api</artifactId>
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.njcn.message;
|
package com.njcn.message;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.mybatis.spring.annotation.MapperScan;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
import org.springframework.context.annotation.DependsOn;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -13,9 +13,9 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
|
|||||||
* @date 2021年12月09日 20:59
|
* @date 2021年12月09日 20:59
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
//@MapperScan("com.njcn.**.mapper")
|
|
||||||
@EnableFeignClients(basePackages = "com.njcn")
|
@EnableFeignClients(basePackages = "com.njcn")
|
||||||
@SpringBootApplication(scanBasePackages = "com.njcn")
|
@SpringBootApplication(scanBasePackages = "com.njcn")
|
||||||
|
@DependsOn("proxyMapperRegister")
|
||||||
public class MessageBootApplication {
|
public class MessageBootApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.njcn.mq.message.AppAutoDataMessage;
|
|||||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||||
import com.njcn.redis.pojo.enums.RedisKeyEnum;
|
import com.njcn.redis.pojo.enums.RedisKeyEnum;
|
||||||
import com.njcn.redis.utils.RedisUtil;
|
import com.njcn.redis.utils.RedisUtil;
|
||||||
|
import com.njcn.rt.api.RtFeignClient;
|
||||||
import com.njcn.stat.api.StatFeignClient;
|
import com.njcn.stat.api.StatFeignClient;
|
||||||
import com.njcn.system.api.RocketMqLogFeignClient;
|
import com.njcn.system.api.RocketMqLogFeignClient;
|
||||||
import com.njcn.system.pojo.po.RocketmqMsgErrorLog;
|
import com.njcn.system.pojo.po.RocketmqMsgErrorLog;
|
||||||
@@ -39,14 +40,14 @@ public class AppAutoDataConsumer extends EnhanceConsumerMessageHandler<AppAutoDa
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private StatFeignClient statFeignClient;
|
private StatFeignClient statFeignClient;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private RedisUtil redisUtil;
|
private RedisUtil redisUtil;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private RocketMqLogFeignClient rocketMqLogFeignClient;
|
private RocketMqLogFeignClient rocketMqLogFeignClient;
|
||||||
|
@Resource
|
||||||
|
private RtFeignClient rtFeignClient;
|
||||||
// @Resource
|
// @Resource
|
||||||
// private WlRecordFeignClient wlRecordFeignClient;
|
// private WlRecordFeignClient wlRecordFeignClient
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleMessage(AppAutoDataMessage appAutoDataMessage) {
|
protected void handleMessage(AppAutoDataMessage appAutoDataMessage) {
|
||||||
@@ -57,6 +58,7 @@ public class AppAutoDataConsumer extends EnhanceConsumerMessageHandler<AppAutoDa
|
|||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
log.info("分发至实时数据");
|
log.info("分发至实时数据");
|
||||||
|
rtFeignClient.analysis(appAutoDataMessage);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
log.info(appAutoDataMessage.getKey() + "分发至统计数据");
|
log.info(appAutoDataMessage.getKey() + "分发至统计数据");
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ public class AppEventConsumer extends EnhanceConsumerMessageHandler<AppEventMess
|
|||||||
break;
|
break;
|
||||||
case 32:
|
case 32:
|
||||||
log.info("分发至便携式基础数据处理");
|
log.info("分发至便携式基础数据处理");
|
||||||
|
eventFeignClient.getPortableData(appEventMessage);
|
||||||
break;
|
break;
|
||||||
case 241:
|
case 241:
|
||||||
log.info("分发装置异常事件统计");
|
log.info("分发装置异常事件统计");
|
||||||
|
|||||||
Reference in New Issue
Block a user