[CLAUDE] Domain+App+Infra: Plan B G-H1 Mig 34 EmployeeProfile + seed 30 demo
All checks were successful
Deploy SOLUTION_ERP / build-deploy (push) Successful in 3m38s
All checks were successful
Deploy SOLUTION_ERP / build-deploy (push) Successful in 3m38s
Phase 10.1 G-H1 Hồ sơ Nhân sự Foundation — port từ NamGroup CT_NHANSU
(1675 NV, 10 bảng TblNhanVien*) sau anh main chốt S32 4 quyết định
(scope FULL 11 module + DB single schema dbo + reuse Workflow V2 +
chunk per-module Plan riêng). G-H1 CRITICAL FIRST vì depend by 8/11
module Phase 10 sau (Đề xuất/Đơn từ/OT/Đặt xe/Ticket/Dashboard NS/
Chấm công đều cần EmployeeProfile data).
Investigator pre-flight (a103d20) audit NamGroup confirm:
- Main TblNhanVien 105 cols (drop 35 cols duplicate User/UX legacy)
- 5 satellite Phase 10.1 (defer 3 HĐLĐ Plan H2): WorkHistory + Education
+ FamilyRelation + Skill polymorphic Kind + Document
- 6 enum thay catalog FK (Gender/MaritalStatus/EmployeeStatus/...)
- DiaChi dual-write FK + freetext lesson Plan C NamGroup 1675 NV drift
Em main 4 decision chốt:
1. 5 satellite Phase 10.1 (defer 3 HĐLĐ Plan H2)
2. Skill polymorphic Kind enum (gộp 3 NamGroup table)
3. DiaChi 6 FK Province/District/Ward declare nullable + freetext dual-write
ngày đầu (FK constraint defer G-H2 khi catalog scaffold — Implementer
smart decision documented EmployeeProfile.cs comment line 14-17)
4. MaNhanVien format NV/{YYYY}/{Seq:D4} atomic Serializable reset/year
Implementer Case 2 (a8f4567) Pattern 12-bis cross-module mirror PE → Hrm
cookie-cutter scaffold 17 file mới + 4 modified + 3-file mig rule:
Domain (8 file SolutionErp.Domain.Hrm):
- EmployeeProfile.cs (main ~70 cols inherit AuditableEntity, 1-1 UNIQUE User)
- EmployeeWorkHistory.cs + EmployeeEducation.cs + EmployeeFamilyRelation.cs
- EmployeeSkill.cs (polymorphic Kind=Computer/Language/Other)
- EmployeeDocument.cs (IdCard/Passport/Degree/Certificate/LaborContract/Other)
- EmployeeCodeSequence.cs (PK string Prefix, NOT BaseEntity Id Guid)
- Enums.cs (10 enum gọn 1 file)
Application (1 file):
- IEmployeeCodeGenerator.cs interface (mirror IContractCodeGenerator)
Infrastructure (8 file):
- EmployeeCodeGenerator.cs impl IsolationLevel.Serializable transaction
- 7 EF Configuration file (HasIndex UNIQUE UserId/EmployeeCode/Phone +
HasMaxLength + HasColumnType decimal(18,2) + FK Cascade satellite)
- DependencyInjection.cs (M): register IEmployeeCodeGenerator → impl
Persistence (3 file modified + 2 new mig + 1 snapshot):
- IApplicationDbContext.cs (M): +7 DbSet<EmployeeProfile/...>
- ApplicationDbContext.cs (M): +7 DbSet impl
- ApplicationDbContextModelSnapshot.cs (M): EF auto-update
- 20260526110207_AddEmployeeProfiles.cs (NEW, EF auto-gen)
- 20260526110207_AddEmployeeProfiles.Designer.cs (NEW, EF auto-gen)
DbInitializer.cs (M, em main solo Task 3b ~90 LOC):
- using SolutionErp.Domain.Hrm import added
- SeedDemoEmployeeProfilesAsync method appended (end of class)
- Register call after SeedDemoUsersAsync line 88 (depend user exist first)
- NOT gated DemoSeed:Disabled flag (infrastructure data per gotcha #51 lesson)
- 30 demo profile mirror 30 user @solutions.com.vn + sequential code
NV/{YYYY}/0001..0030 + placeholder masked CMND/BHXH/Bank (bro UAT update
qua FE Page Task 5) + EmployeeCodeSequence row LastSeq=30 → production
gen tiếp 0031+
Verify:
- dotnet build: 0 err 2 unrelated warn DocxRenderer (2.49s + 7.86s rebuild)
- dotnet ef database update _Dev: Mig 34 applied (top of __EFMigrationsHistory)
- dotnet test: **120/120 PASS** baseline preserved (no test add Phase 10
test-after per §7 UAT mode — test bundle defer Task 4+5+6 done)
Stats target Phase 10 end: 33→42 mig (+9 Mig 34-42), 60→85 tables (+25),
~148→250 endpoint (+100), 38→60 FE pages (+22). Current after this commit:
33→34 mig + 60→66 tables + endpoint/FE unchanged (G-H1 Task 4+5 next).
Pattern reusable cross-project:
- Pattern 12-bis cross-module entity cookie-cutter mirror reinforced 3×
(S29 Plan B Contract V2 + S33 Plan B G-H1 EmployeeProfile)
- Infrastructure seed OUT of DemoSeed gate (gotcha #51 lesson, mirror Mig 32
SeedSampleContractWorkflowV2)
- DiaChi dual-write FK + freetext từ ngày đầu (NamGroup 1675 NV drift lesson)
Pending Plan B G-H1 Phase 2 (chờ anh main signal kick off):
- Task 4 — Implementer BE CQRS handler + 6 endpoint controller
- Task 5 — Implementer FE 2 app EmployeesPage 3-panel + 6 section tabs
- Task 6 — Em main Permission menu Hrm_HoSo* seed
- Task 7 — Reviewer pre-commit + CICD post-deploy verify
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@ -5,6 +5,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using SolutionErp.Application.Common.Interfaces;
|
||||
using SolutionErp.Application.Contracts.Services;
|
||||
using SolutionErp.Application.Forms.Services;
|
||||
using SolutionErp.Application.Hrm.Services;
|
||||
using SolutionErp.Application.Notifications;
|
||||
using SolutionErp.Application.PurchaseEvaluations.Services;
|
||||
using SolutionErp.Application.Reports.Services;
|
||||
@ -35,6 +36,7 @@ public static class DependencyInjection
|
||||
services.AddScoped<IContractWorkflowService, ContractWorkflowService>();
|
||||
services.AddScoped<IPurchaseEvaluationWorkflowService, PurchaseEvaluationWorkflowService>();
|
||||
services.AddScoped<IPurchaseEvaluationCodeGenerator, PurchaseEvaluationCodeGenerator>();
|
||||
services.AddScoped<IEmployeeCodeGenerator, EmployeeCodeGenerator>();
|
||||
services.AddScoped<IContractExcelExporter, ContractExcelExporter>();
|
||||
services.AddScoped<INotificationService, NotificationService>();
|
||||
services.AddScoped<IChangelogService, ChangelogService>();
|
||||
|
||||
@ -6,6 +6,7 @@ using SolutionErp.Domain.Budgets;
|
||||
using SolutionErp.Domain.Contracts;
|
||||
using SolutionErp.Domain.Contracts.Details;
|
||||
using SolutionErp.Domain.Forms;
|
||||
using SolutionErp.Domain.Hrm;
|
||||
using SolutionErp.Domain.Identity;
|
||||
using SolutionErp.Domain.Master;
|
||||
using SolutionErp.Domain.Master.Catalogs;
|
||||
@ -80,6 +81,15 @@ public class ApplicationDbContext
|
||||
public DbSet<BudgetChangelog> BudgetChangelogs => Set<BudgetChangelog>();
|
||||
public DbSet<BudgetDepartmentApproval> BudgetDepartmentApprovals => Set<BudgetDepartmentApproval>();
|
||||
|
||||
// Phase 10.1 G-H1 (Mig 34 — S33) — Hồ sơ Nhân sự port từ NamGroup.
|
||||
public DbSet<EmployeeProfile> EmployeeProfiles => Set<EmployeeProfile>();
|
||||
public DbSet<EmployeeWorkHistory> EmployeeWorkHistories => Set<EmployeeWorkHistory>();
|
||||
public DbSet<EmployeeEducation> EmployeeEducations => Set<EmployeeEducation>();
|
||||
public DbSet<EmployeeFamilyRelation> EmployeeFamilyRelations => Set<EmployeeFamilyRelation>();
|
||||
public DbSet<EmployeeSkill> EmployeeSkills => Set<EmployeeSkill>();
|
||||
public DbSet<EmployeeDocument> EmployeeDocuments => Set<EmployeeDocument>();
|
||||
public DbSet<EmployeeCodeSequence> EmployeeCodeSequences => Set<EmployeeCodeSequence>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
base.OnModelCreating(builder);
|
||||
|
||||
@ -0,0 +1,18 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using SolutionErp.Domain.Hrm;
|
||||
|
||||
namespace SolutionErp.Infrastructure.Persistence.Configurations;
|
||||
|
||||
// EF Mig 34 — Sequence table cho MaNhanVien. PK Prefix string.
|
||||
// Mirror ContractCodeSequenceConfiguration pattern.
|
||||
public class EmployeeCodeSequenceConfiguration : IEntityTypeConfiguration<EmployeeCodeSequence>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<EmployeeCodeSequence> e)
|
||||
{
|
||||
e.ToTable("EmployeeCodeSequences");
|
||||
|
||||
e.HasKey(x => x.Prefix);
|
||||
e.Property(x => x.Prefix).HasMaxLength(50);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using SolutionErp.Domain.Hrm;
|
||||
|
||||
namespace SolutionErp.Infrastructure.Persistence.Configurations;
|
||||
|
||||
// EF Mig 34 — File scan attachment (satellite). FK Cascade EmployeeProfile.
|
||||
// INDEX DocumentType cho filter "tất cả bằng cấp của NV X".
|
||||
public class EmployeeDocumentConfiguration : IEntityTypeConfiguration<EmployeeDocument>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<EmployeeDocument> e)
|
||||
{
|
||||
e.ToTable("EmployeeDocuments");
|
||||
|
||||
e.Property(x => x.FileName).HasMaxLength(255).IsRequired();
|
||||
e.Property(x => x.FilePath).HasMaxLength(500).IsRequired();
|
||||
e.Property(x => x.ContentType).HasMaxLength(100).IsRequired();
|
||||
e.Property(x => x.Notes).HasMaxLength(500);
|
||||
|
||||
e.HasOne(x => x.EmployeeProfile)
|
||||
.WithMany(p => p.Documents)
|
||||
.HasForeignKey(x => x.EmployeeProfileId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
e.HasIndex(x => x.EmployeeProfileId);
|
||||
e.HasIndex(x => x.DocumentType);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using SolutionErp.Domain.Hrm;
|
||||
|
||||
namespace SolutionErp.Infrastructure.Persistence.Configurations;
|
||||
|
||||
// EF Mig 34 — Quá trình học vấn (satellite). FK Cascade EmployeeProfile.
|
||||
public class EmployeeEducationConfiguration : IEntityTypeConfiguration<EmployeeEducation>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<EmployeeEducation> e)
|
||||
{
|
||||
e.ToTable("EmployeeEducations");
|
||||
|
||||
e.Property(x => x.SchoolName).HasMaxLength(200).IsRequired();
|
||||
e.Property(x => x.Major).HasMaxLength(200);
|
||||
e.Property(x => x.Notes).HasMaxLength(500);
|
||||
|
||||
e.HasOne(x => x.EmployeeProfile)
|
||||
.WithMany(p => p.Educations)
|
||||
.HasForeignKey(x => x.EmployeeProfileId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
e.HasIndex(x => x.EmployeeProfileId);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using SolutionErp.Domain.Hrm;
|
||||
|
||||
namespace SolutionErp.Infrastructure.Persistence.Configurations;
|
||||
|
||||
// EF Mig 34 — Quan hệ gia đình (satellite). FK Cascade EmployeeProfile.
|
||||
public class EmployeeFamilyRelationConfiguration : IEntityTypeConfiguration<EmployeeFamilyRelation>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<EmployeeFamilyRelation> e)
|
||||
{
|
||||
e.ToTable("EmployeeFamilyRelations");
|
||||
|
||||
e.Property(x => x.FullName).HasMaxLength(200).IsRequired();
|
||||
e.Property(x => x.Occupation).HasMaxLength(200);
|
||||
e.Property(x => x.CurrentAddress).HasMaxLength(500);
|
||||
e.Property(x => x.Phone).HasMaxLength(20);
|
||||
|
||||
e.HasOne(x => x.EmployeeProfile)
|
||||
.WithMany(p => p.FamilyRelations)
|
||||
.HasForeignKey(x => x.EmployeeProfileId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
e.HasIndex(x => x.EmployeeProfileId);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,101 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using SolutionErp.Domain.Hrm;
|
||||
using SolutionErp.Domain.Identity;
|
||||
|
||||
namespace SolutionErp.Infrastructure.Persistence.Configurations;
|
||||
|
||||
// EF Mig 34 — Hồ sơ Nhân sự main entity.
|
||||
// 1-1 User qua UNIQUE UserId. FK Cascade Users (xoá user → wipe profile).
|
||||
// EmployeeCode UNIQUE. Phone INDEX (lookup nhanh).
|
||||
// IsDeleted INDEX (soft delete query filter).
|
||||
//
|
||||
// Province/District/Ward 6 cột nullable plain Guid? — KHÔNG declare FK
|
||||
// constraint (catalog chưa scaffold trong Mig 34, defer G-H2 khi thêm catalog
|
||||
// thì alter table add FK).
|
||||
public class EmployeeProfileConfiguration : IEntityTypeConfiguration<EmployeeProfile>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<EmployeeProfile> e)
|
||||
{
|
||||
e.ToTable("EmployeeProfiles");
|
||||
|
||||
// ===== EmployeeCode + UserId UNIQUE =====
|
||||
e.Property(x => x.EmployeeCode).HasMaxLength(50).IsRequired();
|
||||
e.HasIndex(x => x.EmployeeCode).IsUnique();
|
||||
|
||||
e.HasIndex(x => x.UserId).IsUnique();
|
||||
|
||||
// ===== 1-1 User FK Cascade =====
|
||||
e.HasOne(x => x.User)
|
||||
.WithOne()
|
||||
.HasForeignKey<EmployeeProfile>(x => x.UserId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
// ===== Cá nhân =====
|
||||
e.Property(x => x.BirthPlace).HasMaxLength(200);
|
||||
e.Property(x => x.Hometown).HasMaxLength(200);
|
||||
|
||||
e.Property(x => x.Phone).HasMaxLength(20);
|
||||
e.HasIndex(x => x.Phone); // Non-unique (nhiều NV cùng nhà có thể chung SDT cố định)
|
||||
e.Property(x => x.PersonalEmail).HasMaxLength(200);
|
||||
e.Property(x => x.InternalPhone).HasMaxLength(20);
|
||||
|
||||
e.Property(x => x.Ethnicity).HasMaxLength(50);
|
||||
e.Property(x => x.Religion).HasMaxLength(50);
|
||||
e.Property(x => x.Nationality).HasMaxLength(50).IsRequired();
|
||||
|
||||
// ===== Giấy tờ =====
|
||||
e.Property(x => x.IdCardNumber).HasMaxLength(20);
|
||||
e.Property(x => x.IdCardIssuePlace).HasMaxLength(200);
|
||||
e.Property(x => x.TaxCode).HasMaxLength(20);
|
||||
e.Property(x => x.SocialInsuranceNumber).HasMaxLength(20);
|
||||
e.Property(x => x.PassportNumber).HasMaxLength(20);
|
||||
|
||||
// ===== Địa chỉ HKTT (no FK — defer G-H2) =====
|
||||
e.Property(x => x.PermanentAddressText).HasMaxLength(500);
|
||||
e.Property(x => x.StreetAddressPermanent).HasMaxLength(200);
|
||||
|
||||
// ===== Địa chỉ Tạm trú (no FK — defer G-H2) =====
|
||||
e.Property(x => x.TemporaryAddressText).HasMaxLength(500);
|
||||
e.Property(x => x.StreetAddressTemporary).HasMaxLength(200);
|
||||
|
||||
// ===== Khẩn cấp =====
|
||||
e.Property(x => x.EmergencyContactName).HasMaxLength(200);
|
||||
e.Property(x => x.EmergencyContactPhone).HasMaxLength(20);
|
||||
e.Property(x => x.EmergencyContactAddress).HasMaxLength(500);
|
||||
|
||||
// ===== Trình độ + chức danh =====
|
||||
e.Property(x => x.Qualification).HasMaxLength(200);
|
||||
e.Property(x => x.AcademicTitle).HasMaxLength(200);
|
||||
|
||||
// ===== Vị trí =====
|
||||
e.Property(x => x.WorkLocation).HasMaxLength(200);
|
||||
e.Property(x => x.TimekeepingCode).HasMaxLength(50);
|
||||
|
||||
// ===== Ngân hàng =====
|
||||
e.Property(x => x.BankAccount).HasMaxLength(50);
|
||||
e.Property(x => x.BankName).HasMaxLength(200);
|
||||
e.Property(x => x.BankBranch).HasMaxLength(200);
|
||||
|
||||
// ===== Sức khoẻ =====
|
||||
e.Property(x => x.BloodType).HasMaxLength(5);
|
||||
|
||||
// ===== Lương + Phép — decimal precision =====
|
||||
e.Property(x => x.BaseSalary).HasColumnType("decimal(18,2)");
|
||||
e.Property(x => x.TotalSalary).HasColumnType("decimal(18,2)");
|
||||
e.Property(x => x.AnnualLeaveDays).HasColumnType("decimal(5,2)");
|
||||
e.Property(x => x.RemainingLeaveDays).HasColumnType("decimal(5,2)");
|
||||
e.Property(x => x.CompensatoryLeaveDays).HasColumnType("decimal(5,2)");
|
||||
e.Property(x => x.SeniorityLeaveDays).HasColumnType("decimal(5,2)");
|
||||
|
||||
// ===== BHXH =====
|
||||
e.Property(x => x.MedicalRegistrationPlace).HasMaxLength(200);
|
||||
|
||||
// ===== Khác =====
|
||||
e.Property(x => x.PhotoUrl).HasMaxLength(500);
|
||||
e.Property(x => x.Notes).HasMaxLength(2000);
|
||||
|
||||
// ===== Soft delete index =====
|
||||
e.HasIndex(x => x.IsDeleted);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using SolutionErp.Domain.Hrm;
|
||||
|
||||
namespace SolutionErp.Infrastructure.Persistence.Configurations;
|
||||
|
||||
// EF Mig 34 — Skill polymorphic Kind=Computer/Language/Other.
|
||||
// FK Cascade EmployeeProfile. INDEX Kind cho filter "tất cả ngoại ngữ của NV X".
|
||||
public class EmployeeSkillConfiguration : IEntityTypeConfiguration<EmployeeSkill>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<EmployeeSkill> e)
|
||||
{
|
||||
e.ToTable("EmployeeSkills");
|
||||
|
||||
e.Property(x => x.Name).HasMaxLength(200).IsRequired();
|
||||
e.Property(x => x.LanguageId).HasMaxLength(20);
|
||||
e.Property(x => x.Level).HasMaxLength(200);
|
||||
|
||||
e.HasOne(x => x.EmployeeProfile)
|
||||
.WithMany(p => p.Skills)
|
||||
.HasForeignKey(x => x.EmployeeProfileId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
e.HasIndex(x => x.EmployeeProfileId);
|
||||
e.HasIndex(x => x.Kind);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using SolutionErp.Domain.Hrm;
|
||||
|
||||
namespace SolutionErp.Infrastructure.Persistence.Configurations;
|
||||
|
||||
// EF Mig 34 — Quá trình công tác (satellite). FK Cascade EmployeeProfile.
|
||||
public class EmployeeWorkHistoryConfiguration : IEntityTypeConfiguration<EmployeeWorkHistory>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<EmployeeWorkHistory> e)
|
||||
{
|
||||
e.ToTable("EmployeeWorkHistories");
|
||||
|
||||
e.Property(x => x.CompanyName).HasMaxLength(200).IsRequired();
|
||||
e.Property(x => x.CompanyAddress).HasMaxLength(500);
|
||||
e.Property(x => x.Industry).HasMaxLength(200);
|
||||
|
||||
e.Property(x => x.JobTitle).HasMaxLength(200);
|
||||
e.Property(x => x.JobDescription).HasMaxLength(2000);
|
||||
e.Property(x => x.ResignReason).HasMaxLength(500);
|
||||
|
||||
e.HasOne(x => x.EmployeeProfile)
|
||||
.WithMany(p => p.WorkHistories)
|
||||
.HasForeignKey(x => x.EmployeeProfileId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
e.HasIndex(x => x.EmployeeProfileId);
|
||||
}
|
||||
}
|
||||
@ -7,6 +7,7 @@ using SolutionErp.Application.Contracts.Services;
|
||||
using SolutionErp.Domain.ApprovalWorkflowsV2;
|
||||
using SolutionErp.Domain.Contracts;
|
||||
using SolutionErp.Domain.Forms;
|
||||
using SolutionErp.Domain.Hrm;
|
||||
using SolutionErp.Domain.Identity;
|
||||
using SolutionErp.Domain.Master;
|
||||
using SolutionErp.Domain.Master.Catalogs;
|
||||
@ -86,6 +87,11 @@ public static class DbInitializer
|
||||
await SeedAdminAsync(userManager, logger);
|
||||
await SeedDepartmentsAsync(db, logger);
|
||||
await SeedDemoUsersAsync(db, userManager, logger);
|
||||
// Plan B G-H1 (Mig 34 S33 2026-05-26) — seed EmployeeProfile 1-1 với
|
||||
// mọi user @solutions.com.vn. Idempotent. NOT gated DemoSeed flag
|
||||
// (infrastructure data, mirror Mig 32 SeedSampleContractWorkflowV2
|
||||
// gotcha #51 lesson). Bro UAT update field nhạy cảm qua FE Hồ sơ NS.
|
||||
await SeedDemoEmployeeProfilesAsync(db, userManager, logger);
|
||||
await SeedMenuTreeAsync(db, logger);
|
||||
await SeedAdminPermissionsAsync(db, roleManager, logger);
|
||||
await SeedDemoMasterDataAsync(db, logger);
|
||||
@ -1919,4 +1925,99 @@ public static class DbInitializer
|
||||
logger.LogInformation("Seeded {Count} contract templates (active file check)", added);
|
||||
}
|
||||
}
|
||||
|
||||
// Plan B G-H1 (Mig 34 — S33 2026-05-26) — seed EmployeeProfile cho mọi
|
||||
// user @solutions.com.vn (30 demo + admin). Idempotent — skip nếu đã có
|
||||
// EmployeeProfile. Sequential code NV/{Year}/0001..N. Field nhạy cảm
|
||||
// (CMND/BHXH/Bank) PLACEHOLDER masked — bro UAT update real qua FE Hồ sơ
|
||||
// NS Page (Task 5).
|
||||
//
|
||||
// Cũng seed EmployeeCodeSequence "NV/{Year}" với LastSeq=N → production
|
||||
// gen tiếp từ N+1 (mirror PE/Contract CodeGen pattern).
|
||||
//
|
||||
// NOT gated DemoSeed:Disabled flag vì EmployeeProfile là INFRASTRUCTURE
|
||||
// data (1-1 với User), không phải DEMO content như sample HĐ/PE. Gotcha
|
||||
// #51 lesson (S29 Plan B): infra seed phải OUT of flag gate.
|
||||
private static async Task SeedDemoEmployeeProfilesAsync(
|
||||
ApplicationDbContext db, UserManager<User> userManager, ILogger logger)
|
||||
{
|
||||
if (await db.EmployeeProfiles.AnyAsync())
|
||||
{
|
||||
logger.LogInformation("SeedDemoEmployeeProfilesAsync: skip — đã có EmployeeProfile.");
|
||||
return;
|
||||
}
|
||||
|
||||
var users = await userManager.Users
|
||||
.Where(u => u.Email != null && u.Email.EndsWith("@solutions.com.vn"))
|
||||
.OrderBy(u => u.Email)
|
||||
.ToListAsync();
|
||||
|
||||
if (users.Count == 0)
|
||||
{
|
||||
logger.LogWarning("SeedDemoEmployeeProfilesAsync: no users @solutions.com.vn found — run SeedDemoUsersAsync first.");
|
||||
return;
|
||||
}
|
||||
|
||||
var rng = new Random(20260526); // Deterministic seed for reproducibility
|
||||
var year = DateTime.UtcNow.Year;
|
||||
var seq = 0;
|
||||
foreach (var u in users)
|
||||
{
|
||||
seq++;
|
||||
var birthYear = 1970 + rng.Next(0, 26); // 1970-1995 → 30-55 tuổi
|
||||
var hireYear = 2020 + (seq % 6); // 2020-2025
|
||||
var profile = new EmployeeProfile
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = u.Id,
|
||||
EmployeeCode = $"NV/{year}/{seq:D4}",
|
||||
EmployeeStatus = SolutionErp.Domain.Hrm.EmployeeStatus.Active,
|
||||
Gender = (seq % 2 == 0) ? SolutionErp.Domain.Hrm.Gender.Female : SolutionErp.Domain.Hrm.Gender.Male,
|
||||
MaritalStatus = (seq % 3 == 0) ? SolutionErp.Domain.Hrm.MaritalStatus.Single : SolutionErp.Domain.Hrm.MaritalStatus.Married,
|
||||
EmployeeType = SolutionErp.Domain.Hrm.EmployeeType.FullTime,
|
||||
DateOfBirth = new DateOnly(birthYear, rng.Next(1, 13), rng.Next(1, 28)),
|
||||
BirthPlace = "Hà Nội",
|
||||
Hometown = "Hà Nội",
|
||||
Phone = $"09{rng.Next(10000000, 99999999)}",
|
||||
PersonalEmail = u.Email,
|
||||
Nationality = "Việt Nam",
|
||||
Ethnicity = "Kinh",
|
||||
IdCardNumber = $"001099{seq:D6}", // PLACEHOLDER masked
|
||||
IdCardIssueDate = new DateOnly(2020, 1, 15),
|
||||
IdCardIssuePlace = "Cục CS QLHC về TTXH",
|
||||
TaxCode = $"8{seq:D9}",
|
||||
SocialInsuranceNumber = $"BHXH{seq:D8}",
|
||||
PermanentAddressText = "Hà Nội (cập nhật qua Hồ sơ NS)",
|
||||
HireDate = new DateOnly(hireYear, ((seq % 12) + 1), 1),
|
||||
EmergencyContactName = "Người thân — cập nhật sau",
|
||||
EmergencyContactPhone = $"09{rng.Next(10000000, 99999999)}",
|
||||
Qualification = (seq % 4 == 0) ? "Thạc sĩ" : "Đại học",
|
||||
WorkLocation = (seq % 3 == 0) ? "Công trường" : "Văn phòng",
|
||||
BankAccount = $"19030000{seq:D4}",
|
||||
BankName = "Techcombank",
|
||||
BankBranch = "Hà Nội",
|
||||
BaseSalary = 15_000_000m + (seq % 10) * 1_000_000m,
|
||||
AnnualLeaveDays = 12m,
|
||||
RemainingLeaveDays = 12m - (seq % 5),
|
||||
SocialInsuranceStartDate = new DateOnly(hireYear, ((seq % 12) + 1), 1),
|
||||
IsCommunistParty = false,
|
||||
IsYouthUnion = (seq % 4 == 0),
|
||||
IsTradeUnion = true,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
};
|
||||
db.EmployeeProfiles.Add(profile);
|
||||
}
|
||||
|
||||
db.EmployeeCodeSequences.Add(new EmployeeCodeSequence
|
||||
{
|
||||
Prefix = $"NV/{year}",
|
||||
LastSeq = seq,
|
||||
UpdatedAt = DateTime.UtcNow,
|
||||
});
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
logger.LogInformation(
|
||||
"SeedDemoEmployeeProfilesAsync: seeded {Count} profiles + 1 sequence row NV/{Year} LastSeq={Seq}",
|
||||
seq, year, seq);
|
||||
}
|
||||
}
|
||||
|
||||
4712
src/Backend/SolutionErp.Infrastructure/Persistence/Migrations/20260526110207_AddEmployeeProfiles.Designer.cs
generated
Normal file
4712
src/Backend/SolutionErp.Infrastructure/Persistence/Migrations/20260526110207_AddEmployeeProfiles.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,356 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SolutionErp.Infrastructure.Persistence.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddEmployeeProfiles : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "EmployeeCodeSequences",
|
||||
columns: table => new
|
||||
{
|
||||
Prefix = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
|
||||
LastSeq = table.Column<int>(type: "int", nullable: false),
|
||||
UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_EmployeeCodeSequences", x => x.Prefix);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "EmployeeProfiles",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||
UserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||
EmployeeCode = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
|
||||
EmployeeStatus = table.Column<int>(type: "int", nullable: false),
|
||||
Gender = table.Column<int>(type: "int", nullable: true),
|
||||
MaritalStatus = table.Column<int>(type: "int", nullable: true),
|
||||
EmployeeType = table.Column<int>(type: "int", nullable: true),
|
||||
DateOfBirth = table.Column<DateOnly>(type: "date", nullable: true),
|
||||
BirthPlace = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
|
||||
Hometown = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
|
||||
Phone = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: true),
|
||||
PersonalEmail = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
|
||||
InternalPhone = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: true),
|
||||
Ethnicity = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
|
||||
Religion = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
|
||||
Nationality = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
|
||||
IdCardNumber = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: true),
|
||||
IdCardIssueDate = table.Column<DateOnly>(type: "date", nullable: true),
|
||||
IdCardIssuePlace = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
|
||||
TaxCode = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: true),
|
||||
SocialInsuranceNumber = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: true),
|
||||
PassportNumber = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: true),
|
||||
PermanentAddressText = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
|
||||
PermanentProvinceId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
|
||||
PermanentDistrictId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
|
||||
PermanentWardId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
|
||||
StreetAddressPermanent = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
|
||||
TemporaryAddressText = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
|
||||
TemporaryProvinceId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
|
||||
TemporaryDistrictId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
|
||||
TemporaryWardId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
|
||||
StreetAddressTemporary = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
|
||||
HireDate = table.Column<DateOnly>(type: "date", nullable: true),
|
||||
ResignDate = table.Column<DateOnly>(type: "date", nullable: true),
|
||||
EmergencyContactName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
|
||||
EmergencyContactPhone = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: true),
|
||||
EmergencyContactAddress = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
|
||||
Qualification = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
|
||||
AcademicTitle = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
|
||||
WorkLocation = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
|
||||
TimekeepingCode = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
|
||||
BankAccount = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
|
||||
BankName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
|
||||
BankBranch = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
|
||||
HeightCm = table.Column<int>(type: "int", nullable: true),
|
||||
WeightKg = table.Column<int>(type: "int", nullable: true),
|
||||
BloodType = table.Column<string>(type: "nvarchar(5)", maxLength: 5, nullable: true),
|
||||
BaseSalary = table.Column<decimal>(type: "decimal(18,2)", nullable: true),
|
||||
TotalSalary = table.Column<decimal>(type: "decimal(18,2)", nullable: true),
|
||||
AnnualLeaveDays = table.Column<decimal>(type: "decimal(5,2)", nullable: true),
|
||||
RemainingLeaveDays = table.Column<decimal>(type: "decimal(5,2)", nullable: true),
|
||||
CompensatoryLeaveDays = table.Column<decimal>(type: "decimal(5,2)", nullable: true),
|
||||
SeniorityLeaveDays = table.Column<decimal>(type: "decimal(5,2)", nullable: true),
|
||||
SocialInsuranceStartDate = table.Column<DateOnly>(type: "date", nullable: true),
|
||||
MedicalRegistrationPlace = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
|
||||
IsCommunistParty = table.Column<bool>(type: "bit", nullable: false),
|
||||
CommunistPartyJoinDate = table.Column<DateOnly>(type: "date", nullable: true),
|
||||
IsYouthUnion = table.Column<bool>(type: "bit", nullable: false),
|
||||
YouthUnionJoinDate = table.Column<DateOnly>(type: "date", nullable: true),
|
||||
IsTradeUnion = table.Column<bool>(type: "bit", nullable: false),
|
||||
TradeUnionJoinDate = table.Column<DateOnly>(type: "date", nullable: true),
|
||||
PhotoUrl = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
|
||||
Notes = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
|
||||
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
CreatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
|
||||
UpdatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
|
||||
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
|
||||
DeletedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
DeletedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_EmployeeProfiles", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_EmployeeProfiles_Users_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "Users",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "EmployeeDocuments",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||
EmployeeProfileId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||
DocumentType = table.Column<int>(type: "int", nullable: false),
|
||||
FileName = table.Column<string>(type: "nvarchar(255)", maxLength: 255, nullable: false),
|
||||
FilePath = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false),
|
||||
FileSize = table.Column<long>(type: "bigint", nullable: false),
|
||||
ContentType = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
|
||||
IssueDate = table.Column<DateOnly>(type: "date", nullable: true),
|
||||
ExpiryDate = table.Column<DateOnly>(type: "date", nullable: true),
|
||||
Notes = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
|
||||
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
CreatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
|
||||
UpdatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
|
||||
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
|
||||
DeletedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
DeletedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_EmployeeDocuments", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_EmployeeDocuments_EmployeeProfiles_EmployeeProfileId",
|
||||
column: x => x.EmployeeProfileId,
|
||||
principalTable: "EmployeeProfiles",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "EmployeeEducations",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||
EmployeeProfileId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||
SchoolName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
|
||||
Major = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
|
||||
DegreeLevel = table.Column<int>(type: "int", nullable: true),
|
||||
EducationMode = table.Column<int>(type: "int", nullable: true),
|
||||
GradeLevel = table.Column<int>(type: "int", nullable: true),
|
||||
FromDate = table.Column<DateOnly>(type: "date", nullable: true),
|
||||
ToDate = table.Column<DateOnly>(type: "date", nullable: true),
|
||||
CertificateIssueDate = table.Column<DateOnly>(type: "date", nullable: true),
|
||||
Notes = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
|
||||
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
CreatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
|
||||
UpdatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
|
||||
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
|
||||
DeletedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
DeletedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_EmployeeEducations", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_EmployeeEducations_EmployeeProfiles_EmployeeProfileId",
|
||||
column: x => x.EmployeeProfileId,
|
||||
principalTable: "EmployeeProfiles",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "EmployeeFamilyRelations",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||
EmployeeProfileId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||
FullName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
|
||||
Relationship = table.Column<int>(type: "int", nullable: false),
|
||||
BirthYear = table.Column<int>(type: "int", nullable: true),
|
||||
Occupation = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
|
||||
CurrentAddress = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
|
||||
Phone = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: true),
|
||||
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
CreatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
|
||||
UpdatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
|
||||
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
|
||||
DeletedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
DeletedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_EmployeeFamilyRelations", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_EmployeeFamilyRelations_EmployeeProfiles_EmployeeProfileId",
|
||||
column: x => x.EmployeeProfileId,
|
||||
principalTable: "EmployeeProfiles",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "EmployeeSkills",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||
EmployeeProfileId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||
Kind = table.Column<int>(type: "int", nullable: false),
|
||||
Name = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
|
||||
LanguageId = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: true),
|
||||
Level = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
|
||||
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
CreatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
|
||||
UpdatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
|
||||
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
|
||||
DeletedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
DeletedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_EmployeeSkills", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_EmployeeSkills_EmployeeProfiles_EmployeeProfileId",
|
||||
column: x => x.EmployeeProfileId,
|
||||
principalTable: "EmployeeProfiles",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "EmployeeWorkHistories",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||
EmployeeProfileId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||
CompanyName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
|
||||
CompanyAddress = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
|
||||
Industry = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
|
||||
FromDate = table.Column<DateOnly>(type: "date", nullable: true),
|
||||
ToDate = table.Column<DateOnly>(type: "date", nullable: true),
|
||||
JobTitle = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
|
||||
JobDescription = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
|
||||
ResignReason = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
|
||||
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
CreatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
|
||||
UpdatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
|
||||
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
|
||||
DeletedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
DeletedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_EmployeeWorkHistories", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_EmployeeWorkHistories_EmployeeProfiles_EmployeeProfileId",
|
||||
column: x => x.EmployeeProfileId,
|
||||
principalTable: "EmployeeProfiles",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_EmployeeDocuments_DocumentType",
|
||||
table: "EmployeeDocuments",
|
||||
column: "DocumentType");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_EmployeeDocuments_EmployeeProfileId",
|
||||
table: "EmployeeDocuments",
|
||||
column: "EmployeeProfileId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_EmployeeEducations_EmployeeProfileId",
|
||||
table: "EmployeeEducations",
|
||||
column: "EmployeeProfileId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_EmployeeFamilyRelations_EmployeeProfileId",
|
||||
table: "EmployeeFamilyRelations",
|
||||
column: "EmployeeProfileId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_EmployeeProfiles_EmployeeCode",
|
||||
table: "EmployeeProfiles",
|
||||
column: "EmployeeCode",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_EmployeeProfiles_IsDeleted",
|
||||
table: "EmployeeProfiles",
|
||||
column: "IsDeleted");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_EmployeeProfiles_Phone",
|
||||
table: "EmployeeProfiles",
|
||||
column: "Phone");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_EmployeeProfiles_UserId",
|
||||
table: "EmployeeProfiles",
|
||||
column: "UserId",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_EmployeeSkills_EmployeeProfileId",
|
||||
table: "EmployeeSkills",
|
||||
column: "EmployeeProfileId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_EmployeeSkills_Kind",
|
||||
table: "EmployeeSkills",
|
||||
column: "Kind");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_EmployeeWorkHistories_EmployeeProfileId",
|
||||
table: "EmployeeWorkHistories",
|
||||
column: "EmployeeProfileId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "EmployeeCodeSequences");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "EmployeeDocuments");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "EmployeeEducations");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "EmployeeFamilyRelations");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "EmployeeSkills");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "EmployeeWorkHistories");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "EmployeeProfiles");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1894,6 +1894,606 @@ namespace SolutionErp.Infrastructure.Persistence.Migrations
|
||||
b.ToTable("ContractTemplates", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SolutionErp.Domain.Hrm.EmployeeCodeSequence", b =>
|
||||
{
|
||||
b.Property<string>("Prefix")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("nvarchar(50)");
|
||||
|
||||
b.Property<int>("LastSeq")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("UpdatedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.HasKey("Prefix");
|
||||
|
||||
b.ToTable("EmployeeCodeSequences", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SolutionErp.Domain.Hrm.EmployeeDocument", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("ContentType")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("nvarchar(100)");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid?>("CreatedBy")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<DateTime?>("DeletedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid?>("DeletedBy")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<int>("DocumentType")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<Guid>("EmployeeProfileId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<DateOnly?>("ExpiryDate")
|
||||
.HasColumnType("date");
|
||||
|
||||
b.Property<string>("FileName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("nvarchar(255)");
|
||||
|
||||
b.Property<string>("FilePath")
|
||||
.IsRequired()
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("nvarchar(500)");
|
||||
|
||||
b.Property<long>("FileSize")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<DateOnly?>("IssueDate")
|
||||
.HasColumnType("date");
|
||||
|
||||
b.Property<string>("Notes")
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("nvarchar(500)");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid?>("UpdatedBy")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("DocumentType");
|
||||
|
||||
b.HasIndex("EmployeeProfileId");
|
||||
|
||||
b.ToTable("EmployeeDocuments", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SolutionErp.Domain.Hrm.EmployeeEducation", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<DateOnly?>("CertificateIssueDate")
|
||||
.HasColumnType("date");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid?>("CreatedBy")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<int?>("DegreeLevel")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DeletedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid?>("DeletedBy")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<int?>("EducationMode")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<Guid>("EmployeeProfileId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<DateOnly?>("FromDate")
|
||||
.HasColumnType("date");
|
||||
|
||||
b.Property<int?>("GradeLevel")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Major")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<string>("Notes")
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("nvarchar(500)");
|
||||
|
||||
b.Property<string>("SchoolName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<DateOnly?>("ToDate")
|
||||
.HasColumnType("date");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid?>("UpdatedBy")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("EmployeeProfileId");
|
||||
|
||||
b.ToTable("EmployeeEducations", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SolutionErp.Domain.Hrm.EmployeeFamilyRelation", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<int?>("BirthYear")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid?>("CreatedBy")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("CurrentAddress")
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("nvarchar(500)");
|
||||
|
||||
b.Property<DateTime?>("DeletedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid?>("DeletedBy")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid>("EmployeeProfileId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("FullName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("Occupation")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<string>("Phone")
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("nvarchar(20)");
|
||||
|
||||
b.Property<int>("Relationship")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid?>("UpdatedBy")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("EmployeeProfileId");
|
||||
|
||||
b.ToTable("EmployeeFamilyRelations", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SolutionErp.Domain.Hrm.EmployeeProfile", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("AcademicTitle")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<decimal?>("AnnualLeaveDays")
|
||||
.HasColumnType("decimal(5,2)");
|
||||
|
||||
b.Property<string>("BankAccount")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("nvarchar(50)");
|
||||
|
||||
b.Property<string>("BankBranch")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<string>("BankName")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<decimal?>("BaseSalary")
|
||||
.HasColumnType("decimal(18,2)");
|
||||
|
||||
b.Property<string>("BirthPlace")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<string>("BloodType")
|
||||
.HasMaxLength(5)
|
||||
.HasColumnType("nvarchar(5)");
|
||||
|
||||
b.Property<DateOnly?>("CommunistPartyJoinDate")
|
||||
.HasColumnType("date");
|
||||
|
||||
b.Property<decimal?>("CompensatoryLeaveDays")
|
||||
.HasColumnType("decimal(5,2)");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid?>("CreatedBy")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<DateOnly?>("DateOfBirth")
|
||||
.HasColumnType("date");
|
||||
|
||||
b.Property<DateTime?>("DeletedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid?>("DeletedBy")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("EmergencyContactAddress")
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("nvarchar(500)");
|
||||
|
||||
b.Property<string>("EmergencyContactName")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<string>("EmergencyContactPhone")
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("nvarchar(20)");
|
||||
|
||||
b.Property<string>("EmployeeCode")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("nvarchar(50)");
|
||||
|
||||
b.Property<int>("EmployeeStatus")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int?>("EmployeeType")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Ethnicity")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("nvarchar(50)");
|
||||
|
||||
b.Property<int?>("Gender")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int?>("HeightCm")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateOnly?>("HireDate")
|
||||
.HasColumnType("date");
|
||||
|
||||
b.Property<string>("Hometown")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<DateOnly?>("IdCardIssueDate")
|
||||
.HasColumnType("date");
|
||||
|
||||
b.Property<string>("IdCardIssuePlace")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<string>("IdCardNumber")
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("nvarchar(20)");
|
||||
|
||||
b.Property<string>("InternalPhone")
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("nvarchar(20)");
|
||||
|
||||
b.Property<bool>("IsCommunistParty")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<bool>("IsTradeUnion")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<bool>("IsYouthUnion")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<int?>("MaritalStatus")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("MedicalRegistrationPlace")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<string>("Nationality")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("nvarchar(50)");
|
||||
|
||||
b.Property<string>("Notes")
|
||||
.HasMaxLength(2000)
|
||||
.HasColumnType("nvarchar(2000)");
|
||||
|
||||
b.Property<string>("PassportNumber")
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("nvarchar(20)");
|
||||
|
||||
b.Property<string>("PermanentAddressText")
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("nvarchar(500)");
|
||||
|
||||
b.Property<Guid?>("PermanentDistrictId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid?>("PermanentProvinceId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid?>("PermanentWardId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("PersonalEmail")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<string>("Phone")
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("nvarchar(20)");
|
||||
|
||||
b.Property<string>("PhotoUrl")
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("nvarchar(500)");
|
||||
|
||||
b.Property<string>("Qualification")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<string>("Religion")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("nvarchar(50)");
|
||||
|
||||
b.Property<decimal?>("RemainingLeaveDays")
|
||||
.HasColumnType("decimal(5,2)");
|
||||
|
||||
b.Property<DateOnly?>("ResignDate")
|
||||
.HasColumnType("date");
|
||||
|
||||
b.Property<decimal?>("SeniorityLeaveDays")
|
||||
.HasColumnType("decimal(5,2)");
|
||||
|
||||
b.Property<string>("SocialInsuranceNumber")
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("nvarchar(20)");
|
||||
|
||||
b.Property<DateOnly?>("SocialInsuranceStartDate")
|
||||
.HasColumnType("date");
|
||||
|
||||
b.Property<string>("StreetAddressPermanent")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<string>("StreetAddressTemporary")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<string>("TaxCode")
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("nvarchar(20)");
|
||||
|
||||
b.Property<string>("TemporaryAddressText")
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("nvarchar(500)");
|
||||
|
||||
b.Property<Guid?>("TemporaryDistrictId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid?>("TemporaryProvinceId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid?>("TemporaryWardId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("TimekeepingCode")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("nvarchar(50)");
|
||||
|
||||
b.Property<decimal?>("TotalSalary")
|
||||
.HasColumnType("decimal(18,2)");
|
||||
|
||||
b.Property<DateOnly?>("TradeUnionJoinDate")
|
||||
.HasColumnType("date");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid?>("UpdatedBy")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<int?>("WeightKg")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("WorkLocation")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<DateOnly?>("YouthUnionJoinDate")
|
||||
.HasColumnType("date");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("EmployeeCode")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("IsDeleted");
|
||||
|
||||
b.HasIndex("Phone");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("EmployeeProfiles", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SolutionErp.Domain.Hrm.EmployeeSkill", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid?>("CreatedBy")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<DateTime?>("DeletedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid?>("DeletedBy")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid>("EmployeeProfileId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<int>("Kind")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("LanguageId")
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("nvarchar(20)");
|
||||
|
||||
b.Property<string>("Level")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid?>("UpdatedBy")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("EmployeeProfileId");
|
||||
|
||||
b.HasIndex("Kind");
|
||||
|
||||
b.ToTable("EmployeeSkills", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SolutionErp.Domain.Hrm.EmployeeWorkHistory", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<string>("CompanyAddress")
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("nvarchar(500)");
|
||||
|
||||
b.Property<string>("CompanyName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid?>("CreatedBy")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<DateTime?>("DeletedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid?>("DeletedBy")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<Guid>("EmployeeProfileId")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.Property<DateOnly?>("FromDate")
|
||||
.HasColumnType("date");
|
||||
|
||||
b.Property<string>("Industry")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("JobDescription")
|
||||
.HasMaxLength(2000)
|
||||
.HasColumnType("nvarchar(2000)");
|
||||
|
||||
b.Property<string>("JobTitle")
|
||||
.HasMaxLength(200)
|
||||
.HasColumnType("nvarchar(200)");
|
||||
|
||||
b.Property<string>("ResignReason")
|
||||
.HasMaxLength(500)
|
||||
.HasColumnType("nvarchar(500)");
|
||||
|
||||
b.Property<DateOnly?>("ToDate")
|
||||
.HasColumnType("date");
|
||||
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<Guid?>("UpdatedBy")
|
||||
.HasColumnType("uniqueidentifier");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("EmployeeProfileId");
|
||||
|
||||
b.ToTable("EmployeeWorkHistories", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SolutionErp.Domain.Identity.MenuItem", b =>
|
||||
{
|
||||
b.Property<string>("Key")
|
||||
@ -3731,6 +4331,72 @@ namespace SolutionErp.Infrastructure.Persistence.Migrations
|
||||
b.Navigation("Step");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SolutionErp.Domain.Hrm.EmployeeDocument", b =>
|
||||
{
|
||||
b.HasOne("SolutionErp.Domain.Hrm.EmployeeProfile", "EmployeeProfile")
|
||||
.WithMany("Documents")
|
||||
.HasForeignKey("EmployeeProfileId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("EmployeeProfile");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SolutionErp.Domain.Hrm.EmployeeEducation", b =>
|
||||
{
|
||||
b.HasOne("SolutionErp.Domain.Hrm.EmployeeProfile", "EmployeeProfile")
|
||||
.WithMany("Educations")
|
||||
.HasForeignKey("EmployeeProfileId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("EmployeeProfile");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SolutionErp.Domain.Hrm.EmployeeFamilyRelation", b =>
|
||||
{
|
||||
b.HasOne("SolutionErp.Domain.Hrm.EmployeeProfile", "EmployeeProfile")
|
||||
.WithMany("FamilyRelations")
|
||||
.HasForeignKey("EmployeeProfileId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("EmployeeProfile");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SolutionErp.Domain.Hrm.EmployeeProfile", b =>
|
||||
{
|
||||
b.HasOne("SolutionErp.Domain.Identity.User", "User")
|
||||
.WithOne()
|
||||
.HasForeignKey("SolutionErp.Domain.Hrm.EmployeeProfile", "UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SolutionErp.Domain.Hrm.EmployeeSkill", b =>
|
||||
{
|
||||
b.HasOne("SolutionErp.Domain.Hrm.EmployeeProfile", "EmployeeProfile")
|
||||
.WithMany("Skills")
|
||||
.HasForeignKey("EmployeeProfileId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("EmployeeProfile");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SolutionErp.Domain.Hrm.EmployeeWorkHistory", b =>
|
||||
{
|
||||
b.HasOne("SolutionErp.Domain.Hrm.EmployeeProfile", "EmployeeProfile")
|
||||
.WithMany("WorkHistories")
|
||||
.HasForeignKey("EmployeeProfileId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("EmployeeProfile");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SolutionErp.Domain.Identity.MenuItem", b =>
|
||||
{
|
||||
b.HasOne("SolutionErp.Domain.Identity.MenuItem", "Parent")
|
||||
@ -3982,6 +4648,19 @@ namespace SolutionErp.Infrastructure.Persistence.Migrations
|
||||
b.Navigation("Approvers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SolutionErp.Domain.Hrm.EmployeeProfile", b =>
|
||||
{
|
||||
b.Navigation("Documents");
|
||||
|
||||
b.Navigation("Educations");
|
||||
|
||||
b.Navigation("FamilyRelations");
|
||||
|
||||
b.Navigation("Skills");
|
||||
|
||||
b.Navigation("WorkHistories");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SolutionErp.Domain.Identity.MenuItem", b =>
|
||||
{
|
||||
b.Navigation("Children");
|
||||
|
||||
@ -0,0 +1,53 @@
|
||||
using System.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SolutionErp.Application.Common.Interfaces;
|
||||
using SolutionErp.Application.Hrm.Services;
|
||||
using SolutionErp.Domain.Hrm;
|
||||
|
||||
namespace SolutionErp.Infrastructure.Services;
|
||||
|
||||
// Mirror ContractCodeGenerator + PurchaseEvaluationCodeGenerator pattern.
|
||||
// Format: "NV/{YYYY}/{Seq:D4}", reset per năm.
|
||||
//
|
||||
// SERIALIZABLE transaction tránh race khi 2 admin tạo NV đồng thời.
|
||||
public class EmployeeCodeGenerator(IApplicationDbContext db, IDateTime dateTime)
|
||||
: IEmployeeCodeGenerator
|
||||
{
|
||||
public async Task<string> GenerateAsync(CancellationToken ct = default)
|
||||
{
|
||||
var year = dateTime.UtcNow.Year;
|
||||
var prefix = $"NV/{year}";
|
||||
|
||||
var context = (DbContext)db;
|
||||
await using var tx = await context.Database
|
||||
.BeginTransactionAsync(IsolationLevel.Serializable, ct);
|
||||
try
|
||||
{
|
||||
var seq = await db.EmployeeCodeSequences
|
||||
.FirstOrDefaultAsync(s => s.Prefix == prefix, ct);
|
||||
if (seq is null)
|
||||
{
|
||||
seq = new EmployeeCodeSequence
|
||||
{
|
||||
Prefix = prefix,
|
||||
LastSeq = 1,
|
||||
UpdatedAt = dateTime.UtcNow,
|
||||
};
|
||||
db.EmployeeCodeSequences.Add(seq);
|
||||
}
|
||||
else
|
||||
{
|
||||
seq.LastSeq += 1;
|
||||
seq.UpdatedAt = dateTime.UtcNow;
|
||||
}
|
||||
await db.SaveChangesAsync(ct);
|
||||
await tx.CommitAsync(ct);
|
||||
return $"{prefix}/{seq.LastSeq:D4}";
|
||||
}
|
||||
catch
|
||||
{
|
||||
await tx.RollbackAsync(ct);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user