using Microsoft.AspNetCore.Mvc; using System; using System.Threading.Tasks; using Yitter.IdGenerator; using Znyc.Recruitment.Admin.AspNetCore.Controllers; using Znyc.Recruitment.Admin.AspNetCore.Entitys; using Znyc.Recruitment.Admin.AspNetCore.Mvc; using Znyc.Recruitment.Admin.Commons.Cache; using Znyc.Recruitment.Admin.Commons.Entitys; using Znyc.Recruitment.Admin.Commons.Mapping; using Znyc.Recruitment.Admin.Commons.Pages; using Znyc.Recruitment.Admin.Security.Dtos; using Znyc.Recruitment.Admin.Security.Entitys; using Znyc.Recruitment.Admin.Security.IServices; namespace Znyc.Recruitment.Admin.WebApi.Controllers { /// /// /// [ApiController] [Route("api/Security/[controller]")] public class ActivityController : AreaApiController { /// /// 构造函数 /// /// public ActivityController(IActivityService _service) : base(_service) { } /// /// 新增前处理数据 /// /// protected override void OnBeforeInsert(ActivityEntity info) { info.Id = YitIdHelper.NextId(); info.CreatedTime = DateTime.Now; info.CreatedUserId = CurrentUser.UserId; info.IsDeleted = false; } /// /// 在更新数据前对数据的修改操作 /// /// /// protected override void OnBeforeUpdate(ActivityEntity info) { info.ModifiedUserId = CurrentUser.UserId; info.ModifiedTime = DateTime.Now; } /// /// 在软删除数据前对数据的修改操作 /// /// /// protected override void OnBeforeSoftDelete(ActivityEntity info) { info.IsDeleted = true; } /// /// 分页查询 /// /// /// [HttpPost("FindWithPagerSearchAsync")] [FunctionAuthorize("List")] public async Task FindWithPagerSearchAsync(SearchActivityModel search) { CommonResult> result = new CommonResult> { ResData = await _service.FindWithPagerSearchAsync(search), ErrCode = ErrCode.successCode }; return ToJsonContent(result); } /// /// 异步新增数据 /// /// /// [HttpPost("InsertAsync")] [FunctionAuthorize("Add")] public async Task InsertAsync(ActivityAddInput input) { CommonResult result = new CommonResult(); CacheHelper cacheHelper = new CacheHelper(); ActivityEntity info = input.MapTo(); OnBeforeInsert(info); result = await _service.InsertAsync(info); if (result.Success) { cacheHelper.Remove("activity:list"); result.ErrCode = ErrCode.successCode; result.ErrMsg = ErrCode.err0; } else { result.ErrMsg = result.ErrMsg; result.ErrCode = "43001"; } return ToJsonContent(result); } /// /// 异步更新数据 /// /// /// [HttpPost("UpdateAsync")] [FunctionAuthorize("Edit")] public async Task UpdateAsync(ActivityUpdateInput input) { CommonResult result = new CommonResult(); CacheHelper cacheHelper = new CacheHelper(); ActivityEntity entity = input.MapTo(); OnBeforeUpdate(entity); result = await _service.UpdateAsync(entity); if (result.Success) { cacheHelper.Remove("activity:list"); result.ErrCode = ErrCode.successCode; result.ErrMsg = ErrCode.err0; } else { result.ErrMsg = result.ErrMsg; result.ErrCode = "43001"; } return ToJsonContent(result); } } }