using Furion;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
namespace cylsg.Core
{
///
/// 仓储类,使用方式只需要继承就行
///
///
public class BaseRepository : SimpleClient where T : class, new()
{
public BaseRepository(ISqlSugarClient context = null) : base(context)//默认值等于null不能少
{
base.Context = App.GetService();//用手动获取方式支持切换仓储
}
///
/// 重写更新方法
///
///
///
public Task EzUpdateAsync(T updateObj)
{
var intbs = updateObj as BaseModelBase;
if (intbs != null)
{
intbs.UpDataBy = GetJwtBy();
intbs.UpDataTime = DateTime.Now;
}
return base.UpdateAsync(updateObj);
}
///
/// 异步插入
///
///
///
public Task EzInsertAsync(T insertObj)
{
var intbs = insertObj as BaseModelBase;
if (intbs != null)
{
intbs.CreateBy = GetJwtBy();
intbs.CreateTime = DateTime.Now;
}
return base.InsertAsync(insertObj);
}
///
/// 重写插入
///
///
///
public T EzInsertReturnEntity(T insertObj)
{
var intbs = insertObj as BaseModelBase;
if (intbs != null)
{
intbs.CreateBy = GetJwtBy();
intbs.CreateTime = DateTime.Now;
}
return base.InsertReturnEntity(insertObj);
}
///
/// 异步插入
///
///
///
public Task EzInsertReturnIdentityAsync(T insertObj)
{
var intbs = insertObj as BaseModelBase;
if (intbs != null)
{
intbs.CreateBy = GetJwtBy();
intbs.CreateTime = DateTime.Now;
}
return base.InsertReturnIdentityAsync(insertObj);
}
///
/// 获取用户姓名和ID
///
///
private string GetJwtBy()
{
return (App.User?.FindFirstValue("UserID") ?? "") + "|" + (App.User?.FindFirstValue("NickName") ?? "系统自主处理");
}
}
}