2024-05-11 10:11:42 +00:00
|
|
|
|
using Admin.NET.Core.Service;
|
|
|
|
|
using Admin.NET.Application.Const;
|
|
|
|
|
using Admin.NET.Application.Entity;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
namespace Admin.NET.Application;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 网址信息服务
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiDescriptionSettings(ApplicationConst.GroupName, Order = 100)]
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
public class UrlInfoService : IDynamicApiController, ITransient
|
|
|
|
|
{
|
|
|
|
|
private readonly SqlSugarRepository<UrlInfo> _rep;
|
|
|
|
|
public UrlInfoService(SqlSugarRepository<UrlInfo> rep)
|
|
|
|
|
{
|
|
|
|
|
_rep = rep;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 分页查询网址信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ApiDescriptionSettings(Name = "Page")]
|
|
|
|
|
public async Task<SqlSugarPagedList<UrlInfoOutput>> Page(UrlInfoInput input)
|
|
|
|
|
{
|
2024-05-20 10:06:52 +00:00
|
|
|
|
var query = _rep.AsQueryable().Where(a => !a.IsDelete)
|
2024-05-11 10:11:42 +00:00
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), u =>
|
|
|
|
|
u.Name.Contains(input.SearchKey.Trim())
|
|
|
|
|
|| u.Url.Contains(input.SearchKey.Trim())
|
|
|
|
|
|| u.UrlType.Contains(input.SearchKey.Trim())
|
|
|
|
|
)
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Name), u => u.Name.Contains(input.Name.Trim()))
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Url), u => u.Url.Contains(input.Url.Trim()))
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.UrlType), u => u.UrlType.Contains(input.UrlType.Trim()))
|
|
|
|
|
.Select<UrlInfoOutput>();
|
|
|
|
|
return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 增加网址信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ApiDescriptionSettings(Name = "Add")]
|
|
|
|
|
public async Task<long> Add(AddUrlInfoInput input)
|
|
|
|
|
{
|
|
|
|
|
var entity = input.Adapt<UrlInfo>();
|
|
|
|
|
await _rep.InsertAsync(entity);
|
|
|
|
|
return entity.Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除网址信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ApiDescriptionSettings(Name = "Delete")]
|
|
|
|
|
public async Task Delete(DeleteUrlInfoInput input)
|
|
|
|
|
{
|
|
|
|
|
var entity = await _rep.GetFirstAsync(u => u.Id == input.Id) ?? throw Oops.Oh(ErrorCodeEnum.D1002);
|
|
|
|
|
await _rep.FakeDeleteAsync(entity); //假删除
|
|
|
|
|
//await _rep.DeleteAsync(entity); //真删除
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新网址信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ApiDescriptionSettings(Name = "Update")]
|
|
|
|
|
public async Task Update(UpdateUrlInfoInput input)
|
|
|
|
|
{
|
|
|
|
|
var entity = input.Adapt<UrlInfo>();
|
|
|
|
|
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取网址信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[ApiDescriptionSettings(Name = "Detail")]
|
|
|
|
|
public async Task<UrlInfo> Detail([FromQuery] QueryByIdUrlInfoInput input)
|
|
|
|
|
{
|
|
|
|
|
return await _rep.GetFirstAsync(u => u.Id == input.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取网址信息列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[ApiDescriptionSettings(Name = "List")]
|
|
|
|
|
public async Task<List<UrlInfoOutput>> List()
|
|
|
|
|
{
|
|
|
|
|
return await _rep.AsQueryable().Select<UrlInfoOutput>().ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|