package com.zd.exam.controller;

import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.zd.common.core.domain.R;
import com.zd.common.core.domain.per.PerFun;
import com.zd.common.core.domain.per.PerPrefix;
import com.zd.common.core.utils.poi.ExcelUtil;
import com.zd.common.core.web.controller.BaseController;
import com.zd.common.core.web.domain.AjaxResult;
import com.zd.common.core.web.page.TableDataInfo;
import com.zd.common.log.annotation.Log;
import com.zd.common.log.enums.BusinessType;
import com.zd.common.security.annotation.PreAuthorize;
import com.zd.common.swagger.config.Knife4jConfiguration;
import com.zd.exam.domain.ElScoreRewardconfig;
import com.zd.exam.service.IElScoreRewardconfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * 奖励分设置Controller
 *
 * @author zd
 * @date 2021-12-14
 */
@RestController
@Api(tags = "【奖励分设置】")
//作者手动加入 ，在接口上加作者@ApiOperationSupport(author = "XXX")
@ApiSupport(author = Knife4jConfiguration.Author.CYL)
@RequestMapping("/rewardconfig")
public class ElScoreRewardconfigController extends BaseController
{
    @Autowired
    private IElScoreRewardconfigService elScoreRewardconfigService;

    /**
     * 查询奖励分设置列表  "exam:rewardconfig:list"
     */
    @PreAuthorize(hasPermi = PerPrefix.EXAM_REWARDCONFIG+ PerFun.LIST)
    @GetMapping("/list")
    @ApiOperation(value = "查询奖励分设置列表 " ,notes="权限字符："+PerPrefix.EXAM_REWARDCONFIG+ PerFun.LIST)
    public R list()
    {
//        startPage();
        List<ElScoreRewardconfig> list = elScoreRewardconfigService.selectElScoreRewardconfigList(null);
        return R.ok(list);
    }

    /**
     * 导出奖励分设置列表  "exam:rewardconfig:export"
     */
    @ApiOperation(value = "导出奖励分设置列表" ,notes="权限字符："+PerPrefix.EXAM_REWARDCONFIG+ PerFun.EXPORT)
    @PreAuthorize(hasPermi =PerPrefix.EXAM_REWARDCONFIG+ PerFun.EXPORT)
    @Log(title = "奖励分设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ElScoreRewardconfig elScoreRewardconfig) throws IOException
    {
        List<ElScoreRewardconfig> list = elScoreRewardconfigService.selectElScoreRewardconfigList(elScoreRewardconfig);
        ExcelUtil<ElScoreRewardconfig> util = new ExcelUtil<ElScoreRewardconfig>(ElScoreRewardconfig.class);
        util.exportExcel(response, list, "奖励分设置数据");
    }

    /**
     * 获取奖励分设置详细信息  "exam:rewardconfig:query"
     */
    @ApiOperation(value = "获取奖励分设置详细信息",notes="权限字符："+PerPrefix.EXAM_REWARDCONFIG+ PerFun.QUERY)
    @PreAuthorize(hasPermi =PerPrefix.EXAM_REWARDCONFIG+ PerFun.QUERY)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(elScoreRewardconfigService.selectElScoreRewardconfigById(id));
    }

    /**
     * 新增奖励分设置  "exam:rewardconfig:add"
     */
    @ApiOperation(value = "新增奖励分设置" ,notes="权限字符："+PerPrefix.EXAM_REWARDCONFIG+ PerFun.ADD)
    @PreAuthorize(hasPermi =PerPrefix.EXAM_REWARDCONFIG+ PerFun.ADD)
    @Log(title = "奖励分设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ElScoreRewardconfig elScoreRewardconfig)
    {
        return toAjax(elScoreRewardconfigService.insertElScoreRewardconfig(elScoreRewardconfig));
    }

    /**
     * 修改奖励分设置 "exam:rewardconfig:edit"
     */
    @ApiOperation(value = "修改奖励分设置",notes="权限字符："+PerPrefix.EXAM_REWARDCONFIG+ PerFun.EDIT)
    @PreAuthorize(hasPermi = PerPrefix.EXAM_REWARDCONFIG+ PerFun.EDIT)
    @Log(title = "奖励分设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ElScoreRewardconfig elScoreRewardconfig)
    {
        return  toAjax(elScoreRewardconfigService.updateElScoreRewardconfig(elScoreRewardconfig));
    }

    /**
     * 删除奖励分设置 "exam:rewardconfig:remove"
     */
    @ApiOperation(value = "删除奖励分设置",notes="权限字符："+PerPrefix.EXAM_REWARDCONFIG+ PerFun.REMOVE)
    @PreAuthorize(hasPermi = PerPrefix.EXAM_REWARDCONFIG+ PerFun.REMOVE)
    @Log(title = "奖励分设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(elScoreRewardconfigService.deleteElScoreRewardconfigByIds(ids));
    }


    @PostMapping("/addloginfo")
    public R addLoginfo(@RequestBody Map map){
        return elScoreRewardconfigService.addLoginfo(map);
    }


    @RequestMapping("/getBonusPointsConfig")
    @ApiOperation(value = "查询奖励分设置列表")
    public AjaxResult getBonusPointsConfig(@RequestBody Map map)
    {
        List<ElScoreRewardconfig> list = elScoreRewardconfigService.selectElScoreRewardconfigList(null);
        return AjaxResult.success(list);
    }
}
