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 { /// /// SysDictDataController /// [Route("api/[controller]/[action]")] [ApiController] [Authorize(Permissions.Name)] public class SysDictDataController : BaseApiUserController { /// /// _sysDictDataService /// private readonly ISysDictDataService _sysDictDataService; /// /// 构造方法 /// /// /// public SysDictDataController(ISysDictDataService SysDictDataService, ISysUserService sysUserService) : base(sysUserService) { _sysUserService = sysUserService; _sysDictDataService = SysDictDataService; } /// /// 分页查询 /// /// /// [HttpPost] public async Task>> GetByPage([FromBody] PageQuery pageQuery) { if (!pageQuery.Query.IsNotEmptyOrNull()) { pageQuery.Query = new SysDictData(); } var model = await _sysDictDataService.SelectDictDataList(pageQuery); return Success(model); } /// /// 根据ID查询 /// /// 主键 /// [HttpGet] public async Task> GetByID(int id) { return new MessageModel() { msg = Resource_SysBase.OprateSuccess, success = true, data = await _sysDictDataService.SelectDictDataById(id) }; } /// /// 新增一条数据 /// /// SysDictData /// [HttpPost] public async Task> Add([FromBody] SysDictData request) { var data = new MessageModel(); request.CreateBy = CurrentUser.LoginName; request.UpdateBy = CurrentUser.LoginName; data.data = await _sysDictDataService.InsertDictData(request); if (data.data > 0) { data.success = true; data.msg = Resource_SysBase.OprateSuccess; } else { data.success = false; data.msg = Resource_SysBase.OprateFail; } return data; } /// /// 更新一条数据 /// /// SysDictData /// [HttpPost] public async Task> Update([FromBody] SysDictData request) { var data = new MessageModel(); request.UpdateBy = CurrentUser.LoginName; data.success = await _sysDictDataService.UpdateDictData(request); if (data.success) { data.msg = Resource_SysBase.OprateSuccess; } else { data.msg = Resource_SysBase.OprateFail; } return data; } /// /// 删除一条数据 /// /// 主键 /// [HttpPost] public async Task> Del(List ids) { var data = new MessageModel(); data.success = await _sysDictDataService.DeleteDictDataByIds(ids); if (data.success) { data.msg = Resource_SysBase.OprateSuccess; } else { data.msg = Resource_SysBase.OprateFail; } return data; } /// /// 根据字典类型查询字典数据信息 /// /// /// [HttpGet] public async Task>> DictType(string dictType) { return Success(await _sysDictDataService.QueryAsync(x => x.DictType == dictType && x.Status == SysConst.ENABLE)); } } }