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.
162 lines
5.8 KiB
162 lines
5.8 KiB
using COSSTS;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Threading.Tasks;
|
|
using Znyc.Cloudcar.Admin.Commons.Cache;
|
|
using Znyc.Cloudcar.Admin.Commons.Core.App;
|
|
using Znyc.Cloudcar.Admin.Commons.Cos;
|
|
using Znyc.Cloudcar.Admin.Commons.Dtos;
|
|
using Znyc.Cloudcar.Admin.Commons.Entitys;
|
|
using Znyc.Cloudcar.Admin.Commons.Mapping;
|
|
using Znyc.Cloudcar.Admin.Commons.Pages;
|
|
using Znyc.Cloudcar.Admin.Commons.Services;
|
|
using Znyc.Cloudcar.Admin.Security.Dtos;
|
|
using Znyc.Cloudcar.Admin.Security.Dtos.Document;
|
|
using Znyc.Cloudcar.Admin.Security.Entitys;
|
|
using Znyc.Cloudcar.Admin.Security.IRepositories;
|
|
using Znyc.Cloudcar.Admin.Security.IServices;
|
|
|
|
namespace Znyc.Cloudcar.Admin.Security.Services
|
|
{
|
|
/// <summary>
|
|
/// </summary>
|
|
public class APPService : BaseService<APPEntity, AppOutputDto, long>, IAPPService
|
|
{
|
|
private readonly IAPPRepository _appRepository;
|
|
private static CosOptions _cosOptions;
|
|
|
|
public APPService(IAPPRepository repository) : base(repository)
|
|
{
|
|
_appRepository = repository;
|
|
_cosOptions = App.GetService<CosOptions>();
|
|
if (_cosOptions == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(_cosOptions));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 同步新增实体。
|
|
/// </summary>
|
|
/// <param name="entity">实体</param>
|
|
/// <param name="trans">事务对象</param>
|
|
/// <returns></returns>
|
|
public override long Insert(APPEntity 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(APPEntity 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(APPEntity 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 APPEntity GetAPP(string appid, string secret)
|
|
{
|
|
return _appRepository.GetAPP(appid, secret);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取app对象
|
|
/// </summary>
|
|
/// <param name="appid">应用ID</param>
|
|
/// <returns></returns>
|
|
public APPEntity 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<APPEntity> 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<APPEntity> 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<APPEntity> appList = repository.GetAllByIsNotDeleteAndEnabledMark();
|
|
cacheHelper.Add("AllowAppId", appList);
|
|
}
|
|
|
|
public CommonResult GetCosToken()
|
|
{
|
|
CommonResult result = new CommonResult();
|
|
Dictionary<string, object> values = new()
|
|
{
|
|
["bucket"] = _cosOptions.Bucket,
|
|
["region"] = _cosOptions.Region,
|
|
["allowPrefix"] = _cosOptions.AllowPrefix,
|
|
["allowActions"] = _cosOptions.AllowActions,
|
|
["durationSeconds"] = _cosOptions.DurationSeconds,
|
|
["secretId"] = _cosOptions.SecretId,
|
|
["secretKey"] = _cosOptions.SecretKey
|
|
};
|
|
Dictionary<string, object> credential = STSClient.genCredential(values);
|
|
result.ResData = JsonConvert.DeserializeObject<ImageOutput>(JsonConvert.SerializeObject(credential));
|
|
result.ErrCode = "0";
|
|
result.Success = true;
|
|
return result;
|
|
}
|
|
}
|
|
}
|