Explorar el Código

按钮盒业务逻辑开发完成(差下发模具搬运任务)

k hace 2 años
padre
commit
4c8fa39aa5

+ 93 - 48
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java

@@ -1,161 +1,206 @@
 package com.ruoyi.common.core.domain;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
+
+import com.alibaba.fastjson.JSON;
 import com.ruoyi.common.constant.HttpStatus;
+import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.utils.StringUtils;
+import org.apache.poi.ss.formula.functions.T;
 
 /**
  * 操作消息提醒
- * 
+ *
  * @author ruoyi
  */
-public class AjaxResult extends HashMap<String, Object>
-{
+public class AjaxResult extends HashMap<String, Object> {
     private static final long serialVersionUID = 1L;
 
-    /** 状态码 */
+    /**
+     * 状态码
+     */
     public static final String CODE_TAG = "code";
 
-    /** 返回内容 */
+    /**
+     * 返回内容
+     */
     public static final String MSG_TAG = "msg";
 
-    /** 数据对象 */
+    /**
+     * 数据对象
+     */
     public static final String DATA_TAG = "data";
 
     /**
      * 初始化一个新创建的 AjaxResult 对象,使其表示一个空消息。
      */
-    public AjaxResult()
-    {
+    public AjaxResult() {
     }
 
     /**
      * 初始化一个新创建的 AjaxResult 对象
-     * 
+     *
      * @param code 状态码
-     * @param msg 返回内容
+     * @param msg  返回内容
      */
-    public AjaxResult(int code, String msg)
-    {
+    public AjaxResult(int code, String msg) {
         super.put(CODE_TAG, code);
         super.put(MSG_TAG, msg);
     }
 
     /**
      * 初始化一个新创建的 AjaxResult 对象
-     * 
+     *
      * @param code 状态码
-     * @param msg 返回内容
+     * @param msg  返回内容
      * @param data 数据对象
      */
-    public AjaxResult(int code, String msg, Object data)
-    {
+    public AjaxResult(int code, String msg, Object data) {
         super.put(CODE_TAG, code);
         super.put(MSG_TAG, msg);
-        if (StringUtils.isNotNull(data))
-        {
+        if (StringUtils.isNotNull(data)) {
             super.put(DATA_TAG, data);
         }
     }
 
+    /**
+     * 是否成功
+     *
+     * @return
+     */
+    public boolean isSuccess() {
+        return (int) super.get(CODE_TAG) == 200;
+    }
+
+    /**
+     * 获取反馈
+     *
+     * @return
+     */
+    public String getMsg() {
+        return (String) super.get(MSG_TAG);
+    }
+
+    /**
+     * 获取数据
+     *
+     * @return
+     */
+    public Object getData() {
+        return super.get(DATA_TAG);
+    }
+
+    /**
+     * 获取数据
+     *
+     * @return
+     */
+    public <T> T getDataParseObject(Class<T> clazz) {
+        String json = JSON.toJSONString(getData());
+        return JSON.parseObject(json, clazz);
+    }
+
+    /**
+     * 获取数据
+     *
+     * @return
+     */
+    public <T> List<T> getDataParseArray(Class<T> clazz) {
+        String json = JSON.toJSONString(getData());
+        return JSON.parseArray(json, clazz);
+    }
+
     /**
      * 返回成功消息
-     * 
+     *
      * @return 成功消息
      */
-    public static AjaxResult success()
-    {
+    public static AjaxResult success() {
         return AjaxResult.success("操作成功");
     }
 
     /**
      * 返回成功数据
-     * 
+     *
      * @return 成功消息
      */
-    public static AjaxResult success(Object data)
-    {
+    public static AjaxResult success(Object data) {
         return AjaxResult.success("操作成功", data);
     }
 
     /**
      * 返回成功消息
-     * 
+     *
      * @param msg 返回内容
      * @return 成功消息
      */
-    public static AjaxResult success(String msg)
-    {
+    public static AjaxResult success(String msg) {
         return AjaxResult.success(msg, null);
     }
 
     /**
      * 返回成功消息
-     * 
-     * @param msg 返回内容
+     *
+     * @param msg  返回内容
      * @param data 数据对象
      * @return 成功消息
      */
-    public static AjaxResult success(String msg, Object data)
-    {
+    public static AjaxResult success(String msg, Object data) {
         return new AjaxResult(HttpStatus.SUCCESS, msg, data);
     }
 
     /**
      * 返回错误消息
-     * 
+     *
      * @return
      */
-    public static AjaxResult error()
-    {
+    public static AjaxResult error() {
         return AjaxResult.error("操作失败");
     }
 
     /**
      * 返回错误消息
-     * 
+     *
      * @param msg 返回内容
      * @return 警告消息
      */
-    public static AjaxResult error(String msg)
-    {
+    public static AjaxResult error(String msg) {
         return AjaxResult.error(msg, null);
     }
 
     /**
      * 返回错误消息
-     * 
-     * @param msg 返回内容
+     *
+     * @param msg  返回内容
      * @param data 数据对象
      * @return 警告消息
      */
-    public static AjaxResult error(String msg, Object data)
-    {
+    public static AjaxResult error(String msg, Object data) {
         return new AjaxResult(HttpStatus.ERROR, msg, data);
     }
 
     /**
      * 返回错误消息
-     * 
+     *
      * @param code 状态码
-     * @param msg 返回内容
+     * @param msg  返回内容
      * @return 警告消息
      */
-    public static AjaxResult error(int code, String msg)
-    {
+    public static AjaxResult error(int code, String msg) {
         return new AjaxResult(code, msg, null);
     }
 
     /**
      * 方便链式调用
      *
-     * @param key 键
+     * @param key   
      * @param value 值
      * @return 数据对象
      */
     @Override
-    public AjaxResult put(String key, Object value)
-    {
+    public AjaxResult put(String key, Object value) {
         super.put(key, value);
         return this;
     }

+ 65 - 0
warewms-ams/src/main/java/com/ruoyi/ams/agv/ndc/thread/AutoButtonBoxTask.java

@@ -1,5 +1,8 @@
 package com.ruoyi.ams.agv.ndc.thread;
 
+import com.ruoyi.ams.business.IBusinessService;
+import com.ruoyi.base.constant.Constant;
+import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.hard.modbus.tcp.ButtonBoxClient;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -11,7 +14,69 @@ public class AutoButtonBoxTask {
 
     @Autowired
     private ButtonBoxClient buttonBoxClient;
+    @Autowired
+    private IBusinessService businessService;
+
 
+    /**
+     * 1.读取按钮是否被按下
+     * 2.根据按下的按钮触发模具搬运任务
+     * 3.任务生成成功,按钮盒灭灯,并且清除按下标记
+     */
     public void run() {
+        Boolean readBtn01 = buttonBoxClient.readBtn01();
+        Boolean readBtn02 = buttonBoxClient.readBtn02();
+        if (readBtn01) {
+            buttonTask01();
+        }
+        if (readBtn02) {
+            buttonTask02();
+        }
+    }
+
+    /**
+     * 按钮1业务(冲边任务)
+     */
+    public void buttonTask01() {
+        log.info("按钮1已经被按下");
+        // 下发模具搬运任务(冲边)
+//        AjaxResult ajaxResult = businessService.agvCall(null, Constant.MOLD_HANDLING_CB_FLOW_ID);
+//        if (!ajaxResult.isSuccess()) {
+//            log.error("下发模具搬运任务(冲边)失败:" + ajaxResult.getMsg());
+//            return;
+//        }
+        try {
+            Thread.sleep(10000);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+        // 清除按下标记
+        buttonBoxClient.clearBtn01();
+        // 灭灯
+        buttonBoxClient.writeLamp01Death();
+        log.info("按钮1已经灭灯");
+    }
+
+    /**
+     * 按钮2业务(硫化任务)
+     */
+    public void buttonTask02() {
+        log.info("按钮2已经被按下");
+        // 下发模具搬运任务(硫化)
+//        AjaxResult ajaxResult = businessService.agvCall(null, Constant.MOLD_HANDLING_LH_FLOW_ID);
+//        if (!ajaxResult.isSuccess()) {
+//            log.error("下发模具搬运任务(硫化)失败:" + ajaxResult.getMsg());
+//            return;
+//        }
+        try {
+            Thread.sleep(10000);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+        // 清除按下标记
+        buttonBoxClient.clearBtn02();
+        // 灭灯
+        buttonBoxClient.writeLamp02Death();
+        log.info("按钮2已经灭灯");
     }
 }

+ 12 - 0
warewms-ams/src/main/java/com/ruoyi/ams/agv/ndc/thread/AutoRfidReaderTask.java

@@ -73,6 +73,12 @@ public class AutoRfidReaderTask {
             // 记录关门的次数 超过10次 就不再重复关门
             if (isOutdoor ? closeOutDoorNum < 10 : closeInDoorNum < 10) {
                 autoDoorClient.sendClose(isOutdoor);
+                log.info("发送关门指令!{},{}", isOutdoor, isOutdoor ? closeOutDoorNum : closeInDoorNum);
+                if (isOutdoor) {
+                    closeOutDoorNum++;
+                } else {
+                    closeInDoorNum++;
+                }
             }
             return;
         }
@@ -91,6 +97,12 @@ public class AutoRfidReaderTask {
             // 记录关门的次数 超过10次 就不再重复关门
             if (isOutdoor ? closeOutDoorNum < 10 : closeInDoorNum < 10) {
                 autoDoorClient.sendClose(isOutdoor);
+                log.info("发送关门指令!{},{}", isOutdoor, isOutdoor ? closeOutDoorNum : closeInDoorNum);
+                if (isOutdoor) {
+                    closeOutDoorNum++;
+                } else {
+                    closeInDoorNum++;
+                }
             }
         }
 

+ 12 - 0
warewms-base/src/main/java/com/ruoyi/base/constant/Constant.java

@@ -24,6 +24,18 @@ public class Constant {
      * 接驳位到出库缓存区
      */
     public static final long TRAN_OUT_FLOW_ID = 21;
+    /**
+     * 模具搬运(移库)
+     */
+    public static final long MOLD_HANDLING_MV_FLOW_ID = 23;
+    /**
+     * 模具搬运(冲边)
+     */
+    public static final long MOLD_HANDLING_CB_FLOW_ID = 23;
+    /**
+     * 模具搬运(硫化)
+     */
+    public static final long MOLD_HANDLING_LH_FLOW_ID = 24;
 
 
     /**