模拟直连设备在APP注册接入

This commit is contained in:
2023-07-06 11:32:25 +08:00
parent 18aa374215
commit feb30c71dd
111 changed files with 968 additions and 3603 deletions

View File

@@ -21,10 +21,24 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>com.njcn</groupId>
<artifactId>junit</artifactId> <artifactId>common-core</artifactId>
<version>4.11</version> <version>${project.version}</version>
<scope>test</scope> </dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>common-db</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>common-microservice</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>common-poi</artifactId>
<version>${project.version}</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@@ -1,4 +1,4 @@
package com.njcn.access.param; package com.njcn.access.annotation;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;

View File

@@ -14,19 +14,22 @@ public enum AccessResponseEnum {
* A0301 ~ A0399 用于用户模块的枚举 * A0301 ~ A0399 用于用户模块的枚举
* <p> * <p>
*/ */
NDID_NO_FIND("A0301", "与平台nDid匹配错误!"), NDID_NO_FIND("A0301", "nDid在平台端未找到或者已接入"),
MODEL_REPEAT("A0302", "模板重复,请勿重复录入!"), MODEL_REPEAT("A0302", "模板重复,请勿重复录入!"),
MODEL_NO_FIND("A0302", "模板不存在,请先录入模板数据!"), MODEL_NO_FIND("A0302", "模板不存在,请先录入模板数据!"),
MESSAGE_TYPE_ERROR("A0303","报文消息类型Type错误!"), MESSAGE_TYPE_ERROR("A0303","报文消息类型Type错误!"),
DEV_TYPE_ERROR("A0303","装置类型错误!"), DEV_TYPE_ERROR("A0303","装置类型错误!"),
DEV_NOT_FIND("A0303","装置类型未找到!"),
DEV_MODEL_NOT_FIND("A0303","装置型号未找到!"),
DEV_IS_NOT_ZL("A0303","注册装置不是直连装置!"),
RESPONSE_ERROR("A0304","装置请求响应错误!"), REGISTER_RESPONSE_ERROR("A0304","装置注册,装置侧应答失败!"),
DEV_TYPE_NOT_FIND("A0305","装置类型未找到,需要录入!"), DEV_TYPE_NOT_FIND("A0305","装置类型未找到,需要录入!"),
NO_RECEIVE_FROM_DEV("A0306","未收到装置注册响应,请核查!"), REGISTER_ERROR("A0306","装置注册失败!"),
DICT_MISSING("A0307","字典数据缺失!"), DICT_MISSING("A0307","字典数据缺失!"),
EPD_DICT_MISSING("A0307","Epd字典数据缺失!"), EPD_DICT_MISSING("A0307","Epd字典数据缺失!"),
@@ -42,6 +45,9 @@ public enum AccessResponseEnum {
INSET_DICT_MISSING("A0307","InSet字典数据缺失!"), INSET_DICT_MISSING("A0307","InSet字典数据缺失!"),
CTRL_DICT_MISSING("A0307","Ctrl字典数据缺失!"), CTRL_DICT_MISSING("A0307","Ctrl字典数据缺失!"),
MODEL_MISS("A0308","模板信息缺失!"),
MODEL_VERSION_ERROR("A0308","询问装置模板信息错误"),
; ;
private final String code; private final String code;

View File

@@ -0,0 +1,71 @@
package com.njcn.access.param;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/7/5 16:25
*/
@Data
public class DevAccessParam implements Serializable {
@ApiModelProperty("项目id")
@NotNull(message = "项目id不能为空")
private String projectId;
@ApiModelProperty("区域")
private String area;
@ApiModelProperty("拓扑图id")
@NotNull(message = "拓扑图id不能为空")
private String topologyDiagram;
@ApiModelProperty("设备识别码")
@NotNull(message = "设备识别码不能为空")
private String nDid;
@ApiModelProperty("监测点集合")
@NotNull(message = "监测点集合不能为空")
private List<LineParam> list;
@Data
public static class LineParam {
@ApiModelProperty("监测点名称")
@NotNull(message = "监测点名称不能为空")
private String name;
@ApiModelProperty("安装位置")
@NotNull(message = "安装位置不能为空")
private String position;
@ApiModelProperty("电压等级")
@NotNull(message = "电压等级不能为空")
private String volGrade;
@ApiModelProperty("PT变比")
@NotNull(message = "PT变比不能为空")
private String ptRatio;
@ApiModelProperty("CT变比")
@NotNull(message = "CT变比不能为空")
private String ctRatio;
@ApiModelProperty("中心点经度")
@NotNull(message = "中心点经度不能为空")
private Double lng;
@ApiModelProperty("中心点纬度")
@NotNull(message = "中心点纬度不能为空")
private Double lat;
}
}

View File

@@ -1,6 +1,6 @@
package com.njcn.access.pojo.dto; package com.njcn.access.pojo.dto;
import com.njcn.access.param.ParamName; import com.njcn.access.annotation.ParamName;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;

View File

@@ -1,8 +1,7 @@
package com.njcn.access.pojo.dto; package com.njcn.access.pojo.dto;
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName; import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
import com.njcn.access.param.ParamName; import com.njcn.access.annotation.ParamName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;

View File

@@ -1,8 +1,11 @@
package com.njcn.access.pojo.dto; package com.njcn.access.pojo.dto;
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName; import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
@@ -12,16 +15,43 @@ import java.util.List;
* *
* @author xuyang * @author xuyang
* @version 1.0.0 * @version 1.0.0
* @createTime 2023/4/10 10:54 * @createTime 2023/7/5 11:26
*/ */
@Data @Data
public class ModelDto implements Serializable { public class ModelDto implements Serializable {
@SerializedName("DevCfg") @SerializedName("Mid")
@NotNull(message = "设备配置序列,不为空") @ApiModelProperty("报文ID,在请求报文中该值为请求ID")
private List<DevCfgDto> devCfg; @NotNull(message = "报文ID不能为空")
private Integer mid;
@SerializedName("DevModInfo") @SerializedName("Did")
@NotNull(message = "设备模板信息序列,不为空") @ApiModelProperty("设备唯一标识lDid,填入0代表nDid")
private List<DevModInfoDto> devMod; @NotBlank(message = "设备唯一标识lDid不能为空")
private String did;
@SerializedName("Pri")
@ApiModelProperty("报文处理的优先级")
@NotNull(message = "报文处理的优先级不能为空")
private Integer pri;
@SerializedName("Type")
@ApiModelProperty("消息类型")
@NotNull(message = "消息类型不能为空")
private String type;
@SerializedName("Msg")
@ApiModelProperty("报文内容")
private Msg msg;
@Data
public static class Msg {
@SerializedName("DevCfg")
@ApiModelProperty("设备配置序列")
private List<DevCfgDto> devCfg;
@SerializedName("DevModInfo")
@ApiModelProperty("设备模板信息序列")
private List<DevModInfoDto> devMod;
}
} }

View File

@@ -1,4 +1,4 @@
package com.njcn.access.pojo.param; package com.njcn.access.pojo.dto;
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName; import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
@@ -8,6 +8,7 @@ import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
/** /**
* 类的介绍 * 类的介绍
@@ -17,7 +18,7 @@ import java.io.Serializable;
* @createTime 2023/4/20 14:05 * @createTime 2023/4/20 14:05
*/ */
@Data @Data
public class ReqAndResParam implements Serializable { public class ReqAndResDto implements Serializable {
@SerializedName("Mid") @SerializedName("Mid")
@ApiModelProperty("报文ID,在请求报文中该值为请求ID") @ApiModelProperty("报文ID,在请求报文中该值为请求ID")
@@ -48,7 +49,7 @@ public class ReqAndResParam implements Serializable {
*/ */
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public static class Req extends ReqAndResParam { public static class Req extends ReqAndResDto {
@SerializedName("Expire") @SerializedName("Expire")
@ApiModelProperty("此报文过期的相对时间,单位秒,该字段为-1时表示永不过期.控制类报文接收者超时处理按此时间") @ApiModelProperty("此报文过期的相对时间,单位秒,该字段为-1时表示永不过期.控制类报文接收者超时处理按此时间")
@NotNull(message = "报文过期的相对时间不能为空") @NotNull(message = "报文过期的相对时间不能为空")
@@ -60,10 +61,11 @@ public class ReqAndResParam implements Serializable {
*/ */
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public static class Res extends ReqAndResParam { public static class Res extends ReqAndResDto {
@SerializedName("Code") @SerializedName("Code")
@ApiModelProperty("标识应答的返回码") @ApiModelProperty("标识应答的返回码")
@NotNull(message = "状态码不能为空") @NotNull(message = "状态码不能为空")
private Integer code; private Integer code;
} }
} }

View File

@@ -38,17 +38,8 @@ public class StsDto implements Serializable {
@NotNull(message = "当前值,不为空") @NotNull(message = "当前值,不为空")
private Integer curSts; private Integer curSts;
@SerializedName("ClassID")
@NotNull(message = "数据分类,不为空")
private String classId;
@SerializedName("TranRule") @SerializedName("TranRule")
@NotNull(message = "上送规则,不为空") @NotNull(message = "上送规则,不为空")
@ApiModelProperty("变化:change 周期:period") @ApiModelProperty("变化:change 周期:period")
private String tranRule; private String tranRule;
//todo 不确定是否还有这个字段先保留
@SerializedName("GroupId")
@NotNull(message = "数据分组组号,不为空")
private List<Object> groupId;
} }

View File

@@ -0,0 +1,45 @@
package com.njcn.access.pojo.dto.devModel;
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/7/3 15:15
*/
@Data
public class ApfDto implements Serializable {
@SerializedName("OpAttr")
@NotNull(message = "读写操作属性,不为空")
private String opAttr;
@SerializedName("Name")
@NotNull(message = "数据名称,不为空")
private String name;
@SerializedName("IDX")
@NotNull(message = "数据编号,不为空")
private Integer idx;
@SerializedName("Type")
@NotNull(message = "数据类型,不为空")
private String type;
@SerializedName("Unit")
@ApiModelProperty("单位")
private String unit;
@SerializedName("StatMethod")
@ApiModelProperty("数据统计方法(max,min,avg,cp95)")
private List<String> statMethod;
}

View File

@@ -1,63 +0,0 @@
package com.njcn.access.pojo.dto.devModel;
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
import lombok.Data;
import java.io.Serializable;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/4/10 16:35
*/
@Data
public class CfgDto implements Serializable {
@SerializedName("DevModName")
private String name;
@SerializedName("DevModVersion")
private String version;
@SerializedName("DevModTime")
private String time;
@SerializedName("ID")
private String id;
@SerializedName("DevType")
private String type;
@SerializedName("DevApp")
private String devApp;
@SerializedName("DevInfo")
private DevInfoDto devInfo;
@SerializedName("Province")
private String province;
@SerializedName("City")
private String city;
@SerializedName("County")
private String county;
@SerializedName("Address")
private String address;
@SerializedName("Position")
private String position;
@SerializedName("LineNum")
private Integer lineNum;
@SerializedName("FileFrameLength")
private Integer fileFrameLength;
@SerializedName("FileFrameTimeout")
private Integer fileFrameTimeout;
}

View File

@@ -28,7 +28,7 @@ public class ClDevDto implements Serializable {
@SerializedName("DataList") @SerializedName("DataList")
@NotEmpty(message = "数据模型列表,不可为空") @NotEmpty(message = "数据模型列表,不可为空")
private List<DevModDataListDto> dataList; private List<String> dataList;
@SerializedName("DataSet") @SerializedName("DataSet")
@NotEmpty(message = "数据集序列,不可为空") @NotEmpty(message = "数据集序列,不可为空")

View File

@@ -1,77 +0,0 @@
package com.njcn.access.pojo.dto.devModel;
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
import com.njcn.access.pojo.dto.data.*;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import java.io.Serializable;
import java.util.List;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/5/16 15:27
*/
@Data
public class DevModDataListDto implements Serializable {
@SerializedName("SoftInfo")
@NotEmpty(message = "软件信息,不可为空")
private SoftInfoDto softInfoDto;
@SerializedName("LdevInfo")
@NotEmpty(message = "设备信息,不可为空")
private List<LDevInfoDto> lDevInfoDto;
@SerializedName("Epd")
@NotEmpty(message = "电能数据,不可为空")
private List<EpdPqdDto> epdDto;
@SerializedName("Pqd")
@NotEmpty(message = "电能质量数据,不可为空")
private List<EpdPqdDto> pqdDto;
@SerializedName("Bmd")
@NotEmpty(message = "基础测量数据,不可为空")
private List<BmdDto> bmdDto;
@SerializedName("Evt")
@NotEmpty(message = "事件,不可为空")
private List<EvtDto> evtDto;
@SerializedName("Alm")
@NotEmpty(message = "告警,不可为空")
private List<AlmDto> almDto;
@SerializedName("Sts")
@NotEmpty(message = "状态,不可为空")
private List<StsDto> stsDto;
@SerializedName("Di")
@NotEmpty(message = "开入,不可为空")
private List<DiDto> diDto;
@SerializedName("Do")
@NotEmpty(message = "开出,不可为空")
private List<DoDto> doDto;
@SerializedName("Parm")
@NotEmpty(message = "参数,不可为空")
private List<ParmDto> parmDto;
@SerializedName("Set")
@NotEmpty(message = "定值,不可为空")
private List<SetDto> setDto;
@SerializedName("InSet")
@NotEmpty(message = "内部定值,不可为空")
private List<InSetDto> inSetDto;
@SerializedName("Ctrl")
@NotEmpty(message = "控制,不可为空")
private List<CtrlDto> ctrlDto;
}

View File

@@ -1,44 +0,0 @@
package com.njcn.access.pojo.dto.devModel;
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import java.io.Serializable;
import java.util.List;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/5/4 10:00
*/
@Data
public class DevModDto implements Serializable {
@SerializedName("Version")
@NotEmpty(message = "直连装置/网关版本号,不可为空")
private String version;
@SerializedName("Time")
@NotEmpty(message = "创建或最后修改时间,不可为空")
private String time;
@SerializedName("DevType")
@NotEmpty(message = "设备型号,不可为空")
private String devType;
@SerializedName("DataList")
@NotEmpty(message = "数据模型列表,不可为空")
private List<DevModDataListDto> dataList;
@SerializedName("DataSet")
@NotEmpty(message = "数据集,不可为空")
private List<DataSetDto> dataSetDtoList;
@SerializedName("Cldev")
@ApiModelProperty(value = "逻辑子设备序列")
private List<ClDevDto> clDevDtoList;
}

View File

@@ -1,27 +0,0 @@
package com.njcn.access.pojo.dto.devModel;
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import java.io.Serializable;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/5/16 15:27
*/
@Data
public class NetDevModDataListDto implements Serializable {
@SerializedName("SoftInfo")
@NotEmpty(message = "软件信息,不可为空")
private SoftInfoDto softInfoDto;
@SerializedName("PrjInfo")
@NotEmpty(message = "工程信息,不可为空")
private PrjInfoDto prjInfoDto;
}

View File

@@ -1,35 +0,0 @@
package com.njcn.access.pojo.dto.devModel;
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import java.io.Serializable;
import java.util.List;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/4/10 16:25
*/
@Data
public class NetDevModDto implements Serializable {
@SerializedName("Version")
@NotEmpty(message = "直连装置/网关版本号,不可为空")
private String version;
@SerializedName("Time")
@NotEmpty(message = "创建或最后修改时间,不可为空")
private String time;
@SerializedName("DevType")
@NotEmpty(message = "设备型号,不可为空")
private String devType;
@SerializedName("DataList")
@NotEmpty(message = "数据模型列表,不可为空")
private List<NetDevModDataListDto> dataList;
}

View File

@@ -1,10 +1,13 @@
package com.njcn.access.pojo.dto.devModel; package com.njcn.access.pojo.dto.devModel;
import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName; import com.alibaba.nacos.shaded.com.google.gson.annotations.SerializedName;
import com.njcn.access.pojo.dto.data.*;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
/** /**
* 类的介绍: * 类的介绍:
@@ -16,12 +19,88 @@ import java.io.Serializable;
@Data @Data
public class TemplateDto implements Serializable { public class TemplateDto implements Serializable {
@SerializedName("NetDevMod") @SerializedName("Version")
@NotEmpty(message = "直连装置/网关信息描述表,不为空") @NotEmpty(message = "版本号,不为空")
private NetDevModDto netDevModDto; private String version;
@SerializedName("DevMod") @SerializedName("Time")
@NotEmpty(message = "逻辑设备数据模板说明,不为空") @NotEmpty(message = "创建或最后修改时间,不为空")
private DevModDto devModDto; private String time;
@SerializedName("DevType")
@NotEmpty(message = "设备型号,不可为空")
private String devType;
@SerializedName("DataList")
@NotEmpty(message = "数据模型列表,不可为空")
private List<String> dataList;
@SerializedName("DataSet")
@NotEmpty(message = "数据集,不可为空")
private List<DataSetDto> dataSet;
@SerializedName("Cldev")
@ApiModelProperty(value = "逻辑子设备序列")
private List<ClDevDto> clDevDtoList;
@SerializedName("SoftInfo")
@NotEmpty(message = "软件信息,不可为空")
private List<SoftInfoDto> softInfoDto;
@SerializedName("LdevInfo")
@NotEmpty(message = "设备信息,不可为空")
private List<LDevInfoDto> lDevInfoDto;
@SerializedName("Apf")
@NotEmpty(message = "谐波治理设备Apf,不可为空")
private List<ApfDto> apfDto;
@SerializedName("Epd")
@ApiModelProperty("电能数据")
private List<EpdPqdDto> epdDto;
@SerializedName("Pqd")
@ApiModelProperty("电能质量数据")
private List<EpdPqdDto> pqdDto;
@SerializedName("Bmd")
@ApiModelProperty("基础测量数据")
private List<BmdDto> bmdDto;
@SerializedName("Evt")
@ApiModelProperty("事件")
private List<EvtDto> evtDto;
@SerializedName("Alm")
@ApiModelProperty("告警")
private List<AlmDto> almDto;
@SerializedName("Sts")
@ApiModelProperty("状态")
private List<StsDto> stsDto;
@SerializedName("Di")
@ApiModelProperty("开入")
private List<DiDto> diDto;
@SerializedName("Do")
@ApiModelProperty("开出")
private List<DoDto> doDto;
@SerializedName("Parm")
@ApiModelProperty("参数")
private List<ParmDto> parmDto;
@SerializedName("Set")
@ApiModelProperty("定值")
private List<SetDto> setDto;
@SerializedName("InSet")
@ApiModelProperty("内部定值")
private List<InSetDto> inSetDto;
@SerializedName("Ctrl")
@ApiModelProperty("控制")
private List<CtrlDto> ctrlDto;
} }

View File

@@ -1,6 +1,6 @@
package com.njcn.access.pojo.dto.heart; package com.njcn.access.pojo.dto.heart;
import com.njcn.access.param.ParamName; import com.njcn.access.annotation.ParamName;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;

View File

@@ -1,4 +1,4 @@
package com.njcn.access.pojo; package com.njcn.access.pojo.param;
import lombok.Data; import lombok.Data;

View File

@@ -1,62 +0,0 @@
package com.njcn.access.pojo.po;
import com.baomidou.mybatisplus.annotation.TableName;
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
import com.njcn.db.bo.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* <p>
* 设备告警数据表
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("cs_alm")
@Deprecated
public class CsAlmPO extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* id
*/
private String id;
/**
* 读写操作属性“r”
*/
private String opAttr;
/**
* 告警事件名称
*/
@MppMultiId(value = "name")
private String name;
/**
* 告警事件编号
*/
private Integer idx;
/**
* 告警事件类别“1”“2”
*/
private String type;
/**
* 别名
*/
private String anotherName;
/**
* 数据分类,唯一类别
*/
private String classId;
}

View File

@@ -1,46 +0,0 @@
package com.njcn.access.pojo.po;
import com.baomidou.mybatisplus.annotation.TableName;
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
import lombok.Data;
/**
* <p>
*
* </p>
*
* @author xuyang
* @since 2023-05-11
*/
@Data
@TableName("cs_bmd")
@Deprecated
public class CsBmdPO {
private static final long serialVersionUID = 1L;
private String id;
@MppMultiId(value = "name")
private String name;
private String anotherName;
private Integer idx;
private String type;
private String unit;
@MppMultiId(value = "phase")
private String phase;
private String classId;
private String statMethod;
private String tranRule;
private String opAttr;
}

View File

@@ -1,99 +0,0 @@
package com.njcn.access.pojo.po;
import com.baomidou.mybatisplus.annotation.TableName;
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
import com.njcn.db.bo.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.naming.Name;
/**
* <p>
* 控制表
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("cs_ctrl")
@Deprecated
public class CsCtrlPO extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* id
*/
private String id;
/**
* 读写操作属性“r”
*/
private String opAttr;
/**
* 参数名称
*/
@MppMultiId(value = "name")
private String name;
/**
* 别名
*/
private String anotherName;
/**
* 参数编号
*/
private Integer idx;
/**
* 下发数据类型 “string”“float”“enum”
*/
private String type;
/**
* 是否需遥控校验 “1”“0”
*/
private Integer remoteControlCheck;
/**
* 是否支持自动控制 “1”“0”
*/
private Integer auto;
/**
* 设置最大值
*/
private Integer maxNum;
/**
* 设置最小值
*/
private Integer minNum;
/**
* 参数为enum可设置的所有值序列
*/
private String ctlValue;
/**
* 参数string可设置字符串的长度上限
*/
private Integer strlen;
/**
* 是否加密“1”“0”
*/
private Integer encode;
/**
* 数据分类,唯一类别
*/
private String classId;
}

View File

@@ -1,83 +0,0 @@
package com.njcn.access.pojo.po;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
import com.njcn.db.bo.BaseEntity;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
/**
* <p>
* 开入表
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("cs_di")
@Deprecated
public class CsDiPO extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* Id
*/
private String id;
/**
* 读写操作属性“r”
*/
private String opAttr;
/**
* 开入信号名称
*/
@MppMultiId(value = "name")
private String name;
/**
* 开入编号
*/
private Integer idx;
/**
* 是否存储“1”“0”
*/
private Integer storeFlag;
/**
* 当前值“1”“0”
*/
private Integer curSts;
/**
* 数据分类,唯一类别
*/
private String classId;
/**
* 数据是否上送 “1”“0”
*/
private Integer tranFlag;
/**
* 上送规则 变化:“change”周期:“period”
*/
private String tranRule;
/**
* 别名
*/
private String anotherName;
}

View File

@@ -1,93 +0,0 @@
package com.njcn.access.pojo.po;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
import com.njcn.db.bo.BaseEntity;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
/**
* <p>
* 开出表
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("cs_do")
@Deprecated
public class CsDoPO extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* Id
*/
private String id;
/**
* 读写操作属性“r”
*/
private String opAttr;
/**
* 开出信号名称
*/
@MppMultiId(value = "name")
private String name;
/**
* DO编号
*/
private Integer idx;
/**
* 当前值/设定值“1”“0”
*/
private Integer curSts;
/**
* 是否可远程控制 “1”“0”
*/
private Integer ctlSts;
/**
* 创建用户
*/
private String createBy;
/**
* 创建时间
*/
private LocalDateTime createTime;
/**
* 更新用户
*/
private String updateBy;
/**
* 更新时间
*/
private LocalDateTime updateTime;
/**
* 别名
*/
private String anotherName;
/**
* 数据分类,唯一类别
*/
private String classId;
}

View File

@@ -1,61 +0,0 @@
package com.njcn.access.pojo.po;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
import lombok.Data;
/**
* <p>
*
* </p>
*
* @author xuyang
* @since 2023-05-11
*/
@Data
@TableName("cs_epd_pqd")
@Deprecated
public class CsEpdPqdPO {
private static final long serialVersionUID = 1L;
@MppMultiId(value = "name")
private String name;
@MppMultiId(value = "phase")
private String phase;
@TableField(value = "id")
private String id;
@TableField(value = "another_name")
private String anotherName;
@TableField(value = "idx")
private Integer idx;
@TableField(value = "type")
private String type;
@TableField(value = "unit")
private String unit;
@TableField(value = "harm_start")
private Integer harmStart;
@TableField(value = "harm_end")
private Integer harmEnd;
@TableField(value = "class_id")
private String classId;
@TableField(value = "stat_method")
private String statMethod;
@TableField(value = "op_attr")
private String opAttr;
}

View File

@@ -1,85 +0,0 @@
package com.njcn.access.pojo.po;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
import com.njcn.db.bo.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
/**
* <p>
* 事件表
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("cs_evt")
@Deprecated
public class CsEvtPO extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* id
*/
private String id;
/**
* 读写操作属性“r”
*/
private String opAttr;
/**
* 事件信息名称
*/
@MppMultiId(value = "name")
private String name;
/**
* 事件编号
*/
private Integer idx;
/**
* 事件类别“1”“2”
*/
private String type;
/**
* 创建用户
*/
private String createBy;
/**
* 创建时间
*/
private LocalDateTime createTime;
/**
* 更新用户
*/
private String updateBy;
/**
* 更新时间
*/
private LocalDateTime updateTime;
/**
* 别名
*/
private String anotherName;
/**
* 数据分类,唯一类别
*/
private String classId;
}

View File

@@ -0,0 +1,62 @@
package com.njcn.access.pojo.po;
import com.baomidou.mybatisplus.annotation.TableName;
import com.njcn.db.bo.BaseEntity;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
/**
* <p>
* 监测点模板表
* </p>
*
* @author xuyang
* @since 2023-07-05
*/
@Data
@TableName("cs_line_model")
public class CsLineModel {
private static final long serialVersionUID = 1L;
/**
* 监测点id
*/
private String lineId;
/**
* 模板id
*/
private String pid;
/**
* 监测点默认名称
*/
private String name;
/**
* 安装位置
*/
private String position;
/**
* 电压等级
*/
private String volGrade;
/**
* PT变比
*/
private String ptRatio;
/**
* CT变比
*/
private String ctRatio;
}

View File

@@ -1,98 +0,0 @@
package com.njcn.access.pojo.po;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
import com.njcn.db.bo.BaseEntity;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
/**
* <p>
* 参数表
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
@Data
@TableName("cs_parm")
@Deprecated
public class CsParmPO extends BaseEntity {
private static final long serialVersionUID = 1L;
private String id;
/**
* 读写操作属性“r”
*/
private String opAttr;
/**
* 参数名称
*/
@MppMultiId(value = "name")
private String name;
/**
* 别名
*/
private String anotherName;
/**
* 参数编号
*/
private Integer idx;
/**
* 系统参数“sys”运行参数“run” 功能参数:“fun”
*/
private String type;
/**
* 参数数据类型 “string”“float”“enum”
*/
private String dataType;
/**
* 是否可修改 “1”“0”
*/
private Integer modifyFlag;
/**
* 设置最大值
*/
private Integer maxNum;
/**
* 设置最小值
*/
private Integer minNum;
/**
* 参数为enum可设置的所有值序列
*/
private String setValue;
/**
* 参数string可设置字符串的长度上限
*/
private Integer strlen;
/**
* 参数缺省值
*/
private String defaultValue;
/**
* 数据分类,唯一类别
*/
private String classId;
}

