|
|
|
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(TenantReq model)
|
|
|
|
{
|
|
|
|
if (model.Id.IsNullOrEmpty())
|
|
|
|
{
|
|
|
|
var isExist = db.Queryable<SysTenant>().Where(x => x.TaxNo == model.TaxNo).First();
|
|
|
|
if (isExist != null)
|
|
|
|
{
|
|
|
|
return DataResult.Failed("租户唯一编码已存在!");
|
|
|
|
}
|
|
|
|
|
|
|
|
var data = model.MapTo<TenantReq, SysTenant>();
|
|
|
|
|
|
|
|
db.Insertable(data).ExecuteCommand();
|
|
|
|
|
|
|
|
return DataResult.Successed("添加成功!");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var info = db.Queryable<SysTenant>().Where(x => x.Id == model.Id).First();
|
|
|
|
|
|
|
|
info = model.MapTo<TenantReq, 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 ==long.Parse(id))
|
|
|
|
.First();
|
|
|
|
return DataResult<SysTenant>.Success(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|