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>
This commit is contained in:
commit
fa1b286463
241 files changed
+31188
No files matched your search
@@ -0,0 +1,171 @@
|
||||
using SqlSugar;
|
||||
using WmsLite.Api.Common;
|
||||
using WmsLite.Api.Dtos.Location;
|
||||
using WmsLite.Api.Infrastructure.Auth;
|
||||
using WmsLite.Api.Models;
|
||||
using WmsLite.Api.Repositories.Interfaces;
|
||||
|
||||
namespace WmsLite.Api.Repositories;
|
||||
|
||||
public class LocationRepository : BaseRepository<Location>, ILocationRepository
|
||||
{
|
||||
public LocationRepository(ISqlSugarClient db, ICurrentUserContext userContext) : base(db, userContext)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<Location?> GetByWarehouseAreaZoneAndLocationCodeAsync(
|
||||
string tenantId,
|
||||
string ownerCode,
|
||||
string warehouseCode,
|
||||
string areaCode,
|
||||
string zoneCode,
|
||||
string locationCode)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(warehouseCode)
|
||||
|| string.IsNullOrWhiteSpace(areaCode)
|
||||
|| string.IsNullOrWhiteSpace(zoneCode)
|
||||
|| string.IsNullOrWhiteSpace(locationCode))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var w = warehouseCode.Trim();
|
||||
var a = areaCode.Trim();
|
||||
var z = zoneCode.Trim();
|
||||
var l = locationCode.Trim();
|
||||
var tenant = tenantId.Trim();
|
||||
var owner = ownerCode.Trim();
|
||||
return await Db.Queryable<Location>()
|
||||
.Where(x =>
|
||||
!x.IsDeleted && x.TenantId == tenant && x.OwnerCode == owner && x.WarehouseCode == w
|
||||
&& x.AreaCode == a && x.ZoneCode == z && x.Code == l)
|
||||
.FirstAsync();
|
||||
}
|
||||
|
||||
public async Task<Location?> GetByWarehouseAreaAndLocationCodeAsync(
|
||||
string tenantId,
|
||||
string ownerCode,
|
||||
string warehouseCode,
|
||||
string areaCode,
|
||||
string locationCode)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(warehouseCode)
|
||||
|| string.IsNullOrWhiteSpace(areaCode)
|
||||
|| string.IsNullOrWhiteSpace(locationCode))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var w = warehouseCode.Trim();
|
||||
var a = areaCode.Trim();
|
||||
var l = locationCode.Trim();
|
||||
var tenant = tenantId.Trim();
|
||||
var owner = ownerCode.Trim();
|
||||
return await Db.Queryable<Location>()
|
||||
.Where(x =>
|
||||
!x.IsDeleted && x.TenantId == tenant && x.OwnerCode == owner && x.WarehouseCode == w
|
||||
&& x.AreaCode == a && x.Code == l)
|
||||
.OrderBy(x => x.ZoneCode)
|
||||
.FirstAsync();
|
||||
}
|
||||
|
||||
public async Task<PagedResult<Location>> GetPagedListAsync(LocationPagedQuery query)
|
||||
{
|
||||
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 dbQuery = Db.Queryable<Location>()
|
||||
.Where(x => !x.IsDeleted && x.TenantId == tenantId && x.OwnerCode == ownerCode)
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(query.WarehouseCode), x => x.WarehouseCode == query.WarehouseCode!.Trim())
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(query.AreaCode), x => x.AreaCode == query.AreaCode!.Trim())
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(query.ZoneCode), x => x.ZoneCode == query.ZoneCode!.Trim())
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(query.AisleCode), x => x.AisleCode == query.AisleCode!.Trim())
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(query.Code), x => x.Code.Contains(query.Code!.Trim()))
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(query.Name),
|
||||
x => x.Name != null && x.Name.Contains(query.Name!.Trim()))
|
||||
.WhereIF(query.LocationStatus.HasValue, x => x.LocationStatus == query.LocationStatus!.Value)
|
||||
.WhereIF(query.IsOuter.HasValue, x => x.IsOuter == query.IsOuter!.Value)
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(query.ContainerCode),
|
||||
x => x.ContainerCode != null && x.ContainerCode.Contains(query.ContainerCode!.Trim()));
|
||||
|
||||
RefAsync<int> total = 0;
|
||||
var items = await dbQuery
|
||||
.OrderBy(x => x.Id)
|
||||
.ToPageListAsync(pageIndex, pageSize, total);
|
||||
|
||||
return new PagedResult<Location>
|
||||
{
|
||||
PageIndex = pageIndex,
|
||||
PageSize = pageSize,
|
||||
TotalCount = total,
|
||||
Items = items
|
||||
};
|
||||
}
|
||||
|
||||
/// <returns>已存在于库内的编码。</returns>
|
||||
public async Task<HashSet<string>> GetExistingCodesAsync(
|
||||
string tenantId,
|
||||
string ownerCode,
|
||||
string warehouseCode,
|
||||
string areaCode,
|
||||
string zoneCode,
|
||||
IReadOnlyCollection<string> codes)
|
||||
{
|
||||
if (codes.Count == 0)
|
||||
{
|
||||
return new HashSet<string>(StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
var tenant = tenantId.Trim();
|
||||
var owner = ownerCode.Trim();
|
||||
var w = warehouseCode.Trim();
|
||||
var a = areaCode.Trim();
|
||||
var z = zoneCode.Trim();
|
||||
var list = codes
|
||||
.Where(static c => !string.IsNullOrWhiteSpace(c))
|
||||
.Select(static c => c.Trim())
|
||||
.Distinct()
|
||||
.ToList();
|
||||
if (list.Count == 0)
|
||||
{
|
||||
return new HashSet<string>(StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
var existing = await Db.Queryable<Location>()
|
||||
.Where(x =>
|
||||
!x.IsDeleted && x.TenantId == tenant && x.OwnerCode == owner && x.WarehouseCode == w
|
||||
&& x.AreaCode == a && x.ZoneCode == z)
|
||||
.Where(x => list.Contains(x.Code))
|
||||
.Select(x => x.Code)
|
||||
.ToListAsync();
|
||||
|
||||
return existing.ToHashSet(StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
/// <summary>批量插入。</summary>
|
||||
public async Task InsertManyAsync(IReadOnlyList<Location> entities)
|
||||
{
|
||||
if (entities.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var now = DateTime.Now;
|
||||
var list = new List<Location>(entities.Count);
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
if (entity.Id == 0)
|
||||
{
|
||||
entity.Id = SnowFlakeSingle.Instance.NextId();
|
||||
}
|
||||
|
||||
entity.CreateTime ??= now;
|
||||
entity.IsDeleted = false;
|
||||
list.Add(entity);
|
||||
}
|
||||
|
||||
await Db.Insertable(list).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user