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;
///
///
///
public class TenantService : ITenantService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
///
///
///
///
public TenantService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService();
}
///
///
///
///
///
public DataResult> GetListByPage(PageRequest request)
{
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = db.Queryable()
.Where(whereList).ToQueryPage(request.PageCondition);
return data;
}
///
///
///
///
///
public DataResult EditTenant(TenantReq model)
{
if (model.Id.IsNullOrEmpty())
{
var isExist = db.Queryable().Where(x => x.TaxNo == model.TaxNo).First();
if (isExist != null)
{
return DataResult.Failed("租户唯一编码已存在!");
}
var data = model.MapTo();
db.Insertable(data).ExecuteCommand();
return DataResult.Successed("添加成功!");
}
else
{
var info = db.Queryable().Where(x => x.Id == model.Id).First();
info = model.MapTo();
db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
return DataResult.Successed("更新成功!");
}
}
///
///
///
///
///
public DataResult GetTenantInfo(string id)
{
var data = db.Queryable()
.Where(a => a.Id ==long.Parse(id))
.First();
return DataResult.Success(data);
}
}