#
qlsxk
1 天以前 ab0db76dc627a63699380dc65e2773c47d12f449
src/main/java/com/zy/asrs/controller/ConsoleController.java
@@ -1,22 +1,33 @@
package com.zy.asrs.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.annotations.ManagerAuth;
import com.core.common.Cools;
import com.core.common.R;
import com.zy.asrs.domain.param.SystemSwitchParam;
import com.zy.asrs.entity.BasMap;
import com.zy.asrs.entity.DeviceConfig;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.service.BasMapService;
import com.zy.asrs.service.DeviceConfigService;
import com.zy.asrs.service.LocMastService;
import com.zy.asrs.utils.Utils;
import com.zy.common.model.MapNode;
import com.zy.common.model.NavigateNode;
import com.zy.common.model.enums.NavigationMapType;
import com.zy.common.utils.NavigateMapData;
import com.zy.common.utils.RedisUtil;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.RedisKeyType;
import com.zy.core.properties.SlaveProperties;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.command.ShuttleRedisCommand;
import com.zy.core.model.protocol.ShuttleProtocol;
import com.zy.core.properties.SystemProperties;
import com.zy.core.thread.ShuttleThread;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
@@ -32,15 +43,15 @@
public class ConsoleController {
    @Autowired
    private SlaveProperties slaveProperties;
    @Autowired
    private BasMapService basMapService;
    @Autowired
    private RedisUtil redisUtil;
    @Value("${super.pwd}")
    private String superPwd;
    @Autowired
    private NavigateMapData navigateMapData;
    @Autowired
    private LocMastService locMastService;
    @Autowired
    private DeviceConfigService deviceConfigService;
    @PostMapping("/system/running/status")
    @ManagerAuth(memo = "系统运行状态")
@@ -68,6 +79,20 @@
    }
    /**
     * 获取地图楼层数据
     */
    @GetMapping("/map/lev/list")
    @ManagerAuth
    public R getMapLevList() {
        List<BasMap> basMaps = basMapService.selectList(new EntityWrapper<BasMap>().orderBy("lev", true));
        ArrayList<Integer> levList = new ArrayList<>();
        for (BasMap basMap : basMaps) {
            levList.add(basMap.getLev());
        }
        return R.ok().add(levList);
    }
    /**
     * 获取地图数据
     */
    @GetMapping("/map/{lev}/auth")
@@ -78,10 +103,41 @@
            return R.error();
        }
        BasMap basMap = JSON.parseObject(data.toString(), BasMap.class);
        //解析json地图数据
        ArrayList arrayList = JSON.parseObject(basMap.getData(), ArrayList.class);
        List<List<MapNode>> lists = navigateMapData.filterMap(NavigationMapType.NONE.id, arrayList, lev, null, null);//过滤地图数据
        List<List<MapNode>> arrayList = (List<List<MapNode>>) data;
        List<List<MapNode>> lists = navigateMapData.filterMap(NavigationMapType.getMapTypes(NavigationMapType.NONE, NavigationMapType.PATH_LOCK), arrayList, lev, null, null);//过滤地图数据
        return R.ok().add(lists);
    }
    /**
     * 获取库位地图数据
     */
    @GetMapping("/locMap/{lev}/auth")
    @ManagerAuth
    public R getLocMap(@PathVariable Integer lev) {
        Object data = redisUtil.get(RedisKeyType.MAP.key + lev);
        if (data == null) {
            return R.error();
        }
        List<List<MapNode>> arrayList = (List<List<MapNode>>) data;
        List<List<MapNode>> lists = navigateMapData.filterMap(NavigationMapType.getMapTypes(NavigationMapType.NONE), arrayList, lev, null, null);//过滤地图数据
        //获取当前楼层库位数据
        List<LocMast> locMasts = locMastService.selectLocByLev(lev);
        for (LocMast locMast : locMasts) {
            Integer row = locMast.getRow1();
            Integer bay = locMast.getBay1();
            List<MapNode> list = lists.get(row);
            MapNode mapNode = list.get(bay);
            mapNode.setLocSts(locMast.getLocSts());
            mapNode.setLocNo(locMast.getLocNo());
            //更新list
            list.set(bay, mapNode);
            lists.set(row, list);
        }
        return R.ok().add(lists);
    }
