Explorar el Código

RFID模块迁移,重构

hanzhiwei hace 3 años
padre
commit
94f3c93433
Se han modificado 39 ficheros con 1893 adiciones y 462 borrados
  1. 1 1
      ArcFace64.dat
  2. 13 0
      pom.xml
  3. 197 0
      zd-api/zd-algorithm-api/src/main/java/com/zd/algorithm/api/rfid/domain/entity/HardwareRfid.java
  4. 149 0
      zd-api/zd-algorithm-api/src/main/java/com/zd/algorithm/api/rfid/domain/vo/HardwareRfidVo.java
  5. 7 7
      zd-api/zd-algorithm-api/src/main/java/com/zd/algorithm/api/rfid/feign/RemoteRfidService.java
  6. 4 4
      zd-api/zd-algorithm-api/src/main/java/com/zd/algorithm/api/rfid/feign/fallback/RemoteRfidFallbackFactory.java
  7. 13 0
      zd-common/common-core/src/main/java/com/zd/common/core/web/controller/BaseController.java
  8. 5 0
      zd-model/pom.xml
  9. 194 0
      zd-model/src/main/java/com/zd/model/entity/HardwareRfidDto.java
  10. 5 1
      zd-model/src/main/java/com/zd/model/entity/InventoryTag.java
  11. 29 0
      zd-model/src/main/java/com/zd/model/enums/DeviceOnOffEnum.java
  12. 30 0
      zd-model/src/main/java/com/zd/model/enums/DeviceStatusEnum.java
  13. 2 2
      zd-modules/zd-airbottle/src/main/java/com/zd/airbottle/service/IAlarmRecordService.java
  14. 7 6
      zd-modules/zd-airbottle/src/main/java/com/zd/airbottle/service/impl/AlarmRecordServiceImpl.java
  15. 5 0
      zd-modules/zd-algorithm/pom.xml
  16. 4 1
      zd-modules/zd-algorithm/src/main/java/com/zd/alg/AlgorithmApplication.java
  17. 29 0
      zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/base/MyBatisPlusConfig.java
  18. 1 1
      zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/base/RfidConsumer.java
  19. 96 0
      zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/controller/HardwareRfidController.java
  20. 16 8
      zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/controller/RfidDeviceController.java
  21. 7 7
      zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/enums/ManufacturerTypeEnum.java
  22. 13 21
      zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/init/RfidStartListener.java
  23. 19 0
      zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/mapper/HardwareRfidMapper.java
  24. 35 35
      zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/sdk/DeJuRFIDClientImpl.java
  25. 57 52
      zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/sdk/DeJuRFIDServerImpl.java
  26. 430 0
      zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/sdk/RfidClientImpl.java
  27. 249 249
      zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/sdk/WuYuanRFIDServiceImpl.java
  28. 47 0
      zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/service/HardwareRfidService.java
  29. 8 5
      zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/service/IRfidService.java
  30. 2 1
      zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/service/ISendService.java
  31. 14 10
      zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/service/IService.java
  32. 103 0
      zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/service/impl/HardwareRfidServiceImpl.java
  33. 14 16
      zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/service/impl/RfidServiceImpl.java
  34. 14 19
      zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/service/impl/SendServiceImpl.java
  35. 56 0
      zd-modules/zd-algorithm/src/main/resources/mapper/rfid/HardwareRfidMapper.xml
  36. 7 6
      zd-modules/zd-bottle-parent/zd-bottle/src/main/java/com/zd/bottle/service/impl/AlarmRecordServiceImpl.java
  37. 4 4
      zd-modules/zd-chemical/src/main/java/com/zd/chemical/service/impl/HxpStockServiceImpl.java
  38. 6 5
      zd-modules/zd-modules-laboratory/src/main/java/com/zd/laboratory/controller/LabHardwareController.java
  39. 1 1
      zd-modules/zd-modules-system/src/main/resources/mapper/system/SysUserMapper.xml

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 1 - 1
ArcFace64.dat


+ 13 - 0
pom.xml

@@ -52,6 +52,7 @@
         <face.version>3.0.0.0</face.version>
         <bce.version>0.10.154</bce.version>
         <pinyin4j.version>2.5.1</pinyin4j.version>
+        <mybatis-plus.version>3.5.2</mybatis-plus.version>
     </properties>
 
     <!-- 依赖声明 -->
@@ -112,6 +113,18 @@
                 <version>${spring-boot.mybatis}</version>
             </dependency>
 
