package com.ruoyi.web.controller.info;

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

import com.ruoyi.common.core.domain.R;
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 com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.InfoPinglun;
import com.ruoyi.system.service.IInfoPinglunService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 信息评论Controller
 * 
 * @author boman
 * @date 2023-11-28
 */
@RestController
@RequestMapping("/system/pinglun")
public class InfoPinglunController extends BaseController
{
    @Autowired
    private IInfoPinglunService infoPinglunService;

    /**
     * 查询信息评论列表
     */
    @PreAuthorize("@ss.hasPermi('system:pinglun:list')")
    @GetMapping("/list")
    public TableDataInfo list(InfoPinglun infoPinglun)
    {
        startPage();
        List<InfoPinglun> list = infoPinglunService.selectInfoPinglunList(infoPinglun);
        return getDataTable(list);
    }

    /**
     * 根据附件id查询评论
     * @param annexId
     * @return
     */
    @GetMapping("/pingLun/{annexId}")
    public AjaxResult getPingLunInfo(@PathVariable Long annexId) {
        List<InfoPinglun> pingLunInfo = infoPinglunService.getPingLunInfo(annexId);
        return AjaxResult.success(pingLunInfo);
    }

    /**
     * 根据附件id查询评论滚动
     * @param annexId
     * @return
     */
    @GetMapping("/pingLun/index/{annexId}")
    public AjaxResult getPingLunInfoIndex(@PathVariable Long annexId) {
        List<InfoPinglun> pingLunInfo = infoPinglunService.getPingLunInfoIndex(annexId);
        return AjaxResult.success(pingLunInfo);
    }

    /**
     * 导出信息评论列表
     */
    @PreAuthorize("@ss.hasPermi('system:pinglun:export')")
    @Log(title = "信息评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InfoPinglun infoPinglun)
    {
        List<InfoPinglun> list = infoPinglunService.selectInfoPinglunList(infoPinglun);
        ExcelUtil<InfoPinglun> util = new ExcelUtil<InfoPinglun>(InfoPinglun.class);
        util.exportExcel(response, list, "信息评论数据");
    }

    /**
     * 获取信息评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:pinglun:query')")
    @GetMapping(value = "/{infoPinglunId}")
    public AjaxResult getInfo(@PathVariable("infoPinglunId") Long infoPinglunId)
    {
        return success(infoPinglunService.selectInfoPinglunByInfoPinglunId(infoPinglunId));
    }

    /**
     * 新增信息评论
     */
    @PostMapping()
    public AjaxResult add(@RequestBody InfoPinglun infoPinglun)
    {
        return toAjax(infoPinglunService.insertInfoPinglun(infoPinglun));
    }

    /**
     * 修改信息评论
     */
    @PreAuthorize("@ss.hasPermi('system:pinglun:edit')")
    @Log(title = "信息评论", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody InfoPinglun infoPinglun)
    {
        return toAjax(infoPinglunService.updateInfoPinglun(infoPinglun));
    }

    /**
     * 删除信息评论
     */
    @PreAuthorize("@ss.hasPermi('system:pinglun:remove')")
    @Log(title = "信息评论", businessType = BusinessType.DELETE)
	@GetMapping("/delete/{infoPinglunIds}")
    public AjaxResult remove(@PathVariable Long[] infoPinglunIds)
    {
        return toAjax(infoPinglunService.deleteInfoPinglunByInfoPinglunIds(infoPinglunIds));
    }
}
