| Numéro du ticket | Titre du ticket | |------------------|-----------------| | #278 | Plan du site | ## Description de la PR [#278] Plan du site ## Modification du .env ## Check list - [ ] Pas de régression - [x] TU/TI/TF rédigée - [x] TU/TI/TF OK - [ ] CHANGELOG modifié Co-authored-by: Matteo <matteo@yuno.malio.fr> Reviewed-on: https://gitea.malio.fr/MALIO-DEV/Ferme/pulls/33 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
This commit is contained in:
@@ -5,8 +5,12 @@ declare(strict_types=1);
|
||||
namespace App\Command;
|
||||
|
||||
use App\Entity\Address;
|
||||
use App\Entity\Bovine;
|
||||
use App\Entity\BovineType;
|
||||
use App\Entity\Building;
|
||||
use App\Entity\BuildingCase;
|
||||
use App\Entity\BuildingCasePosition;
|
||||
use App\Entity\BuildingLayout;
|
||||
use App\Entity\Carrier;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Driver;
|
||||
@@ -14,9 +18,11 @@ use App\Entity\MerchandiseType;
|
||||
use App\Entity\PelletType;
|
||||
use App\Entity\ReceptionType;
|
||||
use App\Entity\ShipmentType;
|
||||
use App\Entity\Statut;
|
||||
use App\Entity\Supplier;
|
||||
use App\Entity\Truck;
|
||||
use App\Entity\Vehicle;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
@@ -52,6 +58,8 @@ class SeedCommand extends Command
|
||||
$this->seedMerchandiseTypes();
|
||||
$this->seedPelletTypes();
|
||||
$this->seedBuildings();
|
||||
$this->seedBuildingInfrastructure();
|
||||
$this->seedBovines($io);
|
||||
$this->seedReceptionTypes();
|
||||
$this->seedBovineTypes();
|
||||
$this->seedShipmentTypes();
|
||||
@@ -215,6 +223,137 @@ class SeedCommand extends Command
|
||||
}
|
||||
}
|
||||
|
||||
private function seedBuildingInfrastructure(): void
|
||||
{
|
||||
$statusByCode = [];
|
||||
$statusRows = [
|
||||
['label' => 'Libre', 'code' => 'LB', 'color' => '#A3B18A'],
|
||||
['label' => 'Occupé', 'code' => 'OC', 'color' => '#3A506B'],
|
||||
['label' => 'Malade', 'code' => 'ML', 'color' => '#E07A5F'],
|
||||
];
|
||||
foreach ($statusRows as $statusRow) {
|
||||
/** @var Statut $status */
|
||||
$status = $this->upsertByCode(Statut::class, $statusRow['code'], static function (Statut $entity) use ($statusRow) {
|
||||
$entity
|
||||
->setLabel($statusRow['label'])
|
||||
->setCode($statusRow['code'])
|
||||
->setColor($statusRow['color'])
|
||||
;
|
||||
});
|
||||
$statusByCode[$statusRow['code']] = $status;
|
||||
}
|
||||
|
||||
$buildingRepo = $this->entityManager->getRepository(Building::class);
|
||||
$layoutByBuildingCode = [];
|
||||
$layoutRows = [
|
||||
['buildingCode' => 'B1', 'name' => 'plan1', 'columns' => 23, 'rows' => 2],
|
||||
['buildingCode' => 'B2', 'name' => 'plan2', 'columns' => 23, 'rows' => 2],
|
||||
['buildingCode' => 'B3', 'name' => 'plan3', 'columns' => 23, 'rows' => 2],
|
||||
];
|
||||
foreach ($layoutRows as $layoutRow) {
|
||||
$building = $buildingRepo->findOneBy(['code' => $layoutRow['buildingCode']]);
|
||||
if (!$building instanceof Building) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/** @var BuildingLayout $layout */
|
||||
$layout = $this->upsertByName(BuildingLayout::class, $layoutRow['name'], static function (BuildingLayout $entity) use ($layoutRow, $building) {
|
||||
$entity
|
||||
->setName($layoutRow['name'])
|
||||
->setColumns($layoutRow['columns'])
|
||||
->setRows($layoutRow['rows'])
|
||||
->setIdBuilding($building)
|
||||
;
|
||||
});
|
||||
$layoutByBuildingCode[$layoutRow['buildingCode']] = $layout;
|
||||
}
|
||||
|
||||
$caseRows = [
|
||||
['buildingCode' => 'B1', 'from' => 1, 'to' => 12, 'status' => 'LB'],
|
||||
['buildingCode' => 'B1', 'from' => 13, 'to' => 24, 'status' => 'OC'],
|
||||
['buildingCode' => 'B1', 'from' => 25, 'to' => 32, 'status' => 'ML'],
|
||||
['buildingCode' => 'B1', 'from' => 33, 'to' => 44, 'status' => 'LB'],
|
||||
['buildingCode' => 'B2', 'from' => 1, 'to' => 10, 'status' => 'OC'],
|
||||
['buildingCode' => 'B2', 'from' => 11, 'to' => 22, 'status' => 'LB'],
|
||||
['buildingCode' => 'B2', 'from' => 23, 'to' => 30, 'status' => 'ML'],
|
||||
['buildingCode' => 'B2', 'from' => 31, 'to' => 44, 'status' => 'OC'],
|
||||
['buildingCode' => 'B3', 'from' => 1, 'to' => 8, 'status' => 'ML'],
|
||||
['buildingCode' => 'B3', 'from' => 9, 'to' => 20, 'status' => 'LB'],
|
||||
['buildingCode' => 'B3', 'from' => 21, 'to' => 34, 'status' => 'OC'],
|
||||
['buildingCode' => 'B3', 'from' => 35, 'to' => 44, 'status' => 'ML'],
|
||||
];
|
||||
|
||||
$caseByCode = [];
|
||||
foreach ($caseRows as $caseRow) {
|
||||
$building = $buildingRepo->findOneBy(['code' => $caseRow['buildingCode']]);
|
||||
$status = $statusByCode[$caseRow['status']] ?? null;
|
||||
if (!$building instanceof Building || !$status instanceof Statut) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for ($caseNumber = $caseRow['from']; $caseNumber <= $caseRow['to']; ++$caseNumber) {
|
||||
$code = sprintf('%s-C%d', $caseRow['buildingCode'], $caseNumber);
|
||||
|
||||
/** @var BuildingCase $buildingCase */
|
||||
$buildingCase = $this->upsertByCode(BuildingCase::class, $code, static function (BuildingCase $entity) use ($code, $caseNumber, $building, $status) {
|
||||
$entity
|
||||
->setCode($code)
|
||||
->setCaseNumber($caseNumber)
|
||||
->setCapacity(15)
|
||||
->setIdBuilding($building)
|
||||
->setStatut($status)
|
||||
;
|
||||
});
|
||||
$caseByCode[$code] = $buildingCase;
|
||||
}
|
||||
}
|
||||
|
||||
$slots = $this->buildSlotMap();
|
||||
$positionRepo = $this->entityManager->getRepository(BuildingCasePosition::class);
|
||||
|
||||
foreach (['B1' => 'plan1', 'B2' => 'plan2', 'B3' => 'plan3'] as $buildingCode => $layoutName) {
|
||||
$layout = $layoutByBuildingCode[$buildingCode] ?? null;
|
||||
if (!$layout instanceof BuildingLayout || $layout->getName() !== $layoutName) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($slots as $slot) {
|
||||
$caseCode = sprintf('%s-C%d', $buildingCode, $slot['caseNumber']);
|
||||
$buildingCase = $caseByCode[$caseCode] ?? null;
|
||||
if (!$buildingCase instanceof BuildingCase) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$position = $positionRepo->findOneBy([
|
||||
'buildingLayout' => $layout,
|
||||
'buildingCase' => $buildingCase,
|
||||
'x' => $slot['x'],
|
||||
'y' => $slot['y'],
|
||||
]);
|
||||
|
||||
if ($position instanceof BuildingCasePosition) {
|
||||
++$this->updated;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$position = new BuildingCasePosition();
|
||||
$position
|
||||
->setX($slot['x'])
|
||||
->setY($slot['y'])
|
||||
->setW($slot['w'])
|
||||
->setH($slot['h'])
|
||||
->setRenderOrder((string) $slot['renderOrder'])
|
||||
->setBuildingLayout($layout)
|
||||
->setBuildingCase($buildingCase)
|
||||
;
|
||||
|
||||
++$this->created;
|
||||
$this->entityManager->persist($position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function seedReceptionTypes(): void
|
||||
{
|
||||
$receptionTypes = [
|
||||
@@ -231,6 +370,134 @@ class SeedCommand extends Command
|
||||
}
|
||||
}
|
||||
|
||||
private function seedBovines(SymfonyStyle $io): void
|
||||
{
|
||||
$rows = [
|
||||
[1, 15, '7979580026', 390, '2026-02-25'],
|
||||
[5, 113, '4405604924', 397, '2025-05-22'],
|
||||
[4, 113, '4405604944', 375, '2025-05-22'],
|
||||
[2, 113, '4963291114', 319, '2025-05-22'],
|
||||
[3, 113, '4405604922', 386, '2025-05-22'],
|
||||
[6, 126, '4415811026', 367, '2025-07-02'],
|
||||
[7, 126, '4950971149', 398, '2025-07-02'],
|
||||
[8, 126, '4950971170', 386, '2025-07-02'],
|
||||
[9, 126, '4489751630', 408, '2025-07-02'],
|
||||
[10, 126, '8551323003', 478, '2025-07-02'],
|
||||
[11, 126, '8503833703', 378, '2025-07-02'],
|
||||
[12, 126, '4402104572', 379, '2025-07-02'],
|
||||
[13, 126, '4402104580', 465, '2025-07-02'],
|
||||
[14, 126, '4402104607', 381, '2025-07-02'],
|
||||
[15, 126, '8504059581', 446, '2025-07-02'],
|
||||
[16, 124, '4950971161', 382, '2025-07-02'],
|
||||
[17, 124, '5652911499', 376, '2025-07-02'],
|
||||
[18, 124, '8551323029', 414, '2025-07-02'],
|
||||
[19, 124, '4402104590', 474, '2025-07-02'],
|
||||
[20, 124, '4402104594', 408, '2025-07-02'],
|
||||
[21, 124, '4402104595', 399, '2025-07-02'],
|
||||
[22, 124, '4402104604', 374, '2025-07-02'],
|
||||
[23, 124, '8504059579', 403, '2025-07-02'],
|
||||
[24, 124, '8504059590', 398, '2025-07-02'],
|
||||
[25, 123, '8551782070', 395, '2025-07-02'],
|
||||
[26, 123, '8551782080', 443, '2025-07-02'],
|
||||
[27, 123, '8551782084', 394, '2025-07-02'],
|
||||
[28, 123, '8551782090', 378, '2025-07-02'],
|
||||
[29, 123, '8551782092', 424, '2025-07-02'],
|
||||
[30, 123, '8551782094', 389, '2025-07-02'],
|
||||
[31, 123, '8551782099', 411, '2025-07-02'],
|
||||
[32, 123, '8551323020', 392, '2025-07-02'],
|
||||
[33, 123, '8551323051', 371, '2025-07-02'],
|
||||
[34, 123, '7947673148', 378, '2025-07-02'],
|
||||
[39, 114, '1731177447', 395, '2025-06-19'],
|
||||
[42, 114, '1726167608', 299, '2025-06-19'],
|
||||
[38, 114, '1731177442', 343, '2025-06-19'],
|
||||
[40, 114, '1731177448', 362, '2025-06-19'],
|
||||
[41, 114, '1731177458', 359, '2025-06-19'],
|
||||
[35, 114, '7946282100', 291, '2025-06-19'],
|
||||
[43, 114, '1726167613', 339, '2025-06-19'],
|
||||
[37, 114, '1731177427', 375, '2025-06-19'],
|
||||
[36, 114, '7946282103', 354, '2025-06-19'],
|
||||
];
|
||||
|
||||
$bovineRepo = $this->entityManager->getRepository(Bovine::class);
|
||||
$caseRepo = $this->entityManager->getRepository(BuildingCase::class);
|
||||
|
||||
foreach ($rows as [, $legacyCaseId, $nationalNumber, $receivedWeight, $arrivalDate]) {
|
||||
$buildingCase = $this->resolveBuildingCaseByLegacyId((int) $legacyCaseId);
|
||||
if (!$buildingCase instanceof BuildingCase) {
|
||||
$buildingCase = $caseRepo->find((int) $legacyCaseId);
|
||||
}
|
||||
if (!$buildingCase instanceof BuildingCase) {
|
||||
$io->warning(sprintf(
|
||||
'Bovine %s skipped: building_case token %d not found.',
|
||||
$nationalNumber,
|
||||
$legacyCaseId
|
||||
));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$bovine = $bovineRepo->findOneBy(['nationalNumber' => $nationalNumber]);
|
||||
if (!$bovine instanceof Bovine) {
|
||||
$bovine = new Bovine();
|
||||
++$this->created;
|
||||
} else {
|
||||
++$this->updated;
|
||||
}
|
||||
|
||||
$bovine
|
||||
->setNationalNumber((string) $nationalNumber)
|
||||
->setBuildingCase($buildingCase)
|
||||
->setReceivedWeight((int) $receivedWeight)
|
||||
->setArrivalDate(new DateTimeImmutable((string) $arrivalDate))
|
||||
;
|
||||
|
||||
$this->entityManager->persist($bovine);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array{x:int,y:int,w:int,h:int,renderOrder:int,caseNumber:int}>
|
||||
*/
|
||||
private function buildSlotMap(): array
|
||||
{
|
||||
$slots = [];
|
||||
|
||||
for ($column = 1; $column <= 12; ++$column) {
|
||||
$slots[] = ['x' => $column, 'y' => 1, 'w' => 1, 'h' => 1, 'renderOrder' => $column, 'caseNumber' => $column + 12];
|
||||
}
|
||||
for ($column = 14; $column <= 23; ++$column) {
|
||||
$slots[] = ['x' => $column, 'y' => 1, 'w' => 1, 'h' => 1, 'renderOrder' => $column - 1, 'caseNumber' => $column + 11];
|
||||
}
|
||||
for ($column = 1; $column <= 12; ++$column) {
|
||||
$slots[] = ['x' => $column, 'y' => 2, 'w' => 1, 'h' => 1, 'renderOrder' => 22 + $column, 'caseNumber' => 13 - $column];
|
||||
}
|
||||
for ($column = 14; $column <= 23; ++$column) {
|
||||
$slots[] = ['x' => $column, 'y' => 2, 'w' => 1, 'h' => 1, 'renderOrder' => 21 + $column, 'caseNumber' => 58 - $column];
|
||||
}
|
||||
|
||||
return $slots;
|
||||
}
|
||||
|
||||
private function resolveBuildingCaseByLegacyId(int $legacyCaseId): ?BuildingCase
|
||||
{
|
||||
if ($legacyCaseId < 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$buildingNumber = intdiv($legacyCaseId - 1, 44) + 1;
|
||||
$caseNumber = (($legacyCaseId - 1) % 44) + 1;
|
||||
|
||||
if ($buildingNumber < 1 || $buildingNumber > 3) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$code = sprintf('B%d-C%d', $buildingNumber, $caseNumber);
|
||||
|
||||
$buildingCase = $this->entityManager->getRepository(BuildingCase::class)->findOneBy(['code' => $code]);
|
||||
|
||||
return $buildingCase instanceof BuildingCase ? $buildingCase : null;
|
||||
}
|
||||
|
||||
private function seedBovineTypes(): void
|
||||
{
|
||||
$bovineTypes = [
|
||||
|
||||
Reference in New Issue
Block a user