From f49fa4b5027cfdc27b429985d023e8002abcca2e Mon Sep 17 00:00:00 2001
From: huanghongfeng <huanghongfeng@hnkhzn.com>
Date: 星期三, 05 十一月 2025 23:54:12 +0800
Subject: [PATCH] 1

---
 代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs |  401 +++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 331 insertions(+), 70 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs"
index 0fc8907..5c96cff 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs"
@@ -20,6 +20,7 @@
 using NetTaste;
 using Newtonsoft.Json;
 using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
 using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
 using SqlSugar;
 using System;
@@ -40,14 +41,16 @@
 using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.BaseServices;
 using WIDESEAWCS_Core.Enums;
+using WIDESEAWCS_Core.Utilities;
 using WIDESEAWCS_DTO.Enum;
 using WIDESEAWCS_DTO.TaskInfo;
 using WIDESEAWCS_ITaskInfoRepository;
 using WIDESEAWCS_ITaskInfoService;
 using WIDESEAWCS_Model.Models;
-using WIDESEAWCS_QuartzJob;
 using WIDESEAWCS_QuartzJob.Models;
 using WIDESEAWCS_QuartzJob.Service;
+using WIDESEAWCS_TaskInfoRepository;
+using static Microsoft.IO.RecyclableMemoryStreamManager;
 
 namespace WIDESEAWCS_TaskInfoService
 {
@@ -57,6 +60,7 @@
         private readonly ITaskExecuteDetailService _taskExecuteDetailService;
         private readonly ITaskExecuteDetailRepository _taskExecuteDetailRepository;
         private readonly ITask_HtyService _task_HtyService;
+        private readonly ITask_HtyRepository _task_HtyRepository;
         private readonly IMapper _mapper;
 
         private Dictionary<string, OrderByType> _taskOrderBy = new()
@@ -71,21 +75,23 @@
 
         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, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, IMapper mapper, ITask_HtyService task_HtyService, ITask_HtyRepository task_HtyRepository) : base(BaseDal)
         {
             _routerService = routerService;
             _taskExecuteDetailService = taskExecuteDetailService;
             _taskExecuteDetailRepository = taskExecuteDetailRepository;
             _task_HtyService = task_HtyService;
+            _task_HtyRepository = task_HtyRepository;
             _mapper = mapper;
         }
 
         public string urlWMSTask = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlWMSTask"];
         public string urlTaskCompleted = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlTaskCompleted"];
         public string urlWMSMovelibraryTask = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlWMSMovelibraryTask"];
-        public string urlRelocationTaskCompleted = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlRelocationTaskCompleted"];
         public string urlQueryinventory = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlQueryinventory"];
         public string urlEmptyOutbound = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlEmptyOutbound"];
+        public string urlRawmaterialout = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlRawmaterialout"];
+        public string urlPalletQueryinventory = WIDESEAWCS_Core.Helper.AppSettings.Configuration["urlPalletQueryinventory"];
         /// <summary>
         /// 鎺ユ敹WMS浠诲姟淇℃伅
         /// </summary>
@@ -106,10 +112,12 @@
                     Dt_Task task = _mapper.Map<Dt_Task>(item);
                     task.TaskState = (int)TaskOutStatusEnum.OutNew;
                     task.Roadway = task.Roadway == "1" ? task.Roadway = "SC01" : task.Roadway = "SC02";
+                    task.CreateDate = DateTime.Now;
                     tasks.Add(task);
                 }
                 BaseDal.AddData(tasks);
                 _taskExecuteDetailService.AddTaskExecuteDetail(tasks.Select(x => x.TaskNum).ToList(), "鎺ユ敹WMS浠诲姟");
+
                 content = WebResponseContent.Instance.OK("鎴愬姛");
             }
             catch (Exception ex)
@@ -134,6 +142,14 @@
             public string SourceAddress { get; set; }
             public string PalletCode { get; set; }
         }
