fix 基础数据代码调整
This commit is contained in:
@@ -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,23 +16,30 @@ namespace Dlhis.Common.EnumSetting;
|
||||
[ApiController]
|
||||
public class EnumsController : ControllerBase
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
|
||||
public EnumsController(IDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有枚举
|
||||
/// 获取所有枚举/基础类型
|
||||
/// </summary>
|
||||
/// <param name="code">枚举code</param>
|
||||
/// <param name="code">code</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public object GetEnums(string code)
|
||||
public List<CommonEnumResponse> 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 result = types.Select(x =>
|
||||
{
|
||||
var d = x.GetDescription();
|
||||
return new
|
||||
return new CommonEnumResponse
|
||||
{
|
||||
Code = x.Name,
|
||||
Name = d,
|
||||
@@ -37,13 +47,36 @@ public class EnumsController : ControllerBase
|
||||
{
|
||||
var e = (Enum)Enum.Parse(item.FieldType, item.GetValue(null).ToString());
|
||||
var fd = e.GetDescription();
|
||||
return new
|
||||
return new KeyValueDto
|
||||
{
|
||||
Key = fd,
|
||||
Value = (int)item.GetValue(null)
|
||||
};
|
||||
}).ToList()
|
||||
};
|
||||
})
|
||||
.ToList();
|
||||
|
||||
//todo cache 速度
|
||||
var dbTypes = _dbContext.Queryable<BasicTypeEntity>().OrderBy(x => x.Sequence).ToList();
|
||||
var dbResult = dbTypes.GroupBy(x => x.Type).Select(g =>
|
||||
{
|
||||
var type = g.Key;
|
||||
return new CommonEnumResponse
|
||||
{
|
||||
Code = type,
|
||||
Name = type,
|
||||
Data = g.AsEnumerable().Select(x => new KeyValueDto
|
||||
{
|
||||
Key = x.Code,
|
||||
Value = x.Display
|
||||
})
|
||||
.ToList()
|
||||
};
|
||||
});
|
||||
|
||||
result.AddRange(dbResult);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// 类型
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class TypesController : ControllerBase
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
|
||||
public TypesController(IDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Basic类型表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public object GetTypes()
|
||||
{
|
||||
var types = _dbContext.Queryable<BasicTypeEntity>().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
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
9
Src/Dlhis.Common/Response/CommonEnumResponse.cs
Normal file
9
Src/Dlhis.Common/Response/CommonEnumResponse.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Dlhis.Common.Response
|
||||
{
|
||||
public class CommonEnumResponse
|
||||
{
|
||||
public string Code { get; set; }
|
||||
public string Name { get; set; }
|
||||
public List<KeyValueDto> Data { get; set; }
|
||||
}
|
||||
}
|
||||
8
Src/Dlhis.Common/Response/KeyValueDto.cs
Normal file
8
Src/Dlhis.Common/Response/KeyValueDto.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Dlhis.Common.Response
|
||||
{
|
||||
public class KeyValueDto
|
||||
{
|
||||
public string Key { get; set; }
|
||||
public object Value { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.Entity.Basic.Entity
|
||||
namespace Dlhis.Entity.Basic.Entity;
|
||||
|
||||
/// <summary>
|
||||
/// Basic类型表
|
||||
/// </summary>
|
||||
[SugarTable(TableName = "BasicType", TableDescription = "Basic类型表")]
|
||||
public class BasicTypeEntity : SugarBaseEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// Basic类型表
|
||||
/// </summary>
|
||||
[SugarTable(TableName = "BasicType", TableDescription = "Basic类型表")]
|
||||
public class BasicTypeEntity : SugarBaseEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// 类型
|
||||
/// </summary>
|
||||
@@ -24,13 +24,13 @@ namespace Dlhis.Entity.Basic.Entity
|
||||
/// 中文描述
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "中文描述")]
|
||||
public string Descript { get; set; }
|
||||
public string Display { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 英文描述
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "英文描述")]
|
||||
public string DescriptEn { get; set; }
|
||||
public string DisplayEn { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
@@ -41,8 +41,7 @@ namespace Dlhis.Entity.Basic.Entity
|
||||
/// <summary>
|
||||
/// 排序
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "排序")]
|
||||
public string Sort { get; set; }
|
||||
[SugarColumn(ColumnDescription = "排序", DefaultValue = "0")]
|
||||
public int Sequence { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user