package com.qmth.paper.library.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.paper.library.common.bean.result.TaskListResult;
import com.qmth.paper.library.common.contant.ApiPrefixConstant;
import com.qmth.paper.library.common.contant.SystemConstant;
import com.qmth.paper.library.common.enums.TaskResultEnum;
import com.qmth.paper.library.common.enums.TaskStatusEnum;
import com.qmth.paper.library.common.enums.TaskTypeEnum;
import com.qmth.paper.library.common.service.TBTaskService;
import com.qmth.paper.library.common.util.Result;
import com.qmth.paper.library.common.util.ResultUtil;
import io.swagger.annotations.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

/**
 * <p>
 * 导入导出任务表 前端控制器
 * </p>
 *
 * @author wangliang
 * @since 2021-03-19
 */
@Api(tags = "数据管理-任务管理Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + ApiPrefixConstant.PREFIX_DATA)
@Validated
public class TBTaskController {
    @Resource
    TBTaskService tbTaskService;

    @ApiOperation(value = "任务管理查询接口")
    @PostMapping("/t_b_task/query")
    @ApiResponses({@ApiResponse(code = 200, message = "任务管理列表信息", response = TaskListResult.class)})
    public Result taskQuery(@ApiParam(value = "任务状态") @RequestParam(required = false) TaskStatusEnum status,
                            @ApiParam(value = "任务类型") @RequestParam(required = false) TaskTypeEnum type,
                            @ApiParam(value = "任务数据结果") @RequestParam(required = false) TaskResultEnum result,
                            @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
                            @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
        IPage<TaskListResult> taskListResultIPage = tbTaskService.query(new Page<>(pageNumber, pageSize), status, type, result);
        return ResultUtil.ok(taskListResultIPage);
    }
}
