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.VoteEventCompetitionZones;
import com.vote.system.domain.VoteSubmission;
import com.vote.system.domain.vo.VoteEventCompetitionZonesVo;
import com.vote.system.service.VoteEventCompetitionZonesService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author feng
 * @date 2024/8/21
 */
@Validated
@RestController
@RequestMapping("/eventCompetitionZones")
public class VoteEventCompetitionZonesController {

    @Autowired
    private VoteEventCompetitionZonesService voteEventCompetitionZonesService;


    /**
     * 分页查询 赛区列表
     *
     * @param voteEventCompetitionZones
     * @return
     */
    @GetMapping("/page")
    public AjaxResult selectByPage(VoteEventCompetitionZones voteEventCompetitionZones) {
        IPage<VoteEventCompetitionZonesVo> page = voteEventCompetitionZonesService.selectByPage(voteEventCompetitionZones);
        return AjaxResult.success(page);
    }


    /**
     * 获取各省份下的作品数量
     *
     * @param voteSubmission
     * @return
     */
    @GetMapping("/list")
    public AjaxResult list(VoteSubmission voteSubmission) {
        return AjaxResult.success(voteEventCompetitionZonesService.getSubmissionCount(voteSubmission));
    }

    /**
     * 添加赛区
     *
     * @return
     */
    @PostMapping()
    public AjaxResult add(@RequestBody @Valid VoteEventCompetitionZones voteEventCompetitionZones) {
        return AjaxResult.success(voteEventCompetitionZonesService.addZones(voteEventCompetitionZones));
    }

    /**
     * 删除赛区
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id) {
        return AjaxResult.success(voteEventCompetitionZonesService.deleteZones(id));
    }


    /**
     * 编辑
     *
     * @param voteEventCompetitionZones
     * @return
     */
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody VoteEventCompetitionZones voteEventCompetitionZones) {
        return AjaxResult.success(voteEventCompetitionZonesService.updateById(voteEventCompetitionZones));
    }

    /**
     * 专家回显
     * @param voteEventCompetitionZones
     * @return
     */
    @GetMapping("/showJudges")
    public AjaxResult showJudges(VoteEventCompetitionZones voteEventCompetitionZones) {
        return AjaxResult.success(voteEventCompetitionZonesService.showJudges(voteEventCompetitionZones));
    }

    /**
     * 分配专家
     *
     * @param voteEventCompetitionZones
     * @return
     */
    @PostMapping("/distribute")
    public AjaxResult distribute(@RequestBody VoteEventCompetitionZones voteEventCompetitionZones) {
        return AjaxResult.success(voteEventCompetitionZonesService.updateById(voteEventCompetitionZones));
    }

}
