'respository'
This commit is contained in:
1 parent
fa1b286463
commit
38ecbf82e5
41 files changed
+67
-120
No files matched your search
@@ -56,8 +56,8 @@ public class AreaRepository : BaseRepository<Area>, IAreaRepository
|
||||
{
|
||||
var pageIndex = query.PageIndex <= 0 ? 1 : query.PageIndex;
|
||||
var pageSize = query.PageSize <= 0 ? 20 : query.PageSize;
|
||||
var tenantId = query.TenantId.Trim();
|
||||
var ownerCode = query.OwnerCode.Trim();
|
||||
var tenantId = ScopeTenantId;
|
||||
var ownerCode = ScopeOwnerCode;
|
||||
|
||||
var kw = query.Keyword?.Trim();
|
||||
var dbQuery = Db.Queryable<Area>()
|
||||
|
||||
@@ -14,14 +14,18 @@ namespace WmsLite.Api.Repositories;
|
||||
public class BaseRepository<TEntity> : IBaseRepository<TEntity> where TEntity : BaseEntity, new()
|
||||
{
|
||||
protected readonly ISqlSugarClient Db;
|
||||
private readonly ICurrentUserContext _userContext;
|
||||
protected readonly ICurrentUserContext UserContext;
|
||||
|
||||
public BaseRepository(ISqlSugarClient db, ICurrentUserContext userContext)
|
||||
{
|
||||
Db = db;
|
||||
_userContext = userContext;
|
||||
UserContext = userContext;
|
||||
}
|
||||
|
||||
protected string ScopeTenantId => UserContext.TenantId.Trim();
|
||||
|
||||
protected string ScopeOwnerCode => UserContext.OwnerCode.Trim();
|
||||
|
||||
public virtual async Task<TEntity?> GetByIdAsync(long id)
|
||||
{
|
||||
return await Db.Queryable<TEntity>()
|
||||
@@ -50,8 +54,8 @@ public class BaseRepository<TEntity> : IBaseRepository<TEntity> where TEntity :
|
||||
{
|
||||
var pageIndex = query.PageIndex <= 0 ? 1 : query.PageIndex;
|
||||
var pageSize = query.PageSize <= 0 ? 20 : query.PageSize;
|
||||
var tenantId = query.TenantId.Trim();
|
||||
var ownerCode = query.OwnerCode.Trim();
|
||||
var tenantId = ScopeTenantId;
|
||||
var ownerCode = ScopeOwnerCode;
|
||||
|
||||
RefAsync<int> total = 0;
|
||||
var items = await Db.Queryable<TEntity>()
|
||||
@@ -74,9 +78,9 @@ public class BaseRepository<TEntity> : IBaseRepository<TEntity> where TEntity :
|
||||
entity.Id = entity.Id == 0 ? SnowFlakeSingle.Instance.NextId() : entity.Id;
|
||||
entity.CreateTime ??= DateTime.Now;
|
||||
entity.IsDeleted = false;
|
||||
if (_userContext.IsAuthenticated)
|
||||
if (UserContext.IsAuthenticated)
|
||||
{
|
||||
entity.CreateBy = _userContext.UserId;
|
||||
entity.CreateBy = UserContext.UserId;
|
||||
}
|
||||
|
||||
await Db.Insertable(entity).ExecuteCommandAsync();
|
||||
@@ -86,9 +90,9 @@ public class BaseRepository<TEntity> : IBaseRepository<TEntity> where TEntity :
|
||||
public virtual async Task<int> UpdateAsync(TEntity entity)
|
||||
{
|
||||
entity.UpdateTime = DateTime.Now;
|
||||
if (_userContext.IsAuthenticated)
|
||||
if (UserContext.IsAuthenticated)
|
||||
{
|
||||
entity.UpdateBy = _userContext.UserId;
|
||||
entity.UpdateBy = UserContext.UserId;
|
||||
}
|
||||
|
||||
return await Db.Updateable(entity).ExecuteCommandAsync();
|
||||
@@ -96,9 +100,9 @@ public class BaseRepository<TEntity> : IBaseRepository<TEntity> where TEntity :
|
||||
|
||||
public virtual async Task<int> SoftDeleteAsync(long id)
|
||||
{
|
||||
if (_userContext.IsAuthenticated)
|
||||
if (UserContext.IsAuthenticated)
|
||||
{
|
||||
var uid = _userContext.UserId;
|
||||
var uid = UserContext.UserId;
|
||||
return await Db.Updateable<TEntity>()
|
||||
.SetColumns(x => x.IsDeleted == true)
|
||||
.SetColumns(x => x.UpdateTime == DateTime.Now)
|
||||
@@ -120,9 +124,9 @@ public class BaseRepository<TEntity> : IBaseRepository<TEntity> where TEntity :
|
||||
{
|
||||
var tenant = tenantId.Trim();
|
||||
var owner = ownerCode.Trim();
|
||||
if (_userContext.IsAuthenticated)
|
||||
if (UserContext.IsAuthenticated)
|
||||
{
|
||||
var uid = _userContext.UserId;
|
||||
var uid = UserContext.UserId;
|
||||
return await Db.Updateable<TEntity>()
|
||||
.SetColumns(x => x.IsDeleted == true)
|
||||
.SetColumns(x => x.UpdateTime == DateTime.Now)
|
||||
|
||||
@@ -32,8 +32,8 @@ public class ContainerRepository : BaseRepository<Container>, IContainerReposito
|
||||
{
|
||||
var pageIndex = query.PageIndex <= 0 ? 1 : query.PageIndex;
|
||||
var pageSize = query.PageSize <= 0 ? 20 : query.PageSize;
|
||||
var tenantId = query.TenantId.Trim();
|
||||
var ownerCode = query.OwnerCode.Trim();
|
||||
var tenantId = ScopeTenantId;
|
||||
var ownerCode = ScopeOwnerCode;
|
||||
var kw = query.Keyword?.Trim();
|
||||
|
||||
var dbQuery = Db.Queryable<Container>()
|
||||
|
||||
@@ -22,8 +22,8 @@ public class InventoryRepository : BaseRepository<Inventory>, IInventoryReposito
|
||||
{
|
||||
var pageIndex = query.PageIndex <= 0 ? 1 : query.PageIndex;
|
||||
var pageSize = query.PageSize <= 0 ? 20 : query.PageSize;
|
||||
var tenantId = query.TenantId.Trim();
|
||||
var ownerCode = query.OwnerCode.Trim();
|
||||
var tenantId = ScopeTenantId;
|
||||
var ownerCode = ScopeOwnerCode;
|
||||
|
||||
var dbQuery = Db.Queryable<Inventory>()
|
||||
.Where(x => !x.IsDeleted && x.TenantId == tenantId && x.OwnerCode == ownerCode)
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
||||
using SqlSugar;
|
||||
using WmsLite.Api.Common;
|
||||
using WmsLite.Api.Dtos.Inventory;
|
||||
using WmsLite.Api.Infrastructure.Auth;
|
||||
using WmsLite.Api.Models;
|
||||
using WmsLite.Api.Repositories.Interfaces;
|
||||
|
||||
@@ -11,10 +12,12 @@ namespace WmsLite.Api.Repositories;
|
||||
public class InventoryTransactionRepository : IInventoryTransactionRepository
|
||||
{
|
||||
private readonly ISqlSugarClient _db;
|
||||
private readonly ICurrentUserContext _userContext;
|
||||
|
||||
public InventoryTransactionRepository(ISqlSugarClient db)
|
||||
public InventoryTransactionRepository(ISqlSugarClient db, ICurrentUserContext userContext)
|
||||
{
|
||||
_db = db;
|
||||
_userContext = userContext;
|
||||
}
|
||||
|
||||
public async Task<long> InsertAsync(InventoryTransaction entity)
|
||||
@@ -30,8 +33,8 @@ public class InventoryTransactionRepository : IInventoryTransactionRepository
|
||||
{
|
||||
var pageIndex = query.PageIndex <= 0 ? 1 : query.PageIndex;
|
||||
var pageSize = query.PageSize <= 0 ? 20 : query.PageSize;
|
||||
var tenant = query.TenantId.Trim();
|
||||
var owner = query.OwnerCode.Trim();
|
||||
var tenant = _userContext.TenantId.Trim();
|
||||
var owner = _userContext.OwnerCode.Trim();
|
||||
|
||||
var dbQuery = _db.Queryable<InventoryTransaction>()
|
||||
.Where(x => !x.IsDeleted && x.TenantId == tenant && x.OwnerCode == owner)
|
||||
|
||||
@@ -73,8 +73,8 @@ public class LocationRepository : BaseRepository<Location>, ILocationRepository
|
||||
{
|
||||
var pageIndex = query.PageIndex <= 0 ? 1 : query.PageIndex;
|
||||
var pageSize = query.PageSize <= 0 ? 20 : query.PageSize;
|
||||
var tenantId = query.TenantId.Trim();
|
||||
var ownerCode = query.OwnerCode.Trim();
|
||||
var tenantId = ScopeTenantId;
|
||||
var ownerCode = ScopeOwnerCode;
|
||||
|
||||
var dbQuery = Db.Queryable<Location>()
|
||||
.Where(x => !x.IsDeleted && x.TenantId == tenantId && x.OwnerCode == ownerCode)
|
||||
|
||||
@@ -49,8 +49,8 @@ public class MaterialRepository : BaseRepository<Material>, IMaterialRepository
|
||||
{
|
||||
var pageIndex = query.PageIndex <= 0 ? 1 : query.PageIndex;
|
||||
var pageSize = query.PageSize <= 0 ? 20 : query.PageSize;
|
||||
var tenantId = query.TenantId.Trim();
|
||||
var ownerCode = query.OwnerCode.Trim();
|
||||
var tenantId = ScopeTenantId;
|
||||
var ownerCode = ScopeOwnerCode;
|
||||
|
||||
var kw = query.Keyword?.Trim();
|
||||
var dbQuery = Db.Queryable<Material>()
|
||||
|
||||
@@ -41,8 +41,8 @@ public abstract class OrderRepositoryBase<TEntity, TQuery> : BaseRepository<TEnt
|
||||
ArgumentNullException.ThrowIfNull(query);
|
||||
var pageIndex = query.PageIndex <= 0 ? 1 : query.PageIndex;
|
||||
var pageSize = query.PageSize <= 0 ? 20 : query.PageSize;
|
||||
var tenant = (query.TenantId ?? string.Empty).Trim();
|
||||
var owner = (query.OwnerCode ?? string.Empty).Trim();
|
||||
var tenant = ScopeTenantId;
|
||||
var owner = ScopeOwnerCode;
|
||||
|
||||
// 注意:WhereIF(condition, sql, anonymousObject) 会在 condition 为 false 时仍对参数表达式求值,
|
||||
// 因此不能在匿名对象里对可能为 null 的 query.OrderNo / query.BizType 直接调用 Trim()。
|
||||
|
||||
@@ -32,8 +32,8 @@ public class SysTemplateRepository : BaseRepository<SysTemplate>, ISysTemplateRe
|
||||
{
|
||||
var pageIndex = query.PageIndex <= 0 ? 1 : query.PageIndex;
|
||||
var pageSize = query.PageSize <= 0 ? 20 : query.PageSize;
|
||||
var tenant = query.TenantId.Trim();
|
||||
var owner = query.OwnerCode.Trim();
|
||||
var tenant = ScopeTenantId;
|
||||
var owner = ScopeOwnerCode;
|
||||
|
||||
var dbQuery = Db.Queryable<SysTemplate>()
|
||||
.Where(x => !x.IsDeleted && x.TenantId == tenant && x.OwnerCode == owner)
|
||||
|
||||
@@ -49,8 +49,8 @@ public class WarehouseRepository : BaseRepository<Warehouse>, IWarehouseReposito
|
||||
{
|
||||
var pageIndex = query.PageIndex <= 0 ? 1 : query.PageIndex;
|
||||
var pageSize = query.PageSize <= 0 ? 20 : query.PageSize;
|
||||
var tenantId = query.TenantId.Trim();
|
||||
var ownerCode = query.OwnerCode.Trim();
|
||||
var tenantId = ScopeTenantId;
|
||||
var ownerCode = ScopeOwnerCode;
|
||||
|
||||
var kw = query.Keyword?.Trim();
|
||||
var dbQuery = Db.Queryable<Warehouse>()
|
||||
|
||||
@@ -66,8 +66,8 @@ public class ZoneRepository : BaseRepository<Zone>, IZoneRepository
|
||||
{
|
||||
var pageIndex = query.PageIndex <= 0 ? 1 : query.PageIndex;
|
||||
var pageSize = query.PageSize <= 0 ? 20 : query.PageSize;
|
||||
var tenantId = query.TenantId.Trim();
|
||||
var ownerCode = query.OwnerCode.Trim();
|
||||
var tenantId = ScopeTenantId;
|
||||
var ownerCode = ScopeOwnerCode;
|
||||
|
||||
var kw = query.Keyword?.Trim();
|
||||
var dbQuery = Db.Queryable<Zone>()
|
||||
|
||||
Reference in new issue
Block a user