Quellcode durchsuchen

永湖代码优化

ChenYang vor 1 Jahr
Ursprung
Commit
49a4b957e5

+ 7 - 0
package.xml

@@ -53,6 +53,13 @@
                 <include>logs</include>
             </includes>
         </fileSet>
+        <fileSet>
+            <directory>${basedir}/src/main/resources/lib</directory>
+            <outputDirectory>lib</outputDirectory>
+            <includes>
+                <include>*.jar</include>
+            </includes>
+        </fileSet>
     </fileSets>
     <!-- 依赖的 jar 包 copy 到 lib 目录下 -->
     <dependencySets>

+ 0 - 4
pom.xml

@@ -237,10 +237,6 @@
     <packaging>pom</packaging>
 
 
-    <dependencies>
-
-    </dependencies>
-
     <build>
         <plugins>
             <plugin>

+ 9 - 4
ruoyi-admin/pom.xml

@@ -15,6 +15,11 @@
         web服务入口
     </description>
 
+    <properties>
+        <project.name>${project.artifactId}-release-${project.parent.version}</project.name>
+        <project.build.libUrl>${project.build.directory}/${project.name}/${project.name}/lib</project.build.libUrl>
+    </properties>
+
     <dependencies>
 
         <!-- spring-boot-devtools -->
@@ -171,11 +176,11 @@
 
                         <configuration>
                             <!-- 打包生成的文件名 -->
-                            <finalName>${project.artifactId}</finalName>
+                            <finalName>${project.name}</finalName>
                             <!-- jar 等压缩文件在被打包进入 zip、tar.gz 时是否压缩,设置为 false 可加快打包速度 -->
                             <recompressZippedFiles>false</recompressZippedFiles>
-                            <!-- 打包生成的文件是否要追加 release.xml 中定义的 id 值 -->
-                            <appendAssemblyId>true</appendAssemblyId>
+                            <!-- 打包生成的文件是否要追加 package.xml 中定义的 id 值 -->
+                            <appendAssemblyId>false</appendAssemblyId>
                             <!-- 指向打包描述文件 package.xml -->
                             <descriptors>
                                 <descriptor>package.xml</descriptor>
@@ -199,4 +204,4 @@
         </plugins>
     </build>
 
-</project>
+</project>

+ 28 - 7
ruoyi-admin/src/main/resources/application-dev.yml

@@ -56,16 +56,37 @@ spring:
                 wall:
                     config:
                         multi-statement-allow: true
+    redis:
+        # 地址
+        host: 154.12.20.200
+        # 端口,默认为6379
+        port: 6379
+        # 数据库索引
+        database: 0
+        # 密码
+        password:
+        # 连接超时时间
+        timeout: 10s
+        lettuce:
+            pool:
+                # 连接池中的最小空闲连接
+                min-idle: 0
+                # 连接池中的最大空闲连接
+                max-idle: 8
+                # 连接池的最大数据库连接数
+                max-active: 8
+                # #连接池最大阻塞等待时间(使用负值表示没有限制)
+                max-wait: -1ms
+
+# 日志配置
+logging:
+    level:
+        com.ruoyi: info
+        org.springframework: info
 
 
 # 是否开启服务
 testtag:
     autosend: false
     aciservice: false
-    gsService: false
-
-# 日志配置
-logging:
-    level:
-        com.ruoyi: debug
-        org.springframework: debug
+    gsService: false

+ 27 - 5
ruoyi-admin/src/main/resources/application-prod.yml

@@ -55,6 +55,33 @@ spring:
                 wall:
                     config:
                         multi-statement-allow: true
+    redis:
+        # 地址
+        host: localhost
+        # 端口,默认为6379
+        port: 6379
+        # 数据库索引
+        database: 0
+        # 密码
+        password:
+        # 连接超时时间
+        timeout: 10s
+        lettuce:
+            pool:
+                # 连接池中的最小空闲连接
+                min-idle: 0
+                # 连接池中的最大空闲连接
+                max-idle: 8
+                # 连接池的最大数据库连接数
+                max-active: 8
+                # #连接池最大阻塞等待时间(使用负值表示没有限制)
+                max-wait: -1ms
+
+# 日志配置
+logging:
+    level:
+        com.ruoyi: info
+        org.springframework: info
 
 # 是否开启服务
 testtag:
@@ -62,8 +89,3 @@ testtag:
     aciservice: true
     gsService: true
 
-# 日志配置
-logging:
-    level:
-        com.ruoyi: info
-        org.springframework: info

+ 0 - 28
ruoyi-admin/src/main/resources/application.yml

@@ -30,12 +30,6 @@ server:
     # Tomcat启动初始化的线程数,默认值25
     min-spare-threads: 30
 
-# 日志配置
-logging:
-  level:
-    com.ruoyi: debug
-    org.springframework: warn
-
 # Spring配置
 spring:
   # 资源信息
@@ -56,28 +50,6 @@ spring:
     restart:
       # 热部署开关
       enabled: true
-  # redis 配置
-  redis:
-    # 地址
-    host: 154.12.20.200
-    # 端口,默认为6379
-    port: 6379
-    # 数据库索引
-    database: 0
-    # 密码
-    password:
-    # 连接超时时间
-    timeout: 10s
-    lettuce:
-      pool:
-        # 连接池中的最小空闲连接
-        min-idle: 0
-        # 连接池中的最大空闲连接
-        max-idle: 8
-        # 连接池的最大数据库连接数
-        max-active: 8
-        # #连接池最大阻塞等待时间(使用负值表示没有限制)
-        max-wait: -1ms
 
 # token配置
 token:

