<?php

namespace Application\Form\project;


use Application\Common\EventEnumV2;
use Application\Service\DB\Admin\Log;
use Application\Service\DB\Db;
use Application\Service\DB\Dictionary\FormGroup;
use Application\Service\Extension\Form\BaseForm;
use Application\Service\Extension\Helper\ArrayHelper;
use Application\Service\Extension\Helper\DataHelper;
use Application\Service\Extension\Helper\FormContentHelper;
use Application\Service\Extension\Helper\SDMHelper;
use Application\Service\Extension\Helper\StringHelper;
use Application\Service\Extension\Helper\WsHelper;
use Application\Service\Extension\Laminas;
use Application\Service\Extension\Logger\FormContentLogger;
use Application\Service\Extension\Validator\ValidatorApplication;
use Exception;
use Laminas\Db\Sql\Predicate\IsNotNull;
use Laminas\Db\Sql\Where;
use Laminas\Json\Json;
use Laminas\Validator\Exception\InvalidArgumentException;
use Application\Service\DB\Dictionary\Form;
use Zend\Stdlib\ArrayUtils;

class AeForm extends BaseForm
{
    private array $relationData = [];

    private ?array $aeFormData = [];

    private FormContentHelper $logger;
    private array $postData = [];
    private array $postOriginData = [];

    public function __construct(ValidatorApplication $validator = null)
    {
        parent::__construct($validator);

        $this->logger =  SDMHelper::app()->log->formContentLog->setContentType(\Application\Service\Extension\Helper\components\FormContentHelper::CONTENT_TYPE_AE);
    }

    public function getAeForm()
    {
        if (!$this->aeFormData) {
            $this->aeFormData = Laminas::$serviceManager->itemForm->fetchOne([
                'where' => [
                    'item_id' => $this->validator->attributes['item_id'],
                    'group_id' => FormGroup::AE,
                    'is_del' => 0
                ]
            ]);
        }

        return $this->aeFormData;
    }

    public function rollbackToOriginType(int $contentId, int $type, int $csaeId)
    {
        $csaeData = Laminas::$serviceManager->itemPatientAeContent->fetchOne([
            'where' => ['id' => $contentId]
        ]);

        $signId = $csaeData['itemsig_id'];
        $itemId = $csaeData['item_id'];

        $r = function () use ($csaeId, $signId, $itemId) {
            Laminas::$serviceManager->itemCsae->update(['ae_type' => 0, 'is_ae_sure' => 0], ['id' => $csaeId]);
            WsHelper::pushAeMessage($itemId, $signId);
        };


        if ($type == 5) {
                $r();
        } elseif ($type == 6) {
                $r();
        }
    }

    /**
     * 是否提交了受试者新增ae
     * @return bool
     * @throws Exception
     */
    private function isPostNewAeForm(): bool
    {
        $aeFormId = SDMHelper::app()->form->getAeForm($this->validator->attributes['item_id'])['id'];
        $config = Laminas::$serviceManager->itemForm->getPreviewConfig($aeFormId);
        $forms = ArrayHelper::index($config['form'] ?: [], 'prop');
        foreach ($forms as $firstLevelKey => $firstLevel) {
            if (!isset($this->validator->attributes[$firstLevelKey])) {
                return false;
            }
        }

        return true;
    }

    public function initFormContentLog() {
        $this->logger->setEvent($this->event)->setPostData($this->postData)->setPostOriginData($this->postOriginData);
    }

