1
zhangc
2025-04-10 50435a81915932eda06b7f1afd48f9ff1ae84f19
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/service/impl/MainServiceImpl.java
@@ -28,13 +28,17 @@
import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol;
import com.zy.asrs.wcs.rcs.model.protocol.StaProtocol;
import com.zy.asrs.wcs.rcs.service.DeviceService;
import com.zy.asrs.wcs.rcs.thread.*;
import com.zy.asrs.wcs.rcs.thread.DevpThread;
import com.zy.asrs.wcs.rcs.thread.LedThread;
import com.zy.asrs.wcs.rcs.thread.LiftThread;
import com.zy.asrs.wcs.rcs.thread.ShuttleThread;
import com.zy.asrs.wcs.system.entity.Dict;
import com.zy.asrs.wcs.system.service.DictService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
/**
@@ -89,6 +93,71 @@
    @Autowired
    private ShuttleStandbyService shuttleStandbyService;
    private boolean isInEnable(DevpThread devpThread, Integer staNo) {
        if (staNo == null) {
            return false;
        }
        // 获取入库站信息
        switch (staNo) {
            case 1011:
            case 1012:
                devpThread.getStation().get(1012).isInEnable();
                break;
            case 1021:
            case 1022:
            case 1023:
                devpThread.getStation().get(1022).isInEnable();
                break;
            case 1031:
            case 1032:
                devpThread.getStation().get(1032).isInEnable();
                break;
            case 1025:
            case 1026:
                devpThread.getStation().get(1025).isInEnable();
                break;
            case 1013:
            case 1014:
            case 1015:
                devpThread.getStation().get(1014).isInEnable();
                break;
        }
        return false;
    }
    private boolean isOutEnable(DevpThread devpThread, Integer staNo) {
        if (staNo == null) {
            return false;
        }
        // 获取入库站信息
        switch (staNo) {
            case 1011:
            case 1012:
                devpThread.getStation().get(1012).isOutEnable();
                break;
            case 1021:
            case 1022:
            case 1023:
                devpThread.getStation().get(1022).isOutEnable();
                break;
            case 1031:
            case 1032:
                devpThread.getStation().get(1032).isOutEnable();
                break;
            case 1025:
            case 1026:
                devpThread.getStation().get(1025).isOutEnable();
                break;
            case 1013:
            case 1014:
            case 1015:
                devpThread.getStation().get(1014).isOutEnable();
                break;
        }
        return false;
    }
    /**
     * 组托
     * 入库站,根据条码扫描生成入库工作档,工作状态 2
@@ -104,7 +173,7 @@
                // 遍历入库口
                for (StaDto inSta : JSON.parseArray(basConveyor.getInSta(), StaDto.class)) {
                    BasConveyorSta basConveyorSta = basConveyorStaService.selectBySiteNo(inSta.getStaNo().toString());
                    if(basConveyorSta == null) {
                    if (basConveyorSta == null) {
                        continue;
                    }
@@ -160,7 +229,7 @@
                    // 判断是否满足入库条件
                    if (staProtocol.isAutoing() && staProtocol.isLoading()
                            && staProtocol.isInEnable()
                            && isInEnable(devpThread, inSta.getStaNo())
                            && !staProtocol.isEmptyMk() && (workNo == 0 || (workNo >= 9990 && workNo <= 9999))
                            && staProtocol.isPakMk()
                    ) {
@@ -197,7 +266,7 @@
                        if (task1 != null) {
                            News.error("工作档已存在,工作号={}", task1.getTaskNo());
                            if (staProtocol.getWorkNo().intValue() != Integer.parseInt(task1.getTaskNo())) {
                                devpThread.writeWorkSta(staProtocol.getSiteId(), Short.parseShort(task1.getTaskNo()), Short.parseShort(task1.getOriginSite()));
                                devpThread.writeWorkSta(staProtocol.getSiteId(), Short.parseShort(task1.getTaskNo()), Short.parseShort(task1.getDestSite()));
                                devpThread.setPakMk(staProtocol.getSiteId(), false);
                                News.info("输送线入库命令下发,任务数据={}", JSON.toJSON(task1));
                            }
@@ -262,7 +331,7 @@
//                                }
                                redisUtil.set(DeviceRedisConstant.LIFT_PALLET_INBOUND + inSta.getStaNo(), "in", 10);
                            }else {
                            } else {
                                String msg = jsonObject.getString("msg");
                                HashMap<String, String> hashMap = new HashMap<>();
                                hashMap.put("msg", msg);
@@ -339,10 +408,10 @@
                        mapNode.setXBase(object.getInteger("refx"));
                        mapNode.setYBase(object.getInteger("refy"));
                        if(mapNode.getValue() == MapNodeType.CONVEYOR.id) {
                        if (mapNode.getValue() == MapNodeType.CONVEYOR.id) {
                            //输送线,判断小车是否可走
                            if (object.containsKey("conveyorHasGo")) {
                                if(object.getBoolean("conveyorHasGo")) {
                                if (object.getBoolean("conveyorHasGo")) {
                                    //小车可走
                                    mapNode.setValue(MapNodeType.CONVEYOR_CAR_GO.id);
                                }
@@ -436,7 +505,7 @@
                ArrayList<MapNode> headNodes = new ArrayList<>();
                ArrayList<MapNode> footerNodes = new ArrayList<>();
                for (int i = 0; i < row+2; i++) {
                for (int i = 0; i < row + 2; i++) {
                    headNodes.add(mapNode.clone());
                    footerNodes.add(mapNode.clone());
                }
@@ -473,7 +542,7 @@
                // 遍历入库口
                for (StaDto inSta : JSON.parseArray(basConveyor.getDeviceInSta(), StaDto.class)) {
                    BasConveyorSta basConveyorSta = basConveyorStaService.selectBySiteNo(inSta.getStaNo().toString());
                    if(basConveyorSta == null) {
                    if (basConveyorSta == null) {
                        continue;
                    }
@@ -485,94 +554,93 @@
                    } else {
                        staProtocol = staProtocol.clone();
                    }
                    int workNo = staProtocol.getWorkNo().intValue();
                    int workNo = 0;
                    // 判断是否满足入库条件
                    if (staProtocol.isAutoing()
                            && staProtocol.isLoading()
                            && staProtocol.isInEnable()
                            && (workNo >= 0)
//                            && staProtocol.isPakMk()
                    ) {
                    if ((staProtocol.getSiteId() == 1015 || staProtocol.getSiteId() == 1023 || staProtocol.getSiteId() == 1026 || staProtocol.getSiteId() == 1032) &&
                            staProtocol.isAutoing() && staProtocol.isLoading()) {
                        workNo = staProtocol.getFinishWorkNo().intValue();
                    } else if ((staProtocol.getSiteId() == 1012) && staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInEnable()) {
                        workNo = staProtocol.getWorkNo().intValue();
                    } else {
                        continue;
                    }
                        Task task = taskService.getOne(new LambdaQueryWrapper<Task>()
                                .in(Task::getTaskSts, TaskStsType.NEW_INBOUND.sts)
                                .eq(Task::getTaskNo, workNo));
                        if (task != null) {
                            if (!Cools.isEmpty(task.getLiftNo())) {
                                if (task.getLiftNo() > 0) {
                                    task.setLiftNo(0);
                                    task.setUpdateTime(new Date());
                                    if (!taskService.updateById(task)) {
                                        News.info("{}任务更新释放提升机失败", task.getTaskNo());
                                    }
                                }
                            }
                            //获取距离目标位置最近的可换层提升机(可能不空闲)
                            LiftThread liftThread = liftDispatcher.searchLift(task.getDestLoc(), task.getHostId(), true);
                            if (liftThread == null) {
                                continue;
                            }
                            Device transferLiftDevice = liftThread.getDevice();
                            //获取小车待机库位 ==> 进提升机
                            ShuttleStandby shuttleStandbyTo = shuttleStandbyService.getOne(new LambdaQueryWrapper<ShuttleStandby>()
                                    .eq(ShuttleStandby::getDeviceId, transferLiftDevice.getId())
                                    .eq(ShuttleStandby::getDeviceLev, Utils.getLev(task.getDestLoc()))
                                    .eq(ShuttleStandby::getStatus, 1));
                            //穿梭车进提升机库位号
                            String liftLocNoTo = shuttleStandbyTo.getDeviceLoc();
                            //穿梭车进提升机待机位库位号  输送线位置
                            String standbyLocNoTo = shuttleStandbyTo.getDeviceStandbyLoc();
                            //不走提升机
                            if (staProtocol.getSiteId() == 1015 || staProtocol.getSiteId() == 1026) {
                                standbyLocNoTo = staProtocol.getLocNo();
                            }
                            if (Cools.isEmpty(task.getShuttleNo())) {
                                //分配小车
                                //调度空闲车去取货待机位
                                Device shuttleDevice = shuttleDispatcher.dispatchShuttle(task, standbyLocNoTo);
                                if (shuttleDevice == null) {
                                    News.info("{}任务未找到空闲穿梭车", task.getTaskNo());
                                    continue;
                                }
                                task.setShuttleNo(Integer.valueOf(shuttleDevice.getDeviceNo()));//保存穿梭车号
                    Task task = taskService.getOne(new LambdaQueryWrapper<Task>()
                            .in(Task::getTaskSts, TaskStsType.NEW_INBOUND.sts)
                            .eq(Task::getTaskNo, workNo));
                    if (task != null) {
                        if (!Cools.isEmpty(task.getLiftNo())) {
                            if (task.getLiftNo() > 0) {
                                task.setLiftNo(0);
                                task.setUpdateTime(new Date());
                                if (!taskService.updateById(task)) {
                                    News.info("{}任务更新穿梭车号失败", task.getTaskNo());
                                    News.info("{}任务更新释放提升机失败", task.getTaskNo());
                                }
                                continue;
                            }
                            //判断小车是否到达取货待机位置
                            String shuttleLocNo = shuttleDispatcher.findShuttleLocNo(task.getShuttleNo(), task.getHostId());
                            if (shuttleLocNo == null) {
                                continue;
                            }
                            if (!standbyLocNoTo.equals(shuttleLocNo)) {
                                continue;
                            }
                            // generate motion list
                            List<Motion> motionList = analyzeService.generateMotion(task);
                            if (motionList.isEmpty()) {
                                continue;
                            }
                            motionService.batchInsert(motionList, task.getUuid(), Integer.valueOf(task.getTaskNo()), task.getHostId());
                            // 更新工作主档
                            task.setTaskSts(TaskStsType.ANALYZE_INBOUND.sts); // 工作状态
                            task.setUpdateTime(new Date());
                            if (!taskService.updateById(task)) {
                                News.error("更新工作档失败!!! [工作号:{}]", task.getTaskNo());
                            }
                            break;
                        }
                        //获取距离目标位置最近的可换层提升机(可能不空闲)
                        LiftThread liftThread = liftDispatcher.searchLift(task.getDestLoc(), task.getHostId(), true);
                        if (liftThread == null) {
                            continue;
                        }
                        Device transferLiftDevice = liftThread.getDevice();
                        //获取小车待机库位 ==> 进提升机
                        ShuttleStandby shuttleStandbyTo = shuttleStandbyService.getOne(new LambdaQueryWrapper<ShuttleStandby>()
                                .eq(ShuttleStandby::getDeviceId, transferLiftDevice.getId())
                                .eq(ShuttleStandby::getDeviceLev, Utils.getLev(task.getDestLoc()))
                                .eq(ShuttleStandby::getStatus, 1));
                        //穿梭车进提升机库位号
                        String liftLocNoTo = shuttleStandbyTo.getDeviceLoc();
                        //穿梭车进提升机待机位库位号  输送线位置
                        String standbyLocNoTo = shuttleStandbyTo.getDeviceStandbyLoc();
                        //不走提升机
                        if (staProtocol.getSiteId() == 1015 || staProtocol.getSiteId() == 1026) {
                            standbyLocNoTo = staProtocol.getLocNo();
                        }
                        if (Cools.isEmpty(task.getShuttleNo())) {
                            //分配小车
                            //调度空闲车去取货待机位
                            Device shuttleDevice = shuttleDispatcher.dispatchShuttle(task, standbyLocNoTo);
                            if (shuttleDevice == null) {
                                News.info("{}任务未找到空闲穿梭车", task.getTaskNo());
                                continue;
                            }
                            task.setShuttleNo(Integer.valueOf(shuttleDevice.getDeviceNo()));//保存穿梭车号
                            task.setUpdateTime(new Date());
                            if (!taskService.updateById(task)) {
                                News.info("{}任务更新穿梭车号失败", task.getTaskNo());
                            }
                            continue;
                        }
                        //判断小车是否到达取货待机位置
                        String shuttleLocNo = shuttleDispatcher.findShuttleLocNo(task.getShuttleNo(), task.getHostId());
                        if (shuttleLocNo == null) {
                            continue;
                        }
                        if (!standbyLocNoTo.equals(shuttleLocNo)) {
                            continue;
                        }
                        // generate motion list
                        List<Motion> motionList = analyzeService.generateMotion(task);
                        if (motionList.isEmpty()) {
                            continue;
                        }
                        motionService.batchInsert(motionList, task.getUuid(), Integer.valueOf(task.getTaskNo()), task.getHostId());
                        // 更新工作主档
                        task.setTaskSts(TaskStsType.ANALYZE_INBOUND.sts); // 工作状态
                        task.setUpdateTime(new Date());
                        if (!taskService.updateById(task)) {
                            News.error("更新工作档失败!!! [工作号:{}]", task.getTaskNo());
                        }
                        break;
                    }
                }
            }
@@ -678,7 +746,7 @@
            }
            BasConveyor basConveyor = basConveyorService.getById(destStaObj.getConveyorId());
            if(basConveyor == null) {
            if (basConveyor == null) {
                continue;
            }
@@ -1069,8 +1137,8 @@
                    staProtocol = staProtocol.clone();
                }
                String taskNo = "0";
                if (staProtocol.isOutEnable() && staProtocol.getSiteId() == 31001 ){
                    if (0 != staProtocol.getWorkNo()){
                if (staProtocol.isOutEnable() && staProtocol.getSiteId() == 31001) {
                    if (0 != staProtocol.getWorkNo()) {
                        Motion motion = motionService.getOne(new LambdaQueryWrapper<Motion>().eq(Motion::getMotionCtg, 9).eq(Motion::getTemp, staProtocol.getWorkNo()));
                        // 获取工作档数据
                        Task task = taskService.getOne(new LambdaQueryWrapper<Task>().eq(Task::getTaskNo, motion.getTaskNo()));
@@ -1092,7 +1160,7 @@
                        HashMap<String, Object> param = new HashMap<>();
                        param.put("taskNo", taskNo);
                        param.put("sta",staNo);
                        param.put("sta", staNo);
                        String response = new HttpHandler.Builder()
                                .setUri(wmsUrl)
                                .setPath("/rpc/led/getTask")
@@ -1174,7 +1242,9 @@
            for (Integer staNo : staArr) {
                // 获取叉车站点
                StaProtocol staProtocol = devpThread.getStation().get(staNo);
                if (staProtocol == null) { continue; }
                if (staProtocol == null) {
                    continue;
                }
                if (staProtocol.getWorkNo() != 0) {
                    reset = false;
                    break;