Browse Source

事件整理

qzyReal 1 year ago
parent
commit
57cfe8480f

+ 1 - 0
app.pid

@@ -0,0 +1 @@
+21564

+ 8 - 5
config.xml

@@ -3,17 +3,20 @@
 <config>
     <eventList>
         <event>
-            <name>PLC.LED_READ</name>
+            <name>WEIGHBRIDGE.READ</name>
+            <!--动作格式 模块.命令-->
             <actionList>
-                <action>LED_SHOW_CONTENT(led初始化成功)</action>
+                <action>LED.LED_SHOW_CONTENT(地磅初始化)</action>
                 <action>CENTER.TIMER_SLEEP(1500)</action>
+                <action>LED.LED_SHOW_CONTENT(地磅初始化成功)</action>
             </actionList>
         </event>
         <event>
-            <name>RED_READ</name>
+            <name>LED.READ</name>
             <actionList>
-                <action>LED_SHOW_CONTENT(红外初始化成功)</action>
-                <action>LED_SHOW_CONTENT(欢迎使用红外)</action>
+                <action>LED.LED_SHOW_CONTENT(红外初始化=======)</action>
+                <action>CENTER.TIMER_SLEEP(10000)</action>
+                <action>LED.LED_SHOW_CONTENT(欢迎使用红外)</action>
             </actionList>
         </event>
     </eventList>

+ 5 - 5
src/main/java/com/gzlh/api/OpenApi.java

@@ -1,7 +1,10 @@
 package com.gzlh.api;
 
+import com.gzlh.config.ModuleEnum;
 import com.gzlh.event.EventBus;
+import com.gzlh.led.event.LedDefaultEvent;
 import com.gzlh.utils.ResultJson;
+import com.gzlh.weighbridge.event.WeighbridgeEvent;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -18,11 +21,8 @@ public class OpenApi {
 
     @RequestMapping("test")
     public ResultJson test(){
-        eventBus.start("LED_SHOW_CONTENT");
-        eventBus.start("LED_SHOW_CONTENT");
-        eventBus.start("LED_SHOW_CONTENT");
-        eventBus.start("LED_SHOW_CONTENT");
-        eventBus.start("LED_SHOW_CONTENT");
+        eventBus.start(ModuleEnum.LED_MODULE.getModuleEn()+"."+ LedDefaultEvent.READ);
+        eventBus.start(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn()+"."+ WeighbridgeEvent.READ);
         return ResultJson.success();
     }
 }

+ 13 - 6
src/main/java/com/gzlh/config/ModuleEnum.java

@@ -6,14 +6,21 @@ import lombok.Getter;
 @AllArgsConstructor
 @Getter
 public enum ModuleEnum {
-    LED_MODULE("led显示屏","led"),
-    WEIGHBRIDGE_MODULE("地磅","weighbridge"),
-    INFRARED_MODULE("红外","infrared"),
-    TRAFFIC_MODULE("红绿灯","traffic"),
-    GATE_MODULE("红绿灯","gate"),
-    CENTER_MODULE("action调度中心","center"),
+    LED_MODULE("led显示屏","LED"),
+    WEIGHBRIDGE_MODULE("地磅","WEIGHBRIDGE"),
+    INFRARED_MODULE("红外","INFRARED"),
+    TRAFFIC_MODULE("红绿灯","TRAFFIC"),
+    GATE_MODULE("红绿灯","GATE"),
+    PLC_MODULE("PLC","PLC"),
+    CENTER_MODULE("action调度中心","CENTER"),
 
     ;
+    /**
+     * 模块(硬件)中文名
+     */
     private String moduleZh;
+    /**
+     * 模块(硬件)英文
+     */
     private String moduleEn;
 }

+ 22 - 29
src/main/java/com/gzlh/event/EventThread.java

@@ -4,6 +4,7 @@ import cn.hutool.core.thread.ThreadUtil;
 import cn.hutool.core.util.NumberUtil;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.hutool.extra.spring.SpringUtil;
 import com.gzlh.config.ModuleEnum;
 import com.gzlh.dto.EventDTO;
 import com.gzlh.infrared.config.RedPropertiesConfig;
