#
Junjie
2024-09-26 f5ce30b28233487bbad44b20e9f93ca299941a8a
#
1个文件已添加
124 ■■■■■ 已修改文件
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/MapCommandService.java 124 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/MapCommandService.java
New file
@@ -0,0 +1,124 @@
package com.zy.asrs.wcs.core.kernel.command;
import com.zy.asrs.wcs.core.entity.Motion;
import com.zy.asrs.wcs.core.model.MapNode;
import com.zy.asrs.wcs.core.model.NavigateNode;
import com.zy.asrs.wcs.core.model.enums.MotionCtgType;
import com.zy.asrs.wcs.core.model.enums.NavigationMapType;
import com.zy.asrs.wcs.core.utils.*;
import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
import com.zy.asrs.wcs.rcs.constant.DeviceRedisConstant;
import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol;
import com.zy.asrs.wcs.rcs.thread.ShuttleThread;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Slf4j
@Service
public class MapCommandService {
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private NavigateMapUtils navigateMapUtils;
    @Autowired
    private NavigateMapData navigateMapData;
    public Boolean accept(Motion motion) {
        switch (Objects.requireNonNull(MotionCtgType.get(motion.getMotionCtgEl()))) {
            case MAP_LOCK_PATH:
                return lockPath(motion, true);
            case MAP_UNLOCK_PATH:
                return lockPath(motion, false);
            default:
                break;
        }
        return Boolean.TRUE;
    }
    public Boolean finish(Motion motion) {
        switch (Objects.requireNonNull(MotionCtgType.get(motion.getMotionCtgEl()))) {
            case MAP_LOCK_PATH:
                return checkLockPath(motion, true);
            case MAP_UNLOCK_PATH:
                return checkLockPath(motion, false);
            default:
                break;
        }
        return Boolean.TRUE;
    }
    private boolean lockPath(Motion motion, boolean lock) {
        Integer deviceNo = Integer.parseInt(motion.getDevice());
        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, deviceNo);
        if (shuttleThread == null) {
            return false;
        }
        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
        if (null == shuttleProtocol) {
            return false;
        }
        NavigateNode navigateNode = NavigatePositionConvert.locNoToNode(motion.getTarget());
        List<NavigateNode> nodes = new ArrayList<>();
        nodes.add(navigateNode);
        //所使用的路径进行锁定/解锁
        boolean lockResult = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(motion.getTarget()), shuttleProtocol.getShuttleNo(), nodes, lock);//所使用的路径进行锁定/解锁
        if (!lockResult) {
            return false;//锁定/解锁失败
        }
        return true;
    }
    private boolean checkLockPath(Motion motion, boolean lock) {
        NavigateNode navigateNode = NavigatePositionConvert.locNoToNode(motion.getTarget());
        List<NavigateNode> nodes = new ArrayList<>();
        nodes.add(navigateNode);
        int lev = Utils.getLev(motion.getTarget());
        Object o = redisUtil.get(DeviceRedisConstant.MAP + lev);
        if (o == null) {
            return false;
        }
        Integer deviceNo = Integer.parseInt(motion.getDevice());
        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, deviceNo);
        if (shuttleThread == null) {
            return false;
        }
        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
        if (null == shuttleProtocol) {
            return false;
        }
        //获取小车节点
        List<int[]> shuttlePoints = Utils.getShuttlePoints(shuttleProtocol.getShuttleNo(), lev);
        List<List<MapNode>> map = navigateMapData.getJsonData(NavigationMapType.DFX.id, null, shuttlePoints);
        for (NavigateNode node : nodes) {
            List<MapNode> listX = map.get(node.getX());
            MapNode mapNode = listX.get(node.getY());
            if (lock) {//检测是否锁定
                if (mapNode.getValue() != -999) {
                    return false;//路径未锁定
                }
            }else {//检测是否未锁定
                if(mapNode.getValue() == -999) {
                    return false;//路径已锁定
                }
            }
        }
        return true;
    }
}