WMSlite/WmsLite.Api/Repositories/InventoryTransactionRepository.cs
zhougf fa1b286463 Add WmsLite monorepo with JWT auth, tenant context, and project READMEs.
Implement API security baseline (sys_user, JWT, audit fields, transactions,
unique constraints) and Web real login with 401 handling. Document setup
and development workflows in root, WmsLite.Api, and WmsLite.Web README files.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-24 14:17:47 +08:00

56 lines
1.9 KiB
C#

using System;
using System.Threading.Tasks;
using SqlSugar;
using WmsLite.Api.Common;
using WmsLite.Api.Dtos.Inventory;
using WmsLite.Api.Models;
using WmsLite.Api.Repositories.Interfaces;
namespace WmsLite.Api.Repositories;
public class InventoryTransactionRepository : IInventoryTransactionRepository
{
private readonly ISqlSugarClient _db;
public InventoryTransactionRepository(ISqlSugarClient db)
{
_db = db;
}
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 = query.TenantId.Trim();
var owner = query.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
};
}
}