优化接口、仓储层

This commit is contained in:
izory
2021-09-27 16:07:55 +08:00
parent 40026f596f
commit 56a04bbf73
48 changed files with 621 additions and 745 deletions
+231 -273
View File
@@ -1,12 +1,4 @@
using Infrastructure.Attribute;
using Infrastructure.Model;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using ZR.Model;
using ZR.Repository;
using ZR.Repository.DbProvider;
using ZR.Repository;
namespace ZR.Service
{
@@ -14,318 +6,284 @@ namespace ZR.Service
/// 基础服务定义
/// </summary>
/// <typeparam name="T"></typeparam>
public class BaseService<T> : BaseRepository<T> where T : class,new()//, IBaseService<T> where T : class, new()
public class BaseService<T> : BaseRepository<T>, IBaseService<T> where T : class, new()
{
//private readonly IBaseRepository<T> BaseRepository;
//public BaseService(IBaseRepository<T> baseRepository)
//{
// BaseRepository = baseRepository;
//}
#region 事务
//#region 添加操作
///// <summary>
///// 启用事务
///// 添加一条数据
///// </summary>
//public void BeginTran()
///// <param name="parm">T</param>
///// <returns></returns>
//public int Add(T parm)
//{
// Context.Ado.BeginTran();
// return Add(parm);// Context.Insertable(parm).RemoveDataCache().ExecuteCommand();
//}
///// <summary>
///// 提交事务
///// 添加
///// </summary>
//public void CommitTran()
//{
// Context.Ado.CommitTran();
//}
///// <summary>
///// 回滚事务
///// </summary>
//public void RollbackTran()
//{
// Context.Ado.RollbackTran();
//}
#endregion
#region 添加操作
/// <summary>
/// 添加一条数据
/// </summary>
/// <param name="parm">T</param>
/// <returns></returns>
public int Add(T parm)
{
return base.Add(parm);// Context.Insertable(parm).RemoveDataCache().ExecuteCommand();
}
/// <summary>
/// 添加
/// </summary>
/// <param name="parm"></param>
/// <param name="iClumns">插入列</param>
/// <param name="ignoreNull">忽略null列</param>
/// <returns></returns>
///// <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)
//{
// return Add(parm);
//}
/// <summary>
/// 批量添加数据
/// </summary>
/// <param name="parm">List<T></param>
/// <returns></returns>
public int Add(List<T> parm)
{
return Context.Insertable(parm).RemoveDataCache().ExecuteCommand();
}
///// <summary>
///// 批量添加数据
///// </summary>
///// <param name="parm">List<T></param>
///// <returns></returns>
//public int Add(List<T> parm)
//{
// return 1;// Context.Insertable(parm).RemoveDataCache().ExecuteCommand();
//}
/// <summary>
/// 添加或更新数据,不推荐使用了
/// </summary>
/// <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)
{
var command = Context.Saveable(parm);
///// <summary>
///// 添加或更新数据,不推荐使用了
///// </summary>
///// <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)
//{
// var command = Context.Saveable(parm);
if (uClumns != null)
{
command = command.UpdateIgnoreColumns(uClumns);
}
// if (uClumns != null)
// {
// command = command.UpdateIgnoreColumns(uClumns);
// }
if (iColumns != null)
{
command = command.InsertIgnoreColumns(iColumns);
}
// if (iColumns != null)
// {
// command = command.InsertIgnoreColumns(iColumns);
// }
return command.ExecuteReturnEntity();
}
// return command.ExecuteReturnEntity();
//}
/// <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);
///// <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);
if (uClumns != null)
{
command = command.UpdateIgnoreColumns(uClumns);
}
// if (uClumns != null)
// {
// command = command.UpdateIgnoreColumns(uClumns);
// }
if (iColumns != null)
{
command = command.InsertIgnoreColumns(iColumns);
}
// if (iColumns != null)
// {
// command = command.InsertIgnoreColumns(iColumns);
// }
return command.ExecuteReturnList();
}
#endregion
// return command.ExecuteReturnList();
//}
//#endregion
#region 查询操作
//#region 查询操作
/// <summary>
/// 根据条件查询数据是否存在
/// </summary>
/// <param name="where">条件表达式树</param>
/// <returns></returns>
///// <summary>
///// 根据条件查询数据是否存在
///// </summary>
///// <param name="where">条件表达式树</param>
///// <returns></returns>
//public bool Any(Expression<Func<T, bool>> where)
//{
// return base.Context.Any(where);
// return true;// base.Context.Any(where);
//}
/// <summary>
/// 根据条件合计字段
/// </summary>
/// <param name="where">条件表达式树</param>
/// <returns></returns>
public TResult Sum<TResult>(Expression<Func<T, bool>> where, Expression<Func<T, TResult>> field)
{
return base.Context.Queryable<T>().Where(where).Sum(field);
}
/// <summary>
/// 根据主值查询单条数据
/// </summary>
/// <param name="pkValue">主键值</param>
/// <returns>泛型实体</returns>
//public T GetId(object pkValue)
///// <summary>
///// 根据条件合计字段
///// </summary>
///// <param name="where">条件表达式树</param>
///// <returns></returns>
//public TResult Sum<TResult>(Expression<Func<T, bool>> where, Expression<Func<T, TResult>> field)
//{
// return base.Context.Queryable<T>().InSingle(pkValue);
// return base.Context.Queryable<T>().Where(where).Sum(field);
//}
/// <summary>
/// 根据主键查询多条数据
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public List<T> GetIn(object[] ids)
{
return Context.Queryable<T>().In(ids).ToList();
}
///// <summary>
///// 根据主值查询单条数据
///// </summary>
///// <param name="pkValue">主键值</param>
///// <returns>泛型实体</returns>
////public T GetId(object pkValue)
////{
//// return base.Context.Queryable<T>().InSingle(pkValue);
////}
/// <summary>
/// 根据条件取条数
/// </summary>
/// <param name="where">条件表达式树</param>
/// <returns></returns>
public int GetCount(Expression<Func<T, bool>> where)
{
return Context.Queryable<T>().Count(where);
}
/// <summary>
/// 查询所有数据(无分页,请慎用)
/// </summary>
/// <returns></returns>
public List<T> GetAll(bool useCache = false, int cacheSecond = 3600)
{
return Context.Queryable<T>().WithCacheIF(useCache, cacheSecond).ToList();
}
/// <summary>
/// 获得一条数据
/// </summary>
/// <param name="where">Expression<Func<T, bool>></param>
/// <returns></returns>
public T GetFirst2(Expression<Func<T, bool>> where)
{
return base.GetFirst(where);// Context.Queryable<T>().Where(where).First();
}
/// <summary>
/// 获得一条数据
/// </summary>
/// <param name="parm">string</param>
/// <returns></returns>
//public T GetFirst(string parm)
///// <summary>
///// 根据主键查询多条数据
///// </summary>
///// <param name="ids"></param>
///// <returns></returns>
//public List<T> GetIn(object[] ids)
//{
// return Context.Queryable<T>().Where(parm).First();
// return Context.Queryable<T>().In(ids).ToList();
//}
/// <summary>
/// 根据条件查询分页数据
/// </summary>
/// <param name="where"></param>
/// <param name="parm"></param>
/// <returns></returns>
public PagedInfo<T> GetPages(Expression<Func<T, bool>> where, PagerInfo parm)
{
var source = Context.Queryable<T>().Where(where);
///// <summary>
///// 根据条件取条数
///// </summary>
///// <param name="where">条件表达式树</param>
///// <returns></returns>
//public int GetCount(Expression<Func<T, bool>> where)
//{
// return Context.Queryable<T>().Count(where);
return source.ToPage(parm);
}
//}
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);
///// <summary>
///// 查询所有数据(无分页,请慎用)
///// </summary>
///// <returns></returns>
//public List<T> GetAll(bool useCache = false, int cacheSecond = 3600)
//{
// return Context.Queryable<T>().WithCacheIF(useCache, cacheSecond).ToList();
//}
return source.ToPage(parm);
}
///// <summary>
///// 获得一条数据
///// </summary>
///// <param name="where">Expression<Func<T, bool>></param>
///// <returns></returns>
//public T GetFirst2(Expression<Func<T, bool>> where)
//{
// return base.GetFirst(where);// Context.Queryable<T>().Where(where).First();
//}
///// <summary>
///// 获得一条数据
///// </summary>
///// <param name="parm">string</param>
///// <returns></returns>
////public T GetFirst(string parm)
////{
//// return Context.Queryable<T>().Where(parm).First();
////}
///// <summary>
///// 根据条件查询分页数据
///// </summary>
///// <param name="where"></param>
///// <param name="parm"></param>
///// <returns></returns>
//public PagedInfo<T> GetPages(Expression<Func<T, bool>> where, PagerInfo parm)
//{
// var source = Context.Queryable<T>().Where(where);
// return source.ToPage(parm);
//}
//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();
}
// 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>
/// 根据条件查询数据
/// </summary>
/// <param name="where">条件表达式树</param>
/// <returns></returns>
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>
///// 根据条件查询数据
///// </summary>
///// <param name="parm">T</param>
///// <param name="where">条件表达式树</param>
///// <returns></returns>
//public int Update(T parm)
// 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()
//{
// return Context.Updateable(parm).RemoveDataCache().ExecuteCommand();
// return Context.Deleteable<T>().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()
{
return Context.Deleteable<T>().RemoveDataCache().ExecuteCommand();
}
#endregion
//#endregion
}
}
@@ -11,31 +11,6 @@ namespace ZR.Service
{
public static class QueryableExtension
{
/// <summary>
/// 读取列表
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source"></param>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <returns></returns>
//public static async Task<PagedInfo<T>> ToPageAsync<T>(this ISugarQueryable<T> source, PageParm parm)
//{
// var page = new PagedInfo<T>();
// var total = await source.CountAsync();
// page.TotalCount = total;
// page.TotalPages = total / parm.PageSize;
// if (total % parm.PageSize > 0)
// page.TotalPages++;
// page.PageSize = parm.PageSize;
// page.PageIndex = parm.PageIndex;
// page.DataSource = await source.OrderByIF(!string.IsNullOrEmpty(parm.Sort), $"{parm.OrderBy} {(parm.Sort == "descending" ? "desc" : "asc")}").ToPageListAsync(parm.PageIndex, parm.PageSize);
// return page;
//}
/// <summary>
/// 读取列表
/// </summary>
@@ -49,11 +24,6 @@ namespace ZR.Service
var page = new PagedInfo<T>();
var total = source.Count();
page.TotalCount = total;
//page.TotalPage = total / parm.PageSize;
//if (total % parm.PageSize > 0)
// page.TotalPages++;
page.PageSize = parm.PageSize;
page.PageIndex = parm.PageNum;
+146 -167
View File
@@ -3,6 +3,7 @@ using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using ZR.Repository;
namespace ZR.Service
{
@@ -10,221 +11,199 @@ namespace ZR.Service
/// 基础服务定义
/// </summary>
/// <typeparam name="T"></typeparam>
public interface IBaseService<T> where T : class
public interface IBaseService<T> : IBaseRepository<T> where T : class, new()
{
#region 事务
///// <summary>
///// 启用事务
///// </summary>
//void BeginTran();
///// <summary>
///// 提交事务
///// </summary>
//void CommitTran();
///// <summary>
///// 回滚事务
///// </summary>
//void RollbackTran();
#endregion
#region 添加操作
/// <summary>
/// 添加一条数据
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
int Add(T parm);
//int Add(T parm);
int Add(T parm, Expression<Func<T, object>> iClumns = null, bool ignoreNull = false);
//int Add(T parm, Expression<Func<T, object>> iClumns = null, bool ignoreNull = false);
/// <summary>
/// 批量添加数据
/// </summary>
/// <param name="parm">List<T></param>
/// <returns></returns>
int Add(List<T> parm);
///// <summary>
///// 批量添加数据
///// </summary>
///// <param name="parm">List<T></param>
///// <returns></returns>
//int Add(List<T> parm);
/// <summary>
/// 添加或更新数据
/// </summary>
/// <param name="parm"><T></param>
/// <returns></returns>
T Saveable(T parm, Expression<Func<T, object>> uClumns = null, Expression<Func<T, object>> iColumns = null);
///// <summary>
///// 添加或更新数据
///// </summary>
///// <param name="parm"><T></param>
///// <returns></returns>
//T Saveable(T parm, Expression<Func<T, object>> uClumns = null, Expression<Func<T, object>> iColumns = null);
/// <summary>
/// 批量添加或更新数据
/// </summary>
/// <param name="parm">List<T></param>
/// <returns></returns>
List<T> Saveable(List<T> parm, Expression<Func<T, object>> uClumns = null, Expression<Func<T, object>> iColumns = null);
///// <summary>
///// 批量添加或更新数据
///// </summary>
///// <param name="parm">List<T></param>
///// <returns></returns>
//List<T> Saveable(List<T> parm, Expression<Func<T, object>> uClumns = null, Expression<Func<T, object>> iColumns = null);
#endregion
//#endregion
#region 查询操作
//#region 查询操作
/// <summary>
/// 根据条件查询数据是否存在
/// </summary>
/// <param name="where">条件表达式树</param>
/// <returns></returns>
bool Any(Expression<Func<T, bool>> where);
///// <summary>
///// 根据条件查询数据是否存在
///// </summary>
///// <param name="where">条件表达式树</param>
///// <returns></returns>
//bool Any(Expression<Func<T, bool>> where);
/// <summary>
/// 根据条件合计字段
/// </summary>
/// <param name="where">条件表达式树</param>
/// <returns></returns>
TResult Sum<TResult>(Expression<Func<T, bool>> where, Expression<Func<T, TResult>> field);
///// <summary>
///// 根据条件合计字段
///// </summary>
///// <param name="where">条件表达式树</param>
///// <returns></returns>
//TResult Sum<TResult>(Expression<Func<T, bool>> where, Expression<Func<T, TResult>> field);
/// <summary>
/// 根据主值查询单条数据
/// </summary>
/// <param name="pkValue">主键值</param>
/// <returns>泛型实体</returns>
T GetId(object pkValue);
///// <summary>
///// 根据主值查询单条数据
///// </summary>
///// <param name="pkValue">主键值</param>
///// <returns>泛型实体</returns>
//T GetId(object pkValue);
/// <summary>
/// 根据主键查询多条数据
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
List<T> GetIn(object[] ids);
///// <summary>
///// 根据主键查询多条数据
///// </summary>
///// <param name="ids"></param>
///// <returns></returns>
//List<T> GetIn(object[] ids);
/// <summary>
/// 根据条件取条数
/// </summary>
/// <param name="where">条件表达式树</param>
/// <returns></returns>
int GetCount(Expression<Func<T, bool>> where);
///// <summary>
///// 根据条件取条数
///// </summary>
///// <param name="where">条件表达式树</param>
///// <returns></returns>
//int GetCount(Expression<Func<T, bool>> where);
/// <summary>
/// 查询所有数据(无分页,请慎用)
/// </summary>
/// <returns></returns>
List<T> GetAll(bool useCache = false, int cacheSecond = 3600);
///// <summary>
///// 查询所有数据(无分页,请慎用)
///// </summary>
///// <returns></returns>
//List<T> GetAll(bool useCache = false, int cacheSecond = 3600);
/// <summary>
/// 获得一条数据
/// </summary>
/// <param name="where">Expression<Func<T, bool>></param>
/// <returns></returns>
T GetFirst(Expression<Func<T, bool>> where);
///// <summary>
///// 获得一条数据
///// </summary>
///// <param name="where">Expression<Func<T, bool>></param>
///// <returns></returns>
//T GetFirst(Expression<Func<T, bool>> where);
/// <summary>
/// 获得一条数据
/// </summary>
/// <param name="parm">string</param>
/// <returns></returns>
T GetFirst(string parm);
///// <summary>
///// 获得一条数据
///// </summary>
///// <param name="parm">string</param>
///// <returns></returns>
//T GetFirst(string parm);
/// <summary>
/// 根据条件查询分页数据
/// </summary>
/// <param name="where"></param>
/// <param name="parm"></param>
/// <returns></returns>
PagedInfo<T> GetPages(Expression<Func<T, bool>> where, Model.PagerInfo parm);
///// <summary>
///// 根据条件查询分页数据
///// </summary>
///// <param name="where"></param>
///// <param name="parm"></param>
///// <returns></returns>
//PagedInfo<T> GetPages(Expression<Func<T, bool>> where, Model.PagerInfo parm);
/// <summary>
/// 根据条件查询分页
/// </summary>
/// <param name="where"></param>
/// <param name="parm"></param>
/// <param name="order"></param>
/// <param name="orderEnum"></param>
/// <returns></returns>
PagedInfo<T> GetPages(Expression<Func<T, bool>> where, Model.PagerInfo parm, Expression<Func<T, object>> order, string orderEnum = "Asc");
///// <summary>
///// 根据条件查询分页
///// </summary>
///// <param name="where"></param>
///// <param name="parm"></param>
///// <param name="order"></param>
///// <param name="orderEnum"></param>
///// <returns></returns>
//PagedInfo<T> GetPages(Expression<Func<T, bool>> where, Model.PagerInfo parm, Expression<Func<T, object>> order, string orderEnum = "Asc");
/// <summary>
/// 根据条件查询数据
/// </summary>
/// <param name="where">条件表达式树</param>
/// <returns></returns>
List<T> GetWhere(Expression<Func<T, bool>> where, bool useCache = false, int cacheSecond = 3600);
///// <summary>
///// 根据条件查询数据
///// </summary>
///// <param name="where">条件表达式树</param>
///// <returns></returns>
////List<T> GetWhere(Expression<Func<T, bool>> where, bool useCache = false, int cacheSecond = 3600);
/// <summary>
/// 根据条件查询数据
/// </summary>
/// <param name="where">条件表达式树</param>
/// <returns></returns>
List<T> GetWhere(Expression<Func<T, bool>> where, Expression<Func<T, object>> order, string orderEnum = "Asc", bool useCache = false, int cacheSecond = 3600);
/////// <summary>
/////// 根据条件查询数据
/////// </summary>
/////// <param name="where">条件表达式树</param>
/////// <returns></returns>
////List<T> GetWhere(Expression<Func<T, bool>> where, Expression<Func<T, object>> order, string orderEnum = "Asc", bool useCache = false, int cacheSecond = 3600);
#endregion
//#endregion
#region 修改操作
//#region 修改操作
/// <summary>
/// 修改一条数据
/// </summary>
/// <param name="parm">T</param>
/// <returns></returns>
int Update(T parm);
///// <summary>
///// 修改一条数据
///// </summary>
///// <param name="parm">T</param>
///// <returns></returns>
//int Update(T parm);
/// <summary>
/// 批量修改
/// </summary>
/// <param name="parm">T</param>
/// <returns></returns>
int Update(List<T> parm);
///// <summary>
///// 批量修改
///// </summary>
///// <param name="parm">T</param>
///// <returns></returns>
//int Update(List<T> parm);
/// <summary>
/// 按查询条件更新
/// </summary>
/// <param name="where"></param>
/// <param name="columns"></param>
/// <returns></returns>
int Update(Expression<Func<T, bool>> where, Expression<Func<T, T>> columns);
///// <summary>
///// 按查询条件更新
///// </summary>
///// <param name="where"></param>
///// <param name="columns"></param>
///// <returns></returns>
//int Update(Expression<Func<T, bool>> where, Expression<Func<T, T>> columns);
#endregion
//#endregion
#region 删除操作
//#region 删除操作
/// <summary>
/// 删除一条或多条数据
/// </summary>
/// <param name="parm">string</param>
/// <returns></returns>
int Delete(object id);
///// <summary>
///// 删除一条或多条数据
///// </summary>
///// <param name="parm">string</param>
///// <returns></returns>
//int Delete(object id);
/// <summary>
/// 删除一条或多条数据
/// </summary>
/// <param name="parm">string</param>
/// <returns></returns>
int Delete(object[] ids);
///// <summary>
///// 删除一条或多条数据
///// </summary>
///// <param name="parm">string</param>
///// <returns></returns>
//int Delete(object[] ids);
/// <summary>
/// 根据条件删除一条或多条数据
/// </summary>
/// <param name="where">过滤条件</param>
/// <returns></returns>
int Delete(Expression<Func<T, bool>> where);
/// <summary>
/// 清空表
/// </summary>
/// <returns></returns>
int DeleteTable();
///// <summary>
///// 根据条件删除一条或多条数据
///// </summary>
///// <param name="where">过滤条件</param>
///// <returns></returns>
//int Delete(Expression<Func<T, bool>> where);
///// <summary>
///// 清空表
///// </summary>
///// <returns></returns>
//int DeleteTable();
#endregion
}
+1 -1
View File
@@ -10,7 +10,7 @@ namespace ZR.Service.System
/// 文章目录
/// </summary>
[AppService(ServiceType = typeof(IArticleCategoryService), ServiceLifetime = LifeTime.Transient)]
public class ArticleCategoryService : IArticleCategoryService
public class ArticleCategoryService : BaseService<ArticleCategory>, IArticleCategoryService
{
/// <summary>
/// 构建前端所需要树结构
+1 -1
View File
@@ -8,7 +8,7 @@ namespace ZR.Service.System
///
/// </summary>
[AppService(ServiceType = typeof(IArticleService), ServiceLifetime = LifeTime.Transient)]
public class ArticleService : IArticleService
public class ArticleService : BaseService<Article>, IArticleService
{
}
+1 -5
View File
@@ -67,11 +67,7 @@ namespace ZR.Service.System
var predicate = Expressionable.Create<GenTable>();
predicate = predicate.AndIF(genTable.TableName.IfNotEmpty(), it => it.TableName.Contains(genTable.TableName));
(List<GenTable>, int) ts = GenTableRepository.QueryableToPage(predicate.ToExpression(), pagerInfo.PageNum, pagerInfo.PageSize);
PagedInfo<GenTable> pagedInfo = new(ts.Item1, pagerInfo.PageNum, pagerInfo.PageSize);
pagedInfo.TotalCount = ts.Item2;
return pagedInfo;
return GenTableRepository.GetPages(predicate.ToExpression(), pagerInfo);
}
/// <summary>
@@ -7,7 +7,7 @@ using ZR.Model.System;
namespace ZR.Service.System.IService
{
public interface IArticleCategoryService //: IBaseService<ArticleCategory>
public interface IArticleCategoryService : IBaseService<ArticleCategory>
{
List<ArticleCategory> BuildCategoryTree(List<ArticleCategory> categories);
}
@@ -8,7 +8,7 @@ using ZR.Model.System;
namespace ZR.Service.System.IService
{
public interface IArticleService //: IBaseService<Article>
public interface IArticleService : IBaseService<Article>
{
}
@@ -6,15 +6,15 @@ using ZR.Model.Vo.System;
namespace ZR.Service.System.IService
{
public interface ISysDeptService //: IBaseService<SysDept>
public interface ISysDeptService : IBaseService<SysDept>
{
public List<SysDept> GetSysDepts(SysDept dept);
public string CheckDeptNameUnique(SysDept dept);
public int InsertDept(SysDept dept);
public int UpdateDept(SysDept dept);
public void UpdateDeptChildren(long deptId, string newAncestors, string oldAncestors);
public List<SysDept> GetChildrenDepts(List<SysDept> depts, long deptId);
public List<SysDept> BuildDeptTree(List<SysDept> depts);
public List<TreeSelectVo> BuildDeptTreeSelect(List<SysDept> depts);
List<SysDept> GetSysDepts(SysDept dept);
string CheckDeptNameUnique(SysDept dept);
int InsertDept(SysDept dept);
int UpdateDept(SysDept dept);
void UpdateDeptChildren(long deptId, string newAncestors, string oldAncestors);
List<SysDept> GetChildrenDepts(List<SysDept> depts, long deptId);
List<SysDept> BuildDeptTree(List<SysDept> depts);
List<TreeSelectVo> BuildDeptTreeSelect(List<SysDept> depts);
}
}
@@ -8,7 +8,7 @@ namespace ZR.Service.System.IService
/// <summary>
///
/// </summary>
public interface ISysDictService : IBaseService<SysDictType>
public interface ISysDictService
{
public List<SysDictType> SelectDictTypeList(SysDictType dictType, Model.PagerInfo pager);
@@ -39,5 +39,12 @@ namespace ZR.Service.System.IService
/// <param name="sysDictType"></param>
/// <returns></returns>
public int UpdateDictType(SysDictType sysDictType);
/// <summary>
/// 获取字典信息
/// </summary>
/// <param name="dictId"></param>
/// <returns></returns>
SysDictType GetInfo(long dictId);
}
}
@@ -6,7 +6,7 @@ using ZR.Repository;
namespace ZR.Service.System.IService
{
public interface ISysPostService: IBaseRepository<SysPost>
public interface ISysPostService : IBaseService<SysPost>
{
string CheckPostNameUnique(SysPost sysPost);
string CheckPostCodeUnique(SysPost sysPost);
@@ -3,7 +3,7 @@ using ZR.Repository;
namespace ZR.Service.System.IService
{
public interface ISysTasksLogService: IBaseRepository<SysTasksLog>
public interface ISysTasksLogService : IBaseService<SysTasksLog>
{
/// <summary>
/// 记录任务执行日志
@@ -7,8 +7,8 @@ using ZR.Model.System;
namespace ZR.Service.System.IService
{
public interface ISysTasksQzService
public interface ISysTasksQzService : IBaseService<SysTasksQz>
{
SysTasksQz GetId(object id);
//SysTasksQz GetId(object id);
}
}
+8 -10
View File
@@ -18,7 +18,7 @@ namespace ZR.Service.System
/// 部门管理
/// </summary>
[AppService(ServiceType = typeof(ISysDeptService), ServiceLifetime = LifeTime.Transient)]
public class SysDeptService :ISysDeptService
public class SysDeptService : BaseService<SysDept>, ISysDeptService
{
public SysDeptRepository DeptRepository;
@@ -76,7 +76,7 @@ namespace ZR.Service.System
}
dept.Ancestors = info.Ancestors + "," + dept.ParentId;
return DeptRepository.Insert(dept, true);
return DeptRepository.Add(dept);
}
/// <summary>
@@ -86,8 +86,8 @@ namespace ZR.Service.System
/// <returns></returns>
public int UpdateDept(SysDept dept)
{
SysDept newParentDept = DeptRepository.GetSingle(it => it.ParentId == dept.ParentId);
SysDept oldDept = DeptRepository.GetSingle(m => m.DeptId == dept.DeptId);
SysDept newParentDept = DeptRepository.GetFirst(it => it.ParentId == dept.ParentId);
SysDept oldDept = DeptRepository.GetFirst(m => m.DeptId == dept.DeptId);
if (newParentDept != null && oldDept != null)
{
string newAncestors = newParentDept.Ancestors + "," + newParentDept.DeptId;
@@ -129,12 +129,10 @@ namespace ZR.Service.System
foreach (var child in children)
{
child.Ancestors = child.Ancestors.Replace(oldAncestors, newAncestors);
if (child.DeptId.Equals(deptId))
{
//TODO Saveable(child, it => new { it.Ancestors });
//DeptRepository.UdateDeptChildren(child);
}
}
if (children.Count > 0)
{
//DeptRepository.UdateDeptChildren(child);
}
}
+1 -1
View File
@@ -37,7 +37,7 @@ namespace ZR.Service.System
public List<SysDictData> SelectDictDataByType(string dictType)
{
string CK = $"SelectDictDataByType_{dictType}";
if (!(CacheHelper.GetCache(CK) is List<SysDictData> list))
if (CacheHelper.GetCache(CK) is not List<SysDictData> list)
{
list = SysDictDataRepository.SelectDictDataByType(dictType);
CacheHelper.SetCache(CK, list, 30);
+12 -2
View File
@@ -13,7 +13,7 @@ namespace ZR.Service.System
/// 字典类型
/// </summary>
[AppService(ServiceType = typeof(ISysDictService), ServiceLifetime = LifeTime.Transient)]
public class SysDictService : BaseService<SysDictType>, ISysDictService
public class SysDictService : ISysDictService
{
private SysDictRepository DictRepository;
private SysDictDataRepository DictDataRepository;
@@ -79,7 +79,7 @@ namespace ZR.Service.System
/// <returns></returns>
public long InsertDictType(SysDictType sysDictType)
{
return DictRepository.InsertReturnEntity(sysDictType).DictId;
return DictRepository.InsertReturnBigIdentity(sysDictType);
}
/// <summary>
@@ -97,5 +97,15 @@ namespace ZR.Service.System
}
return DictRepository.UpdateDictType(sysDictType);
}
/// <summary>
/// 获取字典信息
/// </summary>
/// <param name="dictId"></param>
/// <returns></returns>
public SysDictType GetInfo(long dictId)
{
return DictRepository.GetFirst(f => f.DictId == dictId);
}
}
}
+1 -1
View File
@@ -13,7 +13,7 @@ namespace ZR.Service.System
/// 岗位管理
/// </summary>
[AppService(ServiceType = typeof(ISysPostService), ServiceLifetime = LifeTime.Transient)]
public class SysPostService : BaseRepository<SysPost>, ISysPostService
public class SysPostService : BaseService<SysPost>, ISysPostService
{
public SysPostRepository PostRepository;
public SysPostService(SysPostRepository postRepository)
+1 -1
View File
@@ -28,7 +28,7 @@ namespace ZR.Service.System
logModel.CreateTime = DateTime.Now;
}
Insert(logModel, true);
Add(logModel);
return logModel;
}
}
+1 -1
View File
@@ -5,7 +5,7 @@ using ZR.Service.System.IService;
namespace ZR.Service.System
{
[AppService(ServiceType = typeof(ISysTasksQzService), ServiceLifetime = LifeTime.Transient)]
public class SysTasksQzService : ISysTasksQzService
public class SysTasksQzService : BaseService<SysTasksQz>, ISysTasksQzService
{
}