+
+        public class GenerateInv3
+        {
+            
+            public string PalletCode { get; set; }
+            public int outCount { get; set; }
+            public string TargetAddress { get; set; }
+        }
         public WebResponseContent RequestWMSTask(string palletCode, string sourceAddress)
         {
             WebResponseContent content = new WebResponseContent();
@@ -145,6 +161,7 @@
                     PalletCode = palletCode
                 };
                 content = HttpHelper.Post<WebResponseContent>($"{urlWMSTask}", generate);
+                WriteLog.GetLog("鍏ュ簱浠诲姟鎺ユ敹").Write(JsonConvert.SerializeObject(content), "鍏ュ簱浠诲姟鎺ユ敹");
                 Dt_Task task = new Dt_Task();
                 if (content != null)
                 {
@@ -154,24 +171,17 @@
                         task.TaskState = (int)TaskInStatusEnum.Line_InFinish;
                         task.Roadway = task.Roadway == "1" ? task.Roadway = "SC01" : task.Roadway = "SC02";
                         BaseDal.AddData(task);
+                        return content;
                     }
-                    else
-                    {
+                }
 
-                        return null;
-                    }
-                }
-                else
-                {
-                    return null;
-                }
                 
+                return content = WebResponseContent.Instance.Error();
             }
             catch (Exception ex)
             {
-                content = WebResponseContent.Instance.Error(ex.Message);
+                return content = WebResponseContent.Instance.Error(ex.Message);
             }
-            return content;
         }
         /// <summary>
         /// 杩涜缁勭洏
@@ -180,8 +190,66 @@
         /// <returns></returns>
         public WebResponseContent ToPlatform(string palletCode)
         {
+            try
+            {
+                WebResponseContent content = new WebResponseContent();
+                GenerateInv generate = new GenerateInv()
+                {
+                    SourceAddress = "",
+                    PalletCode = palletCode
+                };
+
+                return content = HttpHelper.Post<WebResponseContent>($"{urlQueryinventory}", generate);
+            }
+            catch (Exception ex)
+            {
+
+                throw;
+            }
+        }
+
+            
+
+        /// <summary>
+        /// 鏍规嵁鎵樼洏鍙枫�佽捣濮嬪湴鍧�鍚慦MS璇锋眰浠诲姟
+        /// </summary>
+        /// <param name="palletCode">鎵樼洏鍙�</param>
+        /// <param name="sourceAddress">璧峰鍦板潃</param>
+        /// <returns></returns>
+        public WebResponseContent RequestWMSTask2(string palletCode,string sourceAddress)
+        {
             WebResponseContent content = new WebResponseContent();
-            return  content = HttpHelper.Get<WebResponseContent>($"{urlQueryinventory}?palletCode={palletCode}");
+            try
+            {
+                GenerateInv generate = new GenerateInv()
+                {
+                    SourceAddress = sourceAddress,
+                    PalletCode = palletCode
+                };
+                content = HttpHelper.Post<WebResponseContent>($"{urlEmptyOutbound}", generate);
+                Dt_Task task = new Dt_Task();
+                if (content != null)
+                {
+                    if (content.Status)
+                    {
+                        task = JsonConvert.DeserializeObject<Dt_Task>(content.Data.ToString());
+                        task.TaskState = (int)TaskOutStatusEnum.OutNew;
+                        task.TaskType = (int)TaskOutboundTypeEnum.Outbound;
+                        task.Roadway = task.Roadway == "1" ? task.Roadway = "SC01" : task.Roadway = "SC02";
+                        BaseDal.AddData(task);
+                        return content = WebResponseContent.Instance.OK();
+                    }
+                    else
+                    {
+                        WriteLog.GetLog("PLC鏃ュ織鍑哄簱鏃ュ織").Write($"绌烘墭鍑哄簱澶辫触锛岃鎯咃細{content.Message}", "闇�瑕佺┖鎵�");
+                    }
+                }
+                return content;
+            }
+            catch (Exception ex)
+            {
+                return content.Error(ex.Message);
+            }
         }
 
         /// <summary>
@@ -190,34 +258,51 @@
         /// <param name="palletCode">鎵樼洏鍙�</param>
         /// <param name="sourceAddress">璧峰鍦板潃</param>
         /// <returns></returns>
