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);
}
}
}