ty130316261 3 anni fa
parent
commit
5a02b50ebc
17 ha cambiato i file con 471 aggiunte e 332 eliminazioni
  1. 1 0
      docker/mysql/update/lab-update.sql
  2. 10 0
      zd-api/zd-api-system/src/main/java/com/zd/system/api/laboratory/domain/RemoteLabHardware.java
  3. 1 13
      zd-api/zd-api-system/src/main/java/com/zd/system/api/netty/RemoteNettyService.java
  4. 1 6
      zd-api/zd-api-system/src/main/java/com/zd/system/api/netty/factory/RemoteNettyFallbackFactory.java
  5. 1 1
      zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/controller/LabHardwareController.java
  6. 10 0
      zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/domain/LabHardware.java
  7. 6 1
      zd-modules/zd-modules-laboratory/src/main/resources/mapper/laboratory/LabHardwareMapper.xml
  8. 7 0
      zd-modules/zd-netty/pom.xml
  9. 3 75
      zd-modules/zd-netty/src/main/java/com/zd/netty/controller/FridDeviceController.java
  10. 50 0
      zd-modules/zd-netty/src/main/java/com/zd/netty/enums/ManufacturerTypeEnum.java
  11. 1 1
      zd-modules/zd-netty/src/main/java/com/zd/netty/init/NettyStartListener.java
  12. 110 0
      zd-modules/zd-netty/src/main/java/com/zd/netty/sdk/DeJuRFIDService.java
  13. 236 0
      zd-modules/zd-netty/src/main/java/com/zd/netty/sdk/WuYuanRFIDService.java
  14. 6 26
      zd-modules/zd-netty/src/main/java/com/zd/netty/service/IFridService.java
  15. 19 0
      zd-modules/zd-netty/src/main/java/com/zd/netty/service/IService.java
  16. 9 209
      zd-modules/zd-netty/src/main/java/com/zd/netty/service/impl/FridServiceImpl.java
  17. BIN
      zd-modules/zd-netty/src/main/resources/libs/reader.jar

+ 1 - 0
docker/mysql/update/lab-update.sql

@@ -0,0 +1 @@
+ALTER TABLE lab_hardware ADD manufacturer_type TINYINT(4) COMMENT '供应厂商';

+ 10 - 0
zd-api/zd-api-system/src/main/java/com/zd/system/api/laboratory/domain/RemoteLabHardware.java

