From 7ca9651f81d7b84f054194d3d46fdbd1d9c8b922 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期三, 09 七月 2025 22:55:27 +0800
Subject: [PATCH] 增加质检出入库逻辑

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_Core/LogHelper/LogLock.cs |   92 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 92 insertions(+), 0 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/LogHelper/LogLock.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/LogHelper/LogLock.cs"
new file mode 100644
index 0000000..50da663
--- /dev/null
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/LogHelper/LogLock.cs"
@@ -0,0 +1,92 @@
+锘�
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using WIDESEA_Core.Helper;
+
+namespace WIDESEA_Core.LogHelper
+{
+    public class LogLock
+    {
+        static ReaderWriterLockSlim LogWriteLock = new ReaderWriterLockSlim();
+        static int WritedCount = 0;
+        static int FailedCount = 0;
+        static string _contentRoot = string.Empty;
+
+        public LogLock(string contentPath)
+        {
+            _contentRoot = contentPath;
+        }
+
+        public static void OutLogAOP(string prefix, string[] dataParas, bool IsHeader = true)
+        {
+            OutSql2LogToFile(prefix, dataParas, IsHeader);
+        }
+
+        public static void OutSql2LogToFile(string prefix, string[] dataParas, bool IsHeader = true, bool isWrt = false)
+        {
+            try
+            {
+                //璁剧疆璇诲啓閿佷负鍐欏叆妯″紡鐙崰璧勬簮锛屽叾浠栧啓鍏ヨ姹傞渶瑕佺瓑寰呮湰娆″啓鍏ョ粨鏉熶箣鍚庢墠鑳界户缁啓鍏�
+                //娉ㄦ剰锛氶暱鏃堕棿鎸佹湁璇荤嚎绋嬮攣鎴栧啓绾跨▼閿佷細浣垮叾浠栫嚎绋嬪彂鐢熼ゥ楗� (starve)銆� 涓轰簡寰楀埌鏈�濂界殑鎬ц兘锛岄渶瑕佽�冭檻閲嶆柊鏋勯�犲簲鐢ㄧ▼搴忎互灏嗗啓璁块棶鐨勬寔缁椂闂村噺灏戝埌鏈�灏忋��
+                //      浠庢�ц兘鏂归潰鑰冭檻锛岃姹傝繘鍏ュ啓鍏ユā寮忓簲璇ョ揣璺熸枃浠舵搷浣滀箣鍓嶏紝鍦ㄦ澶勮繘鍏ュ啓鍏ユā寮忎粎鏄负浜嗛檷浣庝唬鐮佸鏉傚害
+                //      鍥犺繘鍏ヤ笌閫�鍑哄啓鍏ユā寮忓簲鍦ㄥ悓涓�涓猼ry finally璇彞鍧楀唴锛屾墍浠ュ湪璇锋眰杩涘叆鍐欏叆妯″紡涔嬪墠涓嶈兘瑙﹀彂寮傚父锛屽惁鍒欓噴鏀炬鏁板ぇ浜庤姹傛鏁板皢浼氳Е鍙戝紓甯�
+                LogWriteLock.EnterWriteLock();
+
+                var folderPath = Path.Combine(_contentRoot, "Log");
+                if (!Directory.Exists(folderPath))
+                {
+                    Directory.CreateDirectory(folderPath);
+                }
+                //string logFilePath = Path.Combine(path, $@"{filename}.log");
+                var logFilePath = FileHelper.GetAvailableFileWithPrefixOrderSize(folderPath, prefix);
+
+                var now = DateTime.Now;
+                string logContent = String.Join("\r\n", dataParas);
+                if (IsHeader)
+                {
+                    logContent = (
+                       "--------------------------------\r\n" +
+                       DateTime.Now + "|\r\n" +
+                       String.Join("\r\n", dataParas) + "\r\n"
+                       );
+                }
+                else
+                {
+                    logContent = (
+                       dataParas[1] + ",\r\n"
+                       );
+                }
+
+                //if (logContent.IsNotEmptyOrNull() && logContent.Length > 500)
+                //{
+                //    logContent = logContent.Substring(0, 500) + "\r\n";
+                //}
+                if (isWrt)
+                {
+                    System.IO.File.WriteAllText(logFilePath, logContent);
+                }
+                else
+                {
+                    System.IO.File.AppendAllText(logFilePath, logContent);
+                }
+                WritedCount++;
+            }
+            catch (Exception e)
+            {
+                //Console.Write(e.Message);
+                FailedCount++;
+            }
+            finally
+            {
+                //閫�鍑哄啓鍏ユā寮忥紝閲婃斁璧勬簮鍗犵敤
+                //娉ㄦ剰锛氫竴娆¤姹傚搴斾竴娆¢噴鏀�
+                //      鑻ラ噴鏀炬鏁板ぇ浜庤姹傛鏁板皢浼氳Е鍙戝紓甯竅鍐欏叆閿佸畾鏈粡淇濇寔鍗宠閲婃斁]
+                //      鑻ヨ姹傚鐞嗗畬鎴愬悗鏈噴鏀惧皢浼氳Е鍙戝紓甯竅姝ゆā寮忎笉涓嬪厑璁镐互閫掑綊鏂瑰紡鑾峰彇鍐欏叆閿佸畾]
+                LogWriteLock.ExitWriteLock();
+            }
+        }
+    }
+}

--
Gitblit v1.9.3