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.TbMemberSubjectCollect;
import com.ruoyi.hezhi.service.ITbMemberSubjectCollectService;
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/memberSubjectCollect")
public class TbMemberSubjectCollectController extends BaseController
{
    @Autowired
    private ITbMemberSubjectCollectService tbMemberSubjectCollectService;

    /**
     * 查询我的收藏题目列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberSubjectCollect:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbMemberSubjectCollect tbMemberSubjectCollect)
    {
        startPage();
        List<TbMemberSubjectCollect> list = tbMemberSubjectCollectService.selectTbMemberSubjectCollectList(tbMemberSubjectCollect);
        return getDataTable(list);
    }

    /**
     * 导出我的收藏题目列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberSubjectCollect:export')")
    @Log(title = "我的收藏题目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbMemberSubjectCollect tbMemberSubjectCollect)
    {
        List<TbMemberSubjectCollect> list = tbMemberSubjectCollectService.selectTbMemberSubjectCollectList(tbMemberSubjectCollect);
        ExcelUtil<TbMemberSubjectCollect> util = new ExcelUtil<TbMemberSubjectCollect>(TbMemberSubjectCollect.class);
        util.exportExcel(response, list, "我的收藏题目数据");
    }

    /**
     * 获取我的收藏题目详细信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberSubjectCollect:query')")
    @GetMapping(value = "/{memberSubjectCollectId}")
    public AjaxResult getInfo(@PathVariable("memberSubjectCollectId") Long memberSubjectCollectId)
    {
        return success(tbMemberSubjectCollectService.selectTbMemberSubjectCollectByMemberSubjectCollectId(memberSubjectCollectId));
    }

    /**
     * 新增我的收藏题目
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberSubjectCollect:add')")
    @Log(title = "我的收藏题目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbMemberSubjectCollect tbMemberSubjectCollect)
    {
        return toAjax(tbMemberSubjectCollectService.insertTbMemberSubjectCollect(tbMemberSubjectCollect));
    }

    /**
     * 修改我的收藏题目
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberSubjectCollect:edit')")
    @Log(title = "我的收藏题目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbMemberSubjectCollect tbMemberSubjectCollect)
    {
        return toAjax(tbMemberSubjectCollectService.updateTbMemberSubjectCollect(tbMemberSubjectCollect));
    }

    /**
     * 删除我的收藏题目
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberSubjectCollect:remove')")
    @Log(title = "我的收藏题目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{memberSubjectCollectIds}")
    public AjaxResult remove(@PathVariable Long[] memberSubjectCollectIds)
    {
        return toAjax(tbMemberSubjectCollectService.deleteTbMemberSubjectCollectByMemberSubjectCollectIds(memberSubjectCollectIds));
    }
}
