From 3590ec552055adb6a20fa2b6424b4326b586eecd Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <1247017146@qq.com>
Date: 星期一, 02 六月 2025 17:45:04 +0800
Subject: [PATCH] 1

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_StorageSocketServices/SocketClientService.cs |  808 +++++++++++++++++++++++++++++++-------------------------
 1 files changed, 446 insertions(+), 362 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageSocketServices/SocketClientService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageSocketServices/SocketClientService.cs"
index 898832d..0b968d9 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageSocketServices/SocketClientService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_StorageSocketServices/SocketClientService.cs"
@@ -1,38 +1,34 @@
 锘縰sing LogLibrary.Log;
 using Microsoft.Extensions.Configuration;
-using Microsoft.Extensions.Hosting;
 using Microsoft.Extensions.Logging;
-using MimeKit;
 using Newtonsoft.Json;
-using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
-using Org.BouncyCastle.Tls;
-using System;
 using System.Net;
 using System.Net.Sockets;
 using System.Reflection;
 using System.Text;
 using WIDESEA_Common;
 using WIDESEA_Core;
-using WIDESEA_Core.BaseServices;
 using WIDESEA_Core.Enums;
 using WIDESEA_Core.Helper;
-using WIDESEA_Core.Middlewares;
 using WIDESEA_DTO.AGV;
 using WIDESEA_DTO;
-using WIDESEA_IServices;
 using WIDESEA_IStorageBasicRepository;
 using WIDESEA_IStorageSocketServices;
 using WIDESEA_IStorageTaskRepository;
-using WIDESEA_IStorageTaskServices;
 using WIDESEA_Model.Models.AGV;
 using WIDESEA_Model.Models;
 using WIDESEAWCS_BasicInfoRepository;
-//using static MailKit.Telemetry;
 using WIDESEAWCS_Model.Models;
-using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
 using WIDESEA_Core.BaseRepository;
 using AutoMapper;
 using Mapster;
+using AngleSharp.Dom;
+using Masuit.Tools.Security;
+using WIDESEA_IStorageTaskServices;
+using System.Threading.Tasks;
+using Microsoft.Extensions.DependencyInjection;
+using WIDESEA_IBusinessesRepository;
+using WIDESEA_Repository;
 
 namespace WIDESEA_StorageSocketServices
 {
@@ -53,14 +49,28 @@
         private readonly IDt_Task_HtyRepository _task_HtyRepository;
         private readonly IMapper _mapper;
         private readonly ILocationInfoRepository _locationRepository;
+        private readonly IDt_TaskService _taskService;
+        private readonly IDt_HostLogRepository _hostLogRepository;
+        private bool _IsOnline=false;
 
 
-        public SocketClientService(/*IDt_TaskService taskService*/IDt_TaskRepository TaskRepository, IDt_StationManagerRepository stationManagerRepository, ILogger<SocketClientService> logger)
+        public SocketClientService(IDt_TaskService TaskService, IDt_TaskRepository TaskRepository, IDt_StationManagerRepository stationManagerRepository, ILogger<SocketClientService> logger, ILocationInfoRepository locationInfoRepository,IDt_HostLogRepository hostLogRepository)
         {
-            //_taskService = taskService;
-            BaseDal= TaskRepository;
-            _stationManagerRepository= stationManagerRepository;
+            BaseDal = TaskRepository;
+            _stationManagerRepository = stationManagerRepository;
             _logger = logger;
+            _taskService = TaskService;
+            _locationRepository = locationInfoRepository;
+            _hostLogRepository = hostLogRepository;
+            #region
+            //if (App.RootServices != null)
+            //{
+            //    IDt_TaskRepository? BaseDal = App.RootServices.CreateScope().ServiceProvider.GetService(typeof(IDt_TaskRepository)) as IDt_TaskRepository;
+            //    IDt_TaskService? _taskService = App.RootServices.CreateScope().ServiceProvider.GetService(typeof(IDt_TaskService)) as IDt_TaskService;
+            //    ILocationInfoRepository? _locationRepository = App.RootServices.CreateScope().ServiceProvider.GetService(typeof(ILocationInfoRepository)) as ILocationInfoRepository;
+            //    IDt_StationManagerRepository? _stationManagerRepository = App.RootServices.CreateScope().ServiceProvider.GetService(typeof(IDt_StationManagerRepository)) as IDt_StationManagerRepository;
+            //}
+            #endregion
         }
 
         public void ConnectServer(string IP, int Port)
@@ -70,10 +80,10 @@
                 // 妫�鏌ユ槸鍚﹀凡杩炴帴锛岄伩鍏嶉噸澶嶅垱寤�
                 if (socket != null && socket.Connected)
                 {
-                    //Console.WriteLine("Socket宸茶繛鎺ワ紝鏃犻渶閲嶅鍒涘缓");
                     ConsoleHelper.WriteErrorLine($"Socket宸插浜庤繛鎺ョ姸鎬�");
                     return;
                 }
+
                 //鍒涘缓璐熻矗閫氫俊鐨剆ocket
                 socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                 IPAddress ip = IPAddress.Parse(IP);
@@ -84,7 +94,7 @@
 
                 _logger.LogInformation("Socket杩炴帴鎴愬姛");
                 ConsoleHelper.WriteSuccessLine("Socket杩炴帴鎴愬姛");
-
+                _IsOnline = true;
                 RequestCommunication();
                 DeviceStateReport("I");
 
@@ -92,14 +102,18 @@
                 Thread th = new Thread(Receive);
                 th.IsBackground = true;
                 th.Start();
-                ConsoleHelper.WriteErrorLine($"Socket鍚姩");
                 return;
             }
             catch (Exception ex)
             {
+                _IsOnline = false;
                 ConsoleHelper.WriteErrorLine($"Socket杩炴帴澶辫触{ex.Message}");
                 HandleDisconnection();
             }
+        }
+        public bool Socketonline()
+        {
+            return _IsOnline;
         }
         void Receive()
         {
@@ -153,11 +167,12 @@
                     }
                     else
                     {
-                         LogFactory.GetLog("Socket鎺ユ敹鏁版嵁").Error(true, "鏃犳晥鎶ユ枃鏍煎紡");
+                        LogFactory.GetLog("Socket鎺ユ敹鏁版嵁").Error(true, $"鏃犳晥鎶ユ枃鏍煎紡:{JsonConvert.SerializeObject(Y)}");
                     }
                 }
                 catch
                 {
+                    _IsOnline = false;
                     HandleDisconnection();
 
                 }
@@ -172,13 +187,13 @@
                     ReceiveCommandResponse(x);
                     break;
                 case "906":
-                    AGVJobStartOrEndResponse(x.Substring(21, 1),x.Substring(22,1));
+                    AGVJobStartOrEndResponse(x.Substring(20, 1), x.Substring(21, 1));
                     break;
                 case "902":
