mh_frame_sps/APT.Infrastructure.Api/Service/CommonService.cs

1085 lines
42 KiB
C#
Raw Permalink Normal View History

2026-04-07 13:47:52 +08:00
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using APT.Infrastructure.Core;
namespace APT.Infrastructure.Api
{
public partial class CommonService : DomainServiceBase, ICommonService
{
private IRepository _repository;
public IRepository Repository { get { return _repository; } }
public CommonService(IRepository repository) : base(repository.UnitOfWork)
{
_repository = repository;
}
public IUnitOfWork UnitWork()
{
return Repository.UnitOfWork;
}
public virtual bool AddEntity<T>(T entity) where T : MesEntityBase, new()
{
this.Repository.AddEntity<T>(entity);
return true;
}
public virtual T AddAndGetEntity<T>(T entity) where T : MesEntityBase, new()
{
return this.Repository.AddAndGetEntity<T>(entity);
}
public virtual bool BantchAddEntity<T>(IEnumerable<T> entities) where T : MesEntityBase, new()
{
this.Repository.AddEntities<T>(entities);
return true;
}
/// <summary>
/// 逻辑删除
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public virtual bool DeleteEntity<T>(Guid id) where T : MesEntityBase, new()
{
this.Repository.DeleteEntity<T>(id);
return true;
}
/// <summary>
/// 逻辑删除
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public virtual bool DeleteEntity<T>(Expression<Func<T, bool>> predicate) where T : MesEntityBase, new()
{
this.Repository.DeleteEntity<T>(predicate);
return true;
}
/// <summary>
/// 逻辑删除
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public virtual bool DeleteEntity<T>(IEnumerable<T> entities) where T : MesEntityBase, new()
{
this.Repository.DeleteEntities(entities);
return true;
}
/// <summary>
/// 逻辑批量删除
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="ids"></param>
/// <returns></returns>
public bool BantchDeleteEntity<T>(List<Guid> ids) where T : MesEntityBase, new()
{
if (ids == null || !ids.Any()) return false;
this.Repository.DeleteEntity<T>(t => ids.Contains(t.ID));
return true;
}
/// <summary>
/// 逻辑删除
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public virtual bool DeleteEntity<T>(T entity) where T : MesEntityBase, new()
{
this.Repository.DeleteEntity<T>(entity);
return true;
}
/// <summary>
/// 更新
/// </summary>
/// <param name="entity">实体</param>
/// <returns>是否成功</returns>
public virtual bool UpdateEntity<T>(T entity) where T : MesEntityBase, new()
{
this.Repository.UpdateEntity<T>(entity);
return true;
}
public virtual bool UpdateEntity<T>(T entity, params string[] updateField) where T : MesEntityBase, new()
{
this.Repository.UpdateEntity<T>(entity, true, updateField);
return true;
}
public virtual bool BantchUpdateEntity<T>(IEnumerable<T> entities, params string[] updateField) where T : MesEntityBase, new()
{
this.Repository.UpdateEntities(entities, true, updateField);
return true;
}
/// <summary>
/// 批量更新
/// </summary>
/// <param name="entities">实体集合</param>
/// <returns>是否成功</returns>
public virtual bool BantchUpdateEntity<T>(IEnumerable<T> entities) where T : MesEntityBase, new()
{
this.Repository.UpdateEntities(entities);
return true;
}
/// <summary>
/// 批量更新(新增和保存一起)速度慢
/// </summary>
/// <param name="entities">实体集合</param>
/// <returns>是否成功</returns>
public virtual bool BantchSaveEntity<T>(IEnumerable<T> entities) where T : MesEntityBase, new()
{
//entities.ForEach(i => i.MODIFICATION_TIME = DateTime.Now);
this.Repository.SaveEntities(entities);
return true;
}
#region
/// <summary>
/// 添加实体
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public bool TreeAddEntity<T>(T entity) where T : TreeEntityBase<T>, new()
{
return this.AddEntity<T>(entity);
}
public T TreeAddAndGetEntity<T>(T entity) where T : MesEntityBase, new()
{
return this.AddAndGetEntity<T>(entity);
}
/// <summary>
/// 删除实体
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public bool TreeDeleteEntity<T>(Guid id) where T : TreeEntityBase<T>, new()
{
return this.DeleteEntity<T>(id);
}
/// <summary>
/// 删除实体
/// </summary>
/// <param name="expression"></param>
/// <returns></returns>
public bool TreeDeleteEntity<T>(Expression<Func<T, bool>> expression) where T : TreeEntityBase<T>, new()
{
return this.DeleteEntity<T>(expression);
}
/// <summary>
/// 删除实体
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public bool TreeDeleteEntity<T>(IEnumerable<T> entity) where T : TreeEntityBase<T>, new()
{
return this.DeleteEntity<T>(entity);
}
/// <summary>
/// 删除实体
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="entity"></param>
/// <returns></returns>
public bool TreeDeleteEntity<T>(T entity) where T : TreeEntityBase<T>, new()
{
return this.DeleteEntity<T>(entity);
}
/// <summary>
/// 逻辑批量删除
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="ids"></param>
/// <returns></returns>
public bool TreeBantchDeleteEntity<T>(List<Guid> ids) where T : TreeEntityBase<T>, new()
{
return this.BantchDeleteEntity<T>(ids);
}
/// <summary>
/// 更新实体
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public bool TreeUpdateEntity<T>(T entity) where T : TreeEntityBase<T>, new()
{
return this.UpdateEntity<T>(entity);
}
/// <summary>
/// 批量添加实体
/// </summary>
/// <param name="entities">实体集合</param>
/// <returns></returns>
public bool TreeBantchAddEntity<T>(IEnumerable<T> entities) where T : TreeEntityBase<T>, new()
{
return this.BantchAddEntity<T>(entities);
}
/// <summary>
/// 批量更新实体
/// </summary>
/// <param name="entities">实体集</param>
/// <returns></returns>
public bool TreeBantchUpdateEntity<T>(IEnumerable<T> entities) where T : TreeEntityBase<T>, new()
{
return this.BantchUpdateEntity<T>(entities);
}
/// <summary>
/// 批量保存实体
/// </summary>
/// <param name="entities">批量保存</param>
/// <returns></returns>
public bool TreeBantchSaveEntity<T>(IEnumerable<T> entities) where T : TreeEntityBase<T>, new()
{
return this.BantchSaveEntity<T>(entities);
}
#endregion
/// <summary>
/// 查询实体
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="id"></param>
/// <param name="paths"></param>
/// <returns></returns>
public T GetEntity<T>(string id, params string[] paths) where T : MesEntityBase, new()
{
var gId = new Guid(id);
return this.GetEntity<T>(t => t.ID == gId, paths);
}
public T GetEntity<T>(Guid id, params string[] paths) where T : MesEntityBase, new()
{
return this.GetEntity<T>(t => t.ID == id, paths);
}
/// <summary>
/// 查询实体
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="expression"></param>
/// <param name="paths"></param>
/// <returns></returns>
public T GetEntity<T>(Expression<Func<T, bool>> expression, params string[] paths) where T : MesEntityBase, new()
{
return this.GetEntity<T>(expression, null, paths);
}
/// <summary>
/// 查询实体
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="expression"></param>
/// <param name="paths"></param>
/// <returns></returns>
public T GetEntity<T>(Expression<Func<T, bool>> expression, BaseFilter filter, params string[] paths)
where T : MesEntityBase, new()
{
return this.GetEntity(expression, filter, (!filter?.IsNoTranking) ?? true, paths);
}
public T GetEntity<T>(Expression<Func<T, bool>> expression, BaseFilter filter, bool isTracking = true, params string[] paths)
where T : MesEntityBase, new()
{
return this.Repository.GetEntity(expression, filter, isTracking, paths);
}
public int GetCount<T>(Expression<Func<T, bool>> expression, BaseFilter filter)
where T : MesEntityBase, new()
{
return this.GetCount<T>(expression, filter);
}
public T GetEntityByRedis<T>(string key, Guid orgid)
where T : MesEntityBase, new()
{
return this.Repository.GetEntityByRedis<T>(key, orgid);
}
public List<T> GetEntitiesByRedis<T>(BaseFilter filter) where T : MesEntityBase, new()
{
return this.Repository.GetEntitiesByRedis<T>(filter).Result;
}
public List<T> GetEntitiesByGroupRedis<T>(BaseFilter filter, string groupValue) where T : MesEntityBase, new()
{
return this.Repository.GetEntitiesByGroupRedis<T>(filter, groupValue).Result;
}
public List<T> GetEntitiesByRedis<T>(Expression<Func<T, bool>> expression, BaseFilter filter) where T : MesEntityBase, new()
{
return this.Repository.GetEntitiesByRedis<T>(expression, filter);
}
public List<T> GetEntitiesTableByRedis<T>(Expression<Func<T, bool>> expression, BaseFilter filter,
params string[] paths) where T : MesEntityBase, new()
{
return this.Repository.GetEntitiesTableByRedis<T>(expression, filter, paths).Result;
}
public List<T> GetEntitiesByRedis<T>(Expression<Func<T, bool>> expression, BaseFilter filter, string groupValue,
params string[] paths) where T : MesEntityBase, new()
{
return this.Repository.GetEntitiesByRedis<T>(expression, filter, groupValue, paths).Result;
}
public PagedResultDto<T> GetOrderPageByRedis<T>(Expression<Func<T, bool>> expression, BasePageFilter pageFilter,
params string[] paths) where T : MesEntityBase, new()
{
return this.Repository.GetOrderPageByRedis<T>(expression, pageFilter, paths);
}
public T GetEntityByRedis<T>(Guid key, Guid orgid)
where T : MesEntityBase, new()
{
return this.Repository.GetEntityByRedis<T>(key, orgid);
}
public IEnumerable<T> GetEntities<T>(Expression<Func<T, bool>> expression,
params string[] paths) where T : MesEntityBase, new()
{
return this.GetEntities<T>(expression, false, paths);
}
public IEnumerable<T> GetEntities<T>(Expression<Func<T, bool>> expression,
bool isTracking = false, params string[] paths) where T : MesEntityBase, new()
{
return this.Repository.GetEntities<T>(expression, null, isTracking, paths);
}
/// <summary>
/// 获取所有数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="expression"></param>
/// <param name="filter"></param>
/// <param name="paths"></param>
/// <returns></returns>
public IEnumerable<T> GetEntities<T>(Expression<Func<T, bool>> expression,
BaseFilter filter, params string[] paths) where T : MesEntityBase, new()
{
return this.Repository.GetEntities<T>(expression, filter, false, paths);
}
public IEnumerable<T> GetEntities<T>(Expression<Func<T, bool>> expression, BaseFilter filter,
bool isTracking = false, params string[] paths) where T : MesEntityBase, new()
{
return this.Repository.GetEntities<T>(expression, filter, isTracking, paths);
}
/// <summary>
/// 获取所有数据
/// </summary>
/// <typeparam name="T">类型</typeparam>
/// <param name="orderBy">排序</param>
/// <param name="expression">lambd表达式</param>
/// <param name="filter">过滤器</param>
/// <param name="paths">需要关联查询的数据</param>
/// <returns></returns>
public IEnumerable<T> GetOrderEntities<T>(Expression<Func<T, bool>> expression,
BaseFilter filter, Action<IOrderable<T>> orderBy, params string[] paths)
where T : MesEntityBase, new()
{
return this.Repository.GetOrderEntities<T>(expression, filter, null, orderBy, false, paths);
}
/// <summary>
/// 获取所有数据
/// </summary>
/// <typeparam name="T">类型</typeparam>
/// <param name="expression">lambd表达式</param>
/// <param name="filter">过滤器</param>
/// <param name="paths">需要关联查询的数据</param>
/// <returns></returns>
public IEnumerable<T> GetOrderEntities<T>
(Expression<Func<T, bool>> expression, BaseFilter filter, params string[] paths) where T : MesEntityBase, new()
{
return this.GetOrderEntities<T>(expression, filter, new Dictionary<string, string>(), paths);
}
public IEnumerable<T> GetOrderEntities<T>(Expression<Func<T, bool>> expression,
BaseFilter filter, Action<IOrderable<T>> orderBy, bool isTracking = false, params string[] paths) where T : MesEntityBase, new()
{
return this.Repository.GetOrderEntities<T>(expression, filter, null, orderBy, isTracking, paths);
}
/// <summary>
/// 排序获取数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="expression"></param>
/// <param name="sort"></param>
/// <param name="order"></param>
/// <param name="filter"></param>
/// <param name="paths"></param>
/// <returns></returns>
public IEnumerable<T> GetOrderEntities<T>(Expression<Func<T, bool>> expression, BaseFilter filter,
string sort, string order, params string[] paths) where T : MesEntityBase, new()
{
Dictionary<string, string> orders = new Dictionary<string, string>();
if (!string.IsNullOrEmpty(sort))
orders[sort] = order;
return this.GetOrderEntities<T>(expression, filter, orders, paths);
}
/// <summary>
/// 排序获取数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="expression"></param>
/// <param name="sort"></param>
/// <param name="order"></param>
/// <param name="filter"></param>
/// <param name="paths"></param>
/// <returns></returns>
public IEnumerable<T> GetOrderEntities<T>(Expression<Func<T, bool>> expression, BaseFilter filter,
Dictionary<string, string> orders, params string[] paths) where T : MesEntityBase, new()
{
return this.GetOrderEntities<T>(expression, filter, orders, null, false, paths);
}
public IEnumerable<T> GetOrderEntities<T>(Expression<Func<T, bool>> expression, BaseFilter filter,
bool isTracking = false, params string[] paths) where T : MesEntityBase, new()
{
return this.GetOrderEntities(expression, filter, null, null, isTracking, paths);
}
public IEnumerable<T> GetOrderEntities<T>(Expression<Func<T, bool>> expression,
BaseFilter filter, Dictionary<string, string> orders, Action<IOrderable<T>> orderBy, bool isTracking = false, params string[] paths) where T : MesEntityBase, new()
{
return this.Repository.GetOrderEntities(expression, filter, orders, orderBy, isTracking, paths);
}
public PagedResultDto<T> GetOrderPageEntities<T>(Expression<Func<T, bool>> expression, BasePageFilter pageFilter,
Action<IOrderable<T>> orderBy,
params string[] paths) where T : MesEntityBase, new()
{
return this.GetOrderPageEntities(expression, pageFilter, null, 0, 0, orderBy, false, paths);
}
public PagedResultDto<T> GetPageEntities<T>(Expression<Func<T, bool>> expression, BasePageFilter pageFilter,
params string[] paths) where T : MesEntityBase, new()
{
return this.Repository.GetPageEntities(expression, pageFilter, paths);
}
public PagedResultDto<T> GetOrderPageEntities<T>(Expression<Func<T, bool>> expression, BasePageFilter pageFilter,
params string[] paths) where T : MesEntityBase, new()
{
return this.GetOrderPageEntities(expression, pageFilter, 0, 0, paths);
}
public PagedResultDto<T> GetOrderPageEntities<T>(Expression<Func<T, bool>> expression, BasePageFilter pageFilter,
int pageSize, int startIndex,
params string[] paths) where T : MesEntityBase, new()
{
return this.GetOrderPageEntities(expression, pageFilter, pageSize, startIndex, (!pageFilter?.IsNoTranking) ?? true, paths);
}
public PagedResultDto<T> GetOrderPageEntities<T>(Expression<Func<T, bool>> expression, BasePageFilter pageFilter,
int pageSize, int startIndex, bool isTracking = false,
params string[] paths) where T : MesEntityBase, new()
{
return this.Repository.GetOrderPageEntities(expression, pageFilter, pageSize, startIndex, isTracking, paths);
}
public IEnumerable<TreeNode<T>> GetTreeOrderEntities<T>(Expression<Func<T, bool>> expression, BaseFilter filter, bool isTracking = false,
params string[] paths) where T : TreeEntityBase<T>, new()
{
return this.Repository.GetTreeOrderEntities(expression, filter, isTracking, paths);
}
public IEnumerable<T> GetTree<T>(string id, bool containCurrent = true, BaseFilter filter = null,
params string[] paths) where T : TreeEntityBase<T>, new()
{
return this.Repository.GetTree<T>(id, containCurrent, filter, paths);
}
public PagedResultDto<T> GetOrderPageEntities<T>(Expression<Func<T, bool>> expression, BasePageFilter pageFilter,
Dictionary<string, string> orders,
int pageSize, int startIndex, bool isTracking = false,
params string[] paths) where T : MesEntityBase, new()
{
return this.Repository.GetOrderPageEntities(expression, pageFilter, orders, pageSize, startIndex, isTracking, paths);
}
public PagedResultDto<T> GetOrderPageEntities<T>(Expression<Func<T, bool>> expression, BasePageFilter pageFilter,
Dictionary<string, string> orders,
int pageSize, int startIndex, Action<IOrderable<T>> orderBy, bool isTracking = false,
params string[] paths) where T : MesEntityBase, new()
{
return this.Repository.GetOrderPageEntities(expression, pageFilter, orders, 0, 0, orderBy, isTracking, paths);
}
public PagedResultDto<T> GetOrderPageEntities<T>(Expression<Func<T, bool>> expression, BasePageFilter pageFilter, string[] selectField,
params string[] paths) where T : MesEntityBase, new()
{
return this.Repository.GetOrderPageEntities(expression, pageFilter, selectField, paths);
}
public async Task<PagedResultDto<T>> GetOrderPageEntitiesSync<T>(Expression<Func<T, bool>> expression, BasePageFilter pageFilter,
params string[] paths) where T : MesEntityBase, new()
{
return await this.GetOrderPageEntitiesSync(expression, pageFilter, 0, 0, paths);
}
public async Task<PagedResultDto<T>> GetOrderPageEntitiesSync<T>(Expression<Func<T, bool>> expression, BasePageFilter pageFilter,
int pageSize, int startIndex,
params string[] paths) where T : MesEntityBase, new()
{
return await this.GetOrderPageEntitiesSync(expression, pageFilter, pageSize, startIndex, false, paths);
}
public async Task<PagedResultDto<T>> GetOrderPageEntitiesSync<T>(Expression<Func<T, bool>> expression, BasePageFilter pageFilter,
int pageSize, int startIndex, bool isTracking = false,
params string[] paths) where T : MesEntityBase, new()
{
return await this.Repository.GetOrderPageEntitiesSync(expression, pageFilter, pageSize, startIndex, isTracking, paths);
}
public async Task<PagedResultDto<T>> GetOrderPageEntitiesSync<T>(Expression<Func<T, bool>> expression, BasePageFilter pageFilter,
Dictionary<string, string> orders,
int pageSize, int startIndex, bool isTracking = false,
params string[] paths) where T : MesEntityBase, new()
{
return await this.Repository.GetOrderPageEntitiesSync(expression, pageFilter, orders, pageSize, startIndex, isTracking, paths);
}
public async Task<PagedResultDto<T>> GetOrderPageEntitiesSync<T>(Expression<Func<T, bool>> expression, BasePageFilter pageFilter,
Dictionary<string, string> orders,
int pageSize, int startIndex, Action<IOrderable<T>> orderBy, bool isTracking = false,
params string[] paths) where T : MesEntityBase, new()
{
return await this.Repository.GetOrderPageEntitiesSync(expression, pageFilter, orders, pageSize, startIndex, orderBy, isTracking, paths);
}
public async Task<PagedResultDto<T>> GetOrderPageEntitiesSync<T>(Expression<Func<T, bool>> expression, BasePageFilter pageFilter,
Action<IOrderable<T>> orderBy,
params string[] paths) where T : MesEntityBase, new()
{
return await this.Repository.GetOrderPageEntitiesSync(expression, pageFilter, null, 0, 0, orderBy, false, paths);
}
public int Count<T>(Expression<Func<T, bool>> expression, BaseFilter filter) where T : MesEntityBase, new()
{
return this.Repository.GetCount<T>(expression, filter);
}
public bool IsAny<T>(Expression<Func<T, bool>> expression, BaseFilter filter) where T : MesEntityBase, new()
{
return this.Repository.IsAny<T>(expression, filter);
}
public int Count<T>(Expression<Func<T, bool>> expression) where T : MesEntityBase, new()
{
return this.Count(expression, null);
}
/// <summary>
/// 提交事务
/// </summary>
/// <param name="comitAction">提交方法</param>
protected void WitCommitTransaction(Action comitAction)
{
try
{
UnitOfWork.BeginTransaction();
comitAction();
UnitOfWork.CommitTransaction();
}
catch
{
try
{
UnitOfWork.RollbackTransaction();
}
catch (Exception ex)
{
LoggerManager.GetLogger().Info("rollback Error" + ex.ToString());
}
throw;
}
}
public T AddAndGetEntity_noneBase<T>(T entity) where T : class
{
return this.Repository.AddAndGetEntity_noneBase<T>(entity);
}
public void AddEntities_noneBase<T>(IEnumerable<T> entities) where T : class
{
this.Repository.AddEntities_noneBase<T>(entities);
}
public void UpdateEntities_noneBase<T>(IEnumerable<T> entities) where T : class
{
if (entities != null && entities.Any())
this.Repository.UpdateEntities_noneBase<T>(entities);
}
public T GetEntity_noneBase<T>(Expression<Func<T, bool>> expressions) where T : class
{
return this.Repository.GetEntity_noneBase(expressions);
}
public List<T> GetEntities_noneBase<T>(Expression<Func<T, bool>> expressions) where T : class
{
return this.Repository.GetEntities_noneBase(expressions);
}
public bool DeleteEntity_noneBase<T>(Expression<Func<T, bool>> expression) where T : class
{
Repository.DeleteEntity_noneBase<T>(expression);
return true;
}
#region nocomit
public bool AddEntityNoCommit<T>(T entity) where T : MesEntityBase, new()
{
this.Repository.AddEntityNoCommit<T>(entity);
return true;
}
public bool BantchAddEntityNoCommit<T>(IEnumerable<T> entities) where T : MesEntityBase, new()
{
this.Repository.AddEntitiesNoCommit<T>(entities);
return true;
}
/// <summary>
/// 逻辑删除
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public bool DeleteEntityNoCommit<T>(Guid id) where T : MesEntityBase, new()
{
this.Repository.DeleteEntityNoCommit<T>(id);
return true;
}
/// <summary>
/// 逻辑删除
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public bool DeleteEntityNoCommit<T>(Expression<Func<T, bool>> predicate) where T : MesEntityBase, new()
{
this.Repository.DeleteEntityNoCommit<T>(predicate);
return true;
}
/// <summary>
/// 逻辑删除
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public bool DeleteEntityNoCommit<T>(IEnumerable<T> entities) where T : MesEntityBase, new()
{
this.Repository.DeleteEntitiesNoCommit(entities);
return true;
}
/// <summary>
/// 逻辑批量删除
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="ids"></param>
/// <returns></returns>
public bool BantchDeleteEntityNoCommit<T>(List<Guid> ids) where T : MesEntityBase, new()
{
if (ids == null || !ids.Any()) return false;
this.Repository.DeleteEntityNoCommit<T>(t => ids.Contains(t.ID));
return true;
}
/// <summary>
/// 逻辑删除
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public bool DeleteEntityNoCommit<T>(T entity) where T : MesEntityBase, new()
{
this.Repository.DeleteEntityNoCommit<T>(entity);
return true;
}
/// <summary>
/// 更新
/// </summary>
/// <param name="entity">实体</param>
/// <returns>是否成功</returns>
public bool UpdateEntityNoCommit<T>(T entity) where T : MesEntityBase, new()
{
this.Repository.UpdateEntityNoCommit<T>(entity);
return true;
}
/// <summary>
/// 批量更新
/// </summary>
/// <param name="entities">实体集合</param>
/// <returns>是否成功</returns>
public bool BantchUpdateEntityNoCommit<T>(IEnumerable<T> entities) where T : MesEntityBase, new()
{
this.Repository.UpdateEntitiesNoCommit(entities);
return true;
}
/// <summary>
/// 批量更新
/// </summary>
/// <param name="entities">实体集合</param>
/// <returns>是否成功</returns>
public bool BantchUpdateEntityNoCommit<T>(IEnumerable<T> entities, params string[] updateField) where T : MesEntityBase, new()
{
this.Repository.UpdateEntitiesNoCommit(entities, updateField);
return true;
}
/// <summary>
/// 更新
/// </summary>
/// <param name="entity">实体</param>
/// <returns>是否成功</returns>
public bool UpdateEntityNoCommit<T>(T entity, params string[] updateField) where T : MesEntityBase, new()
{
this.Repository.UpdateEntityNoCommit<T>(entity, updateField);
return true;
}
/// <summary>
/// 批量更新(新增和保存一起)速度慢
/// </summary>
/// <param name="entities">实体集合</param>
/// <returns>是否成功</returns>
public bool BantchSaveEntityNoCommit<T>(IEnumerable<T> entities) where T : MesEntityBase, new()
{
this.Repository.SaveEntitiesNoCommit(entities);
return true;
}
/// <summary>
/// 统一提交
/// </summary>
/// <param name="comitAction">数据库方法</param>
public void UnifiedCommit(Action comitAction)
{
try
{
comitAction();
UnitOfWork.SaveChanges();
}
catch (Exception ex)
{
LoggerManager.GetLogger().Info("rollback Error" + ex.ToString());
throw;
}
}
/// <summary>
/// 批量添加实体
/// </summary>
/// <param name="entities">实体集合</param>
/// <returns></returns>
public bool TreeBantchAddEntityNoCommit<T>(IEnumerable<T> entities) where T : TreeEntityBase<T>, new()
{
return this.BantchAddEntityNoCommit<T>(entities);
}
/// <summary>
/// 添加实体
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public bool TreeAddEntityNoCommit<T>(T entity) where T : TreeEntityBase<T>, new()
{
return this.AddEntityNoCommit<T>(entity);
}
public T TreeAddAndGetEntityNoCommit<T>(T entity) where T : MesEntityBase, new()
{
return this.AddAndGetEntityNoCommit<T>(entity);
}
public T AddAndGetEntityNoCommit<T>(T entity) where T : MesEntityBase, new()
{
return this.Repository.AddAndGetEntityNoCommit<T>(entity);
}
/// <summary>
/// 删除实体
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public bool TreeDeleteEntityNoCommit<T>(Guid id) where T : TreeEntityBase<T>, new()
{
return this.DeleteEntityNoCommit<T>(id);
}
/// <summary>
/// 删除实体
/// </summary>
/// <param name="expression"></param>
/// <returns></returns>
public bool TreeDeleteEntityNoCommit<T>(Expression<Func<T, bool>> expression) where T : TreeEntityBase<T>, new()
{
return this.DeleteEntityNoCommit<T>(expression);
}
/// <summary>
/// 删除实体
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public bool TreeDeleteEntityNoCommit<T>(IEnumerable<T> entity) where T : TreeEntityBase<T>, new()
{
return this.DeleteEntityNoCommit<T>(entity);
}
/// <summary>
/// 删除实体
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="entity"></param>
/// <returns></returns>
public bool TreeDeleteEntityNoCommit<T>(T entity) where T : TreeEntityBase<T>, new()
{
return this.DeleteEntityNoCommit<T>(entity);
}
/// <summary>
/// 逻辑批量删除
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="ids"></param>
/// <returns></returns>
public bool TreeBantchDeleteEntityNoCommit<T>(List<Guid> ids) where T : TreeEntityBase<T>, new()
{
return this.BantchDeleteEntityNoCommit<T>(ids);
}
/// <summary>
/// 更新实体
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public bool TreeUpdateEntityNoCommit<T>(T entity) where T : TreeEntityBase<T>, new()
{
return this.UpdateEntityNoCommit<T>(entity);
}
/// <summary>
/// 批量更新实体
/// </summary>
/// <param name="entities">实体集</param>
/// <returns></returns>
public bool TreeBantchUpdateEntityNoCommit<T>(IEnumerable<T> entities) where T : TreeEntityBase<T>, new()
{
return this.BantchUpdateEntityNoCommit<T>(entities);
}
/// <summary>
/// 批量保存实体
/// </summary>
/// <param name="entities">批量保存</param>
/// <returns></returns>
public bool TreeBantchSaveEntityNoCommit<T>(IEnumerable<T> entities) where T : TreeEntityBase<T>, new()
{
return this.BantchSaveEntityNoCommit<T>(entities);
}
/// <summary>
/// 根据数据库连接新增数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="entity">实体数据</param>
/// <param name="conn">加密连接</param>
public void AddEntityByConn<T>(T entity, string conn) where T : MesEntityBase, new()
{
this.Repository.AddEntityByConn<T>(entity, conn);
}
/// <summary>
/// 根据数据库连接更新数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="entities">实体数据集合</param>
/// <param name="conn">加密连接</param>
public void UpdateEntitiesByConn<T>(IEnumerable<T> entities, string conn) where T : MesEntityBase, new()
{
this.Repository.UpdateEntitiesByConn<T>(entities, conn);
}
/// <summary>
/// 根据数据库连接更新数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="entity">实体数据</param>
/// <param name="conn">加密连接</param>
/// <param name="updateField">更新字段</param>
public void UpdateEntityByConn<T>(T entity, string conn, params string[] updateField) where T : MesEntityBase, new()
{
this.Repository.UpdateEntityByConn<T>(entity, conn, updateField);
}
/// <summary>
/// 根据数据库连接删除数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="expression">表达式</param>
/// <param name="conn">加密连接</param>
public void DeleteEntityByConn<T>(Expression<Func<T, bool>> expression, string conn) where T : MesEntityBase, new()
{
this.Repository.DeleteEntityByConn<T>(expression, conn);
}
/// <summary>
/// 根据数据库连接删除数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="entity">数据实体</param>
/// <param name="conn">加密连接</param>
public void DeleteEntityByConn<T>(T entity, string conn) where T : MesEntityBase, new()
{
this.Repository.DeleteEntityByConn<T>(entity, conn);
}
/// <summary>
/// 根据数据库连接删除数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="id">主键</param>
/// <param name="conn">加密连接</param>
public void DeleteEntityByConn<T>(Guid id, string conn) where T : MesEntityBase, new()
{
this.Repository.DeleteEntityByConn<T>(id, conn);
}
/// <summary>
/// 根据数据库连接删除数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="entities">数据集合</param>
/// <param name="conn">加密连接</param>
public void DeleteEntitiesByConn<T>(IEnumerable<T> entities, string conn) where T : MesEntityBase, new()
{
this.Repository.DeleteEntitiesByConn<T>(entities, conn);
}
/// <summary>
/// 根据数据库连接新增数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="entities">数据集合</param>
/// <param name="conn">加密连接</param>
public void AddEntitiesByConn<T>(IEnumerable<T> entities, string conn) where T : MesEntityBase, new()
{
this.Repository.AddEntitiesByConn<T>(entities, conn);
}
/// <summary>
/// 根据数据库连接新增数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="entities"></param>
/// <param name="conn"></param>
/// <param name="updateField"></param>
public void UpdateEntitiesByConn<T>(IEnumerable<T> entities, string conn, params string[] updateField) where T : MesEntityBase, new()
{
this.Repository.UpdateEntitiesByConn<T>(entities, conn, updateField);
}
//Tenant
/// <summary>
/// 根据数据库连接新增数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="entity">实体数据</param>
/// <param name="Tenant">加密连接</param>
public void AddEntityByTenant<T>(T entity, string Tenant) where T : MesEntityBase, new()
{
this.Repository.AddEntityByTenant<T>(entity, Tenant);
}
/// <summary>
/// 根据数据库连接更新数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="entities">实体数据集合</param>
/// <param name="Tenant">加密连接</param>
public void UpdateEntitiesByTenant<T>(IEnumerable<T> entities, string Tenant) where T : MesEntityBase, new()
{
this.Repository.UpdateEntitiesByTenant<T>(entities, Tenant);
}
/// <summary>
/// 根据数据库连接更新数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="entity">实体数据</param>
/// <param name="Tenant">加密连接</param>
/// <param name="updateField">更新字段</param>
public void UpdateEntityByTenant<T>(T entity, string Tenant, params string[] updateField) where T : MesEntityBase, new()
{
this.Repository.UpdateEntityByTenant<T>(entity, Tenant, updateField);
}
/// <summary>
/// 根据数据库连接删除数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="expression">表达式</param>
/// <param name="Tenant">加密连接</param>
public void DeleteEntityByTenant<T>(Expression<Func<T, bool>> expression, string Tenant) where T : MesEntityBase, new()
{
this.Repository.DeleteEntityByTenant<T>(expression, Tenant);
}
/// <summary>
/// 根据数据库连接删除数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="entity">数据实体</param>
/// <param name="Tenant">加密连接</param>
public void DeleteEntityByTenant<T>(T entity, string Tenant) where T : MesEntityBase, new()
{
this.Repository.DeleteEntityByTenant<T>(entity, Tenant);
}
/// <summary>
/// 根据数据库连接删除数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="id">主键</param>
/// <param name="Tenant">加密连接</param>
public void DeleteEntityByTenant<T>(Guid id, string Tenant) where T : MesEntityBase, new()
{
this.Repository.DeleteEntityByTenant<T>(id, Tenant);
}
/// <summary>
/// 根据数据库连接删除数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="entities">数据集合</param>
/// <param name="Tenant">加密连接</param>
public void DeleteEntitiesByTenant<T>(IEnumerable<T> entities, string Tenant) where T : MesEntityBase, new()
{
this.Repository.DeleteEntitiesByTenant<T>(entities, Tenant);
}
/// <summary>
/// 根据数据库连接新增数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="entities">数据集合</param>
/// <param name="Tenant">加密连接</param>
public void AddEntitiesByTenant<T>(IEnumerable<T> entities, string Tenant) where T : MesEntityBase, new()
{
this.Repository.AddEntitiesByTenant<T>(entities, Tenant);
}
/// <summary>
/// 根据数据库连接新增数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="entities"></param>
/// <param name="Tenant"></param>
/// <param name="updateField"></param>
public void UpdateEntitiesByTenant<T>(IEnumerable<T> entities, string Tenant, params string[] updateField) where T : MesEntityBase, new()
{
this.Repository.UpdateEntitiesByTenant<T>(entities, Tenant, updateField);
}
#endregion
}
}