package cn.cecep.talroad.controller.effective;

import cn.cecep.talroad.common.core.utils.poi.ExcelUtil;
import cn.cecep.talroad.common.core.web.domain.AjaxResults;
import cn.cecep.talroad.common.log.annotation.Log;
import cn.cecep.talroad.common.log.enums.BusinessType;
import cn.cecep.talroad.domain.effective.MAiControlDelayAssessment;
import cn.cecep.talroad.service.effective.MAiControlDelayAssessmentService;
import cn.cecep.talroad.vo.query.effective.MAiControlDelayAssessmentQuery;
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 javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("controlAssessment")
@Api(tags = "管控延时评估")
public class MAiControlDelayAssessmentController {

    @Autowired
    private MAiControlDelayAssessmentService service;

    @GetMapping("list")
    @ApiOperation("获取列表")
    public AjaxResults<IPage<MAiControlDelayAssessment>> getList(MAiControlDelayAssessmentQuery query){
        Page<MAiControlDelayAssessment> page=new Page<>(query.getPageNum(),query.getPageSize());
        return AjaxResults.success( service.page(page, MAiControlDelayAssessmentQuery.createLambdaQueryWrapper(query)));
    }
    @ApiOperation(value = "导出管控延时评估列表")
    @Log(title = "导出管控延时评估列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody MAiControlDelayAssessmentQuery query) {
        query.setPageSize(Integer.MAX_VALUE);
        List<MAiControlDelayAssessment> list = service.list(MAiControlDelayAssessmentQuery.createLambdaQueryWrapper(query));
        ExcelUtil<MAiControlDelayAssessment> util = new ExcelUtil<>(MAiControlDelayAssessment.class);
        util.exportExcel(response, list, "管控延时评估列表");
    }
    @GetMapping("/factoryList")
    @ApiOperation("获取企业名字列表")
    public AjaxResults<List<Object>> getFactoryList(MAiControlDelayAssessmentQuery query){
        QueryWrapper<MAiControlDelayAssessment> wrapper = MAiControlDelayAssessmentQuery.createLambdaQueryWrapper(query).select(query.getSelectName()).groupBy(query.getSelectName());
        return AjaxResults.success( service.listObjs(wrapper));
    }
    @GetMapping("/map")
    @ApiOperation("获取map列表")
    public AjaxResults<Map<String,Object>> getMap(MAiControlDelayAssessmentQuery query){
        return AjaxResults.success(service.getMapService(query));
    }
}
