| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace App\Module\Farm\Dtos;
- use App\Module\Farm\Enums\DISASTER_TYPE;
- /**
- * 灾害信息数据传输对象
- */
- class DisasterInfoDto
- {
- /**
- * 灾害类型
- *
- * @var int
- */
- public $type;
- /**
- * 灾害类型名称
- *
- * @var string
- */
- public $typeName;
- /**
- * 生成时间
- *
- * @var string
- */
- public $generatedTs;
- /**
- * 状态
- *
- * @var string
- */
- public $status;
- /**
- * 清理时间
- *
- * @var string|null
- */
- public $clearedAt;
- /**
- * 从数组创建DTO
- *
- * @param array $disasterInfo
- * @return self
- */
- public static function fromArray(array $disasterInfo): self
- {
- $dto = new self();
- $dto->type = $disasterInfo['type'] ?? 0;
- $dto->typeName = DISASTER_TYPE::getName($dto->type);
- $dto->generatedAt = $disasterInfo['generated_ts'] ?? '';
- $dto->status = $disasterInfo['status'] ?? 'active';
- $dto->clearedAt = $disasterInfo['cleared_at'] ?? null;
- return $dto;
- }
- /**
- * 转换为数组
- *
- * @return array
- */
- public function toArray(): array
- {
- return [
- 'type' => $this->type,
- 'type_name' => $this->typeName,
- 'generated_ts' => $this->generatedAt,
- 'status' => $this->status,
- 'cleared_at' => $this->clearedAt,
- ];
- }
- }
|