View File

@@ -1,103 +0,0 @@
package com.njcn.access.pojo.po;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
import com.njcn.db.bo.BaseEntity;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
/**
* <p>
* 设备定值数据表
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("cs_set")
@Deprecated
public class CsSetPO extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* id
*/
private String id;
/**
* 读写操作属性“r”
*/
private String opAttr;
/**
* 参数名称
*/
@MppMultiId(value = "name")
private String name;
/**
* 别名
*/
private String anotherName;
/**
* 参数编号
*/
private Integer idx;
/**
* 定值数据类型 “hex”“number”
*/
private String dataType;
/**
* 设置最大值
*/
private Integer maxNum;
/**
* 设置最小值
*/
private Integer minNum;
/**
* 定值缺省值
*/
private String defaultValue;
/**
* 数据分类,唯一类别
*/
private String classId;
/**
* 创建用户
*/
private String createBy;
/**
* 创建时间
*/
private LocalDateTime createTime;
/**
* 更新用户
*/
private String updateBy;
/**
* 更新时间
*/
private LocalDateTime updateTime;
}

View File

@@ -1,78 +0,0 @@
package com.njcn.access.pojo.po;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
import com.njcn.db.bo.BaseEntity;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
/**
* <p>
* 状态表
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("cs_sts")
@Deprecated
public class CsStsPO extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* id
*/
private String id;
/**
* 读写操作属性“r”
*/
private String opAttr;
/**
* 状态名称
*/
@MppMultiId(value = "name")
private String name;
/**
* 状态编号
*/
private Integer idx;
/**
* 是否存储“1”“0”
*/
private Integer storeFlag;
/**
* 当前值“1”“0”
*/
private Integer curSts;
/**
* 数据分类,唯一类别
*/
private String classId;
/**
* 上送规则 变化:“change”周期:“period”
*/
private String tranRule;
/**
* 别名
*/
private String anotherName;
}

