From b45155e1a5d76ca95d138025ab458fe2f3689748 Mon Sep 17 00:00:00 2001
From: xiazhengtongxue <133085197+xiazhengtongxue@users.noreply.github.com>
Date: 星期三, 28 一月 2026 11:19:54 +0800
Subject: [PATCH] 1

---
 项目代码/WCSServices/WIDESEAWCS_TaskInfoService/WriteLog.cs                   |  182 +++++++++++++++++++++++++++++++++++++++++++++
 项目代码/WCSServices/WIDESEAWCS_TaskInfoService/InvokeAGVService.cs           |    2 
 项目代码/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs                |   10 +
 项目代码/WCSServices/WIDESEAWCS_Server/Controllers/Task/TaskController.cs     |    7 +
 项目代码/WCSServices/WIDESEAWCS_Tasks/二期线体/ConveyorLineJob2.cs                |   17 +++-
 项目代码/WCSServices/WIDESEAWCS_Server/Log/容器入库创建任务/2026-01-27/任务信息260127.txt |    5 +
 6 files changed, 213 insertions(+), 10 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Server/Controllers/Task/TaskController.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Server/Controllers/Task/TaskController.cs"
index ed12e6c..bc2a84c 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Server/Controllers/Task/TaskController.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Server/Controllers/Task/TaskController.cs"
@@ -13,6 +13,7 @@
 using WIDESEAWCS_ITaskInfoService;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob;
+using WIDESEAWCS_TaskInfoService;
 using WIDESEAWCS_Tasks;
 using WIDESEAWCS_Tasks.DBNames;
 
@@ -91,14 +92,18 @@
                     }
                     else
                     {
+                        Thread.Sleep(500);
                         CommonConveyorLine commonConveyorLine = (CommonConveyorLine)device;
                         string PickBarCode = commonConveyorLine.GetValue<ConveyorLineDBName, string>(ConveyorLineDBName.R_PickBarCode, stationManger.StationCode).Trim();
+
                         if (containerFlowDTO.ContainerCode != PickBarCode) throw new Exception($"浼犲叆鏂欑鐮亄containerFlowDTO.ContainerCode}锛岃緭閫佹枡绠辩爜{PickBarCode}鏁版嵁閿欒");
-                        if (containerFlowDTO.Direction == "100")
+                        int W_PickToHode = commonConveyorLine.GetValue<ConveyorLineDBName, short>(ConveyorLineDBName.W_PickToHode, stationManger.StationDeviceCode);
+                        if (containerFlowDTO.Direction == "100" && W_PickToHode == 300)
                         {
                             WebResponseContent responseContent = Service.ContainerFlow(containerFlowDTO, stationManger.StationDeviceCode, stationManger.PickStationCode);
                             if (!responseContent.Status) throw new Exception(responseContent.Message);
                         }
+                        WriteLog.Write_Log($"瀹瑰櫒娴佸姩{stationManger.StationCode}", $"杈撻�佺嚎淇℃伅", "寮�濮嬪叆搴�", $"鐘舵�亄containerFlowDTO.Direction}锛屾枡绠辩爜{containerFlowDTO.ContainerCode}");
                         commonConveyorLine.SetValue(ConveyorLineDBName.W_PickToHode, (short)containerFlowDTO.Direction.ObjToInt(), stationManger.StationCode);
                     }
                     content.OK();
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Server/Log/\345\256\271\345\231\250\345\205\245\345\272\223\345\210\233\345\273\272\344\273\273\345\212\241/2026-01-27/\344\273\273\345\212\241\344\277\241\346\201\257260127.txt" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Server/Log/\345\256\271\345\231\250\345\205\245\345\272\223\345\210\233\345\273\272\344\273\273\345\212\241/2026-01-27/\344\273\273\345\212\241\344\277\241\346\201\257260127.txt"
new file mode 100644
index 0000000..bd99545
--- /dev/null
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Server/Log/\345\256\271\345\231\250\345\205\245\345\272\223\345\210\233\345\273\272\344\273\273\345\212\241/2026-01-27/\344\273\273\345\212\241\344\277\241\346\201\257260127.txt"
@@ -0,0 +1,5 @@
+2026/1/27 11:36:07.534
+寮�濮嬪叆搴�
+"鎵樼洏鍙穝tring"
+-------------------------------
+
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/InvokeAGVService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/InvokeAGVService.cs"
index a7f89a8..d3f1524 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/InvokeAGVService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/InvokeAGVService.cs"
@@ -113,7 +113,7 @@
         /// <summary>
         /// AGV鐘舵�佹煡璇㈣皟鐢ㄥ強WMS鏁呴殰涓婃姤
         /// </summary>
