package com.vote.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.vctgo.common.core.web.domain.AjaxResult;
import com.vote.system.domain.VoteSubmission;
import com.vote.system.domain.dto.VoteSubmissionDto;
import com.vote.system.domain.dto.VoteSubmissionItemDto;
import com.vote.system.domain.vo.VoteSubmissionVo;
import com.vote.system.service.VoteSubmissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author feng
 * @date 2024/8/20
 */
@RestController
@RequestMapping("/subMission")
public class VoteSubmissionController {

    @Autowired
    private VoteSubmissionService voteSubmissionService;


    /**
     * 分页查询 参赛作品
     *
     * @param voteSubmissionDto
     * @return
     */
    @GetMapping("/page")
    public AjaxResult selectPage(VoteSubmissionDto voteSubmissionDto) {
        IPage<VoteSubmissionVo> page = voteSubmissionService.selectPage(voteSubmissionDto);
        return AjaxResult.success(page);
    }


    /**
     * 修改作品状态
     *
     * @param voteSubmission
     * @return
     */
    @PutMapping("/edit")
    public AjaxResult editStatus(@RequestBody VoteSubmission voteSubmission) {
        return AjaxResult.success(voteSubmissionService.updateById(voteSubmission));
    }


    /**
     * 查询作品详情
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public AjaxResult selectById(@PathVariable Long id) {
        VoteSubmissionVo voteSubmission = voteSubmissionService.selectById(id);
        return AjaxResult.success(voteSubmission);
    }

    /**
     * 评选结果 (评选轮) 分页查询
     */
    @GetMapping("/result")
    public AjaxResult getResult(VoteSubmissionDto voteSubmissionDto) {
        IPage<VoteSubmissionVo> page = voteSubmissionService.getResult(voteSubmissionDto);
        return AjaxResult.success(page);
    }

    /**
     * 评选结果 (评选轮) 全部作品类型统计
     */
    @GetMapping("/all")
    public AjaxResult getAllSubmissionCount(VoteSubmissionDto voteSubmissionDto) {
        return AjaxResult.success(voteSubmissionService.getAllSubmissionCount(voteSubmissionDto));
    }

    /**
     * 晋级
     */
    @PutMapping("/promote")
    public AjaxResult promote(@RequestBody VoteSubmissionDto voteSubmissionDto) {
        return AjaxResult.success(voteSubmissionService.promote(voteSubmissionDto));
    }

    /**
     * 修改评分项回显
     *
     * @param voteSubmissionDto
     * @return
     */
    @GetMapping("/getSubmissionItem")
    public AjaxResult getSubmissionItem(VoteSubmissionDto voteSubmissionDto) {
        return AjaxResult.success(voteSubmissionService.getSubmissionItem(voteSubmissionDto));
    }

    /**
     * 修改
     * @param voteSubmissionDto
     * @return
     */
    @PutMapping("/editItem")
    public AjaxResult editItem(@RequestBody VoteSubmissionItemDto voteSubmissionDto) {
        return AjaxResult.success(voteSubmissionService.editItem(voteSubmissionDto));
    }


    /**
     * 评选结果 (评奖轮) 类型统计
     */
    @GetMapping("/allAward")
    public AjaxResult getAllAwardCount(VoteSubmissionDto voteSubmissionDto) {
        return AjaxResult.success(voteSubmissionService.getAllAwardCount(voteSubmissionDto));
    }


    /**
     * 评选结果 (评奖轮) 分页查询
     */
    @GetMapping("/resultAward")
    public AjaxResult getResultAward(VoteSubmissionDto voteSubmissionDto) {
        IPage<VoteSubmissionVo> page = voteSubmissionService.getResultAward(voteSubmissionDto);
        return AjaxResult.success(page);
    }


    /**
     * 奖项名回显
     */
    @GetMapping("/awardShow")
    public AjaxResult awardShow(VoteSubmissionDto voteSubmissionDto) {
        return AjaxResult.success(voteSubmissionService.awardShow(voteSubmissionDto));
    }

    /**
     * 评奖
     */
    @PutMapping("/distribute")
    public AjaxResult distribute(@RequestBody VoteSubmissionDto voteSubmissionDto) {
        return AjaxResult.success(voteSubmissionService.distribute(voteSubmissionDto));
    }
}
