#
Junjie
3 天以前 706eabba4750cf92282378ae5d2414f497a4578c
src/main/java/com/zy/asrs/utils/Utils.java
@@ -11,9 +11,11 @@
import com.core.exception.CoolException;
import com.zy.asrs.entity.BasCrnp;
import com.zy.asrs.entity.BasDualCrnp;
import com.zy.asrs.entity.BasStationDevice;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.service.BasCrnpService;
import com.zy.asrs.service.BasDualCrnpService;
import com.zy.asrs.service.BasStationDeviceService;
import com.zy.asrs.service.WrkMastService;
import com.zy.common.model.NavigateNode;
import com.zy.common.utils.NavigateUtils;
@@ -168,6 +170,18 @@
            NavigateUtils navigateUtils = SpringUtils.getBean(NavigateUtils.class);
            WrkMastService wrkMastService = SpringUtils.getBean(WrkMastService.class);
            BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class);
            BasStationDeviceService basStationDeviceService = SpringUtils.getBean(BasStationDeviceService.class);
            List<BasStationDevice> stationDevices = basStationDeviceService.selectList(new EntityWrapper<BasStationDevice>().eq("station_id", stationId));
            boolean hasConfig = !stationDevices.isEmpty();
            List<Integer> allowedCrnNos = new ArrayList<>();
            if (hasConfig) {
                for (BasStationDevice sd : stationDevices) {
                    if (SlaveType.Crn.toString().equals(sd.getDeviceType())) {
                        allowedCrnNos.add(sd.getDeviceNo());
                    }
                }
            }
            Integer currentCircleTaskCrnNo = null;
            Object object = redisUtil.get(RedisKeyType.CURRENT_CIRCLE_TASK_CRN_NO.key);
