using System.Collections.Generic;
using System.Threading.Tasks;
using Znyc.Admin.Commons.Entitys;
using Znyc.Admin.Commons.IServices;
using Znyc.Admin.Commons.Pages;
namespace Znyc.Admin.Commons.Application
{
///
/// 业务层基类,Service用于普通的数据库操作
///
/// 实体类型
/// 实体类型
/// Service类型
/// 主键类型
public class BaseApp
where T : Entity
where TDto : class
where TService : IService
{
///
/// 用于普通的数据库操作
///
/// The service.
protected IService service;
///
///
///
///
public BaseApp(IService _service)
{
service = _service;
}
///
/// 同步物理删除实体。
///
/// 实体
///
public virtual bool Delete(T entity)
{
return service.Delete(entity, null);
}
///
/// 同步物理删除实体。
///
/// 主键
///
public virtual bool Delete(Tkey id)
{
return service.Delete(id, null);
}
///
/// 异步物理删除实体。
///
/// 主键
///
public virtual Task DeleteAsync(Tkey id)
{
return service.DeleteAsync(id, null);
}
///
/// 异步物理删除实体。
///
/// 实体
///
public virtual Task DeleteAsync(T entity)
{
return service.DeleteAsync(entity, null);
}
///
/// 按主键批量删除
///
///
///
public virtual bool DeleteBatch(IList ids)
{
return service.DeleteBatch(ids, null);
}
///
/// 按条件批量删除
///
/// 条件
///
public virtual bool DeleteBatchWhere(string where)
{
return service.DeleteBatchWhere(where, null);
}
///
/// 软删除信息,将IsDeleted设置为1-删除,0-恢复删除
///
/// true为不删除,false删除
/// 主键ID
/// 操作用户
///
public virtual bool DeleteSoft(bool bl, Tkey id, int userId)
{
return service.DeleteSoft(bl, id, userId, null);
}
///
/// 异步软删除信息,将IsDeleted设置为1-删除,0-恢复删除
///
/// true为不删除,false删除
/// 主键ID
/// 操作用户
///
public virtual Task DeleteSoftAsync(bool bl, Tkey id, int userId)
{
return service.DeleteSoftAsync(bl, id, userId, null);
}
///
/// 同步查询单个实体。
///
/// 主键
///
public virtual T Get(Tkey id)
{
return service.Get(id);
}
///
/// 同步查询单个实体。
///
/// 查询条件
///
public virtual T GetWhere(string where)
{
return service.GetWhere(where, null);
}
///
/// 异步查询单个实体。
///
/// 查询条件
///
public virtual async Task GetWhereAsync(string where)
{
return await service.GetWhereAsync(where, null);
}
///
/// 根据查询条件查询前多少条数据
///
/// 多少条数据
/// 查询条件
///
public virtual IEnumerable GetListTopWhere(int top, string where = null)
{
return service.GetListTopWhere(top, where);
}
///
/// 同步查询所有实体。
///
///
public virtual IEnumerable GetAll()
{
return service.GetAll(null);
}
///
/// 异步步查询所有实体。
///
///
public virtual Task> GetAllAsync()
{
return service.GetAllAsync(null);
}
///
///
///
///
///
public virtual Task GetAsync(Tkey id)
{
return service.GetAsync(id);
}
///
/// 根据查询条件查询数据
///
/// 查询条件
///
public virtual IEnumerable GetListWhere(string where = null)
{
return service.GetListWhere(where, null);
}
///
/// 异步根据查询条件查询数据
///
/// 查询条件
///
public virtual async Task> GetListWhereAsync(string where = null)
{
return await service.GetListWhereAsync(where, null);
}
///
/// 同步新增实体。
///
/// 实体
///
public virtual long Insert(T entity)
{
return service.Insert(entity, null);
}
///
/// 异步步新增实体。
///
/// 实体
///
public virtual Task InsertAsync(T entity)
{
return service.InsertAsync(entity, null);
}
///
/// 同步更新实体。
///
/// 实体
/// 主键ID
///
public virtual bool Update(T entity, Tkey id)
{
return service.Update(entity, id, null);
}
///
/// 异步更新实体。
///
/// 实体
/// 主键ID
///
public virtual Task UpdateAsync(T entity, Tkey id)
{
return service.UpdateAsync(entity, id, null);
}
///
/// 更新某一字段值
///
/// 字段
/// 字段值
/// 条件,为空更新所有内容
///
public virtual bool UpdateTableField(string strField, string fieldValue, string where)
{
return service.UpdateTableField(strField, fieldValue, where, null);
}
///
/// 查询软删除的数据,如果查询条件为空,即查询所有软删除的数据
///
/// 查询条件
///
public virtual IEnumerable GetAllByIsIsDeleted(string where = null)
{
return service.GetAllByIsIsDeleted(where, null);
}
///
/// 查询未软删除的数据,如果查询条件为空,即查询所有未软删除的数据
///
/// 查询条件
///
public virtual IEnumerable GetAllByIsNotIsDeleted(string where = null)
{
return service.GetAllByIsNotIsDeleted(where, null);
}
///
/// 查询有效的数据,如果查询条件为空,即查询所有有效的数据
///
/// 查询条件
///
public virtual IEnumerable GetAllByIsEnabledMark(string where = null)
{
return service.GetAllByIsEnabledMark(where, null);
}
///
/// 查询无效的数据,如果查询条件为空,即查询所有无效的数据
///
/// 查询条件
///
public virtual IEnumerable GetAllByIsNotEnabledMark(string where = null)
{
return service.GetAllByIsNotEnabledMark(where, null);
}
///
/// 查询未软删除且有效的数据,如果查询条件为空,即查询所有数据
///
/// 查询条件
///
public virtual IEnumerable GetAllByIsNotDeleteAndEnabledMark(string where = null)
{
return service.GetAllByIsNotDeleteAndEnabledMark(where, null);
}
///
/// 查询软删除的数据,如果查询条件为空,即查询所有软删除的数据
///
/// 查询条件
///
public virtual async Task> GetAllByIsIsDeletedAsync(string where = null)
{
return await service.GetAllByIsIsDeletedAsync(where, null);
}
///
/// 查询未软删除的数据,如果查询条件为空,即查询所有未软删除的数据
///
/// 查询条件
///
public virtual async Task> GetAllByIsNotIsDeletedAsync(string where = null)
{
return await service.GetAllByIsNotIsDeletedAsync(where, null);
}
///
/// 查询有效的数据,如果查询条件为空,即查询所有有效的数据
///
/// 查询条件
///
public virtual async Task> GetAllByIsEnabledMarkAsync(string where = null)
{
return await service.GetAllByIsEnabledMarkAsync(where, null);
}
///
/// 查询无效的数据,如果查询条件为空,即查询所有无效的数据
///
/// 查询条件
///
public virtual async Task> GetAllByIsNotEnabledMarkAsync(string where = null)
{
return await service.GetAllByIsNotEnabledMarkAsync(where, null);
}
///
/// 查询未软删除且有效的数据,如果查询条件为空,即查询所有数据
///
/// 查询条件
///
public virtual async Task> GetAllByIsNotDeleteAndEnabledMarkAsync(string where = null)
{
return await service.GetAllByIsNotDeleteAndEnabledMarkAsync(where, null);
}
///
/// 设置数据有效性,将IsEnabled设置为1:有效,0-为无效
///
/// true为有效,false无效
/// 主键ID
/// 操作用户
///
public virtual bool SetEnabledMark(bool bl, Tkey id, int userId = 0)
{
return service.SetEnabledMark(bl, id, userId, null);
}
///
/// 异步设置数据有效性,将IsEnabled设置为1:有效,0-为无效
///
/// true为有效,false无效
/// 主键ID
/// 操作用户
///
public virtual async Task SetEnabledMarkAsync(bool bl, Tkey id, int userId = 0)
{
return await service.SetEnabledMarkAsync(bl, id, userId, null);
}
///
/// 根据条件查询数据库,并返回对象集合(用于分页数据显示)
///
/// 查询的条件
/// 分页实体
/// 指定对象的集合
public virtual List FindWithPager(string condition, PagerInfo info)
{
return service.FindWithPager(condition, info, null);
}
///
/// 根据条件查询数据库,并返回对象集合(用于分页数据显示)
///
/// 查询的条件
/// 分页实体
/// 排序字段
/// 指定对象的集合
public virtual List FindWithPager(string condition, PagerInfo info, string fieldToSort)
{
return service.FindWithPager(condition, info, fieldToSort, null);
}
///
/// 根据条件查询数据库,并返回对象集合(用于分页数据显示)
///
/// 查询的条件
/// 分页实体
/// 排序字段
/// 是否降序
/// 指定对象的集合
public virtual List FindWithPager(string condition, PagerInfo info, string fieldToSort, bool desc)
{
return service.FindWithPager(condition, info, fieldToSort, desc, null);
}
///
/// 分页查询,自行封装sql语句
///
/// 查询条件
/// 分页信息
/// 排序字段
/// 排序方式 true为desc,false为asc
///
public virtual List FindWithPagerSql(string condition, PagerInfo info, string fieldToSort, bool desc)
{
return service.FindWithPagerSql(condition, info, fieldToSort, desc, null);
}
///
/// 分页查询包含用户信息
/// 查询主表别名为t1,用户表别名为t2,在查询字段需要注意使用t1.xxx格式,xx表示主表字段
/// 用户信息主要有用户账号:Account、昵称:UserName、真实姓名:RealName、头像:HeadIcon、手机号:MobilePhone
/// 输出对象请在Dtos中进行自行封装,不能是使用实体Model类
///
/// 查询条件字段需要加表别名
/// 分页信息
/// 排序字段,也需要加表别名
/// 排序方式
///
public virtual List