87 lines
2.3 KiB
C#
87 lines
2.3 KiB
C#
using System.Reflection;
|
|
using Dlhis.Common.Response;
|
|
using Dlhis.Entity.Basic.Entity;
|
|
using Kurisu.AspNetCore.Utils.Extensions;
|
|
using Kurisu.SqlSugar.Services;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Dlhis.Common.EnumSetting;
|
|
|
|
/// <summary>
|
|
/// 枚举
|
|
/// </summary>
|
|
[Authorize]
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class EnumsController : ControllerBase
|
|
{
|
|
|
|
private readonly IDbContext _dbContext;
|
|
|
|
public EnumsController(IDbContext dbContext)
|
|
{
|
|
_dbContext = dbContext;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取所有枚举
|
|
/// </summary>
|
|
/// <param name="code">枚举code</param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public object GetEnums(string code)
|
|
{
|
|
var types = Assembly.Load("Dlhis.Entity")
|
|
.GetTypes()
|
|
.Where(x => x.IsEnum)
|
|
.WhereIf(code.IsPresent(), x => x.Name == code);
|
|
|
|
return types.Select(x =>
|
|
{
|
|
var d = x.GetDescription();
|
|
return new
|
|
{
|
|
Code = x.Name,
|
|
Name = d,
|
|
Data = x.GetFields(BindingFlags.Public | BindingFlags.Static).Select(item =>
|
|
{
|
|
var e = (Enum)Enum.Parse(item.FieldType, item.GetValue(null).ToString());
|
|
var fd = e.GetDescription();
|
|
return new
|
|
{
|
|
Key = fd,
|
|
Value = (int)item.GetValue(null)
|
|
};
|
|
})
|
|
};
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 获取档案类型数据
|
|
/// </summary>
|
|
/// <param name="code"></param>
|
|
/// <returns></returns>
|
|
public object GetTypes(string type)
|
|
{
|
|
var types = _dbContext.Queryable<GainfoTypeEntity>().Where(x => x.Type == type).ToList();
|
|
|
|
return types.Select(x =>
|
|
{
|
|
return new
|
|
{
|
|
Type = x.Type,
|
|
Data = types.Select(x => new GainfoTypeResponse
|
|
{
|
|
Id = x.Id,
|
|
Type = x.Type,
|
|
Code = x.Code,
|
|
Descript = x.Descript,
|
|
DescriptEn = x.DescriptEn,
|
|
Remark = x.Remark,
|
|
}).ToList()
|
|
};
|
|
});
|
|
}
|
|
}
|