From b341ebb2bc1b0feecf3ff746fa70045fc2c95a53 Mon Sep 17 00:00:00 2001 From: chenhaojie Date: Fri, 5 Jul 2024 10:55:30 +0800 Subject: [PATCH 1/6] =?UTF-8?q?das=E6=8E=A5=E5=8F=A3=E6=96=B0=E5=A2=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/das/modules/auth/entity/SysOrg.java | 5 +- .../controller/EquipmentController.java | 26 +++++- .../domain/excel/SysEquipmentExcel.java | 91 +++++++++++++++++++ .../equipment/mapper/SysEquipmentMapper.java | 8 ++ .../service/SysEquipmentService.java | 4 + .../service/impl/SysEquipmentServiceImpl.java | 50 +++++++++- .../resources/mapper/SysEquipmentMapper.xml | 47 ++++++++++ 7 files changed, 227 insertions(+), 4 deletions(-) create mode 100644 das/src/main/java/com/das/modules/equipment/domain/excel/SysEquipmentExcel.java diff --git a/das/src/main/java/com/das/modules/auth/entity/SysOrg.java b/das/src/main/java/com/das/modules/auth/entity/SysOrg.java index cd4ee878..4c9bf54e 100644 --- a/das/src/main/java/com/das/modules/auth/entity/SysOrg.java +++ b/das/src/main/java/com/das/modules/auth/entity/SysOrg.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.das.common.constant.BaseEntity; +import com.das.modules.equipment.entity.SysEquipment; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import lombok.AllArgsConstructor; @@ -102,8 +103,8 @@ public class SysOrg extends BaseEntity { private String aliasName; /** - * 子节点 + * 子设备节点 */ @TableField(exist = false) - private List children; + private List equipChildren; } diff --git a/das/src/main/java/com/das/modules/equipment/controller/EquipmentController.java b/das/src/main/java/com/das/modules/equipment/controller/EquipmentController.java index d592710e..b3651c9e 100644 --- a/das/src/main/java/com/das/modules/equipment/controller/EquipmentController.java +++ b/das/src/main/java/com/das/modules/equipment/controller/EquipmentController.java @@ -8,9 +8,12 @@ import com.das.common.result.R; import com.das.common.utils.PageDataInfo; import com.das.modules.auth.entity.SysOrg; import com.das.modules.equipment.domain.dto.SysEquipmentDto; +import com.das.modules.equipment.domain.dto.SysIotModelDto; import com.das.modules.equipment.domain.vo.EquipmentTypeVo; import com.das.modules.equipment.domain.vo.SysEquipmentVo; import com.das.modules.equipment.service.SysEquipmentService; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; @@ -110,15 +113,36 @@ public class EquipmentController { return sysEquipmentService.querySysEquipmentList(sysEquipmentDto); } + /** + * 查询设备类型列表 + * @return 所有的设备类型 + */ + @PostMapping("/list") + public R> queryAllSysEquipmentList(@RequestBody SysEquipmentDto sysEquipmentDto) { + return R.success(sysEquipmentService.queryAllSysEquipmentList(sysEquipmentDto)); + } + /** * 查询设备树 * @return 所有的设备类型 */ - @PostMapping("/getDeviceTree") + @PostMapping("/getEquipmentTree") public R> getRootOrg(@RequestBody SysEquipmentDto sysEquipmentDto) { if (sysEquipmentDto.getOrgId() == null) { throw new ServiceException("参数缺失"); } return R.success(sysEquipmentService.getRootOrg(sysEquipmentDto)); } + + + /** 设备导出 */ + @PostMapping("/export") + public void exportSysEquipment(@RequestBody SysEquipmentDto sysEquipmentDto, HttpServletRequest request, HttpServletResponse response) { + + if (sysEquipmentDto.getParentEquipmentId() == null) { + throw new ServiceException("请选择需要下载的设备类型信息"); + } + sysEquipmentService.exportSysEquipment(sysEquipmentDto,request, response); + + } } diff --git a/das/src/main/java/com/das/modules/equipment/domain/excel/SysEquipmentExcel.java b/das/src/main/java/com/das/modules/equipment/domain/excel/SysEquipmentExcel.java new file mode 100644 index 00000000..200c7bf3 --- /dev/null +++ b/das/src/main/java/com/das/modules/equipment/domain/excel/SysEquipmentExcel.java @@ -0,0 +1,91 @@ +package com.das.modules.equipment.domain.excel; + +import com.alibaba.excel.annotation.ExcelProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import lombok.Data; + +import java.util.Date; + +@Data +public class SysEquipmentExcel { + + /** + * 设备类型编码 + */ + @ExcelProperty(value = "设备类型编码",index = 0) + private Integer objectType; + + /** + * 所属物模型ID + */ + @ExcelProperty(value = "所属物模型名称",index = 1) + private String iotModelName; + + /** + * 设备编码 + */ + @ExcelProperty(value = "设备编码",index = 2) + private String code; + + /** + * 设备名称 + */ + @ExcelProperty(value = "设备名称",index = 3) + private String name; + + /** + * 制造商 + */ + @ExcelProperty(value = "制造商",index = 4) + private String madeinFactory; + + /** + * 型号规格 + */ + @ExcelProperty(value = "型号规格",index = 5) + private String model; + + /** + * 安装位置 + */ + @ExcelProperty(value = "安装位置",index = 6) + private String location; + + /** + * 安装位置_经度 + */ + @ExcelProperty(value = "安装位置_经度",index = 7) + private float longitude; + + /** + * 安装位置_纬度 + */ + @ExcelProperty(value = "安装位置_纬度",index = 8) + private float latitude; + + /** + * 安装日期 + */ + @ExcelProperty(value = "安装日期",index = 9) + private Date installDate; + + /** + * 备注 + */ + @ExcelProperty(value = "备注",index = 10) + private String remarks; + + /** + * 机构id + */ + @ExcelProperty(value = "机构名称",index = 11) + private String orgName; + + /** + * 上级设备id + */ + @ExcelProperty(value = "上级设备名称",index = 12) + private String parentEquipmentName; + +} diff --git a/das/src/main/java/com/das/modules/equipment/mapper/SysEquipmentMapper.java b/das/src/main/java/com/das/modules/equipment/mapper/SysEquipmentMapper.java index a9daf69b..bcbdc9bb 100644 --- a/das/src/main/java/com/das/modules/equipment/mapper/SysEquipmentMapper.java +++ b/das/src/main/java/com/das/modules/equipment/mapper/SysEquipmentMapper.java @@ -4,15 +4,23 @@ package com.das.modules.equipment.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.das.modules.equipment.domain.dto.SysEquipmentDto; +import com.das.modules.equipment.domain.dto.SysIotModelDto; import com.das.modules.equipment.domain.dto.SysIotModelFieldDto; +import com.das.modules.equipment.domain.excel.SysEquipmentExcel; import com.das.modules.equipment.domain.vo.SysEquipmentVo; import com.das.modules.equipment.domain.vo.SysIotModelFieldVo; import com.das.modules.equipment.entity.SysEquipment; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import java.util.List; + @Mapper public interface SysEquipmentMapper extends BaseMapper { IPage querySysEquipmentList(IPage page, @Param("info") SysEquipmentDto sysEquipmentDto); + + List queryEquipmentTree(@Param("info")SysEquipmentDto sysEquipmentDto); + + List queryInfoById (@Param("info") SysEquipmentDto sysEquipmentDto); } diff --git a/das/src/main/java/com/das/modules/equipment/service/SysEquipmentService.java b/das/src/main/java/com/das/modules/equipment/service/SysEquipmentService.java index 278561d9..82fe5cfb 100644 --- a/das/src/main/java/com/das/modules/equipment/service/SysEquipmentService.java +++ b/das/src/main/java/com/das/modules/equipment/service/SysEquipmentService.java @@ -24,6 +24,10 @@ public interface SysEquipmentService { PageDataInfo querySysEquipmentList(SysEquipmentDto sysEquipmentDto); + List queryAllSysEquipmentList(SysEquipmentDto sysEquipmentDto); + List getRootOrg(SysEquipmentDto sysEquipmentDto); + void exportSysEquipment(SysEquipmentDto sysEquipmentDto, HttpServletRequest request, HttpServletResponse response); + } diff --git a/das/src/main/java/com/das/modules/equipment/service/impl/SysEquipmentServiceImpl.java b/das/src/main/java/com/das/modules/equipment/service/impl/SysEquipmentServiceImpl.java index 2068867c..01b8434b 100644 --- a/das/src/main/java/com/das/modules/equipment/service/impl/SysEquipmentServiceImpl.java +++ b/das/src/main/java/com/das/modules/equipment/service/impl/SysEquipmentServiceImpl.java @@ -6,11 +6,18 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.das.common.config.SessionUtil; import com.das.common.exceptions.ServiceException; import com.das.common.utils.BeanCopyUtils; +import com.das.common.utils.ExcelUtil; import com.das.common.utils.PageDataInfo; import com.das.common.utils.PageQuery; import com.das.modules.auth.domain.vo.SysUserVo; import com.das.modules.auth.entity.SysOrg; +import com.das.modules.auth.mapper.SysOrgMapper; import com.das.modules.equipment.domain.dto.SysEquipmentDto; +import com.das.modules.equipment.domain.dto.SysIotModelDto; +import com.das.modules.equipment.domain.excel.SheetInfoBean; +import com.das.modules.equipment.domain.excel.SysEquipmentExcel; +import com.das.modules.equipment.domain.excel.SysIotModelFieldExcel; +import com.das.modules.equipment.domain.excel.SysIotModelServiceExcel; import com.das.modules.equipment.domain.vo.SysEquipmentVo; import com.das.modules.equipment.domain.vo.SysIotModelServiceVo; import com.das.modules.equipment.domain.vo.SysIotModelVo; @@ -19,10 +26,13 @@ import com.das.modules.equipment.entity.SysIotModel; import com.das.modules.equipment.mapper.SysEquipmentMapper; import com.das.modules.equipment.mapper.SysIotModelMapper; import com.das.modules.equipment.service.SysEquipmentService; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -32,6 +42,9 @@ public class SysEquipmentServiceImpl implements SysEquipmentService { @Autowired private SysEquipmentMapper sysEquipmentMapper; + + @Autowired + private SysOrgMapper sysOrgMapper; @Override public SysEquipmentVo creatSysEquipment(SysEquipmentDto sysEquipmentDto) { SysEquipment sysEquipment = new SysEquipment(); @@ -79,8 +92,43 @@ public class SysEquipmentServiceImpl implements SysEquipmentService { return PageDataInfo.build(iPage.getRecords(), iPage.getTotal()); } + @Override + public List queryAllSysEquipmentList(SysEquipmentDto sysEquipmentDto) { + // 查询当前账号机构下的子机构和子设备 + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("org_id", sysEquipmentDto.getOrgId()); + queryWrapper.eq("parent_equipment_id", sysEquipmentDto.getParentEquipmentId()); + queryWrapper.eq("object_type", sysEquipmentDto.getObjectType()); + List sysEquipmentList = sysEquipmentMapper.selectList(queryWrapper); + List list = new ArrayList<>(); + list.addAll(BeanCopyUtils.copyList(sysEquipmentList, SysEquipmentVo.class)); + return list; + } + @Override public List getRootOrg(SysEquipmentDto sysEquipmentDto) { - return null; + // 查询当前账号机构下的子机构和子设备 + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("id", sysEquipmentDto.getOrgId()); + List sysOrgList = sysOrgMapper.selectList(queryWrapper); + if (sysOrgList.size() == 0) { + throw new ServiceException("机构不存在"); + } + for (SysOrg sysOrg : sysOrgList) { + sysOrg.setEquipChildren(sysEquipmentMapper.queryEquipmentTree(sysEquipmentDto)); + } + + return sysOrgList; + } + + @Override + public void exportSysEquipment(SysEquipmentDto sysEquipmentDto, HttpServletRequest request, HttpServletResponse response) { + // 查询物模型属性和动作 + List sysEquipmentList = sysEquipmentMapper.queryInfoById(sysEquipmentDto); + String fileName = "设备类型信息表"; + List sheetInfoBeanList = new ArrayList<>(); + SheetInfoBean sheetInfoBean = new SheetInfoBean("设备类型信息", SysEquipmentExcel.class, sysEquipmentList); + sheetInfoBeanList.add(sheetInfoBean); + ExcelUtil.exportMoreSheet(fileName,request,response,sheetInfoBeanList); } } diff --git a/das/src/main/resources/mapper/SysEquipmentMapper.xml b/das/src/main/resources/mapper/SysEquipmentMapper.xml index beb964ae..1c742ef2 100644 --- a/das/src/main/resources/mapper/SysEquipmentMapper.xml +++ b/das/src/main/resources/mapper/SysEquipmentMapper.xml @@ -19,6 +19,23 @@ + + + + + + + + + + + + + + + + + + + + + + + From 4eb3c3caa8441c0adb03a2d99c1de2d7f0dcae4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=B7=E6=88=90=E4=BC=9F?= Date: Fri, 5 Jul 2024 13:42:46 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E6=96=87=E6=A1=A3=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/datacollect/README.md | 87 +++++++++++++++++++++++++++----------- 1 file changed, 62 insertions(+), 25 deletions(-) diff --git a/docs/datacollect/README.md b/docs/datacollect/README.md index 7d0433be..a89ec5d5 100644 --- a/docs/datacollect/README.md +++ b/docs/datacollect/README.md @@ -152,8 +152,8 @@ PS: 同一节点只允许建立一条连接。 **数据体:** ```json { - //设备ID - "12351235213":{ + "deviceId": "1123451235464", + "values": { //设备完整初始数据 "Ia": 123.1, "Ib": 122.1, @@ -162,22 +162,12 @@ PS: 同一节点只允许建立一条连接。 "Ub": 221.4, "Uc": 223.1, "Switch01": 1 - }, - "12351235214":{ - //设备完整初始数据 - "Ia": 122.1, - "Ib": 123.1, - "Ic": 121.1, - "Ua": 224.3, - "Ub": 223.4, - "Uc": 223.1, - "Switch01": 0 } } -```` +``` -### 模拟量上报 +### 模拟量数据上报 ?> 方向: `采集程序` -> `系统` @@ -186,33 +176,80 @@ PS: 同一节点只允许建立一条连接。 **数据体:** ```json { - //key为设备ID - "1123451235": { + //数据时间(毫秒) + "dataTime": 123123123123, + //设备ID + "deviceId": "1123451235464", + "values": { //key为属性名 "Ia": 123.1, "Ib": 122.1, "Ic": 123.1 - }, - "351235123" : { - "P" : 1213.1, - "Q" : 123.1 } } ``` -### 状态量上报 +### 状态量数据上报 ?> 方向: `采集程序` -> `系统` -**命令:** `discreteData` +**命令:** `stateData` **数据体:** ```json { - //key为设备ID - "1123451235": { + //数据时间(毫秒) + "dataTime": 123123123123, + //设备ID + "deviceId": "1123451235464", + "values": { //key为属性名 "Switch01": 1 - }, + } } ``` + +### 历史模拟量数据上报 + +?> 方向: `采集程序` -> `系统` + +**命令:** `historyAnalogData` + +**数据体:** + +```json +{ + //数据时间(毫秒) + "dataTime": 123123123123, + //设备ID + "deviceId": "1123451235464", + "values": { + //key为属性名 + "Ia": 123.1, + "Ib": 122.1, + "Ic": 123.1 + } +} +``` + + +### 历史状态量数据上报 + +?> 方向: `采集程序` -> `系统` + +**命令:** `historyStateData` + +**数据体:** + +```json +{ + //数据时间(毫秒) + "dataTime": 123123123123, + //设备ID + "deviceId": "1123451235464", + "values": { + //key为属性名 + "Switch01": 1 + } +} +``` \ No newline at end of file From 9e862a643944bce00a37819d2f750d83d9897cdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=B7=E6=88=90=E4=BC=9F?= Date: Fri, 5 Jul 2024 13:57:12 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E6=96=87=E6=A1=A3=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/datacollect/README.md | 42 +++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/docs/datacollect/README.md b/docs/datacollect/README.md index a89ec5d5..965f0a17 100644 --- a/docs/datacollect/README.md +++ b/docs/datacollect/README.md @@ -252,4 +252,44 @@ PS: 同一节点只允许建立一条连接。 "Switch01": 1 } } -``` \ No newline at end of file +``` + +### 遥控/遥调命令请求 + +?> 方向: `系统` -> `采集程序` + +**命令:** `deviceControl` + +**数据体:** + +```json +{ + //设备ID + "deviceId": "1123451235464", + //遥控服务名 + "serviceName": "start", + //操作值 + "opValue": 1 +} +``` + +### 遥控/遥调命令响应 + +?> 方向: `采集程序` -> `系统` + +**命令:** `deviceControlResp` + +**数据体:** + +```json +{ + //操作结果 + "result": true, + //设备ID + "deviceId": "1123451235464", + //遥控服务名 + "serviceName": "start", + //操作值 + "opValue": 1 +} +``` From 60a908acac142533b313c74ce8087111d719864e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=B7=E6=88=90=E4=BC=9F?= Date: Fri, 5 Jul 2024 14:06:30 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=89=88=E6=9C=AC=20=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/datacollect/README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/datacollect/README.md b/docs/datacollect/README.md index 965f0a17..82a86c3f 100644 --- a/docs/datacollect/README.md +++ b/docs/datacollect/README.md @@ -92,7 +92,10 @@ 采集程序建立连接时,需要带上自身节点ID,连接URL如下所示: -`ws://127.0.0.1:7790/gate/{nodeId}` +`ws://127.0.0.1:7790/gate/{nodeId}/{version}` + +* `nodeId`: 采集节点ID +* `version`: 采集节点配置版本号 PS: 同一节点只允许建立一条连接。 From 8da34f87e13ae713ad2399b57027a5b850848f2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=B7=E6=88=90=E4=BC=9F?= Date: Fri, 5 Jul 2024 14:35:55 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/datacollect/README.md | 78 +++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/docs/datacollect/README.md b/docs/datacollect/README.md index 82a86c3f..c3a51f9e 100644 --- a/docs/datacollect/README.md +++ b/docs/datacollect/README.md @@ -1,12 +1,48 @@ # 数据采集 -## 采集配置说明 +## 采集程序与系统交互通道 -采集程序配置存放在: `/das/conf/collector.json` +采集程序与系统间采用Websocket方式通讯, 访问系统服务器端口: 7790 -如果系统配置更新将生成配置更新文件: `/das/conf/collector.json.update`。 +报文格式为`json`, 字符集: `utf-8`。 -配置文件内容如下: +### 通道建立 + +采集程序建立连接时,需要带上自身节点ID,连接URL如下所示: + +`ws://127.0.0.1:7790/gate/{nodeId}/{version}` + +* `nodeId`: 采集节点ID +* `version`: 采集节点配置版本号,无配置时为0 + +建立连接后,当{version}为0时,或者{version}比系统中的版本低时,会主动推送配置更新命令。 + +PS: 同一节点只允许建立一条连接。 + +## 通讯报文 + +### 报文格式 + +```json +{ + //命令 + "cmd": "heartbeat", + //命令ID + "cmdId": "123123", + //发送时间(毫秒) + "time": 123123123123, + //数据体 + "data": {} +} +``` + +### 配置更新 + +?> 方向: `系统` -> `采集程序` + +**命令:** `configUpdate` + +**数据体:** ```json { @@ -82,40 +118,6 @@ } ``` -## 采集程序与系统交互通道 - -采集程序与系统间采用Websocket方式通讯, 访问系统服务器端口: 7790 - -报文格式为`json`, 字符集: `utf-8`。 - -### 通道建立 - -采集程序建立连接时,需要带上自身节点ID,连接URL如下所示: - -`ws://127.0.0.1:7790/gate/{nodeId}/{version}` - -* `nodeId`: 采集节点ID -* `version`: 采集节点配置版本号 - -PS: 同一节点只允许建立一条连接。 - -## 通讯报文 - -### 报文格式 - -```json -{ - //命令 - "cmd": "heartbeat", - //命令ID - "cmdId": "123123", - //发送时间(毫秒) - "time": 123123123123, - //数据体 - "data": {} -} -``` - ### 节点心跳报文 ?> 方向: `采集程序` -> `系统` From 97168eb3b527c28667be3fe8d1a3c2b463f370ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=B7=E6=88=90=E4=BC=9F?= Date: Fri, 5 Jul 2024 14:40:46 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/datacollect/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/datacollect/README.md b/docs/datacollect/README.md index c3a51f9e..79cc696e 100644 --- a/docs/datacollect/README.md +++ b/docs/datacollect/README.md @@ -15,7 +15,7 @@ * `nodeId`: 采集节点ID * `version`: 采集节点配置版本号,无配置时为0 -建立连接后,当{version}为0时,或者{version}比系统中的版本低时,会主动推送配置更新命令。 +建立连接后,当{version}为0时, 会主动推送配置更新命令。 PS: 同一节点只允许建立一条连接。