From 7f70cb15d035f0c233b9e62b9e43aa985317c908 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期一, 04 十一月 2024 10:22:45 +0800
Subject: [PATCH] #

---
 zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/FuncStaServiceImpl.java |   42 +++++++++++++++++++-----------------------
 1 files changed, 19 insertions(+), 23 deletions(-)

diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/FuncStaServiceImpl.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/FuncStaServiceImpl.java
index ae89023..d9358ea 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/FuncStaServiceImpl.java
+++ b/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;
@@ -57,19 +58,7 @@
     public List<FuncSta> findInIdleStatus(FuncStaType type, Long agvId) {
         LambdaQueryWrapper<FuncSta> wrapper = new LambdaQueryWrapper<FuncSta>()
                 .eq(FuncSta::getType, type).eq(FuncSta::getStatus, StatusType.ENABLE.val);
-        if (null != agvId) {
-            wrapper.eq(FuncSta::getAgvId, agvId);
-        }
         List<FuncSta> funcStaList = this.list(wrapper);
-        funcStaList = funcStaList.stream().filter(funcSta -> {
-            if (null != funcSta.getAgvId()) {
-                if (!funcSta.getAgvId().equals(agvId)) {
-                    return false;
-                }
-            }
-
-            return true;
-        }).collect(Collectors.toList());
 
         if (Cools.isEmpty(funcStaList)) {
             return new ArrayList<>();
@@ -84,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;
+                            }
                         }
                     }
                 }
@@ -111,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())
@@ -153,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;
                 }
@@ -165,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]));
     }
 
 }

--
Gitblit v1.9.1