[CLAUDE] App: chuẩn hóa mã dự án — trim + kiểm-trùng bỏ dấu-cách chống trùng do khoảng trắng
All checks were successful
Deploy SOLUTION_ERP / build-deploy (push) Successful in 5m24s
All checks were successful
Deploy SOLUTION_ERP / build-deploy (push) Successful in 5m24s
Project Create/Update: LƯU chỉ Trim (giữ mã như người dùng gõ — owner chốt), nhưng kiểm-trùng so trên dạng bỏ-dấu-cách (Code.Replace(' ','')) để chặn tạo/sửa thành bản trùng chỉ khác khoảng trắng ('FLOCK 01' vs 'FLOCK01'). +4 test guard ProjectCodeNormalizationTests. Đây là vá gốc cho vụ dự án trùng vừa gom trên prod (5 phiếu + 5 ngân sách trỏ lại, 3 bản dấu-cách ẩn mềm).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -92,11 +92,17 @@ public class CreateProjectCommandHandler(IApplicationDbContext db) : IRequestHan
|
||||
{
|
||||
public async Task<Guid> Handle(CreateProjectCommand request, CancellationToken ct)
|
||||
{
|
||||
if (await db.Projects.AnyAsync(x => x.Code == request.Code, ct))
|
||||
throw new ConflictException($"Mã dự án '{request.Code}' đã tồn tại.");
|
||||
// [Fix UAT — dự án trùng do khác dấu-cách trong mã: "FLOCK 01" vs "FLOCK01"]
|
||||
// Owner (chốt): LƯU chỉ cắt đầu/cuối (Trim) — giữ mã như người dùng gõ; nhưng
|
||||
// KIỂM-TRÙNG bỏ-qua-dấu-cách để chặn tạo bản trùng chỉ khác khoảng trắng.
|
||||
// (Collation SQL mặc định CI → đã bỏ-qua hoa/thường; đây thêm bỏ-qua dấu-cách.)
|
||||
var code = request.Code.Trim();
|
||||
var codeKey = code.Replace(" ", "");
|
||||
if (await db.Projects.AnyAsync(x => x.Code.Replace(" ", "") == codeKey, ct))
|
||||
throw new ConflictException($"Mã dự án '{code}' đã tồn tại (trùng mã sau khi bỏ dấu cách).");
|
||||
var entity = new Project
|
||||
{
|
||||
Code = request.Code, Name = request.Name,
|
||||
Code = code, Name = request.Name,
|
||||
StartDate = request.StartDate, EndDate = request.EndDate,
|
||||
ManagerUserId = request.ManagerUserId, BudgetTotal = request.BudgetTotal, Note = request.Note,
|
||||
Year = request.Year, Investor = request.Investor, Location = request.Location, Package = request.Package,
|
||||
@ -135,9 +141,12 @@ public class UpdateProjectCommandHandler(IApplicationDbContext db) : IRequestHan
|
||||
{
|
||||
var entity = await db.Projects.FirstOrDefaultAsync(x => x.Id == request.Id, ct)
|
||||
?? throw new NotFoundException("Project", request.Id);
|
||||
if (entity.Code != request.Code && await db.Projects.AnyAsync(x => x.Code == request.Code && x.Id != request.Id, ct))
|
||||
throw new ConflictException($"Mã dự án '{request.Code}' đã tồn tại.");
|
||||
entity.Code = request.Code;
|
||||
// Chuẩn hóa mã như CREATE: Trim khi lưu + kiểm-trùng bỏ-qua-dấu-cách.
|
||||
var code = request.Code.Trim();
|
||||
var codeKey = code.Replace(" ", "");
|
||||
if (entity.Code != code && await db.Projects.AnyAsync(x => x.Id != request.Id && x.Code.Replace(" ", "") == codeKey, ct))
|
||||
throw new ConflictException($"Mã dự án '{code}' đã tồn tại (trùng mã sau khi bỏ dấu cách).");
|
||||
entity.Code = code;
|
||||
entity.Name = request.Name;
|
||||
entity.StartDate = request.StartDate;
|
||||
entity.EndDate = request.EndDate;
|
||||
|
||||
Reference in New Issue
Block a user