using DS.Module.Core; using DS.Module.Core.Extensions; using DS.Module.UserModule; using DS.WMS.Core.Sys.Dtos; using DS.WMS.Core.Sys.Entity; using DS.WMS.Core.Sys.Interface; using Mapster; using Microsoft.Extensions.DependencyInjection; using SqlSugar; namespace DS.WMS.Core.Sys.Method; /// /// 多语言设置服务 /// public class LanguageSetService:ILanguageSetService { private readonly IServiceProvider _serviceProvider; private readonly ISqlSugarClient db; private readonly IUser user; private readonly ICommonService _commonService; /// /// /// /// public LanguageSetService(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; db = _serviceProvider.GetRequiredService(); user = _serviceProvider.GetRequiredService(); _commonService = _serviceProvider.GetRequiredService(); } public DataResult> GetListByPage(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 EditLanguageSet(LanguageSetReq req) { if (req.Id == 0) { var isExist = db.Queryable().Where(x => x.MultiCode == req.MultiCode && x.LanguageType == req.LanguageType).First(); if (isExist != null) { return DataResult.Failed("多语言配置信息已存在!"); } var data = req.Adapt(); var entity = db.Insertable(data).ExecuteReturnEntity(); return DataResult.Successed("添加成功!", entity.Id); } else { var info = db.Queryable().Where(x => x.Id == req.Id).First(); info = req.Adapt(info); db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); return DataResult.Successed("更新成功!"); } } public DataResult GetLanguageSetInfo(string id) { var data = db.Queryable() .Where(a => a.Id == long.Parse(id)) .Select() .First(); return DataResult.Success(data); } /// /// 获取多语言常量列表 /// /// public DataResult> GetLanguageConstList() { var data = new List(); var list = ConstUtil.GetMultiLanguageFields(); foreach (var item in list) { data.Add(new MultiLanguageConstRes() { Key = item.Key, Value = item.Value }); } return DataResult>.Success(data); } /// /// 获取当前租户已有的多语言信息 /// /// 语言类型 /// public DataResult> GetExistLanguageConstList(string languageType) { var data = db.Queryable() .Where(a => a.LanguageType == languageType) .Select(n=>n.MultiCode) .ToList(); return DataResult>.Success(data); } /// /// 导入多语言配置 /// /// /// public DataResult ImportMultiLanguageSet(ImportLanguageSetReq model) { var list = new List(); foreach (var item in model.LanguageSets) { if (!db.Queryable().Where(x=>x.LanguageType == model.LanguageType && x.MultiCode == item.Key).Any()) { list.Add(new SysLanguageSet() { LanguageType = model.LanguageType, MultiCode = item.Key, Content = item.Value }); } } if (list.Count>0) { db.Insertable(list).ExecuteCommand(); } return DataResult.Successed("导入成功!",MultiLanguageConst.DataImportSuccess); } }