|
|
using Myshipping.Core;
|
|
|
using Furion.DependencyInjection;
|
|
|
using Furion.DynamicApiController;
|
|
|
using Mapster;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using SqlSugar;
|
|
|
using System.Linq;
|
|
|
using System.Threading.Tasks;
|
|
|
using Myshipping.Core.Entity;
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
using System;
|
|
|
using Furion.DataEncryption;
|
|
|
|
|
|
namespace Myshipping.Core.Service
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 接口授权服务
|
|
|
/// </summary>
|
|
|
[ApiDescriptionSettings(Name = "DjyApiAuth", Order = 1)]
|
|
|
public class DjyApiAuthService : IDjyApiAuthService, IDynamicApiController, ITransient
|
|
|
{
|
|
|
private readonly SqlSugarRepository<DjyApiAuth> _rep;
|
|
|
private readonly ILogger<DjyApiAuth> _logger;
|
|
|
|
|
|
public DjyApiAuthService(SqlSugarRepository<DjyApiAuth> rep, ILogger<DjyApiAuth> logger)
|
|
|
{
|
|
|
_rep = rep;
|
|
|
_logger = logger;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 分页查询接口授权
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/DjyApiAuth/page")]
|
|
|
public async Task<dynamic> Page([FromQuery] QueryDjyApiAuthInput input)
|
|
|
{
|
|
|
var entities = await _rep.AsQueryable().Filter(null, true).Where(x => x.IsDeleted == false)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ApiCode), u => u.ApiCode.Contains(input.ApiCode))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.ApiName), u => u.ApiName.Contains(input.ApiName))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.TenantName), u => u.TenantName == input.TenantName)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.UserName), u => u.UserName == input.UserName)
|
|
|
.WhereIF(input.IsDisable.HasValue, u => u.IsDisable == input.IsDisable.Value)
|
|
|
.ToPagedListAsync(input.PageNo, input.PageSize);
|
|
|
return entities.XnPagedResult();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 保存授权
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/DjyApiAuth/save")]
|
|
|
public async Task<long> Save(SaveDjyApiAuthInput input)
|
|
|
{
|
|
|
DjyApiAuth entity = null;
|
|
|
if (input.Id == 0)
|
|
|
{
|
|
|
entity = input.Adapt<DjyApiAuth>();
|
|
|
entity.ApiKey = Guid.NewGuid().ToString().Replace("-", "").ToLower();
|
|
|
entity.ApiSecret = GenSecret();
|
|
|
await _rep.InsertAsync(entity);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
entity = _rep.AsQueryable().Filter(null, true).First(x => x.Id == input.Id);
|
|
|
input.Adapt(entity);
|
|
|
await _rep.UpdateAsync(entity);
|
|
|
}
|
|
|
return entity.Id;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除接口授权
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/DjyApiAuth/delete")]
|
|
|
public async Task Delete(GetDjyApiAuthInput input)
|
|
|
{
|
|
|
var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
|
|
|
await _rep.DeleteAsync(entity);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取接口授权
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("/DjyApiAuth/detail")]
|
|
|
public async Task<DjyApiAuth> Get([FromQuery] GetDjyApiAuthInput input)
|
|
|
{
|
|
|
return await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 重置秘钥
|
|
|
/// </summary>
|
|
|
/// <param name="id"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/DjyApiAuth/SecretReset")]
|
|
|
public async Task<string> SecretReset(long id)
|
|
|
{
|
|
|
var entity = _rep.AsQueryable().Filter(null, true).First(x => x.Id == id);
|
|
|
entity.ApiSecret = GenSecret();
|
|
|
await _rep.UpdateAsync(entity);
|
|
|
return entity.ApiSecret;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 启用禁用
|
|
|
/// </summary>
|
|
|
/// <param name="id"></param>
|
|
|
/// <param name="disable">可用:false,禁用:true</param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("/DjyApiAuth/SetDisable")]
|
|
|
public async Task SetDisable(long id, bool disable)
|
|
|
{
|
|
|
var entity = _rep.AsQueryable().Filter(null, true).First(x => x.Id == id);
|
|
|
entity.IsDisable = disable;
|
|
|
await _rep.UpdateAsync(entity);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 生成新秘钥
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
[NonAction]
|
|
|
private string GenSecret()
|
|
|
{
|
|
|
return DESCEncryption.Encrypt(Guid.NewGuid().ToString(), "13245687").ToLower();
|
|
|
}
|
|
|
|
|
|
///// <summary>
|
|
|
///// 获取接口授权列表
|
|
|
///// </summary>
|
|
|
///// <param name="input"></param>
|
|
|
///// <returns></returns>
|
|
|
//[HttpGet("/DjyApiAuth/list")]
|
|
|
//public async Task<dynamic> List([FromQuery] QueryDjyApiAuthInput input)
|
|
|
//{
|
|
|
// return await _rep.ToListAsync();
|
|
|
//}
|
|
|
}
|
|
|
}
|