2026-10-12 16:22:04 +08:00
|
|
|
using Common;
|
|
|
|
|
using CommonInfrastructure;
|
|
|
|
|
using Domain.Admin.Admin;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using MongoRepository;
|
|
|
|
|
|
|
|
|
|
namespace UserApi.Dict
|
|
|
|
|
{
|
|
|
|
|
[ApiController, Route("api/[controller]")]
|
|
|
|
|
public class DictController : BaseController
|
|
|
|
|
{
|
|
|
|
|
private readonly IMongoBaseRepository<SystemDic> _dicRepo;
|
|
|
|
|
|
|
|
|
|
public DictController(IMongoBaseRepository<SystemDic> dicRepo)
|
|
|
|
|
{
|
|
|
|
|
_dicRepo = dicRepo;
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-19 00:44:00 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 根据编码获取字典项
|
|
|
|
|
/// </summary>
|
2026-10-12 16:22:04 +08:00
|
|
|
[HttpGet("GetByCode")]
|
|
|
|
|
public async Task<BaseResponse<SystemDic>> GetByCode(string code)
|
|
|
|
|
{
|
|
|
|
|
var dic = await _dicRepo.FindOneAsync(c => c.IsDelete == false && c.Code == code);
|
|
|
|
|
return this.ToResult(dic);
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-19 00:44:00 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 根据编码获取字典子项列表 - 返回该字典编码下所有子项(按 Order 排序)
|
|
|
|
|
/// </summary>
|
2026-10-12 16:22:04 +08:00
|
|
|
[HttpGet("GetListByCode")]
|
|
|
|
|
public async Task<BaseResponse<List<SystemDic>>> GetListByCode(string code)
|
|
|
|
|
{
|
|
|
|
|
var all = await _dicRepo.FilterByAsync(c => c.IsDelete == false);
|
|
|
|
|
var parent = all.FirstOrDefault(c => c.Code == code);
|
|
|
|
|
if (parent == null)
|
|
|
|
|
return this.ToResult(new List<SystemDic>());
|
|
|
|
|
var children = all.Where(c => c.ParentId == parent.Id).OrderBy(c => c.Order).ToList();
|
|
|
|
|
return this.ToResult(children);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|