| | |
| | | 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.common.exception.BusinessException; |
| | | import com.zy.acs.manager.manager.entity.Sta; |
| | | import com.zy.acs.manager.manager.entity.StaReserve; |
| | |
| | | import com.zy.acs.manager.manager.enums.StaReserveStateType; |
| | | import com.zy.acs.manager.manager.enums.StaReserveType; |
| | | import com.zy.acs.manager.manager.enums.StatusType; |
| | | import com.zy.acs.manager.manager.enums.TaskTypeType; |
| | | import com.zy.acs.manager.manager.mapper.StaMapper; |
| | | import com.zy.acs.manager.manager.mapper.StaReserveMapper; |
| | | import com.zy.acs.manager.manager.service.StaReserveService; |
| | |
| | | @Service("staReserveService") |
| | | public class StaReserveServiceImpl extends ServiceImpl<StaReserveMapper, StaReserve> implements StaReserveService { |
| | | |
| | | public static final Long RESERVE_EXPIRE_TIME = 30 * 60 * 1000L; |
| | | public static final Long WAITING_EXPIRE_TIME = 5 * 60 * 1000L; |
| | | public static final Long RESERVE_EXPIRE_TIME = 30 * 60L; |
| | | public static final Long WAITING_EXPIRE_TIME = 5 * 60L; |
| | | |
| | | public static final Integer DEFAULT_QTY = 1; |
| | | |
| | |
| | | qty = Optional.ofNullable(qty).orElse(DEFAULT_QTY); |
| | | |
| | | // update reserve to be waiting state |
| | | int changed = this.baseMapper.updateStateToWaiting(sta.getId() |
| | | , task.getId() |
| | | int changed = this.baseMapper.updateStateToWaiting(task.getId() |
| | | , sta.getId() |
| | | , type.toString() |
| | | , StaReserveStateType.WAITING.toString() |
| | | , WAITING_EXPIRE_TIME |
| | |
| | | if (Cools.isEmpty(list)) { |
| | | return false; |
| | | } |
| | | |
| | | StaReserve reserve = list.get(0); |
| | | |
| | | StaReserveStateType stateType = StaReserveStateType.of(reserve.getState()); |
| | |
| | | default: |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Boolean rollbackWaitingToReserved(Sta sta, Task task, StaReserveType type) { |
| | | int changed = this.baseMapper.updateStateBackToWaiting( |
| | | task.getId() |
| | | , sta.getId() |
| | | , type.toString() |
| | | , StaReserveStateType.RESERVED.toString() |
| | | , WAITING_EXPIRE_TIME |
| | | ); |
| | | return changed > 0; |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void allocateCallBack(Task task, Long agvId) { |
| | | if (Cools.isEmpty(task, agvId)) { |
| | | return; |
| | | } |
| | | TaskTypeType taskType = TaskTypeType.get(task.getTaskTypeEl()); |
| | | if (null == taskType) { |
| | | return; |
| | | } |
| | | Date now = new Date(); |
| | | StaReserve inStaReserve = null; |
| | | StaReserve outStaReserve = null; |
| | | switch (taskType) { |
| | | case LOC_TO_STA: |
| | | inStaReserve = this.getOne(new LambdaQueryWrapper<StaReserve>() |
| | | .eq(StaReserve::getTaskId, task.getId()) |
| | | .eq(StaReserve::getStaId, task.getDestSta()) |
| | | .eq(StaReserve::getType, StaReserveType.IN.toString()) |
| | | .eq(StaReserve::getState, StaReserveStateType.RESERVED.toString()) |
| | | // .gt(StaReserve::getExpireTime, now) |
| | | ); |
| | | if (null == inStaReserve) { |
| | | throw new CoolException("failed to find out sta reserve"); |
| | | } |
| | | break; |
| | | case STA_TO_LOC: |
| | | outStaReserve = this.getOne(new LambdaQueryWrapper<StaReserve>() |
| | | .eq(StaReserve::getTaskId, task.getId()) |
| | | .eq(StaReserve::getStaId, task.getOriSta()) |
| | | .eq(StaReserve::getType, StaReserveType.OUT.toString()) |
| | | .eq(StaReserve::getState, StaReserveStateType.RESERVED.toString()) |
| | | // .gt(StaReserve::getExpireTime, now) |
| | | ); |
| | | if (null == outStaReserve) { |
| | | throw new CoolException("failed to find out sta reserve"); |
| | | } |
| | | break; |
| | | case STA_TO_STA: |
| | | inStaReserve = this.getOne(new LambdaQueryWrapper<StaReserve>() |
| | | .eq(StaReserve::getTaskId, task.getId()) |
| | | .eq(StaReserve::getStaId, task.getDestSta()) |
| | | .eq(StaReserve::getType, StaReserveType.IN.toString()) |
| | | .eq(StaReserve::getState, StaReserveStateType.RESERVED.toString()) |
| | | // .gt(StaReserve::getExpireTime, now) |
| | | ); |
| | | outStaReserve = this.getOne(new LambdaQueryWrapper<StaReserve>() |
| | | .eq(StaReserve::getTaskId, task.getId()) |
| | | .eq(StaReserve::getStaId, task.getOriSta()) |
| | | .eq(StaReserve::getType, StaReserveType.OUT.toString()) |
| | | .eq(StaReserve::getState, StaReserveStateType.RESERVED.toString()) |
| | | // .gt(StaReserve::getExpireTime, now) |
| | | ); |
| | | if (null == inStaReserve) { |
| | | throw new CoolException("failed to find out sta reserve"); |
| | | } |
| | | if (null == outStaReserve) { |
| | | throw new CoolException("failed to find out sta reserve"); |
| | | } |
| | | break; |
| | | default: |
| | | return; |
| | | } |
| | | if (null != inStaReserve) { |
| | | inStaReserve.setAgvId(agvId); |
| | | inStaReserve.setUpdateTime(now); |
| | | if (!this.updateById(inStaReserve)) { |
| | | throw new CoolException("failed to update sta reserve"); |
| | | } |
| | | } |
| | | if (null != outStaReserve) { |
| | | outStaReserve.setAgvId(agvId); |
| | | outStaReserve.setUpdateTime(now); |
| | | if (!this.updateById(outStaReserve)) { |
| | | throw new CoolException("failed to update sta reserve"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | private String generateReserveUniqKey(Long staId, Long taskId, StaReserveType type) { |
| | | return "STA:" + staId + "-TASK:" + taskId + "-T:" + type.toString(); |