From 147aef0bfd1b674ebca03bac0544385110de3ae3 Mon Sep 17 00:00:00 2001 From: xuyang <748613696@qq.com> Date: Tue, 11 Jul 2023 10:22:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../njcn/access/enums/AccessResponseEnum.java | 3 +- .../njcn/access/param/WgDevRegisterParam.java | 32 +++++ .../access/param/WgDeviceRegisterParam.java | 53 ++++++++ .../njcn/access/param/WgRegisterParam.java | 65 ++++++++++ .../com/njcn/access/pojo/po/CsGateway.java | 51 ++++++++ .../njcn/access/pojo/po/CsGatewayDevice.java | 32 +++++ .../com/njcn/access/pojo/vo/CsGatewayVo.java | 50 ++++++++ .../access/controller/CsDeviceController.java | 7 +- .../controller/CsGatewayController.java | 92 ++++++++++++++ .../access/handler/MqttMessageHandler.java | 10 +- .../access/mapper/CsGatewayDeviceMapper.java | 23 ++++ .../njcn/access/mapper/CsGatewayMapper.java | 24 ++++ .../mapper/mapping/CsGatewayDeviceMapper.xml | 14 +++ .../access/mapper/mapping/CsGatewayMapper.xml | 34 +++++ .../njcn/access/service/ICsDeviceService.java | 3 +- .../service/ICsGatewayDeviceService.java | 27 ++++ .../access/service/ICsGatewayService.java | 51 ++++++++ .../service/impl/CsDeviceServiceImpl.java | 10 +- .../impl/CsGatewayDeviceServiceImpl.java | 28 +++++ .../service/impl/CsGatewayServiceImpl.java | 116 ++++++++++++++++++ 20 files changed, 711 insertions(+), 14 deletions(-) create mode 100644 iot-access/access-api/src/main/java/com/njcn/access/param/WgDevRegisterParam.java create mode 100644 iot-access/access-api/src/main/java/com/njcn/access/param/WgDeviceRegisterParam.java create mode 100644 iot-access/access-api/src/main/java/com/njcn/access/param/WgRegisterParam.java create mode 100644 iot-access/access-api/src/main/java/com/njcn/access/pojo/po/CsGateway.java create mode 100644 iot-access/access-api/src/main/java/com/njcn/access/pojo/po/CsGatewayDevice.java create mode 100644 iot-access/access-api/src/main/java/com/njcn/access/pojo/vo/CsGatewayVo.java create mode 100644 iot-access/access-boot/src/main/java/com/njcn/access/controller/CsGatewayController.java create mode 100644 iot-access/access-boot/src/main/java/com/njcn/access/mapper/CsGatewayDeviceMapper.java create mode 100644 iot-access/access-boot/src/main/java/com/njcn/access/mapper/CsGatewayMapper.java create mode 100644 iot-access/access-boot/src/main/java/com/njcn/access/mapper/mapping/CsGatewayDeviceMapper.xml create mode 100644 iot-access/access-boot/src/main/java/com/njcn/access/mapper/mapping/CsGatewayMapper.xml create mode 100644 iot-access/access-boot/src/main/java/com/njcn/access/service/ICsGatewayDeviceService.java create mode 100644 iot-access/access-boot/src/main/java/com/njcn/access/service/ICsGatewayService.java create mode 100644 iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsGatewayDeviceServiceImpl.java create mode 100644 iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsGatewayServiceImpl.java diff --git a/iot-access/access-api/src/main/java/com/njcn/access/enums/AccessResponseEnum.java b/iot-access/access-api/src/main/java/com/njcn/access/enums/AccessResponseEnum.java index 48202ba..24e8a0a 100644 --- a/iot-access/access-api/src/main/java/com/njcn/access/enums/AccessResponseEnum.java +++ b/iot-access/access-api/src/main/java/com/njcn/access/enums/AccessResponseEnum.java @@ -14,7 +14,7 @@ public enum AccessResponseEnum { * A0301 ~ A0399 用于用户模块的枚举 *

*/ - NDID_NO_FIND("A0301", "nDid在平台端未找到或者已接入"), + NDID_NO_FIND("A0301", "nDid在平台端未找到或者已注册"), MODEL_REPEAT("A0302", "模板重复,请勿重复录入!"), MODEL_NO_FIND("A0302", "模板不存在,请先录入模板数据!"), @@ -24,6 +24,7 @@ public enum AccessResponseEnum { DEV_NOT_FIND("A0303","装置类型未找到!"), DEV_MODEL_NOT_FIND("A0303","装置型号未找到!"), DEV_IS_NOT_ZL("A0303","注册装置不是直连装置!"), + DEV_IS_NOT_WG("A0303","注册装置不是网关!"), REGISTER_RESPONSE_ERROR("A0304","装置注册,装置侧应答失败!"), diff --git a/iot-access/access-api/src/main/java/com/njcn/access/param/WgDevRegisterParam.java b/iot-access/access-api/src/main/java/com/njcn/access/param/WgDevRegisterParam.java new file mode 100644 index 0000000..feede77 --- /dev/null +++ b/iot-access/access-api/src/main/java/com/njcn/access/param/WgDevRegisterParam.java @@ -0,0 +1,32 @@ +package com.njcn.access.param; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * 类的介绍: + * + * @author xuyang + * @version 1.0.0 + * @createTime 2023/7/7 15:00 + */ +@Data +public class WgDevRegisterParam { + + @ApiModelProperty("网关id") + private String id; + + @Data + public static class Device { + + @ApiModelProperty("设备型号") + private String devModel; + + @ApiModelProperty("设备码") + private String lDid; + + + + + } +} diff --git a/iot-access/access-api/src/main/java/com/njcn/access/param/WgDeviceRegisterParam.java b/iot-access/access-api/src/main/java/com/njcn/access/param/WgDeviceRegisterParam.java new file mode 100644 index 0000000..87f6481 --- /dev/null +++ b/iot-access/access-api/src/main/java/com/njcn/access/param/WgDeviceRegisterParam.java @@ -0,0 +1,53 @@ +package com.njcn.access.param; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + * 类的介绍: + * + * @author xuyang + * @version 1.0.0 + * @createTime 2023/7/6 16:11 + */ +@Data +public class WgDeviceRegisterParam { + + @ApiModelProperty("网关id") + @NotNull(message = "网关id不能为空") + private String wgId; + + @ApiModelProperty("装置型号") + @NotNull(message = "装置型号不能为空") + private String devModel; + + @ApiModelProperty("did") + @NotNull(message = "did不能为空") + private String did; + + @ApiModelProperty("拓扑图id") + @NotNull(message = "拓扑图id不能为空") + private String topologyDiagram; + + @Data + public static class LineParam { + + @ApiModelProperty("监测点名称") + @NotNull(message = "监测点名称不能为空") + private String name; + + @ApiModelProperty("安装位置") + @NotNull(message = "安装位置不能为空") + private String position; + + @ApiModelProperty("中心点经度") + @NotNull(message = "中心点经度不能为空") + private Double lng; + + @ApiModelProperty("中心点纬度") + @NotNull(message = "中心点纬度不能为空") + private Double lat; + } +} diff --git a/iot-access/access-api/src/main/java/com/njcn/access/param/WgRegisterParam.java b/iot-access/access-api/src/main/java/com/njcn/access/param/WgRegisterParam.java new file mode 100644 index 0000000..dadb4e5 --- /dev/null +++ b/iot-access/access-api/src/main/java/com/njcn/access/param/WgRegisterParam.java @@ -0,0 +1,65 @@ +package com.njcn.access.param; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + * 类的介绍: + * + * @author xuyang + * @version 1.0.0 + * @createTime 2023/7/6 15:59 + */ +@Data +public class WgRegisterParam { + + @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; + + @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; + } + +} diff --git a/iot-access/access-api/src/main/java/com/njcn/access/pojo/po/CsGateway.java b/iot-access/access-api/src/main/java/com/njcn/access/pojo/po/CsGateway.java new file mode 100644 index 0000000..864aa8d --- /dev/null +++ b/iot-access/access-api/src/main/java/com/njcn/access/pojo/po/CsGateway.java @@ -0,0 +1,51 @@ +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; + +/** + *

+ * 网关表 + *

+ * + * @author xuyang + * @since 2023-07-06 + */ +@Data +@TableName("cs_gateway") +public class CsGateway extends BaseEntity { + + private static final long serialVersionUID = 1L; + + /** + * 网关id + */ + private String id; + + /** + * 项目id + */ + private String pid; + + /** + * 位置信息 + */ + private String area; + + /** + * 拓扑图id + */ + private String tid; + + /** + * 状态 0-删除;1-正常;默认正常 + */ + private Integer status; + +} diff --git a/iot-access/access-api/src/main/java/com/njcn/access/pojo/po/CsGatewayDevice.java b/iot-access/access-api/src/main/java/com/njcn/access/pojo/po/CsGatewayDevice.java new file mode 100644 index 0000000..f56e952 --- /dev/null +++ b/iot-access/access-api/src/main/java/com/njcn/access/pojo/po/CsGatewayDevice.java @@ -0,0 +1,32 @@ +package com.njcn.access.pojo.po; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.njcn.db.bo.BaseEntity; +import lombok.Data; + +/** + *

+ * 网关装置关系表 + *

+ * + * @author xuyang + * @since 2023-07-07 + */ +@Data +@TableName("cs_gateway_device") +public class CsGatewayDevice extends BaseEntity { + + private static final long serialVersionUID = 1L; + + /** + * 网关id + */ + private String id; + + /** + * 网关下设备id + */ + private String devId; + + +} diff --git a/iot-access/access-api/src/main/java/com/njcn/access/pojo/vo/CsGatewayVo.java b/iot-access/access-api/src/main/java/com/njcn/access/pojo/vo/CsGatewayVo.java new file mode 100644 index 0000000..ecfc6fc --- /dev/null +++ b/iot-access/access-api/src/main/java/com/njcn/access/pojo/vo/CsGatewayVo.java @@ -0,0 +1,50 @@ +package com.njcn.access.pojo.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + * 类的介绍: + * + * @author xuyang + * @version 1.0.0 + * @createTime 2023/7/7 9:09 + */ +@Data +public class CsGatewayVo { + + @ApiModelProperty("网关id") + private String id; + + @ApiModelProperty("网关名称") + private String wgName; + + @ApiModelProperty("项目名称") + private String proName; + + @ApiModelProperty("设备型号") + private String devModel; + + @ApiModelProperty("型号版本") + private String programVersion; + + @ApiModelProperty("拓扑图") + private String filePath; + + @ApiModelProperty("设备集合") + private List list; + + @Data + public static class Device { + + @ApiModelProperty("设备名称") + private String devName; + + @ApiModelProperty("项目名称") + private String proName; + } + + +} diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/controller/CsDeviceController.java b/iot-access/access-boot/src/main/java/com/njcn/access/controller/CsDeviceController.java index e6031ad..7863bf0 100644 --- a/iot-access/access-boot/src/main/java/com/njcn/access/controller/CsDeviceController.java +++ b/iot-access/access-boot/src/main/java/com/njcn/access/controller/CsDeviceController.java @@ -35,7 +35,7 @@ public class CsDeviceController extends BaseController { @OperateInfo(info = LogEnum.BUSINESS_COMMON) @PostMapping("/register") - @ApiOperation("设备注册") + @ApiOperation("直连设备注册") @ApiImplicitParam(name = "nDid", value = "设备识别码", required = true) public HttpResult devRegister(@RequestParam String nDid){ csDeviceService.devRegister(nDid); @@ -44,7 +44,7 @@ public class CsDeviceController extends BaseController { @OperateInfo(info = LogEnum.BUSINESS_COMMON) @PostMapping("/model") - @ApiOperation("获取装置模板信息") + @ApiOperation("获取直连设备模板信息") @ApiImplicitParam(name = "nDid", value = "设备识别码", required = true) public HttpResult getModel(@RequestParam String nDid){ String methodDescribe = getMethodDescribe("getModel"); @@ -54,12 +54,11 @@ public class CsDeviceController extends BaseController { @OperateInfo(info = LogEnum.BUSINESS_COMMON) @PostMapping("/access") - @ApiOperation("设备接入") + @ApiOperation("直连设备接入") @ApiImplicitParam(name = "devAccessParam", value = "接入参数", required = true) public HttpResult devAccess(@RequestBody @Validated DevAccessParam devAccessParam){ String methodDescribe = getMethodDescribe("getModel"); csDeviceService.devAccess(devAccessParam); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); } - } diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/controller/CsGatewayController.java b/iot-access/access-boot/src/main/java/com/njcn/access/controller/CsGatewayController.java new file mode 100644 index 0000000..265b984 --- /dev/null +++ b/iot-access/access-boot/src/main/java/com/njcn/access/controller/CsGatewayController.java @@ -0,0 +1,92 @@ +package com.njcn.access.controller; + + +import com.njcn.access.param.WgDeviceRegisterParam; +import com.njcn.access.param.WgRegisterParam; +import com.njcn.access.pojo.vo.CsGatewayVo; +import com.njcn.access.service.ICsGatewayService; +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.*; + +import java.util.List; + +/** + *

+ * 网关表 前端控制器 + *

+ * + * @author xuyang + * @since 2023-07-06 + */ +@Slf4j +@RestController +@RequestMapping("/csGateway") +@Api(tags = "治理网关信息") +@AllArgsConstructor +@Validated +public class CsGatewayController extends BaseController { + + private final ICsGatewayService csGatewayService; + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/wgRegister") + @ApiOperation("网关注册1") + @ApiImplicitParam(name = "nDid", value = "设备识别码", required = true) + public HttpResult wgRegister(@RequestParam String nDid){ + String methodDescribe = getMethodDescribe("wgRegister"); + csGatewayService.wgRegister(nDid); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/wgRegister2") + @ApiOperation("网关注册2") + @ApiImplicitParam(name = "wgRegisterParam", value = "网关注册参数", required = true) + public HttpResult wgRegister2(@RequestBody @Validated WgRegisterParam wgRegisterParam){ + String methodDescribe = getMethodDescribe("wgRegister2"); + csGatewayService.wgRegister2(wgRegisterParam); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/findList") + @ApiOperation("网关列表") + public HttpResult> findList(){ + String methodDescribe = getMethodDescribe("findList"); + List list = csGatewayService.getWgList(); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe); + } + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/findById") + @ApiOperation("网关详情") + @ApiImplicitParam(name = "wgId", value = "网关注册参数", required = true) + public HttpResult findById(@RequestParam String wgId){ + String methodDescribe = getMethodDescribe("findById"); + CsGatewayVo vo = csGatewayService.findById(wgId); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, vo, methodDescribe); + } + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/registerByWg") + @ApiOperation("网关下设备注册") + @ApiImplicitParam(name = "list", value = "网关下设备注册参数集合", required = true) + public HttpResult registerByWg(@RequestBody @Validated List list){ + String methodDescribe = getMethodDescribe("registerByWg"); + csGatewayService.registerByWg(list); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } + +} + diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/handler/MqttMessageHandler.java b/iot-access/access-boot/src/main/java/com/njcn/access/handler/MqttMessageHandler.java index a7775f6..d868505 100644 --- a/iot-access/access-boot/src/main/java/com/njcn/access/handler/MqttMessageHandler.java +++ b/iot-access/access-boot/src/main/java/com/njcn/access/handler/MqttMessageHandler.java @@ -108,7 +108,8 @@ public class MqttMessageHandler { ReqAndResDto.Res res = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), ReqAndResDto.Res.class); if (Objects.equals(res.getCode(),AccessEnum.SUCCESS.getCode())){ if (Objects.equals(res.getType(),TypeEnum.TYPE_17.getCode())){ - equipmentFeignClient.updateStatusBynDid(nDid, AccessEnum.REGISTERED.getCode()); + //这边用redis缓存来判断是否接收响应 + redisUtil.saveByKeyWithExpire(nDid,AccessEnum.SUCCESS.getCode(),600L); //询问模板数据 ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req(); reqAndResParam.setMid(1); @@ -117,8 +118,6 @@ public class MqttMessageHandler { reqAndResParam.setType(TypeEnum.TYPE_3.getCode()); reqAndResParam.setExpire(-1); publisher.send("/Pfm/DevCmd/V1/"+nDid,new Gson().toJson(reqAndResParam),1,false); - //这边用redis缓存来判断是否接收响应 - redisUtil.saveByKey(nDid,AccessEnum.SUCCESS.getCode()); } else { log.info(AccessResponseEnum.MESSAGE_TYPE_ERROR.getMessage()); } @@ -160,13 +159,12 @@ public class MqttMessageHandler { List lineList = csLineModelService.getMonitorNumByModelId(modelId); String key = "LINE" + nDid; //存储监测点模板信息,用于界面回显 - redisUtil.saveByKey(key,lineList); + redisUtil.saveByKeyWithExpire(key,lineList,600L); //存储模板id //todo 这边也是要调整的 String key2 = "MODEL" + nDid; - redisUtil.saveByKey(key2,modelId); + redisUtil.saveByKeyWithExpire(key2,modelId,600L); redisUtil.delete(nDid); - } diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/mapper/CsGatewayDeviceMapper.java b/iot-access/access-boot/src/main/java/com/njcn/access/mapper/CsGatewayDeviceMapper.java new file mode 100644 index 0000000..b1bd9ad --- /dev/null +++ b/iot-access/access-boot/src/main/java/com/njcn/access/mapper/CsGatewayDeviceMapper.java @@ -0,0 +1,23 @@ +package com.njcn.access.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.njcn.access.pojo.po.CsGatewayDevice; +import com.njcn.access.pojo.vo.CsGatewayVo; +import com.njcn.csdevice.pojo.po.CsEquipmentAlarmPO; +import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO; + +import java.util.List; + +/** + *

+ * 网关装置关系表 Mapper 接口 + *

+ * + * @author xuyang + * @since 2023-07-07 + */ +public interface CsGatewayDeviceMapper extends BaseMapper { + + List getList(String id); + +} diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/mapper/CsGatewayMapper.java b/iot-access/access-boot/src/main/java/com/njcn/access/mapper/CsGatewayMapper.java new file mode 100644 index 0000000..629e846 --- /dev/null +++ b/iot-access/access-boot/src/main/java/com/njcn/access/mapper/CsGatewayMapper.java @@ -0,0 +1,24 @@ +package com.njcn.access.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.njcn.access.pojo.po.CsGateway; +import com.njcn.access.pojo.vo.CsGatewayVo; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + *

+ * 网关表 Mapper 接口 + *

+ * + * @author xuyang + * @since 2023-07-06 + */ +public interface CsGatewayMapper extends BaseMapper { + + List getWgList(@Param("userId") String userId); + + CsGatewayVo findById(@Param("id") String id); +} diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/mapper/mapping/CsGatewayDeviceMapper.xml b/iot-access/access-boot/src/main/java/com/njcn/access/mapper/mapping/CsGatewayDeviceMapper.xml new file mode 100644 index 0000000..19bed21 --- /dev/null +++ b/iot-access/access-boot/src/main/java/com/njcn/access/mapper/mapping/CsGatewayDeviceMapper.xml @@ -0,0 +1,14 @@ + + + + + + + \ No newline at end of file diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/mapper/mapping/CsGatewayMapper.xml b/iot-access/access-boot/src/main/java/com/njcn/access/mapper/mapping/CsGatewayMapper.xml new file mode 100644 index 0000000..dcf5a04 --- /dev/null +++ b/iot-access/access-boot/src/main/java/com/njcn/access/mapper/mapping/CsGatewayMapper.xml @@ -0,0 +1,34 @@ + + + + + + + + \ No newline at end of file diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsDeviceService.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsDeviceService.java index 45afbc6..25eae19 100644 --- a/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsDeviceService.java +++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsDeviceService.java @@ -1,6 +1,8 @@ package com.njcn.access.service; import com.njcn.access.param.DevAccessParam; +import com.njcn.access.param.WgDeviceRegisterParam; +import com.njcn.access.param.WgRegisterParam; /** * 类的介绍: @@ -29,5 +31,4 @@ public interface ICsDeviceService { * @param devAccessParam */ void devAccess(DevAccessParam devAccessParam); - } diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsGatewayDeviceService.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsGatewayDeviceService.java new file mode 100644 index 0000000..9ed85d4 --- /dev/null +++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsGatewayDeviceService.java @@ -0,0 +1,27 @@ +package com.njcn.access.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.njcn.access.pojo.po.CsGatewayDevice; +import com.njcn.csdevice.pojo.po.CsEquipmentAlarmPO; +import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO; + +import java.util.List; + +/** + *

+ * 网关装置关系表 服务类 + *

+ * + * @author xuyang + * @since 2023-07-07 + */ +public interface ICsGatewayDeviceService extends IService { + + /** + * 根据网关id获取网关下装置的信息 + * @param id + * @return + */ + List getList(String id); + +} diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsGatewayService.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsGatewayService.java new file mode 100644 index 0000000..43f3b90 --- /dev/null +++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/ICsGatewayService.java @@ -0,0 +1,51 @@ +package com.njcn.access.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.njcn.access.param.WgDeviceRegisterParam; +import com.njcn.access.param.WgRegisterParam; +import com.njcn.access.pojo.po.CsGateway; +import com.njcn.access.pojo.vo.CsGatewayVo; + +import java.util.List; + +/** + *

+ * 网关表 服务类 + *

+ * + * @author xuyang + * @since 2023-07-06 + */ +public interface ICsGatewayService extends IService { + + /** + * 网关注册 + * @param nDid 设备识别码 + */ + void wgRegister(String nDid); + + /** + * 网关ndid校验成功后,添加网关信息 + * @param wgRegisterParam + */ + void wgRegister2(WgRegisterParam wgRegisterParam); + + /** + * 查询用户下的网关 + * @return + */ + List getWgList(); + + /** + * 查询具体网关信息 + * @return + */ + CsGatewayVo findById(String id); + + /** + * 网关下设备注册 + * @param list + */ + void registerByWg(List list); + +} diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDeviceServiceImpl.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDeviceServiceImpl.java index 61eabf0..017bc02 100644 --- a/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDeviceServiceImpl.java +++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsDeviceServiceImpl.java @@ -1,14 +1,19 @@ package com.njcn.access.service.impl; import cn.hutool.core.util.IdUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.github.tocrhz.mqtt.publisher.MqttPublisher; import com.njcn.access.enums.AccessEnum; import com.njcn.access.enums.AccessResponseEnum; import com.njcn.access.enums.TypeEnum; import com.njcn.access.param.DevAccessParam; +import com.njcn.access.param.WgDeviceRegisterParam; +import com.njcn.access.param.WgRegisterParam; import com.njcn.access.pojo.dto.AccessDto; import com.njcn.access.pojo.dto.ReqAndResDto; +import com.njcn.access.pojo.po.CsGateway; import com.njcn.access.service.ICsDeviceService; +import com.njcn.access.service.ICsGatewayService; import com.njcn.common.pojo.enums.response.CommonResponseEnum; import com.njcn.common.pojo.exception.BusinessException; import com.njcn.common.utils.PubUtils; @@ -66,6 +71,8 @@ public class CsDeviceServiceImpl implements ICsDeviceService { private final CsDeviceUserFeignClient csDeviceUserFeignClient; + private final ICsGatewayService csGatewayService; + private final MqttPublisher publisher; private final RedisUtil redisUtil; @@ -177,7 +184,7 @@ public class CsDeviceServiceImpl implements ICsDeviceService { devModelRelationFeignClient.addDevModelRelation(csDevModelRelationAddParm); redisUtil.delete("MODEL" + devAccessParam.getNDid()); //5.修改装置状态 - equipmentFeignClient.updateStatusBynDid(devAccessParam.getNDid(), AccessEnum.ACCESS.getCode()); + equipmentFeignClient.updateStatusBynDid(devAccessParam.getNDid(), AccessEnum.REGISTERED.getCode()); //6.设置心跳时间,超时改为掉线 redisUtil.saveByKeyWithExpire("MQTT:" + devAccessParam.getNDid(), Instant.now().toEpochMilli(),180L); //7.绑定装置和人的关系 @@ -194,7 +201,6 @@ public class CsDeviceServiceImpl implements ICsDeviceService { } } - public void zhiLianRegister(String nDid,String devType) { ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req(); reqAndResParam.setMid(1); diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsGatewayDeviceServiceImpl.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsGatewayDeviceServiceImpl.java new file mode 100644 index 0000000..9d03d62 --- /dev/null +++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsGatewayDeviceServiceImpl.java @@ -0,0 +1,28 @@ +package com.njcn.access.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.njcn.access.mapper.CsGatewayDeviceMapper; +import com.njcn.access.pojo.po.CsGatewayDevice; +import com.njcn.access.service.ICsGatewayDeviceService; +import com.njcn.csdevice.pojo.po.CsEquipmentAlarmPO; +import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + *

+ * 网关装置关系表 服务实现类 + *

+ * + * @author xuyang + * @since 2023-07-07 + */ +@Service +public class CsGatewayDeviceServiceImpl extends ServiceImpl implements ICsGatewayDeviceService { + + @Override + public List getList(String id) { + return this.baseMapper.getList(id); + } +} diff --git a/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsGatewayServiceImpl.java b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsGatewayServiceImpl.java new file mode 100644 index 0000000..302893c --- /dev/null +++ b/iot-access/access-boot/src/main/java/com/njcn/access/service/impl/CsGatewayServiceImpl.java @@ -0,0 +1,116 @@ +package com.njcn.access.service.impl; + +import cn.hutool.core.collection.CollectionUtil; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.njcn.access.enums.AccessEnum; +import com.njcn.access.enums.AccessResponseEnum; +import com.njcn.access.mapper.CsGatewayMapper; +import com.njcn.access.param.WgDeviceRegisterParam; +import com.njcn.access.param.WgRegisterParam; +import com.njcn.access.pojo.po.CsGateway; +import com.njcn.access.pojo.vo.CsGatewayVo; +import com.njcn.access.service.ICsGatewayDeviceService; +import com.njcn.access.service.ICsGatewayService; +import com.njcn.common.pojo.exception.BusinessException; +import com.njcn.csdevice.api.EquipmentFeignClient; +import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO; +import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO; +import com.njcn.oss.utils.FileStorageUtil; +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.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +/** + *

+ * 网关表 服务实现类 + *

+ * + * @author xuyang + * @since 2023-07-06 + */ +@Service +@AllArgsConstructor +public class CsGatewayServiceImpl extends ServiceImpl implements ICsGatewayService { + + private final FileStorageUtil fileStorageUtil; + + private final EquipmentFeignClient equipmentFeignClient; + + private final DictTreeFeignClient dictTreeFeignClient; + + private final ICsGatewayDeviceService csGatewayDeviceService; + + @Override + public void wgRegister(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.GATEWAY_DEV.getCode())){ + throw new BusinessException(AccessResponseEnum.DEV_IS_NOT_WG); + } + } + + @Override + @Transactional(rollbackFor = {Exception.class}) + public void wgRegister2(WgRegisterParam wgRegisterParam) { + CsEquipmentDeliveryVO csEquipmentDeliveryVO = equipmentFeignClient.queryEquipmentByndid(wgRegisterParam.getNDid()).getData(); + CsGateway csGateway = new CsGateway(); + csGateway.setId(csEquipmentDeliveryVO.getId()); + csGateway.setPid(wgRegisterParam.getProjectId()); + csGateway.setArea(wgRegisterParam.getArea()); + csGateway.setTid(wgRegisterParam.getTopologyDiagram()); + csGateway.setStatus(1); + this.save(csGateway); + equipmentFeignClient.updateStatusBynDid(wgRegisterParam.getNDid(), AccessEnum.REGISTERED.getCode()); + } + + + @Override + public List getWgList() { + return this.baseMapper.getWgList(RequestUtil.getUserIndex()); + } + + @Override + public CsGatewayVo findById(String id) { + CsGatewayVo vo = this.baseMapper.findById(id); + vo.setFilePath (fileStorageUtil.getFileUrl (vo.getFilePath())); + List list = csGatewayDeviceService.getList(id); + List devList = new ArrayList<>(); + if (CollectionUtil.isNotEmpty(list)){ + list.forEach(item->{ + CsGatewayVo.Device pojo = new CsGatewayVo.Device(); + pojo.setDevName(item.getName()); + pojo.setProName(vo.getProName()); + devList.add(pojo); + }); + } + vo.setList(devList); + return vo; + } + + @Override + public void registerByWg(List list) { + list.forEach(item->{ + + + }); + + + } +}