65 lines
1.7 KiB
C#
65 lines
1.7 KiB
C#
using NoFurion.Extensions;
|
|
using Dolphin.ExamPictureCut.Common.Dto;
|
|
using SqlSugar;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using NoFurion;
|
|
|
|
namespace Dolphin.ExamPictureCut.Common;
|
|
|
|
public class CommonAppService : DolphinAppService
|
|
{
|
|
private readonly ISqlSugarClient _client;
|
|
public CommonAppService(ISqlSugarClient client)
|
|
{
|
|
_client = client;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取枚举值
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
public List<EnumInfoDto> GetEnumInfo(GetEnumInfoInput input)
|
|
{
|
|
var result = input.EnumName.GetEnumValueDto(input.IncludeValues, input.ExcludeValues);
|
|
ExceptionExt.ThrowIf(result == null || result.Count == 0, $"不存在名称为{input.EnumName}枚举");
|
|
return result;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 批量获取枚举值
|
|
/// </summary>
|
|
/// <param name="enumNames"></param>
|
|
/// <returns></returns>
|
|
public Dictionary<string, List<EnumInfoDto>> GetEnumInfos([Required] List<string> enumNames)
|
|
{
|
|
var resultDict = new Dictionary<string, List<EnumInfoDto>>();
|
|
foreach (var name in enumNames.Distinct())
|
|
{
|
|
var datas = name.GetEnumValueDto();
|
|
resultDict[name] = datas;
|
|
}
|
|
return resultDict;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取 class 字段
|
|
/// </summary>
|
|
/// <param name="className"></param>
|
|
/// <returns></returns>
|
|
public List<string> GetClassFieldNames(string className)
|
|
{
|
|
var cls = Type.GetType(className);
|
|
if (cls == null) return null;
|
|
var fields = new List<string>();
|
|
foreach (var p in cls.GetProperties())
|
|
{
|
|
fields.Add(p.Name);
|
|
}
|
|
return fields;
|
|
}
|
|
}
|
|
|
|
|