-        public WebResponseContent RequestWMSTask2(string sourceAddress)
+        public WebResponseContent RequestWMSTask3(string palletCode, int outCount,string Loc)
         {
             WebResponseContent content = new WebResponseContent();
             try
             {
-                content = HttpHelper.Get<WebResponseContent>($"{urlEmptyOutbound}?sourceAddress={sourceAddress}");
+                if (outCount==0)
+                {
+                    outCount = 1;
+                }
+                GenerateInv3 generate = new GenerateInv3()
+                {
+                    PalletCode = palletCode,
+                    outCount = outCount,
+                    TargetAddress= Loc
+                };
+                content = HttpHelper.Post<WebResponseContent>($"{urlRawmaterialout}", generate);
                 Dt_Task task = new Dt_Task();
                 if (content != null)
                 {
                     if (content.Status)
                     {
                         task = JsonConvert.DeserializeObject<Dt_Task>(content.Data.ToString());
-                        task.TaskState = (int)TaskInStatusEnum.Line_InFinish;
+                        task.TaskState = (int)TaskOutStatusEnum.OutNew;
+                        task.TaskType = (int)TaskOutboundTypeEnum.Outbound;
                         task.Roadway = task.Roadway == "1" ? task.Roadway = "SC01" : task.Roadway = "SC02";
                         BaseDal.AddData(task);
                         return content = WebResponseContent.Instance.OK();
                     }
-                    else
-                    {
-
-                        return content = WebResponseContent.Instance.Error();
-                    }
                 }
-                else
-                {
-                    return content = WebResponseContent.Instance.Error();
-                }
+                return content = WebResponseContent.Instance.Error();
+            }
+            catch (Exception ex)
+            {
+                return content = WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
 
+
+        public WebResponseContent RequestWMSTask4()
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+
+                return content = HttpHelper.Get<WebResponseContent>($"{urlPalletQueryinventory}");
             }
             catch (Exception ex)
             {
@@ -239,15 +324,63 @@
             {
                 if (content.Status)
                 {
-                    if (Convert.ToInt32(content.Data) != _Task.TaskNum)
+                    if(content.Data != null)
                     {
                         task = JsonConvert.DeserializeObject<Dt_Task>(content.Data.ToString());
-                        task.TaskState = (int)TaskRelocationTypeEnum.Relocation;
-                        task.Roadway = task.Roadway == "1" ? task.Roadway = "SC01" : task.Roadway = "SC02";
-                        task.Grade = 3;
-                        BaseDal.AddData(task);
-                        return task;
+                        if (task.TaskNum != _Task.TaskNum)
+                        {
+                            WriteLog.GetLog("鎺ユ敹浠诲姟").Write("绉诲簱浠诲姟锛�"+JsonConvert.SerializeObject(task), "鎺ユ敹浠诲姟");
+                            task.TaskState = (int)TaskRelocationTypeEnum.Relocation;
+                            task.Roadway = task.Roadway == "1" ? task.Roadway = "SC01" : task.Roadway = "SC02";
+                            task.TaskNum = task.TaskNum;
+                            task.Grade = 3;
+                            task.TaskType= (int)TaskRelocationTypeEnum.Relocation;
+                            BaseDal.AddData(task);
+                            return task;
+                        }
                     }
+                }
+                else
+                {
+                    WriteLog.GetLog("PLC鏃ュ織").Write($"澶辫触淇℃伅锛歿content.Message}", "绉诲簱淇℃伅");
+                    return null;
+                    
+                }
+            }
+
+            return _Task;
+        }
+
+
+        public Dt_Task RequestWMSTaskMovelibrary2(Dt_Task _Task)
+        {
+            WebResponseContent content = new WebResponseContent();
+            content = HttpHelper.Get<WebResponseContent>($"{urlWMSMovelibraryTask}?TaskNum={_Task.TaskNum}&SourceAddress={_Task.TargetAddress}");
+            Dt_Task task = new Dt_Task();
+            if (content != null)
+            {
+                if (content.Status)
+                {
+                    if (content.Data != null)
+                    {
+                        task = JsonConvert.DeserializeObject<Dt_Task>(content.Data.ToString());
+                        if (task.TaskNum != _Task.TaskNum)
+                        {
+                            WriteLog.GetLog("鎺ユ敹浠诲姟").Write("绉诲簱浠诲姟锛�" + JsonConvert.SerializeObject(task), "鎺ユ敹浠诲姟");
+                            task.TaskState = (int)TaskOutStatusEnum.ResRestNet;
+                            task.Roadway = task.Roadway == "1" ? task.Roadway = "SC01" : task.Roadway = "SC02";
+                            task.TaskNum = task.TaskNum;
+                            task.Grade = 3;
+                            task.TaskType = (int)TaskRelocationTypeEnum.Relocation;
+                            BaseDal.AddData(task);
+                            return task;
+                        }
+                    }
+                }
+                else
+                {
+                    WriteLog.GetLog("PLC鏃ュ織").Write($"澶辫触淇℃伅锛歿content.Message}", "绉诲簱淇℃伅");
+                    return null;
 
                 }
             }
@@ -318,10 +451,36 @@
             else
                 return BaseDal.QueryFirst(x => x.Roadway == deviceNo && x.CurrentAddress == currentAddress && (TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InFinish || TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew), TaskOrderBy);
         }
+
+        public List<Dt_Task> CraneTaskList(string deviceNo)
+        {
+            return BaseDal.QueryData(x => x.Roadway == deviceNo && (x.TaskState == (int)TaskInStatusEnum.Line_InFinish || x.TaskState == (int)TaskOutStatusEnum.OutNew),TaskOrderBy);
+        }
+
+        public Dt_Task CutStackerCraneTask(string deviceNo)
+        {
+            Dt_Task dt_Task = BaseDal.QueryFirst(x => x.Roadway == deviceNo && (x.TaskState == (int)TaskOutStatusEnum.SC_OutExecuting || x.TaskState == (int)TaskOutStatusEnum.SC_OutFinish || x.TaskState == (int)TaskInStatusEnum.SC_InExecuting || x.TaskState == (int)TaskInStatusEnum.SC_InFinish));
+            return dt_Task;
+        }
+
         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>
@@ -371,7 +530,12 @@
         /// <returns>杩斿洖浠诲姟瀹炰綋瀵硅薄闆嗗悎锛屽彲鑳戒负null</returns>
         public List<Dt_Task> QueryStationIsOccupiedOutTasks(string deviceNo, string SourceAddress)
         {
-            return BaseDal.QueryData(x => x.Roadway == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew && SourceAddress.Contains(x.SourceAddress), TaskOrderBy);
+            return BaseDal.QueryData(x => x.Roadway == deviceNo && SourceAddress.Contains(x.SourceAddress), TaskOrderBy);
+        }
+
+        public List<Dt_Task> QueryStationIsOccupiedOutTasks2(string deviceNo, string TargetAddress)
+        {
+            return BaseDal.QueryData(x => x.Roadway == deviceNo && TargetAddress.Contains(x.SourceAddress), TaskOrderBy);
         }
 
         /// <summary>
@@ -461,13 +625,10 @@
                         return content = WebResponseContent.Instance.Error($"璇ヤ换鍔$姸鎬佷笉鍙烦杞埌涓嬩竴姝�,浠诲姟鍙�:銆恵task.TaskNum}銆�,浠诲姟鐘舵��:銆恵task.TaskState}銆�");
                     }
 
