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;
using Microsoft.AspNetCore.Authorization;
using GDZZ.Application.Help;
using System;
using Microsoft.Extensions.Options;
namespace GDZZ.Application
{
///
/// 活动广告列表服务
///
[ApiDescriptionSettings("Application",Name = "MiniBanner", Order = 1)]
public class MiniBannerService : IMiniBannerService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _rep;
private readonly SqlSugarRepository AnnexRep;
private readonly UploadFileOptions _options;
public MiniBannerService(SqlSugarRepository rep,
IOptions options,
SqlSugarRepository AnnexRep)
{
_rep = rep;
this.AnnexRep = AnnexRep;
this._options = options.Value;
}
///
/// 分页查询活动广告列表
///
///
///
[HttpGet("/Mini/BannePpage")]
public async Task Page([FromQuery] MiniBannerInput input)
{
var entities = await _rep.AsQueryable()
.Where(u => u.Type == input.Type)
.ToPagedListAsync(input.PageNo, input.PageSize);
return entities.XnPagedResult();
}
///
/// 增加活动广告列表
///
///
///
[HttpPost("/Mini/BannerAdd")]
public async Task Add([FromForm] AddMiniBannerInput input)
{
//var fileInfo = await Utils.UploadFile(input.File, this._options.Default.path, FileLocation.LOCAL);
//if (fileInfo == null)
// throw new Exception("文件上传失败!");
//input.Url = input.FileUrl;
var banner = input.Adapt();
await _rep.InsertAsync(banner);
}
///
/// 删除活动广告列表
///
///
///
[HttpPost("/Mini/BannerDelete")]
public async Task Delete(DeleteMiniBannerInput input)
{
var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
await _rep.DeleteAsync(entity);
}
///
/// 更新活动广告列表
///
///
///
[HttpPost("/Mini/BannerEdit")]
public async Task Update(UpdateMiniBannerInput input)
{
var entity = input.Adapt();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns:true).ExecuteCommandAsync();
}
///
/// 获取活动广告详情
///
///
///
[HttpGet("/Mini/BannerDetail")]
public async Task Get([FromQuery] QueryeMiniBannerInput input)
{
return await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
}
///
/// 获取活动广告列表列表
///
///
///
[HttpGet("/Mini/GetBannerList")]
[AllowAnonymous]
public async Task List([FromQuery] MiniBannerInput input)
{
return await _rep.Where(u => u.Type == input.Type).ToListAsync();
}
}
}