    /**
     * @throws Exception
     */
    public function createNewAeV2()
    {
        $branchHashString = StringHelper::generateHashValue();

        $this->validator->setAttributes([
            'form_id' => $this->getAeForm()['id'],
            'branch'  => $branchHashString,
        ]);
        $this->postData = DataHelper::handleFormData($this->validator->attributes, $this->getAeForm()['id']);

        $this->event = EventEnumV2::getVal(EventEnumV2::EVENT_FORM_CONTENT_CREATE);

        Db::beginTransaction();

        // 初始表单日志信息
        $this->initFormContentLog();

        if ($this->validator->attributes['ae_type'] ==  5 && !$this->validator->attributes['result_id']) {
            throw new \Application\Service\Exceptions\InvalidArgumentException('请选择AE名称。');
        }

        // 受试者新增AE, 属于新增ae - 新增ae数据
        if (in_array($this->validator->attributes['ae_type'], [0, 6])) {
            if ($this->validator->attributes['ae_type'] == 6 && $this->isPostNewAeForm() === false) {
                throw new \Application\Service\Exceptions\InvalidArgumentException('请新增AE表单。');
            }

            $contentId = Laminas::$serviceManager->itemPatientAeContent->save([
                'patient_id' => $this->validator->attributes['patient_id'] ?: $this->getCsae($this->validator->attributes['id'])['patient_id'],
                'item_id' => $this->validator->attributes['item_id'],
                'itemsig_id' => $this->validator->attributes['itemsig_id'] ?: $this->getCsae($this->validator->attributes['id'])['itemsig_id'],
                'data' => json_encode($this->postData),
                'is_del' => 0,
                'csae_id' => $this->validator->attributes['id'],
                'new_ae_list' => 0,
                'ae_type' => $this->validator->attributes['ae_type'],
                'branch' => $branchHashString,
                'form_id' => $this->getAeForm()['id'],
                'is_skip' => 0,
                'is_complete' => $this->getIsComplete($this->validator->attributes,$this->getAeForm()['id'])
            ]);

            if ($this->validator->attributes['ae_type'] == 6) {
                $this->addNewAeRelation($contentId, $branchHashString);
            } elseif ($this->validator->attributes['ae_type'] == 0 && $this->validator->attributes['patient_id']) {
                $this->addPatientNewAe($contentId, $branchHashString);
            }
            $this->logger->setContentId($contentId)->flush();
        }

        Db::commit();
        if (!empty($contentId) && in_array($this->validator->attributes['ae_type'], [0, 6])) {
            //异步处理访视进度情况信息
            $form_content_arr = isset($contentId) && !empty($contentId) ? [$contentId] : [];
            Laminas::$serviceManager->swTaskClient->send([
                'svName' => 'projectPatientworkbatch',
                'methodName' => 'multipleUpdateData',
                'params' => [
                    'item_id' => $this->validator->attributes['item_id'],
                    'itemsig_id' => $this->validator->attributes['itemsig_id'] ?: $this->getCsae($this->validator->attributes['id'])['itemsig_id'],
                    'patient_id' => $this->validator->attributes['patient_id'] ?: $this->getCsae($this->validator->attributes['id'])['patient_id'],
                    'checktime_id' => -1,
                    'form_id' => $this->getAeForm()['id'],
                    'operate_type' => 10,
                    'content_id' => !empty($form_content_arr) ? $form_content_arr : [],
                    'user_id' => Laminas::$serviceManager->identity->getId()
                ]
            ]);
        }
        unset($form_content_arr);

    }

    /**
     * Notes:AE表单完整性判断
     * @param
     * @return
     * @author haojinhua
     * @date 2025-04-07
     */
    public function getIsComplete(array $postData,int $formId = null): bool
    {
        $helper = SDMHelper::app()->setAttributes(['form_id' => $formId])->form;
        $versionData = $helper->getVersionData();
        $finish_condition = $helper->getFinishCondition($formId);
        $skipField = 0;

        foreach ($postData as $k => $v) {
            $new_key = explode('-', $k)[0];
            // 排除掉id等其他参数
            if (!isset($versionData[$new_key])) {
                $skipField++;
                continue;
            }

            // 对传过来空图片数据做处理
            if ($v == '[]') {
                $v = '';
            } elseif ($v === 'null') {
                $v = null;
            }

            if (is_array($v)) {
                // 防止notice错误, 有多维的数组和一维的, 还有空数组
                $v = $v ? json_encode($v) : implode(',', $v);
            }

            if (trim($v)) {
                // 表单完成条件为任意一个
                if ($finish_condition == Form::FORM_FINISH_CONDITION_ANYONE) {
                    return true;
                }
            } else {
                $skipField++;

                if (!$v) {
                    return false;
                }
            }
        }

        if (count($postData) == $skipField) {
            return false;
        }

        return true;
    }

    /**
     * 新增ae - 新增一条新的数据
     * @param int $contentId
     * @param $branchHash
     */
    private function addNewAeRelation(int $contentId, string $branchHash = '')
    {
        Laminas::$serviceManager->itemCsaeRelation->insert([
            'csae_id' => $this->validator->attributes['id'],
            'new_ae_list_id' => 0,
            'content_id' => $contentId,
            'patient_id' => $this->validator->attributes['patient_id'],
            'branch' => $branchHash
        ]);
    }

