zhang
7 天以前 1809dba25f489ea01c07a9ecc977d9f408545310
zy-acs-manager/src/main/java/com/zy/acs/manager/core/scheduler/AutoRunScheduler.java
@@ -63,8 +63,18 @@
    @Scheduled(fixedDelay = 1000) // 固定频率执行,同步
//    @Scheduled(cron = "0/1 * * * * ? ")
    private void execute() {
        if (!configService.getVal("TaskAssignMode", Boolean.class)) { return; }
        this.autoRun();
        if (configService.getVal("TaskAssignMode", Boolean.class)) {
            this.autoRun();
        }
        if (configService.getVal("TaskAssignMode1", Boolean.class,false)) {
            this.autoRun0(1);
        }
        if (configService.getVal("TaskAssignMode2", Boolean.class,false)) {
            this.autoRun0(2);
        }
        if (configService.getVal("TaskAssignMode3", Boolean.class,false)) {
            this.autoRun0(3);
        }
    }
    private void autoRun() {
@@ -76,13 +86,33 @@
        String memo = "DEMO_STA_" + String.join("-", staPreNos);
        // 入库
        this.runStaToLoc(memo);
        this.runStaToLoc0(memo);
        // 出库
        this.runLocToSta(memo);
        this.runLocToSta0(memo);
        // 移库
        this.runLocToLoc(memo);
    }
    private void autoRun0(Integer i) {
        int availableAgvCount = this.getAvailableAgvCount();
        if (0 == availableAgvCount) { return; }
//        List<String> staPreNos = getStaPrefixes(staGroupList);
        List<String> staPreNos = new ArrayList<>();
        String memo = "DEMO_STA_" + String.join("-", staPreNos);
        if(i ==1){
            // 入库
            this.runStaToLoc0(memo);
        }else if (i == 2){
            // 出库
            this.runLocToSta0(memo);
        }else if (i == 3){
            // 移库
            this.runLocToLoc(memo);
        }
    }
    // 入库
    private void runStaToLoc(String memo) {
@@ -133,6 +163,14 @@
    }
    private void runStaToLoc0(String memo) {
        int availableAgvCount = this.getAvailableAgvCount();
        // 最多 ? 组bus运行
        if (availableAgvCount <= busService.count(new LambdaQueryWrapper<Bus>()
                .in(Bus::getBusSts, BusStsType.RECEIVE.val(), BusStsType.PROGRESS.val())
                .in(Bus::getMemo, memo, memo)
        )) { return; }
        AgvModel agvModel = agvModelService.getOne(new LambdaQueryWrapper<AgvModel>().eq(AgvModel::getType, AgvModelType.CTU_BOX_TRANSPORT_AGV.toString()));
        if (null == agvModel) { return; }
@@ -154,7 +192,7 @@
            // 所在区域的条码,如果没有area绑定,就全地图
            List<String> codeList = areaGovernService.queryCodesByOneCode(staCode);
            if (Cools.isEmpty(codeList)) {
                idleLoc = locService.selectRandOneByLocSts(LocStsType.IDLE.val());
                idleLoc = locService.selectRandOneByLocSts(LocStsType.IDLE.val(), 1);
            } else {
                Collections.shuffle(codeList);
                for (String codeData : codeList) {
@@ -245,6 +283,14 @@
    }
    private void runLocToSta0(String memo) {
        int availableAgvCount = this.getAvailableAgvCount();
        // 最多 ? 组bus运行
        if (availableAgvCount <= busService.count(new LambdaQueryWrapper<Bus>()
                .in(Bus::getBusSts, BusStsType.RECEIVE.val(), BusStsType.PROGRESS.val())
                .in(Bus::getMemo, memo, memo)
        )) { return; }
        AgvModel agvModel = agvModelService.getOne(new LambdaQueryWrapper<AgvModel>().eq(AgvModel::getType, AgvModelType.CTU_BOX_TRANSPORT_AGV.toString()));
        if (null == agvModel) { return; }
@@ -266,7 +312,7 @@
            // 所在区域的条码,如果没有area绑定,就全地图
            List<String> codeList = areaGovernService.queryCodesByOneCode(staCode);
            if (Cools.isEmpty(codeList)) {
                stockLoc = locService.selectRandOneByLocSts(LocStsType.STOCK.val());
                stockLoc = locService.selectRandOneByLocSts(LocStsType.STOCK.val(), 1);
            } else {
                Collections.shuffle(codeList);
                for (String codeData : codeList) {
@@ -305,12 +351,6 @@
    // 移库
    private void runLocToLoc(String staTaskMemo) {
//        Integer startRow = Collections.min(locGroupList);
//        Integer endRow = Collections.max(locGroupList);
        Integer startRow = null;
        Integer endRow = null;
//        String memo = "DEMO_LOC_" + startRow + "-" + endRow;
        String memo = "DEMO_LOC";
        int availableAgvCount = this.getAvailableAgvCount();
@@ -319,41 +359,32 @@
        if (availableAgvCount <= busService.count(new LambdaQueryWrapper<Bus>()
                .in(Bus::getBusSts, BusStsType.RECEIVE.val(), BusStsType.PROGRESS.val())
                .in(Bus::getMemo, memo, staTaskMemo)
        )) {
            return;
        }
        )) { return; }
        AgvModel agvModel = agvModelService.getOne(new LambdaQueryWrapper<AgvModel>().eq(AgvModel::getType, AgvModelType.CTU_BOX_TRANSPORT_AGV.toString()));
        if (null == agvModel) {
            return;
        }
        if (null == agvModel) { return; }
        int maxCapacity = agvModel.getBackpack();
        // STOCK
        LambdaQueryWrapper<Loc> stockWrapper = new LambdaQueryWrapper<Loc>().eq(Loc::getLocSts, LocStsType.STOCK.val());
        if (null != startRow) { stockWrapper.ge(Loc::getRow, startRow); }
        if (null != endRow) { stockWrapper.le(Loc::getRow, endRow); }
        List<Loc> stockList = locService.list(stockWrapper);
        if (Cools.isEmpty(stockList) || stockList.size() < agvModel.getBackpack()) {
        List<Loc> stockLocList = locService.selectRandByLocSts(LocStsType.STOCK.val(), maxCapacity);
        if (Cools.isEmpty(stockLocList)) {
            return;
        }
        Collections.shuffle(stockList);
        Collections.shuffle(stockLocList);
        // IDLE
        LambdaQueryWrapper<Loc> idleWrapper = new LambdaQueryWrapper<Loc>().eq(Loc::getLocSts, LocStsType.IDLE.val());
        if (null != startRow) { idleWrapper.ge(Loc::getRow, startRow); }
        if (null != endRow) { idleWrapper.le(Loc::getRow, endRow); }
        List<Loc> idleList = locService.list(idleWrapper);
        if (Cools.isEmpty(idleList)) {
        List<Loc> idleLocList = locService.selectRandByLocSts(LocStsType.IDLE.val(), maxCapacity);
        if (Cools.isEmpty(idleLocList)) {
            return;
        }
        Collections.shuffle(idleList);
        Collections.shuffle(idleLocList);
        OpenBusSubmitParam param = new OpenBusSubmitParam();
        param.setBatch(String.valueOf(snowflakeIdWorker.nextId()).substring(13, 19));
        for (int i = 0; i < Math.min(maxCapacity, Math.min(stockList.size(), idleList.size())); i++) {
            Loc stockLoc = stockList.get(i);
            Loc idleLoc = idleList.get(i);
        for (int i = 0; i < Math.min(maxCapacity, Math.min(stockLocList.size(), idleLocList.size())); i++) {
            Loc stockLoc = stockLocList.get(i);
            Loc idleLoc = idleLocList.get(i);
            TaskDto taskDto = new TaskDto();
            taskDto.setOriLoc(stockLoc.getLocNo());
@@ -362,6 +393,7 @@
            param.getTaskList().add(taskDto);
        }
        if (Cools.isEmpty(param.getTaskList())) { return; }
        mainService.generateBusAndTask(param, memo);
    }