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:
zhougfandCursor committed 2026-05-24 14:17:47 +08:00
commit fa1b286463
241 files changed
+31188

No files matched your search

+142
View File
@@ -0,0 +1,142 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using SqlSugar;
using WmsLite.Api.Common;
using WmsLite.Api.Dtos.Common;
using WmsLite.Api.Infrastructure.Auth;
using WmsLite.Api.Models;
using WmsLite.Api.Repositories.Interfaces;
namespace WmsLite.Api.Repositories;
public class BaseRepository<TEntity> : IBaseRepository<TEntity> where TEntity : BaseEntity, new()
{
protected readonly ISqlSugarClient Db;
private readonly ICurrentUserContext _userContext;
public BaseRepository(ISqlSugarClient db, ICurrentUserContext userContext)
{
Db = db;
_userContext = userContext;
}
public virtual async Task<TEntity?> GetByIdAsync(long id)
{
return await Db.Queryable<TEntity>()
.Where(x => !x.IsDeleted && x.Id == id)
.FirstAsync();
}
public virtual async Task<TEntity?> GetByIdAsync(long id, string tenantId, string ownerCode)
{
var tenant = tenantId.Trim();
var owner = ownerCode.Trim();
return await Db.Queryable<TEntity>()
.Where(x => !x.IsDeleted && x.Id == id && x.TenantId == tenant && x.OwnerCode == owner)
.FirstAsync();
}
public virtual async Task<List<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> predicate)
{
return await Db.Queryable<TEntity>()
.Where(x => !x.IsDeleted)
.Where(predicate)
.ToListAsync();
}
public virtual async Task<PagedResult<TEntity>> GetPagedListAsync(BasePagedQuery 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();
RefAsync<int> total = 0;
var items = await Db.Queryable<TEntity>()
.Where(x => !x.IsDeleted && x.TenantId == tenantId && x.OwnerCode == ownerCode)
.OrderByDescending(x => x.UpdateTime)
.OrderByDescending(x => x.CreateTime)
.ToPageListAsync(pageIndex, pageSize, total);
return new PagedResult<TEntity>
{
PageIndex = pageIndex,
PageSize = pageSize,
TotalCount = total,
Items = items
};
}
public virtual async Task<long> InsertAsync(TEntity entity)
{
entity.Id = entity.Id == 0 ? SnowFlakeSingle.Instance.NextId() : entity.Id;
entity.CreateTime ??= DateTime.Now;
entity.IsDeleted = false;
if (_userContext.IsAuthenticated)
{
entity.CreateBy = _userContext.UserId;
}
await Db.Insertable(entity).ExecuteCommandAsync();
return entity.Id;
}
public virtual async Task<int> UpdateAsync(TEntity entity)
{
entity.UpdateTime = DateTime.Now;
if (_userContext.IsAuthenticated)
{
entity.UpdateBy = _userContext.UserId;
}
return await Db.Updateable(entity).ExecuteCommandAsync();
}
public virtual async Task<int> SoftDeleteAsync(long id)
{
if (_userContext.IsAuthenticated)
{
var uid = _userContext.UserId;
return await Db.Updateable<TEntity>()
.SetColumns(x => x.IsDeleted == true)
.SetColumns(x => x.UpdateTime == DateTime.Now)
.SetColumns(x => x.DeleteTime == DateTime.Now)
.SetColumns(x => x.DeleteBy == uid)
.Where(x => x.Id == id)
.ExecuteCommandAsync();
}
return await Db.Updateable<TEntity>()
.SetColumns(x => x.IsDeleted == true)
.SetColumns(x => x.UpdateTime == DateTime.Now)
.SetColumns(x => x.DeleteTime == DateTime.Now)
.Where(x => x.Id == id)
.ExecuteCommandAsync();
}
public virtual async Task<int> SoftDeleteAsync(long id, string tenantId, string ownerCode)
{
var tenant = tenantId.Trim();
var owner = ownerCode.Trim();
if (_userContext.IsAuthenticated)
{
var uid = _userContext.UserId;
return await Db.Updateable<TEntity>()
.SetColumns(x => x.IsDeleted == true)
.SetColumns(x => x.UpdateTime == DateTime.Now)
.SetColumns(x => x.DeleteTime == DateTime.Now)
.SetColumns(x => x.DeleteBy == uid)
.Where(x => x.Id == id && x.TenantId == tenant && x.OwnerCode == owner)
.ExecuteCommandAsync();
}
return await Db.Updateable<TEntity>()
.SetColumns(x => x.IsDeleted == true)
.SetColumns(x => x.UpdateTime == DateTime.Now)
.SetColumns(x => x.DeleteTime == DateTime.Now)
.Where(x => x.Id == id && x.TenantId == tenant && x.OwnerCode == owner)
.ExecuteCommandAsync();
}
}