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.FsUserCourseStudyLog;
import com.fs.course.service.IFsUserCourseStudyLogService;
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/userCourseStudyLog")
public class FsUserCourseStudyLogController extends BaseController
{
    @Autowired
    private IFsUserCourseStudyLogService fsUserCourseStudyLogService;

    /**
     * 查询课程用户学习日志列表
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseStudyLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsUserCourseStudyLog fsUserCourseStudyLog)
    {
        startPage();
        List<FsUserCourseStudyLog> list = fsUserCourseStudyLogService.selectFsUserCourseStudyLogList(fsUserCourseStudyLog);
        return getDataTable(list);
    }

    /**
     * 导出课程用户学习日志列表
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseStudyLog:export')")
    @Log(title = "课程用户学习日志", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsUserCourseStudyLog fsUserCourseStudyLog)
    {
        List<FsUserCourseStudyLog> list = fsUserCourseStudyLogService.selectFsUserCourseStudyLogList(fsUserCourseStudyLog);
        ExcelUtil<FsUserCourseStudyLog> util = new ExcelUtil<FsUserCourseStudyLog>(FsUserCourseStudyLog.class);
        return util.exportExcel(list, "课程用户学习日志数据");
    }

    /**
     * 获取课程用户学习日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseStudyLog:query')")
    @GetMapping(value = "/{logId}")
    public AjaxResult getInfo(@PathVariable("logId") String logId)
    {
        return AjaxResult.success(fsUserCourseStudyLogService.selectFsUserCourseStudyLogByLogId(logId));
    }

    /**
     * 新增课程用户学习日志
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseStudyLog:add')")
    @Log(title = "课程用户学习日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsUserCourseStudyLog fsUserCourseStudyLog)
    {
        return toAjax(fsUserCourseStudyLogService.insertFsUserCourseStudyLog(fsUserCourseStudyLog));
    }

    /**
     * 修改课程用户学习日志
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseStudyLog:edit')")
    @Log(title = "课程用户学习日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsUserCourseStudyLog fsUserCourseStudyLog)
    {
        return toAjax(fsUserCourseStudyLogService.updateFsUserCourseStudyLog(fsUserCourseStudyLog));
    }

    /**
     * 删除课程用户学习日志
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseStudyLog:remove')")
    @Log(title = "课程用户学习日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{logIds}")
    public AjaxResult remove(@PathVariable String[] logIds)
    {
        return toAjax(fsUserCourseStudyLogService.deleteFsUserCourseStudyLogByLogIds(logIds));
    }
}