+            <!-- mybatis-plus 依赖配置 -->
+            <dependency>
+                <groupId>com.baomidou</groupId>
+                <artifactId>mybatis-plus-boot-starter</artifactId>
+                <version>${mybatis-plus.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>com.baomidou</groupId>
+                <artifactId>mybatis-plus-annotation</artifactId>
+                <version>${mybatis-plus.version}</version>
+            </dependency>
+
             <!-- Swagger 依赖配置 -->
             <dependency>
                 <groupId>io.swagger</groupId>

+ 197 - 0
zd-api/zd-algorithm-api/src/main/java/com/zd/algorithm/api/rfid/domain/entity/HardwareRfid.java

@@ -0,0 +1,197 @@
+package com.zd.algorithm.api.rfid.domain.entity;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+/**
+ * @创建人 hzw
+ * @描述 RFID硬件表
+ * @创建时间 2022/11/15
+ */
+@ApiModel(value = "RFID硬件表实体类")
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class HardwareRfid implements Serializable {
+    /**
+     * 主键id
+     */
+    @JsonSerialize(using = ToStringSerializer.class)
+    @ApiModelProperty(value = "主键id")
+    private Long id;
+
+    /**
+     * 设备名称
+     */
+    @ApiModelProperty(value = "设备名称")
+    private String deviceName;
+
+    /**
+     * 设备类型(7,RFID识别器)
+     */
+    @ApiModelProperty(value = "设备类型(7,RFID识别器)")
+    private Integer deviceType;
+
+    /**
+     * 供应商类型
+     */
+    @ApiModelProperty(value = "供应商类型")
+    private Integer manufacturerType;
+
+    /**
+     * 设备编码
+     */
+    @ApiModelProperty(value = "设备编码")
+    private String hardwareNum;
+
+    /**
+     * ip地址
+     */
+    @ApiModelProperty(value = "ip地址")
+    private String ipAddress;
+
+    /**
+     * 设备端口号
+     */
+    @ApiModelProperty(value = "设备端口号")
+    private Integer port;
+
+    /**
+     * 天线功率
+     */
+    @ApiModelProperty(value = "天线功率")
+    private String uniformPower;
+
+    /**
+     * 设备推送频率,0最大,2最小
+     */
+    @ApiModelProperty(value = "设备推送频率,0最大,2最小")
+    private Integer sessionIndex;
+
+    /**
+     * 1通道、4通道、8通道、16通道
+     */
+    @ApiModelProperty(value = "1通道、4通道、8通道、16通道")
+    private Integer channels;
+
+    /**
+     * 设备启用停用(0是停用,1是启用)
+     */
+    @ApiModelProperty(value = "设备启用停用(0是停用,1是启用)")
+    private Integer onOff;
+
+    /**
+     * 设备状态(0离线,1在线,2异常)
+     */
+    @ApiModelProperty(value = "设备状态(0离线,1在线,2异常)")
+    private Integer deviceStatus;
+
+    /**
+     * 所属实验室id
+     */
+    @ApiModelProperty(value = "所属实验室id")
+    private Long subjectId;
+
+    /**
+     * 部门id
+     */
+    @ApiModelProperty(value = "部门id")
+    private Long deptId;
+
+    /**
+     * 部门名称
+     */
+    @ApiModelProperty(value = "部门名称")
+    private String deptName;
+
+    /**
+     * 创建人(用于数据权限)
+     */
+    @ApiModelProperty(value = "创建人(用于数据权限)")
+    private Long userId;
+
+    /**
+     * 创建人
+     */
+    @ApiModelProperty(value = "创建人")
+    private String createBy;
+
+    /**
+     * 创建时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "创建时间")
+    private LocalDateTime createTime;
+
+    /**
+     * 修改人
+     */
+    @ApiModelProperty(value = "修改人")
+    private String updateBy;
+
+    /**
+     * 修改时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "修改时间")
+    private LocalDateTime updateTime;
+
+    /**
+     * 备注
+     */
+    @ApiModelProperty(value = "备注")
+    private String remark;
+
+    private static final long serialVersionUID = 1L;
+
+    public static final String COL_ID = "id";
+
+    public static final String COL_DEVICE_NAME = "device_name";
+
+    public static final String COL_DEVICE_TYPE = "device_type";
+
+    public static final String COL_MANUFACTURER_TYPE = "manufacturer_type";
+
+    public static final String COL_HARDWARE_NUM = "hardware_num";
+
+    public static final String COL_IP_ADDRESS = "ip_address";
+
+    public static final String COL_PORT = "port";
+
+    public static final String COL_UNIFORM_POWER = "uniform_power";
+
+    public static final String COL_SESSION_INDEX = "session_index";
+
+    public static final String COL_CHANNELS = "channels";
+
+    public static final String COL_SWITCH = "switch";
+
+    public static final String COL_DEVICE_STATUS = "device_status";
+
+    public static final String COL_SUBJECT_ID = "subject_id";
+
+    public static final String COL_DEPT_ID = "dept_id";
+
+    public static final String COL_DEPT_NAME = "dept_name";
+
+    public static final String COL_USER_ID = "user_id";
+
+    public static final String COL_CREATE_BY = "create_by";
+
+    public static final String COL_CREATE_TIME = "create_time";
+
+    public static final String COL_UPDATE_BY = "update_by";
+
+    public static final String COL_UPDATE_TIME = "update_time";
+
+    public static final String COL_REMARK = "remark";
+}

+ 149 - 0
zd-api/zd-algorithm-api/src/main/java/com/zd/algorithm/api/rfid/domain/vo/HardwareRfidVo.java

@@ -0,0 +1,149 @@
+package com.zd.algorithm.api.rfid.domain.vo;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
+/**
+ * @创建人 hzw
+ * @描述
+ * @创建时间 2022/11/15
+ */
+@Data
+public class HardwareRfidVo {
+
+    /**
+     * 主键id
+     */
+    @JsonSerialize(using = ToStringSerializer.class)
+    @ApiModelProperty(value = "主键id")
+    private Long id;
+    /**
+     * 设备名称
+     */
+//    @NotBlank(message = "设备名称不能为空!")
+    @ApiModelProperty(value = "设备名称")
+    private String deviceName;
+
+    /**
+     * 设备类型(7,RFID识别器)
+     */
+    @ApiModelProperty(value = "设备类型(7,RFID识别器)")
+    private Integer deviceType;
+
+    /**
+     * 供应商类型
+     */
+    @ApiModelProperty(value = "供应商类型")
+    private Integer manufacturerType;
+
+    /**
+     * 设备编码
+     */
+    @NotBlank(message = "设备编码不能为空!")
+    @ApiModelProperty(value = "设备编码")
+    private String hardwareNum;
+
+    /**
+     * ip地址
+     */
+    @NotBlank(message = "ip地址不能为空!")
+    @ApiModelProperty(value = "ip地址")
+    private String ipAddress;
+
+    /**
+     * 设备端口号
+     */
+    @ApiModelProperty(value = "设备端口号")
+    private Integer port;
+
+    /**
+     * 天线功率
+     */
+    @ApiModelProperty(value = "天线功率")
+    private String uniformPower;
+
+    /**
+     * 设备推送频率,0最大,2最小
+     */
+    @ApiModelProperty(value = "设备推送频率,0最大,2最小")
+    private Integer sessionIndex;
+
+    /**
+     * 1通道、4通道、8通道、16通道
+     */
+    @ApiModelProperty(value = "1通道、4通道、8通道、16通道")
+    private Integer channels;
+
+    /**
+     * 设备启用停用(0是停用,1是启用)
+     */
+    @ApiModelProperty(value = "设备启用停用(0是停用,1是启用)")
+    private Integer onOff;
+
+    /**
+     * 设备状态(0离线,1在线,2异常)
+     */
+    @ApiModelProperty(value = "设备状态(0离线,1在线,2异常)")
+    private Integer deviceStatus;
+
+    /**
+     * 所属实验室id
+     */
+    @NotNull(message = "所属实验室id不能为空!")
+    @ApiModelProperty(value = "所属实验室id")
+    private Long subjectId;
+
+    /**
+     * 部门id
+     */
+    @ApiModelProperty(value = "部门id")
+    private String deptId;
+
+    /**
+     * 部门名称
+     */
+    @ApiModelProperty(value = "部门名称")
+    private String deptName;
+
+    /**
+     * 创建人(用于数据权限)
+     */
+    @ApiModelProperty(value = "创建人(用于数据权限)")
+    private Long userId;
+
+    /**
+     * 创建人
+     */
+    @ApiModelProperty(value = "创建人")
+    private String createBy;
+
+    /**
+     * 备注
+     */
+    @ApiModelProperty(value = "备注")
+    private String remark;
+
+    /**
+     * 查询参数
+     */
+    @ApiModelProperty(value = "查询参数")
+    private String searchValue;
+
+    /**
+     * 当前页
+     */
+    @ApiModelProperty(value = "当前页")
+    private Integer pageNum;
+
+    /**
+     * 每页记录条数
+     */
+    @ApiModelProperty(value = "每页记录条数")
+    private Integer pageSize;
+
+}

+ 7 - 7
zd-api/zd-algorithm-api/src/main/java/com/zd/algorithm/api/rfid/feign/RemoteRfidService.java

@@ -3,7 +3,7 @@ package com.zd.algorithm.api.rfid.feign;
 import com.zd.algorithm.api.rfid.feign.fallback.RemoteRfidFallbackFactory;
 import com.zd.model.constant.ApplicationConstants;
 import com.zd.model.domain.R;
-import com.zd.model.entity.RemoteLabHardware;
+import com.zd.model.entity.HardwareRfidDto;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -16,29 +16,29 @@ import org.springframework.web.bind.annotation.RequestBody;
 public interface RemoteRfidService {
     /**
      * 断开设备连接
-     * @param hardware 设备对象
+     * @param hardwareRfidDto 设备对象
      * @return 结果
      */
     @ApiOperation("断开设备连接")
     @PostMapping("/rfid/disconnect")
-    R<Boolean> disconnect(@RequestBody RemoteLabHardware hardware);
+    R<Boolean> disconnect(@RequestBody HardwareRfidDto hardwareRfidDto);
 
     /**
      * 信道启动RFID扫描监控
-     * @param hardware 设备对象
+     * @param hardwareRfidDto 设备对象
      * @return 结果
      */
     @ApiOperation("信道启动RFID扫描监控")
     @PostMapping("/rfid/startMonitorChannels")
-    R<Boolean> startMonitorChannels(@RequestBody RemoteLabHardware hardware);
+    R<Boolean> startMonitorChannels(@RequestBody HardwareRfidDto hardwareRfidDto);
 
     /**
      * 开启设备警报
-     * @param hardware 设备参数
+     * @param hardwareRfidDto 设备参数
      * @return R
      */
     @ApiOperation("开启设备警报")
     @PostMapping("/rfid/alarm")
-    R<Boolean> alarm(@RequestBody RemoteLabHardware hardware);
+    R<Boolean> alarm(@RequestBody HardwareRfidDto hardwareRfidDto);
 
 }

+ 4 - 4
zd-api/zd-algorithm-api/src/main/java/com/zd/algorithm/api/rfid/feign/fallback/RemoteRfidFallbackFactory.java

@@ -2,7 +2,7 @@ package com.zd.algorithm.api.rfid.feign.fallback;
 
 import com.zd.algorithm.api.rfid.feign.RemoteRfidService;
 import com.zd.model.domain.R;
-import com.zd.model.entity.RemoteLabHardware;
+import com.zd.model.entity.HardwareRfidDto;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.cloud.openfeign.FallbackFactory;
@@ -18,17 +18,17 @@ public class RemoteRfidFallbackFactory implements FallbackFactory<RemoteRfidServ
         log.error("Rfid门禁服务调用失败:{}", throwable.getMessage());
         return new RemoteRfidService() {
             @Override
-            public R<Boolean> disconnect(RemoteLabHardware hardware) {
+            public R<Boolean> disconnect(HardwareRfidDto hardwareRfidDto) {
                 return  R.fail("停止扫描失败:" + throwable.getMessage());
             }
 
             @Override
-            public R<Boolean> startMonitorChannels(RemoteLabHardware hardware) {
+            public R<Boolean> startMonitorChannels(HardwareRfidDto hardwareRfidDto) {
                 return  R.fail("启动扫描失败:" + throwable.getMessage());
             }
 
             @Override
-            public R<Boolean> alarm(RemoteLabHardware hardware) {
+            public R<Boolean> alarm(HardwareRfidDto hardwareRfidDto) {
                 return  R.fail("开启警报失败:" + throwable.getMessage());
             }
         };

+ 13 - 0
zd-common/common-core/src/main/java/com/zd/common/core/web/controller/BaseController.java

@@ -96,6 +96,19 @@ public class BaseController<T> {
         return rspData;
     }
 
+    /**
+     * 响应请求分页数据 传入总数
+     */
+    @SuppressWarnings({"rawtypes", "unchecked"})
+    protected TableDataInfo<T> getDataTable(List<? extends T> list,Long total) {
+        TableDataInfo<T> rspData = new TableDataInfo();
+        rspData.setCode(HttpStatus.SUCCESS);
+        rspData.setRows(list);
+        rspData.setMsg("查询成功");
+        rspData.setTotal(total);
+        return rspData;
+    }
+
 
     /**
      * 响应请求分页数据

+ 5 - 0
zd-model/pom.xml

@@ -71,5 +71,10 @@
             <groupId>com.github.pagehelper</groupId>
             <artifactId>pagehelper-spring-boot-starter</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-annotation</artifactId>
+        </dependency>
     </dependencies>
 </project>

+ 194 - 0
zd-model/src/main/java/com/zd/model/entity/HardwareRfidDto.java

@@ -0,0 +1,194 @@
+package com.zd.model.entity;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+/**
+ * @创建人 hzw
+ * @描述 RFID硬件表
+ * @创建时间 2022/11/15
+ */
+@ApiModel(value = "RFID硬件表实体类")
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class HardwareRfidDto implements Serializable {
+    /**
+     * 主键id
+     */
+    @ApiModelProperty(value = "主键id")
+    private Long id;
+
+    /**
+     * 设备名称
+     */
+    @ApiModelProperty(value = "设备名称")
+    private String deviceName;
+
+    /**
+     * 设备类型(7,RFID识别器)
+     */
+    @ApiModelProperty(value = "设备类型(7,RFID识别器)")
+    private Integer deviceType;
+
+    /**
+     * 供应商类型
+     */
+    @ApiModelProperty(value = "供应商类型")
+    private Integer manufacturerType;
+
+    /**
+     * 设备编码
+     */
+    @ApiModelProperty(value = "设备编码")
+    private String hardwareNum;
+
+    /**
+     * ip地址
+     */
+    @ApiModelProperty(value = "ip地址")
+    private String ipAddress;
+
+    /**
+     * 设备端口号
+     */
+    @ApiModelProperty(value = "设备端口号")
+    private Integer port;
+
+    /**
+     * 天线功率
+     */
+    @ApiModelProperty(value = "天线功率")
+    private String uniformPower;
+
+    /**
+     * 设备推送频率,0最大,2最小
+     */
+    @ApiModelProperty(value = "设备推送频率,0最大,2最小")
+    private Boolean sessionIndex;
+
+    /**
+     * 1通道、4通道、8通道、16通道
+     */
+    @ApiModelProperty(value = "1通道、4通道、8通道、16通道")
+    private Integer channels;
+
+    /**
+     * 设备启用停用(0是停用,1是启用)
+     */
+    @ApiModelProperty(value = "设备启用停用(0是停用,1是启用)")
+    private Integer onOff;
+
+    /**
+     * 设备状态(0离线,1在线,2异常)
+     */
+    @ApiModelProperty(value = "设备状态(0离线,1在线,2异常)")
+    private Integer deviceStatus;
+
+    /**
+     * 所属实验室id
+     */
+    @ApiModelProperty(value = "所属实验室id")
+    private Long subjectId;
+
+    /**
+     * 部门id
+     */
+    @ApiModelProperty(value = "部门id")
+    private Long deptId;
+
+    /**
+     * 部门名称
+     */
+    @ApiModelProperty(value = "部门名称")
+    private String deptName;
+
+    /**
+     * 创建人(用于数据权限)
+     */
+    @ApiModelProperty(value = "创建人(用于数据权限)")
+    private Long userId;
+
+    /**
+     * 创建人
+     */
+    @ApiModelProperty(value = "创建人")
+    private String createBy;
+
+    /**
+     * 创建时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "创建时间")
+    private LocalDateTime createTime;
+
+    /**
+     * 修改人
+     */
+    @ApiModelProperty(value = "修改人")
+    private String updateBy;
+
+    /**
+     * 修改时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "修改时间")
+    private LocalDateTime updateTime;
+
+    /**
+     * 备注
+     */
+    @ApiModelProperty(value = "备注")
+    private String remark;
+
+    private static final long serialVersionUID = 1L;
+
+    public static final String COL_ID = "id";
+
+    public static final String COL_DEVICE_NAME = "device_name";
+
+    public static final String COL_DEVICE_TYPE = "device_type";
+
+    public static final String COL_MANUFACTURER_TYPE = "manufacturer_type";
+
+    public static final String COL_HARDWARE_NUM = "hardware_num";
+
+    public static final String COL_IP_ADDRESS = "ip_address";
+
+    public static final String COL_PORT = "port";
+
+    public static final String COL_UNIFORM_POWER = "uniform_power";
+
+    public static final String COL_SESSION_INDEX = "session_index";
+
+    public static final String COL_CHANNELS = "channels";
+
+    public static final String COL_SWITCH = "switch";
+
+    public static final String COL_DEVICE_STATUS = "device_status";
+
+    public static final String COL_SUBJECT_ID = "subject_id";
+
+    public static final String COL_DEPT_ID = "dept_id";
+
+    public static final String COL_DEPT_NAME = "dept_name";
+
+    public static final String COL_USER_ID = "user_id";
+
+    public static final String COL_CREATE_BY = "create_by";
+
+    public static final String COL_CREATE_TIME = "create_time";
+
+    public static final String COL_UPDATE_BY = "update_by";
+
+    public static final String COL_UPDATE_TIME = "update_time";
+
+    public static final String COL_REMARK = "remark";
+}

+ 5 - 1
zd-model/src/main/java/com/zd/model/entity/InventoryTag.java

@@ -39,5 +39,9 @@ public class InventoryTag {
     /**
      * 硬件信息
      */
-    private RemoteLabHardware remoteLabHardware;
+//    private RemoteLabHardware remoteLabHardware;
+    /**
+     * rfid新硬件信息
+     */
+    private HardwareRfidDto hardwareRfidDto;
 }

+ 29 - 0
zd-model/src/main/java/com/zd/model/enums/DeviceOnOffEnum.java

@@ -0,0 +1,29 @@
+package com.zd.model.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @Description 公共设备开关枚举类
+ * @Author hzw
+ * @Date 2022/11/17 16:45
+ * @Version 2.0
+ */
+@Getter
+@AllArgsConstructor
+public enum DeviceOnOffEnum {
+    OFF(0, "关闭"),
+    ON(1,"打开");
+
+    private  Integer code;
+    private  String name;
+
+    public static String getValue(Integer code) {
+        for (DeviceOnOffEnum deviceOnOffEnum : values()) {
+            if (deviceOnOffEnum.getCode().equals(code)) {
+                return deviceOnOffEnum.getName();
+            }
+        }
+        return null;
+    }
+}

+ 30 - 0
zd-model/src/main/java/com/zd/model/enums/DeviceStatusEnum.java

@@ -0,0 +1,30 @@
+package com.zd.model.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @author hzw
+ * @描述 设备状态枚举类
+ * @创建时间 2022/11/16
+ */
+
+@Getter
+@AllArgsConstructor
+public enum DeviceStatusEnum {
+    OFF_LINE(0, "离线"),
+    ON_LINE(1, "在线"),
+    EXCEPTION(2, "异常");
+
+    private Integer code;
+    private String name;
+
+    public static String getValue(Integer code) {
+        for (DeviceStatusEnum deviceStatusEnum : values()) {
+            if (deviceStatusEnum.getCode().equals(code)) {
+                return deviceStatusEnum.getName();
+            }
+        }
+        return null;
+    }
+}

+ 2 - 2
zd-modules/zd-airbottle/src/main/java/com/zd/airbottle/service/IAlarmRecordService.java

@@ -3,8 +3,8 @@ package com.zd.airbottle.service;
 import com.zd.airbottle.domain.AlarmRecord;
 import com.zd.airbottle.domain.vo.AlarmRecordVo;
 import com.zd.airbottle.domain.vo.BottleStorageInfoVo;
+import com.zd.model.entity.HardwareRfidDto;
 import com.zd.model.entity.InventoryTag;
-import com.zd.model.entity.RemoteLabHardware;
 
 import java.util.List;
 
@@ -36,7 +36,7 @@ public interface IAlarmRecordService {
      * @param hardware RFID设备信息
      * @return 结果
      */
-    int insertAlarmRecord(AlarmRecord alarmRecord, RemoteLabHardware hardware);
+    int insertAlarmRecord(AlarmRecord alarmRecord, HardwareRfidDto hardwareRfidDto);
 
     /**
      * 获取拓展信息

+ 7 - 6
zd-modules/zd-airbottle/src/main/java/com/zd/airbottle/service/impl/AlarmRecordServiceImpl.java

@@ -23,6 +23,7 @@ import com.zd.laboratory.api.feign.RemoteSubQueryService;
 import com.zd.model.constant.HttpStatus;
 import com.zd.model.domain.AjaxResult;
 import com.zd.model.domain.R;
+import com.zd.model.entity.HardwareRfidDto;
 import com.zd.model.entity.InventoryTag;
 import com.zd.model.entity.RemoteLabHardware;
 import com.zd.model.entity.TemplateResult;
@@ -92,18 +93,18 @@ public class AlarmRecordServiceImpl implements IAlarmRecordService {
      * 默认新增气瓶报警记录
      *
      * @param alarmRecord 报警记录
-     * @param hardware RFID 设备数据
+     * @param hardwareRfidDto RFID 设备数据
      * @return 结果
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public int insertAlarmRecord(AlarmRecord alarmRecord, RemoteLabHardware hardware) {
+    public int insertAlarmRecord(AlarmRecord alarmRecord, HardwareRfidDto hardwareRfidDto) {
         String electronicTag = alarmRecord.getElectronicTag();
         QpBottleStorageRVo storageRVo = storageService.getByElectronicTag(electronicTag);
         if (storageRVo != null) {
-            if (hardware!=null){
+            if (hardwareRfidDto!=null){
                 //RFID设备报警
-                R<Boolean> alarm = remoteRfidService.alarm(hardware);
+                R<Boolean> alarm = remoteRfidService.alarm(hardwareRfidDto);
                 log.info("==================>{},{}",alarm.getCode(),alarm.getMsg());
             }
             Long id = storageRVo.getId();
@@ -121,7 +122,7 @@ public class AlarmRecordServiceImpl implements IAlarmRecordService {
                     .setProductType(1);
             return alarmRecordMapper.insertAlarmRecord(alarmRecord);
         }else {
-            if (hardware!=null){
+            if (hardwareRfidDto!=null){
                 log.info("==================>{},{}",alarmRecord.getElectronicTag(),"标签无数据");
             }
         }
@@ -245,7 +246,7 @@ public class AlarmRecordServiceImpl implements IAlarmRecordService {
     @Override
     @Transactional(rollbackFor = Exception.class)
     public boolean remoteAdd(InventoryTag tag) {
-        return insertAlarmRecord(new AlarmRecord().setElectronicTag(tag.getEpc()),tag.getRemoteLabHardware())==1;
+        return insertAlarmRecord(new AlarmRecord().setElectronicTag(tag.getEpc()),tag.getHardwareRfidDto())==1;
     }
 
     @Override

+ 5 - 0
zd-modules/zd-algorithm/pom.xml

@@ -58,6 +58,11 @@
             <artifactId>okhttp</artifactId>
             <version>3.10.0</version>
         </dependency>
+        <!-- mybatis plus -->
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-boot-starter</artifactId>
+        </dependency>
 
         <!-- 人脸对接  -->
         <dependency>

+ 4 - 1
zd-modules/zd-algorithm/src/main/java/com/zd/alg/AlgorithmApplication.java

@@ -9,6 +9,7 @@ import com.zd.common.core.launch.ZdStartApplication;
 import com.zd.common.mqtt.model.MqttProperties;
 import com.zd.model.constant.ApplicationConstants;
 import com.zd.model.constant.BaseConstants;
+import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.boot.web.servlet.ServletComponentScan;
@@ -22,12 +23,14 @@ import org.springframework.context.ConfigurableApplicationContext;
 @EnableZdFeignClients
 @SpringBootApplication(scanBasePackages = BaseConstants.BASE_PACKAGE)
 @EnableConfigurationProperties({MqttProperties.class, AlgorithmYml.class, FireProperties.class})
+@MapperScan(value = {"com.zd.**.mapper"})
 public class AlgorithmApplication {
 
     private static String[] args;
     private static ConfigurableApplicationContext context;
+
     public static void main(String[] args) {
-        AlgorithmApplication.args=args;
+        AlgorithmApplication.args = args;
         AlgorithmApplication.context = ZdStartApplication.run(ApplicationConstants.ALGORITHM_SERVICE, AlgorithmApplication.class, args);
     }
 

+ 29 - 0
zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/base/MyBatisPlusConfig.java

@@ -0,0 +1,29 @@
+package com.zd.alg.rfid.base;
+
+import com.baomidou.mybatisplus.annotation.DbType;
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+@MapperScan("com.cn.springbootmybatisplus06.mapper")
+@EnableTransactionManagement//自动管理事务
+@Configuration // 配置类
+public class MyBatisPlusConfig {
+
+    /**
+     * 新版
+     */
+    @Bean
+    public MybatisPlusInterceptor mybatisPlusInterceptor() {
+        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
+        //配置乐观锁
+        mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
+        //配置分页插件
+        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
+        return mybatisPlusInterceptor;
+    }
+}

+ 1 - 1
zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/base/RfidConsumer.java

@@ -23,7 +23,7 @@ public class RfidConsumer implements Consumer<InventoryTag> {
     public void accept(InventoryTag tag) {
         try {
             tag.setEpc(tag.getEpc().replace(" ", ""));
-            com.zd.model.entity.InventoryTag  inventoryTag = new com.zd.model.entity.InventoryTag ();
+            com.zd.model.entity.InventoryTag inventoryTag = new com.zd.model.entity.InventoryTag();
             BeanUtils.copyProperties(tag,inventoryTag);
             sendService.send(inventoryTag);
         } catch (BeansException e) {

+ 96 - 0
zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/controller/HardwareRfidController.java

@@ -0,0 +1,96 @@
+package com.zd.alg.rfid.controller;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.zd.alg.rfid.service.HardwareRfidService;
+import com.zd.algorithm.api.rfid.domain.entity.HardwareRfid;
+import com.zd.algorithm.api.rfid.domain.vo.HardwareRfidVo;
+import com.zd.common.core.annotation.Log;
+import com.zd.common.core.annotation.PreAuthorize;
+import com.zd.common.core.log.BusinessType;
+import com.zd.common.core.utils.BeanUtils;
+import com.zd.common.core.web.controller.BaseController;
+import com.zd.model.domain.ResultData;
+import com.zd.model.domain.per.PerFun;
+import com.zd.model.domain.per.PerPrefix;
+import com.zd.model.page.TableDataInfo;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * @author: hzw
+ * @date: 2022/11/15 17:47
+ */
+@Api(tags = "RFID硬件信息")
+@RestController
+@RequestMapping("/hardwareRfid")
+public class HardwareRfidController extends BaseController<HardwareRfid> {
+
+    @Autowired
+    private HardwareRfidService hardwareRfidService;
+
+
+    /**
+     * 新增RFID硬件信息
+     */
+    @Log(title = "新增RFID硬件", businessType = BusinessType.INSERT)
+    @ApiOperation("新增RFID硬件")
+    @PreAuthorize(hasAnyPermi = {PerPrefix.LABORATORY_HARDWARE7 + PerFun.ADD})
+    @PostMapping("/save")
+    public ResultData save(@Validated @RequestBody HardwareRfidVo hardwareRfidVo) {
+        HardwareRfid hardwareRfid = new HardwareRfid();
+        BeanUtils.copyProperties(hardwareRfidVo, hardwareRfid);
+        return hardwareRfidService.saveHardwareRfid(hardwareRfid);
+    }
+
+    /**
+     * 修改RFID硬件信息
+     */
+    @Log(title = "修改RFID硬件", businessType = BusinessType.UPDATE)
+    @ApiOperation("修改RFID硬件")
+    @PreAuthorize(hasAnyPermi = {PerPrefix.LABORATORY_HARDWARE7 + PerFun.EDIT})
+    @PutMapping("/update")
+    public ResultData update(@Validated @RequestBody HardwareRfidVo hardwareRfidVo) {
+        HardwareRfid hardwareRfid = new HardwareRfid();
+        BeanUtils.copyProperties(hardwareRfidVo, hardwareRfid);
+        return hardwareRfidService.updateHardwareRfid(hardwareRfid);
+    }
+
+    /**
+     * 删除RFID硬件信息
+     */
+    @Log(title = "删除RFID硬件", businessType = BusinessType.DELETE)
+    @ApiOperation("删除RFID硬件")
+    @PreAuthorize(hasAnyPermi = {PerPrefix.LABORATORY_HARDWARE7 + PerFun.REMOVE})
+    @DeleteMapping("/delete/{id}")
+    public ResultData delete(@PathVariable("id") Long id) {
+        return ResultData.result(hardwareRfidService.removeById(id));
+    }
+
+    /**
+     * 查询RFID硬件信息
+     */
+    @Log(title = "查询RFID硬件", businessType = BusinessType.OTHER)
+    @ApiOperation("查询RFID硬件")
+    @PreAuthorize(hasAnyPermi = {PerPrefix.LABORATORY_HARDWARE7 + PerFun.QUERY})
+    @GetMapping("/query")
+    public TableDataInfo query(HardwareRfidVo hardwareRfidVo) {
+        Page<HardwareRfid> pages = hardwareRfidService.search(new Page(hardwareRfidVo.getPageNum(), hardwareRfidVo.getPageSize()), hardwareRfidVo);
+        return getDataTable(pages.getRecords(),pages.getTotal());
+    }
+
+    /**
+     * 启动/停止RFID硬件
+     */
+    @Log(title = "启动/停止RFID硬件", businessType = BusinessType.UPDATE)
+    @ApiOperation("启动/停止RFID硬件")
+    @PreAuthorize(hasAnyPermi = {PerPrefix.LABORATORY_HARDWARE7 + PerFun.CHANGESTATUS})
+    @ApiImplicitParam(name = "id",value = "硬件Id",dataType = "Long")
+    @PutMapping("/startOrStop/{id}")
+    public ResultData startOrStop(@PathVariable("id") Long id) {
+        return hardwareRfidService.startOrStop(id);
+    }
+}

+ 16 - 8
zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/controller/RfidDeviceController.java

@@ -2,8 +2,10 @@ package com.zd.alg.rfid.controller;
 
 import com.zd.alg.rfid.constant.RfidConstants;
 import com.zd.alg.rfid.service.IRfidService;
+import com.zd.algorithm.api.rfid.domain.entity.HardwareRfid;
+import com.zd.common.core.utils.BeanUtils;
 import com.zd.model.domain.R;
-import com.zd.model.entity.RemoteLabHardware;
+import com.zd.model.entity.HardwareRfidDto;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.web.bind.annotation.*;
@@ -32,8 +34,10 @@ public class RfidDeviceController {
      */
     @ApiOperation("信道启动RFID扫描监控")
     @PostMapping("/startMonitorChannels")
-    public R<Boolean> startMonitorChannels(@RequestBody RemoteLabHardware hardware) {
-        service.start(hardware);
+    public R<Boolean> startMonitorChannels(@RequestBody HardwareRfidDto hardwareRfidDto) {
+        HardwareRfid hardwareRfid = new HardwareRfid();
+        BeanUtils.copyProperties(hardwareRfidDto,hardwareRfid);
+        service.start(hardwareRfid);
         return R.ok();
     }
 
@@ -42,8 +46,10 @@ public class RfidDeviceController {
      */
     @ApiOperation("断开设备连接")
     @PostMapping("/disconnect")
-    public R<Boolean> disconnect(@RequestBody RemoteLabHardware hardware) {
-        service.stop(hardware);
+    public R<Boolean> disconnect(@RequestBody HardwareRfidDto hardwareRfidDto) {
+        HardwareRfid hardwareRfid = new HardwareRfid();
+        BeanUtils.copyProperties(hardwareRfidDto,hardwareRfid);
+        service.stop(hardwareRfid);
         return R.ok();
     }
 
@@ -52,12 +58,14 @@ public class RfidDeviceController {
      */
     @ApiOperation("开启设备警报")
     @PostMapping("/alarm")
-    public R<Boolean> alarm(@RequestBody RemoteLabHardware hardware) {
-        return R.ok(service.alarm(hardware));
+    public R<Boolean> alarm(@RequestBody HardwareRfidDto hardwareRfidDto) {
+        HardwareRfid hardwareRfid = new HardwareRfid();
+        BeanUtils.copyProperties(hardwareRfidDto,hardwareRfid);
+        return R.ok(service.alarm(hardwareRfid));
     }
 
     /**
-     * 开启设备警报
+     * 获取RFID配置
      */
     @ApiOperation("获取RFID配置")
     @GetMapping("/config")

+ 7 - 7
zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/enums/ManufacturerTypeEnum.java

@@ -1,9 +1,8 @@
 package com.zd.alg.rfid.enums;
 
-import com.zd.alg.rfid.sdk.DeJuRFIDClientImpl;
-import com.zd.alg.rfid.service.IService;
 import com.zd.alg.rfid.sdk.DeJuRFIDServerImpl;
-import com.zd.alg.rfid.sdk.WuYuanRFIDServiceImpl;
+import com.zd.alg.rfid.sdk.RfidClientImpl;
+import com.zd.alg.rfid.service.IService;
 import lombok.AllArgsConstructor;
 import lombok.Getter;
 
@@ -18,9 +17,10 @@ public enum ManufacturerTypeEnum {
     /**
      * 枚举常量
      */
-    WU_WEI(1,"无源", WuYuanRFIDServiceImpl.class),
+//    WU_WEI(1,"无源", WuYuanRFIDServiceImpl.class),
     DE_JU(2,"惠州德聚服务端", DeJuRFIDServerImpl.class),
-    DE_JU2(3,"惠州德聚客户端", DeJuRFIDClientImpl.class);
+//    DE_JU2(3,"惠州德聚客户端", DeJuRFIDClientImpl.class);
+    DE_JU2(3,"惠州德聚客户端", RfidClientImpl.class);
 
     /**
      * 字典码
@@ -48,7 +48,7 @@ public enum ManufacturerTypeEnum {
                 return item;
             }
         }
-        return WU_WEI;
+        return DE_JU2;
     }
 
     /**
@@ -63,6 +63,6 @@ public enum ManufacturerTypeEnum {
                 return item;
             }
         }
-        return WU_WEI;
+        return DE_JU2;
     }
 }

+ 13 - 21
zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/init/RfidStartListener.java

@@ -1,11 +1,13 @@
 package com.zd.alg.rfid.init;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.zd.alg.rfid.service.HardwareRfidService;
 import com.zd.alg.rfid.service.IRfidService;
+import com.zd.algorithm.api.rfid.domain.entity.HardwareRfid;
 import com.zd.laboratory.api.feign.RemoteLaboratoryService;
-import com.zd.model.constant.HttpStatus;
-import com.zd.model.domain.R;
-import com.zd.model.entity.RemoteLabHardware;
+import com.zd.model.enums.DeviceOnOffEnum;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.ApplicationArguments;
 import org.springframework.boot.ApplicationRunner;
 import org.springframework.stereotype.Component;
@@ -29,29 +31,19 @@ public class RfidStartListener implements ApplicationRunner {
     @Resource
     private SocketServer socketServer;
 
+    @Autowired
+    private HardwareRfidService hardwareRfidService;
+
 
     @Override
     public void run(ApplicationArguments args) {
-        R<List<RemoteLabHardware>> listStart = laboratoryService.listStart();
-        synchronized (this){
-            while (listStart.getCode() != HttpStatus.SUCCESS) {
-                try {
-                    log.error("com.zd.system.api.laboratory.RemoteLaboratoryService:远程接口调用异常");
-                    //防止laboratory模块未启动完成,故每30秒执行一次程序,直到接口可以正常访问
-                    this.wait(30 * 1000L);
-                    RfidStartListener.this.run(args);
-                } catch (InterruptedException e) {
-                    Thread.currentThread().interrupt();
-                }
-            }
-            List<RemoteLabHardware> unitVos = listStart.getData();
-            if (!unitVos.isEmpty()) {
+        List<HardwareRfid> list = hardwareRfidService.list(new LambdaQueryWrapper<HardwareRfid>().eq(HardwareRfid::getOnOff, DeviceOnOffEnum.ON.getCode()));
+        synchronized (this) {
+            if (!list.isEmpty()) {
                 try {
-                    unitVos.stream()
-                            .filter(u -> StringUtils.hasLength(u.getIpAddress()))
-                            .forEach(u -> rfidService.start(u));
+                    list.stream().filter(u -> StringUtils.hasLength(u.getIpAddress())).forEach(u -> rfidService.start(u));
                 } catch (Exception e) {
-                    e.fillInStackTrace();
+                    log.error("启动操作失败!{}", e);
                 }
             }
         }

+ 19 - 0
zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/mapper/HardwareRfidMapper.java

@@ -0,0 +1,19 @@
+package com.zd.alg.rfid.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.zd.algorithm.api.rfid.domain.entity.HardwareRfid;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+  * @创建人 hzw
+  * @描述
+  * @创建时间  2022/11/15
+ */
+@Mapper
+public interface HardwareRfidMapper extends BaseMapper<HardwareRfid> {
+    int batchInsert(@Param("list") List<HardwareRfid> list);
+
+}

+ 35 - 35
zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/sdk/DeJuRFIDClientImpl.java

@@ -6,10 +6,10 @@ import com.gg.reader.api.protocol.gx.MsgBaseInventoryEpc;
 import com.gg.reader.api.protocol.gx.MsgBaseSetBaseband;
 import com.gg.reader.api.protocol.gx.MsgBaseSetPower;
 import com.zd.alg.rfid.service.IService;
+import com.zd.algorithm.api.rfid.domain.entity.HardwareRfid;
 import com.zd.common.core.exception.ServiceException;
 import com.zd.common.core.utils.SpringUtils;
 import com.zd.laboratory.api.feign.RemoteLaboratoryService;
-import com.zd.model.entity.RemoteLabHardware;
 import com.zd.model.enums.HardwareOperate;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.data.redis.core.RedisTemplate;
@@ -36,13 +36,13 @@ public class DeJuRFIDClientImpl implements IService {
     private DeJuRFIDServerImpl service;
 
     @Resource
-    private RedisTemplate<String, RemoteLabHardware> redisTemplate;
+    private RedisTemplate<String, HardwareRfid> redisTemplate;
 
     private static final ScheduledExecutorService scheduledExecutorService = SpringUtils.getBean("scheduledExecutorService");
 
     @Override
-    public void start(RemoteLabHardware hardware) {
-        String ipAddress = hardware.getIpAddress();
+    public void start(HardwareRfid hardwareRfid) {
+        String ipAddress = hardwareRfid.getIpAddress();
         GServer server;
         if (serverMap.containsKey(ipAddress)) {
             server = serverMap.get(ipAddress);
@@ -61,7 +61,7 @@ public class DeJuRFIDClientImpl implements IService {
         }
         if (server.open(port)) {
             log.info("开始监听:"+ipAddress);
-            subscribeServerHandler(server, hardware);
+            subscribeServerHandler(server, hardwareRfid);
         } else {
             log.info("监听失败:"+ipAddress);
             throw new ServiceException("监听失败,请稍后进行设备重连。。。");
@@ -69,11 +69,11 @@ public class DeJuRFIDClientImpl implements IService {
     }
 
     @Override
-    public void disconnect(RemoteLabHardware hardware) {
-        String ipAddress = hardware.getIpAddress();
+    public void disconnect(HardwareRfid hardwareRfid) {
+        String ipAddress = hardwareRfid.getIpAddress();
         if (serverMap.containsKey(ipAddress)) {
             GServer server = serverMap.get(ipAddress);
-            service.close(hardware);
+            service.close(hardwareRfid);
             server.close();
             serverMap.remove(ipAddress);
             log.info(ipAddress + "---监听结束");
@@ -81,26 +81,26 @@ public class DeJuRFIDClientImpl implements IService {
     }
 
     @Override
-    public boolean alarm(RemoteLabHardware hardware) {
-        return service.alarm(hardware);
+    public boolean alarm(HardwareRfid hardwareRfid) {
+        return service.alarm(hardwareRfid);
     }
 
     /**
      * 订阅监听上报
      *
      * @param server   服务对象
-     * @param hardware 设备对象
+     * @param hardwareRfid 设备对象
      */
-    public void subscribeServerHandler(GServer server, RemoteLabHardware hardware) {
+    public void subscribeServerHandler(GServer server, HardwareRfid hardwareRfid) {
         server.onGClientConnected = (client, serialNumber) -> {
-            redisTemplate.opsForValue().set(client.getSerialNumber(),hardware);
+            redisTemplate.opsForValue().set(client.getSerialNumber(),hardwareRfid);
             client.setSendHeartBeat(true);//开启心跳检测Tcp连接状态
             subscribeTcpHandler(client);//订阅Tcp断连上报
             client.setPrint(true);
-            reSet(hardware, client);
-            service.subscribeHandler(client, hardware);
+            reSet(hardwareRfid, client);
+            service.subscribeHandler(client, hardwareRfid);
             subscribeHandlerTagEpcOver(client);
-            remoteLaboratoryService.update(HardwareOperate.OPEN, hardware.getIpAddress());
+            remoteLaboratoryService.update(HardwareOperate.OPEN, hardwareRfid.getIpAddress());
             log.info(client.getName() + "---监听成功");
         };
     }
@@ -113,43 +113,43 @@ public class DeJuRFIDClientImpl implements IService {
     public void subscribeHandlerTagEpcOver(GClient client) {
         client.onTagEpcOver= (s, logBaseEpcInfo) -> {
             log.info("HandlerTagEpcOver:"+s);
-            RemoteLabHardware labHardware = redisTemplate.opsForValue().get(client.getSerialNumber());
-            if (labHardware==null){
+            HardwareRfid hardwareRfid = redisTemplate.opsForValue().get(client.getSerialNumber());
+            if (hardwareRfid==null){
                 return;
             }
-            disconnect(labHardware);
-            start(labHardware);
+            disconnect(hardwareRfid);
+            start(hardwareRfid);
         };
     }
 
-    private void reSet(RemoteLabHardware hardware, GClient client) {
-        MsgBaseSetBaseband msgBaseSetBaseband = DeJuRFIDServerImpl.setSession(hardware, client);
+    private void reSet(HardwareRfid hardwareRfid, GClient client) {
+        MsgBaseSetBaseband msgBaseSetBaseband = DeJuRFIDServerImpl.setSession(hardwareRfid, client);
         if (0 != msgBaseSetBaseband.getRtCode()) {
             log.error("Session configuration error.");
-            reConnect(hardware, client);
+            reConnect(hardwareRfid, client);
             return;
         }
-        MsgBaseSetPower msgBaseSetPower = DeJuRFIDServerImpl.setPower(hardware, client);
+        MsgBaseSetPower msgBaseSetPower = DeJuRFIDServerImpl.setPower(hardwareRfid, client);
         if (0 != msgBaseSetPower.getRtCode()) {
             log.error("Power configuration error.");
-            reConnect(hardware, client);
+            reConnect(hardwareRfid, client);
             return;
         }
-        MsgBaseInventoryEpc msgBaseInventoryEpc = DeJuRFIDServerImpl.setInventory(hardware, client);
+        MsgBaseInventoryEpc msgBaseInventoryEpc = DeJuRFIDServerImpl.setInventory(hardwareRfid, client);
         if (0 != msgBaseInventoryEpc.getRtCode()) {
             log.error("Inventory epc error.");
-            reConnect(hardware, client);
+            reConnect(hardwareRfid, client);
             return;
         }
         boolean changeGpi = DeJuRFIDServerImpl.setGpi(client);
         if (!changeGpi){
-            reConnect(hardware,client);
+            reConnect(hardwareRfid,client);
         }
     }
 
-    private void reConnect(RemoteLabHardware hardware, GClient client) {
+    private void reConnect(HardwareRfid hardwareRfid, GClient client) {
         DeJuRFIDServerImpl.stopMsg(client);
-        reSet(hardware, client);
+        reSet(hardwareRfid, client);
     }
 
     /**
@@ -158,14 +158,14 @@ public class DeJuRFIDClientImpl implements IService {
      * @param client   客户端对象
      */
     private void subscribeTcpHandler(GClient client) {
-        RemoteLabHardware labHardware = redisTemplate.opsForValue().get(client.getSerialNumber());
+        HardwareRfid hardwareRfid = redisTemplate.opsForValue().get(client.getSerialNumber());
         client.onDisconnected = s -> {
             log.info("连接" + s + "已断开");
-            if (labHardware!=null){
-                disconnect(labHardware);
-                remoteLaboratoryService.update(HardwareOperate.CLOSE, labHardware.getIpAddress());
+            if (hardwareRfid!=null){
+                disconnect(hardwareRfid);
+                remoteLaboratoryService.update(HardwareOperate.CLOSE, hardwareRfid.getIpAddress());
                 log.info("连接" + s + "重连中。。。");
-                scheduledExecutorService.schedule(()-> start(labHardware),30, TimeUnit.SECONDS);
+                scheduledExecutorService.schedule(()-> start(hardwareRfid),30, TimeUnit.SECONDS);
             }
         };
     }

+ 57 - 52
zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/sdk/DeJuRFIDServerImpl.java

@@ -4,11 +4,12 @@ import com.gg.reader.api.dal.GClient;
 import com.gg.reader.api.protocol.gx.*;
 import com.zd.alg.rfid.service.ISendService;
 import com.zd.alg.rfid.service.IService;
+import com.zd.algorithm.api.rfid.domain.entity.HardwareRfid;
 import com.zd.common.core.exception.ServiceException;
 import com.zd.common.core.utils.SpringUtils;
 import com.zd.laboratory.api.feign.RemoteLaboratoryService;
+import com.zd.model.entity.HardwareRfidDto;
 import com.zd.model.entity.InventoryTag;
-import com.zd.model.entity.RemoteLabHardware;
 import com.zd.model.enums.HardwareOperate;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
@@ -43,19 +44,19 @@ public class DeJuRFIDServerImpl implements IService {
     private static final ScheduledExecutorService scheduledExecutorService = SpringUtils.getBean("scheduledExecutorService");
 
     @Resource
-    private RedisTemplate<String, RemoteLabHardware> redisTemplate;
+    private RedisTemplate<String, HardwareRfid> redisTemplate;
 
     @Resource
     private RemoteLaboratoryService remoteLaboratoryService;
 
     @Override
-    public void start(RemoteLabHardware hardware) {
-        open(hardware);
+    public void start(HardwareRfid hardwareRfid) {
+        open(hardwareRfid);
     }
 
-    private void open(RemoteLabHardware hardware) {
+    private void open(HardwareRfid hardwareRfid) {
         GClient client;
-        String ipAddress = hardware.getIpAddress();
+        String ipAddress = hardwareRfid.getIpAddress();
         if (clientMap.containsKey(ipAddress)) {
             client = clientMap.get(ipAddress);
         } else {
@@ -72,41 +73,41 @@ public class DeJuRFIDServerImpl implements IService {
             boolean change = setGpi(client);
             if (!change){
                 log.info("GPI epc error.");
-                close(hardware);
-                open(hardware);
+                close(hardwareRfid);
+                open(hardwareRfid);
                 return;
             }
-            MsgBaseSetBaseband msgBaseSetBaseband = setSession(hardware, client);
+            MsgBaseSetBaseband msgBaseSetBaseband = setSession(hardwareRfid, client);
             if (0 != msgBaseSetBaseband.getRtCode()) {
                 log.info("Session epc error.");
-                close(hardware);
-                open(hardware);
+                close(hardwareRfid);
+                open(hardwareRfid);
                 return;
             }
             // 功率配置, 将4个天线功率都设置为30dBm.
-            MsgBaseSetPower msgBaseSetPower = setPower(hardware, client);
+            MsgBaseSetPower msgBaseSetPower = setPower(hardwareRfid, client);
             if (0 != msgBaseSetPower.getRtCode()) {
                 log.info("Power configuration error.");
-                close(hardware);
-                open(hardware);
+                close(hardwareRfid);
+                open(hardwareRfid);
                 return;
             }
             //天线读卡, 读取EPC数据区以及TID数据区
-            MsgBaseInventoryEpc msgBaseInventoryEpc = setInventory(hardware, client);
+            MsgBaseInventoryEpc msgBaseInventoryEpc = setInventory(hardwareRfid, client);
             if (0 != msgBaseInventoryEpc.getRtCode()) {
                 log.info("Inventory epc error.");
-                close(hardware);
-                open(hardware);
+                close(hardwareRfid);
+                open(hardwareRfid);
                 return;
             }
 
             // 订阅标签上报事件
-            subscribeHandler(client, hardware);
-            subscribeHandlerTagEpcOver(client,hardware);
+            subscribeHandler(client, hardwareRfid);
+            subscribeHandlerTagEpcOver(client,hardwareRfid);
             subscribeTcpHandler(client);
             String serialNumber = client.getSerialNumber();
             if (StringUtils.hasLength(serialNumber)){
-                redisTemplate.opsForValue().set(serialNumber, hardware);
+                redisTemplate.opsForValue().set(serialNumber, hardwareRfid);
             }
         } else {
             throw new ServiceException("Connect failure.");
@@ -119,21 +120,21 @@ public class DeJuRFIDServerImpl implements IService {
      * @param client   客户端对象
      */
     public void subscribeTcpHandler(GClient client) {
-        RemoteLabHardware labHardware = redisTemplate.opsForValue().get(client.getSerialNumber());
+        HardwareRfid hardwareRfid = redisTemplate.opsForValue().get(client.getSerialNumber());
         client.onDisconnected = s -> {
             log.info("连接" + s + "已断开");
-            if (labHardware!=null){
+            if (hardwareRfid!=null){
                 client.close();
-                remoteLaboratoryService.update(HardwareOperate.CLOSE, labHardware.getIpAddress());
+                remoteLaboratoryService.update(HardwareOperate.CLOSE, hardwareRfid.getIpAddress());
                 log.info("连接" + s + "重连中。。。");
-                start(labHardware);
+                start(hardwareRfid);
             }
         };
     }
 
-    public static MsgBaseInventoryEpc setInventory(RemoteLabHardware hardware, GClient client) {
+    public static MsgBaseInventoryEpc setInventory(HardwareRfid hardwareRfid, GClient client) {
         MsgBaseInventoryEpc msgBaseInventoryEpc = new MsgBaseInventoryEpc();
-        switch (hardware.getChannels()) {
+        switch (hardwareRfid.getChannels()) {
             case 4:
                 msgBaseInventoryEpc.setAntennaEnable(EnumG.AntennaNo_1 | EnumG.AntennaNo_2 | EnumG.AntennaNo_3 | EnumG.AntennaNo_4);
                 break;
@@ -156,30 +157,30 @@ public class DeJuRFIDServerImpl implements IService {
         return msgBaseInventoryEpc;
     }
 
-    public static MsgBaseSetPower setPower(RemoteLabHardware hardware, GClient client) {
-        String uniformPower = hardware.getUniformPower();
+    public static MsgBaseSetPower setPower(HardwareRfid hardwareRfid, GClient client) {
+        String uniformPower = hardwareRfid.getUniformPower();
         MsgBaseGetPower msgBaseGetPower = new MsgBaseGetPower();
         client.sendSynMsg(msgBaseGetPower);
         MsgBaseSetPower msgBaseSetPower = new MsgBaseSetPower();
         if (0 == msgBaseGetPower.getRtCode()) {
-            sendPower(hardware, client, uniformPower, msgBaseGetPower, msgBaseSetPower);
+            sendPower(hardwareRfid, client, uniformPower, msgBaseGetPower, msgBaseSetPower);
         } else {
             log.info("==============获取输出功率失败==============");
         }
         return msgBaseSetPower;
     }
 
-    private static void sendPower(RemoteLabHardware hardware, GClient client, String uniformPower, MsgBaseGetPower msgBaseGetPower, MsgBaseSetPower msgBaseSetPower) {
+    private static void sendPower(HardwareRfid hardwareRfid, GClient client, String uniformPower, MsgBaseGetPower msgBaseGetPower, MsgBaseSetPower msgBaseSetPower) {
         if (StringUtils.hasLength(uniformPower)) {
-            editAndSendPower(hardware, client, uniformPower, msgBaseSetPower, msgBaseGetPower);
+            editAndSendPower(hardwareRfid, client, uniformPower, msgBaseSetPower, msgBaseGetPower);
         } else {
             msgBaseSetPower.setRtCode((byte) 0);
         }
     }
 
-    private static void editAndSendPower(RemoteLabHardware hardware, GClient client, String uniformPower, MsgBaseSetPower msgBaseSetPower, MsgBaseGetPower msgBaseGetPower) {
+    private static void editAndSendPower(HardwareRfid hardwareRfid, GClient client, String uniformPower, MsgBaseSetPower msgBaseSetPower, MsgBaseGetPower msgBaseGetPower) {
         Hashtable<Integer, Integer> dicPower = msgBaseGetPower.getDicPower();
-        Integer channels = hardware.getChannels();
+        Integer channels = hardwareRfid.getChannels();
         String[] uniformPowers = uniformPower.split(",");
         for (int i = 1; i <= channels; i++) {
             Integer power = dicPower.get(i);
@@ -199,15 +200,15 @@ public class DeJuRFIDServerImpl implements IService {
         }
     }
 
-    public static MsgBaseSetBaseband setSession(RemoteLabHardware hardware, GClient client) {
+    public static MsgBaseSetBaseband setSession(HardwareRfid hardwareRfid, GClient client) {
         MsgBaseGetBaseband msgBaseGetBaseband = new MsgBaseGetBaseband();
         MsgBaseSetBaseband msgBaseSetBaseband = new MsgBaseSetBaseband();
         client.sendSynMsg(msgBaseGetBaseband);
         if (0 == msgBaseGetBaseband.getRtCode()) {
             int session = msgBaseGetBaseband.getSession();
             log.info("Session index is:==============》{}", session);
-            if (session != hardware.getSessionIndex()) {
-                msgBaseSetBaseband.setSession(hardware.getSessionIndex());
+            if (session != hardwareRfid.getSessionIndex()) {
+                msgBaseSetBaseband.setSession(hardwareRfid.getSessionIndex());
                 client.sendSynMsg(msgBaseSetBaseband);
                 if (0 != msgBaseSetBaseband.getRtCode()) {
                     log.info("Session epc error.");
@@ -253,14 +254,14 @@ public class DeJuRFIDServerImpl implements IService {
     }
 
     @Override
-    public void disconnect(RemoteLabHardware hardware) {
-        close(hardware);
+    public void disconnect(HardwareRfid hardwareRfid) {
+        close(hardwareRfid);
     }
 
     @Override
-    public boolean alarm(RemoteLabHardware hardware) {
+    public boolean alarm(HardwareRfid hardwareRfid) {
         //灯带设置
-        String ipAddress = hardware.getIpAddress();
+        String ipAddress = hardwareRfid.getIpAddress();
         if (clientMap.containsKey(ipAddress)) {
             GClient client = clientMap.get(ipAddress);
             boolean alarm = false;
@@ -278,8 +279,8 @@ public class DeJuRFIDServerImpl implements IService {
         return false;
     }
 
-    public void close(RemoteLabHardware hardware) {
-        String ipAddress = hardware.getIpAddress();
+    public void close(HardwareRfid hardwareRfid) {
+        String ipAddress = hardwareRfid.getIpAddress();
         if (clientMap.containsKey(ipAddress)) {
             GClient client = clientMap.get(ipAddress);
             changeGpo(ipAddress, 0, client, 0);
@@ -342,10 +343,10 @@ public class DeJuRFIDServerImpl implements IService {
      * 订阅6c标签信息上报
      *
      * @param client   客户端
-     * @param hardware 设备数据
+     * @param hardwareRfid 设备数据
      */
-    public void subscribeHandler(GClient client, RemoteLabHardware hardware) {
-        String ipAddress = hardware.getIpAddress();
+    public void subscribeHandler(GClient client, HardwareRfid hardwareRfid) {
+        String ipAddress = hardwareRfid.getIpAddress();
         clientMap.computeIfAbsent(ipAddress, f -> client);
         String serialNumber = client.getSerialNumber();
         client.onTagEpcLog = (s, logBaseEpcInfo) -> {
@@ -355,17 +356,21 @@ public class DeJuRFIDServerImpl implements IService {
                 String key=epc+antId;
                 if (Boolean.FALSE.equals(redisTemplate.hasKey(key))){
                     log.info("===========》{},index: {}", epc, antId);
-                    redisTemplate.opsForValue().set(key,hardware,30,TimeUnit.SECONDS);
+                    redisTemplate.opsForValue().set(key,hardwareRfid,30,TimeUnit.SECONDS);
                     scheduledExecutorService.execute(()->{
                         InventoryTag tag = new InventoryTag();
                         BeanUtils.copyProperties(logBaseEpcInfo, tag);
                         String readerSerialNumber = logBaseEpcInfo.getReaderSerialNumber();
                         log.info("===========》读取器设备编码:{}", readerSerialNumber);
+                        HardwareRfidDto hardwareRfidDto = new HardwareRfidDto();
                         if (StringUtils.hasLength(serialNumber)){
                             tag.setSerialNumber(serialNumber);
-                            tag.setRemoteLabHardware(redisTemplate.opsForValue().get(serialNumber));
+//                            tag.setRemoteLabHardware(redisTemplate.opsForValue().get(serialNumber));
+                            BeanUtils.copyProperties(redisTemplate.opsForValue().get(serialNumber),hardwareRfidDto);
+                            tag.setHardwareRfidDto(hardwareRfidDto);
                         }else {
-                            tag.setRemoteLabHardware(hardware);
+                            BeanUtils.copyProperties(hardwareRfid,hardwareRfidDto);
+                            tag.setHardwareRfidDto(hardwareRfidDto);
                         }
                         sendService.send(tag);
                     });
@@ -378,13 +383,13 @@ public class DeJuRFIDServerImpl implements IService {
      * 订阅6c标签信息上报停止事件
      *
      * @param client   客户端
-     * @param hardware 设备数据
+     * @param hardwareRfid 设备数据
      */
-    public void subscribeHandlerTagEpcOver(GClient client, RemoteLabHardware hardware) {
+    public void subscribeHandlerTagEpcOver(GClient client, HardwareRfid hardwareRfid) {
         client.onTagEpcOver= (s, logBaseEpcInfo) -> {
             log.info("HandlerTagEpcOver:"+s);
-            close(hardware);
-            open(hardware);
+            close(hardwareRfid);
+            open(hardwareRfid);
         };
     }
 }

+ 430 - 0
zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/sdk/RfidClientImpl.java

@@ -0,0 +1,430 @@
+package com.zd.alg.rfid.sdk;
+
+import com.gg.reader.api.dal.*;
+import com.gg.reader.api.protocol.gx.*;
+import com.zd.alg.rfid.service.HardwareRfidService;
+import com.zd.alg.rfid.service.ISendService;
+import com.zd.alg.rfid.service.IService;
+import com.zd.algorithm.api.rfid.domain.entity.HardwareRfid;
+import com.zd.common.core.utils.SpringUtils;
+import com.zd.model.entity.HardwareRfidDto;
+import com.zd.model.entity.InventoryTag;
+import com.zd.model.enums.DeviceStatusEnum;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @创建人 hzw
+ * @描述 rfid客户端实现类
+ * @创建时间 2022/11/15
+ */
+@Slf4j
+@Service
+public class RfidClientImpl implements IService {
+    private static final ISendService sendService = SpringUtils.getBean("sendService");
+
+    private static final Map<String, GClient> clientMap = new ConcurrentHashMap<>();
+    private static final Map<String, GServer> serverMap = new ConcurrentHashMap<>();
+    //传送方向
+    private static final Map<String, Integer> directionMap = new ConcurrentHashMap<>();
+    private static final ScheduledExecutorService scheduledExecutorService = SpringUtils.getBean("scheduledExecutorService");
+    @Resource
+    private RedisTemplate<String, HardwareRfid> redisTemplate;
+    @Autowired
+    private HardwareRfidService hardwareRfidService;
+
+    @Override
+    public void start(HardwareRfid hardwareRfid) {
+        GServer server = new GServer();
+        int port = getPort(hardwareRfid.getIpAddress());
+        if (server.open(port)) {
+            log.info("【RFID门禁机】开始监听");
+            subscribeServerHandler(hardwareRfid, server);
+        } else {
+            log.info("【RFID门禁机】监听失败");
+        }
+    }
+
+    /**
+     * 订阅监听上报
+     */
+    private void subscribeServerHandler(HardwareRfid hardwareRfid, GServer server) {
+        //TCP 处于监听状态,远程读写设备主动连接上位机时,会触发此事件上报
+        server.onGClientConnected = new HandlerGClientConnected() {
+            @Override
+            public void log(GClient client, String serialNumber) {
+                String ipAddress = getIp(hardwareRfid);
+                if (clientMap.containsKey(ipAddress)) {
+                    log.info("此ip已存在客户端!");
+                    return;
+                }
+                //存储客户端
+                clientMap.put(ipAddress, client);
+                //储存服务端
+                serverMap.put(ipAddress, server);
+                //开启心跳检测Tcp连接状态
+                client.setSendHeartBeat(true);
+                client.setPrint(true);
+                //订阅Tcp断连上报
+                subscribeTcpHandler(client,hardwareRfid);
+                //设置rfid初始化参数
+                setConfig(client, hardwareRfid);
+                //订阅报告启动事件
+                subscribeReportedStartEvents(client, hardwareRfid);
+                //订阅报告结束事件
+                subscribeReportedOverEvents(client, hardwareRfid);
+                //修改设备状态
+                changStatus(hardwareRfid,DeviceStatusEnum.ON_LINE.getCode());
+                log.info("【RFID门禁机】监听成功!{}", client.getName());
+            }
+        };
+    }
+
+    /**
+     * 订阅TCP断开连接上报
+     */
+    private void subscribeTcpHandler(GClient client,HardwareRfid hardwareRfid) {
+        client.onDisconnected = new HandlerTcpDisconnected() {
+            @Override
+            public void log(String ipPort) {
+                log.warn("【RFID门禁机】连接已断开:{}", ipPort);
+                changStatus(hardwareRfid,DeviceStatusEnum.OFF_LINE.getCode());
+                //释放当前连接资源
+                client.close();
+                //删除客户端map数据
+                String[] split = ipPort.split(":");
+                clientMap.remove(split[0]);
+            }
+        };
+    }
+
+    private void subscribeReportedStartEvents(GClient client, HardwareRfid hardwareRfid) {
+        // 订阅标签上报事件
+        client.onTagEpcLog = new HandlerTagEpcLog() {
+            @Override
+            public void log(String readName, LogBaseEpcInfo logBaseEpcInfo) {
+                // 回调内部如有阻塞,会影响 API 正常使用
+                // 标签回调数量较多,请将标签数据先缓存起来再作业务处理
+                if (null != logBaseEpcInfo && 0 == logBaseEpcInfo.getResult()) {
+                    log.info("接收到RFID读写器消息:{}", logBaseEpcInfo);
+                    // redis是否存在此标签
+                    int antId = logBaseEpcInfo.getAntId();
+                    String epc = logBaseEpcInfo.getEpc();
+                    if (Boolean.FALSE.equals(redisTemplate.hasKey(logBaseEpcInfo.getEpc() + antId))) {
+                        //不存在缓存,设置间隔30s调用
+                        redisTemplate.opsForValue().set(logBaseEpcInfo.getEpc() + antId, hardwareRfid, 30, TimeUnit.SECONDS);
+                        scheduledExecutorService.execute(() -> {
+                            InventoryTag tag = new InventoryTag();
+                            BeanUtils.copyProperties(logBaseEpcInfo, tag);
+                            HardwareRfidDto hardwareRfidDto = new HardwareRfidDto();
+                            BeanUtils.copyProperties(hardwareRfid, hardwareRfidDto);
+                            tag.setHardwareRfidDto(hardwareRfidDto);
+                            sendService.send(tag);
+                        });
+                    } else {
+                        //标签存在缓存,间隔30s调用
+                        log.info("标签操作频繁,请间隔30s调用!");
+                    }
+                }
+            }
+        };
+    }
+
+    private void subscribeReportedOverEvents(GClient client, HardwareRfid hardwareRfid) {
+        client.onTagEpcOver = new HandlerTagEpcOver() {
+            @Override
+            public void log(String s, LogBaseEpcOver logBaseEpcOver) {
+                log.info("【RFID门禁机】已离线!");
+                hardwareRfid.setDeviceStatus(DeviceStatusEnum.OFF_LINE.getCode());
+                hardwareRfidService.updateHardwareRfid(hardwareRfid);
+            }
+        };
+    }
+
+    private void setConfig(GClient client, HardwareRfid hardwareRfid) {
+        try {
+            // 读写器停止读写卡
+            if (stopMsg(client)) {
+                //设置GPI
+                if (!setGpi(client)) {
+                    return;
+                }
+                //设置session
+                if (!setSession(client)) {
+                    return;
+                }
+                // 天线功率配置(将4个天线功率都设置为30dBm)
+                if (!setPower(client, hardwareRfid)) {
+                    return;
+                }
+                //天线读卡, 读取EPC数据区以及TID数据区
+                setInventory(client, hardwareRfid);
+                //读写器传输方向
+                //directionMap.put("direction",1);
+            }
+        } catch (Exception e) {
+            changStatus(hardwareRfid,DeviceStatusEnum.EXCEPTION.getCode());
+            log.error("设置门禁机异常,请联系管理员!");
+        }
+    }
+
+    private void changStatus(HardwareRfid hardwareRfid,Integer code) {
+        hardwareRfid.setDeviceStatus(code);
+        hardwareRfidService.updateHardwareRfid(hardwareRfid);
+    }
+
+    public boolean setGpi(GClient client) {
+        MsgAppGetGpiState gpiState = new MsgAppGetGpiState();
+        client.sendSynMsg(gpiState);
+        HashMap<Integer, Integer> hashMap = gpiState.getHpGpiState();
+        boolean change = true;
+        for (Map.Entry<Integer, Integer> entry : hashMap.entrySet()) {
+            Integer k = entry.getKey();
+            MsgAppGetGpiTrigger getGpiTrigger = new MsgAppGetGpiTrigger();
+            getGpiTrigger.setGpiPort(k - 1);
+            client.sendSynMsg(getGpiTrigger);
+            if (getGpiTrigger.getRtCode() == 0) {
+                int triggerOver = getGpiTrigger.getTriggerOver();
+                int triggerStart = getGpiTrigger.getTriggerStart();
+                if (triggerStart != 0 || triggerOver != 0) {
+                    MsgAppSetGpiTrigger gpiTrigger = new MsgAppSetGpiTrigger();
+                    gpiTrigger.setGpiPort(getGpiTrigger.getGpiPort());
+                    gpiTrigger.setTriggerOver(0);
+                    gpiTrigger.setTriggerStart(0);
+                    client.sendSynMsg(gpiTrigger);
+                    if (0 != gpiTrigger.getRtCode()) {
+                        log.error("GPI epc error.");
+                        change = false;
+                    }
+                }
+            }
+        }
+        log.info("【RFID门禁机】GPI配置成功!");
+        return change;
+    }
+
+    public boolean setSession(GClient client) {
+        MsgBaseGetBaseband msgBaseGetBaseband = new MsgBaseGetBaseband();
+        MsgBaseSetBaseband msgBaseSetBaseband = new MsgBaseSetBaseband();
+        client.sendSynMsg(msgBaseGetBaseband);
+        if (0 == msgBaseGetBaseband.getRtCode()) {
+            int session = msgBaseGetBaseband.getSession();
+            if (session == 0) {
+                log.info("【RFID门禁机】Session已配置成功!");
+                return true;
+            } else {
+                msgBaseSetBaseband.setSession(0);
+                client.sendSynMsg(msgBaseSetBaseband);
+                if (0 == msgBaseSetBaseband.getRtCode()) {
+                    log.info("【RFID门禁机】Session配置成功!");
+                    return true;
+                }
+            }
+        }
+        log.error("【RFID门禁机】Session配置失败!");
+        return false;
+    }
+
+    public boolean setPower(GClient client, HardwareRfid hardwareRfid) {
+        MsgBaseGetPower msgBaseGetPower = new MsgBaseGetPower();
+        client.sendSynMsg(msgBaseGetPower);
+        if (0 == msgBaseGetPower.getRtCode()) {
+            return sendPower(client, hardwareRfid, msgBaseGetPower);
+        } else {
+            log.error("【RFID门禁机】获取天线功率失败!{}", msgBaseGetPower.getRtMsg());
+            return false;
+        }
+    }
+
+    public boolean setInventory(GClient client, HardwareRfid hardwareRfid) {
+        //几路天线读卡和通道数保持一致。
+        if (hardwareRfid.getChannels() == null) {
+            log.error("【RFID门禁机】通道配置为空!");
+            return false;
+        }
+        // 4个天线读卡, 读取 EPC 数据区以及 TID 数据区 默认只读 EPC
+        MsgBaseInventoryEpc msgBaseInventoryEpc = new MsgBaseInventoryEpc();
+        switch (hardwareRfid.getChannels()) {
+            case 4:
+                msgBaseInventoryEpc.setAntennaEnable(EnumG.AntennaNo_1 | EnumG.AntennaNo_2 | EnumG.AntennaNo_3 | EnumG.AntennaNo_4);
+                break;
+            case 8:
+                msgBaseInventoryEpc.setAntennaEnable(EnumG.AntennaNo_1 | EnumG.AntennaNo_2 | EnumG.AntennaNo_3 | EnumG.AntennaNo_4 | EnumG.AntennaNo_5 | EnumG.AntennaNo_6 | EnumG.AntennaNo_7 | EnumG.AntennaNo_8);
+                break;
+            case 16:
+                msgBaseInventoryEpc.setAntennaEnable(EnumG.AntennaNo_1 | EnumG.AntennaNo_2 | EnumG.AntennaNo_3 | EnumG.AntennaNo_4 | EnumG.AntennaNo_5 | EnumG.AntennaNo_6 | EnumG.AntennaNo_7 | EnumG.AntennaNo_8 | EnumG.AntennaNo_9 | EnumG.AntennaNo_10 | EnumG.AntennaNo_11 | EnumG.AntennaNo_12 | EnumG.AntennaNo_13 | EnumG.AntennaNo_14 | EnumG.AntennaNo_15 | EnumG.AntennaNo_16);
+                break;
+            case 1:
+            default:
+                msgBaseInventoryEpc.setAntennaEnable(EnumG.AntennaNo_1);
+        }
+        msgBaseInventoryEpc.setInventoryMode(EnumG.InventoryMode_Inventory);
+        client.sendSynMsg(msgBaseInventoryEpc);
+        if (0 == msgBaseInventoryEpc.getRtCode()) {
+            log.info("【RFID门禁机】Inventory epc配置成功!");
+            return true;
+        } else {
+            log.error("【RFID门禁机】Inventory epc配置失败!");
+            return false;
+        }
+    }
+
+
+    private boolean sendPower(GClient client, HardwareRfid hardwareRfid, MsgBaseGetPower msgBaseGetPower) {
+        //根据硬件配置参数配置设备功率
+        if (!hardwareRfid.getUniformPower().isEmpty() && hardwareRfid.getChannels() != null) {
+            Hashtable<Integer, Integer> dicPower = msgBaseGetPower.getDicPower();
+            Integer channels = hardwareRfid.getChannels();
+            String[] uniformPowers = hardwareRfid.getUniformPower().split(",");
+            for (int i = 1; i <= channels; i++) {
+                Integer power = dicPower.get(i);
+                String tempUniformPower = uniformPowers[i - 1];
+                String[] tempUniformPowers = tempUniformPower.split(":");
+                String temp = tempUniformPowers[0];
+                if (power == null || !Objects.equals(power, Integer.valueOf(temp))) {
+                    dicPower.put(i, Integer.valueOf(temp));
+                }
+            }
+            MsgBaseSetPower msgBaseSetPower = new MsgBaseSetPower();
+            msgBaseSetPower.setDicPower(dicPower);
+            client.sendSynMsg(msgBaseSetPower);
+            if (0 == msgBaseSetPower.getRtCode()) {
+                log.info("【RFID门禁机】设置天线功率成功!");
+                return true;
+            } else {
+                log.error("【RFID门禁机】设置天线功率失败!{}", msgBaseSetPower.getRtMsg());
+                return false;
+            }
+        } else {
+            log.error("设备输出频率或通道参数配置为空,UniformPower={},Channels={}", hardwareRfid.getUniformPower(), hardwareRfid.getChannels());
+            return false;
+        }
+    }
+
+    private boolean changeGpo(String ipAddress, int state, GClient client, int delayTime) {
+        log.info("进入控制报警方法!是否开启={}", state);
+        MsgAppSetGpo msgAppSetGpo = new MsgAppSetGpo();
+        msgAppSetGpo.setGpo1(state);
+        msgAppSetGpo.setGpo2(state);
+        msgAppSetGpo.setGpo3(state);
+        msgAppSetGpo.setGpo4(state);
+        client.sendSynMsg(msgAppSetGpo);//发送响铃之后,进入下方if,开启定时线程
+        String status = state == 1 ? "开启" : "关闭";
+        if (0 == msgAppSetGpo.getRtCode()) {
+            log.info("【RFID门禁机】灯带报警{}成功!", status);
+            if (state == 1) {
+                stopGpo(ipAddress, client, delayTime);
+            }
+            return true;
+        }
+        log.info("【RFID门禁机】灯带报警{}失败!", status);
+        return false;
+
+    }
+
+    @Override
+    public void disconnect(HardwareRfid hardwareRfid) {
+        String ip = getIp(hardwareRfid);
+        if (clientMap.containsKey(ip)) {
+            GClient client = clientMap.get(ip);
+            GServer server = serverMap.get(ip);
+            //关闭报警
+            changeGpo(ip, 0, client, 0);
+            //停止读写卡
+            stopMsg(client);
+            //客户端资源释放
+            client.close();
+            //服务端接口释放
+            server.close();
+            //客户端清除
+            clientMap.remove(ip);
+            //服务端缓存清除
+            serverMap.remove(ip);
+            log.info("【RFID门禁机】关闭成功!");
+        }
+
+    }
+
+    /**
+     * 停止读写卡
+     */
+    public boolean stopMsg(GClient client) {
+        // 停止指令,空闲态
+        MsgBaseStop msgBaseStop = new MsgBaseStop();
+        client.sendSynMsg(msgBaseStop);
+        if (0x00 == msgBaseStop.getRtCode()) {
+            log.info("【RFID门禁机】停止读写成功!");
+            return true;
+        } else {
+            log.error("【RFID门禁机】停止读写失败!{}", msgBaseStop.getRtMsg());
+            return false;
+        }
+    }
+
+    @Override
+    public boolean alarm(HardwareRfid hardwareRfid) {
+        log.info("收到调用报警!");
+        //灯带设置
+        String ipAddress = getIp(hardwareRfid);
+        if (clientMap.containsKey(ipAddress)) {
+            GClient client = clientMap.get(ipAddress);
+            synchronized (this) {
+                //设置开始报警、报警时长
+                return changeGpo(ipAddress, 1, client, 1);
+            }
+        }
+        return false;
+    }
+
+    public void stopGpo(String ipAddress, GClient client, int delayTime) {
+        scheduledExecutorService.schedule(new TimerTask() {
+            @Override
+            public void run() {
+                changeGpo(ipAddress, 0, client, 0);
+            }
+        }, delayTime, TimeUnit.SECONDS);
+    }
+
+    /**
+     * 去掉端口号,只获取ip
+     */
+    private static String getIp(HardwareRfid hardwareRfid) {
+        String ipAddress;
+        if (Objects.isNull(hardwareRfid) || StringUtils.isBlank(hardwareRfid.getIpAddress())) {
+            log.error("RFID配置ip为空!");
+        }
+        String[] ipPort = hardwareRfid.getIpAddress().split(":");
+        if (ipPort.length > 1) {
+            ipAddress = ipPort[0];
+        } else {
+            ipAddress = hardwareRfid.getIpAddress();
+        }
+        return ipAddress;
+    }
+
+    /**
+     * 获取端口号 未配置端口号默认给到8160
+     */
+    private static int getPort(String ipPort) {
+        //默认给到8160
+        int port = 8160;
+        if (null == ipPort || "".equals(ipPort)) {
+            return port;
+        }
+        String[] split = ipPort.split(":");
+        if (split.length > 1) {
+            port = Integer.valueOf(split[1]);
+        }
+        return port;
+    }
+}

+ 249 - 249
zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/sdk/WuYuanRFIDServiceImpl.java

@@ -1,249 +1,249 @@
-package com.zd.alg.rfid.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.alg.rfid.base.RfidConsumer;
-import com.zd.alg.rfid.service.ISendService;
-import com.zd.alg.rfid.service.IService;
-import com.zd.common.core.exception.ServiceException;
-import com.zd.laboratory.api.feign.RemoteLaboratoryService;
-import com.zd.model.entity.RemoteLabHardware;
-import com.zd.model.enums.HardwareOperate;
-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 WuYuanRFIDServiceImpl 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 RfidConsumer rfidConsumer;
-    @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(rfidConsumer)
-                //读取失败
-                .setOnFailure(failure -> errorMsg(failure, index, SCANNER_MSG, hardware))
-                .build();
-        reader.setInventoryConfig(config);
-        //true -- 开启循环调用
-        reader.startInventory(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);
-    }
-
-    @Override
-    public boolean alarm(RemoteLabHardware hardware) {
-        // TODO document why this method is empty
-        return false;
-    }
-
-    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();
-        int power=33;
-        String uniformPower = hardware.getUniformPower();
-        String index = uniformPower.split(",")[0].split(":")[0];
-        if (StringUtils.hasLength(index)){
-            power= Integer.parseInt(index);
-        }
-        if (readerMap.containsKey(ipAddress)) {
-            reader = readerMap.get(ipAddress);
-        } else {
-            throw new ServiceException(MSG);
-        }
-
-        stopMonitor(hardware);
-        reader.setOutputPowerUniformly(
-                (byte) Integer.parseInt(Integer.toHexString(power)),
-                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());
-    }
-}
+//package com.zd.alg.rfid.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.alg.rfid.base.RfidConsumer;
+//import com.zd.alg.rfid.service.ISendService;
+//import com.zd.alg.rfid.service.IService;
+//import com.zd.common.core.exception.ServiceException;
+//import com.zd.laboratory.api.feign.RemoteLaboratoryService;
+//import com.zd.model.entity.RemoteLabHardware;
+//import com.zd.model.enums.HardwareOperate;
+//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 WuYuanRFIDServiceImpl 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 RfidConsumer rfidConsumer;
+//    @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(rfidConsumer)
+//                //读取失败
+//                .setOnFailure(failure -> errorMsg(failure, index, SCANNER_MSG, hardware))
+//                .build();
+//        reader.setInventoryConfig(config);
+//        //true -- 开启循环调用
+//        reader.startInventory(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);
+//    }
+//
+//    @Override
+//    public boolean alarm(RemoteLabHardware hardware) {
+//        // TODO document why this method is empty
+//        return false;
+//    }
+//
+//    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();
+//        int power=33;
+//        String uniformPower = hardware.getUniformPower();
+//        String index = uniformPower.split(",")[0].split(":")[0];
+//        if (StringUtils.hasLength(index)){
+//            power= Integer.parseInt(index);
+//        }
+//        if (readerMap.containsKey(ipAddress)) {
+//            reader = readerMap.get(ipAddress);
+//        } else {
+//            throw new ServiceException(MSG);
+//        }
+//
+//        stopMonitor(hardware);
+//        reader.setOutputPowerUniformly(
+//                (byte) Integer.parseInt(Integer.toHexString(power)),
+//                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());
+//    }
+//}

+ 47 - 0
zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/service/HardwareRfidService.java

@@ -0,0 +1,47 @@
+package com.zd.alg.rfid.service;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.zd.algorithm.api.rfid.domain.entity.HardwareRfid;
+import com.zd.algorithm.api.rfid.domain.vo.HardwareRfidVo;
+import com.zd.model.domain.ResultData;
+
+import java.util.List;
+
+/**
+ * @创建人 hzw
+ * @描述 rfid硬件接口
+ * @创建时间 2022/11/15
+ */
+public interface HardwareRfidService extends IService<HardwareRfid> {
+
+    int batchInsert(List<HardwareRfid> list);
+
+    /**
+     * 新增rfid硬件信息
+     * @Param [hardwareRfid]
+     * @Return com.zd.model.domain.ResultData
+     **/
+    ResultData saveHardwareRfid(HardwareRfid hardwareRfid);
+
+    /**
+     * 修改rfid硬件信息
+     * @Param [hardwareRfid]
+     * @Return com.zd.model.domain.ResultData
+     **/
+    ResultData updateHardwareRfid(HardwareRfid hardwareRfid);
+
+    /**
+     * 分页查询rfid硬件信息
+     * @Param [page, hardwareRfidVo]
+     * @Return com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.zd.algorithm.api.rfid.domain.entity.HardwareRfid>
+     **/
+    Page<HardwareRfid> search(Page<HardwareRfid> page, HardwareRfidVo hardwareRfidVo);
+
+    /**
+     * 根据硬件Id 打开/关闭rfid硬件设备
+     * @Param [id]
+     * @Return com.zd.model.domain.ResultData
+     **/
+    ResultData startOrStop(Long id);
+}

+ 8 - 5
zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/service/IRfidService.java

@@ -1,7 +1,7 @@
 package com.zd.alg.rfid.service;
 
 
-import com.zd.model.entity.RemoteLabHardware;
+import com.zd.algorithm.api.rfid.domain.entity.HardwareRfid;
 
 /**
  * @author Administrator
@@ -11,18 +11,21 @@ public interface IRfidService {
      * 启动RFID扫描器
      * @param hardware 设备数据
      */
-    void start(RemoteLabHardware hardware);
+//    void start(RemoteLabHardware hardware);
+    void start(HardwareRfid hardwareRfid);
 
     /**
      * 关闭RFID扫描器
      * @param hardware  设备数据
      */
-    void stop(RemoteLabHardware hardware);
+//    void stop(RemoteLabHardware hardware);
+    void stop(HardwareRfid hardwareRfid);
 
     /**
      * 启动警报
-     * @param hardware 设备数据
+     * @param hardwareRfid 设备数据
      * @return boolean
      */
-    boolean alarm(RemoteLabHardware hardware);
+//    boolean alarm(RemoteLabHardware hardware);
+    boolean alarm(HardwareRfid hardwareRfid);
 }

+ 2 - 1
zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/service/ISendService.java

@@ -11,13 +11,14 @@ public interface ISendService {
     /**
      * 发送读取到的编码
      *
-     * @param tag    rfid数据
+     * @param tag rfid数据
      * @return boolean
      */
     boolean send(InventoryTag tag);
 
     /**
      * 发送异常信息
+     *
      * @param msg 异常消息
      */
     void sendError(String msg);

+ 14 - 10
zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/service/IService.java

@@ -1,30 +1,34 @@
 package com.zd.alg.rfid.service;
 
 
-import com.zd.model.entity.RemoteLabHardware;
+import com.zd.algorithm.api.rfid.domain.entity.HardwareRfid;
 
 /**
  * RFID接口类
+ *
  * @author Administrator
  */
 public interface IService {
 
     /**
      * 启动RFID读写器
-     * @param hardware 设备数据
+     *
+     * @param hardwareRfid 设备数据
      */
-    void start(RemoteLabHardware hardware);
+    void start(HardwareRfid hardwareRfid);
 
     /**
      * 断开RFID读写器
-     * @param hardware 设备数据
+     *
+     * @param hardwareRfid 设备数据
      */
-    void disconnect(RemoteLabHardware hardware);
+    void disconnect(HardwareRfid hardwareRfid);
 
     /**
-     * 启动警报
-     * @param hardware 设备数据
-     * @return boolean
-     */
-    boolean alarm(RemoteLabHardware hardware);
+     *报警
+     *
+     * @Param [hardwareRfid]
+     * @Return boolean
+     **/
+    boolean alarm(HardwareRfid hardwareRfid);
 }

+ 103 - 0
zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/service/impl/HardwareRfidServiceImpl.java

@@ -0,0 +1,103 @@
+package com.zd.alg.rfid.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zd.alg.rfid.enums.ManufacturerTypeEnum;
+import com.zd.alg.rfid.mapper.HardwareRfidMapper;
+import com.zd.alg.rfid.service.HardwareRfidService;
+import com.zd.alg.rfid.service.IService;
+import com.zd.algorithm.api.rfid.domain.entity.HardwareRfid;
+import com.zd.algorithm.api.rfid.domain.vo.HardwareRfidVo;
+import com.zd.common.core.security.TokenService;
+import com.zd.common.core.utils.BeanUtils;
+import com.zd.common.core.utils.SecurityUtils;
+import com.zd.common.core.utils.SpringUtils;
+import com.zd.model.domain.ResultData;
+import com.zd.model.enums.DeviceOnOffEnum;
+import com.zd.model.enums.DeviceStatusEnum;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * @创建人 hzw
+ * @描述
+ * @创建时间 2022/11/15
+ */
+@Service
+@Transactional
+public class HardwareRfidServiceImpl extends ServiceImpl<HardwareRfidMapper, HardwareRfid> implements HardwareRfidService {
+
+    @Autowired
+    private TokenService tokenService;
+
+    @Override
+    public int batchInsert(List<HardwareRfid> list) {
+        return baseMapper.batchInsert(list);
+    }
+
+    @Override
+    public ResultData saveHardwareRfid(HardwareRfid hardwareRfid) {
+        if (baseMapper.selectCount(new LambdaQueryWrapper<HardwareRfid>().eq(HardwareRfid::getHardwareNum, hardwareRfid.getHardwareNum())) > 0) {
+            return ResultData.fail("设备编码已存在!");
+        }
+        tokenService.getLoginUser().getSysUser();
+        hardwareRfid.setCreateBy(SecurityUtils.getUsername());
+        hardwareRfid.setUserId(SecurityUtils.getUserId());
+        return ResultData.result(baseMapper.insert(hardwareRfid));
+    }
+
+    @Override
+    public ResultData updateHardwareRfid(HardwareRfid hardwareRfid) {
+        if (hardwareRfid.getId() == null) {
+            return ResultData.fail("设备id不存在!");
+        }
+        if (baseMapper.selectCount(new LambdaQueryWrapper<HardwareRfid>().eq(HardwareRfid::getHardwareNum, hardwareRfid.getHardwareNum()).ne(HardwareRfid::getId, hardwareRfid.getId())) > 0) {
+            return ResultData.fail("设备编码已存在!");
+        }
+        hardwareRfid.setUpdateBy(SecurityUtils.getUsername());
+        return ResultData.result(baseMapper.updateById(hardwareRfid));
+    }
+
+    @Override
+    public Page<HardwareRfid> search(Page<HardwareRfid> page, HardwareRfidVo hardwareRfidVo) {
+        if (StringUtils.isNotBlank(hardwareRfidVo.getSearchValue())) {
+            return baseMapper.selectPage(page, new LambdaQueryWrapper<HardwareRfid>().like(HardwareRfid::getHardwareNum, hardwareRfidVo.getSearchValue()).or().like(HardwareRfid::getDeptName, hardwareRfidVo.getSearchValue()).orderByDesc(HardwareRfid::getCreateTime));
+        }
+        HardwareRfid hardwareRfid = new HardwareRfid();
+        BeanUtils.copyProperties(hardwareRfidVo, hardwareRfid);
+        return baseMapper.selectPage(page, new LambdaQueryWrapper<HardwareRfid>().setEntity(hardwareRfid).orderByDesc(HardwareRfid::getCreateTime));
+    }
+
+    @Override
+    public ResultData startOrStop(Long id) {
+        HardwareRfid hardwareRfid = baseMapper.selectById(id);
+        if (Objects.isNull(hardwareRfid)) {
+            log.error("未查询到相关配置!");
+        }
+        if (DeviceOnOffEnum.ON.getCode().equals(hardwareRfid.getOnOff())) {
+            //开启状态 断开
+            rfidService(hardwareRfid.getManufacturerType()).disconnect(hardwareRfid);
+            hardwareRfid.setOnOff(DeviceOnOffEnum.OFF.getCode());
+            hardwareRfid.setDeviceStatus(DeviceStatusEnum.OFF_LINE.getCode());
+        } else {
+            //关闭状态 打开设备开关 启动
+            rfidService(hardwareRfid.getManufacturerType()).start(hardwareRfid);
+            hardwareRfid.setOnOff(DeviceOnOffEnum.ON.getCode());
+            hardwareRfid.setDeviceStatus(DeviceStatusEnum.ON_LINE.getCode());
+        }
+        if (baseMapper.updateById(hardwareRfid) > 0) {
+            return ResultData.success(hardwareRfid.getOnOff(), "设备已" + DeviceOnOffEnum.getValue(hardwareRfid.getOnOff()));
+        }
+        return ResultData.fail("开启或关闭失败!");
+    }
+
+    private IService rfidService(Integer type) {
+        return SpringUtils.getBean(ManufacturerTypeEnum.matchByValue(type).getService());
+    }
+}

+ 14 - 16
zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/service/impl/RfidServiceImpl.java

@@ -3,8 +3,8 @@ package com.zd.alg.rfid.service.impl;
 import com.zd.alg.rfid.enums.ManufacturerTypeEnum;
 import com.zd.alg.rfid.service.IRfidService;
 import com.zd.alg.rfid.service.IService;
+import com.zd.algorithm.api.rfid.domain.entity.HardwareRfid;
 import com.zd.common.core.utils.SpringUtils;
-import com.zd.model.entity.RemoteLabHardware;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Service;
@@ -23,37 +23,35 @@ import static com.zd.model.constant.BaseConstants.MAP_INIT_SIZE;
 public class RfidServiceImpl implements IRfidService {
 
     private final ThreadPoolTaskExecutor taskExecutor = SpringUtils.getBean("taskExecutor");
-
     private final Map<String, Thread> threadMap = new HashMap<>(MAP_INIT_SIZE);
 
-    private IService rfidService(Integer type) {
-        return SpringUtils.getBean(ManufacturerTypeEnum.matchByValue(type).getService());
-    }
-
     @Override
-    public void start(RemoteLabHardware hardware) {
+    public void start(HardwareRfid hardwareRfid) {
         synchronized (this){
             taskExecutor.execute(() -> {
-                rfidService(hardware.getManufacturerType()).start(hardware);
-                log.info("===================thread name:{}===============", Thread.currentThread().getName());
-                threadMap.computeIfAbsent(hardware.getIpAddress(), f -> Thread.currentThread());
+                rfidService(hardwareRfid.getManufacturerType()).start(hardwareRfid);
+                log.info("===============thread name:{}===============", Thread.currentThread().getName());
+                threadMap.computeIfAbsent(hardwareRfid.getIpAddress(), f -> Thread.currentThread());
                 log.info("==============>线程数量:{}",threadMap.size());
             });
         }
     }
 
     @Override
-    public void stop(RemoteLabHardware hardware) {
-        rfidService(hardware.getManufacturerType()).disconnect(hardware);
-        Thread thread = threadMap.get(hardware.getIpAddress());
+    public void stop(HardwareRfid hardwareRfid) {
+        rfidService(hardwareRfid.getManufacturerType()).disconnect(hardwareRfid);
+        Thread thread = threadMap.get(hardwareRfid.getIpAddress());
         if (thread != null && thread.isAlive()) {
             thread.interrupt();
-            threadMap.remove(hardware.getIpAddress());
+            threadMap.remove(hardwareRfid.getIpAddress());
         }
     }
 
     @Override
-    public boolean alarm(RemoteLabHardware hardware) {
-       return rfidService(hardware.getManufacturerType()).alarm(hardware);
+    public boolean alarm(HardwareRfid hardwareRfid) {
+       return rfidService(hardwareRfid.getManufacturerType()).alarm(hardwareRfid);
+    }
+    private IService rfidService(Integer type) {
+        return SpringUtils.getBean(ManufacturerTypeEnum.matchByValue(type).getService());
     }
 }

+ 14 - 19
zd-modules/zd-algorithm/src/main/java/com/zd/alg/rfid/service/impl/SendServiceImpl.java

@@ -6,6 +6,7 @@ import com.zd.bottle.feign.service.RemoteBottleService;
 import com.zd.chemical.api.fegin.RemoteStockService;
 import com.zd.model.constant.HttpStatus;
 import com.zd.model.domain.R;
+import com.zd.model.entity.HardwareRfidDto;
 import com.zd.model.entity.InventoryTag;
 import com.zd.model.entity.RemoteLabHardware;
 import lombok.extern.slf4j.Slf4j;
@@ -37,21 +38,15 @@ public class SendServiceImpl implements ISendService {
 
     @Override
     public boolean send(InventoryTag tag) {
-        String serialNumber = tag.getSerialNumber();
-        RemoteLabHardware hardware = tag.getRemoteLabHardware();
-        if (StringUtils.hasLength(serialNumber)){
-            log.info("===============》设备编码:{}",serialNumber);
-            hardware = redisTemplate.opsForValue().get(serialNumber);
-        }
-        if (hardware!=null){
-            log.info("=========ip:{},设备编码:{}=========",hardware.getIpAddress(),serialNumber);
+        HardwareRfidDto hardwareRfidDto = tag.getHardwareRfidDto();
+        if (hardwareRfidDto != null) {
             int antId = tag.getAntId();
-            String uniformPower = hardware.getUniformPower();
+            String uniformPower = hardwareRfidDto.getUniformPower();
             String[] uniformPowers = uniformPower.split(",");
             return handleTag(tag, antId, uniformPowers);
         }
-        log.info("=========未获取到设备信息=========");
-        return sendTag(tag,null);
+        log.error("未获取到设备信息");
+        return sendTag(tag, null);
     }
 
     private boolean handleTag(InventoryTag tag, int antId, String[] uniformPowers) {
@@ -74,14 +69,14 @@ public class SendServiceImpl implements ISendService {
     private boolean sendTag(InventoryTag tag, String temp) {
         if (temp == null) {
             boolean b = sendBottle(tag);
-            if (b){
+            if (b) {
                 return true;
             }
             return sendStock(tag);
         }
         if (ALL_TYPE.equals(temp)) {
             boolean b = sendBottle(tag);
-            if (b){
+            if (b) {
                 return true;
             }
             return sendStock(tag);
@@ -115,19 +110,19 @@ public class SendServiceImpl implements ISendService {
     private boolean sendBottle(InventoryTag tag) {
         R<Boolean> result;
         try {
-            log.info("=====================》气瓶服务开始调用");
+            log.info("======》气瓶服务开始调用");
             result = bottleService.remoteAdd(tag);
-            log.info("气瓶服务调用:" + result.getData());
+            log.info("======》气瓶服务调用结果:{},(true开启报警,false不报警)", result.getData());
             if (result.getCode() == HttpStatus.SUCCESS) {
-               return result.getData();
+                return result.getData();
             }
         } catch (Exception e) {
-            log.info("气瓶服务异常:" + e.getMessage());
+            log.info("气瓶服务异常:{}", e.getMessage());
         }
         try {
-            log.info("=====================》气瓶服务开始调用");
+            log.info("======》气瓶服务开始调用");
             result = remoteBottleService.remoteAdd(tag);
-            log.info("气瓶服务调用:" + result.getData());
+            log.info("======》新气瓶服务调用结果:{},(true开启报警,false不报警)",result.getData());
             if (result.getCode() == HttpStatus.SUCCESS) {
                 return result.getData();
             }

+ 56 - 0
zd-modules/zd-algorithm/src/main/resources/mapper/rfid/HardwareRfidMapper.xml

@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.zd.alg.rfid.mapper.HardwareRfidMapper">
+    <resultMap id="BaseResultMap" type="com.zd.algorithm.api.rfid.domain.entity.HardwareRfid">
+        <!--@mbg.generated-->
+        <!--@Table hardware_rfid-->
+        <id column="id" jdbcType="BIGINT" property="id"/>
+        <result column="device_name" jdbcType="VARCHAR" property="deviceName"/>
+        <result column="device_type" jdbcType="TINYINT" property="deviceType"/>
+        <result column="manufacturer_type" jdbcType="TINYINT" property="manufacturerType"/>
+        <result column="hardware_num" jdbcType="VARCHAR" property="hardwareNum"/>
+        <result column="ip_address" jdbcType="VARCHAR" property="ipAddress"/>
+        <result column="port" jdbcType="INTEGER" property="port"/>
+        <result column="uniform_power" jdbcType="VARCHAR" property="uniformPower"/>
+        <result column="session_index" jdbcType="TINYINT" property="sessionIndex"/>
+        <result column="channels" jdbcType="TINYINT" property="channels"/>
+        <result column="on_off" jdbcType="TINYINT" property="onOff"/>
+        <result column="device_status" jdbcType="TINYINT" property="deviceStatus"/>
+        <result column="subject_id" jdbcType="BIGINT" property="subjectId"/>
+        <result column="dept_id" jdbcType="BIGINT" property="deptId"/>
+        <result column="dept_name" jdbcType="VARCHAR" property="deptName"/>
+        <result column="user_id" jdbcType="BIGINT" property="userId"/>
+        <result column="create_by" jdbcType="VARCHAR" property="createBy"/>
+        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
+        <result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
+        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
+        <result column="remark" jdbcType="VARCHAR" property="remark"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        <!--@mbg.generated-->
+        id, device_name, device_type, manufacturer_type, hardware_num, ip_address, port,
+        uniform_power, session_index, channels, switch, device_status, subject_id, dept_id,
+        dept_name, user_id, create_by, create_time, update_by, update_time, remark
+    </sql>
+    <insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map" useGeneratedKeys="true">
+        <!--@mbg.generated-->
+        insert into hardware_rfid
+                (device_name, device_type, manufacturer_type, hardware_num, ip_address, port, uniform_power,
+                 session_index, channels, switch, device_status, subject_id, dept_id, dept_name,
+                 user_id, create_by, create_time, update_by, update_time, remark)
+                values
+        <foreach collection="list" item="item" separator=",">
+            (#{item.deviceName,jdbcType=VARCHAR}, #{item.deviceType,jdbcType=SMALLINT},
+             #{item.manufacturerType,jdbcType=TINYINT},
+             #{item.hardwareNum,jdbcType=VARCHAR}, #{item.ipAddress,jdbcType=VARCHAR}, #{item.port,jdbcType=INTEGER},
+             #{item.uniformPower,jdbcType=VARCHAR}, #{item.sessionIndex,jdbcType=BOOLEAN},
+             #{item.channels,jdbcType=TINYINT},
+             #{item.onOff,jdbcType=SMALLINT}, #{item.deviceStatus,jdbcType=SMALLINT}, #{item.subjectId,jdbcType=BIGINT},
+             #{item.deptId,jdbcType=CHAR}, #{item.deptName,jdbcType=VARCHAR}, #{item.userId,jdbcType=BIGINT},
+             #{item.createBy,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP},
+             #{item.updateBy,jdbcType=VARCHAR},
+             #{item.updateTime,jdbcType=TIMESTAMP}, #{item.remark,jdbcType=VARCHAR})
+        </foreach>
+    </insert>
+</mapper>

+ 7 - 6
zd-modules/zd-bottle-parent/zd-bottle/src/main/java/com/zd/bottle/service/impl/AlarmRecordServiceImpl.java

@@ -31,6 +31,7 @@ import com.zd.laboratory.api.feign.RemoteSubQueryService;
 import com.zd.model.constant.HttpStatus;
 import com.zd.model.domain.AjaxResult;
 import com.zd.model.domain.R;
+import com.zd.model.entity.HardwareRfidDto;
 import com.zd.model.entity.InventoryTag;
 import com.zd.model.entity.RemoteLabHardware;
 import com.zd.model.entity.SysFile;
@@ -127,7 +128,7 @@ public class AlarmRecordServiceImpl extends ServiceImpl<AlarmRecordMapper, Alarm
     @Transactional(rollbackFor = Exception.class)
     public synchronized boolean remoteAdd(InventoryTag tag) {
         String electronicTag = tag.getEpc();
-        RemoteLabHardware hardware = tag.getRemoteLabHardware();
+        HardwareRfidDto hardwareRfidDto = tag.getHardwareRfidDto();
         LambdaQueryWrapper<RfidTag> queryWrapper = Wrappers.lambdaQuery(RfidTag.class);
         queryWrapper.eq(RfidTag::getTagCode, electronicTag);
         RfidTag rfidTag = tagService.getOne(queryWrapper);
@@ -146,7 +147,7 @@ public class AlarmRecordServiceImpl extends ServiceImpl<AlarmRecordMapper, Alarm
             List<UsegasApply> applies = applyService.list(lambdaQuery);
             if (applies.isEmpty()) {
                 Long id = bottleStorage.getId();
-                R<SysFile> fileR = getFileR(tag, hardware);
+                R<SysFile> fileR = getFileR(tag, hardwareRfidDto);
                 String key = RFID_CODE + electronicTag + id;
                 String rfid = redisService.getCacheObject(key);
                 if (rfid != null) {
@@ -169,7 +170,7 @@ public class AlarmRecordServiceImpl extends ServiceImpl<AlarmRecordMapper, Alarm
                 return save(alarmRecord);
             }
         } else {
-            if (hardware != null) {
+            if (hardwareRfidDto != null) {
                 log.info(MSG_MATCH, electronicTag, "标签未绑定气瓶");
             }
         }
@@ -177,10 +178,10 @@ public class AlarmRecordServiceImpl extends ServiceImpl<AlarmRecordMapper, Alarm
     }
 
     @Nullable
-    private R<SysFile> getFileR(InventoryTag tag, RemoteLabHardware hardware) {
+    private R<SysFile> getFileR(InventoryTag tag, HardwareRfidDto hardwareRfidDto) {
         //触发RFID警报
-        if (hardware != null) {
-            R<Boolean> alarm = remoteRfidService.alarm(hardware);//RFID设备报警
+        if (hardwareRfidDto != null) {
+            R<Boolean> alarm = remoteRfidService.alarm(hardwareRfidDto);//RFID设备报警
             log.info(MSG_MATCH, alarm.getCode(), alarm.getMsg());
         } else {
             log.info("==================> rfid 参数有误!" + tag);

+ 4 - 4
zd-modules/zd-chemical/src/main/java/com/zd/chemical/service/impl/HxpStockServiceImpl.java

@@ -28,8 +28,8 @@ import com.zd.laboratory.api.feign.RemoteMessageContentService;
 import com.zd.model.domain.AjaxResult;
 import com.zd.model.domain.R;
 import com.zd.model.domain.per.PerPrefix;
+import com.zd.model.entity.HardwareRfidDto;
 import com.zd.model.entity.InventoryTag;
-import com.zd.model.entity.RemoteLabHardware;
 import com.zd.model.entity.SysFile;
 import com.zd.system.api.entity.SysDictData;
 import org.apache.commons.collections4.CollectionUtils;
@@ -353,10 +353,10 @@ public class HxpStockServiceImpl implements IHxpStockService {
                 logger.info("文件上传状态:{},接口返回消息:{},文件上传路径:{}",fileR.getCode(),fileR.getMsg(),fileR.getData());
             }
             //触发RFID警报
-            RemoteLabHardware hardware = tag.getRemoteLabHardware();
+            HardwareRfidDto hardwareRfidDto = tag.getHardwareRfidDto();
             boolean isAlarm = false;
-            if (hardware!=null){
-                R<Boolean> alarm = remoteRfidService.alarm(hardware);//RFID设备报警
+            if (hardwareRfidDto!=null){
+                R<Boolean> alarm = remoteRfidService.alarm(hardwareRfidDto);//RFID设备报警
                 logger.info("==================>{},{}",alarm.getCode(),alarm.getMsg());
                 //isAlarm = true;
             }else {

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

@@ -29,6 +29,7 @@ import com.zd.model.domain.R;
 import com.zd.model.domain.ResultData;
 import com.zd.model.domain.per.PerFun;
 import com.zd.model.domain.per.PerPrefix;
+import com.zd.model.entity.HardwareRfidDto;
 import com.zd.model.entity.RemoteLabHardware;
 import com.zd.model.enums.HardwareOperate;
 import com.zd.model.enums.HardwareTypeEnum;
@@ -387,13 +388,13 @@ public class LabHardwareController extends BaseController {
         if (labHardwareVO.getIpAddress()==null){
             return ResultData.fail("设备尚未配置IP");
         }
-        RemoteLabHardware remoteLabHardware=new RemoteLabHardware();
-        BeanUtils.copyProperties(labHardwareVO,remoteLabHardware);
-        remoteLabHardware.setType(labHardwareVO.getType().getHardwareTypeCode());
+        HardwareRfidDto hardwareRfidDto = new HardwareRfidDto();
+        BeanUtils.copyProperties(labHardwareVO,hardwareRfidDto);
+        hardwareRfidDto.setDeviceType(labHardwareVO.getType().getHardwareTypeCode());
         HardwareOperate operate = labHardwareVO.getOperate();
         if (operate==null || operate.getCode()==4){
             subjectManagerService.control(id, Symbol.command.open);
-            R<Boolean> result = rfidService.startMonitorChannels(remoteLabHardware);
+            R<Boolean> result = rfidService.startMonitorChannels(hardwareRfidDto);
             if (result.getCode()== HttpStatus.SUCCESS){
                 operate=HardwareOperate.OPEN;
             }else {
@@ -401,7 +402,7 @@ public class LabHardwareController extends BaseController {
             }
         }else {
             subjectManagerService.control(id, Symbol.command.close);
-            R<Boolean> result = rfidService.disconnect(remoteLabHardware);
+            R<Boolean> result = rfidService.disconnect(hardwareRfidDto);
             if (result.getCode()== HttpStatus.SUCCESS){
                 operate=HardwareOperate.CLOSE;
             }else {

+ 1 - 1
zd-modules/zd-modules-system/src/main/resources/mapper/system/SysUserMapper.xml

@@ -630,7 +630,7 @@
         set position = '未定'
         where user_id = #{userId}
     </update>
-<!--    <update id="updateUserStatus" parameterType="com.zd.model.entity.SysUser">-->
+<!--    <update id="updateUserStatus" parameterType="com.zd.model.domain.SysUser">-->
 <!-- 		update sys_user set status = #{status} where user_id = #{userId}-->
 <!--	</update>-->