jiazx0107@163.com
2023-08-23 9c49930966edbe0f24e62e38f58c2d3e453976b3
更新MODBUS-TCP协议 4
已修改13个文件
已添加5个文件
1393 ■■■■ 文件已修改
igds-core/src/main/java/com/ld/igds/data/SimpleDepot.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-core/src/main/java/com/ld/igds/io/constant/ProtocolEnum.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-core/src/main/java/com/ld/igds/modbus/DeviceModbus.view.xml 289 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-core/src/main/java/com/ld/igds/modbus/DeviceModbusPR.java 92 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-core/src/main/java/com/ld/igds/modbus/ModbusConstant.java 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-core/src/main/java/com/ld/igds/modbus/service/HDeviceModbusService.java 118 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-core/src/main/java/com/ld/igds/models/Device.java 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-core/src/main/java/com/ld/igds/models/DeviceModbus.java 85 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-core/src/main/java/com/ld/igds/view/Device.view.xml 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-core/src/main/java/com/ld/igds/view/service/DeviceService.java 470 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-core/src/main/java/models/igds.model.xml 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-core/src/main/resources/mapper/DeviceMapper.xml 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-modbus/pom.xml 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/command/AnalysisService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/command/RemoteControlServiceImpl.java 120 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/data/ModbusTcp.java 80 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-web/pom.xml 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-web/src/main/resources/application-dev.yml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
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(&quot;deviceModbusPR#triggerFun&quot;).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(&quot;deviceModbusPR#triggerFun&quot;).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(&quot;deviceModbusPR#triggerFun&quot;).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(&quot;deviceModbusPR#triggerFun&quot;).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(&quot;deviceModbusPR#triggerFun&quot;).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(&quot;deviceModbusPR#triggerFun&quot;).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(&quot;deviceModbusPR#triggerFun&quot;).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(&quot;#dsMain&quot;).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(&quot;#uaAction&quot;).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(&quot;#dsMain.data:#&quot;);&#xD;
if(!data){&#xD;
    return;&#xD;
}&#xD;
view.get(&quot;#ajaxDel&quot;).set(&quot;parameter&quot;,data).execute(function(result){&#xD;
    if(result){&#xD;
        $alert(result);&#xD;
        return;&#xD;
    }else{&#xD;
        data.remove();&#xD;
    }&#xD;
});           </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(&quot;#dsMain&quot;).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(&quot;#dataSetC&quot;).insert();</ClientEvent>
    <ClientEvent name="onReady">view.get(&quot;#dataSetC&quot;).insert();&#xD;
&#xD;
openModbusDevice = function(){&#xD;
    view.get(&quot;#dialogModbus&quot;).show();&#xD;
}</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 =&quot;&lt;a href='javascripe:;' onclick='openModbusDevice()'>Modbus配置&lt;/a>&quot;;&#xD;
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==