智云SRM-WEBAPI(目前客户通用API)
王 垚
2021-10-29 90325aa6dd4e2d357a1d24575bbd601dda4e167d
日志文件 供应商和用户权限登录查询返回数据
1个文件已添加
2个文件已修改
84 ■■■■■ 已修改文件
WebAPI/Code/LogService.cs 73 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
WebAPI/Controllers/POOrderController.cs 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
WebAPI/WebAPI.csproj 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
WebAPI/Code/LogService.cs
New file
@@ -0,0 +1,73 @@
using 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
    }
}
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)
                {
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" />