using GDZZ.Core;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System.Linq;
using System.Threading.Tasks;
using GDZZ.Application.Entity;
namespace GDZZ.Application
{
///
/// 业务配置服务
///
[ApiDescriptionSettings("Application",Name = "ServiceConfig", Order = 1)]
public class ServiceConfigService : IServiceConfigService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _rep;
public ServiceConfigService(SqlSugarRepository rep)
{
_rep = rep;
}
///
/// 分页查询业务配置
///
///
///
[HttpGet("/ServiceConfig/page")]
public async Task Page([FromQuery] ServiceConfigInput input)
{
var entities = await _rep.AsQueryable()
.WhereIF(!string.IsNullOrWhiteSpace(input.Name), u => u.Name == input.Name)
.WhereIF(!string.IsNullOrWhiteSpace(input.Value), u => u.Value == input.Value)
.ToPagedListAsync(input.PageNo, input.PageSize);
return entities.XnPagedResult();
}
///
/// 增加业务配置
///
///
///
[HttpPost("/ServiceConfig/add")]
public async Task Add(AddServiceConfigInput input)
{
var entity = input.Adapt();
await _rep.InsertAsync(entity);
}
///
/// 删除业务配置
///
///
///
[HttpPost("/ServiceConfig/delete")]
public async Task Delete(DeleteServiceConfigInput input)
{
var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
await _rep.DeleteAsync(entity);
}
///
/// 更新业务配置
///
///
///
[HttpPost("/ServiceConfig/edit")]
public async Task Update(UpdateServiceConfigInput input)
{
var entity = input.Adapt();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns:true).ExecuteCommandAsync();
}
///
/// 获取业务配置
///
///
///
[HttpGet("/ServiceConfig/detail")]
public async Task Get([FromQuery] QueryeServiceConfigInput input)
{
return await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
}
///
/// 获取业务配置列表
///
///
///
[HttpGet("/ServiceConfig/list")]
public async Task List([FromQuery] ServiceConfigInput input)
{
return await _rep.ToListAsync();
}
}
}