diff --git a/Tiobon.Core.IServices/BASE/IBaseServices.cs b/Tiobon.Core.IServices/BASE/IBaseServices.cs
index fabbe38d..4e087f80 100644
--- a/Tiobon.Core.IServices/BASE/IBaseServices.cs
+++ b/Tiobon.Core.IServices/BASE/IBaseServices.cs
@@ -69,4 +69,81 @@ namespace Tiobon.Core.IServices.BASE
#endregion
}
+
+ ///
+ /// 增删改查接口
+ ///
+ ///
+ ///
+ ///
+ ///
+ public interface IBaseServices where TEntity : class
+ {
+ ISqlSugarClient Db { get; }
+
+ Task AnyAsync(object objId);
+
+ ///
+ /// 根据ID查询实体数据是否存在
+ ///
+ ///
+ ///
+ Task QueryById(object objId);
+ Task QueryById(object objId, bool blnUseCache = false);
+ Task> QueryByIDs(object[] lstIds);
+
+ Task Add(TInsertDto model);
+
+ Task> Add(List listEntity);
+
+ Task DeleteById(object id);
+
+ Task Delete(TEntity model);
+
+ Task DeleteByIds(object[] ids);
+
+ Task Update(long Id, TEditDto model);
+ Task Update(List model);
+ Task Update(TEntity entity, string where);
+
+ Task Update(object operateAnonymousObjects);
+
+ Task Update(TEntity entity, List lstColumns = null, List lstIgnoreColumns = null, string where = "");
+
+ Task> Query();
+ Task> Query(string where);
+ Task> Query(Expression> whereExpression);
+ Task> Query(Expression> whereExpression, string orderByFields);
+ Task> Query(Expression> expression);
+ Task> Query(Expression> expression, Expression> whereExpression, string orderByFields);
+ Task> Query(Expression> whereExpression, Expression> orderByExpression, bool isAsc = true);
+ Task> Query(string where, string orderByFields);
+ Task> QuerySql(string sql, SugarParameter[] parameters = null);
+ Task QueryTable(string sql, SugarParameter[] parameters = null);
+
+ Task> Query(Expression> whereExpression, int top, string orderByFields);
+ Task> Query(string where, int top, string orderByFields);
+
+ Task> Query(
+ Expression> whereExpression, int pageIndex, int pageSize, string orderByFields);
+ Task> Query(string where, int pageIndex, int pageSize, string orderByFields);
+
+
+ Task> QueryPage(Expression> whereExpression, int pageIndex = 1, int pageSize = 20, string orderByFields = null);
+ Task> QueryFilterPage([FromFilter] QueryFilter filter);
+
+ Task> QueryMuch(
+ Expression> joinExpression,
+ Expression> selectExpression,
+ Expression> whereLambda = null) where T : class, new();
+ Task> QueryPage(PaginationModel pagination);
+
+ #region 分表
+ Task QueryByIdSplit(object objId);
+ Task> AddSplit(TEntity entity);
+ Task DeleteSplit(TEntity entity, DateTime dateTime);
+ Task UpdateSplit(TEntity entity, DateTime dateTime);
+ Task> QueryPageSplit(Expression> whereExpression, DateTime beginTime, DateTime endTime, int pageIndex = 1, int pageSize = 20, string orderByFields = null);
+ #endregion
+ }
}
diff --git a/Tiobon.Core.IServices/BASE/IBaseServices1.cs b/Tiobon.Core.IServices/BASE/IBaseServices1.cs
deleted file mode 100644
index 087d39eb..00000000
--- a/Tiobon.Core.IServices/BASE/IBaseServices1.cs
+++ /dev/null
@@ -1,86 +0,0 @@
-using System.Data;
-using System.Linq.Expressions;
-using SqlSugar;
-using Tiobon.Core.Common;
-using Tiobon.Core.Model;
-
-namespace Tiobon.Core.IServices.BASE
-{
- ///
- /// 增删改查接口
- ///
- ///
- ///
- ///
- ///
- public interface IBaseServices where TEntity : class
- {
- ISqlSugarClient Db { get; }
-
- Task AnyAsync(object objId);
-
- ///
- /// 根据ID查询实体数据是否存在
- ///
- ///
- ///
- Task QueryById(object objId);
- Task QueryById(object objId, bool blnUseCache = false);
- Task> QueryByIDs(object[] lstIds);
-
- Task Add(TInsertDto model);
-
- Task> Add(List listEntity);
-
- Task DeleteById(object id);
-
- Task Delete(TEntity model);
-
- Task DeleteByIds(object[] ids);
-
- Task Update(long Id, TEditDto model);
- Task Update(List model);
- Task Update(TEntity entity, string where);
-
- Task Update(object operateAnonymousObjects);
-
- Task Update(TEntity entity, List lstColumns = null, List lstIgnoreColumns = null, string where = "");
-
- Task> Query();
- Task> Query(string where);
- Task> Query(Expression> whereExpression);
- Task> Query(Expression> whereExpression, string orderByFields);
- Task> Query(Expression> expression);
- Task> Query(Expression> expression, Expression> whereExpression, string orderByFields);
- Task> Query(Expression> whereExpression, Expression> orderByExpression, bool isAsc = true);
- Task> Query(string where, string orderByFields);
- Task> QuerySql(string sql, SugarParameter[] parameters = null);
- Task QueryTable(string sql, SugarParameter[] parameters = null);
-
- Task> Query(Expression> whereExpression, int top, string orderByFields);
- Task> Query(string where, int top, string orderByFields);
-
- Task> Query(
- Expression> whereExpression, int pageIndex, int pageSize, string orderByFields);
- Task> Query(string where, int pageIndex, int pageSize, string orderByFields);
-
-
- Task> QueryPage(Expression> whereExpression, int pageIndex = 1, int pageSize = 20, string orderByFields = null);
- Task> QueryFilterPage([FromFilter] QueryFilter filter);
-
- Task> QueryMuch(
- Expression> joinExpression,
- Expression> selectExpression,
- Expression> whereLambda = null) where T : class, new();
- Task> QueryPage(PaginationModel pagination);
-
- #region 分表
- Task QueryByIdSplit(object objId);
- Task> AddSplit(TEntity entity);
- Task DeleteSplit(TEntity entity, DateTime dateTime);
- Task UpdateSplit(TEntity entity, DateTime dateTime);
- Task> QueryPageSplit(Expression> whereExpression, DateTime beginTime, DateTime endTime, int pageIndex = 1, int pageSize = 20, string orderByFields = null);
- #endregion
- }
-
-}
diff --git a/Tiobon.Core.Services/BASE/BaseServices.cs b/Tiobon.Core.Services/BASE/BaseServices.cs
index b59c2284..db3f875d 100644
--- a/Tiobon.Core.Services/BASE/BaseServices.cs
+++ b/Tiobon.Core.Services/BASE/BaseServices.cs
@@ -1,7 +1,11 @@
using System.Data;
using System.Linq.Expressions;
+using System.Reflection;
+using AgileObjects.AgileMapper;
+using Microsoft.AspNetCore.Http;
using SqlSugar;
using Tiobon.Core.Common;
+using Tiobon.Core.Common.Extensions;
using Tiobon.Core.Common.Helper;
using Tiobon.Core.Common.UserManager;
using Tiobon.Core.IRepository.Base;
@@ -369,4 +373,509 @@ namespace Tiobon.Core.Services.BASE
#endregion
}
+
+
+ ///
+ /// 增删改查基础服务
+ ///
+ ///
+ ///
+ ///
+ ///
+ public class BaseServices : IBaseServices where TEntity : class, new()
+ {
+ public BaseServices(IBaseRepository BaseDal = null)
+ {
+ this.BaseDal = BaseDal;
+ }
+
+ //public IBaseRepository baseDal = new BaseRepository();
+ public IBaseRepository BaseDal { get; set; } //通过在子类的构造函数中注入,这里是基类,不用构造函数
+
+ public ISqlSugarClient Db => BaseDal.Db;
+
+ ///
+ /// 根据ID查询实体数据是否存在
+ ///
+ ///
+ ///
+ public async Task AnyAsync(object objId)
+ {
+ var data = await BaseDal.AnyAsync(objId);
+ return data;
+ }
+
+ public async Task QueryById(object objId)
+ {
+ var data = await BaseDal.QueryById(objId);
+ return Mapper.Map(data).ToANew();
+ }
+
+ ///
+ /// 根据ID查询一条数据
+ ///
+ /// id(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件
+ /// 是否使用缓存
+ /// 数据实体
+ public async Task QueryById(object objId, bool blnUseCache = false)
+ {
+ var data = await BaseDal.QueryById(objId, blnUseCache);
+ return Mapper.Map(data).ToANew();
+ }
+
+ ///
+ /// 根据ID查询数据
+ ///
+ /// id列表(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件
+ /// 数据实体列表
+ public async Task> QueryByIDs(object[] lstIds)
+ {
+ var data = await BaseDal.QueryByIDs(lstIds);
+ return Mapper.Map(data).ToANew>();
+ }
+
+ ///
+ /// 写入实体数据
+ ///
+ /// 博文实体类
+ ///
+ public async Task Add(TInsertDto entity)
+ {
+ var userId = UserContext.Current.User_Id;
+ HttpRequest request = UserContext.Context.Request;
+ var api = request.Path.ObjToString().TrimEnd('/').ToLower();
+ var ip = GetUserIp(UserContext.Context);
+
+ BasePoco ent = entity as BasePoco;
+
+ ent.CreateIP = ip;
+ ent.CreateProg = api;
+
+ var entity1 = Mapper.Map(entity).ToANew();
+ return await BaseDal.Add(entity1);
+ }
+
+ ///
+ /// 批量插入实体(速度快)
+ ///
+ /// 实体集合
+ /// 影响行数
+ public async Task> Add(List listEntity)
+ {
+ var userId = UserContext.Current.User_Id;
+ HttpRequest request = UserContext.Context.Request;
+ var api = request.Path.ObjToString().TrimEnd('/').ToLower();
+ var ip = GetUserIp(UserContext.Context);
+ listEntity.ForEach(entity =>
+ {
+ BasePoco ent = entity as BasePoco;
+ ent.CreateIP = ip;
+ ent.CreateProg = api;
+ });
+ var list = Mapper.Map(listEntity).ToANew>();
+ return await BaseDal.Add(list);
+ }
+
+ ///
+ /// 更新实体数据
+ ///
+ /// 博文实体类
+ ///
+ public async Task Update(long Id, TEditDto editModel)
+ {
+ HttpRequest request = UserContext.Context.Request;
+ var api = request.Path.ObjToString().TrimEnd('/').ToLower();
+ var ip = GetUserIp(UserContext.Context);
+
+ if (editModel == null || !await BaseDal.AnyAsync(Id))
+ return false;
+
+ var entity = await BaseDal.QueryById(Id);
+ ConvertTEditDto2TEntity(editModel, entity);
+ BasePoco ent = entity as BasePoco;
+ ent.UpdateIP = ip;
+ ent.UpdateProg = api;
+ return await BaseDal.Update(entity);
+ }
+ ///
+ /// 更新实体数据
+ ///
+ /// 博文实体类
+ ///
+ public async Task Update(List listEntity)
+ {
+ HttpRequest request = UserContext.Context.Request;
+ var api = request.Path.ObjToString().TrimEnd('/').ToLower();
+ var ip = GetUserIp(UserContext.Context);
+ listEntity.ForEach(entity =>
+ {
+ BasePoco ent = entity as BasePoco;
+ ent.UpdateIP = ip;
+ ent.UpdateProg = api;
+ });
+ return await BaseDal.Update(listEntity);
+ }
+
+ public async Task Update(TEntity entity, string where)
+ {
+ HttpRequest request = UserContext.Context.Request;
+ var api = request.Path.ObjToString().TrimEnd('/').ToLower();
+ var ip = GetUserIp(UserContext.Context);
+ BasePoco ent = entity as BasePoco;
+ ent.UpdateIP = ip;
+ ent.UpdateProg = api;
+ return await BaseDal.Update(entity, where);
+ }
+
+ public async Task Update(object operateAnonymousObjects)
+ {
+ return await BaseDal.Update(operateAnonymousObjects);
+ }
+
+ public async Task Update(
+ TEntity entity,
+ List lstColumns = null,
+ List lstIgnoreColumns = null,
+ string where = ""
+ )
+ {
+ return await BaseDal.Update(entity, lstColumns, lstIgnoreColumns, where);
+ }
+
+
+ ///
+ /// 根据实体删除一条数据
+ ///
+ /// 博文实体类
+ ///
+ public async Task Delete(TEntity entity)
+ {
+ return await BaseDal.Delete(entity);
+ }
+
+ ///
+ /// 删除指定ID的数据
+ ///
+ /// 主键ID
+ ///
+ public async Task DeleteById(object id)
+ {
+ return await BaseDal.DeleteById(id);
+ }
+
+ ///
+ /// 删除指定ID集合的数据(批量删除)
+ ///
+ /// 主键ID集合
+ ///
+ public async Task DeleteByIds(object[] ids)
+ {
+ return await BaseDal.DeleteByIds(ids);
+ }
+
+
+ ///
+ /// 查询所有数据
+ ///
+ /// 数据列表
+ public async Task> Query()
+ {
+ return await BaseDal.Query();
+ }
+
+ ///
+ /// 查询数据列表
+ ///
+ /// 条件
+ /// 数据列表
+ public async Task> Query(string where)
+ {
+ return await BaseDal.Query(where);
+ }
+
+ ///
+ /// 查询数据列表
+ ///
+ /// whereExpression
+ /// 数据列表
+ public async Task> Query(Expression> whereExpression)
+ {
+ return await BaseDal.Query(whereExpression);
+ }
+
+ ///
+ /// 按照特定列查询数据列表
+ ///
+ ///
+ ///
+ ///
+ public async Task> Query(Expression> expression)
+ {
+ return await BaseDal.Query(expression);
+ }
+
+ ///
+ /// 按照特定列查询数据列表带条件排序
+ ///
+ ///
+ /// 过滤条件
+ /// 查询实体条件
+ /// 排序条件
+ ///
+ public async Task> Query(Expression> expression, Expression> whereExpression, string orderByFileds)
+ {
+ return await BaseDal.Query(expression, whereExpression, orderByFileds);
+ }
+
+ ///
+ /// 查询一个列表
+ ///
+ /// 条件表达式
+ /// 排序字段,如name asc,age desc
+ /// 数据列表
+ public async Task> Query(Expression> whereExpression, Expression> orderByExpression, bool isAsc = true)
+ {
+ return await BaseDal.Query(whereExpression, orderByExpression, isAsc);
+ }
+
+ public async Task> Query(Expression> whereExpression, string orderByFileds)
+ {
+ return await BaseDal.Query(whereExpression, orderByFileds);
+ }
+
+ ///
+ /// 查询一个列表
+ ///
+ /// 条件
+ /// 排序字段,如name asc,age desc
+ /// 数据列表
+ public async Task> Query(string where, string orderByFileds)
+ {
+ return await BaseDal.Query(where, orderByFileds);
+ }
+
+ ///
+ /// 根据sql语句查询
+ ///
+ /// 完整的sql语句
+ /// 参数
+ /// 泛型集合
+ public async Task> QuerySql(string sql, SugarParameter[] parameters = null)
+ {
+ return await BaseDal.QuerySql(sql, parameters);
+ }
+
+ ///
+ /// 根据sql语句查询
+ ///
+ /// 完整的sql语句
+ /// 参数
+ /// DataTable
+ public async Task QueryTable(string sql, SugarParameter[] parameters = null)
+ {
+ return await BaseDal.QueryTable(sql, parameters);
+ }
+
+ ///
+ /// 查询前N条数据
+ ///
+ /// 条件表达式
+ /// 前N条
+ /// 排序字段,如name asc,age desc
+ /// 数据列表
+ public async Task> Query(Expression> whereExpression, int top, string orderByFileds)
+ {
+ return await BaseDal.Query(whereExpression, top, orderByFileds);
+ }
+
+ ///
+ /// 查询前N条数据
+ ///
+ /// 条件
+ /// 前N条
+ /// 排序字段,如name asc,age desc
+ /// 数据列表
+ public async Task> Query(
+ string where,
+ int top,
+ string orderByFileds)
+ {
+ return await BaseDal.Query(where, top, orderByFileds);
+ }
+
+ ///
+ /// 分页查询
+ ///
+ /// 条件表达式
+ /// 页码(下标0)
+ /// 页大小
+ /// 排序字段,如name asc,age desc
+ /// 数据列表
+ public async Task> Query(
+ Expression> whereExpression,
+ int pageIndex,
+ int pageSize,
+ string orderByFileds)
+ {
+ return await BaseDal.Query(
+ whereExpression,
+ pageIndex,
+ pageSize,
+ orderByFileds);
+ }
+
+ ///
+ /// 分页查询
+ ///
+ /// 条件
+ /// 页码(下标0)
+ /// 页大小
+ /// 排序字段,如name asc,age desc
+ /// 数据列表
+ public async Task> Query(
+ string where,
+ int pageIndex,
+ int pageSize,
+ string orderByFileds)
+ {
+ return await BaseDal.Query(
+ where,
+ pageIndex,
+ pageSize,
+ orderByFileds);
+ }
+
+ public async Task> QueryPage(Expression> whereExpression,
+ int pageIndex = 1, int pageSize = 20, string orderByFileds = null)
+ {
+ return await BaseDal.QueryPage(whereExpression,
+ pageIndex, pageSize, orderByFileds);
+ }
+
+ public async Task> QueryFilterPage([FromFilter] QueryFilter filter)
+ {
+ var data = await BaseDal.QueryFilterPage(filter);
+
+ return new PageModel(filter.PageIndex, data.dataCount, filter.PageSize, Mapper.Map(data.data).ToANew>());
+
+ }
+
+ public async Task> QueryMuch(Expression> joinExpression, Expression> selectExpression, Expression> whereLambda = null) where T : class, new()
+ {
+ return await BaseDal.QueryMuch(joinExpression, selectExpression, whereLambda);
+ }
+
+ public async Task> QueryPage(PaginationModel pagination)
+ {
+ var express = DynamicLinqFactory.CreateLambda(pagination.Conditions);
+ return await QueryPage(express, pagination.PageIndex, pagination.PageSize, pagination.OrderByFileds);
+ }
+
+ #region 分表
+
+ public async Task> AddSplit(TEntity entity)
+ {
+ return await BaseDal.AddSplit(entity);
+ }
+
+ public async Task UpdateSplit(TEntity entity, DateTime dateTime)
+ {
+ return await BaseDal.UpdateSplit(entity, dateTime);
+ }
+
+ ///
+ /// 根据实体删除一条数据
+ ///
+ /// 博文实体类
+ ///
+ public async Task DeleteSplit(TEntity entity, DateTime dateTime)
+ {
+ return await BaseDal.DeleteSplit(entity, dateTime);
+ }
+
+ public async Task QueryByIdSplit(object objId)
+ {
+ return await BaseDal.QueryByIdSplit(objId);
+ }
+
+ public async Task> QueryPageSplit(Expression> whereExpression, DateTime beginTime, DateTime endTime,
+ int pageIndex = 1, int pageSize = 20, string orderByFields = null)
+ {
+ return await BaseDal.QueryPageSplit(whereExpression, beginTime, endTime,
+ pageIndex, pageSize, orderByFields);
+ }
+
+ #endregion
+
+ public static string GetUserIp(HttpContext context)
+ {
+ string realIP = null;
+ string forwarded = null;
+ string remoteIpAddress = context.Connection.RemoteIpAddress.ToString();
+ if (context.Request.Headers.ContainsKey("X-Real-IP"))
+ {
+ realIP = context.Request.Headers["X-Real-IP"].ToString();
+ if (realIP != remoteIpAddress)
+ {
+ remoteIpAddress = realIP;
+ }
+ }
+ if (context.Request.Headers.ContainsKey("X-Forwarded-For"))
+ {
+ forwarded = context.Request.Headers["X-Forwarded-For"].ToString();
+ if (forwarded != remoteIpAddress)
+ {
+ remoteIpAddress = forwarded;
+ }
+ }
+ remoteIpAddress = remoteIpAddress.Replace("::ffff:", null);
+ return remoteIpAddress;
+ }
+
+
+ #region 辅助方法
+ ///
+ /// 转换TEditDto2TEntity
+ ///
+ ///
+ ///
+ ///
+ protected void ConvertTEditDto2TEntity(TEditDto source, TEntity dest)
+ {
+ foreach (PropertyInfo mItem in typeof(TEditDto).GetProperties())
+ {
+ if (dest.HasField(mItem.Name))
+ dest.SetValueForField(mItem.Name, mItem.GetValue(source, null));
+ }
+ //dest.SetValueForField(DbConsts.ColunmName_LastModificationTime, DateTimeHelper.Now());
+ //if (_currentUserId != default)
+ //{
+ // //dest.SetValueForField(DbConsts.ColunmName_LastModifierId, _currentUserId);
+ // dest.SetValueForField(DbConsts.ColunmName_LastModifier, _currentUserName);
+ //}
+
+ //if (_currentTenantId != null)
+ //{
+ // dest.SetValueForField(DbConsts.ColunmName_TenantId, _currentTenantId);
+ //}
+ }
+
+ ///
+ /// 获取根据ID查询的条件
+ ///
+ ///
+ ///
+ protected QueryFilter QueryFilterById(Guid id)
+ {
+ return new QueryFilter
+ {
+ PageIndex = 1,
+ PageSize = 1,
+ Sorting = string.Empty,
+ Predicate = "Id=@0",
+ PredicateValues = new object[] { id }
+ };
+ }
+ #endregion
+ }
}
\ No newline at end of file
diff --git a/Tiobon.Core.Services/BASE/BaseServices1.cs b/Tiobon.Core.Services/BASE/BaseServices1.cs
deleted file mode 100644
index d0e1e95e..00000000
--- a/Tiobon.Core.Services/BASE/BaseServices1.cs
+++ /dev/null
@@ -1,528 +0,0 @@
-using System.Collections.Generic;
-using System.Data;
-using System.Diagnostics;
-using System.Linq.Expressions;
-using System.Reflection;
-using AgileObjects.AgileMapper;
-using Microsoft.AspNetCore.Http;
-using Microsoft.IdentityModel.Tokens;
-using MongoDB.Driver;
-using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
-using SharpCompress.Common;
-using SqlSugar;
-using Tiobon.Core.Common;
-using Tiobon.Core.Common.Extensions;
-using Tiobon.Core.Common.Helper;
-using Tiobon.Core.Common.HttpContextUser;
-using Tiobon.Core.Common.UserManager;
-using Tiobon.Core.IRepository.Base;
-using Tiobon.Core.IServices.BASE;
-using Tiobon.Core.Model;
-using Tiobon.Core.Repository.Base;
-
-namespace Tiobon.Core.Services.BASE
-{
- ///
- /// 增删改查基础服务
- ///
- ///
- ///
- ///
- ///
- public class BaseServices : IBaseServices where TEntity : class, new()
- {
- public BaseServices(IBaseRepository BaseDal = null)
- {
- this.BaseDal = BaseDal;
- }
-
- //public IBaseRepository baseDal = new BaseRepository();
- public IBaseRepository BaseDal { get; set; } //通过在子类的构造函数中注入,这里是基类,不用构造函数
-
- public ISqlSugarClient Db => BaseDal.Db;
-
- ///
- /// 根据ID查询实体数据是否存在
- ///
- ///
- ///
- public async Task AnyAsync(object objId)
- {
- var data = await BaseDal.AnyAsync(objId);
- return data;
- }
-
- public async Task QueryById(object objId)
- {
- var data = await BaseDal.QueryById(objId);
- return Mapper.Map(data).ToANew();
- }
-
- ///
- /// 根据ID查询一条数据
- ///
- /// id(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件
- /// 是否使用缓存
- /// 数据实体
- public async Task QueryById(object objId, bool blnUseCache = false)
- {
- var data = await BaseDal.QueryById(objId, blnUseCache);
- return Mapper.Map(data).ToANew();
- }
-
- ///
- /// 根据ID查询数据
- ///
- /// id列表(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件
- /// 数据实体列表
- public async Task> QueryByIDs(object[] lstIds)
- {
- var data = await BaseDal.QueryByIDs(lstIds);
- return Mapper.Map(data).ToANew>();
- }
-
- ///
- /// 写入实体数据
- ///
- /// 博文实体类
- ///
- public async Task Add(TInsertDto entity)
- {
- var userId = UserContext.Current.User_Id;
- HttpRequest request = UserContext.Context.Request;
- var api = request.Path.ObjToString().TrimEnd('/').ToLower();
- var ip = GetUserIp(UserContext.Context);
-
- BasePoco ent = entity as BasePoco;
-
- ent.CreateIP = ip;
- ent.CreateProg = api;
-
- var entity1 = Mapper.Map(entity).ToANew();
- return await BaseDal.Add(entity1);
- }
-
- ///
- /// 批量插入实体(速度快)
- ///
- /// 实体集合
- /// 影响行数
- public async Task> Add(List listEntity)
- {
- var userId = UserContext.Current.User_Id;
- HttpRequest request = UserContext.Context.Request;
- var api = request.Path.ObjToString().TrimEnd('/').ToLower();
- var ip = GetUserIp(UserContext.Context);
- listEntity.ForEach(entity =>
- {
- BasePoco ent = entity as BasePoco;
- ent.CreateIP = ip;
- ent.CreateProg = api;
- });
- var list = Mapper.Map(listEntity).ToANew>();
- return await BaseDal.Add(list);
- }
-
- ///
- /// 更新实体数据
- ///
- /// 博文实体类
- ///
- public async Task Update(long Id, TEditDto editModel)
- {
- HttpRequest request = UserContext.Context.Request;
- var api = request.Path.ObjToString().TrimEnd('/').ToLower();
- var ip = GetUserIp(UserContext.Context);
-
- if (editModel == null || !await BaseDal.AnyAsync(Id))
- return false;
-
- var entity = await BaseDal.QueryById(Id);
- ConvertTEditDto2TEntity(editModel, entity);
- BasePoco ent = entity as BasePoco;
- ent.UpdateIP = ip;
- ent.UpdateProg = api;
- return await BaseDal.Update(entity);
- }
- ///
- /// 更新实体数据
- ///
- /// 博文实体类
- ///
- public async Task Update(List listEntity)
- {
- HttpRequest request = UserContext.Context.Request;
- var api = request.Path.ObjToString().TrimEnd('/').ToLower();
- var ip = GetUserIp(UserContext.Context);
- listEntity.ForEach(entity =>
- {
- BasePoco ent = entity as BasePoco;
- ent.UpdateIP = ip;
- ent.UpdateProg = api;
- });
- return await BaseDal.Update(listEntity);
- }
-
- public async Task Update(TEntity entity, string where)
- {
- HttpRequest request = UserContext.Context.Request;
- var api = request.Path.ObjToString().TrimEnd('/').ToLower();
- var ip = GetUserIp(UserContext.Context);
- BasePoco ent = entity as BasePoco;
- ent.UpdateIP = ip;
- ent.UpdateProg = api;
- return await BaseDal.Update(entity, where);
- }
-
- public async Task Update(object operateAnonymousObjects)
- {
- return await BaseDal.Update(operateAnonymousObjects);
- }
-
- public async Task Update(
- TEntity entity,
- List lstColumns = null,
- List lstIgnoreColumns = null,
- string where = ""
- )
- {
- return await BaseDal.Update(entity, lstColumns, lstIgnoreColumns, where);
- }
-
-
- ///
- /// 根据实体删除一条数据
- ///
- /// 博文实体类
- ///
- public async Task Delete(TEntity entity)
- {
- return await BaseDal.Delete(entity);
- }
-
- ///
- /// 删除指定ID的数据
- ///
- /// 主键ID
- ///
- public async Task DeleteById(object id)
- {
- return await BaseDal.DeleteById(id);
- }
-
- ///
- /// 删除指定ID集合的数据(批量删除)
- ///
- /// 主键ID集合
- ///
- public async Task DeleteByIds(object[] ids)
- {
- return await BaseDal.DeleteByIds(ids);
- }
-
-
- ///
- /// 查询所有数据
- ///
- /// 数据列表
- public async Task> Query()
- {
- return await BaseDal.Query();
- }
-
- ///
- /// 查询数据列表
- ///
- /// 条件
- /// 数据列表
- public async Task> Query(string where)
- {
- return await BaseDal.Query(where);
- }
-
- ///
- /// 查询数据列表
- ///
- /// whereExpression
- /// 数据列表
- public async Task> Query(Expression> whereExpression)
- {
- return await BaseDal.Query(whereExpression);
- }
-
- ///
- /// 按照特定列查询数据列表
- ///
- ///
- ///
- ///
- public async Task> Query(Expression> expression)
- {
- return await BaseDal.Query(expression);
- }
-
- ///
- /// 按照特定列查询数据列表带条件排序
- ///
- ///
- /// 过滤条件
- /// 查询实体条件
- /// 排序条件
- ///
- public async Task> Query(Expression> expression, Expression> whereExpression, string orderByFileds)
- {
- return await BaseDal.Query(expression, whereExpression, orderByFileds);
- }
-
- ///
- /// 查询一个列表
- ///
- /// 条件表达式
- /// 排序字段,如name asc,age desc
- /// 数据列表
- public async Task> Query(Expression> whereExpression, Expression> orderByExpression, bool isAsc = true)
- {
- return await BaseDal.Query(whereExpression, orderByExpression, isAsc);
- }
-
- public async Task> Query(Expression> whereExpression, string orderByFileds)
- {
- return await BaseDal.Query(whereExpression, orderByFileds);
- }
-
- ///
- /// 查询一个列表
- ///
- /// 条件
- /// 排序字段,如name asc,age desc
- /// 数据列表
- public async Task> Query(string where, string orderByFileds)
- {
- return await BaseDal.Query(where, orderByFileds);
- }
-
- ///
- /// 根据sql语句查询
- ///
- /// 完整的sql语句
- /// 参数
- /// 泛型集合
- public async Task> QuerySql(string sql, SugarParameter[] parameters = null)
- {
- return await BaseDal.QuerySql(sql, parameters);
- }
-
- ///
- /// 根据sql语句查询
- ///
- /// 完整的sql语句
- /// 参数
- /// DataTable
- public async Task QueryTable(string sql, SugarParameter[] parameters = null)
- {
- return await BaseDal.QueryTable(sql, parameters);
- }
-
- ///
- /// 查询前N条数据
- ///
- /// 条件表达式
- /// 前N条
- /// 排序字段,如name asc,age desc
- /// 数据列表
- public async Task> Query(Expression> whereExpression, int top, string orderByFileds)
- {
- return await BaseDal.Query(whereExpression, top, orderByFileds);
- }
-
- ///
- /// 查询前N条数据
- ///
- /// 条件
- /// 前N条
- /// 排序字段,如name asc,age desc
- /// 数据列表
- public async Task> Query(
- string where,
- int top,
- string orderByFileds)
- {
- return await BaseDal.Query(where, top, orderByFileds);
- }
-
- ///
- /// 分页查询
- ///
- /// 条件表达式
- /// 页码(下标0)
- /// 页大小
- /// 排序字段,如name asc,age desc
- /// 数据列表
- public async Task> Query(
- Expression> whereExpression,
- int pageIndex,
- int pageSize,
- string orderByFileds)
- {
- return await BaseDal.Query(
- whereExpression,
- pageIndex,
- pageSize,
- orderByFileds);
- }
-
- ///
- /// 分页查询
- ///
- /// 条件
- /// 页码(下标0)
- /// 页大小
- /// 排序字段,如name asc,age desc
- /// 数据列表
- public async Task> Query(
- string where,
- int pageIndex,
- int pageSize,
- string orderByFileds)
- {
- return await BaseDal.Query(
- where,
- pageIndex,
- pageSize,
- orderByFileds);
- }
-
- public async Task> QueryPage(Expression> whereExpression,
- int pageIndex = 1, int pageSize = 20, string orderByFileds = null)
- {
- return await BaseDal.QueryPage(whereExpression,
- pageIndex, pageSize, orderByFileds);
- }
-
- public async Task> QueryFilterPage([FromFilter] QueryFilter filter)
- {
- var data = await BaseDal.QueryFilterPage(filter);
-
- return new PageModel(filter.PageIndex, data.dataCount, filter.PageSize, Mapper.Map(data.data).ToANew>());
-
- }
-
- public async Task> QueryMuch(Expression> joinExpression, Expression> selectExpression, Expression> whereLambda = null) where T : class, new()
- {
- return await BaseDal.QueryMuch(joinExpression, selectExpression, whereLambda);
- }
-
- public async Task