2026-06-14 21:32:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Infrastructure\Adapters\Services;
|
|
|
|
|
|
|
|
|
|
use App\Models\Employee;
|
|
|
|
|
use Carbon\CarbonImmutable;
|
|
|
|
|
use Domain\Models\ValueObjects\EmployeeUpsertData;
|
|
|
|
|
use Domain\Ports\Services\EmployeeImportStorageService;
|
|
|
|
|
|
|
|
|
|
class EloquentEmployeeImportStorageService implements EmployeeImportStorageService
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @param list<EmployeeUpsertData> $upsertData
|
|
|
|
|
*/
|
|
|
|
|
public function upsertEmployees(array $upsertData): void
|
|
|
|
|
{
|
2026-10-02 12:14:48 +02:00
|
|
|
$now = CarbonImmutable::now()->format('Y-m-d H:i:s');
|
feat(employees): automated sync with Arcadia API, BO settings, Shopper value objects, and pagination migration
- Implement automated synchronization of employees via Arcadia API (EmployeeSyncService, SynchronizeEmployeesWithArcadiaApi, FetchAndUpsertArcadiaEmployees)
- Add Back-Office application settings for employee sites (Setting singleton, GetSettingsQuery, UpdateSettings, SettingsController, EmployeeSitesInputComponent.vue)
- Strongly type Employee attributes using Domain Value Objects (ShopperEstablishmentCode, ShopperSiteCode, ShopperServiceCode) and Eloquent Casts
- Migrate pagination from Domain to Shared\Pagination namespace across queries and inputs
- Remove legacy and dead CSV employee import/export code
- Restore Domain\Ports\Services\CsvGenerator interface for Regate order generation
- Add comprehensive Pest unit, integration, and feature test coverage
2026-10-01 17:26:30 +02:00
|
|
|
$mappedData = array_map(static function (EmployeeUpsertData $data) use ($now): array {
|
2026-06-14 21:32:07 +02:00
|
|
|
return [
|
|
|
|
|
'matricule' => $data->matricule->value,
|
feat(employees): automated sync with Arcadia API, BO settings, Shopper value objects, and pagination migration
- Implement automated synchronization of employees via Arcadia API (EmployeeSyncService, SynchronizeEmployeesWithArcadiaApi, FetchAndUpsertArcadiaEmployees)
- Add Back-Office application settings for employee sites (Setting singleton, GetSettingsQuery, UpdateSettings, SettingsController, EmployeeSitesInputComponent.vue)
- Strongly type Employee attributes using Domain Value Objects (ShopperEstablishmentCode, ShopperSiteCode, ShopperServiceCode) and Eloquent Casts
- Migrate pagination from Domain to Shared\Pagination namespace across queries and inputs
- Remove legacy and dead CSV employee import/export code
- Restore Domain\Ports\Services\CsvGenerator interface for Regate order generation
- Add comprehensive Pest unit, integration, and feature test coverage
2026-10-01 17:26:30 +02:00
|
|
|
'nom' => $data->lastname,
|
|
|
|
|
'prenom' => $data->firstname,
|
|
|
|
|
'etablissement' => $data->etablissement->value,
|
|
|
|
|
'service' => $data->service->value,
|
|
|
|
|
'site' => $data->site->value,
|
2026-06-14 21:32:07 +02:00
|
|
|
'start_date' => $data->startDate->format('Y-m-d H:i:s'),
|
|
|
|
|
'end_date' => $data->endDate?->format('Y-m-d H:i:s'),
|
|
|
|
|
'code' => $data->code->value,
|
feat(employees): automated sync with Arcadia API, BO settings, Shopper value objects, and pagination migration
- Implement automated synchronization of employees via Arcadia API (EmployeeSyncService, SynchronizeEmployeesWithArcadiaApi, FetchAndUpsertArcadiaEmployees)
- Add Back-Office application settings for employee sites (Setting singleton, GetSettingsQuery, UpdateSettings, SettingsController, EmployeeSitesInputComponent.vue)
- Strongly type Employee attributes using Domain Value Objects (ShopperEstablishmentCode, ShopperSiteCode, ShopperServiceCode) and Eloquent Casts
- Migrate pagination from Domain to Shared\Pagination namespace across queries and inputs
- Remove legacy and dead CSV employee import/export code
- Restore Domain\Ports\Services\CsvGenerator interface for Regate order generation
- Add comprehensive Pest unit, integration, and feature test coverage
2026-10-01 17:26:30 +02:00
|
|
|
'last_sync' => $now,
|
2026-06-14 21:32:07 +02:00
|
|
|
];
|
|
|
|
|
}, $upsertData);
|
|
|
|
|
|
|
|
|
|
// NOTE: chunking is essential here because the query builder has a binding limit of 65535
|
feat(employees): automated sync with Arcadia API, BO settings, Shopper value objects, and pagination migration
- Implement automated synchronization of employees via Arcadia API (EmployeeSyncService, SynchronizeEmployeesWithArcadiaApi, FetchAndUpsertArcadiaEmployees)
- Add Back-Office application settings for employee sites (Setting singleton, GetSettingsQuery, UpdateSettings, SettingsController, EmployeeSitesInputComponent.vue)
- Strongly type Employee attributes using Domain Value Objects (ShopperEstablishmentCode, ShopperSiteCode, ShopperServiceCode) and Eloquent Casts
- Migrate pagination from Domain to Shared\Pagination namespace across queries and inputs
- Remove legacy and dead CSV employee import/export code
- Restore Domain\Ports\Services\CsvGenerator interface for Regate order generation
- Add comprehensive Pest unit, integration, and feature test coverage
2026-10-01 17:26:30 +02:00
|
|
|
// each row has 10 bindings, so we can insert at most 65535 / 10 = 6553 rows at once
|
2026-06-14 21:32:07 +02:00
|
|
|
// we use 1000 to be safe
|
|
|
|
|
foreach (array_chunk($mappedData, 1000) as $chunk) {
|
2026-06-17 16:57:52 +02:00
|
|
|
Employee::query()->upsert(
|
|
|
|
|
values: $chunk,
|
|
|
|
|
uniqueBy: ['matricule'],
|
feat(employees): automated sync with Arcadia API, BO settings, Shopper value objects, and pagination migration
- Implement automated synchronization of employees via Arcadia API (EmployeeSyncService, SynchronizeEmployeesWithArcadiaApi, FetchAndUpsertArcadiaEmployees)
- Add Back-Office application settings for employee sites (Setting singleton, GetSettingsQuery, UpdateSettings, SettingsController, EmployeeSitesInputComponent.vue)
- Strongly type Employee attributes using Domain Value Objects (ShopperEstablishmentCode, ShopperSiteCode, ShopperServiceCode) and Eloquent Casts
- Migrate pagination from Domain to Shared\Pagination namespace across queries and inputs
- Remove legacy and dead CSV employee import/export code
- Restore Domain\Ports\Services\CsvGenerator interface for Regate order generation
- Add comprehensive Pest unit, integration, and feature test coverage
2026-10-01 17:26:30 +02:00
|
|
|
update: ['nom', 'prenom', 'etablissement', 'service', 'site', 'start_date', 'end_date', 'last_sync']
|
2026-06-14 21:32:07 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param \Domain\Models\ValueObjects\Matricule[] $matriculesToInsert
|
|
|
|
|
* @return object{insertedCount: int, updatedCount: int, matriculesInserted: \Domain\Models\ValueObjects\Matricule[]}
|
|
|
|
|
*/
|
|
|
|
|
public function getImportedAfter(array $matriculesToInsert, CarbonImmutable $importStartTime): object
|
|
|
|
|
{
|
|
|
|
|
$employees = Employee::query()
|
|
|
|
|
->whereIn('matricule', $matriculesToInsert)
|
|
|
|
|
->get(['matricule', 'created_at', 'updated_at']);
|
|
|
|
|
|
|
|
|
|
/** @var list<\Domain\Models\ValueObjects\Matricule> $matriculesInserted */
|
|
|
|
|
$matriculesInserted = $employees
|
|
|
|
|
->pluck('matricule')
|
|
|
|
|
->values()
|
|
|
|
|
->toArray();
|
|
|
|
|
|
|
|
|
|
$insertedCount = $employees
|
|
|
|
|
->where('created_at', '>=', $importStartTime)
|
|
|
|
|
->count();
|
|
|
|
|
|
|
|
|
|
$updatedCount = $employees
|
|
|
|
|
->where('created_at', '<', $importStartTime)
|
|
|
|
|
->where('updated_at', '>=', $importStartTime)
|
|
|
|
|
->count();
|
|
|
|
|
|
|
|
|
|
return (object) [
|
|
|
|
|
'insertedCount' => $insertedCount,
|
|
|
|
|
'updatedCount' => $updatedCount,
|
|
|
|
|
'matriculesInserted' => $matriculesInserted,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|