-                    DataReportResponse(x.Substring(21, 1));
+                    DataReportResponse(x.Substring(20, 1));
                     break;
                 case "935":
-                    DeviceStationStatusInvite();
+                    DeviceStationStatusInvite(x.Substring(15, 5));
                     break;
                 case "103":
                     HOSTOutBoundTask(x);
@@ -187,7 +202,7 @@
                     RecreateGetLocation(x);
                     break;
                 case "108":
-                    RecreateGetLocation(x.Substring(21, 1));
+                    EmptyOutBoundResponse(x.Substring(20, 1));
                     break;
                 case "909":
                     DeviceStatusReportRequest();
@@ -221,26 +236,10 @@
                 attempts--;
             } while (!socket.Connected && attempts > 0);
         }
-
-        //private void CheckTimeout(object state)
-        //{
-        //    TimeSpan elapsed = DateTime.Now - _lastActivityTime;
-        //    if (elapsed.TotalSeconds > 180) // 3鍒嗛挓瓒呮椂
-        //    {
-        //        Console.WriteLine("瓒呮椂鏈敹鍒版暟鎹紝瑙﹀彂909鍛戒护骞跺皾璇曢噸鏂拌繛鎺�...");
-
-        //        // 瑙﹀彂909鍛戒护
-        //        _workTaskService.DeviceStatusReportRequest();
-
-        //        // 灏濊瘯閲嶆柊杩炴帴
-        //        HandleDisconnection();
-        //    }
-        //}
-
         public void clientSend(byte[] buffer)
         {
             var Y = Encoding.UTF8.GetString(buffer);
-            LogFactory.GetLog("Socket鍙戦�佹暟鎹�").Error(true, Y);
+            LogFactory.GetLog("Socket鍙戦�佹暟鎹�").Info(true, Y);
             socket.Send(buffer);
         }
 