    /**
     * ae列表 - 新增受试者ae
     * @param int $contentId
     */
    private function addPatientNewAe(int $contentId, string $branch)
    {
        Laminas::$serviceManager->itemCsaeRelation->insert([
            'csae_id' => 0,
            'new_ae_list_id' => 0,
            'content_id' => $contentId,
            'patient_id' => $this->validator->attributes['patient_id'],
            'branch' => $branch
        ]);
    }

    /**
     * 编辑 - AE判断结果 - 属于新增ae
     * @throws Exception
     */
    public function editNewAeV2()
    {
        $relationData = Laminas::$serviceManager->itemCsaeRelation->fetchOne([
            'where' => ['content_id' => $this->validator->attributes['result_id']]
        ]);

        // 修改之前的数据
        $oldData = Laminas::$serviceManager->itemPatientAeContent->getOneFieldVal('data',"id = {$this->validator->attributes['result_id']}");

        // 补充本次提交的数据，
        $this->validator->setAttributes([
            'form_id' => $this->getAeForm()['id'],
            'branch'  => $relationData['branch'] ?? Json::decode($oldData, Json::TYPE_ARRAY)['branch'],
        ]);

        $this->postData = $newData = DataHelper::handleFormData($this->validator->attributes, $this->getAeForm()['id']);
        $this->event = EventEnumV2::getVal(EventEnumV2::EVENT_FORM_CONTENT_EDIT);

        $this->postOriginData = ArrayUtils::merge($this->postData, [
            'old_data_str' => $oldData,
        ]);


        $reason = $this->validator->attributes['reason'];
        if(!empty($reason)){
            $reason_res = [];
            $reason_datas = json_decode($reason,true);
            foreach ($reason_datas as $reason_data){
                $reason_res[] = [
                    'filed_id'=>$reason_data['filed_id'],
                    'modify_reason'=>$reason_data['modify_reason'],
                ];
            }
            unset($reason_datas);
            $reason = json_encode($reason_res,true);
        }
       //$this->validator->attributes['note'] = $reason;
        unset($this->validator->attributes['reason']);
        $this->postData['note'] =  $reason;

        Db::beginTransaction();

        // 初始表单日志
        $this->initFormContentLog();

        $contentId = $delContentId = 0;
        if ($this->validator->attributes['ae_type'] == 5) {
            if (!$this->validator->attributes['result_id']) {
                throw new \Application\Service\Exceptions\InvalidArgumentException('请选择AE名称。');
            }
            $contentId = $this->editIsHasAe($relationData,$newData,$oldData);
        } elseif ($this->validator->attributes['ae_type'] == 6) {
            //已有AE

            if ($this->isPostNewAeForm() === false) {
                throw new \Application\Service\Exceptions\InvalidArgumentException('请新增AE表单。');
            }
            $delContentId = $this->validator->attributes['result_id'];
            $contentId = Laminas::$serviceManager->itemPatientAeContent->insert([
                'data' => json_encode($this->postData),
                'patient_id' => $this->validator->attributes['patient_id'],
                'item_id' => $this->validator->attributes['item_id'],
                'branch' => $relationData['branch'],
                'csae_id' => $this->validator->attributes['csae_id'],
                'itemsig_id' => $this->validator->attributes['itemsig_id'],
                'ae_type' => $this->validator->attributes['ae_type'],
                'new_ae_list' => $this->validator->attributes['new_ae_list'] ? 0 : $this->validator->attributes['csae_id'],
                'is_skip' => 0,
                'form_id' => $this->getAeForm()['id'],
                'is_complete' => $this->getIsComplete($this->validator->attributes,$this->getAeForm()['id'])
            ]);

            Laminas::$serviceManager->itemCsaeRelation->update([
                'content_id' => $contentId
            ], ['content_id' => $this->validator->attributes['result_id']]);

            Laminas::$serviceManager->itemPatientAeContent->update(['is_del' => 1], [
                'id' => $this->validator->attributes['result_id']
            ]);

            Laminas::$serviceManager->itemCsaeChecked->update([
                'content_id' => $contentId
            ], ['content_id' => $this->validator->attributes['result_id']]);

             Laminas::$serviceManager->patientFormContentUpdated->changeAeErrorId(
               $this->validator->attributes['result_id'],
               $contentId,
               $this->validator->attributes['patient_id'],
               $this->getAeForm()['id'],
               $newData,$oldData
           );
        } elseif ($this->validator->attributes['id'] == 0) {
            $delContentId = $this->validator->attributes['result_id'];
            //新增AE
            $contentId = Laminas::$serviceManager->itemPatientAeContent->insert([
                'data' => json_encode(DataHelper::handleFormData($this->validator->attributes, $this->getAeForm()['id'])),
                'patient_id' => $this->validator->attributes['patient_id'],
                'item_id' => $this->validator->attributes['item_id'],
                'csae_id' => $this->validator->attributes['csae_id'],
                'branch' => $relationData['branch'],
                'itemsig_id' => $this->validator->attributes['itemsig_id'],
                'ae_type' => $this->validator->attributes['ae_type'],
                'new_ae_list' => $this->validator->attributes['new_ae_list'] ?: $this->validator->attributes['csae_id'],
                'is_skip' => 0,
                'form_id' => $this->getAeForm()['id'],
                'is_complete' => $this->getIsComplete($this->validator->attributes,$this->getAeForm()['id'])
            ]);

            Laminas::$serviceManager->itemPatientAeContent->update([
                'is_del' => 1
            ], ['id' => $this->validator->attributes['result_id']]);

            Laminas::$serviceManager->itemCsaeRelation->update([
                'content_id' => $contentId
            ], ['content_id' => $this->validator->attributes['result_id']]);

            Laminas::$serviceManager->itemCsaeChecked->update([
                'content_id' => $contentId
            ], ['content_id' => $this->validator->attributes['result_id']]);

            Laminas::$serviceManager->patientFormContentUpdated->changeAeErrorId(
                $this->validator->attributes['result_id'],
                $contentId,
                $this->validator->attributes['patient_id'],
                $this->getAeForm()['id'],$newData,$oldData
            );

            //更新SDV、Review
        } elseif ($this->validator->attributes['id']) {
            $contentId = $this->validator->attributes['id'];
            Laminas::$serviceManager->itemPatientAeContent->update([
                'data' => json_encode(DataHelper::handleFormData($this->validator->attributes, $this->getAeForm()['id'])),
            ], ['id' => $this->validator->attributes['id']]);

            Laminas::$serviceManager->patientFormContentUpdated->changeAeErrorId(
                $this->validator->attributes['id'],
                $this->validator->attributes['id'],
                $this->validator->attributes['patient_id'],
                $this->getAeForm()['id'],$newData,$oldData
            );
        }
        $oldContentId = Laminas::$serviceManager->itemPatientAeContent->getOneFieldVal('id',[
            'branch' => $relationData['branch']
        ]);

        $this->logger->setContentId($oldContentId)->flush();

        Db::commit();
        if(!empty($delContentId) && !empty($contentId)){
            Laminas::$serviceManager->projectPatientworkinfo->update(['content_id'=>$contentId],[
                'is_del' => 0,
                'checktime_id' => -1,
                'content_id' => $delContentId,
            ]);
        }
        if(!empty($contentId)){
            //异步处理访视进度情况信息
            $form_content_arr = isset($contentId) && !empty($contentId) ? [$contentId] : [];
            Laminas::$serviceManager->swTaskClient->send([
                'svName' => 'projectPatientworkbatch',
                'methodName' => 'multipleUpdateData',
                'params' => [
                    'item_id' => $this->validator->attributes['item_id'],
                    'itemsig_id' => $this->validator->attributes['itemsig_id'],
                    'patient_id' => $this->validator->attributes['patient_id'],
                    'checktime_id' => -1,
                    'form_id' => $this->getAeForm()['id'],
                    'operate_type'=>11,
                    'content_id'=>!empty($form_content_arr) ? $form_content_arr : [],
                    'user_id' => Laminas::$serviceManager->identity->getId()
                ]
            ]);
            unset($form_content_arr);
        }
    }

