1
15 小时以前 e711c834aec2293c53b07efe53e81e3573c289b6
rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/AgvServiceImpl.java
@@ -19,6 +19,8 @@
import com.vincent.rsf.server.manager.service.impl.DeviceSiteServiceImpl;
import com.vincent.rsf.server.manager.service.impl.MatnrServiceImpl;
import com.vincent.rsf.server.manager.utils.LocManageUtil;
import com.vincent.rsf.server.manager.utils.WarehouseLocationRetrievalUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -32,8 +34,10 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
@Slf4j
@Service
public class AgvServiceImpl implements AgvService {
@@ -66,7 +70,11 @@
    @Transactional(rollbackFor = Exception.class)
    public R AGVBindAndInTaskStart(WaitPakinParam waitPakinPda, Long loginUserId) {
        //先绑定
        getAGVStaBind(waitPakinPda);
        try{
            getAGVStaBind(waitPakinPda);
        } catch (CoolException e) {
            log.error(e.getMessage());
        }
        //生成任务
        AGVInTaskStart(waitPakinPda, loginUserId);
        return R.ok();
@@ -103,6 +111,9 @@
        if (Cools.isEmpty(param.getPalletBarcode())) {
            throw new CoolException("托盘码不能为空!!");
        }
        if (Cools.isEmpty(param.getPalletSta())) {
            throw new CoolException("操作站点不能为空!!");
        }
        checkPalletBarcodeAvailable(param.getPalletBarcode());
@@ -126,9 +137,48 @@
                .setAnfme(1.0)
                .setOrderItems(Collections.singletonList(buildOrderItem(param, matnr, nowMillis, nowSeconds).setBarcode(param.getPalletBarcode())));
        syncOrder.setStationId(param.getPalletSta());
        receiveMsgService.syncCheckOrder(Collections.singletonList(syncOrder), loginUserId);
        R r = receiveMsgService.syncCheckOrder(Collections.singletonList(syncOrder), loginUserId);
        if (!Objects.isNull(r) && Objects.equals(String.valueOf(r.get("code")), "200")) {
            autoCallAgvInTask(param, loginUserId);
        }
        return R.ok(Cools.add("orderNo", orderNo).add("palletBarcode", param.getPalletBarcode()));
    }
    private void autoCallAgvInTask(AgvBindAndInTParam param, Long loginUserId) {
        CompletableFuture.runAsync(() -> {
            int retry = 0;
            while (retry < 5) {
                retry++;
                try {
                    Thread.sleep(3000);
                    WaitPakin waitPakin = waitPakinService.getOne(new LambdaQueryWrapper<WaitPakin>()
                            .eq(WaitPakin::getBarcode, param.getPalletBarcode())
                            .eq(WaitPakin::getIoStatus, PakinIOStatus.PAKIN_IO_STATUS_DONE.val)
                            .last("limit 1"));
                    if (Objects.isNull(waitPakin)) {
                        continue;
                    }
                    BasStation basStation = basStationService.getOne(new LambdaQueryWrapper<BasStation>()
                            .eq(BasStation::getStationName, param.getPalletSta())
                            .last("limit 1"));
                    if (Objects.isNull(basStation)) {
                        return;
                    }
//                    if (Objects.isNull(basStation) || Objects.isNull(basStation.getArea())) {
//                        return;
//                    }
                    WaitPakinParam waitPakinPda = new WaitPakinParam()
                            .setBarcode(param.getPalletBarcode())
                            .setStaNo(param.getPalletSta())
                            .setArea(param.getArea());
                    AGVBindAndInTaskStart(waitPakinPda, loginUserId);
                    return;
                } catch (Exception ignored) {
                }
            }
        });
    }
    private SyncOrdersItem buildOrderItem(AgvBindAndInTParam param, Matnr matnr, long uniqueSeed, long nowSeconds) {
@@ -230,12 +280,12 @@
        if (Cools.isEmpty(area)) {
            throw new CoolException("目标库区不能为空");
        }
        DeviceSite deviceSite = deviceSiteService.getOne(new LambdaQueryWrapper<DeviceSite>()
                .eq(DeviceSite::getSite, sta)
                .eq(DeviceSite::getAreaIdEnd, Long.parseLong(area))
                .eq(DeviceSite::getType, TaskType.TASK_TYPE_IN.type).last("limit 1"));
        if (Cools.isEmpty(deviceSite)) {
        boolean isItAvailable = new WarehouseLocationRetrievalUtil().queryPathIsItAvailableInArea(sta, area, waitPakinPda.getBarcode(), "in");
//        DeviceSite deviceSite = deviceSiteService.getOne(new LambdaQueryWrapper<DeviceSite>()
//                .eq(DeviceSite::getSite, sta)
//                .eq(DeviceSite::getAreaIdEnd, Long.parseLong(area))
//                .eq(DeviceSite::getType, TaskType.TASK_TYPE_IN.type).last("limit 1"));
        if (!isItAvailable) {
            throw new CoolException("无可用路径!!");
        }
@@ -258,7 +308,7 @@
        }
        String targetLoc = LocManageUtil.getTargetLoc(Long.parseLong(area));
        taskService.generateAGVTasks(waitPakin, targetLoc, sta, deviceSite.getDeviceCode(),loginUserId);
        taskService.generateAGVTasks(waitPakin, targetLoc, sta,loginUserId,area);
        if (!basStation.getType().equals(0)){
            basStation.setUseStatus(LocStsType.LOC_STS_TYPE_R.type);
        }
@@ -531,3 +581,4 @@
        return true;
    }
}