View File

@@ -23,16 +23,6 @@
<dependency> <dependency>
<groupId>com.njcn</groupId> <groupId>com.njcn</groupId>
<artifactId>access-api</artifactId> <artifactId>access-api</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>algorithm-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>cs-system-api</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
@@ -40,6 +30,34 @@
<artifactId>system-api</artifactId> <artifactId>system-api</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>cs-device-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>common-web</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>common-oss</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.njcn</groupId>
<artifactId>common-swagger</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@@ -1,6 +1,5 @@
package com.njcn.access; package com.njcn.access;
import com.github.jeffreyning.mybatisplus.conf.EnableMPP;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
@@ -17,7 +16,6 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
@MapperScan("com.njcn.**.mapper") @MapperScan("com.njcn.**.mapper")
@EnableFeignClients(basePackages = "com.njcn") @EnableFeignClients(basePackages = "com.njcn")
@SpringBootApplication(scanBasePackages = "com.njcn") @SpringBootApplication(scanBasePackages = "com.njcn")
@EnableMPP
public class AccessBootApplication { public class AccessBootApplication {
public static void main(String[] args) { public static void main(String[] args) {

View File

@@ -1,91 +0,0 @@
package com.njcn.access.config;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.OAuthBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
import java.util.List;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/4/3 9:03
*/
@Configuration
public class SwaggerConfig {
@Value("${microservice.gateway.url}")
private String gatewayUrl;
@Bean
public Docket createRestApi() {
List<GrantType> grantTypes = new ArrayList<>();
String passwordTokenUrl = "http://" + gatewayUrl + "/pqs-auth/oauth/token";
ResourceOwnerPasswordCredentialsGrant resourceOwnerPasswordCredentialsGrant = new ResourceOwnerPasswordCredentialsGrant(passwordTokenUrl);
grantTypes.add(resourceOwnerPasswordCredentialsGrant);
OAuth oAuth = new OAuthBuilder().name("oauth2").grantTypes(grantTypes).build();
//schemas
List<SecurityScheme> securitySchemes = Lists.newArrayList(oAuth);
return new Docket(DocumentationType.SWAGGER_2)
.groupName("物联网注册服务")
.apiInfo(apiInfo())
.enable(true)
.select()
.apis(RequestHandlerSelectors.basePackage("com.njcn.access.controller"))
.paths(PathSelectors.any())
.build()
.securityContexts(securityContexts())
.securitySchemes(securitySchemes);
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("物接入")
.description("物接入接口文档")
.version("1.0")
.contact(contact())
.build();
}
private List<SecurityContext> securityContexts() {
List<SecurityContext> securityContexts = new ArrayList<>();
securityContexts.add(
SecurityContext.builder()
.securityReferences(defaultAuth())
.forPaths(PathSelectors.ant("/**"))
.build());
return securityContexts;
}
List<SecurityReference> defaultAuth() {
//scope方位
List<AuthorizationScope> scopes = new ArrayList<>();
scopes.add(new AuthorizationScope("read", "read resources"));
scopes.add(new AuthorizationScope("write", "write resources"));
scopes.add(new AuthorizationScope("reads", "read all resources"));
scopes.add(new AuthorizationScope("writes", "write all resources"));
SecurityReference securityReference = new SecurityReference("oauth2", scopes.toArray(new AuthorizationScope[]{}));
List<SecurityReference> securityReferences = new ArrayList<>();
securityReferences.add(securityReference);
return securityReferences;
}
private Contact contact() {
return new Contact("灿能系统组", "", "13914774158@163.com");
}
}

View File

@@ -1,33 +0,0 @@
package com.njcn.access.controller;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/5/16 13:58
*/
@Slf4j
@RestController
@RequestMapping("/devAccess")
@RequiredArgsConstructor
@Api(tags = "装置接入")
public class AccessController extends BaseController {
}

View File

@@ -1,20 +1,21 @@
package com.njcn.access.controller; package com.njcn.access.controller;
import com.njcn.access.pojo.param.DevModelParam; import com.njcn.access.pojo.param.DevModelParam;
import com.njcn.access.service.IDevModelService; import com.njcn.access.service.ICsDevModelService;
import com.njcn.common.pojo.annotation.OperateInfo; import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum; import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum; import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil; import com.njcn.common.utils.HttpResultUtil;
import com.njcn.common.utils.LogUtil;
import com.njcn.web.controller.BaseController; import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping; 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.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@@ -23,27 +24,26 @@ import org.springframework.web.bind.annotation.RestController;
* *
* @author xuyang * @author xuyang
* @version 1.0.0 * @version 1.0.0
* @createTime 2023/4/10 10:26 * @createTime 2023/7/3 15:31
*/ */
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/devModel") @RequestMapping("/analyzeModel")
@Api(tags = "模板解析")
@AllArgsConstructor @AllArgsConstructor
@Validated public class CsDevModelController extends BaseController {
@Api(tags = "装置模板录入")
public class DevModelController extends BaseController {
private final IDevModelService devModelService; private final ICsDevModelService csDevModelService;
@PostMapping("/add")
@OperateInfo(info = LogEnum.BUSINESS_COMMON) @OperateInfo(info = LogEnum.BUSINESS_COMMON)
@ApiOperation("装置录入模板") @PostMapping("/addModel")
public HttpResult<String> add(DevModelParam devModelParam){ @ApiOperation("新增设备模板")
log.info("装置录入模板文件"); @ApiImplicitParam(name = "devModelParam", value = "设备模板参数", required = true)
String methodDescribe = getMethodDescribe("add"); public HttpResult<String> addModel(@RequestBody @Validated DevModelParam devModelParam){
LogUtil.njcnDebug(log, "{},装置录入模板文件", methodDescribe); String methodDescribe = getMethodDescribe("addModel");
devModelService.add(devModelParam); csDevModelService.addModel(devModelParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
} }
} }

View File

@@ -0,0 +1,65 @@
package com.njcn.access.controller;
import com.njcn.access.param.DevAccessParam;
import com.njcn.access.service.ICsDeviceService;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/7/4 11:23
*/
@Slf4j
@RestController
@RequestMapping("/device")
@Api(tags = "设备注册接入")
@AllArgsConstructor
@Validated
public class CsDeviceController extends BaseController {
private final ICsDeviceService csDeviceService;
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/register")
@ApiOperation("设备注册")
@ApiImplicitParam(name = "nDid", value = "设备识别码", required = true)
public HttpResult<String> devRegister(@RequestParam String nDid){
csDeviceService.devRegister(nDid);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, "设备MQTT通讯状态!");
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/model")
@ApiOperation("获取装置模板信息")
@ApiImplicitParam(name = "nDid", value = "设备识别码", required = true)
public HttpResult<Object> getModel(@RequestParam String nDid){
String methodDescribe = getMethodDescribe("getModel");
Object object = csDeviceService.getModel(nDid);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, object, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/access")
@ApiOperation("设备接入")
@ApiImplicitParam(name = "devAccessParam", value = "接入参数", required = true)
public HttpResult<String> devAccess(@RequestBody @Validated DevAccessParam devAccessParam){
String methodDescribe = getMethodDescribe("getModel");
csDeviceService.devAccess(devAccessParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
}

View File

@@ -2,7 +2,7 @@ package com.njcn.access.controller;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@@ -11,18 +11,20 @@ import com.njcn.web.controller.BaseController;
/** /**
* <p> * <p>
* 联网设备 前端控制器 * 监测点模板 前端控制器
* </p> * </p>
* *
* @author xuyang * @author xuyang
* @since 2023-05-17 * @since 2023-07-05
*/ */
@RestController
@RequestMapping("/csNetDev")
@RequiredArgsConstructor
@Api(tags = "网关管理")
@Slf4j @Slf4j
public class CsNetDevController extends BaseController { @RestController
@RequestMapping("/csLineModel")
@Api(tags = "监测点模板")
@AllArgsConstructor
public class CsLineModelController extends BaseController {
} }

View File

@@ -1,54 +1,54 @@
package com.njcn.access.controller; //package com.njcn.access.controller;
//
import com.njcn.access.pojo.MessageParam; //import com.njcn.access.pojo.param.MessageParam;
import com.njcn.web.controller.BaseController; //import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api; //import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; //import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; //import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord; //import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener; //import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.KafkaTemplate; //import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component; //import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping; //import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; //import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; //import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; //import org.springframework.web.bind.annotation.RestController;
//
import javax.annotation.Resource; //import javax.annotation.Resource;
import javax.validation.Valid; //import javax.validation.Valid;
//
/** ///**
* 类的介绍: // * 类的介绍:
* // *
* @author xuyang // * @author xuyang
* @version 1.0.0 // * @version 1.0.0
* @createTime 2023/4/18 13:53 // * @createTime 2023/4/18 13:53
*/ // */
@Slf4j //@Slf4j
@RestController //@RestController
@RequestMapping("/test") //@RequestMapping("/test")
@Api(value = "TestController", tags = {"测试 API"}) //@Api(value = "TestController", tags = {"测试 API"})
public class KafkaController extends BaseController { //public class KafkaController extends BaseController {
//
@Resource // @Resource
private KafkaTemplate<String, String> kafkaTemplate; // private KafkaTemplate<String, String> kafkaTemplate;
//
@PostMapping("/kafka/sendMessage") // @PostMapping("/kafka/sendMessage")
@ApiOperation(value = "发送kafka告警消息") // @ApiOperation(value = "发送kafka告警消息")
public void sendKafkaMessage(@Valid @ApiParam("参数") @RequestBody MessageParam param) { // public void sendKafkaMessage(@Valid @ApiParam("参数") @RequestBody MessageParam param) {
kafkaTemplate.send(param.getTopic(), param.getMessage()); // kafkaTemplate.send(param.getTopic(), param.getMessage());
} // }
//
@Component // @Component
public class KafkaConsumer { // public class KafkaConsumer {
// 消费监听 // // 消费监听
@KafkaListener(topics = {"topic2"}) // @KafkaListener(topics = {"topic2"})
public void onMessage1(ConsumerRecord<?, ?> record){ // public void onMessage1(ConsumerRecord<?, ?> record){
// 消费的哪个topic、partition的消息,打印出消息内容 // // 消费的哪个topic、partition的消息,打印出消息内容
System.out.println("简单消费:"+record.topic()+"-"+record.partition()+"-"+record.value()); // System.out.println("简单消费:"+record.topic()+"-"+record.partition()+"-"+record.value());
} // }
} // }
//
//
} //}

View File

@@ -1,51 +0,0 @@
package com.njcn.access.controller;
import com.njcn.access.enums.AccessResponseEnum;
import com.njcn.access.service.IAccessService;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.common.utils.LogUtil;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.Optional;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/3/31 9:12
*/
@Slf4j
@RestController
@RequestMapping("/devRegister")
@RequiredArgsConstructor
@Api(tags = "装置注册")
public class RegisterController extends BaseController {
private final IAccessService accessService;
@PostMapping("/add")
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@ApiOperation("平台发起注册")
@ApiImplicitParam(name = "nDid", value = "网关识别码", required = true)
public HttpResult<Object> add(@RequestParam String nDid){
log.info("设备向装置侧发起注册请求请求的nDid为" + nDid);
String methodDescribe = getMethodDescribe("add");
LogUtil.njcnDebug(log, "{}设备向装置侧发起注册请求请求的nDid为{}", methodDescribe, nDid);
accessService.add(nDid);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
}

View File

@@ -1,48 +0,0 @@
package com.njcn.access.controller;
import com.njcn.access.service.ICsTopicService;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.common.utils.LogUtil;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/5/12 10:28
*/
@Slf4j
@RestController
@RequestMapping("/topic")
@RequiredArgsConstructor
@Api(tags = "装置主题")
public class TopicController extends BaseController {
private final ICsTopicService csTopicService;
@PostMapping("/ask")
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@ApiOperation("平台询问装置支持主题")
@ApiImplicitParam(name = "nDid", value = "网关识别码", required = true)
public HttpResult<Object> ask(@RequestParam String nDid){
String methodDescribe = getMethodDescribe("ask");
LogUtil.njcnDebug(log, "{}平台询问装置支持主题请求的nDid为{}", methodDescribe, nDid);
csTopicService.askDevTopic(nDid);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
}

View File

@@ -1,5 +1,6 @@
package com.njcn.access.handler; package com.njcn.access.handler;
import com.alibaba.excel.util.CollectionUtils;
import com.alibaba.nacos.shaded.com.google.gson.Gson; import com.alibaba.nacos.shaded.com.google.gson.Gson;
import com.github.tocrhz.mqtt.annotation.MqttSubscribe; import com.github.tocrhz.mqtt.annotation.MqttSubscribe;
import com.github.tocrhz.mqtt.annotation.NamedValue; import com.github.tocrhz.mqtt.annotation.NamedValue;
@@ -10,22 +11,17 @@ import com.njcn.access.enums.AccessResponseEnum;
import com.njcn.access.enums.TypeEnum; import com.njcn.access.enums.TypeEnum;
import com.njcn.access.pojo.dto.DevModInfoDto; import com.njcn.access.pojo.dto.DevModInfoDto;
import com.njcn.access.pojo.dto.ModelDto; import com.njcn.access.pojo.dto.ModelDto;
import com.njcn.access.pojo.dto.TopicDto; import com.njcn.access.pojo.dto.ReqAndResDto;
import com.njcn.access.pojo.dto.heart.HeartBeatDto; import com.njcn.access.pojo.dto.heart.HeartBeatDto;
import com.njcn.access.pojo.param.ReqAndResParam; import com.njcn.access.pojo.po.CsLineModel;
import com.njcn.access.pojo.po.CsTopicPO; import com.njcn.access.service.ICsLineModelService;
import com.njcn.access.service.ICsTopicService; import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.algorithm.api.DevModelFeignClient;
import com.njcn.algorithm.api.EquipmentFeignClient;
import com.njcn.algorithm.pojo.param.CsDevModelQueryListParm;
import com.njcn.algorithm.pojo.vo.CsDevModelPageVO;
import com.njcn.algorithm.pojo.vo.CsEquipmentDeliveryVO;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.PubUtils; import com.njcn.common.utils.PubUtils;
import com.njcn.csdevice.api.DevModelFeignClient;
import com.njcn.csdevice.api.EquipmentFeignClient;
import com.njcn.csdevice.pojo.po.CsDevModelPO;
import com.njcn.redis.utils.RedisUtil; import com.njcn.redis.utils.RedisUtil;
import com.njcn.system.api.DicDataFeignClient; import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.pojo.po.DictData;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttMessage; import org.eclipse.paho.client.mqttv3.MqttMessage;
@@ -33,11 +29,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.validation.ConstraintViolation;
import javax.validation.Validator; import javax.validation.Validator;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.time.Instant; import java.util.ArrayList;
import java.util.*; import java.util.List;
import java.util.Objects;
/** /**
* @author hongawen * @author hongawen
@@ -49,52 +45,52 @@ import java.util.*;
@AllArgsConstructor @AllArgsConstructor
public class MqttMessageHandler { public class MqttMessageHandler {
private final EquipmentFeignClient equipmentFeignClient;
private final DevModelFeignClient devModelFeignClient; private final DevModelFeignClient devModelFeignClient;
private final EquipmentFeignClient equipmentFeignClient;
private final DicDataFeignClient dicDataFeignClient; private final DicDataFeignClient dicDataFeignClient;
private final ICsLineModelService csLineModelService;
private final MqttPublisher publisher; private final MqttPublisher publisher;
private final RedisUtil redisUtil; private final RedisUtil redisUtil;
private final ICsTopicService csTopicService;
@Autowired @Autowired
Validator validator; Validator validator;
@MqttSubscribe(value = "/Dev/Topic/{edgeId}",qos = 1) // @MqttSubscribe(value = "/Dev/Topic/{edgeId}",qos = 1)
@Transactional(rollbackFor = Exception.class) // @Transactional(rollbackFor = Exception.class)
public void devTopic(String topic, MqttMessage message, @NamedValue("edgeId") String nDid, @Payload String payload){ // public void devTopic(String topic, MqttMessage message, @NamedValue("edgeId") String nDid, @Payload String payload){
Gson gson = new Gson(); // Gson gson = new Gson();
ReqAndResParam.Res res = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), ReqAndResParam.Res.class); // ReqAndResParam.Res res = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), ReqAndResParam.Res.class);
//检验传递的参数是否准确 // //检验传递的参数是否准确
Set<ConstraintViolation<ReqAndResParam.Res>> validate = validator.validate(res); // Set<ConstraintViolation<ReqAndResParam.Res>> validate = validator.validate(res);
validate.forEach(constraintViolation -> { // validate.forEach(constraintViolation -> {
System.out.println(constraintViolation.getMessage()); // System.out.println(constraintViolation.getMessage());
}); // });
if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){ // if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){
if (Objects.equals(res.getType(), TypeEnum.TYPE_1.getCode())){ // if (Objects.equals(res.getType(), TypeEnum.TYPE_1.getCode())){
List<CsTopicPO> list = new ArrayList<>(); // List<CsTopicPO> list = new ArrayList<>();
//fixme 这边获取数据需要调整 // //fixme 这边获取数据需要调整
Map<String,List<String>> map = (Map<String,List<String>>)res.getMsg(); // Map<String,List<String>> map = (Map<String,List<String>>)res.getMsg();
List<String> topicList = map.get("Topic"); // List<String> topicList = map.get("Topic");
topicList.forEach(item->{ // topicList.forEach(item->{
CsTopicPO csTopicPo = new CsTopicPO(); // CsTopicPO csTopicPo = new CsTopicPO();
csTopicPo.setNdid(nDid); // csTopicPo.setNdid(nDid);
csTopicPo.setTopic(item); // csTopicPo.setTopic(item);
csTopicPo.setType(0); // csTopicPo.setType(0);
list.add(csTopicPo); // list.add(csTopicPo);
}); // });
csTopicService.addList(list); // csTopicService.addList(list);
} else { // } else {
log.info(AccessResponseEnum.MESSAGE_TYPE_ERROR.getMessage()); // log.info(AccessResponseEnum.MESSAGE_TYPE_ERROR.getMessage());
} // }
} else { // } else {
log.info(AccessResponseEnum.RESPONSE_ERROR.getMessage()); // log.info(AccessResponseEnum.RESPONSE_ERROR.getMessage());
} // }
} // }
/** /**
* 装置注册应答 * 装置注册应答
@@ -108,31 +104,26 @@ public class MqttMessageHandler {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void devOperation(String topic, MqttMessage message, @NamedValue("edgeId") String nDid, @Payload String payload){ public void devOperation(String topic, MqttMessage message, @NamedValue("edgeId") String nDid, @Payload String payload){
log.info("收到注册应答响应--->" + nDid); log.info("收到注册应答响应--->" + nDid);
//这边用redis缓存来判断是否接收响应
redisUtil.saveByKeyWithExpire(nDid,true,5L);
Gson gson = new Gson(); Gson gson = new Gson();
ReqAndResParam.Res res = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), ReqAndResParam.Res.class); ReqAndResDto.Res res = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), ReqAndResDto.Res.class);
//检验传递的参数是否准确
Set<ConstraintViolation<ReqAndResParam.Res>> validate = validator.validate(res);
validate.forEach(constraintViolation -> {
System.out.println(constraintViolation.getMessage());
});
if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){ if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){
if (Objects.equals(res.getType(),TypeEnum.TYPE_17.getCode())){ if (Objects.equals(res.getType(),TypeEnum.TYPE_17.getCode())){
equipmentFeignClient.updateStatusBynDid(nDid, AccessEnum.REGISTERED.getCode()); equipmentFeignClient.updateStatusBynDid(nDid, AccessEnum.REGISTERED.getCode());
//询问模板数据 //询问模板数据
ReqAndResParam.Req reqAndResParam = new ReqAndResParam.Req(); ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
reqAndResParam.setMid(1); reqAndResParam.setMid(1);
reqAndResParam.setDid("0"); reqAndResParam.setDid("0");
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode()); reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
reqAndResParam.setType(TypeEnum.TYPE_3.getCode()); reqAndResParam.setType(TypeEnum.TYPE_3.getCode());
reqAndResParam.setExpire(-1); reqAndResParam.setExpire(-1);
publisher.send("/Pfm/DevCmd/V1/"+nDid,new Gson().toJson(reqAndResParam),1,false); publisher.send("/Pfm/DevCmd/V1/"+nDid,new Gson().toJson(reqAndResParam),1,false);
//这边用redis缓存来判断是否接收响应
redisUtil.saveByKey(nDid,AccessEnum.SUCCESS.getCode());
} else { } else {
log.info(AccessResponseEnum.MESSAGE_TYPE_ERROR.getMessage()); log.info(AccessResponseEnum.MESSAGE_TYPE_ERROR.getMessage());
} }
} else { } else {
log.info(AccessResponseEnum.RESPONSE_ERROR.getMessage()); log.info(AccessResponseEnum.REGISTER_RESPONSE_ERROR.getMessage());
} }
} }
@@ -151,50 +142,31 @@ public class MqttMessageHandler {
public void devModelOperation(String topic, MqttMessage message, @NamedValue("version") String version, @NamedValue("edgeId") String nDid, @Payload String payload){ public void devModelOperation(String topic, MqttMessage message, @NamedValue("version") String version, @NamedValue("edgeId") String nDid, @Payload String payload){
Gson gson = new Gson(); Gson gson = new Gson();
ModelDto modelDto = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), ModelDto.class); ModelDto modelDto = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), ModelDto.class);
HttpResult<CsEquipmentDeliveryVO> pojo = equipmentFeignClient.queryEquipmentByndid(nDid); List<DevModInfoDto> list = modelDto.getMsg().getDevMod();
if (!Objects.isNull(pojo)){ if (CollectionUtils.isEmpty(list)){
String devType = pojo.getData().getDevModel(); log.error(AccessResponseEnum.MODEL_VERSION_ERROR.getMessage());
String dictCode = dicDataFeignClient.getDicDataById(devType).getData().getCode(); throw new BusinessException(AccessResponseEnum.MODEL_VERSION_ERROR);
//直连设备处理
if (Objects.equals(dictCode, DicDataEnum.CONNECT_DEV.getCode())){
List<DevModInfoDto> list = modelDto.getDevMod();
list.forEach(item->{
DictData dicData = dicDataFeignClient.getDicDataByCode(item.getDevType()).getData();
CsDevModelQueryListParm csDevModelQueryListParm = new CsDevModelQueryListParm();
if (Objects.isNull(dicData)) {
log.info(AccessResponseEnum.DEV_TYPE_NOT_FIND.getMessage());
return;
} else {
csDevModelQueryListParm.setDevType(dicData.getId());
}
csDevModelQueryListParm.setVersionNo(item.getVersionNo());
csDevModelQueryListParm.setVersionDate(item.getVersionDate());
CsDevModelPageVO csDevModelPageVO = devModelFeignClient.queryDevModelOne(csDevModelQueryListParm).getData();
if (Objects.isNull(csDevModelPageVO)){
log.info(AccessResponseEnum.MODEL_NO_FIND.getMessage());
} else {
ReqAndResParam.Req reqAndResParam = new ReqAndResParam.Req();
reqAndResParam.setMid(1);
reqAndResParam.setDid("0");
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
reqAndResParam.setType(TypeEnum.TYPE_5.getCode());
reqAndResParam.setExpire(-1);
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid,new Gson().toJson(reqAndResParam),1,false);
//将装置状态改为接入
equipmentFeignClient.updateStatusBynDid(nDid, AccessEnum.ACCESS.getCode());
//设置心跳时间,超时改为掉线
redisUtil.saveByKeyWithExpire("MQTT:" + nDid,Instant.now().toEpochMilli(),180L);
}
});
}
//网关处理 生成报文下发给装置,装置响应版本
else if (Objects.equals(dictCode, DicDataEnum.GATEWAY_DEV.getCode())){
//todo 处理待定
System.out.println("网关设备判断");
}
} else {
log.info(AccessResponseEnum.NDID_NO_FIND.getMessage());
} }
//校验前置传递的装置模板库中是否存在
list.forEach(item->{
CsDevModelPO po = devModelFeignClient.findModel(item.getDevType(),item.getVersionNo(),item.getVersionDate()).getData();
if (Objects.isNull(po)){
log.error(AccessResponseEnum.MODEL_NO_FIND.getMessage());
throw new BusinessException(AccessResponseEnum.MODEL_NO_FIND);
}
});
//fixme 这边先写死模板id后期要选择电能质量的模板来确定监测点个数
String modelId = "1";
List<CsLineModel> lineList = csLineModelService.getMonitorNumByModelId(modelId);
String key = "LINE" + nDid;
//存储监测点模板信息,用于界面回显
redisUtil.saveByKey(key,lineList);
//存储模板id
//todo 这边也是要调整的
String key2 = "MODEL" + nDid;
redisUtil.saveByKey(key2,modelId);
redisUtil.delete(nDid);
} }
@@ -210,7 +182,7 @@ public class MqttMessageHandler {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void devHeartBeat(String topic, MqttMessage message, @NamedValue("version") String version, @NamedValue("edgeId") String nDid, @Payload String payload) { public void devHeartBeat(String topic, MqttMessage message, @NamedValue("version") String version, @NamedValue("edgeId") String nDid, @Payload String payload) {
//响应请求 //响应请求
ReqAndResParam.Req reqAndResParam = new ReqAndResParam.Req(); ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
HeartBeatDto heartBeatDto = new HeartBeatDto(); HeartBeatDto heartBeatDto = new HeartBeatDto();
heartBeatDto.setTime(System.currentTimeMillis()/1000); heartBeatDto.setTime(System.currentTimeMillis()/1000);
reqAndResParam.setMid(1); reqAndResParam.setMid(1);
@@ -221,7 +193,7 @@ public class MqttMessageHandler {
reqAndResParam.setMsg(heartBeatDto); reqAndResParam.setMsg(heartBeatDto);
publisher.send("/Dev/PfmRsp/"+version+"/"+nDid,PubUtils.obj2json(reqAndResParam),1,false); publisher.send("/Dev/PfmRsp/"+version+"/"+nDid,PubUtils.obj2json(reqAndResParam),1,false);
//处理业务逻辑 //处理业务逻辑
ReqAndResParam.Res res = PubUtils.json2obj(new String(message.getPayload(), StandardCharsets.UTF_8), ReqAndResParam.Res.class); ReqAndResDto.Res res = PubUtils.json2obj(new String(message.getPayload(), StandardCharsets.UTF_8), ReqAndResDto.Res.class);
Object object = res.getMsg(); Object object = res.getMsg();
if (!Objects.isNull(object)){ if (!Objects.isNull(object)){
List<String> abnormalList = new ArrayList<>(); List<String> abnormalList = new ArrayList<>();

View File

@@ -1,16 +0,0 @@
package com.njcn.access.mapper;
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
import com.njcn.access.pojo.po.CsAlmPO;
/**
* <p>
* 设备告警数据表 Mapper 接口
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
public interface CsAlmMapper extends MppBaseMapper<CsAlmPO> {
}

View File

@@ -1,16 +0,0 @@
package com.njcn.access.mapper;
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
import com.njcn.access.pojo.po.CsBmdPO;
/**
* <p>
* Mapper 接口
* </p>
*
* @author xuyang
* @since 2023-05-11
*/
public interface CsBmdMapper extends MppBaseMapper<CsBmdPO> {
}

View File

@@ -1,16 +0,0 @@
package com.njcn.access.mapper;
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
import com.njcn.access.pojo.po.CsCtrlPO;
/**
* <p>
* 控制表 Mapper 接口
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
public interface CsCtrlMapper extends MppBaseMapper<CsCtrlPO> {
}

View File

@@ -1,16 +0,0 @@
package com.njcn.access.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.access.pojo.po.CsDataArrayPO;
/**
* <p>
* 详细数据表 Mapper 接口
* </p>
*
* @author xuyang
* @since 2023-05-23
*/
public interface CsDataArrayMapper extends BaseMapper<CsDataArrayPO> {
}

View File

@@ -1,16 +0,0 @@
package com.njcn.access.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.access.pojo.po.CsDataSetPO;
/**
* <p>
* 数据集表 Mapper 接口
* </p>
*
* @author xuyang
* @since 2023-05-23
*/
public interface CsDataSetMapper extends BaseMapper<CsDataSetPO> {
}

View File

@@ -1,16 +0,0 @@
package com.njcn.access.mapper;
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
import com.njcn.access.pojo.po.CsDiPO;
/**
* <p>
* 开入表 Mapper 接口
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
public interface CsDiMapper extends MppBaseMapper<CsDiPO> {
}

View File

@@ -1,16 +0,0 @@
package com.njcn.access.mapper;
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
import com.njcn.access.pojo.po.CsDoPO;
/**
* <p>
* 开出表 Mapper 接口
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
public interface CsDoMapper extends MppBaseMapper<CsDoPO> {
}

View File

@@ -1,16 +0,0 @@
package com.njcn.access.mapper;
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
import com.njcn.access.pojo.po.CsEpdPqdPO;
/**
* <p>
* Mapper 接口
* </p>
*
* @author xuyang
* @since 2023-05-11
*/
public interface CsEpdPqdMapper extends MppBaseMapper<CsEpdPqdPO> {
}

View File

@@ -1,16 +0,0 @@
package com.njcn.access.mapper;
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
import com.njcn.access.pojo.po.CsEvtPO;
/**
* <p>
* 事件表 Mapper 接口
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
public interface CsEvtMapper extends MppBaseMapper<CsEvtPO> {
}

View File

@@ -1,16 +0,0 @@
package com.njcn.access.mapper;
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
import com.njcn.access.pojo.po.CsEvtParmPO;
/**
* <p>
* 事件参数表 Mapper 接口
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
public interface CsEvtParmMapper extends MppBaseMapper<CsEvtParmPO> {
}

View File

@@ -0,0 +1,16 @@
package com.njcn.access.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.access.pojo.po.CsLineModel;
/**
* <p>
* 监测点模板表 Mapper 接口
* </p>
*
* @author xuyang
* @since 2023-07-05
*/
public interface CsLineModelMapper extends BaseMapper<CsLineModel> {
}

View File

@@ -1,16 +0,0 @@
package com.njcn.access.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.access.pojo.po.CsNetDevPO;
/**
* <p>
* 联网设备表 Mapper 接口
* </p>
*
* @author xuyang
* @since 2023-05-17
*/
public interface CsNetDevMapper extends BaseMapper<CsNetDevPO> {
}

View File

@@ -1,17 +0,0 @@
package com.njcn.access.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
import com.njcn.access.pojo.po.CsParmPO;
/**
* <p>
* 参数表 Mapper 接口
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
public interface CsParmMapper extends MppBaseMapper<CsParmPO> {
}

View File

@@ -1,16 +0,0 @@
package com.njcn.access.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.access.pojo.po.CsPrjInfoPO;
/**
* <p>
* 工程信息表 Mapper 接口
* </p>
*
* @author xuyang
* @since 2023-05-17
*/
public interface CsPrjInfoMapper extends BaseMapper<CsPrjInfoPO> {
}

View File

@@ -1,16 +0,0 @@
package com.njcn.access.mapper;
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
import com.njcn.access.pojo.po.CsSetPO;
/**
* <p>
* 设备定值数据表 Mapper 接口
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
public interface CsSetMapper extends MppBaseMapper<CsSetPO> {
}

View File

@@ -1,16 +0,0 @@
package com.njcn.access.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.access.pojo.po.CsSoftInfoPO;
/**
* <p>
* 系统软件表 Mapper 接口
* </p>
*
* @author xuyang
* @since 2023-05-17
*/
public interface CsSoftInfoMapper extends BaseMapper<CsSoftInfoPO> {
}

View File

@@ -1,16 +0,0 @@
package com.njcn.access.mapper;
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
import com.njcn.access.pojo.po.CsStsPO;
/**
* <p>
* 状态表 Mapper 接口
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
public interface CsStsMapper extends MppBaseMapper<CsStsPO> {
}

View File

@@ -1,18 +0,0 @@
package com.njcn.access.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.access.pojo.po.CsTopicPO;
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
* Mapper 接口
* </p>
*
* @author xuyang
* @since 2023-05-12
*/
@Mapper
public interface CsTopicMapper extends BaseMapper<CsTopicPO> {
}

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.njcn.access.mapper.CsEpdPqdMapper">
</mapper>

View File

@@ -1,16 +0,0 @@
package com.njcn.access.service;
/**
* @author 徐扬
*/
public interface IAccessService {
/**
* 设备注册(1.判断此装置是否完成出厂设置 2.判断此装置是否能正常通讯)
* 1.根据nDid获取装置的信息(设备型号、网关识别码)
* 2.发送MQTT信息给装置
* 3.装置响应则修改装置状态3分钟未响应则生成告警信息
* @param nDid 网关识别码
*/
void add(String nDid);
}

View File

@@ -1,19 +0,0 @@
package com.njcn.access.service;
import com.njcn.access.pojo.po.CsAlmPO;
import java.util.List;
/**
* <p>
* 设备告警数据表 服务类
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
public interface ICsAlmService {
void saveData(List<CsAlmPO> list);
}

View File

@@ -1,21 +0,0 @@
package com.njcn.access.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.access.pojo.po.CsBmdPO;
import com.njcn.access.pojo.po.CsEpdPqdPO;
import java.util.List;
/**
* <p>
* 服务类
* </p>
*
* @author xuyang
* @since 2023-05-11
*/
public interface ICsBmdService {
void saveData(List<CsBmdPO> list);
}

View File

@@ -1,19 +0,0 @@
package com.njcn.access.service;
import com.njcn.access.pojo.po.CsCtrlPO;
import java.util.List;
/**
* <p>
* 控制表 服务类
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
public interface ICsCtrlService {
void saveData(List<CsCtrlPO> list);
}

View File

@@ -1,19 +0,0 @@
package com.njcn.access.service;
import com.njcn.access.pojo.po.CsDataArrayPO;
import java.util.List;
/**
* <p>
* 详细数据表 服务类
* </p>
*
* @author xuyang
* @since 2023-05-23
*/
public interface ICsDataArrayService {
void saveData(List<CsDataArrayPO> list);
}

View File

@@ -1,17 +0,0 @@
package com.njcn.access.service;
import com.njcn.access.pojo.po.CsDataSetPO;
/**
* <p>
* 数据集表 服务类
* </p>
*
* @author xuyang
* @since 2023-05-23
*/
public interface ICsDataSetService {
CsDataSetPO addOne(CsDataSetPO csDataSetPo);
}

View File

@@ -0,0 +1,21 @@
package com.njcn.access.service;
import com.njcn.access.pojo.param.DevModelParam;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/7/3 15:39
*/
public interface ICsDevModelService {
/**
* 解析模板文件->入库
* @param devModelParam
*/
void addModel(DevModelParam devModelParam);
}

View File

@@ -0,0 +1,33 @@
package com.njcn.access.service;
import com.njcn.access.param.DevAccessParam;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/7/4 13:43
*/
public interface ICsDeviceService {
/**
* 直连设备注册
* @param nDid 设备识别码
*/
void devRegister(String nDid);
/**
* MQTT连接成功获取装置所用的模板信息
* @param nDid
*/
Object getModel(String nDid);
/**
* MQTT连接成功获取装置所用的模板信息
* @param devAccessParam
*/
void devAccess(DevAccessParam devAccessParam);
}

View File

@@ -1,19 +0,0 @@
package com.njcn.access.service;
import com.njcn.access.pojo.po.CsDiPO;
import java.util.List;
/**
* <p>
* 开入表 服务类
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
public interface ICsDiService {
void saveData(List<CsDiPO> list);
}

View File

@@ -1,19 +0,0 @@
package com.njcn.access.service;
import com.njcn.access.pojo.po.CsDoPO;
import java.util.List;
/**
* <p>
* 开出表 服务类
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
public interface ICsDoService {
void saveData(List<CsDoPO> list);
}

View File

@@ -1,20 +0,0 @@
package com.njcn.access.service;
import com.njcn.access.pojo.po.CsEpdPqdPO;
import java.util.List;
/**
* <p>
* 服务类
* </p>
*
* @author xuyang
* @since 2023-05-11
*/
public interface ICsEpdPqdService {
void saveData(List<CsEpdPqdPO> list);
// CsEpdPqdPO findOne(Integer idx);
}

View File

@@ -1,19 +0,0 @@
package com.njcn.access.service;
import com.njcn.access.pojo.po.CsEvtParmPO;
import java.util.List;
/**
* <p>
* 事件参数表 服务类
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
public interface ICsEvtParmService {
boolean saveData(List<CsEvtParmPO> list);
}

View File

@@ -1,20 +0,0 @@
package com.njcn.access.service;
import com.njcn.access.pojo.po.CsEvtPO;
import java.util.List;
import java.util.Map;
/**
* <p>
* 事件表 服务类
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
public interface ICsEvtService {
Map<String,String> saveData(List<CsEvtPO> list);
}

View File

@@ -0,0 +1,24 @@
package com.njcn.access.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.access.pojo.po.CsLineModel;
import java.util.List;
/**
* <p>
* 监测点模板表 服务类
* </p>
*
* @author xuyang
* @since 2023-07-05
*/
public interface ICsLineModelService extends IService<CsLineModel> {
/**
* 获取模板下监测点个数
* @param id 模板Id
*/
List<CsLineModel> getMonitorNumByModelId(String id);
}

View File

@@ -1,17 +0,0 @@
package com.njcn.access.service;
import com.njcn.access.pojo.po.CsNetDevPO;
/**
* <p>
* 联网设备表 服务类
* </p>
*
* @author xuyang
* @since 2023-05-17
*/
public interface ICsNetDevService {
boolean saveData(CsNetDevPO csNetDevPo);
}

View File

@@ -1,19 +0,0 @@
package com.njcn.access.service;
import com.njcn.access.pojo.po.CsParmPO;
import java.util.List;
/**
* <p>
* 参数表 服务类
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
public interface ICsParmService {
void saveData(List<CsParmPO> list);
}

View File

@@ -1,18 +0,0 @@
package com.njcn.access.service;
import com.njcn.access.pojo.po.CsPrjInfoPO;
import com.njcn.access.pojo.po.CsSoftInfoPO;
/**
* <p>
* 工程信息表 服务类
* </p>
*
* @author xuyang
* @since 2023-05-17
*/
public interface ICsPrjInfoService {
CsPrjInfoPO saveData(CsPrjInfoPO csPrjInfoPO);
}

View File

@@ -1,19 +0,0 @@
package com.njcn.access.service;
import com.njcn.access.pojo.po.CsSetPO;
import java.util.List;
/**
* <p>
* 设备定值数据表 服务类
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
public interface ICsSetService {
void saveData(List<CsSetPO> list);
}

View File

@@ -1,17 +0,0 @@
package com.njcn.access.service;
import com.njcn.access.pojo.po.CsSoftInfoPO;
/**
* <p>
* 系统软件表 服务类
* </p>
*
* @author xuyang
* @since 2023-05-17
*/
public interface ICsSoftInfoService {
CsSoftInfoPO saveData(CsSoftInfoPO csSoftInfoPo);
}

View File

@@ -1,19 +0,0 @@
package com.njcn.access.service;
import com.njcn.access.pojo.po.CsStsPO;
import java.util.List;
/**
* <p>
* 状态表 服务类
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
public interface ICsStsService {
void saveData(List<CsStsPO> list);
}

View File

@@ -1,22 +0,0 @@
package com.njcn.access.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.access.pojo.po.CsTopicPO;
import java.util.List;
/**
* <p>
* 服务类
* </p>
*
* @author xuyang
* @since 2023-05-12
*/
public interface ICsTopicService {
void askDevTopic(String nDid);
boolean addList(List<CsTopicPO> list);
}

View File

@@ -1,7 +0,0 @@
package com.njcn.access.service;
/**
* @author xy
*/
public interface IDataArrayService {
}

View File

@@ -1,9 +0,0 @@
package com.njcn.access.service;
/**
* @author xy
*/
public interface IDataSetService {
void add();
}

View File

@@ -1,18 +0,0 @@
package com.njcn.access.service;
import com.njcn.access.pojo.param.DevModelParam;
import com.njcn.common.pojo.response.HttpResult;
/**
* @author xy
*/
public interface IDevModelService {
/**
* 直连装置录入模板信息
* 1.解析模板文件,将数据录入库中
* 2.将文件上传至文件服务器保存起来,先以装置型号-版本号-时间作为名称名称
* @param devModelParam 模板文件参数
*/
void add(DevModelParam devModelParam);
}

View File

@@ -0,0 +1,44 @@
package com.njcn.access.service.impl;
import com.alibaba.nacos.shaded.com.google.gson.Gson;
import com.njcn.access.pojo.dto.devModel.TemplateDto;
import com.njcn.access.pojo.param.DevModelParam;
import com.njcn.access.service.ICsDevModelService;
import com.njcn.access.utils.JsonUtil;
import com.njcn.oss.constant.OssPath;
import com.njcn.oss.utils.FileStorageUtil;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import java.io.IOException;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/7/3 15:40
*/
@Service
@AllArgsConstructor
public class CsDevModelServiceImpl implements ICsDevModelService {
private final FileStorageUtil fileStorageUtil;
@Override
public void addModel(DevModelParam devModelParam) {
String json = null;
try {
json = JsonUtil.convertStreamToString(devModelParam.getFile().getInputStream());
Gson gson = new Gson();
TemplateDto templateDto = gson.fromJson(json, TemplateDto.class);
//模板文件存入文件服务器
//String filePath = fileStorageUtil.uploadMultipart(devModelParam.getFile(), OssPath.DEV_MODEL + devModelParam.getDevType() + "_");
String filePath = "";
System.out.println("templateDto==:" + templateDto);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,212 @@
package com.njcn.access.service.impl;
import cn.hutool.core.util.IdUtil;
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
import com.njcn.access.enums.AccessEnum;
import com.njcn.access.enums.AccessResponseEnum;
import com.njcn.access.enums.TypeEnum;
import com.njcn.access.param.DevAccessParam;
import com.njcn.access.pojo.dto.AccessDto;
import com.njcn.access.pojo.dto.ReqAndResDto;
import com.njcn.access.service.ICsDeviceService;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.utils.PubUtils;
import com.njcn.csdevice.api.*;
import com.njcn.csdevice.pojo.param.CsDevModelRelationAddParm;
import com.njcn.csdevice.pojo.param.CsLedgerParam;
import com.njcn.csdevice.pojo.po.AppLineTopologyDiagramPO;
import com.njcn.csdevice.pojo.po.CsDeviceUserPO;
import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
import com.njcn.redis.utils.RedisUtil;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.api.DictTreeFeignClient;
import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.pojo.po.SysDicTreePO;
import com.njcn.web.utils.RequestUtil;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/7/4 13:43
*/
@Service
@AllArgsConstructor
public class CsDeviceServiceImpl implements ICsDeviceService {
private static final Logger logger = LoggerFactory.getLogger(CsDeviceServiceImpl.class);
private final EquipmentFeignClient equipmentFeignClient;
private final DictTreeFeignClient dictTreeFeignClient;
private final DicDataFeignClient dicDataFeignClient;
private final CsLedgerFeignClient csLedgerFeignClient;
private final CsLineFeignClient csLineFeignClient;
private final CsLineTopologyFeignClient csLineTopologyFeignClient;
private final DevModelRelationFeignClient devModelRelationFeignClient;
private final CsDeviceUserFeignClient csDeviceUserFeignClient;
private final MqttPublisher publisher;
private final RedisUtil redisUtil;
@Override
@Transactional(rollbackFor = {Exception.class})
public void devRegister(String nDid) {
//1.判断nDid是否存在
CsEquipmentDeliveryVO csEquipmentDeliveryVO = equipmentFeignClient.queryEquipmentByndid(nDid).getData();
if (Objects.isNull(csEquipmentDeliveryVO.getNdid())){
throw new BusinessException(AccessResponseEnum.NDID_NO_FIND);
}
//2.判断设备是否是直连设备
SysDicTreePO sysDicTreePo = dictTreeFeignClient.queryById(csEquipmentDeliveryVO.getDevType()).getData();
if (Objects.isNull(sysDicTreePo)){
throw new BusinessException(AccessResponseEnum.DEV_NOT_FIND);
}
String code = sysDicTreePo.getCode();
if (!Objects.equals(code, DicDataEnum.CONNECT_DEV.getCode())){
throw new BusinessException(AccessResponseEnum.DEV_IS_NOT_ZL);
}
//3.MQTT询问装置用的模板并判断库中是否存在模板
//存在则建立关系;不存在则告警出来
SysDicTreePO dictData = dictTreeFeignClient.queryById(csEquipmentDeliveryVO.getDevModel()).getData();
if (Objects.isNull(dictData)){
throw new BusinessException(AccessResponseEnum.DEV_MODEL_NOT_FIND);
}
String devModel = dictData.getCode();
zhiLianRegister(nDid,devModel);
try {
Thread.sleep(1000);
//这边使用redis缓存来判断装置是否连接MQTT或者是否出现异常
if (Objects.isNull(redisUtil.getObjectByKey(nDid))){
logger.error("装置注册失败,请核查!");
throw new BusinessException(AccessResponseEnum.REGISTER_ERROR);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
public Object getModel(String nDid) {
Object model = null;
try {
Thread.sleep(1000);
String key = "LINE" + nDid;
model = redisUtil.getObjectByKey(key);
if (Objects.isNull(model)){
throw new BusinessException(AccessResponseEnum.MODEL_MISS);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
return model;
}
@Override
@Transactional(rollbackFor = {Exception.class})
public void devAccess(DevAccessParam devAccessParam) {
try {
CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(devAccessParam.getNDid()).getData();
List<CsLinePO> csLinePoList = new ArrayList<>();
List<AppLineTopologyDiagramPO> appLineTopologyDiagramPoList = new ArrayList<>();
//1.录入装置台账信息
CsLedgerParam csLedgerParam = new CsLedgerParam();
csLedgerParam.setId(vo.getId());
csLedgerParam.setPid(devAccessParam.getProjectId());
csLedgerParam.setName(vo.getName());
csLedgerParam.setLevel(2);
csLedgerParam.setSort(0);
csLedgerFeignClient.add(csLedgerParam);
//2.监测点表录入关系
devAccessParam.getList().forEach(item->{
String id = IdUtil.fastSimpleUUID();
CsLinePO po = new CsLinePO();
po.setLineId(id);
po.setName(item.getName());
po.setPosition(item.getPosition());
po.setVolGrade(item.getVolGrade());
//todo 目前ct、pt数据不确定 后期补
//po.setPtRatio(item.getPtRatio());
//po.setCtRatio(item.getCtRatio());
po.setStatus(1);
csLinePoList.add(po);
CsLedgerParam param = new CsLedgerParam();
param.setId(id);
param.setPid(vo.getId());
param.setName(item.getName());
param.setLevel(3);
param.setSort(0);
csLedgerFeignClient.add(param).getData();
AppLineTopologyDiagramPO appLineTopologyDiagramPo = new AppLineTopologyDiagramPO();
appLineTopologyDiagramPo.setId(devAccessParam.getTopologyDiagram());
appLineTopologyDiagramPo.setLineId(id);
appLineTopologyDiagramPo.setLat(item.getLat());
appLineTopologyDiagramPo.setLng(item.getLng());
appLineTopologyDiagramPo.setStatus("1");
appLineTopologyDiagramPoList.add(appLineTopologyDiagramPo);
});
csLineFeignClient.addLineList(csLinePoList);
//3.监测点拓扑图表录入关系
csLineTopologyFeignClient.addList(appLineTopologyDiagramPoList);
//4.新增装置-模板关系
String modelId = redisUtil.getObjectByKey("MODEL" + devAccessParam.getNDid()).toString();
CsDevModelRelationAddParm csDevModelRelationAddParm = new CsDevModelRelationAddParm();
csDevModelRelationAddParm.setDevId(vo.getId());
csDevModelRelationAddParm.setModelId(modelId);
devModelRelationFeignClient.addDevModelRelation(csDevModelRelationAddParm);
redisUtil.delete("MODEL" + devAccessParam.getNDid());
//5.修改装置状态
equipmentFeignClient.updateStatusBynDid(devAccessParam.getNDid(), AccessEnum.ACCESS.getCode());
//6.设置心跳时间,超时改为掉线
redisUtil.saveByKeyWithExpire("MQTT:" + devAccessParam.getNDid(), Instant.now().toEpochMilli(),180L);
//7.绑定装置和人的关系
CsDeviceUserPO po = new CsDeviceUserPO();
po.setPrimaryUserId(RequestUtil.getUserIndex());
po.setSubUserId(RequestUtil.getUserIndex());
po.setDeviceId(vo.getId());
csDeviceUserFeignClient.add(Collections.singletonList(po));
//8.删除redis监测点模板信息
redisUtil.delete("LINE" + devAccessParam.getNDid());
//todo 9.记录操作日志
} catch (Exception e) {
throw new BusinessException(CommonResponseEnum.FAIL);
}
}
public void zhiLianRegister(String nDid,String devType) {
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
reqAndResParam.setMid(1);
reqAndResParam.setDid("0");
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
reqAndResParam.setType(TypeEnum.TYPE_2.getCode());
reqAndResParam.setExpire(-1);
AccessDto accessDto = new AccessDto();
accessDto.setNDid(nDid);
accessDto.setDevType(devType);
reqAndResParam.setMsg(accessDto);
publisher.send("/Pfm/Reg/"+nDid, PubUtils.obj2json(reqAndResParam),1,false);
}
}

View File

@@ -0,0 +1,27 @@
package com.njcn.access.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.access.mapper.CsLineModelMapper;
import com.njcn.access.pojo.po.CsLineModel;
import com.njcn.access.service.ICsLineModelService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 监测点模板表 服务实现类
* </p>
*
* @author xuyang
* @since 2023-07-05
*/
@Service
public class CsLineModelServiceImpl extends ServiceImpl<CsLineModelMapper, CsLineModel> implements ICsLineModelService {
@Override
public List<CsLineModel> getMonitorNumByModelId(String id) {
return this.lambdaQuery().eq(CsLineModel::getPid,id).list();
}
}

View File

@@ -1,105 +0,0 @@
package com.njcn.access.service.serviceImpl;
import com.alibaba.csp.sentinel.util.TimeUtil;
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
import com.njcn.access.enums.AccessEnum;
import com.njcn.access.enums.AccessResponseEnum;
import com.njcn.access.enums.TypeEnum;
import com.njcn.access.handler.MqttMessageHandler;
import com.njcn.access.pojo.dto.AccessDto;
import com.njcn.access.pojo.param.ReqAndResParam;
import com.njcn.access.service.IAccessService;
import com.njcn.algorithm.api.CsEdDataFeignClient;
import com.njcn.algorithm.api.EquipmentFeignClient;
import com.njcn.algorithm.pojo.vo.CsEdDataVO;
import com.njcn.algorithm.pojo.vo.CsEquipmentDeliveryVO;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.common.utils.PubUtils;
import com.njcn.redis.utils.RedisUtil;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.enums.DicDataEnum;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.Objects;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/3/31 9:21
*/
@Service
@AllArgsConstructor
public class AccessServiceImpl implements IAccessService {
private static final Logger logger = LoggerFactory.getLogger(AccessServiceImpl.class);
private final MqttPublisher publisher;
private final EquipmentFeignClient equipmentFeignClient;
private final CsEdDataFeignClient csEdDataFeignClient;
private final DicDataFeignClient dicDataFeignClient;
private final RedisUtil redisUtil;
@Override
public void add(String nDid) {
CsEquipmentDeliveryVO vo = equipmentFeignClient.queryEquipmentByndid(nDid).getData();
if (Objects.isNull(vo.getNdid())){
logger.error("平台侧无此网关信息,请先录入!");
throw new BusinessException(AccessResponseEnum.NDID_NO_FIND);
} else {
HttpResult<CsEdDataVO> result = csEdDataFeignClient.findByDevTypeId(vo.getDevModel());
String typeId = result.getData().getType();
if(Objects.isNull(typeId)) {
logger.error("平台侧无此装置类型,请先录入!");
throw new BusinessException(AccessResponseEnum.DEV_TYPE_NOT_FIND);
} else {
String type = dicDataFeignClient.getDicDataById(typeId).getData().getCode();
if (Objects.equals(DicDataEnum.GATEWAY_DEV.getCode(),type)) {
//处理网关设备
System.out.println("网关");
} else if (Objects.equals(DicDataEnum.CONNECT_DEV.getCode(),type)) {
//处理直连设备
zhiLianRegister(nDid,vo.getDevModel());
} else {
logger.error("请求注册的装置类型错误(不是网关或者直连设备),请核查!");
throw new BusinessException(AccessResponseEnum.DEV_TYPE_ERROR);
}
}
}
try {
Thread.sleep(2000);
//这边使用redis缓存来判断装置是否连接MQTT
if(Objects.isNull(redisUtil.getObjectByKey(nDid))) {
logger.error("未收到装置注册响应,请核查!");
throw new BusinessException(AccessResponseEnum.NO_RECEIVE_FROM_DEV);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void zhiLianRegister(String nDid,String devType) {
ReqAndResParam.Req reqAndResParam = new ReqAndResParam.Req();
reqAndResParam.setMid(1);
reqAndResParam.setDid("0");
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
reqAndResParam.setType(TypeEnum.TYPE_2.getCode());
reqAndResParam.setExpire(-1);
AccessDto accessDto = new AccessDto();
accessDto.setNDid(nDid);
accessDto.setDevType(devType);
reqAndResParam.setMsg(accessDto);
publisher.send("/platform/register/"+nDid, PubUtils.obj2json(reqAndResParam),1,false);
}
}

View File

@@ -1,27 +0,0 @@
package com.njcn.access.service.serviceImpl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.access.mapper.CsAlmMapper;
import com.njcn.access.pojo.po.CsAlmPO;
import com.njcn.access.service.ICsAlmService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 设备告警数据表 服务实现类
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
@Service
public class CsAlmServiceImpl extends MppServiceImpl<CsAlmMapper, CsAlmPO> implements ICsAlmService {
@Override
public void saveData(List<CsAlmPO> list) {
this.saveOrUpdateBatchByMultiId(list,100);
}
}

View File

@@ -1,26 +0,0 @@
package com.njcn.access.service.serviceImpl;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.access.mapper.CsBmdMapper;
import com.njcn.access.pojo.po.CsBmdPO;
import com.njcn.access.service.ICsBmdService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 服务实现类
* </p>
*
* @author xuyang
* @since 2023-05-11
*/
@Service
public class CsBmdServiceImpl extends MppServiceImpl<CsBmdMapper, CsBmdPO> implements ICsBmdService {
@Override
public void saveData(List<CsBmdPO> list) {
this.saveOrUpdateBatchByMultiId(list,100);
}
}

View File

@@ -1,26 +0,0 @@
package com.njcn.access.service.serviceImpl;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.access.mapper.CsCtrlMapper;
import com.njcn.access.pojo.po.CsCtrlPO;
import com.njcn.access.service.ICsCtrlService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 控制表 服务实现类
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
@Service
public class CsCtrlServiceImpl extends MppServiceImpl<CsCtrlMapper, CsCtrlPO> implements ICsCtrlService {
@Override
public void saveData(List<CsCtrlPO> list) {
this.saveOrUpdateBatchByMultiId(list,100);
}
}

View File

@@ -1,26 +0,0 @@
package com.njcn.access.service.serviceImpl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.access.mapper.CsDataArrayMapper;
import com.njcn.access.pojo.po.CsDataArrayPO;
import com.njcn.access.service.ICsDataArrayService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 详细数据表 服务实现类
* </p>
*
* @author xuyang
* @since 2023-05-23
*/
@Service
public class CsDataArrayServiceImpl extends ServiceImpl<CsDataArrayMapper, CsDataArrayPO> implements ICsDataArrayService {
@Override
public void saveData(List<CsDataArrayPO> list) {
this.saveBatch(list,100);
}
}

View File

@@ -1,25 +0,0 @@
package com.njcn.access.service.serviceImpl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.access.mapper.CsDataSetMapper;
import com.njcn.access.pojo.po.CsDataSetPO;
import com.njcn.access.service.ICsDataSetService;
import org.springframework.stereotype.Service;
/**
* <p>
* 数据集表 服务实现类
* </p>
*
* @author xuyang
* @since 2023-05-23
*/
@Service
public class CsDataSetServiceImpl extends ServiceImpl<CsDataSetMapper, CsDataSetPO> implements ICsDataSetService {
@Override
public CsDataSetPO addOne(CsDataSetPO csDataSetPo) {
this.save(csDataSetPo);
return csDataSetPo;
}
}

View File

@@ -1,27 +0,0 @@
package com.njcn.access.service.serviceImpl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.access.mapper.CsDiMapper;
import com.njcn.access.pojo.po.CsDiPO;
import com.njcn.access.service.ICsDiService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 开入表 服务实现类
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
@Service
public class CsDiServiceImpl extends MppServiceImpl<CsDiMapper, CsDiPO> implements ICsDiService {
@Override
public void saveData(List<CsDiPO> list) {
this.saveOrUpdateBatchByMultiId(list,100);
}
}

View File

@@ -1,26 +0,0 @@
package com.njcn.access.service.serviceImpl;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.access.mapper.CsDoMapper;
import com.njcn.access.pojo.po.CsDoPO;
import com.njcn.access.service.ICsDoService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 开出表 服务实现类
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
@Service
public class CsDoServiceImpl extends MppServiceImpl<CsDoMapper, CsDoPO> implements ICsDoService {
@Override
public void saveData(List<CsDoPO> list) {
this.saveOrUpdateBatchByMultiId(list,100);
}
}

View File

@@ -1,41 +0,0 @@
package com.njcn.access.service.serviceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.access.enums.AccessResponseEnum;
import com.njcn.access.mapper.CsEpdPqdMapper;
import com.njcn.access.pojo.po.CsEpdPqdPO;
import com.njcn.access.service.ICsEpdPqdService;
import com.njcn.common.pojo.exception.BusinessException;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
/**
* <p>
* 服务实现类
* </p>
*
* @author xuyang
* @since 2023-05-11
*/
@Service
public class CsEpdPqdServiceImpl extends MppServiceImpl<CsEpdPqdMapper, CsEpdPqdPO> implements ICsEpdPqdService {
@Override
public void saveData(List<CsEpdPqdPO> list) {
this.saveOrUpdateBatchByMultiId(list,100);
}
// @Override
// public CsEpdPqdPO findOne(Integer idx) {
// LambdaQueryWrapper<CsEpdPqdPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
// lambdaQueryWrapper.eq(CsEpdPqdPO::getClassId, DataType.POWER_DATA).eq(CsEpdPqdPO::getIdx,idx);
// CsEpdPqdPO csEpdPqdPo = this.baseMapper.selectOne(lambdaQueryWrapper);
// if (Objects.isNull(csEpdPqdPo)) {
// throw new BusinessException(AccessResponseEnum.DICT_MISSING);
// }
// return csEpdPqdPo;
// }
}

View File

@@ -1,26 +0,0 @@
package com.njcn.access.service.serviceImpl;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.access.mapper.CsEvtParmMapper;
import com.njcn.access.pojo.po.CsEvtParmPO;
import com.njcn.access.service.ICsEvtParmService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 事件参数表 服务实现类
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
@Service
public class CsEvtParmServiceImpl extends MppServiceImpl<CsEvtParmMapper, CsEvtParmPO> implements ICsEvtParmService {
@Override
public boolean saveData(List<CsEvtParmPO> list) {
return this.saveOrUpdateBatchByMultiId(list,1000);
}
}

View File

@@ -1,40 +0,0 @@
package com.njcn.access.service.serviceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.access.mapper.CsEvtMapper;
import com.njcn.access.pojo.po.CsEvtPO;
import com.njcn.access.service.ICsEvtService;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* <p>
* 事件表 服务实现类
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
@Service
public class CsEvtServiceImpl extends MppServiceImpl<CsEvtMapper, CsEvtPO> implements ICsEvtService {
@Override
public Map<String,String> saveData(List<CsEvtPO> list) {
this.saveOrUpdateBatchByMultiId(list,100);
List<String> nameList = list.stream().map(CsEvtPO::getName).collect(Collectors.toList());
LambdaQueryWrapper<CsEvtPO> lambdaQueryWrapper = new LambdaQueryWrapper<CsEvtPO>();
lambdaQueryWrapper.in(CsEvtPO::getName,nameList);
List<CsEvtPO> list1 = this.baseMapper.selectList(lambdaQueryWrapper);
Map<String,String> map = new HashMap<>();
list1.forEach(item->{
map.put(item.getName(),item.getId());
});
return map;
}
}

View File

@@ -1,39 +0,0 @@
package com.njcn.access.service.serviceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.access.enums.AccessResponseEnum;
import com.njcn.access.mapper.CsNetDevMapper;
import com.njcn.access.pojo.po.CsNetDevPO;
import com.njcn.access.service.ICsNetDevService;
import com.njcn.common.pojo.exception.BusinessException;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.Objects;
/**
* <p>
* 联网设备表 服务实现类
* </p>
*
* @author xuyang
* @since 2023-05-17
*/
@Service
public class CsNetDevServiceImpl extends ServiceImpl<CsNetDevMapper, CsNetDevPO> implements ICsNetDevService {
@Override
public boolean saveData(CsNetDevPO csNetDevPo) {
LambdaQueryWrapper<CsNetDevPO> lambdaQueryWrapper = new LambdaQueryWrapper<CsNetDevPO>();
lambdaQueryWrapper.eq(CsNetDevPO::getDevType,csNetDevPo.getDevType())
.eq(CsNetDevPO::getTime,csNetDevPo.getTime())
.eq(CsNetDevPO::getVersion,csNetDevPo.getVersion())
.eq(CsNetDevPO::getStatus,1);
CsNetDevPO po = this.baseMapper.selectOne(lambdaQueryWrapper);
if (!Objects.isNull(po)){
throw new BusinessException(AccessResponseEnum.MODEL_REPEAT);
}
return this.save(csNetDevPo);
}
}

View File

@@ -1,27 +0,0 @@
package com.njcn.access.service.serviceImpl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.njcn.access.mapper.CsParmMapper;
import com.njcn.access.pojo.po.CsParmPO;
import com.njcn.access.service.ICsParmService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 参数表 服务实现类
* </p>
*
* @author xuyang
* @since 2023-05-19
*/
@Service
public class CsParmServiceImpl extends MppServiceImpl<CsParmMapper, CsParmPO> implements ICsParmService {
@Override
public void saveData(List<CsParmPO> list) {
this.saveOrUpdateBatchByMultiId(list,100);
}
}

Some files were not shown because too many files have changed in this diff Show More