@@ -249,7 +248,7 @@
             int sum = 0;
             try
             {
-                for (int i = 0; i < x.Length-2; i++)
+                for (int i = 0; i < x.Length - 2; i++)
                 {
                     sum += x[i];
                 }
@@ -278,6 +277,14 @@
         public const string priority = "1";
 
         /// <summary>
+        /// 閲嶅叆搴�
+        /// </summary>
+        public const string Restocking = "2100";
+
+
+        public const string EmptyOutBoundconst = "2101";
+
+        /// <summary>
         /// 鎵樼洏涓暟  棰勭暀
         /// </summary>
         public const string TrayCnt = "1";
@@ -285,7 +292,7 @@
         /// <summary>
         /// 璁惧缂栧彿
         /// </summary>
-        public const string DeviceID = "0000000001";
+        public const string DeviceID = "0013130010";
         /// <summary>
         /// 鍙戦�佷笉闇�瑕佸洖澶�
         /// </summary>
@@ -348,7 +355,7 @@
         {
             try
             {
-                string str = SendandReply + "101" + BaseDal.GetSeqNo().Result.ToString() + GetFieldsAsString(Agvstatus) + GetListStringOutStation(outStations) + "1" + GetFieldsAsString(inStation);
+                string str = SendandReply + "101" + BaseDal.GetSeqNo().Result.ToString("D5") + GetFieldsAsString(Agvstatus) + GetListStringOutStation(outStations) + OutStationSpare2 + "1" + GetFieldsAsString(inStation);
                 clientSend(MakeStringToByteMsg(str));
             }
             catch (Exception ex)
@@ -366,7 +373,7 @@
         {
             try
             {
-                string str = SendandReply + "925" + BaseDal.GetSeqNo().Result.ToString();
+                string str = SendandReply + "925" + BaseDal.GetSeqNo().Result.ToString("D5");
                 clientSend(MakeStringToByteMsg(str));
             }
             catch (Exception ex)
@@ -384,7 +391,7 @@
         {
             try
             {
-                string str = SendNotReply + "915" + BaseDal.GetSeqNo().Result.ToString() + Command;
+                string str = SendNotReply + "915" + BaseDal.GetSeqNo().Result.ToString("D5") + Command;
                 clientSend(MakeStringToByteMsg(str));
             }
             catch (Exception ex)
@@ -403,7 +410,7 @@
         {
             try
             {
-                string str = SendNotReply + "913" + BaseDal.GetSeqNo().Result.ToString() + Status;
+                string str = SendNotReply + "913" + BaseDal.GetSeqNo().Result.ToString("D5") + Status;
                 clientSend(MakeStringToByteMsg(str));
             }
             catch (Exception ex)
@@ -422,7 +429,7 @@
         {
             try
             {
-                string str = SendNotReply + "917" + BaseDal.GetSeqNo().Result.ToString() + Status;
+                string str = SendNotReply + "917" + BaseDal.GetSeqNo().Result.ToString("D5") + Status;
                 clientSend(MakeStringToByteMsg(str));
             }
             catch (Exception ex)
@@ -444,7 +451,7 @@
         {
             try
             {
-                string str = SendandReply + "905" + BaseDal.GetSeqNo().Result.ToString() + Status + JobOrderID + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode;
+                string str = SendandReply + "905" + BaseDal.GetSeqNo().Result.ToString("D5") + Status + JobOrderID + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode;
                 clientSend(MakeStringToByteMsg(str));
             }
             catch (Exception ex)
@@ -467,7 +474,7 @@
         {
             try
             {
-                string str = SendNotReply + "907" + BaseDal.GetSeqNo().Result.ToString() + Status + JobOrderID + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode;
+                string str = SendNotReply + "907" + BaseDal.GetSeqNo().Result.ToString("D5") + Status + JobOrderID + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode;
                 clientSend(MakeStringToByteMsg(str));
             }
             catch (Exception ex)
@@ -489,7 +496,14 @@
         {
             try
             {
-                string str = SendandReply + "901" + BaseDal.GetSeqNo().Result.ToString() + "0" + JobOrderID + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode;
+                string str = SendandReply + "901" + BaseDal.GetSeqNo().Result.ToString("D5") + "0" + JobOrderID + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode;
+                Dt_HostLog hostLog = new Dt_HostLog()
+                {
+                    CommandID = 901,
+                    Count=0,
+                    Messgae=str,
+                };
+                _hostLogRepository.AddData(hostLog);
                 clientSend(MakeStringToByteMsg(str));
             }
             catch (Exception ex)
@@ -507,11 +521,14 @@
         /// <param name="TaskType">浠诲姟绫诲瀷 I鍏ュ簱銆丱鍑哄簱銆丼绔欏彴鍒扮珯鍙般�丷绉诲簱</param>
         /// <param name="PallteCode">鎵樼洏鍙�</param>
         /// <returns></returns>
-        public void DeviceStationStatusReport(HOSTAGVStatus Agvstatus, List<OutStationStatus> outStations, List<InStationStatus> inStation)
+        public void DeviceStationStatusReport(HOSTAGVStatus Agvstatus, List<OutStationStatus> outStations, List<InStationStatus> inStation, string sGetSeqNo)
         {
             try
             {
-                string str = SendNotReply + "936" + BaseDal.GetSeqNo().Result.ToString() + GetFieldsAsString(Agvstatus) + GetListStringOutStation(outStations) + GetListStringInStation(inStation);
+                var agvstatus = GetFieldsAsString(Agvstatus);
+                var outstation = GetListStringOutStation(outStations);
+                var instation = GetListStringInStation(inStation);
+                string str = SendNotReply + "936" + sGetSeqNo + agvstatus + outstation + OutStationSpare2 + "2" + instation;
                 clientSend(MakeStringToByteMsg(str));
             }
             catch (Exception ex)
@@ -532,7 +549,14 @@
         {
             try
             {
-                string str = SendandReply + "105" + BaseDal.GetSeqNo().Result.ToString() + "R" + JobOrderID + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode;
+                string str = SendandReply + "105" + BaseDal.GetSeqNo().Result.ToString("D5") + "R" + JobOrderID + priority + FormLocation + ToLocation + TaskType + TrayCnt + PallteCode;
+                Dt_HostLog hostLog = new Dt_HostLog()
+                {
+                    CommandID = 105,
+                    Count = 0,
+                    Messgae = str,
+                };
+                _hostLogRepository.AddData(hostLog);
                 clientSend(MakeStringToByteMsg(str));
             }
             catch (Exception ex)
@@ -552,7 +576,7 @@
         {
             try
             {
-                string str = SendNotReply + "985" + BaseDal.GetSeqNo().Result.ToString() + Trouble + Level + Location;
+                string str = SendNotReply + "985" + BaseDal.GetSeqNo().Result.ToString("D5") + Trouble + Level + Location;
                 clientSend(MakeStringToByteMsg(str));
             }
             catch (Exception ex)
@@ -571,7 +595,7 @@
         {
             try
             {
-                string str = SendNotReply + "104" + BaseDal.GetSeqNo().Result.ToString() + Statues;
+                string str = SendNotReply + "104" + BaseDal.GetSeqNo().Result.ToString("D5") + Statues;
                 clientSend(MakeStringToByteMsg(str));
             }
             catch (Exception ex)
@@ -592,7 +616,14 @@
         {
             try
             {
-                string str = SendandReply + "107" + BaseDal.GetSeqNo().Result.ToString() + "1" + JobOrderID + priority + FormLocation + ToLocation + "O" + TrayCnt + PallteCode;
+                string str = SendandReply + "107" + BaseDal.GetSeqNo().Result.ToString("D5") + "1" + JobOrderID + priority + FormLocation + ToLocation + "O" + TrayCnt + PallteCode;
+                Dt_HostLog hostLog = new Dt_HostLog()
+                {
+                    CommandID = 107,
+                    Count = 0,
+                    Messgae = str,
+                };
+                _hostLogRepository.AddData(hostLog);
                 clientSend(MakeStringToByteMsg(str));
             }
             catch (Exception ex)
@@ -608,7 +639,8 @@
         /// <param name="AgvStatus"></param>
         public void DeviceStatusReportResponse(HOSTAGVStatus AgvStatus, string X, string Y)
         {
-            string str = SendNotReply + "910" + BaseDal.GetSeqNo().Result.ToString() + "1" + GetFieldsAsString(AgvStatus) + X + Y;
+            string str = SendNotReply + "910" + BaseDal.GetSeqNo().Result.ToString("D5") + GetFieldsAsString(AgvStatus) + X + Y;
+            clientSend(MakeStringToByteMsg(str));
         }
 
         #endregion
@@ -622,16 +654,38 @@
         public void ReceiveCommandResponse(string message)
         {
             var parseMessage = GetParse(message);
+            var lcationEnd = parseMessage.body.ToLocation;
             switch (parseMessage.body.ret)
             {
                 //OK
                 case "0":
-                    //UpdateTaskLocation(parseMessage);
-                    InsertWMSTask(parseMessage);
-                    Thread.Sleep(500);
-                    //915
-                    JobReady("0");
-                    break;
+                    //var location = _locationRepository.QueryFirst(x => x.LocationCode == lcationEnd);
+                    var location = SqlSugarHelper.DbWMS.Queryable<DtLocationInfo>().Where(x => x.LocationCode == parseMessage.body.ToLocation).First();
+                    if (location == null)
+                    {
+                        return;
+                    }
+                    if (location.LocationStatus == (int)LocationEnum.Free)
+                    {
+                        var task = InsertWMSTask(parseMessage);
+                        Thread.Sleep(500);
+                        InsertAGVTask(task);
+                        location.LocationStatus = 1;
+                        //SqlSugarHelper.DbWMS.Insertable(task).ExecuteCommand();
+                        SqlSugarHelper.DbWMS.Updateable(location).ExecuteCommand();
+                        BaseDal.AddData(task);
+                        //915
+                        JobReady("0");
+                        return;
+                    }
+                    else
+                    {
+                        ErrorReport(Restocking, "A", "00");
+                        Thread.Sleep(500);
+                        RecreateGetLocation(parseMessage.body.FromLocation, parseMessage.body.ToLocation, parseMessage.body.JobType, parseMessage.body.TrayIdList.Substring(0, 10));
+                        //todo璐т綅鏈夎揣閲嶅鍏ュ簱
+                        return;
+                    }
                 //NG
                 case "1":
                     break;
@@ -650,6 +704,8 @@
                 default:
                     break;
             }
+
+            LogFactory.GetLog("Host102鍥炲WMS101").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(parseMessage)}{Environment.NewLine}", "");
         }
 
         /// <summary>
@@ -677,6 +733,8 @@
                 default:
                     break;
             }
+
+            LogFactory.GetLog("Host906鍥炲WMS905").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(status)}{Environment.NewLine}{JsonConvert.SerializeObject(message)}{Environment.NewLine}", "");
         }
 
         /// <summary>
@@ -684,50 +742,45 @@
         /// </summary>
         public void DataReportResponse(string message)
         {
-            Dt_Task task = BaseDal.QueryFirst(x => x.TaskState == (int)TaskOutStatusEnum.AGV_OutFinish || x.TaskState == (int)TaskRelocationStatusEnum.AGV_RelocationFinish || x.TaskState == (int)TaskInStatusEnum.AGV_InFinish);
-            if (task != null)
-            {
-                switch (task.TaskType)
-                {
-                    case (int)TaskInboundTypeEnum.Inbound:
-                        //鍏ュ簱
-                        task.TaskState = (int)TaskInStatusEnum.AGV_InFinish;
-                        if (message == "0")
-                        {
-                            JobStartOrEnd("E", task.SourceAddress, task.TargetAddress, "O", task.PalletCode);
-                        }
-                       CompleteInboundTask(task);
-                        break;
-                    case (int)TaskOutboundTypeEnum.Outbound:
-                        //鍑哄簱
-                        if (message == "0")
-                        {
-                            JobStartOrEnd("E", task.SourceAddress, task.TargetAddress, "O", task.PalletCode);
-                        }
-                        task.TaskState = (int)TaskOutStatusEnum.AGV_OutFinish;
-                        CompleteOutboundTask(task);
-                        break;
-                    case (int)TaskRelocationTypeEnum.Relocation:
-                        if (message == "0")
-                        {
-                            JobStartOrEnd("E", task.SourceAddress, task.TargetAddress, "O", task.PalletCode);
-                        }
-                        task.TaskState = (int)TaskRelocationStatusEnum.AGV_RelocationFinish;
-                        CompleteRelocationboundTask(task);
-                        break;
-                    case (int)TaskStationTypeEnum.StationToStation:
-                        if (message == "0")
-                        {
-                            JobStartOrEnd("E", task.SourceAddress, task.TargetAddress, "O", task.PalletCode);
-                        }
-                        task.TaskState = (int)TaskOutStatusEnum.AGV_OutFinish;
-                        TaskMoveHty(task);
-                        break;
-                    default:
-                        break;
-                }
-
-            }
+            LogFactory.GetLog("Host902鍥炲WMS901").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(message)}{Environment.NewLine}", "");
+            #region 
+            //Dt_Task task = BaseDal.QueryFirst(x => (x.TaskState == (int)TaskOutStatusEnum.AGV_OutFinish || x.TaskState == (int)TaskRelocationStatusEnum.AGV_RelocationFinish || x.TaskState == (int)TaskInStatusEnum.AGV_InFinish) && x.Roadway != "PDA");
+            //if (task != null)
+            //{
+            //    switch (task.TaskType)
+            //    {
+            //        case 200:
+            //            //鍏ュ簱
+            //            if (message == "0")
+            //            {
+            //                JobStartOrEnd("E", task.Remark, task.TargetAddress, "O", task.PalletCode);
+            //            }
+            //            break;
+            //        case 100:
+            //            //鍑哄簱
+            //            if (message == "0")
+            //            {
+            //                JobStartOrEnd("E", task.SourceAddress, task.Remark, "O", task.PalletCode);
+            //            }
+            //            break;
+            //        case 300:
+            //            if (message == "0")
+            //            {
+            //                JobStartOrEnd("E", task.SourceAddress, task.TargetAddress, "O", task.PalletCode);
+            //            }
+            //            _taskService.CompleteRelocationboundTask(task);
+            //            break;
+            //        case 400:
+            //            if (message == "0")
+            //            {
+            //                JobStartOrEnd("E", task.Remark, task.HostName, "O", task.PalletCode);
+            //            }
+            //            break;
+            //        default:
+            //            break;
+            //    }
+            //}
+            #endregion
         }
         /// <summary>
         /// HOST涓嬪彂鍑哄簱浠诲姟  宸ュ簭103
@@ -742,21 +795,42 @@
                 {
                     //OK
                     case "0":
-                        var task = InsertWMSTask(parseMessage);
-                        BaseDal.AddData(task);
-                        InsertAGVTask(task);
-                        Thread.Sleep(500);
-                        //915
-                        JobReady("0");
-                        Thread.Sleep(500);
-                        //104
-                        DeviceReceiveJobResponse("0");
+                        var location = SqlSugarHelper.DbWMS.Queryable<DtLocationInfo>().Where(x => x.LocationCode == parseMessage.body.FromLocation).First();
+                        if (location == null)
+                        {
+                            return;
+                        }
+                        if (location.LocationStatus == (int)LocationEnum.InStock)
+                        {
+                            Dt_Task task = InsertWMSTask(parseMessage);
+                            //BaseDal.AddData(task);
+                            location.LocationStatus = 1;
+                            SqlSugarHelper.DbWMS.Insertable(task).ExecuteCommand();
+                            SqlSugarHelper.DbWMS.Updateable(location).ExecuteCommand();
+                            InsertAGVTask(task);
+                            //Thread.Sleep(500);
+                            //915
+                            JobReady("0");
+                            Thread.Sleep(500);
+                            //104
+                            DeviceReceiveJobResponse("0");
+                        }
+                        else
+                        {
+                            ErrorReport(EmptyOutBoundconst, "A", "00");
+                            Thread.Sleep(500);
+                            EmptyOutBound(parseMessage.body.FromLocation, parseMessage.body.ToLocation, parseMessage.body.TrayIdList.Substring(0, 10));
+                            return;
+                        }
+
                         break;
                     default:
                         break;
                 }
+                LogFactory.GetLog("Host103").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(parseMessage)}{Environment.NewLine}", "");
+
             }
-            catch (Exception)
+            catch (Exception ex)
             {
                 DeviceReceiveJobResponse("1");
             }
@@ -767,58 +841,72 @@
         /// HOST璁惧鐘舵�佽幏鍙�  宸ュ簭935
         /// </summary>
         /// <param name="message"></param>
-        public void DeviceStationStatusInvite()
+        public void DeviceStationStatusInvite(string sSeqNo)
         {
             try
             {
                 //鍥炲936
-                List<Dt_StationManager> Instation = _stationManagerRepository.QueryData(x => x.stationType == 1).ToList();
-                List<Dt_StationManager> Outstation = _stationManagerRepository.QueryData(x => x.stationType == 2).ToList();
-                List<OutStationStatus> outStationStatus = new List<OutStationStatus>();
-                List<InStationStatus> inStationStatus = new List<InStationStatus>();
-                foreach (var item in Instation)
-                {
-                    inStationStatus.Add(new InStationStatus()
-                    {
-                        StationName = item.stationName,
-                        StationEnable = item.stationStatus,
-                        IsDistributionTask = item.stationHasTask,
-                        PallteCode = "0000000000",
-                    });
-                }
-                foreach (var item in Outstation)
-                {
-                    StationStatus station = GetStationStatus(item.stationName);
-                    var taskStation = BaseDal.QueryFirst(x => x.SourceAddress == item.stationName || x.TargetAddress == item.stationName);
-                    outStationStatus.Add(new OutStationStatus()
-                    {
-                        StationName = item.stationName,
-                        StationEnable = station.StationEnable == "1" ? "0" : "1",
-                        IsDistributionTask = taskStation == null ? "0" : "1",
-                        Spare1 = "00"
-                    });
-                    //outStationStatus.Add(new OutStationStatus()
-                    //{
-                    //    StationName = item.stationName,
-                    //    StationEnable = item.stationStatus,
-                    //    IsDistributionTask = item.stationHasTask,
-                    //    Spare1 = "00"
-                    //});
-                }
+
+                StationStatus stationIn = GetStationStatus("B002");
+                StationStatus stationOut = GetStationStatus("B001");
+                List<OutStationStatus> outStationStatus = GetOutStationStatus(stationOut);
+                List<InStationStatus> inStationStatus = GetInStationStatus(stationIn);
+
+                #region
+                //inStationStatus.Add(new InStationStatus()
+                //{
+                //    StationName = "02",
+                //    StationEnable = stationIn.WorkstationO == "1" ? "0" : "1",
+                //    IsDistributionTask = "0",
+                //    PallteCode = "0000000000",
+                //});
+                //inStationStatus.Add(new InStationStatus()
+                //{
+                //    StationName = "01",
+                //    StationEnable = stationIn.WorkstationT == "1" ? "0" : "1",
+                //    IsDistributionTask = "0",
+                //    PallteCode = "0000000000",
+                //});
+                //var taskOutStationO = BaseDal.QueryFirst(x => x.SourceAddress == "B001::1" || x.TargetAddress == "B001::1");
+                //var taskOutStationT = BaseDal.QueryFirst(x => x.SourceAddress == "B001::2" || x.TargetAddress == "B001::2");
+                //outStationStatus.Add(new OutStationStatus()
+                //{
+                //    StationName = "04",
+                //    StationEnable = stationOut.WorkstationO == "1" ? "0" : "1",
+                //    IsDistributionTask = taskOutStationO == null ? "0" : "1",
+                //    Spare1 = "00"
+                //});
+                //outStationStatus.Add(new OutStationStatus()
+                //{
+                //    StationName = "03",
+                //    StationEnable = stationOut.WorkstationT == "1" ? "0" : "1",
+                //    IsDistributionTask = taskOutStationT == null ? "0" : "1",
+                //    Spare1 = "00"
+                //});
+                #endregion
                 AGVStatusRespone status = GetAGVStatus();
                 HOSTAGVStatus AgvStatus = new HOSTAGVStatus()
                 {
                     RuntimeStatus = CapitalizeFirstLetter(status.RuntimeStatus),
                     AutoStatus = status.AutoStatus == "MaintenanceMode" ? "1" : "0",
-                    Ready = status.AutoStatus == "MaintenanceMode" ? "0" : "1",
+                    //Ready = status.AutoStatus == "MaintenanceMode" ? "0" : "1",
                 };
-                DeviceStationStatusReport(AgvStatus, outStationStatus, inStationStatus);
+                if (status.RuntimeStatus == "Idle" && status.AutoStatus == "ControlMode")
+                {
+                    AgvStatus.Ready = "1";
+                }
+                else
+                {
+                    AgvStatus.Ready = "0";
+                }
+                DeviceStationStatusReport(AgvStatus, outStationStatus, inStationStatus, sSeqNo);
             }
             catch (Exception)
             {
                 DeviceReceiveJobResponse("1");
             }
 
+            LogFactory.GetLog("Host935").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(sSeqNo)}{Environment.NewLine}", "");
         }
 
         /// <summary>
@@ -830,12 +918,55 @@
             try
             {
                 var parseMessage = GetParse(message);
+                var lcationEnd = parseMessage.body.ToLocation;
                 switch (parseMessage.body.ret)
                 {
                     //OK
                     case "0":
-                        UpdateTaskLocation(parseMessage);
-                        break;
+                        var location = SqlSugarHelper.DbWMS.Queryable<DtLocationInfo>().Where(x => x.LocationCode == parseMessage.body.ToLocation).First();
+                        if (location == null)
+                        {
+                            ErrorReport("2102", "A", "00");
+                            Thread.Sleep(500);
+                            RecreateGetLocation(parseMessage.body.FromLocation, parseMessage.body.ToLocation, parseMessage.body.JobType, parseMessage.body.TrayIdList.Substring(0, 10));
+                            return;
+                        }
+                        if (location.LocationStatus == (int)LocationEnum.Free)
+                        {
+                            var task = SqlSugarHelper.DbWMS.Queryable<Dt_Task>().Where(x => x.PalletCode == parseMessage.body.TrayIdList.Substring(0, 10)).First();
+                            if (task == null)
+                            {
+                                location.LocationStatus = (int)LocationEnum.Lock;
+                                var tasknew = InsertWMSTask(parseMessage);
+                                InsertAGVTask(tasknew);
+                                BaseDal.AddData(tasknew);
+                                SqlSugarHelper.DbWMS.Updateable(location);
+                                Thread.Sleep(500);
+                                //915
+                                JobReady("0");
+                            }
+                            else
+                            {
+                                var Agvtask = SqlSugarHelper.DbAGV.Queryable<task_call>().Where(x => x.d_involed5 == task.TaskNum.ToString()).First();
+                                location.LocationStatus = (int)LocationEnum.Lock;
+                                task.TargetAddress = lcationEnd;
+                                Agvtask.d_involed2 = lcationEnd;
+                                SqlSugarHelper.DbWMS.Updateable(task);
+                                SqlSugarHelper.DbWMS.Updateable(location);
+                                SqlSugarHelper.DbAGV.Updateable(Agvtask);
+                                Thread.Sleep(500);
+                                //915
+                                JobReady("0");
+                            }
+                            return;
+                        }
+                        else
+                        {
+                            ErrorReport(Restocking, "A", "00");
+                            Thread.Sleep(500);
+                            RecreateGetLocation(parseMessage.body.FromLocation, parseMessage.body.ToLocation, parseMessage.body.JobType, parseMessage.body.TrayIdList.Substring(0, 10));
+                            return;
+                        }
                     //NG
                     case "1":
                         break;
@@ -847,12 +978,13 @@
                     default:
                         break;
                 }
+
+                LogFactory.GetLog("Host106閲嶆柊鍒嗛厤搴撲綅").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(parseMessage)}{Environment.NewLine}", "");
             }
             catch (Exception)
             {
                 DeviceReceiveJobResponse("1");
             }
-
         }
 
         /// <summary>
@@ -864,10 +996,10 @@
             if (message != null && message == "0")
             {
                 DeviceStateReport("I");
-                Thread.Sleep(500);
+                Thread.Sleep(2000);
                 JobReady("1");
-
             }
+            LogFactory.GetLog("Host108绌哄嚭搴撳搷搴�").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(message)}{Environment.NewLine}", "");
         }
 
         /// <summary>
@@ -875,14 +1007,27 @@
         /// </summary>
         public void DeviceStatusReportRequest()
         {
+            AGVStatusRespone status = GetAGVStatus();
+
             HOSTAGVStatus AgvStatus = new HOSTAGVStatus()
             {
-                RuntimeStatus = "R",
-                AutoStatus = "1",
-                Ready = "1"
+                RuntimeStatus = CapitalizeFirstLetter(status.RuntimeStatus),
+                AutoStatus = status.AutoStatus == "MaintenanceMode" ? "1" : "0",
+
             };
+            if (status.RuntimeStatus == "Idle" && status.AutoStatus == "ControlMode")
+            {
+                AgvStatus.Ready = "1";
+            }
+            else
+            {
+                AgvStatus.Ready = "0";
+            }
             string axis = "000000";
+
             DeviceStatusReportResponse(AgvStatus, axis, axis);
+
+            LogFactory.GetLog("Host蹇冭烦").InfoFormat(true, $"璇锋眰鍙傛暟锛歿JsonConvert.SerializeObject(AgvStatus)}{Environment.NewLine}{JsonConvert.SerializeObject(status)}{Environment.NewLine}", "");
         }
         #endregion
 
@@ -899,7 +1044,6 @@
             {
                 byte[] byt = Encoding.UTF8.GetBytes(Message);  // 浣跨敤 UTF-8 閬垮厤缂栫爜闂
 
-                LogFactory.GetLog("璇锋眰鎵樼洏浠诲姟").Error(true, BitConverter.ToString(byt));
                 string checksum = GetCheckSum(byt);
 
                 string str = Message + checksum;
@@ -921,6 +1065,8 @@
                 // 澶嶅埗鍘熷鏁扮粍鐨勬墍鏈夋暟鎹埌鏂版暟缁勭殑涓棿閮ㄥ垎
                 Array.Copy(buffer, 0, newArray, 1, buffer.Length);
 
+                //var parseMessage = GetParse(str);
+                LogFactory.GetLog("Socket鍙戦�佹姤鏂�").Info(true, str);
                 return newArray;
             }
             catch (Exception ex)
@@ -928,17 +1074,13 @@
                 throw new Exception(ex.Message);
             }
         }
