From 73cddc1f15fbee51a0f79189f7df631361483b0d Mon Sep 17 00:00:00 2001
From: zhangc <zc@123>
Date: 星期四, 19 十二月 2024 14:23:23 +0800
Subject: [PATCH] 优化AGV工作处理及上报逻辑

---
 src/main/java/com/zy/asrs/controller/AgvOpenController.java |  345 ++++++++++++++++++++++++++++++--------------------------
 1 files changed, 184 insertions(+), 161 deletions(-)

diff --git a/src/main/java/com/zy/asrs/controller/AgvOpenController.java b/src/main/java/com/zy/asrs/controller/AgvOpenController.java
index 08a651a..66ecba6 100644
--- a/src/main/java/com/zy/asrs/controller/AgvOpenController.java
+++ b/src/main/java/com/zy/asrs/controller/AgvOpenController.java
@@ -1,14 +1,21 @@
 package com.zy.asrs.controller;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.core.annotations.AppAuth;
+import com.core.common.Cools;
 import com.core.common.R;
-import com.zy.asrs.entity.AgvWaitPakin;
-import com.zy.asrs.entity.AgvWrkDetl;
+import com.zy.asrs.entity.AgvBasDevp;
+import com.zy.asrs.entity.AgvLocMast;
 import com.zy.asrs.entity.AgvWrkMast;
+import com.zy.asrs.entity.WrkMastExecute;
 import com.zy.asrs.entity.param.AgvTaskCallBackParam;
 import com.zy.asrs.service.*;
+import com.zy.asrs.utils.AppAuthUtil;
 import com.zy.common.web.BaseController;
 import lombok.Setter;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
@@ -18,220 +25,236 @@
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.PostConstruct;
+import javax.servlet.http.HttpServletRequest;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.util.Date;
 import java.util.EnumSet;
+import java.util.Map;
 
