using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataLinkMesWork;


namespace WebApi.Helpers
{
    public class LogHelper
    {
        /// <summary>
        /// UUID生成
        /// </summary>
        /// <returns></returns>
        public static string UuidUtil()
        {
            string result = Guid.NewGuid().ToString();
            return result;
        }

        public static void ShowMsg(string msg)
        {
            MyLog4Net.MyLogHelper.Error("WebApi", msg);
        }

        public static int SaveWebApiReqLogo(string url, string JSON)
        {
            int AID = -1;
            try
            {
                //存储日志
                var CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");

                string procedureName = "接口_IOT接口交互日志_请求记录";
                SqlParameter[] thisParms = new SqlParameter[4];
                thisParms[0] = new System.Data.SqlClient.SqlParameter("@接口地址", url);
                thisParms[1] = new System.Data.SqlClient.SqlParameter("@接口类型", 2);
                thisParms[2] = new System.Data.SqlClient.SqlParameter("@请求内容", JSON);
                thisParms[3] = new System.Data.SqlClient.SqlParameter("@请求时间", CreateTime);
                SQLCommon.ExecuteStoredProcedure(procedureName, ApplicationConfig.ConnectionString_MES, out DataTable dt, out string errorMessage);
                // DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out DataTable dt);
                if (dt.Rows.Count > 0)
                {
                    AID = Convert.ToInt32(dt.Rows[0]["AID"]);
                }
            }
            catch (Exception ex)
            {

            }
            return AID;
        }

        public static void SaveWebApiResLogo(int AID, string JSON)
        {
            try
            {
                //存储日志
                var CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                string procedureName = "接口_IOT接口交互日志_响应记录";
                SqlParameter[] thisParms = new SqlParameter[3];
                thisParms[0] = new System.Data.SqlClient.SqlParameter("@AID", AID);
                thisParms[1] = new System.Data.SqlClient.SqlParameter("@响应时间", CreateTime);
                thisParms[2] = new System.Data.SqlClient.SqlParameter("@响应内容", JSON);
                DataAccess.ExecuteStoredProcedure(procedureName, ref thisParms, out DataTable dt);
            }
            catch (Exception ex)
            {
            }
        }
    }
}
