using Common.Enum; using Entity.Base; using Entity.DbModel.System; using Entity.Dto.Req; using HybirdFrameworkCore.Autofac.Attribute; using Mapster; using Repository.System; using SqlSugar; namespace Service.System.Dict { [Scope("SingleInstance")] public class SysDictDataService : BaseServices { private readonly SysDicDataRepository _sysDictDataRep; public SysDictDataService(SysDicDataRepository sysDictDataRep) { _sysDictDataRep = sysDictDataRep; base.BaseDal = sysDictDataRep; } /// /// 获取字典值分页列表 🔖 /// /// /// public async Task> Page(PageDictDataReq input) { RefAsync total = 0; var items = await _sysDictDataRep.QueryListByClauseAsync( u => u.DictTypeId == input.DictTypeId, !string.IsNullOrEmpty(input.Code?.Trim()), u => u.Code.Contains(input.Code), !string.IsNullOrEmpty(input.Value?.Trim()), u => u.Value.Contains(input.Value), u => new { u.OrderNo, u.Code }, input.Page, input.PageSize, total); return SqlSugarPagedExtensions.CreateSqlSugarPagedList(items, total, input.Page, input.PageSize); } /// /// 获取字典值列表 🔖 /// /// public async Task> GetList(GetDataDictDataReq input) { return await GetDictDataListByDictTypeId(input.DictTypeId); } /// /// 增加字典值 🔖 /// /// /// public async Task AddDictData(AddDictDataReq input) { string result = ""; var isExist = await _sysDictDataRep.QueryByClauseAsync(u => u.Code == input.Code && u.DictTypeId == input.DictTypeId); if (isExist != null) result = "字典值已存在,名称或编码重复"; await _sysDictDataRep.InsertAsync(input.Adapt()); return result; } /// /// 更新字典值 🔖 /// /// /// public async Task UpdateDictData(UpdateDictDataReq input) { string result = ""; var isExist = await _sysDictDataRep.QueryByClauseAsync(u => u.Id == input.Id); if (isExist == null) result = "字典值不存在"; isExist = await _sysDictDataRep.QueryByClauseAsync(u => u.Code == input.Code && u.DictTypeId == input.DictTypeId && u.Id != input.Id); if (isExist != null) result = "字典值已存在,名称或编码重复"; await _sysDictDataRep.UpdateAsync(input.Adapt()); return result; } /// /// 删除字典值 🔖 /// /// /// public async Task DeleteDictData(DeleteDictDataReq input) { string result = ""; var dictData = await _sysDictDataRep.QueryByClauseAsync(u => u.Id == input.Id); if (dictData == null) result = "字典值不存在"; await _sysDictDataRep.DeleteAsync(dictData); return result; } /// /// 获取字典值详情 🔖 /// /// /// public async Task GetDetail(DictDataReq input) { return await _sysDictDataRep.QueryByClauseAsync(u => u.Id == input.Id); } /// /// 修改字典值状态 🔖 /// /// /// public async Task SetStatus(DictDataReq input) { string result = ""; var dictData = await _sysDictDataRep.QueryByClauseAsync(u => u.Id == input.Id); if (dictData == null) result = "字典值不存在"; if (!Enum.IsDefined(typeof(StatusEnum), input.Status)) result = "字典状态错误"; dictData.Status = input.Status; await _sysDictDataRep.UpdateAsync(dictData); return result; } /// /// 根据字典类型Id获取字典值集合 /// /// /// public async Task> GetDictDataListByDictTypeId(long dictTypeId) { return await _sysDictDataRep.QueryByOrderByClauseAsync( u => u.DictTypeId == dictTypeId, u => new { u.OrderNo, u.Code }); } /// /// 根据字典类型编码获取字典值集合 🔖 /// /// /// public async Task> GetDataList(string code) { return await _sysDictDataRep.QueryByClauseAsync( (u, a) => u.Id == a.DictTypeId, (u, a) => u.Code == code && u.Status == StatusEnum.Enable && a.Status == StatusEnum.Enable, (u, a) => new { a.OrderNo, a.Code }, (u, a) => a); } /// /// 根据查询条件获取字典值集合 🔖 /// /// /// public async Task> GetDataList(QueryDictDataReq input) { return await _sysDictDataRep.QueryByClauseAsync( (u, a) => u.Id == a.DictTypeId, (u, a) => u.Code == input.Code, input.Status.HasValue, (u, a) => a.Status == (StatusEnum)input.Status.Value, (u, a) => new { a.OrderNo, a.Code }, (u, a) => a); } } }