@@ -110,6 +110,9 @@ public class RemoteLabHardware{
      */
     private int hardwareType;
 
+    @ApiModelProperty(value = "供应厂商")
+    private Integer manufacturerType;
+
     /** ip地址 */
     @Length(message = "ip地址长度不能超过100")
     @ApiModelProperty(value = "ip地址")
@@ -128,6 +131,13 @@ public class RemoteLabHardware{
     private Integer channels;
 
 
+    public Integer getManufacturerType() {
+        return manufacturerType;
+    }
+
+    public void setManufacturerType(Integer manufacturerType) {
+        this.manufacturerType = manufacturerType;
+    }
 
     public String getHardwareNum() {
         return hardwareNum;

+ 1 - 13
zd-api/zd-api-system/src/main/java/com/zd/system/api/netty/RemoteNettyService.java

@@ -15,24 +15,12 @@ import org.springframework.web.bind.annotation.RequestParam;
 
 @FeignClient(contextId = "remoteNettyService", value = ServiceNameConstants.NETTY_SERVICE, fallbackFactory = RemoteNettyFallbackFactory.class)
 public interface RemoteNettyService {
-
-    @ApiOperation("启动FRID扫描监控")
-    @GetMapping("/frid/startMonitor")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name = "index", value = "session 枚举类所提供的下标,从0开始,最大为3,超过会默认为0"),
-            @ApiImplicitParam(name = "uniformPower", value = "设备输出功率,1开始,默认最大33"),
-            @ApiImplicitParam(name = "ipAddress", value = "设备IP地址")
-    })
-    R<Boolean> startMonitor(@RequestParam(name = "index",required = false, defaultValue = "2") byte index,
-                            @RequestParam(name = "uniformPower", required = false, defaultValue = "33") Integer uniformPower,
-                            @RequestParam("ipAddress") String ipAddress);
-
     /**
      * 断开设备连接
      */
     @ApiOperation("断开设备连接")
     @GetMapping("/frid/disconnect")
-    R<Boolean> disconnect(@RequestParam("ipAddress") String ipAddress);
+    R<Boolean> disconnect(@RequestBody RemoteLabHardware hardware);
 
     @ApiOperation("信道启动FRID扫描监控")
     @PostMapping("/frid/startMonitorChannels")

+ 1 - 6
zd-api/zd-api-system/src/main/java/com/zd/system/api/netty/factory/RemoteNettyFallbackFactory.java

@@ -18,12 +18,7 @@ public class RemoteNettyFallbackFactory implements FallbackFactory<RemoteNettySe
         log.error("netty服务调用失败:{}", throwable.getMessage());
         return new RemoteNettyService() {
             @Override
-            public R<Boolean> startMonitor(byte index, Integer uniformPower, String ipAddress) {
-                return  R.fail("启动失败:" + throwable.getMessage());
-            }
-
-            @Override
-            public R<Boolean> disconnect(String ipAddress) {
+            public R<Boolean> disconnect(RemoteLabHardware hardware) {
                 return  R.fail("停止扫描失败:" + throwable.getMessage());
             }
 

+ 1 - 1
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/controller/LabHardwareController.java

@@ -395,7 +395,7 @@ public class LabHardwareController extends BaseController {
                 return ResultData.fail(result.getMsg());
             }
         }else {
-            R<Boolean> result = nettyService.disconnect(remoteLabHardware.getIpAddress());
+            R<Boolean> result = nettyService.disconnect(remoteLabHardware);
             if (result.getCode()== HttpStatus.SUCCESS){
                 operate=HardwareOperate.CLOSE;
             }else {

+ 10 - 0
zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/domain/LabHardware.java

@@ -194,6 +194,16 @@ public class LabHardware extends BaseEntity {
 
     @ApiModelProperty(value = "设备启用停用(1是启用,0是停用)")
     private Integer deviceStatus;
+    @ApiModelProperty(value = "供应厂商")
+    private Integer manufacturerType;
+
+    public Integer getManufacturerType() {
+        return manufacturerType;
+    }
+
+    public void setManufacturerType(Integer manufacturerType) {
+        this.manufacturerType = manufacturerType;
+    }
 
     public String getFunctionStatus() {
         return functionStatus;

+ 6 - 1
zd-modules/zd-modules-laboratory/src/main/resources/mapper/laboratory/LabHardwareMapper.xml

@@ -37,6 +37,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="lockId" column="lock_id"/>
         <result property="joinCabinet"    column="join_cabinet"    />
         <result property="deviceStatus" column="device_status"/>
+        <result property="manufacturerType" column="manufacturer_type"/>
     </resultMap>
 
     <resultMap type="com.zd.laboratory.domain.vo.LabHardwareVO" id="LabHardwareVOResult">
@@ -79,7 +80,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
           '-',(SELECT bg.name FROM lab_building bg,lab_subject st WHERE bg.id = st.floor_id AND st.id = he.subject_id),
           '-',(SELECT slt.room FROM lab_subject_layout slt,lab_subject st WHERE slt.id = st.layout_id AND st.id = he.subject_id)) posi,
           stc.ring_time, stc.deal_time,he.operate_time,he.join_cabinet joinCabinetId,he.join_cabinet_time joinCabinetTime,he.lock_id lockId,
-          he.device_status deviceStatus
+          he.device_status deviceStatus,he.manufacturer_type manufacturerType
           from
           lab_hardware he LEFT JOIN hxp_smart_terminal_config stc ON he.id = stc.terminal_id
           )xx left join lab_subject_hardware_position hp on hp.hard_id = xx.id
@@ -222,6 +223,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         `port`,
         uniform_power,
         session_index,
+        manufacturer_type,
         channels,
         bit
         from
@@ -321,6 +323,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="configName != null">config_name,</if>
             <if test="configStatus != null">config_status,</if>
             <if test="ipAddress != null">ip_address,</if>
+            <if test="manufacturertype != null">manufacturer_type,</if>
 
             <if test="port != null">port,</if>
 
@@ -357,6 +360,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="configName != null">#{configName},</if>
             <if test="configStatus != null">#{configStatus},</if>
             <if test="ipAddress != null">#{ipAddress},</if>
+            <if test="manufacturerType != null">#{manufacturerType},</if>
             <if test="port != null">#{port},</if>
             <if test="uniformPower != null">#{uniformPower},</if>
             <if test="sessionIndex != null">#{sessionIndex},</if>
@@ -398,6 +402,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="lockId != null">lock_id = #{lockId},</if>
             <if test="operateTime != null">operate_time=#{operateTime},</if>
             <if test="deviceStatus != null">device_status=#{deviceStatus},</if>
+            <if test="manufacturerType != null">manufacturer_type=#{manufacturerType},</if>
         </trim>
         where id = #{id}
     </update>

+ 7 - 0
zd-modules/zd-netty/pom.xml

@@ -137,6 +137,13 @@
             <scope>system</scope>
             <systemPath>${project.basedir}/src/main/resources/libs/reader-lib.jar</systemPath>
         </dependency>
+        <dependency>
+            <groupId>com.gg.reader</groupId>
+            <artifactId>greader-api</artifactId>
+            <version>1.0.0</version>
+            <scope>system</scope>
+            <systemPath>${project.basedir}/src/main/resources/libs/reader.jar</systemPath>
+        </dependency>
     </dependencies>
     <build>
         <finalName>${project.artifactId}</finalName>

+ 3 - 75
zd-modules/zd-netty/src/main/java/com/zd/netty/controller/FridDeviceController.java

@@ -18,42 +18,6 @@ public class FridDeviceController {
 
     @Resource
     private IFridService service;
-    /**
-     * 连接设备
-     */
-    @ApiOperation("连接设备")
-    @GetMapping("/connect")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name = "uniformPower",value = "设备输出功率,1开始,默认最大33"),
-            @ApiImplicitParam(name = "ipAddress",value = "设备IP地址")
-    })
-    public R<Boolean> connect(@RequestParam(value = "uniformPower",required = false,defaultValue = "33") Integer uniformPower,@RequestParam("ipAddress") String ipAddress) {
-        connectAndSet(uniformPower,ipAddress);
-        return R.ok();
-    }
-
-    private void connectAndSet(Integer uniformPower, String ipAddress) {
-        if (Boolean.FALSE.equals(service.deviceStatus(ipAddress))){
-            service.connect(ipAddress,4001);
-            service.setDevice(uniformPower,ipAddress);
-        }
-    }
-
-    /**
-     * 设置设备运行参数
-     * @param uniformPower 设置输出功率
-     * @param ipAddress IP地址
-     * @return Boolean
-     */
-    @ApiOperation("设置设备运行参数")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name = "uniformPower",value = "设备输出功率,1开始,默认最大33"),
-            @ApiImplicitParam(name = "ipAddress",value = "设备IP地址")
-    })
-    @GetMapping("/setDevice")
-    public R<Boolean> setDevice(Integer uniformPower,String ipAddress) {
-        return R.ok(service.setDevice(uniformPower,ipAddress));
-    }
 
     /**
      * 启动FRID扫描监控
@@ -62,62 +26,26 @@ public class FridDeviceController {
      *         Session.S2 在辐射范围内重复出现或停止不动的有且仅返回一次数据,当设备离开辐射区域后重置缓存记录,根据厂商提供的文档和本人结合业务应用实际测试,推荐使用此session
      *         Session.S3 这个暂时没搞懂,选择此session的时候在没有标签在辐射区域会报错,不知道是因为识别设备不够四个还是其他问题,待确定
      */
