From e69f814f50fd59739dbedd88518dc8cb8d2ed3ee Mon Sep 17 00:00:00 2001
From: z8018 <1282578289@qq.com>
Date: 星期二, 08 四月 2025 21:18:47 +0800
Subject: [PATCH] 1

---
 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs |  981 +++++++++++----------------------------------------------
 1 files changed, 199 insertions(+), 782 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs"
index 5ce308e..058e2e0 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs"
@@ -16,851 +16,268 @@
 #endregion << 鐗� 鏈� 娉� 閲� >>
 
 using AutoMapper;
-using Magicodes.ExporterAndImporter.Core;
-using Microsoft.AspNetCore.Mvc.RazorPages;
-using NetTaste;
-using Newtonsoft.Json;
-using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
-using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
-using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
+using HslCommunication.WebSocket;
 using SqlSugar;
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Linq;
-using System.Linq.Expressions;
-using System.Reflection;
-using System.Reflection.Metadata;
-using System.Security.Policy;
-using System.Text;
-using System.Threading.Tasks;
-using System.Xml.Linq;
-using WIDESEA_Comm.Http;
-using WIDESEA_Common.Log;
-using WIDESEAWCS_Common.TaskEnum;
+using WIDESEAWCS_BasicInfoRepository;
+using WIDESEAWCS_BasicInfoService;
+using WIDESEAWCS_Common;
 using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.BaseServices;
-using WIDESEAWCS_Core.Enums;
-using WIDESEAWCS_Core.Utilities;
-using WIDESEAWCS_DTO.Enum;
+using WIDESEAWCS_Core.Helper;
 using WIDESEAWCS_DTO.TaskInfo;
+using WIDESEAWCS_IBasicInfoRepository;
 using WIDESEAWCS_ITaskInfoRepository;
 using WIDESEAWCS_ITaskInfoService;
 using WIDESEAWCS_Model.Models;