    public function getIsChangeRelationAeId(): bool
    {
        $query = Laminas::$serviceManager->itemCsae->fetchOne([
            'where' => [
                'id' => $this->validator->attributes['id']
            ]
        ]);

        if ($query['relation_ae_id'] == 0 && !$this->validator->attributes['new_ae_list']) {
            return false;
        }

        if ($query && $query['relation_ae_id'] != $this->validator->attributes['new_ae_list']) {
            return true;
        }

        return false;
    }

    public function getIsChangeAeResult(): bool
    {
        if ($this->validator->attributes['id'] == 0) {
            return false;
        }
        $query = Laminas::$serviceManager->itemCsae->fetchOne([
            'where' => [
                'id' => $this->validator->attributes['id']
            ]
        ]);

        if ($query && $query['ae_type'] != $this->validator->attributes['ae_type']) {
            return true;
        }

        return false;
    }


    /**
     * 编辑 - 属于已有AE - 重新选择指标项, 或者编辑指标项数据
     */
    public function editIsHasAe($relationData,$newData,$oldData): int
    {
        // 移除旧content
        Laminas::$serviceManager->itemPatientAeContent->update(['is_del' => 1], [
            'id' => $this->validator->attributes['result_id']
        ]);

        // 插入新content
        $contentId = Laminas::$serviceManager->itemPatientAeContent->insert([
            'data' => json_encode(DataHelper::handleFormData($this->validator->attributes, $this->getAeForm()['id'])),
            'patient_id' => $this->validator->attributes['patient_id'],
            'item_id' => $this->validator->attributes['item_id'],
            'branch' => $relationData['branch'],
            'csae_id' => $this->validator->attributes['csae_id'],
            'new_ae_list' => $this->validator->attributes['new_ae_list'],
            'itemsig_id' => $this->validator->attributes['itemsig_id'],
            'form_id' => $this->getAeForm()['id'],
            'ae_type' => $this->validator->attributes['ae_type'],
        ]);

        Laminas::$serviceManager->itemCsaeChecked->update([
            'is_del' => 1,
        ], (new Where())
            ->equalTo('csae_id', $this->validator->attributes['csae_id'])
            ->notIn('new_id', [$this->validator->attributes['new_ae_list']]));

        Laminas::$serviceManager->itemCsaeChecked->insert([
            'csae_id' => $this->validator->attributes['csae_id'],
            'new_id' => $this->validator->attributes['new_ae_list'],
            'content_id' => $contentId,
            'branch' => $relationData['branch']
        ]);

        Laminas::$serviceManager->itemCsaeRelation->update([
            'content_id' => $contentId,
            'new_ae_list_id' => $this->validator->attributes['new_ae_list']
        ], ['id' => $relationData['id']]);

        Laminas::$serviceManager->itemCsae->update([
            'relation_ae_id' => $this->validator->attributes['new_ae_list'],
        ], ['id' => $this->validator->attributes['csae_id']]);

        Laminas::$serviceManager->patientFormContentUpdated->changeAeErrorId(
            $this->validator->attributes['result_id'],
            $contentId,
            $this->validator->attributes['patient_id'],
            $this->getAeForm()['id'],$newData,$oldData
        );

        return (int)$contentId;
    }

