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.FsUserCourseStudy;
import com.fs.course.service.IFsUserCourseStudyService;
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/userCourseStudy")
public class FsUserCourseStudyController extends BaseController
{
    @Autowired
    private IFsUserCourseStudyService fsUserCourseStudyService;

    /**
     * 查询课程用户关联列表
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseStudy:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsUserCourseStudy fsUserCourseStudy)
    {
        startPage();
        List<FsUserCourseStudy> list = fsUserCourseStudyService.selectFsUserCourseStudyList(fsUserCourseStudy);
        return getDataTable(list);
    }

    /**
     * 导出课程用户关联列表
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseStudy:export')")
    @Log(title = "课程用户关联", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsUserCourseStudy fsUserCourseStudy)
    {
        List<FsUserCourseStudy> list = fsUserCourseStudyService.selectFsUserCourseStudyList(fsUserCourseStudy);
        ExcelUtil<FsUserCourseStudy> util = new ExcelUtil<FsUserCourseStudy>(FsUserCourseStudy.class);
        return util.exportExcel(list, "课程用户关联数据");
    }

    /**
     * 获取课程用户关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseStudy:query')")
    @GetMapping(value = "/{studyId}")
    public AjaxResult getInfo(@PathVariable("studyId") String studyId)
    {
        return AjaxResult.success(fsUserCourseStudyService.selectFsUserCourseStudyByStudyId(studyId));
    }

    /**
     * 新增课程用户关联
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseStudy:add')")
    @Log(title = "课程用户关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsUserCourseStudy fsUserCourseStudy)
    {
        return toAjax(fsUserCourseStudyService.insertFsUserCourseStudy(fsUserCourseStudy));
    }

    /**
     * 修改课程用户关联
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseStudy:edit')")
    @Log(title = "课程用户关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsUserCourseStudy fsUserCourseStudy)
    {
        return toAjax(fsUserCourseStudyService.updateFsUserCourseStudy(fsUserCourseStudy));
    }

    /**
     * 删除课程用户关联
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseStudy:remove')")
    @Log(title = "课程用户关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{studyIds}")
    public AjaxResult remove(@PathVariable String[] studyIds)
    {
        return toAjax(fsUserCourseStudyService.deleteFsUserCourseStudyByStudyIds(studyIds));
    }
}