-using WIDESEAWCS_QuartzJob.Models;
-using WIDESEAWCS_QuartzJob.Service;
-using static Microsoft.IO.RecyclableMemoryStreamManager;
+using WIDESEAWCS_QuartzJob.Repository;
 
 namespace WIDESEAWCS_TaskInfoService
 {
     public class TaskService : ServiceBase<Dt_Task, ITaskRepository>, ITaskService
     {
-        private readonly IRouterService _routerService;
-        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
-        private readonly ITaskExecuteDetailRepository _taskExecuteDetailRepository;
-        private readonly ITask_HtyService _task_HtyService;
         private readonly IMapper _mapper;
+        private readonly IContainerRepository _containerRepository;
+        private readonly IContainerItemRepository _containerItemRepository;
+        private readonly WebSocketServer _webSocketServer;
+        private readonly IOrderDetailsRepository _orderDetailsRepository;
 
-
-        private Dictionary<string, OrderByType> _taskOrderBy = new()
-            {
-                {nameof(Dt_Task.Grade),OrderByType.Desc },
-                {nameof(Dt_Task.CreateDate),OrderByType.Asc},
-            };
-
-        public Dictionary<string, OrderByType> TaskOrderBy { get { return _taskOrderBy; } set { _taskOrderBy = value; } }
-
-        public List<int> TaskInboundTypes => typeof(TaskInboundTypeEnum).GetEnumIndexList();
-
-        public List<int> TaskOutboundTypes => typeof(TaskOutboundTypeEnum).GetEnumIndexList();
-
-        public TaskService(ITaskRepository BaseDal, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, IMapper mapper, ITask_HtyService task_HtyService) : base(BaseDal)
+        public TaskService(ITaskRepository BaseDal, IMapper mapper, IContainerRepository containerRepository, IContainerItemRepository containerItemRepository, WebSocketServer webSocketServer, IOrderDetailsRepository orderDetailsRepository) : base(BaseDal)
         {
-            _routerService = routerService;
-            _taskExecuteDetailService = taskExecuteDetailService;
-            _taskExecuteDetailRepository = taskExecuteDetailRepository;
-            _task_HtyService = task_HtyService;
             _mapper = mapper;
+            _containerRepository = containerRepository;
+            _containerItemRepository = containerItemRepository;
+            _webSocketServer = webSocketServer;
+            _orderDetailsRepository = orderDetailsRepository;
         }
 
-        /// <summary>
-        /// 鎺ユ敹WMS浠诲姟淇℃伅
-        /// </summary>
-        /// <param name="taskDTOs">WMS浠诲姟瀵硅薄闆嗗悎</param>
-        /// <returns>杩斿洖澶勭悊缁撴灉</returns>
-        public WebResponseContent ReceiveWMSTask(Dt_Task taskDTOs)
+        public Dt_Task? QueryAGantryUnExecuteTask(string gantryDeviceNo)
         {
-            WebResponseContent content = new WebResponseContent();
+            return BaseDal.QueryFirst(x => x.TaskState == (int)TaskStatusEnum.Gantry_New && x.DeviceCode == gantryDeviceNo);
+        }
+
+        public WebResponseContent PlaceBlockTest(int orderRowId)
+        {
             try
             {
-                
-                BaseDal.AddData(taskDTOs);
-                content = WebResponseContent.Instance.OK("鎴愬姛");
-            }
-            catch (Exception ex)
-            {
-                content = WebResponseContent.Instance.Error($"鐢熸垚浠诲姟澶辫触,閿欒淇℃伅:{ex.Message}");
-            }
-            finally
-            {
-                WriteLog.GetLog("鐢熸垚浠诲姟").Write(JsonConvert.SerializeObject(content), "鐢熸垚浠诲姟");
-            }
-            return content;
-        }
-
-        /// <summary>
-        /// 鏌ユ壘璇ョ珯鍙版槸鍚︽湁浠诲姟
-        /// </summary>
-        /// <param name="deviceNo">璁惧缂栧彿</param>
-        /// <param name="currentAddress">褰撳墠鍦板潃</param>
-        /// <returns></returns>
-        public List<string> QueryConveyorLineTaskSourceAddress()
-        {
-            return BaseDal.QueryData().Select(task => task.SourceAddress).ToList();
-        }
-
-        /// <summary>
-        /// 淇敼浠诲姟锛屾坊鍔犵洰鏍囧湴鍧�
-        /// </summary>
-        /// <param name="deviceNo">璁惧缂栧彿</param>
-        /// <param name="currentAddress">褰撳墠鍦板潃</param>
-        /// <returns></returns>
-        public WebResponseContent UpdateTargetAddress(int TaskId,string TargetAddress)
-        {
-            
-            WebResponseContent content = new WebResponseContent();
-            try
-            {
-                Dt_Task dt_Task = BaseDal.QueryFirst(x => x.TaskId == TaskId);
-                dt_Task.TargetAddress = TargetAddress;
-                dt_Task.NextAddress = TargetAddress;
-                BaseDal.UpdateData(dt_Task);
-                content = WebResponseContent.Instance.OK("鎴愬姛");
-            }
-            catch (Exception ex)
-            {
-                content = WebResponseContent.Instance.Error($"浠诲姟鎺ユ敹閿欒,閿欒淇℃伅:{ex.Message}");
-            }
-            finally
-            {
-                WriteLog.GetLog("鎺ユ敹浠诲姟").Write(JsonConvert.SerializeObject(content), "鎺ユ敹浠诲姟");
-            }
-            return content;
-        }
-
-        /// <summary>
-        /// 鏌ユ壘鏄惁鏈変换鍔″彲浠ユ斁鍦ㄨ浣嶇疆
-        /// </summary>
-        /// <param name="deviceNo">璁惧缂栧彿</param>
-        /// <param name="currentAddress">褰撳墠鍦板潃</param>
-        /// <returns></returns>
-        public Dt_Task QueryConveyorLineTaskRoadway(int agvarea)
-        {
-            return BaseDal.QueryFirst(x => x.Roadway == agvarea.ToString() && x.MaterialType == (int)AgvStationEnum.BoardUnload && x.TargetAddress =="");
-
-        }
-
-
-        public bool QueryConveyorLinetaeersuadd(string taeersuadd)
-        {
-            Dt_Task dt_= BaseDal.QueryFirst(x => x.SourceAddress == taeersuadd || x.TargetAddress == taeersuadd);
-            if(dt_==null) return true;
-            else return false;
-
-        }
-        /// <summary>
-        /// 鏍规嵁璁惧缂栧彿銆佸綋鍓嶅湴鍧�鏌ヨ杈撻�佺嚎鏈墽琛岀殑浠诲姟
-        /// </summary>
-        /// <param name="deviceNo">璁惧缂栧彿</param>
-        /// <param name="currentAddress">褰撳墠鍦板潃</param>
-        /// <returns></returns>
-        public Dt_Task QueryConveyorLineTask(string deviceNo, string currentAddress)
-        {
-            return BaseDal.QueryFirst(x => (TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.InNew || TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.SC_OutFinish) && x.CurrentAddress == currentAddress, TaskOrderBy);
-        }
-
-        /// <summary>
-        /// 鏍规嵁浠诲姟鍙枫�佷笅涓�鍦板潃鏌ヨ杈撻�佺嚎鎵ц涓殑浠诲姟
-        /// </summary>
-        /// <param name="taskNum">浠诲姟鍙�</param>
-        /// <param name="nextAddress">涓嬩竴鍦板潃</param>
-        /// <returns></returns>
-        public Dt_Task QueryExecutingConveyorLineTask(int taskNum, string nextAddress)
-        {
-            return BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.NextAddress == nextAddress && (x.TaskState == (int)TaskInStatusEnum.Line_InExecuting || x.TaskState == (int)TaskOutStatusEnum.Line_OutExecuting), TaskOrderBy);
-        }
-
-        /// <summary>
-        /// 鏍规嵁浠诲姟鍙枫�佸綋鍓嶅湴鍧�鏌ヨ杈撻�佺嚎瀹屾垚鐨勪换鍔�
-        /// </summary>
-        /// <param name="taskNum">浠诲姟鍙�</param>
-        /// <param name="currentAddress">褰撳墠鍦板潃</param>
-        /// <returns></returns>
-        public Dt_Task QueryCompletedConveyorLineTask(int taskNum, string currentAddress)
-        {
-            return BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.CurrentAddress == currentAddress && (x.TaskState == (int)TaskInStatusEnum.Line_InFinish || x.TaskState == (int)TaskOutStatusEnum.Line_OutFinish), TaskOrderBy);
-        }
-
-        /// <summary>
-        /// 鏍规嵁璁惧缂栧彿銆佷换鍔$被鍨嬪垎缁�(鍙��)鎸夌収浼樺厛绾т互鍙婂垱寤烘椂闂存帓搴忔煡璇换鍔℃睜鏂板鐨勪换鍔�
-        /// </summary>
-        /// <param name="deviceNo">璁惧缂栧彿</param>
-        /// <param name="taskTypeGroup">浠诲姟绫诲瀷鍒嗙粍(鍙��)</param>
-        /// <returns></returns>
-        public Dt_Task? QuertStackerCraneTask(string deviceNo, TaskTypeGroup? taskTypeGroup = null)
-        {
-            if(taskTypeGroup == null)
-                return BaseDal.QueryFirst(x => x.Roadway == deviceNo && (TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InFinish || TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew), TaskOrderBy);
-            if(taskTypeGroup.Value == TaskTypeGroup.InboundGroup)
-                return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InFinish, TaskOrderBy);
-            if(taskTypeGroup.Value == TaskTypeGroup.OutbondGroup)
-                return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew, TaskOrderBy);
-            return null;
-        }
-
-        /// <summary>
-        /// 鏍规嵁璁惧缂栧彿銆佸綋鍓嶅湴鍧�鎸夌収浼樺厛绾т互鍙婂垱寤烘椂闂存帓搴忔煡璇换鍔℃睜鏂板鐨勪换鍔�
-        /// </summary>
-        /// <param name="deviceNo">璁惧缂栧彿</param>
-        /// <param name="currentAddress">褰撳墠鍦板潃</param>
-        /// <returns>杩斿洖浠诲姟瀹炰綋瀵硅薄锛屽彲鑳戒负null</returns>
-        public Dt_Task QueryStackerCraneTask(string deviceNo, string currentAddress = "")
-        {
-            return BaseDal.QueryFirst(x => x.TaskState == (int)TaskOutStatusEnum.OutNew && (deviceNo == "AGV01" ? x.Roadway == AgvareaEnum.AreaOne.ToString() : x.Roadway != AgvareaEnum.AreaOne.ToString()),TaskOrderBy);
-        }
-
-
-        public Dt_Task IngStackerCraneTask(string deviceNo)
-        {
-            //string deviceNot = deviceNo == "SC01" ? "1" : "2";
-            return BaseDal.QueryFirst(x => x.Roadway == deviceNo && x.TaskState == (int)TaskInStatusEnum.SC_InExecuting);
-        }
-
-        public Dt_Task IngStackerCraneTask2(string deviceNo)
-        {
-            //string deviceNot = deviceNo == "SC01" ? "1" : "2";
-            try
-            {
-                return BaseDal.QueryFirst(x => x.Roadway == deviceNo && x.TaskState == (int)TaskOutStatusEnum.SC_OutExecuting);
-            }
-            catch (Exception ex)
-            {
-
-                throw;
-            }
-        }
-
-        /// <summary>
-        /// 鏍规嵁璁惧缂栧彿銆佸綋鍓嶅湴鍧�鎸夌収浼樺厛绾т互鍙婂垱寤烘椂闂存帓搴忔煡璇换鍔℃睜鍏ュ簱绫诲瀷鐨勬柊澧炵殑浠诲姟
-        /// </summary>
-        /// <param name="deviceNo">璁惧缂栧彿</param>
-        /// <param name="currentAddress">褰撳墠鍦板潃</param>
-        /// <returns>杩斿洖浠诲姟瀹炰綋瀵硅薄锛屽彲鑳戒负null</returns>
-        public Dt_Task QueryStackerCraneInTask(string deviceNo, string currentAddress = "")
-        {
-            if (string.IsNullOrEmpty(currentAddress))
-                return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InFinish, TaskOrderBy);
-            else
-                return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InFinish && x.CurrentAddress == currentAddress, TaskOrderBy);
-        }
-
-        /// <summary>
-        /// 鏍规嵁璁惧缂栧彿銆佸綋鍓嶅湴鍧�鎸夌収浼樺厛绾т互鍙婂垱寤烘椂闂存帓搴忔煡璇换鍔℃睜鍑哄簱绫诲瀷鐨勬柊澧炵殑浠诲姟
-        /// </summary>
-        /// <param name="deviceNo">璁惧缂栧彿</param>
-        /// <param name="currentAddress">褰撳墠鍦板潃</param>
-        /// <returns>杩斿洖浠诲姟瀹炰綋瀵硅薄锛屽彲鑳戒负null</returns>
-        public Dt_Task QueryStackerCraneOutTask(string deviceNo, string currentAddress = "")
-        {
-            if (string.IsNullOrEmpty(currentAddress))
-                return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew, TaskOrderBy);
-            else
-                return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew && x.CurrentAddress == currentAddress, TaskOrderBy);
-        }
-
-        /// <summary>
-        /// 鏍规嵁璁惧缂栧彿銆佸綋鍓嶅湴鍧�鎸夌収浼樺厛绾т互鍙婂垱寤烘椂闂存帓搴忔煡璇换鍔℃睜鍑哄簱绫诲瀷鐨勬柊澧炵殑浠诲姟
-        /// </summary>
-        /// <param name="deviceNo">璁惧缂栧彿</param>
-        /// <param name="currentAddress">褰撳墠鍦板潃</param>
-        /// <returns>杩斿洖浠诲姟瀹炰綋瀵硅薄闆嗗悎锛屽彲鑳戒负null</returns>
-        public List<Dt_Task> QueryStackerCraneOutTasks(string deviceNo, List<string> outStationCodes)
-        {
-            return BaseDal.QueryData(x => x.Roadway == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew && outStationCodes.Contains(x.CurrentAddress), TaskOrderBy);
-        }
-
-        /// <summary>
-        /// 鏍规嵁鍑哄簱璐т綅鏌ヨ鏄惁鏈夊綋鍓嶆祬璐т綅浠诲姟
-        /// </summary>
-        /// <param name="deviceNo">璁惧缂栧彿</param>
-        /// <param name="currentAddress">褰撳墠鍦板潃</param>
-        /// <returns>杩斿洖浠诲姟瀹炰綋瀵硅薄闆嗗悎锛屽彲鑳戒负null</returns>
-        public List<Dt_Task> QueryStationIsOccupiedOutTasks(string deviceNo, string SourceAddress)
-        {
-            return BaseDal.QueryData(x => x.Roadway == deviceNo && SourceAddress.Contains(x.SourceAddress), TaskOrderBy);
-        }
-
-        /// <summary>
-        /// 鏇存柊浠诲姟寮傚父淇℃伅鏄剧ず
-        /// </summary>
-        /// <param name="taskNum">浠诲姟鍙�</param>
-        /// <param name="message">寮傚父淇℃伅</param>
-        public WebResponseContent UpdateTaskExceptionMessage(int taskNum, string message)
-        {
-            WebResponseContent content = new WebResponseContent();
-            try
-            {
-                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
-                if (task == null) return WebResponseContent.Instance.Error($"鏈壘鍒拌浠诲姟淇℃伅,浠诲姟鍙�:銆恵taskNum}銆�");
-                if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
+                List<OrderDetails> orderDetails = _orderDetailsRepository.QueryData(x => x.Orderrowsid == orderRowId);
+                if (orderDetails == null || orderDetails.Count == 0)
                 {
-                    task.TaskState = (int)TaskOutStatusEnum.OutPending;
+                    return WebResponseContent.Instance.Error("鏈壘鍒拌鍗曟槑缁嗕俊鎭�");
                 }
-                else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
+
+                Dt_Container putContainer = _containerRepository.QueryFirst(x => x.ContainerType == ContainerTypeEnum.PutContainer.ObjToInt());
+                if (putContainer == null)
                 {
-                    task.TaskState = (int)TaskInStatusEnum.InPending;
+                    return WebResponseContent.Instance.Error("鏀捐揣浣嶇疆涓嶅瓨鍦�");
                 }
-                task.ExceptionMessage = message;
-                task.ModifyDate = DateTime.Now;
-                BaseDal.UpdateData(task);
 
-                _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, task.ExceptionMessage);
+                ContainerSize containerSize = new ContainerSize(1500, putContainer.ContainerWidth, putContainer.ContainerHeight);
+                List<PlacedBlock> placedBlocks = new List<PlacedBlock>();
 
-                content = WebResponseContent.Instance.OK();
-            }
-            catch (Exception ex)
-            {
-                content = WebResponseContent.Instance.Error(ex.Message);
-            }
-            return content;
-        }
-
-        /// <summary>
-        /// 鏇存柊浠诲姟鐘舵�佷俊鎭紝骞跺悓姝ヨ嚦WMS
-        /// </summary>
-        /// <param name="taskNum">浠诲姟鍙�</param>
-        /// <param name="status">浠诲姟鐘舵��</param>
-        public void UpdateTaskStatus(int taskNum, int status)
-        {
-            Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
-            if (task == null) return;
-            task.TaskState = status;
-            task.ModifyDate = DateTime.Now;
-            BaseDal.UpdateData(task);
-        }
-
-        /// <summary>
-        /// 灏嗕换鍔$姸鎬佷慨鏀逛负涓嬩竴涓姸鎬�
-        /// </summary>
-        /// <param name="taskNum">浠诲姟鍙�</param>
-        public WebResponseContent UpdateTaskStatusToNext(int taskNum)
-        {
-            WebResponseContent content = new WebResponseContent();
-            try
-            {
-                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
-                if (task == null) return WebResponseContent.Instance.Error($"鏈壘鍒拌浠诲姟淇℃伅,浠诲姟鍙�:銆恵taskNum}銆�");
-                return UpdateTaskStatusToNext(task);
-            }
-            catch (Exception ex)
-            {
-                content = WebResponseContent.Instance.Error(ex.Message);
-            }
-            return content;
-        }
-
-        /// <summary>
-        /// 灏嗕换鍔$姸鎬佷慨鏀逛负涓嬩竴涓姸鎬�
-        /// </summary>
-        /// <param name="task">浠诲姟瀹炰綋瀵硅薄</param>
-        /// <returns></returns>
-        public WebResponseContent UpdateTaskStatusToNext([NotNull] Dt_Task task)
-        {
-            WebResponseContent content = new WebResponseContent();
-            try
-            {
-                int oldState = task.TaskState;
-                if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound)
+                for (int i = 0; i < orderDetails.Count; i++)
                 {
-                    if (task.TaskState >= (int)TaskOutStatusEnum.OutFinish)
+                    try
                     {
-                        return content = WebResponseContent.Instance.Error($"璇ヤ换鍔$姸鎬佷笉鍙烦杞埌涓嬩竴姝�,浠诲姟鍙�:銆恵task.TaskNum}銆�,浠诲姟鐘舵��:銆恵task.TaskState}銆�");
-                    }
-
-                    int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskOutStatusEnum>();
-
-                    task.TaskState = nextStatus;
-                    if (task.TaskState == (int)TaskOutStatusEnum.SC_OutExecuting)
-                    {
-                        task.Dispatchertime = DateTime.Now;
-                    }
-                }
-                else if (task.TaskType == (int)TaskInboundTypeEnum.Inbound)
-                {
-                    if (task.TaskState >= (int)TaskInStatusEnum.InFinish)
-                    {
-                        return content = WebResponseContent.Instance.Error($"璇ヤ换鍔$姸鎬佷笉鍙烦杞埌涓嬩竴姝�,浠诲姟鍙�:銆恵task.TaskNum}銆�,浠诲姟鐘舵��:銆恵task.TaskState}銆�");
-                    }
-
-                    int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskInStatusEnum>();
-                    task.TaskState = nextStatus;
-                    if (task.TaskState == (int)TaskInStatusEnum.SC_InExecuting)
-                    {
-                        task.Dispatchertime = DateTime.Now;
-                    }
-                    if (task.TaskState == (int)TaskRelocationTypeEnum.Relocation)
-                    {
-                        Random random = new Random();
-                        task.CurrentAddress = task.NextAddress;
-                        task.NextAddress = $"{random.Next(1, 100).ToString().PadLeft(3, '0')}-{random.Next(1, 100).ToString().PadLeft(3, '0')}-{random.Next(1, 100).ToString().PadLeft(3, '0')}";
-                        task.TargetAddress = task.NextAddress;
-                    }
-                }
-                else if (task.TaskType == (int)TaskInboundTypeEnum.Inbound)
-                {
-                    if (task.TaskState <= (int)TaskRelocationStatusEnum.SC_RelocationFinish)
-                    {
-                        
-                        return content = WebResponseContent.Instance.Error($"璇ヤ换鍔$姸鎬佷笉鍙烦杞埌涓嬩竴姝�,浠诲姟鍙�:銆恵task.TaskNum}銆�,浠诲姟鐘舵��:銆恵task.TaskState}銆�");
-                    }
-
-                    int nextStatus = (int)TaskRelocationStatusEnum.SC_RelocationExecuting;
-                    task.TaskState = nextStatus;
-                    if (task.TaskState == (int)TaskRelocationStatusEnum.SC_RelocationExecuting)
-                    {
-                        task.Dispatchertime = DateTime.Now;
-                    }
-                }
-                else
-                {
-                    throw new Exception($"浠诲姟绫诲瀷閿欒,鏈壘鍒拌浠诲姟绫诲瀷,浠诲姟鍙�:銆恵task.TaskNum}銆�,浠诲姟绫诲瀷:銆恵task.TaskType}銆�");
-                }
-
-                if (task.TaskState <= 0)
-                {
-                    return content = WebResponseContent.Instance.Error($"璇ヤ换鍔$姸鎬佷笉鍙烦杞埌涓嬩竴姝�,浠诲姟鍙�:銆恵task.TaskNum}銆�,浠诲姟鐘舵��:銆恵task.TaskState}銆�");
-                }
-
-                
-                task.ModifyDate = DateTime.Now;
-                task.Modifier = "System";
-                BaseDal.UpdateData(task);
-
-                _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, App.User.UserId > 0 ? $"浜哄伐鎵嬪姩灏嗕换鍔$姸鎬佷粠銆恵oldState}銆戣烦杞埌銆恵task.TaskState}銆�" : $"绯荤粺鑷姩娴佺▼锛屼换鍔$姸鎬佷粠銆恵oldState}銆戣浆鍒般�恵task.TaskState}銆�");
-
-                content = WebResponseContent.Instance.OK();
-            }
-            catch (Exception ex)
-            {
-                content = WebResponseContent.Instance.Error(ex.Message);
-            }
-            return content;
-        }
-
-        /// <summary>
-        /// 鏍规嵁浠诲姟鍙枫�佸綋鍓嶅湴鍧�鏇存柊浠诲姟浣嶇疆淇℃伅
-        /// </summary>
-        /// <param name="taskNum">浠诲姟鍙�</param>
-        /// <param name="currentAddress">褰撳墠鍦板潃</param>
-        /// <returns></returns>
-        public Dt_Task? UpdatePosition(int taskNum, string currentAddress)
-        {
-            try
-            {
-                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.CurrentAddress == currentAddress);
-                if (task == null) throw new Exception($"鏈壘鍒拌浠诲姟淇℃伅,浠诲姟鍙�:銆恵taskNum}銆�");
-
-                string oldCurrentPos = task.CurrentAddress;
-                string oldNextPos = task.NextAddress;
-
-                List<Dt_Router> routers = _routerService.QueryNextRoutes(task.NextAddress, task.TargetAddress);
-                if (!routers.Any()) throw new Exception($"鏈壘鍒拌澶囪矾鐢变俊鎭�");
-
-                task.CurrentAddress = task.NextAddress;
-                task.NextAddress = routers.FirstOrDefault().ChildPosi;
-
-                task.ModifyDate = DateTime.Now;
-                task.Modifier = "System";
-                BaseDal.UpdateData(task);
-
-                _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"绯荤粺鑷姩娴佺▼锛屾洿鏂板綋鍓嶄綅缃�恵oldCurrentPos} ----> {task.CurrentAddress}銆戝拰涓嬩竴浣嶇疆銆恵oldNextPos} ----> {task.NextAddress}銆�");
-                return task;
-            }
-            catch (Exception ex)
-            {
-            }
-            return null;
-        }
-
-        
-        public WebResponseContent StackCraneTaskCompleted(int taskNum)
-        {
-            WebResponseContent content = new WebResponseContent();
-            try
-            {
-                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
-                if (task == null) return WebResponseContent.Instance.Error($"鏈壘鍒拌浠诲姟淇℃伅,浠诲姟鍙�:銆恵taskNum}銆�");
-
-                if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.TaskState == (int)TaskOutStatusEnum.SC_OutExecuting)
-                {
-                    /*List<Dt_Router> routers = _routerService.QueryNextRoutes(task.NextAddress, task.TargetAddress);
-                    if (!routers.Any()) return WebResponseContent.Instance.Error($"鏈壘鍒拌澶囪矾鐢变俊鎭�");*/
-
-                    task.TaskState = (int)TaskOutStatusEnum.OutFinish;
-                    task.ModifyDate = DateTime.Now;
-                    BaseDal.DeleteData(task);
-                    _task_HtyService.AddTaskHty(task);
-                    _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"鍑哄簱瀹屾垚");
-                    //todo 鍚屾鍒癢MS
-
-                    //鏆備笉鑰冭檻澶氫釜鍑哄簱鍙�
-                }
-                else if (task.TaskType == (int)TaskInboundTypeEnum.Inbound && task.TaskState == (int)TaskInStatusEnum.SC_InExecuting)
-                {
-                    //todo 
-                    //int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskInStatusEnum>();
-                    task.TaskState = (int)TaskInStatusEnum.InFinish;
-                    task.ModifyDate = DateTime.Now;
-                    task.Modifier = "System";
-                    BaseDal.DeleteData(task);
-                    _task_HtyService.AddTaskHty(task);
-                    _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"鍏ュ簱瀹屾垚");
-
-                }
-                else
-                {
-                    throw new Exception($"浠诲姟绫诲瀷閿欒,鏈壘鍒拌浠诲姟绫诲瀷,浠诲姟鍙�:銆恵taskNum}銆�,浠诲姟绫诲瀷:銆恵task.TaskType}銆�");
-                }
-                content = WebResponseContent.Instance.OK();
-            }
-            catch (Exception ex)
-            {
-                content = WebResponseContent.Instance.Error($"浠诲姟瀹屾垚寮傚父,浠诲姟鍙�:銆恵taskNum}銆�");
-            }
-            return content;
-        }
-
-        /// <summary>
-        /// 鎭㈠鎸傝捣浠诲姟
-        /// </summary>
-        /// <param name="taskNum">浠诲姟鍙�</param>
-        /// <returns>杩斿洖澶勭悊缁撴灉</returns>
-        public WebResponseContent TaskStatusRecovery(int taskNum)
-        {
-            WebResponseContent content = new WebResponseContent();
-            try
-            {
-                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
-                if (task == null) return WebResponseContent.Instance.Error($"鏈壘鍒拌浠诲姟淇℃伅,浠诲姟鍙�:銆恵taskNum}銆�");
-                if (task.TaskState != (int)TaskInStatusEnum.InPending && task.TaskState != (int)TaskOutStatusEnum.OutPending)
-                {
-                    return content = WebResponseContent.Instance.Error($"璇ヤ换鍔$姸鎬佷笉鍙仮澶�,浠诲姟鍙�:銆恵taskNum}銆�,浠诲姟鐘舵��:銆恵task.TaskState}銆�");
-                }
-
-                Dt_TaskExecuteDetail taskExecuteDetail = _taskExecuteDetailRepository.QueryFirst(x => x.TaskId == task.TaskId && x.IsNormal, new Dictionary<string, OrderByType> { { nameof(Dt_TaskExecuteDetail.TaskDetailId), OrderByType.Desc } });
-                if (taskExecuteDetail != null)
-                {
-                    task.TaskState = taskExecuteDetail.TaskState;
-                }
-                else
-                {
-                    if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
-                    {
-                        task.TaskState = (int)TaskOutStatusEnum.OutNew;
-                    }
-                    else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
-                    {
-                        task.TaskState = (int)TaskInStatusEnum.InNew;
-                    }
-                    //todo
-                }
-
-                task.ExceptionMessage = string.Empty;
-
-                BaseDal.UpdateData(task);
-
-                _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"浜哄伐鎭㈠鎸傝捣浠诲姟,鎭㈠鎸傝捣鏃朵换鍔$姸鎬併�恵task.TaskState}銆�");
-
-                content = WebResponseContent.Instance.OK();
-            }
-            catch (Exception ex)
-            {
-                content = WebResponseContent.Instance.Error(ex.Message);
-            }
-            return content;
-        }
-
-        /// <summary>
-        /// 鍥炴粴浠诲姟鐘舵��
-        /// </summary>
-        /// <param name="taskNum">浠诲姟鍙�</param>
-        /// <returns>杩斿洖澶勭悊缁撴灉</returns>
-        public WebResponseContent RollbackTaskStatusToLast(int taskNum)
-        {
-            WebResponseContent content = new();
-            try
-            {
-                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
-                if (task == null) return WebResponseContent.Instance.Error($"鏈壘鍒拌浠诲姟淇℃伅,浠诲姟鍙�:銆恵taskNum}銆�");
-
-                int oldState = task.TaskState;
-                Dt_TaskExecuteDetail taskExecuteDetail = _taskExecuteDetailRepository.QueryFirst(x => x.TaskId == task.TaskId && x.TaskState < task.TaskState && x.TaskState > 0, new Dictionary<string, OrderByType> { { nameof(Dt_TaskExecuteDetail.TaskDetailId), OrderByType.Desc } });
-                if (taskExecuteDetail != null)
-                {
-                    task.TaskState = taskExecuteDetail.TaskState;
-                    task.CurrentAddress = taskExecuteDetail.CurrentAddress;
-                    task.NextAddress = taskExecuteDetail.NextAddress;
-                }
-                else
-                {
-                    return content = WebResponseContent.Instance.Error($"鏈壘鍒颁换鍔℃槑缁嗕俊鎭�,璇ヤ换鍔$姸鎬佷笉鍙洖婊氬埌涓婁竴姝�,浠诲姟鍙�:銆恵taskNum}銆�,浠诲姟鐘舵��:銆恵task.TaskState}銆�");
-                }
-
-                task.ExceptionMessage = string.Empty;
-
-                BaseDal.UpdateData(task);
-
-                _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"浜哄伐灏嗕换鍔$姸鎬佷粠銆恵oldState}銆戝洖婊氬埌銆恵task.TaskState}銆�");
-
-                content = WebResponseContent.Instance.OK();
-            }
-            catch (Exception ex)
-            {
-                content = WebResponseContent.Instance.Error(ex.Message);
-            }
-            return content;
-        }
-
-
-        /// <summary>
-        /// 鍒犻櫎鏁版嵁
-        /// </summary>
-        /// <param name="keys">涓婚敭鏁扮粍</param>
-        /// <returns></returns>
-        public virtual WebResponseContent DeleteData(object[] keys)
-        {
-            try
-            {
-                List<Dt_Task> tasks = BaseDal.QureyDataByIds(keys);
-                foreach (Dt_Task task in tasks)
-                {
-                    _task_HtyService.AddTaskHty(task);
-                }
-
-
-                if (typeof(Dt_Task).GetNavigatePro() == null)
-                    return BaseDal.DeleteDataByIds(keys) ? WebResponseContent.Instance.OK() : WebResponseContent.Instance.Error();
-                else
-                {
-                    if (keys != null)
-                    {
-                        Type detailType = typeof(Dt_Task).GetDetailType();
-                        string name = typeof(Dt_Task).GetMainIdByDetail();
-                        List<object> dynamicDelKeys = new List<object>();
-
-                        for (int i = 0; i < keys.Length; i++)
+                        lock (placedBlocks)
                         {
-                            dynamicDelKeys.Add(keys[i]);
+                            int length = Convert.ToInt32(orderDetails[i].Orderdetails_length);
+                            int width = Convert.ToInt32(orderDetails[i].Orderdetails_width);
+                            int height = Convert.ToInt32(orderDetails[i].Orderdetails_thickness);
+
+                            TaskPosition taskPosition = new TaskPosition();
+                            taskPosition = GetTakePutPosition(length, width, height, containerSize, placedBlocks);
+
+                            PlacedBlock placedBlock = new PlacedBlock(new Point3D(taskPosition.PositionX, taskPosition.PositionY, taskPosition.PositionZ), length, width, height);
+                            placedBlocks.Add(placedBlock);
+
+                            object obj = new
+                            {
+                                x = taskPosition.PutCenterPositionX - containerSize.Length / 2,
+                                y = taskPosition.PutCenterPositionY - containerSize.Width / 2,
+                                z = taskPosition.PutCenterPositionZ,
+                                length,
+                                width,
+                                height,
+                            };
+
+                            _webSocketServer.PublishAllClientPayload(obj.Serialize());
+
+                            Thread.Sleep(100);
                         }
-                        ((SqlSugarClient)BaseDal.Db).BeginTran();
-
-                        if (dynamicDelKeys.Count > 0)
-                            BaseDal.Db.Deleteable<object>().AS(detailType.Name).Where($"{name} in (@id)", new { id = dynamicDelKeys.ToArray() }).ExecuteCommandHasChange();
-
-                        BaseDal.DeleteDataByIds(keys);
-
-                        ((SqlSugarClient)BaseDal.Db).CommitTran();
-
-                        return WebResponseContent.Instance.OK();
                     }
-                    else
+                    catch (Exception ex)
                     {
-                        return WebResponseContent.Instance.Error("鍙傛暟閿欒");
+
                     }
                 }
+                return WebResponseContent.Instance.OK(data: placedBlocks);
             }
             catch (Exception ex)
             {
-                ((SqlSugarClient)BaseDal.Db).RollbackTran();
                 return WebResponseContent.Instance.Error(ex.Message);
             }
         }
 
