From 617a8c4fc0b81ec4b96db8a013a91f4e666b0b96 Mon Sep 17 00:00:00 2001
From: zhangc <zc@123>
Date: 星期三, 08 一月 2025 14:33:45 +0800
Subject: [PATCH] 出现空指针异常

---
 src/main/java/com/zy/asrs/service/impl/AgvWrkMastServiceImp.java |  368 +++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 288 insertions(+), 80 deletions(-)

diff --git a/src/main/java/com/zy/asrs/service/impl/AgvWrkMastServiceImp.java b/src/main/java/com/zy/asrs/service/impl/AgvWrkMastServiceImp.java
index ad0cdbd..af24386 100644
--- a/src/main/java/com/zy/asrs/service/impl/AgvWrkMastServiceImp.java
+++ b/src/main/java/com/zy/asrs/service/impl/AgvWrkMastServiceImp.java
@@ -2,119 +2,327 @@
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.mapper.Wrapper;
 import com.baomidou.mybatisplus.service.impl.ServiceImpl;
+import com.core.common.Cools;
 import com.core.exception.CoolException;
+import com.zy.asrs.entity.AgvBasDevp;
+import com.zy.asrs.entity.AgvLocMast;
 import com.zy.asrs.entity.AgvWrkMast;
 import com.zy.asrs.entity.param.AgvTaskCreateParam;
 import com.zy.asrs.entity.param.AgvTaskParam;
-import com.zy.asrs.entity.param.AgvTaskkDescribeParam;
 import com.zy.asrs.mapper.AgvWrkMastMapper;
-import com.zy.asrs.service.AgvWrkMastService;
-import com.zy.asrs.service.ApiLogService;
+import com.zy.asrs.service.*;
+import com.zy.common.service.AgvCommonService;
 import com.zy.common.utils.HttpHandler;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
+import java.util.*;
+import java.util.concurrent.TimeUnit;
 
 @Service