-    @ApiOperation("启动FRID扫描监控")
     @GetMapping("/startMonitor")
     @ApiImplicitParams({
             @ApiImplicitParam(name = "index",value = "session 枚举类所提供的下标,从0开始,最大为3,超过会默认为0"),
             @ApiImplicitParam(name = "uniformPower",value = "设备输出功率,1开始,默认最大33"),
             @ApiImplicitParam(name = "ipAddress",value = "设备IP地址")
     })
-    public R<Boolean> startMonitor(@RequestParam(required = false,defaultValue = "2") byte index,
-                                   @RequestParam(value = "uniformPower",required = false,defaultValue = "33") Integer uniformPower,
-                                   @RequestParam("ipAddress") String ipAddress) {
-        connectAndSet(uniformPower, ipAddress);
-        service.startMonitor(index,ipAddress);
-        return R.ok();
-    }
-
     @ApiOperation("信道启动FRID扫描监控")
     @PostMapping("/startMonitorChannels")
     public R<Boolean> startMonitorChannels(@RequestBody RemoteLabHardware hardware) {
-        service.startMonitorChannels(hardware);
+        service.start(hardware);
         return R.ok();
     }
 
     /**
-     * 停止FRID扫描监控
-     */
-    @ApiOperation("停止FRID扫描监控")
-    @GetMapping("/stopMonitor")
-    public R<Boolean> stopMonitor(@RequestParam("ipAddress") String ipAddress) {
-        return R.ok(service.stopMonitor(ipAddress));
-    }
-
-    /**
      * 断开设备连接
      */
     @ApiOperation("断开设备连接")
     @GetMapping("/disconnect")
-    public R<Boolean> disconnect(@RequestParam("ipAddress") String ipAddress) {
-        return R.ok(service.disconnect(ipAddress));
-    }
-
-    /**
-     * 获取设备状态
-     */
-    @ApiOperation("获取设备状态")
-    @GetMapping("/status")
-    public R<Boolean> deviceStatus(@RequestParam("ipAddress") String ipAddress) {
-        return R.ok(service.deviceStatus(ipAddress));
-    }
-
-    /**
-     * 设备重启
-     */
-    @ApiOperation("设备重启")
-    @GetMapping("/restart")
-    public R<Boolean> restart(@RequestParam(required = false,defaultValue = "2") byte index,@RequestParam("ipAddress") String ipAddress) {
-        service.deviceRestart(index,ipAddress);
+    public R<Boolean> disconnect(RemoteLabHardware hardware) {
+        service.stop(hardware);
         return R.ok();
     }
 }

+ 50 - 0
zd-modules/zd-netty/src/main/java/com/zd/netty/enums/ManufacturerTypeEnum.java

@@ -0,0 +1,50 @@
+package com.zd.netty.enums;
+
+import com.zd.netty.sdk.DeJuRFIDService;
+import com.zd.netty.sdk.WuYuanRFIDService;
+import com.zd.netty.service.IService;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+@Getter
+@AllArgsConstructor
+public enum ManufacturerTypeEnum {
+
+    WU_WEI(1,"无源", WuYuanRFIDService.class),
+    DE_JU(2,"惠州德聚",DeJuRFIDService .class);
+
+    private final Integer code;
+    private final String name;
+
+    private final Class<? extends IService> service;
+
+    /**
+     * 根据类型返回具体的SubjectType
+     *
+     * @param value value
+     * @return SubjectType
+     */
+    public static ManufacturerTypeEnum matchByValue(Integer value) {
+        for (ManufacturerTypeEnum item : ManufacturerTypeEnum.values()) {
+            if (item.code.equals(value)) {
+                return item;
+            }
+        }
+        return WU_WEI;
+    }
+
+    /**
+     * 根据描述返回具体的SubjectType
+     *
+     * @param name name
+     * @return SubjectType
+     */
+    public static ManufacturerTypeEnum matchByName(String name) {
+        for (ManufacturerTypeEnum item : ManufacturerTypeEnum.values()) {
+            if (item.name.equals(name)) {
+                return item;
+            }
+        }
+        return WU_WEI;
+    }
+}

