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,109 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using WmsLite.Api.Common;
|
||||
using WmsLite.Api.Dtos.Warehouse;
|
||||
using WmsLite.Api.Infrastructure.Auth;
|
||||
using WmsLite.Api.Models;
|
||||
using WmsLite.Api.Repositories.Interfaces;
|
||||
using WmsLite.Api.Services.Interfaces;
|
||||
|
||||
namespace WmsLite.Api.Services;
|
||||
|
||||
public class WarehouseService : IWarehouseService
|
||||
{
|
||||
private readonly IWarehouseRepository _warehouseRepository;
|
||||
private readonly ICurrentUserContext _userContext;
|
||||
|
||||
public WarehouseService(IWarehouseRepository warehouseRepository, ICurrentUserContext userContext)
|
||||
{
|
||||
_warehouseRepository = warehouseRepository;
|
||||
_userContext = userContext;
|
||||
}
|
||||
|
||||
public async Task<PagedResult<WarehouseViewDto>> GetPagedListAsync(WarehousePagedQuery query)
|
||||
{
|
||||
query.TenantId = _userContext.TenantId.Trim();
|
||||
query.OwnerCode = _userContext.OwnerCode.Trim();
|
||||
var page = await _warehouseRepository.GetPagedListAsync(query);
|
||||
var items = page.Items.ConvertAll(MapToView);
|
||||
return new PagedResult<WarehouseViewDto>
|
||||
{
|
||||
PageIndex = page.PageIndex,
|
||||
PageSize = page.PageSize,
|
||||
TotalCount = page.TotalCount,
|
||||
Items = items
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<WarehouseViewDto?> GetByIdAsync(long id, string tenantId, string ownerCode)
|
||||
{
|
||||
var entity = await _warehouseRepository.GetByIdAsync(id, _userContext.TenantId.Trim(), _userContext.OwnerCode.Trim());
|
||||
return entity is null ? null : MapToView(entity);
|
||||
}
|
||||
|
||||
public async Task<WarehouseViewDto> CreateAsync(WarehouseSaveRequest request)
|
||||
{
|
||||
var code = request.Code.Trim();
|
||||
var name = request.Name.Trim();
|
||||
|
||||
if (await _warehouseRepository.GetByCodeAsync(_userContext.TenantId.Trim(), _userContext.OwnerCode.Trim(), code) is not null)
|
||||
{
|
||||
throw new BusinessException($"仓库编码已存在: {code}");
|
||||
}
|
||||
|
||||
var entity = new Warehouse
|
||||
{
|
||||
TenantId = _userContext.TenantId.Trim(),
|
||||
OwnerCode = _userContext.OwnerCode.Trim(),
|
||||
Code = code,
|
||||
Name = name,
|
||||
Attrs = request.Attrs
|
||||
};
|
||||
|
||||
await _warehouseRepository.InsertAsync(entity);
|
||||
return MapToView(entity);
|
||||
}
|
||||
|
||||
public async Task<WarehouseViewDto?> UpdateAsync(WarehouseUpdateRequest request)
|
||||
{
|
||||
var entity = await _warehouseRepository.GetByIdAsync(request.Id, _userContext.TenantId.Trim(), _userContext.OwnerCode.Trim());
|
||||
if (entity is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var code = request.Code.Trim();
|
||||
var name = request.Name.Trim();
|
||||
|
||||
var existing = await _warehouseRepository.GetByCodeAsync(_userContext.TenantId.Trim(), _userContext.OwnerCode.Trim(), code);
|
||||
if (existing is not null && existing.Id != entity.Id)
|
||||
{
|
||||
throw new BusinessException($"仓库编码已被占用: {code}");
|
||||
}
|
||||
|
||||
entity.Code = code;
|
||||
entity.Name = name;
|
||||
entity.Attrs = request.Attrs;
|
||||
|
||||
await _warehouseRepository.UpdateAsync(entity);
|
||||
return MapToView(entity);
|
||||
}
|
||||
|
||||
public Task<int> DeleteAsync(long id, string tenantId, string ownerCode)
|
||||
{
|
||||
return _warehouseRepository.SoftDeleteAsync(id, _userContext.TenantId.Trim(), _userContext.OwnerCode.Trim());
|
||||
}
|
||||
|
||||
private static WarehouseViewDto MapToView(Warehouse entity)
|
||||
{
|
||||
return new WarehouseViewDto
|
||||
{
|
||||
Id = entity.Id,
|
||||
TenantId = entity.TenantId,
|
||||
OwnerCode = entity.OwnerCode,
|
||||
Code = entity.Code,
|
||||
Name = entity.Name,
|
||||
Attrs = entity.Attrs
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user