package com.ruoyi.hezhi.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hezhi.domain.TbMemberSubjectWrong;
import com.ruoyi.hezhi.service.ITbMemberSubjectWrongService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 我的错题Controller
 *
 * @author ruoyi
 * @date 2024-11-07
 */
@RestController
@RequestMapping("/hezhi/memberSubjectWrong")
public class TbMemberSubjectWrongController extends BaseController
{
    @Autowired
    private ITbMemberSubjectWrongService tbMemberSubjectWrongService;

    /**
     * 查询我的错题列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberSubjectWrong:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbMemberSubjectWrong tbMemberSubjectWrong)
    {
        startPage();
        List<TbMemberSubjectWrong> list = tbMemberSubjectWrongService.selectTbMemberSubjectWrongList(tbMemberSubjectWrong);
        return getDataTable(list);
    }

    /**
     * 导出我的错题列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberSubjectWrong:export')")
    @Log(title = "我的错题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbMemberSubjectWrong tbMemberSubjectWrong)
    {
        List<TbMemberSubjectWrong> list = tbMemberSubjectWrongService.selectTbMemberSubjectWrongList(tbMemberSubjectWrong);
        ExcelUtil<TbMemberSubjectWrong> util = new ExcelUtil<TbMemberSubjectWrong>(TbMemberSubjectWrong.class);
        util.exportExcel(response, list, "我的错题数据");
    }

    /**
     * 获取我的错题详细信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberSubjectWrong:query')")
    @GetMapping(value = "/{memberSubjectWrongId}")
    public AjaxResult getInfo(@PathVariable("memberSubjectWrongId") Long memberSubjectWrongId)
    {
        return success(tbMemberSubjectWrongService.selectTbMemberSubjectWrongByMemberSubjectWrongId(memberSubjectWrongId));
    }

    /**
     * 新增我的错题
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberSubjectWrong:add')")
    @Log(title = "我的错题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbMemberSubjectWrong tbMemberSubjectWrong)
    {
        return toAjax(tbMemberSubjectWrongService.insertTbMemberSubjectWrong(tbMemberSubjectWrong));
    }

    /**
     * 修改我的错题
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberSubjectWrong:edit')")
    @Log(title = "我的错题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbMemberSubjectWrong tbMemberSubjectWrong)
    {
        return toAjax(tbMemberSubjectWrongService.updateTbMemberSubjectWrong(tbMemberSubjectWrong));
    }

    /**
     * 删除我的错题
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberSubjectWrong:remove')")
    @Log(title = "我的错题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{memberSubjectWrongIds}")
    public AjaxResult remove(@PathVariable Long[] memberSubjectWrongIds)
    {
        return toAjax(tbMemberSubjectWrongService.deleteTbMemberSubjectWrongByMemberSubjectWrongIds(memberSubjectWrongIds));
    }
}
