1
1 天以前 5e53e4f9156c5712de7cdb7f72e7cd1605c279be
rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskSchedules.java
@@ -1,5 +1,6 @@
package com.vincent.rsf.server.manager.schedules;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -8,6 +9,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.cfg.CoercionAction;
import com.fasterxml.jackson.databind.cfg.CoercionInputShape;
import com.vincent.rsf.framework.common.Cools;
import com.vincent.rsf.framework.common.R;
import com.vincent.rsf.framework.exception.CoolException;
import com.vincent.rsf.server.api.config.RemotesInfoProperties;
@@ -91,6 +93,43 @@
    private RemotesInfoProperties.RcsApi rcsApi;
    @Autowired
    private BasStationService basStationService;
//    /**
//     * 任务下发
//     */
//    @Scheduled(cron = "0/5 * * * * ?  ")
//    @Transactional(rollbackFor = Exception.class)
//    public void pubTaskToWcs() {
//        Long loginUserId = SystemAuthUtils.getLoginUserId();
//        List<Integer> list = Arrays.asList(TaskType.TASK_TYPE_IN.type, TaskType.TASK_TYPE_OUT.type, TaskType.TASK_TYPE_LOC_MOVE.type, TaskType.TASK_TYPE_EMPTY_IN.type
//                , TaskType.TASK_TYPE_CHECK_IN.type, TaskType.TASK_TYPE_MERGE_IN.type, TaskType.TASK_TYPE_EMPTY_OUT.type, TaskType.TASK_TYPE_PICK_IN.type,
//                TaskType.TASK_TYPE_PICK_AGAIN_OUT.type, TaskType.TASK_TYPE_CHECK_OUT.type, TaskType.TASK_TYPE_MERGE_OUT.type);
//        List<Integer> integers = Arrays.asList(TaskStsType.GENERATE_IN.id, TaskStsType.GENERATE_OUT.id);
//        List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
//                .in(Task::getTaskType, list)
//                .in(Task::getTaskStatus, integers).last("limit 1")
//                .orderByDesc(Task::getSort));
//        for (Task task : tasks) {
//            /**移库不做站点操作*/
//            if (!task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
//                BasStation station = basStationService.getOne(new LambdaQueryWrapper<BasStation>()
//                        .eq(BasStation::getStationName,
//                                task.getTaskStatus().equals(TaskStsType.GENERATE_IN.id) ? task.getOrgSite() : task.getTargSite()));
//                if (Cools.isEmpty(station)){
//                    log.info("非光电站点任务下发:站点信息异常,任务信息:"+ JSON.toJSONString(task));
//                    continue;
//                }
//                if (station.getType().equals(StationTypeEnum.STATION_TYPE_MUTI.type)) {
//                    continue;
//                }
//            }
//            /**下发普通站点任务,报错回滚,不再往下执行*/
//            pubTaskToWcs(task);
//        }
//    }
    /**
     * @param
@@ -233,98 +272,102 @@
//            });
//        }
    }
    /**
     * 非光电站点任务下发
     */
//
//    /**
//     * 非光电站点任务下发
//     */
//    @Scheduled(cron = "0/5 * * * * ?  ")
    @Transactional(rollbackFor = Exception.class)
    public void pubTaskToWcs() {
        Long loginUserId = SystemAuthUtils.getLoginUserId();
        List<Integer> list = Arrays.asList(TaskType.TASK_TYPE_IN.type, TaskType.TASK_TYPE_OUT.type, TaskType.TASK_TYPE_LOC_MOVE.type, TaskType.TASK_TYPE_EMPITY_IN.type
                , TaskType.TASK_TYPE_CHECK_IN.type, TaskType.TASK_TYPE_MERGE_IN.type, TaskType.TASK_TYPE_EMPITY_OUT.type, TaskType.TASK_TYPE_PICK_IN.type,
                TaskType.TASK_TYPE_PICK_AGAIN_OUT.type, TaskType.TASK_TYPE_CHECK_OUT.type, TaskType.TASK_TYPE_MERGE_OUT.type);
        List<Integer> integers = Arrays.asList(TaskStsType.GENERATE_IN.id, TaskStsType.GENERATE_OUT.id);
        List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
                .in(Task::getTaskType, list)
                .in(Task::getTaskStatus, integers).last("limit 1")
                .orderByDesc(Task::getSort));
        for (Task task : tasks) {
            /**移库不做站点操作*/
            if (!task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
                BasStation station = basStationService.getOne(new LambdaQueryWrapper<BasStation>()
                        .eq(BasStation::getStationName,
                        task.getTaskStatus().equals(TaskStsType.GENERATE_IN.id) ? task.getOrgSite() : task.getTargSite()));
                if (station.getType().equals(StationTypeEnum.STATION_TYPE_MUTI.type)) {
                    continue;
                }
            }
            /**下发普通站点任务,报错回滚,不再往下执行*/
            pubTaskToWcs(task);
        }
    }
    /**
     * @author Ryan
     * @date 2025/9/4
     * @description: 光电站点任务下发
     * @version 1.0
     */
