package com.microservices.dms.resourceLibrary.controller;

import com.microservices.common.core.utils.PageUtils;
import com.microservices.common.core.utils.poi.ExcelUtil;
import com.microservices.common.core.web.controller.BaseController;
import com.microservices.common.core.web.domain.AjaxResult;
import com.microservices.common.core.web.page.GenericsTableDataInfo;
import com.microservices.common.core.web.page.TableDataInfo;
import com.microservices.dms.resourceLibrary.domain.CompetitionResourceLibrary;
import com.microservices.dms.resourceLibrary.domain.vo.CompetitionListVo;
import com.microservices.dms.resourceLibrary.service.CompetitionResourceLibraryService;
import com.microservices.dms.resourceLibrary.domain.vo.UserActionDataVo;
import com.microservices.dms.resourceLibrary.service.TaskResourceLibraryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

import static com.microservices.common.core.utils.PageUtils.startPage;
import static com.microservices.common.core.web.domain.AjaxResult.success;

@Api(tags = "数据管理体系-竞赛资源库接口")
@RestController
@RequestMapping("/competitionResourceLibrary")
@RequiredArgsConstructor
public class CompetitionResourceLibraryController extends BaseController {

    private final TaskResourceLibraryService taskResourceLibraryService;
    private final CompetitionResourceLibraryService competitionResourceLibraryService;

    @GetMapping("/selectRegisterCondition")
    @ApiOperation(value = "查询用户报名")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemId", value = "对象ID", paramType = "query", dataTypeClass = Integer.class),
    })
    public GenericsTableDataInfo<UserActionDataVo> selectRegisterCondition(UserActionDataVo taskJournals) {
        startPage();
        List<UserActionDataVo> userActionDataVos = competitionResourceLibraryService.selectRegisterCondition(taskJournals);
        return PageUtils.toPage(userActionDataVos);
    }

    @GetMapping("/selectOpusCondition")
    @ApiOperation(value = "查询用户作品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status", value = "状态3", paramType = "query", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "itemId", value = "对象ID", paramType = "query", dataTypeClass = Integer.class),
    })
    public GenericsTableDataInfo<UserActionDataVo> selectOpusCondition(UserActionDataVo taskJournals) {
        startPage();
        List<UserActionDataVo> userActionDataVos = competitionResourceLibraryService.selectOpusCondition(taskJournals);
        return PageUtils.toPage(userActionDataVos);
    }

    @GetMapping("/selectCompetitionListCondition")
    @ApiOperation(value = "查询竞赛作品列表")
    public GenericsTableDataInfo<CompetitionListVo> selectCompetitionListCondition(CompetitionListVo taskJournals) {
        startPage();
        List<CompetitionListVo> userActionDataVos = competitionResourceLibraryService.selectCompetitionListCondition(taskJournals);
        return PageUtils.toPage(userActionDataVos);
    }

    @GetMapping("/list")
    public TableDataInfo list(CompetitionResourceLibrary competitionResourceLibrary) {
        startPage();
        List<CompetitionResourceLibrary> list = competitionResourceLibraryService.selectCompetitionResourceLibraryList(competitionResourceLibrary);
        return getDataTable(list);
    }

    @PostMapping("/export")
    public void export(HttpServletResponse response, CompetitionResourceLibrary competitionResourceLibrary) {
        List<CompetitionResourceLibrary> list = competitionResourceLibraryService.selectCompetitionResourceLibraryList(competitionResourceLibrary);
        ExcelUtil<CompetitionResourceLibrary> util = new ExcelUtil<CompetitionResourceLibrary>(CompetitionResourceLibrary.class);
        util.exportExcel(response, list, "数据");
    }

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(competitionResourceLibraryService.selectCompetitionResourceLibraryById(id));
    }

    @PostMapping
    public AjaxResult add(@RequestBody CompetitionResourceLibrary competitionResourceLibrary) {
        return success(competitionResourceLibraryService.insertCompetitionResourceLibrary(competitionResourceLibrary));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody CompetitionResourceLibrary competitionResourceLibrary) {
        return success(competitionResourceLibraryService.updateCompetitionResourceLibrary(competitionResourceLibrary));
    }

    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return success(competitionResourceLibraryService.deleteCompetitionResourceLibraryByIds(ids));
    }

    /**
     * 返回开放竞赛总数
     *
     * @return 开放竞赛总数
     */
    @ApiOperation(value = "返回开放竞赛总数")
    @GetMapping(value = "/getTotalOpenCompetitions")
    public AjaxResult getTotalOpenCompetitions() {
        // 这里替换成你的实际逻辑，例如从数据库查询
        return AjaxResult.success(competitionResourceLibraryService.getTotalOpenCompetitions());
    }

    /**
     * 返回竞赛转换成果数
     *
     * @return 竞赛转换成果数
     */
    @ApiOperation(value = "返回竞赛转换成果数")
    @GetMapping(value = "/getTotalCompetitionAchievements")
    public AjaxResult getTotalCompetitionAchievements() {
        // 这里替换成你的实际逻辑
        return AjaxResult.success(competitionResourceLibraryService.getTotalCompetitionAchievements());
    }

    /**
     * 返回竞赛提交作品数
     *
     * @return 竞赛提交作品数
     */
    @ApiOperation(value = "返回竞赛提交作品数")
    @GetMapping(value = "/getTotalCompetitionSubmissions")
    public AjaxResult getTotalCompetitionSubmissions() {
        // 这里替换成你的实际逻辑
        return AjaxResult.success(competitionResourceLibraryService.getTotalCompetitionSubmissions());
    }

    /**
     * 返回已结束竞赛数
     *
     * @return 已结束竞赛数
     */
    @ApiOperation(value = "返回已结束竞赛数")
    @GetMapping(value = "/getTotalFinishedCompetitions")
    public AjaxResult getTotalFinishedCompetitions() {
        // 这里替换成你的实际逻辑
        return AjaxResult.success(competitionResourceLibraryService.getTotalFinishedCompetitions());
    }

    /**
     * 返回需评审竞赛数
     *
     * @return 需评审竞赛数
     */
    @ApiOperation(value = "需评审竞赛数")
    @GetMapping(value = "/getReviewCompetitionCount")
    public AjaxResult getReviewCompetitionCount() {
        // 这里替换成你的实际逻辑
        return AjaxResult.success(competitionResourceLibraryService.getReviewCompetitionCount());
    }
}