-        //public bool IsOnline()
-        //{
-
-        //}
         public string GetListStringOutStation(List<OutStationStatus> outStationStatus)
         {
             return string.Join("", outStationStatus.Select(status => $"{status.StationName}{status.StationEnable}{status.IsDistributionTask}{status.Spare1}"));
         }
         public string GetListStringInStation(List<InStationStatus> inStationStatus)
         {
-            return string.Join("", inStationStatus.Select(status => $"{status.StationName}{status.StationEnable}{status.IsDistributionTask}{status.Spare1}"));
+            return string.Join("", inStationStatus.Select(status => $"{status.StationName}{status.StationEnable}{status.IsDistributionTask}{status.IsHasPallte}{status.Spare1}{status.StationPallteCount}{status.PallteCode}{status.Spare2}"));
         }
         /// <summary>
         /// 灏嗗璞″�煎嚟鎷兼帴
@@ -992,6 +1134,49 @@
             }
         }
 
+        public List<OutStationStatus> GetOutStationStatus(StationStatus stationOut)
+        {
+            List<OutStationStatus> outStationStatus = new List<OutStationStatus>();
+            var taskOutStationO = BaseDal.QueryFirst(x => x.SourceAddress == "B001::1" || x.TargetAddress == "B001::1");
+            var taskOutStationT = BaseDal.QueryFirst(x => x.SourceAddress == "B001::2" || x.TargetAddress == "B001::2");
+            outStationStatus.Add(new OutStationStatus()
+            {
+                StationName = "04",
+                StationEnable = stationOut.WorkstationO == "1" ? "0" : "1",
+                IsDistributionTask = taskOutStationO == null ? "0" : "1",
+                Spare1 = "00"
+            });
+            outStationStatus.Add(new OutStationStatus()
+            {
+                StationName = "03",
+                StationEnable = stationOut.WorkstationT == "1" ? "0" : "1",
+                IsDistributionTask = taskOutStationT == null ? "0" : "1",
+                Spare1 = "00"
+            });
+            return outStationStatus;
+        }
+
+        public List<InStationStatus> GetInStationStatus(StationStatus stationIn)
+        {
+            List<InStationStatus> inStationStatus = new List<InStationStatus>();
+            var taskOutStationO = BaseDal.QueryFirst(x => x.SourceAddress == "B002::1" || x.TargetAddress == "B002::1");
+            var taskOutStationT = BaseDal.QueryFirst(x => x.SourceAddress == "B002::2" || x.TargetAddress == "B002::2");
+            inStationStatus.Add(new InStationStatus()
+            {
+                StationName = "02",
+                StationEnable = stationIn.WorkstationO == "1" ? "0" : "1",
+                IsDistributionTask = taskOutStationO == null ? "0" : "1",
+                PallteCode = "0000000000",
+            });
+            inStationStatus.Add(new InStationStatus()
+            {
+                StationName = "01",
+                StationEnable = stationIn.WorkstationT == "1" ? "0" : "1",
+                IsDistributionTask = taskOutStationT == null ? "0" : "1",
+                PallteCode = "0000000000",
+            });
+            return inStationStatus;
+        }
         public ParseMessage SubString(string Y)
         {
 
@@ -1050,60 +1235,74 @@
         #endregion
 
         #region 绉佹湁鏂规硶
-        private void UpdateTaskLocation(ParseMessage parseMessage)
-        {
-            var task = BaseDal.QueryFirst(x => x.SeqNo == Convert.ToInt32(parseMessage.nSeqNo) && x.PalletCode.Contains(parseMessage.body.TrayIdList));
-            if (task != null)
-            {
-                task.TargetAddress = parseMessage.body.ToLocation;
-                task_call agvtask = SqlSugarHelper.DbAGV.Queryable<task_call>().Where(it => it.d_involed5 == task.TaskNum).First();
-                BaseDal.Update(task);
-                SqlSugarHelper.DbAGV.Updateable(agvtask).ExecuteCommand();
-            }
-
-        }
 
         private Dt_Task InsertWMSTask(ParseMessage parseMessage)
         {
-            //var task = BaseDal.QueryFirst(x => x.PalletCode.Contains(parseMessage.body.TrayIdList));
             int taskType = 0;
             int taskState = 0;
+            Dt_Task task = new Dt_Task();
             if (parseMessage.body.JobType == "I")
             {
+                Dt_StationManager Instation = _stationManagerRepository.QueryFirst(x => x.HostName == parseMessage.body.FromLocation.Substring(4, 2));
+                task.SourceAddress = Instation.stationName;
+                task.TargetAddress = parseMessage.body.ToLocation;
+                task.CurrentAddress = Instation.stationName;
+                task.NextAddress = parseMessage.body.ToLocation;
                 taskType = (int)TaskInboundTypeEnum.Inbound;
                 taskState = (int)TaskInStatusEnum.InNew;
+                task.Remark = parseMessage.body.FromLocation;
+
             }
             else if (parseMessage.body.JobType == "O")
             {
+                task.SourceAddress = parseMessage.body.FromLocation;
+                Dt_StationManager Instation = _stationManagerRepository.QueryFirst(x => x.HostName == parseMessage.body.ToLocation.Substring(4, 2));
+                task.TargetAddress = Instation.stationName;
+                task.CurrentAddress = parseMessage.body.FromLocation;
+                task.NextAddress = Instation.stationName;
                 taskType = (int)TaskOutboundTypeEnum.Outbound;
                 taskState = (int)TaskOutStatusEnum.OutNew;
+                task.Remark = parseMessage.body.ToLocation;
             }
             else if (parseMessage.body.JobType == "S")
             {
+                Dt_StationManager stationone = _stationManagerRepository.QueryFirst(x => x.HostName == parseMessage.body.FromLocation.Substring(4, 2));
+                Dt_StationManager stationtwo = _stationManagerRepository.QueryFirst(x => x.HostName == parseMessage.body.ToLocation.Substring(4, 2));
                 taskType = (int)TaskStationTypeEnum.StationToStation;
                 taskState = (int)TaskOutStatusEnum.OutNew;
+                task.SourceAddress = stationone.stationName;
+                task.TargetAddress = stationtwo.stationName;
+                task.CurrentAddress = stationone.stationName;
+                task.NextAddress = stationtwo.stationName;
+                task.Remark = parseMessage.body.FromLocation;
+                task.HostName = parseMessage.body.ToLocation;
+                task.HostName = parseMessage.body.ToLocation;
             }
             else if (parseMessage.body.JobType == "R")
             {
                 taskType = (int)TaskRelocationTypeEnum.Relocation;
                 taskState = (int)TaskRelocationStatusEnum.RelocationNew;
+
+                task.SourceAddress = parseMessage.body.FromLocation;
+                task.TargetAddress = parseMessage.body.ToLocation;
+                task.CurrentAddress = parseMessage.body.FromLocation;
+                task.NextAddress = parseMessage.body.ToLocation;
             }
             else
             {
                 throw new Exception("鏈煡搴撲綅");
             }
-            return new Dt_Task()
-            {
-                TaskNum = BaseDal.GetTaskNo().Result,
-                SourceAddress = parseMessage.body.FromLocation,
-                TargetAddress = parseMessage.body.ToLocation,
-                PalletCode = parseMessage.body.TrayIdList.Substring(0, 10),
-                TaskType = taskType,
-                TaskState = taskState,
-                Dispatchertime = DateTime.Now,
-                SeqNo = Convert.ToInt32(parseMessage.nSeqNo),
-                CommandID = Convert.ToInt32(parseMessage.bCmdID)
-            };
+
+
+            task.TaskNum = BaseDal.GetTaskNo().Result;
+            task.PalletCode = parseMessage.body.TrayIdList.Substring(0, 10);
+            task.TaskType = taskType;
+            task.TaskState = taskState;
+            task.Dispatchertime = DateTime.Now;
+            task.Grade = 1;
+            task.SeqNo = Convert.ToInt32(parseMessage.nSeqNo);
+            task.CommandID = Convert.ToInt32(parseMessage.bCmdID);
+            return task;
 
         }
         /// <summary>
@@ -1113,13 +1312,35 @@
         /// <returns></returns>
         private int InsertAGVTask(Dt_Task task)
         {
+            string SourceAddress = string.Empty;
+            string TargetAddress = string.Empty;
+            if (task.TaskType == (int)TaskInboundTypeEnum.Inbound)
+            {
+                SourceAddress = task.SourceAddress;
+                TargetAddress = InsertHyphenEveryTwoChars(task.TargetAddress);
+            }
+            else if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound)
+            {
+                SourceAddress = InsertHyphenEveryTwoChars(task.SourceAddress);
+                TargetAddress = task.TargetAddress;
+            }
+            else if (task.TaskType == (int)TaskRelocationTypeEnum.Relocation)
+            {
+                TargetAddress = InsertHyphenEveryTwoChars(task.TargetAddress);
+                SourceAddress = InsertHyphenEveryTwoChars(task.SourceAddress);
+            }
+            else if (task.TaskType == (int)TaskStationTypeEnum.StationToStation)
+            {
+                TargetAddress = task.TargetAddress;
+                SourceAddress = task.SourceAddress;
+            }
             task_call task_Call = new task_call()
             {
-                d_task_type = task.TaskType == (int)TaskTypeEnum.Inbound ? 1 : 2,
-                d_floor = 1,
-                d_involed1 = task.SourceAddress,
-                d_involed2 = task.TargetAddress,
-                d_involed5 = task.TaskNum,
+                d_task_type = task.TaskType == (int)TaskTypeEnum.Inbound ? "1" : "2",
+                d_floor = "1",
+                d_involed1 = SourceAddress,
+                d_involed2 = TargetAddress,
+                d_involed5 = task.TaskNum.ToString(),
             };
 
             return SqlSugarHelper.DbAGV.Insertable(task_Call).ExecuteCommand();
@@ -1135,20 +1356,20 @@
                 nSeqNo = x.Substring(15, 5),
                 body = new ReceiveBody
                 {
-                    ret = x.Substring(21, 1),
-                    JobOrderID = x.Substring(22, 16),
-                    priority = x.Substring(39, 1),
-                    FromLocation = x.Substring(40, 6),
-                    ToLocation = x.Substring(47, 6),
-                    JobType = x.Substring(54, 1),
-                    TrayCnt = x.Substring(55, 1),
-                    TrayIdList = x.Substring(56)
+                    ret = x.Substring(20, 1),
+                    JobOrderID = x.Substring(21, 16),
+                    priority = x.Substring(37, 1),
+                    FromLocation = x.Substring(38, 6),
+                    ToLocation = x.Substring(44, 6),
+                    JobType = x.Substring(50, 1),
+                    TrayCnt = x.Substring(51, 1),
+                    TrayIdList = x.Substring(52)
                 },
             };
         }
         public AGVStatusRespone GetAGVStatus()
         {
-            string urlnew = url + "/ilns/AGV/getAgvState";
+            string urlnew = url + "/ilns/AGV/getState";
             var result = HttpsClient.PostAsync(urlnew, JsonConvert.DeserializeObject<Dictionary<string, object>>(new { getStatus = "1" }.ToJson())).Result;
 
             return JsonConvert.DeserializeObject<AGVStatusRespone>(result.ToString());
@@ -1156,8 +1377,8 @@
 
         public StationStatus GetStationStatus(string stationName)
         {
-            string urlnew = url + "/ilns/strl/getStat";
-            var result = HttpsClient.PostAsync(urlnew, JsonConvert.DeserializeObject<Dictionary<string, object>>(new { strlName = stationName }.ToJson())).Result;
+            string urlnew = url + "/ilns/ctrl/getState";
+            var result = HttpsClient.PostAsync(urlnew, JsonConvert.DeserializeObject<Dictionary<string, object>>(new { ctrlName = "B001" }.ToJson())).Result;
             return JsonConvert.DeserializeObject<StationStatus>(result.ToString());
         }
         public string CapitalizeFirstLetter(string s)
@@ -1166,170 +1387,33 @@
             {
                 return "";
             }
-
             char firstChar = s[0];
             return char.ToUpper(firstChar).ToString();
         }
