zyh
10 小时以前 466cc943089116f996db0c2f249878a74fb1cc10
src/main/java/com/zy/asrs/service/impl/RcsServiceImpl.java
@@ -1,6 +1,7 @@
package com.zy.asrs.service.impl;
import com.alibaba.excel.util.StringUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
@@ -11,6 +12,7 @@
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.Task;
import com.zy.core.model.protocol.StaProtocol;
import com.zy.core.thread.SiemensDevpThread;
import lombok.extern.slf4j.Slf4j;
@@ -68,7 +70,12 @@
        String slotCategory = values.getString("slotCategory");
        String slotCode = values.getString("slotCode");
        EntityWrapper<AgvTask> wrapper = new EntityWrapper<>();
        wrapper.eq("task_no", rcsReporterTask.getRobotTaskCode().substring(0, rcsReporterTask.getRobotTaskCode().length() - 2));
        // 修改后的逻辑:有"-"则去掉最后一个"-"及后面内容,没有则保持原样
        String taskNo = rcsReporterTask.getRobotTaskCode();
        if (taskNo.contains("-")) {
            taskNo = taskNo.substring(0, taskNo.lastIndexOf("-"));
        }
        wrapper.eq("task_no", taskNo);
        AgvTask task = agvTaskService.selectOne(wrapper);
        if (!Cools.isEmpty(task)) {
            try {
@@ -100,7 +107,7 @@
                                    rcsReturn.setData(data);
                                } else {
                                    //出发PLC站点的扫码器扫码
                                    boolean result = MessageQueue.offer(SlaveType.Devp, 1, new com.zy.core.model.Task(3, staProtocol));
                                    boolean result = MessageQueue.offer(SlaveType.Devp, 1, new Task(3, staProtocol));
                                    if (result) {
                                        log.info("入库站点={}触发扫码成功", staProtocol.getSiteId());
                                        // 返回RCS
@@ -168,7 +175,26 @@
                    //放货完成 --》agv已经离开
                    case TASK_END: {
                        if (task.getStaNo().equals("401") || task.getStaNo().equals("402") || task.getStaNo().equals("307")) {
                        try {
                            Thread.sleep(5000);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                        if (task.getStaNo().equals("Q-E1")){
                            // 更新任务状态等内部逻辑
                            task.setWrkSts(304L);   // 301 任务下发、302 任务执行、303 任务中断、304 任务结束
                            task.setModiTime(new Date());
                            agvTaskService.updateById(task);
                            // 返回RCS
                            rcsReturn.setCode("SUCCESS");
                            rcsReturn.setMessage("");
                            JSONObject data = new JSONObject();
                            data.put("robotTaskCode", robotTaskCode);
                            rcsReturn.setData(data);
                        }
                        else if (task.getStaNo().equals("401") || task.getStaNo().equals("402") || task.getStaNo().equals("307")) {
                            Integer sourceStaNo = Integer.valueOf(task.getStaNo());
                            SiemensDevpThread siemensDevpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1);
                            StaProtocol staProtocol = siemensDevpThread.getStation().get(sourceStaNo).clone();
@@ -189,8 +215,8 @@
                            if (boo) {
                                staProtocol.setWorkNo(wrkNo);//空料架到位信号点
                                staProtocol.setStaNo(Short.valueOf("0"));
                                boolean result = MessageQueue.offer(SlaveType.Devp, 1, new com.zy.core.model.Task(2, staProtocol));
                                log.info("AGV放货完成,给站点写9991工作号,下发任务:{},站点:{},agv任务号:{}", result, task.getStaNo(), task.getTaskNo());
                                boolean result = MessageQueue.offer(SlaveType.Devp, 1, new Task(2, staProtocol));
                                log.info("AGV放货完成,给站点写9997工作号,下发任务:{},站点:{},agv任务号:{}", result, task.getStaNo(), task.getTaskNo());
                                if (result) {
                                    // 更新任务状态等内部逻辑
                                    task.setWrkSts(304L);   // 301 任务下发、302 任务执行、303 任务中断、304 任务结束
@@ -199,6 +225,7 @@
                                    // 返回RCS
                                    rcsReturn.setCode("SUCCESS");
                                    rcsReturn.setMessage("");
                                    JSONObject data = new JSONObject();
                                    data.put("robotTaskCode", robotTaskCode);
                                    rcsReturn.setData(data);
@@ -297,7 +324,7 @@
                            TransParent transParent = new TransParent();
                            transParent.setTaskno(task.getTaskNo() + "-" + (task.getCtnType() - 1));
                            transParent.setTaskname(task.getTaskNo() + "-" + (task.getCtnType() - 1));
                            transParent.setStationId(task.getStaNo());
                            transParent.setStationId(task.getSourceStaNo());
                            transParent.setAgvCode("2");//连接器库
                            //08-1是空托盘转序任务
                            //08-2是物料转序任务
@@ -338,9 +365,11 @@
                            if (staProtocol != null && !staProtocol.isLoading() && !staProtocol.isEmptyOutType()) {
                                staProtocol.setWorkNo((short) 0);
                                staProtocol.setStaNo((short) 0);
                                boolean result = MessageQueue.offer(SlaveType.Devp, 1, new com.zy.core.model.Task(2, staProtocol));
                                boolean result = MessageQueue.offer(SlaveType.Devp, 1, new Task(2, staProtocol));
                                log.info("AGV取货完成,给站点写0工作号,下发任务:{},站点:{},agv任务号:{}", result, task.getStaNo(), task.getTaskNo());
                                if (result) {
                                    task.setWrkSts(303L);
                                    agvTaskService.updateById(task);
                                    // 返回RCS
                                    rcsReturn.setCode("SUCCESS");
                                    rcsReturn.setMessage("");
@@ -355,14 +384,12 @@
                                    data.put("robotTaskCode", robotTaskCode);
                                    rcsReturn.setData(data);
                                }
                            }
                        } else {
                            TransParent transParent = new TransParent();
                            transParent.setTaskno(task.getTaskNo() + "-" + (task.getCtnType() - 1));
                            transParent.setTaskname(task.getTaskNo() + "-" + (task.getCtnType() - 1));
                            transParent.setStationId(task.getStaNo());
                            transParent.setStationId(task.getSourceStaNo());
                            transParent.setAgvCode("2");//连接器库
                            //08-1是空托盘转序任务
                            //08-2是物料转序任务
@@ -378,10 +405,6 @@
                            //取货离开站点
                            int i = AGVDepartureCompleted(transParent);
                            if (i == 1) {
                                // 更新任务状态等内部逻辑
                                task.setWrkSts(304L);   // 301 任务下发、302 任务执行、303 任务中断、304 任务结束
                                task.setModiTime(new Date());
                                agvTaskService.updateById(task);
                                rcsReturn.setCode("SUCCESS");
                                rcsReturn.setMessage("");
                                JSONObject data = new JSONObject();
@@ -400,6 +423,7 @@
                    break;
                    //AGV取货离站请求
                    case APPLY_IN_OFF_STATION: {
                        //如果是立库站点直接允许离站
                        if (task.getSourceStaNo().equals("401") || task.getSourceStaNo().equals("402") || task.getSourceStaNo().equals("307")) {
                            RcsTaskContinue rcsTaskContinue = new RcsTaskContinue();
@@ -428,11 +452,20 @@
                                }
                            }
                        } else {
                            // 延迟处理,确保到站完成信号优先处理
                            try {
                                Thread.sleep(5000); // 睡眠5秒
                            } catch (InterruptedException e)
                            {
                                Thread.currentThread().interrupt();
                            }
                            //如果是工位需要像mes请求离站
                            TransParent transParent = new TransParent();
                            transParent.setTaskno(task.getTaskNo() + "-" + (task.getCtnType() - 1));
                            transParent.setTaskname(task.getTaskNo() + "-" + (task.getCtnType() - 1));
                            transParent.setStationId(task.getStaNo());
                            transParent.setStationId(values.getString("slotName"));
                            transParent.setAgvCode("2");//连接器库
                            //08-1是空托盘转序任务
                            //08-2是物料转序任务
@@ -466,7 +499,7 @@
                    //AGV放货离站请求
                    case APPLY_OFF_STATION: {
                        //如果是立库站点直接允许离站
                        if (task.getStaNo().equals("401") || task.getStaNo().equals("402") || task.getStaNo().equals("307")) {
                        if (task.getStaNo().equals("401") || task.getStaNo().equals("402") || task.getStaNo().equals("307") || task.getTaskType().equals("AGV补空料架")) {
                            RcsTaskContinue rcsTaskContinue = new RcsTaskContinue();
                            rcsTaskContinue.setRobotTaskCode(task.getTaskNo() + "-" + (task.getCtnType() - 1));
                            rcsTaskContinue.setTriggerType("TASK");
@@ -477,7 +510,7 @@
                            if (!StringUtils.isEmpty(response) && response.contains("code")) {
                                RcsReturn rcsReturn1 = JSONObject.parseObject(response, RcsReturn.class);
                                if ("SUCCESS".equals(rcsReturn1.getCode())) {
                                    // 返回RCS
//                                     返回RCS
                                    rcsReturn.setCode("SUCCESS");
                                    rcsReturn.setMessage("");
                                    JSONObject data = new JSONObject();
@@ -493,11 +526,19 @@
                                }
                            }
                        } else {
                            // 延迟处理,确保到站完成信号优先处理
                            try {
                                Thread.sleep(5000); // 睡眠5秒
                            } catch (InterruptedException e)
                            {
                                Thread.currentThread().interrupt();
                            }
                            //如果是工位需要像mes请求离站
                            TransParent transParent = new TransParent();
                            transParent.setTaskno(task.getTaskNo() + "-" + (task.getCtnType() - 1));
                            transParent.setTaskname(task.getTaskNo() + "-" + (task.getCtnType() - 1));
                            transParent.setStationId(task.getStaNo());
                            transParent.setStationId(values.getString("slotName"));
                            transParent.setAgvCode("2");//连接器库
                            //08-1是空托盘转序任务
                            //08-2是物料转序任务
@@ -531,7 +572,7 @@
                    }
                    //到站完成
                    case ARRIVE_ON_STATION: {
                        if (task.getStaNo().equals("401") || task.getStaNo().equals("402") || task.getStaNo().equals("307")) {
                        if (task.getStaNo().equals("401") || task.getStaNo().equals("402") || values.getString("slotName").equals("307")) {
                            // 返回RCS
                            rcsReturn.setCode("SUCCESS");
                            rcsReturn.setMessage("");
@@ -542,7 +583,7 @@
                            TransParent transParent = new TransParent();
                            transParent.setTaskno(task.getTaskNo() + "-" + (task.getCtnType() - 1));
                            transParent.setTaskname(task.getTaskNo() + "-" + (task.getCtnType() - 1));
                            transParent.setStationId(task.getStaNo());
                            transParent.setStationId(values.getString("slotName"));
                            transParent.setAgvCode("2");//连接器库
                            //08-1是空托盘转序任务
                            //08-2是物料转序任务
@@ -733,4 +774,25 @@
        return 0;
    }
    public void agvPause(StaProtocol staProtocol){
        if (staProtocol.isHighError()) {
            String url = HIK_URL + "/api/robot/controller/zone/pause";
            try {
                System.out.println("超高报警");
                JSONObject params = null;
                params.put("zoneCode", "GK307");
                params.put("mapCode", "BB");
                params.put("invoke", "FREEZE");
                String response = RcsServiceImpl.sendPost(url, JSONObject.toJSONString(params));
                JSONObject jsonObject = JSON.parseObject(response);
                if (!StringUtils.isEmpty(response) && (jsonObject.getString("code").equals("SUCCESS") || jsonObject.getInteger("code") == 200)) {
                    System.out.println("暂停成功");
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
}