1
This commit is contained in:
parent
5785d39e04
commit
317dc30b17
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@ riderModule.iml
|
|||||||
.idea/
|
.idea/
|
||||||
/.vs
|
/.vs
|
||||||
/Fake.sln.DotSettings.user
|
/Fake.sln.DotSettings.user
|
||||||
|
/InterfaceForward.sln.DotSettings.user
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"launchUrl": "swagger/index.html",
|
"launchUrl": "swagger/index.html",
|
||||||
"applicationUrl": "http://localhost:5145",
|
"applicationUrl": "http://localhost:8888",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using InterfaceForward.Repositories.Dictionary.Services;
|
using System.ComponentModel;
|
||||||
|
using System.Reflection;
|
||||||
|
using InterfaceForward.Repositories.Dictionary.Services;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace InterfaceForward.Application.Services.App
|
namespace InterfaceForward.Application.Services.App
|
||||||
@ -6,11 +8,11 @@ namespace InterfaceForward.Application.Services.App
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 字典服务
|
/// 字典服务
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Route("Dictionary")]
|
|
||||||
[ApiExplorerSettings(GroupName = "应用服务")]
|
[ApiExplorerSettings(GroupName = "应用服务")]
|
||||||
public class DictionaryService : ApplicationService
|
public class DictionaryService : ApplicationService
|
||||||
{
|
{
|
||||||
private readonly IDictionaryRepository _dictionaryRepository;
|
private readonly IDictionaryRepository _dictionaryRepository;
|
||||||
|
private static readonly Dictionary<string, Dictionary<string, int>> EnumCache = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
@ -21,17 +23,62 @@ namespace InterfaceForward.Application.Services.App
|
|||||||
_dictionaryRepository = dictionaryRepository;
|
_dictionaryRepository = dictionaryRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Get
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 列表
|
/// 列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="type">类型</param>
|
/// <param name="type">类型</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("GetList")]
|
[HttpGet("Dictionary/GetList")]
|
||||||
public async Task<dynamic> GetList(string type)
|
public async Task<dynamic> GetList(string type)
|
||||||
{
|
{
|
||||||
return await _dictionaryRepository.AsQueryable().Where(x => x.Type == type).Select(x => new { Key = x.Id, Value = x.Name }).ToListAsync();
|
return await _dictionaryRepository.AsQueryable().Where(x => x.Type == type).Select(x => new { Key = x.Id, Value = x.Name }).ToListAsync();
|
||||||
}
|
}
|
||||||
#endregion
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取枚举下拉列表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="enumTypeName">枚举类型名称</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("Dictionary/GetKvsByEnumTypeName")]
|
||||||
|
public Dictionary<string, int> GetKvsByEnumTypeName(string enumTypeName)
|
||||||
|
{
|
||||||
|
// Check if the type is already cached
|
||||||
|
if (EnumCache.TryGetValue(enumTypeName, out var res))
|
||||||
|
{
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load the assembly
|
||||||
|
var assemblyName = "InterfaceForward.Domain.Shared";
|
||||||
|
var assembly = Assembly.Load(assemblyName);
|
||||||
|
if (assembly == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"Assembly '{assemblyName}' could not be loaded.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the enum type
|
||||||
|
var enumType = assembly.GetType("InterfaceForward.Domain.Shared.Enum." + enumTypeName);
|
||||||
|
if (enumType == null || !enumType.IsEnum)
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"The type '{enumTypeName}' is not a valid enum.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve the descriptions and values
|
||||||
|
var enumDict = new Dictionary<string, int>();
|
||||||
|
foreach (var value in enumType.GetEnumValues())
|
||||||
|
{
|
||||||
|
var name = value.ToString();
|
||||||
|
var fieldInfo = enumType.GetField(name);
|
||||||
|
var descriptionAttribute = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
|
||||||
|
string description = descriptionAttribute != null ? descriptionAttribute.Description : name;
|
||||||
|
enumDict[description] = (int)value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cache the result
|
||||||
|
EnumCache[enumTypeName] = enumDict;
|
||||||
|
|
||||||
|
return enumDict;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,65 @@
|
|||||||
|
using InterfaceForward.Repositories;
|
||||||
|
using InterfaceForward.Repositories.Interface.Entitys;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace InterfaceForward.Application.Services.Interface;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 接口分类
|
||||||
|
/// </summary>
|
||||||
|
[ApiExplorerSettings(GroupName = "接口服务")]
|
||||||
|
public class InterfaceCategoryService(IBasicRepository<InterfaceCategoryEntity> categoryRepository) : ApplicationService
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 添加接口分类
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pId">父级id,没有就传0,表示顶级</param>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
[HttpPost("Interface/AddInterfaceCategory")]
|
||||||
|
public async Task AddInterfaceCategoryInput(int pId, string name)
|
||||||
|
{
|
||||||
|
if (await categoryRepository.AnyAsync(x => x.PId == pId && x.Name == name))
|
||||||
|
{
|
||||||
|
throw new BusinessException("重复添加");
|
||||||
|
}
|
||||||
|
|
||||||
|
await categoryRepository.InsertAsync(new InterfaceCategoryEntity
|
||||||
|
{
|
||||||
|
PId = pId,
|
||||||
|
Name = name
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新接口分类
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">id</param>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
[HttpPut("Interface/UpdateInterfaceCategoryInput")]
|
||||||
|
public async Task UpdateInterfaceCategoryInput(int id, string name)
|
||||||
|
{
|
||||||
|
var category = await categoryRepository.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
if (category == null)
|
||||||
|
{
|
||||||
|
throw new BusinessException("分类不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
category.Name = name;
|
||||||
|
await categoryRepository.UpdateAsync(category);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除接口分类
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">id</param>
|
||||||
|
[HttpDelete("Interface/DeleteInterfaceCategoryInput")]
|
||||||
|
public async Task DeleteInterfaceCategoryInput(int id)
|
||||||
|
{
|
||||||
|
var category = await categoryRepository.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
|
if (category == null)
|
||||||
|
{
|
||||||
|
throw new BusinessException("分类不存在");
|
||||||
|
}
|
||||||
|
await categoryRepository.SoftDeleteAsync(x => x.Id == id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
namespace InterfaceForward.Repositories.Interface.Entitys
|
||||||
|
{
|
||||||
|
///<summary>
|
||||||
|
/// 接口分类表
|
||||||
|
///</summary>
|
||||||
|
[SugarTable("t_interface_category")]
|
||||||
|
public class InterfaceCategoryEntity : FullAuditedAggregateRoot<int>
|
||||||
|
{
|
||||||
|
///<summary>
|
||||||
|
/// 父分类id
|
||||||
|
///</summary>
|
||||||
|
[SugarColumn(ColumnName = "PId")]
|
||||||
|
public int PId { get; set; }
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
/// 分类名称
|
||||||
|
///</summary>
|
||||||
|
[SugarColumn(ColumnName = "Name")]
|
||||||
|
public string Name { get; set; } = null!;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user