+ 1 - 1
zd-modules/zd-netty/src/main/java/com/zd/netty/init/NettyStartListener.java

@@ -51,7 +51,7 @@ public class NettyStartListener implements ApplicationRunner {
                             unitVos.stream()
                                     .filter(u -> StringUtils.hasLength(u.getIpAddress()))
                                     .filter(u -> u.getOperate() == HardwareOperate.OPEN)
-                                    .forEach(u -> fridService.startMonitorChannels(u));
+                                    .forEach(u -> fridService.start(u));
                         } catch (Exception e) {
                             e.fillInStackTrace();
                         }

+ 110 - 0
zd-modules/zd-netty/src/main/java/com/zd/netty/sdk/DeJuRFIDService.java

@@ -0,0 +1,110 @@
+package com.zd.netty.sdk;
+
+import com.gg.reader.api.dal.GClient;
+import com.gg.reader.api.protocol.gx.EnumG;
+import com.gg.reader.api.protocol.gx.MsgBaseInventoryEpc;
+import com.gg.reader.api.protocol.gx.MsgBaseSetPower;
+import com.gg.reader.api.protocol.gx.MsgBaseStop;
+import com.zd.netty.service.ISendService;
+import com.zd.netty.service.IService;
+import com.zd.system.api.domain.InventoryTag;
+import com.zd.system.api.laboratory.domain.RemoteLabHardware;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Hashtable;
+
+@Slf4j
+@Service
+public class DeJuRFIDService implements IService {
+
+    @Autowired
+    private ISendService sendService;
+    static GClient client;
+
+    @Override
+    public void start(RemoteLabHardware hardware) {
+        client = new GClient();
+        String ipAddress = hardware.getIpAddress();
+        Integer port = hardware.getPort();
+        if (client.openTcp(ipAddress+":"+port, 2000)) {
+            // 订阅标签上报事件
+            client.onTagEpcLog = (readName, logBaseEpcInfo) -> {
+                // 回调内部如有阻塞,会影响API正常使用
+                // 标签回调数量较多,请将标签数据先缓存起来再作业务处理
+                if (null != logBaseEpcInfo && 0 == logBaseEpcInfo.getResult()) {
+                    InventoryTag tag=new InventoryTag();
+                    BeanUtils.copyProperties(logBaseEpcInfo,tag);
+                    sendService.send(tag);
+                }
+            };
+            //标签上报结束
+            client.onTagEpcOver = (readName, logBaseEpcOver) -> {
+                if (null != logBaseEpcOver) {
+                    System.out.println("Epc log over.");
+                }
+            };
+            // 停止指令,空闲态
+            MsgBaseStop msgBaseStop = new MsgBaseStop();
+            client.sendSynMsg(msgBaseStop);
+            if (0 == msgBaseStop.getRtCode()) {
+                System.out.println("Stop successful.");
+            } else {
+                System.out.println("Stop error.");
+            }
+
+            // 功率配置, 将4个天线功率都设置为30dBm.
+            //todo 持久化配置,断电保存 ,请勿做重复配置操作,需要频繁配置时,请先查询校验
+            MsgBaseSetPower msgBaseSetPower = new MsgBaseSetPower();
+            Hashtable<Integer, Integer> hashtable = new Hashtable<>();
+            Integer uniformPower = hardware.getUniformPower();
+            hashtable.put(1, uniformPower);
+            hashtable.put(2, uniformPower);
+            hashtable.put(3, uniformPower);
+            hashtable.put(4, uniformPower);
+            msgBaseSetPower.setDicPower(hashtable);
+            client.sendSynMsg(msgBaseSetPower);
+            if (0 == msgBaseSetPower.getRtCode()) {
+                System.out.println("Power configuration successful.");
+            } else {
+                System.out.println("Power configuration error.");
+            }
+
+            // 4个天线读卡, 读取EPC数据区以及TID数据区
+            MsgBaseInventoryEpc msgBaseInventoryEpc = new MsgBaseInventoryEpc();
+            msgBaseInventoryEpc.setAntennaEnable(EnumG.AntennaNo_1 | EnumG.AntennaNo_2 | EnumG.AntennaNo_3 | EnumG.AntennaNo_4);
+            msgBaseInventoryEpc.setInventoryMode(EnumG.InventoryMode_Inventory);
+
+            //ParamEpcReadTid tid = new ParamEpcReadTid();
+            //tid.setMode(EnumG.ParamTidMode_Auto);
+            //tid.setLen(6);
+            //msgBaseInventoryEpc.setReadTid(tid);
+
+            client.sendSynMsg(msgBaseInventoryEpc);
+            if (0 == msgBaseInventoryEpc.getRtCode()) {
+                System.out.println("Inventory epc successful.");
+            } else {
+                System.out.println("Inventory epc error.");
+            }
+
+        } else {
+            System.out.println("Connect failure.");
+        }
+    }
+
+    @Override
+    public void disconnect(RemoteLabHardware hardware) {
+        MsgBaseStop msg = new MsgBaseStop();
+        // 停止读卡,空闲态
+        client.sendSynMsg(msg);
+        if (0 == msg.getRtCode()) {
+            System.out.println("Stop successful.");
+        } else {
+            System.out.println("Stop error.");
+        }
+        System.out.println("Close the connection");
+        client.close();
+    }
+}