-                    int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskOutStatusEnum>();
+                    //int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskOutStatusEnum>();
 
-                    task.TaskState = nextStatus;
-                    if (task.TaskState == (int)TaskOutStatusEnum.SC_OutExecuting)
-                    {
-                        task.Dispatchertime = DateTime.Now;
-                    }
+                    task.TaskState = (int)TaskOutStatusEnum.SC_OutExecuting;
+                    task.Dispatchertime = DateTime.Now;
                 }
                 else if (task.TaskType == (int)TaskInboundTypeEnum.Inbound)
                 {
@@ -476,34 +637,17 @@
                         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;
-                    }
+                    //int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskInStatusEnum>();
+                    task.TaskState = (int)TaskInStatusEnum.SC_InExecuting;
+                    task.Dispatchertime = DateTime.Now;
                 }
-                else if (task.TaskType == (int)TaskInboundTypeEnum.Inbound)
+                else if (task.TaskType == (int)TaskRelocationTypeEnum.Relocation)
                 {
-                    if (task.TaskState <= (int)TaskRelocationStatusEnum.SC_RelocationFinish)
+                    if (task.TaskState != (int)TaskOutStatusEnum.ResRestNet)
                     {
-                        
                         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;
-                    }
+                    task.TaskState = (int)TaskOutStatusEnum.ResRest;    //涓嬪彂绉诲簱浠诲姟
                 }
                 else
                 {
@@ -571,6 +715,12 @@
         /// </summary>
         /// <param name="taskNum">浠诲姟缂栧彿</param>
         /// <returns>杩斿洖澶勭悊缁撴灉</returns>
+        public class GenerateInv2
+        {
+            public string PalletCode { get; set; }
+            public string SourceAddress { get; set; }
+            public string TargetAddress { get; set; }
+        }
         public WebResponseContent StackCraneTaskCompleted(int taskNum)
         {
             WebResponseContent content = new WebResponseContent();
@@ -583,9 +733,14 @@
                 {
                     /*List<Dt_Router> routers = _routerService.QueryNextRoutes(task.NextAddress, task.TargetAddress);
                     if (!routers.Any()) return WebResponseContent.Instance.Error($"鏈壘鍒拌澶囪矾鐢变俊鎭�");*/
-
-                    content = HttpHelper.Get<WebResponseContent>($"{urlTaskCompleted}?TaskNum={task.TaskNum}");
                     task.TaskState = (int)TaskOutStatusEnum.OutFinish;
+                    BaseDal.UpdateData(task);
+
+
+                    content = HttpHelper.Get<WebResponseContent>($"{urlTaskCompleted}?TaskNum={task.TaskNum}&HowWorks=2");
+
+                    wcs_PLCto09("鍑哄簱浠诲姟", $"鏉$爜锛歿task.PalletCode},浠诲姟鍙凤細{task.TaskNum}", $"璋冨彇wms浠诲姟鍙嶉锛歿JsonConvert.SerializeObject(content)}");
+
                     task.ModifyDate = DateTime.Now;
                     BaseDal.DeleteData(task);
                     _task_HtyService.AddTaskHty(task);
@@ -596,10 +751,14 @@
                 }
                 else if (task.TaskType == (int)TaskInboundTypeEnum.Inbound && task.TaskState == (int)TaskInStatusEnum.SC_InExecuting)
                 {
-                    content = HttpHelper.Get<WebResponseContent>($"{urlTaskCompleted}?TaskNum={task.TaskNum}");
+                    task.TaskState = (int)TaskInStatusEnum.InFinish;
+                    BaseDal.UpdateData(task);
+
+                    content = HttpHelper.Get<WebResponseContent>($"{urlTaskCompleted}?TaskNum={task.TaskNum}&HowWorks=2");
+
+                    wcs_PLCto09("鍏ュ簱浠诲姟", $"鏉$爜锛歿task.PalletCode},浠诲姟鍙凤細{task.TaskNum}", $"璋冨彇wms浠诲姟鍙嶉锛歿JsonConvert.SerializeObject(content)}");
                     //todo 
                     //int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskInStatusEnum>();
-                    task.TaskState = (int)TaskInStatusEnum.InFinish;
                     task.ModifyDate = DateTime.Now;
                     task.Modifier = "System";
                     BaseDal.DeleteData(task);
@@ -609,8 +768,13 @@
                 }
                 else if (task.TaskType == (int)TaskRelocationTypeEnum.Relocation)
                 {
-                    content = HttpHelper.Get<WebResponseContent>($"{urlRelocationTaskCompleted}?PalletCode={task.PalletCode}&SourceAddress ={ task.SourceAddress}TargetAddress ={task.TargetAddress}");
-                    task.TaskState = (int)TaskOutStatusEnum.SC_OutFinish;
+                    task.TaskState = (int)TaskOutStatusEnum.OutRest;
+                    BaseDal.UpdateData(task);
+
+                    content = HttpHelper.Get<WebResponseContent>($"{urlTaskCompleted}?TaskNum={task.TaskNum}&HowWorks=2");
+
+                    wcs_PLCto09("鍏ュ簱浠诲姟", $"鏉$爜锛歿task.PalletCode},浠诲姟鍙凤細{task.TaskNum}", $"璋冨彇wms浠诲姟鍙嶉锛歿JsonConvert.SerializeObject(content)}");
+
                     task.ModifyDate = DateTime.Now;
                     BaseDal.DeleteData(task);
                     _task_HtyService.AddTaskHty(task);
@@ -628,9 +792,19 @@
             }
             catch (Exception ex)
             {
-                content = WebResponseContent.Instance.Error($"浠诲姟瀹屾垚寮傚父,浠诲姟鍙�:銆恵taskNum}銆�");
+                content = WebResponseContent.Instance.Error($"浠诲姟瀹屾垚寮傚父,浠诲姟鍙�:銆恵taskNum}銆戯紝鍘熷洜锛歿ex.Message}");
             }
             return content;
+        }
+
+        public WebResponseContent StackCraneTashty(int taskNum)
+        {
+            WebResponseContent content = new WebResponseContent();
+            int taskcount = _task_HtyRepository.QueryData(x =>x.TaskNum == taskNum && x.CreateDate >= DateTime.Now.AddMinutes(-30)).Count();
+
+            if (taskcount>0) return WebResponseContent.Instance.OK();
+
+             return WebResponseContent.Instance.Error($"鏈壘鍒拌浠诲姟淇℃伅锛屾椂闂翠笉鍦ㄨ寖鍥村唴,浠诲姟鍙蜂负锛歿taskNum}");
         }
 
         /// <summary>
@@ -723,5 +897,92 @@
             }
             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++)