//    @Transactional(rollbackFor = Exception.class)
//    public void pubTaskToWcs() {
//        Long loginUserId = SystemAuthUtils.getLoginUserId();
//        List<Integer> list = Arrays.asList(TaskType.TASK_TYPE_IN.type, TaskType.TASK_TYPE_OUT.type, TaskType.TASK_TYPE_LOC_MOVE.type, TaskType.TASK_TYPE_EMPTY_IN.type
//                , TaskType.TASK_TYPE_CHECK_IN.type, TaskType.TASK_TYPE_MERGE_IN.type, TaskType.TASK_TYPE_EMPTY_OUT.type, TaskType.TASK_TYPE_PICK_IN.type,
//                TaskType.TASK_TYPE_PICK_AGAIN_OUT.type, TaskType.TASK_TYPE_CHECK_OUT.type, TaskType.TASK_TYPE_MERGE_OUT.type);
//        List<Integer> integers = Arrays.asList(TaskStsType.GENERATE_IN.id, TaskStsType.GENERATE_OUT.id);
//        List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
//                .in(Task::getTaskType, list)
//                .in(Task::getTaskStatus, integers).last("limit 1")
//                .orderByDesc(Task::getSort));
//        for (Task task : tasks) {
//            /**移库不做站点操作*/
//            if (!task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
//                BasStation station = basStationService.getOne(new LambdaQueryWrapper<BasStation>()
//                        .eq(BasStation::getStationName,
//                        task.getTaskStatus().equals(TaskStsType.GENERATE_IN.id) ? task.getOrgSite() : task.getTargSite()));
//                if (Cools.isEmpty(station)){
//                    log.info("非光电站点任务下发:站点信息异常,任务信息:"+ JSON.toJSONString(task));
//                    continue;
//                }
//                if (station.getType().equals(StationTypeEnum.STATION_TYPE_MUTI.type)) {
//                    continue;
//                }
//            }
//            /**下发普通站点任务,报错回滚,不再往下执行*/
//            pubTaskToWcs(task);
//        }
//    }
//
//    /**
//     * @author Ryan
//     * @date 2025/9/4
//     * @description: 光电站点任务下发
//     * @version 1.0
//     */
//    @Scheduled(cron = "0/5 * * * * ?  ")
    @Transactional(rollbackFor = Exception.class)
    public void taskToWCS() throws Exception {
        Long loginUserId = SystemAuthUtils.getLoginUserId();
        List<Integer> list = Arrays.asList(TaskType.TASK_TYPE_IN.type, TaskType.TASK_TYPE_OUT.type, TaskType.TASK_TYPE_LOC_MOVE.type, TaskType.TASK_TYPE_EMPITY_IN.type
                , TaskType.TASK_TYPE_CHECK_IN.type, TaskType.TASK_TYPE_MERGE_IN.type, TaskType.TASK_TYPE_EMPITY_OUT.type,
                TaskType.TASK_TYPE_PICK_AGAIN_OUT.type, TaskType.TASK_TYPE_CHECK_OUT.type, TaskType.TASK_TYPE_MERGE_OUT.type);
        List<Integer> integers = Arrays.asList(TaskStsType.GENERATE_IN.id, TaskStsType.GENERATE_OUT.id);
        List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
                .in(Task::getTaskType, list)
                .in(Task::getTaskStatus, integers)
                .orderByDesc(Task::getSort));
        for (Task task : tasks) {
            /**移库不做站点操作*/
            if (!task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
                BasStation station = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName,
                        task.getTaskStatus().equals(TaskStsType.GENERATE_IN.id) ? task.getOrgSite() : task.getTargSite()));
                /**过滤掉普通站点任务*/
                if (station.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) {
                    continue;
                }
                Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getBarcode, task.getBarcode()));
                if (Objects.isNull(loc)) {
                    continue;
                }
                //判断是否深库位
                if (!LocUtils.isShallowLoc(loc.getCode())) {
                    //获取深库位对应的浅库位
                    String shallowLoc = LocUtils.getShallowLoc(loc.getCode());
                    if (StringUtils.isBlank(shallowLoc)) {
                        continue;
                    }
                    Loc shalloc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, shallowLoc));
                    if (Objects.isNull(shalloc) || !shalloc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_F.type)) {
                        //如果浅库位不在库跳出循环
                        continue;
                    }
                    LocToTaskParams params = new LocToTaskParams();
                    params.setOrgLoc(shallowLoc).setType(TaskType.TASK_TYPE_LOC_MOVE.type + "");
                    //生成移库任务
                    Task moveTask = locItemService.genMoveTask(params, loginUserId);
                    moveTask.setSort(!Objects.isNull(task.getSort()) ? task.getSort() + 1 : Constants.TASK_SORT_DEFAULT_VALUE + 1);
                    if (!taskService.updateById(moveTask)) {
                        throw new Exception("任务优先级更新失败!!");
                    }
                }
            }
            /**下发任务*/
            try {
                pubTaskToWcs(task);
            } catch (Exception e) {
                log.error("任务下发失败!!", e);
            }
        }
    }
