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.FsUserCourseNote;
import com.fs.course.service.IFsUserCourseNoteService;
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/userCourseNote")
public class FsUserCourseNoteController extends BaseController
{
    @Autowired
    private IFsUserCourseNoteService fsUserCourseNoteService;

    /**
     * 查询课堂笔记列表
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseNote:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsUserCourseNote fsUserCourseNote)
    {
        startPage();
        List<FsUserCourseNote> list = fsUserCourseNoteService.selectFsUserCourseNoteList(fsUserCourseNote);
        return getDataTable(list);
    }

    /**
     * 导出课堂笔记列表
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseNote:export')")
    @Log(title = "课堂笔记", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsUserCourseNote fsUserCourseNote)
    {
        List<FsUserCourseNote> list = fsUserCourseNoteService.selectFsUserCourseNoteList(fsUserCourseNote);
        ExcelUtil<FsUserCourseNote> util = new ExcelUtil<FsUserCourseNote>(FsUserCourseNote.class);
        return util.exportExcel(list, "课堂笔记数据");
    }

    /**
     * 获取课堂笔记详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseNote:query')")
    @GetMapping(value = "/{noteId}")
    public AjaxResult getInfo(@PathVariable("noteId") Long noteId)
    {
        return AjaxResult.success(fsUserCourseNoteService.selectFsUserCourseNoteByNoteId(noteId));
    }

    /**
     * 新增课堂笔记
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseNote:add')")
    @Log(title = "课堂笔记", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsUserCourseNote fsUserCourseNote)
    {
        return toAjax(fsUserCourseNoteService.insertFsUserCourseNote(fsUserCourseNote));
    }

    /**
     * 修改课堂笔记
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseNote:edit')")
    @Log(title = "课堂笔记", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsUserCourseNote fsUserCourseNote)
    {
        return toAjax(fsUserCourseNoteService.updateFsUserCourseNote(fsUserCourseNote));
    }

    /**
     * 删除课堂笔记
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseNote:remove')")
    @Log(title = "课堂笔记", businessType = BusinessType.DELETE)
	@DeleteMapping("/{noteIds}")
    public AjaxResult remove(@PathVariable Long[] noteIds)
    {
        return toAjax(fsUserCourseNoteService.deleteFsUserCourseNoteByNoteIds(noteIds));
    }
}