+/**
+ * 涓婃姤浜嬩欢绫诲瀷锛坋ventType锛夛細
+ * 飦� task锛氫笂鎶ヤ换鍔$姸鎬併��
+ * 飦� task_allocated: 涓婃姤浠诲姟鍒嗛厤缁欐満鍣ㄤ汉銆�
+ * 飦� tote_load锛氫笂鎶ュ彇绠辩姸鎬併��
+ * 飦� tote_unload锛氫笂鎶ユ斁绠辩姸鎬併��
+ * 飦� robot_reach锛氭満鍣ㄤ汉鍒拌揪宸ヤ綔绔欍��
+ * 飦� weight锛氱О閲嶄簨浠跺洖璋冦��
+ * 飦� rfid锛歊FID璇嗗埆浜嬩欢鍥炶皟銆�
+ *
+ * 浠诲姟鐘舵�侊紙status锛夛細
+ * 飦� success锛氭垚鍔熴��
+ * 飦� fail锛氬け璐ャ��
+ * 飦� cancel锛氬彇娑堛��
+ * 飦� suspend锛氭寕璧枫��
+ */
+@Slf4j
 @RestController
 @RequestMapping("/agv")
 public class AgvOpenController extends BaseController {
 
     @Autowired
     AgvWrkMastService agvWrkMastService;
+    @Autowired
+    ApiLogService apiLogService;
+    @Autowired
+    private WrkMastExecuteService wrkMastExecuteService;
+    @Autowired
+    private AgvBasDevpService agvBasDevpService;
 
     @PostMapping("/task/event/status")
-    public R taskEventStaus(@RequestBody AgvTaskCallBackParam param){
+    @AppAuth(memo = "ESS浠诲姟鍥炶皟")
+    public R taskEventStaus(@RequestBody AgvTaskCallBackParam param, HttpServletRequest request){
 
-        int wrkMastCount = agvWrkMastService.selectCount(new EntityWrapper<AgvWrkMast>().eq("wrk_no", param.getTaskCode()));
-        if(wrkMastCount < 1){
-            return R.error("浠诲姟缂栧彿閿欒");
-        }
 
-        AgvTask agvTask = AgvTask.valueOf(param.getEventType());
-        Class<AgvTask> clz = AgvTask.class;
-        try {
-            Method method = clz.getDeclaredMethod(param.getStatus(),AgvTaskCallBackParam.class);
-            method.invoke(agvTask,param);
-        } catch (NoSuchMethodException e) {
-            return R.error("浠诲姟鐘舵�乻tatus鍙傛暟鏈夎");
-        } catch (InvocationTargetException e) {
-            e.printStackTrace();
-            return R.error();
-        } catch (IllegalAccessException e) {
-            e.printStackTrace();
-            return R.error();
+
+
+        //save api log (appkey 鍚庣画娣诲姞)
+
+        R r = new R(0, "鎴愬姛");
+
+        AppAuthUtil.auth("",param, request);
+        int wrkNo = Integer.parseInt(param.getTaskCode());
+        if(wrkNo < 0){
+            wrkNo = -wrkNo;
         }
+        AgvWrkMast agvWrkMast = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("wrk_no", wrkNo));
+        if(Cools.isEmpty(agvWrkMast)){
+            agvWrkMast = agvWrkMastService.selectOne(new EntityWrapper<AgvWrkMast>().eq("barcode",param.getPodCode()));
+            if (Cools.isEmpty(agvWrkMast)){
+                r = R.error("浠诲姟缂栧彿閿欒");
+                logPost(param,JSONObject.toJSONString(r),false);
+                return r;
+            }
+        }
+        if (agvWrkMast.getIoType().equals(121)){
+            try{
+                if (agvWrkMast.getWrkSts().equals(12L)){
+                    WrkMastExecute wrkMastExecute = wrkMastExecuteService.selectOne(new EntityWrapper<WrkMastExecute>().eq("wrk_no", wrkNo));
+                    if (Cools.isEmpty(wrkMastExecute) || wrkMastExecute.getWrkSts()!=1){
+                        r = R.error("浠诲姟鐘舵�乄rkSts鍙傛暟鏈夎,WrkSts:"+wrkMastExecute.getWrkSts$());
+                        logPost(param,"浠诲姟鐘舵�乄rkSts鍙傛暟鏈夎,WrkSts:"+wrkMastExecute.getWrkSts$()+JSONObject.toJSONString(r),false);
+                        return r;
+                    } else {
+                        wrkMastExecute.setWrkSts(wrkMastExecute.getWrkStsCode());
+                        wrkMastExecuteService.updateById(wrkMastExecute);
+                    }
+                }else {
+                    r = R.error("浠诲姟寮傚父");
+                    logPost(param,JSONObject.toJSONString(r),false);
+
+                    return r;
+                }
+            }catch (Exception e){
+                r = R.error(""+e.getMessage());
+                logPost(param,JSONObject.toJSONString(r),false);
+                return r;
+            }
+        }else {
+            if(agvWrkMast.getWrkSts() >= 205){
+                r = R.error("褰撳墠浠诲姟宸插畬鎴�");
+                logPost(param,JSONObject.toJSONString(r),false);
+                return r;
+            }
+
+            AgvTask agvTask = AgvTask.valueOf(param.getMethod());
+            Class<AgvTask> clz = AgvTask.class;
+            try {
+                Method method = clz.getDeclaredMethod("success", AgvWrkMast.class, AgvTaskCallBackParam.class);
+                method.invoke(agvTask,agvWrkMast,param);
+            } catch (NoSuchMethodException e) {
+                r = R.error("浠诲姟鐘舵�乻tatus鍙傛暟鏈夎");
+                logPost(param,JSONObject.toJSONString(r),false);
+                return r;
+            } catch (InvocationTargetException e) {
+                log.error(e.getMessage());
+                r = R.error(""+e.getMessage());
+                logPost(param,JSONObject.toJSONString(r),false);
+                return r;
+            } catch (IllegalAccessException e) {
+                log.error(e.getMessage());
+                r = R.error(""+e.getMessage());
+                logPost(param,JSONObject.toJSONString(r),false);
+                return r;
+            }
+        }
+        logPost(param,JSONObject.toJSONString(r),true);
+        return r;
+    }
+
+    @PostMapping("/conveyor/loadContainerFinish ")
+    @AppAuth(memo = "鍙栬揣鏋跺畬鎴愰�氱煡")
+    public R loadContainerFinish(@RequestBody Map<String,Object> params){
+
         return R.ok();
     }
 
+    private void logPost( AgvTaskCallBackParam param,String response,boolean success){
+        apiLogService.save(
+                "ESS浠诲姟鍥炶皟",
+                "/phyzwms/agv/task/event/status",
+                null,
+                null,
+                JSON.toJSONString(JSONObject.toJSONString(param)),
+                response,
+                success
+        );
+    }
 }
 
 enum AgvTask{
 
     /**
-     * 涓婃姤浠诲姟鐘舵��
+     * 涓婃姤浠诲姟瀹屾垚
      */
-    task{
+    end{
         @Transactional
-        public void success(AgvTaskCallBackParam param) {
-            int wrkNo = Integer.valueOf(param.getTaskCode());
-            String barcode = agvWrkMastService.selectById(wrkNo).getBarcode();
-            //鐢熸垚AGV宸ヤ綔鍘嗗彶妗�
-            agvWrkMastLogService.save(wrkNo);
-            //鐢熸垚AGV宸ヤ綔鏄庣粏鍘嗗彶妗�
-            agvWrkDetlLogService.save(wrkNo);
-            //鍒犻櫎AGV宸ヤ綔妗�
-            agvWrkMastService.deleteById(wrkNo);
-            //鍒犻櫎AGV宸ヤ綔鏄庣粏妗�
-            agvWrkDetlService.delete(new EntityWrapper<AgvWrkDetl>().eq("wrk_no",wrkNo));
-            //鐢熸垚鍏ュ簱閫氱煡鍘嗗彶妗�
-            agvWaitPakinLogService.save(barcode);
-            //鍒犻櫎鍏ュ簱閫氱煡妗�
-            agvWaitPakinService.delete(new EntityWrapper<AgvWaitPakin>().eq("zpallet",barcode));
+        public void success(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) {
+            //淇敼AGV宸ヤ綔妗g殑宸ヤ綔鐘舵�佷负205.宸ヤ綔瀹屾垚
+            agvWrkMast.setWrkSts(205L);
 
-        }
-
-        public void fail(AgvTaskCallBackParam param) {
-
-        }
-
-        public void cancel(AgvTaskCallBackParam param) {
-
-        }
-
-        public void suspend(AgvTaskCallBackParam param) {
-
+            //鍑哄簱浠诲姟 101.鍑哄簱 || 103.鎷f枡鍑哄簱 || 107.鐩樼偣鍑哄簱
+            if(agvWrkMast.getIoType() == 101 || agvWrkMast.getIoType() == 103 || agvWrkMast.getIoType() == 107){
+                //淇敼鍑哄簱绔欑偣鐘舵��
+                agvBasDevpService.updateLocStsAndBarcodeByDevNo(agvWrkMast.getLocNo(),"F",agvWrkMast.getBarcode(),agvWrkMast.getWhsType().shortValue());
+            }
+            //鍑哄簱浠诲姟 110.绌烘澘鍑哄簱
+            if(agvWrkMast.getIoType() == 110){
+                agvBasDevpService.updateLocStsAndBarcodeByDevNo(agvWrkMast.getLocNo(),"F",agvWrkMast.getBarcode(),agvWrkMast.getWhsType().shortValue());
+                agvWrkMast.setWrkSts(206L);
+            }
+            agvWrkMast.setModiTime(new Date());
+            agvWrkMastService.updateById(agvWrkMast);
         }
     },
     /**
-     * 涓婃姤浠诲姟鍒嗛厤缁欐満鍣ㄤ汉
+     * 浠诲姟寮�濮�
      */
-    task_allocated{
+    start{
         @Transactional
-        public void success(AgvTaskCallBackParam param) {
-
-        }
-
-        public void fail(AgvTaskCallBackParam param) {
-
-        }
-
-        public void cancel(AgvTaskCallBackParam param) {
-
-        }
-
-        public void suspend(AgvTaskCallBackParam param) {
-
+        public void success(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) {
+            //淇敼AGV宸ヤ綔妗g殑宸ヤ綔鐘舵�佷负203.浠诲姟寮�濮�
+            agvWrkMast.setWrkSts(203L);
+            agvWrkMast.setModiTime(new Date());
+            agvWrkMastService.updateById(agvWrkMast);
         }
     },
     /**
-     * 涓婃姤鍙栫鐘舵��
+     * 璧板嚭鍌ㄤ綅鐘舵��
      */
-    tote_load{
+    outbin{
         @Transactional
-        public void success(AgvTaskCallBackParam param) {
-            //淇敼婧愮珯鐐圭姸鎬佷负O.绌猴紝浠ュ強瑙g粦鎵樼洏鏉$爜
-            agvBasDevpService.updateLocStsAndBarcodeByDevNo(param.getStationCode(),"O","");
-            //淇敼AGV宸ヤ綔妗g殑宸ヤ綔鐘舵�佷负2锛堣澶囦笂璧帮級
-            agvWrkMastService.updateWrkStsByWrkNo(Integer.valueOf(param.getTaskCode()),2);
-            //淇敼AGV鍏ュ簱閫氱煡妗g姸鎬�
-            agvWaitPakinService.updateIoStatus(Integer.valueOf(param.getTaskCode()),"Y");
+        public void success(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) {
+
+            switch(agvWrkMast.getIoType()) {
+                //鍏ュ簱浠诲姟
+                case 1:
+                // 绌烘澘鍏ュ簱
+                case 10:
+                // 鎷f枡鍏ュ簱浠诲姟
+                case 53:
+                // 鐩樼偣鍐嶅叆搴�
+                case 57:
+                    agvBasDevpService.updateLocStsAndBarcodeByDevNo(agvWrkMast.getSourceLocNo(),"O","",null);
+                    break;
+            }
+            //if(agvWrkMast.getIoType() == 1 || agvWrkMast.getIoType() == 53 || agvWrkMast.getIoType() == 57 || agvWrkMast.getIoType() == 10){
+            //    //淇敼婧愮珯鐐圭姸鎬佷负O.绌猴紝浠ュ強瑙g粦鎵樼洏鏉$爜
+            //    agvBasDevpService.updateLocStsAndBarcodeByDevNo(agvWrkMast.getSourceLocNo(),"O","",null);
+            //}
+
+            //淇敼AGV宸ヤ綔妗g殑宸ヤ綔鐘舵�佷负203.RCS鏀捐揣涓�
+            agvWrkMastService.updateWrkStsByWrkNo(agvWrkMast.getWrkNo(),204);
 
         }
 
-        public void fail(AgvTaskCallBackParam param) {
-
-        }
-
-        public void cancel(AgvTaskCallBackParam param) {
-
-        }
-
-        public void suspend(AgvTaskCallBackParam param) {
-
-        }
     },
     /**
      * 涓婃姤鏀剧鐘舵��
      */
-    tote_unload{
+    cancel{
         @Transactional
-        public void success(AgvTaskCallBackParam param) {
-            int wrkNo = Integer.valueOf(param.getTaskCode());
-            String barcode = agvWrkMastService.selectById(wrkNo).getBarcode();
-            //淇敼鐩爣搴撲綅鐘舵�佷负F.鍦ㄥ簱
-            agvLocMastService.updateLocStsByLocNo(param.getLocationCode(),"F");
-            //鏇存柊鐩爣搴撲綅鏄庣粏
-            agvLocDetlService.addLocDetlInfo(param.getLocationCode(),wrkNo);
-            //淇敼宸ヤ綔妗g姸鎬佷负14锛堝叆搴撳畬鎴愶級
-            agvWrkMastService.updateWrkStsByWrkNo(wrkNo,14);
-        }
+        public void success(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) {
 
-        public void fail(AgvTaskCallBackParam param) {
 
         }
 
-        public void cancel(AgvTaskCallBackParam param) {
-
-        }
-
-        public void suspend(AgvTaskCallBackParam param) {
-
-        }
     },
-    robot_reach{
+    apply{
         @Transactional
-        public void success(AgvTaskCallBackParam param) {
-
-        }
-
-        public void fail(AgvTaskCallBackParam param) {
-
-        }
-
-        public void cancel(AgvTaskCallBackParam param) {
-
-        }
-
-        public void suspend(AgvTaskCallBackParam param) {
-
-        }
-    },
-    weight{
-        @Transactional
-        public void success(AgvTaskCallBackParam param) {
-
-        }
-
-        public void fail(AgvTaskCallBackParam param) {
-
-        }
-
-        public void cancel(AgvTaskCallBackParam param) {
-
-        }
-
-        public void suspend(AgvTaskCallBackParam param) {
-
-        }
-    },
-    rfid{
-        @Transactional
-        public void success(AgvTaskCallBackParam param) {
-
-        }
-
-        public void fail(AgvTaskCallBackParam param) {
-
-        }
-
-        public void cancel(AgvTaskCallBackParam param) {
-
-        }
-
-        public void suspend(AgvTaskCallBackParam param) {
+        public void success(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param) {
 
         }
     };
 
     //浠诲姟鐘舵�佷负鎴愬姛
-    public abstract void success(AgvTaskCallBackParam param);
-    //浠诲姟鐘舵�佷负澶辫触
-    public abstract void fail(AgvTaskCallBackParam param);
-    //浠诲姟鐘舵�佷负鍙栨秷
-    public abstract void cancel(AgvTaskCallBackParam param);
-    //浠诲姟鐘舵�佷负鎸傝捣
-    public abstract void suspend(AgvTaskCallBackParam param);
+    public abstract void success(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param);
+//    //浠诲姟鐘舵�佷负澶辫触
+//    public abstract void fail(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param);
+//    //浠诲姟鐘舵�佷负鍙栨秷
+//    public abstract void cancel(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param);
+//    //浠诲姟鐘舵�佷负鎸傝捣
+//    public abstract void suspend(AgvWrkMast agvWrkMast, AgvTaskCallBackParam param);
 
     @Setter
     AgvBasDevpService agvBasDevpService;

--
Gitblit v1.9.1