package com.miaxis.pc.controller.question;

import com.miaxis.common.annotation.Log;
import com.miaxis.common.core.controller.BaseController;
import com.miaxis.common.core.domain.Response;
import com.miaxis.common.core.page.ResponsePageInfo;
import com.miaxis.common.enums.BusinessTypeEnum;
import com.miaxis.question.dto.QuestionInfoSortDTO;
import com.miaxis.question.dto.QuestionInfoSortUpateDTO;
import com.miaxis.question.service.IQuestionInfoService;
import com.miaxis.question.vo.QuestionInfoExcelTypeVo;
import com.miaxis.question.vo.QuestionInfoExcelVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【题库】Controller
 *
 * @author miaxis
 * @date 2021-12-24
 */
@RestController
@RequestMapping("pc/question/info")
@Api(tags={"【pc-题库排序】"})
public class PcQuestionInfoController extends BaseController{
    @Autowired
    private IQuestionInfoService questionInfoService;

    /**
     * 查询题库列表
     */
    @PreAuthorize("@ss.hasPermi('question:info:list')")
    @GetMapping("/list")
    @ApiOperation("查询题库列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
    })
    public ResponsePageInfo<QuestionInfoExcelVo> list(@ModelAttribute QuestionInfoSortDTO questionInfoSortDTO){
        startPage();
        initParams(questionInfoSortDTO);
        List<QuestionInfoExcelVo> list = questionInfoService.selectQuestionInfoSortList(questionInfoSortDTO);
        return toResponsePageInfo(list);
    }

    private void initParams(QuestionInfoSortDTO questionInfoSortDTO) {
        Integer issueTypeValue = questionInfoSortDTO.getIssueTypeValue();
        switch (issueTypeValue){
            case 1:
                questionInfoSortDTO.setIssueTypeParmName("class_issue");
                questionInfoSortDTO.setSortName("class_sort");
                break;
            case 2:
                questionInfoSortDTO.setIssueTypeParmName("excell_issue");
                questionInfoSortDTO.setSortName("excell_sort");
                break;
            case 3:
                questionInfoSortDTO.setIssueTypeParmName("place_issue");
                questionInfoSortDTO.setSortName("place_sort");
                break;
            case 4:
                questionInfoSortDTO.setIssueTypeParmName("seque_issue");
                questionInfoSortDTO.setSortName("seque_sort");
                break;
        }

    }

//    /**
//     * 导出题库列表
//     */
//    @PreAuthorize("@ss.hasPermi('question:info:export')")
//    @Log(title = "题库", businessType = BusinessTypeEnum.EXPORT)
//    @GetMapping("/export")
//    @ApiOperation("导出题库列表Excel")
//    public Response<String> export(@ModelAttribute QuestionInfo questionInfo){
//        List<QuestionInfo> list = questionInfoService.selectQuestionInfoList(questionInfo);
//        ExcelUtil<QuestionInfo> util = new ExcelUtil<QuestionInfo>(QuestionInfo.class);
//        return util.exportExcel(list, "info");
//    }



    /**
     * 根据专题类型获取具体分类
     */
    @PreAuthorize("@ss.hasPermi('question:info:list')")
    @GetMapping(value = "/issueType")
    @ApiOperation("根据专题类型获取具体分类")
    public Response<List<QuestionInfoExcelTypeVo>> getTypes(Integer subject,Integer issueTypeValue)
    {

        return Response.success(questionInfoService.getIssueTypes(issueTypeValue,subject));
    }


    /**
     * 修改题库
     */
    @PreAuthorize("@ss.hasPermi('question:info:edit')")
    @Log(title = "题库", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改顺序")
    public Response questionInfoSortUpate(@RequestBody QuestionInfoSortUpateDTO questionInfoSortUpateDTO){
        initParams(questionInfoSortUpateDTO);
        questionInfoService.updateSortById(questionInfoSortUpateDTO);
        return Response.success();
    }

    private void initParams(QuestionInfoSortUpateDTO dto) {
        Integer issueTypeValue = dto.getIssueTypeValue();
        switch (issueTypeValue){
            case 1:
                dto.setSortName("class_sort");
                break;
            case 2:
                dto.setSortName("excell_sort");
                break;
            case 3:
                dto.setSortName("place_sort");
                break;
            case 4:
                dto.setSortName("seque_sort");
                break;
        }
    }




}
