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 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; 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> 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-读离æ£éè¾å ¥")); 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; } } 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-读离æ£éè¾å ¥ 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"; } 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; } } 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 = "é对åééé 置设å¤ï¼å¦æ··æµé£å£ç飿ºãè½´æµé£å£ç飿º") 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 = "æ ¹æ®ä¸å¡éè¦èªå®ä¹åå¨å¼") 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; /** * æ ¹æ®è®¾å¤é ç½®çModbus-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"; } 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è§åï¼å¼å°å-å ³å°å-åå°å-å¼å°ä½-å ³å°ä½-弿 é-å ³æ éï¼æ å°åç¨N代æ¿</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> 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); } } 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> 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, igds-protocol-modbus/pom.xml
@@ -13,8 +13,6 @@ </properties> <dependencies> <!-- å¼å ¥IOå --> 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, "设å¤ç¶ææ¥è¯¢æåå¹¶å®æè§£æï¼"); 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("å½å设å¤---{}{},为è·åå°é ç½®çMODBUSä¿¡æ¯", 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("å½å设å¤---{}{},为è·åå°é ç½®çMODBUSä¿¡æ¯", 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()); 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è§åï¼å¼å°å-å ³å°å-åå°å-å¼å°ä½-å ³å°ä½-弿 é-å ³æ éï¼æ å°åç¨Nä»£æ¿ 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è§åï¼å¼å°å-å ³å°å-åå°å-å¼å°ä½-å ³å°ä½-弿 é-å ³æ éï¼æ å°åç¨Nä»£æ¿ // 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; } } 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ãå¶æ°®æº--> 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==