#
vincentlu
5 小时以前 6cbb420754e6e29fa134a6afca4514b8dfd62918
zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/StaReserveServiceImpl.java
@@ -3,6 +3,7 @@
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;
@@ -10,6 +11,7 @@
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;
@@ -26,8 +28,8 @@
@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;
@@ -111,8 +113,8 @@
        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
@@ -131,7 +133,6 @@
        if (Cools.isEmpty(list)) {
            return false;
        }
        StaReserve reserve = list.get(0);
        StaReserveStateType stateType = StaReserveStateType.of(reserve.getState());
@@ -145,11 +146,15 @@
    }
    @Override
    public Boolean rollbackWaitingToReserved(Sta sta, Task currTask, StaReserveType staReserveType) {
        rollbackWaitingToReserved
        return null;
    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
@@ -205,6 +210,84 @@
        }
    }
    @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();