<?php

namespace app\controller\admin\system;

use app\BaseController;
use app\entity\SysRequestRecord;
use app\service\CurdService;
use think\response\Json;

class RequestRecordController extends BaseController
{
    /**
     * 分页查询请求日志记录
     * @return Json
     */
    public function page(): Json
    {
        ini_set('memory_limit', '512M');
        try {
            /*
             * 这里有两个字段数据太大，提到详情里面做查询
             */
            $model = SysRequestRecord::withoutField('request_headers,response_data')->withSearch(['createTime', 'contextId'], [
                'createTime' => [
                    $this->request->get('createTimeStart/s', ''),
                    $this->request->get('createTimeEnd/s', '')
                ],
                'contextId' => $this->request->get('contextId/s','')
            ]);
            $paginate = CurdService::getPaginate($this->request, $model);
        } catch (\Exception $e) {
            return $this->writeError($e->getMessage());
        }
        return $this->writeSuccess('ok', $paginate);
    }

    public function info(): Json
    {
        ini_set('memory_limit', '512M');
        $id = $this->request->get('id');
        $data = SysRequestRecord::find($id);
        return $this->writeSuccess('ok', $data);
    }
}