#
vincentlu
1 天以前 f7543a1cc6c89ea03c0d6a0591526baf10d7934b
zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/MainService.java
@@ -4,10 +4,7 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.zy.acs.common.constant.RedisConstant;
import com.zy.acs.common.domain.AgvAction;
import com.zy.acs.common.domain.AgvActionItem;
import com.zy.acs.common.domain.AgvProtocol;
import com.zy.acs.common.domain.BaseResult;
import com.zy.acs.common.domain.*;
import com.zy.acs.common.domain.protocol.*;
import com.zy.acs.common.domain.protocol.action.*;
import com.zy.acs.common.enums.*;
@@ -26,7 +23,7 @@
import com.zy.acs.manager.core.domain.TaskPosDto;
import com.zy.acs.manager.core.integrate.conveyor.ConveyorStationService;
import com.zy.acs.manager.core.service.astart.MapDataDispatcher;
import com.zy.acs.manager.manager.controller.param.OpenBusSubmitParam;
import com.zy.acs.manager.core.integrate.dto.OpenBusSubmitParam;
import com.zy.acs.manager.manager.entity.*;
import com.zy.acs.manager.manager.enums.*;
import com.zy.acs.manager.manager.service.*;
@@ -107,11 +104,12 @@
    @Transactional
    public Bus generateBusAndTask(OpenBusSubmitParam busSubmitParam, String memo) {
        String errorMsg = busService.checkoutValid(busSubmitParam);
        Boolean maintainLocSts = configService.getVal("maintainLocSts", Boolean.class);
        if (!Cools.isEmpty(errorMsg)) {
            throw new BusinessException(errorMsg);
        }
        String batch = busSubmitParam.getBatch();
        List<TaskDto> taskDtoList = busSubmitParam.getTaskList();
        String batchNo = busSubmitParam.getBatchNo();
        List<TaskDto> taskDtoList = busSubmitParam.getTasks();
        if (Cools.isEmpty(taskDtoList)) {
            throw new BusinessException("taskList can't be empty!");
        }
@@ -126,7 +124,7 @@
        Date now = new Date();
        Bus bus = new Bus();
        bus.setUuid(String.valueOf(snowflakeIdWorker.nextId()).substring(3));
        bus.setBusNo(batch);
        bus.setBusNo(batchNo);
        bus.setStartTime(now);
        bus.setBusSts(BusStsType.RECEIVE.val());
        bus.setMemo(memo);
@@ -150,35 +148,39 @@
            Sta destSta = null;
            switch (TaskTypeType.get(task.getTaskTypeEl())) {
                case LOC_TO_LOC:
                    oriLoc = locService.getById(task.getOriLoc());
                    if (!oriLoc.getLocSts().equals(LocStsType.STOCK.val())) {
                        throw new BusinessException("oriLoc:" + task.getOriLoc$() + " is not in STOCK status");
                    }
                    oriLoc.setLocSts(LocStsType.PAKOUT.val());
                    oriLoc.setUpdateTime(now);
                    if (!locService.updateById(oriLoc)) {
                        throw new BusinessException("oriLoc:" + task.getOriLoc$() + " failed to update");
                    }
                    if (maintainLocSts) {
                        oriLoc = locService.getById(task.getOriLoc());
                        if (!oriLoc.getLocSts().equals(LocStsType.STOCK.val())) {
                            throw new BusinessException("oriLoc:" + task.getOriLoc$() + " is not in STOCK status");
                        }
                        oriLoc.setLocSts(LocStsType.PAKOUT.val());
                        oriLoc.setUpdateTime(now);
                        if (!locService.updateById(oriLoc)) {
                            throw new BusinessException("oriLoc:" + task.getOriLoc$() + " failed to update");
                        }
                    destLoc = locService.getById(task.getDestLoc());
                    if (!destLoc.getLocSts().equals(LocStsType.IDLE.val())) {
                        throw new BusinessException("destLoc:" + task.getDestLoc$() + " is not in IDLE status");
                    }
                    destLoc.setLocSts(LocStsType.PAKIN.val());
                    destLoc.setUpdateTime(now);
                    if (!locService.updateById(destLoc)) {
                        throw new BusinessException("destLoc:" + task.getDestLoc$() + " failed to update");
                        destLoc = locService.getById(task.getDestLoc());
                        if (!destLoc.getLocSts().equals(LocStsType.IDLE.val())) {
                            throw new BusinessException("destLoc:" + task.getDestLoc$() + " is not in IDLE status");
                        }
                        destLoc.setLocSts(LocStsType.PAKIN.val());
                        destLoc.setUpdateTime(now);
                        if (!locService.updateById(destLoc)) {
                            throw new BusinessException("destLoc:" + task.getDestLoc$() + " failed to update");
                        }
                    }
                    break;
                case LOC_TO_STA:
                    oriLoc = locService.getById(task.getOriLoc());
                    if (!oriLoc.getLocSts().equals(LocStsType.STOCK.val())) {
                        throw new BusinessException("oriLoc:" + task.getOriLoc$() + " is not in STOCK status");
                    }
                    oriLoc.setLocSts(LocStsType.PAKOUT.val());
                    oriLoc.setUpdateTime(now);
                    if (!locService.updateById(oriLoc)) {
                        throw new BusinessException("oriLoc:" + task.getOriLoc$() + " failed to update");
                    if (maintainLocSts) {
                        oriLoc = locService.getById(task.getOriLoc());
                        if (!oriLoc.getLocSts().equals(LocStsType.STOCK.val())) {
                            throw new BusinessException("oriLoc:" + task.getOriLoc$() + " is not in STOCK status");
                        }
                        oriLoc.setLocSts(LocStsType.PAKOUT.val());
                        oriLoc.setUpdateTime(now);
                        if (!locService.updateById(oriLoc)) {
                            throw new BusinessException("oriLoc:" + task.getOriLoc$() + " failed to update");
                        }
                    }
                    destSta = staService.getById(task.getDestSta());
@@ -192,14 +194,16 @@
                        throw new BusinessException("oriSta:" + task.getOriSta$() + " failed to reserve");
                    }
                    destLoc = locService.getById(task.getDestLoc());
                    if (!destLoc.getLocSts().equals(LocStsType.IDLE.val())) {
                        throw new BusinessException("destLoc:" + task.getDestLoc$() + " is not in IDLE status");
                    }
                    destLoc.setLocSts(LocStsType.PAKIN.val());
                    destLoc.setUpdateTime(now);
                    if (!locService.updateById(destLoc)) {
                        throw new BusinessException("destLoc:" + task.getDestLoc$() + " failed to update");
                    if (maintainLocSts) {
                        destLoc = locService.getById(task.getDestLoc());
                        if (!destLoc.getLocSts().equals(LocStsType.IDLE.val())) {
                            throw new BusinessException("destLoc:" + task.getDestLoc$() + " is not in IDLE status");
                        }
                        destLoc.setLocSts(LocStsType.PAKIN.val());
                        destLoc.setUpdateTime(now);
                        if (!locService.updateById(destLoc)) {
                            throw new BusinessException("destLoc:" + task.getDestLoc$() + " failed to update");
                        }
                    }
                    break;
                case STA_TO_STA:
@@ -794,6 +798,7 @@
            task.setPriority(taskType.equals(TaskTypeType.TO_CHARGE)?2:1);
            task.setTaskSts(TaskStsType.ASSIGN.val());
            task.setTaskType(taskType.val());
            task.setUplinkSts(TaskUplinkStateType.SKIPPED.toString());
            task.setIoTime(now);
            task.setStartTime(now);
            if (!taskService.save(task)) {
@@ -895,6 +900,8 @@
            long actionPrepareSts = ActionStsType.PREPARE.val();
//            JSONObject storeDirection = configService.getVal("storeDirection", JSONObject.class);
            int angleOffsetVal = configService.getVal("mapAngleOffsetVal", Integer.class);
//            Double defaultShelfDepth = configService.getVal("defaultShelfDepth", Double.class);
//            defaultShelfDepth = Optional.ofNullable(defaultShelfDepth).orElse((double) 0);
            String agvNo = agvService.getAgvNo(agvId);
//            if (!agvService.judgeEnable(agvId)) {
//                throw new CoolException("AGV[" + agvNo + "]当前不可用...");
@@ -1148,7 +1155,7 @@
                }
                // 作业点动作
                AgvDirectionType agvDirectionType;
                ActuatorDirectionType actuatorDirectionType;
                Double staWorkDirection;
                AgvBackpackType backpackType = AgvBackpackType.query(segment.getBackpack());
                switch (Objects.requireNonNull(TaskPosDto.queryPosType(segment.getPosType()))) {
@@ -1161,7 +1168,8 @@
                        // 货架取货
                        Loc oriLoc = locService.getById(task.getOriLoc());
                        // 计算左右方向
                        agvDirectionType = mapService.calculateAgvWorkDirectionByShelf(oriLoc, lastCode);
                        actuatorDirectionType = ActuatorDirectionType.fromVal(oriLoc.getCompDirect());
//                        actuatorDirectionType = mapService.calculateAgvWorkDirectionByShelf(oriLoc, lastCode);
                        actionList.add(new Action(
                                null,    // 编号
                                task.getBusId(),    // 总线
@@ -1169,9 +1177,9 @@
                                null,    // 动作号
                                null,    // 优先级
                                ActionTypeType.ReadyTakeFromShelvesLoc.desc,    // 名称
                                (double) agvDirectionType.val,    // 属性值
                                (double) actuatorDirectionType.val,    // 属性值
                                lastCode.getData(),    // 地面码
                                String.valueOf(oriLoc.getOffset()),   // 动作参数
                                JSON.toJSONString(new HeightDepthDto(oriLoc.getOffset())),   // 动作参数
                                ActionTypeType.ReadyTakeFromShelvesLoc.val(),    // 动作类型
                                actionPrepareSts,    // 动作进度
                                agvId,    // AGV
@@ -1224,7 +1232,8 @@
                        // 货架放货
                        Loc destLoc = locService.getById(task.getDestLoc());
                        // 计算左右方向
                        agvDirectionType = mapService.calculateAgvWorkDirectionByShelf(destLoc, lastCode);
                        actuatorDirectionType = ActuatorDirectionType.fromVal(destLoc.getCompDirect());
//                        actuatorDirectionType = mapService.calculateAgvWorkDirectionByShelf(destLoc, lastCode);
                        actionList.add(new Action(
                                null,    // 编号
                                task.getBusId(),    // 总线
@@ -1232,9 +1241,9 @@
                                null,    // 动作号
                                 null,    // 优先级
                                ActionTypeType.ReadyReleaseToShelvesLoc.desc,    // 名称
                                (double) agvDirectionType.val,    // 属性值
                                (double) actuatorDirectionType.val,    // 属性值
                                lastCode.getData(),    // 地面码
                                String.valueOf(destLoc.getOffset()),   // 动作参数
                                JSON.toJSONString(new HeightDepthDto(destLoc.getOffset())),   // 动作参数
                                ActionTypeType.ReadyReleaseToShelvesLoc.val(),    // 动作类型
                                actionPrepareSts,    // 动作进度
                                agvId,    // AGV
@@ -1269,7 +1278,8 @@
                            lastDirection = oriStaWorkDirection;
                        }
                        // 计算货叉工作方向
                        staWorkDirection = mapService.calculateAgvWorkDirectionByStation(oriStaWorkDirection, lastDirection);
                        actuatorDirectionType = ActuatorDirectionType.fromVal(oriSta.getActDir());
//                        staWorkDirection = mapService.calculateAgvWorkDirectionByStation(oriStaWorkDirection, lastDirection);
                        actionList.add(new Action(
                                null,    // 编号
                                task.getBusId(),    // 总线
@@ -1277,9 +1287,9 @@
                                null,    // 动作号
                                null,    // 优先级
                                ActionTypeType.ReadyTakeFromConveyorSta.desc,    // 名称
                                staWorkDirection,    // 属性值
                                (double) actuatorDirectionType.val,    // 属性值
                                lastCode.getData(),    // 地面码
                                String.valueOf(oriSta.getOffset()),   // 动作参数
                                JSON.toJSONString(new HeightDepthDto(oriSta.getHeight(), Optional.ofNullable(oriSta.getDepth()).orElse((double) 0))),   // 动作参数
                                ActionTypeType.ReadyTakeFromConveyorSta.val(),    // 动作类型
                                actionPrepareSts,    // 动作进度
                                agvId,    // AGV
@@ -1352,7 +1362,8 @@
                            ));
                        }
                        // 计算货叉工作方向
                        staWorkDirection = mapService.calculateAgvWorkDirectionByStation(destStaWorkDirection, lastDirection);
//                        staWorkDirection = mapService.calculateAgvWorkDirectionByStation(destStaWorkDirection, lastDirection);
                        actuatorDirectionType = ActuatorDirectionType.fromVal(destSta.getActDir());
                        actionList.add(new Action(
                                null,    // 编号
                                task.getBusId(),    // 总线
@@ -1360,9 +1371,9 @@
                                null,    // 动作号
                                null,    // 优先级
                                ActionTypeType.ReadyReleaseToConveyorSta.desc,    // 名称
                                staWorkDirection,    // 属性值
                                (double) actuatorDirectionType.val,    // 属性值
                                lastCode.getData(),    // 地面码
                                String.valueOf(destSta.getOffset()),   // 动作参数
                                JSON.toJSONString(new HeightDepthDto(destSta.getHeight(), Optional.ofNullable(destSta.getDepth()).orElse((double) 0))),   // 动作参数
                                ActionTypeType.ReadyReleaseToConveyorSta.val(),    // 动作类型
                                actionPrepareSts,    // 动作进度
                                agvId,    // AGV
@@ -1635,14 +1646,22 @@
                        agvAction.add(new AgvActionItem<>(ReadyTakeFromShelvesLoc.class)
                                .setVal(action.getVal().intValue())
                                .setQrCode(action.getCode())
                                .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams())))
                                .bodySync((body) -> {
                                    HeightDepthDto heightDepthDto = JSON.parseObject(action.getParams(), HeightDepthDto.class);
                                    body.setHeight(heightDepthDto.getHeight());
                                    body.setDepth(heightDepthDto.getDepth());
                                })
                        );
                        break;
                    case ReadyTakeFromConveyorSta:
                        agvAction.add(new AgvActionItem<>(ReadyTakeFromConveyorSta.class)
                                .setVal(action.getVal().intValue())
                                .setQrCode(action.getCode())
                                .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams())))
                                .bodySync((body) -> {
                                    HeightDepthDto heightDepthDto = JSON.parseObject(action.getParams(), HeightDepthDto.class);
                                    body.setHeight(heightDepthDto.getHeight());
                                    body.setDepth(heightDepthDto.getDepth());
                                })
                        );
                        break;
                    case ReadyTakeFromAgvSite:
@@ -1656,21 +1675,22 @@
                        agvAction.add(new AgvActionItem<>(ReadyReleaseToShelvesLoc.class)
                                .setVal(action.getVal().intValue())
                                .setQrCode(action.getCode())
                                .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams())))
                        );
                        break;
                    case LoadPlatformLift:
                        agvAction.add(new AgvActionItem<>(LoadPlatformLift.class)
                                .setVal(action.getVal().intValue())
                                .setQrCode(action.getCode())
                                .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams())))
                                .bodySync((body) -> {
                                    HeightDepthDto heightDepthDto = JSON.parseObject(action.getParams(), HeightDepthDto.class);
                                    body.setHeight(heightDepthDto.getHeight());
                                    body.setDepth(heightDepthDto.getDepth());
                                })
                        );
                        break;
                    case ReadyReleaseToConveyorSta:
                        agvAction.add(new AgvActionItem<>(ReadyReleaseToConveyorSta.class)
                                .setVal(action.getVal().intValue())
                                .setQrCode(action.getCode())
                                .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams())))
                                .bodySync((body) -> {
                                    HeightDepthDto heightDepthDto = JSON.parseObject(action.getParams(), HeightDepthDto.class);
                                    body.setHeight(heightDepthDto.getHeight());
                                    body.setDepth(heightDepthDto.getDepth());
                                })
                        );
                        break;
                    case ReadyReleaseToAgvSite:
