package com.miaxis.app.controller;

import com.miaxis.common.constant.Constants;

import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;

import com.miaxis.question.domain.QuestionCollection;
import com.miaxis.question.dto.QuestionCollectionDTO;
import com.miaxis.question.dto.QuestionWrongDTO;
import io.swagger.annotations.*;
import com.miaxis.common.core.domain.Response;
import org.springframework.beans.BeanUtils;
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.QuestionWrong;
import com.miaxis.question.service.IQuestionWrongService;
import com.miaxis.common.utils.poi.ExcelUtil;
import com.miaxis.common.core.page.ResponsePageInfo;

/**
 * 【wrong】Controller
 *
 * @author miaxis
 * @date 2021-08-19
 */
@RestController
@RequestMapping("/question/wrong")
@Api(tags={"【APP-错题】"})
public class QuestionWrongController extends BaseController{
    @Autowired
    private IQuestionWrongService questionWrongService;

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


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

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

    @PostMapping("wrongs")
    @ApiOperation("批量新增wrongs")
    public Response<Integer> wrongs(@RequestBody List<QuestionWrongDTO> list){
        List<QuestionWrong> qlist = new ArrayList<QuestionWrong>();
        for (QuestionWrongDTO questionWrongDTO: list) {
            QuestionWrong questionWrong = new QuestionWrong();
            BeanUtils.copyProperties(questionWrongDTO,questionWrong);
            qlist.add(questionWrong);
        }
        return toResponse(questionWrongService.saveBatch(qlist) ? 1 : 0);
    }

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

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