    /**
     * 移除所有勾选过的关联ae
     */
    public function removeAllCheckedByChangeAeType()
    {
    }

    private function getCsae(int $id)
    {
        return Laminas::$serviceManager->itemCsae->fetchOne([
            'where' => ['id' => $id]
        ]);
    }

    /**
     * 是否可以删除
     */
    private function canDeleteNewAe(int $id)
    {
        return !(bool)Laminas::$serviceManager->itemCsaeChecked->fetchOne([
            'where' => ['new_id' => $id, 'is_del' => 0]
        ]);
    }

    /**
     * 判断能否修改ae状态
     * @return bool
     */
    public function canChangeAeResult()
    {
        $query = Laminas::$serviceManager->itemCsae->fetchOne([
            'where' => [
                'id' => $this->validator->attributes['id']
            ]
        ]);

        if ($query && ($query['ae_type'] == 6 && $this->validator->attributes['ae_type'] == 5)) {
            throw new \Application\Service\Exceptions\InvalidArgumentException('新增ae不能修改成已有ae');
        }

        return true;
    }

    public function rollbackContent()
    {
        if ($this->validator->attributes['id'] !== null) {
            // 新增ae切走, 要把原来的指标删除掉
            if ($this->getCsae($this->validator->attributes['id'])['ae_type'] == 6) {
                Laminas::$serviceManager->itemCsaeRelation->update(['is_del' => 1], [
                    'csae_id' => $this->validator->attributes['id']
                ]);

                return;
            }

            // 所有勾选中的指标
            $originCheckedData = Laminas::$serviceManager->itemCsaeChecked->fetchAll([
                'where' => ['csae_id' => $this->validator->attributes['id'], 'is_del' => 0, new IsNotNull('branch')]
            ]);

            $rollbackData = [];
            foreach ($originCheckedData as $item) {
                // 设置skip
                Laminas::$serviceManager->itemPatientAeContent->update(['is_skip' => 1, 'is_del' => 1], [
                    'csae_id' => $this->validator->attributes['id'],
                    'new_ae_list' => $item['new_id'],
                    'branch' => $item['branch']
                ]);
                $rollbackData[] = $item;
            }

            foreach ($rollbackData as $value) {
                $lastNode = $this->getLastNode($value['new_id'], $value['branch']);
                Laminas::$serviceManager->itemCsaeRelation->update([
                    'content_id' => $lastNode
                ], ['csae_id' => $value['new_id'], 'branch' => $value['branch']]);
            }
        }
    }

