shgx_tz_mom/ZR.Service/BaseService.cs

290 lines
9.7 KiB
C#
Raw Normal View History

2021-09-27 16:07:55 +08:00
using ZR.Repository;
2021-08-23 16:57:25 +08:00
namespace ZR.Service
{
/// <summary>
/// 基础服务定义
/// </summary>
/// <typeparam name="T"></typeparam>
2021-09-27 16:07:55 +08:00
public class BaseService<T> : BaseRepository<T>, IBaseService<T> where T : class, new()
2021-08-23 16:57:25 +08:00
{
2021-09-27 16:07:55 +08:00
//#region 添加操作
///// <summary>
///// 添加一条数据
///// </summary>
///// <param name="parm">T</param>
///// <returns></returns>
//public int Add(T parm)
2021-09-27 08:06:09 +08:00
//{
2021-09-27 16:07:55 +08:00
// return Add(parm);// Context.Insertable(parm).RemoveDataCache().ExecuteCommand();
2021-09-27 08:06:09 +08:00
//}
2021-08-23 16:57:25 +08:00
2021-09-27 08:06:09 +08:00
///// <summary>
2021-09-27 16:07:55 +08:00
///// 添加
2021-09-27 08:06:09 +08:00
///// </summary>
2021-09-27 16:07:55 +08:00
///// <param name="parm"></param>
///// <param name="iClumns">插入列</param>
///// <param name="ignoreNull">忽略null列</param>
///// <returns></returns>
//public int Add(T parm, Expression<Func<T, object>> iClumns = null, bool ignoreNull = true)
2021-09-27 08:06:09 +08:00
//{
2021-09-27 16:07:55 +08:00
// return Add(parm);
2021-09-27 08:06:09 +08:00
//}
///// <summary>
2021-09-27 16:07:55 +08:00
///// 批量添加数据
2021-09-27 08:06:09 +08:00
///// </summary>
2021-09-27 16:07:55 +08:00
///// <param name="parm">List<T></param>
///// <returns></returns>
//public int Add(List<T> parm)
2021-09-27 08:06:09 +08:00
//{
2021-09-27 16:07:55 +08:00
// return 1;// Context.Insertable(parm).RemoveDataCache().ExecuteCommand();
2021-09-27 08:06:09 +08:00
//}
///// <summary>
2021-09-27 16:07:55 +08:00
///// 添加或更新数据,不推荐使用了
2021-09-27 08:06:09 +08:00
///// </summary>
2021-09-27 16:07:55 +08:00
///// <param name="parm">List<T></param>
///// <returns></returns>
//public T Saveable(T parm, Expression<Func<T, object>> uClumns = null, Expression<Func<T, object>> iColumns = null)
2021-09-27 08:06:09 +08:00
//{
2021-09-27 16:07:55 +08:00
// var command = Context.Saveable(parm);
2021-08-23 16:57:25 +08:00
2021-09-27 16:07:55 +08:00
// if (uClumns != null)
// {
// command = command.UpdateIgnoreColumns(uClumns);
// }
2021-08-23 16:57:25 +08:00
2021-09-27 16:07:55 +08:00
// if (iColumns != null)
// {
// command = command.InsertIgnoreColumns(iColumns);
// }
2021-08-23 16:57:25 +08:00
2021-09-27 16:07:55 +08:00
// return command.ExecuteReturnEntity();
2021-09-27 08:06:09 +08:00
//}
2021-09-21 20:31:35 +08:00
2021-09-27 16:07:55 +08:00
///// <summary>
///// 批量添加或更新数据
///// </summary>
///// <param name="parm">List<T></param>
///// <returns></returns>
//public List<T> Saveable(List<T> parm, Expression<Func<T, object>> uClumns = null, Expression<Func<T, object>> iColumns = null)
//{
// var command = Context.Saveable(parm);
2021-08-23 16:57:25 +08:00
2021-09-27 16:07:55 +08:00
// if (uClumns != null)
// {
// command = command.UpdateIgnoreColumns(uClumns);
// }
2021-08-23 16:57:25 +08:00
2021-09-27 16:07:55 +08:00
// if (iColumns != null)
// {
// command = command.InsertIgnoreColumns(iColumns);
// }
2021-08-23 16:57:25 +08:00
2021-09-27 16:07:55 +08:00
// return command.ExecuteReturnList();
//}
//#endregion
2021-08-23 16:57:25 +08:00
2021-09-27 16:07:55 +08:00
//#region 查询操作
2021-08-23 16:57:25 +08:00
2021-09-27 16:07:55 +08:00
///// <summary>
///// 根据条件查询数据是否存在
///// </summary>
///// <param name="where">条件表达式树</param>
///// <returns></returns>
2021-09-27 08:06:09 +08:00
//public bool Any(Expression<Func<T, bool>> where)
//{
2021-09-27 16:07:55 +08:00
// return true;// base.Context.Any(where);
2021-09-27 08:06:09 +08:00
//}
2021-08-23 16:57:25 +08:00
2021-09-27 16:07:55 +08:00
///// <summary>
///// 根据条件合计字段
///// </summary>
///// <param name="where">条件表达式树</param>
///// <returns></returns>
//public TResult Sum<TResult>(Expression<Func<T, bool>> where, Expression<Func<T, TResult>> field)
2021-09-27 08:06:09 +08:00
//{
2021-09-27 16:07:55 +08:00
// return base.Context.Queryable<T>().Where(where).Sum(field);
2021-09-27 08:06:09 +08:00
//}
2021-08-23 16:57:25 +08:00
2021-09-27 16:07:55 +08:00
///// <summary>
///// 根据主值查询单条数据
///// </summary>
///// <param name="pkValue">主键值</param>
///// <returns>泛型实体</returns>
////public T GetId(object pkValue)
////{
//// return base.Context.Queryable<T>().InSingle(pkValue);
////}
2021-08-23 16:57:25 +08:00
2021-09-27 16:07:55 +08:00
///// <summary>
///// 根据主键查询多条数据
///// </summary>
///// <param name="ids"></param>
///// <returns></returns>
//public List<T> GetIn(object[] ids)
2021-09-27 08:06:09 +08:00
//{
2021-09-27 16:07:55 +08:00
// return Context.Queryable<T>().In(ids).ToList();
2021-09-27 08:06:09 +08:00
//}
2021-08-23 16:57:25 +08:00
2021-09-27 08:06:09 +08:00
///// <summary>
2021-09-27 16:07:55 +08:00
///// 根据条件取条数
2021-09-27 08:06:09 +08:00
///// </summary>
2021-09-27 16:07:55 +08:00
///// <param name="where">条件表达式树</param>
2021-09-27 08:06:09 +08:00
///// <returns></returns>
2021-09-27 16:07:55 +08:00
//public int GetCount(Expression<Func<T, bool>> where)
2021-09-27 08:06:09 +08:00
//{
2021-09-27 16:07:55 +08:00
// return Context.Queryable<T>().Count(where);
2021-09-27 08:06:09 +08:00
//}
///// <summary>
2021-09-27 16:07:55 +08:00
///// 查询所有数据(无分页,请慎用)
2021-09-27 08:06:09 +08:00
///// </summary>
///// <returns></returns>
2021-09-27 16:07:55 +08:00
//public List<T> GetAll(bool useCache = false, int cacheSecond = 3600)
2021-09-27 08:06:09 +08:00
//{
2021-09-27 16:07:55 +08:00
// return Context.Queryable<T>().WithCacheIF(useCache, cacheSecond).ToList();
2021-09-27 08:06:09 +08:00
//}
///// <summary>
2021-09-27 16:07:55 +08:00
///// 获得一条数据
2021-09-27 08:06:09 +08:00
///// </summary>
2021-09-27 16:07:55 +08:00
///// <param name="where">Expression<Func<T, bool>></param>
2021-09-27 08:06:09 +08:00
///// <returns></returns>
2021-09-27 16:07:55 +08:00
//public T GetFirst2(Expression<Func<T, bool>> where)
2021-09-27 08:06:09 +08:00
//{
2021-09-27 16:07:55 +08:00
// return base.GetFirst(where);// Context.Queryable<T>().Where(where).First();
2021-09-27 08:06:09 +08:00
//}
2021-08-23 16:57:25 +08:00
2021-09-27 08:06:09 +08:00
///// <summary>
2021-09-27 16:07:55 +08:00
///// 获得一条数据
2021-09-27 08:06:09 +08:00
///// </summary>
///// <param name="parm">string</param>
///// <returns></returns>
2021-09-27 16:07:55 +08:00
////public T GetFirst(string parm)
////{
//// return Context.Queryable<T>().Where(parm).First();
////}
2021-09-27 08:06:09 +08:00
///// <summary>
2021-09-27 16:07:55 +08:00
///// 根据条件查询分页数据
2021-09-27 08:06:09 +08:00
///// </summary>
2021-09-27 16:07:55 +08:00
///// <param name="where"></param>
///// <param name="parm"></param>
2021-09-27 08:06:09 +08:00
///// <returns></returns>
2021-09-27 16:07:55 +08:00
//public PagedInfo<T> GetPages(Expression<Func<T, bool>> where, PagerInfo parm)
2021-09-27 08:06:09 +08:00
//{
2021-09-27 16:07:55 +08:00
// var source = Context.Queryable<T>().Where(where);
// return source.ToPage(parm);
2021-09-27 08:06:09 +08:00
//}
2021-09-27 16:07:55 +08:00
//public PagedInfo<T> GetPages(Expression<Func<T, bool>> where, PagerInfo parm, Expression<Func<T, object>> order, string orderEnum = "Asc")
//{
// var source = Context.Queryable<T>().Where(where).OrderByIF(orderEnum == "Asc", order, OrderByType.Asc).OrderByIF(orderEnum == "Desc", order, OrderByType.Desc);
// return source.ToPage(parm);
//}
/// <summary>
/// 根据条件查询数据
/// </summary>
/// <param name="where">条件表达式树</param>
/// <returns></returns>
// public List<T> GetWhere(Expression<Func<T, bool>> where, bool useCache = false, int cacheSecond = 3600)
// {
// var query = Context.Queryable<T>().Where(where).WithCacheIF(useCache, cacheSecond);
// return query.ToList();
// }
// /// <summary>
///// 根据条件查询数据
2021-09-27 08:06:09 +08:00
///// </summary>
2021-09-27 16:07:55 +08:00
///// <param name="where">条件表达式树</param>
2021-09-27 08:06:09 +08:00
///// <returns></returns>
2021-09-27 16:07:55 +08:00
// public List<T> GetWhere(Expression<Func<T, bool>> where, Expression<Func<T, object>> order, string orderEnum = "Asc", bool useCache = false, int cacheSecond = 3600)
// {
// var query = Context.Queryable<T>().Where(where).OrderByIF(orderEnum == "Asc", order, OrderByType.Asc).OrderByIF(orderEnum == "Desc", order, OrderByType.Desc).WithCacheIF(useCache, cacheSecond);
// return query.ToList();
// }
// #endregion
//#region 修改操作
/////// <summary>
/////// 修改一条数据
/////// </summary>
/////// <param name="parm">T</param>
/////// <returns></returns>
////public int Update(T parm)
////{
//// return Context.Updateable(parm).RemoveDataCache().ExecuteCommand();
////}
/////// <summary>
/////// 批量修改
/////// </summary>
/////// <param name="parm">T</param>
/////// <returns></returns>
////public int Update(List<T> parm)
////{
//// return Context.Updateable(parm).RemoveDataCache().ExecuteCommand();
////}
/////// <summary>
/////// 按查询条件更新
/////// </summary>
/////// <param name="where"></param>
/////// <param name="columns"></param>
/////// <returns></returns>
////public int Update(Expression<Func<T, bool>> where, Expression<Func<T, T>> columns)
////{
//// return Context.Updateable<T>().SetColumns(columns).Where(where).RemoveDataCache().ExecuteCommand();
////}
//#endregion
//#region 删除操作
/////// <summary>
/////// 删除一条或多条数据
/////// </summary>
/////// <param name="parm">string</param>
/////// <returns></returns>
////public int Delete(object id)
////{
//// return Context.Deleteable<T>(id).RemoveDataCache().ExecuteCommand();
////}
/////// <summary>
/////// 删除一条或多条数据
/////// </summary>
/////// <param name="parm">string</param>
/////// <returns></returns>
////public int Delete(object[] ids)
////{
//// return Context.Deleteable<T>().In(ids).RemoveDataCache().ExecuteCommand();
////}
/////// <summary>
/////// 根据条件删除一条或多条数据
/////// </summary>
/////// <param name="where">过滤条件</param>
/////// <returns></returns>
////public int Delete(Expression<Func<T, bool>> where)
////{
//// return Context.Deleteable<T>().Where(where).RemoveDataCache().ExecuteCommand();
////}
//public int DeleteTable()
2021-09-27 08:06:09 +08:00
//{
2021-09-27 16:07:55 +08:00
// return Context.Deleteable<T>().RemoveDataCache().ExecuteCommand();
2021-09-27 08:06:09 +08:00
//}
2021-09-27 16:07:55 +08:00
//#endregion
2021-08-23 16:57:25 +08:00
}
}