You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
4.7 KiB
C#

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