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.domain.R;
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.FsUserCourse;
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 java.util.List;

/**
 * 课程Controller
 *
 * @author fs
 * @date 2024-05-15
 */
@RestController
@RequestMapping("/course/userCourse")
public class FsUserCourseController extends BaseController
{
    @Autowired
    private IFsUserCourseService fsUserCourseService;

    /**
     * 查询课程列表
     */
    @PreAuthorize("@ss.hasPermi('course:userCourse:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsUserCourse fsUserCourse)
    {
        startPage();
        List<FsUserCourseListPVO> list = fsUserCourseService.selectFsUserCourseListPVO(fsUserCourse);
        return getDataTable(list);
    }

    /**
     * 查询公域课程列表
     */
    @PreAuthorize("@ss.hasPermi('course:userCourse:publicList')")
    @GetMapping("/publicList")
    public TableDataInfo publicList(FsUserCourse fsUserCourse)
    {
        startPage();
        List<FsUserCourseListPVO> list = fsUserCourseService.selectFsUserCourseListPVO(fsUserCourse);
        return getDataTable(list);
    }

    /**
     * 导出课程列表
     */
    @PreAuthorize("@ss.hasPermi('course:userCourse:export')")
    @Log(title = "课程", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsUserCourse fsUserCourse)
    {
        List<FsUserCourse> list = fsUserCourseService.selectFsUserCourseList(fsUserCourse);
        ExcelUtil<FsUserCourse> util = new ExcelUtil<FsUserCourse>(FsUserCourse.class);
        return util.exportExcel(list, "课程数据");
    }

    /**
     * 导出课程列表
     */
    @PreAuthorize("@ss.hasPermi('course:userCourse:publicExport')")
    @Log(title = "课程", businessType = BusinessType.EXPORT)
    @GetMapping("/publicExport")
    public AjaxResult publicExport(FsUserCourse fsUserCourse)
    {
        List<FsUserCourse> list = fsUserCourseService.selectFsUserCourseList(fsUserCourse);
        ExcelUtil<FsUserCourse> util = new ExcelUtil<FsUserCourse>(FsUserCourse.class);
        return util.exportExcel(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:publicQuery')")
    @GetMapping(value = "/public/{courseId}")
    public AjaxResult publicGetInfo(@PathVariable("courseId") Long courseId)
    {
        return AjaxResult.success(fsUserCourseService.selectFsUserCourseByCourseId(courseId));
    }

    /**
     * 新增课程
     */
    @PreAuthorize("@ss.hasPermi('course:userCourse:add')")
    @Log(title = "课程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsUserCourse fsUserCourse)
    {
        return toAjax(fsUserCourseService.insertFsUserCourse(fsUserCourse));
    }

    /**
     * 新增公域课程
     */
    @PreAuthorize("@ss.hasPermi('course:userCourse:publicAdd')")
    @Log(title = "课程", businessType = BusinessType.INSERT)
    @PostMapping("/public")
    public AjaxResult publicAdd(@RequestBody FsUserCourse fsUserCourse)
    {
        return toAjax(fsUserCourseService.insertFsUserCourse(fsUserCourse));
    }

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

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

    /**
     * 删除课程
     */
    @PreAuthorize("@ss.hasPermi('course:userCourse:remove')")
    @Log(title = "课程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{courseIds}")
    public AjaxResult remove(@PathVariable Long[] courseIds)
    {
        return toAjax(fsUserCourseService.deleteFsUserCourseByCourseIds(courseIds));
    }

    /**
     * 删除公域课程
     */
    @PreAuthorize("@ss.hasPermi('course:userCourse:publicRemove')")
    @Log(title = "课程", businessType = BusinessType.DELETE)
    @DeleteMapping("/public/{courseIds}")
    public AjaxResult publicRemove(@PathVariable Long[] courseIds)
    {
        return toAjax(fsUserCourseService.deleteFsUserCourseByCourseIds(courseIds));
    }


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

    @PreAuthorize("@ss.hasPermi('course:userCourse:updateIsShow')")
    @Log(title = "课程上架", businessType = BusinessType.UPDATE)
    @PostMapping("/updateIsShow")
    public AjaxResult updateIsShow(@RequestBody FsUserCourse fsUserCourse)
    {
       return toAjax(fsUserCourseService.updateFsUserCourse(fsUserCourse));
    }

    @PreAuthorize("@ss.hasPermi('course:userCourse:publicUpdateIsShow')")
    @Log(title = "课程上架", businessType = BusinessType.UPDATE)
    @PostMapping("/publicUpdateIsShow")
    public AjaxResult publicUpdateIsShow(@RequestBody FsUserCourse fsUserCourse)
    {
        return toAjax(fsUserCourseService.updateFsUserCourse(fsUserCourse));
    }

    @PreAuthorize("@ss.hasPermi('course:userCourse:putOn')")
    @Log(title = "课程批量上架", businessType = BusinessType.UPDATE)
    @PostMapping("/putOn/{courseIds}")
    public AjaxResult putOn(@PathVariable Long[] courseIds)
    {
        return toAjax(fsUserCourseService.updateFsUserCourseIsShow(courseIds,1));
    }

    @PreAuthorize("@ss.hasPermi('course:userCourse:publicPutOn')")
    @Log(title = "课程批量上架", businessType = BusinessType.UPDATE)
    @PostMapping("/publicPutOn/{courseIds}")
    public AjaxResult publicPutOn(@PathVariable Long[] courseIds)
    {
        return toAjax(fsUserCourseService.updateFsUserCourseIsShow(courseIds,1));
    }

    @PreAuthorize("@ss.hasPermi('course:userCourse:putOn')")
    @Log(title = "课程批量下架", businessType = BusinessType.UPDATE)
    @PostMapping("/pullOff/{courseIds}")
    public AjaxResult pullOff(@PathVariable Long[] courseIds)
    {
        return toAjax(fsUserCourseService.updateFsUserCourseIsShow(courseIds,0));
    }

    @PreAuthorize("@ss.hasPermi('course:userCourse:publicPutOff')")
    @Log(title = "课程批量下架", businessType = BusinessType.UPDATE)
    @PostMapping("/publicPullOff/{courseIds}")
    public AjaxResult publicPullOff(@PathVariable Long[] courseIds)
    {
        return toAjax(fsUserCourseService.updateFsUserCourseIsShow(courseIds,0));
    }
}