+ 236 - 0
zd-modules/zd-netty/src/main/java/com/zd/netty/sdk/WuYuanRFIDService.java

@@ -0,0 +1,236 @@
+package com.zd.netty.sdk;
+
+import com.payne.connect.net.NetworkHandle;
+import com.payne.reader.Reader;
+import com.payne.reader.base.BaseInventory;
+import com.payne.reader.bean.config.AntennaCount;
+import com.payne.reader.bean.config.ProfileId;
+import com.payne.reader.bean.config.Session;
+import com.payne.reader.bean.receive.Failure;
+import com.payne.reader.bean.receive.Success;
+import com.payne.reader.bean.send.*;
+import com.payne.reader.process.ReaderImpl;
+import com.zd.common.core.enums.HardwareOperate;
+import com.zd.common.core.exception.ServiceException;
+import com.zd.netty.base.FridConsumer;
+import com.zd.netty.service.ISendService;
+import com.zd.netty.service.IService;
+import com.zd.system.api.laboratory.RemoteLaboratoryService;
+import com.zd.system.api.laboratory.domain.RemoteLabHardware;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+import javax.annotation.Resource;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+@Slf4j
+@Service
+public class WuYuanRFIDService implements IService {
+
+    private final Map<String, Reader> readerMap = new ConcurrentHashMap<>();
+    private final Map<String, NetworkHandle> handleMap = new ConcurrentHashMap<>();
+    private static final String MSG = "请先连接设备";
+    private static final String SCANNER_MSG = "服务已断开,请检查连接状态正常后重启程序:";
+    @Resource
+    private FridConsumer fridConsumer;
+    @Resource
+    private ISendService sendService;
+    @Resource
+    private RemoteLaboratoryService laboratoryService;
+
+    @Override
+    public void start(RemoteLabHardware hardware) {
+        String ipAddress = hardware.getIpAddress();
+        if (!StringUtils.hasLength(ipAddress)){
+            return;
+        }
+        Integer channels = hardware.getChannels();
+        channels=channels==null?1:channels;
+        Byte sessionIndex = hardware.getSessionIndex();
+        sessionIndex=sessionIndex==null?0:sessionIndex;
+        if (Boolean.FALSE.equals(deviceStatus(hardware))){
+            connect(hardware);
+            setDevice(hardware);
+        }
+
+        Reader reader;
+        if (readerMap.containsKey(ipAddress)) {
+            reader = readerMap.get(ipAddress);
+        } else {
+            throw new ServiceException(MSG);
+        }
+        if (reader == null || !reader.isConnected()) {
+            throw new ServiceException(MSG);
+        }
+        stopMonitor(hardware);
+        Session session = Session.valueOf(sessionIndex);
+        BaseInventory inventory;
+        switch (channels){
+            case 4:
+                inventory=new FastSwitchFourAntennaInventory.Builder().session(session)
+                        .build();
+                break;
+            case 8:
+                inventory=new FastSwitchEightAntennaInventory.Builder().session(session)
+                        .build();
+                break;
+            case 16:
+                inventory=new FastSwitchSixteenAntennaInventory.Builder().session(session)
+                        .build();
+                break;
+            case 1:
+            default:
+                inventory=new FastSwitchSingleAntennaInventory.Builder().session(session)
+                        .build();
+
+        }
+        log.info("============================>" + session);
+
+        Byte index = sessionIndex;
+        InventoryConfig config = new InventoryConfig.Builder()
+                .setInventory(inventory)
+                .setOnInventoryTagSuccess(fridConsumer)
+                .setOnFailure(failure -> errorMsg(failure, index, SCANNER_MSG, hardware))//读取失败
+                .build();
+        reader.setInventoryConfig(config);
+        reader.startInventory(true);//true -- 开启循环调用
+        laboratoryService.update(HardwareOperate.OPEN,ipAddress);
+    }
+
+    @Override
+    public void disconnect(RemoteLabHardware hardware) {
+        Reader reader = null;
+        String ipAddress = hardware.getIpAddress();
+        stopMonitor(hardware);
+        if (readerMap.containsKey(ipAddress)) {
+            reader = readerMap.get(ipAddress);
+        }
+        if (reader != null && reader.isConnected()) {
+            reader.disconnect();
+        }
+
+        handleMap.remove(ipAddress);
+        readerMap.remove(ipAddress);
+    }
+
+    public Boolean deviceStatus(RemoteLabHardware hardware) {
+        Reader reader = null;
+        String ipAddress = hardware.getIpAddress();
+        if (readerMap.containsKey(ipAddress)) {
+            reader = readerMap.get(ipAddress);
+        }
+        return reader != null && reader.isConnected();
+    }
+
+    public void connect(RemoteLabHardware hardware) {
+        Reader reader = null;
+        String host = hardware.getIpAddress();
+        Integer port = hardware.getPort();
+        if (readerMap.containsKey(host)) {
+            reader = readerMap.get(host);
+        }
+        if (reader != null && reader.isConnected()) {
+            throw new ServiceException("设备已连接");
+        }
+        if (reader == null) {
+            reader = ReaderImpl.create(AntennaCount.FOUR_CHANNELS);
+        }
+        NetworkHandle handle;
+        if (handleMap.containsKey(host)) {
+            handle = handleMap.get(host);
+        } else {
+            handle = new NetworkHandle(host, port);
+            handleMap.put(host, handle);
+        }
+        if (reader.connect(handle)) {
+            reader.getFirmwareVersion(version -> log.info("==========================reader1 version:\t" + version.getVersion()),
+                    failure -> errorMsg(failure, (byte) -1, "版本获取异常:", hardware));
+        } else {
+            throw new ServiceException("读写器连接失败");
+        }
+        if (!readerMap.containsKey(host)) {
+            readerMap.put(host, reader);
+        }
+    }
+
+    public void setDevice(RemoteLabHardware hardware) {
+        Reader reader;
+        String ipAddress = hardware.getIpAddress();
+        Integer uniformPower = hardware.getUniformPower();
+        if (readerMap.containsKey(ipAddress)) {
+            reader = readerMap.get(ipAddress);
+        } else {
+            throw new ServiceException(MSG);
+        }
+
+        stopMonitor(hardware);
+        reader.setOutputPowerUniformly(
+                (byte) Integer.parseInt(Integer.toHexString(uniformPower)),
+                true,
+                success -> successMsg(success, "设置读写器的射频输出功率"),
+                failure -> errorMsg(failure, (byte) -1, "设置读写器的射频输出功率失败:", hardware));
+
+        reader.setOutputPower(
+                OutputPowerConfig.outputPower(new PowerFourAntenna.Builder().build()),
+                success -> successMsg(success, "设置每个天线的射频输出功率"),
+                failure -> errorMsg(failure, (byte) -1, "设置每个天线的射频输出功率失败:", hardware));
+
+        reader.setFrequencyRegion(
+                new FreqNormal.Builder().build(),
+                success -> successMsg(success, "设置读写器的工作频率范围"),
+                failure -> errorMsg(failure, (byte) -1, "设置读写器的工作频率范围失败:", hardware));
+
+        reader.setRfLinkProfile(
+                ProfileId.Profile1,
+                success -> successMsg(success, "设置射频链路配置"),
+                failure -> errorMsg(failure, (byte) -1, "设置射频链路配置失败:", hardware));
+
+    }
+
+    private void errorMsg(Failure failure, byte index, String msg, RemoteLabHardware hardware) {
+        byte errorCode = failure.getErrorCode();
+        if (errorCode == -34 && msg.equals(SCANNER_MSG) && index != -1) {
+            deviceRestart(hardware);
+        }
+        if (errorCode == -79) {
+            sendService.sendError(msg + "\t" + failure);
+            stopMonitor(hardware);
+            disconnect(hardware);
+            if (index != -1) {
+                deviceRestart(hardware);
+            }
+        }
+    }
+
+    public void deviceRestart(RemoteLabHardware hardware) {
+        connect(hardware);
+        String ipAddress = hardware.getIpAddress();
+        if (readerMap.containsKey(ipAddress)) {
+            Reader reader = readerMap.get(ipAddress);
+            if (reader.isConnected()) {
+                sendService.sendError("重连成功");
+                start(hardware);
+            }
+            return;
+        }
+        throw new ServiceException("设备未连接");
+    }
+
+    public void stopMonitor(RemoteLabHardware hardware) {
+        Reader reader = null;
+        String ipAddress = hardware.getIpAddress();
+        if (readerMap.containsKey(ipAddress)) {
+            reader = readerMap.get(ipAddress);
+        }
+        if (reader != null && reader.isConnected()) {
+            reader.stopInventory();
+        }
+        laboratoryService.update(HardwareOperate.CLOSE,ipAddress);
+    }
+
+    private void successMsg(Success success, String msg) {
+        log.info("=========================={}:\t {}", msg, success.toString());
+    }
+}

