自动化立体仓库 - WCS系统
野心家
2025-03-13 7112338864ef558d54db0329d75b903322787f6c
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -42,12 +42,14 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.CompletableFuture;
/**
 * 立体仓库WCS系统主流程业务
@@ -94,7 +96,10 @@
    private ApiLogService apiLogService;
    @Autowired
    private CommonService commonService;
    @Value("${wms.count}")
    private Integer maxCount;
    @Autowired
    private WrkMastService wrkMastService;
    @Value("${wms.url}")
    private String wmsUrl;
    @Value("${wms.inboundTaskApplyPath}")
@@ -107,6 +112,95 @@
    private CrnController crnController;
    @Autowired
    private SiteController siteController;
    //出库站点至112循环站点
    public synchronized void shiftTargetToCyclePoint() throws IOException, InterruptedException{
        try{
            for (DevpSlave devp : slaveProperties.getDevp()) {
                for (DevpSlave.Sta outSta : devp.getOutSta()) {
                    DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                    StaProtocol staProtocol = devpThread.getStation().get(outSta.getStaNo());
                    StaProtocol staProtocol1 = devpThread.getStation().get(1001);
                    StaProtocol staProtocol2 = devpThread.getStation().get(1002);
                    StaProtocol staProtocol3 = devpThread.getStation().get(1003);
                    StaProtocol staProtocol4 = devpThread.getStation().get(1004);
                    if (staProtocol == null) {
                        continue;
                    } else {
                        staProtocol = staProtocol.clone();
                    }
                    if (staProtocol1 == null) {
                        continue;
                    } else {
                        staProtocol1 = staProtocol1.clone();
                    }
                    if (staProtocol2 == null) {
                        continue;
                    } else {
                        staProtocol2 = staProtocol2.clone();
                    }
                    if (staProtocol3 == null) {
                        continue;
                    } else {
                        staProtocol3 = staProtocol3.clone();
                    }
                    if (staProtocol4 == null) {
                        continue;
                    } else {
                        staProtocol4 = staProtocol4.clone();
                    }
                    boolean result = false;
                    switch(outSta.getStaNo()){
                        case 105: if (staProtocol1.isLoading()){
                            result = true;
                        }
                        case 107: if (staProtocol2.isLoading()){
                            result = true;
                        }
                        case 109: if (staProtocol3.isLoading()){
                            result = true;
                        }
                        case 110: if (staProtocol4.isLoading()){
                            result = true;
                        }
                        default: break;
                    }
                    if(result){
                        staProtocol.setStaNo((short) 112);
                        MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                    }
                }
            }
        }catch (Exception e) {
            log.error("generateStoreWrkFile e", e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
    }
    //112循环站点至出库站
    public synchronized void shiftCyclePointToTarget() throws IOException, InterruptedException{
        try{
            for (DevpSlave devp : slaveProperties.getDevp()) {
                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                StaProtocol staProtocol = devpThread.getStation().get(112);
                if (staProtocol == null) {
                    continue;
                } else {
                    staProtocol = staProtocol.clone();
                }
                WrkMast wrkMast = wrkMastMapper.selectById(staProtocol.getWorkNo());
                if(wrkMast != null &&  wrkMast.getWrkNo() < 9000 && wrkMast.getWrkNo() > 7000){
                    staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
                    MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                }
            }
        }catch (Exception e) {
            log.error("generateStoreWrkFile e", e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
    }
    public synchronized void generateStoreWrkFile1() throws IOException, InterruptedException {
@@ -722,6 +816,7 @@
                    continue;
                }
                // 获取工作状态为2(设备上走)的入库工作档
                TaskWrk taskWrk = taskWrkMapper.selectPakIn(slave.getId(), staProtocol.getWorkNo().intValue(), staDesc.getStnNo().toString());
                if (null == taskWrk) {
@@ -847,6 +942,12 @@
                        if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) {
                            break;
                        }
                        int storeCount = taskWrkService.getStoreCount(taskWrk.getCrnNo());
                        if(storeCount >= maxCount){
                            log.error("{}号堆垛机暂存数已满!", taskWrk.getCrnNo());
                            break;
                        }
                        // 已经存在吊车执行任务时,则过滤
                        if (taskWrkMapper.selectCrnWorking(slave.getId()) != null) {