<?php

namespace Application\Controller;

use Application\Common\StatusCode;
use Application\Form\item\LogicModel;
use Application\Form\item\patient\PatientFormModel;
use Application\Form\LogicFormModel;
use Application\Form\project\AeForm;
use Application\Form\project\LogicAeForm;
use Application\Mvc\Controller\BasicController;
use Application\Service\DB\AbstractDb;
use Application\Service\DB\Db;
use Application\Service\DB\Dictionary\FormField;
use Application\Service\DB\Dictionary\FormGroup;
use Application\Service\DB\Item\PatientFormLogicErrorQuery;
use Application\Service\DB\Item\Signatory;
use Application\Service\Extension\CheckLogic\CheckLogicApplication;
use Application\Service\Extension\CheckLogic\ExpressionGenerator;
use Application\Service\Extension\ErrorHandler;
use Application\Service\Extension\Formatter\Formatter;
use Application\Service\Extension\Formatter\LogicErrorFormatter;
use Application\Service\Extension\Helper\ArrayHelper;
use Application\Service\Extension\Helper\CurlHelper;
use Application\Service\Extension\Helper\FileHelper;
use Application\Service\Extension\Helper\StringHelper;
use Application\Service\Extension\Helper\VarDumperHelper;
use Application\Service\Extension\Laminas;
use Application\Service\Extension\Validator\ValidatorApplication;
use Laminas\Db\ResultSet\ResultSet;
use Laminas\Db\Sql\Expression;
use Laminas\Db\Sql\Predicate\IsNotNull;
use Laminas\Db\Sql\Predicate\Like;
use Laminas\Db\Sql\Predicate\Operator;
use Laminas\Db\Sql\Predicate\Predicate;
use Laminas\Db\Sql\Select;
use Laminas\Db\Sql\Sql;
use Laminas\Db\TableGateway\Feature\EventFeatureEventsInterface;
use Laminas\Mvc\Controller\AbstractActionController;

class ExposeController extends AbstractActionController // BaseController
{
   public function reportAction()
   {
       // type , content_id
       $changeId = intval($this->params()->fromPost('change_id'));
       $isCollectDate = intval($this->params()->fromPost('is_collectDate'));
       $query = Laminas::$serviceManager->itemCsae->fetchOne(['where' => ['patient_change_id' => $changeId, 'is_del' => 0, 'is_ae_sure' => 1]]);
       $type = $query['ae_type'] ?? false;
       $csaeId = $query['id'] ?? false;
       $v = new ValidatorApplication($this->params()->fromPost());
       $v->attributes['type'] = $type;
       $model = new LogicAeForm($v);

       Db::beginTransaction();
       // 属于已有ae
       if ($type == 5) {
           $model->updateAeType($csaeId);
       } if ($type == 6) { // 属于新增ae
           $model->updateAeType($csaeId);
       }

       if ($isCollectDate) {
           Laminas::$serviceManager->itemCsae->isAnnulDate($changeId);
       } else {
           Laminas::$serviceManager->itemCsae->isAnnulChecknameSaveAction($changeId);
       }

       Db::commit();
       return $this->RenderApiJson()->Success();
   }

   public function fileTimestampAction()
   {
       $directory = APP_PATH . '/' . ($this->getRequest()->getQuery('path') ?: 'module/Application');
       $files = FileHelper::getFiles($directory);

       foreach ($files as $file) {
           $fileLastModifiedTime = filemtime($file);

           $fileLastModifiedTimeFormatted = date("Y-m-d H:i:s", $fileLastModifiedTime);

           $file = strtr($file, [
               APP_PATH => ''
           ]);
           echo "{$file} [{$fileLastModifiedTimeFormatted}]" . PHP_EOL;
       }
// 输出结果
       die;
   }
}