From 90325aa6dd4e2d357a1d24575bbd601dda4e167d Mon Sep 17 00:00:00 2001
From: 王 垚 <1402714037@qq.com>
Date: 星期五, 29 十月 2021 09:13:51 +0800
Subject: [PATCH] 日志文件 供应商和用户权限登录查询返回数据

---
 WebAPI/Code/LogService.cs               |   73 ++++++++++++++++++++++++++++++++++++
 WebAPI/Controllers/POOrderController.cs |   10 +++-
 WebAPI/WebAPI.csproj                    |    1 
 3 files changed, 81 insertions(+), 3 deletions(-)

diff --git a/WebAPI/Code/LogService.cs b/WebAPI/Code/LogService.cs
new file mode 100644
index 0000000..dae6308
--- /dev/null
+++ b/WebAPI/Code/LogService.cs
@@ -0,0 +1,73 @@
+锘縰sing Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WebAPI.Code
+{
+    public class LogService
+    {
+        private static readonly object lockObj = new object();
+
+        public static void WriteAsync(object obj, string filePath = "Vlog", bool isAppend = true)
+        {
+            Task.Run(() =>
+            {
+                Write(obj, filePath, isAppend);
+            });
+        }
+
+        public static void WriteAsync<T>(object obj, string filePath = "Vlog", bool isAppend = true)
+        {
+            Task.Run(() =>
+            {
+                Write(obj, $@"{filePath}\{typeof(T).Name}", isAppend);
+            }); 
+        }
+
+        #region 鏃ュ織
+        public static void Write(object obj, string filePath = "Vlog", bool isAppend = true)
+        {
+            try
+            {
+                lock (lockObj)
+                {
+                    filePath = $@"{filePath}\webapi{DateTime.Now.ToString("yyyyMMdd")}.txt";
+
+                    filePath = AppDomain.CurrentDomain.BaseDirectory + filePath;
+
+                    if (!System.IO.Directory.Exists(Path.GetDirectoryName(filePath)))
+                    {
+                        System.IO.Directory.CreateDirectory(Path.GetDirectoryName(filePath));
+                    }
+
+                    bool fileExists = System.IO.File.Exists(filePath);
+                    //涓嶅瓨鍦� 鍒欏垱寤鸿鏂囦欢
+                    if (!fileExists)
+                    {
+                        System.IO.File.Create(filePath).Close();
+                    }
+
+                    using (StreamWriter writer = new StreamWriter(filePath, isAppend))
+                    {
+                        //瀛樺湪鐨勬椂鍊欐墠鍐欎竴琛�
+                        if (fileExists && isAppend)
+                        {
+                            writer.WriteLine();
+                        }
+
+                        var content = obj is string ? obj : JsonConvert.SerializeObject(obj);
+                        writer.WriteLine($"{DateTime.Now} {content}");
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+            }
+        }
+        #endregion
+    }
+}
diff --git a/WebAPI/Controllers/POOrderController.cs b/WebAPI/Controllers/POOrderController.cs
index 08a189d..0fb66d7 100644
--- a/WebAPI/Controllers/POOrderController.cs
+++ b/WebAPI/Controllers/POOrderController.cs
@@ -42,12 +42,13 @@
                 //鍏朵粬杩囨护
                 if (msg.Trim() == "")
                 {
-                    msg = " Where hsupid in (select HItemID from h_v_IF_Supplier where hnumber=^^" + HSupNo.Trim() + "^^) " + sqlWhere;
+                    msg = " Where hsupid in (select HSupID from h_v_Gy_UserSupplierList where 鐢ㄦ埛 = ^^" + HSupNo.Trim() + "^^) " + sqlWhere;
                     // msg = " Where   hsupid in (select hsupid from Gy_UserSupplierRelation where HUserID=^^" + System.Web.HttpContext.Current.Session["HUserName"].ToString() + "^^)";
                 }
                 else
                 {
-                    msg = msg + " and   hsupid in (select HItemID from h_v_IF_Supplier where hnumber=^^" + HSupNo.Trim() + "^^) " + sqlWhere;
+                    msg += " and hsupid in (select HSupID from h_v_Gy_UserSupplierList where 鐢ㄦ埛 =^^" + HSupNo.Trim() + "^^) " + sqlWhere;
+                    //msg = msg + " and   hsupid in (select HItemID from h_v_IF_Supplier where hnumber=^^" + HSupNo.Trim() + "^^) " + sqlWhere;
                     // msg = msg + " Where   hsupid in (select hsupid from Gy_UserSupplierRelation where HUserID=^^" + System.Web.HttpContext.Current.Session["HUserName"].ToString() + "^^)";
                 }
                 //杞崲鐗规畩瀛楃
@@ -60,8 +61,11 @@
                     return objjson;
                 }
                 //鑾峰彇鎬昏鏁�
-                Int64 RowTotal = Common.GetRowTotal("H_v_SRM_POOrderBillList", VsWhere, ref DBUtility.ClsPub.sExeReturnInfo);
+                //Int64 RowTotal = Common.GetRowTotal("H_v_SRM_POOrderBillList", VsWhere, ref DBUtility.ClsPub.sExeReturnInfo);
                 //鑾峰彇杩斿洖鏁版嵁
+                string sql = "exec H_p_SRM_POOrderBillList '" + PcWhere + "'";
+                LogService.WriteAsync(sql);
+
                 ds = oCn.RunProcReturn("exec H_p_SRM_POOrderBillList '" + PcWhere + "'", "H_p_SRM_POOrderBillList");
                 if (ds == null || ds.Tables[0].Rows.Count == 0)
                 {
diff --git a/WebAPI/WebAPI.csproj b/WebAPI/WebAPI.csproj
index c1169c7..6c29760 100644
--- a/WebAPI/WebAPI.csproj
+++ b/WebAPI/WebAPI.csproj
@@ -161,6 +161,7 @@
     <Compile Include="App_Start\WebApiConfig.cs" />
     <Compile Include="BLL\WebServer.cs" />
     <Compile Include="Code\Common.cs" />
+    <Compile Include="Code\LogService.cs" />
     <Compile Include="Code\Test2.cs" />
     <Compile Include="Code\TestDAL.cs" />
     <Compile Include="Controllers\BarCodeController.cs" />

--
Gitblit v1.9.1