-        //agv浠诲姟
-        public WebResponseContent GetAgvTaskData()
+        public TaskPosition GetTakePutPosition(int length, int width, int height, ContainerSize containerSize, List<PlacedBlock> placedBlocks)
         {
-            WebResponseContent content=new WebResponseContent();
-            List<Dt_Task> tasks = BaseDal.QueryData().ToList();
-            List<AGCTaskDto> agvdto = new List<AGCTaskDto>();
-            foreach (var item in tasks)
-            {
-                AGCTaskDto aGCTaskDto = new AGCTaskDto();
-                aGCTaskDto.TaskNum = item.TaskNum;
-                aGCTaskDto.SourceAddress= item.SourceAddress;
-                aGCTaskDto.TargetAddress= item.TargetAddress==null? "鏆傚畾" : item.TargetAddress;
-                aGCTaskDto.Dispatchertime = item.Dispatchertime;
-                aGCTaskDto.TaskState = item.TaskState == (int)TaskInStatusEnum.InNew ? "鏂板缓浠诲姟" : (item.TaskState == (int)TaskInStatusEnum.AGV_InExecuting ? "AGV浠诲姟鎵ц" : "浠诲姟瀹屾垚");
-                aGCTaskDto.TaskType = item.TaskType.ToString();
-                aGCTaskDto.Roadway = item.Roadway=="1"?"鍖哄煙涓�":(item.Roadway == "2" ? "鍖哄煙浜�": item.Roadway == "3" ? "鍖哄煙涓�":"鍖哄煙鍥�");
-                agvdto.Add(aGCTaskDto);
-            }
-            return content.OK(data: agvdto);
-        }
-
-        //agv鐘舵��
-        public WebResponseContent GetAgvStatusData()
-        {
-            var response = new WebResponseContent();
             try
             {
-                //agv绫诲瀷锛�0-娼滀紡鍨嬶紝1 - 鐗靛紩鍨嬶紝2 - 鎵胯浇鍨嬶紝3 - 涓惧崌鍨嬶紝4 -杈婇亾鍨嬶紝5 - 鍙夎溅鍨嬶紝6 - 鍏朵粬
-                int agvType = 0;
-                //agv缂栧彿
-                int agvCode = 2;
-                //agv涓婁笅绾跨姸鎬侊紝0-涓嬬嚎锛�1 - 涓婄嚎
-                int agvOnline = 4;
-                //agv褰撳墠鍦版爣鍙�
-                int agvRfidLabel = 6;
-                //agv褰撳墠x鍧愭爣鍊�
-                int agvXcoordinate = 8;
-                //agv褰撳墠y鍧愭爣鍊�
-                int agvYcoordinate = 12;
-                //agv杩愯鐘舵�� 锛�0-鍋滄锛�1 - 琛岄┒锛�2 - 鏆傚仠
-                int agvStatus = 16;
-                //agv褰撳墠杩愯閫熷害(mm / s)
-                int agvSpeed = 18;
-                //agv鎶ヨ浠g爜(鎸変綅鐘舵�佹彁鍙栵紝鏈�澶氬彲琛ㄧず32绉嶆姤璀�
-                int agvAlarmCode = 20;
-                bool isFirst = true;
-                List<AGVStatus> statusList = new List<AGVStatus>();
-                
-                for (int i = 0; i < 3; i++)
-                {
-                    AGVStatus aGVStatus = new AGVStatus();
-                    aGVStatus.agvCode = i;
-                    aGVStatus.agvType = 1+i;
-                    aGVStatus.agvOnline = "123" + i;
-                    aGVStatus.agvRfidLabel = 2 + i;
-                    aGVStatus.agvXcoordinate = 3 + i;
-                    aGVStatus.agvYcoordinate = 4 + i;
-                    aGVStatus.agvStatus = 5 + i;
-                    aGVStatus.agvSpeed = 6 + i;
-                    aGVStatus.agvAlarmCode = i+99; //client.SiemensPLCClient.SiemensS7NetClient.Read("DB1001." + agvAlarmCode.ToString(), 32).Content;
-                    statusList.Add(aGVStatus);
+                PlaceBlockService placeBlockService = new PlaceBlockService(containerSize, placedBlocks);
 
+                Point3D? point3D = placeBlockService.PlaceBlock(length, width, height);
+                if (point3D == null)
+                {
+                    throw new Exception("鏀捐揣浣嶇疆宸叉弧");
                 }
-                
-                response.OK(data: statusList);
+
+                //鏀捐揣浣嶇疆鏉挎潗涓績鐐�
+                Point3D putCenter = new Point3D(point3D.Value.X + length / 2, point3D.Value.Y + width / 2, point3D.Value.Z + height / 2);
+
+                //鍙栬揣浣嶇疆鏉挎潗涓績鐐�
+                Point3D takeCenter = new Point3D(length / 2, width / 2, height / 2);
+
+                //鍚哥洏闀�530 闂撮殧660  鏈�澶�920 鍚哥洏瀹�130
+
+                int positionR = 1;
+
+                int takePositionX = 0;
+                int takePositionY = 0;
+                int takePositionZ = 0;
+                int putPositionX = 0;
+                int putPositionY = 0;
+                int putPositionZ = 0;
+
+                //1.濡傛灉闀垮害澶т簬920锛屽搴﹀ぇ浜庣瓑浜�300锛屽垯鍙互浣跨敤鍙屽惛鐩樻í鍚戝惛鍙�
+                if (length > 920 && width >= 300)
+                {
+                    //
+                    Point3D deviceCenter = new Point3D(530 / 2, 920 / 2, 0);
+
+                    positionR = 1;
+                    takePositionX = takeCenter.Y - deviceCenter.X;
+                    takePositionY = takeCenter.X - deviceCenter.Y;
+                    takePositionZ = 10;
+
+                    putPositionX = putCenter.Y - deviceCenter.X;
+                    putPositionY = putCenter.X - deviceCenter.Y;
+                    putPositionZ = point3D.Value.Z; // putCenter.Z /*+ 10*/;
+                }
+                else
+                {
+                    positionR = 0;
+                    Point3D deviceCenter = new Point3D(130 / 2, 530 / 2, 0);
+                    takePositionX = takeCenter.Y - deviceCenter.X;
+                    takePositionY = takeCenter.X - deviceCenter.Y;
+                    takePositionZ = 10;
+
+                    putPositionX = putCenter.Y - deviceCenter.X;
+                    putPositionY = putCenter.X - deviceCenter.Y;
+                    putPositionZ = point3D.Value.Z; //putCenter.Z /*+ 10*/;
+                }
+
+                TaskPosition taskPosition = new TaskPosition()
+                {
+                    PositionR = positionR,
+                    TakePositionX = takePositionX,
+                    TakePositionY = takePositionY,
+                    TakePositionZ = takePositionZ,
+                    PutPositionX = putPositionX,
+                    PutPositionY = putPositionY,
+                    PutPositionZ = putPositionZ,
+                    TakeCenterPositionX = takeCenter.X,
+                    TakeCenterPositionY = takeCenter.Y,
+                    TakeCenterPositionZ = takeCenter.Z,
+                    PutCenterPositionX = putCenter.X,
+                    PutCenterPositionY = putCenter.Y,
+                    PutCenterPositionZ = putCenter.Z,
+                    PositionX = point3D.Value.X,
+                    PositionY = point3D.Value.Y,
+                    PositionZ = point3D.Value.Z
+                };
+
+                return taskPosition;
             }
             catch (Exception ex)
             {
-                response.Error(ex.Message);
+                throw new Exception(ex.Message);
             }
-
-            return response;
         }
 
-        public WebResponseContent GetAgvStatusData2()
+        public WebResponseContent CreateTask(string takePosition, string putPosition, string deviceCode, int length, int width, int height)
         {
-            var response = new WebResponseContent();
             try
             {
-                //agv绫诲瀷锛�0-娼滀紡鍨嬶紝1 - 鐗靛紩鍨嬶紝2 - 鎵胯浇鍨嬶紝3 - 涓惧崌鍨嬶紝4 -杈婇亾鍨嬶紝5 - 鍙夎溅鍨嬶紝6 - 鍏朵粬
-                int agvType = 0;
-                //agv缂栧彿
-                int agvCode = 2;
-                //agv涓婁笅绾跨姸鎬侊紝0-涓嬬嚎锛�1 - 涓婄嚎
-                int agvOnline = 4;
-                //agv褰撳墠鍦版爣鍙�
-                int agvRfidLabel = 6;
-                //agv褰撳墠x鍧愭爣鍊�
-                int agvXcoordinate = 8;
-                //agv褰撳墠y鍧愭爣鍊�
-                int agvYcoordinate = 12;
-                //agv杩愯鐘舵�� 锛�0-鍋滄锛�1 - 琛岄┒锛�2 - 鏆傚仠
-                int agvStatus = 16;
-                //agv褰撳墠杩愯閫熷害(mm / s)
-                int agvSpeed = 18;
-                //agv鎶ヨ浠g爜(鎸変綅鐘舵�佹彁鍙栵紝鏈�澶氬彲琛ㄧず32绉嶆姤璀�
-                int agvAlarmCode = 20;
-                bool isFirst = true;
-                List<AGVStatus> statusList = new List<AGVStatus>();
-
-                for (int i = 0; i < 6; i++)
+                Dt_Container takeContainer = _containerRepository.QueryFirst(x => x.ContainerCode == takePosition && x.ContainerType == ContainerTypeEnum.TakeContainer.ObjToInt());
+                if (takeContainer == null)
                 {
-                    AGVStatus aGVStatus = new AGVStatus();
-                    aGVStatus.agvCode = i;
-                    aGVStatus.agvType = 1 + i;
-                    aGVStatus.agvOnline = "123" + i;
-                    aGVStatus.agvRfidLabel = 2 + i;
-                    aGVStatus.agvXcoordinate = 3 + i;
-                    aGVStatus.agvYcoordinate = 4 + i;
-                    aGVStatus.agvStatus = 5 + i;
-                    aGVStatus.agvSpeed = 6 + i;
-                    aGVStatus.agvAlarmCode = i + 99; //client.SiemensPLCClient.SiemensS7NetClient.Read("DB1001." + agvAlarmCode.ToString(), 32).Content;
-                    statusList.Add(aGVStatus);
-
+                    return WebResponseContent.Instance.Error("鍙栬揣浣嶇疆涓嶅瓨鍦�");
                 }
 
-                response.OK(data: statusList);
+                Dt_Container putContainer = _containerRepository.QueryFirst(x => x.ContainerCode == putPosition && x.ContainerType == ContainerTypeEnum.PutContainer.ObjToInt());
+                if (putContainer == null)
+                {
+                    return WebResponseContent.Instance.Error("鏀捐揣浣嶇疆涓嶅瓨鍦�");
+                }
+
+                ContainerSize containerSize = new ContainerSize(putContainer.ContainerLength, putContainer.ContainerWidth, putContainer.ContainerHeight);
+                List<Dt_ContainerItem> containerItems = _containerItemRepository.QueryData(x => x.ContainerId == putContainer.Id);
+
+                List<PlacedBlock> placedBlocks = containerItems.Select(x => new PlacedBlock(new Point3D(x.ItemPositionX, x.ItemPositionY, x.ItemPositionZ), x.ItemLength, x.ItemWidth, x.ItemHeight)).ToList();
+
+
+                TaskPosition taskPosition = GetTakePutPosition(length, width, height, containerSize, placedBlocks);
+
+                object obj = new
+                {
+                    x = taskPosition.PutCenterPositionX - putContainer.ContainerLength / 2,
+                    y = taskPosition.PutCenterPositionY - putContainer.ContainerWidth / 2,
+                    z = taskPosition.PutCenterPositionZ,
+                    length,
+                    width,
+                    height,
+                };
+
+                _webSocketServer.PublishAllClientPayload(obj.Serialize());
+
+                string code = DateTime.Now.ToString("yyyyMMddHHmmss");
+
+                Dt_ContainerItem dt_ContainerItem = new Dt_ContainerItem()
+                {
+                    ContainerId = putContainer.Id,
+                    ItemCode = code,
+                    ItemLength = length,
+                    ItemWidth = width,
+                    ItemHeight = height,
+                    ItemPositionX = taskPosition.PutPositionX,
+                    ItemPositionY = taskPosition.PutPositionY,
+                    ItemPositionZ = taskPosition.PutPositionZ,
+                    ItemStatus = (int)ItemStatusEnum.Assigned,
+                    ItemName = code
+                };
+
+                Dt_Task dt_Task = new Dt_Task()
+                {
+                    TaskNum = 1,
+                    PalletCode = code,
+                    DeviceCode = deviceCode,
+                    TaskState = (int)TaskStatusEnum.Gantry_New,
+                    TaskType = 0,
+                    SourceAddress = $"{takePosition}*{taskPosition.TakePositionX}*{taskPosition.TakePositionY}*{taskPosition.TakePositionZ}*{taskPosition.PositionR}",
+                    TargetAddress = $"{putPosition}*{taskPosition.PutPositionX}*{taskPosition.PutPositionX}*{taskPosition.PutPositionZ}*{taskPosition.PositionR}",
+                    CurrentAddress = $"{takePosition}*{taskPosition.TakePositionX}*{taskPosition.TakePositionY}*{taskPosition.TakePositionZ}*{taskPosition.PositionR}",
+                    NextAddress = $"{putPosition}*{taskPosition.PutPositionX}*{taskPosition.PutPositionX}*{taskPosition.PutPositionZ}*{taskPosition.PositionR}",
+                    Grade = 0,
+                };
+
+                _containerItemRepository.AddData(dt_ContainerItem);
+                base.AddData(dt_Task);
+
+                return WebResponseContent.Instance.OK();
             }
             catch (Exception ex)
             {
-                response.Error(ex.Message);
+                return WebResponseContent.Instance.Error(ex.Message);
             }
-
-            return response;
-        }
-
-
-        public class AGVStatus
-        {
-            /// <summary>
-            /// agv绫诲瀷锛�0-娼滀紡鍨嬶紝1 - 鐗靛紩鍨嬶紝2 - 鎵胯浇鍨嬶紝3 - 涓惧崌鍨嬶紝4 -杈婇亾鍨嬶紝5 - 鍙夎溅鍨嬶紝6 - 鍏朵粬
-            /// </summary>
-            public int agvType { get; set; }
-
-            /// <summary>
-            /// agv缂栧彿
-            /// </summary>
-            public int agvCode { get; set; }
-
-            /// <summary>
-            /// agv涓婁笅绾跨姸鎬侊紝0-涓嬬嚎锛�1 - 涓婄嚎
-            /// </summary>
-            public string agvOnline { get; set; }
-
-            /// <summary>
-            /// agv褰撳墠鍦版爣鍙�
-            /// </summary>
-            public int agvRfidLabel { get; set; }
-
-            /// <summary>
-            /// agv褰撳墠x鍧愭爣鍊�
-            /// </summary>
-            public int agvXcoordinate { get; set; }
-
-            /// <summary>
-            /// agv褰撳墠y鍧愭爣鍊�
-            /// </summary>
-            public int agvYcoordinate { get; set; }
-
-            /// <summary>
-            /// agv杩愯鐘舵�� 锛�0-鍋滄锛�1 - 琛岄┒锛�2 - 鏆傚仠
-            /// </summary>
-            public int agvStatus { get; set; }
-
-            /// <summary>
-            /// agv褰撳墠杩愯閫熷害(mm / s)
-            /// </summary>
-            public int agvSpeed { get; set; }
-
-            /// <summary>
-            /// agv鎶ヨ浠g爜(鎸変綅鐘舵�佹彁鍙栵紝鏈�澶氬彲琛ㄧず32绉嶆姤璀�
-            /// </summary>
-            public int agvAlarmCode { get; set; }
         }
     }
 }

--
Gitblit v1.9.3