+ 6 - 26
zd-modules/zd-netty/src/main/java/com/zd/netty/service/IFridService.java

@@ -3,35 +3,15 @@ package com.zd.netty.service;
 import com.zd.system.api.laboratory.domain.RemoteLabHardware;
 
 public interface IFridService {
-
-    /**
-     * 链接FRID读写器
-     * @param host FRID读写器IP
-     * @param port 端口号
-     */
-    void connect(String host,Integer port);
-
-    /**
-     * 设置设备运行参数
-     * @return boolean
-     */
-    Boolean setDevice(Integer uniformPower,String ipAddress);
-
-    void startMonitor(byte index, String ipAddress);
-
-    void startMonitorChannels(RemoteLabHardware hardware);
-
     /**
-     * 断开FRID读写
-     * @return boolean
+     * 启动RFID扫描器
+     * @param hardware 设备数据
      */
-    Boolean disconnect(String ipAddress);
+    void start(RemoteLabHardware hardware);
 
     /**
-     * 停止FRID扫描监控
+     * 关闭RFID扫描器
+     * @param hardware  设备数据
      */
-    Boolean stopMonitor(String ipAddress);
-
-    Boolean deviceStatus(String ipAddress);
-    void deviceRestart(byte index, String ipAddress);
+    void stop(RemoteLabHardware hardware);
 }