@@ -91,8 +147,10 @@
    @GetMapping("/map/resetMap/auth")
    @ManagerAuth
    public R resetMapToRedis() {
        for (int i = 1; i <= 10; i++) {//总共10层楼
            redisUtil.del(RedisKeyType.MAP.key + i);
        List<BasMap> basMaps = basMapService.selectList(new EntityWrapper<BasMap>().orderBy("lev", true));
        for (BasMap basMap : basMaps) {
            Integer lev = basMap.getLev();
            redisUtil.del(RedisKeyType.MAP.key + lev);
        }
        return R.ok();
    }
@@ -107,4 +165,105 @@
        return R.ok();
    }
    /**
     * 获取预计路径
     */
    @GetMapping("/getMoveAdvancePath/{lev}/auth")
    @ManagerAuth
    public R getMoveAdvancePath(@PathVariable Integer lev) {
        HashMap<String, Object> pathMap = new HashMap<>();
        List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                .eq("device_type", String.valueOf(SlaveType.Shuttle)));
        for (DeviceConfig deviceConfig : shuttleList) {
            // 获取四向穿梭车信息
            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, deviceConfig.getDeviceNo());
            if (shuttleThread == null) {
                continue;
            }
            ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
            if (shuttleProtocol == null || shuttleProtocol.getShuttleNo()==null) {
                continue;
            }
            if (shuttleProtocol.getCurrentLocNo() == null) {
                continue;
            }
            if (Utils.getLev(shuttleProtocol.getCurrentLocNo()) != lev) {
                continue;
            }
            if (shuttleProtocol.getTaskNo() == 0) {
            }
            //存在任务,获取指令
            Object object = redisUtil.get(RedisKeyType.SHUTTLE_WORK_FLAG.key + shuttleProtocol.getTaskNo());
            if (object != null) {
                ShuttleRedisCommand redisCommand = JSON.parseObject(object.toString(), ShuttleRedisCommand.class);
                List<NavigateNode> nodes = redisCommand.getAssignCommand().getNodes();//穿梭车预计路径
                for (NavigateNode node : nodes) {
                    String locNo = Utils.getLocNo(node.getX(), node.getY(), node.getZ());
                    List<Integer> shuttleNoList = new ArrayList<>();
                    Object tmp = pathMap.get(locNo);
                    if(tmp != null) {
                        shuttleNoList = (List<Integer>) tmp;
                    }
                    if (!shuttleNoList.contains(shuttleProtocol.getShuttleNo())) {
                        shuttleNoList.add(shuttleProtocol.getShuttleNo());
                    }
                    pathMap.put(locNo, shuttleNoList);
                }
            }
        }
        List<HashMap<String, Object>> pathList = new ArrayList<>();
        for (Map.Entry<String, Object> entry : pathMap.entrySet()) {
            String locNo = entry.getKey();
            Object shuttleNoList = entry.getValue();
            HashMap<String, Object> map = new HashMap<>();
            map.put("locNo", locNo);
            map.put("x", Utils.getRow(locNo));
            map.put("y", Utils.getBay(locNo));
            map.put("z", Utils.getLev(locNo));
            map.put("shuttleNoList", shuttleNoList);
            pathList.add(map);
        }
        return R.ok().add(pathList);
    }
    /**
     * 获取锁定路径
     */
    @GetMapping("/getLockPath/{lev}/auth")
    @ManagerAuth
    public R getLockPath(@PathVariable Integer lev) {
        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<HashMap<String, Object>> lockList = new ArrayList<>();
        for (Map.Entry<String, Object> entry : lockMap.entrySet()) {
            String locNo = entry.getKey();
            Object shuttleNo = entry.getValue();
            HashMap<String, Object> map = new HashMap<>();
            map.put("locNo", locNo);
            map.put("x", Utils.getRow(locNo));
            map.put("y", Utils.getBay(locNo));
            map.put("z", Utils.getLev(locNo));
            map.put("shuttleNo", shuttleNo);
            lockList.add(map);
        }
        return R.ok().add(lockList);
    }
}