<?php

namespace Application\Service\Extension\Logger;

use Application\Service\Extension\Laminas;
use Application\Service\Extension\Params\Params;

/**
 * 基础日志模板, 只记录一些基础的数据.
 */
class BasicLogger extends BaseLogger
{
    /**
     * @throws \Exception
     */
    public function __construct()
    {
        // 被初始化的数据
        // 这里的数据先从前端传过来的数据初始化
        foreach (['itemId', 'signId', 'checkTimeId', 'formId', 'patientId'] as $item) {
            if (Params::app()->$item) {
                $this->{$item} = Params::app()->$item;
            }
        }
    }

    public function flush()
    {
        Laminas::$serviceManager->patientFormContentUpdatedLog()->save([
            'item_id' => $this->itemId,
            'sign_id' => $this->signId,
            'checktime_id' => $this->checkTimeId,
            'form_id' => $this->formId,
            'patient_id' => $this->patientId,
            'is_del' => 0,
            'data' => $this->data,
            'content_id' => $this->contentId,
            'source' => Laminas::$serviceManager->identity->getPlatform() ?? 'SCRIPT',
            'event' => $this->event, // 必须有操作事件
            'change_data' => '',
            'change_data_str' => '',
            'json' => '',
            'concat_id' => $this->patientId . $this->checkTimeId . $this->formId,
        ]);
    }
}