+@Slf4j
 public class AgvWrkMastServiceImp extends ServiceImpl<AgvWrkMastMapper, AgvWrkMast> implements AgvWrkMastService {
 
+    @Value("${agv.flag}")
+    private boolean flag;
+
+    @Value("${agv.url}")
     private String url;
 
-    private String path;
+    @Value("${agv.taskCreatePath}")
+    private String taskCreatePath;
+
+    @Value("${agv.taskCancelPath}")
+    private String taskCancelPath;
+
+    @Value("${agv.containerMoveInPath}")
+    private String containerMoveInPath;
+
+    @Value("${agv.containerMoveOutPath}")
+    private String containerMoveOutPath;
+
+    @Value("${agv.containerArrivedPath}")
+    private String containerArrivedPath;
 
     @Autowired
     AgvWrkMastMapper agvWrkMastMapper;
     @Autowired
+    AgvWrkDetlService agvWrkDetlService;
+    @Autowired
+    AgvLocMastService agvLocMastService;
+    @Autowired
     ApiLogService apiLogService;
+    @Autowired
+    AgvBasDevpService agvBasDevpService;
+    @Autowired
+    private AgvCommonService agvCommonService;
+    @Autowired
+    private AgvWrkMastService agvWrkMastService;
 
-    public void updateWrkStsByWrkNo(int wrkNo, long wrkSts) {
+
+    public Boolean updateWrkStsByWrkNo(int wrkNo, long wrkSts) {
         AgvWrkMast agvWrkMast = this.selectById(wrkNo);
+        //鍒ゆ柇瑕佷慨鏀圭殑宸ヤ綔妗g姸鎬佹槸鍚﹀悎鐞嗭紝濡傛灉涓嶅悎鐞嗗垯鎶涘嚭寮傚父
+        checkWrkSts(agvWrkMast, wrkSts);
         agvWrkMast.setWrkSts(wrkSts);
+        agvWrkMast.setModiTime(new Date());
+        return this.updateById(agvWrkMast);
+    }
+
+    public void updateWrkStsByWrkNo(int wrkNo, long wrkSts, String manuType, long userId) {
+        Date now = new Date();
+        AgvWrkMast agvWrkMast = this.selectById(wrkNo);
+        //鍒ゆ柇瑕佷慨鏀圭殑宸ヤ綔妗g姸鎬佹槸鍚﹀悎鐞嗭紝濡傛灉涓嶅悎鐞嗗垯鎶涘嚭寮傚父
+        checkWrkSts(agvWrkMast, wrkSts);
+        agvWrkMast.setWrkSts(wrkSts);
+        agvWrkMast.setManuType(manuType);
+        agvWrkMast.setModiTime(now);
+        agvWrkMast.setModiUser(userId);
         this.updateById(agvWrkMast);
     }
 
-    public Map<String,List<Map<String,String>>> startWrk(List<AgvWrkMast> agvWrkMastList) throws IOException {
+    // TODO 鍒ゆ柇瑙勫垯
+    private boolean checkWrkSts(AgvWrkMast agvWrkMast, long wrkSts) {
 
-        AgvTaskCreateParam agvTaskCreateParam = new AgvTaskCreateParam();
-        agvTaskCreateParam.setTaskType("putaway");
 
-        //璋冪敤瀹瑰櫒鍏ュ満鏃舵墍闇�瑕佸弬鏁�
-        Map<String,List<Map<String,String>>> containerMoveParam = new HashMap<>();
-        List<Map<String,String>> positionCodeMapList = new ArrayList<>();
-        containerMoveParam.put("containerMoveIns",positionCodeMapList);
-
-        List<AgvTaskParam> agvTaskParamList = agvWrkMastList.stream().map(agvWrkMast -> {
-            AgvTaskParam agvTaskParam = new AgvTaskParam();
-            AgvTaskkDescribeParam agvTaskkDescribeParam = new AgvTaskkDescribeParam();
-            agvTaskParam.setTaskDescribe(agvTaskkDescribeParam);
-            //AgvTaskParam
-            agvTaskParam.setTaskCode(agvWrkMast.getWrkNo().toString());
-            agvTaskParam.setTaskPriority(agvWrkMast.getIoPri().intValue());
-
-            //寰�瀹瑰櫒鍏ュ満鍙傛暟涓斁鍏ユ簮绔欑偣浣嶇疆
-            Map<String,String> positionCodeMap = new HashMap<>();
-            positionCodeMap.put("positionCode",agvWrkMast.getSourceLocNo());
-            positionCodeMapList.add(positionCodeMap);
-
-            //AgvTaskkDescribeParam
-            agvTaskkDescribeParam.setFromLocationCode(agvWrkMast.getSourceLocNo());
-            agvTaskkDescribeParam.setToLocationCode(agvWrkMast.getLocNo());
-            agvTaskkDescribeParam.setContainerCode(agvWrkMast.getBarcode());
-            return agvTaskParam;
-        }).collect(Collectors.toList());
-
-        agvTaskCreateParam.setTasks(agvTaskParamList);
-
-        String response = "";
-
-        try {
-            response = new HttpHandler.Builder()
-                    .setUri("localhost:8080")
-                    .setPath("test/task/create")
-                    .setJson(JSONObject.toJSONString(agvTaskCreateParam))
-                    .build()
-                    .doPost();
-        }catch (Exception e){
-
-        }finally {
-//            apiLogService.save(
-//                    "涓婃灦浠诲姟涓嬪彂",
-//                    url + path,
-//                    null,
-//                    "127.0.0.1",
-//                    JSON.toJSONString(requestMap),
-//                    response,
-//                    success
-//            );
-        }
-
-        JSONObject jsonObject = JSON.parseObject(response);
-        //save log api
-        int code = (int) jsonObject.get("code");
-        if(code != 0){
-            throw new CoolException("璋冪敤AGV鎺ュ彛澶辫触");
-        }
-
-        return containerMoveParam;
+        return true;
     }
 
-    public int containerMove(Map<String, List<Map<String, String>>> containerMoveParam) throws IOException {
-        String response = new HttpHandler.Builder()
-                .setUri("localhost:8080")
-                .setPath("test/container/moveIn")
-                .setJson(JSONObject.toJSONString(containerMoveParam))
-                .build()
-                .doPost();
+    public int startWrk(AgvWrkMast agvWrkMast) throws IOException {
 
-        JSONObject jsonObject = JSON.parseObject(response);
-        return (int) jsonObject.get("code");
+        AgvTaskCreateParam agvTaskCreateParam = new AgvTaskCreateParam();
+        //agvTaskCreateParam.setTaskType(taskType);
+
+        getRequestParam(agvTaskCreateParam, agvWrkMast);
+
+        return doHttpRequest(agvTaskCreateParam, "鎼繍浠诲姟涓嬪彂", url, taskCreatePath, null, "127.0.0.1");
+
+        //return containerMoveParam;
+    }
+
+    public int startAllcationIn(AgvWrkMast agvWrkMast) throws IOException {
+        AgvBasDevp basDevp = agvBasDevpService.selectByDevNo(agvWrkMast.getSourceLocNo());
+        //妫�绱㈠簱浣嶏紝閫夋嫨鍚堥�傜殑搴撲綅
+        AgvLocMast locMast = agvCommonService.getLocNo(basDevp.getLocType1(), basDevp.getFloor(), false, true);
+        agvWrkMast.setLocNo(locMast.getLocNo());
+        agvWrkMast.setWrkSts(201L);
+        agvWrkMast.setLogErrMemo("startAllcationIn");
+        agvWrkMast.setModiTime(new Date());
+        agvWrkMastService.updateById(agvWrkMast);
+        // 鏇寸洰鏍囧簱浣�
+        locMast.setLocSts("S");
+        agvLocMastService.updateById(locMast);
+        return 0;
+
+    }
+
+    //璐ф灦鍏ュ満
+    public int containerMoveIn(List<AgvWrkMast> agvWrkMastList) throws IOException {
+        //璋冪敤璐ф灦鍏ュ満鏃舵墍闇�瑕佸弬鏁�
+        Map<String, List<Map<String, String>>> containerMoveParam = new HashMap<>();
+        List<Map<String, String>> positionCodeMapList = new ArrayList<>();
+        containerMoveParam.put("containerMoveIns", positionCodeMapList);
+
+        getContainerMoveParam(agvWrkMastList, positionCodeMapList);
+
+        if (Cools.isEmpty(positionCodeMapList)) {
+            return 0;
+        }
+        return doHttpRequest(containerMoveParam, "璐ф灦鍏ュ満浠诲姟涓嬪彂", url, containerMoveInPath, null, "127.0.0.1");
+
+    }
+
+    //璐ф灦绂诲満
+    public int containerMoveOut(List<AgvWrkMast> agvWrkMastList) {
+        Map<String, List<Map<String, String>>> containerMoveParam = new HashMap<>();
+        List<Map<String, String>> positionCodeMapList = new ArrayList<>();
+        containerMoveParam.put("containerMoveOuts", positionCodeMapList);
+        for (AgvWrkMast agvWrkMast : agvWrkMastList) {
+            Map<String, String> positionCodeMap = new HashMap<>();
+            positionCodeMap.put("positionCode", agvWrkMast.getLocNo());
+            positionCodeMapList.add(positionCodeMap);
+        }
+        return doHttpRequest(containerMoveParam, "璐ф灦绂诲満浠诲姟涓嬪彂", url, containerMoveOutPath, null, "127.0.0.1");
+    }
+
+    public boolean insertByIncrease(AgvWrkMast agvWrkMast) {
+        int index = this.baseMapper.insertByIncrease(agvWrkMast);
+
+        return index > 0;
+    }
+
+    @Override
+    public boolean deleteByWrkNo(int wrkNo) {
+        return this.delete(new EntityWrapper<AgvWrkMast>().eq("wrk_no", wrkNo));
+    }
+
+    //璐ф灦鍒拌揪閫氱煡
+    public int containerArrived(AgvWrkMast agvWrkMast) {
+
+        Map<String, String> containerArrivedParam = new HashMap<>();
+        containerArrivedParam.put("slotCode", agvWrkMast.getSourceLocNo());
+        containerArrivedParam.put("containerCode", agvWrkMast.getBarcode());
+
+        return doHttpRequest(containerArrivedParam, "璐ф灦杈惧埌閫氱煡", url, containerArrivedPath, null, "127.0.0.1");
+    }
+
+    @Override
+    public List<AgvWrkMast> selectReadyAgvWrkMast() {
+        List<String> stationCodes = agvBasDevpService.selectAllStationCode();
+        Wrapper<AgvWrkMast> wrapper = new EntityWrapper<AgvWrkMast>().eq("wrk_sts", 21L).like(false, "loc_no", "@");
+        wrapper.in("loc_no", stationCodes);
+        return this.selectList(wrapper);
+        //return this.baseMapper.selectReadyAgvWrkMast();
+    }
+
+    @Override
+    public AgvWrkMast selectByContainerCode(String containerCode) {
+        return this.selectOne(new EntityWrapper<AgvWrkMast>().eq("barcode", containerCode));
+    }
+
+    @Override
+    public int callCancelTask(int wrkNo) {
+
+        AgvTaskCreateParam agvTaskCreateParam = new AgvTaskCreateParam();
+        agvTaskCreateParam.setTaskCode(wrkNo + "");
+
+        return doHttpRequest(agvTaskCreateParam, "鍙栨秷浠诲姟涓嬪彂", url, taskCancelPath, null, "127.0.0.1");
+
+    }
+
+
+    private void getContainerMoveParam(List<AgvWrkMast> agvWrkMastList, List<Map<String, String>> positionCodeMapList) {
+        //寰�璐ф灦鍏ュ満鍙傛暟涓斁鍏ユ簮绔欑偣浣嶇疆
+        for (AgvWrkMast agvWrkMast : agvWrkMastList) {
+            //鍒ゆ柇鏄惁涓鸿緭閫佺嚎鍏ュ簱锛屾槸鍒欎笉闇�瑕佽揣鏋惰繘鍦鸿姹�
+            if ("Y".equals(agvWrkMast.getMk())) {
+                continue;
+            }
+            Map<String, String> positionCodeMap = new HashMap<>();
+            positionCodeMap.put("positionCode", agvWrkMast.getSourceLocNo());
+            positionCodeMapList.add(positionCodeMap);
+        }
+    }
+
+    private void getRequestParam(AgvTaskCreateParam agvTaskCreateParam, AgvWrkMast agvWrkMast) {
+
+        List<AgvTaskParam> agvTaskParamList = Arrays.asList(
+                //璧峰浣�
+                new AgvTaskParam(agvWrkMast.getSourceLocNo()),
+                //鐩爣浣�
+                new AgvTaskParam(agvWrkMast.getLocNo()));
+
+//        //璧峰浣�
+//        agvTaskParamList.add(new AgvTaskParam(agvWrkMast.getSourceLocNo()));
+//        //鐩爣浣�
+//        agvTaskParamList.add(new AgvTaskParam(agvWrkMast.getLocNo()));
+
+        if (agvWrkMast.getIoType() == 53 || agvWrkMast.getIoType() == 57) {
+            agvWrkMast.setWrkNo(-agvWrkMast.getWrkNo());
+        }
+        agvTaskCreateParam.setTaskCode(agvWrkMast.getWrkNo().toString());
+        switch (agvWrkMast.getIoType()) {
+            case 114:
+            case 108:
+            case 12:
+                agvTaskCreateParam.setTaskTyp("F06");
+                break;
+            case 109:
+                if (agvWrkMast.getWrkSts() == 201) {
+                    agvTaskCreateParam.setTaskTyp("F06");
+                } else {
+                    agvTaskCreateParam.setTaskTyp("F01");
+                }
+                break;
+            case 1:
+            case 57:
+                // 鍏ュ簱浠诲姟鏄彧鏈� 鎺ラ┏浣� -- > 搴撲綅
+                AgvLocMast loc = agvLocMastService.selectOne(new EntityWrapper<AgvLocMast>().eq("loc_no", agvWrkMast.getLocNo()));
+                String locSub = loc.getLocNo().substring(loc.getLocNo().length() - 4).substring(0, 2).substring(0, 2);
+                AgvBasDevp agvBasDevp = agvBasDevpService.selectByDevNo(agvWrkMast.getSourceLocNo());
+                if ("02".equals(locSub)) {
+                    if (agvBasDevp.getFloor() == 4) {
+                        agvTaskCreateParam.setTaskTyp("F01");
+                    } else {
+                        agvTaskCreateParam.setTaskTyp("F06");
+                    }
+
+                } else {
+                    // 鐩爣妤煎眰浣�1妤� 浣嗘簮搴撲綅锛堟帴椹充綅锛夊湪鍚稿浜屾ゼ
+                    if (agvBasDevp.getFloor() == 4) {
+                        agvTaskCreateParam.setTaskTyp("F06");
+                    } else {
+                        agvTaskCreateParam.setTaskTyp("F01");
+                    }
+
+
+                }
+                break;
+            default:
+                agvTaskCreateParam.setTaskTyp("F01");
+                break;
+        }
+
+        agvTaskCreateParam.setPositionCodePath(agvTaskParamList);
+
+    }
+
+    private int doHttpRequest(Object requestParam, String namespace, String url, String path, String appkey, String ip) {
+        if (!flag) {
+            return 1;
+        }
+        String response = "";
+        boolean success = false;
+        int code = 0;
+        try {
+            response = new HttpHandler.Builder()
+                    .setUri(url)
+                    .setPath(path)
+                    .setTimeout(30, TimeUnit.SECONDS)
+                    .setJson(JSONObject.toJSONString(requestParam))
+                    .build()
+                    .doPost();
+            JSONObject jsonObject = JSON.parseObject(response);
+
+            code = Integer.parseInt(jsonObject.get("code").toString());
+            if (code != 0) {
+                if (code == 6) {
+                    log.info("AGV浠诲姟鍗曞彿宸蹭笂鎶�:{}", response);
+                    String message = jsonObject.getString("message");
+                    if (!Cools.isEmpty(message) && message.contains("宸插瓨鍦ㄤ换鍔″崟澶翠负")) {
+                        success = true;
+                        return 0;
+                    }
+                }
+                throw new CoolException("璋冪敤AGV鍝嶅簲閿欒");
+                //return code;
+            }
+            success = true;
+            return code;
+        } catch (Exception e) {
+            log.error(e.getMessage());
+            throw new CoolException("璋冪敤AGV鍝嶅簲閿欒");
+            //return 1;
+        } finally {
+            if (code != 6) {
+                apiLogService.save(
+                        namespace,
+                        url + path,
+                        appkey,
+                        ip,
+                        JSON.toJSONString(JSONObject.toJSONString(requestParam)),
+                        response,
+                        success
+                );
+            }
+        }
+
     }
 
 }

--
Gitblit v1.9.1