package cn.cecep.talroad.controller;

import cn.cecep.talroad.common.core.web.controller.BasesController;
import cn.cecep.talroad.common.core.web.domain.AjaxResults;
import cn.cecep.talroad.domain.BMainTwoRandomTask;
import cn.cecep.talroad.service.IBMainTwoRandomTaskService;
import cn.cecep.talroad.vo.BMainTwoRandomTaskVo;
import cn.cecep.talroad.vo.query.BMainTwoRandomTaskQuery;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;


/**
 * * 开发公司：中节能天融科技有限公司
 * 移动执法信息-双随机任务Controller 控制层
 */
@Api(tags = "移动执法信息-双随机任务")
@RestController
@RequestMapping("/twoRandomTask")
public class BMainTwoRandomTaskController extends BasesController
{
    @Autowired
    private IBMainTwoRandomTaskService bMainTwoRandomTaskService;

    /**
     * 查询移动执法信息-双随机任务列表
     */
    @ApiOperation(value = "查询移动执法信息-双随机任务")
    @GetMapping("/list")
    public AjaxResults<IPage<BMainTwoRandomTask>> list(BMainTwoRandomTaskQuery bMainTwoRandomTask)
    {
        Page<BMainTwoRandomTask> page = new Page<>(bMainTwoRandomTask.getPageNum(), bMainTwoRandomTask.getPageSize());
        IPage<BMainTwoRandomTask> list = bMainTwoRandomTaskService.page(page, BMainTwoRandomTaskQuery.createLambdaQueryWrapper(bMainTwoRandomTask));
        return AjaxResults.success(list);
    }

    /**
     * 获取移动执法信息-双随机任务详细信息
     */
    @ApiOperation(value = "获取移动执法信息-双随机任务详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResults<BMainTwoRandomTaskVo> getInfo(@PathVariable("id") String id) {
        return AjaxResults.success(bMainTwoRandomTaskService.getInfo(id));
    }

    @ApiOperation(value = "获取任务类型下拉框数据")
    @GetMapping("/taskTypeOptions")
    public AjaxResults<List<String>> taskTypeOptions()
    {
        List<String> list = bMainTwoRandomTaskService.list(new QueryWrapper<BMainTwoRandomTask>().select("task_type").groupBy("task_type"))
                .stream().map(BMainTwoRandomTask::getTaskType)
                .collect(Collectors.toList());
        return AjaxResults.success(list);
    }

    @ApiOperation(value = "获取任务状态下拉框数据")
    @GetMapping("/taskStatusOptions")
    public AjaxResults<List<String>> taskStatusOptions()
    {
        List<String> list = bMainTwoRandomTaskService.list(new QueryWrapper<BMainTwoRandomTask>().select("task_status").groupBy("task_status"))
                .stream().map(BMainTwoRandomTask::getTaskStatus)
                .collect(Collectors.toList());
        return AjaxResults.success(list);
    }

}
