| | |
| | | // 取放货请求包 |
| | | if (msgBody instanceof AGV_06_UP) { |
| | | AGV_06_UP agv_06_up = (AGV_06_UP) msgBody; |
| | | |
| | | log.info("Agv [{}] 取放货请求包 ===>> {}", protocol.getAgvNo(), JSON.toJSONString(agv_06_up)); |
| | | |
| | | // query current segment |
| | | Segment currSeg = segmentService.getCurrRunningSeg(agv.getId(), agv_06_up.getQrCode()); |
| | | if (null == currSeg) { |
| | | log.error("failed to find curr segment [{}]", agv.getUuid()); |
| | | } else { |
| | | boolean success = false; |
| | | |
| | | boolean responseAck = true; |
| | | TaskPosDto.PosType posType = TaskPosDto.PosType.of(currSeg.getPosType()); |
| | | assert null != posType; |
| | | switch (posType) { |
| | | case ORI_LOC: |
| | | case DEST_LOC: |
| | | break; |
| | | case ORI_STA: |
| | | case DEST_STA: |
| | | // todo |
| | | break; |
| | | default: |
| | | responseAck = false; |
| | | log.error("agv[{}] has wrong posType [{}], segment [{}]", protocol.getAgvNo(), posType.toString(), currSeg.getId()); |
| | | break; |
| | | try { |
| | | Code code = codeService.getCacheByData(agv_06_up.getQrCode()); |
| | | |
| | | // query current segment |
| | | Segment currSeg = segmentService.getCurrRunningSeg(agv.getId(), code.getId()); |
| | | if (null == currSeg) { |
| | | log.error("failed to find curr segment [{}]", agv.getUuid()); |
| | | } else { |
| | | |
| | | // query current task |
| | | Task currTask = taskService.getById(currSeg.getTaskId()); |
| | | if (currTask == null || !currTask.getTaskSts().equals(TaskStsType.PROGRESS.val())) { |
| | | |
| | | log.error("agv[{}] task invalid, task={}", protocol.getAgvNo(), currSeg.getTaskId()); |
| | | } else { |
| | | |
| | | Sta sta; |
| | | TaskPosDto.PosType posType = TaskPosDto.PosType.of(currSeg.getPosType()); |
| | | assert null != posType; |
| | | switch (posType) { |
| | | case ORI_LOC: |
| | | case DEST_LOC: |
| | | success = true; |
| | | break; |
| | | case ORI_STA: |
| | | sta = staService.getById(currTask.getOriSta()); |
| | | success = staReserveService.waitingStaReserve(sta, currTask, 1, StaReserveType.OUT); |
| | | // load sta |
| | | // remove expiredTime |
| | | break; |
| | | case DEST_STA: |
| | | // place sta |
| | | sta = staService.getById(currTask.getDestSta()); |
| | | success = staReserveService.waitingStaReserve(sta, currTask, 1, StaReserveType.IN); |
| | | break; |
| | | default: |
| | | log.error("agv[{}] has wrong posType [{}], segment [{}]", protocol.getAgvNo(), posType.toString(), currSeg.getId()); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | if (responseAck) { |
| | | |
| | | // todo:vincent 校验是否可以取放货 |
| | | |
| | | AGV_06_DOWN agv_06_down = new AGV_06_DOWN(); |
| | | agv_06_down.setSerialNo(agv_06_up.getSerialNo()); |
| | | agv_06_down.setActionCode(agv_06_up.getActionCode()); |
| | | agv_06_down.setResult(1); |
| | | |
| | | redis.push(RedisConstant.AGV_PATH_DOWN_FLAG, AgvProtocol.build(protocol.getAgvNo()).setMessageBody(agv_06_down)); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.error("agv[{}] failed to deal with action request, qrCode={}", agv.getUuid(), agv_06_up.getVal(), e); |
| | | } |
| | | |
| | | AGV_06_DOWN agv_06_down = new AGV_06_DOWN(); |
| | | agv_06_down.setSerialNo(agv_06_up.getSerialNo()); |
| | | agv_06_down.setActionCode(agv_06_up.getActionCode()); |
| | | agv_06_down.setResult(success ? 1 : 0); |
| | | |
| | | redis.push(RedisConstant.AGV_PATH_DOWN_FLAG, AgvProtocol.build(protocol.getAgvNo()).setMessageBody(agv_06_down)); |
| | | } |
| | | |
| | | // 料仓信息包 |
| | |
| | | package com.zy.acs.manager.manager.enums; |
| | | |
| | | import com.zy.acs.framework.common.Cools; |
| | | import com.zy.acs.framework.exception.CoolException; |
| | | |
| | | public enum StaReserveStateType { |
| | | |
| | | RESERVED, |
| | |
| | | TIMEOUT, |
| | | ; |
| | | |
| | | public static StaReserveStateType of(String state) { |
| | | if (Cools.isEmpty(state)) { |
| | | return null; |
| | | } |
| | | for (StaReserveStateType type : StaReserveStateType.values()) { |
| | | if (type.toString().equals(state)) { |
| | | return type; |
| | | } |
| | | } |
| | | throw new CoolException("failed to find StaReserveStateType for [" + state + "]"); |
| | | } |
| | | |
| | | } |
| | |
| | | , @Param("state") String state |
| | | ); |
| | | |
| | | int updateStateToWaiting( |
| | | @Param("taskId") Long taskId |
| | | , @Param("staId") Long staId |
| | | , @Param("type") String type |
| | | , @Param("state") String state |
| | | ); |
| | | |
| | | } |
| | |
| | | |
| | | Boolean cancel(Long segmentId, Long userId); |
| | | |
| | | Segment getCurrRunningSeg(Long agvId, String qrCode); |
| | | Segment getCurrRunningSeg(Long agvId, Long codeId); |
| | | |
| | | } |
| | |
| | | |
| | | StaReserve reserveStaOut(Sta sta, Task task, Integer qty); |
| | | |
| | | |
| | | Boolean waitingStaReserve(Sta sta, Task task, Integer qty, StaReserveType type); |
| | | |
| | | |
| | | void confirmStaReserve(Sta sta, Task task, Integer qty, StaReserveType type); |
| | | |
| | | void cancelStaReserve(Sta sta, Task task, Integer qty, StaReserveType type); |
| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.zy.acs.framework.common.Cools; |
| | | import com.zy.acs.framework.exception.CoolException; |
| | | import com.zy.acs.manager.manager.entity.Code; |
| | | import com.zy.acs.manager.manager.entity.Segment; |
| | | import com.zy.acs.manager.manager.entity.Task; |
| | | import com.zy.acs.manager.manager.enums.ActionStsType; |
| | |
| | | import com.zy.acs.manager.manager.enums.TaskStsType; |
| | | import com.zy.acs.manager.manager.mapper.SegmentMapper; |
| | | import com.zy.acs.manager.manager.service.*; |
| | | import com.zy.acs.framework.common.Cools; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Segment getCurrRunningSeg(Long agvId, String qrCode) { |
| | | Code codeId = codeService.getCacheByData(qrCode); |
| | | public Segment getCurrRunningSeg(Long agvId, Long codeId) { |
| | | List<Segment> segments = this.list(new LambdaQueryWrapper<Segment>() |
| | | .eq(Segment::getAgvId, agvId) |
| | | .eq(Segment::getState, SegmentStateType.RUNNING.toString()) |
| | |
| | | package com.zy.acs.manager.manager.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.zy.acs.framework.common.Cools; |
| | | import com.zy.acs.manager.common.exception.BusinessException; |
| | | import com.zy.acs.manager.manager.entity.Sta; |
| | | import com.zy.acs.manager.manager.entity.StaReserve; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.Optional; |
| | | |
| | | @Service("staReserveService") |
| | | public class StaReserveServiceImpl extends ServiceImpl<StaReserveMapper, StaReserve> implements StaReserveService { |
| | | |
| | | public static final Long RESERVE_EXPIRE_TIME = 30 * 60 * 1000L; |
| | | |
| | | public static final Integer DEFAULT_QTY = 1; |
| | | |
| | | @Autowired |
| | | private StaService staService; |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public StaReserve reserveStaIn(Sta sta, Task task, Integer qty) { |
| | | qty = Optional.ofNullable(qty).orElse(1); |
| | | qty = Optional.ofNullable(qty).orElse(DEFAULT_QTY); |
| | | |
| | | // reserve sta in |
| | | if (staMapper.tryReserveIn(sta.getId(), qty) < qty) { |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public StaReserve reserveStaOut(Sta sta, Task task, Integer qty) { |
| | | qty = Optional.ofNullable(qty).orElse(1); |
| | | qty = Optional.ofNullable(qty).orElse(DEFAULT_QTY); |
| | | |
| | | // reserve sta out |
| | | if (staMapper.tryReserveOut(sta.getId(), qty) < qty) { |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean waitingStaReserve(Sta sta, Task task, Integer qty, StaReserveType type) { |
| | | qty = Optional.ofNullable(qty).orElse(DEFAULT_QTY); |
| | | |
| | | // update reserve to be waiting state |
| | | if (0 < this.baseMapper.updateStateToWaiting(sta.getId() |
| | | , task.getId() |
| | | , type.toString() |
| | | , StaReserveStateType.WAITING.toString())) { |
| | | return true; |
| | | } |
| | | |
| | | List<StaReserve> list = this.list(new LambdaQueryWrapper<StaReserve>() |
| | | .eq(StaReserve::getStaId, sta.getId()) |
| | | .eq(StaReserve::getTaskId, task.getId()) |
| | | .eq(StaReserve::getType, type.toString()) |
| | | .eq(StaReserve::getStatus, StatusType.ENABLE.val) |
| | | ); |
| | | |
| | | if (Cools.isEmpty(list)) { |
| | | return false; |
| | | } |
| | | |
| | | StaReserve reserve = list.get(0); |
| | | |
| | | StaReserveStateType stateType = StaReserveStateType.of(reserve.getState()); |
| | | switch (Objects.requireNonNull(stateType)) { |
| | | case WAITING: |
| | | case CONFIRMED: |
| | | return true; |
| | | default: |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void confirmStaReserve(Sta sta, Task task, Integer qty, StaReserveType type) { |
| | | qty = Optional.ofNullable(qty).orElse(1); |
| | | qty = Optional.ofNullable(qty).orElse(DEFAULT_QTY); |
| | | |
| | | // update reserve state to be confirmed |
| | | if (0 == this.baseMapper.updateState(task.getId(), sta.getId(), type.toString(), StaReserveStateType.CONFIRMED.toString())) { |
| | |
| | | |
| | | @Override |
| | | public void cancelStaReserve(Sta sta, Task task, Integer qty, StaReserveType type) { |
| | | qty = Optional.ofNullable(qty).orElse(1); |
| | | qty = Optional.ofNullable(qty).orElse(DEFAULT_QTY); |
| | | |
| | | // update reserve state to be canceled |
| | | if (0 == this.baseMapper.updateState(task.getId(), sta.getId(), type.toString(), StaReserveStateType.CANCELLED.toString())) { |
| | |
| | | AND type = #{type} |
| | | AND deleted = 0 |
| | | AND status = 1 |
| | | -- AND state IN ('WAITING','RESERVED'); |
| | | -- AND state IN ('WAITING','RESERVED') |
| | | </update> |
| | | |
| | | <update id="updateStateToWaiting"> |
| | | UPDATE man_sta_reserve |
| | | SET state = #{state}, |
| | | waiting_at = IFNULL(waiting_at, NOW()), |
| | | update_time = NOW() |
| | | WHERE task_id = #{taskId} |
| | | AND sta_id = #{staId} |
| | | AND type = #{type} |
| | | AND deleted = 0 |
| | | AND status = 1 |
| | | -- AND state IN ('RESERVED','WAITING') |
| | | </update> |
| | | |
| | | </mapper> |