using System.Collections.Generic;
using System.Data;
using System.Threading.Tasks;
using Znyc.Admin.Commons.Cache;
using Znyc.Admin.Commons.Dtos;
using Znyc.Admin.Commons.Mapping;
using Znyc.Admin.Commons.Pages;
using Znyc.Admin.Commons.Services;
using Znyc.Admin.Security.Dtos;
using Znyc.Admin.Security.Entitys;
using Znyc.Admin.Security.IRepositories;
using Znyc.Admin.Security.IServices;
namespace Znyc.Admin.Security.Services
{
///
///
///
public class APPService : BaseService, IAPPService
{
private readonly IAPPRepository _appRepository;
public APPService(IAPPRepository repository) : base(repository)
{
_appRepository = repository;
}
///
/// 同步新增实体。
///
/// 实体
/// 事务对象
///
public override long Insert(APP entity, IDbTransaction trans = null)
{
long result = repository.Insert(entity, trans);
UpdateCacheAllowApp();
return result;
}
///
/// 异步更新实体。
///
/// 实体
/// 主键ID
/// 事务对象
///
public override async Task UpdateAsync(APP entity, long id, IDbTransaction trans = null)
{
bool result = await repository.UpdateAsync(entity, id, trans);
UpdateCacheAllowApp();
return result;
}
///
/// 异步步新增实体。
///
/// 实体
/// 事务对象
///
public override async Task InsertAsync(APP entity, IDbTransaction trans = null)
{
int result = await repository.InsertAsync(entity, trans);
UpdateCacheAllowApp();
return result;
}
///
/// 获取app对象
///
/// 应用ID
/// 应用密钥AppSecret
///
public APP GetAPP(string appid, string secret)
{
return _appRepository.GetAPP(appid, secret);
}
///
/// 获取app对象
///
/// 应用ID
///
public APP GetAPP(string appid)
{
return _appRepository.GetAPP(appid);
}
public IList SelectApp()
{
return _appRepository.SelectApp();
}
///
/// 根据条件查询数据库,并返回对象集合(用于分页数据显示)
///
/// 查询的条件
/// 指定对象的集合
public override async Task> FindWithPagerAsync(SearchInputDto search)
{
bool order = search.Order == "asc" ? false : true;
string where = GetDataPrivilege(false);
if (!string.IsNullOrEmpty(search.Keywords))
{
@where += string.Format(" and (AppId like '%{0}%' or RequestUrl like '%{0}%')", search.Keywords);
};
PagerInfo pagerInfo = new PagerInfo
{
CurrenetPageIndex = search.CurrenetPageIndex,
PageSize = search.PageSize
};
List list = await repository.FindWithPagerAsync(where, pagerInfo, search.Sort, order);
PageResult pageResult = new PageResult
{
CurrentPage = pagerInfo.CurrenetPageIndex,
Items = list.MapTo(),
ItemsPerPage = pagerInfo.PageSize,
TotalItems = pagerInfo.RecordCount
};
return pageResult;
}
public void UpdateCacheAllowApp()
{
CacheHelper cacheHelper = new CacheHelper();
IEnumerable appList = repository.GetAllByIsNotDeleteAndEnabledMark();
cacheHelper.Add("AllowAppId", appList);
}
}
}