[CLAUDE] Domain+Infra: Migration 16 — 2-stage dept approval + smart reject schema
Chunk A của feature 2-stage department approval (Phase 9). 3 ràng buộc gộp 1 migration để rollback atomic. Schema changes: 1. Smart reject (3 ALTER): - Contracts.RejectedFromPhase int NULL - PurchaseEvaluations.RejectedFromPhase int NULL - Budgets.RejectedFromPhase int NULL Lưu phase nguồn khi reject để Drafter trình lại quay về đúng phase (skip phase trung gian đã duyệt) thay vì đi tuần tự từ DangSoanThao. 2. Bypass per-user (1 ALTER): - Users.CanBypassReview bit NOT NULL DEFAULT 0 Khi true → NV được duyệt thay TPB (skip Stage Review, đẩy thẳng Stage Confirm). Audit qua DepartmentApproval.IsBypassed=true. 3. 2-stage dept approval (3 CREATE TABLE): - ContractDepartmentApprovals - PurchaseEvaluationDepartmentApprovals - BudgetDepartmentApprovals Schema (chung): - Id, *Id FK Cascade, PhaseAtApproval int, DepartmentId FK - Stage enum (1=Review NV, 2=Confirm TPB) - ApproverUserId, ApproverRoleSnapshot, Comment, ApprovedAt - IsBypassed bit (mark NV bypass) - AuditableEntity (CreatedAt/By/UpdatedAt/By/IsDeleted/...) Indexes: - UNIQUE (TargetId, PhaseAtApproval, DepartmentId, Stage) - Single: TargetId, DepartmentId, ApproverUserId Files: - Domain: 4 entity update (Contract/PE/Budget/User add field) + 1 enum mới ApprovalStage + 3 entity DepartmentApproval mới - Infrastructure: 3 EntityConfiguration update + 1 file mới DepartmentApprovalsConfiguration với 3 config classes - IApplicationDbContext: thêm 3 DbSet - ApplicationDbContext: thêm 3 DbSet - Migration 16: 3 file (.cs + Designer.cs + Snapshot.cs) — 3-file rule Verify: - Build pass (2 warning DocxRenderer cũ, không liên quan) - 77 unit test pass (54 Domain + 23 Infra) — Domain policy chưa update, test pass nguyên không regression Note: KHÔNG khác PurchaseEvaluationDepartmentOpinion (Migration 15) — Opinion là sign-off block "Ý kiến 4 phòng ban" trên header phiếu. DepartmentApproval mới là 2-stage approval workflow per phase. Tổng sau Migration 16: 55 bảng (52+3), 16 migration. Chunk B-E sẽ implement Application + FE + Tests. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@ -25,10 +25,16 @@ public class Contract : AuditableEntity
|
||||
public bool SlaWarningSent { get; set; } // Flag để không gửi warning 2 lần
|
||||
public Guid? BudgetId { get; set; } // Reference Budget (Phase 7) — đối chiếu chi phí HĐ vs ngân sách
|
||||
|
||||
// Smart reject (Phase 9 — Migration 16): Phase nguồn khi reject. Drafter
|
||||
// sửa lại + trình lại → quay về RejectedFromPhase thay vì DangSoanThao
|
||||
// tuần tự lại từ đầu. Null khi chưa từng reject hoặc đã trình lại xong.
|
||||
public ContractPhase? RejectedFromPhase { get; set; }
|
||||
|
||||
public List<ContractApproval> Approvals { get; set; } = new();
|
||||
public List<ContractComment> Comments { get; set; } = new();
|
||||
public List<ContractAttachment> Attachments { get; set; } = new();
|
||||
public List<ContractChangelog> Changelogs { get; set; } = new();
|
||||
public List<ContractDepartmentApproval> DepartmentApprovals { get; set; } = new();
|
||||
|
||||
// Per-type details — chỉ 1 collection có data tương ứng với Type. Backend
|
||||
// logic dispatch theo Contract.Type để load đúng bảng. KHÔNG load eager
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
using SolutionErp.Domain.Common;
|
||||
|
||||
namespace SolutionErp.Domain.Contracts;
|
||||
|
||||
// 2-stage department approval cho HĐ workflow (Phase 9 — Migration 16).
|
||||
// Mỗi phase × phòng ban có max 2 row: Stage=Review (NV duyệt) + Stage=Confirm
|
||||
// (TPB duyệt). Workflow service guard: chỉ transition khi đã có Stage=Confirm.
|
||||
//
|
||||
// User.CanBypassReview=true → NV insert thẳng Stage=Confirm (IsBypassed=true).
|
||||
//
|
||||
// UNIQUE (ContractId, PhaseAtApproval, DepartmentId, Stage) — 1 phase × 1 phòng
|
||||
// × 1 stage = 1 row duy nhất. UPDATE in-place khi user đổi ý (audit qua
|
||||
// ContractChangelog).
|
||||
public class ContractDepartmentApproval : AuditableEntity
|
||||
{
|
||||
public Guid ContractId { get; set; }
|
||||
public int PhaseAtApproval { get; set; } // snapshot ContractPhase int (Phase tại lúc approve)
|
||||
public Guid DepartmentId { get; set; }
|
||||
public ApprovalStage Stage { get; set; } // 1=Review (NV), 2=Confirm (TPB)
|
||||
public Guid ApproverUserId { get; set; }
|
||||
public string? ApproverRoleSnapshot { get; set; } // VD "NV.CCM" / "TPB.CCM" — denorm cho audit readable
|
||||
public string? Comment { get; set; }
|
||||
public DateTime ApprovedAt { get; set; }
|
||||
public bool IsBypassed { get; set; } // true nếu NV bypass (User.CanBypassReview=true)
|
||||
|
||||
public Contract? Contract { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user