package com.zy.asrs.wms.apis.wcs.services.Impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.zy.asrs.framework.common.R; import com.zy.asrs.framework.exception.CoolException; import com.zy.asrs.wms.apis.wcs.entity.domain.EssTaskStatus; import com.zy.asrs.wms.apis.wcs.entity.request.*; import com.zy.asrs.wms.apis.wcs.services.WcsApiService; import com.zy.asrs.wms.asrs.entity.Task; import com.zy.asrs.wms.asrs.entity.enums.TaskStsType; import com.zy.asrs.wms.asrs.service.TaskService; import com.zy.asrs.wms.asrs.service.WaitPakinService; import com.zy.asrs.wms.asrs.service.WorkService; import io.jsonwebtoken.lang.Collections; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; @Slf4j @Service public class WcsApiServiceImpl implements WcsApiService { @Autowired private WaitPakinService waitPakinService; @Autowired private WorkService workService; @Autowired private TaskService taskService; /** * 容器到达接收 * 根据ESS返回的容器编码修改任务档中的输送线起始位置节点,及任务档执行状态 * * 当前问题: * * //TODO 1. 目前任务下发接口沟通下来,是需要目标位置的,这里我们只是刚组拖完成,并不是通知流动,没有目标位置 * * //TODO 2. 文档上的搬运任务下发指的都是多任务,多容器搬运,而不是我们需要物料信息同步功能 * * //TODO 3. 流程走不通暂时先跳过,确认是否需要WMS触发料箱滚动至扫码区 * * @param arrivedParam * @param hostId * @return */ @Override @Transactional(rollbackFor = Exception.class) public R containerArrivedNotify(ContainerArrivedParam arrivedParam, String taskType, Long hostId) { List tasks = taskService.list(new LambdaQueryWrapper().eq(Task::getBarcode, arrivedParam.getContainerCode())); if (Collections.isEmpty(tasks)) { return R.error("任务不存在!!"); } if (taskType.equals("inStock")) { //DONE 根据ESS返回的容器编码修改任务档中的输送线起始位置节点,及任务档容器到达状态 taskService.update(new LambdaUpdateWrapper() .set(Task::getTaskSts, TaskStsType.WCS_CONTAINER_RECEIVE.id) .set(Task::getOriginLoc, arrivedParam.getSlotCode()) .eq(Task::getBarcode, arrivedParam.getContainerCode())); } else { boolean update = taskService.update(new LambdaUpdateWrapper() .set(Task::getTaskSts, TaskStsType.WCS_EXECUTE_OUT_ARRIVED.id) .set(Task::getOriginLoc, arrivedParam.getSlotCode()) .eq(Task::getBarcode, arrivedParam.getContainerCode())); } return R.success("success"); } @Override @Transactional(rollbackFor = Exception.class) public void receiveTaskStatus(TasksStatusCallbackParam callbackParam, String stockType, Long hostId) { List list = taskService.list(new LambdaQueryWrapper() .eq(Task::getBarcode, callbackParam.getContainerCode()) .eq(Task::getTaskNo, callbackParam.getTaskCode())); if (!Collections.isEmpty(list)) { list.forEach(task -> { TaskStsType taskStsType = null; if (stockType.equals("inStock")) { //入库任务 if (callbackParam.getEventType().equals(EssTaskStatus.TASK_EVENT_TOTE_LOAD.event)) { //上报取箱状态 if (task.getTaskSts() == TaskStsType.WCS_CONVEYOR_START.id) { taskStsType = TaskStsType.WCS_TOTE_LOAD; } else { String errMsg = "任务编号:" + task.getTaskNo() + "状态为不匹配," + "不能执行:" + TaskStsType.WCS_TOTE_LOAD.desc + "任务"; log.error(errMsg); throw new CoolException(errMsg); } } else if (callbackParam.getEventType().equals(EssTaskStatus.TASK_EVENT_TOTE_UNLOAD.event)) { //上报放箱状态 if (task.getTaskSts() == TaskStsType.WCS_TOTE_LOAD.id) { taskStsType = TaskStsType.WCS_TOTE_UNLOAD; } else { String errMsg = "任务编号:" + task.getTaskNo() + "状态为不匹配," + "不能执行:" + TaskStsType.WCS_TOTE_UNLOAD.desc + "任务"; log.error(errMsg); throw new CoolException(errMsg); } } else if (callbackParam.getEventType().equals(EssTaskStatus.TASK_EVENT_STATUS.event)) { //TODO 需确认上报任务中,任务完成是哪个事件,目前暂定task事件 if (task.getTaskSts() == TaskStsType.WCS_TOTE_UNLOAD.id) { taskStsType = TaskStsType.WCS_PUTAWAY_SUCESS; } else { String errMsg = "任务编号:" + task.getTaskNo() + "状态为不匹配," + "不能执行:" + TaskStsType.WCS_PUTAWAY_SUCESS.desc + "任务"; log.error(errMsg); throw new CoolException(errMsg); } } boolean result = taskService.update(new LambdaUpdateWrapper() .set(Task::getRobotCode, callbackParam.getRobotCode()) .set(Task::getSysTaskCode, callbackParam.getSysTaskCode()) .set(Task::getTaskSts, taskStsType.id) .set(Task::getExcudeStatus, callbackParam.getStatus()) .set(Task::getTaskDesc, callbackParam.getMessage()) .eq(Task::getBarcode, callbackParam.getContainerCode()) .eq(Task::getTaskNo, callbackParam.getTaskCode())); if (callbackParam.getEventType().equals(EssTaskStatus.TASK_EVENT_STATUS.event) && result) { workService.completeTask(task.getId()); } } else { //出库任务 if (callbackParam.getEventType().equals(EssTaskStatus.TASK_EVENT_TOTE_LOAD.event)) { //上报取箱状态 //TODO 定时器开启后,要删除 || task.getTaskType() == TaskStsType.GENERATE_OUT.id if (task.getTaskSts() == TaskStsType.WCS_EXECUTE_OUT.id || task.getTaskSts() == TaskStsType.GENERATE_OUT.id) { taskStsType = TaskStsType.WCS_EXECUTE_OUT_TOTE_LOAD; } else { String errMsg = "任务编号:" + task.getTaskNo() + "状态为不匹配," + "不能执行:" + TaskStsType.WCS_EXECUTE_OUT_TOTE_LOAD.desc + "任务"; log.error(errMsg); throw new CoolException(errMsg); } } else if (callbackParam.getEventType().equals(EssTaskStatus.TASK_EVENT_TOTE_UNLOAD.event)) { //上报放箱状态 if (task.getTaskSts() == TaskStsType.WCS_EXECUTE_OUT_TOTE_LOAD.id) { taskStsType = TaskStsType.WCS_EXECUTE_OUT_TOTE_UNLOAD; } else { String errMsg = "任务编号:" + task.getTaskNo() + "状态为不匹配," + "不能执行:" + TaskStsType.WCS_EXECUTE_OUT_TOTE_UNLOAD.desc + "任务"; log.error(errMsg); throw new CoolException(errMsg); } } else if (callbackParam.getEventType().equals(EssTaskStatus.TASK_EVENT_STATUS.event)) { //上报完成状态 if (task.getTaskSts() == TaskStsType.WCS_EXECUTE_OUT_TOTE_UNLOAD.id || task.getTaskSts() == TaskStsType.WCS_EXECUTE_OUT_TASK_DONE.id) { //出库任务完成,修改状态为播种中,定时任务生成播种波次 taskStsType = TaskStsType.WAVE_SEED; } else { String errMsg = "任务编号:" + task.getTaskNo() + "状态为不匹配," + "不能执行:" + TaskStsType.WCS_EXECUTE_OUT_TASK_DONE.desc + "任务"; log.error(errMsg); throw new CoolException(errMsg); } } //更新出库状态及相关字段 taskService.update(new LambdaUpdateWrapper() .set(Task::getRobotCode, callbackParam.getRobotCode()) .set(Task::getSysTaskCode, callbackParam.getSysTaskCode()) .set(Task::getTaskSts, taskStsType.id) .set(Task::getExcudeStatus, callbackParam.getStatus()) .set(Task::getTaskDesc, callbackParam.getMessage()) .eq(Task::getBarcode, callbackParam.getContainerCode()) .eq(Task::getTaskNo, callbackParam.getTaskCode())); } }); } else { throw new CoolException("更新内容不存在!!"); } } }