bklLiudl
2025-04-28 9b3567a5a2f1a81bec684e8aecda3a1146906cca
Admin.NET/WCS.Application/Util/FourWayCarUtil.cs
@@ -7,6 +7,7 @@
using System.Text;
using System.Threading.Tasks;
using WCS.Application.Entity;
using static Elastic.Clients.Elasticsearch.JoinField;
namespace WCS.Application.Util;
@@ -14,16 +15,67 @@
{
    private static readonly ISqlSugarClient _db = SqlSugarSetup.ITenant.GetConnectionScope(SqlSugarConst.MainConfigId);
    /// <summary>
    ///
    /// </summary>
    /// <param name="list">集合</param>
    /// <param name="moveType">移动类型 0:移动 1:移货 </param>
    /// <returns></returns>
    public static List<CarModel> GetCarPathUp(List<CarModel> list,int moveType)
    {
        for (int i = 0; i < list.Count; i++)
        {
            if (i > 0 && i < list.Count - 1)
            {
                if (list[i].X == list[i + 1].X)
                {
                    list[i].NodeCom = 2;
                }
                else if (list[i].Y == list[i + 1].Y)
                {
                    list[i].NodeCom = 3;
                }
            }
            if (i== 0)
            {
                list[i].IsSendPlc = true;
                if (moveType == 0)
                {
                    if (list[i + 1] == null)
                    {
                        continue;
                    }
                }
                else
                {
                    list[i].NodeCom = 1;
                }
            }
            if (i == list.Count-1)
            {
                list[i].IsSendPlc = true;
                if (moveType == 0)
                {
                    list[i].NodeCom = list[i + 1].NodeCom;
                }
                else
                {
                    list[i].NodeCom = 4;
                }
            }
        }
        return list;
    }
    /// <summary>
    /// 获取小车路径
    /// </summary>
    /// <param name="startLocation">起始位置</param>
    /// <param name="endLocation">目标位置</param>
    /// <param name="moveType">移动类型 0:移动 1:取货 2:放货</param>
    /// <param name="isLoad">是否载货0:未载货  1:已载货</param>
    /// <returns></returns>
    public static List<CarModel> GetCarPath(string startLocation, string endLocation, int moveType, string isLoad = "0")
    public static List<CarModel> GetCarPath(string startLocation, string endLocation,  string isLoad = "0")
    {
        if (string.IsNullOrEmpty(startLocation) || string.IsNullOrEmpty(endLocation))
        {
@@ -174,25 +226,55 @@
                    if (!gScore.ContainsKey(neighbor) || tentativeGScore < gScore[neighbor])
                    {
                        neighbor.IsSendPlc = false;
                        // 补充参数
                        if (neighbor.Equals(end))
                        {
                            neighbor.NodeCom = moveType;
                            neighbor.IsSendPlc = true;
                        }
                        else if (currentModel.Make != locationModel.Make)
                        {
                            if (current.X == neighbor.X)
                            {
                                neighbor.NodeCom = 3;
                            }
                            else if (current.Y == neighbor.Y)
                            {
                                neighbor.NodeCom = 2;
                            }
                            neighbor.IsSendPlc = true;
                        //if (current.X == neighbor.X)
                        //{
                        //    current.NodeCom = 2;
                        //}
                        //else if (current.Y == neighbor.Y)
                        //{
                        //    current.NodeCom = 3;
                        //}
                        //// 补充参数
                        //if (current.Equals(start))
                        //{
                        //    current.NodeCom = moveType;
                        //    current.IsSendPlc = true;
                        //}
                        //if (neighbor.Equals(end))
                        //{
                        //    //neighbor.NodeCom = moveType != 0 ? 2:0 ;
                        //    if (moveType == 1)
                        //    {
                        //        neighbor.NodeCom = 4;
                        //    }
                        //    else
                        //    {
                        //        neighbor.NodeCom = current.NodeCom;
                        //    }
                        //    neighbor.IsSendPlc = true;
                        //}
                        if (currentModel.Make != locationModel.Make)
                        {
                            //if (current.X != neighbor.X)
                            //{
                            //    current.IsSendPlc = true;
                            //}
                            if (current.Y > neighbor.Y)
                            {
                                current.IsSendPlc = true;
                            }
                            else if (current.Y < neighbor.Y)
                            {
                                neighbor.IsSendPlc = true;
                            }
                            //current.IsSendPlc = true;
                        }
                        // 更新实际距离与预估距离
                        cameFrom[neighbor] = current;
@@ -372,6 +454,28 @@
    }
    /// <summary>
    /// 获取总任务表下发ID主键
    /// </summary>
    /// <returns></returns>
    public static int GetTaskId()
    {
        var list = _db.Queryable<WcsTask>().ToList();
        var maxNo = list.Max(m => m.TaskId);
        if (maxNo != null && maxNo > 0)
        {
            if (maxNo++ > 99999999)
            {
                return 1;
            }
            return (int)maxNo++;
        }
        return 1;
    }
    /// <summary>
    /// 计算曼哈顿距离
    /// </summary>
    /// <param name="start">起始位置</param>