//    @Transactional(rollbackFor = Exception.class)
//    public void taskToWCS() throws Exception {
//        Long loginUserId = SystemAuthUtils.getLoginUserId();
//        List<Integer> list = Arrays.asList(TaskType.TASK_TYPE_IN.type, TaskType.TASK_TYPE_OUT.type, TaskType.TASK_TYPE_LOC_MOVE.type, TaskType.TASK_TYPE_EMPTY_IN.type
//                , TaskType.TASK_TYPE_CHECK_IN.type, TaskType.TASK_TYPE_MERGE_IN.type, TaskType.TASK_TYPE_EMPTY_OUT.type,
//                TaskType.TASK_TYPE_PICK_AGAIN_OUT.type, TaskType.TASK_TYPE_CHECK_OUT.type, TaskType.TASK_TYPE_MERGE_OUT.type);
//        List<Integer> integers = Arrays.asList(TaskStsType.GENERATE_IN.id, TaskStsType.GENERATE_OUT.id);
//        List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
//                .in(Task::getTaskType, list)
//                .in(Task::getTaskStatus, integers)
//                .orderByDesc(Task::getSort));
//        for (Task task : tasks) {
//            /**移库不做站点操作*/
//            if (!task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
//                BasStation station = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName,
//                        task.getTaskStatus().equals(TaskStsType.GENERATE_IN.id) ? task.getOrgSite() : task.getTargSite()));
//                /**过滤掉普通站点任务*/
//                if (station.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) {
//                    continue;
//                }
//                Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getBarcode, task.getBarcode()));
//                if (Objects.isNull(loc)) {
//                    continue;
//                }
//                //判断是否深库位
//                if (!LocUtils.isShallowLoc(loc.getCode())) {
//                    //获取深库位对应的浅库位
//                    String shallowLoc = LocUtils.getShallowLoc(loc.getCode());
//                    if (StringUtils.isBlank(shallowLoc)) {
//                        continue;
//                    }
//                    Loc shalloc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, shallowLoc));
//                    if (Objects.isNull(shalloc) || !shalloc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_F.type)) {
//                        //如果浅库位不在库跳出循环
//                        continue;
//                    }
//                    LocToTaskParams params = new LocToTaskParams();
//                    params.setOrgLoc(shallowLoc).setType(TaskType.TASK_TYPE_LOC_MOVE.type + "");
//                    //生成移库任务
//                    Task moveTask = locItemService.genMoveTask(params, loginUserId);
//                    moveTask.setSort(!Objects.isNull(task.getSort()) ? task.getSort() + 1 : Constants.TASK_SORT_DEFAULT_VALUE + 1);
//                    if (!taskService.updateById(moveTask)) {
//                        throw new Exception("任务优先级更新失败!!");
//                    }
//                }
//            }
//            /**下发任务*/
//            try {
//                pubTaskToWcs(task);
//            } catch (Exception e) {
//                log.error("任务下发失败!!", e);
//            }
//        }
//    }
    /**
     * 每五秒校验深库位是否为空,如果浅库位有货,将浅库位移至深库位
@@ -367,14 +410,59 @@
        BasStation station = null;
        if (!task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
             station = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, task.getTargSite()));
            station = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, task.getTargSite()));
            if (Objects.isNull(station)) {
                throw new CoolException("站点不存在!!");
            }
        }
        /**判断是否光电站点,非光店站点需管控站点状态*/
        /**判断是否起点系统类型  非标准程序*/
        Loc locStart = null;
        if (task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type) || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_OUT.type) ||
                task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type) || task.getTaskType().equals(TaskType.TASK_TYPE_EMPTY_OUT.type)) {
            locStart = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, task.getOrgLoc()));
            if (Objects.isNull(locStart)) {
                throw new CoolException("源库位不存在!!");
            }
        }
        if (!Objects.isNull(locStart)) {
            taskParams.setSign(LocStsWcsOrOtherType.getApiType(locStart.getAreaId$()));
        } else {
            taskParams.setSign(LocStsWcsOrOtherType.LOC_STS_TYPE_RCS.type);
        }
        /**判断是否起点系统类型  非标准程序*/
        if (locStart == null) {
            if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type) || task.getTaskType().equals(TaskType.TASK_TYPE_EMPTY_IN.type) ||
                    task.getTaskType().equals(TaskType.TASK_TYPE_PICK_IN.type) ||
                    task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_IN.type) || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)
            ) {
                BasStation stationS = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, task.getOrgSite()));
                if (Objects.isNull(stationS)) {
                    throw new CoolException("源库位不存在!!");
                }
                if (stationS.getType().equals(StationTypeEnum.STATION_TYPE_MUTI.type)) {
                    taskParams.setSign(LocStsWcsOrOtherType.LOC_STS_TYPE_WCS.type);
                } else {
                    Loc locEnd = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, task.getTargLoc()));
                    if (Objects.isNull(locEnd)) {
                        throw new CoolException("源库位不存在!!");
                    }
                    String type = LocStsWcsOrOtherType.getApiType(locEnd.getAreaId$());
                    if (type.equals(LocStsWcsOrOtherType.LOC_STS_TYPE_WCS.type)) {
                        taskParams.setSignType("2");
                    }
                    taskParams.setSign(LocStsWcsOrOtherType.LOC_STS_TYPE_RCS.type);
                }
            }
        }
        /**判断是否光电站点,非光店站点需管控站点状态*/ //目标站点
        if (!Objects.isNull(station) && station.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) {
            if (task.getTaskType() <= TaskType.TASK_TYPE_CHECK_IN.type && !task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
//                if (!station.getUseStatus().equals(LocStsType.LOC_STS_TYPE_F.type)) {
@@ -400,7 +488,7 @@
            itemParam.setOriLoc(task.getOrgLoc()).setDestLoc(task.getTargLoc());
        } else if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)
                || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_IN.type)
                || task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_IN.type)) {
                || task.getTaskType().equals(TaskType.TASK_TYPE_EMPTY_IN.type)) {
            /**全板入库参数*/
            itemParam.setDestLoc(task.getTargLoc())
                    .setOriSta(task.getOrgSite());
@@ -410,7 +498,7 @@
                    .setOriSta(task.getTargSite());
        } else if (task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type)
                || task.getTaskType().equals(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type)
                || task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_OUT.type)
                || task.getTaskType().equals(TaskType.TASK_TYPE_EMPTY_OUT.type)
                || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type)
                || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_OUT.type)) {
            /**出库参数*/
@@ -452,7 +540,7 @@
        ResponseEntity<String> exchange = restTemplate.exchange(pubTakUrl, HttpMethod.POST, httpEntity, String.class);
        log.info("任务下发后,响应结果: {}", exchange);
        if (Objects.isNull(exchange.getBody())) {
            throw new CoolException("任务下发失败!!");
            throw new CoolException("任务下发失败!!,返回参数为空!!!");
        } else {
            try {
                ObjectMapper objectMapper = new ObjectMapper();
@@ -463,7 +551,7 @@
                    if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)
                            || task.getTaskType().equals(TaskType.TASK_TYPE_PICK_IN.type)
                            || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)
                            || task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_IN.type)
                            || task.getTaskType().equals(TaskType.TASK_TYPE_EMPTY_IN.type)
                            || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_IN.type)
                            || task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
                        if (!taskService.update(new LambdaUpdateWrapper<Task>().eq(Task::getTaskCode, task.getTaskCode())
@@ -483,7 +571,7 @@
                    } else if (task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type)
                            || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type)
                            || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_OUT.type)
                            || task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_OUT.type)
                            || task.getTaskType().equals(TaskType.TASK_TYPE_EMPTY_OUT.type)
                            || task.getTaskType().equals(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type)) {
                        if (!taskService.update(new LambdaUpdateWrapper<Task>().eq(Task::getTaskCode, task.getTaskCode())
                                .set(Task::getTaskStatus, TaskStsType.WCS_EXECUTE_OUT.id))) {