-
-        #region 澶栭儴鎺ュ彛鏂规硶
-
-        public WebResponseContent CompleteInboundTask(Dt_Task task)
+        public string InsertHyphenEveryTwoChars(string input)
         {
-            WebResponseContent content = new WebResponseContent();
-            try
+            if (string.IsNullOrEmpty(input))
             {
-                _unitOfWorkManage.BeginTran();
-                var locationInf = _locationRepository.QueryFirst(x => x.LocationCode == task.TargetAddress);
-                locationInf.LocationStatus = (int)LocationEnum.InStock;
-                var stock = new DtStockInfo()
+                return input;
+            }
+
+            StringBuilder result = new StringBuilder();
+
+            for (int i = 0; i < input.Length; i += 2)
+            {
+                // 娣诲姞涓や釜瀛楃
+                result.Append(input.Substring(i, 2));
+
+                // 濡傛灉涓嶆槸鏈�鍚庝袱涓瓧绗︼紝娣诲姞涓�涓繛瀛楃
+                if (i + 2 < input.Length)
                 {
-                    PalletCode = task.PalletCode,
-                    LocationCode = task.TargetAddress,
-                    CreateDate = DateTime.Now,
-                    Creater = "system",
-                    LocationId = locationInf.Id,
-                };
-                _stockInfoRepository.AddData(stock);
-                _locationRepository.UpdateData(locationInf);
-                TaskMoveHty(task);
-                _unitOfWorkManage.CommitTran();
-                return content.OK();
-            }
-            catch (Exception ex)
-            {
-                _unitOfWorkManage.RollbackTran();
-                return content.Error(ex.Message);
-            }
-        }
-
-        public WebResponseContent CompleteOutboundTask(Dt_Task task)
-        {
-            WebResponseContent content = new WebResponseContent();
-            try
-            {
-                _unitOfWorkManage.BeginTran();
-                var locationInf = _locationRepository.QueryFirst(x => x.LocationCode == task.TargetAddress);
-                locationInf.LocationStatus = (int)LocationEnum.Free;
-                var stock = _stockInfoRepository.QueryFirst(x => x.PalletCode == task.PalletCode);
-
-                DtStockInfo_Hty stockInfo_Hty = stock.Adapt<DtStockInfo_Hty>();
-                stockInfo_Hty.ModifyDate = DateTime.Now;
-
-                AddStockInfoHty(stockInfo_Hty);
-
-                _stockInfoRepository.DeleteData(stock);
-                _locationRepository.UpdateData(locationInf);
-
-                TaskMoveHty(task);
-
-                _unitOfWorkManage.CommitTran();
-                return content.OK();
-            }
-            catch (Exception ex)
-            {
-                _unitOfWorkManage.RollbackTran();
-                return content.Error(ex.Message);
-            }
-        }
-
-        public WebResponseContent CompleteRelocationboundTask(Dt_Task task)
-        {
-            WebResponseContent content = new WebResponseContent();
-            try
-            {
-                _unitOfWorkManage.BeginTran();
-                var locationInf = _locationRepository.QueryFirst(x => x.LocationCode == task.TargetAddress);
-                var location = _locationRepository.QueryFirst(x => x.LocationCode == task.SourceAddress);
-                locationInf.LocationStatus = (int)LocationEnum.InStock;
-                location.LocationStatus = (int)LocationEnum.Free;
-
-                var stock = _stockInfoRepository.QueryFirst(x => x.PalletCode == task.PalletCode);
-
-                stock.LocationCode = locationInf.LocationCode;
-                stock.LocationId = locationInf.Id;
-
-
-                _stockInfoRepository.UpdateData(stock);
-                _locationRepository.UpdateData(locationInf);
-                _locationRepository.UpdateData(location);
-                TaskMoveHty(task);
-                _unitOfWorkManage.CommitTran();
-                return content.OK();
-            }
-            catch (Exception ex)
-            {
-                _unitOfWorkManage.RollbackTran();
-                return content.Error(ex.Message);
-            }
-        }
-        public WebResponseContent TaskMoveHty(Dt_Task task)
-        {
-            WebResponseContent content = new WebResponseContent();
-            try
-            {
-                _unitOfWorkManage.BeginTran();
-                var taskHtyNG = CreateHistoricalTask(task);
-                var isTaskHtyAdd = _task_HtyRepository.AddData(taskHtyNG) > 0;
-                var isTaskDelete = Delete(task.TaskId);
-                var AgvTask = SqlSugarHelper.DbAGV.Queryable<task_call>().Where(x => x.d_involed5 == task.TaskNum).First();
-                if (AgvTask != null)
-                {
-                    SqlSugarHelper.DbAGV.Deleteable(AgvTask).ExecuteCommand();
+                    result.Append('-');
                 }
-                _unitOfWorkManage.CommitTran();
-                return content.OK();
             }
-            catch (Exception ex)
-            {
-                _unitOfWorkManage.RollbackTran();
-                return content.Error(ex.Message);
-            }
+
+            return result.ToString();
         }
 
