59 lines
2.1 KiB
C#
59 lines
2.1 KiB
C#
using System;
|
|
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;
|
|
|
|
namespace WmsLite.Api.Repositories;
|
|
|
|
public class InventoryTransactionRepository : IInventoryTransactionRepository
|
|
{
|
|
private readonly ISqlSugarClient _db;
|
|
private readonly ICurrentUserContext _userContext;
|
|
|
|
public InventoryTransactionRepository(ISqlSugarClient db, ICurrentUserContext userContext)
|
|
{
|
|
_db = db;
|
|
_userContext = userContext;
|
|
}
|
|
|
|
public async Task<long> InsertAsync(InventoryTransaction entity)
|
|
{
|
|
entity.Id = entity.Id == 0 ? SnowFlakeSingle.Instance.NextId() : entity.Id;
|
|
entity.CreateTime ??= DateTime.Now;
|
|
entity.IsDeleted = false;
|
|
await _db.Insertable(entity).ExecuteCommandAsync();
|
|
return entity.Id;
|
|
}
|
|
|
|
public async Task<PagedResult<InventoryTransaction>> GetPagedListAsync(InventoryTransactionPagedQuery query)
|
|
{
|
|
var pageIndex = query.PageIndex <= 0 ? 1 : query.PageIndex;
|
|
var pageSize = query.PageSize <= 0 ? 20 : query.PageSize;
|
|
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)
|
|
.WhereIF(query.InventoryId.HasValue, x => x.InventoryId == query.InventoryId!.Value)
|
|
.WhereIF(query.MovementType.HasValue, x => x.MovementType == query.MovementType!.Value)
|
|
.WhereIF(!string.IsNullOrWhiteSpace(query.BizNo), x => x.BizNo != null && x.BizNo.Contains(query.BizNo!.Trim()));
|
|
|
|
RefAsync<int> total = 0;
|
|
var items = await dbQuery
|
|
.OrderByDescending(x => x.CreateTime)
|
|
.ToPageListAsync(pageIndex, pageSize, total);
|
|
|
|
return new PagedResult<InventoryTransaction>
|
|
{
|
|
PageIndex = pageIndex,
|
|
PageSize = pageSize,
|
|
TotalCount = total,
|
|
Items = items
|
|
};
|
|
}
|
|
}
|