using Admin.Core.Model; using Admin.Core.Common.Resource; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Threading.Tasks; using Admin.Core.Common; using Admin.Core.IService.ISys; using Admin.Core.Model.Sys; namespace Admin.Core.Api { /// /// SysNoticeController /// [Route("api/[controller]/[action]")] [ApiController] [Authorize(Permissions.Name)] public class SysNoticeController : BaseApiUserController { /// /// _sysNoticeService /// private readonly ISysNoticeService _sysNoticeService; /// /// 构造方法 /// /// /// public SysNoticeController(ISysNoticeService SysNoticeService, ISysUserService sysUserService) : base(sysUserService) { _sysUserService = sysUserService; _sysNoticeService = SysNoticeService; } /// /// 分页查询 /// /// /// [HttpPost] [Action("通知公告", ActionType.QUERY)] public async Task>> GetByPage([FromBody] PageQuery pageQuery) { Expression> whereExpression = x => true; if (pageQuery.Query.NoticeTitle.IsNotEmptyOrNull()) { whereExpression = whereExpression.And(x => x.NoticeTitle.Contains(pageQuery.Query.NoticeTitle)); } if (pageQuery.Query.NoticeType.IsNotEmptyOrNull()) { whereExpression = whereExpression.And(x => x.NoticeType == pageQuery.Query.NoticeType); } if (pageQuery.Query.CreateBy.IsNotEmptyOrNull()) { whereExpression = whereExpression.And(x => x.CreateBy.Contains(pageQuery.Query.CreateBy)); } if (pageQuery.Query.Status.IsNotEmptyOrNull()) { whereExpression = whereExpression.And(x => x.Status == pageQuery.Query.Status); } var data = await _sysNoticeService.QueryPageAsync(whereExpression, pageQuery.Page, pageQuery.PageSize, "UpdateTime desc"); return Success(data); } /// /// 根据ID查询 /// /// 主键 /// [HttpGet] [Action("通知公告", ActionType.QUERY)] public async Task> GetByID(int id) { return new MessageModel() { msg = Resource_SysBase.OprateSuccess, success = true, data = await _sysNoticeService.QueryByIdAsync(id) }; } /// /// 新增一条数据 /// /// SysNotice /// [HttpPost] [Action("通知公告", ActionType.ADD)] public async Task> Add([FromBody] SysNotice request) { var data = new MessageModel(); request.CreateBy = CurrentUser.LoginName; request.UpdateBy = CurrentUser.LoginName; request.CreateTime = DateTime.Now; request.UpdateTime = DateTime.Now; data.data = await _sysNoticeService.AddAsync(request); if (data.success) { data.success = true; data.msg = Resource_SysBase.OprateSuccess; } else { data.success = false; data.msg = Resource_SysBase.OprateFail; } return data; } /// /// 更新一条数据 /// /// SysNotice /// [HttpPost] [Action("通知公告", ActionType.UPDATE)] public async Task> Update([FromBody] SysNotice request) { var data = new MessageModel(); request.UpdateBy = CurrentUser.LoginName; request.UpdateTime = DateTime.Now; data.success = await _sysNoticeService.UpdateAsync(request); if (data.success) { data.msg = Resource_SysBase.OprateSuccess; } else { data.msg = Resource_SysBase.OprateFail; } return data; } /// /// 删除一条数据 /// /// 主键 /// [HttpPost] [Action("通知公告", ActionType.DEL)] public async Task> Del(List ids) { var data = new MessageModel(); data.success = await _sysNoticeService.DeleteByIdAsync(ids); if (data.success) { data.msg = Resource_SysBase.OprateSuccess; } else { data.msg = Resource_SysBase.OprateFail; } return data; } } }