jiazx0107@163.com
2023-08-25 73f74cbf665a431b0db474be129a03c655e2338a
更新MODBUS-TCP协议,添加GasModus的配置
已删除1个文件
已修改5个文件
已添加4个文件
945 ■■■■ 文件已修改
igds-core/src/main/java/com/ld/igds/view/DepotConf.view.xml 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-modbus/src/main/java/com/ld/igds/modbus/DeviceModbusPR.java 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-modbus/src/main/java/com/ld/igds/modbus/GasModbus.view.xml 373 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-modbus/src/main/java/com/ld/igds/modbus/GasModbusPR.java 94 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-modbus/src/main/java/com/ld/igds/modbus/ModbusConstant.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-modbus/src/main/java/com/ld/igds/modbus/service/HDeviceModbusService.java 118 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-modbus/src/main/java/com/ld/igds/modbus/service/HModbusService.java 240 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-modbus/src/main/java/com/ld/igds/models/DeviceModbus.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-modbus/src/main/java/com/ld/igds/models/GasModbus.java 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/command/RemoteControlServiceImpl.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
igds-core/src/main/java/com/ld/igds/view/DepotConf.view.xml
@@ -314,6 +314,15 @@
                <Property name="property">ph3Max</Property>
                <Editor/>
              </AutoFormElement>
              <Button>
                <ClientEvent name="onClick">var depotId = view.get(&quot;#dsMain.data:#&quot;).get(&quot;depotId&quot;);&#xD;
var path = &quot;com.ld.igds.modbus.GasModbus.d?depotId=&quot;+depotId;&#xD;
view.get(&quot;#iframModbus&quot;).set(&quot;path&quot;,path);&#xD;
view.get(&quot;#dialogModbus&quot;).show();</ClientEvent>
                <Property name="caption">Modbus配置</Property>
                <Property name="tip">针对Modbus协议的配置</Property>
                <Property name="iconClass">fa fa-refresh</Property>
              </Button>
            </AutoForm>
          </Children>
        </FieldSet>
@@ -346,6 +355,15 @@
                <Property name="property">pestMax</Property>
                <Editor/>
              </AutoFormElement>
              <Button>
                <ClientEvent name="onClick">var depotId = view.get(&quot;#dsMain.data:#&quot;).get(&quot;depotId&quot;);&#xD;
var path = &quot;com.ld.igds.modbus.PestModbus.d?depotId=&quot;+depotId;&#xD;
view.get(&quot;#iframModbus&quot;).set(&quot;path&quot;,path);&#xD;
view.get(&quot;#dialogModbus&quot;).show();</ClientEvent>
                <Property name="caption">Modbus配置</Property>
                <Property name="tip">针对Modbus协议的配置</Property>
                <Property name="iconClass">fa fa-refresh</Property>
              </Button>
            </AutoForm>
          </Children>
        </FieldSet>
@@ -388,5 +406,17 @@
      <Property name="service">depotPR#ajaxGetAllCache</Property>
      <Property name="executingMessage">初始化数据……</Property>
    </AjaxAction>
    <Dialog id="dialogModbus">
      <Property name="width">80%</Property>
      <Property name="height">95%</Property>
      <Property name="caption">Modbus-TCP配置</Property>
      <Buttons/>
      <Children>
        <IFrame id="iframModbus">
          <Property name="path">com.ld.igds.modbus.GasModbus.d</Property>
        </IFrame>
      </Children>
      <Tools/>
    </Dialog>
  </View>
</ViewConfig>
igds-protocol-modbus/src/main/java/com/ld/igds/modbus/DeviceModbusPR.java
@@ -3,7 +3,7 @@
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.modbus.service.HModbusService;
import com.ld.igds.models.DeviceModbus;
import com.ld.igds.models.DicTrigger;
import com.ld.igds.util.ContextUtil;
@@ -20,7 +20,7 @@
public class DeviceModbusPR {
    @Resource
    private HDeviceModbusService deviceModbusService;
    private HModbusService deviceModbusService;
    /**
     * deviceModbusPR#listAll
@@ -30,7 +30,7 @@
    @DataProvider
    public List<DeviceModbus> listAll() {
        String companyId = ContextUtil.getCompanyId();
        return deviceModbusService.listAll(companyId);
        return deviceModbusService.listAllDevice(companyId);
    }
    /**
@@ -41,7 +41,7 @@
    @Expose
    public void flushCache() {
        String companyId = ContextUtil.getCompanyId();
        deviceModbusService.flushCache(companyId);
        deviceModbusService.flushCacheDevice(companyId);
    }
    /**
@@ -52,7 +52,7 @@
    @Expose
    public String delData(DeviceModbus data) {
        if (null == data.getId()) return null;
        return deviceModbusService.delData(data);
        return deviceModbusService.delDataDevice(data);
    }
    /**
@@ -63,7 +63,7 @@
     */
    @DataResolver
    public void updateData(List<DeviceModbus> details) {
        deviceModbusService.updateData(details);
        deviceModbusService.updateDataDevice(details);
    }
@@ -87,6 +87,5 @@
        list.add(new DicTrigger(ModbusConstant.FUN_99, "未配置"));
        return list;
    }
}
igds-protocol-modbus/src/main/java/com/ld/igds/modbus/GasModbus.view.xml
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,373 @@
<?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>
        <Property name="label">ID</Property>
      </PropertyDef>
      <PropertyDef name="deviceCode">
        <Property></Property>
        <Property name="label">仓库编码</Property>
        <Property name="mapping">
          <Property name="mapValues">${dorado.getDataProvider(&quot;depotPR#getAllCache&quot;).getResult()}</Property>
          <Property name="keyProperty">id</Property>
          <Property name="valueProperty">name</Property>
        </Property>
      </PropertyDef>
      <PropertyDef name="open">
        <Property></Property>
        <Property name="label">开地址</Property>
      </PropertyDef>
      <PropertyDef name="openFun">
        <Property></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>
        <Property name="label">关地址</Property>
      </PropertyDef>
      <PropertyDef name="closeFun">
        <Property></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>
        <Property name="label">停地址</Property>
      </PropertyDef>
      <PropertyDef name="stopFun">
        <Property></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>
        <Property name="label">开到位</Property>
      </PropertyDef>
      <PropertyDef name="openEndFun">
        <Property></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>
        <Property name="label">关到位</Property>
      </PropertyDef>
      <PropertyDef name="closeEndFun">
        <Property></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>
        <Property name="label">开故障</Property>
      </PropertyDef>
      <PropertyDef name="openErrorFun">
        <Property></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>
        <Property name="label">关故障</Property>
      </PropertyDef>
      <PropertyDef name="closeErrorFun">
        <Property></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>
      <Reference name="listGas">
        <Property name="dataType">[dtGas]</Property>
        <Property name="dataProvider">gasModbusPR#listGasModBus</Property>
        <Property name="parameter">$${this.deviceCode}</Property>
      </Reference>
    </DataType>
    <DataType name="dtGas">
      <Property name="creationType">com.ld.igds.models.GasModbus</Property>
      <PropertyDef name="id">
        <Property/>
        <Property name="label">ID</Property>
      </PropertyDef>
      <PropertyDef name="depotId">
        <Property/>
        <Property name="label">所属仓库</Property>
      </PropertyDef>
      <PropertyDef name="passcode">
        <Property name="dataType">int</Property>
        <Property name="label">通道</Property>
      </PropertyDef>
      <PropertyDef name="co2">
        <Property/>
        <Property name="label">二氧化碳</Property>
      </PropertyDef>
      <PropertyDef name="co2Fun">
        <Property/>
        <Property name="label">功能号</Property>
      </PropertyDef>
      <PropertyDef name="o2">
        <Property/>
        <Property name="label">氧气</Property>
      </PropertyDef>
      <PropertyDef name="o2Fun">
        <Property/>
        <Property name="label">功能号</Property>
      </PropertyDef>
      <PropertyDef name="ph3">
        <Property/>
        <Property name="label">磷化氢</Property>
      </PropertyDef>
      <PropertyDef name="ph3Fun">
        <Property/>
        <Property name="label">功能号</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">gasModbusPR#getGasData</Property>
      <Property name="parameter">${request.getParameter('depotId')}</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">var list = view.get(&quot;#dsMain.data&quot;).get(&quot;listGas&quot;);&#xD;
list.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;#dataGrid1&quot;).getCurrentItem();;&#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">
        <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>
      <AutoForm>
        <Property name="dataSet">dsMain</Property>
        <Property name="cols">*,*,*,*</Property>
        <Property name="labelAlign">right</Property>
        <Property name="labelSeparator">:</Property>
        <Property name="labelWidth">100</Property>
        <AutoFormElement layoutConstraint="colSpan:2">
          <Property name="name">deviceCode</Property>
          <Property name="property">deviceCode</Property>
          <Property name="label">仓库编码</Property>
          <Property name="labelWidth">100</Property>
          <Editor/>
        </AutoFormElement>
        <AutoFormElement>
          <Property name="name">open</Property>
          <Property name="property">open</Property>
          <Editor/>
        </AutoFormElement>
        <AutoFormElement>
          <Property name="name">openFun</Property>
          <Property name="property">openFun</Property>
          <Editor/>
        </AutoFormElement>
        <AutoFormElement>
          <Property name="name">close</Property>
          <Property name="property">close</Property>
          <Editor/>
        </AutoFormElement>
        <AutoFormElement>
          <Property name="name">closeFun</Property>
          <Property name="property">closeFun</Property>
          <Editor/>
        </AutoFormElement>
        <AutoFormElement>
          <Property name="name">stop</Property>
          <Property name="property">stop</Property>
          <Editor/>
        </AutoFormElement>
        <AutoFormElement>
          <Property name="name">stopFun</Property>
          <Property name="property">stopFun</Property>
          <Editor/>
        </AutoFormElement>
        <AutoFormElement>
          <Property name="name">openEnd</Property>
          <Property name="property">openEnd</Property>
          <Editor/>
        </AutoFormElement>
        <AutoFormElement>
          <Property name="name">openEndFun</Property>
          <Property name="property">openEndFun</Property>
          <Editor/>
        </AutoFormElement>
        <AutoFormElement>
          <Property name="name">closeEnd</Property>
          <Property name="property">closeEnd</Property>
          <Editor/>
        </AutoFormElement>
        <AutoFormElement>
          <Property name="name">closeEndFun</Property>
          <Property name="property">closeEndFun</Property>
          <Editor/>
        </AutoFormElement>
        <AutoFormElement>
          <Property name="name">openError</Property>
          <Property name="property">openError</Property>
          <Editor/>
        </AutoFormElement>
        <AutoFormElement>
          <Property name="name">openErrorFun</Property>
          <Property name="property">openErrorFun</Property>
          <Editor/>
        </AutoFormElement>
        <AutoFormElement>
          <Property name="name">closeError</Property>
          <Property name="property">closeError</Property>
          <Editor/>
        </AutoFormElement>
        <AutoFormElement>
          <Property name="name">closeErrorFun</Property>
          <Property name="property">closeErrorFun</Property>
          <Editor/>
        </AutoFormElement>
      </AutoForm>
      <ToolBar>
        <ToolBarLabel>
          <Property name="text">检测通道配置</Property>
          <Property name="style">
            <Property name="font-weight">bold</Property>
          </Property>
        </ToolBarLabel>
      </ToolBar>
      <DataGrid id="dataGrid1" layoutConstraint="center padding:5px">
        <Property name="dataSet">dsMain</Property>
        <Property name="dataPath">#.listGas</Property>
        <RowNumColumn/>
        <DataColumn>
          <Property name="property">passcode</Property>
          <Property name="name">passcode</Property>
          <Editor/>
        </DataColumn>
        <ColumnGroup>
          <Property name="caption">CO2</Property>
          <DataColumn>
            <Property name="property">co2</Property>
            <Property name="caption">地址</Property>
            <Property name="name">co2</Property>
          </DataColumn>
          <DataColumn>
            <Property name="property">co2Fun</Property>
            <Property name="caption">功能</Property>
            <Property name="trigger">autoMappingDropDown1</Property>
            <Property name="name">co2Fun</Property>
          </DataColumn>
        </ColumnGroup>
        <ColumnGroup>
          <Property name="caption">O2</Property>
          <DataColumn>
            <Property name="property">o2</Property>
            <Property name="caption">地址</Property>
            <Property name="name">o2</Property>
          </DataColumn>
          <DataColumn>
            <Property name="property">o2Fun</Property>
            <Property name="caption">功能</Property>
            <Property name="trigger">autoMappingDropDown1</Property>
            <Property name="name">o2Fun</Property>
          </DataColumn>
        </ColumnGroup>
        <ColumnGroup>
          <Property name="caption">PH3</Property>
          <DataColumn>
            <Property name="property">ph3</Property>
            <Property name="caption">地址</Property>
            <Property name="name">ph3</Property>
          </DataColumn>
          <DataColumn>
            <Property name="property">ph3Fun</Property>
            <Property name="caption">功能</Property>
            <Property name="trigger">autoMappingDropDown1</Property>
            <Property name="name">ph3Fun</Property>
          </DataColumn>
        </ColumnGroup>
      </DataGrid>
    </Container>
    <UpdateAction id="uaAction">
      <Property name="dataResolver">gasModbusPR#updateData</Property>
      <UpdateItem>
        <Property name="dataSet">dsMain</Property>
        <Property name="dataPath">[#current]</Property>
      </UpdateItem>
    </UpdateAction>
    <AjaxAction id="ajaxDel">
      <Property name="service">gasModbusPR#delData</Property>
      <Property name="confirmMessage">确定要删除么?</Property>
    </AjaxAction>
    <AjaxAction id="ajaxFlushCache">
      <Property name="service">gasModbusPR#flushCache</Property>
      <Property name="successMessage">缓存更新成功</Property>
    </AjaxAction>
  </View>
</ViewConfig>
igds-protocol-modbus/src/main/java/com/ld/igds/modbus/GasModbusPR.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,94 @@
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.constant.BizType;
import com.ld.igds.modbus.service.HModbusService;
import com.ld.igds.models.DeviceModbus;
import com.ld.igds.models.GasModbus;
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 GasModbusPR {
    @Resource
    private HModbusService modbusService;
    /**
     * gasModbusPR#getGasData
     *
     * @return
     */
    @DataProvider
    public DeviceModbus getGasData(String depotId) {
        if (null == depotId) return new DeviceModbus();
        String bizType = BizType.GAS.getCode();
        String companyId = ContextUtil.getCompanyId();
        DeviceModbus result = modbusService.getGasData(companyId, depotId, bizType);
        if (null == result) {
            result = new DeviceModbus();
            result.setBizType(bizType);
            result.setDeviceCode(depotId);
            result.setListGas(new ArrayList<>());
        }
        return result;
    }
    /**
     * gasModbusPR#listGasModBus
     *
     * @param depotId
     * @return
     */
    @DataProvider
    public List<GasModbus> listGasModBus(String depotId) {
        return modbusService.listGasModBus(depotId);
    }
    /**
     * gasModbusPR#updateData
     * @param data
     */
    @DataResolver
    public void updateData(DeviceModbus data){
        modbusService.updateGasModbus(data);
    }
    /**
     * gasModbusPR#flushCache
     *
     * @return
     */
    @Expose
    public void flushCache() {
        String companyId = ContextUtil.getCompanyId();
        modbusService.flushCacheGas(companyId);
    }
    /**
     * deviceModbusPR#delData
     *
     * @return
     */
    @Expose
    public String delData(GasModbus data) {
        if (null == data.getId()) return null;
        return modbusService.delDataGas(data);
    }
}
igds-protocol-modbus/src/main/java/com/ld/igds/modbus/ModbusConstant.java
@@ -29,7 +29,7 @@
    public static final String MODBUS_DEVICE_CACHE = "MODBUS_DEVICE";
    public static final String MODBUS_GAS_CACHE_LIST = "MODBUS_GAS_LIST";
igds-protocol-modbus/src/main/java/com/ld/igds/modbus/service/HDeviceModbusService.java
ÎļþÒÑɾ³ý
igds-protocol-modbus/src/main/java/com/ld/igds/modbus/service/HModbusService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,240 @@
package com.ld.igds.modbus.service;
import com.bstek.bdf2.core.orm.hibernate.HibernateDao;
import com.ld.igds.constant.BizType;
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.models.GasModbus;
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.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Component
public class HModbusService extends HibernateDao {
    @Resource
    private RedisUtil redisUtil;
    public List<DeviceModbus> listAllDevice(String companyId) {
        String hql = " from " + DeviceModbus.class.getName() + " where 1=1 order by deviceCode+0";
        return this.query(hql);
    }
    public void flushCacheDevice(String companyId) {
        if (null == companyId) companyId = ContextUtil.getDefaultCompanyId();
        List<DeviceModbus> listAll = this.listAllDevice(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 updateDataDevice(List<DeviceModbus> details) {
        if (null == details || details.isEmpty()) return;
        Session session = this.getSessionFactory().openSession();
        try {
            for (DeviceModbus device : details) {
                device = updateInitData(device);
                if (null == device.getId()) {
                    device.setId(ContextUtil.getUUID());
                    session.save(device);
                } else {
                    session.update(device);
                }
            }
            flushCacheDevice(null);
        } catch (Exception e) {
        } finally {
            session.flush();
            session.close();
        }
    }
    private DeviceModbus updateInitData(DeviceModbus device) {
        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 (StringUtils.isEmpty(device.getBizType())) device.setBizType(BizType.AREATION.getCode());
        return device;
    }
    public String delDataDevice(DeviceModbus data) {
        Session session = this.getSessionFactory().openSession();
        try {
            session.delete(data);
            flushCacheDevice(null);
        } catch (Exception e) {
        } finally {
            session.flush();
            session.close();
        }
        return null;
    }
    public DeviceModbus getGasData(String companyId, String depotId, String bizType) {
        String hql = " from " + DeviceModbus.class.getName() + " where bizType=:bizType and deviceCode =:deviceCode";
        Map<String, Object> param = new HashMap<>();
        param.put("bizType", bizType);
        param.put("deviceCode", depotId);
        List<DeviceModbus> list = this.query(hql, param);
        if (null == list || list.isEmpty()) {
            return null;
        }
        return list.get(0);
    }
    public List<GasModbus> listGasModBus(String depotId) {
        String hql = " from " + GasModbus.class.getName();
        if (null == depotId) {
            return this.query(hql);
        } else {
            hql += " where depotId=:depotId order by passcode";
            Map<String, Object> param = new HashMap<>();
            param.put("depotId", depotId);
            return this.query(hql, param);
        }
    }
    public void updateGasModbus(DeviceModbus data) {
        Session session = this.getSessionFactory().openSession();
        try {
            data = updateInitData(data);
            data.setBizType(BizType.GAS.getCode());
            if (StringUtils.isEmpty(data.getId())) {
                data.setId(ContextUtil.getUUID());
                session.save(data);
            } else {
                session.update(data);
            }
            flushCacheDevice(null);
            this.updateListGas(session, data);
        } catch (Exception e) {
        } finally {
            session.flush();
            session.close();
        }
    }
    private void updateListGas(Session session, DeviceModbus data) {
        List<GasModbus> list = data.getListGas();
        if (null == list || list.isEmpty()) return;
        for (GasModbus gas : list) {
            gas.setDepotId(data.getDeviceCode());
            if (StringUtils.isEmpty(gas.getId())) {
                gas.setId(ContextUtil.getUUID());
                session.save(gas);
            } else {
                session.update(gas);
            }
        }
        flushCacheGas(null);
    }
    public void flushCacheGas(String companyId) {
        List<GasModbus> listAll = this.listGasModBus(null);
        if (null == listAll || listAll.isEmpty()) return;
        if (null == companyId) companyId = ContextUtil.getDefaultCompanyId();
        Map<String, List<GasModbus>> collect = listAll.stream().collect(Collectors.groupingBy(GasModbus::getDepotId));
        String key;
        for (String depotId : collect.keySet()) {
            key = RedisConst.buildKey(companyId, ModbusConstant.MODBUS_GAS_CACHE_LIST, depotId);
            redisUtil.set(key, key);
        }
    }
    public List<GasModbus> getCacheGasModbus(String companyId, String depotId) {
        if (null == companyId) companyId = ContextUtil.getDefaultCompanyId();
        String key = RedisConst.buildKey(companyId, ModbusConstant.MODBUS_GAS_CACHE_LIST, depotId);
        return (List<GasModbus>) redisUtil.get(key);
    }
    public String delDataGas(GasModbus data) {
        Session session = this.getSessionFactory().openSession();
        try {
            session.delete(data);
            flushCacheGas(null);
        } catch (Exception e) {
        } finally {
            session.flush();
            session.close();
        }
        return null;
    }
}
igds-protocol-modbus/src/main/java/com/ld/igds/models/DeviceModbus.java
@@ -1,11 +1,13 @@
package com.ld.igds.models;
import com.bstek.dorado.annotation.PropertyDef;
import com.ld.igds.constant.BizType;
import com.ld.igds.constant.Constant;
import lombok.Data;
import javax.persistence.*;
import java.io.Serializable;
import java.util.List;
/**
 * æ ¹æ®è®¾å¤‡é…ç½®çš„Modbus-TCP参数配置
@@ -25,10 +27,15 @@
    @Column(name = "DEVICE_CODE_", length = 40)
    @PropertyDef(label = "设备编码")
    private String deviceCode;
    @Column(name = "BIZ_TYEP_", length = 10)
    @PropertyDef(label = "业务类型")
    private String bizType = BizType.AREATION.getCode();
    @Column(name = "OPEN_", length = 10)
    @PropertyDef(label = "开地址")
    private String open = Constant.YN_N;
    @Column(name = "OPEN_FUN", length = 4)
    @PropertyDef(label = "功能号")
@@ -82,4 +89,8 @@
    @PropertyDef(label = "功能号")
    private String closeErrorFun = "99";
    @Transient
    private List<GasModbus> listGas;
}
igds-protocol-modbus/src/main/java/com/ld/igds/models/GasModbus.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,60 @@
package com.ld.igds.models;
import com.bstek.dorado.annotation.PropertyDef;
import com.ld.igds.constant.Constant;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
/**
 * é…ç½®æµ‹æ°”和测虫的MODBUS-TCP配置信息
 */
@Data
@Entity
@Table(name = "D_GAS_MODBUS")
public class GasModbus implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "ID_", length = 40)
    @PropertyDef(label = "ID")
    private String id;
    @Column(name = "DEPOT_ID_", length = 50)
    @PropertyDef(label = "所属仓库")
    private String depotId;
    @Column(name = "PASS_CODE_")
    @PropertyDef(label = "通道")
    private int passcode;
    @Column(name = "CO2_", length = 10)
    @PropertyDef(label = "二氧化碳")
    private String co2 = Constant.YN_N;
    @Column(name = "CO2_FUN", length = 4)
    @PropertyDef(label = "功能号")
    private String co2Fun = "99";
    @Column(name = "O2_", length = 10)
    @PropertyDef(label = "氧气")
    private String o2 = Constant.YN_N;
    @Column(name = "O2_FUN", length = 4)
    @PropertyDef(label = "功能号")
    private String o2Fun = "99";
    @Column(name = "PH3_", length = 10)
    @PropertyDef(label = "磷化氢")
    private String ph3= Constant.YN_N;
    @Column(name = "PH3_FUN", length = 4)
    @PropertyDef(label = "功能号")
    private String ph3Fun = "99";
}
igds-protocol-modbus/src/main/java/com/ld/igds/protocol/modbus/command/RemoteControlServiceImpl.java
@@ -11,7 +11,7 @@
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.modbus.service.HModbusService;
import com.ld.igds.models.Device;
import com.ld.igds.models.DeviceModbus;
import com.ld.igds.protocol.modbus.ModbusUtil2;
@@ -40,7 +40,7 @@
    @Resource
    private CoreDeviceService coreDeviceService;
    @Resource
    private HDeviceModbusService deviceModbusService;
    private HModbusService deviceModbusService;
    @Resource
    private AnalysisService analysisService;