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.BMainExceptionTaskCheck;
import cn.cecep.talroad.service.IBMainExceptionTaskCheckService;
import cn.cecep.talroad.vo.BMainExceptionTaskCheckVo;
import cn.cecep.talroad.vo.query.BMainExceptionTaskCheckQuery;
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("/exceptionTaskCheck")
public class BMainExceptionTaskCheckController extends BasesController
{
    @Autowired
    private IBMainExceptionTaskCheckService bMainExceptionTaskCheckService;

    @ApiOperation(value = "查询移动执法信息-异常任务核查")
    @GetMapping("/list")
    public AjaxResults<IPage<BMainExceptionTaskCheck>> list(BMainExceptionTaskCheckQuery bMainExceptionTaskCheck)
    {
        Page<BMainExceptionTaskCheck> page = new Page<>(bMainExceptionTaskCheck.getPageNum(), bMainExceptionTaskCheck.getPageSize());
        IPage<BMainExceptionTaskCheck> list = bMainExceptionTaskCheckService.page(page, BMainExceptionTaskCheckQuery.createLambdaQueryWrapper(bMainExceptionTaskCheck));
        return AjaxResults.success(list);
    }

    @ApiOperation(value = "获取区域下拉框数据, 汇总异常任务核查所有的区域")
    @GetMapping("/regionOptions")
    public AjaxResults<List<String>> regionOptions()
    {
        List<BMainExceptionTaskCheck> taskChecks = bMainExceptionTaskCheckService.list(new QueryWrapper<BMainExceptionTaskCheck>().select("region_name").groupBy("region_name"));
        return AjaxResults.success(taskChecks.stream().map(BMainExceptionTaskCheck::getRegionName).collect(Collectors.toList()));
    }

    @ApiOperation(value = "获取移动执法信息-异常任务核查详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResults<BMainExceptionTaskCheckVo.DetailVo> getInfo(@PathVariable("id") String id) {
        return AjaxResults.success(bMainExceptionTaskCheckService.getInfo(id));
    }
}
