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.

115 lines
3.8 KiB

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;
11 months ago
using GDZZ.Application.Help;
using System;
using Microsoft.Extensions.Options;
namespace GDZZ.Application
{
/// <summary>
/// 活动广告列表服务
/// </summary>
[ApiDescriptionSettings("Application",Name = "MiniBanner", Order = 1)]
public class MiniBannerService : IMiniBannerService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<MiniBanner> _rep;
11 months ago
private readonly SqlSugarRepository<Annex> AnnexRep;
private readonly UploadFileOptions _options;
11 months ago
public MiniBannerService(SqlSugarRepository<MiniBanner> rep,
IOptions<UploadFileOptions> options,
SqlSugarRepository<Annex> AnnexRep)
{
_rep = rep;
11 months ago
this.AnnexRep = AnnexRep;
this._options = options.Value;
}
/// <summary>
/// 分页查询活动广告列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/Mini/BannePpage")]
public async Task<dynamic> Page([FromQuery] MiniBannerInput input)
{
var entities = await _rep.AsQueryable()
.Where(u => u.Type == input.Type)
.ToPagedListAsync(input.PageNo, input.PageSize);
return entities.XnPagedResult();
}
/// <summary>
/// 增加活动广告列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/Mini/BannerAdd")]
11 months ago
public async Task Add([FromForm] AddMiniBannerInput input)
{
11 months ago
//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<MiniBanner>();
await _rep.InsertAsync(banner);
}
/// <summary>
/// 删除活动广告列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/Mini/BannerDelete")]
public async Task Delete(DeleteMiniBannerInput input)
{
var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
await _rep.DeleteAsync(entity);
}
/// <summary>
/// 更新活动广告列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
11 months ago
[HttpPost("/Mini/BannerEdit")]
public async Task Update(UpdateMiniBannerInput input)
{
var entity = input.Adapt<MiniBanner>();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns:true).ExecuteCommandAsync();
}
/// <summary>
/// 获取活动广告详情
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/Mini/BannerDetail")]
public async Task<MiniBanner> Get([FromQuery] QueryeMiniBannerInput input)
{
return await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
}
/// <summary>
/// 获取活动广告列表列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/Mini/GetBannerList")]
[AllowAnonymous]
public async Task<dynamic> List([FromQuery] MiniBannerInput input)
{
return await _rep.Where(u => u.Type == input.Type).ToListAsync();
}
}
}