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.TbMemberDiscuss;
import com.ruoyi.hezhi.service.ITbMemberDiscussService;
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-19
 */
@RestController
@RequestMapping("/hezhi/memberDiscuss")
public class TbMemberDiscussController extends BaseController
{
    @Autowired
    private ITbMemberDiscussService tbMemberDiscussService;

    /**
     * 查询用户讨论列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberDiscuss:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbMemberDiscuss tbMemberDiscuss)
    {
        startPage();
        List<TbMemberDiscuss> list = tbMemberDiscussService.selectTbMemberDiscussList(tbMemberDiscuss);
        return getDataTable(list);
    }

    /**
     * 导出用户讨论列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberDiscuss:export')")
    @Log(title = "用户讨论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbMemberDiscuss tbMemberDiscuss)
    {
        List<TbMemberDiscuss> list = tbMemberDiscussService.selectTbMemberDiscussList(tbMemberDiscuss);
        ExcelUtil<TbMemberDiscuss> util = new ExcelUtil<TbMemberDiscuss>(TbMemberDiscuss.class);
        util.exportExcel(response, list, "用户讨论数据");
    }

    /**
     * 获取用户讨论详细信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberDiscuss:query')")
    @GetMapping(value = "/{memberDiscussId}")
    public AjaxResult getInfo(@PathVariable("memberDiscussId") Long memberDiscussId)
    {
        return success(tbMemberDiscussService.selectTbMemberDiscussByMemberDiscussId(memberDiscussId));
    }

    /**
     * 新增用户讨论
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberDiscuss:add')")
    @Log(title = "用户讨论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbMemberDiscuss tbMemberDiscuss)
    {
        return toAjax(tbMemberDiscussService.insertTbMemberDiscuss(tbMemberDiscuss));
    }

    /**
     * 修改用户讨论
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberDiscuss:edit')")
    @Log(title = "用户讨论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbMemberDiscuss tbMemberDiscuss)
    {
        return toAjax(tbMemberDiscussService.updateTbMemberDiscuss(tbMemberDiscuss));
    }

    /**
     * 删除用户讨论
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberDiscuss:remove')")
    @Log(title = "用户讨论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{memberDiscussIds}")
    public AjaxResult remove(@PathVariable Long[] memberDiscussIds)
    {
        return toAjax(tbMemberDiscussService.deleteTbMemberDiscussByMemberDiscussIds(memberDiscussIds));
    }
}
