diff --git a/Src/Dlhis.Common/EnumSetting/EnumsController.cs b/Src/Dlhis.Common/EnumSetting/EnumsController.cs
index bd342d06..030e8127 100644
--- a/Src/Dlhis.Common/EnumSetting/EnumsController.cs
+++ b/Src/Dlhis.Common/EnumSetting/EnumsController.cs
@@ -1,5 +1,8 @@
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;
@@ -13,37 +16,67 @@ namespace Dlhis.Common.EnumSetting;
[ApiController]
public class EnumsController : ControllerBase
{
+ private readonly IDbContext _dbContext;
+
+ public EnumsController(IDbContext dbContext)
+ {
+ _dbContext = dbContext;
+ }
+
///
- /// 获取所有枚举
+ /// 获取所有枚举/基础类型
///
- /// 枚举code
+ /// code
///
[HttpGet]
- public object GetEnums(string code)
+ public List GetEnums(string code)
{
var types = Assembly.Load("Dlhis.Entity")
.GetTypes()
.Where(x => x.IsEnum)
- .WhereIf(code.IsPresent(), x => x.Name == code);
+ .WhereIf(code.IsPresent(), x => x.Name == code);
- return types.Select(x =>
+ var result = types.Select(x =>
+ {
+ var d = x.GetDescription();
+ return new CommonEnumResponse
+ {
+ 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 KeyValueDto
+ {
+ Key = fd,
+ Value = (int)item.GetValue(null)
+ };
+ }).ToList()
+ };
+ })
+ .ToList();
+
+ //todo cache 速度
+ var dbTypes = _dbContext.Queryable().OrderBy(x => x.Sequence).ToList();
+ var dbResult = dbTypes.GroupBy(x => x.Type).Select(g =>
{
- var d = x.GetDescription();
- return new
+ var type = g.Key;
+ return new CommonEnumResponse
{
- Code = x.Name,
- Name = d,
- Data = x.GetFields(BindingFlags.Public | BindingFlags.Static).Select(item =>
+ Code = type,
+ Name = type,
+ Data = g.AsEnumerable().Select(x => new KeyValueDto
{
- var e = (Enum)Enum.Parse(item.FieldType, item.GetValue(null).ToString());
- var fd = e.GetDescription();
- return new
- {
- Key = fd,
- Value = (int)item.GetValue(null)
- };
+ Key = x.Code,
+ Value = x.Display
})
+ .ToList()
};
});
+
+ result.AddRange(dbResult);
+
+ return result;
}
}
diff --git a/Src/Dlhis.Common/EnumSetting/TypesController.cs b/Src/Dlhis.Common/EnumSetting/TypesController.cs
deleted file mode 100644
index 03c13fd1..00000000
--- a/Src/Dlhis.Common/EnumSetting/TypesController.cs
+++ /dev/null
@@ -1,48 +0,0 @@
-using Dlhis.Entity.Basic.Entity;
-using Kurisu.SqlSugar.Services;
-using Microsoft.AspNetCore.Authorization;
-using Microsoft.AspNetCore.Mvc;
-
-namespace Dlhis.Common.EnumSetting;
-
-///
-/// 类型
-///
-[Authorize]
-[Route("api/[controller]")]
-[ApiController]
-public class TypesController : ControllerBase
-{
- private readonly IDbContext _dbContext;
-
- public TypesController(IDbContext dbContext)
- {
- _dbContext = dbContext;
- }
-
- ///
- /// Basic类型表
- ///
- ///
- [HttpGet]
- public object GetTypes()
- {
- var types = _dbContext.Queryable().ToList().AsEnumerable();
- var distinctTypes = types.Select(x => x.Type).Distinct();
-
- return distinctTypes.Select(type =>
- {
- var date = types.Where(item => item.Type == type)
- .Select(item => new
- {
- Key = item.Code,
- Value = item.Descript
- });
- return new
- {
- Type = type,
- Date = date
- };
- });
- }
-}
\ No newline at end of file
diff --git a/Src/Dlhis.Common/Response/CommonEnumResponse.cs b/Src/Dlhis.Common/Response/CommonEnumResponse.cs
new file mode 100644
index 00000000..68a3d718
--- /dev/null
+++ b/Src/Dlhis.Common/Response/CommonEnumResponse.cs
@@ -0,0 +1,9 @@
+namespace Dlhis.Common.Response
+{
+ public class CommonEnumResponse
+ {
+ public string Code { get; set; }
+ public string Name { get; set; }
+ public List Data { get; set; }
+ }
+}
diff --git a/Src/Dlhis.Common/Response/KeyValueDto.cs b/Src/Dlhis.Common/Response/KeyValueDto.cs
new file mode 100644
index 00000000..26e64747
--- /dev/null
+++ b/Src/Dlhis.Common/Response/KeyValueDto.cs
@@ -0,0 +1,8 @@
+namespace Dlhis.Common.Response
+{
+ public class KeyValueDto
+ {
+ public string Key { get; set; }
+ public object Value { get; set; }
+ }
+}
diff --git a/Src/Dlhis.Entity/Basic/Entity/BasicTypeEntity.cs b/Src/Dlhis.Entity/Basic/Entity/BasicTypeEntity.cs
index 7f9a18cc..21452fd9 100644
--- a/Src/Dlhis.Entity/Basic/Entity/BasicTypeEntity.cs
+++ b/Src/Dlhis.Entity/Basic/Entity/BasicTypeEntity.cs
@@ -1,48 +1,47 @@
using SqlSugar;
-namespace Dlhis.Entity.Basic.Entity
+namespace Dlhis.Entity.Basic.Entity;
+
+///
+/// Basic类型表
+///
+[SugarTable(TableName = "BasicType", TableDescription = "Basic类型表")]
+public class BasicTypeEntity : SugarBaseEntity
{
///
- /// Basic类型表
+ /// 类型
///
- [SugarTable(TableName = "BasicType", TableDescription = "Basic类型表")]
- public class BasicTypeEntity : SugarBaseEntity
- {
- ///
- /// 类型
- ///
- [SugarColumn(ColumnDescription = "类型")]
- public string Type { get; set; }
+ [SugarColumn(ColumnDescription = "类型")]
+ public string Type { get; set; }
- ///
- /// 编码
- ///
- [SugarColumn(ColumnDescription = "编码")]
- public string Code { get; set; }
+ ///
+ /// 编码
+ ///
+ [SugarColumn(ColumnDescription = "编码")]
+ public string Code { get; set; }
- ///
- /// 中文描述
- ///
- [SugarColumn(ColumnDescription = "中文描述")]
- public string Descript { get; set; }
+ ///
+ /// 中文描述
+ ///
+ [SugarColumn(ColumnDescription = "中文描述")]
+ public string Display { get; set; }
- ///
- /// 英文描述
- ///
- [SugarColumn(ColumnDescription = "英文描述")]
- public string DescriptEn { get; set; }
+ ///
+ /// 英文描述
+ ///
+ [SugarColumn(ColumnDescription = "英文描述")]
+ public string DisplayEn { get; set; }
- ///
- /// 备注
- ///
- [SugarColumn(ColumnDescription = "备注")]
- public string Remark { get; set; }
+ ///
+ /// 备注
+ ///
+ [SugarColumn(ColumnDescription = "备注")]
+ public string Remark { get; set; }
- ///
- /// 排序
- ///
- [SugarColumn(ColumnDescription = "排序")]
- public string Sort { get; set; }
+ ///
+ /// 排序
+ ///
+ [SugarColumn(ColumnDescription = "排序", DefaultValue = "0")]
+ public int Sequence { get; set; }
- }
}