-        #endregion 澶栭儴鎺ュ彛鏂规硶
-
-        #region private 鍐呴儴鏂规硶
-
-        /// <summary>
-        /// 鍒涘缓鍘嗗彶浠诲姟璁板綍
-        /// </summary>
-        /// <param name="task"></param>
-        /// <returns></returns>
-        public Dt_Task_Hty CreateHistoricalTask(Dt_Task task, bool isHand = false)
-        {
-            task.CurrentAddress = task.NextAddress;
-
-            // 鍒涘缓鍘嗗彶浠诲姟
-            var taskHty = _mapper.Map<Dt_Task_Hty>(task);
-            taskHty.FinishTime = DateTime.Now;
-            taskHty.TaskId = 0;
-            taskHty.OperateType = isHand ? (int)OperateTypeEnum.浜哄伐鍒犻櫎 : App.User.UserName != null ? (int)OperateTypeEnum.浜哄伐瀹屾垚 : (int)OperateTypeEnum.鑷姩瀹屾垚;
-            taskHty.SourceId = task.TaskId;
-            if (isHand)
-            {
-                taskHty.Creater = App.User.UserName != null ? App.User.UserName : "System";
-            }
-            return taskHty;
-        }
-        /// <summary>
-        /// 鍒犻櫎涓�涓换鍔�
-        /// </summary>
-        /// <param name="id">浠诲姟ID</param>
-        /// <returns>鏄惁鍒犻櫎鎴愬姛</returns>
-        public bool Delete(int id)
-        {
-            return BaseDal.Delete(id);
-        }
-        private void AddStockInfoHty(DtStockInfo_Hty dtStock)
-        {
-            var isStockAdd = SqlSugarHelper.DbWMS.InsertNav(dtStock).IncludesAllFirstLayer().ExecuteCommand();
-            if (!isStockAdd)
-            {
-                throw new Exception("搴撳瓨鍘嗗彶淇℃伅娣诲姞澶辫触");
-            }
-        }
-
-        #endregion private 鍐呴儴鏂规硶
         #endregion
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3