warewms-hard/src/main/resources/lib/RXTXcomm.jar → ruoyi-admin/src/main/resources/lib/RXTXcomm.jar


warewms-hard/src/main/resources/lib/jssc-2.8.0.jar → ruoyi-admin/src/main/resources/lib/jssc-2.8.0.jar


warewms-hard/src/main/resources/lib/modbus-spring-boot-starter.jar → ruoyi-admin/src/main/resources/lib/modbus-spring-boot-starter.jar


warewms-hard/src/main/resources/lib/modbus4j-3.0.5.jar → ruoyi-admin/src/main/resources/lib/modbus4j-3.0.5.jar


warewms-hard/src/main/resources/lib/rfid-1.0.0.jar → ruoyi-admin/src/main/resources/lib/rfid-1.0.0.jar


warewms-hard/src/main/resources/lib/rfid-zebra-spring-boot-starter.jar → ruoyi-admin/src/main/resources/lib/rfid-zebra-spring-boot-starter.jar


+ 11 - 7
warewms-hard/pom.xml

@@ -13,6 +13,10 @@
     <version>1.0</version>
     <description>硬件对接</description>
 
+    <properties>
+        <local.lib.basedir>${pom.basedir}/../ruoyi-admin/src/main/resources/lib</local.lib.basedir>
+    </properties>
+
     <dependencies>
         <!-- 若依框架 -->
         <dependency>
@@ -25,23 +29,23 @@
             <artifactId>modbus-spring-boot-starter</artifactId>
             <version>1.0</version>
             <scope>system</scope>
-            <systemPath>${basedir}/src/main/resources/lib/modbus-spring-boot-starter.jar</systemPath>
+            <systemPath>${local.lib.basedir}/modbus-spring-boot-starter.jar</systemPath>
         </dependency>
         <dependency>
             <groupId>com.jwk</groupId>
             <artifactId>rfid-zebra-spring-boot-starter</artifactId>
             <version>1.0</version>
             <scope>system</scope>
-            <systemPath>${basedir}/src/main/resources/lib/rfid-zebra-spring-boot-starter.jar</systemPath>
+            <systemPath>${local.lib.basedir}/rfid-zebra-spring-boot-starter.jar</systemPath>
         </dependency>
 
         <!-- rfid-zebra-只能跑在window上-->
         <dependency>
-            <groupId>com.warewms</groupId>
+            <groupId>com.jwk</groupId>
             <artifactId>rfid</artifactId>
             <version>1.0.0</version>
             <scope>system</scope>
-            <systemPath>${basedir}/src/main/resources/lib/rfid-1.0.0.jar</systemPath>
+            <systemPath>${local.lib.basedir}/rfid-1.0.0.jar</systemPath>
         </dependency>
 
         <!--modbus4j start-->
@@ -50,21 +54,21 @@
             <artifactId>RXTXcomm</artifactId>
             <version>3.0.5</version>
             <scope>system</scope>
-            <systemPath>${basedir}/src/main/resources/lib/RXTXcomm.jar</systemPath>
+            <systemPath>${local.lib.basedir}/RXTXcomm.jar</systemPath>
         </dependency>
         <dependency>
             <groupId>com.jwk</groupId>
             <artifactId>modbus4j</artifactId>
             <version>3.0.5</version>
             <scope>system</scope>
-            <systemPath>${basedir}/src/main/resources/lib/modbus4j-3.0.5.jar</systemPath>
+            <systemPath>${local.lib.basedir}/modbus4j-3.0.5.jar</systemPath>
         </dependency>
         <dependency>
             <groupId>com.jwk</groupId>
             <artifactId>jssc</artifactId>
             <version>2.8.0</version>
             <scope>system</scope>
-            <systemPath>${basedir}/src/main/resources/lib/jssc-2.8.0.jar</systemPath>
+            <systemPath>${local.lib.basedir}/jssc-2.8.0.jar</systemPath>
         </dependency>
         <!--modbus4j end-->
     </dependencies>

+ 265 - 0
warewms-hard/src/main/java/com/ruoyi/hard/modbus/tcp/AutoDoorClient.java

