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.

115 lines
3.7 KiB
C#

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 ConfigService : IConfigService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly IUser user;
/// <summary>
///
/// </summary>
/// <param name="serviceProvider"></param>
public ConfigService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>();
}
/// <summary>
/// 列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public DataResult<List<ConfigRes>> GetListByPage(PageRequest request)
{
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = db.Queryable<SysConfig>()
.Where(whereList)
.Select<ConfigRes>().ToQueryPage(request.PageCondition);
return data;
}
/// <summary>
/// 编辑
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
public DataResult EditConfig(ConfigReq req)
{
if (req.Id == 0)
{
if (db.Queryable<SysConfig>().Where(x=>x.Code == req.Code).Any())
{
return DataResult.Failed("系统参数已存在!",MultiLanguageConst.ConfigExist);
}
var data = req.Adapt<SysConfig>();
var entity = db.Insertable(data).ExecuteReturnEntity();
return DataResult.Successed("添加成功!", entity.Id,MultiLanguageConst.DataCreateSuccess);
}
else
{
var info = db.Queryable<SysConfig>().Where(x => x.Id == req.Id).First();
info = req.Adapt(info);
db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
return DataResult.Successed("更新成功!",MultiLanguageConst.DataUpdateSuccess);
}
}
/// <summary>
/// 详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataResult<ConfigRes> GetConfigInfo(string id)
{
var data = db.Queryable<SysConfig>()
.Where(a => a.Id == long.Parse(id))
.Select<ConfigRes>()
.First();
return DataResult<ConfigRes>.Success(data,MultiLanguageConst.DataQuerySuccess);
}
5 months ago
#region 获取系统参数详情
/// <summary>
/// 获取系统参数详情
/// </summary>
/// <param name="code">参数代码</param>
/// <param name="tenantId">租户ID</param>
/// <param name="isSystemDefault">是否默认系统租户 true-是tenantId不传参数false-否tenantId必传</param>
/// <returns></returns>
public async Task<DataResult<ConfigRes>> GetConfig(string code, Nullable<long> tenantId = null, bool isSystemDefault = true)
{
//这里如果是默认则租户默认ID
if (isSystemDefault)
tenantId = 1288018625843826688;
if(!tenantId.HasValue)
DataResult<ConfigRes>.Failed("租户ID不能为空");
var data = await db.Queryable<SysConfig>().Filter(null, true)
.Where(x => x.Code == code && x.TenantId == tenantId).Select<ConfigRes>().FirstAsync();
if(data != null)
DataResult<ConfigRes>.Success(data);
return DataResult<ConfigRes>.FailedData(data);
5 months ago
}
#endregion
}