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.

87 lines
2.4 KiB
C#

using DS.Module.Core;
using DS.Module.Core.Extensions;
using DS.WMS.Core.System.Dtos;
using DS.WMS.Core.System.Entity;
using DS.WMS.Core.System.Interface;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
namespace DS.WMS.Core.System.Method;
/// <summary>
///
/// </summary>
public class TenantService : ITenantService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
/// <summary>
///
/// </summary>
/// <param name="serviceProvider"></param>
public TenantService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
}
/// <summary>
///
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public DataResult<List<SysTenant>> GetListByPage(PageRequest request)
{
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = db.Queryable<SysTenant>()
.Where(whereList).ToQueryPage(request.PageCondition);
return data;
}
/// <summary>
///
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public DataResult EditTenant(TenantInput model)
{
if (model.Id.IsNullOrEmpty())
{
var isExist = db.Queryable<SysTenant>().Where(x => x.Code == model.Code).First();
if (isExist != null)
{
return DataResult.Failed("租户唯一编码已存在!");
}
var data = model.MapTo<TenantInput, SysTenant>();
db.Insertable(data).ExecuteCommand();
return DataResult.Successed("添加成功!");
}
else
{
var info = db.Queryable<SysTenant>().Where(x => x.Id == model.Id).First();
info = model.MapTo<TenantInput, SysTenant>();
db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
return DataResult.Successed("更新成功!");
}
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataResult<SysTenant> GetTenantInfo(string id)
{
var data = db.Queryable<SysTenant>()
.Where(a => a.Id == id)
.First();
return DataResult<SysTenant>.Success(data);
}
}