#
Junjie
4 天以前 6daf900a09adcca981f620744bf89851654d88e0
src/main/java/com/zy/common/utils/NavigateMapUtils.java
@@ -2,19 +2,57 @@
import com.zy.asrs.utils.Utils;
import com.zy.common.model.NavigateNode;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.RedisKeyType;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.protocol.ShuttleProtocol;
import com.zy.core.thread.ShuttleThread;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
public class NavigateMapUtils {
    @Autowired
    private RedisUtil redisUtil;
    public synchronized boolean clearPath(Integer shuttleNo) {
        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
        if (shuttleThread == null) {
            return false;
        }
        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
        if (shuttleProtocol == null) {
            return false;
        }
        String currentLocNo = shuttleProtocol.getCurrentLocNo();
        int lev = Utils.getLev(currentLocNo);
        HashMap<String, Object> lockMap = new HashMap<>();
        Object o = redisUtil.get(RedisKeyType.LOCK_MAP_NODES.key + lev);
        if (o != null) {
            lockMap = (HashMap<String, Object>) o;
        }
        List<NavigateNode> list = new ArrayList<>();
        for (Map.Entry<String, Object> entry : lockMap.entrySet()) {
            String locNo = entry.getKey();
            Integer value = (Integer) entry.getValue();
            if (value.equals(shuttleNo)) {
                NavigateNode navigateNode = NavigatePositionConvert.locNoToNode(locNo);
                list.add(navigateNode);
            }
        }
        return writeNavigateNodeToRedisMap(lev, shuttleNo, list, false);
    }
    /**
     * 写入路径节点数据到redis地图中
@@ -58,7 +96,10 @@
            //判断节点是否被锁定
            if(lockMap.containsKey(key)) {
                return false;
                Integer deviceNo = (Integer) lockMap.get(key);
                if (!shuttleNo.equals(deviceNo)) {//等待锁定的节点已被当前小车锁定,认定锁定成功
                    return false;
                }
            }
            tmpMap.put(key, shuttleNo);
@@ -93,7 +134,6 @@
                lockMap.remove(key);
            }
        }
        lockMap.putAll(lockMap);
        redisUtil.set(RedisKeyType.LOCK_MAP_NODES.key + lev, lockMap);
        return true;
    }