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>
61 lines
2.1 KiB
C#
61 lines
2.1 KiB
C#
using WmsLite.Api.Dtos.Dictionary;
|
|
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 SysDictService : ISysDictService
|
|
{
|
|
private readonly ISysDictItemRepository _repository;
|
|
private readonly ICurrentUserContext _userContext;
|
|
|
|
public SysDictService(ISysDictItemRepository repository, ICurrentUserContext userContext)
|
|
{
|
|
_repository = repository;
|
|
_userContext = userContext;
|
|
}
|
|
|
|
public async Task<Dictionary<string, Dictionary<string, string>>> GetMergedMapAsync(SysDictionaryMapRequest request)
|
|
{
|
|
IReadOnlyList<string>? filter = request.Categories?.Where(static c => !string.IsNullOrWhiteSpace(c))
|
|
.Select(static c => c.Trim())
|
|
.Distinct(StringComparer.Ordinal)
|
|
.ToList();
|
|
|
|
var rows = await _repository.ListEnabledAsync(_userContext.TenantId.Trim(), _userContext.OwnerCode.Trim(), filter);
|
|
|
|
var platform = rows.Where(static r =>
|
|
string.Equals(r.TenantId, "system", StringComparison.OrdinalIgnoreCase)
|
|
&& string.Equals(r.OwnerCode, "system", StringComparison.OrdinalIgnoreCase))
|
|
.ToList();
|
|
|
|
var tenantOwned = rows.Where(r =>
|
|
!string.Equals(r.TenantId, "system", StringComparison.OrdinalIgnoreCase)
|
|
|| !string.Equals(r.OwnerCode, "system", StringComparison.OrdinalIgnoreCase))
|
|
.ToList();
|
|
|
|
var merged = new Dictionary<string, Dictionary<string, string>>(StringComparer.OrdinalIgnoreCase);
|
|
|
|
void Apply(IEnumerable<SysDictItem> source)
|
|
{
|
|
foreach (var row in source)
|
|
{
|
|
if (!merged.TryGetValue(row.Category, out var inner))
|
|
{
|
|
inner = new Dictionary<string, string>(StringComparer.Ordinal);
|
|
merged[row.Category] = inner;
|
|
}
|
|
|
|
inner[row.Code.Trim()] = row.Label.Trim();
|
|
}
|
|
}
|
|
|
|
Apply(platform);
|
|
Apply(tenantOwned);
|
|
|
|
return merged;
|
|
}
|
|
}
|