You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
4.5 KiB
C#

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;
/// <summary>
/// 多语言设置服务
/// </summary>
public class LanguageSetService:ILanguageSetService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly IUser user;
private readonly ICommonService _commonService;
/// <summary>
///
/// </summary>
/// <param name="serviceProvider"></param>
public LanguageSetService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>();
_commonService = _serviceProvider.GetRequiredService<ICommonService>();
}
public DataResult<List<LanguageSetRes>> GetListByPage(PageRequest request)
{
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = db.Queryable<SysLanguageSet>()
.Select<LanguageSetRes>()
.Where(whereList).ToQueryPage(request.PageCondition);
return data;
}
public DataResult EditLanguageSet(LanguageSetReq req)
{
if (req.Id == 0)
{
var isExist = db.Queryable<SysLanguageSet>().Where(x => x.MultiCode == req.MultiCode && x.LanguageType == req.LanguageType).First();
if (isExist != null)
{
return DataResult.Failed("多语言配置信息已存在!");
}
var data = req.Adapt<SysLanguageSet>();
var entity = db.Insertable(data).ExecuteReturnEntity();
return DataResult.Successed("添加成功!", entity.Id);
}
else
{
var info = db.Queryable<SysLanguageSet>().Where(x => x.Id == req.Id).First();
info = req.Adapt(info);
db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
return DataResult.Successed("更新成功!");
}
}
public DataResult<LanguageSetRes> GetLanguageSetInfo(string id)
{
var data = db.Queryable<SysLanguageSet>()
.Where(a => a.Id == long.Parse(id))
.Select<LanguageSetRes>()
.First();
return DataResult<LanguageSetRes>.Success(data);
}
/// <summary>
/// 获取多语言常量列表
/// </summary>
/// <returns></returns>
public DataResult<List<MultiLanguageConstRes>> GetLanguageConstList()
{
var data = new List<MultiLanguageConstRes>();
var list = ConstUtil.GetMultiLanguageFields();
foreach (var item in list)
{
data.Add(new MultiLanguageConstRes()
{
Key = item.Key,
Value = item.Value
});
}
return DataResult<List<MultiLanguageConstRes>>.Success(data);
}
/// <summary>
/// 获取当前租户已有的多语言信息
/// </summary>
/// <param name="languageType">语言类型</param>
/// <returns></returns>
public DataResult<List<string>> GetExistLanguageConstList(string languageType)
{
var data = db.Queryable<SysLanguageSet>()
.Where(a => a.LanguageType == languageType)
.Select(n=>n.MultiCode)
.ToList();
return DataResult<List<string>>.Success(data);
}
/// <summary>
/// 导入多语言配置
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public DataResult ImportMultiLanguageSet(ImportLanguageSetReq model)
{
var list = new List<SysLanguageSet>();
foreach (var item in model.LanguageSets)
{
if (!db.Queryable<SysLanguageSet>().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);
}
}