-        public void AgvSearchStatus() // 1鍘熸潵鍜�2鏇存柊浠诲姟
+        public void AgvSearchStatus()
         {
             try
             {
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs"
index 062769d..abcbd34 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/TaskService.cs"
@@ -200,6 +200,7 @@
             WebResponseContent content = new WebResponseContent();
             try
             {
+                WriteLog.Write_Log("瀹瑰櫒鍏ュ簱鍒涘缓浠诲姟", $"杈撻�佺嚎淇℃伅", "寮�濮嬪叆搴�", $"鎵樼洏鍙穥containerFlowDTO.ContainerCode}锛岃澶噞deviceCode}");
                 List<Dt_LocationInfo> locationInfos = _locationInfoRepository.QueryData();
                 Dt_LocationInfo? locationInfo = locationInfos.FirstOrDefault(x => x.PalletCode == containerFlowDTO.ContainerCode);
                 if (locationInfo != null) throw new Exception($"搴撲綅鏂欑鍙穥containerFlowDTO.ContainerCode}宸插瓨鍦�");
@@ -221,13 +222,14 @@
                     _taskExecuteDetailService.AddTaskExecuteDetail(new List<int>() { taskOld.TaskNum }, $"{oldSlotCode}鎹㈣嚦{containerFlowDTO.SlotCode}鍏ュ簱");
                     return content.OK();
                 }
-                else if(taskOld != null)
+                else if (taskOld != null)
                 {
-                    throw new Exception($"鏂欑鍙穥containerFlowDTO.ContainerCode}" + (taskOld.TaskType == TaskTypeEnum.Inbound.ObjToInt() ? "鍏ュ簱AGV鎵ц涓�": "鍑哄簱AGV鎵ц涓�"));
+                    throw new Exception($"鏂欑鍙穥containerFlowDTO.ContainerCode}" + (taskOld.TaskType == TaskTypeEnum.Inbound.ObjToInt() ? "鍏ュ簱AGV鎵ц涓�" : "鍑哄簱AGV鎵ц涓�"));
                 }
                 Dt_LocationInfo? noInLocation = locationInfos.FirstOrDefault(x => x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && x.EnableStatus == EnableStatusEnum.Normal.ObjToInt());
                 if (noInLocation == null) throw new Exception($"鍙敤璐т綅涓嶈冻!");
                 Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt() && x.StationDeviceCode == deviceCode);
+                WriteLog.Write_Log("瀹瑰櫒鍏ュ簱鍒涘缓浠诲姟", $"绔欏彴淇℃伅", "鏌ヨ绔欏彴", $"绔欏彴鍙穥stationManger.StationCode}锛岃澶噞stationManger.StationDeviceCode}");
                 //鍒涘缓浠诲姟
                 Dt_Task task = new Dt_Task();
                 task.PalletCode = containerFlowDTO.ContainerCode;
@@ -242,7 +244,8 @@
                 task.TaskState = TaskStatusEnum.CL_Executing.ObjToInt();
                 
                 //娣诲姞浠诲姟
-                BaseDal.AddData(task);
+                int taskId = BaseDal.AddData(task);
+                WriteLog.Write_Log("瀹瑰櫒鍏ュ簱鍒涘缓浠诲姟", $"浠诲姟淇℃伅", "鍒涘缓鍏ュ簱", $"浠诲姟鍙凤細{taskId},鎵樼洏缂栧彿锛歿task.PalletCode}");
                 if (type > 0)
                 {
                     _taskExecuteDetailService.AddTaskExecuteDetail(new List<int>() { task.TaskNum }, "鎵嬪姩鎸夐挳鍏ュ簱");
@@ -255,6 +258,7 @@
             }
             catch (Exception ex)
             {
+                WriteLog.Write_Log("瀹瑰櫒鍏ュ簱鍒涘缓浠诲姟", $"浠诲姟", "鍒涘缓鍏ュ簱", $"澶辫触锛歿ex.Message}");
                 content.Error($"閿欒淇℃伅:{ex.Message}");
             }
             return content;
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/WriteLog.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/WriteLog.cs"
new file mode 100644
index 0000000..da33d77
--- /dev/null
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_TaskInfoService/WriteLog.cs"
@@ -0,0 +1,182 @@
+锘縰sing Newtonsoft.Json;
+
+namespace WIDESEAWCS_TaskInfoService
+{
+    public class WriteLog
+    {
+        private int fileSize;
+        private string logFileName;
+        public static WriteLog log;
+        static string EquipName;
+        public static WriteLog GetLog(string equipName)
+        {
+            EquipName = equipName;
+            //if (log == null)
+            log = new WriteLog(equipName);
+            log.FileLogPath = AppContext.BaseDirectory + "\\log\\" + DateTime.Now.ToString("yyyyMMdd") /*+ "\\" + EquipName + "_" + DateTime.Now.ToString("yyyyMMdd")*/ + "\\";
+            return log;
+        }
+
+        public static WriteLog Info(string equipName)
+        {
+            EquipName = equipName;
+            //if (log == null)
+            log = new WriteLog("Info" + equipName);
+            log.FileLogPath = AppContext.BaseDirectory + "\\log\\Info\\" + DateTime.Now.ToString("yyyyMMdd") /*+ "\\" + EquipName + "_" + DateTime.Now.ToString("yyyyMMdd")*/ + "\\";
+            return log;
+        }
+
+        public static WriteLog Error(string equipName)
+        {
+            EquipName = equipName;
+            //if (log == null)
+            log = new WriteLog("Error" + equipName);
+            log.FileLogPath = AppContext.BaseDirectory + "\\log\\Error\\" + DateTime.Now.ToString("yyyyMMdd") /*+ "\\" + EquipName + "_" + DateTime.Now.ToString("yyyyMMdd")*/ + "\\";
+            return log;
+        }
+
+        private WriteLog(string equipName)
+        {
+            //鍒濆鍖栧ぇ浜�399M鏃ュ織鏂囦欢灏嗚嚜鍔ㄥ垹闄�;
+
+            this.fileSize = 2048 * 1024 * 200;//50M   2048 * 1024 * 200= 419430000瀛楄妭(b)=399.9996185鍏嗗瓧鑺�(mb)
+
+            //榛樿璺緞
+
+            //this.FileLogPath = AppContext.BaseDirectory + "\\log\\" + EquipName + "\\";
+            EquipName = equipName;
+            if (!string.IsNullOrEmpty(equipName))
+                this.logFileName = equipName + "_log" + DateTime.Now.ToString("yyyyMMdd") + ".log";
+            else
+                this.logFileName = "log" + DateTime.Now.ToString("yyyyMMdd") + ".log";
+            //this.logFileName = EquipName + "_log" + DateTime.Now.ToString("yyyyMMdd") + ".log";
+        }
+
+        public int FileSize
+        {
+            set
+            {
+                fileSize = value;
+            }
+            get
+            {
+                return fileSize;
+            }
+        }
+
+        public string FileLogPath { set; get; } //= AppContext.BaseDirectory + "\\log\\" + EquipName + "\\";
+
+        public string LogFileName
+        {
+            set
+            {
+                this.logFileName = value;
+            }
+            get
+            {
+                return this.logFileName;
+            }
+        }
+
+        object flag = new object();
+
+        public void Write(string Message, string equipName)
+        {
+            lock (flag)
+            {
+                if (!string.IsNullOrEmpty(equipName))
+                    this.logFileName = equipName + "_log" + DateTime.Now.ToString("yyyyMMdd") + ".log";
+                else
+                    this.logFileName = "log" + DateTime.Now.ToString("yyyyMMdd") + ".log";
+                this.Write(this.logFileName, Message, equipName);
+            }
+        }
+
+        public void Write(string LogFileName, string Message, string equipName)
+        {
+
+            //DirectoryInfo path=new DirectoryInfo(LogFileName);
+            //濡傛灉鏃ュ織鏂囦欢鐩綍涓嶅瓨鍦�,鍒欏垱寤�
+            if (!Directory.Exists(this.FileLogPath))
+            {
+                Directory.CreateDirectory(this.FileLogPath);
+            }
+
+            FileInfo finfo = new FileInfo(this.FileLogPath + LogFileName);
+            if (finfo.Exists && finfo.Length > fileSize)
+            {
+                finfo.Delete();
+            }
+            try
+            {
+                FileStream fs = new FileStream(this.FileLogPath + LogFileName, FileMode.Append);
+                StreamWriter strwriter = new StreamWriter(fs);
+                try
+                {
+
+                    DateTime d = DateTime.Now;
+                    strwriter.WriteLine("鏃堕棿:" + d.ToString());
+                    strwriter.WriteLine(Message);
+                    //strwriter.WriteLine();
+                    strwriter.Flush();
+                }
+                catch (Exception ee)
+                {
+                    //Console.WriteLine("鏃ュ織鏂囦欢鍐欏叆澶辫触淇℃伅:" + ee.ToString());
+                }
+                finally
+                {
+                    strwriter.Close();
+                    strwriter = null;
+                    fs.Close();
+                    fs = null;
+                }
+            }
+            catch (Exception ee)
+            {
+                //Console.WriteLine("鏃ュ織鏂囦欢娌℃湁鎵撳紑,璇︾粏淇℃伅濡備笅:");
+            }
+        }
+        /// <summary>
+        /// 鍐欏叆鏃ュ織(涓嶈澶氱嚎绋嬫搷浣滃悓涓�鏂囦欢锛屼竴涓澶囦竴涓枃浠跺す)
+        /// </summary>
+        /// <param name="groupName">鏃ュ織缁�</param>
+        /// <param name="logName">鏃ュ織鍚嶇О</param>
+        /// <param name="content">鍐呭</param>
+        /// <param name="data">鏁版嵁</param>
+        public static void Write_Log(string groupName, string logName, string content, object data = null)
+        {
+            DateTime nowTime = DateTime.Now;
+            string basePath = System.Environment.CurrentDirectory + "/Log/" + $"/{groupName}/{nowTime.ToString("yyyy-MM-dd")}";
+            //濡傛灉鏃ュ織鏂囦欢鐩綍涓嶅瓨鍦�,鍒欏垱寤�
+            if (!Directory.Exists(basePath))
+            {
+                Directory.CreateDirectory(basePath);
+            }
+            try
+            {
+                FileStream fs = new FileStream(basePath + "/" + logName + $"{nowTime.ToString("yyMMdd")}.txt", FileMode.Append);
+                StreamWriter strwriter = new StreamWriter(fs);
+                try
+                {
+                    strwriter.WriteLine(nowTime.ToString() + "." + nowTime.Millisecond);
+                    strwriter.WriteLine(content);
+                    if (data != null)
+                    {
+                        strwriter.WriteLine(JsonConvert.SerializeObject(data));
+                    }
+                    strwriter.WriteLine("-------------------------------");
+                    strwriter.WriteLine();
+                    strwriter.Flush();
+                }
+                catch { }
+                finally
+                {
+                    strwriter.Close();
+                    fs.Close();
+                }
+            }
+            catch { }
+        }
+    }
+}
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Tasks/\344\272\214\346\234\237\347\272\277\344\275\223/ConveyorLineJob2.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Tasks/\344\272\214\346\234\237\347\272\277\344\275\223/ConveyorLineJob2.cs"
index 334d6b7..cf0fd2b 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Tasks/\344\272\214\346\234\237\347\272\277\344\275\223/ConveyorLineJob2.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_Tasks/\344\272\214\346\234\237\347\272\277\344\275\223/ConveyorLineJob2.cs"
@@ -18,6 +18,7 @@
 using WIDESEAWCS_QuartzJob;
 using WIDESEAWCS_QuartzJob.DTO;
 using WIDESEAWCS_QuartzJob.Service;
+using WIDESEAWCS_TaskInfoService;
 
 namespace WIDESEAWCS_Tasks
 {
@@ -72,6 +73,7 @@
                                         WriteError(conveyorLine.DeviceCode, $"{station.PickStationCode}鎷i�夌敵璇蜂笂鎶MS閿欒{PickBarCode}锛屼俊鎭瘂content.Message}");
                                     }
                                     //鍐欏叆鎷i�夌‘璁�
+                                    WriteLog.Write_Log("浜屾湡杈撻�佺嚎鎷i�夊啓鍏�", $"{station.StationCode}", "浜屾湡杈撻�佺嚎鎷i�夊啓鍏�", $"W_PickToHode鍐欏叆PLC淇″彿:300");
                                     conveyorLine.SetValue(ConveyorLineDBName.W_PickToHode, (short)300, station.StationCode);
                                 }
                                 else
