Files
PowderCoatingLogix/src/PowderCoating.Infrastructure/Services/SeedDataService.Equipment.cs
T
2026-04-23 21:38:24 -04:00

276 lines
13 KiB
C#

using Microsoft.EntityFrameworkCore;
using PowderCoating.Core.Entities;
using PowderCoating.Core.Enums;
namespace PowderCoating.Infrastructure.Services;
public partial class SeedDataService
{
/// <summary>
/// Seeds ten realistic pieces of powder coating shop equipment for the given company:
/// two curing ovens, two spray booths, two blast units, an air compressor, an overhead
/// conveyor, a parts washer, and a powder reclaim system.
/// </summary>
/// <remarks>
/// <para>
/// Idempotency is enforced by checking for the sentinel equipment number
/// <c>{CompanyCode}-OVN-001</c> before inserting. If that record already exists the
/// method returns 0 without touching the database.
/// </para>
/// <para>
/// <c>IgnoreQueryFilters()</c> is used on the existence check so that a previously
/// soft-deleted seed record is still detected and does not cause duplicate inserts.
/// </para>
/// <para>
/// One equipment record is intentionally set to <see cref="EquipmentStatus.NeedsMaintenance"/>
/// (the media blast room) to provide a realistic demo that includes equipment in a degraded
/// state, triggering the maintenance alert banner.
/// </para>
/// <para>
/// Throws <see cref="InvalidOperationException"/> if <paramref name="company"/> has no
/// <c>CompanyCode</c> because all equipment numbers and serial-number fingerprints depend
/// on that value.
/// </para>
/// </remarks>
/// <param name="company">The tenant company to seed equipment for.</param>
/// <returns>Number of equipment records inserted, or 0 if already seeded.</returns>
private async Task<int> SeedEquipmentAsync(Company company)
{
// Validate company code
if (string.IsNullOrWhiteSpace(company.CompanyCode))
{
throw new InvalidOperationException($"Company {company.CompanyName} (ID: {company.Id}) has no CompanyCode.");
}
// Check if seed equipment already exists by looking for specific equipment number
var seedEquipmentNumber = $"{company.CompanyCode}-OVN-001";
var seedEquipmentExists = await _context.Set<Equipment>()
.IgnoreQueryFilters()
.AnyAsync(e => e.CompanyId == company.Id && e.EquipmentNumber == seedEquipmentNumber && !e.IsDeleted);
if (seedEquipmentExists)
{
return 0;
}
var equipment = new List<Equipment>
{
new Equipment
{
EquipmentName = "Batch Powder Coating Oven #1",
EquipmentNumber = $"{company.CompanyCode}-OVN-001",
EquipmentType = "Oven",
Manufacturer = "Reliant Finishing Systems",
Model = "RFS-2400",
SerialNumber = "RFS240023456",
PurchaseDate = DateTime.UtcNow.AddYears(-3),
PurchasePrice = 45000m,
WarrantyExpiration = DateTime.UtcNow.AddYears(-1),
Status = EquipmentStatus.Operational,
Location = "Bay 1",
RecommendedMaintenanceIntervalDays = 90,
LastMaintenanceDate = DateTime.UtcNow.AddDays(-45),
NextScheduledMaintenance = DateTime.UtcNow.AddDays(45),
Notes = "24'x8'x8' gas-fired batch oven, max temp 450°F",
IsActive = true,
CompanyId = company.Id,
CreatedAt = DateTime.UtcNow.AddYears(-3)
},
new Equipment
{
EquipmentName = "Batch Powder Coating Oven #2",
EquipmentNumber = $"{company.CompanyCode}-OVN-002",
EquipmentType = "Oven",
Manufacturer = "Reliant Finishing Systems",
Model = "RFS-1800",
SerialNumber = "RFS180012789",
PurchaseDate = DateTime.UtcNow.AddYears(-5),
PurchasePrice = 38000m,
WarrantyExpiration = DateTime.UtcNow.AddYears(-3),
Status = EquipmentStatus.Operational,
Location = "Bay 2",
RecommendedMaintenanceIntervalDays = 90,
LastMaintenanceDate = DateTime.UtcNow.AddDays(-30),
NextScheduledMaintenance = DateTime.UtcNow.AddDays(60),
Notes = "18'x8'x8' gas-fired batch oven",
IsActive = true,
CompanyId = company.Id,
CreatedAt = DateTime.UtcNow.AddYears(-5)
},
new Equipment
{
EquipmentName = "Automated Powder Coating Booth #1",
EquipmentNumber = $"{company.CompanyCode}-BOOTH-001",
EquipmentType = "Spray Booth",
Manufacturer = "Nordson Corporation",
Model = "Nordson ProBooth 1200",
SerialNumber = "NOR120045678",
PurchaseDate = DateTime.UtcNow.AddYears(-2),
PurchasePrice = 65000m,
WarrantyExpiration = DateTime.UtcNow.AddMonths(6),
Status = EquipmentStatus.Operational,
Location = "Coating Line A",
RecommendedMaintenanceIntervalDays = 30,
LastMaintenanceDate = DateTime.UtcNow.AddDays(-15),
NextScheduledMaintenance = DateTime.UtcNow.AddDays(15),
Notes = "Fully automated booth with cyclone recovery system",
IsActive = true,
CompanyId = company.Id,
CreatedAt = DateTime.UtcNow.AddYears(-2)
},
new Equipment
{
EquipmentName = "Manual Powder Coating Booth #2",
EquipmentNumber = $"{company.CompanyCode}-BOOTH-002",
EquipmentType = "Spray Booth",
Manufacturer = "Columbia Coatings",
Model = "CC-Manual-800",
SerialNumber = "CC800034512",
PurchaseDate = DateTime.UtcNow.AddYears(-6),
PurchasePrice = 28000m,
WarrantyExpiration = DateTime.UtcNow.AddYears(-4),
Status = EquipmentStatus.Operational,
Location = "Coating Line B",
RecommendedMaintenanceIntervalDays = 60,
LastMaintenanceDate = DateTime.UtcNow.AddDays(-40),
NextScheduledMaintenance = DateTime.UtcNow.AddDays(20),
Notes = "Manual booth for small custom jobs",
IsActive = true,
CompanyId = company.Id,
CreatedAt = DateTime.UtcNow.AddYears(-6)
},
new Equipment
{
EquipmentName = "Pressure Blast Cabinet",
EquipmentNumber = $"{company.CompanyCode}-BLAST-001",
EquipmentType = "Sandblaster",
Manufacturer = "Empire Abrasive Equipment",
Model = "Empire Industrial 4836",
SerialNumber = "EMP483623890",
PurchaseDate = DateTime.UtcNow.AddYears(-4),
PurchasePrice = 18500m,
WarrantyExpiration = DateTime.UtcNow.AddYears(-3),
Status = EquipmentStatus.Operational,
Location = "Prep Area A",
RecommendedMaintenanceIntervalDays = 45,
LastMaintenanceDate = DateTime.UtcNow.AddDays(-20),
NextScheduledMaintenance = DateTime.UtcNow.AddDays(25),
Notes = "48\"x36\" cabinet, aluminum oxide media",
IsActive = true,
CompanyId = company.Id,
CreatedAt = DateTime.UtcNow.AddYears(-4)
},
new Equipment
{
EquipmentName = "Media Blast Room",
EquipmentNumber = $"{company.CompanyCode}-BLAST-002",
EquipmentType = "Sandblaster",
Manufacturer = "Clemco Industries",
Model = "Clemco BRT-1012",
SerialNumber = "CLM101223456",
PurchaseDate = DateTime.UtcNow.AddYears(-7),
PurchasePrice = 42000m,
WarrantyExpiration = DateTime.UtcNow.AddYears(-5),
Status = EquipmentStatus.NeedsMaintenance,
Location = "Prep Area B",
RecommendedMaintenanceIntervalDays = 60,
LastMaintenanceDate = DateTime.UtcNow.AddDays(-75),
NextScheduledMaintenance = DateTime.UtcNow.AddDays(-15),
Notes = "10'x12' walk-in blast room - needs filter replacement",
IsActive = true,
CompanyId = company.Id,
CreatedAt = DateTime.UtcNow.AddYears(-7)
},
new Equipment
{
EquipmentName = "Rotary Screw Air Compressor",
EquipmentNumber = $"{company.CompanyCode}-COMP-001",
EquipmentType = "Compressor",
Manufacturer = "Atlas Copco",
Model = "GA75 VSD",
SerialNumber = "ATC7523467",
PurchaseDate = DateTime.UtcNow.AddYears(-3),
PurchasePrice = 35000m,
WarrantyExpiration = DateTime.UtcNow.AddMonths(-6),
Status = EquipmentStatus.Operational,
Location = "Compressor Room",
RecommendedMaintenanceIntervalDays = 90,
LastMaintenanceDate = DateTime.UtcNow.AddDays(-60),
NextScheduledMaintenance = DateTime.UtcNow.AddDays(30),
Notes = "75 HP variable speed drive compressor",
IsActive = true,
CompanyId = company.Id,
CreatedAt = DateTime.UtcNow.AddYears(-3)
},
new Equipment
{
EquipmentName = "Overhead Conveyor System",
EquipmentNumber = $"{company.CompanyCode}-CONV-001",
EquipmentType = "Conveyor",
Manufacturer = "Pacline Conveyors",
Model = "PAC-500 Overhead",
SerialNumber = "PAC50034521",
PurchaseDate = DateTime.UtcNow.AddYears(-4),
PurchasePrice = 52000m,
WarrantyExpiration = DateTime.UtcNow.AddYears(-2),
Status = EquipmentStatus.Operational,
Location = "Main Production Line",
RecommendedMaintenanceIntervalDays = 180,
LastMaintenanceDate = DateTime.UtcNow.AddDays(-120),
NextScheduledMaintenance = DateTime.UtcNow.AddDays(60),
Notes = "500 lb capacity overhead conveyor with power and free sections",
IsActive = true,
CompanyId = company.Id,
CreatedAt = DateTime.UtcNow.AddYears(-4)
},
new Equipment
{
EquipmentName = "Parts Washer System",
EquipmentNumber = $"{company.CompanyCode}-WASH-001",
EquipmentType = "Washer",
Manufacturer = "Better Engineering",
Model = "BE-4896 Power Wash",
SerialNumber = "BE489612345",
PurchaseDate = DateTime.UtcNow.AddYears(-5),
PurchasePrice = 24000m,
WarrantyExpiration = DateTime.UtcNow.AddYears(-3),
Status = EquipmentStatus.Operational,
Location = "Prep Area A",
RecommendedMaintenanceIntervalDays = 30,
LastMaintenanceDate = DateTime.UtcNow.AddDays(-10),
NextScheduledMaintenance = DateTime.UtcNow.AddDays(20),
Notes = "48\"x96\" spray washer with heated solution",
IsActive = true,
CompanyId = company.Id,
CreatedAt = DateTime.UtcNow.AddYears(-5)
},
new Equipment
{
EquipmentName = "Powder Reclaim System",
EquipmentNumber = $"{company.CompanyCode}-RCLM-001",
EquipmentType = "Reclaim System",
Manufacturer = "Gema USA",
Model = "OptiCenter OC06",
SerialNumber = "GEM0623456",
PurchaseDate = DateTime.UtcNow.AddYears(-2),
PurchasePrice = 32000m,
WarrantyExpiration = DateTime.UtcNow.AddMonths(3),
Status = EquipmentStatus.Operational,
Location = "Coating Line A",
RecommendedMaintenanceIntervalDays = 60,
LastMaintenanceDate = DateTime.UtcNow.AddDays(-35),
NextScheduledMaintenance = DateTime.UtcNow.AddDays(25),
Notes = "Automatic powder recovery and color change system",
IsActive = true,
CompanyId = company.Id,
CreatedAt = DateTime.UtcNow.AddYears(-2)
}
};
await _context.Set<Equipment>().AddRangeAsync(equipment);
await _context.SaveChangesAsync();
return equipment.Count;
}
}