<?php
/**
 *
 *User:Administrator
 *Date:2021/10/12
 */

namespace app\api\controller\v1;

//牵头单位

use app\api\business\OrganizerTaskBus;
use app\api\business\TestUnitBus;
use app\api\validate\TaskValidate;
use think\exception\ValidateException;

class QianTou
{
    private $OrganizerTaskBus;

    public function __construct()
    {
        $this->OrganizerTaskBus = new OrganizerTaskBus();
    }

    public function selectQtTaskList()
    {
        $data=[
            'year'=>request()->param('year','','trim'),//年度
            'ispublic'=>request()->param('ispublic','','trim'),//任务状态：0：未发布，1：执行中，2：已结束未完成，3：已结束已完成
            'starttime' => request()->param('starttime','','trim'),//任务开始时间
            'endtime' => request()->param('endtime','','trim'),//任务结束时间
            'task_name' => request()->param('task_name','','trim'),//任务名称
            'task_class'=>request()->param('task_class','','trim'),//任务类型：例行监测，专项监测
            'pageNum' => request()->param('pageNum', 1, 'int'),
            'pageSize' => request()->param('pageSize',10, 'int'),
        ];
        try {
            validate(TaskValidate::class)->scene('selectQtTaskList')->check($data);
        } catch (ValidateException $exception) {
            return showError($exception->getError());
        }
        $result =$this->OrganizerTaskBus->selectTaskList($data);
        return showSuccess($result);
    }

    public function getTaskInfo()
    {
        $data = [
            'pageNum' => request()->param('pageNum', 1, 'int'),
            'pageSize' => request()->param('pageSize',null, 'int'),
            'task_id' => request()->param('task_id'),
        ];
        try {
            validate(TaskValidate::class)->scene('getTaskInfo')->check($data);
        } catch (ValidateException $exception) {
            return showError($exception->getError());
        }

        $result = $this->OrganizerTaskBus->getTaskInfo($data);
        return showSuccess($result);
    }

    public function qtRelease()
    {
        $task_id = request()->param('task_id', '', 'int');
        try {
            validate(TaskValidate::class)->scene('qtRelease')->check($task_id);
        } catch (ValidateException $exception) {
            return showError($exception->getError());
        }
        $result = $this->OrganizerTaskBus->releaseTask($task_id);
        return showSuccess($result);
    }


    public function getTestUnitList()
    {
        $data=[
            'name' => request()->param('name','','trim'),
            'group_type' => request()->param('groupname', '检测机构', 'trim'),//todo 这里看以后的数据安排，先默认显示检测机构的分组 validate//在jcdw表中的groupname
            'pageNum' => request()->param('pageNum', 1, 'int'),
            'pageSize' => request()->param('pageSize', 10, 'int'),
        ];
        try {
            validate(TaskValidate::class)->scene('getTestUnitList')->check($data);
        } catch (ValidateException $exception) {
            return showError($exception->getError());
        }
        $result = (new TestUnitBus())->selectTestUnit($data);
        return showSuccess($result);
    }
}