package com.qmth.sop.server.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qmth.boot.api.annotation.Aac;
import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.sop.business.entity.SysDingDate;
import com.qmth.sop.business.service.SysDingDateService;
import com.qmth.sop.common.contant.SystemConstant;
import com.qmth.sop.common.util.Result;
import com.qmth.sop.common.util.ResultUtil;
import io.swagger.annotations.*;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

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

/**
 * 考勤特殊日期 控制器
 *
 * @author: shudonghui
 * @date: 2023-08-15 10:03:13
 * @version: 1.0
 * @email: shudonghui@qmth.com.cn
 * @Company: www.qmth.com.cn
 */
@Api(tags = "考勤特殊日期 Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/sys/ding/date")
public class SysDingDateController {


    @Resource
    SysDingDateService sysDingDateService;

    @Aac(auth = false)
    @ApiOperation(value = "考勤特殊日期查询接口")
    @RequestMapping(value = "/query", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "考勤特殊日期查询结果", response = SysDingDate.class)})
    public Result query(
            @ApiParam(value = "模糊查询条件", required = false) @RequestParam(required = false) String query,
            @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<SysDingDate> resultIPage = sysDingDateService.query(new Page<>(pageNumber, pageSize), query);

        return ResultUtil.ok(resultIPage);
    }

    @Aac(auth = false)
    @ApiOperation(value = "考勤特殊日期新增修改接口")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = Object.class)})
    public Result save(@Valid @ApiParam(value = "考勤特殊日期信息", required = true) @RequestBody(required = true) SysDingDate sysDingDate, BindingResult bindingResult) throws InterruptedException {
        if (bindingResult.hasErrors()) {
            return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        return ResultUtil.ok(sysDingDateService.saveSysDingDate(sysDingDate));
    }


    @Aac(auth = false)
    @ApiOperation(value = "考勤特殊日期删除接口")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = Object.class)})
    public Result delete(@ApiParam(value = "考勤特殊日期id", required = true) @RequestParam(required = true) long id) {
        return ResultUtil.ok(sysDingDateService.delete(id));
    }


    @Aac(auth = false)
    @ApiOperation(value = "考勤特殊日期获取单个接口")
    @RequestMapping(value = "/get", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "考勤特殊日期信息", response = SysDingDate.class)})
    public Result get(@ApiParam(value = "考勤特殊日期id", required = true) @RequestParam long id) {
        return ResultUtil.ok(sysDingDateService.getById(id));
    }


}