From 9c49930966edbe0f24e62e38f58c2d3e453976b3 Mon Sep 17 00:00:00 2001
From: jiazx0107@163.com <jiazx0107@163.com>
Date: 星期三, 23 八月 2023 15:51:39 +0800
Subject: [PATCH] 更新MODBUS-TCP协议 4
---
igds-core/src/main/java/com/ld/igds/modbus/service/HDeviceModbusService.java | 118 ++++
igds-core/src/main/java/com/ld/igds/view/service/DeviceService.java | 470 +++++++++---------
igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/command/RemoteControlServiceImpl.java | 120 ++--
igds-web/src/main/resources/application-dev.yml | 2
igds-core/src/main/java/com/ld/igds/view/Device.view.xml | 47 +
igds-core/src/main/java/com/ld/igds/io/constant/ProtocolEnum.java | 2
igds-core/src/main/java/com/ld/igds/modbus/DeviceModbus.view.xml | 289 ++++++++++++
igds-core/src/main/java/com/ld/igds/modbus/DeviceModbusPR.java | 92 +++
igds-protocol-modbus/pom.xml | 2
igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/data/ModbusTcp.java | 80 --
igds-core/src/main/java/com/ld/igds/models/Device.java | 12
igds-core/src/main/java/com/ld/igds/data/SimpleDepot.java | 3
igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/command/AnalysisService.java | 4
igds-core/src/main/java/com/ld/igds/modbus/ModbusConstant.java | 36 +
igds-core/src/main/resources/mapper/DeviceMapper.xml | 1
igds-core/src/main/java/com/ld/igds/models/DeviceModbus.java | 85 +++
igds-web/pom.xml | 18
igds-core/src/main/java/models/igds.model.xml | 12
18 files changed, 995 insertions(+), 398 deletions(-)
diff --git a/igds-core/src/main/java/com/ld/igds/data/SimpleDepot.java b/igds-core/src/main/java/com/ld/igds/data/SimpleDepot.java
index 6602824..d8b4885 100644
--- a/igds-core/src/main/java/com/ld/igds/data/SimpleDepot.java
+++ b/igds-core/src/main/java/com/ld/igds/data/SimpleDepot.java
@@ -4,9 +4,6 @@
import com.ld.igds.models.Depot;
import lombok.Data;
-import javax.persistence.Column;
-import javax.persistence.Id;
-
/**
* @Desc: 鐢ㄤ簬浣滀负涓嬫媺妗嗙殑鏁版嵁灏佽锛屽彧鍖呭惈鍩虹淇℃伅
* @author: andy.jia
diff --git a/igds-core/src/main/java/com/ld/igds/io/constant/ProtocolEnum.java b/igds-core/src/main/java/com/ld/igds/io/constant/ProtocolEnum.java
index d951865..d22bf75 100644
--- a/igds-core/src/main/java/com/ld/igds/io/constant/ProtocolEnum.java
+++ b/igds-core/src/main/java/com/ld/igds/io/constant/ProtocolEnum.java
@@ -33,7 +33,7 @@
TCP_BHZH_INOUT_V1("TCP_BHZH_INOUT_V1", "閭︽捣鏅鸿兘鍑哄叆搴撴帶鍒跺櫒鍗忚"),
TCP_BEIBO_GRAIN_V1("TCP_BEIBO_GRAIN_V1", "璐濆崥绮儏鍒嗘満鏈嶅姟绔崗璁�"),
FZZY_OPENAPI_HTTP("FZZY_OPENAPI_HTTP", "椋庢鑷磋繙API-HTTP鍗忚"),
- MODBUS_TCP("MODBUS_TCP", "Modbus-TCP鍗忚");
+ TCP_MODBUS("TCP_MODBUS", "Modbus-TCP鍗忚");
private String code;
diff --git a/igds-core/src/main/java/com/ld/igds/modbus/DeviceModbus.view.xml b/igds-core/src/main/java/com/ld/igds/modbus/DeviceModbus.view.xml
new file mode 100644
index 0000000..1c4353f
--- /dev/null
+++ b/igds-core/src/main/java/com/ld/igds/modbus/DeviceModbus.view.xml
@@ -0,0 +1,289 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ViewConfig>
+ <Arguments/>
+ <Context/>
+ <Model>
+ <DataType name="dtMain">
+ <Property name="creationType">com.ld.igds.models.DeviceModbus</Property>
+ <PropertyDef name="id">
+ <Property/>
+ <Property name="label">ID</Property>
+ </PropertyDef>
+ <PropertyDef name="deviceCode">
+ <Property/>
+ <Property name="label">璁惧缂栫爜</Property>
+ </PropertyDef>
+ <PropertyDef name="open">
+ <Property/>
+ <Property name="label">寮�鍦板潃</Property>
+ </PropertyDef>
+ <PropertyDef name="openFun">
+ <Property/>
+ <Property name="label">鍔熻兘鍙�</Property>
+ <Property name="mapping">
+ <Property name="mapValues">${dorado.getDataProvider("deviceModbusPR#triggerFun").getResult()}</Property>
+ <Property name="keyProperty">code</Property>
+ <Property name="valueProperty">name</Property>
+ </Property>
+ </PropertyDef>
+ <PropertyDef name="close">
+ <Property/>
+ <Property name="label">鍏冲湴鍧�</Property>
+ </PropertyDef>
+ <PropertyDef name="closeFun">
+ <Property/>
+ <Property name="label">鍔熻兘鍙�</Property>
+ <Property name="mapping">
+ <Property name="mapValues">${dorado.getDataProvider("deviceModbusPR#triggerFun").getResult()}</Property>
+ <Property name="keyProperty">code</Property>
+ <Property name="valueProperty">name</Property>
+ </Property>
+ </PropertyDef>
+ <PropertyDef name="stop">
+ <Property/>
+ <Property name="label">鍋滃湴鍧�</Property>
+ </PropertyDef>
+ <PropertyDef name="stopFun">
+ <Property/>
+ <Property name="label">鍔熻兘鍙�</Property>
+ <Property name="mapping">
+ <Property name="mapValues">${dorado.getDataProvider("deviceModbusPR#triggerFun").getResult()}</Property>
+ <Property name="keyProperty">code</Property>
+ <Property name="valueProperty">name</Property>
+ </Property>
+ </PropertyDef>
+ <PropertyDef name="openEnd">
+ <Property/>
+ <Property name="label">鍋滃湴鍧�</Property>
+ </PropertyDef>
+ <PropertyDef name="openEndFun">
+ <Property/>
+ <Property name="label">鍔熻兘鍙�</Property>
+ <Property name="mapping">
+ <Property name="mapValues">${dorado.getDataProvider("deviceModbusPR#triggerFun").getResult()}</Property>
+ <Property name="keyProperty">code</Property>
+ <Property name="valueProperty">name</Property>
+ </Property>
+ </PropertyDef>
+ <PropertyDef name="closeEnd">
+ <Property/>
+ <Property name="label">鍏冲埌浣嶅湴鍧�</Property>
+ </PropertyDef>
+ <PropertyDef name="closeEndFun">
+ <Property/>
+ <Property name="label">鍔熻兘鍙�</Property>
+ <Property name="mapping">
+ <Property name="mapValues">${dorado.getDataProvider("deviceModbusPR#triggerFun").getResult()}</Property>
+ <Property name="keyProperty">code</Property>
+ <Property name="valueProperty">name</Property>
+ </Property>
+ </PropertyDef>
+ <PropertyDef name="openError">
+ <Property/>
+ <Property name="label">寮�鏁呴殰鍦板潃</Property>
+ </PropertyDef>
+ <PropertyDef name="openErrorFun">
+ <Property/>
+ <Property name="label">鍔熻兘鍙�</Property>
+ <Property name="mapping">
+ <Property name="mapValues">${dorado.getDataProvider("deviceModbusPR#triggerFun").getResult()}</Property>
+ <Property name="keyProperty">code</Property>
+ <Property name="valueProperty">name</Property>
+ </Property>
+ </PropertyDef>
+ <PropertyDef name="closeError">
+ <Property/>
+ <Property name="label">鍏虫晠闅滃湴鍧�</Property>
+ </PropertyDef>
+ <PropertyDef name="closeErrorFun">
+ <Property/>
+ <Property name="label">鍔熻兘鍙�</Property>
+ <Property name="mapping">
+ <Property name="mapValues">${dorado.getDataProvider("deviceModbusPR#triggerFun").getResult()}</Property>
+ <Property name="keyProperty">code</Property>
+ <Property name="valueProperty">name</Property>
+ </Property>
+ </PropertyDef>
+ </DataType>
+ </Model>
+ <View layout="padding:5;regionPadding:5">
+ <Property name="packages">font-awesome,css-common</Property>
+ <DataSet id="dsMain">
+ <Property name="loadMode">lazy</Property>
+ <Property name="dataType">[dtMain]</Property>
+ <Property name="dataProvider">deviceModbusPR#listAll</Property>
+ </DataSet>
+ <Container layout="regionPadding:10" layoutConstraint="top">
+ <Property name="exClassName">bg-color</Property>
+ <Property name="contentOverflow">hidden</Property>
+ <Property name="height">55</Property>
+ <Label layoutConstraint="left">
+ <Property name="text">鑿滃崟鏍忥細</Property>
+ </Label>
+ <Button layoutConstraint="left">
+ <ClientEvent name="onClick">view.get("#dsMain").insert({});</ClientEvent>
+ <Property name="caption">鏂板</Property>
+ <Property name="exClassName">btn-default</Property>
+ <Property name="iconClass">fa fa-plus</Property>
+ </Button>
+ <Button>
+ <ClientEvent name="onClick"> view.get("#uaAction").execute(); </ClientEvent>
+ <Property name="caption">淇濆瓨</Property>
+ <Property name="iconClass">fa fa-check</Property>
+ <Property name="exClassName">btn-normal</Property>
+ </Button>
+ <Button layoutConstraint="left">
+ <ClientEvent name="onClick">var data = view.get("#dsMain.data:#");
+if(!data){
+ return;
+}
+view.get("#ajaxDel").set("parameter",data).execute(function(result){
+ if(result){
+ $alert(result);
+ return;
+ }else{
+ data.remove();
+ }
+}); </ClientEvent>
+ <Property name="caption">鍒犻櫎</Property>
+ <Property name="exClassName">btn-warn</Property>
+ <Property name="iconClass">fa fa-minus</Property>
+ </Button>
+ <Button layoutConstraint="left">
+ <ClientEvent name="onClick">view.get("#dsMain").flushAsync(); </ClientEvent>
+ <Property name="caption">鍒锋柊</Property>
+ <Property name="exClassName">btn-default</Property>
+ <Property name="iconClass">fa fa-refresh</Property>
+ </Button>
+ <Button layoutConstraint="left">
+ <Property name="caption">鍒锋柊缂撳瓨</Property>
+ <Property name="exClassName">btn-default</Property>
+ <Property name="iconClass">fa fa-refresh</Property>
+ <Property name="action">ajaxFlushCache</Property>
+ </Button>
+ </Container>
+ <Container layout="regionPadding:10" layoutConstraint="center">
+ <Property name="exClassName">bg-color</Property>
+ <DataGrid layoutConstraint="center padding:5px">
+ <Property name="dataSet">dsMain</Property>
+ <RowNumColumn/>
+ <DataColumn name="deviceCode">
+ <Property name="property">deviceCode</Property>
+ </DataColumn>
+ <ColumnGroup>
+ <Property name="caption">寮�鎿嶄綔</Property>
+ <DataColumn name="open">
+ <Property name="property">open</Property>
+ <Property name="caption">鍦板潃</Property>
+ <Property name="width">100</Property>
+ </DataColumn>
+ <DataColumn name="openFun">
+ <Property name="property">openFun</Property>
+ <Property name="caption">鍔熻兘</Property>
+ <Property name="width">100</Property>
+ <Property name="trigger">autoMappingDropDown1</Property>
+ </DataColumn>
+ </ColumnGroup>
+ <ColumnGroup>
+ <Property name="caption">鍏虫搷浣�</Property>
+ <DataColumn name="close">
+ <Property name="property">close</Property>
+ <Property name="caption">鍦板潃</Property>
+ <Property name="width">100</Property>
+ </DataColumn>
+ <DataColumn name="closeFun">
+ <Property name="property">closeFun</Property>
+ <Property name="caption">鍔熻兘</Property>
+ <Property name="width">100</Property>
+ <Property name="trigger">autoMappingDropDown1</Property>
+ </DataColumn>
+ </ColumnGroup>
+ <ColumnGroup>
+ <Property name="caption">鍋滄搷浣�</Property>
+ <DataColumn name="stop">
+ <Property name="property">stop</Property>
+ <Property name="caption">鍦板潃</Property>
+ <Property name="width">100</Property>
+ </DataColumn>
+ <DataColumn name="stopFun">
+ <Property name="property">stopFun</Property>
+ <Property name="caption">鍔熻兘</Property>
+ <Property name="width">100</Property>
+ <Property name="trigger">autoMappingDropDown1</Property>
+ </DataColumn>
+ </ColumnGroup>
+ <ColumnGroup>
+ <Property name="caption">寮�鍒颁綅</Property>
+ <DataColumn name="openEnd">
+ <Property name="property">openEnd</Property>
+ <Property name="caption">鍦板潃</Property>
+ <Property name="width">100</Property>
+ </DataColumn>
+ <DataColumn name="openEndFun">
+ <Property name="property">openEndFun</Property>
+ <Property name="caption">鍔熻兘</Property>
+ <Property name="width">100</Property>
+ <Property name="trigger">autoMappingDropDown1</Property>
+ </DataColumn>
+ </ColumnGroup>
+ <ColumnGroup>
+ <Property name="caption">鍏冲埌浣�</Property>
+ <DataColumn name="closeEnd">
+ <Property name="property">closeEnd</Property>
+ <Property name="caption">鍦板潃</Property>
+ <Property name="width">100</Property>
+ </DataColumn>
+ <DataColumn name="closeEndFun">
+ <Property name="property">closeEndFun</Property>
+ <Property name="caption">鍔熻兘</Property>
+ <Property name="width">100</Property>
+ <Property name="trigger">autoMappingDropDown1</Property>
+ </DataColumn>
+ </ColumnGroup>
+ <ColumnGroup>
+ <Property name="caption">寮�鏁呴殰</Property>
+ <DataColumn name="openError">
+ <Property name="property">openError</Property>
+ <Property name="caption">鍦板潃</Property>
+ <Property name="width">100</Property>
+ </DataColumn>
+ <DataColumn name="openErrorFun">
+ <Property name="property">openErrorFun</Property>
+ <Property name="caption">鍔熻兘</Property>
+ <Property name="width">100</Property>
+ <Property name="trigger">autoMappingDropDown1</Property>
+ </DataColumn>
+ </ColumnGroup>
+ <ColumnGroup>
+ <Property name="caption">鍏虫晠闅�</Property>
+ <DataColumn name="closeError">
+ <Property name="property">closeError</Property>
+ <Property name="caption">鍦板潃</Property>
+ <Property name="width">100</Property>
+ </DataColumn>
+ <DataColumn name="closeErrorFun">
+ <Property name="property">closeErrorFun</Property>
+ <Property name="caption">鍔熻兘</Property>
+ <Property name="width">100</Property>
+ <Property name="trigger">autoMappingDropDown1</Property>
+ </DataColumn>
+ </ColumnGroup>
+ </DataGrid>
+ </Container>
+ <UpdateAction id="uaAction">
+ <Property name="dataResolver">deviceModbusPR#updateData</Property>
+ <UpdateItem>
+ <Property name="dataSet">dsMain</Property>
+ <Property name="dataPath">!DIRTY_TREE</Property>
+ </UpdateItem>
+ </UpdateAction>
+ <AjaxAction id="ajaxDel">
+ <Property name="service">deviceModbusPR#delData</Property>
+ <Property name="confirmMessage">纭畾瑕佸垹闄や箞锛�</Property>
+ </AjaxAction>
+ <AjaxAction id="ajaxFlushCache">
+ <Property name="service">deviceModbusPR#flushCache</Property>
+ <Property name="successMessage">缂撳瓨鏇存柊鎴愬姛</Property>
+ </AjaxAction>
+ </View>
+</ViewConfig>
diff --git a/igds-core/src/main/java/com/ld/igds/modbus/DeviceModbusPR.java b/igds-core/src/main/java/com/ld/igds/modbus/DeviceModbusPR.java
new file mode 100644
index 0000000..500a440
--- /dev/null
+++ b/igds-core/src/main/java/com/ld/igds/modbus/DeviceModbusPR.java
@@ -0,0 +1,92 @@
+package com.ld.igds.modbus;
+
+import com.bstek.dorado.annotation.DataProvider;
+import com.bstek.dorado.annotation.DataResolver;
+import com.bstek.dorado.annotation.Expose;
+import com.ld.igds.modbus.service.HDeviceModbusService;
+import com.ld.igds.models.DeviceModbus;
+import com.ld.igds.models.DicTrigger;
+import com.ld.igds.util.ContextUtil;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * MOOBUS-TCP璁惧鍙傛暟閰嶇疆
+ */
+@Component
+public class DeviceModbusPR {
+
+ @Resource
+ private HDeviceModbusService deviceModbusService;
+
+ /**
+ * deviceModbusPR#listAll
+ *
+ * @return
+ */
+ @DataProvider
+ public List<DeviceModbus> listAll() {
+ String companyId = ContextUtil.getCompanyId();
+ return deviceModbusService.listAll(companyId);
+ }
+
+ /**
+ * deviceModbusPR#flushCache
+ *
+ * @return
+ */
+ @Expose
+ public void flushCache() {
+ String companyId = ContextUtil.getCompanyId();
+ deviceModbusService.flushCache(companyId);
+ }
+
+ /**
+ * deviceModbusPR#delData
+ *
+ * @return
+ */
+ @Expose
+ public String delData(DeviceModbus data) {
+ if (null == data.getId()) return null;
+ return deviceModbusService.delData(data);
+ }
+
+ /**
+ * 鏁版嵁鏇存柊
+ * deviceModbusPR#updateData
+ *
+ * @param details
+ */
+ @DataResolver
+ public void updateData(List<DeviceModbus> details) {
+ deviceModbusService.updateData(details);
+ }
+
+
+ /**
+ * ${dorado.getDataProvider("deviceModbusPR#triggerFun").getResult()}
+ *
+ * @return
+ */
+ @DataProvider
+ public List<DicTrigger> triggerFun() {
+ List<DicTrigger> list = new ArrayList<>();
+
+ list.add(new DicTrigger(ModbusConstant.FUN_01, "01-璇荤嚎鍦�"));
+ list.add(new DicTrigger(ModbusConstant.FUN_02, "02-璇荤鏁i噺杈撳叆"));
+ list.add(new DicTrigger(ModbusConstant.FUN_03, "03-璇讳繚鎸佸瘎瀛樺櫒"));
+ list.add(new DicTrigger(ModbusConstant.FUN_04, "04-璇昏緭鍏ュ瘎瀛樺櫒"));
+ list.add(new DicTrigger(ModbusConstant.FUN_05, "05-鍐欏崟涓嚎鍦�"));
+ list.add(new DicTrigger(ModbusConstant.FUN_06, "06-鍐欏崟涓瘎瀛樺櫒"));
+ list.add(new DicTrigger(ModbusConstant.FUN_15, "15-鍐欏涓嚎鍦�"));
+ list.add(new DicTrigger(ModbusConstant.FUN_16, "16-鍐欏涓瘎瀛樺櫒"));
+ list.add(new DicTrigger(ModbusConstant.FUN_99, "鏈厤缃�"));
+ return list;
+ }
+
+
+}
diff --git a/igds-core/src/main/java/com/ld/igds/modbus/ModbusConstant.java b/igds-core/src/main/java/com/ld/igds/modbus/ModbusConstant.java
new file mode 100644
index 0000000..9a630ca
--- /dev/null
+++ b/igds-core/src/main/java/com/ld/igds/modbus/ModbusConstant.java
@@ -0,0 +1,36 @@
+package com.ld.igds.modbus;
+
+/**
+ * MOdBUS-鍩虹甯搁噺淇℃伅
+ */
+public class ModbusConstant {
+
+
+ //01-璇荤嚎鍦�
+ public static final String FUN_01 = "01";
+ //02-璇荤鏁i噺杈撳叆
+ public static final String FUN_02 = "02";
+ //03-璇讳繚鎸佸瘎瀛樺櫒
+ public static final String FUN_03 = "03";
+ //04-璇昏緭鍏ュ瘎瀛樺櫒
+ public static final String FUN_04 = "04";
+ //05-鍐欏崟涓嚎鍦�
+ public static final String FUN_05 = "05";
+ //06-鍐欏崟涓瘎瀛樺櫒
+ public static final String FUN_06 = "06";
+ //15-鍐欏涓嚎鍦�
+ public static final String FUN_15 = "15";
+ //16-鍐欏涓瘎瀛樺櫒
+ public static final String FUN_16 = "16";
+ //99-涓嶆搷浣�
+ public static final String FUN_99 = "99";
+
+
+
+ public static final String MODBUS_DEVICE_CACHE = "MODBUS_DEVICE";
+
+
+
+
+
+}
diff --git a/igds-core/src/main/java/com/ld/igds/modbus/service/HDeviceModbusService.java b/igds-core/src/main/java/com/ld/igds/modbus/service/HDeviceModbusService.java
new file mode 100644
index 0000000..a5da293
--- /dev/null
+++ b/igds-core/src/main/java/com/ld/igds/modbus/service/HDeviceModbusService.java
@@ -0,0 +1,118 @@
+package com.ld.igds.modbus.service;
+
+import com.bstek.bdf2.core.orm.hibernate.HibernateDao;
+import com.ld.igds.constant.Constant;
+import com.ld.igds.constant.RedisConst;
+import com.ld.igds.modbus.ModbusConstant;
+import com.ld.igds.models.DeviceModbus;
+import com.ld.igds.util.ContextUtil;
+import com.ld.igds.util.RedisUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.hibernate.Session;
+import org.springframework.beans.BeanUtils;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+
+@Component
+public class HDeviceModbusService extends HibernateDao {
+
+ @Resource
+ private RedisUtil redisUtil;
+
+
+ public List<DeviceModbus> listAll(String companyId) {
+
+ String hql = " from " + DeviceModbus.class.getName() + " where 1=1 order by deviceCode+0";
+
+ return this.query(hql);
+ }
+
+ public void flushCache(String companyId) {
+
+ if (null == companyId) companyId = ContextUtil.getCompanyId();
+
+ List<DeviceModbus> listAll = this.listAll(companyId);
+
+ if (null == listAll || listAll.isEmpty()) return;
+
+
+ String key;
+ DeviceModbus entityDevice;
+ for (DeviceModbus hibDevice : listAll) {
+ entityDevice = new DeviceModbus();
+ BeanUtils.copyProperties(hibDevice, entityDevice);
+ key = RedisConst.buildKey(companyId, ModbusConstant.MODBUS_DEVICE_CACHE, hibDevice.getDeviceCode());
+ redisUtil.set(key, entityDevice);
+ }
+ }
+
+ public DeviceModbus getCacheDeviceModbus(String companyId, String deviceCode) {
+ String key = RedisConst.buildKey(companyId, ModbusConstant.MODBUS_DEVICE_CACHE, deviceCode);
+ return (DeviceModbus) redisUtil.get(key);
+ }
+
+ public void updateData(List<DeviceModbus> details) {
+ if (null == details || details.isEmpty()) return;
+
+ Session session = this.getSessionFactory().openSession();
+ try {
+ for (DeviceModbus device : details) {
+
+ if (StringUtils.isEmpty(device.getOpen())) device.setOpen(Constant.YN_N);
+ if (StringUtils.isEmpty(device.getOpenFun())) device.setOpenFun(ModbusConstant.FUN_99);
+
+ if (StringUtils.isEmpty(device.getOpenEnd())) device.setOpenEnd(Constant.YN_N);
+ if (StringUtils.isEmpty(device.getOpenEndFun())) device.setOpenEndFun(ModbusConstant.FUN_99);
+
+ if (StringUtils.isEmpty(device.getOpenError())) device.setOpenError(Constant.YN_N);
+ if (StringUtils.isEmpty(device.getOpenErrorFun())) device.setOpenErrorFun(ModbusConstant.FUN_99);
+
+ if (StringUtils.isEmpty(device.getClose())) device.setClose(Constant.YN_N);
+ if (StringUtils.isEmpty(device.getCloseFun())) device.setCloseFun(ModbusConstant.FUN_99);
+
+ if (StringUtils.isEmpty(device.getCloseEnd())) device.setCloseEnd(Constant.YN_N);
+ if (StringUtils.isEmpty(device.getCloseEndFun())) device.setCloseEndFun(ModbusConstant.FUN_99);
+
+ if (StringUtils.isEmpty(device.getCloseError())) device.setCloseError(Constant.YN_N);
+ if (StringUtils.isEmpty(device.getCloseErrorFun())) device.setCloseErrorFun(ModbusConstant.FUN_99);
+
+ if (StringUtils.isEmpty(device.getStop())) device.setStop(Constant.YN_N);
+ if (StringUtils.isEmpty(device.getStopFun())) device.setStopFun(ModbusConstant.FUN_99);
+
+
+ if (null == device.getId()) {
+ device.setId(ContextUtil.getUUID());
+ session.save(device);
+ } else {
+ session.update(device);
+ }
+ }
+
+ flushCache(null);
+
+ } catch (Exception e) {
+
+ } finally {
+ session.flush();
+ session.close();
+ }
+ }
+
+ public String delData(DeviceModbus data) {
+ Session session = this.getSessionFactory().openSession();
+ try {
+ session.delete(data);
+ flushCache(null);
+ } catch (Exception e) {
+ } finally {
+ session.flush();
+ session.close();
+ }
+ return null;
+ }
+
+
+}
diff --git a/igds-core/src/main/java/com/ld/igds/models/Device.java b/igds-core/src/main/java/com/ld/igds/models/Device.java
index eebb08e..be25a08 100644
--- a/igds-core/src/main/java/com/ld/igds/models/Device.java
+++ b/igds-core/src/main/java/com/ld/igds/models/Device.java
@@ -66,9 +66,9 @@
@PropertyDef(label = "璁惧鍔熺巼", description = "璁惧鍔熺巼锛屾病鏈夊彲涓嶅~鍐�:KW/H")
private Double power;
- @Column(name = "MODBUS_",length = 100)
- @PropertyDef(label = "Modbus閰嶇疆")
- private String modbus;
+// @Column(name = "MODBUS_",length = 100)
+// @PropertyDef(label = "Modbus閰嶇疆")
+// private String modbus;
@Column(name = "REMARK_", length = 250)
@PropertyDef(label = "澶囨敞", description = "澶囨敞淇℃伅")
@@ -78,9 +78,9 @@
@PropertyDef(label = "鍏宠仈璁惧閫氶亾", description = "閽堝鍙岄�氶亾閰嶇疆璁惧锛屽娣锋祦椋庡彛鐨勯鏈恒�佽酱娴侀鍙g殑椋庢満")
private String link;
- @Column(name = "LINK_MODBUS_",length = 100)
- @PropertyDef(label = "鍏宠仈璁惧Modbus")
- private String linkModbus;
+// @Column(name = "LINK_MODBUS_",length = 100)
+// @PropertyDef(label = "鍏宠仈璁惧Modbus")
+// private String linkModbus;
@Column(name = "EXT1_", length = 20)
@PropertyDef(label = "鎵╁睍瀛楁1", description = "鏍规嵁涓氬姟闇�瑕佽嚜瀹氫箟瀛樺偍鍊�")
diff --git a/igds-core/src/main/java/com/ld/igds/models/DeviceModbus.java b/igds-core/src/main/java/com/ld/igds/models/DeviceModbus.java
new file mode 100644
index 0000000..e41d581
--- /dev/null
+++ b/igds-core/src/main/java/com/ld/igds/models/DeviceModbus.java
@@ -0,0 +1,85 @@
+package com.ld.igds.models;
+
+import com.bstek.dorado.annotation.PropertyDef;
+import com.ld.igds.constant.Constant;
+import lombok.Data;
+
+import javax.persistence.*;
+import java.io.Serializable;
+
+/**
+ * 鏍规嵁璁惧閰嶇疆鐨凪odbus-TCP鍙傛暟閰嶇疆
+ */
+@Data
+@Entity
+@Table(name = "D_DEVICE_MODBUS")
+public class DeviceModbus implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @Id
+ @Column(name = "ID_", length = 40)
+ @PropertyDef(label = "ID")
+ private String id;
+
+ @Column(name = "DEVICE_CODE_", length = 40)
+ @PropertyDef(label = "璁惧缂栫爜")
+ private String deviceCode;
+
+ @Column(name = "OPEN_", length = 10)
+ @PropertyDef(label = "寮�鍦板潃")
+ private String open = Constant.YN_N;
+
+ @Column(name = "OPEN_FUN", length = 4)
+ @PropertyDef(label = "鍔熻兘鍙�")
+ private String openFun = "99";
+
+ @Column(name = "CLOSE_", length = 10)
+ @PropertyDef(label = "鍏冲湴鍧�")
+ private String close = Constant.YN_N;
+
+ @Column(name = "CLOSE_FUN", length = 4)
+ @PropertyDef(label = "鍔熻兘鍙�")
+ private String closeFun = "99";
+
+ @Column(name = "STOP_", length = 10)
+ @PropertyDef(label = "鍋滃湴鍧�")
+ private String stop = Constant.YN_N;
+
+ @Column(name = "STOP_FUN", length = 4)
+ @PropertyDef(label = "鍔熻兘鍙�")
+ private String stopFun = "99";
+
+ @Column(name = "OPEN_END_", length = 10)
+ @PropertyDef(label = "鍋滃湴鍧�")
+ private String openEnd = Constant.YN_N;
+
+ @Column(name = "OPEN_END_FUN", length = 4)
+ @PropertyDef(label = "鍔熻兘鍙�")
+ private String openEndFun = "99";
+
+ @Column(name = "CLOSE_END_", length = 10)
+ @PropertyDef(label = "鍏冲埌浣嶅湴鍧�")
+ private String closeEnd = Constant.YN_N;
+
+ @Column(name = "CLOSE_END_FUN", length = 4)
+ @PropertyDef(label = "鍔熻兘鍙�")
+ private String closeEndFun = "99";
+
+ @Column(name = "OPEN_ERROR_", length = 10)
+ @PropertyDef(label = "寮�鏁呴殰鍦板潃")
+ private String openError = Constant.YN_N;
+
+ @Column(name = "OPEN_ERROR_FUN", length = 4)
+ @PropertyDef(label = "鍔熻兘鍙�")
+ private String openErrorFun = "99";
+
+ @Column(name = "CLOSE_ERROR_", length = 10)
+ @PropertyDef(label = "鍏虫晠闅滃湴鍧�")
+ private String closeError = Constant.YN_N;
+
+ @Column(name = "CLOSE_ERROR_FUN", length = 4)
+ @PropertyDef(label = "鍔熻兘鍙�")
+ private String closeErrorFun = "99";
+
+}
diff --git a/igds-core/src/main/java/com/ld/igds/view/Device.view.xml b/igds-core/src/main/java/com/ld/igds/view/Device.view.xml
index 4e847df..5b7bcfb 100644
--- a/igds-core/src/main/java/com/ld/igds/view/Device.view.xml
+++ b/igds-core/src/main/java/com/ld/igds/view/Device.view.xml
@@ -34,7 +34,11 @@
</DataType>
</Model>
<View layout="padding:5;regionPadding:5">
- <ClientEvent name="onReady">view.get("#dataSetC").insert();</ClientEvent>
+ <ClientEvent name="onReady">view.get("#dataSetC").insert();
+
+openModbusDevice = function(){
+ view.get("#dialogModbus").show();
+}</ClientEvent>
<Property name="packages">font-awesome,css-common</Property>
<DataSet id="dsDevice">
<Property name="dataProvider">devicePR#loadDeviceByContion</Property>
@@ -130,7 +134,7 @@
</DataColumn>
<DataColumn name="link">
<Property name="property">link</Property>
- <Property name="caption">鍏宠仈璁惧</Property>
+ <Property name="caption">椋庢満缂栫爜</Property>
<Property name="align">center</Property>
</DataColumn>
<DataColumn name="serId">
@@ -140,6 +144,15 @@
<DataColumn name="remark">
<Property name="property">remark</Property>
<Property name="align">center</Property>
+ </DataColumn>
+ <DataColumn>
+ <ClientEvent name="onRenderCell">arg.dom.innerHTML ="<a href='javascripe:;' onclick='openModbusDevice()'>Modbus閰嶇疆</a>";
+arg.progressDefault = false;</ClientEvent>
+ <Property name="name">id</Property>
+ <Property name="property">id</Property>
+ <Property name="width">100</Property>
+ <Property name="caption">鎿嶄綔</Property>
+ <Editor/>
</DataColumn>
</DataGrid>
<ToolBar layoutConstraint="bottom">
@@ -226,24 +239,6 @@
<Property name="property">power</Property>
<Editor/>
</AutoFormElement>
- <AutoFormElement layoutConstraint="colSpan:2">
- <Property name="name">modbus</Property>
- <Property name="property">modbus</Property>
- <Editor/>
- </AutoFormElement>
- <AutoFormElement layoutConstraint="colSpan:2">
- <Property name="name">linkModbus</Property>
- <Property name="property">linkModbus</Property>
- <Property name="label">椋庢満Modbus</Property>
- <Editor/>
- </AutoFormElement>
- <Label layoutConstraint="colSpan:2">
- <Property name="text">modbus瑙勫垯锛氬紑鍦板潃-鍏冲湴鍧�-鍋滃湴鍧�-寮�鍒颁綅-鍏冲埌浣�-寮�鏁呴殰-鍏虫晠闅滐紝鏃犲湴鍧�鐢∟浠f浛</Property>
- <Property name="style">
- <Property name="padding-left">100px</Property>
- <Property name="color">blue</Property>
- </Property>
- </Label>
<AutoFormElement layoutConstraint="colSpan:2">
<Property name="name">remark</Property>
<Property name="property">remark</Property>
@@ -332,5 +327,17 @@
<Property name="successMessage">鍒锋柊鎴愬姛锛�</Property>
<Property name="confirmMessage">纭畾瑕佸埛鏂扮紦瀛樹箞锛�</Property>
</AjaxAction>
+ <Dialog id="dialogModbus">
+ <Property name="width">100%</Property>
+ <Property name="height">95%</Property>
+ <Property name="caption">璁惧MOBUS-TCP鐩稿叧閰嶇疆</Property>
+ <Buttons/>
+ <Children>
+ <IFrame id="iframeModbusDevice">
+ <Property name="path">com.ld.igds.modbus.DeviceModbus.d</Property>
+ </IFrame>
+ </Children>
+ <Tools/>
+ </Dialog>
</View>
</ViewConfig>
diff --git a/igds-core/src/main/java/com/ld/igds/view/service/DeviceService.java b/igds-core/src/main/java/com/ld/igds/view/service/DeviceService.java
index 9635b30..8bb0320 100644
--- a/igds-core/src/main/java/com/ld/igds/view/service/DeviceService.java
+++ b/igds-core/src/main/java/com/ld/igds/view/service/DeviceService.java
@@ -1,279 +1,275 @@
package com.ld.igds.view.service;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.lang.StringUtils;
-import org.hibernate.Session;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
import com.bstek.bdf2.core.orm.hibernate.HibernateDao;
import com.bstek.dorado.data.provider.Page;
import com.ld.igds.common.CoreDeviceService;
import com.ld.igds.models.Device;
import com.ld.igds.util.ContextUtil;
+import org.apache.commons.lang.StringUtils;
+import org.hibernate.Session;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
/**
- *
* @author Andy
- *
*/
@Component
public class DeviceService extends HibernateDao {
-
-
- @Autowired
- private CoreDeviceService coreDeviceService;
- /**
- * 鍔犺浇鎵�鏈夎澶囨暟鎹�
- * <p>
- * Title: loadDevice
- * </p>
- * <p>
- * Description:
- * </p>
- *
- */
- public List<Device> loadDevice(Map<String, Object> parameter) {
- if (parameter == null || parameter.size() <= 0)
- return null;
- Map<String, Object> p = new HashMap<String, Object>();
- String hql = " from " + Device.class.getName()
- + " where companyId = :companyId ";
-
- String companyId = (String) parameter.get("companyId");
- if(null == companyId){
- companyId = ContextUtil.getCompanyId();
- }
- p.put("companyId", companyId);
+ @Resource
+ private CoreDeviceService coreDeviceService;
- String depotId = (String) parameter.get("depotId");
- if (StringUtils.isNotEmpty(depotId)) {
- hql += " and depotId =:depotId";
- p.put("depotId", depotId);
- }
+ /**
+ * 鍔犺浇鎵�鏈夎澶囨暟鎹�
+ * <p>
+ * Title: loadDevice
+ * </p>
+ * <p>
+ * Description:
+ * </p>
+ */
+ public List<Device> loadDevice(Map<String, Object> parameter) {
+ if (parameter == null || parameter.size() <= 0)
+ return null;
- String type = (String) parameter.get("type");
- if (StringUtils.isNotEmpty(type)) {
- hql += " and type =:type";
- p.put("type", type);
- }
+ Map<String, Object> p = new HashMap<String, Object>();
+ String hql = " from " + Device.class.getName()
+ + " where companyId = :companyId ";
- String serId = (String) parameter.get("serId");
- if (StringUtils.isNotEmpty(serId)) {
- hql += " and serId =:serId";
- p.put("serId", serId);
- }
+ String companyId = (String) parameter.get("companyId");
+ if (null == companyId) {
+ companyId = ContextUtil.getCompanyId();
+ }
+ p.put("companyId", companyId);
- hql += " order by type,id";
- return this.query(hql, p);
- }
+ String depotId = (String) parameter.get("depotId");
+ if (StringUtils.isNotEmpty(depotId)) {
+ hql += " and depotId =:depotId";
+ p.put("depotId", depotId);
+ }
- public void loadDeviceByContion(Page<Device> page,
- Map<String, Object> parameter) throws Exception {
- Map<String, Object> p = new HashMap<String, Object>();
- String hql = " from " + Device.class.getName()
- + " where companyId = :companyId ";
- p.put("companyId", ContextUtil.getCompanyId());
-
- if(null == parameter)parameter = new HashMap<String, Object>();
+ String type = (String) parameter.get("type");
+ if (StringUtils.isNotEmpty(type)) {
+ hql += " and type =:type";
+ p.put("type", type);
+ }
- String depotId = (String) parameter.get("depotId");
- if (StringUtils.isNotEmpty(depotId)) {
- hql += " and depotId =:depotId";
- p.put("depotId", depotId);
- }
+ String serId = (String) parameter.get("serId");
+ if (StringUtils.isNotEmpty(serId)) {
+ hql += " and serId =:serId";
+ p.put("serId", serId);
+ }
- String type = (String) parameter.get("type");
- if (StringUtils.isNotEmpty(type)) {
- hql += " and type =:type";
- p.put("type", type);
- }
+ hql += " order by type,id";
+ return this.query(hql, p);
+ }
- String serId = (String) parameter.get("serId");
- if (StringUtils.isNotEmpty(serId)) {
- hql += " and serId =:serId";
- p.put("serId", serId);
- }
+ public void loadDeviceByContion(Page<Device> page,
+ Map<String, Object> parameter) throws Exception {
+ Map<String, Object> p = new HashMap<String, Object>();
+ String hql = " from " + Device.class.getName()
+ + " where companyId = :companyId ";
+ p.put("companyId", ContextUtil.getCompanyId());
- String countSql = "select count(*) " + hql;
- hql += " order by serId,id asc";
- this.pagingQuery(page, hql, countSql, p);
- }
+ if (null == parameter) parameter = new HashMap<String, Object>();
- /**
- * 淇敼璁惧淇℃伅
- * <p>
- * Title: upDepotDevice
- * </p>
- * <p>
- * Description:
- * </p>
- *
- * @param depotDevice
- */
+ String depotId = (String) parameter.get("depotId");
+ if (StringUtils.isNotEmpty(depotId)) {
+ hql += " and depotId =:depotId";
+ p.put("depotId", depotId);
+ }
- public void upDepotDevice(Device depotDevice) {
- Session session = null;
- try {
- session = this.getSessionFactory().openSession();
- session.update(depotDevice);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- session.flush();
- session.close();
- }
+ String type = (String) parameter.get("type");
+ if (StringUtils.isNotEmpty(type)) {
+ hql += " and type =:type";
+ p.put("type", type);
+ }
- }
+ String serId = (String) parameter.get("serId");
+ if (StringUtils.isNotEmpty(serId)) {
+ hql += " and serId =:serId";
+ p.put("serId", serId);
+ }
- /**
- * 鍒犻櫎璁惧
- * <p>
- * Title: delDepotDevice
- * </p>
- * <p>
- * Description:
- * </p>
- */
- public void delDepotDevice(Device depotDevice) {
- Session session = null;
- try {
- session = this.getSessionFactory().openSession();
- session.delete(depotDevice);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- session.flush();
- session.close();
- }
- }
+ String countSql = "select count(*) " + hql;
+ hql += " order by serId,id asc";
+ this.pagingQuery(page, hql, countSql, p);
+ }
- public void delDepotDevice(String id) {
- Session session = null;
- try {
- session = this.getSessionFactory().openSession();
- String hql = " delete from " + Device.class.getName()
- + " where id=:id";
- session.createQuery(hql).setString("id", id).executeUpdate();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- session.flush();
- session.close();
- }
- }
+ /**
+ * 淇敼璁惧淇℃伅
+ * <p>
+ * Title: upDepotDevice
+ * </p>
+ * <p>
+ * Description:
+ * </p>
+ *
+ * @param depotDevice
+ */
- public String saveOrUpdate(Device device, String id) {
- if (null != id) {
- this.delDepotDevice(id);
- return null;
- }
- Session session = null;
- try {
- session = this.getSessionFactory().openSession();
- if (null != device.getId()) {
- session.update(device);
- } else {
- device.setCompanyId(ContextUtil.getCompanyId());
- device.setId(ContextUtil.buildDeviceId(device.getCompanyId(),
- device.getDepotId(), device.getPassCode()));
- session.save(device);
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- session.flush();
- session.close();
- }
- return null;
- }
+ public void upDepotDevice(Device depotDevice) {
+ Session session = null;
+ try {
+ session = this.getSessionFactory().openSession();
+ session.update(depotDevice);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ session.flush();
+ session.close();
+ }
- public void addDepotDevice(Device depotDevice) {
- Session session = null;
- try {
- session = this.getSessionFactory().openSession();
- depotDevice.setCompanyId(ContextUtil.getCompanyId());
- depotDevice.setId(ContextUtil.buildDeviceId(
- depotDevice.getCompanyId(), depotDevice.getDepotId(),
- depotDevice.getPassCode()));
- session.save(depotDevice);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- session.flush();
- session.close();
- }
- }
+ }
- public void refreshCache(String companyId) {
- coreDeviceService.refreshCache(companyId);
- }
+ /**
+ * 鍒犻櫎璁惧
+ * <p>
+ * Title: delDepotDevice
+ * </p>
+ * <p>
+ * Description:
+ * </p>
+ */
+ public void delDepotDevice(Device depotDevice) {
+ Session session = null;
+ try {
+ session = this.getSessionFactory().openSession();
+ session.delete(depotDevice);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ session.flush();
+ session.close();
+ }
+ }
- public Device getDeviceById(String id){
- Map<String, Object> p = new HashMap<String, Object>();
- String hql = " from " + Device.class.getName()
- + " where companyId = :companyId and id=:id";
+ public void delDepotDevice(String id) {
+ Session session = null;
+ try {
+ session = this.getSessionFactory().openSession();
+ String hql = " delete from " + Device.class.getName()
+ + " where id=:id";
+ session.createQuery(hql).setString("id", id).executeUpdate();
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ session.flush();
+ session.close();
+ }
+ }
- String companyId = ContextUtil.getCompanyId();
- p.put("companyId", companyId);
- p.put("id", id);
- List<Device> list = this.query(hql,p);
- if(list != null && list.size() > 0){
- return list.get(0);
- }
- return null;
- }
+ public String saveOrUpdate(Device device, String id) {
+ if (null != id) {
+ this.delDepotDevice(id);
+ return null;
+ }
+ Session session = null;
+ try {
+ session = this.getSessionFactory().openSession();
+ if (null != device.getId()) {
+ session.update(device);
+ } else {
+ device.setCompanyId(ContextUtil.getCompanyId());
+ device.setId(ContextUtil.buildDeviceId(device.getCompanyId(),
+ device.getDepotId(), device.getPassCode()));
+ session.save(device);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ session.flush();
+ session.close();
+ }
+ return null;
+ }
- public List<Device> loadDeviceByType(Map<String, Object> parameter) {
- if (parameter == null || parameter.size() <= 0)
- return null;
+ public void addDepotDevice(Device depotDevice) {
+ Session session = null;
+ try {
+ session = this.getSessionFactory().openSession();
+ depotDevice.setCompanyId(ContextUtil.getCompanyId());
+ depotDevice.setId(ContextUtil.buildDeviceId(
+ depotDevice.getCompanyId(), depotDevice.getDepotId(),
+ depotDevice.getPassCode()));
+ session.save(depotDevice);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ session.flush();
+ session.close();
+ }
+ }
- Map<String, Object> p = new HashMap<String, Object>();
- String hql = " from " + Device.class.getName()
- + " where companyId = :companyId ";
+ public void refreshCache(String companyId) {
+ coreDeviceService.refreshCache(companyId);
+ }
- String companyId = (String) parameter.get("companyId");
- if(null == companyId){
- companyId = ContextUtil.getCompanyId();
- }
- p.put("companyId", companyId);
+ public Device getDeviceById(String id) {
+ Map<String, Object> p = new HashMap<String, Object>();
+ String hql = " from " + Device.class.getName()
+ + " where companyId = :companyId and id=:id";
- String depotId = (String) parameter.get("depotId");
- if (StringUtils.isNotEmpty(depotId)) {
- hql += " and depotId =:depotId";
- p.put("depotId", depotId);
- }
+ String companyId = ContextUtil.getCompanyId();
+ p.put("companyId", companyId);
+ p.put("id", id);
+ List<Device> list = this.query(hql, p);
+ if (list != null && list.size() > 0) {
+ return list.get(0);
+ }
+ return null;
+ }
- String type = (String) parameter.get("type");
- if (StringUtils.isNotEmpty(type)) {
- hql += " and type =:type";
- p.put("type", type);
- }
+ public List<Device> loadDeviceByType(Map<String, Object> parameter) {
+ if (parameter == null || parameter.size() <= 0)
+ return null;
- String serId = (String) parameter.get("serId");
- if (StringUtils.isNotEmpty(serId)) {
- hql += " and serId =:serId";
- p.put("serId", serId);
- }
- String tag = (String) parameter.get("tag");
- // tag = 1 鏌ヨ椋庢満绫诲瀷鐨勮澶囷紝tag = 2 鏌ヨ鐓ф槑璁惧锛屽惁鍒欐槸鍏朵綑鐨勫叾瀹冭澶�
- if (StringUtils.isNotEmpty(tag) && "1".equals(tag)) {
- hql += " and type in (:types)";
- p.put("types", new String[] {"02","03","04","0C","0D"});
- }else if (StringUtils.isNotEmpty(tag) && "2".equals(tag)) {
- hql += " and type =:type";
- p.put("type", "06");
- }else{
- hql += " and type not in (:types)";
- p.put("types", new String[] {"02","03","04","0C","0D"});
- }
- hql += " order by type,id";
- return this.query(hql, p);
- }
+ Map<String, Object> p = new HashMap<String, Object>();
+ String hql = " from " + Device.class.getName()
+ + " where companyId = :companyId ";
+
+ String companyId = (String) parameter.get("companyId");
+ if (null == companyId) {
+ companyId = ContextUtil.getCompanyId();
+ }
+ p.put("companyId", companyId);
+
+ String depotId = (String) parameter.get("depotId");
+ if (StringUtils.isNotEmpty(depotId)) {
+ hql += " and depotId =:depotId";
+ p.put("depotId", depotId);
+ }
+
+ String type = (String) parameter.get("type");
+ if (StringUtils.isNotEmpty(type)) {
+ hql += " and type =:type";
+ p.put("type", type);
+ }
+
+ String serId = (String) parameter.get("serId");
+ if (StringUtils.isNotEmpty(serId)) {
+ hql += " and serId =:serId";
+ p.put("serId", serId);
+ }
+ String tag = (String) parameter.get("tag");
+ // tag = 1 鏌ヨ椋庢満绫诲瀷鐨勮澶囷紝tag = 2 鏌ヨ鐓ф槑璁惧锛屽惁鍒欐槸鍏朵綑鐨勫叾瀹冭澶�
+ if (StringUtils.isNotEmpty(tag) && "1".equals(tag)) {
+ hql += " and type in (:types)";
+ p.put("types", new String[]{"02", "03", "04", "0C", "0D"});
+ } else if (StringUtils.isNotEmpty(tag) && "2".equals(tag)) {
+ hql += " and type =:type";
+ p.put("type", "06");
+ } else {
+ hql += " and type not in (:types)";
+ p.put("types", new String[]{"02", "03", "04", "0C", "0D"});
+ }
+ hql += " order by type,id";
+ return this.query(hql, p);
+ }
}
diff --git a/igds-core/src/main/java/models/igds.model.xml b/igds-core/src/main/java/models/igds.model.xml
index 791ffe0..933f79a 100644
--- a/igds-core/src/main/java/models/igds.model.xml
+++ b/igds-core/src/main/java/models/igds.model.xml
@@ -518,14 +518,17 @@
<Property name="keyProperty">id</Property>
<Property name="valueProperty">name</Property>
</Property>
+ <Property name="required">true</Property>
</PropertyDef>
<PropertyDef name="name">
<Property></Property>
<Property name="label">鍚嶇О</Property>
+ <Property name="required">true</Property>
</PropertyDef>
<PropertyDef name="passCode">
<Property name="dataType">int</Property>
<Property name="label">璁惧缂栧彿</Property>
+ <Property name="required">true</Property>
</PropertyDef>
<PropertyDef name="link">
<Property></Property>
@@ -548,6 +551,7 @@
<Property name="keyProperty">id</Property>
<Property name="valueProperty">name</Property>
</Property>
+ <Property name="required">true</Property>
</PropertyDef>
<PropertyDef name="type">
<Property></Property>
@@ -602,14 +606,6 @@
<PropertyDef name="locationName">
<Property></Property>
<Property name="label">浣嶇疆</Property>
- </PropertyDef>
- <PropertyDef name="modbus">
- <Property></Property>
- <Property name="label">Modbus閰嶇疆</Property>
- </PropertyDef>
- <PropertyDef name="linkModbus">
- <Property/>
- <Property name="label">鍏宠仈璁惧Modbus</Property>
</PropertyDef>
<PropertyDef name="ext1">
<Property></Property>
diff --git a/igds-core/src/main/resources/mapper/DeviceMapper.xml b/igds-core/src/main/resources/mapper/DeviceMapper.xml
index 056e15d..8b1a57a 100644
--- a/igds-core/src/main/resources/mapper/DeviceMapper.xml
+++ b/igds-core/src/main/resources/mapper/DeviceMapper.xml
@@ -17,7 +17,6 @@
g.LOCATION_ AS location,
g.STATUS_ AS status,
g.POWER_ AS power,
- g.MODBUS_ AS modbus,
g.LINK_ AS link,
g.EXT1_ AS ext1,
g.EXT2_ AS ext2,
diff --git a/igds-protocol-modbus/pom.xml b/igds-protocol-modbus/pom.xml
index 75ac12b..708d3c0 100644
--- a/igds-protocol-modbus/pom.xml
+++ b/igds-protocol-modbus/pom.xml
@@ -13,8 +13,6 @@
</properties>
-
-
<dependencies>
<!-- 寮曞叆IO鍖� -->
diff --git a/igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/command/AnalysisService.java b/igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/command/AnalysisService.java
index 710329d..07211d3 100644
--- a/igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/command/AnalysisService.java
+++ b/igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/command/AnalysisService.java
@@ -19,7 +19,7 @@
public class AnalysisService {
@Resource
- private CoreDeviceService deviceService;
+ private CoreDeviceService coreDeviceService;
@Resource
private NotifyWebInvoker notifyInvoker;
@@ -38,7 +38,7 @@
Thread.sleep(sleepTime);
}
- deviceService.updateStatus(request.getCompanyId(), request.getSerId(), ServerUtil.getStatusMap());
+ coreDeviceService.updateStatus(request.getCompanyId(), request.getSerId(), ServerUtil.getStatusMap());
notifyInvoker.notifyAnalysisStatusSuccess(request.getCompanyId(), request.getSerId(), OrderRespEnum.MSG_SUCCESS, "璁惧鐘舵�佹煡璇㈡垚鍔熷苟瀹屾垚瑙f瀽锛�");
diff --git a/igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/command/RemoteControlServiceImpl.java b/igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/command/RemoteControlServiceImpl.java
index 100023b..756c767 100644
--- a/igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/command/RemoteControlServiceImpl.java
+++ b/igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/command/RemoteControlServiceImpl.java
@@ -11,11 +11,14 @@
import com.ld.igds.io.request.ExeDevice;
import com.ld.igds.io.request.TempControlRequest;
import com.ld.igds.io.response.DeviceControlResponse;
+import com.ld.igds.modbus.service.HDeviceModbusService;
import com.ld.igds.models.Device;
+import com.ld.igds.models.DeviceModbus;
import com.ld.igds.protocol.modbus.ModbusUtil;
import com.ld.igds.protocol.modbus.ServerUtil;
import com.ld.igds.protocol.modbus.data.ModbusTcp;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@@ -35,7 +38,9 @@
public static final String BEAN_ID = "modbus.remoteControlService";
@Resource
- private CoreDeviceService deviceService;
+ private CoreDeviceService coreDeviceService;
+ @Resource
+ private HDeviceModbusService deviceModbusService;
@Resource
private AnalysisService analysisService;
@Resource
@@ -44,7 +49,7 @@
@Override
public String getProtocol() {
- return ProtocolEnum.MODBUS_TCP.getCode();
+ return ProtocolEnum.TCP_MODBUS.getCode();
}
@Override
@@ -56,55 +61,59 @@
}
try {
- Device device;
+ DeviceModbus deviceModbus;
ModbusTcp modbusTcp;
ModbusTcp modbusTcpLink = null;
String temp = Constant.YN_N;
for (ExeDevice exeDevice : deviceList) {
- device = deviceService.getCacheDeviceById(exeDevice.getCompanyId(), exeDevice.getId());
+ deviceModbus = deviceModbusService.getCacheDeviceModbus(request.getCompanyId(), exeDevice.getPassCode() + "");
- if (null == device) continue;
+ if (null == deviceModbus) {
+ log.error("褰撳墠璁惧---{}{},涓鸿幏鍙栧埌閰嶇疆鐨凪ODBUS淇℃伅", exeDevice.getSerId(), exeDevice.getName());
+ continue;
+ }
- if (null == device.getModbus()) continue;
-
- modbusTcp = new ModbusTcp(device.getModbus());
+ modbusTcp = new ModbusTcp(deviceModbus);
modbusTcp.setIp(request.getIp());
modbusTcp.setPort(request.getPort());
- modbusTcp.setDeviceCode(device.getPassCode() + "");
+ modbusTcp.setDeviceCode(exeDevice.getPassCode() + "");
modbusTcp.setSerId(request.getSerId());
modbusTcp.setCompanyId(request.getCompanyId());
- if (null != device.getLinkModbus()) {
- modbusTcpLink = new ModbusTcp(device.getLinkModbus());
- modbusTcpLink.setIp(request.getIp());
- modbusTcpLink.setPort(request.getPort());
- modbusTcpLink.setDeviceCode(device.getLink());
- modbusTcpLink.setSerId(request.getSerId());
- modbusTcpLink.setCompanyId(request.getCompanyId());
- }
-
//鏍规嵁璁惧鐩爣鐩爣鐘舵�侊紝閫夋嫨闇�瑕佹墽琛岀殑閫氶亾
- if (DeviceStatus.CLOSE.getCode().equals(device.getTargetStatus())) {
- temp = modbusTcp.getAddrClose();
+ if (DeviceStatus.CLOSE.getCode().equals(exeDevice.getTargetStatus())) {
+ temp = modbusTcp.getDeviceModbus().getClose();
}
- if (DeviceStatus.OPEN.getCode().equals(device.getTargetStatus())) {
- temp = modbusTcp.getAddrOpen();
+ if (DeviceStatus.OPEN.getCode().equals(exeDevice.getTargetStatus())) {
+ temp = modbusTcp.getDeviceModbus().getOpen();
}
- if (null == modbusTcpLink) {
+
+ if (StringUtils.isEmpty(exeDevice.getLink())) {
//鏍规嵁璁惧鐩爣鐘舵�侊紝璋冪敤MODBUS鎵ц
modbusTcp.setAddrExe(this.getAddrExe(temp));
- doWriteExe(modbusTcp, device.getTargetStatus());
+ doWriteExe(modbusTcp, exeDevice.getTargetStatus());
+
continue;
}
+ deviceModbus = deviceModbusService.getCacheDeviceModbus(request.getCompanyId(), exeDevice.getLink());
+ if (null == deviceModbus) continue;
+ modbusTcpLink = new ModbusTcp(deviceModbus);
+ modbusTcpLink.setIp(request.getIp());
+ modbusTcpLink.setPort(request.getPort());
+ modbusTcpLink.setDeviceCode(exeDevice.getLink());
+ modbusTcpLink.setSerId(request.getSerId());
+ modbusTcpLink.setCompanyId(request.getCompanyId());
+
+
//濡傛灉鏄紑椋庢満
- if (DeviceStatus.F_OPEN.getCode().equals(device.getTargetStatus())) {
+ if (DeviceStatus.F_OPEN.getCode().equals(exeDevice.getTargetStatus())) {
//鍏堝紑绐楀彛
- temp = modbusTcp.getAddrOpen();
+ temp = modbusTcp.getDeviceModbus().getOpen();
modbusTcp.setAddrExe(this.getAddrExe(temp));
doWriteExe(modbusTcp, DeviceStatus.OPEN.getCode());
@@ -113,15 +122,15 @@
Thread.sleep(300);
//鍐嶅紑椋庢満
- temp = modbusTcpLink.getAddrOpen();
+ temp = modbusTcpLink.getDeviceModbus().getOpen();
modbusTcpLink.setAddrExe(this.getAddrExe(temp));
doWriteExe(modbusTcpLink, DeviceStatus.OPEN.getCode());
}
//濡傛灉鍏抽鏈�
- if (DeviceStatus.F_CLOSE.equals(device.getTargetStatus())) {
- temp = modbusTcpLink.getAddrClose();
+ if (DeviceStatus.F_CLOSE.equals(exeDevice.getTargetStatus())) {
+ temp = modbusTcpLink.getDeviceModbus().getStop();
modbusTcpLink.setAddrExe(this.getAddrExe(temp));
doWriteExe(modbusTcpLink, DeviceStatus.CLOSE.getCode());
@@ -129,25 +138,25 @@
//濡傛灉寮�绐�
- if (DeviceStatus.W_OPEN.equals(device.getTargetStatus())) {
- temp = modbusTcp.getAddrOpen();
+ if (DeviceStatus.W_OPEN.equals(exeDevice.getTargetStatus())) {
+ temp = modbusTcp.getDeviceModbus().getOpen();
modbusTcp.setAddrExe(this.getAddrExe(temp));
- doWriteExe(modbusTcp, device.getTargetStatus());
+ doWriteExe(modbusTcp, exeDevice.getTargetStatus());
}
//濡傛灉鏄叧绐楁埛
- if (DeviceStatus.W_CLOSE.equals(device.getTargetStatus())) {
+ if (DeviceStatus.W_CLOSE.equals(exeDevice.getTargetStatus())) {
//鍏堝叧椋庢満
- temp = modbusTcpLink.getAddrClose();
+ temp = modbusTcpLink.getDeviceModbus().getStop();
modbusTcpLink.setAddrExe(this.getAddrExe(temp));
doWriteExe(modbusTcpLink, DeviceStatus.CLOSE.getCode());
Thread.sleep(300);
//鍦ㄥ叧绐楁埛
- temp = modbusTcp.getAddrClose();
+ temp = modbusTcp.getDeviceModbus().getOpen();
modbusTcp.setAddrExe(this.getAddrExe(temp));
doWriteExe(modbusTcp, DeviceStatus.CLOSE.getCode());
@@ -186,55 +195,64 @@
@Override
public DeviceControlResponse queryStatus(DeviceControlRequest request) {
try {
- List<Device> list = deviceService.getCacheDeviceBySerId(request.getCompanyId(), request.getSerId());
+ List<Device> list = coreDeviceService.getCacheDeviceBySerId(request.getCompanyId(), request.getSerId());
if (null == list || list.isEmpty()) {
return new DeviceControlResponse(OrderRespEnum.ORDER_ERROR.getCode(), "鏈幏鍙栧埌璁惧鍒楄〃淇℃伅");
}
+ DeviceModbus deviceModbus;
ModbusTcp modbusTcp;
ModbusTcp modbusTcpLink;
- int addrExe;
+ int i = 1;
for (Device device : list) {
- if (null == device.getModbus()) continue;
+ deviceModbus = deviceModbusService.getCacheDeviceModbus(request.getCompanyId(), device.getPassCode() + "");
+ if (null == deviceModbus) {
+ log.error("褰撳墠璁惧---{}{},涓鸿幏鍙栧埌閰嶇疆鐨凪ODBUS淇℃伅", device.getSerId(), device.getName());
+ continue;
+ }
- modbusTcp = new ModbusTcp(device.getModbus());
+ if (Constant.YN_N.equals(deviceModbus.getOpen())) continue;
+
+ modbusTcp = new ModbusTcp(deviceModbus);
modbusTcp.setIp(request.getIp());
modbusTcp.setPort(request.getPort());
modbusTcp.setDeviceCode(device.getPassCode() + "");
modbusTcp.setSerId(device.getSerId());
modbusTcp.setCompanyId(device.getCompanyId());
+ // modbusTcp.setAddrExe(this.getAddrExe(modbusTcp.getDeviceModbus().getOpenEnd()));
- if (Constant.YN_N.equals(modbusTcp.getAddrOpenEnd())) continue;
-
- addrExe = Integer.valueOf(modbusTcp.getAddrOpenEnd()) - 1;
- modbusTcp.setAddrExe(addrExe);
-
+ modbusTcp.setAddrExe(1024);
doReadExe(modbusTcp);
- if (null == device.getLinkModbus()) continue;
+ if (i == 1) break;
+
+ if (StringUtils.isEmpty(device.getLink())) continue;
Thread.sleep(300);
- modbusTcpLink = new ModbusTcp(device.getModbus());
+ deviceModbus = deviceModbusService.getCacheDeviceModbus(request.getCompanyId(), device.getLink());
+
+ if (null == deviceModbus) continue;
+
+ modbusTcpLink = new ModbusTcp(deviceModbus);
modbusTcpLink.setIp(request.getIp());
modbusTcpLink.setPort(request.getPort());
modbusTcpLink.setSerId(device.getSerId());
modbusTcpLink.setDeviceCode(device.getLink());
modbusTcpLink.setCompanyId(device.getCompanyId());
- addrExe = Integer.valueOf(modbusTcpLink.getAddrOpenEnd()) - 1;
- modbusTcpLink.setAddrExe(addrExe);
+
+ modbusTcpLink.setAddrExe(this.getAddrExe(modbusTcp.getDeviceModbus().getOpenEnd()));
doReadExe(modbusTcpLink);
-
}
} catch (Exception e) {
log.error("璋冪敤MODBUS-TCP鎵ц寮傚父锛歿}", e);
- return new DeviceControlResponse(OrderRespEnum.ORDER_ERROR.getCode(), "鍚庡彴鎵ц寮傚父锛�" + e.getMessage());
+ return new DeviceControlResponse(OrderRespEnum.ORDER_ERROR.getCode(), "鍚庡彴鎵ц寮傚父锛�" + e.getLocalizedMessage());
}
analysisService.analysisDevice(request, 3000);
@@ -250,7 +268,7 @@
*/
private void doReadExe(ModbusTcp modbusTcp) throws Exception {
- if (Constant.YN_N.equals(modbusTcp.getAddrOpenEnd())) return;
+ if (Constant.YN_N.equals(modbusTcp.getDeviceModbus().getOpen())) return;
boolean[] result = modbusUtil.readStatus02(modbusTcp.getIp(), modbusTcp.getPort(), modbusTcp.getAddrExe(), 2);
log.debug("---------璇诲彇鐘舵��------{}--{}", modbusTcp.getDeviceCode(), result.toString());
diff --git a/igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/data/ModbusTcp.java b/igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/data/ModbusTcp.java
index 88d5d63..c69d629 100644
--- a/igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/data/ModbusTcp.java
+++ b/igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/data/ModbusTcp.java
@@ -1,6 +1,6 @@
package com.ld.igds.protocol.modbus.data;
-import com.ld.igds.constant.Constant;
+import com.ld.igds.models.DeviceModbus;
import lombok.Data;
/**
@@ -22,76 +22,24 @@
private int port;
- /**
- * 寮�鍦板潃
- **/
- private String addrOpen = Constant.YN_N;
+ private DeviceModbus deviceModbus;
- /**
- * 鍏冲湴鍧�
- **/
- private String addrClose = Constant.YN_N;
-
- /**
- * 鍋滃湴鍧�
- **/
- private String addrStop = Constant.YN_N;
-
- /**
- * 寮�鍒颁綅鍦板潃
- **/
- private String addrOpenEnd = Constant.YN_N;
-
- /**
- * 鍏冲埌浣嶅湴鍧�
- **/
- private String addrCloseEnd = Constant.YN_N;
-
- /**
- * 寮�鏁呴殰鍦板潃
- **/
- private String addrOpenError = Constant.YN_N;
-
- /**
- * 鍏虫晠闅滃湴鍧�
- **/
- private String addrCloseError = Constant.YN_N;
-
- private int addrExe = 65535;
-
+ private int addrExe;
public ModbusTcp() {
super();
}
- public ModbusTcp(String modbusStr) {
- //modbus瑙勫垯锛氬紑鍦板潃-鍏冲湴鍧�-鍋滃湴鍧�-寮�鍒颁綅-鍏冲埌浣�-寮�鏁呴殰-鍏虫晠闅滐紝鏃犲湴鍧�鐢∟浠f浛
- String[] addr = modbusStr.split("-");
- this.addrOpen = addr[0];
- this.addrClose = addr[1];
- this.addrStop = addr[2];
- this.addrOpenEnd = addr[3];
- this.addrCloseEnd = addr[4];
- this.addrOpenError = addr[5];
- this.addrCloseError = addr[6];
+ public ModbusTcp(DeviceModbus deviceModbus) {
+ this.deviceModbus = deviceModbus;
}
-//
-// public ModbusTcp(String modbusStr) {
-// //modbus瑙勫垯锛氬紑鍦板潃-鍏冲湴鍧�-鍋滃湴鍧�-寮�鍒颁綅-鍏冲埌浣�-寮�鏁呴殰-鍏虫晠闅滐紝鏃犲湴鍧�鐢∟浠f浛
-// String[] addr = modbusStr.split("-");
-// String temp = addr[0];
-// if (!Constant.YN_N.equals(temp)) this.addrOpen = temp;
-// temp = addr[1];
-// if (!Constant.YN_N.equals(temp)) this.addrClose = temp;
-// temp = addr[2];
-// if (!Constant.YN_N.equals(temp)) this.addrStop = temp;
-// temp = addr[3];
-// if (!Constant.YN_N.equals(temp)) this.addrOpenEnd = temp;
-// temp = addr[4];
-// if (!Constant.YN_N.equals(temp)) this.addrCloseEnd = temp;
-// temp = addr[5];
-// if (!Constant.YN_N.equals(temp)) this.addrOpenError = temp;
-// temp = addr[6];
-// if (!Constant.YN_N.equals(temp)) this.addrCloseError = temp;
-// }
+
+ public ModbusTcp(String companyId, String deviceCode, String serId, String ip, int port, DeviceModbus deviceModbus) {
+ this.companyId = companyId;
+ this.deviceCode = deviceCode;
+ this.serId = serId;
+ this.ip = ip;
+ this.port = port;
+ this.deviceModbus = deviceModbus;
+ }
}
diff --git a/igds-web/pom.xml b/igds-web/pom.xml
index e2ef9c4..8190d3a 100644
--- a/igds-web/pom.xml
+++ b/igds-web/pom.xml
@@ -125,6 +125,7 @@
<artifactId>igds-api-phone</artifactId>
<version>${igds.version}</version>
</dependency>
+
<!-- 鍏朵粬閫氱敤鍝佺墝鍗忚 -->
<dependency>
<groupId>com.ld.igds</groupId>
@@ -167,6 +168,23 @@
</exclusion>
</exclusions>
</dependency>
+
+ <!-- MODBUS-TCP -->
+ <dependency>
+ <groupId>com.ld.igds</groupId>
+ <artifactId>igds-protocol-modbus</artifactId>
+ <version>${igds.version}</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>slf4j-log4j12</artifactId>
+ <groupId>org.slf4j</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>log4j</artifactId>
+ <groupId>log4j</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
<!-- 绉佹湁鍗忚-椋庢鑷磋繙IOT銆佸埗姘満-->
diff --git a/igds-web/src/main/resources/application-dev.yml b/igds-web/src/main/resources/application-dev.yml
index 8193ef5..b15c2a3 100644
--- a/igds-web/src/main/resources/application-dev.yml
+++ b/igds-web/src/main/resources/application-dev.yml
@@ -12,7 +12,7 @@
db-base:
name: db-base
type: com.alibaba.druid.pool.DruidDataSource
- url: jdbc:mysql://127.0.0.1:3306/igds_v40?useUnicode=true&characterEncoding=utf-8
+ url: jdbc:mysql://127.0.0.1:3306/igds_5325?useUnicode=true&characterEncoding=utf-8
driver-class-name: com.mysql.jdbc.Driver
username: root
password: ukJp12Qf+elyBvGHkJ5MQMa95pfVm0oFBHefdEgDFKoFSjbgYa9PYfv5vlem5nvoXjQsP9tIIo53DvSbsl160Q==
--
Gitblit v1.9.3