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.
 
 

174 lines
5.7 KiB

using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using Yitter.IdGenerator;
using Znyc.Cloudcar.Admin.AspNetCore.Controllers;
using Znyc.Cloudcar.Admin.AspNetCore.Entitys;
using Znyc.Cloudcar.Admin.AspNetCore.Mvc;
using Znyc.Cloudcar.Admin.Commons.Cache;
using Znyc.Cloudcar.Admin.Commons.Entitys;
using Znyc.Cloudcar.Admin.Commons.Enums;
using Znyc.Cloudcar.Admin.Commons.Mapping;
using Znyc.Cloudcar.Admin.Commons.Pages;
using Znyc.Cloudcar.Admin.Security.Dtos;
using Znyc.Cloudcar.Admin.Security.Entitys;
using Znyc.Cloudcar.Admin.Security.IServices;
namespace Znyc.Cloudcar.Admin.WebApi.Controllers
{
/// <summary>
///
/// </summary>
[ApiController]
[Route("api/Security/[controller]")]
public class
BannerController : AreaApiController<BannerEntity, BannerOutputDto, BannerInput, IBannerService, long>
{
/// <summary>
/// 构造函数
/// </summary>
/// <param name="_service"></param>
public BannerController(IBannerService _service) : base(_service)
{
}
/// <summary>
/// 新增前处理数据
/// </summary>
/// <param name="info"></param>
protected override void OnBeforeInsert(BannerEntity info)
{
info.Id = YitIdHelper.NextId();
info.CreatedTime = DateTime.Now;
info.CreatedUserId = CurrentUser.UserId;
info.IsDeleted = false;
}
/// <summary>
/// 在更新数据前对数据的修改操作
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
protected override void OnBeforeUpdate(BannerEntity info)
{
info.ModifiedUserId = CurrentUser.UserId;
info.ModifiedTime = DateTime.Now;
}
/// <summary>
/// 在软删除数据前对数据的修改操作
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
protected override void OnBeforeSoftDelete(BannerEntity info)
{
info.IsDeleted = true;
info.ModifiedUserId = CurrentUser.UserId;
info.ModifiedTime = DateTime.Now;
}
/// <summary>
/// 分页查询
/// </summary>
/// <param name="search"></param>
/// <returns></returns>
[HttpPost("FindWithPagerSearchAsync")]
//[FunctionAuthorize("List")]
public async Task<IActionResult> FindWithPagerSearchAsync(SearchBannerModel search)
{
CommonResult<PageResult<BannerOutputDto>> result = new CommonResult<PageResult<BannerOutputDto>>
{
ResData = await _service.FindWithPagerSearchAsync(search),
ErrCode = ErrCode.successCode
};
return ToJsonContent(result);
}
/// <summary>
/// 新增banner/活动
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("InsertAsync")]
[FunctionAuthorize("Add")]
public async Task<IActionResult> InsertAsync(BannerInput input)
{
CommonResult result = new CommonResult();
CacheHelper cacheHelper = new CacheHelper();
BannerEntity banner = input.MapTo<BannerEntity>();
OnBeforeInsert(banner);
result = await _service.InsertAsync(banner);
if (result.Success)
{
//清除缓存
cacheHelper.Remove("banner:list");
result.ErrCode = ErrCode.successCode;
result.ErrMsg = ErrCode.err0;
}
else
{
result.ErrMsg = result.ErrMsg;
result.ErrCode = "43001";
}
return ToJsonContent(result);
}
/// <summary>
/// 异步更新数据
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("UpdateAsync")]
[FunctionAuthorize("Edit")]
public async Task<IActionResult> UpdateAsync(BannerUpdateInput input)
{
CommonResult result = new CommonResult();
CacheHelper cacheHelper = new CacheHelper();
BannerEntity bannerEntity = input.MapTo<BannerEntity>();
OnBeforeUpdate(bannerEntity);
result = await _service.UpdateAsync(bannerEntity);
if (result.Success)
{
cacheHelper.Remove("banner:list");
result.ErrCode = ErrCode.successCode;
result.ErrMsg = ErrCode.err0;
}
else
{
result.ErrMsg = result.ErrMsg;
result.ErrCode = "43001";
}
return ToJsonContent(result);
}
/// <summary>
/// 异步软删除数据
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpDelete("DeleteSoftAsync")]
[FunctionAuthorize("Delete")]
public async Task<IActionResult> DeleteSoftAsync(long id)
{
CommonResult result = new CommonResult();
CacheHelper cacheHelper = new CacheHelper();
result.Success = await _service.DeleteSoftAsync(false, id, CurrentUser.UserId);
if (result.Success)
{
cacheHelper.Remove("banner:list");
result.ErrCode = ErrCode.successCode;
result.ErrMsg = ErrCode.err0;
}
else
{
result.ErrMsg = ErrCode.err43001;
result.ErrCode = "43001";
}
return ToJsonContent(result);
}
}
}