package com.miaxis.app.controller;

import com.miaxis.common.constant.Constants;
import java.util.List;
import java.util.Arrays;
import io.swagger.annotations.*;
import com.miaxis.common.core.domain.Response;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.ModelAttribute;
import com.miaxis.common.annotation.Log;
import com.miaxis.common.core.controller.BaseController;
import com.miaxis.common.enums.BusinessTypeEnum;
import com.miaxis.question.domain.QuestionVersion;
import com.miaxis.question.service.IQuestionVersionService;
import com.miaxis.common.utils.poi.ExcelUtil;
import com.miaxis.common.core.page.ResponsePageInfo;

/**
 * 【version】Controller
 *
 * @author zhangbin
 * @date 2021-07-26
 */
@RestController
@RequestMapping("/question/version")
@Api(tags={"【APP-题库版本】"})
public class QuestionVersionController extends BaseController{
    @Autowired
    private IQuestionVersionService questionVersionService;

    /**
     * 查询version列表
     */
//    @PreAuthorize("@ss.hasPermi('question:version:list')")
    @GetMapping("/list")
    @ApiOperation("查询version列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
    })
    public ResponsePageInfo<QuestionVersion> list(@ModelAttribute QuestionVersion questionVersion){
        startPage();
        List<QuestionVersion> list = questionVersionService.selectQuestionVersionList(questionVersion);
        return toResponsePageInfo(list);
    }



    /**
     * 获取version详细信息
     */
//    @PreAuthorize("@ss.hasPermi('question:version:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取version详细信息")
    public Response<QuestionVersion> getInfo(
            @ApiParam(name = "id", value = "version参数", required = true)
            @PathVariable("id") Long id
    ){
        return Response.success(questionVersionService.getById(id));
    }

    /**
     * 新增version
     */
//    @PreAuthorize("@ss.hasPermi('question:version:add')")
    @Log(title = "version", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation("新增version")
    public Response<Integer> add(@RequestBody QuestionVersion questionVersion){
        return toResponse(questionVersionService.save(questionVersion) ? 1 : 0);
    }

    /**
     * 修改version
     */
//    @PreAuthorize("@ss.hasPermi('question:version:edit')")
    @Log(title = "version", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改version")
    public Response<Integer> edit(@RequestBody QuestionVersion questionVersion){
        return toResponse(questionVersionService.updateById(questionVersion) ? 1 : 0);
    }

    /**
     * 删除version
     */
//    @PreAuthorize("@ss.hasPermi('question:version:remove')")
    @Log(title = "version", businessType = BusinessTypeEnum.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除version")
    public  Response<Integer> remove(
            @ApiParam(name = "ids", value = "versionids参数", required = true)
            @PathVariable Long[] ids
    ){
        return toResponse(questionVersionService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