@@ -81,9 +83,11 @@
                             }
                             //鎸夐挳鐢宠
                             bool DownRequest = conveyorLine.GetValue<ConveyorLineDBName, bool>(ConveyorLineDBName.R_DownRequest, station.StationCode);
-                            if (DownRequest)
+                            int W_PickToHode = conveyorLine.GetValue<ConveyorLineDBName, short>(ConveyorLineDBName.W_PickToHode, station.StationCode);
+                            if (DownRequest && W_PickToHode == 300)
                             {
                                 string PickBarCode = conveyorLine.GetValue<ConveyorLineDBName, string>(ConveyorLineDBName.R_PickBarCode, station.StationCode).Trim();
+                                WriteInfo(conveyorLine.DeviceCode, $"鐢宠鍏ュ簱{PickBarCode}锛岀珯鍙帮細{station.StationCode}");
                                 //涓婃姤WMS鏂欑鍒拌揪
                                 if (PickBarCode.IsNotEmptyOrNull())
                                 {
@@ -93,9 +97,12 @@
                                         ContainerCode = PickBarCode,
                                         Direction="100"
                                     };
+                                    WriteInfo(conveyorLine.DeviceCode, $"浠诲姟鏋勫缓瀹屾垚SlotCode: {containerFlowDTO.SlotCode}, ContainerCode: {containerFlowDTO.ContainerCode}");
                                     WebResponseContent responseContent = _taskService.ContainerFlow(containerFlowDTO, station.StationDeviceCode, station.PickStationCode,1);
                                     if (responseContent.Status)
                                     {
+                                        WriteLog.Write_Log("浜屾湡杈撻�佺嚎鎷i�夊啓鍏�", $"{station.StationCode}", "浜屾湡杈撻�佺嚎鎷i�夊啓鍏�", $"W_PickToHode鍐欏叆PLC淇″彿锛歿containerFlowDTO.Direction}");
+                                        WriteInfo(conveyorLine.DeviceCode, $"鍐欏叆PLC淇″彿W_PickToHode: {containerFlowDTO.Direction}锛岀珯鍙帮細{station.StationCode}");
                                         conveyorLine.SetValue(ConveyorLineDBName.W_PickToHode, (short)containerFlowDTO.Direction.ObjToInt(), station.StationCode);
                                     }
                                     else
@@ -107,7 +114,6 @@
                                 {
                                     WriteError(conveyorLine.DeviceCode, $"{station.PickStationCode}鎸夐挳鐢宠涓簕DownRequest}鏉$爜涓虹┖鍊�");
                                 }
-                                
                             }
 
                         }
