You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

130 lines
4.3 KiB

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
{
/// <summary>
///
/// </summary>
public class APPService : BaseService<APP, AppOutputDto, long>, IAPPService
{
private readonly IAPPRepository _appRepository;
public APPService(IAPPRepository repository) : base(repository)
{
_appRepository = repository;
}
/// <summary>
/// 同步新增实体。
/// </summary>
/// <param name="entity">实体</param>
/// <param name="trans">事务对象</param>
/// <returns></returns>
public override long Insert(APP entity, IDbTransaction trans = null)
{
long result = repository.Insert(entity, trans);
UpdateCacheAllowApp();
return result;
}
/// <summary>
/// 异步更新实体。
/// </summary>
/// <param name="entity">实体</param>
/// <param name="id">主键ID</param>
/// <param name="trans">事务对象</param>
/// <returns></returns>
public override async Task<bool> UpdateAsync(APP entity, long id, IDbTransaction trans = null)
{
bool result = await repository.UpdateAsync(entity, id, trans);
UpdateCacheAllowApp();
return result;
}
/// <summary>
/// 异步步新增实体。
/// </summary>
/// <param name="entity">实体</param>
/// <param name="trans">事务对象</param>
/// <returns></returns>
public override async Task<int> InsertAsync(APP entity, IDbTransaction trans = null)
{
int result = await repository.InsertAsync(entity, trans);
UpdateCacheAllowApp();
return result;
}
/// <summary>
/// 获取app对象
/// </summary>
/// <param name="appid">应用ID</param>
/// <param name="secret">应用密钥AppSecret</param>
/// <returns></returns>
public APP GetAPP(string appid, string secret)
{
return _appRepository.GetAPP(appid, secret);
}
/// <summary>
/// 获取app对象
/// </summary>
/// <param name="appid">应用ID</param>
/// <returns></returns>
public APP GetAPP(string appid)
{
return _appRepository.GetAPP(appid);
}
public IList<AppOutputDto> SelectApp()
{
return _appRepository.SelectApp();
}
/// <summary>
/// 根据条件查询数据库,并返回对象集合(用于分页数据显示)
/// </summary>
/// <param name="search">查询的条件</param>
/// <returns>指定对象的集合</returns>
public override async Task<PageResult<AppOutputDto>> FindWithPagerAsync(SearchInputDto<APP> 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<APP> list = await repository.FindWithPagerAsync(where, pagerInfo, search.Sort, order);
PageResult<AppOutputDto> pageResult = new PageResult<AppOutputDto>
{
CurrentPage = pagerInfo.CurrenetPageIndex,
Items = list.MapTo<AppOutputDto>(),
ItemsPerPage = pagerInfo.PageSize,
TotalItems = pagerInfo.RecordCount
};
return pageResult;
}
public void UpdateCacheAllowApp()
{
CacheHelper cacheHelper = new CacheHelper();
IEnumerable<APP> appList = repository.GetAllByIsNotDeleteAndEnabledMark();
cacheHelper.Add("AllowAppId", appList);
}
}
}