diff --git a/ruoyi-api/hw-api-business/src/main/java/com/ruoyi/business/api/RemoteBusinessService.java b/ruoyi-api/hw-api-business/src/main/java/com/ruoyi/business/api/RemoteBusinessService.java
index 8421fac..10dfed8 100644
--- a/ruoyi-api/hw-api-business/src/main/java/com/ruoyi/business/api/RemoteBusinessService.java
+++ b/ruoyi-api/hw-api-business/src/main/java/com/ruoyi/business/api/RemoteBusinessService.java
@@ -20,4 +20,10 @@ public interface RemoteBusinessService {
*/
@GetMapping("/device/computeOnlineDevicecCount/{days}")
public R> computeOnlineDevicecCount(@PathVariable("days") int days, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
+
+ @GetMapping("/plcDevice/modbusDataProcess")
+ public R> modbusDataProcess(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
+
+ @GetMapping("/plcDevice/mcDataProcess")
+ public R> mcDataProcess(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
}
diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/TdEngineConstants.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/TdEngineConstants.java
index 3970059..5816825 100644
--- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/TdEngineConstants.java
+++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/TdEngineConstants.java
@@ -32,7 +32,9 @@ public class TdEngineConstants {
// public static final String DEFAULT_DB_NAME_PREFIX = "db_scene_";//数据库名称前缀
public static final String DEFAULT_SUPER_TABLE_NAME_PREFIX = "st_devicemode_";//超级表名称前缀
+ public static final String PLC_SUPER_TABLE_NAME_PREFIX = "plc_";//plc超级表名称前缀
public static final String DEFAULT_TABLE_NAME_PREFIX = "t_device_";//数据表名称前缀
+ public static final String PLC_TABLE_NAME_PREFIX = "plc_device_";//plc数据表名称前缀
public static final String DEFAULT_DEVICE_STATUS_SUPER_TABLE_NAME= "st_ds";//设备状态超级表名称
public static final String DEFAULT_DEVICE_STATUS_TABLE_NAME_PREFIX = "t_ds_";//设备状态数据表名称前缀
@@ -43,6 +45,14 @@ public class TdEngineConstants {
public static final int ST_TAG_DEVICECODE_TYPE = 10;
public static final int ST_TAG_DEVICECODE_SIZE=50;
+ public static final String PLC_TAG_IP = "IP";
+ public static final int PLC_TAG_IP_TYPE = 10;
+ public static final int PLC_TAG_IP_SIZE=100;
+
+ public static final String PLC_TAG_LOCATION = "dlocation";
+ public static final int PLC_TAG_LOCATION_TYPE = 10;
+ public static final int PLC_TAG_LOCATION_SIZE=50;
+
public static final String ST_TAG_DEVICENAME = "devicename";
public static final String ST_TAG_DEVICETYPE = "devicetype";
@@ -53,6 +63,9 @@ public class TdEngineConstants {
public static final String ST_TAG_DEVICEID = "deviceid";
public static final int ST_TAG_DEVICEID_TYPE = 2;
+ public static final String PLC_TAG_PORT = "PORT1";
+ public static final int PLC_TAG_PORT_TYPE = 2;
+
public static final String ST_TAG_DEVICEMODEID = "devicemodeid";
public static final int ST_TAG_DEVICEMODEID_TYPE = 2;
diff --git a/ruoyi-modules/hw-business/pom.xml b/ruoyi-modules/hw-business/pom.xml
index a8a5663..6bd0a2f 100644
--- a/ruoyi-modules/hw-business/pom.xml
+++ b/ruoyi-modules/hw-business/pom.xml
@@ -105,6 +105,11 @@
com.ruoyi
hw-api-tdengine
+
+ com.github.dathlin
+ HslCommunication
+ 3.3.1
+
diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/PlcDeviceController.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/PlcDeviceController.java
new file mode 100644
index 0000000..a45ee4a
--- /dev/null
+++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/PlcDeviceController.java
@@ -0,0 +1,147 @@
+package com.ruoyi.business.controller;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.ruoyi.business.domain.HwDevice;
+import com.ruoyi.business.domain.HwDeviceMode;
+import com.ruoyi.business.domain.PlcDevice;
+import com.ruoyi.business.domain.PlcDeviceMode;
+import com.ruoyi.business.service.PlcDeviceService;
+import com.ruoyi.common.core.web.controller.BaseController;
+import com.ruoyi.common.core.web.domain.AjaxResult;
+import com.ruoyi.common.core.web.page.TableDataInfo;
+import com.ruoyi.common.security.utils.SecurityUtils;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * plc设备信息(PlcDevice)表控制层
+ *
+ * @author makejava
+ * @since 2024-12-19 16:22:43
+ */
+@RestController
+@RequestMapping("plcDevice")
+public class PlcDeviceController extends BaseController {
+ /**
+ * 服务对象
+ */
+ @Resource
+ private PlcDeviceService plcDeviceService;
+
+ /**
+ * 分页查询
+ *
+ * @param plcDevice 筛选条件
+ * @param pageRequest 分页对象
+ * @return 查询结果
+ */
+ @GetMapping
+ public ResponseEntity> queryByPage(PlcDevice plcDevice, PageRequest pageRequest) {
+ return ResponseEntity.ok(this.plcDeviceService.queryByPage(plcDevice, pageRequest));
+ }
+
+ /**
+ * 通过主键查询单条数据
+ *
+ * @param id 主键
+ * @return 单条数据
+ */
+ @GetMapping("{deviceId}")
+ public AjaxResult queryById(@PathVariable("deviceId") Long id) throws JsonProcessingException {
+ return AjaxResult.success(this.plcDeviceService.queryById(id));
+ }
+
+ /**
+ * 新增数据
+ *
+ * @param plcDevice 实体
+ * @return 新增结果
+ */
+ @PostMapping
+ public AjaxResult add(@RequestBody PlcDevice plcDevice) {
+ return toAjax(this.plcDeviceService.insert(plcDevice));
+ }
+
+ @PutMapping("/changeDeviceStatus")
+ public AjaxResult changeDeviceStatus(@RequestBody PlcDevice device) {
+ return toAjax(plcDeviceService.changeDeviceStatus(device));
+ }
+
+ /**
+ * 编辑数据
+ *
+ * @param plcDevice 实体
+ * @return 编辑结果
+ */
+// @PutMapping
+// public AjaxResult edit(PlcDevice plcDevice) {
+// return AjaxResult.success(plcDeviceService.update(plcDevice));
+// }
+ @GetMapping("getProtocols")
+ public AjaxResult getProtocols(){
+ HashMap map = new HashMap<>();
+ map.put("protocolName","mc");
+ map.put("protocolValue","1");
+ HashMap map1 = new HashMap<>();
+ map1.put("protocolName","modbus");
+ map1.put("protocolValue","2");
+ ArrayList objects = new ArrayList<>();
+ objects.add(map);
+ objects.add(map1);
+ return AjaxResult.success(objects);
+ }
+ /**
+ * 删除数据
+ *
+ * @param id 主键
+ * @return 删除是否成功
+ */
+ @DeleteMapping("{deviceId}")
+ public AjaxResult deleteById(@PathVariable("deviceId") Long deviceId) {
+ return AjaxResult.success(this.plcDeviceService.deleteById(deviceId));
+ }
+ @GetMapping("/modbusDataProcess")
+ public AjaxResult modbusDataProcess() throws JsonProcessingException {
+ return AjaxResult.success(plcDeviceService.modbusDataProcess());
+ }
+
+ @GetMapping("/mcDataProcess")
+ public AjaxResult mcDataProcess() throws JsonProcessingException {
+ return AjaxResult.success(plcDeviceService.mcDataProcess());
+ }
+ @GetMapping("/aeDataProcess")
+ public AjaxResult aeDataProcess() throws JsonProcessingException {
+ return AjaxResult.success(plcDeviceService.aeDataProcess());
+ }
+ @GetMapping("/linkDataProcess")
+ public AjaxResult linkDataProcess() throws JsonProcessingException {
+ return AjaxResult.success(plcDeviceService.linkDataProcess());
+ }
+ @GetMapping("/list")
+ public TableDataInfo list(PlcDevice hwDevice) {
+ startPage();
+ List list = plcDeviceService.selectHwDeviceJoinList(hwDevice);
+ return getDataTable(list);
+ }
+ @GetMapping(value = {"/getDeviceModes/", "/getDeviceModes/{sceneId}"})
+ public AjaxResult getDeviceModes(@PathVariable(value = "sceneId", required = false) Long sceneId) {
+ PlcDeviceMode queryDeviceMode = new PlcDeviceMode();
+ queryDeviceMode.setSceneId(sceneId);
+ return success(plcDeviceService.selectHwDeviceModeList(queryDeviceMode));
+ }
+
+ @PutMapping
+ public AjaxResult edit(@RequestBody PlcDevice hwDevice) {
+ hwDevice.setUpdateBy(SecurityUtils.getUsername());
+ return toAjax(plcDeviceService.updateDevice(hwDevice));
+ }
+
+}
+
diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/PlcDeviceModeController.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/PlcDeviceModeController.java
new file mode 100644
index 0000000..0ae49e6
--- /dev/null
+++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/PlcDeviceModeController.java
@@ -0,0 +1,111 @@
+package com.ruoyi.business.controller;
+
+import com.ruoyi.business.domain.HwDeviceMode;
+import com.ruoyi.business.domain.HwDeviceModeFunction;
+import com.ruoyi.business.domain.PlcDeviceMode;
+import com.ruoyi.business.domain.PlcDeviceModeFunction;
+import com.ruoyi.business.service.PlcDeviceModeService;
+import com.ruoyi.common.core.constant.HwDictConstants;
+import com.ruoyi.common.core.web.controller.BaseController;
+import com.ruoyi.common.core.web.domain.AjaxResult;
+import com.ruoyi.common.core.web.page.TableDataInfo;
+import com.ruoyi.common.security.annotation.RequiresPermissions;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * plc设备模型(PlcDeviceMode)表控制层
+ *
+ * @author makejava
+ * @since 2024-12-19 16:23:27
+ */
+@RestController
+@RequestMapping("plcDeviceMode")
+public class PlcDeviceModeController extends BaseController {
+ /**
+ * 服务对象
+ */
+ @Resource
+ private PlcDeviceModeService plcDeviceModeService;
+
+ /**
+ * 分页查询
+ *
+ * @param plcDeviceMode 筛选条件
+ * @param pageRequest 分页对象
+ * @return 查询结果
+ */
+ @GetMapping
+ public ResponseEntity> queryByPage(PlcDeviceMode plcDeviceMode, PageRequest pageRequest) {
+ return ResponseEntity.ok(this.plcDeviceModeService.queryByPage(plcDeviceMode, pageRequest));
+ }
+
+ /**
+ * 通过主键查询单条数据
+ *
+ * @param id 主键
+ * @return 单条数据
+ */
+ @GetMapping("{deviceModeId}")
+ public AjaxResult queryById(@PathVariable("deviceModeId") Long deviceModeId) {
+ PlcDeviceMode hwDeviceMode = plcDeviceModeService.selectHwDeviceModeByDeviceModeId(deviceModeId);
+ List hwDeviceModeFunctions = plcDeviceModeService.selectFunctionList(deviceModeId);
+ hwDeviceMode.setFunctionList(null);
+ Map map = new HashMap<>();
+ map.put("deviceMode", hwDeviceMode);
+ map.put("deviceModeFunctionMap", hwDeviceModeFunctions);
+ return success(map);
+ }
+
+ /**
+ * 新增数据
+ *
+ * @param plcDeviceMode 实体
+ * @return 新增结果
+ */
+ @PostMapping
+ public AjaxResult add(@RequestBody PlcDeviceMode plcDeviceMode) {
+ return toAjax(this.plcDeviceModeService.insert(plcDeviceMode));
+ }
+
+ @RequiresPermissions("business:deviceMode:list")
+ @GetMapping("/list")
+ public TableDataInfo list(PlcDeviceMode hwDeviceMode) {
+ startPage();
+ hwDeviceMode.setDeviceModeStatus(HwDictConstants.DEVICE_MODE_STATUS_NORMAL);
+ List list = plcDeviceModeService.selectList(hwDeviceMode);
+ return getDataTable(list);
+ }
+
+ /**
+ * 编辑数据
+ *
+ * @param plcDeviceMode 实体
+ * @return 编辑结果
+ */
+ @PutMapping
+ public AjaxResult edit(@RequestBody PlcDeviceMode plcDeviceMode) {
+ return toAjax(this.plcDeviceModeService.update(plcDeviceMode));
+ }
+
+ /**
+ * 删除数据
+ *
+ * @param id 主键
+ * @return 删除是否成功
+ */
+ @DeleteMapping("/{deviceModeIds}")
+ public ResponseEntity deleteById(@PathVariable Long[] deviceModeIds) {
+ return ResponseEntity.ok(this.plcDeviceModeService.deleteHwDeviceModeByDeviceModeIds(deviceModeIds));
+ }
+
+}
+
diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/PlcDeviceModeFunctionController.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/PlcDeviceModeFunctionController.java
new file mode 100644
index 0000000..4cfe0b6
--- /dev/null
+++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/PlcDeviceModeFunctionController.java
@@ -0,0 +1,87 @@
+package com.ruoyi.business.controller;
+
+
+import com.ruoyi.business.domain.PlcDeviceModeFunction;
+import com.ruoyi.business.service.PlcDeviceModeFunctionService;
+import com.ruoyi.common.core.web.controller.BaseController;
+import com.ruoyi.common.core.web.domain.AjaxResult;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+
+/**
+ * plc设备模型功能(PlcDeviceModeFunction)表控制层
+ *
+ * @author makejava
+ * @since 2024-12-19 16:23:52
+ */
+@RestController
+@RequestMapping("plcDeviceModeFunction")
+public class PlcDeviceModeFunctionController extends BaseController {
+ /**
+ * 服务对象
+ */
+ @Resource
+ private PlcDeviceModeFunctionService plcDeviceModeFunctionService;
+
+ /**
+ * 分页查询
+ *
+ * @param plcDeviceModeFunction 筛选条件
+ * @param pageRequest 分页对象
+ * @return 查询结果
+ */
+ @GetMapping
+ public ResponseEntity> queryByPage(PlcDeviceModeFunction plcDeviceModeFunction, PageRequest pageRequest) {
+ return ResponseEntity.ok(this.plcDeviceModeFunctionService.queryByPage(plcDeviceModeFunction, pageRequest));
+ }
+
+ /**
+ * 通过主键查询单条数据
+ *
+ * @param id 主键
+ * @return 单条数据
+ */
+ @GetMapping("{id}")
+ public ResponseEntity queryById(@PathVariable("id") Long id) {
+ return ResponseEntity.ok(this.plcDeviceModeFunctionService.queryById(id));
+ }
+
+ /**
+ * 新增数据
+ *
+ * @param plcDeviceModeFunction 实体
+ * @return 新增结果
+ */
+ @PostMapping
+ public AjaxResult add(@RequestBody PlcDeviceModeFunction plcDeviceModeFunction) {
+ return toAjax(this.plcDeviceModeFunctionService.insert(plcDeviceModeFunction));
+ }
+
+ /**
+ * 编辑数据
+ *
+ * @param plcDeviceModeFunction 实体
+ * @return 编辑结果
+ */
+ @PutMapping
+ public AjaxResult edit(@RequestBody PlcDeviceModeFunction plcDeviceModeFunction) {
+ return toAjax(this.plcDeviceModeFunctionService.update(plcDeviceModeFunction));
+ }
+
+ /**
+ * 删除数据
+ *
+ * @param id 主键
+ * @return 删除是否成功
+ */
+ @DeleteMapping("/{modeFunctionId}")
+ public AjaxResult deleteById(@PathVariable("modeFunctionId") Long modeFunctionId) {
+ return toAjax(this.plcDeviceModeFunctionService.deleteById(modeFunctionId));
+ }
+
+}
+
diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/PlcDevice.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/PlcDevice.java
new file mode 100644
index 0000000..2f977a3
--- /dev/null
+++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/PlcDevice.java
@@ -0,0 +1,247 @@
+package com.ruoyi.business.domain;
+
+import com.ruoyi.common.core.annotation.Excel;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * plc设备信息(PlcDevice)实体类
+ *
+ * @author makejava
+ * @since 2024-12-19 16:22:47
+ */
+@Data
+public class PlcDevice implements Serializable {
+ private static final long serialVersionUID = -11771385039084146L;
+ /**
+ * 设备ID
+ */
+ private Long deviceId;
+ /**
+ * 设备编号
+ */
+ private String deviceCode;
+ /**
+ * 设备名称
+ */
+ private String deviceName;
+ /**
+ * 租户ID,关联hw_tenant的tenant_id
+ */
+ private Long tenantId;
+ /**
+ * 所属场景,关联hw_scene表的scene_id字段
+ */
+ private Long sceneId;
+ /**
+ * ip地址
+ */
+ private String ip;
+ /**
+ * 端口
+ */
+ private Integer port1;
+ /**
+ * 读取寄存器位置
+ */
+ private String location;
+ /**
+ * 协议类型,1mc,2modbus
+ */
+ private Integer accessProtocol;
+ private Integer station;
+ /**
+ * 长度
+ */
+ private Integer length;
+ private String dataType;
+ private String tenantName;
+ private String sceneName;
+ private String deviceModeName;
+ /**
+ * 设备模型,关联表hw_device_mode的字段device_mode_id
+ */
+ @Excel(name = "设备模型")
+ private Long deviceModeId;
+ /**
+ * 设备状态(0、测试,1、发布,9、删除)
+ */
+ private String deviceStatus;
+ /**
+ * 创建人
+ */
+ private String createBy;
+ /**
+ * 创建时间
+ */
+ private Date createTime;
+ private Date publishTime;
+ /**
+ * 更新人
+ */
+ private String updateBy;
+ /**
+ * 更新时间
+ */
+ private Date updateTime;
+ public void setDeviceModeId(Long deviceModeId) {
+ this.deviceModeId = deviceModeId;
+ }
+
+ public Long getDeviceModeId() {
+ return deviceModeId;
+ }
+
+
+ public Long getDeviceId() {
+ return deviceId;
+ }
+
+ public void setDeviceId(Long deviceId) {
+ this.deviceId = deviceId;
+ }
+
+ public String getDeviceCode() {
+ return deviceCode;
+ }
+
+ public void setDeviceCode(String deviceCode) {
+ this.deviceCode = deviceCode;
+ }
+ public String getDataType() {
+ return dataType;
+ }
+
+ public void setDataType(String dataType) {
+ this.dataType = dataType;
+ }
+
+ public String getDeviceName() {
+ return deviceName;
+ }
+
+ public void setDeviceName(String deviceName) {
+ this.deviceName = deviceName;
+ }
+// public String getdLocation() {
+// return dLocation;
+// }
+//
+// public void setdLocation(String dLocation) {
+// this.dLocation = dLocation;
+// }
+
+ public Long getTenantId() {
+ return tenantId;
+ }
+
+ public void setTenantId(Long tenantId) {
+ this.tenantId = tenantId;
+ }
+
+ public Long getSceneId() {
+ return sceneId;
+ }
+
+ public void setSceneId(Long sceneId) {
+ this.sceneId = sceneId;
+ }
+
+ public String getIp() {
+ return ip;
+ }
+
+ public void setIp(String ip) {
+ this.ip = ip;
+ }
+
+ public Integer getPort1() {
+ return port1;
+ }
+
+ public void setPort1(Integer port1) {
+ this.port1 = port1;
+ }
+
+ public String getLocation() {
+ return location;
+ }
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ public Integer getAccessProtocol() {
+ return accessProtocol;
+ }
+
+ public void setAccessProtocol(Integer accessProtocol) {
+ this.accessProtocol = accessProtocol;
+ }
+ public Integer getStation() {
+ return station;
+ }
+
+ public void setStation(Integer station) {
+ this.station = station;
+ }
+
+ public Integer getLength() {
+ return length;
+ }
+
+ public void setLength(Integer length) {
+ this.length = length;
+ }
+
+ public String getDeviceStatus() {
+ return deviceStatus;
+ }
+
+ public void setDeviceStatus(String deviceStatus) {
+ this.deviceStatus = deviceStatus;
+ }
+
+ public String getCreateBy() {
+ return createBy;
+ }
+
+ public void setCreateBy(String createBy) {
+ this.createBy = createBy;
+ }
+
+ public Date getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(Date createTime) {
+ this.createTime = createTime;
+ }
+ public Date getPublishTime() {
+ return publishTime;
+ }
+
+ public void setPublishTime(Date publishTime) {
+ this.publishTime = publishTime;
+ }
+
+ public String getUpdateBy() {
+ return updateBy;
+ }
+
+ public void setUpdateBy(String updateBy) {
+ this.updateBy = updateBy;
+ }
+
+ public Date getUpdateTime() {
+ return updateTime;
+ }
+
+ public void setUpdateTime(Date updateTime) {
+ this.updateTime = updateTime;
+ }
+
+}
+
diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/PlcDeviceMode.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/PlcDeviceMode.java
new file mode 100644
index 0000000..78c3cc1
--- /dev/null
+++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/PlcDeviceMode.java
@@ -0,0 +1,147 @@
+package com.ruoyi.business.domain;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * plc设备模型(PlcDeviceMode)实体类
+ *
+ * @author makejava
+ * @since 2024-12-19 16:23:27
+ */
+@Data
+public class PlcDeviceMode implements Serializable {
+ private static final long serialVersionUID = 441335518091339874L;
+ /**
+ * 设备模型ID
+ */
+ private Long deviceModeId;
+ /**
+ * 设备模型名称
+ */
+ private String deviceModeName;
+ /**
+ * 租户ID,关联hw_tenant的tenant_id
+ */
+ private Long tenantId;
+ /**
+ * 所属场景,关联hw_scene表的scene_id字段
+ */
+ private Long sceneId;
+ /**
+ * 设备模型状态(1:启用,9:删除)
+ */
+ private String deviceModeStatus;
+ /**
+ * 创建人
+ */
+ private String createBy;
+ /**
+ * 创建时间
+ */
+ private Date createTime;
+ /**
+ * 更新人
+ */
+ private String updateBy;
+ /**
+ * 更新时间
+ */
+ private Date updateTime;
+
+ private List functionList;
+ private String tenantName;
+ private String sceneName;
+
+
+ public Long getDeviceModeId() {
+ return deviceModeId;
+ }
+
+ public void setDeviceModeId(Long deviceModeId) {
+ this.deviceModeId = deviceModeId;
+ }
+
+ public String getDeviceModeName() {
+ return deviceModeName;
+ }
+
+ public void setDeviceModeName(String deviceModeName) {
+ this.deviceModeName = deviceModeName;
+ }
+ public String getTenantName() {
+ return tenantName;
+ }
+
+ public void setTenantName(String tenantName) {
+ this.tenantName = tenantName;
+ }
+ public String getSceneName() {
+ return sceneName;
+ }
+
+ public void setSceneName(String sceneName) {
+ this.sceneName = sceneName;
+ }
+
+ public Long getTenantId() {
+ return tenantId;
+ }
+
+ public void setTenantId(Long tenantId) {
+ this.tenantId = tenantId;
+ }
+
+ public Long getSceneId() {
+ return sceneId;
+ }
+
+ public void setSceneId(Long sceneId) {
+ this.sceneId = sceneId;
+ }
+
+ public String getDeviceModeStatus() {
+ return deviceModeStatus;
+ }
+
+ public void setDeviceModeStatus(String deviceModeStatus) {
+ this.deviceModeStatus = deviceModeStatus;
+ }
+
+ public String getCreateBy() {
+ return createBy;
+ }
+
+ public void setCreateBy(String createBy) {
+ this.createBy = createBy;
+ }
+
+ public Date getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(Date createTime) {
+ this.createTime = createTime;
+ }
+
+ public String getUpdateBy() {
+ return updateBy;
+ }
+
+ public void setUpdateBy(String updateBy) {
+ this.updateBy = updateBy;
+ }
+
+ public Date getUpdateTime() {
+ return updateTime;
+ }
+
+ public void setUpdateTime(Date updateTime) {
+ this.updateTime = updateTime;
+ }
+
+}
+
diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/PlcDeviceModeFunction.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/PlcDeviceModeFunction.java
new file mode 100644
index 0000000..43b7211
--- /dev/null
+++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/PlcDeviceModeFunction.java
@@ -0,0 +1,134 @@
+package com.ruoyi.business.domain;
+
+import com.ruoyi.common.core.annotation.Excel;
+
+import java.io.Serializable;
+
+/**
+ * plc设备模型功能(PlcDeviceModeFunction)实体类
+ *
+ * @author makejava
+ * @since 2024-12-19 16:23:52
+ */
+public class PlcDeviceModeFunction implements Serializable {
+ private static final long serialVersionUID = -19875863077506718L;
+ /**
+ * 设备模型功能ID
+ */
+ private Long modeFunctionId;
+ /**
+ * 设备模型ID,关联表plc_device_mode的device_mode_id
+ */
+ private Long deviceModeId;
+ /**
+ * 功能名称
+ */
+ private String functionName;
+ /**
+ * 标识符(支持大小写字母、数字和下划线,对外暂时不超过50个字符)
+ */
+ private String functionIdentifier;
+ /**
+ * 数据类型(2、int,4、float,5、double,6、binary(image/base64),9、bool,10、string)
+ */
+ private Integer dataType;
+ /**
+ * 数据定义,按json保存,示例如下:
+ 1、取值范围:{'minValue':1,'maxValue':100},
+ 2、枚举型:
+ {'1':'成功','2','失败','3','提示}
+ 3、bool型:
+ {'0':'关','1','开'}
+ 4、Text型:
+ {'dataLength':1024}
+ 5、String类型(此类型需要定义在数据字典中,支持多语言):
+ {'dateFormat':'String类型的UTC时间戳(毫秒)'}
+ */
+ private String dataDefinition;
+ /**
+ * 单位
+ */
+ private String propertyUnit;
+ /**
+ * 描述
+ */
+ private String remark;
+ /** 功能模式(1、属性,2、服务,3、事件) */
+// @Excel(name = "功能模式", readConverterExp = "1=属性,2=服务,3=事件")
+ private String functionMode;
+
+ public void setFunctionMode(String functionMode)
+ {
+ this.functionMode = functionMode;
+ }
+
+ public String getFunctionMode()
+ {
+ return functionMode;
+ }
+ public Long getModeFunctionId() {
+ return modeFunctionId;
+ }
+
+ public void setModeFunctionId(Long modeFunctionId) {
+ this.modeFunctionId = modeFunctionId;
+ }
+
+ public Long getDeviceModeId() {
+ return deviceModeId;
+ }
+
+ public void setDeviceModeId(Long deviceModeId) {
+ this.deviceModeId = deviceModeId;
+ }
+
+ public String getFunctionName() {
+ return functionName;
+ }
+
+ public void setFunctionName(String functionName) {
+ this.functionName = functionName;
+ }
+
+ public String getFunctionIdentifier() {
+ return functionIdentifier;
+ }
+
+ public void setFunctionIdentifier(String functionIdentifier) {
+ this.functionIdentifier = functionIdentifier;
+ }
+
+ public Integer getDataType() {
+ return dataType;
+ }
+
+ public void setDataType(Integer dataType) {
+ this.dataType = dataType;
+ }
+
+ public String getDataDefinition() {
+ return dataDefinition;
+ }
+
+ public void setDataDefinition(String dataDefinition) {
+ this.dataDefinition = dataDefinition;
+ }
+
+ public String getPropertyUnit() {
+ return propertyUnit;
+ }
+
+ public void setPropertyUnit(String propertyUnit) {
+ this.propertyUnit = propertyUnit;
+ }
+
+ public String getRemark() {
+ return remark;
+ }
+
+ public void setRemark(String remark) {
+ this.remark = remark;
+ }
+
+}
+
diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/PlcDeviceModeFunctionService.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/PlcDeviceModeFunctionService.java
new file mode 100644
index 0000000..9985e1f
--- /dev/null
+++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/PlcDeviceModeFunctionService.java
@@ -0,0 +1,55 @@
+package com.ruoyi.business.service;
+import com.ruoyi.business.domain.PlcDeviceModeFunction;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+
+/**
+ * plc设备模型功能(PlcDeviceModeFunction)表服务接口
+ *
+ * @author makejava
+ * @since 2024-12-19 16:23:52
+ */
+public interface PlcDeviceModeFunctionService {
+
+ /**
+ * 通过ID查询单条数据
+ *
+ * @param modeFunctionId 主键
+ * @return 实例对象
+ */
+ PlcDeviceModeFunction queryById(Long modeFunctionId);
+
+ /**
+ * 分页查询
+ *
+ * @param plcDeviceModeFunction 筛选条件
+ * @param pageRequest 分页对象
+ * @return 查询结果
+ */
+ Page queryByPage(PlcDeviceModeFunction plcDeviceModeFunction, PageRequest pageRequest);
+
+ /**
+ * 新增数据
+ *
+ * @param plcDeviceModeFunction 实例对象
+ * @return 实例对象
+ */
+ int insert(PlcDeviceModeFunction plcDeviceModeFunction);
+
+ /**
+ * 修改数据
+ *
+ * @param plcDeviceModeFunction 实例对象
+ * @return 实例对象
+ */
+ int update(PlcDeviceModeFunction plcDeviceModeFunction);
+
+ /**
+ * 通过主键删除数据
+ *
+ * @param modeFunctionId 主键
+ * @return 是否成功
+ */
+ int deleteById(Long modeFunctionId);
+
+}
diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/PlcDeviceModeService.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/PlcDeviceModeService.java
new file mode 100644
index 0000000..92d87e6
--- /dev/null
+++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/PlcDeviceModeService.java
@@ -0,0 +1,66 @@
+package com.ruoyi.business.service;
+import com.ruoyi.business.domain.HwDeviceMode;
+import com.ruoyi.business.domain.PlcDeviceMode;
+import com.ruoyi.business.domain.PlcDeviceModeFunction;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+
+import java.util.List;
+
+/**
+ * plc设备模型(PlcDeviceMode)表服务接口
+ *
+ * @author makejava
+ * @since 2024-12-19 16:23:27
+ */
+public interface PlcDeviceModeService {
+
+ /**
+ * 通过ID查询单条数据
+ *
+ * @param deviceModeId 主键
+ * @return 实例对象
+ */
+ PlcDeviceMode queryById(Long deviceModeId);
+
+ /**
+ * 分页查询
+ *
+ * @param plcDeviceMode 筛选条件
+ * @param pageRequest 分页对象
+ * @return 查询结果
+ */
+ Page queryByPage(PlcDeviceMode plcDeviceMode, PageRequest pageRequest);
+
+ /**
+ * 新增数据
+ *
+ * @param plcDeviceMode 实例对象
+ * @return 实例对象
+ */
+ int insert(PlcDeviceMode plcDeviceMode);
+
+ /**
+ * 修改数据
+ *
+ * @param plcDeviceMode 实例对象
+ * @return 实例对象
+ */
+ int update(PlcDeviceMode plcDeviceMode);
+
+ /**
+ * 通过主键删除数据
+ *
+ * @param deviceModeId 主键
+ * @return 是否成功
+ */
+ boolean deleteById(Long deviceModeId);
+
+ List selectList(PlcDeviceMode hwDeviceMode);
+
+ PlcDeviceMode selectHwDeviceModeByDeviceModeId(Long deviceModeId);
+
+ List selectFunctionList(Long deviceModeId);
+
+ int deleteHwDeviceModeByDeviceModeIds(Long[] deviceModeIds);
+}
diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/PlcDeviceService.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/PlcDeviceService.java
new file mode 100644
index 0000000..b4b3451
--- /dev/null
+++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/PlcDeviceService.java
@@ -0,0 +1,77 @@
+package com.ruoyi.business.service;
+
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.ruoyi.business.domain.HwDeviceMode;
+import com.ruoyi.business.domain.PlcDevice;
+import com.ruoyi.business.domain.PlcDeviceMode;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+
+import java.util.List;
+
+/**
+ * plc设备信息(PlcDevice)表服务接口
+ *
+ * @author makejava
+ * @since 2024-12-19 16:22:51
+ */
+public interface PlcDeviceService {
+
+ /**
+ * 通过ID查询单条数据
+ *
+ * @param deviceId 主键
+ * @return 实例对象
+ */
+ PlcDevice queryById(Long deviceId) throws JsonProcessingException;
+
+ /**
+ * 分页查询
+ *
+ * @param plcDevice 筛选条件
+ * @param pageRequest 分页对象
+ * @return 查询结果
+ */
+ Page queryByPage(PlcDevice plcDevice, PageRequest pageRequest);
+
+ /**
+ * 新增数据
+ *
+ * @param plcDevice 实例对象
+ * @return 实例对象
+ */
+ int insert(PlcDevice plcDevice);
+
+ /**
+ * 修改数据
+ *
+ * @param plcDevice 实例对象
+ * @return 实例对象
+ */
+ PlcDevice update(PlcDevice plcDevice) throws JsonProcessingException;
+
+ /**
+ * 通过主键删除数据
+ *
+ * @param deviceId 主键
+ * @return 是否成功
+ */
+ int deleteById(Long deviceId);
+
+ String modbusDataProcess() throws JsonProcessingException;
+
+ String mcDataProcess() throws JsonProcessingException;
+
+ List selectHwDeviceJoinList(PlcDevice hwDevice);
+
+ List selectHwDeviceModeList(PlcDeviceMode queryDeviceMode);
+
+ int changeDeviceStatus(PlcDevice device);
+
+ int updateDevice(PlcDevice hwDevice);
+
+ String aeDataProcess() throws JsonProcessingException;
+
+ String linkDataProcess();
+}
diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/PlcDeviceModeFunctionServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/PlcDeviceModeFunctionServiceImpl.java
new file mode 100644
index 0000000..38fb992
--- /dev/null
+++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/PlcDeviceModeFunctionServiceImpl.java
@@ -0,0 +1,252 @@
+package com.ruoyi.business.service.impl;
+
+import com.ruoyi.business.domain.HwDevice;
+import com.ruoyi.business.domain.HwDeviceModeFunction;
+import com.ruoyi.business.domain.PlcDeviceModeFunction;
+import com.ruoyi.business.mapper.PlcDeviceModeFunctionDao;
+import com.ruoyi.business.service.PlcDeviceModeFunctionService;
+import com.ruoyi.common.core.constant.Constants;
+import com.ruoyi.common.core.constant.HwDictConstants;
+import com.ruoyi.common.core.constant.SecurityConstants;
+import com.ruoyi.common.core.constant.TdEngineConstants;
+import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.enums.DataTypeEnums;
+import com.ruoyi.common.core.exception.ServiceException;
+import com.ruoyi.common.core.utils.StringUtils;
+import com.ruoyi.tdengine.api.RemoteTdEngineService;
+import com.ruoyi.tdengine.api.domain.TdField;
+import com.ruoyi.tdengine.api.domain.TdSuperTableVo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageImpl;
+import org.springframework.data.domain.PageRequest;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * plc设备模型功能(PlcDeviceModeFunction)表服务实现类
+ *
+ * @author makejava
+ * @since 2024-12-19 16:23:52
+ */
+@Service("plcDeviceModeFunctionService")
+public class PlcDeviceModeFunctionServiceImpl implements PlcDeviceModeFunctionService {
+ @Resource
+ private PlcDeviceModeFunctionDao plcDeviceModeFunctionDao;
+ @Autowired
+ private RemoteTdEngineService remoteTdEngineService;
+
+ /**
+ * 通过ID查询单条数据
+ *
+ * @param modeFunctionId 主键
+ * @return 实例对象
+ */
+ @Override
+ public PlcDeviceModeFunction queryById(Long modeFunctionId) {
+ return this.plcDeviceModeFunctionDao.queryById(modeFunctionId);
+ }
+
+ /**
+ * 分页查询
+ *
+ * @param plcDeviceModeFunction 筛选条件
+ * @param pageRequest 分页对象
+ * @return 查询结果
+ */
+ @Override
+ public Page queryByPage(PlcDeviceModeFunction plcDeviceModeFunction, PageRequest pageRequest) {
+ long total = this.plcDeviceModeFunctionDao.count(plcDeviceModeFunction);
+ return new PageImpl<>(this.plcDeviceModeFunctionDao.queryAllByLimit(plcDeviceModeFunction, pageRequest), pageRequest, total);
+ }
+
+ /**
+ * 新增数据
+ *
+ * @param plcDeviceModeFunction 实例对象
+ * @return 实例对象
+ */
+ @Override
+ public int insert(PlcDeviceModeFunction plcDeviceModeFunction) {
+ checkDuplicateIdentifiers(plcDeviceModeFunction);
+ int functionId = this.plcDeviceModeFunctionDao.insert(plcDeviceModeFunction);
+ this.addTdSuperTableColumn(plcDeviceModeFunction);
+ return functionId;
+ }
+ private void addTdSuperTableColumn(PlcDeviceModeFunction hwDeviceModeFunction) {
+ String functionMode = hwDeviceModeFunction.getFunctionMode();
+ if (functionMode.equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) {
+ Long deviceModeId = hwDeviceModeFunction.getDeviceModeId();
+ String dbName = TdEngineConstants.getDatabaseName();
+ String superTableName = TdEngineConstants.PLC_SUPER_TABLE_NAME_PREFIX + deviceModeId;
+ TdSuperTableVo tdSuperTableVo = new TdSuperTableVo();
+ TdField schemaField = new TdField();
+ String functionIdentifierTransfer = TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(hwDeviceModeFunction.getFunctionIdentifier());
+ String functionIdentifier = functionIdentifierTransfer == null ? hwDeviceModeFunction.getFunctionIdentifier() : functionIdentifierTransfer;
+ schemaField.setFieldName(functionIdentifier);
+ Integer dataType = hwDeviceModeFunction.getDataType();
+ schemaField.setDataTypeCode(dataType);
+ //一个integer类型,一个long类型,需要转换为string类型比较
+ if (String.valueOf(dataType).equals(String.valueOf(DataTypeEnums.NCHAR.getDataCode()))) {
+ schemaField.setSize(Integer.valueOf(hwDeviceModeFunction.getDataDefinition()));
+ }
+ tdSuperTableVo.setDatabaseName(dbName);
+ tdSuperTableVo.setSuperTableName(superTableName);
+ tdSuperTableVo.setField(schemaField);
+ R> tdReturnMsg = this.remoteTdEngineService.addSuperTableColumn(tdSuperTableVo, SecurityConstants.INNER);
+ if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
+ throw new RuntimeException(tdReturnMsg.getMsg());
+ }
+ }
+ }
+
+ /**
+ * 修改数据
+ *
+ * @param plcDeviceModeFunction 实例对象
+ * @return 实例对象
+ */
+ @Override
+ public int update(PlcDeviceModeFunction plcDeviceModeFunction) {
+ //校验有没有重复标识符
+ checkDuplicateIdentifiers(plcDeviceModeFunction);
+
+ //与数据库中的数据判断标识符有没有修改,如果修改则在tdengine超级表删除老的字段,增加修改的字段
+ String functionMode = plcDeviceModeFunction.getFunctionMode();
+ if (functionMode.equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) {
+ PlcDeviceModeFunction dbHwDeviceModeFunction = plcDeviceModeFunctionDao
+ .queryById(plcDeviceModeFunction.getModeFunctionId());
+
+ String dbFunctionIdentifier = dbHwDeviceModeFunction.getFunctionIdentifier();
+ String functionIdentifier = plcDeviceModeFunction.getFunctionIdentifier();
+ Integer dbDataType = dbHwDeviceModeFunction.getDataType();
+ Integer dataType = plcDeviceModeFunction.getDataType();
+ //标识符或数据类型变化时需要先删除超级表column,再增加新的column,删除的column数据将会清空(有事务问题,暂时不支持)
+ if (!dbFunctionIdentifier.equalsIgnoreCase(functionIdentifier)
+ || !dbDataType.equals(dataType)) {
+// this.dropTdSuperTableColumn(dbHwDeviceModeFunction);
+// this.addTdSuperTableColumn(hwDeviceModeFunction);
+ throw new RuntimeException("标识符和数据类型不支持修改,可删除再新建");
+ } else {
+ if (String.valueOf(dataType).equals(String.valueOf(DataTypeEnums.NCHAR.getDataCode()))) {
+ int dbDataDefinition = Integer.parseInt(dbHwDeviceModeFunction.getDataDefinition());
+ int dataDefinition = Integer.parseInt(plcDeviceModeFunction.getDataDefinition());
+ if (dbDataDefinition > dataDefinition) {
+ throw new ServiceException("数据长度只能改大");
+ } else if (dbDataDefinition < dataDefinition) {
+ this.modifyTdSuperTableColumn(plcDeviceModeFunction);
+ }
+ }
+ }
+ } else {
+ plcDeviceModeFunctionDao.deleteById(plcDeviceModeFunction.getModeFunctionId());
+ List hwDeviceModeFunctions = new ArrayList<>();
+ hwDeviceModeFunctions.add(plcDeviceModeFunction);
+// batchInsertHwDeviceModeParameters(hwDeviceModeFunctions);
+ }
+
+ return plcDeviceModeFunctionDao.update(plcDeviceModeFunction);
+ }
+ private void modifyTdSuperTableColumn(PlcDeviceModeFunction hwDeviceModeFunction) {
+ String functionMode = hwDeviceModeFunction.getFunctionMode();
+ if (functionMode.equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) {
+ Long deviceModeId = hwDeviceModeFunction.getDeviceModeId();
+ String dbName = TdEngineConstants.getDatabaseName();
+ String superTableName = TdEngineConstants.PLC_SUPER_TABLE_NAME_PREFIX + deviceModeId;
+ TdSuperTableVo tdSuperTableVo = new TdSuperTableVo();
+ TdField schemaField = new TdField();
+ String functionIdentifierTransfer = TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(hwDeviceModeFunction.getFunctionIdentifier());
+ String functionIdentifier = functionIdentifierTransfer == null ? hwDeviceModeFunction.getFunctionIdentifier() : functionIdentifierTransfer;
+ schemaField.setFieldName(functionIdentifier);
+ Integer dataType = hwDeviceModeFunction.getDataType();
+ schemaField.setDataTypeCode(dataType.intValue());
+ //一个integer类型,一个long类型,需要转换为string类型比较
+ if (String.valueOf(dataType).equals(String.valueOf(DataTypeEnums.NCHAR.getDataCode()))) {
+ schemaField.setSize(Integer.valueOf(hwDeviceModeFunction.getDataDefinition()));
+ }
+ tdSuperTableVo.setDatabaseName(dbName);
+ tdSuperTableVo.setSuperTableName(superTableName);
+ tdSuperTableVo.setField(schemaField);
+ R> tdReturnMsg = this.remoteTdEngineService.modifySuperTableColumn(tdSuperTableVo, SecurityConstants.INNER);
+ if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
+ throw new RuntimeException(tdReturnMsg.getMsg());
+ }
+ }
+ }
+ /**
+ * @param: hwDeviceModeFunction
+ * @description 在编辑设备模型添加功能或者编辑功能时判断属性值
+ * @author xins
+ * @date 2023-09-13 13:38
+ */
+ private void checkDuplicateIdentifiers(PlcDeviceModeFunction hwDeviceModeFunction) {
+ String functionIdentifier = hwDeviceModeFunction.getFunctionIdentifier();
+ if (TdEngineConstants.ABNDON_FUNCTION_IDENTIFIERS.contains(functionIdentifier.toLowerCase())) {
+ throw new ServiceException("标识符不能等于:" + functionIdentifier);
+ }
+
+// R keyLongitudeR = remoteConfigService.getConfigKeyStr("hw.gps.longitude");
+// R keyLatitudeR = remoteConfigService.getConfigKeyStr("hw.gps.latitude");
+// String keyLongitude = keyLongitudeR.getData();
+// String keyLatitude = keyLatitudeR.getData();
+
+// if (StringUtils.isEmpty(hwDeviceModeFunction.getCoordinate()) &&
+// (hwDeviceModeFunction.getFunctionIdentifier().equalsIgnoreCase(keyLongitude)
+// || hwDeviceModeFunction.getFunctionIdentifier().equalsIgnoreCase(keyLatitude))) {
+// throw new ServiceException("非定位设备模型标识符不能等于:" + keyLongitude + "或" + keyLatitude);
+// }
+
+ Long deviceModeId = hwDeviceModeFunction.getDeviceModeId();
+ HwDeviceModeFunction queryDeviceModeFunction = new HwDeviceModeFunction();
+ queryDeviceModeFunction.setDeviceModeId(deviceModeId);
+ List hwDeviceModeFunctions = plcDeviceModeFunctionDao.selectFunctionList(deviceModeId);
+
+ /**
+ * 判断时如果是修改的标识符则不能跟自己比较
+ */
+ long duplicateCount = hwDeviceModeFunctions.stream().filter(dmf ->
+ ((hwDeviceModeFunction.getModeFunctionId() == null) ||
+ (hwDeviceModeFunction.getModeFunctionId() != null && !hwDeviceModeFunction.getModeFunctionId().equals(dmf.getModeFunctionId())))
+ && dmf.getFunctionIdentifier().equalsIgnoreCase(hwDeviceModeFunction.getFunctionIdentifier())).count();
+ if (duplicateCount > 0) {
+ throw new ServiceException("标识符重复");
+ }
+ }
+
+ /**
+ * 通过主键删除数据
+ *
+ * @param modeFunctionId 主键
+ * @return 是否成功
+ */
+ @Override
+ public int deleteById(Long modeFunctionId) {
+ PlcDeviceModeFunction hwDeviceModeFunction = plcDeviceModeFunctionDao.queryById(modeFunctionId);
+ //查询是否有已发布的设备关联此设备模型
+ int rows = plcDeviceModeFunctionDao.deleteById(modeFunctionId);
+ this.dropTdSuperTableColumn(hwDeviceModeFunction);
+ return rows;
+ }
+ private void dropTdSuperTableColumn(PlcDeviceModeFunction hwDeviceModeFunction) {
+ String functionMode = hwDeviceModeFunction.getFunctionMode();
+ if (functionMode.equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) {
+ Long deviceModeId = hwDeviceModeFunction.getDeviceModeId();
+ String dbName = TdEngineConstants.getDatabaseName();
+ String superTableName = TdEngineConstants.PLC_SUPER_TABLE_NAME_PREFIX + deviceModeId;
+ TdSuperTableVo tdSuperTableVo = new TdSuperTableVo();
+ TdField schemaField = new TdField();
+ schemaField.setFieldName(hwDeviceModeFunction.getFunctionIdentifier());
+ tdSuperTableVo.setDatabaseName(dbName);
+ tdSuperTableVo.setSuperTableName(superTableName);
+ tdSuperTableVo.setField(schemaField);
+
+ R> tdReturnMsg = this.remoteTdEngineService.dropColumnForSuperTable(tdSuperTableVo, SecurityConstants.INNER);
+ if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
+ throw new RuntimeException(tdReturnMsg.getMsg());
+ }
+ }
+ }
+}
diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/PlcDeviceModeServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/PlcDeviceModeServiceImpl.java
new file mode 100644
index 0000000..d404ee4
--- /dev/null
+++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/PlcDeviceModeServiceImpl.java
@@ -0,0 +1,189 @@
+package com.ruoyi.business.service.impl;
+
+import com.ruoyi.business.domain.HwDeviceMode;
+import com.ruoyi.business.domain.HwDeviceModeFunction;
+import com.ruoyi.business.domain.PlcDeviceMode;
+import com.ruoyi.business.domain.PlcDeviceModeFunction;
+import com.ruoyi.business.mapper.PlcDeviceModeDao;
+import com.ruoyi.business.mapper.PlcDeviceModeFunctionDao;
+import com.ruoyi.business.service.PlcDeviceModeService;
+import com.ruoyi.common.core.constant.Constants;
+import com.ruoyi.common.core.constant.HwDictConstants;
+import com.ruoyi.common.core.constant.SecurityConstants;
+import com.ruoyi.common.core.constant.TdEngineConstants;
+import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.enums.DataTypeEnums;
+import com.ruoyi.common.security.utils.SecurityUtils;
+import com.ruoyi.tdengine.api.RemoteTdEngineService;
+import com.ruoyi.tdengine.api.domain.TdField;
+import com.ruoyi.tdengine.api.domain.TdSuperTableVo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageImpl;
+import org.springframework.data.domain.PageRequest;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * plc设备模型(PlcDeviceMode)表服务实现类
+ *
+ * @author makejava
+ * @since 2024-12-19 16:23:27
+ */
+@Service("plcDeviceModeService")
+public class PlcDeviceModeServiceImpl implements PlcDeviceModeService {
+ @Autowired
+ private PlcDeviceModeDao plcDeviceModeDao;
+ @Autowired
+ private PlcDeviceModeFunctionDao plcDeviceModeFunctionDao;
+ @Autowired
+ private RemoteTdEngineService remoteTdEngineService;
+
+ /**
+ * 通过ID查询单条数据
+ *
+ * @param deviceModeId 主键
+ * @return 实例对象
+ */
+ @Override
+ public PlcDeviceMode queryById(Long deviceModeId) {
+ return this.plcDeviceModeDao.queryById(deviceModeId);
+ }
+
+ /**
+ * 分页查询
+ *
+ * @param plcDeviceMode 筛选条件
+ * @param pageRequest 分页对象
+ * @return 查询结果
+ */
+ @Override
+ public Page queryByPage(PlcDeviceMode plcDeviceMode, PageRequest pageRequest) {
+ long total = this.plcDeviceModeDao.count(plcDeviceMode);
+ return new PageImpl<>(this.plcDeviceModeDao.queryAllByLimit(plcDeviceMode, pageRequest), pageRequest, total);
+ }
+
+ /**
+ * 新增数据
+ *
+ * @param plcDeviceMode 实例对象
+ * @return 实例对象
+ */
+ @Override
+ public int insert(PlcDeviceMode plcDeviceMode) {
+ Long tenantId = SecurityUtils.getTenantId();
+ plcDeviceMode.setTenantId(tenantId);
+ plcDeviceMode.setDeviceModeStatus("1");
+ int rows = plcDeviceModeDao.insert(plcDeviceMode);
+ List functionList = plcDeviceMode.getFunctionList();
+ for (PlcDeviceModeFunction function : functionList) {
+ function.setDeviceModeId(plcDeviceMode.getDeviceModeId());
+ }
+ int i = plcDeviceModeFunctionDao.insertBatch(functionList);
+ this.createTdSuperTable(plcDeviceMode);
+ return rows;
+ }
+ private void createTdSuperTable(PlcDeviceMode plcDeviceMode) {
+ TdSuperTableVo tdSuperTableVo = new TdSuperTableVo();
+ String dbName = TdEngineConstants.getDatabaseName();
+ String superTableName = TdEngineConstants.PLC_SUPER_TABLE_NAME_PREFIX + plcDeviceMode.getDeviceModeId();
+
+ List tagFields = new ArrayList();
+ TdField tagField = new TdField();
+ tagField.setFieldName(TdEngineConstants.PLC_TAG_IP);
+ tagField.setDataTypeCode(TdEngineConstants.PLC_TAG_IP_TYPE);
+ tagField.setSize(TdEngineConstants.PLC_TAG_IP_SIZE);
+ tagFields.add(tagField);
+
+ tagField = new TdField();
+ tagField.setFieldName(TdEngineConstants.PLC_TAG_PORT);
+ tagField.setDataTypeCode(TdEngineConstants.PLC_TAG_PORT_TYPE);
+// tagField.setSize(TdEngineConstants.ST_TAG_DEVICENAME_SIZE);
+ tagFields.add(tagField);
+
+ tagField = new TdField();
+ tagField.setFieldName(TdEngineConstants.PLC_TAG_LOCATION);
+ tagField.setDataTypeCode(TdEngineConstants.PLC_TAG_LOCATION_TYPE);
+ tagField.setSize(TdEngineConstants.PLC_TAG_LOCATION_SIZE);
+ tagFields.add(tagField);
+
+
+ List schemaFields = new ArrayList();
+ List hwDeviceModeFunctions = plcDeviceMode.getFunctionList();
+ TdField schemaField;
+ for (PlcDeviceModeFunction hwDeviceModeFunction : hwDeviceModeFunctions) {
+ String functionMode = hwDeviceModeFunction.getFunctionMode();
+ if (functionMode.equalsIgnoreCase(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) {
+ schemaField = new TdField();
+// String functionIdentifierTransfer = TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(hwDeviceModeFunction.getFunctionIdentifier());
+// String functionIdentifier = functionIdentifierTransfer == null ? hwDeviceModeFunction.getFunctionIdentifier() : functionIdentifierTransfer;
+ String functionIdentifier = hwDeviceModeFunction.getFunctionIdentifier();
+ schemaField.setFieldName(functionIdentifier);
+ Integer dataType = hwDeviceModeFunction.getDataType();
+ schemaField.setDataTypeCode(dataType);
+ if (String.valueOf(dataType).equals(String.valueOf(DataTypeEnums.NCHAR.getDataCode()))) {
+ schemaField.setSize(Integer.valueOf(hwDeviceModeFunction.getDataDefinition()));
+ }
+ schemaFields.add(schemaField);
+ }
+ }
+
+ tdSuperTableVo.setDatabaseName(dbName);
+ tdSuperTableVo.setSuperTableName(superTableName);
+ tdSuperTableVo.setFirstFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME);
+ tdSuperTableVo.setSchemaFields(schemaFields);
+ tdSuperTableVo.setTagsFields(tagFields);
+
+ R> tdReturnMsg = this.remoteTdEngineService.createSuperTable(tdSuperTableVo, SecurityConstants.INNER);
+ if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
+ throw new RuntimeException(tdReturnMsg.getMsg());
+ }
+ }
+
+ /**
+ * 修改数据
+ *
+ * @param plcDeviceMode 实例对象
+ * @return 实例对象
+ */
+ @Override
+ public int update(PlcDeviceMode plcDeviceMode) {
+
+ return this.plcDeviceModeDao.update(plcDeviceMode);
+ }
+
+ @Override
+ public int deleteHwDeviceModeByDeviceModeIds(Long[] deviceModeIds) {
+ plcDeviceModeFunctionDao.deleteHwDeviceModeFunctionByDeviceModeIds(deviceModeIds);
+ return plcDeviceModeDao.deleteHwDeviceModeByDeviceModeIds(deviceModeIds);
+ }
+
+ @Override
+ public List selectFunctionList(Long deviceModeId) {
+ return plcDeviceModeFunctionDao.selectFunctionList(deviceModeId);
+ }
+
+ @Override
+ public PlcDeviceMode selectHwDeviceModeByDeviceModeId(Long deviceModeId) {
+ return plcDeviceModeDao.queryById(deviceModeId);
+ }
+
+ @Override
+ public List selectList(PlcDeviceMode hwDeviceMode) {
+ return plcDeviceModeDao.selectList(hwDeviceMode);
+ }
+
+ /**
+ * 通过主键删除数据
+ *
+ * @param deviceModeId 主键
+ * @return 是否成功
+ */
+ @Override
+ public boolean deleteById(Long deviceModeId) {
+ return this.plcDeviceModeDao.deleteById(deviceModeId) > 0;
+ }
+}
diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/PlcDeviceServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/PlcDeviceServiceImpl.java
new file mode 100644
index 0000000..58a3c5c
--- /dev/null
+++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/PlcDeviceServiceImpl.java
@@ -0,0 +1,551 @@
+package com.ruoyi.business.service.impl;
+
+import HslCommunication.Core.Transfer.DataFormat;
+import HslCommunication.Core.Types.OperateResultExOne;
+import HslCommunication.ModBus.ModbusTcpNet;
+import HslCommunication.Profinet.Melsec.MelsecA1ENet;
+import HslCommunication.Profinet.Melsec.MelsecFxSerialOverTcp;
+import HslCommunication.Profinet.Melsec.MelsecHelper;
+import HslCommunication.Profinet.Melsec.MelsecMcNet;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.ruoyi.business.domain.*;
+import com.ruoyi.business.mapper.PlcDeviceDao;
+import com.ruoyi.business.mapper.PlcDeviceModeFunctionDao;
+import com.ruoyi.business.service.PlcDeviceService;
+import com.ruoyi.common.core.constant.Constants;
+import com.ruoyi.common.core.constant.HwDictConstants;
+import com.ruoyi.common.core.constant.SecurityConstants;
+import com.ruoyi.common.core.constant.TdEngineConstants;
+import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.enums.DataTypeEnums;
+import com.ruoyi.common.core.exception.ServiceException;
+import com.ruoyi.common.core.utils.DateUtils;
+import com.ruoyi.common.security.utils.SecurityUtils;
+import com.ruoyi.system.api.domain.SysUser;
+import com.ruoyi.system.api.model.LoginUser;
+import com.ruoyi.tdengine.api.RemoteTdEngineService;
+import com.ruoyi.tdengine.api.domain.AlterTagVo;
+import com.ruoyi.tdengine.api.domain.TdField;
+import com.ruoyi.tdengine.api.domain.TdTableVo;
+import org.apache.poi.ss.formula.functions.T;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageImpl;
+import org.springframework.data.domain.PageRequest;
+
+import javax.annotation.Resource;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * plc设备信息(PlcDevice)表服务实现类
+ *
+ * @author makejava
+ * @since 2024-12-19 16:22:51
+ */
+@Service("plcDeviceService")
+public class PlcDeviceServiceImpl implements PlcDeviceService {
+ @Resource
+ private PlcDeviceDao plcDeviceDao;
+ @Autowired
+ private RemoteTdEngineService remoteTdEngineService;
+ @Autowired
+ private PlcDeviceModeFunctionDao plcDeviceModeFunctionDao;
+
+ /**
+ * 通过ID查询单条数据
+ *
+ * @param deviceId 主键
+ * @return 实例对象
+ */
+ @Override
+ public PlcDevice queryById(Long deviceId) throws JsonProcessingException {
+// List plcDevices = this.plcDeviceDao.queryPlcDevices(1);
+// for (PlcDevice plcDevice : plcDevices) {
+// int station = plcDevice.getStation();
+// byte a = (byte)station;
+// int length = plcDevice.getLength();
+// short b = (short)length;
+// ModbusTcpNet tcpNet = new ModbusTcpNet(plcDevice.getIp(),plcDevice.getPort1(), a);
+// tcpNet.getByteTransform().setDataFormat(DataFormat.CDAB);
+// TdTableVo tdTableVo = new TdTableVo();
+// List schemaFields = new ArrayList<>();
+// TdField firstTdField = new TdField();
+// firstTdField.setFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME);
+// long currentTimeMillis = System.currentTimeMillis();
+// firstTdField.setFieldValue(currentTimeMillis);
+// String databaseName = TdEngineConstants.getDatabaseName();
+// String tableName = TdEngineConstants.PLC_TABLE_NAME_PREFIX + plcDevice.getDeviceId();
+// // firstTdField.setFieldValue(ts);
+// schemaFields.add(firstTdField);
+// List list = plcDeviceModeFunctionDao.selectFunctions(plcDevice.getDeviceModeId());
+// if (plcDevice.getDataType().equals("10")){
+// OperateResultExOne resultExOne = tcpNet.ReadString(plcDevice.getDLocation(),b, StandardCharsets.UTF_8);
+// String content = resultExOne.Content;
+// ObjectMapper objectMapper = new ObjectMapper();
+// Map map = objectMapper.readValue(content, Map.class);
+// for (PlcDeviceModeFunction function : list) {
+// Object value = map.get(function.getFunctionIdentifier());
+// TdField tdField = new TdField();
+// tdField.setFieldName(function.getFunctionIdentifier());
+// tdField.setFieldValue(value);
+// schemaFields.add(tdField);
+// }
+// }else if (plcDevice.getDataType().equals("2")){
+// OperateResultExOne exOne = tcpNet.ReadInt32(plcDevice.getDLocation());
+// TdField tdField = new TdField();
+// tdField.setFieldName(list.get(0).getFunctionIdentifier());
+// tdField.setFieldValue(exOne.Content);
+// schemaFields.add(tdField);
+// }else if (plcDevice.getDataType().equals("4")){
+// OperateResultExOne floatOperateResultExOne = tcpNet.ReadFloat(plcDevice.getDLocation());
+// TdField tdField = new TdField();
+// tdField.setFieldName(list.get(0).getFunctionIdentifier());
+// tdField.setFieldValue(floatOperateResultExOne.Content);
+// schemaFields.add(tdField);
+// }
+// tdTableVo.setDatabaseName(databaseName);
+// tdTableVo.setTableName(tableName);
+// tdTableVo.setSchemaFields(schemaFields);
+// final R> insertResult = this.remoteTdEngineService.insertTable(tdTableVo , SecurityConstants.INNER);
+// }
+
+// OperateResultExOne exOne = tcpNet.ReadFloat("100");
+// System.out.println(exOne.Content);
+ return this.plcDeviceDao.selectHwDeviceByDeviceId(deviceId);
+ }
+
+ @Override
+ public int updateDevice(PlcDevice hwDevice) {
+ PlcDevice dbDevice = plcDeviceDao.selectHwDeviceByDeviceId(hwDevice.getDeviceId());
+ if (dbDevice.getDeviceStatus().equals(HwDictConstants.DEVICE_STATUS_PUBLISH)) {
+ throw new ServiceException("已发布状态不能修改");
+ }
+ hwDevice.setUpdateTime(DateUtils.getNowDate());
+ int rows = plcDeviceDao.update(hwDevice);
+ this.updateTdEngine(hwDevice, dbDevice);
+ return rows;
+ }
+ public void updateTdEngine(PlcDevice hwDevice, PlcDevice dbDevice) {
+
+ String databaseName = TdEngineConstants.getDatabaseName();
+ String tableName = TdEngineConstants.PLC_TABLE_NAME_PREFIX + hwDevice.getDeviceId();
+ AlterTagVo alterTagVo = new AlterTagVo();
+ alterTagVo.setDatabaseName(databaseName);
+ alterTagVo.setTableName(tableName);
+ R> tdReturnMsg;
+ if (!hwDevice.getIp().equals(dbDevice.getIp())) {
+ alterTagVo.setTagName(TdEngineConstants.PLC_TAG_IP);
+ alterTagVo.setTagValue("'" + hwDevice.getIp() + "'");
+
+ tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo, SecurityConstants.INNER);
+ if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
+ throw new RuntimeException(tdReturnMsg.getMsg());
+ }
+ }
+ if (!hwDevice.getPort1().equals(dbDevice.getPort1())) {
+ alterTagVo.setTagName(TdEngineConstants.PLC_TAG_PORT);
+ alterTagVo.setTagValue(hwDevice.getPort1());
+ tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo, SecurityConstants.INNER);
+ if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
+ throw new RuntimeException(tdReturnMsg.getMsg());
+ }
+ }
+
+ if (!hwDevice.getLocation().equals(dbDevice.getLocation())) {
+ alterTagVo.setTagName(TdEngineConstants.PLC_TAG_LOCATION);
+ alterTagVo.setTagValue("'" + hwDevice.getLocation() + "'");
+ tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo, SecurityConstants.INNER);
+ if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
+ throw new RuntimeException(tdReturnMsg.getMsg());
+ }
+ }
+
+ }
+
+ @Override
+ public int changeDeviceStatus(PlcDevice device) {
+ PlcDevice dbDevice = plcDeviceDao.selectHwDeviceByDeviceId(device.getDeviceId());
+ if (dbDevice.getDeviceStatus().equals(HwDictConstants.DEVICE_STATUS_PUBLISH) && !device.getDeviceStatus().equals("0")) {
+ throw new ServiceException("已发布状态不能修改");
+ }
+ device.setUpdateBy(SecurityUtils.getUsername());
+ Date currentDate = new Date();
+ device.setUpdateTime(currentDate);
+ device.setPublishTime(currentDate);
+ return plcDeviceDao.update(device);
+ }
+
+ @Override
+ public List selectHwDeviceModeList(PlcDeviceMode queryDeviceMode) {
+ return plcDeviceDao.selectPlcDeviceMode(queryDeviceMode);
+ }
+
+ @Override
+ public List selectHwDeviceJoinList(PlcDevice hwDevice) {
+ LoginUser loginUser = SecurityUtils.getLoginUser();
+ SysUser sysUser = loginUser.getSysUser();
+ Long tenantId = sysUser.getTenantId();
+ hwDevice.setTenantId(tenantId);
+ return plcDeviceDao.selectHwDeviceJoinList(hwDevice);
+ }
+
+ // mc协议获取处理plc数据
+ @Override
+ public String mcDataProcess() throws JsonProcessingException {
+ List plcDevices = this.plcDeviceDao.queryPlcDevices(1);
+ for (PlcDevice plcDevice : plcDevices) {
+ int station = plcDevice.getStation();
+ byte a = (byte)station;
+ int length = plcDevice.getLength();
+ short b = (short)length;
+ MelsecMcNet melsecMcNet = new MelsecMcNet(plcDevice.getIp(),plcDevice.getPort1());
+// ModbusTcpNet tcpNet = new ModbusTcpNet(plcDevice.getIp(),plcDevice.getPort1(), a);
+// tcpNet.getByteTransform().setDataFormat(DataFormat.CDAB);
+ TdTableVo tdTableVo = new TdTableVo();
+ List schemaFields = new ArrayList<>();
+ TdField firstTdField = new TdField();
+ firstTdField.setFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME);
+ long currentTimeMillis = System.currentTimeMillis();
+ firstTdField.setFieldValue(currentTimeMillis);
+ String databaseName = TdEngineConstants.getDatabaseName();
+ String tableName = TdEngineConstants.PLC_TABLE_NAME_PREFIX + plcDevice.getDeviceId();
+ // firstTdField.setFieldValue(ts);
+ schemaFields.add(firstTdField);
+ List list = plcDeviceModeFunctionDao.selectFunctions(plcDevice.getDeviceModeId());
+ if (plcDevice.getDataType().equals("10")){
+ OperateResultExOne resultExOne = melsecMcNet.ReadString(plcDevice.getLocation(),b, StandardCharsets.UTF_8);
+ String content = resultExOne.Content;
+ ObjectMapper objectMapper = new ObjectMapper();
+ Map map = objectMapper.readValue(content, Map.class);
+ for (PlcDeviceModeFunction function : list) {
+ Object value = map.get(function.getFunctionIdentifier());
+ TdField tdField = new TdField();
+ tdField.setFieldName(function.getFunctionIdentifier());
+ tdField.setFieldValue(value);
+ schemaFields.add(tdField);
+ }
+ }else if (plcDevice.getDataType().equals("2")||plcDevice.getDataType().equals("9")){
+ OperateResultExOne exOne = melsecMcNet.ReadInt32(plcDevice.getLocation());
+ TdField tdField = new TdField();
+ tdField.setFieldName(list.get(0).getFunctionIdentifier());
+ tdField.setFieldValue(exOne.Content);
+ schemaFields.add(tdField);
+ }else if (plcDevice.getDataType().equals("4")){
+ OperateResultExOne floatOperateResultExOne = melsecMcNet.ReadFloat(plcDevice.getLocation());
+ TdField tdField = new TdField();
+ tdField.setFieldName(list.get(0).getFunctionIdentifier());
+ tdField.setFieldValue(floatOperateResultExOne.Content);
+ schemaFields.add(tdField);
+ }else if (plcDevice.getDataType().equals("5")){
+ OperateResultExOne doubleOperateResultExOne = melsecMcNet.ReadDouble(plcDevice.getLocation());
+ TdField tdField = new TdField();
+ tdField.setFieldName(list.get(0).getFunctionIdentifier());
+ tdField.setFieldValue(doubleOperateResultExOne.Content);
+ schemaFields.add(tdField);
+ }
+ tdTableVo.setDatabaseName(databaseName);
+ tdTableVo.setTableName(tableName);
+ tdTableVo.setSchemaFields(schemaFields);
+ final R> insertResult = this.remoteTdEngineService.insertTable(tdTableVo , SecurityConstants.INNER);
+ }
+ return null;
+ }
+// modbus协议获取处理plc数据
+ @Override
+ public String modbusDataProcess() throws JsonProcessingException {
+ List plcDevices = this.plcDeviceDao.queryPlcDevices(2);
+ for (PlcDevice plcDevice : plcDevices) {
+ int station = plcDevice.getStation();
+ byte a = (byte)station;
+ int length = plcDevice.getLength();
+ short b = (short)length;
+ ModbusTcpNet tcpNet = new ModbusTcpNet(plcDevice.getIp(),plcDevice.getPort1(), a);
+ tcpNet.getByteTransform().setDataFormat(DataFormat.CDAB);
+ TdTableVo tdTableVo = new TdTableVo();
+ List schemaFields = new ArrayList<>();
+ TdField firstTdField = new TdField();
+ firstTdField.setFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME);
+ long currentTimeMillis = System.currentTimeMillis();
+ firstTdField.setFieldValue(currentTimeMillis);
+ String databaseName = TdEngineConstants.getDatabaseName();
+ String tableName = TdEngineConstants.PLC_TABLE_NAME_PREFIX + plcDevice.getDeviceId();
+ // firstTdField.setFieldValue(ts);
+ schemaFields.add(firstTdField);
+ List list = plcDeviceModeFunctionDao.selectFunctions(plcDevice.getDeviceModeId());
+ if (plcDevice.getDataType().equals("10")){
+ OperateResultExOne resultExOne = tcpNet.ReadString(plcDevice.getLocation(),b, StandardCharsets.UTF_8);
+ String content = resultExOne.Content;
+ ObjectMapper objectMapper = new ObjectMapper();
+ Map map = objectMapper.readValue(content, Map.class);
+ for (PlcDeviceModeFunction function : list) {
+ Object value = map.get(function.getFunctionIdentifier());
+ TdField tdField = new TdField();
+ tdField.setFieldName(function.getFunctionIdentifier());
+ tdField.setFieldValue(value);
+ schemaFields.add(tdField);
+ }
+ }else if (plcDevice.getDataType().equals("2")||plcDevice.getDataType().equals("9")){
+ OperateResultExOne exOne = tcpNet.ReadInt32(plcDevice.getLocation());
+ TdField tdField = new TdField();
+ tdField.setFieldName(list.get(0).getFunctionIdentifier());
+ tdField.setFieldValue(exOne.Content);
+ schemaFields.add(tdField);
+ }else if (plcDevice.getDataType().equals("4")){
+ OperateResultExOne floatOperateResultExOne = tcpNet.ReadFloat(plcDevice.getLocation());
+ TdField tdField = new TdField();
+ tdField.setFieldName(list.get(0).getFunctionIdentifier());
+ tdField.setFieldValue(floatOperateResultExOne.Content);
+ schemaFields.add(tdField);
+ }else if (plcDevice.getDataType().equals("5")){
+ OperateResultExOne doubleOperateResultExOne = tcpNet.ReadDouble(plcDevice.getLocation());
+ TdField tdField = new TdField();
+ tdField.setFieldName(list.get(0).getFunctionIdentifier());
+ tdField.setFieldValue(doubleOperateResultExOne.Content);
+ schemaFields.add(tdField);
+ }
+ tdTableVo.setDatabaseName(databaseName);
+ tdTableVo.setTableName(tableName);
+ tdTableVo.setSchemaFields(schemaFields);
+ final R> insertResult = this.remoteTdEngineService.insertTable(tdTableVo , SecurityConstants.INNER);
+ }
+ return null;
+ }
+//link数据读取
+ @Override
+ public String linkDataProcess() {
+// List plcDevices = this.plcDeviceDao.queryPlcDevices(1);
+// for (PlcDevice plcDevice : plcDevices) {
+// int station = plcDevice.getStation();
+// byte a = (byte)station;
+// int length = plcDevice.getLength();
+// short b = (short)length;
+// // ModbusTcpNet tcpNet = new ModbusTcpNet(plcDevice.getIp(),plcDevice.getPort1(), a);
+// // tcpNet.getByteTransform().setDataFormat(DataFormat.CDAB);
+// MelsecA1ENet net = new MelsecA1ENet(plcDevice.getIp(),plcDevice.getPort1());
+// MelsecFxSerialOverTcp melsecFxSerialOverTcp = new MelsecFxSerialOverTcp();
+// TdTableVo tdTableVo = new TdTableVo();
+// List schemaFields = new ArrayList<>();
+// TdField firstTdField = new TdField();
+// firstTdField.setFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME);
+// long currentTimeMillis = System.currentTimeMillis();
+// firstTdField.setFieldValue(currentTimeMillis);
+// String databaseName = TdEngineConstants.getDatabaseName();
+// String tableName = TdEngineConstants.PLC_TABLE_NAME_PREFIX + plcDevice.getDeviceId();
+// // firstTdField.setFieldValue(ts);
+// schemaFields.add(firstTdField);
+// List list = plcDeviceModeFunctionDao.selectFunctions(plcDevice.getDeviceModeId());
+// if (plcDevice.getDataType().equals("10")){
+// OperateResultExOne resultExOne = net.ReadString(plcDevice.getLocation(),b, StandardCharsets.UTF_8);
+// String content = resultExOne.Content;
+// ObjectMapper objectMapper = new ObjectMapper();
+// Map map = objectMapper.readValue(content, Map.class);
+// for (PlcDeviceModeFunction function : list) {
+// Object value = map.get(function.getFunctionIdentifier());
+// TdField tdField = new TdField();
+// tdField.setFieldName(function.getFunctionIdentifier());
+// tdField.setFieldValue(value);
+// schemaFields.add(tdField);
+// }
+// }else if (plcDevice.getDataType().equals("2")){
+// OperateResultExOne exOne = net.ReadInt32(plcDevice.getLocation());
+// TdField tdField = new TdField();
+// tdField.setFieldName(list.get(0).getFunctionIdentifier());
+// tdField.setFieldValue(exOne.Content);
+// schemaFields.add(tdField);
+// }else if (plcDevice.getDataType().equals("4")){
+// OperateResultExOne floatOperateResultExOne = net.ReadFloat(plcDevice.getLocation());
+// TdField tdField = new TdField();
+// tdField.setFieldName(list.get(0).getFunctionIdentifier());
+// tdField.setFieldValue(floatOperateResultExOne.Content);
+// schemaFields.add(tdField);
+// }
+// tdTableVo.setDatabaseName(databaseName);
+// tdTableVo.setTableName(tableName);
+// tdTableVo.setSchemaFields(schemaFields);
+// final R> insertResult = this.remoteTdEngineService.insertTable(tdTableVo , SecurityConstants.INNER);
+// }
+ return null;
+ }
+
+ // A1E协议
+ public String aeDataProcess() throws JsonProcessingException {
+ List plcDevices = this.plcDeviceDao.queryPlcDevices(3);
+ for (PlcDevice plcDevice : plcDevices) {
+ int station = plcDevice.getStation();
+ byte a = (byte)station;
+ int length = plcDevice.getLength();
+ short b = (short)length;
+ // ModbusTcpNet tcpNet = new ModbusTcpNet(plcDevice.getIp(),plcDevice.getPort1(), a);
+ // tcpNet.getByteTransform().setDataFormat(DataFormat.CDAB);
+ MelsecA1ENet net = new MelsecA1ENet(plcDevice.getIp(),plcDevice.getPort1());
+ TdTableVo tdTableVo = new TdTableVo();
+ List schemaFields = new ArrayList<>();
+ TdField firstTdField = new TdField();
+ firstTdField.setFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME);
+ long currentTimeMillis = System.currentTimeMillis();
+ firstTdField.setFieldValue(currentTimeMillis);
+ String databaseName = TdEngineConstants.getDatabaseName();
+ String tableName = TdEngineConstants.PLC_TABLE_NAME_PREFIX + plcDevice.getDeviceId();
+ // firstTdField.setFieldValue(ts);
+ schemaFields.add(firstTdField);
+ List list = plcDeviceModeFunctionDao.selectFunctions(plcDevice.getDeviceModeId());
+ if (plcDevice.getDataType().equals("10")){
+ OperateResultExOne resultExOne = net.ReadString(plcDevice.getLocation(),b, StandardCharsets.UTF_8);
+ String content = resultExOne.Content;
+ ObjectMapper objectMapper = new ObjectMapper();
+ Map map = objectMapper.readValue(content, Map.class);
+ for (PlcDeviceModeFunction function : list) {
+ Object value = map.get(function.getFunctionIdentifier());
+ TdField tdField = new TdField();
+ tdField.setFieldName(function.getFunctionIdentifier());
+ tdField.setFieldValue(value);
+ schemaFields.add(tdField);
+ }
+ }else if (plcDevice.getDataType().equals("2")||plcDevice.getDataType().equals("9")){
+ OperateResultExOne exOne = net.ReadInt32(plcDevice.getLocation());
+ TdField tdField = new TdField();
+ tdField.setFieldName(list.get(0).getFunctionIdentifier());
+ tdField.setFieldValue(exOne.Content);
+ schemaFields.add(tdField);
+ }else if (plcDevice.getDataType().equals("4")){
+ OperateResultExOne floatOperateResultExOne = net.ReadFloat(plcDevice.getLocation());
+ TdField tdField = new TdField();
+ tdField.setFieldName(list.get(0).getFunctionIdentifier());
+ tdField.setFieldValue(floatOperateResultExOne.Content);
+ schemaFields.add(tdField);
+ }else if (plcDevice.getDataType().equals("5")){
+ OperateResultExOne doubleOperateResultExOne = net.ReadDouble(plcDevice.getLocation());
+ TdField tdField = new TdField();
+ tdField.setFieldName(list.get(0).getFunctionIdentifier());
+ tdField.setFieldValue(doubleOperateResultExOne.Content);
+ schemaFields.add(tdField);
+ }
+ tdTableVo.setDatabaseName(databaseName);
+ tdTableVo.setTableName(tableName);
+ tdTableVo.setSchemaFields(schemaFields);
+ final R> insertResult = this.remoteTdEngineService.insertTable(tdTableVo , SecurityConstants.INNER);
+ }
+ return null;
+ }
+ /**
+ * 分页查询
+ *
+ * @param plcDevice 筛选条件
+ * @param pageRequest 分页对象
+ * @return 查询结果
+ */
+ @Override
+ public Page queryByPage(PlcDevice plcDevice, PageRequest pageRequest) {
+ long total = this.plcDeviceDao.count(plcDevice);
+ return new PageImpl<>(this.plcDeviceDao.queryAllByLimit(plcDevice, pageRequest), pageRequest, total);
+ }
+
+ /**
+ * 新增数据
+ *
+ * @param plcDevice 实例对象
+ * @return 实例对象
+ */
+ @Override
+ public int insert(PlcDevice plcDevice) {
+ String username = SecurityUtils.getUsername();
+ plcDevice.setCreateBy(username);
+ plcDevice.setCreateTime(new Date());
+ Long tenantId = SecurityUtils.getTenantId();
+ plcDevice.setTenantId(tenantId);
+ plcDevice.setDeviceStatus("0");
+ int deviceId = this.plcDeviceDao.insert(plcDevice);
+ this.createTdTable(plcDevice);
+ return deviceId;
+ }
+
+// public void createTdDeviceStatusTable(HwDevice hwDevice) {
+// TdTableVo tdTableVo = new TdTableVo();
+// tdTableVo.setDatabaseName(TdEngineConstants.PLATFORM_DB_NAME);
+// tdTableVo.setSuperTableName(TdEngineConstants.DEFAULT_DEVICE_STATUS_SUPER_TABLE_NAME);
+// tdTableVo.setTableName(TdEngineConstants.getDeviceStatusTableName(hwDevice.getDeviceId()));
+//
+// List tagsFields = getTdTagsFields(hwDevice);
+//
+// TdField sceneIdTag = new TdField();
+// sceneIdTag.setFieldName(TdEngineConstants.ST_TAG_SCENEID);
+// sceneIdTag.setFieldValue(hwDevice.getSceneId());
+// tagsFields.add(sceneIdTag);
+//
+// tdTableVo.setTagsFieldValues(tagsFields);
+//
+// R> tdReturnMsg = this.remoteTdEngineService.createTable(tdTableVo, SecurityConstants.INNER);
+// if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
+// throw new RuntimeException(tdReturnMsg.getMsg());
+// }
+// }
+ public void createTdTable(PlcDevice hwDevice) {
+ TdTableVo tdTableVo = new TdTableVo();
+ String databaseName = TdEngineConstants.getDatabaseName();
+ String superTableName = TdEngineConstants.PLC_SUPER_TABLE_NAME_PREFIX+hwDevice.getDeviceModeId();
+ String tableName = TdEngineConstants.PLC_TABLE_NAME_PREFIX+hwDevice.getDeviceId();
+
+ List tagsFields = getTdTagsFields(hwDevice);
+
+ tdTableVo.setDatabaseName(databaseName);
+ tdTableVo.setSuperTableName(superTableName);
+ tdTableVo.setTableName(tableName);
+ tdTableVo.setTagsFieldValues(tagsFields);
+
+ R> tdReturnMsg = this.remoteTdEngineService.createTable(tdTableVo, SecurityConstants.INNER);
+ if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
+ throw new RuntimeException(tdReturnMsg.getMsg());
+ }
+ }
+
+ private List getTdTagsFields(PlcDevice hwDevice) {
+ List tagFields = new ArrayList();
+ TdField ipTag = new TdField();
+ ipTag.setFieldName(TdEngineConstants.PLC_TAG_IP);
+ ipTag.setFieldValue(hwDevice.getIp());
+ ipTag.setDataTypeCode(DataTypeEnums.NCHAR.getDataCode());
+ tagFields.add(ipTag);
+
+ TdField portTag = new TdField();
+ portTag.setFieldName(TdEngineConstants.PLC_TAG_PORT);
+ portTag.setFieldValue(hwDevice.getPort1());
+ tagFields.add(portTag);
+
+ TdField locationTag = new TdField();
+ locationTag.setFieldName(TdEngineConstants.PLC_TAG_LOCATION);
+ locationTag.setDataTypeCode(DataTypeEnums.NCHAR.getDataCode());
+ locationTag.setFieldValue(hwDevice.getLocation());
+ tagFields.add(locationTag);
+ return tagFields;
+ }
+
+ /**
+ * 修改数据
+ *
+ * @param plcDevice 实例对象
+ * @return 实例对象
+ */
+ @Override
+ public PlcDevice update(PlcDevice plcDevice) throws JsonProcessingException {
+ this.plcDeviceDao.update(plcDevice);
+ return this.queryById(plcDevice.getDeviceId());
+ }
+
+
+ /**
+ * 通过主键删除数据
+ *
+ * @param deviceId 主键
+ * @return 是否成功
+ */
+ @Override
+ public int deleteById(Long deviceId) {
+ return this.plcDeviceDao.deleteById(deviceId);
+ }
+}
diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/PlcDeviceDao.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/PlcDeviceDao.xml
new file mode 100644
index 0000000..76162c0
--- /dev/null
+++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/PlcDeviceDao.xml
@@ -0,0 +1,280 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ insert into plc_device(device_code, device_name, tenant_id, scene_id, ip, port1, location, access_protocol, length, device_status, create_by, create_time, update_by, update_time,station,data_type,device_mode_id)
+ values (#{deviceCode}, #{deviceName}, #{tenantId}, #{sceneId}, #{ip}, #{port1}, #{location}, #{accessProtocol}, #{length}, #{deviceStatus}, #{createBy}, #{createTime}, #{updateBy}, #{updateTime},#{station},#{dataType},#{deviceModeId})
+
+
+
+ insert into plc_device(device_code, device_name, tenant_id, scene_id, ip, port1, location, access_protocol, length, device_status, create_by, create_time, update_by, update_time)
+ values
+
+ (#{entity.deviceCode}, #{entity.deviceName}, #{entity.tenantId}, #{entity.sceneId}, #{entity.ip}, #{entity.port1}, #{entity.location}, #{entity.accessProtocol}, #{entity.length}, #{entity.deviceStatus}, #{entity.createBy}, #{entity.createTime}, #{entity.updateBy}, #{entity.updateTime})
+
+
+
+
+ insert into plc_device(device_code, device_name, tenant_id, scene_id, ip, port1, location, access_protocol, length, device_status, create_by, create_time, update_by, update_time)
+ values
+
+ (#{entity.deviceCode}, #{entity.deviceName}, #{entity.tenantId}, #{entity.sceneId}, #{entity.ip}, #{entity.port1}, #{entity.location}, #{entity.accessProtocol}, #{entity.length}, #{entity.deviceStatus}, #{entity.createBy}, #{entity.createTime}, #{entity.updateBy}, #{entity.updateTime})
+
+ on duplicate key update
+ device_code = values(device_code),
+ device_name = values(device_name),
+ tenant_id = values(tenant_id),
+ scene_id = values(scene_id),
+ ip = values(ip),
+ port1 = values(port1),
+ location = values(location),
+ access_protocol = values(access_protocol),
+ length = values(length),
+ device_status = values(device_status),
+ create_by = values(create_by),
+ create_time = values(create_time),
+ update_by = values(update_by),
+ update_time = values(update_time)
+
+
+
+
+ update plc_device
+
+
+ device_code = #{deviceCode},
+
+
+ device_name = #{deviceName},
+
+
+ tenant_id = #{tenantId},
+
+
+ scene_id = #{sceneId},
+
+
+ ip = #{ip},
+
+
+ port1 = #{port1},
+
+
+ location = #{location},
+
+
+ access_protocol = #{accessProtocol},
+
+
+ length = #{length},
+
+
+ device_status = #{deviceStatus},
+
+
+ create_by = #{createBy},
+
+
+ create_time = #{createTime},
+
+
+ update_by = #{updateBy},
+
+
+ update_time = #{updateTime},
+
+
+ data_type = #{dataType},
+
+
+ station = #{station},
+
+
+ where device_id = #{deviceId}
+
+
+
+
+ delete from plc_device where device_id = #{deviceId}
+
+
+
+
diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/PlcDeviceModeDao.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/PlcDeviceModeDao.xml
new file mode 100644
index 0000000..e3d9a95
--- /dev/null
+++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/PlcDeviceModeDao.xml
@@ -0,0 +1,206 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ insert into plc_device_mode(device_mode_name, tenant_id, scene_id, device_mode_status, create_by, create_time, update_by, update_time)
+ values (#{deviceModeName}, #{tenantId}, #{sceneId}, #{deviceModeStatus}, #{createBy}, #{createTime}, #{updateBy}, #{updateTime})
+
+
+
+ insert into plc_device_mode(device_mode_name, tenant_id, scene_id, device_mode_status, create_by, create_time, update_by, update_time)
+ values
+
+ (#{entity.deviceModeName}, #{entity.tenantId}, #{entity.sceneId}, #{entity.deviceModeStatus}, #{entity.createBy}, #{entity.createTime}, #{entity.updateBy}, #{entity.updateTime})
+
+
+
+
+ insert into plc_device_mode(device_mode_name, tenant_id, scene_id, device_mode_status, create_by, create_time, update_by, update_time)
+ values
+
+ (#{entity.deviceModeName}, #{entity.tenantId}, #{entity.sceneId}, #{entity.deviceModeStatus}, #{entity.createBy}, #{entity.createTime}, #{entity.updateBy}, #{entity.updateTime})
+
+ on duplicate key update
+ device_mode_name = values(device_mode_name),
+ tenant_id = values(tenant_id),
+ scene_id = values(scene_id),
+ device_mode_status = values(device_mode_status),
+ create_by = values(create_by),
+ create_time = values(create_time),
+ update_by = values(update_by),
+ update_time = values(update_time)
+
+
+
+
+ update plc_device_mode
+
+
+ device_mode_name = #{deviceModeName},
+
+
+ tenant_id = #{tenantId},
+
+
+ scene_id = #{sceneId},
+
+
+ device_mode_status = #{deviceModeStatus},
+
+
+ create_by = #{createBy},
+
+
+ create_time = #{createTime},
+
+
+ update_by = #{updateBy},
+
+
+ update_time = #{updateTime},
+
+
+ where device_mode_id = #{deviceModeId}
+
+
+
+
+ delete from plc_device_mode where device_mode_id = #{deviceModeId}
+
+
+ delete from plc_device_mode where device_mode_id in
+
+ #{deviceModeId}
+
+
+
+
+
diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/PlcDeviceModeFunctionDao.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/PlcDeviceModeFunctionDao.xml
new file mode 100644
index 0000000..611b23c
--- /dev/null
+++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/PlcDeviceModeFunctionDao.xml
@@ -0,0 +1,182 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ insert into plc_device_mode_function(device_mode_id, function_name, function_identifier, data_type, data_definition, property_unit, remark,function_mode)
+ values (#{deviceModeId}, #{functionName}, #{functionIdentifier}, #{dataType}, #{dataDefinition}, #{propertyUnit}, #{remark},#{functionMode})
+
+
+
+ insert into plc_device_mode_function(device_mode_id, function_name, function_identifier, data_type, data_definition, property_unit, remark,function_mode)
+ values
+
+ (#{entity.deviceModeId}, #{entity.functionName}, #{entity.functionIdentifier}, #{entity.dataType}, #{entity.dataDefinition}, #{entity.propertyUnit}, #{entity.remark},#{entity.functionMode})
+
+
+
+
+ insert into plc_device_mode_function(device_mode_id, function_name, function_identifier, data_type, data_definition, property_unit, remark)
+ values
+
+ (#{entity.deviceModeId}, #{entity.functionName}, #{entity.functionIdentifier}, #{entity.dataType}, #{entity.dataDefinition}, #{entity.propertyUnit}, #{entity.remark})
+
+ on duplicate key update
+ device_mode_id = values(device_mode_id),
+ function_name = values(function_name),
+ function_identifier = values(function_identifier),
+ data_type = values(data_type),
+ data_definition = values(data_definition),
+ property_unit = values(property_unit),
+ remark = values(remark)
+
+
+
+
+ update plc_device_mode_function
+
+
+ device_mode_id = #{deviceModeId},
+
+
+ function_name = #{functionName},
+
+
+ function_identifier = #{functionIdentifier},
+
+
+ data_type = #{dataType},
+
+
+ data_definition = #{dataDefinition},
+
+
+ property_unit = #{propertyUnit},
+
+
+ remark = #{remark},
+
+
+ where mode_function_id = #{modeFunctionId}
+
+
+
+
+ delete from plc_device_mode_function where mode_function_id = #{modeFunctionId}
+
+
+
+
+
+ delete from plc_device_mode_function where device_mode_id in
+
+ #{deviceModeId}
+
+
+
+
+