package com.qmth.distributed.print.api;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qmth.boot.api.annotation.Aac;
import com.qmth.boot.api.annotation.BOOL;
import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.distributed.print.business.bean.dto.CardRuleDto;
import com.qmth.distributed.print.business.entity.BasicCardRule;
import com.qmth.distributed.print.business.service.BasicCardRuleService;
import com.qmth.teachcloud.common.contant.SystemConstant;
import com.qmth.teachcloud.common.util.Result;
import com.qmth.teachcloud.common.util.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.List;

/**
 * <p>
 * 题卡规则 前端控制器
 * </p>
 *
 * @author xf
 * @since 2021-03-23
 */
@Api(tags = "题卡规则Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/${prefix.url.basic}/card_rule")
@Validated
public class BasicCardRuleController {

    @Autowired
    private BasicCardRuleService basicCardRuleService;

    /**
     * 查询
     *
     * @param enable
     * @param name
     * @param createStartTime
     * @param createEndTime
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "查询")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public Result list(@RequestParam(value = "enable", required = false) Boolean enable,
                       @RequestParam(value = "name", required = false) String name,
                       @RequestParam(value = "createStartTime", required = false) Long createStartTime,
                       @RequestParam(value = "createEndTime", required = false) Long createEndTime,
                       @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
                       @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
        IPage<CardRuleDto> cardRuleDtoIPage = basicCardRuleService.list(enable, name, createStartTime, createEndTime, pageNumber, pageSize);
        return ResultUtil.ok(cardRuleDtoIPage);
    }

    /**
     * 模糊查询
     *
     * @param param
     * @return
     */
    @ApiOperation(value = "模糊查询")
    @RequestMapping(value = "/query", method = RequestMethod.POST)
    public Result list(@RequestParam(value = "param", required = false) String param) {
        List<BasicCardRule> cardRules = basicCardRuleService.list(param);
        return ResultUtil.ok(cardRules);
    }

    /**
     * 查询单个
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "查询单个")
    @RequestMapping(value = "/get_one", method = RequestMethod.POST)
    public Result getOne(@RequestParam(value = "id", required = true) Long id) {
        BasicCardRule cardRule = basicCardRuleService.getById(id);
        return ResultUtil.ok(cardRule);
    }

    /**
     * 新增/修改
     *
     * @param cardRule
     * @return
     */
    @ApiOperation(value = "新增/修改")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result save(@RequestBody BasicCardRule cardRule) {
        boolean isSuccess = basicCardRuleService.saveCardRule(cardRule);
        return ResultUtil.ok(isSuccess);
    }

    /**
     * 启用/禁用
     *
     * @param cardRule
     * @return
     */
    @ApiOperation(value = "启用/禁用")
    @RequestMapping(value = "/enable", method = RequestMethod.POST)
    public Result enable(@RequestBody BasicCardRule cardRule) {
        boolean isSuccess = basicCardRuleService.enable(cardRule);
        return ResultUtil.ok(isSuccess);
    }
}