    public function rollbackIsHasAe()
    {
        // 所有勾选中的指标
        $originCheckedData = Laminas::$serviceManager->itemCsaeChecked->fetchOne([
            'where' => ['is_del' => 0, 'csae_id' => $this->validator->attributes['csae_id'], 'content_id' => $this->validator->attributes['content_id']]
        ]) ?: [];

        Laminas::$serviceManager->itemCsaeChecked->update([
            'is_del' => 1
        ], ['id' => $originCheckedData['id']]);

        if ($_POST['delete_all'] == 1) {
            $branch = Laminas::$serviceManager->itemPatientAeContent->fetchOne([
                'where' => ['id' => $this->validator->attributes['content_id']]
            ])['branch'];

            Laminas::$serviceManager->itemCsaeRelation->update([
                'is_del' => 1
            ], ['branch' => $branch]);
        }
    }

    protected function getLastNode($csaeId, string $branch)
    {
        $lastNode = Laminas::$serviceManager->itemPatientAeContent->fetchOne([
            'order' => 'id DESC',
            'where' => ['new_ae_list' => $csaeId, 'is_skip' => 0, 'branch' => $branch]
        ])['id'] ?? false;

        if (!$lastNode) {
            $lastNode = Laminas::$serviceManager->itemPatientAeContent->fetchOne([
                'order' => 'id DESC',
                'where' => ['csae_id' => $csaeId, 'is_skip' => 0, 'branch' => $branch]
            ])['id'] ?? false;
        }

        if (!$lastNode) {
            throw new \Application\Service\Exceptions\InvalidArgumentException('没找到要回滚的id');
        }

        return $lastNode;
    }
    /**
     * 渲染ae表单结构
     * @return mixed
     * @throws Exception
     */
    public function renderNewAeTable($showAll = false)
    {

        if (!$aeForm = $this->getAeForm()) {
            throw new InvalidArgumentException("没有AE表单呀~~");
        }

        $config = Laminas::$serviceManager->itemForm;
        if (isset($_POST['ae_type']) && $_POST['ae_type'] == 2) {
            $config->setPreviewScenario('CM_LIST_VIEW');
        }

        $config = $config->getPreviewConfig($aeForm['id']);
        if ($showAll === true) {
            $prop = '111-222-333';
            $config['table'] = ArrayHelper::merge([['prop' => $prop, 'label' => '受试者编号']], $config['table']);
        }

        return ArrayHelper::merge($config, [
            'type' => "0",
            'show_type' => $aeForm['show_type'] ?: 'right',
        ]);
    }

    public function view()
    {
        if ($this->validator->attributes['ae_type'] == 6) {
            return Laminas::$serviceManager->itemPatientAeContent->fetchAllWithPagination([
                'where' => [
                    'csae_id' => $this->validator->attributes['csae_id'],
                    'is_del' => 0
                ]
            ]);
        }
    }

    public function delAeLog($id,$data)
    {
        $this->postData = DataHelper::handleFormData($this->validator->attributes, $this->getAeForm()['id']);

        $this->postData['form_id'] = $data['form_id'];

        $this->event = EventEnumV2::getVal(EventEnumV2::EVENT_FORM_CONTENT_DELETE);

        $this->initFormContentLog();

        $this->postOriginData = ArrayUtils::merge($this->postData, [
            'old_data_str' => $data,
        ]);

        $this->logger->setContentId($id)->flush();
    }
}