+ 19 - 0
zd-modules/zd-netty/src/main/java/com/zd/netty/service/IService.java

@@ -0,0 +1,19 @@
+package com.zd.netty.service;
+
+import com.zd.system.api.laboratory.domain.RemoteLabHardware;
+
+/**
+ * RFID接口类
+ */
+public interface IService {
+
+    /**
+     * 启动RFID读写器
+     */
+    void start(RemoteLabHardware hardware);
+
+    /**
+     * 断开RFID读写器
+     */
+    void disconnect(RemoteLabHardware hardware);
+}

+ 9 - 209
zd-modules/zd-netty/src/main/java/com/zd/netty/service/impl/FridServiceImpl.java

@@ -12,9 +12,12 @@ import com.payne.reader.bean.send.*;
 import com.payne.reader.process.ReaderImpl;
 import com.zd.common.core.enums.HardwareOperate;
 import com.zd.common.core.exception.ServiceException;
+import com.zd.common.core.utils.SpringUtils;
 import com.zd.netty.base.FridConsumer;
+import com.zd.netty.enums.ManufacturerTypeEnum;
 import com.zd.netty.service.IFridService;
 import com.zd.netty.service.ISendService;
+import com.zd.netty.service.IService;
 import com.zd.system.api.airbottle.RemoteAirBottleService;
 import com.zd.system.api.laboratory.RemoteLaboratoryService;
 import com.zd.system.api.laboratory.domain.RemoteLabHardware;
