#
luxiaotao1123
2024-11-04 7f70cb15d035f0c233b9e62b9e43aa985317c908
zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/FuncStaServiceImpl.java
@@ -4,6 +4,7 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zy.acs.common.enums.AgvStatusType;
import com.zy.acs.framework.common.Cools;
import com.zy.acs.manager.common.utils.CommonUtil;
import com.zy.acs.manager.manager.entity.*;
import com.zy.acs.manager.manager.enums.FuncStaType;
import com.zy.acs.manager.manager.enums.StatusType;
@@ -72,16 +73,27 @@
                return false;
            }
            Agv existAgv = agvService.findByPosition(code);
            Agv agv = agvService.findByPosition(code);
            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 != existAgv) {
                    AgvDetail agvDetail = agvDetailService.selectByAgvId(existAgv.getId());
                    AgvModel agvModel = agvModelService.getById(existAgv.getAgvModel());
                if (null != agv) {
                    AgvModel agvModel = agvModelService.getById(agv.getAgvModel());
                    AgvDetail agvDetail = agvDetailService.selectByAgvId(agv.getId());
                    if (agvDetail.getAgvStatus().equals(AgvStatusType.CHARGE)) {
                        if (agvDetail.getVol() < agvModel.getQuaBattery()) {
                            return false;
                        }
                    } else {
                        Task latestTask = taskService.findLatestTask(agv.getId(), null);
                        if (null != latestTask
                                && latestTask.getTaskType().equals(TaskTypeType.TO_CHARGE.val())
                                && latestTask.getDestCode().equals(funcSta.getCode())
                        ) {
                            // avoid the agv already be full battery but there was no task assign to it, so that not in charge status and battery had down
                            if (agvDetailService.isPowerLoss(agv, agvDetail, agvModel)) {
                                return false;
                            }
                        }
                    }
                }
@@ -99,7 +111,7 @@
            if (funcSta.getType().equals(FuncStaType.STANDBY.toString())) {
                if (null == existAgv) {
                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())
@@ -141,10 +153,10 @@
                @Override
                public int compare(FuncSta o1, FuncSta o2) {
                    Code o1Code = codeService.getById(o1.getCode());
                    int o1Distance = calcPositionDistance(startPos, new Double[]{o1Code.getX(), o1Code.getY()});
                    int o1Distance = CommonUtil.calcDistance(startPos, new Double[]{o1Code.getX(), o1Code.getY()});
                    Code o2Code = codeService.getById(o2.getCode());
                    int o2Distance = calcPositionDistance(startPos, new Double[]{o2Code.getX(), o2Code.getY()});
                    int o2Distance = CommonUtil.calcDistance(startPos, new Double[]{o2Code.getX(), o2Code.getY()});
                    return o1Distance - o2Distance;
                }
@@ -153,10 +165,6 @@
        }
        return funcStaList.stream().findFirst().orElse(null);
    }
    private int calcPositionDistance(Double[] from, Double[] to) {
        return (int) (Math.abs(to[0] - from[0]) + Math.abs(to[1] - from[1]));
    }
}