+                        {
+                            dynamicDelKeys.Add(keys[i]);
+                        }
+                        ((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
+                    {
+                        return WebResponseContent.Instance.Error("鍙傛暟閿欒");
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                ((SqlSugarClient)BaseDal.Db).RollbackTran();
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+
+        public WebResponseContent ReceiveWCSTask(int tasknum)
+        {
+            Dt_Task tasks = BaseDal.QueryFirst(x => x.TaskNum == tasknum);
+            if(tasks == null)
+            {
+                return WebResponseContent.Instance.Error();
+            }
+            else
+            {
+                try
+                {
+                    _task_HtyService.AddTaskHty(tasks);
+                    BaseDal.DeleteData(tasks);
+                    WriteLog.Write_Log("WMS鎵嬪姩鍒犻櫎浠诲姟", "鍒犻櫎鎴愬姛", $"鐢宠鍒犻櫎鐨勬潯鐮侊細{tasks.TaskNum},鎵樼洏鏉$爜锛歿tasks.PalletCode}", new { 淇℃伅 = "鍒犻櫎鎴愬姛" });
+                    return WebResponseContent.Instance.OK();
+
+                }
+                catch (Exception ex)
+                {
+                    WriteLog.Write_Log("WMS鎵嬪姩鍒犻櫎浠诲姟", "鍒犻櫎澶辫触", $"鐢宠鍒犻櫎鐨勬潯鐮侊細{tasks.TaskNum},鎵樼洏鏉$爜锛歿tasks.PalletCode}", new { 淇℃伅 = ex.Message });
+                    return WebResponseContent.Instance.Error();
+                }
+            }
+            
+        }
+
+
+        public void wcs_PLCto09(string SCLLinStack, string Logtype, string Magessadd)
+        {
+            WriteLog.Write_Log("浠诲姟瀹屾垚浜や簰", SCLLinStack, Logtype, new { 淇℃伅 = Magessadd });
+        }
     }
 }

--
Gitblit v1.9.3