@@ -30,221 +33,18 @@ import java.util.concurrent.ConcurrentHashMap;
 @Slf4j
 public class FridServiceImpl implements IFridService {
 
-    private final Map<String, Reader> readerMap = new ConcurrentHashMap<>();
-    private final Map<String, NetworkHandle> handleMap = new ConcurrentHashMap<>();
-    private static final String MSG = "请先连接设备";
-    private static final String SCANNER_MSG = "服务已断开,请检查连接状态正常后重启程序:";
-    @Resource
-    private FridConsumer fridConsumer;
-    @Resource
-    private ISendService sendService;
-    @Resource
-    private RemoteLaboratoryService laboratoryService;
 
-    @Override
-    public void connect(String host, Integer port) {
-        Reader reader = null;
-        if (readerMap.containsKey(host)) {
-            reader = readerMap.get(host);
-        }
-        if (reader != null && reader.isConnected()) {
-            throw new ServiceException("设备已连接");
-        }
-        if (reader == null) {
-            reader = ReaderImpl.create(AntennaCount.FOUR_CHANNELS);
-        }
-        NetworkHandle handle;
-        if (handleMap.containsKey(host)) {
-            handle = handleMap.get(host);
-        } else {
-            handle = new NetworkHandle(host, port);
-            handleMap.put(host, handle);
-        }
-        if (reader.connect(handle)) {
-            reader.getFirmwareVersion(version -> log.info("==========================reader1 version:\t" + version.getVersion()),
-                    failure -> errorMsg(failure, (byte) -1, "版本获取异常:", host));
-        } else {
-            throw new ServiceException("读写器连接失败");
-        }
-        if (!readerMap.containsKey(host)) {
-            readerMap.put(host, reader);
-        }
-    }
-
-    @Override
-    public Boolean setDevice(Integer uniformPower, String ipAddress) {
-        Reader reader;
-        if (readerMap.containsKey(ipAddress)) {
-            reader = readerMap.get(ipAddress);
-        } else {
-            throw new ServiceException(MSG);
-        }
-
-        stopMonitor(ipAddress);
-        reader.setOutputPowerUniformly(
-                (byte) Integer.parseInt(Integer.toHexString(uniformPower)),
-                true,
-                success -> successMsg(success, "设置读写器的射频输出功率"),
-                failure -> errorMsg(failure, (byte) -1, "设置读写器的射频输出功率失败:", ipAddress));
-
-        reader.setOutputPower(
-                OutputPowerConfig.outputPower(new PowerFourAntenna.Builder().build()),
-                success -> successMsg(success, "设置每个天线的射频输出功率"),
-                failure -> errorMsg(failure, (byte) -1, "设置每个天线的射频输出功率失败:", ipAddress));
-
-        reader.setFrequencyRegion(
-                new FreqNormal.Builder().build(),
-                success -> successMsg(success, "设置读写器的工作频率范围"),
-                failure -> errorMsg(failure, (byte) -1, "设置读写器的工作频率范围失败:", ipAddress));
-
-        reader.setRfLinkProfile(
-                ProfileId.Profile1,
-                success -> successMsg(success, "设置射频链路配置"),
-                failure -> errorMsg(failure, (byte) -1, "设置射频链路配置失败:", ipAddress));
-
-        return true;
-    }
-
-    @Override
-    public void startMonitor(byte index, String ipAddress) {
-        RemoteLabHardware hardware = new RemoteLabHardware();
-        hardware.setSessionIndex(index);
-        hardware.setIpAddress(ipAddress);
-        hardware.setChannels(4);
-        startMonitorChannels(hardware);
-    }
-
-    @Override
-    public void startMonitorChannels(RemoteLabHardware hardware) {
-        String ipAddress = hardware.getIpAddress();
-        if (!StringUtils.hasLength(ipAddress)){
-            return;
-        }
-        Integer port = hardware.getPort();
-        port=port==null?4001:port;
-        Integer uniformPower = hardware.getUniformPower();
-        uniformPower=uniformPower==null?33:uniformPower;
-        Integer channels = hardware.getChannels();
-        channels=channels==null?1:channels;
-        Byte sessionIndex = hardware.getSessionIndex();
-        sessionIndex=sessionIndex==null?0:sessionIndex;
-        if (Boolean.FALSE.equals(deviceStatus(ipAddress))){
-            connect(ipAddress,port);
-            setDevice(uniformPower,ipAddress);
-        }
-
-        Reader reader;
-        if (readerMap.containsKey(ipAddress)) {
-            reader = readerMap.get(ipAddress);
-        } else {
-            throw new ServiceException(MSG);
-        }
-        if (reader == null || !reader.isConnected()) {
-            throw new ServiceException(MSG);
-        }
-        stopMonitor(ipAddress);
-        Session session = Session.valueOf(sessionIndex);
-        BaseInventory inventory;
-        switch (channels){
-            case 4:
-                inventory=new FastSwitchFourAntennaInventory.Builder().session(session)
-                        .build();
-                break;
-            case 8:
-                inventory=new FastSwitchEightAntennaInventory.Builder().session(session)
-                        .build();
-                break;
-            case 16:
-                inventory=new FastSwitchSixteenAntennaInventory.Builder().session(session)
-                        .build();
-                break;
-            case 1:
-            default:
-                inventory=new FastSwitchSingleAntennaInventory.Builder().session(session)
-                        .build();
-
-        }
-        log.info("============================>" + session);
-
-        Byte index = sessionIndex;
-        InventoryConfig config = new InventoryConfig.Builder()
-                .setInventory(inventory)
-                .setOnInventoryTagSuccess(fridConsumer)
-                .setOnFailure(failure -> errorMsg(failure, index, SCANNER_MSG, ipAddress))//读取失败
-                .build();
-        reader.setInventoryConfig(config);
-        reader.startInventory(true);//true -- 开启循环调用
-        laboratoryService.update(HardwareOperate.OPEN,ipAddress);
-    }
-
-    private void errorMsg(Failure failure, byte index, String msg, String ipAddress) {
-        byte errorCode = failure.getErrorCode();
-        if (errorCode == -34 && msg.equals(SCANNER_MSG) && index != -1) {
-            deviceRestart(index, ipAddress);
-        }
-        if (errorCode == -79) {
-            sendService.sendError(msg + "\t" + failure);
-            stopMonitor(ipAddress);
-            disconnect(ipAddress);
-            if (index != -1) {
-                deviceRestart(index, ipAddress);
-            }
-        }
-    }
-
-    private void successMsg(Success success, String msg) {
-        log.info("=========================={}:\t {}", msg, success.toString());
-    }
-
-    @Override
-    public Boolean disconnect(String ipAddress) {
-        Reader reader = null;
-        stopMonitor(ipAddress);
-        if (readerMap.containsKey(ipAddress)) {
-            reader = readerMap.get(ipAddress);
-        }
-        if (reader != null && reader.isConnected()) {
-            reader.disconnect();
-        }
-
-        handleMap.remove(ipAddress);
-        readerMap.remove(ipAddress);
-        return true;
-    }
-
-    @Override
-    public Boolean stopMonitor(String ipAddress) {
-        Reader reader = null;
-        if (readerMap.containsKey(ipAddress)) {
-            reader = readerMap.get(ipAddress);
-        }
-        if (reader != null && reader.isConnected()) {
-            reader.stopInventory();
-        }
-        laboratoryService.update(HardwareOperate.CLOSE,ipAddress);
-        return true;
+    private IService rfidService(Integer type) {
+        return SpringUtils.getBean(ManufacturerTypeEnum.matchByValue(type).getService());
     }
 
     @Override
-    public Boolean deviceStatus(String ipAddress) {
-        Reader reader = null;
-        if (readerMap.containsKey(ipAddress)) {
-            reader = readerMap.get(ipAddress);
-        }
-        return reader != null && reader.isConnected();
+    public void start(RemoteLabHardware hardware) {
+        rfidService(hardware.getManufacturerType()).start(hardware);
     }
 
     @Override
-    public void deviceRestart(byte index, String ipAddress) {
-        connect(ipAddress, 4001);
-        if (readerMap.containsKey(ipAddress)) {
-            Reader reader = readerMap.get(ipAddress);
-            if (reader.isConnected()) {
-                sendService.sendError("重连成功");
-                startMonitor(index, ipAddress);
-            }
-            return;
-        }
-        throw new ServiceException("设备未连接");
+    public void stop(RemoteLabHardware hardware) {
+        rfidService(hardware.getManufacturerType()).disconnect(hardware);
     }
 }

BIN
zd-modules/zd-netty/src/main/resources/libs/reader.jar