@@ -198,13 +212,27 @@
            List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<>());
            List<BasCrnp> basCrnps = basCrnpService.selectList(wrapper);
            List<BasCrnp> baseList = new ArrayList<>();
            List<BasCrnp> extraList = new ArrayList<>();
            for (BasCrnp basCrnp : basCrnps) {
                if (excludeCrnList.contains(basCrnp.getCrnNo())) {
                    extraList.add(basCrnp);
                }else {
                    baseList.add(basCrnp);
                }
            }
            baseList.addAll(extraList);
            for (WrkMast wrkMast : wrkMasts) {
                Integer crnNo = wrkMast.getCrnNo();
                map.put(crnNo, map.getOrDefault(crnNo, 0) + 1);
            }
            List<BasCrnp> enabledCrnps = new ArrayList<>();
            for (BasCrnp basCrnp : basCrnps) {
            for (BasCrnp basCrnp : baseList) {
                if (hasConfig && !allowedCrnNos.contains(basCrnp.getCrnNo())) {
                    continue;
                }
                CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, basCrnp.getCrnNo());
                if (crnThread == null) {
                    continue;
@@ -221,9 +249,6 @@
                // 检查是否超过最大入库任务数
                if (maxInTaskControl && inWrkMasts.size() >= basCrnp.getMaxInTask()) {
                    News.info("堆垛机:{} 已达最大入库任务数,当前任务数:{}", basCrnp.getCrnNo(), inWrkMasts.size());
                    continue;
                }
                if (excludeCrnList.contains(basCrnp.getCrnNo())) {
                    continue;
                }
@@ -269,6 +294,18 @@
            NavigateUtils navigateUtils = SpringUtils.getBean(NavigateUtils.class);
            WrkMastService wrkMastService = SpringUtils.getBean(WrkMastService.class);
            BasDualCrnpService basDualCrnpService = SpringUtils.getBean(BasDualCrnpService.class);
            BasStationDeviceService basStationDeviceService = SpringUtils.getBean(BasStationDeviceService.class);
            List<BasStationDevice> stationDevices = basStationDeviceService.selectList(new EntityWrapper<BasStationDevice>().eq("station_id", stationId));
            boolean hasConfig = !stationDevices.isEmpty();
            List<Integer> allowedCrnNos = new ArrayList<>();
            if (hasConfig) {
                for (BasStationDevice sd : stationDevices) {
                    if (SlaveType.Crn.toString().equals(sd.getDeviceType())) {
                        allowedCrnNos.add(sd.getDeviceNo());
                    }
                }
            }
            Wrapper<BasDualCrnp> wrapper = new EntityWrapper<BasDualCrnp>()
                    .eq("in_enable", "Y")
@@ -278,13 +315,28 @@
            List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<>());
            List<BasDualCrnp> basDualCrnps = basDualCrnpService.selectList(wrapper);
            List<BasDualCrnp> baseList = new ArrayList<>();
            List<BasDualCrnp> extraList = new ArrayList<>();
            for (BasDualCrnp basDualCrnp : basDualCrnps) {
                if (excludeCrnList.contains(basDualCrnp.getCrnNo())) {
                    extraList.add(basDualCrnp);
                }else {
                    baseList.add(basDualCrnp);
                }
            }
            baseList.addAll(extraList);
            for (WrkMast wrkMast : wrkMasts) {
                Integer dualCrnNo = wrkMast.getDualCrnNo();
                map.put(dualCrnNo, map.getOrDefault(dualCrnNo, 0) + 1);
            }
            List<BasDualCrnp> enabledCrnps = new ArrayList<>();
            for (BasDualCrnp basDualCrnp : basDualCrnps) {
            for (BasDualCrnp basDualCrnp : baseList) {
                if (hasConfig && !allowedCrnNos.contains(basDualCrnp.getCrnNo())) {
                    continue;
                }
                DualCrnThread dualCrnThread = (DualCrnThread) SlaveConnection.get(SlaveType.DualCrn, basDualCrnp.getCrnNo());
                if (dualCrnThread == null) {
                    continue;
@@ -300,10 +352,7 @@
                );
                // 检查是否超过最大入库任务数
                if (maxInTaskControl && inWrkMasts.size() >= basDualCrnp.getMaxInTask()) {
                    News.info("堆垛机:{} 已达最大入库任务数,当前任务数:{}", basDualCrnp.getCrnNo(), inWrkMasts.size());
                    continue;
                }
                if (excludeCrnList.contains(basDualCrnp.getCrnNo())) {
                    News.info("双工位堆垛机:{} 已达最大入库任务数,当前任务数:{}", basDualCrnp.getCrnNo(), inWrkMasts.size());
                    continue;
                }
@@ -364,9 +413,23 @@
            return rowList;
        }
        BasDualCrnpService basDualCrnpService = SpringUtils.getBean(BasDualCrnpService.class);
        if (basDualCrnpService == null) {
            return rowList;
        }
        List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<BasCrnp>());
        for (BasCrnp basCrnp : basCrnps) {
            String deepRowsStr = basCrnp.getDeepRows();
            if(!Cools.isEmpty(deepRowsStr)){
                List<Integer> rows = JSON.parseArray(deepRowsStr, Integer.class);
                rowList.addAll(rows);
            }
        }
        List<BasDualCrnp> basDualCrnps = basDualCrnpService.selectList(new EntityWrapper<BasDualCrnp>());
        for (BasDualCrnp basDualCrnp : basDualCrnps) {
            String deepRowsStr = basDualCrnp.getDeepRows();
            if(!Cools.isEmpty(deepRowsStr)){
                List<Integer> rows = JSON.parseArray(deepRowsStr, Integer.class);
                rowList.addAll(rows);
@@ -377,6 +440,22 @@
    //获取浅库位排号
    public static Integer getShallowRowByDeepRow(Integer deepRow) {
        SlaveType slaveType = checkRowDeviceType(deepRow);
        if (slaveType == null) {
            return null;
        }
        if (slaveType.equals(SlaveType.Crn)) {
            return getShallowRowByCrnDeepRow(deepRow);
        } else if (slaveType.equals(SlaveType.DualCrn)) {
            return getShallowRowByDualCrnDeepRow(deepRow);
        }
        return null;
    }
    //获取堆垛机浅库位排号
    public static Integer getShallowRowByCrnDeepRow(Integer deepRow) {
        BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class);
        if (basCrnpService == null) {
            return null;
@@ -403,6 +482,52 @@
            }
        }
        if (controlRowList == null) {
            return null;
        }
        for (Integer row : controlRowList) {
            if (deepRow.equals(row)) {
                continue;
            }
            return row;
        }
        return null;
    }
    //获取双工位堆垛机浅库位排号
    public static Integer getShallowRowByDualCrnDeepRow(Integer deepRow) {
        BasDualCrnpService basDualCrnpService = SpringUtils.getBean(BasDualCrnpService.class);
        if (basDualCrnpService == null) {
            return null;
        }
        List<Integer> deepRowList = getDeepRowList();
        if (!deepRowList.contains(deepRow)) {
            return null;
        }
        List<Integer> controlRowList = null;
        List<BasDualCrnp> basDualCrnps = basDualCrnpService.selectList(new EntityWrapper<>());
        for (BasDualCrnp basDualCrnp : basDualCrnps) {
            List<List<Integer>> rowList = basDualCrnp.getControlRows$();
            for (List<Integer> rows : rowList) {
                if (rows.contains(deepRow)) {
                    controlRowList = rows;
                    break;
                }
            }
            if (controlRowList != null) {
                break;
            }
        }
        if (controlRowList == null) {
            return null;
        }
        for (Integer row : controlRowList) {
            if (deepRow.equals(row)) {
                continue;
@@ -415,6 +540,19 @@
    //获取深库位排号
    public static Integer getDeepRowByShallowRow(Integer shallowRow) {
        SlaveType slaveType = checkRowDeviceType(shallowRow);
        if (slaveType.equals(SlaveType.Crn)) {
            return getDeepRowByCrnShallowRow(shallowRow);
        } else if (slaveType.equals(SlaveType.DualCrn)) {
            return getDeepRowByDualCrnShallowRow(shallowRow);
        }
        return null;
    }
    //获取堆垛机深库位排号
    public static Integer getDeepRowByCrnShallowRow(Integer shallowRow) {
        BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class);
        if (basCrnpService == null) {
            return null;
@@ -451,4 +589,78 @@
        }
        return null;
    }
    //获取双工位堆垛机深库位排号
    public static Integer getDeepRowByDualCrnShallowRow(Integer shallowRow) {
        BasDualCrnpService basDualCrnpService = SpringUtils.getBean(BasDualCrnpService.class);
        if (basDualCrnpService == null) {
            return null;
        }
        List<Integer> controlRowList = null;
        List<Integer> deepRowList = null;
        List<BasDualCrnp> basDualCrnps = basDualCrnpService.selectList(new EntityWrapper<>());
        for (BasDualCrnp basDualCrnp : basDualCrnps) {
            List<List<Integer>> rowList = basDualCrnp.getControlRows$();
            for (List<Integer> rows : rowList) {
                if (rows.contains(shallowRow)) {
                    controlRowList = rows;
                    deepRowList = JSON.parseArray(basDualCrnp.getDeepRows(), Integer.class);
                    break;
                }
            }
            if (controlRowList != null) {
                break;
            }
        }
        if (deepRowList == null) {
            return null;
        }
        for (Integer row : controlRowList) {
            if (!deepRowList.contains(row)) {
                continue;
            }
            return row;
        }
        return null;
    }
    //检测排号设备类型
    public static SlaveType checkRowDeviceType(Integer row) {
        BasCrnpService basCrnpService = SpringUtils.getBean(BasCrnpService.class);
        if (basCrnpService == null) {
            return null;
        }
        BasDualCrnpService basDualCrnpService = SpringUtils.getBean(BasDualCrnpService.class);
        if (basDualCrnpService == null) {
            return null;
        }
        List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<>());
        for (BasCrnp basCrnp : basCrnps) {
            List<List<Integer>> controlRows = basCrnp.getControlRows$();
            for (List<Integer> list : controlRows) {
                if (list.contains(row)) {
                    return SlaveType.Crn;
                }
            }
        }
        List<BasDualCrnp> basDualCrnps = basDualCrnpService.selectList(new EntityWrapper<>());
        for (BasDualCrnp basDualCrnp : basDualCrnps) {
            List<List<Integer>> controlRows = basDualCrnp.getControlRows$();
            for (List<Integer> list : controlRows) {
                if (list.contains(row)) {
                    return SlaveType.DualCrn;
                }
            }
        }
        return null;
    }
}