@@ -0,0 +1,265 @@
+package com.ruoyi.hard.modbus.tcp;
+
+import com.jwk.spring.boot.autoconfigure.ModbusTcpMasterTemplate;
+import com.jwk.spring.boot.modbus4j.ModbusMasterUtil;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.serotonin.modbus4j.msg.ReadResponse;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import java.util.HashMap;
+import java.util.Map;
+
+import static com.ruoyi.hard.modbus.tcp.AutoDoorClient.AUTOMATIC_DOOR_CODE.*;
+
+
+/**
+ * 自动门对接
+ *
+ * @author JWK
+ * @version 1.0
+ * @date 2022/12/21 21:04
+ */
+@Service
+public class AutoDoorClient {
+
+    /**
+     * 自动门(靠马路)
+     */
+    @Autowired(required = false)
+    @Qualifier("modbusTcpMasterTemplateFirst")
+    private ModbusTcpMasterTemplate modbusTcpMasterTemplateFirst;
+
+    /**
+     * 自动门(靠马路-第二层)
+     */
+    @Autowired(required = false)
+    @Qualifier("modbusTcpMasterTemplateSixth")
+    private ModbusTcpMasterTemplate modbusTcpMasterTemplateSixth;
+
+    /**
+     * 自动门
+     */
+    @Autowired(required = false)
+    @Qualifier("modbusTcpMasterTemplateSecond")
+    private ModbusTcpMasterTemplate modbusTcpMasterTemplateSecond;
+
+    /**
+     * 卷帘门
+     */
+    @Autowired(required = false)
+    @Qualifier("modbusTcpMasterTemplateSeventh")
+    private ModbusTcpMasterTemplate modbusTcpMasterTemplateSeventh;
+
+    private Map<String, ModbusTcpMasterTemplate> tcpMasterTemplateMap;
+
+    @PostConstruct
+    public void initMap() {
+        tcpMasterTemplateMap = new HashMap<>();
+        tcpMasterTemplateMap.put(AUTO_DOOR_NO.A.name(), modbusTcpMasterTemplateFirst);
+        tcpMasterTemplateMap.put(AUTO_DOOR_NO.B.name(), modbusTcpMasterTemplateSecond);
+        tcpMasterTemplateMap.put(AUTO_DOOR_NO.C.name(), modbusTcpMasterTemplateSixth);
+        tcpMasterTemplateMap.put(AUTO_DOOR_NO.D.name(), modbusTcpMasterTemplateSeventh);
+    }
+
+    public ModbusMasterUtil getModbusMasterUtil(AUTO_DOOR_NO doorNo) {
+        return tcpMasterTemplateMap.get(doorNo.name()).getModbusMasterUtil();
+    }
+
+    /**
+     * 自动门编号
+     */
+    public enum AUTO_DOOR_NO {
+        /***
+         * 靠墙门
+         */
+        A("1"),
+        /***
+         * 靠室内
+         */
+        B("2"),
+        /***
+         * 靠墙门(第二层)
+         */
+        C("3"),
+        /***
+         * 卷帘门
+         */
+        D("4");
+
+        private String value;
+
+        AUTO_DOOR_NO(String value) {
+            this.value = value;
+        }
+
+        public String getValue() {
+            return value;
+        }
+
+        /**
+         * 根据值获得枚举类型 switch
+         *
+         * @param value
+         * @return
+         */
+        public static AUTO_DOOR_NO getByValue(String value) {
+            for (AUTO_DOOR_NO code : values()) {
+                if (code.getValue().equals(value)) {
+                    return code;
+                }
+            }
+            return null;
+        }
+    }
+
+
+    /**
+     * 自动门命令
+     */
+    public enum AUTOMATIC_DOOR_CODE {
+        /**
+         * 开门
+         */
+        WRITE_OPEN(1, 0, 1, 0),
+        /**
+         * 关门
+         */
+        WRITE_CLOSE(1, 1, 1, 0),
+        /**
+         * 急停
+         */
+        WRITE_STOP(1, 2, 1, 0),
+        /***
+         * 开门状态
+         */
+        RAED_OPEN_STS(1, 10, 2, 0),
+        /**
+         * 关门状态
+         */
+        RAED_ClOSE_STS(1, 11, 2, 0);
+
+        /**
+         * 从节点id
+         */
+        private int slaveId;
+        /**
+         * 地址
+         */
+        private int offset;
+        /**
+         * 值
+         */
+        private int value;
+        /**
+         * 开关门清除标记
+         */
+        private int clear;
+
+        AUTOMATIC_DOOR_CODE(int slaveId, int offset, int value, int clear) {
+            this.slaveId = slaveId;
+            this.offset = offset;
+            this.value = value;
+            this.clear = clear;
+        }
+
+        public int getSlaveId() {
+            return slaveId;
+        }
+
+        public int getOffset() {
+            return offset;
+        }
+
+        public int getValue() {
+            return value;
+        }
+
+        public int getClear() {
+            return clear;
+        }
+    }
+
+
+    /**
+     * 开门
+     *
+     * @param doorNo
+     */
+    public Boolean sendOpen(AUTO_DOOR_NO doorNo) {
+        ModbusMasterUtil modbusMasterUtil = getModbusMasterUtil(doorNo);
+        sendCloseClear(doorNo);
+        Boolean r = modbusMasterUtil.writeHoldingRegisters(WRITE_OPEN.getSlaveId(), WRITE_OPEN.offset, WRITE_OPEN.getValue());
+        try {
+            Thread.sleep(1000);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+        sendOpenClear(doorNo);
+        return r;
+    }
+
+    /**
+     * 关门
+     *
+     * @param doorNo
+     */
+    public Boolean sendClose(AUTO_DOOR_NO doorNo) {
+        ModbusMasterUtil modbusMasterUtil = getModbusMasterUtil(doorNo);
+        sendOpenClear(doorNo);
+        Boolean r = modbusMasterUtil.writeHoldingRegisters(WRITE_CLOSE.getSlaveId(), WRITE_CLOSE.offset, WRITE_CLOSE.getValue());
+        try {
+            Thread.sleep(1000);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+        sendCloseClear(doorNo);
+        return r;
+    }
+
+    /**
+     * 开门清除标记
+     *
+     * @param doorNo
+     */
+    public Boolean sendOpenClear(AUTO_DOOR_NO doorNo) {
+        ModbusMasterUtil modbusMasterUtil = getModbusMasterUtil(doorNo);
+        return modbusMasterUtil.writeHoldingRegisters(WRITE_OPEN.getSlaveId(), WRITE_OPEN.offset, WRITE_OPEN.getClear());
+    }
+
+    /**
+     * 关门清除标记
+     *
+     * @param doorNo
+     */
+    public Boolean sendCloseClear(AUTO_DOOR_NO doorNo) {
+        ModbusMasterUtil modbusMasterUtil = getModbusMasterUtil(doorNo);
+        return modbusMasterUtil.writeHoldingRegisters(WRITE_CLOSE.getSlaveId(), WRITE_CLOSE.offset, WRITE_CLOSE.getClear());
+    }
+
+    /**
+     * 查询开门状态 暂时用不到
+     *
+     * @param
+     */
+    public AjaxResult readOpenSts(AUTO_DOOR_NO doorNo) {
+        ModbusMasterUtil modbusMasterUtil = getModbusMasterUtil(doorNo);
+        ReadResponse readResponse = modbusMasterUtil.readHoldingRegisters(RAED_OPEN_STS.getSlaveId(), RAED_OPEN_STS.getOffset(), RAED_OPEN_STS.getValue());
+        boolean[] booleanData = readResponse.getBooleanData();
+        return AjaxResult.success("", booleanData);
+    }
+
+    /**
+     * 查询关门门状态 暂时用不到
+     *
+     * @param doorNo
+     */
+    public AjaxResult readCloseSts(AUTO_DOOR_NO doorNo) {
+        ModbusMasterUtil modbusMasterUtil = getModbusMasterUtil(doorNo);
+        ReadResponse readResponse = modbusMasterUtil.readHoldingRegisters(RAED_ClOSE_STS.getSlaveId(), RAED_ClOSE_STS.getOffset(), RAED_ClOSE_STS.getValue());
+        boolean[] booleanData = readResponse.getBooleanData();
+        return AjaxResult.success("", booleanData);
+    }
+}

+ 202 - 0
warewms-hard/src/main/java/com/ruoyi/hard/modbus/tcp/ButtonBoxClient.java

@@ -0,0 +1,202 @@
+package com.ruoyi.hard.modbus.tcp;
+
+import com.jwk.spring.boot.autoconfigure.ModbusTcpMasterTemplate;
+import com.jwk.spring.boot.modbus4j.ModbusMasterUtil;
+import com.serotonin.modbus4j.msg.ReadResponse;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.stereotype.Service;
+
+import static com.ruoyi.hard.modbus.tcp.ButtonBoxClient.BUTTON_BOX_CODE.*;
+
+
+/**
+ * 按钮盒对接
+ *
+ * @author JWK
+ * @version 1.0
+ * @date 2022/12/21 21:04
+ */
+@Service
+public class ButtonBoxClient {
+
+    /**
+     * 按钮盒
+     */
+    @Autowired(required = false)
+    @Qualifier("modbusTcpMasterTemplateThird")
+    private ModbusTcpMasterTemplate modbusTcpMasterTemplateThird;
+
+    /**
+     * 按钮盒命令
+     */
+    public enum BUTTON_BOX_CODE {
+        /**
+         * 1号按钮状态 value代表读的长度(读到1代表按钮被按过) value1代表清除按下标记
+         */
+        BTN_STS_01(1, 1, 1, 0, 0, 0, 0),
+        /**
+         * 1号按钮状态 value代表读的长度(读到1代表按钮被按过) value1代表清除按下标记
+         */
+        BTN_STS_02(1, 2, 1, 0, 0, 0, 0),
+        /**
+         * 1号灯状态 value代表读的长度(0:灭 1:亮 2:快闪 3慢闪) value1-4代表写(0:灭 1:亮 2:快闪 3慢闪)
+         */
+        LAMP_STS_01(1, 5, 1, 0, 1, 2, 3),
+        /**
+         * 1号灯状态 value代表读的长度(0:灭 1:亮 2:快闪 3慢闪) value1-4代表写(0:灭 1:亮 2:快闪 3慢闪)
+         */
+        LAMP_STS_02(1, 6, 1, 0, 1, 2, 3);
+
+
+        /**
+         * 从节点id
+         */
+        private int slaveId;
+        /**
+         * 地址
+         */
+        private int offset;
+        /**
+         * 读的长度
+         */
+        private int value;
+        /**
+         * 写的值
+         */
+        private int value1;
+        private int value2;
+        private int value3;
+        private int value4;
+
+        BUTTON_BOX_CODE(int slaveId, int offset, int value, int value1, int value2, int value3, int value4) {
+            this.slaveId = slaveId;
+            this.offset = offset;
+            this.value = value;
+            this.value1 = value1;
+            this.value2 = value2;
+            this.value3 = value3;
+            this.value4 = value4;
+        }
+
+        public int getSlaveId() {
+            return slaveId;
+        }
+
+        public int getOffset() {
+            return offset;
+        }
+
+        public int getValue() {
+            return value;
+        }
+
+        public int getValue1() {
+            return value1;
+        }
+
+        public int getValue2() {
+            return value2;
+        }
+
+        public int getValue3() {
+            return value3;
+        }
+
+        public int getValue4() {
+            return value4;
+        }
+    }
+
+
+    /**
+     * 读按钮1状态
+     *
+     * @return true 代表按钮被按下
+     */
+    public Boolean readBtn01() {
+        short i = read(BTN_STS_01.getSlaveId(), BTN_STS_01.getOffset(), BTN_STS_01.getValue());
+        return i == 1;
+    }
+
+    /**
+     * 读按钮2状态
+     *
+     * @return true 代表按钮被按下
+     */
+    public Boolean readBtn02() {
+        short i = read(BTN_STS_02.getSlaveId(), BTN_STS_02.getOffset(), BTN_STS_02.getValue());
+        return i == 1;
+    }
+
+    /**
+     * 清除按钮1状态
+     *
+     * @return true
+     */
+    public Boolean clearBtn01() {
+        return write(BTN_STS_01.getSlaveId(), BTN_STS_01.getOffset(), BTN_STS_01.getValue1());
+    }
+
+    /**
+     * 清除按钮2状态
+     *
+     * @return true
+     */
+    public Boolean clearBtn02() {
+        return write(BTN_STS_02.getSlaveId(), BTN_STS_02.getOffset(), BTN_STS_02.getValue1());
+    }
+
+    /**
+     * 写灯1亮
+     *
+     * @return true
+     */
+    public Boolean writeLamp01Bright() {
+        return write(LAMP_STS_01.getSlaveId(), LAMP_STS_01.getOffset(), LAMP_STS_01.getValue2());
+    }
+
+    /**
+     * 写灯2亮
+     *
+     * @return true
+     */
+    public Boolean writeLamp02Bright() {
+        return write(LAMP_STS_02.getSlaveId(), LAMP_STS_02.getOffset(), LAMP_STS_02.getValue2());
+    }
+
+    /**
+     * 写灯1灭
+     *
+     * @return true
+     */
+    public Boolean writeLamp01Death() {
+        return write(LAMP_STS_01.getSlaveId(), LAMP_STS_01.getOffset(), LAMP_STS_01.getValue1());
+    }
+
+    /**
+     * 写灯2灭
+     *
+     * @return true
+     */
+    public Boolean writeLamp02Death() {
+        return write(LAMP_STS_02.getSlaveId(), LAMP_STS_02.getOffset(), LAMP_STS_02.getValue1());
+    }
+
+    private short read(int slaveId, int offset, int len) {
+        ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateThird.getModbusMasterUtil();
+        ReadResponse readResponse = modbusMasterUtil.readHoldingRegisters(slaveId, offset, len);
+        if (readResponse == null) {
+            return 0;
+        }
+        short[] shortData = readResponse.getShortData();
+        return shortData[0];
+    }
+
+
+    private Boolean write(int slaveId, int offset, int value) {
+        ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateThird.getModbusMasterUtil();
+        return modbusMasterUtil.writeHoldingRegisters(slaveId, offset, value);
+    }
+
+}

+ 395 - 0
warewms-hard/src/main/java/com/ruoyi/hard/modbus/tcp/ChargingMachineClient.java

@@ -0,0 +1,395 @@
+package com.ruoyi.hard.modbus.tcp;
+
+import com.jwk.spring.boot.autoconfigure.ModbusTcpMasterTemplate;
+import com.jwk.spring.boot.modbus4j.ModbusMasterUtil;
+import com.serotonin.modbus4j.msg.ReadResponse;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.stereotype.Service;
+
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import static com.ruoyi.hard.modbus.tcp.ChargingMachineClient.CHARGER_ADDRESS_MEANING.*;
+
+
+/**
+ * 充电机
+ *
+ * @author JWK
+ * @version 1.0
+ * @date 2022/9/9 15:03
+ */
+@Slf4j
+@Service
+public class ChargingMachineClient {
+
+    /**
+     * 充电机(三向车)
+     */
+    @Autowired(required = false)
+    @Qualifier("modbusTcpMasterTemplateFourth")
+    private ModbusTcpMasterTemplate modbusTcpMasterTemplateFourth;
+
+    /**
+     * 充电机(迷你堆垛)
+     */
+    @Autowired(required = false)
+    @Qualifier("modbusTcpMasterTemplateFifth")
+    private ModbusTcpMasterTemplate modbusTcpMasterTemplateFifth;
+
+    /**
+     * 充电机操作
+     *
+     * @param operation
+     * @return
+     */
+    public boolean operation(CHARGER_ADDRESS_MEANING operation, boolean con) {
+        switch (operation) {
+            // 启动
+            case START:
+                return start(con);
+            // 停止
+            case STOP:
+                return stop(con);
+            // 放电
+            case DISCHARGE:
+                return discharge(con);
+            default:
+                break;
+        }
+        return false;
+    }
+
+    /**
+     * 获取状态类型和状态对应关系表
+     *
+     * @return
+     */
+    public Map<CHARGER_STATUS, Boolean> getStatusMapping(boolean con) {
+        return ChargingMachineClient.CHARGER_STATUS.getMapping(getStatus(con));
+    }
+
+    /**
+     * 获取状态描述和状态对应关系表
+     *
+     * @return
+     */
+    public Map<String, Boolean> getStatusNameMapping(boolean con) {
+        return ChargingMachineClient.CHARGER_STATUS.getNameMapping(getStatus(con));
+    }
+
+    /**
+     * 获取充电机状态
+     * 第4个字节(状态代码) 第5个字节(故障代码) 第6个字节(各种状态,有些功能需要硬件支持)
+     * 返回3个字节 24位
+     * 假设3个字节为:00000110 00000101 00000100
+     * 则最终返回的数组:[0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
+     */
+    public boolean[] getStatus(boolean con) {
+        ModbusMasterUtil modbusMasterUtil = con ? modbusTcpMasterTemplateFourth.getModbusMasterUtil()
+                : modbusTcpMasterTemplateFifth.getModbusMasterUtil();
+        ReadResponse read = modbusMasterUtil.readCoils(1, CHARGER_STATUS.getOffset(), CHARGER_STATUS.getCommand());
+        if (read == null || read.getBooleanData() == null) {
+            log.error("获取充电机状态为空!");
+            return null;
+        }
+        if (read.getBooleanData().length != 24) {
+            log.error("获取充电机状态错误,不足24位:" + Arrays.toString(read.getBooleanData()));
+            return null;
+        }
+        return read.getBooleanData();
+    }
+
+    /**
+     * 启动充电机
+     *
+     * @return
+     */
+    private boolean start(boolean con) {
+        ModbusMasterUtil modbusMasterUtil = con ? modbusTcpMasterTemplateFourth.getModbusMasterUtil()
+                : modbusTcpMasterTemplateFifth.getModbusMasterUtil();
+        return modbusMasterUtil.writeCoil(1, START.getOffset(), START.getCommand());
+    }
+
+    /**
+     * 停止充电机
+     *
+     * @return
+     */
+    private boolean stop(boolean con) {
+        ModbusMasterUtil modbusMasterUtil = con ? modbusTcpMasterTemplateFourth.getModbusMasterUtil()
+                : modbusTcpMasterTemplateFifth.getModbusMasterUtil();
+        return modbusMasterUtil.writeCoil(1, STOP.getOffset(), STOP.getCommand());
+    }
+
+    /**
+     * 充电机放电
+     *
+     * @return
+     */
+    private boolean discharge(boolean con) {
+        ModbusMasterUtil modbusMasterUtil = con ? modbusTcpMasterTemplateFourth.getModbusMasterUtil()
+                : modbusTcpMasterTemplateFifth.getModbusMasterUtil();
+        return modbusMasterUtil.writeCoil(1, DISCHARGE.getOffset(), DISCHARGE.getCommand());
+    }
+
+    /**
+     * 功能码
+     */
+    public enum FUNCTION_CODE {
+        /***
+         * 读线圈寄存器
+         */
+        READ_01H(0x01),
+        /***
+         * 读保持寄存器
+         */
+        READ_03H(0x03),
+        /***
+         * 写单个线圈寄存器
+         */
+        WRITE_05H(0x05),
+        /***
+         * 写单个保持寄存器
+         */
+        WRITE_06H(0x06);
+
+        private Integer value;
+
+        FUNCTION_CODE(Integer value) {
+            this.value = value;
+        }
+
+        public Integer getValue() {
+            return value;
+        }
+    }
+
+    /**
+     * 充电机ModBus地址码
+     */
+    public enum CHARGER_ADDRESS_MEANING {
+        /***
+         * 启动充电机
+         */
+        START(FUNCTION_CODE.WRITE_05H, 0x0007, 0, 0x0007, 0XFF00),
+        /***
+         * 停止充电机
+         */
+        STOP(FUNCTION_CODE.WRITE_05H, 0x0007, 0, 0x0007, 0X0000),
+        /**
+         * 充电机放电
+         */
+        DISCHARGE(FUNCTION_CODE.WRITE_05H, 0x0008, 0, 0x0008, 0xFF00),
+        /**
+         * 充电机状态
+         */
+        CHARGER_STATUS(FUNCTION_CODE.READ_01H, 0x0040, 24, 0x0040, 0X0018),
+        /**
+         * 读取电压(/100)
+         */
+        READ_VOLTAGE(FUNCTION_CODE.READ_03H, 0x0065, 1, 0x0065, 0X0001),
+        /**
+         * 读取电流(/100)
+         */
+        READ_CURRENT(FUNCTION_CODE.READ_03H, 0x0066, 1, 0x0066, 0X0001),
+        /**
+         * 读取当前容量(/100)
+         */
+        READ_CAPACITY(FUNCTION_CODE.READ_03H, 0x0067, 1, 0x0067, 0X0001),
+        /**
+         * 时
+         */
+        HOURS(FUNCTION_CODE.READ_03H, 0x0068, 1, 0x0068, 0X0001),
+        /**
+         * 钟
+         */
+        MINUTES(FUNCTION_CODE.READ_03H, 0x0069, 1, 0x0069, 0X0001),
+        /**
+         * 秒
+         */
+        SECONDS(FUNCTION_CODE.READ_03H, 0x006A, 1, 0x006A, 0X0001),
+        /**
+         * 设置电压29.00V
+         */
+        SET_VOLTAGE(FUNCTION_CODE.WRITE_06H, 0x0090, 0, 0x0090, 0X0B54),
+        /**
+         * 设置电流29.00A
+         */
+        SET_CURRENT(FUNCTION_CODE.WRITE_06H, 0x0091, 0, 0x0091, 0X0B54),
+        /**
+         * 离线
+         */
+        SET_OFFLINE(FUNCTION_CODE.WRITE_06H, 0x0092, 0, 0x0092, 0X000),
+        /**
+         * 自动
+         */
+        SET_AUTO(FUNCTION_CODE.WRITE_06H, 0x0092, 0, 0x0092, 0X001),
+        /**
+         * 在线
+         */
+        SET_ONLINE(FUNCTION_CODE.WRITE_06H, 0x0092, 0, 0x0092, 0X002);
+
+        /**
+         * 功能码
+         */
+        private FUNCTION_CODE functionCode;
+
+        /**
+         * 读取和写入的开始偏移量
+         */
+        private int offset;
+
+        /**
+         * 长度 10进制
+         */
+        private int length;
+
+        /**
+         * PLC地址
+         */
+        private int address;
+
+        /**
+         * 命令
+         */
+        private int command;
+
+        CHARGER_ADDRESS_MEANING(FUNCTION_CODE functionCode, int offset, int length, int address, int command) {
+            this.functionCode = functionCode;
+            this.offset = offset;
+            this.length = length;
+            this.address = address;
+            this.command = command;
+        }
+
+        public FUNCTION_CODE getFunctionCode() {
+            return functionCode;
+        }
+
+        public int getOffset() {
+            return offset;
+        }
+
+        public int getLength() {
+            return length;
+        }
+
+        public int getAddress() {
+            return address;
+        }
+
+        public int getCommand() {
+            return command;
+        }
+    }
+
+    /**
+     * 充电机状态:
+     * 第4个字节(状态代码) 第5个字节(故障代码) 第6个字节(各种状态,有些功能需要硬件支持)
+     * 假设:第4个字节[00000110] 第5个字节[00000101] 第6个[00000100]
+     * 放在同一个数组中表示:[0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
+     */
+    public enum CHARGER_STATUS {
+
+        // 4bit
+        BIT_04_0("待机", 0),
+        BIT_04_1("故障", 1),
+        BIT_04_2("进行", 2),
+        BIT_04_3("完成", 3),
+        BIT_04_4("离线", 4),
+        BIT_04_5("在线", 5),
+        BIT_04_6("空", 6),
+        BIT_04_7("空", 7),
+
+        // 5bit
+        BIT_05_0("总故障", 8),
+        BIT_05_1("过流", 9),
+        BIT_05_2("过压", 10),
+        BIT_05_3("短路", 11),
+        BIT_05_4("电池未接", 12),
+        BIT_05_5("电池反接", 13),
+        BIT_05_6("模块通信故障", 14),
+        BIT_05_7("Can通信超时", 15),
+
+        // 6bit
+        BIT_06_0("归位", 16),
+        BIT_06_1("正在伸出", 17),
+        BIT_06_2("正在退回", 18),
+        BIT_06_3("伸出充电", 19),
+        BIT_06_4("伸出到底", 20),
+        BIT_06_5("伸缩故障", 21),
+        BIT_06_6("压紧", 22),
+        BIT_06_7("红外到位", 23);
+
+        /**
+         * 判断某位是否为true
+         *
+         * @param booleans
+         * @return
+         */
+        public boolean isTrue(boolean[] booleans) {
+            return booleans[this.getIndex()];
+        }
+
+        /**
+         * 获取枚举类型和状态对应关系表
+         *
+         * @param booleans
+         * @return
+         */
+        public static Map<CHARGER_STATUS, Boolean> getMapping(boolean[] booleans) {
+            if (booleans == null) {
+                return null;
+            }
+            Map<CHARGER_STATUS, Boolean> map = new LinkedHashMap<>();
+            for (CHARGER_STATUS value : values()) {
+                map.put(value, value.isTrue(booleans));
+            }
+            return map;
+        }
+
+        /**
+         * 获取描述和状态对应关系表
+         *
+         * @param booleans
+         * @return
+         */
+        public static Map<String, Boolean> getNameMapping(boolean[] booleans) {
+            if (booleans == null) {
+                return null;
+            }
+            Map<String, Boolean> map = new LinkedHashMap<>();
+            Map<CHARGER_STATUS, Boolean> mapping = getMapping(booleans);
+            mapping.forEach((k, v) -> map.put(k.getDescription(), v));
+            mapping.remove(BIT_04_6.getDescription());
+            return map;
+        }
+
+        /**
+         * 状态描述
+         */
+        private String description;
+        /**
+         * 在数组中下标
+         */
+        private int index;
+
+        CHARGER_STATUS(String description, int index) {
+            this.description = description;
+            this.index = index;
+        }
+
+        public String getDescription() {
+            return description;
+        }
+
+        public int getIndex() {
+            return index;
+        }
+    }
+
+}

+ 67 - 0
warewms-hard/src/main/java/com/ruoyi/hard/modbus/tcp/WarningLightClient.java

@@ -0,0 +1,67 @@
+package com.ruoyi.hard.modbus.tcp;
+
+import com.jwk.spring.boot.autoconfigure.ModbusTcpMasterTemplate;
+import com.jwk.spring.boot.modbus4j.ModbusMasterUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.stereotype.Service;
+
+
+/**
+ * 警报灯对接
+ *
+ * @author JWK
+ * @version 1.0
+ * @date 2022/04/16 21:04
+ */
+@Slf4j
+@Service
+public class WarningLightClient {
+
+    /**
+     * 警报灯对接
+     */
+    @Autowired(required = false)
+    @Qualifier("modbusTcpMasterTemplateEighth")
+    private ModbusTcpMasterTemplate modbusTcpMasterTemplateEighth;
+
+
+    /**
+     * 开警报灯
+     *
+     * @return
+     */
+    public Boolean openWarningLight() {
+        ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateEighth.getModbusMasterUtil();
+        Boolean do1 = false;//打开DO1中间端
+        Boolean do3 = false;//打开DO3中间端
+        try {
+            do1 = modbusMasterUtil.writeCoil(0x20, 0x0000, 0xFF00);
+            do3 = modbusMasterUtil.writeCoil(0x20, 0x0002, 0xFF00);
+        } catch (Exception e) {
+            log.error("开警报灯失败!", e);
+        }
+        return do1 && do3;
+    }
+
+    /**
+     * 关警报灯
+     *
+     * @return
+     */
+    public Boolean closeWarningLight() {
+        ModbusMasterUtil modbusMasterUtil = modbusTcpMasterTemplateEighth.getModbusMasterUtil();
+        Boolean do1 = false;//关闭DO1中间端
+        Boolean do3 = false;//关闭DO3中间端
+        try {
+            do1 = modbusMasterUtil.writeCoil(0x20, 0x0000, 0x0000);//关闭DO1中间端
+            do3 = modbusMasterUtil.writeCoil(0x20, 0x0002, 0x0000);//关闭DO3中间端
+        } catch (Exception e) {
+            log.error("关警报灯失败!", e);
+        }
+        return do1 && do3;
+    }
+
+
+}

+ 104 - 0
warewms-hard/src/main/java/com/ruoyi/hard/rfid/RFIDReaderClient.java

@@ -0,0 +1,104 @@
+package com.ruoyi.hard.rfid;
+
+import com.jwk.spring.boot.autoconfigure.RfidReaderTemplate;
+import com.jwk.spring.boot.rfid.RfidReaderUtil;
+import com.mot.rfid.api3.TagData;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.stereotype.Service;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
+
+/**
+ * RFID对接
+ *
+ * @author JWK
+ * @version 1.0
+ * @date 2022/12/21 21:04
+ */
+@Slf4j
+@Service
+public class RFIDReaderClient {
+
+
+    @Autowired(required = false)
+    @Qualifier("rfidReaderTemplateFirst")
+    private RfidReaderTemplate rfidReaderTemplateFirst;
+    @Autowired(required = false)
+    @Qualifier("rfidReaderTemplateSecond")
+    private RfidReaderTemplate rfidReaderTemplateSecond;
+
+
+    /**
+     * 读取标签 墙外
+     *
+     * @return
+     */
+    public List<String> readTagsOut() {
+        RfidReaderUtil rfidReaderUtil = rfidReaderTemplateFirst.getRfidReaderUtil();
+        TagData[] tagData = rfidReaderUtil.readTags();
+        if (tagData == null) {
+            return null;
+        }
+        return Arrays.stream(tagData).map(v -> v.getTagID()).collect(Collectors.toList());
+    }
+
+    /**
+     * 读取标签 室内
+     *
+     * @return
+     */
+    public List<String> readTagsIn() {
+        RfidReaderUtil rfidReaderUtil = rfidReaderTemplateSecond.getRfidReaderUtil();
+        TagData[] tagData = rfidReaderUtil.readTags();
+        if (tagData == null) {
+            return null;
+        }
+        return Arrays.stream(tagData).map(v -> v.getTagID()).collect(Collectors.toList());
+    }
+
+    /**
+     * 读取标签测试 墙外
+     */
+    public void readTagsOutTest() {
+        RfidReaderUtil rfidReaderUtil = rfidReaderTemplateFirst.getRfidReaderUtil();
+        for (; ; ) {
+            TagData[] tagData = rfidReaderUtil.readTags();
+            if (tagData == null) {
+                log.error("读取标签为空!");
+            } else {
+                List<String> tagIdList = Arrays.stream(tagData).map(v -> v.getTagID()).collect(Collectors.toList());
+                String[] strings = new String[tagIdList.size()];
+                String[] tagIds = tagIdList.toArray(strings);
+                System.out.println("--------------RFID读取标签--------------------");
+                Arrays.stream(tagIds).forEach(v -> System.out.println(v));
+                System.out.println("--------------RFID读取标签--------------------");
+            }
+        }
+    }
+
+    /**
+     * 读取标签测试 室内
+     */
+    public void readTagsInTest() {
+        RfidReaderUtil rfidReaderUtil = rfidReaderTemplateSecond.getRfidReaderUtil();
+        for (; ; ) {
+            TagData[] tagData = rfidReaderUtil.readTags();
+            if (tagData == null) {
+                log.error("读取标签为空!");
+            } else {
+                List<String> tagIdList = Arrays.stream(tagData).map(v -> v.getTagID()).collect(Collectors.toList());
+                String[] strings = new String[tagIdList.size()];
+                String[] tagIds = tagIdList.toArray(strings);
+                System.out.println("--------------RFID读取标签--------------------");
+                Arrays.stream(tagIds).forEach(v -> System.out.println(v));
+                System.out.println("--------------RFID读取标签--------------------");
+            }
+        }
+    }
+}