gwbvipvip 8 месяцев назад
Родитель
Сommit
f6faadb823
5 измененных файлов: 87 добавлений и 14 удалений
  1. +32
    -0
      BPA.KitChen.GroupMealOrder.Core/Entity/BPA_ThirdpartyRequestLog.cs
  2. +28
    -0
      BPA.KitChen.GroupMealOrder.SqlSugar/SqlSugarDb.cs
  3. +10
    -0
      BPA.KitChen.GroupMealOrder.SqlSugar/SqlsugarSetup.cs
  4. +16
    -14
      BPA.KitChen.GroupMealOrder/Handlers/RequestAuditFiltercs.cs
  5. +1
    -0
      BPA.KitChen.GroupMealOrder/appsettings.json

+ 32
- 0
BPA.KitChen.GroupMealOrder.Core/Entity/BPA_ThirdpartyRequestLog.cs Просмотреть файл

@@ -0,0 +1,32 @@
using BPA.KitChen.GroupMealOrder.Core.Entity.Base;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.KitChen.GroupMealOrder.Core.Entity
{

/// <summary>
/// 第三方日志
/// </summary>
[SugarTable("bpa_thirdpartyrequestlog")]
public class BPA_ThirdpartyRequestLog : IBaseEntity, IBaseGroupIdEntity
{
public string GroupId { get; set; }

public string RequestUrl { get; set; }

public string ReauestMethod { get; set; }

public string ResultParm { get; set; }

public string ReauestParm { get; set; }

public string IP { get; set; }

public DateTime CreateAt { get; set; } = DateTime.Now;
}
}

+ 28
- 0
BPA.KitChen.GroupMealOrder.SqlSugar/SqlSugarDb.cs Просмотреть файл

@@ -19,6 +19,7 @@ namespace BPA.KitChen.GroupMealOrder.SqlSugar
public class SqlSugarDb
{
public static SqlSugarScope Db { get; set; }
public static SqlSugarScope DbLog { get; set; }

public static SqlSugarScope SqlSugarScope(ConnectionConfig configConnection)
{
@@ -47,6 +48,33 @@ namespace BPA.KitChen.GroupMealOrder.SqlSugar
return Db;
}

public static SqlSugarScope SqlSugarScopeLog(ConnectionConfig configConnection)
{
//全局过滤

DbLog = new SqlSugarScope(configConnection, db =>
{
//全局过滤
TableFilterItem(db);
db.Aop.OnLogExecuting = (sql, pars) =>
{
Console.WriteLine(sql);

//sql 执行前
};
db.Aop.OnLogExecuted = (sql, pars) =>
{
//sql 执行后
};
db.Aop.OnError = ex =>
{
//sql 异常
};
});

return Db;
}

#region 全局过滤器及配置
/// <summary>
/// 全局过滤


+ 10
- 0
BPA.KitChen.GroupMealOrder.SqlSugar/SqlsugarSetup.cs Просмотреть файл

@@ -26,6 +26,16 @@ namespace BPA.KitChen.GroupMealOrder.SqlSugar
};
var sqlSugar = SqlSugarDb.SqlSugarScope(configConnection);
services.AddSingleton<ISqlSugarClient>(sqlSugar);//这边是SqlSugarScope用AddSingleton


//如果多个数数据库传 List<ConnectionConfig>
var sqlSugarLog = SqlSugarDb.SqlSugarScopeLog(new ConnectionConfig()
{
DbType = DbType.MySql,
ConnectionString = App.Configuration["DBConnectionLogStr"],
IsAutoCloseConnection = true
});
services.AddSingleton<ISqlSugarClient>(sqlSugarLog);//这边是SqlSugarScope用AddSingleton
}
}
}

+ 16
- 14
BPA.KitChen.GroupMealOrder/Handlers/RequestAuditFiltercs.cs Просмотреть файл

@@ -1,6 +1,8 @@
using BPA.KitChen.GroupMealOrder.Application.BaseDto;
using BPA.KitChen.GroupMealOrder.Application.Service.AExternalPlatform.Service.CheckService.Services;
using BPA.KitChen.GroupMealOrder.Core;
using BPA.KitChen.GroupMealOrder.Core.Entity;
using BPA.KitChen.GroupMealOrder.SqlSugar;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.Filters;
using Newtonsoft.Json;
@@ -84,25 +86,25 @@ namespace BPA.KitChen.GroupMealOrder.Handlers
{
try
{
////记录日志
//await SqlSugarDb.Db.Insertable(new BPA_ThirdpartyRequestLog()
//{
// Id = CurrentUser.MessageId,
// CreateBy = DateTime.Now.ToString(),
// GroupId = CurrentUser.GroupId,
// RequestUrl = requestUrl,
// ReauestMethod = httpRequest.Method,
// ReauestParm = JsonConvert.SerializeObject(parameters),
// ResultParm = !isRequestSucceed ? actionContext.Exception.ToString() : JsonConvert.SerializeObject(returnResult),
// IP = remoteIPv4
//}).ExecuteCommandAsync();
//记录日志
await SqlSugarDb.DbLog.Insertable(new BPA_ThirdpartyRequestLog()
{
Id = CurrentUser.MessageId,
CreateAt = DateTime.Now,
GroupId = CurrentUser.TenantId,
RequestUrl = requestUrl,
ReauestMethod = httpRequest.Method,
ReauestParm = JsonConvert.SerializeObject(parameters),
ResultParm = !isRequestSucceed ? actionContext.Exception.ToString() : JsonConvert.SerializeObject(returnResult),
IP = remoteIPv4
}).ExecuteCommandAsync();

////记录下发记录
//if (isRequestSucceed)
//{
// foreach (var parameter in parameters)
// {
// var isPush = DtoValidator.GetAttributePrice(parameter.Value, "isPush");
// var callbackUrl = DtoValidator.GetAttributePrice(parameter.Value, "callbackUrl");
// var storeIdList = DtoValidator.GetAttributePrice(parameter.Value, "storeIdList");
@@ -134,7 +136,7 @@ namespace BPA.KitChen.GroupMealOrder.Handlers
// break;
// }
//}

}
catch (Exception e)


+ 1
- 0
BPA.KitChen.GroupMealOrder/appsettings.json Просмотреть файл

@@ -9,5 +9,6 @@
"GroupMealBaseUrl": "http://localhost:5001/",
"GroupMealUrl": "http://localhost:5002/",
"DBConnectionStr": "server=10.2.1.21;Port=3306;Database=bpa_kitchen_groupmealorder;Uid=root;Pwd=cygadmin;",
"DBConnectionLogStr": "server=10.2.1.21;Port=3306;Database=bpa_kitchen_groupmeallog;Uid=root;Pwd=cygadmin;",
"AllowedHosts": "*"
}

Загрузка…
Отмена
Сохранить