@@ -120,6 +126,8 @@
                             if (InRequest && !InResponse && InWeight>0)
                             {
                                 string InBarCode = conveyorLine.GetValue<ConveyorLineDBName, string>(ConveyorLineDBName.R_InBarCode, station.StationCode).Trim();
+                                WriteInfo(conveyorLine.DeviceCode, $"绔欏彴{station.StationCode}鏂欑{InBarCode}鐢宠鍏ュ簱鎴愬姛");
+                                WriteLog.Write_Log("浜屾湡杈撻�佺嚎鎷i�夊啓鍏�", $"{station.StationCode}", $"绔欏彴{station.StationCode}", $"鏂欑{InBarCode}鐢宠鍏ュ簱鎴愬姛");
                                 //鏂欑鍒拌揪
                                 if (InBarCode.IsNotEmptyOrNull())
                                 {
@@ -127,9 +135,8 @@
                                     WebResponseContent content =_taskService.RequestInTask(station.StationCode,InBarCode);
                                     if (content.Status)
                                     {
-                                        //鍐欏叆鍏ュ簱纭
-                                        conveyorLine.SetValue(ConveyorLineDBName.W_InResponse, true, station.StationCode);
-                                        WriteInfo(conveyorLine.DeviceCode, $"绔欏彴{station.StationCode}鏂欑{InBarCode}鐢宠鍏ュ簱鎴愬姛");
+                                        WriteLog.Write_Log("浜屾湡杈撻�佺嚎鎷i�夊啓鍏�", $"{station.StationCode}", $"鍐欏叆纭畾{ConveyorLineDBName.W_InResponse}", $"鏂欑{InBarCode}");
+                                        conveyorLine.SetValue(ConveyorLineDBName.W_InResponse, true, station.StationCode);   
                                     }
                                     else
                                     {

--
Gitblit v1.9.3