|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (funcSta.getType().equals(FuncStaType.CHARGE.toString())) { | 
|---|
|  |  |  | // if the type of this funSta is charge and the existing agv is in charge status, then that means this funSta is occupied | 
|---|
|  |  |  | if (null != agv) { | 
|---|
|  |  |  | AgvModel agvModel = agvModelService.getById(agv.getAgvModel()); | 
|---|
|  |  |  | if (null != agv && !agv.getId().equals(agvId)) { | 
|---|
|  |  |  | AgvModel agvModel = agvModelService.getByAgvId(agv.getId()); | 
|---|
|  |  |  | AgvDetail agvDetail = agvDetailService.selectByAgvId(agv.getId()); | 
|---|
|  |  |  | if (agvDetail.getAgvStatus().equals(AgvStatusType.CHARGE)) { | 
|---|
|  |  |  | if (agvDetail.getVol() < agvModel.getQuaBattery()) { | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // if there is a running task whose destination is this funSta, then that means this funSta is occupied | 
|---|
|  |  |  | if (0 < taskService.count(new LambdaQueryWrapper<Task>() | 
|---|
|  |  |  | .eq(Task::getTaskType, TaskTypeType.TO_CHARGE.val()) | 
|---|
|  |  |  | .in(Task::getTaskType, TaskTypeType.TO_STANDBY.val(), TaskTypeType.TO_CHARGE.val()) | 
|---|
|  |  |  | .in(Task::getTaskSts, TaskStsType.ASSIGN.val(), TaskStsType.PROGRESS.val()) | 
|---|
|  |  |  | .eq(Task::getDestCode, code) | 
|---|
|  |  |  | )) { | 
|---|
|  |  |  | 
|---|
|  |  |  | if (null == agv) { | 
|---|
|  |  |  | // if there is a running task whose destination is this funSta, then that means this funSta is occupied | 
|---|
|  |  |  | if (0 < taskService.count(new LambdaQueryWrapper<Task>() | 
|---|
|  |  |  | .eq(Task::getTaskType, TaskTypeType.TO_STANDBY.val()) | 
|---|
|  |  |  | .in(Task::getTaskType | 
|---|
|  |  |  | , TaskTypeType.TO_STANDBY.val() | 
|---|
|  |  |  | , TaskTypeType.TO_CHARGE.val() | 
|---|
|  |  |  | , TaskTypeType.MOVE.val() | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | .in(Task::getTaskSts, TaskStsType.ASSIGN.val(), TaskStsType.PROGRESS.val()) | 
|---|
|  |  |  | .eq(Task::getDestCode, code) | 
|---|
|  |  |  | )) { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // if there is an agv on the code of this funSta, should we let this agv leave? | 
|---|
|  |  |  | // we need to judge whether the agv went to this funSta based on a task which in GO_STANDBY type | 
|---|
|  |  |  | if (!agv.getId().equals(agvId)) { | 
|---|
|  |  |  | // if there is an agv on the code of this funSta, should we let this agv leave? | 
|---|
|  |  |  | // we need to judge whether the agv went to this funSta based on a task which in GO_STANDBY type | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //                    Task latestTaskByAgv = taskService.findLatestTask(existAgv.getId()); | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (null != codeId) { | 
|---|
|  |  |  | Code currCode = codeService.getById(codeId); | 
|---|
|  |  |  | Code currCode = codeService.getCacheById(codeId); | 
|---|
|  |  |  | Double[] startPos = new Double[]{currCode.getX(), currCode.getY()}; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // checkout one funSta which is the closest | 
|---|
|  |  |  | 
|---|
|  |  |  | funcStaList.sort(new Comparator<FuncSta>() { | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public int compare(FuncSta o1, FuncSta o2) { | 
|---|
|  |  |  | Code o1Code = codeService.getById(o1.getCode()); | 
|---|
|  |  |  | Code o1Code = codeService.getCacheById(o1.getCode()); | 
|---|
|  |  |  | int o1Distance = CommonUtil.calcDistance(startPos, new Double[]{o1Code.getX(), o1Code.getY()}); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Code o2Code = codeService.getById(o2.getCode()); | 
|---|
|  |  |  | Code o2Code = codeService.getCacheById(o2.getCode()); | 
|---|
|  |  |  | int o2Distance = CommonUtil.calcDistance(startPos, new Double[]{o2Code.getX(), o2Code.getY()}); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return o1Distance - o2Distance; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return funcStaList.stream().findFirst().orElse(null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public FuncSta checkoutFurthestFunSta(Long codeId, List<FuncSta> funcStaList) { | 
|---|
|  |  |  | if (Cools.isEmpty(funcStaList)) { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (null != codeId) { | 
|---|
|  |  |  | Code currCode = codeService.getCacheById(codeId); | 
|---|
|  |  |  | Double[] startPos = new Double[]{currCode.getX(), currCode.getY()}; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // checkout one funSta which is the closest | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // compare => compare返回负数,则排在集合前面 (asc) | 
|---|
|  |  |  | funcStaList.sort(new Comparator<FuncSta>() { | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public int compare(FuncSta o1, FuncSta o2) { | 
|---|
|  |  |  | Code o1Code = codeService.getCacheById(o1.getCode()); | 
|---|
|  |  |  | int o1Distance = CommonUtil.calcDistance(startPos, new Double[]{o1Code.getX(), o1Code.getY()}); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Code o2Code = codeService.getCacheById(o2.getCode()); | 
|---|
|  |  |  | int o2Distance = CommonUtil.calcDistance(startPos, new Double[]{o2Code.getX(), o2Code.getY()}); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return o2Distance - o1Distance; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | agv = agvService.findByPosition(funcSta.getCode()); | 
|---|
|  |  |  | if (null != agv) { | 
|---|
|  |  |  | AgvModel agvModel = agvModelService.getById(agv.getAgvModel()); | 
|---|
|  |  |  | AgvModel agvModel = agvModelService.getByAgvId(agv.getId()); | 
|---|
|  |  |  | AgvDetail agvDetail = agvDetailService.selectByAgvId(agv.getId()); | 
|---|
|  |  |  | if (agvDetail.getAgvStatus().equals(AgvStatusType.CHARGE)) { | 
|---|
|  |  |  | return false; | 
|---|