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.FsCourseAnswerLogs;
import com.fs.course.service.IFsCourseAnswerLogsService;
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-09-11
 */
@RestController
@RequestMapping("/course/courseAnswerLogs")
public class FsCourseAnswerLogsController extends BaseController
{
    @Autowired
    private IFsCourseAnswerLogsService fsCourseAnswerLogsService;

    /**
     * 查询答题日志列表
     */
    @PreAuthorize("@ss.hasPermi('course:courseAnswerLogs:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsCourseAnswerLogs fsCourseAnswerLogs)
    {
        startPage();
        List<FsCourseAnswerLogs> list = fsCourseAnswerLogsService.selectFsCourseAnswerLogsList(fsCourseAnswerLogs);
        return getDataTable(list);
    }

    /**
     * 导出答题日志列表
     */
    @PreAuthorize("@ss.hasPermi('course:courseAnswerLogs:export')")
    @Log(title = "答题日志", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsCourseAnswerLogs fsCourseAnswerLogs)
    {
        List<FsCourseAnswerLogs> list = fsCourseAnswerLogsService.selectFsCourseAnswerLogsList(fsCourseAnswerLogs);
        ExcelUtil<FsCourseAnswerLogs> util = new ExcelUtil<FsCourseAnswerLogs>(FsCourseAnswerLogs.class);
        return util.exportExcel(list, "答题日志数据");
    }

    /**
     * 获取答题日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:courseAnswerLogs:query')")
    @GetMapping(value = "/{logId}")
    public AjaxResult getInfo(@PathVariable("logId") Long logId)
    {
        return AjaxResult.success(fsCourseAnswerLogsService.selectFsCourseAnswerLogsByLogId(logId));
    }

    /**
     * 新增答题日志
     */
    @PreAuthorize("@ss.hasPermi('course:courseAnswerLogs:add')")
    @Log(title = "答题日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsCourseAnswerLogs fsCourseAnswerLogs)
    {
        return toAjax(fsCourseAnswerLogsService.insertFsCourseAnswerLogs(fsCourseAnswerLogs));
    }

    /**
     * 修改答题日志
     */
    @PreAuthorize("@ss.hasPermi('course:courseAnswerLogs:edit')")
    @Log(title = "答题日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsCourseAnswerLogs fsCourseAnswerLogs)
    {
        return toAjax(fsCourseAnswerLogsService.updateFsCourseAnswerLogs(fsCourseAnswerLogs));
    }

    /**
     * 删除答题日志
     */
    @PreAuthorize("@ss.hasPermi('course:courseAnswerLogs:remove')")
    @Log(title = "答题日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{logIds}")
    public AjaxResult remove(@PathVariable Long[] logIds)
    {
        return toAjax(fsCourseAnswerLogsService.deleteFsCourseAnswerLogsByLogIds(logIds));
    }
}