@@ -1678,6 +1698,13 @@
                                .setVal(action.getVal().intValue())
                                .setQrCode(action.getCode())
                                .bodySync(body -> body.setDepth((short) Double.parseDouble(action.getParams())))
                        );
                        break;
                    case LoadPlatformLift:
                        agvAction.add(new AgvActionItem<>(LoadPlatformLift.class)
                                .setVal(action.getVal().intValue())
                                .setQrCode(action.getCode())
                                .bodySync(body -> body.setHeight((short) Double.parseDouble(action.getParams())))
                        );
                        break;
                    case FinishPath:
@@ -1854,7 +1881,7 @@
                                // load from sta
                                sta = staService.getById(currTask.getOriSta());
                                // reserve to be waiting
                                if (!staReserveService.waitingStaReserve(sta, currTask, 1, StaReserveType.OUT)) {
                                if (!staReserveService.waitingStaReserve(sta, currTask, currSeg, 1, StaReserveType.OUT)) {
                                    break;
                                }
                                // convey plc valid
@@ -1870,7 +1897,7 @@
                                // place to sta
                                sta = staService.getById(currTask.getDestSta());
                                // reserve to be waiting
                                if (!staReserveService.waitingStaReserve(sta, currTask, 1, StaReserveType.IN)) {
                                if (!staReserveService.waitingStaReserve(sta, currTask, currSeg, 1, StaReserveType.IN)) {
                                    break;
                                }
                                // convey plc valid