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

namespace app\api\controller\v1;

//牵头单位

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

class QianTou
{
    public function getTaskBaseInfo()
    {
        $data = [
            'task_id' => request()->param('task_id', '', 'int'),
        ];
        $result = (new QianTouBus())->getTaskBaseInfo($data);
        return showSuccess($result);

    }


    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 =(new QianTouBus())->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','','int'),
            ];
        //todo validate
        $result = (new QianTouBus())->getTaskInfo($data);
        return showSuccess($result);
    }

    public function qtRelease()
    {
        $task_id = request()->param('task_id', '', 'int');

        $result = (new QianTouBus())->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);
    }

    public function createUnderTaker()
    {
        $data = [
            'task_id' => request()->param('task_id','','int'),
            'bear_id' => request()->param('bear_id','','int'),//抽样机构
            'check_id' => request()->param('check_id','','int'),//检测机构
            'report_id' => request()->param('report_id','','int'),//报告上传单位
            'address' => request()->param('address','','trim'),//抽样地址
            'upload_time' => request()->param('uploadtime'),//报告上传时间
            'sample_number' => request()->param('sample_number'),//样本数量
        ];
        $result = (new ChengDanBus())->createUnderTakerInfo($data);
        return showSuccess($result);
    }

    public function deleteUnderTaskList()
    {
        $del_arr = request()->param('delarr', '', 'trim');
        $result = (new ChengDanBus())->deleteUnderTaker($del_arr);
        return showSuccess($result);
    }

    public function getUndertakeList()
    {
        $data = [
            'task_id' => request()->param('task_id', '', 'int'),
            'pageNum' => request()->param('pageNum', '1', 'int'),
            'pageSize' => request()->param('pageSize', '', 'int'),
        ];
        $result = (new QianTouBus())->getUndertakeList($data);
        return showSuccess($result);
    }
}