package com.miaxis.icon.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.icon.domain.IconQuestion;
import com.miaxis.icon.service.IIconQuestionService;
import com.miaxis.common.utils.poi.ExcelUtil;
import com.miaxis.common.core.page.ResponsePageInfo;

/**
 * 【题目图标】Controller
 *
 * @author miaxis
 * @date 2022-08-01
 */
@RestController
@RequestMapping("/icon/question")
@Api(tags={"【H5-题目图标】"})
public class IconQuestionController extends BaseController{
    @Autowired
    private IIconQuestionService iconQuestionService;

    /**
     * 查询题目图标列表
     */
    @PreAuthorize("@ss.hasPermi('icon:question: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<IconQuestion> list(@ModelAttribute IconQuestion iconQuestion){
        startPage();
        List<IconQuestion> list = iconQuestionService.selectIconQuestionList(iconQuestion);
        return toResponsePageInfo(list);
    }
    
    /**
     * 导出题目图标列表
     */
    @PreAuthorize("@ss.hasPermi('icon:question:export')")
    @Log(title = "题目图标", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出题目图标列表Excel")
    public Response<String> export(@ModelAttribute IconQuestion iconQuestion){
        List<IconQuestion> list = iconQuestionService.selectIconQuestionList(iconQuestion);
        ExcelUtil<IconQuestion> util = new ExcelUtil<IconQuestion>(IconQuestion.class);
        return util.exportExcel(list, "question");
    }

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

    /**
     * 新增题目图标
     */
    @PreAuthorize("@ss.hasPermi('icon:question:add')")
    @Log(title = "题目图标", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation("新增题目图标")
    public Response<Integer> add(@RequestBody IconQuestion iconQuestion){
        return toResponse(iconQuestionService.save(iconQuestion) ? 1 : 0);
    }

    /**
     * 修改题目图标
     */
    @PreAuthorize("@ss.hasPermi('icon:question:edit')")
    @Log(title = "题目图标", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改题目图标")
    public Response<Integer> edit(@RequestBody IconQuestion iconQuestion){
        return toResponse(iconQuestionService.updateById(iconQuestion) ? 1 : 0);
    }

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