using DS.Module.Core; using DS.Module.Core.Extensions; using DS.Module.UserModule; using DS.WMS.Core.System.Dtos; using DS.WMS.Core.System.Entity; using DS.WMS.Core.System.Interface; using Mapster; using Microsoft.Extensions.DependencyInjection; using SqlSugar; namespace DS.WMS.Core.System.Method; /// /// /// public class SysDictionaryService:ISysDictionaryService { private readonly IServiceProvider _serviceProvider; private readonly ISqlSugarClient db; private readonly IUser user; /// /// /// /// public SysDictionaryService(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; db = _serviceProvider.GetRequiredService(); user = _serviceProvider.GetRequiredService(); } /// /// /// /// /// public DataResult> GetListByPage(PageRequest request) { //序列化查询条件 var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition); var data = db.Queryable().Where(x=>x.DbSql == null || x.DbSql == "" ) .Select() .Where(whereList).ToQueryPage(request.PageCondition); return data; } /// /// /// /// /// /// public DataResult GetSysDictionaryInfo(int id) { var data = db.Queryable() .Where(a => a.Dic_ID == id) .Select() .First(); return DataResult.Success(data); } public DataResult EditSysDictionaryInfo(SysDictionaryInput model) { if (model.Dic_ID.ToString().IsNullOrEmpty()) { var isExist = db.Queryable().Where(x => x.DicNo == model.DicNo).First(); if (isExist!=null) { return DataResult.Failed("字典唯一编码已存在!"); } var data = model.Adapt(); db.Insertable(data).ExecuteCommand(); return DataResult.Successed("添加成功!"); } else { var info =db.Queryable().Where(x => x.Dic_ID == model.Dic_ID).First(); var data = model.Adapt(info); db.Updateable(data).IgnoreColumns(ignoreAllNullColumns:true).ExecuteCommand(); return DataResult.Successed("更新成功!"); } } public DataResult> GetSysDictionaryList(PageRequest request) { //序列化查询条件 var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition); var data = db.Queryable() .Select() .Where(whereList).ToQueryPage(request.PageCondition); return data; } public DataResult GetSysDictionaryListInfo(int id) { var data = db.Queryable() .Where(a => a.DicList_ID == id) .Select() .First(); return DataResult.Success(data); } public DataResult EditSysDictionaryListInfo(SysDictionaryListInput model) { if (model.DicList_ID.ToString().IsNullOrEmpty()) { var isExist = db.Queryable().Where(x => x.DicName == model.DicName && x.Dic_ID == model.Dic_ID).First(); if (isExist!=null) { return DataResult.Failed("字典唯一编码已存在!"); } var data = model.Adapt(); db.Insertable(data).ExecuteCommand(); return DataResult.Successed("添加成功!"); } else { var info =db.Queryable().Where(x => x.DicList_ID == model.DicList_ID).First(); var data = model.Adapt(info); db.Updateable(data).IgnoreColumns(ignoreAllNullColumns:true).ExecuteCommand(); return DataResult.Successed("更新成功!"); } } /// /// /// /// /// public DataResult DelSysDictionaryListInfo(int id) { var info =db.Queryable() .Where(a => a.DicList_ID == id) .First(); if (info.IsNull()) { return DataResult.Failed("字典明细不存在!"); } db.Deleteable(info).ExecuteCommand(); return DataResult.Successed("删除成功!"); } }