package com.fs.course.controller;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.course.domain.FsUserCourseComment;
import com.fs.course.param.FsUserCourseCommentParam;
import com.fs.course.service.IFsUserCourseCommentService;
import com.fs.course.vo.FsUserCourseCommentListVO;
import com.fs.course.vo.FsUserCourseCommentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课堂评论Controller
 *
 * @author fs
 * @date 2024-05-15
 */
@RestController
@RequestMapping("/course/userCourseComment")
public class FsUserCourseCommentController extends BaseController
{
    @Autowired
    private IFsUserCourseCommentService fsUserCourseCommentService;

    /**
     * 查询课堂评论列表
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseComment:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsUserCourseCommentParam fsUserCourseComment)
    {
        startPage();
        List<FsUserCourseCommentListVO> list = fsUserCourseCommentService.selectFsUserCourseCommentListVO(fsUserCourseComment);
        return getDataTable(list);
    }

    /**
     * 导出课堂评论列表
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseComment:export')")
    @Log(title = "课堂评论", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsUserCourseCommentParam fsUserCourseComment)
    {
        List<FsUserCourseCommentListVO> list = fsUserCourseCommentService.selectFsUserCourseCommentListVO(fsUserCourseComment);
        ExcelUtil<FsUserCourseCommentListVO> util = new ExcelUtil<FsUserCourseCommentListVO>(FsUserCourseCommentListVO.class);
        return util.exportExcel(list, "课堂评论数据");
    }

    /**
     * 获取课堂评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseComment:query')")
    @GetMapping(value = "/{commentId}")
    public AjaxResult getInfo(@PathVariable("commentId") Long commentId)
    {
        return AjaxResult.success(fsUserCourseCommentService.selectFsUserCourseCommentVOByCommentId(commentId));
    }


    @GetMapping("/getComment/{commentId}")
    public AjaxResult getComment(@PathVariable("commentId") Long commentId)
    {
        FsUserCourseCommentVO fsUserCourseCommentVO = fsUserCourseCommentService.selectFsUserCourseCommentVOByCommentId(commentId);
        List<FsUserCourseCommentVO> vo =fsUserCourseCommentService.selectFsUserCourseCommentAllListVO(fsUserCourseCommentVO.getParentId()==0?fsUserCourseCommentVO.getCommentId():fsUserCourseCommentVO.getParentId());

        return AjaxResult.success(fsUserCourseCommentVO);
    }

    /**
     * 新增课堂评论
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseComment:add')")
    @Log(title = "课堂评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsUserCourseComment fsUserCourseComment)
    {
        return toAjax(fsUserCourseCommentService.insertFsUserCourseComment(fsUserCourseComment));
    }

    /**
     * 修改课堂评论
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseComment:edit')")
    @Log(title = "课堂评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsUserCourseComment fsUserCourseComment)
    {
        return toAjax(fsUserCourseCommentService.updateFsUserCourseComment(fsUserCourseComment));
    }

    /**
     * 删除课堂评论
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseComment:remove')")
    @Log(title = "课堂评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commentIds}")
    public AjaxResult remove(@PathVariable Long[] commentIds)
    {
        return toAjax(fsUserCourseCommentService.deleteFsUserCourseCommentByCommentIds(commentIds));
    }
}
