package com.qmth.themis.admin.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qmth.themis.business.constant.SystemConstant;
import com.qmth.themis.business.dto.response.TBTaskDto;
import com.qmth.themis.business.entity.TBUser;
import com.qmth.themis.business.enums.TaskStatusEnum;
import com.qmth.themis.business.enums.TaskTypeEnum;
import com.qmth.themis.business.service.TBTaskHistoryService;
import com.qmth.themis.business.util.ServletUtil;
import com.qmth.themis.common.util.Result;
import com.qmth.themis.common.util.ResultUtil;
import io.swagger.annotations.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
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;

/**
 * @Description: 任务 前端控制器
 * @Param:
 * @return:
 * @Author: wangliang
 * @Date: 2020/6/25
 */
@Api(tags = "任务Controller")
@RestController
@RequestMapping(SystemConstant.PREFIX_URL_ADMIN + "/task")
@Validated
public class TBTaskHistoryController {

	@Resource
	TBTaskHistoryService tbTaskHistoryService;

	@ApiOperation(value = "任务查询接口")
	@RequestMapping(value = "/query", method = RequestMethod.POST)
	@ApiResponses({ @ApiResponse(code = 200, message = "任务信息", response = TBTaskDto.class) })
	public Result query(@ApiParam(value = "任务id", required = false) @RequestParam(required = false) Long id,
			@ApiParam(value = "考试批次id", required = false) @RequestParam(required = false) Long examId,
			@ApiParam(value = "业务对象id", required = false) @RequestParam(required = false) Long entityId,
			@ApiParam(value = "任务类型", required = false) @RequestParam(required = false) TaskTypeEnum type,
			@ApiParam(value = "任务状态", required = false) @RequestParam(required = false) TaskStatusEnum status,
			@ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) int pageNumber,
			@ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) int pageSize) {
		TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
		return ResultUtil.ok(tbTaskHistoryService.taskQuery(new Page<>(pageNumber, pageSize), id, entityId, type,
				status, tbUser.getOrgId(),examId));
	}
}