@@ -22,22 +23,12 @@ import java.util.List;
 public class EventThread extends Thread{
     private List<EventDTO> eventDTOList;
     private String eventName;
-    @Resource
-    private LedFactory ledFactory;
-    @Resource
-    private RedFactory redFactory;
-    @Resource
-    WeighbridgeFactory weighbridgeFactory;
-
-    @Resource
-    private WeighbridgePropertiesConfig weighbridgePropertiesConfig;
-    @Resource
-    private RedPropertiesConfig redPropertiesConfig;
-    @Resource
-    private LedPropertiesConfig ledPropertiesConfig;
-
-    public EventThread() {
-    }
+    private final LedFactory ledFactory=SpringUtil.getBean(LedFactory.class);
+    private final RedFactory redFactory=SpringUtil.getBean(RedFactory.class);
+    private  final WeighbridgeFactory weighbridgeFactory=SpringUtil.getBean(WeighbridgeFactory.class);
+    private final WeighbridgePropertiesConfig weighbridgePropertiesConfig=SpringUtil.getBean(WeighbridgePropertiesConfig.class);
+    private final RedPropertiesConfig redPropertiesConfig=SpringUtil.getBean(RedPropertiesConfig.class);
+    private final LedPropertiesConfig ledPropertiesConfig=SpringUtil.getBean(LedPropertiesConfig.class);
 
     public EventThread(String eventName) {
         this.setName(eventName);
@@ -57,23 +48,25 @@ public class EventThread extends Thread{
      */
     public void handlerEvent(String eventName) {
         log.info("event:{}", eventName);
-
         eventDTOList.stream().filter(eventDTO -> StrUtil.equals(eventName, eventDTO.getName()))
                 .findFirst().ifPresent(eventDTO -> {
-
             List<String> actionList = eventDTO.getActionList().getAction();
             //依次执行动作
             actionList.forEach(action -> {
-                String actionPrefix = StrUtil.subBefore(action, ".", true).toLowerCase();
-                String actionCommand = StrUtil.subAfter(action, ".", true).toUpperCase();
-                if (StrUtil.equals(actionPrefix, ModuleEnum.INFRARED_MODULE.getModuleEn())) {
-                    redFactory.handler(redPropertiesConfig.getBrand()).handlerAction(actionCommand);
-                } else if (StrUtil.equals(actionPrefix, ModuleEnum.LED_MODULE.getModuleEn())) {
-                    ledFactory.handler(ledPropertiesConfig.getBrand()).handlerAction(actionCommand);
-                } else if (StrUtil.equals(actionPrefix, ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn())) {
-                    weighbridgeFactory.handler(weighbridgePropertiesConfig.getBrand()).handlerAction(actionCommand);
-                } else if (StrUtil.equals(actionPrefix, ModuleEnum.CENTER_MODULE.getModuleEn())) {
-                    handlerAction(actionCommand);
+                String module = StrUtil.subBefore(action, ".", true);
+                String command = StrUtil.subAfter(action, ".", true);
+                if (StrUtil.equals(module, ModuleEnum.INFRARED_MODULE.getModuleEn())) {
+                    //动作属于红外
+                    redFactory.handler(redPropertiesConfig.getBrand()).handlerAction(command);
+                } else if (StrUtil.equals(module, ModuleEnum.LED_MODULE.getModuleEn())) {
+                    //动作属于led
+                    ledFactory.handler(ledPropertiesConfig.getBrand()).handlerAction(command);
+                } else if (StrUtil.equals(module, ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn())) {
+                    //动作属于地磅
+                    weighbridgeFactory.handler(weighbridgePropertiesConfig.getBrand()).handlerAction(command);
+                } else if (StrUtil.equals(module, ModuleEnum.CENTER_MODULE.getModuleEn())) {
+                    //动作属于中心总线
+                    handlerAction(command);
                 }
                 ThreadUtil.sleep(250);
             });
@@ -99,7 +92,7 @@ public class EventThread extends Thread{
      * @param action
      */
     private void handlerSleep(String action) {
-        String time = StrUtil.subAfter(StrUtil.subAfter(action, "(", true), ")", true);
+        String time = StrUtil.subBefore(StrUtil.subAfter(action, "(", true), ")", true);
         if (NumberUtil.isInteger(time)) {
             ThreadUtil.sleep(Long.parseLong(time));
         }

+ 12 - 0
src/main/java/com/gzlh/led/event/LedDefaultEvent.java

@@ -0,0 +1,12 @@
+package com.gzlh.led.event;
+
+/**
+ * led内置事件
+ */
+public interface LedDefaultEvent {
+    /**
+     * 超时事件
+     */
+    String TIMEOUT = "TIMEOUT";
+    String READ = "READ";
+}

+ 4 - 0
src/main/java/com/gzlh/weighbridge/event/WeighbridgeEvent.java

@@ -1,5 +1,9 @@
 package com.gzlh.weighbridge.event;
 
+/**
+ * 地磅内置事件
+ */
 public interface WeighbridgeEvent {
+    String READ="READ";
     String TIMEOUT="TIMEOUT";
 }

+ 3 - 3
src/main/resources/application.yml

@@ -9,18 +9,18 @@ weighbridge:
   port: 9096
   brand: 3000
   min-kg: 1000
-  enable: true
+  enable: false
 
 led:
   host: 127.0.0.1
   port: 4008
   brand: 1000
-  enable: true
+  enable: false
 red:
     host: 127.0.0.1
     port: 4002
     brand: 2000
-    enable: true
+    enable: false
 gate:
   brand: 4000
   gate-port: 8131