package com.fs.course.controller;


import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.domain.R;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.ServletUtils;
import com.fs.core.security.LoginUser;
import com.fs.course.domain.FsUserCourse;
import com.fs.course.param.FsUserCourseParam;
import com.fs.course.service.IFsUserCourseService;
import com.fs.course.vo.FsUserCourseListPVO;
import com.fs.his.vo.OptionsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.fs.common.annotation.Log;
import com.fs.core.web.service.TokenService;
import java.util.List;

/**
 * 课程Controller
 *
 * @author fs
 * @date 2024-05-15
 */
@RestController
@RequestMapping("/course/userCourse")
public class FsUserCourseController extends BaseController
{
    @Autowired
    private IFsUserCourseService fsUserCourseService;
    @Autowired
    private TokenService tokenService;
    /**
     * 查询课程列表
     */
    @PreAuthorize("@ss.hasPermi('course:userCourse:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsUserCourseParam fsUserCourse)
    {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        fsUserCourse.setCompanyId(loginUser.getCompany().getCompanyId());
        List<FsUserCourseListPVO> list = fsUserCourseService.selectFsUserCourseListCompanyPVO(fsUserCourse);
        return getDataTable(list);
    }



    /**
     * 获取课程详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:userCourse:query')")
    @GetMapping(value = "/{courseId}")
    public AjaxResult getInfo(@PathVariable("courseId") Long courseId)
    {
        return AjaxResult.success(fsUserCourseService.selectFsUserCourseByCourseId(courseId));
    }



    /**
     * 修改课程
     */
    @PreAuthorize("@ss.hasPermi('course:userCourse:edit')")
    @Log(title = "课程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsUserCourse fsUserCourse)
    {
        return toAjax(fsUserCourseService.updateFsUserCourse(fsUserCourse));
    }



    @GetMapping("/getAllList")
    public R getAllList()
    {
        List<OptionsVO> list = fsUserCourseService.selectFsUserCourseAllList();
        return R.ok().put("data", list);
    }


}
