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.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.course.domain.FsUserCourseCategory;
import com.fs.course.service.IFsUserCourseCategoryService;
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/userCourseCategory")
public class FsUserCourseCategoryController extends BaseController
{
    @Autowired
    private IFsUserCourseCategoryService fsUserCourseCategoryService;

    /**
     * 查询课堂分类列表
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseCategory:list')")
    @GetMapping("/list")
    public AjaxResult list(FsUserCourseCategory fsUserCourseCategory)
    {
        List<FsUserCourseCategory> list = fsUserCourseCategoryService.selectFsUserCourseCategoryList(fsUserCourseCategory);
        return AjaxResult.success(list);
    }

    /**
     * 导出课堂分类列表
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseCategory:export')")
    @Log(title = "课堂分类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsUserCourseCategory fsUserCourseCategory)
    {
        List<FsUserCourseCategory> list = fsUserCourseCategoryService.selectFsUserCourseCategoryList(fsUserCourseCategory);
        ExcelUtil<FsUserCourseCategory> util = new ExcelUtil<FsUserCourseCategory>(FsUserCourseCategory.class);
        return util.exportExcel(list, "课堂分类数据");
    }

    /**
     * 获取课堂分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseCategory:query')")
    @GetMapping(value = "/{cateId}")
    public AjaxResult getInfo(@PathVariable("cateId") Long cateId)
    {
        return AjaxResult.success(fsUserCourseCategoryService.selectFsUserCourseCategoryByCateId(cateId));
    }

    /**
     * 新增课堂分类
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseCategory:add')")
    @Log(title = "课堂分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsUserCourseCategory fsUserCourseCategory)
    {
        return toAjax(fsUserCourseCategoryService.insertFsUserCourseCategory(fsUserCourseCategory));
    }

    /**
     * 修改课堂分类
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseCategory:edit')")
    @Log(title = "课堂分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsUserCourseCategory fsUserCourseCategory)
    {
        return toAjax(fsUserCourseCategoryService.updateFsUserCourseCategory(fsUserCourseCategory));
    }

    /**
     * 删除课堂分类
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseCategory:remove')")
    @Log(title = "课堂分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cateIds}")
    public AjaxResult remove(@PathVariable Long[] cateIds)
    {
        return toAjax(fsUserCourseCategoryService.deleteFsUserCourseCategoryByCateIds(cateIds));
    }


    @GetMapping("/getAllList")
    public R getAllList(FsUserCourseCategory fsUserCourseCategory)
    {
        fsUserCourseCategory.setIsShow(1);
        fsUserCourseCategory.setIsDel(0);
        List<FsUserCourseCategory> list = fsUserCourseCategoryService.selectFsUserCourseCategoryList(fsUserCourseCategory);
        return R.ok().put("data", list);
    }

    //获取1级总分类
    @GetMapping("/getCatePidList")
    public R getCatePidList()
    {
        List<OptionsVO> list = fsUserCourseCategoryService.selectFsUserCourseCategoryPidList();
        return R.ok().put("data", list);
    }

    //获取总分类下子分类
    @GetMapping("/getCateListByPid/{pid}")
    public R getCateListByPid(@PathVariable("pid")Long pid)
    {
        List<OptionsVO> list = fsUserCourseCategoryService.selectCateListByPid(pid);
        return R.ok().put("data", list);
    }
}
