package com.qmth.sop.server.api;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.sop.business.bean.result.WorkTaskResult;
import com.qmth.sop.business.service.TBDelayWarnService;
import com.qmth.sop.common.contant.SystemConstant;
import com.qmth.sop.common.enums.WarnTypeEnum;
import com.qmth.sop.common.util.Result;
import com.qmth.sop.common.util.ResultUtil;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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;

/**
 * <p>
 * 我的工作台 前端控制器
 * </p>
 *
 * @author wangliang
 * @since 2023-08-24
 */
@Api(tags = "我的工作台Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_MY_WORK_BENCH)
public class MyWorkBenchController {
    private final static Logger log = LoggerFactory.getLogger(MyWorkBenchController.class);

    @Resource
    TBDelayWarnService tbDelayWarnService;

    @ApiOperation(value = "获取违规/延期预警待办接口")
    @RequestMapping(value = "/warn/list", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = WorkTaskResult.class)})
    public Result getWarnTaskList(@ApiParam(value = "用户id") @RequestParam(required = false) Long userId,
                                  @ApiParam(value = "预警类型") @RequestParam(required = false) WarnTypeEnum type,
                                  @ApiParam(value = "服务单元id") @RequestParam(required = false) Long serviceId,
                                  @ApiParam(value = "客户名称") @RequestParam(required = false) String customName,
                                  @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) {
        return ResultUtil.ok(tbDelayWarnService.getWarnTaskList(new Page<>(pageNumber, pageSize), userId, type, serviceId, customName));
    }

    @ApiOperation(value = "获取违规/延期预警待办计数接口")
    @RequestMapping(value = "/warn/list/count", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = WorkTaskResult.class)})
    public Result getWarnTaskListCount(@ApiParam(value = "用户id") @RequestParam(required = false) Long userId,
                                       @ApiParam(value = "预警类型") @RequestParam(required = false) WarnTypeEnum type,
                                       @ApiParam(value = "服务单元id") @RequestParam(required = false) Long serviceId,
                                       @ApiParam(value = "客户名称") @RequestParam(required = false) String customName) {
        return ResultUtil.ok(tbDelayWarnService.getWarnTaskListCount(userId, type, serviceId, customName));
    }
}
