Compare commits
47 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1bb9ad1cf7 | |||
| 186eec4f7e | |||
| 0b32c09fdb | |||
| 28b23e9c52 | |||
| 7277299c66 | |||
| 49642066f5 | |||
| 826970357e | |||
| 11713e9b68 | |||
| 6d3a1dd735 | |||
| 72150a3acc | |||
| 19999a582e | |||
| 7293d9b84d | |||
| 40a6cd608c | |||
| 1fb08ab66c | |||
| c6e938e7a0 | |||
| 52d2dda01c | |||
| f9926d16f8 | |||
| 87fc735969 | |||
| cc22afd877 | |||
| 2ec0024d0f | |||
| f0a22192fb | |||
| 98b901e6ab | |||
| da3b99f663 | |||
| 04fd2409cf | |||
| b014aa7c8c | |||
| 67be8404d5 | |||
| 19f1c54ade | |||
| f211713f2e | |||
| d9708580db | |||
| af96a91303 | |||
| 4006d26d5f | |||
| 885fc36739 | |||
| eed276c9b3 | |||
| 24cf6e8d56 | |||
| 4028bfbff3 | |||
| 3861726801 | |||
| b5267c24f4 | |||
| 0c2954b8ba | |||
| 5137565195 | |||
| 82b5cfcf8d | |||
| 5c6d05b307 | |||
| 9f6bb44b3b | |||
| c40cd44402 | |||
| fc73879c95 | |||
| de8242fbf0 | |||
| e7412d916a | |||
| 851404f62d |
@@ -0,0 +1,26 @@
|
||||
package com.njcn.access.api;
|
||||
|
||||
import com.njcn.access.api.fallback.CsLineLatestDataClientFallbackFactory;
|
||||
import com.njcn.access.pojo.po.CsLineLatestData;
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.ACCESS_BOOT, path = "/csLineLatestData", fallbackFactory = CsLineLatestDataClientFallbackFactory.class,contextId = "csLineLatestData")
|
||||
|
||||
public interface CsLineLatestDataFeignClient {
|
||||
|
||||
@PostMapping("/add")
|
||||
HttpResult<String> addData(@RequestBody CsLineLatestData csLineLatestData);
|
||||
|
||||
@PostMapping("/list")
|
||||
HttpResult<List<CsLineLatestData>> listData();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.njcn.access.api.fallback;
|
||||
|
||||
import com.njcn.access.api.CsLineLatestDataFeignClient;
|
||||
import com.njcn.access.pojo.po.CsLineLatestData;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class CsLineLatestDataClientFallbackFactory implements FallbackFactory<CsLineLatestDataFeignClient> {
|
||||
@Override
|
||||
public CsLineLatestDataFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if (cause.getCause() instanceof BusinessException) {
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new CsLineLatestDataFeignClient() {
|
||||
|
||||
@Override
|
||||
public HttpResult<String> addData(CsLineLatestData csLineLatestData) {
|
||||
log.error("{}异常,降级处理,异常为:{}","新增治理设备最近数据时间",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<List<CsLineLatestData>> listData() {
|
||||
log.error("{}异常,降级处理,异常为:{}","查询整体数据",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,10 @@ public class RspDataDto {
|
||||
|
||||
@SerializedName("Capacity_A")
|
||||
private Double capacityA;
|
||||
|
||||
@SerializedName("StatCycle")
|
||||
@ApiModelProperty("接线方式")
|
||||
private Integer StatCycle;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.njcn.access.pojo.dto;
|
||||
|
||||
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -17,39 +18,49 @@ import java.util.List;
|
||||
public class AutoDataDto {
|
||||
|
||||
@SerializedName("Mid")
|
||||
@JsonProperty("Mid")
|
||||
private Integer mid;
|
||||
|
||||
@SerializedName("Did")
|
||||
@JsonProperty("Did")
|
||||
@ApiModelProperty("逻辑设备 治理逻辑设备为1 电能质量设备为2")
|
||||
private Integer did;
|
||||
|
||||
@SerializedName("Pri")
|
||||
@JsonProperty("Pri")
|
||||
private Integer pri;
|
||||
|
||||
@SerializedName("Type")
|
||||
@JsonProperty("Type")
|
||||
private Integer type;
|
||||
|
||||
@SerializedName("Msg")
|
||||
@JsonProperty("Msg")
|
||||
private Msg msg;
|
||||
|
||||
@Data
|
||||
public static class Msg{
|
||||
|
||||
@SerializedName("Cldid")
|
||||
@JsonProperty("Cldid")
|
||||
@ApiModelProperty("逻辑子设备 治理逻辑设备为0 电能质量设备为1、2")
|
||||
private Integer clDid;
|
||||
|
||||
@SerializedName("DataType")
|
||||
@JsonProperty("DataType")
|
||||
private Integer dataType;
|
||||
|
||||
@SerializedName("DataAttr")
|
||||
@JsonProperty("DataAttr")
|
||||
@ApiModelProperty("数据属性:无-0、实时-1、统计-2")
|
||||
private Integer dataAttr;
|
||||
|
||||
@SerializedName("DsNameIdx")
|
||||
@JsonProperty("DsNameIdx")
|
||||
private Integer dsNameIdx;
|
||||
|
||||
@SerializedName("DataArray")
|
||||
@JsonProperty("DataArray")
|
||||
private List<DataArray> dataArray;
|
||||
}
|
||||
|
||||
@@ -57,95 +68,119 @@ public class AutoDataDto {
|
||||
public static class DataArray{
|
||||
|
||||
@SerializedName("DataAttr")
|
||||
@JsonProperty("DataAttr")
|
||||
@ApiModelProperty("数据属性 -1-无 0-Rt(实时) 1-Max 2-Min 3-Avg 4-Cp95")
|
||||
private Integer dataAttr;
|
||||
|
||||
@SerializedName("DataTimeSec")
|
||||
@JsonProperty("DataTimeSec")
|
||||
private Long dataTimeSec;
|
||||
|
||||
@SerializedName("DataTimeUSec")
|
||||
@JsonProperty("DataTimeUSec")
|
||||
private Integer dataTimeUSec;
|
||||
|
||||
@SerializedName("DataTag")
|
||||
@JsonProperty("DataTag")
|
||||
@ApiModelProperty("数据是否参与合格率统计")
|
||||
private Integer dataTag;
|
||||
|
||||
@SerializedName("Code")
|
||||
@JsonProperty("Code")
|
||||
@ApiModelProperty("事件码")
|
||||
private Integer code;
|
||||
private String code;
|
||||
|
||||
@SerializedName("Data")
|
||||
@JsonProperty("Data")
|
||||
private String data;
|
||||
|
||||
@SerializedName("PrjName")
|
||||
@JsonProperty("PrjName")
|
||||
@ApiModelProperty("工程名称")
|
||||
private String prjName;
|
||||
|
||||
@SerializedName("PrjTimeStart")
|
||||
@JsonProperty("PrjTimeStart")
|
||||
@ApiModelProperty("装置启动时间")
|
||||
private Long prjTimeStart;
|
||||
|
||||
@SerializedName("PrjTimeEnd")
|
||||
@JsonProperty("PrjTimeEnd")
|
||||
@ApiModelProperty("装置结束时间")
|
||||
private Long prjTimeEnd;
|
||||
|
||||
@SerializedName("PrjDataPath")
|
||||
@JsonProperty("PrjDataPath")
|
||||
@ApiModelProperty("装置数据路径")
|
||||
private String prjDataPath;
|
||||
|
||||
@SerializedName("DevType")
|
||||
@JsonProperty("DevType")
|
||||
@ApiModelProperty("装置型号")
|
||||
private String devType;
|
||||
|
||||
@SerializedName("DevMac")
|
||||
@JsonProperty("DevMac")
|
||||
@ApiModelProperty("装置mac地址")
|
||||
private String devMac;
|
||||
|
||||
@SerializedName("AppVersion")
|
||||
@JsonProperty("AppVersion")
|
||||
@ApiModelProperty("装置程序版本")
|
||||
private String appVersion;
|
||||
|
||||
@SerializedName("Cldid")
|
||||
@JsonProperty("Cldid")
|
||||
@ApiModelProperty("逻辑子设备id")
|
||||
private Integer clDid;
|
||||
|
||||
@SerializedName("StatCycle")
|
||||
@JsonProperty("StatCycle")
|
||||
@ApiModelProperty("统计间隔")
|
||||
private Integer statCycle;
|
||||
|
||||
@SerializedName("VolGrade")
|
||||
@JsonProperty("VolGrade")
|
||||
@ApiModelProperty("电压等级")
|
||||
private Float volGrade;
|
||||
|
||||
@SerializedName("VolConType")
|
||||
@JsonProperty("VolConType")
|
||||
@ApiModelProperty("电压接线方式(0-星型, 1-角型, 2-V型)")
|
||||
private Integer volConType;
|
||||
|
||||
@SerializedName("CurConSel")
|
||||
@JsonProperty("CurConSel")
|
||||
@ApiModelProperty("电流接线方式(0-正常, 1-合成IB, 2-合成IC)")
|
||||
private Integer curConSel;
|
||||
|
||||
@SerializedName("PtRatio")
|
||||
@JsonProperty("PtRatio")
|
||||
@ApiModelProperty("PT变比")
|
||||
private Integer ptRatio;
|
||||
|
||||
@SerializedName("CtRatio")
|
||||
@JsonProperty("CtRatio")
|
||||
@ApiModelProperty("ct变比")
|
||||
private Integer ctRatio;
|
||||
|
||||
@SerializedName("CapacitySscb")
|
||||
@JsonProperty("CapacitySscb")
|
||||
@ApiModelProperty("基准短路容量")
|
||||
private Float capacitySscb;
|
||||
|
||||
@SerializedName("CapacitySscmin")
|
||||
@JsonProperty("CapacitySscmin")
|
||||
@ApiModelProperty("最小短路容量")
|
||||
private Float capacitySscmin;
|
||||
|
||||
@SerializedName("CapacitySt")
|
||||
@JsonProperty("CapacitySt")
|
||||
@ApiModelProperty("供电设备容量")
|
||||
private Float capacitySt;
|
||||
|
||||
@SerializedName("CapacitySi")
|
||||
@JsonProperty("CapacitySi")
|
||||
@ApiModelProperty("用户协议容量")
|
||||
private Float capacitySi;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,10 @@ public class DataSetDto implements Serializable {
|
||||
@ApiModelProperty("Primary-一次值;Secondary-二次值")
|
||||
private String dataLevel;
|
||||
|
||||
@SerializedName("ConType")
|
||||
@ApiModelProperty("接线方式 (0-星型,1-角型,2-V型)")
|
||||
private Integer conType;
|
||||
|
||||
@SerializedName("DataArray")
|
||||
@NotEmpty(message = "数据集合描述,不可为空")
|
||||
private List<DataArrayDto> dataArrayDtoList;
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.njcn.access.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 治理设备模块运行状态记录表
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-07-03
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@TableName("cs_line_latest_data")
|
||||
public class CsLineLatestData implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 监测点id
|
||||
*/
|
||||
@MppMultiId(value = "line_id")
|
||||
private String lineId;
|
||||
|
||||
/**
|
||||
* 最新数据时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime timeId;
|
||||
|
||||
|
||||
}
|
||||
@@ -5,8 +5,7 @@ import com.njcn.redis.utils.RedisUtil;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
@@ -52,4 +51,22 @@ public class ChannelObjectUtil {
|
||||
public Object getDeviceMid(String nDid) {
|
||||
return redisUtil.getObjectByKey(AppRedisKey.DEVICE_MID + nDid);
|
||||
}
|
||||
|
||||
|
||||
public Map<String, List<String>> objectToMap(Object obj) {
|
||||
// 创建并填充 Map
|
||||
Map<String, List<String>> resultMap = new HashMap<>();
|
||||
String json = obj.toString();
|
||||
// 移除首尾的 {}
|
||||
json = json.substring(1, json.length() - 1);
|
||||
// 找到键和值的分隔符位置
|
||||
int keyEndIndex = json.indexOf("=[");
|
||||
String key = json.substring(0, keyEndIndex);
|
||||
String valuesStr = json.substring(keyEndIndex + 2, json.length() - 1);
|
||||
// 将值字符串分割成列表
|
||||
String[] valuesArray = valuesStr.split(", ");
|
||||
List<String> valuesList = Arrays.asList(valuesArray);
|
||||
resultMap.put(key, valuesList);
|
||||
return resultMap;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.njcn.access.utils;
|
||||
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
import com.njcn.access.api.CsTopicFeignClient;
|
||||
import com.njcn.access.enums.AccessEnum;
|
||||
import com.njcn.access.enums.TypeEnum;
|
||||
import com.njcn.access.pojo.dto.ReqAndResDto;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class FileCommonUtils {
|
||||
|
||||
@Resource
|
||||
private CsTopicFeignClient csTopicFeignClient;
|
||||
@Resource
|
||||
private MqttPublisher publisher;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
/**
|
||||
* 询问文件信息
|
||||
*/
|
||||
public void askFileInfo(String nDid, Integer mid, String fileName) {
|
||||
String version = csTopicFeignClient.find(nDid).getData();
|
||||
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
|
||||
reqAndResParam.setMid(mid);
|
||||
reqAndResParam.setDid(0);
|
||||
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_8.getCode()));
|
||||
reqAndResParam.setExpire(-1);
|
||||
String json = "{Name:\""+fileName+"\"}";
|
||||
JSONObject jsonObject = JSONObject.fromObject(json);
|
||||
reqAndResParam.setMsg(jsonObject);
|
||||
log.info("请求文件信息报文:" + new Gson().toJson(reqAndResParam));
|
||||
publisher.send("/Pfm/DevFileCmd/"+version+"/"+nDid,new Gson().toJson(reqAndResParam),1,false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空下载缓存
|
||||
*/
|
||||
public void cleanRedisData(String nDid, String fileName) {
|
||||
redisUtil.deleteKeysByString("downloadFilePath:"+ nDid);
|
||||
redisUtil.delete("fileDowning:"+nDid);
|
||||
redisUtil.delete("fileCheck" + nDid + fileName);
|
||||
redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(fileName));
|
||||
redisUtil.delete(AppRedisKey.FILE_PART.concat(fileName));
|
||||
redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(fileName));
|
||||
redisUtil.delete(AppRedisKey.FILE_DOWN_TIME.concat(fileName));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,6 +20,12 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.paho</groupId>
|
||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||
<version>1.2.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.njcn</groupId>
|
||||
<artifactId>access-api</artifactId>
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.njcn.access.controller;
|
||||
|
||||
|
||||
import com.njcn.access.pojo.po.CsLineLatestData;
|
||||
import com.njcn.access.service.ICsLineLatestDataService;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 治理设备模块运行状态记录表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-07-03
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/csLineLatestData")
|
||||
@Api(tags = "暂降事件")
|
||||
@AllArgsConstructor
|
||||
public class CsLineLatestDataController extends BaseController {
|
||||
|
||||
private final ICsLineLatestDataService csLineLatestDataService;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("新增")
|
||||
@ApiImplicitParam(name = "csLineLatestData", value = "实体", required = true)
|
||||
public HttpResult<String> addData(@RequestBody CsLineLatestData csLineLatestData) {
|
||||
String methodDescribe = getMethodDescribe("csLineLatestData");
|
||||
csLineLatestDataService.addData(csLineLatestData);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/list")
|
||||
@ApiOperation("查询")
|
||||
public HttpResult<List<CsLineLatestData>> listData() {
|
||||
String methodDescribe = getMethodDescribe("listData");
|
||||
List<CsLineLatestData> list = csLineLatestDataService.list();
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.njcn.access.handler;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.alibaba.csp.sentinel.util.StringUtil;
|
||||
import com.alibaba.excel.util.CollectionUtils;
|
||||
@@ -20,7 +21,6 @@ import com.njcn.access.pojo.dto.*;
|
||||
import com.njcn.access.pojo.dto.file.FileDto;
|
||||
import com.njcn.access.pojo.dto.file.FileRedisDto;
|
||||
import com.njcn.access.pojo.param.ReqAndResParam;
|
||||
import com.njcn.access.pojo.po.CsDeviceOnlineLogs;
|
||||
import com.njcn.access.pojo.po.CsLineModel;
|
||||
import com.njcn.access.pojo.po.CsTopic;
|
||||
import com.njcn.access.service.ICsDeviceOnlineLogsService;
|
||||
@@ -31,6 +31,7 @@ import com.njcn.access.utils.ChannelObjectUtil;
|
||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.api.*;
|
||||
import com.njcn.csdevice.pojo.dto.PqsCommunicateDto;
|
||||
import com.njcn.csdevice.pojo.param.CsLineParam;
|
||||
import com.njcn.csdevice.pojo.po.*;
|
||||
import com.njcn.device.biz.pojo.po.Overlimit;
|
||||
@@ -99,6 +100,7 @@ public class MqttMessageHandler {
|
||||
private final ChannelObjectUtil channelObjectUtil;
|
||||
private final WaveFeignClient waveFeignClient;
|
||||
private final RtFeignClient rtFeignClient;
|
||||
private final CsCommunicateFeignClient csCommunicateFeignClient;
|
||||
@Autowired
|
||||
Validator validator;
|
||||
|
||||
@@ -267,6 +269,7 @@ public class MqttMessageHandler {
|
||||
CsDevModelPO po = devModelFeignClient.findModel(item.getDevType(),item.getVersionNo(),item.getVersionDate()).getData();
|
||||
if (Objects.isNull(po)){
|
||||
log.error(AccessResponseEnum.MODEL_NO_FIND.getMessage());
|
||||
logDto.setOperate(nDid + "模板缺失");
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(AccessResponseEnum.MODEL_NO_FIND.getMessage());
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
@@ -310,34 +313,24 @@ public class MqttMessageHandler {
|
||||
csEquipmentDeliveryService.updateStatusBynDid(nDid,AccessEnum.ACCESS.getCode());
|
||||
csEquipmentDeliveryService.updateRunStatusBynDid(nDid,AccessEnum.ONLINE.getCode());
|
||||
//记录设备上线
|
||||
CsDeviceOnlineLogs record = onlineLogsService.findLastData(nDid);
|
||||
CsDeviceOnlineLogs csDeviceOnlineLogs = new CsDeviceOnlineLogs();
|
||||
if(Objects.isNull(record)) {
|
||||
csDeviceOnlineLogs.setNdid(nDid);
|
||||
csDeviceOnlineLogs.setOnlineTime(LocalDateTime.now());
|
||||
onlineLogsService.save(csDeviceOnlineLogs);
|
||||
} else {
|
||||
LocalDateTime time = record.getOfflineTime();
|
||||
if (!Objects.isNull(time)){
|
||||
csDeviceOnlineLogs.setNdid(nDid);
|
||||
csDeviceOnlineLogs.setOnlineTime(LocalDateTime.now());
|
||||
onlineLogsService.save(csDeviceOnlineLogs);
|
||||
} else {
|
||||
record.setOnlineTime(LocalDateTime.now());
|
||||
onlineLogsService.updateById(record);
|
||||
}
|
||||
}
|
||||
//接入后系统重置装置心跳
|
||||
redisUtil.saveByKeyWithExpire("MQTT:" + nDid, Instant.now().toEpochMilli(),180L);
|
||||
//修改redis的mid
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,1);
|
||||
redisUtil.saveByKeyWithExpire("online" + nDid,"online",10L);
|
||||
PqsCommunicateDto dto = new PqsCommunicateDto();
|
||||
dto.setTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN)));
|
||||
dto.setDevId(nDid);
|
||||
dto.setType(1);
|
||||
dto.setDescription("通讯正常");
|
||||
csCommunicateFeignClient.insertion(dto);
|
||||
//询问设备软件信息
|
||||
askDevData(nDid,version,1,mid);
|
||||
//更新治理监测点信息和设备容量
|
||||
askDevData(nDid,version,2,(res.getMid()+1));
|
||||
//更新电网侧、负载侧监测点信息
|
||||
askDevData(nDid,version,3,(res.getMid()+1));
|
||||
//接入后系统重置装置心跳
|
||||
redisUtil.saveByKeyWithExpire("MQTT:" + nDid, Instant.now().toEpochMilli(),180L);
|
||||
//修改redis的mid
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,1);
|
||||
//接入成功标识
|
||||
redisUtil.saveByKeyWithExpire("online" + nDid,"online",10L);
|
||||
//录波任务倒计时
|
||||
redisUtil.saveByKeyWithExpire("startFile:" + nDid,null,60L);
|
||||
} else {
|
||||
@@ -405,6 +398,7 @@ public class MqttMessageHandler {
|
||||
csLineParam.setPtRatio(item.getPtRatio());
|
||||
csLineParam.setCtRatio(item.getCtRatio());
|
||||
csLineParam.setConType(item.getConType());
|
||||
csLineParam.setLineInterval(item.getStatCycle());
|
||||
csLineFeignClient.updateLine(csLineParam);
|
||||
//生成监测点限值
|
||||
Overlimit overlimit = COverlimitUtil.globalAssemble(item.getVolGrade().floatValue(),10f,10f,10f,0,0);
|
||||
@@ -428,11 +422,19 @@ public class MqttMessageHandler {
|
||||
csLineParam.setPtRatio(item.getPtRatio());
|
||||
csLineParam.setCtRatio(item.getCtRatio());
|
||||
csLineParam.setConType(item.getConType());
|
||||
csLineParam.setLineInterval(item.getStatCycle());
|
||||
csLineFeignClient.updateLine(csLineParam);
|
||||
});
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 15:
|
||||
log.info("{}模块{}:处理实时数据", nDid, rspDataDto.getClDid());
|
||||
JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(res));
|
||||
AppAutoDataMessage appAutoDataMessage = JSONObject.toJavaObject(jsonObject, AppAutoDataMessage.class);
|
||||
appAutoDataMessage.setId(nDid);
|
||||
rtFeignClient.apfRtAnalysis(appAutoDataMessage);
|
||||
break;
|
||||
case 48:
|
||||
log.info("询问装置项目列表");
|
||||
logDto.setUserName("运维管理员");
|
||||
@@ -457,10 +459,16 @@ public class MqttMessageHandler {
|
||||
break;
|
||||
}
|
||||
//csLogsFeignClient.addUserLog(logDto);
|
||||
} else {
|
||||
String result = getEnum(res.getCode());
|
||||
log.info(result);
|
||||
logDto.setResult(0);
|
||||
logDto.setFailReason(result);
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 装置心跳 && 主动数据上送
|
||||
* fixme 这边由于接收文件数据时间跨度会很长,途中有其他请求进来会中断之前的程序,目前是记录中断的位置,等处理完成再继续请求接收文件
|
||||
@@ -738,4 +746,41 @@ public class MqttMessageHandler {
|
||||
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid, new Gson().toJson(reqAndResParam),1,false);
|
||||
}
|
||||
|
||||
public String getEnum(Integer code) {
|
||||
String result = null;
|
||||
switch (code) {
|
||||
case 201:
|
||||
result = AccessEnum.START_CHANNEL.getMessage();
|
||||
break;
|
||||
case 202:
|
||||
result = AccessEnum.WAIT_CHANNEL.getMessage();
|
||||
break;
|
||||
case 400:
|
||||
result = AccessEnum.FAIL.getMessage();
|
||||
break;
|
||||
case 401:
|
||||
result = AccessEnum.ERROR.getMessage();
|
||||
break;
|
||||
case 402:
|
||||
result = AccessEnum.REFUSE_WAIT.getMessage();
|
||||
break;
|
||||
case 403:
|
||||
result = AccessEnum.REFUSE_UNKNOWN.getMessage();
|
||||
break;
|
||||
case 404:
|
||||
result = AccessEnum.NOT_FIND.getMessage();
|
||||
break;
|
||||
case 405:
|
||||
result = AccessEnum.BUSY.getMessage();
|
||||
break;
|
||||
case 406:
|
||||
result = AccessEnum.TIME_OUT.getMessage();
|
||||
break;
|
||||
default:
|
||||
result = AccessEnum.OTHER_ERROR.getMessage();
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.njcn.access.listener;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import com.njcn.access.enums.AccessEnum;
|
||||
import com.njcn.access.pojo.dto.NoticeUserDto;
|
||||
import com.njcn.access.pojo.po.CsDeviceOnlineLogs;
|
||||
@@ -10,11 +11,9 @@ import com.njcn.access.service.impl.CsDeviceServiceImpl;
|
||||
import com.njcn.access.utils.MqttUtil;
|
||||
import com.njcn.access.utils.SendMessageUtil;
|
||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||
import com.njcn.csdevice.api.CsDeviceUserFeignClient;
|
||||
import com.njcn.csdevice.api.CsLedgerFeignClient;
|
||||
import com.njcn.csdevice.api.CsLogsFeignClient;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
import com.njcn.csdevice.api.*;
|
||||
import com.njcn.csdevice.pojo.dto.DevDetailDTO;
|
||||
import com.njcn.csdevice.pojo.dto.PqsCommunicateDto;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
@@ -33,7 +32,6 @@ import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -74,6 +72,11 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private SendMessageUtil sendMessageUtil;
|
||||
@Resource
|
||||
private CsDeviceServiceImpl csDeviceServiceImpl;
|
||||
@Resource
|
||||
private CsCommunicateFeignClient csCommunicateFeignClient;
|
||||
|
||||
private final Object lock = new Object();
|
||||
|
||||
public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
|
||||
@@ -96,60 +99,109 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
String expiredKey = message.toString();
|
||||
if(expiredKey.startsWith("MQTT:")){
|
||||
String nDid = expiredKey.split(":")[1];
|
||||
String version = csTopicService.getVersion(nDid);
|
||||
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
executeMainTask(scheduler,nDid,version);
|
||||
executeMainTask(nDid);
|
||||
}
|
||||
}
|
||||
|
||||
//主任务
|
||||
//1.装置心跳断连
|
||||
//2.MQTT客户端不在线
|
||||
private void executeMainTask(ScheduledExecutorService scheduler, String nDid, String version) {
|
||||
log.info("正在执行主任务...");
|
||||
private void executeMainTask(String nDid) {
|
||||
log.info("{}->装置离线", nDid);
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
//判断mqtt
|
||||
String clientName = "NJCN-" + nDid.substring(nDid.length() - 6);
|
||||
boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
||||
//心跳异常,但是客户端在线,则发送接入请求
|
||||
if (mqttClient) {
|
||||
csDeviceService.devAccessAskTemplate(nDid,version,1);
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,1);
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
Object object = redisUtil.getObjectByKey("online" + nDid);
|
||||
if (Objects.nonNull(object)) {
|
||||
scheduler.shutdown();
|
||||
logDto.setOperate(nDid + "客户端在线重连成功");
|
||||
} else {
|
||||
//装置下线
|
||||
csEquipmentDeliveryService.updateRunStatusBynDid(nDid, AccessEnum.OFFLINE.getCode());
|
||||
startScheduledTask(scheduler,nDid,version);
|
||||
logDto.setOperate(nDid +"客户端离线进入定时任务");
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
}
|
||||
//客户端不在线则修改装置状态,进入定时任务
|
||||
else {
|
||||
//装置下线
|
||||
csEquipmentDeliveryService.updateRunStatusBynDid(nDid, AccessEnum.OFFLINE.getCode());
|
||||
logDto.setOperate(nDid +"主任务执行失败,装置下线,进入定时任务");
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
log.info("客户端离线进入定时任务...");
|
||||
startScheduledTask(scheduler,nDid,version);
|
||||
}
|
||||
//装置下线
|
||||
csEquipmentDeliveryService.updateRunStatusBynDid(nDid, AccessEnum.OFFLINE.getCode());
|
||||
//装置调整为注册状态
|
||||
csEquipmentDeliveryService.updateStatusBynDid(nDid,AccessEnum.REGISTERED.getCode());
|
||||
logDto.setOperate(nDid +"装置离线");
|
||||
sendMessage(nDid);
|
||||
//记录装置掉线时间
|
||||
// CsDeviceOnlineLogs record = onlineLogsService.findLastData(nDid);
|
||||
// record.setOfflineTime(LocalDateTime.now());
|
||||
// onlineLogsService.updateById(record);
|
||||
//记录装置掉线时间
|
||||
PqsCommunicateDto dto = new PqsCommunicateDto();
|
||||
dto.setTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN)));
|
||||
dto.setDevId(nDid);
|
||||
dto.setType(0);
|
||||
dto.setDescription("通讯中断");
|
||||
csCommunicateFeignClient.insertion(dto);
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
}
|
||||
|
||||
//主任务
|
||||
//1.装置心跳断连
|
||||
//2.MQTT客户端不在线
|
||||
// private void executeMainTask(String nDid, String version) {
|
||||
// ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
// log.info("{}->装置离线", nDid);
|
||||
// DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
// logDto.setUserName("运维管理员");
|
||||
// logDto.setLoginName("njcnyw");
|
||||
// //判断mqtt
|
||||
// String clientName = "NJCN-" + nDid.substring(nDid.length() - 6);
|
||||
// boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
||||
// //心跳异常,但是客户端在线,则发送接入请求
|
||||
// if (mqttClient) {
|
||||
// csDeviceService.devAccessAskTemplate(nDid,version,1);
|
||||
// redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,1);
|
||||
// try {
|
||||
// Thread.sleep(5000);
|
||||
// Object object = redisUtil.getObjectByKey("online" + nDid);
|
||||
// if (Objects.nonNull(object)) {
|
||||
// scheduler.shutdown();
|
||||
// logDto.setOperate(nDid + "客户端在线重连成功");
|
||||
// } else {
|
||||
// //装置下线
|
||||
// csEquipmentDeliveryService.updateRunStatusBynDid(nDid, AccessEnum.OFFLINE.getCode());
|
||||
// //装置调整为注册状态
|
||||
// csEquipmentDeliveryService.updateStatusBynDid(nDid,AccessEnum.REGISTERED.getCode());
|
||||
// logDto.setOperate(nDid +"装置离线");
|
||||
// sendMessage(nDid);
|
||||
//
|
||||
// //记录装置掉线时间
|
||||
// CsDeviceOnlineLogs record = onlineLogsService.findLastData(nDid);
|
||||
// record.setOfflineTime(LocalDateTime.now());
|
||||
// onlineLogsService.updateById(record);
|
||||
//
|
||||
// scheduler.shutdown();
|
||||
// }
|
||||
// } catch (InterruptedException e) {
|
||||
// scheduler.shutdown();
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// csLogsFeignClient.addUserLog(logDto);
|
||||
// }
|
||||
// //客户端不在线则修改装置状态,进入定时任务
|
||||
// else {
|
||||
// //装置下线
|
||||
// csEquipmentDeliveryService.updateRunStatusBynDid(nDid, AccessEnum.OFFLINE.getCode());
|
||||
// //装置调整为注册状态
|
||||
// csEquipmentDeliveryService.updateStatusBynDid(nDid,AccessEnum.REGISTERED.getCode());
|
||||
// logDto.setOperate(nDid +"主任务执行失败,装置下线");
|
||||
// csLogsFeignClient.addUserLog(logDto);
|
||||
// sendMessage(nDid);
|
||||
//
|
||||
// //记录装置掉线时间
|
||||
// CsDeviceOnlineLogs record = onlineLogsService.findLastData(nDid);
|
||||
// record.setOfflineTime(LocalDateTime.now());
|
||||
// onlineLogsService.updateById(record);
|
||||
//
|
||||
// scheduler.shutdown();
|
||||
// }
|
||||
// }
|
||||
|
||||
private void startScheduledTask(ScheduledExecutorService scheduler, String nDid, String version) {
|
||||
synchronized (lock) {
|
||||
NoticeUserDto dto = sendOffLine(nDid);
|
||||
sendMessageUtil.sendEventToUser(dto);
|
||||
addLogs(dto);
|
||||
//判断是否推送消息
|
||||
boolean devModel = equipmentFeignClient.judgeDevModel(nDid).getData();
|
||||
if (devModel) {
|
||||
NoticeUserDto dto = sendOffLine(nDid);
|
||||
sendMessageUtil.sendEventToUser(dto);
|
||||
addLogs(dto);
|
||||
}
|
||||
String clientName = "NJCN-" + nDid.substring(nDid.length() - 6);
|
||||
ScheduledFuture<?> future = scheduler.scheduleAtFixedRate(() -> {
|
||||
log.info(nDid + "执行重连定时任务...");
|
||||
@@ -171,7 +223,7 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
logDto.setResult(0);
|
||||
//一个小时未连接上,则推送告警消息
|
||||
MAX_WARNING_TIMES++;
|
||||
if (MAX_WARNING_TIMES == 30) {
|
||||
if (MAX_WARNING_TIMES == 30 && devModel) {
|
||||
NoticeUserDto dto2 = sendConnectFail(nDid);
|
||||
sendMessageUtil.sendEventToUser(dto2);
|
||||
addLogs(dto2);
|
||||
@@ -187,7 +239,7 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
} else {
|
||||
//一个小时未连接上,则推送告警消息
|
||||
MAX_WARNING_TIMES++;
|
||||
if (MAX_WARNING_TIMES == 30) {
|
||||
if (MAX_WARNING_TIMES == 30 && devModel) {
|
||||
NoticeUserDto dto2 = sendConnectFail(nDid);
|
||||
sendMessageUtil.sendEventToUser(dto2);
|
||||
addLogs(dto2);
|
||||
@@ -203,6 +255,16 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
|
||||
}
|
||||
}
|
||||
|
||||
//判断设备型号发送数据
|
||||
private void sendMessage(String nDid) {
|
||||
boolean devModel = equipmentFeignClient.judgeDevModel(nDid).getData();
|
||||
if (devModel) {
|
||||
NoticeUserDto dto = sendOffLine(nDid);
|
||||
sendMessageUtil.sendEventToUser(dto);
|
||||
addLogs(dto);
|
||||
}
|
||||
}
|
||||
|
||||
//掉线通知
|
||||
private NoticeUserDto sendOffLine(String nDid) {
|
||||
NoticeUserDto dto = new NoticeUserDto();
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.njcn.access.mapper;
|
||||
|
||||
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
|
||||
import com.njcn.access.pojo.po.CsLineLatestData;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 治理设备模块运行状态记录表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-07-03
|
||||
*/
|
||||
public interface CsLineLatestDataMapper extends MppBaseMapper<CsLineLatestData> {
|
||||
|
||||
}
|
||||
@@ -1,22 +1,24 @@
|
||||
package com.njcn.access.runner;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.njcn.access.service.ICsEquipmentDeliveryService;
|
||||
import com.njcn.access.service.ICsTopicService;
|
||||
import com.njcn.access.service.impl.CsDeviceServiceImpl;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.system.api.DictTreeFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* 类的介绍:用来重新发起设备的接入,存在程序意外停止了,缓存失效导致无法更新装置的状态,所以需要在程序启动时发起设备的接入
|
||||
@@ -27,16 +29,15 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class AccessApplicationRunner implements ApplicationRunner {
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private ICsEquipmentDeliveryService csEquipmentDeliveryService;
|
||||
@Resource
|
||||
private ICsTopicService csTopicService;
|
||||
@Resource
|
||||
private CsDeviceServiceImpl csDeviceService;
|
||||
private final RedisUtil redisUtil;
|
||||
private final ICsEquipmentDeliveryService csEquipmentDeliveryService;
|
||||
private final ICsTopicService csTopicService;
|
||||
private final CsDeviceServiceImpl csDeviceService;
|
||||
private final DictTreeFeignClient dictTreeFeignClient;
|
||||
|
||||
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
private static final long ACCESS_TIME = 60L;
|
||||
|
||||
@@ -44,17 +45,70 @@ public class AccessApplicationRunner implements ApplicationRunner {
|
||||
public void run(ApplicationArguments args) {
|
||||
//项目启动60s后发起自动接入
|
||||
Runnable task = () -> {
|
||||
List<CsEquipmentDeliveryPO> list = csEquipmentDeliveryService.getAll();
|
||||
list.forEach(item->{
|
||||
String version = csTopicService.getVersion(item.getNdid());
|
||||
if (!Objects.isNull(version)){
|
||||
csDeviceService.devAccessAskTemplate(item.getNdid(),version,1);
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + item.getNdid(),1);
|
||||
log.info("系统重启,所有符合条件的装置发起接入!");
|
||||
List<CsEquipmentDeliveryPO> list = csEquipmentDeliveryService.getOnlineDev();
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
ExecutorService executor = Executors.newFixedThreadPool(10);
|
||||
// 将任务平均分配给10个子列表
|
||||
List<List<CsEquipmentDeliveryPO>> subLists = new ArrayList<>();
|
||||
int partitionSize = list.size() / 10;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
int start = i * partitionSize;
|
||||
int end = (i == 9) ? list.size() : start + partitionSize;
|
||||
subLists.add(list.subList(start, end));
|
||||
}
|
||||
});
|
||||
// 创建一个ExecutorService来处理这些任务
|
||||
List<Future<Void>> futures = new ArrayList<>();
|
||||
// 提交任务给线程池执行
|
||||
for (int i = 0; i < 10; i++) {
|
||||
int index = i;
|
||||
futures.add(executor.submit(new Callable<Void>() {
|
||||
@Override
|
||||
public Void call() {
|
||||
accessDev(subLists.get(index));
|
||||
return null;
|
||||
}
|
||||
}));
|
||||
}
|
||||
// 等待所有任务完成
|
||||
for (Future<Void> future : futures) {
|
||||
try {
|
||||
future.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
// 关闭ExecutorService
|
||||
executor.shutdown();
|
||||
}
|
||||
};
|
||||
scheduler.schedule(task, ACCESS_TIME, TimeUnit.SECONDS);
|
||||
// 关闭调度程序
|
||||
scheduler.schedule(task,ACCESS_TIME,TimeUnit.SECONDS);
|
||||
scheduler.shutdown();
|
||||
}
|
||||
|
||||
public void accessDev(List<CsEquipmentDeliveryPO> list) {
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
try {
|
||||
list.forEach(item->{
|
||||
System.out.println(Thread.currentThread().getName() + ": reboot : nDid : " + item.getNdid());
|
||||
//判断设备类型 便携式设备需要特殊处理 未注册的要先注册、再接入;已注册的直接重新接入
|
||||
String code = dictTreeFeignClient.queryById(item.getDevType()).getData().getCode();
|
||||
if (Objects.equals(code, DicDataEnum.PORTABLE.getCode()) && Objects.equals(item.getStatus(),1)) {
|
||||
//csDeviceService.wlDevRegister(item.getNdid());
|
||||
log.info("请先手动注册、接入");
|
||||
} else {
|
||||
String version = csTopicService.getVersion(item.getNdid());
|
||||
if (Objects.isNull(version)) {
|
||||
version = "V1";
|
||||
}
|
||||
csDeviceService.autoAccess(item.getNdid(),version,1);
|
||||
}
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + item.getNdid(),1);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.njcn.access.runner;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.njcn.access.service.ICsEquipmentDeliveryService;
|
||||
import com.njcn.access.service.ICsTopicService;
|
||||
import com.njcn.access.service.impl.CsDeviceServiceImpl;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.system.api.DictTreeFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
* 定时轮询离线设备接入
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class AutoAccessTimer implements ApplicationRunner {
|
||||
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
private static final long AUTO_TIME = 120L;
|
||||
private final RedisUtil redisUtil;
|
||||
private final ICsEquipmentDeliveryService csEquipmentDeliveryService;
|
||||
private final ICsTopicService csTopicService;
|
||||
private final CsDeviceServiceImpl csDeviceService;
|
||||
private final DictTreeFeignClient dictTreeFeignClient;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
Runnable task = () -> {
|
||||
log.info("轮询定时任务执行中!");
|
||||
List<CsEquipmentDeliveryPO> list = csEquipmentDeliveryService.getOfflineDev();
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
ExecutorService executor = Executors.newFixedThreadPool(10);
|
||||
// 将任务平均分配给10个子列表
|
||||
List<List<CsEquipmentDeliveryPO>> subLists = CollUtil.split(list, 10);
|
||||
// List<List<CsEquipmentDeliveryPO>> subLists = new ArrayList<>();
|
||||
// int partitionSize = list.size() / 10;
|
||||
// for (int i = 0; i < 10; i++) {
|
||||
// int start = i * partitionSize;
|
||||
// int end = (i == 9) ? list.size() : start + partitionSize;
|
||||
// subLists.add(list.subList(start, end));
|
||||
// }
|
||||
// 创建一个ExecutorService来处理这些任务
|
||||
List<Future<Void>> futures = new ArrayList<>();
|
||||
// 提交任务给线程池执行
|
||||
// for (int i = 0; i < 10; i++) {
|
||||
// int index = i;
|
||||
// futures.add(executor.submit(() -> {
|
||||
// accessDev(subLists.get(index));
|
||||
// return null;
|
||||
// }));
|
||||
// }
|
||||
for (List<CsEquipmentDeliveryPO> subList : subLists) {
|
||||
futures.add(executor.submit(() -> {
|
||||
accessDev(subList);
|
||||
return null;
|
||||
}));
|
||||
}
|
||||
// 等待所有任务完成
|
||||
for (Future<Void> future : futures) {
|
||||
try {
|
||||
future.get();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
log.error("任务被中断", e);
|
||||
} catch (ExecutionException e) {
|
||||
log.error("任务执行异常", e.getCause());
|
||||
}
|
||||
}
|
||||
// 关闭ExecutorService
|
||||
executor.shutdown();
|
||||
}
|
||||
};
|
||||
//第一次执行的时间为120s,然后在前一个任务执行完毕后,等待120s再执行下一个任务
|
||||
scheduler.scheduleWithFixedDelay(task, AUTO_TIME, AUTO_TIME, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public void accessDev(List<CsEquipmentDeliveryPO> list) {
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
try {
|
||||
list.forEach(item -> {
|
||||
System.out.println(Thread.currentThread().getName() + ": auto : nDid : " + item.getNdid());
|
||||
//判断设备类型 便携式设备需要特殊处理 未注册的要先注册、再接入;已注册的直接重新接入
|
||||
String code = dictTreeFeignClient.queryById(item.getDevType()).getData().getCode();
|
||||
if (Objects.equals(code, DicDataEnum.PORTABLE.getCode()) && Objects.equals(item.getStatus(), 1)) {
|
||||
//csDeviceService.wlDevRegister(item.getNdid());
|
||||
log.info("请先手动注册、接入");
|
||||
} else {
|
||||
String version = csTopicService.getVersion(item.getNdid());
|
||||
if (Objects.isNull(version)) {
|
||||
version = "V1";
|
||||
}
|
||||
csDeviceService.autoAccess(item.getNdid(), version, 1);
|
||||
}
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + item.getNdid(), 1);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,4 +59,14 @@ public interface ICsEquipmentDeliveryService extends IService<CsEquipmentDeliver
|
||||
* 恢复出厂设置
|
||||
*/
|
||||
void devResetFactory(DeviceStatusParam param);
|
||||
|
||||
/**
|
||||
* 获取启用并且客户端在线的装置
|
||||
*/
|
||||
List<CsEquipmentDeliveryPO> getOnlineDev();
|
||||
|
||||
/**
|
||||
* 获取离线、启用、客户端在线的装置
|
||||
*/
|
||||
List<CsEquipmentDeliveryPO> getOfflineDev();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.njcn.access.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.access.pojo.po.CsLineLatestData;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 治理设备模块运行状态记录表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-07-03
|
||||
*/
|
||||
public interface ICsLineLatestDataService extends IService<CsLineLatestData> {
|
||||
|
||||
void addData(CsLineLatestData csLineLatestData);
|
||||
|
||||
}
|
||||
@@ -84,8 +84,8 @@ public class AskDeviceDataServiceImpl implements AskDeviceDataService {
|
||||
public boolean downloadFile(String nDid, String name, Integer size, String fileCheck) {
|
||||
boolean result = true;
|
||||
try {
|
||||
redisUtil.saveByKeyWithExpire("fileDowning:"+nDid,"fileDowning",120L);
|
||||
redisUtil.saveByKeyWithExpire("fileCheck"+nDid+name,fileCheck,120L);
|
||||
redisUtil.saveByKeyWithExpire("fileDowning:"+nDid,"fileDowning",300L);
|
||||
redisUtil.saveByKey("fileCheck"+nDid+name,fileCheck);
|
||||
Object object = getDeviceMid(nDid);
|
||||
if (!Objects.isNull(object)) {
|
||||
mid = (Integer) object;
|
||||
@@ -100,6 +100,7 @@ public class AskDeviceDataServiceImpl implements AskDeviceDataService {
|
||||
} catch (Exception e) {
|
||||
redisUtil.delete("fileDowning:"+nDid);
|
||||
redisUtil.delete("fileCheck"+nDid+name);
|
||||
redisUtil.delete("fileDownUserId"+nDid+name);
|
||||
throw new BusinessException(AlgorithmResponseEnum.FILE_DOWNLOAD_ERROR);
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -33,6 +33,7 @@ public class CsDataSetServiceImpl extends ServiceImpl<CsDataSetMapper, CsDataSet
|
||||
public List<CsDataSet> getDataSetData(String modelId) {
|
||||
return this.lambdaQuery()
|
||||
.eq(CsDataSet::getPid, modelId)
|
||||
.and(item->item.eq(CsDataSet::getConType,1).or().isNull(CsDataSet::getConType))
|
||||
.and(item->item.eq(CsDataSet::getDataType,"Stat").or().isNull(CsDataSet::getDataType))
|
||||
.list();
|
||||
}
|
||||
|
||||
@@ -91,6 +91,12 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
json = JsonUtil.convertStreamToString(file.getInputStream());
|
||||
Gson gson = new Gson();
|
||||
TemplateDto templateDto = gson.fromJson(json, TemplateDto.class);
|
||||
//判断设备型号
|
||||
String devType = templateDto.getDevType();
|
||||
DictTreeVO dictTreeVO = dictTreeFeignClient.queryByCode(devType).getData();
|
||||
if (Objects.isNull(dictTreeVO)){
|
||||
throw new BusinessException(AccessResponseEnum.DEV_TYPE_NOT_FIND);
|
||||
}
|
||||
logDto.setOperate("新增设备模板,模板名称:" + templateDto.getDevType());
|
||||
//模板文件存入文件服务器
|
||||
String filePath = fileStorageUtil.uploadMultipart(file, OssPath.DEV_MODEL + templateDto.getDevType() + "_");
|
||||
@@ -838,9 +844,6 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
List<DataSetDto> dataSetList = templateDto.getDataSet();
|
||||
String devType = templateDto.getDevType();
|
||||
DictTreeVO dictTreeVO = dictTreeFeignClient.queryByCode(devType).getData();
|
||||
if (Objects.isNull(dictTreeVO)){
|
||||
throw new BusinessException(AccessResponseEnum.DEV_TYPE_NOT_FIND);
|
||||
}
|
||||
String code = dictTreeFeignClient.queryById(dictTreeVO.getPid()).getData().getCode();
|
||||
//逻辑设备录入
|
||||
if (CollectionUtil.isNotEmpty(dataSetList)){
|
||||
@@ -859,6 +862,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
csDataSet.setType(0);
|
||||
csDataSet.setClDev(0);
|
||||
csDataSet.setDataLevel(item1.getDataLevel());
|
||||
csDataSet.setConType(item1.getConType());
|
||||
setList.add(csDataSet);
|
||||
List<DataArrayDto> list = item1.getDataArrayDtoList();
|
||||
if(CollectionUtil.isNotEmpty(list)) {
|
||||
@@ -894,6 +898,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
||||
csDataSet.setDataList(String.join(",",item3.getDataList()));
|
||||
csDataSet.setDataLevel(item4.getDataLevel());
|
||||
csDataSet.setDataType(item4.getDataAttr());
|
||||
csDataSet.setConType(item4.getConType());
|
||||
//fixme 先用数据类型来区分模板的类型
|
||||
if (item3.getDataList().contains("Apf") || item3.getDataList().contains("Dvr")){
|
||||
csDataSet.setType(1);
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.api.*;
|
||||
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
||||
import com.njcn.csdevice.pojo.param.CsDevModelRelationAddParm;
|
||||
import com.njcn.csdevice.pojo.param.CsLedgerParam;
|
||||
import com.njcn.csdevice.pojo.param.CsLineParam;
|
||||
@@ -37,6 +38,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -369,7 +371,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
public String wlDevRegister(String nDid) {
|
||||
String result = "fail";
|
||||
// 设备状态判断
|
||||
@@ -438,20 +440,12 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
csDevModelRelationAddParm.setDid(modelList.get(0).getDid());
|
||||
csDevModelRelationService.addDevModelRelation(csDevModelRelationAddParm);
|
||||
//5.发起自动接入请求
|
||||
Thread.sleep(2000);
|
||||
devAccessAskTemplate(nDid,version,1);
|
||||
//6.修改流程,便携式设备接入成功即为实际环境
|
||||
csEquipmentDeliveryService.updateProcessBynDid(nDid,4);
|
||||
//7.存储日志
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
//8.存储设备调试日志表
|
||||
CsEquipmentProcessPO csEquipmentProcess = new CsEquipmentProcessPO();
|
||||
csEquipmentProcess.setDevId(nDid);
|
||||
csEquipmentProcess.setOperator(RequestUtil.getUserIndex());
|
||||
csEquipmentProcess.setStartTime(LocalDateTime.now());
|
||||
csEquipmentProcess.setEndTime(LocalDateTime.now());
|
||||
csEquipmentProcess.setProcess(4);
|
||||
csEquipmentProcess.setStatus(1);
|
||||
processFeignClient.add(csEquipmentProcess);
|
||||
//9.删除redis监测点模板信息
|
||||
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
||||
redisUtil.delete(AppRedisKey.LINE + nDid);
|
||||
@@ -538,6 +532,17 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean devAccessAskTemplate(String nDid,String version,Integer mid) {
|
||||
String clientName = "NJCN-" + nDid.substring(nDid.length() - 6);
|
||||
boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
||||
if (!mqttClient) {
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
logDto.setResult(1);
|
||||
logDto.setOperate(nDid + "接入失败,装置客户端不在线");
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AlgorithmResponseEnum.DEV_OFFLINE);
|
||||
}
|
||||
boolean result = false;
|
||||
Map<Integer,String> modelMap = new HashMap<>();
|
||||
try {
|
||||
@@ -580,8 +585,86 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
||||
redisUtil.saveByKeyWithExpire("startFile:" + nDid,null,60L);
|
||||
result = true;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (Exception e) {
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
logDto.setResult(1);
|
||||
logDto.setOperate(nDid + "装置接入失败");
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 装置重新接入系统,需要校验所用的模板
|
||||
* @param nDid
|
||||
* @param version
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean autoAccess(String nDid,String version,Integer mid) {
|
||||
String clientName = "NJCN-" + nDid.substring(nDid.length() - 6);
|
||||
boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
||||
if (!mqttClient) {
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
logDto.setResult(1);
|
||||
logDto.setOperate(nDid + "接入失败,装置客户端不在线");
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(AlgorithmResponseEnum.DEV_OFFLINE);
|
||||
}
|
||||
boolean result = false;
|
||||
Map<Integer,String> modelMap = new HashMap<>();
|
||||
try {
|
||||
//删除缓存数据
|
||||
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
||||
redisUtil.deleteKeysByString(AppRedisKey.DEV_MODEL);
|
||||
//询问装置当前所用模板
|
||||
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid,new Gson().toJson(getJson(mid,TypeEnum.TYPE_3.getCode())),1,false);
|
||||
//接收到模板,判断模板是否存在,替换模板,发起接入
|
||||
Thread.sleep(2000);
|
||||
List<CsModelDto> modelId = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.MODEL + nDid),CsModelDto.class);
|
||||
if (CollUtil.isNotEmpty(modelId)) {
|
||||
CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(nDid).getData();
|
||||
//重新录入装置和模板关系信息
|
||||
for (CsModelDto item : modelId) {
|
||||
CsDevModelRelationPO po = new CsDevModelRelationPO();
|
||||
po.setDevId(vo.getId());
|
||||
po.setModelId(item.getModelId());
|
||||
po.setDid(item.getDid());
|
||||
po.setUpdateTime(LocalDateTime.now());
|
||||
csDevModelRelationService.addRelation(po);
|
||||
modelMap.put(item.getType(),item.getModelId());
|
||||
}
|
||||
//修改监测点使用的模板和数据集
|
||||
List<CsLinePO> lineList;
|
||||
Object object = redisUtil.getObjectByKey("accessLineInfo:" + nDid);
|
||||
if (Objects.isNull(object)) {
|
||||
lineList = csLineFeignClient.findByNdid(nDid).getData();
|
||||
for (CsLinePO item : lineList) {
|
||||
if (item.getClDid() == 0) {
|
||||
updateLineIds(modelMap.get(0),item.getClDid(),nDid);
|
||||
} else {
|
||||
updateLineIds(modelMap.get(1),item.getClDid(),nDid);
|
||||
}
|
||||
}
|
||||
}
|
||||
//发起接入
|
||||
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid, new Gson().toJson(getJson(mid,TypeEnum.TYPE_5.getCode())),1,false);
|
||||
//录波任务倒计时
|
||||
redisUtil.saveByKeyWithExpire("startFile:" + nDid,null,60L);
|
||||
result = true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
logDto.setResult(1);
|
||||
logDto.setOperate(nDid + "装置接入失败");
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
throw new BusinessException(e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
package com.njcn.access.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.access.enums.AccessEnum;
|
||||
import com.njcn.access.mapper.CsEquipmentDeliveryMapper;
|
||||
import com.njcn.access.pojo.param.DeviceStatusParam;
|
||||
import com.njcn.access.service.ICsEquipmentDeliveryService;
|
||||
import com.njcn.access.utils.MqttUtil;
|
||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||
import com.njcn.csdevice.api.CsLogsFeignClient;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -27,6 +34,10 @@ import java.util.Objects;
|
||||
@RequiredArgsConstructor
|
||||
public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliveryMapper, CsEquipmentDeliveryPO> implements ICsEquipmentDeliveryService {
|
||||
|
||||
private final MqttUtil mqttUtil;
|
||||
|
||||
private final CsLogsFeignClient csLogsFeignClient;
|
||||
|
||||
@Override
|
||||
public void updateStatusBynDid(String nDid,Integer status) {
|
||||
LambdaUpdateWrapper<CsEquipmentDeliveryPO> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||
@@ -81,4 +92,57 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
||||
this.update(lambdaUpdateWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CsEquipmentDeliveryPO> getOnlineDev() {
|
||||
List<CsEquipmentDeliveryPO> result = new ArrayList<>();
|
||||
List<CsEquipmentDeliveryPO> list = this.lambdaQuery()
|
||||
.ne(CsEquipmentDeliveryPO::getRunStatus,AccessEnum.DEL.getCode())
|
||||
.eq(CsEquipmentDeliveryPO::getUsageStatus,1)
|
||||
.list();
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
list.forEach(item->{
|
||||
String clientName = "NJCN-" + item.getNdid().substring(item.getNdid().length() - 6);
|
||||
boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
||||
if (mqttClient) {
|
||||
result.add(item);
|
||||
} else {
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
logDto.setResult(1);
|
||||
logDto.setOperate(item.getNdid() + "接入失败,装置客户端不在线");
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CsEquipmentDeliveryPO> getOfflineDev() {
|
||||
List<CsEquipmentDeliveryPO> result = new ArrayList<>();
|
||||
List<CsEquipmentDeliveryPO> list = this.lambdaQuery()
|
||||
.eq(CsEquipmentDeliveryPO::getRunStatus,AccessEnum.OFFLINE.getCode())
|
||||
.eq(CsEquipmentDeliveryPO::getUsageStatus,1)
|
||||
.in(CsEquipmentDeliveryPO::getStatus, Arrays.asList(2,3))
|
||||
.list();
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
list.forEach(item->{
|
||||
String clientName = "NJCN-" + item.getNdid().substring(item.getNdid().length() - 6);
|
||||
boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
||||
if (mqttClient) {
|
||||
result.add(item);
|
||||
} else {
|
||||
DeviceLogDTO logDto = new DeviceLogDTO();
|
||||
logDto.setUserName("运维管理员");
|
||||
logDto.setLoginName("njcnyw");
|
||||
logDto.setResult(1);
|
||||
logDto.setOperate(item.getNdid() + "接入失败,装置客户端不在线");
|
||||
csLogsFeignClient.addUserLog(logDto);
|
||||
}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.njcn.access.service.impl;
|
||||
|
||||
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
|
||||
import com.njcn.access.mapper.CsLineLatestDataMapper;
|
||||
import com.njcn.access.pojo.po.CsLineLatestData;
|
||||
import com.njcn.access.service.ICsLineLatestDataService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 治理设备模块运行状态记录表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-07-03
|
||||
*/
|
||||
@Service
|
||||
public class CsLineLatestDataServiceImpl extends MppServiceImpl<CsLineLatestDataMapper, CsLineLatestData> implements ICsLineLatestDataService {
|
||||
|
||||
@Override
|
||||
public void addData(CsLineLatestData csLineLatestData) {
|
||||
this.saveOrUpdateByMultiId(csLineLatestData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.njcn;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class BatchProcessing {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 创建包含10000条数据的列表
|
||||
List<Integer> dataList = new ArrayList<>();
|
||||
for (int i = 1; i <= 20000; i++) {
|
||||
dataList.add(i);
|
||||
}
|
||||
|
||||
// 将数据分成10个子列表,每个子列表包含1000条数据
|
||||
List<List<Integer>> batches = new ArrayList<>();
|
||||
int batchSize = 1000;
|
||||
int batchCount = dataList.size() / batchSize;
|
||||
for (int i = 0; i < batchCount; i++) {
|
||||
int fromIndex = i * batchSize;
|
||||
int toIndex = fromIndex + batchSize;
|
||||
List<Integer> batch = dataList.subList(fromIndex, toIndex);
|
||||
batches.add(batch);
|
||||
}
|
||||
|
||||
// 使用多线程并发处理每个子列表
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(10);
|
||||
for (List<Integer> batch : batches) {
|
||||
executorService.submit(() -> processBatch(batch));
|
||||
}
|
||||
executorService.shutdown();
|
||||
}
|
||||
|
||||
private static void processBatch(List<Integer> batch) {
|
||||
for (Integer data : batch) {
|
||||
// 处理数据的逻辑
|
||||
System.out.println(Thread.currentThread().getName() + ": processing data " + data);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,11 @@ import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.mq.message.AppAutoDataMessage;
|
||||
import com.njcn.rt.api.fallback.RtClientFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
@@ -15,4 +19,7 @@ public interface RtFeignClient {
|
||||
|
||||
@PostMapping("/rtAnalysis")
|
||||
HttpResult<String> analysis(AppAutoDataMessage appAutoDataMessage);
|
||||
|
||||
@PostMapping("/apfRtAnalysis")
|
||||
HttpResult<Map<String,Float>> apfRtAnalysis(@RequestBody @Validated AppAutoDataMessage appAutoDataMessage);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@@ -27,7 +29,13 @@ public class RtClientFallbackFactory implements FallbackFactory<RtFeignClient> {
|
||||
|
||||
@Override
|
||||
public HttpResult<String> analysis(AppAutoDataMessage appAutoDataMessage) {
|
||||
log.error("{}异常,降级处理,异常为:{}","实时数据解析",cause.toString());
|
||||
log.error("{}异常,降级处理,异常为:{}","便携式实时数据解析",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<Map<String,Float>> apfRtAnalysis(AppAutoDataMessage appAutoDataMessage) {
|
||||
log.error("{}异常,降级处理,异常为:{}","APF实时数据解析",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -11,6 +11,9 @@ import java.io.Serializable;
|
||||
@Data
|
||||
public class BaseRealDataSet implements Serializable {
|
||||
|
||||
@ApiModelProperty("用户ID")
|
||||
private String userId;
|
||||
|
||||
@ApiModelProperty("监测点id")
|
||||
private String lineId;
|
||||
|
||||
|
||||
@@ -12,6 +12,9 @@ import java.io.Serializable;
|
||||
@Data
|
||||
public class HarmRealDataSet implements Serializable {
|
||||
|
||||
@ApiModelProperty("用户ID")
|
||||
private String userId;
|
||||
|
||||
@ApiModelProperty("监测点id")
|
||||
private String lineId;
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
@@ -45,5 +47,14 @@ public class RtController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/apfRtAnalysis")
|
||||
@ApiOperation("APF实时数据解析")
|
||||
@ApiImplicitParam(name = "appAutoDataMessage", value = "数据实体", required = true)
|
||||
public HttpResult<String> apfRtAnalysis(@RequestBody @Validated AppAutoDataMessage appAutoDataMessage){
|
||||
String methodDescribe = getMethodDescribe("apfRtAnalysis");
|
||||
rtService.apfRtAnalysis(appAutoDataMessage);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,4 +8,10 @@ import com.njcn.mq.message.AppAutoDataMessage;
|
||||
public interface IRtService {
|
||||
|
||||
void analysis(AppAutoDataMessage appAutoDataMessage);
|
||||
|
||||
/**
|
||||
* APF数据解析
|
||||
* @param appAutoDataMessage
|
||||
*/
|
||||
void apfRtAnalysis(AppAutoDataMessage appAutoDataMessage);
|
||||
}
|
||||
|
||||
@@ -52,6 +52,8 @@ public class RtServiceImpl implements IRtService {
|
||||
List<CsDataArray> dataArrayList;
|
||||
//监测点id
|
||||
String lineId = appAutoDataMessage.getId() + appAutoDataMessage.getMsg().getClDid();
|
||||
//用户Id
|
||||
String userId = redisUtil.getObjectByKey("rtDataUserId:"+lineId).toString();
|
||||
//获取监测点基础信息
|
||||
CsLinePO po = csLineFeignClient.getById(lineId).getData();
|
||||
//获取数据集 dataSet
|
||||
@@ -72,6 +74,7 @@ public class RtServiceImpl implements IRtService {
|
||||
//基础数据
|
||||
if (dataSet.getName().contains("Ds$Pqd$Rt$Basic$")) {
|
||||
BaseRealDataSet baseRealDataSet = assembleData(dataArrayList,item,po.getConType());
|
||||
baseRealDataSet.setUserId(userId);
|
||||
baseRealDataSet.setLineId(lineId);
|
||||
baseRealDataSet.setPt(po.getPtRatio().floatValue());
|
||||
baseRealDataSet.setCt(po.getCtRatio().floatValue());
|
||||
@@ -82,7 +85,8 @@ public class RtServiceImpl implements IRtService {
|
||||
}
|
||||
//fixme 目前实时数据只有基础数据和谐波数据,后期拓展,这边需要再判断
|
||||
else {
|
||||
HarmRealDataSet harmRealDataSet = harmData(dataArrayList,item);
|
||||
HarmRealDataSet harmRealDataSet = harmData(dataArrayList,item,dataSet.getDataLevel(),po.getCtRatio());
|
||||
harmRealDataSet.setUserId(userId);
|
||||
harmRealDataSet.setLineId(lineId);
|
||||
harmRealDataSet.setPt(po.getPtRatio().floatValue());
|
||||
harmRealDataSet.setCt(po.getCtRatio().floatValue());
|
||||
@@ -93,6 +97,36 @@ public class RtServiceImpl implements IRtService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apfRtAnalysis(AppAutoDataMessage appAutoDataMessage) {
|
||||
List<CsDataArray> dataArrayList;
|
||||
String lineId;
|
||||
//监测点id
|
||||
if (appAutoDataMessage.getDid() == 1){
|
||||
lineId = appAutoDataMessage.getId() + "0";
|
||||
} else {
|
||||
lineId = appAutoDataMessage.getId() + appAutoDataMessage.getMsg().getClDid();
|
||||
}
|
||||
//获取监测点基础信息
|
||||
CsLinePO po = csLineFeignClient.getById(lineId).getData();
|
||||
//获取数据集 dataSet
|
||||
Integer idx = appAutoDataMessage.getMsg().getDsNameIdx();
|
||||
CsDataSet dataSet = dataSetFeignClient.getDataSetByIdx(po.getDataModelId(),idx).getData();
|
||||
|
||||
String key = "BaseRealData:" + lineId + idx;
|
||||
Object object = redisUtil.getObjectByKey(key);
|
||||
if (Objects.isNull(object)){
|
||||
dataArrayList = saveBaseRealDataSet(key,dataSet.getId());
|
||||
} else {
|
||||
dataArrayList = channelObjectUtil.objectToList(object,CsDataArray.class);
|
||||
}
|
||||
//根据dataArray解析数据
|
||||
AppAutoDataMessage.DataArray item = appAutoDataMessage.getMsg().getDataArray().get(0);
|
||||
Map<String,Float> map = getData(dataArrayList,item);
|
||||
int data = Math.round(map.get("Apf_ModWorkingSts" + "M"));
|
||||
redisUtil.saveByKeyWithExpire("ApfRtData:" + appAutoDataMessage.getMid(),data,10L);
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间处理
|
||||
*/
|
||||
@@ -224,7 +258,7 @@ public class RtServiceImpl implements IRtService {
|
||||
return baseRealDataSet;
|
||||
}
|
||||
|
||||
public HarmRealDataSet harmData(List<CsDataArray> dataArrayList, AppAutoDataMessage.DataArray dataArray) {
|
||||
public HarmRealDataSet harmData(List<CsDataArray> dataArrayList, AppAutoDataMessage.DataArray dataArray, String dataLevel, Double ct) {
|
||||
HarmRealDataSet harmRealDataSet = new HarmRealDataSet();
|
||||
List<HarmData> harmDataList = new ArrayList<>();
|
||||
//解码
|
||||
@@ -255,7 +289,14 @@ public class RtServiceImpl implements IRtService {
|
||||
//通过反射将数据赋值
|
||||
Class<?> clazz = HarmRealDataSet.class;
|
||||
maxDataList.forEach(item->{
|
||||
if (Objects.equals(item.getHarmName(),"Pq_RmsFundI") || Objects.equals(item.getHarmName(),"Pq_RmsFundU")) {
|
||||
if (Objects.equals(item.getHarmName(),"Pq_RmsFundI")) {
|
||||
if ("Secondary".equals(dataLevel)) {
|
||||
double data = item.getData() * ct;
|
||||
harmRealDataSet.setData1(FloatUtils.get2Float((float)data));
|
||||
} else {
|
||||
harmRealDataSet.setData1(FloatUtils.get2Float(item.getData()));
|
||||
}
|
||||
} else if (Objects.equals(item.getHarmName(),"Pq_RmsFundU")) {
|
||||
harmRealDataSet.setData1(FloatUtils.get2Float(item.getData()));
|
||||
} else {
|
||||
String numberStr = item.getHarmName().substring(item.getHarmName().lastIndexOf('_') + 1);
|
||||
@@ -263,7 +304,16 @@ public class RtServiceImpl implements IRtService {
|
||||
try {
|
||||
Field field = clazz.getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
field.set(harmRealDataSet,FloatUtils.get2Float(item.getData()));
|
||||
if (item.getHarmName().contains("Pq_HarmI_")) {
|
||||
if ("Secondary".equals(dataLevel)) {
|
||||
double data = item.getData() * ct;
|
||||
field.set(harmRealDataSet,FloatUtils.get2Float((float)data));
|
||||
} else {
|
||||
field.set(harmRealDataSet,FloatUtils.get2Float(item.getData()));
|
||||
}
|
||||
} else {
|
||||
field.set(harmRealDataSet,FloatUtils.get2Float(item.getData()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.njcn.stat.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.njcn.access.api.CsLineLatestDataFeignClient;
|
||||
import com.njcn.access.pojo.po.CsLineLatestData;
|
||||
import com.njcn.access.utils.ChannelObjectUtil;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.utils.PubUtils;
|
||||
@@ -30,6 +32,10 @@ import org.influxdb.dto.Point;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -51,10 +57,12 @@ public class StatServiceImpl implements IStatService {
|
||||
private final CsLineFeignClient csLineFeignClient;
|
||||
private final RedisUtil redisUtil;
|
||||
private final ChannelObjectUtil channelObjectUtil;
|
||||
private final CsLineLatestDataFeignClient csLineLatestDataFeignClient;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void analysis(AppAutoDataMessage appAutoDataMessage) {
|
||||
LocalDateTime time = null;
|
||||
log.info("开始消费{},发送时间{}",appAutoDataMessage.getKey(),appAutoDataMessage.getSendTime());
|
||||
//1.根据设备网络识别码获取设备id,查询到所用的模板,用来判断模板的类型(治理模板还是电能质量模板)
|
||||
//2.解析appAutoDataMessage的Did,来判断当前数据是治理数据还是电能质量数据
|
||||
@@ -65,6 +73,7 @@ public class StatServiceImpl implements IStatService {
|
||||
dataArrayParam.setId(appAutoDataMessage.getId());
|
||||
dataArrayParam.setDid(appAutoDataMessage.getDid());
|
||||
dataArrayParam.setCldId(appAutoDataMessage.getMsg().getClDid());
|
||||
dataArrayParam.setIdx(appAutoDataMessage.getMsg().getDsNameIdx());
|
||||
List<AppAutoDataMessage.DataArray> list = appAutoDataMessage.getMsg().getDataArray();
|
||||
//获取监测点id
|
||||
String lineId = null;
|
||||
@@ -113,7 +122,7 @@ public class StatServiceImpl implements IStatService {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
String key = AppRedisKey.DEV_MODEL.concat(dataArrayParam.getId() + dataArrayParam.getDid() + dataArrayParam.getCldId() + dataArrayParam.getStatMethod());
|
||||
String key = AppRedisKey.DEV_MODEL.concat(dataArrayParam.getId() + dataArrayParam.getDid() + dataArrayParam.getCldId() + dataArrayParam.getStatMethod() + dataArrayParam.getIdx());
|
||||
Object object = redisUtil.getObjectByKey(key);
|
||||
List<CsDataArray> dataArrayList;
|
||||
if (Objects.isNull(object)){
|
||||
@@ -123,10 +132,19 @@ public class StatServiceImpl implements IStatService {
|
||||
}
|
||||
List<String> result = assembleData(lineId,dataArrayList,item,appAutoDataMessage.getMsg().getClDid(),dataArrayParam.getStatMethod(),po.getProcess());
|
||||
recordList.addAll(result);
|
||||
//获取时间
|
||||
time = Instant.ofEpochSecond(item.getDataTimeSec()-8*3600)
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.toLocalDateTime();
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(recordList)){
|
||||
//influx数据批量入库
|
||||
influxDbUtils.batchInsert(influxDbUtils.getDbName(), "", InfluxDB.ConsistencyLevel.ALL, TimeUnit.MILLISECONDS, recordList);
|
||||
//记录监测点最新数据时间
|
||||
CsLineLatestData csLineLatestData = new CsLineLatestData();
|
||||
csLineLatestData.setLineId(lineId);
|
||||
csLineLatestData.setTimeId(Objects.isNull(time) ? LocalDateTime.now() : time);
|
||||
csLineLatestDataFeignClient.addData(csLineLatestData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.njcn.mq.message.AppFileMessage;
|
||||
import com.njcn.zlevent.api.fallback.FileClientFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
@@ -19,4 +19,7 @@ public interface FileFeignClient {
|
||||
|
||||
@PostMapping("/fileStream")
|
||||
HttpResult<String> fileStream(AppFileMessage appFileMessage);
|
||||
|
||||
@PostMapping("/downloadMakeUpFile")
|
||||
HttpResult<String> downloadMakeUpFile(@RequestParam("nDid") String nDid);
|
||||
}
|
||||
|
||||
@@ -36,6 +36,12 @@ public class FileClientFallbackFactory implements FallbackFactory<FileFeignClien
|
||||
log.error("{}异常,降级处理,异常为:{}","解析文件流",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<String> downloadMakeUpFile(String nDid) {
|
||||
log.error("{}异常,降级处理,异常为:{}","下载补召文件",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,7 @@ import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
@@ -54,4 +51,14 @@ public class FileController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/downloadMakeUpFile")
|
||||
@ApiOperation("下载补召文件")
|
||||
@ApiImplicitParam(name = "nDid", value = "nDid", required = true)
|
||||
public HttpResult<String> downloadMakeUpFile(@RequestParam("nDid") String nDid){
|
||||
String methodDescribe = getMethodDescribe("downloadMakeUpFile");
|
||||
fileService.downloadMakeUpFile(nDid);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
//package com.njcn.zlevent.init;
|
||||
//
|
||||
//import com.njcn.redis.utils.RedisUtil;
|
||||
//import lombok.AllArgsConstructor;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.boot.CommandLineRunner;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * @author xy
|
||||
// *
|
||||
// * 程序重启设置任务,消费历史录波文件
|
||||
// */
|
||||
//@Slf4j
|
||||
//@Component
|
||||
//@AllArgsConstructor
|
||||
//public class InitEventFiles implements CommandLineRunner {
|
||||
//
|
||||
// private final RedisUtil redisUtil;
|
||||
//
|
||||
// @Override
|
||||
// public void run(String... args) {
|
||||
// redisUtil.saveByKeyWithExpire("startFile",null,120L);
|
||||
// }
|
||||
//}
|
||||
@@ -26,4 +26,8 @@ public interface IFileService {
|
||||
*/
|
||||
void analysisFileStream(AppFileMessage appFileMessage);
|
||||
|
||||
/**
|
||||
* 下载补召文件
|
||||
*/
|
||||
void downloadMakeUpFile(String nDid);
|
||||
}
|
||||
|
||||
@@ -2,14 +2,23 @@ package com.njcn.zlevent.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.access.pojo.po.CsDeviceOnlineLogs;
|
||||
import com.njcn.access.utils.ChannelObjectUtil;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.csharmonic.pojo.po.CsEventPO;
|
||||
import com.njcn.mq.message.AppEventMessage;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.system.api.EpdFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.pojo.param.EleEpdPqdParam;
|
||||
import com.njcn.system.pojo.po.EleEpdPqd;
|
||||
import com.njcn.system.pojo.po.SysDicTreePO;
|
||||
import com.njcn.zlevent.mapper.CsEventMapper;
|
||||
import com.njcn.zlevent.pojo.po.CsEventLogs;
|
||||
import com.njcn.zlevent.service.ICsAlarmService;
|
||||
@@ -24,8 +33,11 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.njcn.csdevice.enums.AlgorithmResponseEnum.DATA_ERROR;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 告警事件表 服务实现类
|
||||
@@ -43,28 +55,67 @@ public class CsAlarmServiceImpl extends ServiceImpl<CsEventMapper, CsEventPO> im
|
||||
private final SendEventUtils sendEventUtils;
|
||||
private final ICsEventLogsService csEventLogsService;
|
||||
private final EpdFeignClient epdFeignClient;
|
||||
private final RedisUtil redisUtil;
|
||||
private final ChannelObjectUtil channelObjectUtil;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void analysis(AppEventMessage appEventMessage) {
|
||||
List<CsEventPO> list1 = new ArrayList<>();
|
||||
LocalDateTime eventTime = null;
|
||||
String tag = null;
|
||||
String tag = null, lineId = null;
|
||||
String id = IdUtil.fastSimpleUUID();
|
||||
//获取装置id
|
||||
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(appEventMessage.getId()).getData();
|
||||
List<SysDicTreePO> dictTreeList = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.DICT_TREE),SysDicTreePO.class);
|
||||
String code = dictTreeList.stream().filter(item->Objects.equals(item.getId(),po.getDevType())).findFirst().orElse(null).getCode();
|
||||
|
||||
try {
|
||||
//便携式设备
|
||||
if (Objects.equals(DicDataEnum.PORTABLE.getCode(),code)) {
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get(appEventMessage.getMsg().getClDid().toString()).toString();
|
||||
}
|
||||
//直连设备
|
||||
else if (Objects.equals(DicDataEnum.CONNECT_DEV.getCode(),code)) {
|
||||
if (Objects.equals(appEventMessage.getDid(),1)){
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get("0").toString();
|
||||
} else if (Objects.equals(appEventMessage.getDid(),2)){
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get(appEventMessage.getMsg().getClDid().toString()).toString();
|
||||
}
|
||||
}
|
||||
|
||||
List<AppEventMessage.DataArray> dataArray = appEventMessage.getMsg().getDataArray();
|
||||
for (AppEventMessage.DataArray item : dataArray) {
|
||||
eventTime = eventService.timeFormat(item.getDataTimeSec(),item.getDataTimeUSec());
|
||||
tag = item.getName();
|
||||
//判断各模块事件,如果上次模块事件和这次一致,则不记录
|
||||
CsEventPO csEventPO = this.lambdaQuery().eq(CsEventPO::getLineId,lineId)
|
||||
.eq(CsEventPO::getClDid,appEventMessage.getMsg().getClDid())
|
||||
.eq(CsEventPO::getProcess,po.getProcess())
|
||||
.orderByDesc(CsEventPO::getStartTime).last("LIMIT 1").one();
|
||||
if (csEventPO != null) {
|
||||
if (Objects.equals(csEventPO.getTag(),tag)) {
|
||||
throw new BusinessException(DATA_ERROR);
|
||||
}
|
||||
}
|
||||
//判断是否有重复数据
|
||||
CsEventPO po2 = this.lambdaQuery().eq(CsEventPO::getLineId,lineId)
|
||||
.eq(CsEventPO::getStartTime,eventTime)
|
||||
.eq(CsEventPO::getClDid,appEventMessage.getMsg().getClDid())
|
||||
.eq(CsEventPO::getProcess,po.getProcess())
|
||||
.eq(CsEventPO::getTag,tag).one();
|
||||
if (po2 != null) {
|
||||
throw new BusinessException(DATA_ERROR);
|
||||
}
|
||||
|
||||
//事件入库
|
||||
CsEventPO csEvent = new CsEventPO();
|
||||
csEvent.setLineId(lineId);
|
||||
csEvent.setId(id);
|
||||
csEvent.setDeviceId(po.getId());
|
||||
csEvent.setProcess(po.getProcess());
|
||||
csEvent.setCode(item.getCode());
|
||||
csEvent.setStartTime(eventTime);
|
||||
tag = item.getName();
|
||||
csEvent.setTag(tag);
|
||||
csEvent.setType(3);
|
||||
csEvent.setClDid(appEventMessage.getMsg().getClDid());
|
||||
@@ -91,6 +142,7 @@ public class CsAlarmServiceImpl extends ServiceImpl<CsEventMapper, CsEventPO> im
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CsEventLogs csEventLogs = new CsEventLogs();
|
||||
csEventLogs.setLineId(lineId);
|
||||
csEventLogs.setDeviceId(po.getId());
|
||||
csEventLogs.setStartTime(eventTime);
|
||||
csEventLogs.setTag(tag);
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
package com.njcn.zlevent.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.api.CsTopicFeignClient;
|
||||
import com.njcn.access.enums.AccessEnum;
|
||||
import com.njcn.access.enums.TypeEnum;
|
||||
import com.njcn.access.pojo.dto.ReqAndResDto;
|
||||
import com.njcn.access.utils.ChannelObjectUtil;
|
||||
import com.njcn.access.utils.FileCommonUtils;
|
||||
import com.njcn.access.utils.MqttUtil;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.api.CsLineFeignClient;
|
||||
@@ -26,7 +23,6 @@ import com.njcn.zlevent.pojo.dto.WaveTimeDto;
|
||||
import com.njcn.zlevent.service.ICsWaveAnalysisService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -54,6 +50,7 @@ public class CsWaveAnalysisServiceImpl implements ICsWaveAnalysisService {
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
private final ChannelObjectUtil channelObjectUtil;
|
||||
private final MqttUtil mqttUtil;
|
||||
private final FileCommonUtils fileCommonUtils;
|
||||
private static Integer mid = 1;
|
||||
|
||||
@Override
|
||||
@@ -102,7 +99,6 @@ public class CsWaveAnalysisServiceImpl implements ICsWaveAnalysisService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async("asyncExecutor")
|
||||
public void channelWave(String nDid) {
|
||||
//判断客户端是否在线,在线再处理文件
|
||||
String clientName = "NJCN-" + nDid.substring(nDid.length() - 6);
|
||||
@@ -119,7 +115,7 @@ public class CsWaveAnalysisServiceImpl implements ICsWaveAnalysisService {
|
||||
}
|
||||
WaveTimeDto dto = list.get(0);
|
||||
redisUtil.saveByKeyWithExpire("fileMid:" + nDid,mid + "concat" +dto.getFileName(),60L);
|
||||
askFileInfo(nDid,mid,dto.getFileName());
|
||||
fileCommonUtils.askFileInfo(nDid,mid,dto.getFileName());
|
||||
mid = mid + 1;
|
||||
if (mid > 10000) {
|
||||
mid = 1;
|
||||
@@ -134,25 +130,6 @@ public class CsWaveAnalysisServiceImpl implements ICsWaveAnalysisService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 询问文件信息
|
||||
*/
|
||||
public void askFileInfo(String nDid, Integer mid, String fileName) {
|
||||
String version = csTopicFeignClient.find(nDid).getData();
|
||||
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
|
||||
reqAndResParam.setMid(mid);
|
||||
reqAndResParam.setDid(0);
|
||||
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_8.getCode()));
|
||||
reqAndResParam.setExpire(-1);
|
||||
String json = "{Name:\""+fileName+"\"}";
|
||||
JSONObject jsonObject = JSONObject.fromObject(json);
|
||||
reqAndResParam.setMsg(jsonObject);
|
||||
log.info("请求文件信息报文:" + new Gson().toJson(reqAndResParam));
|
||||
publisher.send("/Pfm/DevFileCmd/"+version+"/"+nDid,new Gson().toJson(reqAndResParam),1,false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 时间处理
|
||||
*/
|
||||
|
||||
@@ -35,6 +35,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.influxdb.InfluxDB;
|
||||
import org.influxdb.dto.BatchPoints;
|
||||
import org.influxdb.dto.Point;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -88,7 +89,22 @@ public class EventServiceImpl implements IEventService {
|
||||
}
|
||||
//获取装置id
|
||||
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(appEventMessage.getId()).getData();
|
||||
//获取设备类型 true:治理设备 false:其他类型的设备
|
||||
boolean devModel = equipmentFeignClient.judgeDevModel(appEventMessage.getId()).getData();
|
||||
try {
|
||||
// lineId = appEventMessage.getId() + appEventMessage.getMsg().getClDid();
|
||||
if (devModel) {
|
||||
if (Objects.equals(appEventMessage.getDid(),1)){
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get("0").toString();
|
||||
} else if (Objects.equals(appEventMessage.getDid(),2)){
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get(appEventMessage.getMsg().getClDid().toString()).toString();
|
||||
}
|
||||
} else {
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get(appEventMessage.getMsg().getClDid().toString()).toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//处理事件数据
|
||||
List<AppEventMessage.DataArray> dataArray = appEventMessage.getMsg().getDataArray();
|
||||
for (AppEventMessage.DataArray item : dataArray) {
|
||||
@@ -110,49 +126,41 @@ public class EventServiceImpl implements IEventService {
|
||||
csEvent.setType(1);
|
||||
} else if (Objects.equals(item.getType(),"1")){
|
||||
csEvent.setType(2);
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get("0").toString();
|
||||
csEvent.setClDid(appEventMessage.getMsg().getClDid());
|
||||
}
|
||||
csEvent.setLevel(Integer.parseInt(item.getType()));
|
||||
csEvent.setClDid(appEventMessage.getMsg().getClDid());
|
||||
csEvent.setLineId(lineId);
|
||||
//参数入库
|
||||
Map<String,String> map = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.ELE_EPD_PQD)), Map.class);
|
||||
if (!Objects.isNull(item.getParam())){
|
||||
//判断是否有参数
|
||||
List<AppEventMessage.Param> params = item.getParam();
|
||||
if (CollectionUtil.isNotEmpty(params)) {
|
||||
String tableName = map.get(item.getName());
|
||||
List<AppEventMessage.Param> params = item.getParam();
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
tags.put(InfluxDBTableConstant.UUID,id);
|
||||
Map<String,Object> fields = new HashMap<>();
|
||||
for (AppEventMessage.Param param : params) {
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
tags.put(InfluxDBTableConstant.UUID,id);
|
||||
Map<String,Object> fields = new HashMap<>();
|
||||
//只有治理型号的设备有监测位置
|
||||
if (Objects.equals(ZlConstant.EVENT_POSITION,param.getName())){
|
||||
if (Objects.equals(param.getData(),ZlConstant.GRID)){
|
||||
fields.put(param.getName(),"电网侧");
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get("1").toString();
|
||||
csEvent.setClDid(1);
|
||||
} else if (Objects.equals(param.getData(),ZlConstant.LOAD)){
|
||||
fields.put(param.getName(),"负载侧");
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get("2").toString();
|
||||
csEvent.setClDid(2);
|
||||
}
|
||||
csEvent.setLocation(param.getData().toString());
|
||||
} else {
|
||||
if (Objects.equals(param.getName(),ZlConstant.EVT_PARAM_TM)){
|
||||
csEvent.setPersistTime(Double.parseDouble(param.getData().toString()));
|
||||
}
|
||||
lineId = appEventMessage.getId() + appEventMessage.getMsg().getClDid();
|
||||
fields.put(param.getName(),null);
|
||||
csEvent.setLocation(null);
|
||||
csEvent.setClDid(appEventMessage.getMsg().getClDid());
|
||||
fields.put(param.getName(),param.getData());
|
||||
if (Objects.equals(param.getName(),ZlConstant.EVT_PARAM_TM)){
|
||||
csEvent.setPersistTime(Double.parseDouble(param.getData().toString()));
|
||||
}
|
||||
//fixme 这边前置传递的应该是UTC时间,但是前置说是传递的北京时间,讨论了一下没太理解。这边暂时先这样处理,influx入库处理成北京时间,减去8小时。
|
||||
Point point = influxDbUtils.pointBuilder(tableName, item.getDataTimeSec()-8*3600, TimeUnit.SECONDS, tags, fields);
|
||||
BatchPoints batchPoints = BatchPoints.database(influxDbUtils.getDbName()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
|
||||
batchPoints.point(point);
|
||||
records.add(batchPoints.lineProtocol());
|
||||
fields.put(param.getName(),param.getData());
|
||||
}
|
||||
//只有治理型号的设备有监测位置
|
||||
if (devModel) {
|
||||
if (appEventMessage.getMsg().getClDid() == 1) {
|
||||
fields.put("Evt_Param_Position","电网侧");
|
||||
csEvent.setLocation("grid");
|
||||
} else if (appEventMessage.getMsg().getClDid() == 2) {
|
||||
fields.put("Evt_Param_Position","负载侧");
|
||||
csEvent.setLocation("load");
|
||||
}
|
||||
}
|
||||
//fixme 这边前置传递的应该是UTC时间,但是前置说是传递的北京时间,讨论了一下没太理解。这边暂时先这样处理,influx入库处理成北京时间,减去8小时。
|
||||
Point point = influxDbUtils.pointBuilder(tableName, item.getDataTimeSec()-8*3600, TimeUnit.SECONDS, tags, fields);
|
||||
BatchPoints batchPoints = BatchPoints.database(influxDbUtils.getDbName()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
|
||||
batchPoints.point(point);
|
||||
records.add(batchPoints.lineProtocol());
|
||||
}
|
||||
csEvent.setLineId(lineId);
|
||||
list1.add(csEvent);
|
||||
//事件处理日志库
|
||||
CsEventLogs csEventLogs = new CsEventLogs();
|
||||
@@ -205,7 +213,7 @@ public class EventServiceImpl implements IEventService {
|
||||
if (!Objects.isNull(record)) {
|
||||
if (!Objects.equals(item.getPrjTimeEnd(),-1L)) {
|
||||
WlRecordParam.UpdateRecord wlRecord = new WlRecordParam.UpdateRecord();
|
||||
wlRecord.setId(record.getId());
|
||||
BeanUtils.copyProperties(record,wlRecord);
|
||||
wlRecord.setProEndTime(timestampToDatetime((item.getPrjTimeEnd() - 8*3600)));
|
||||
wlRecordFeignClient.updateTestRecord(wlRecord);
|
||||
}
|
||||
@@ -213,7 +221,7 @@ public class EventServiceImpl implements IEventService {
|
||||
//新项目入库
|
||||
WlRecord wlRecord = new WlRecord();
|
||||
wlRecord.setId(IdUtil.simpleUUID());
|
||||
wlRecord.setItemName("基础数据");
|
||||
wlRecord.setItemName("在线监测");
|
||||
wlRecord.setGcName(item.getPrjName());
|
||||
wlRecord.setDevId(vo.getId());
|
||||
wlRecord.setLineId(appEventMessage.getId() + item.getClDid().toString());
|
||||
@@ -232,6 +240,9 @@ public class EventServiceImpl implements IEventService {
|
||||
//fixme 电流接线方式 这边系统没有字典,录入字典通用性不强,采用装置上送值存储
|
||||
wlRecord.setCurConSel(item.getCurConSel().toString());
|
||||
wlRecord.setStartTime(timestampToDatetime((item.getPrjTimeStart() - 8*3600)));
|
||||
if (!Objects.equals(item.getPrjTimeEnd(),-1L)) {
|
||||
wlRecord.setEndTime(timestampToDatetime((item.getPrjTimeEnd() - 8*3600)));
|
||||
}
|
||||
wlRecord.setType(1);
|
||||
wlRecord.setState(1);
|
||||
wlRecord.setGcDataPath(item.getPrjDataPath());
|
||||
|
||||
@@ -11,18 +11,27 @@ import com.njcn.access.enums.AccessEnum;
|
||||
import com.njcn.access.enums.AccessResponseEnum;
|
||||
import com.njcn.access.enums.TypeEnum;
|
||||
import com.njcn.access.pojo.dto.ReqAndResDto;
|
||||
import com.njcn.access.pojo.dto.file.FileDto;
|
||||
import com.njcn.access.utils.CRC32Utils;
|
||||
import com.njcn.access.utils.ChannelObjectUtil;
|
||||
import com.njcn.access.utils.FileCommonUtils;
|
||||
import com.njcn.access.utils.MqttUtil;
|
||||
import com.njcn.common.config.GeneralInfo;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.api.DeviceFtpFeignClient;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
import com.njcn.csdevice.api.PortableOffLogFeignClient;
|
||||
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
||||
import com.njcn.csharmonic.api.WavePicFeignClient;
|
||||
import com.njcn.csharmonic.enums.CsHarmonicResponseEnum;
|
||||
import com.njcn.csharmonic.pojo.dto.DownloadMakeUpDto;
|
||||
import com.njcn.mq.message.AppFileMessage;
|
||||
import com.njcn.oss.constant.GeneralConstant;
|
||||
import com.njcn.oss.constant.OssPath;
|
||||
import com.njcn.oss.utils.FileStorageUtil;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.user.api.UserFeignClient;
|
||||
import com.njcn.zlevent.param.CsEventParam;
|
||||
import com.njcn.zlevent.pojo.dto.FileInfoDto;
|
||||
import com.njcn.zlevent.pojo.dto.FileStreamDto;
|
||||
@@ -40,6 +49,7 @@ import net.sf.json.JSONObject;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
@@ -69,6 +79,10 @@ public class FileServiceImpl implements IFileService {
|
||||
private final RemoveInfoUtils removeInfoUtils;
|
||||
private static Integer mid = 1;
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
private final MqttUtil mqttUtil;
|
||||
private final FileCommonUtils fileCommonUtils;
|
||||
private final DeviceFtpFeignClient deviceFtpFeignClient;
|
||||
private final PortableOffLogFeignClient portableOffLogFeignClient;
|
||||
|
||||
@Override
|
||||
public void analysisFileInfo(AppFileMessage appFileMessage) {
|
||||
@@ -163,8 +177,6 @@ public class FileServiceImpl implements IFileService {
|
||||
csEventLogs.setNowStep(1);
|
||||
csEventLogs.setAllStep(1);
|
||||
csEventLogs.setIsAll(1);
|
||||
redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(appFileMessage.getMsg().getName()));
|
||||
redisUtil.delete(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileName));
|
||||
//存储文件信息
|
||||
fileStreamDto.setTotal(appFileMessage.getMsg().getFrameTotal());
|
||||
fileStreamDto.setNDid(appFileMessage.getId());
|
||||
@@ -172,6 +184,16 @@ public class FileServiceImpl implements IFileService {
|
||||
list.add(appFileMessage.getMsg().getFrameCurr());
|
||||
fileStreamDto.setList(list);
|
||||
redisUtil.saveByKey(AppRedisKey.FILE_PART.concat(appFileMessage.getMsg().getName()), fileStreamDto);
|
||||
log.info("当前文件1帧,全部收到,解析成功!");
|
||||
//针对补召文件
|
||||
String key = AppRedisKey.MAKE_UP_FILES + appFileMessage.getId();
|
||||
Object object = redisUtil.getObjectByKey(key);
|
||||
//清空redis缓存
|
||||
fileCommonUtils.cleanRedisData(appFileMessage.getId(),fileName);
|
||||
if (Objects.nonNull(object)) {
|
||||
DownloadMakeUpDto dto = channelObjectUtil.objectToSingleObject(object, DownloadMakeUpDto.class);
|
||||
channelMakeUpFile(dto,appFileMessage.getId(),fileName,filePath,lsFileName);
|
||||
}
|
||||
} else {
|
||||
//收到数据就刷新缓存值
|
||||
redisUtil.saveByKeyWithExpire(AppRedisKey.FILE_DOWN_TIME.concat(appFileMessage.getMsg().getName()), null, 60L);
|
||||
@@ -212,9 +234,15 @@ public class FileServiceImpl implements IFileService {
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(appFileMessage.getMsg().getName()));
|
||||
redisUtil.delete(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileName));
|
||||
redisUtil.delete(AppRedisKey.FILE_DOWN_TIME.concat(appFileMessage.getMsg().getName()));
|
||||
//针对补召文件
|
||||
String key = AppRedisKey.MAKE_UP_FILES + appFileMessage.getId();
|
||||
Object object = redisUtil.getObjectByKey(key);
|
||||
//清空redis缓存
|
||||
fileCommonUtils.cleanRedisData(appFileMessage.getId(),fileName);
|
||||
if (Objects.nonNull(object)) {
|
||||
DownloadMakeUpDto dto2 = channelObjectUtil.objectToSingleObject(object, DownloadMakeUpDto.class);
|
||||
channelMakeUpFile(dto2,appFileMessage.getId(),fileName,filePath,lsFileName);
|
||||
}
|
||||
} else {
|
||||
csEventLogs.setStatus(1);
|
||||
csEventLogs.setRemark("当前文件" + appFileMessage.getMsg().getFrameTotal() + "帧,这是第" + appFileMessage.getMsg().getFrameCurr() + "帧,记录成功!");
|
||||
@@ -235,11 +263,16 @@ public class FileServiceImpl implements IFileService {
|
||||
}
|
||||
}
|
||||
}
|
||||
String userIndex = redisUtil.getObjectByKey("fileDownUserId"+appFileMessage.getId()+appFileMessage.getMsg().getName()).toString();
|
||||
//推送mqtt
|
||||
String json = "{fileName:"+appFileMessage.getMsg().getName()+",allStep:"+appFileMessage.getMsg().getFrameTotal()+",nowStep:"+ appFileMessage.getMsg().getFrameCurr() +"}";
|
||||
String json = "{fileName:" + appFileMessage.getMsg().getName()
|
||||
+ ",allStep:" + appFileMessage.getMsg().getFrameTotal()
|
||||
+ ",nowStep:" + appFileMessage.getMsg().getFrameCurr()
|
||||
+ ",userId:" + userIndex
|
||||
+"}";
|
||||
publisher.send("/Web/Progress/" + appFileMessage.getId(), new Gson().toJson(json), 1, false);
|
||||
if (!Objects.isNull(filePath)){
|
||||
redisUtil.saveByKey("downloadFilePath:" + appFileMessage.getId() + appFileMessage.getMsg().getName(),filePath);
|
||||
redisUtil.saveByKeyWithExpire("downloadFilePath:" + appFileMessage.getId() + appFileMessage.getMsg().getName(),filePath,60L);
|
||||
}
|
||||
}
|
||||
//录波文件下载
|
||||
@@ -353,9 +386,6 @@ public class FileServiceImpl implements IFileService {
|
||||
csEventLogs.setCompleteTime(LocalDateTime.now());
|
||||
//记录日志
|
||||
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];
|
||||
@@ -365,6 +395,96 @@ public class FileServiceImpl implements IFileService {
|
||||
}
|
||||
//继续消费
|
||||
removeInfoUtils.deleteEventInfo(appFileMessage.getId(),appFileMessage.getMsg().getName());
|
||||
//清空redis缓存
|
||||
fileCommonUtils.cleanRedisData(appFileMessage.getId(),fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadMakeUpFile(String nDid) {
|
||||
try {
|
||||
//判断客户端是否在线,在线再处理文件
|
||||
String clientName = "NJCN-" + nDid.substring(nDid.length() - 6);
|
||||
boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
|
||||
if (mqttClient){
|
||||
String key = AppRedisKey.MAKE_UP_FILES + nDid;
|
||||
Object object = redisUtil.getObjectByKey(key);
|
||||
if (Objects.nonNull(object)) {
|
||||
DownloadMakeUpDto dto = channelObjectUtil.objectToSingleObject(object, DownloadMakeUpDto.class);
|
||||
if (CollectionUtil.isNotEmpty(dto.getFileList())){
|
||||
Object object1 = channelObjectUtil.getDeviceMid(nDid);
|
||||
if (!Objects.isNull(object1)) {
|
||||
mid = (Integer) object1;
|
||||
}
|
||||
String file = dto.getFileList().get(0);
|
||||
fileCommonUtils.askFileInfo(nDid,mid,file);
|
||||
mid = mid + 1;
|
||||
if (mid > 10000) {
|
||||
mid = 1;
|
||||
}
|
||||
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,mid);
|
||||
Thread.sleep(10000);
|
||||
String infoKey = AppRedisKey.PROJECT_INFO + nDid;
|
||||
FileDto.FileInfo info = channelObjectUtil.objectToSingleObject(redisUtil.getObjectByKey(infoKey), FileDto.FileInfo.class);
|
||||
deviceFtpFeignClient.downloadFile(nDid,file,info.getFileSize(),info.getFileCheck()).getData();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new BusinessException(AlgorithmResponseEnum.DEV_OFFLINE);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
String key = AppRedisKey.MAKE_UP_FILES + nDid;
|
||||
redisUtil.delete(key);
|
||||
Object object = redisUtil.getObjectByKey(AppRedisKey.MAKE_UP_FILES + nDid);
|
||||
if (Objects.nonNull(object)) {
|
||||
DownloadMakeUpDto dto = channelObjectUtil.objectToSingleObject(object, DownloadMakeUpDto.class);
|
||||
if (CollectionUtil.isNotEmpty(dto.getFileList())){
|
||||
String file = dto.getFileList().get(0);
|
||||
fileCommonUtils.cleanRedisData(nDid,file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理补召文件
|
||||
*/
|
||||
public void channelMakeUpFile(DownloadMakeUpDto dto, String nDid, String fileName, String oldPath, String lsFileName){
|
||||
try {
|
||||
//如果是补召文件,则将文件复制到补召目录下
|
||||
moveFile(oldPath,getFilePath(fileName,nDid),lsFileName);
|
||||
//删除临时文件
|
||||
File file = new File(lsFileName);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
//删除下载文件
|
||||
fileStorageUtil.deleteFile(oldPath);
|
||||
List<String> list = dto.getFileList();
|
||||
list.removeIf(item -> item.equals(fileName));
|
||||
dto.setFileList(list);
|
||||
redisUtil.saveByKey(AppRedisKey.MAKE_UP_FILES + nDid,dto);
|
||||
//判断是否还有缓存的文件
|
||||
if (CollectionUtil.isNotEmpty(list)){
|
||||
//推送进度条
|
||||
String json = "{allStep:" + dto.getAllStep() * 2 + ",nowStep:" + (dto.getAllStep() - list.size()) + "}";
|
||||
publisher.send("/dataOnlineRecruitment/Progress/" + dto.getLineId(), new Gson().toJson(json), 1, false);
|
||||
//下载文件
|
||||
downloadMakeUpFile(nDid);
|
||||
} else {
|
||||
//清空缓存文件
|
||||
String key = AppRedisKey.MAKE_UP_FILES + nDid;
|
||||
redisUtil.delete(key);
|
||||
//推送进度条
|
||||
String json = "{allStep:" + dto.getAllStep() * 2 + ",nowStep:" + dto.getAllStep() + "}";
|
||||
publisher.send("/dataOnlineRecruitment/Progress/" + dto.getLineId(), new Gson().toJson(json), 1, false);
|
||||
//调用方法
|
||||
portableOffLogFeignClient.dataOnlineRecruitment(dto.getDevId(),dto.getLineId(),dto.getEngineeringName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
String key = AppRedisKey.MAKE_UP_FILES + nDid;
|
||||
redisUtil.delete(key);
|
||||
fileCommonUtils.cleanRedisData(nDid,fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -570,5 +690,47 @@ public class FileServiceImpl implements IFileService {
|
||||
* -----------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* 迁移文件
|
||||
*/
|
||||
public void moveFile(String oldPath, String newPath, String lsPath) {
|
||||
try {
|
||||
InputStream inputStream = fileStorageUtil.getFileStream(oldPath);
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(lsPath);
|
||||
// 创建一个缓冲区
|
||||
byte[] buffer = new byte[1024];
|
||||
int bytesRead;
|
||||
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
||||
fileOutputStream.write(buffer, 0, bytesRead);
|
||||
}
|
||||
File src = new File(lsPath);
|
||||
src.getParentFile().mkdirs();
|
||||
InputStream is = Files.newInputStream(src.toPath());
|
||||
fileStorageUtil.uploadStreamSpecifyName(is, OssPath.DEV_MAKE_UP_PATH,newPath);
|
||||
inputStream.close();
|
||||
fileOutputStream.close();
|
||||
is.close();
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(CsHarmonicResponseEnum.MAKE_UP_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 调整文件路径
|
||||
*/
|
||||
private String getFilePath(String path, String nDid) {
|
||||
String[] parts = path.split("/");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean first = true;
|
||||
for (int i = 3; i < parts.length; i++) {
|
||||
if (!first) {
|
||||
sb.append("/");
|
||||
}
|
||||
sb.append(parts[i]);
|
||||
first = false;
|
||||
}
|
||||
return nDid + "/" + sb.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -46,8 +46,6 @@ public class AppAutoDataConsumer extends EnhanceConsumerMessageHandler<AppAutoDa
|
||||
private RocketMqLogFeignClient rocketMqLogFeignClient;
|
||||
@Resource
|
||||
private RtFeignClient rtFeignClient;
|
||||
// @Resource
|
||||
// private WlRecordFeignClient wlRecordFeignClient
|
||||
|
||||
@Override
|
||||
protected void handleMessage(AppAutoDataMessage appAutoDataMessage) {
|
||||
@@ -61,7 +59,7 @@ public class AppAutoDataConsumer extends EnhanceConsumerMessageHandler<AppAutoDa
|
||||
rtFeignClient.analysis(appAutoDataMessage);
|
||||
break;
|
||||
case 2:
|
||||
log.info(appAutoDataMessage.getKey() + "分发至统计数据");
|
||||
log.info("{}分发至统计数据", appAutoDataMessage.getKey());
|
||||
statFeignClient.analysis(appAutoDataMessage);
|
||||
break;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user