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 _dicRepo; public DictController(IMongoBaseRepository dicRepo) { _dicRepo = dicRepo; } /// /// 根据编码获取字典项 /// [HttpGet("GetByCode")] public async Task> GetByCode(string code) { var dic = await _dicRepo.FindOneAsync(c => c.IsDelete == false && c.Code == code); return this.ToResult(dic); } /// /// 根据编码获取字典子项列表 - 返回该字典编码下所有子项(按 Order 排序) /// [HttpGet("GetListByCode")] public async Task>> 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()); var children = all.Where(c => c.ParentId == parent.Id).OrderBy(c => c.Order).ToList(); return this.ToResult(children); } } }