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.domain.model.LoginUser;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.SecurityUtils;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.course.domain.FsCourseLink;
import com.fs.course.param.FsCourseLinkCreateParam;
import com.fs.course.service.IFsCourseLinkService;
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/courseLink")
public class FsCourseLinkController extends BaseController
{
    @Autowired
    private IFsCourseLinkService fsCourseLinkService;

    /**
     * 查询短链列表
     */
    @PreAuthorize("@ss.hasPermi('course:courseLink:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsCourseLink fsCourseLink)
    {
        startPage();
        List<FsCourseLink> list = fsCourseLinkService.selectFsCourseLinkList(fsCourseLink);
        return getDataTable(list);
    }

    /**
     * 导出短链列表
     */
    @PreAuthorize("@ss.hasPermi('course:courseLink:export')")
    @Log(title = "短链", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsCourseLink fsCourseLink)
    {
        List<FsCourseLink> list = fsCourseLinkService.selectFsCourseLinkList(fsCourseLink);
        ExcelUtil<FsCourseLink> util = new ExcelUtil<FsCourseLink>(FsCourseLink.class);
        return util.exportExcel(list, "短链数据");
    }

    /**
     * 获取短链详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:courseLink:query')")
    @GetMapping(value = "/{linkId}")
    public AjaxResult getInfo(@PathVariable("linkId") Long linkId)
    {
        return AjaxResult.success(fsCourseLinkService.selectFsCourseLinkByLinkId(linkId));
    }

    /**
     * 新增短链
     */
    @PreAuthorize("@ss.hasPermi('course:courseLink:add')")
    @Log(title = "短链", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsCourseLink fsCourseLink)
    {
        return toAjax(fsCourseLinkService.insertFsCourseLink(fsCourseLink));
    }

    /**
     * 修改短链
     */
    @PreAuthorize("@ss.hasPermi('course:courseLink:edit')")
    @Log(title = "短链", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsCourseLink fsCourseLink)
    {
        return toAjax(fsCourseLinkService.updateFsCourseLink(fsCourseLink));
    }

    /**
     * 删除短链
     */
    @PreAuthorize("@ss.hasPermi('course:courseLink:remove')")
    @Log(title = "短链", businessType = BusinessType.DELETE)
	@DeleteMapping("/{linkIds}")
    public AjaxResult remove(@PathVariable Long[] linkIds)
    {
        return toAjax(fsCourseLinkService.deleteFsCourseLinkByLinkIds(linkIds));
    }

    @PreAuthorize("@ss.hasPermi('course:courseLink:create')")
    @Log(title = "创建短链", businessType = BusinessType.UPDATE)
    @PutMapping("createLinkUrl")
    public R createLinkUrl(@RequestBody FsCourseLinkCreateParam param)
    {
//        LoginUser user = SecurityUtils.getLoginUser();
//        param.setCompanyId(user.);
        return fsCourseLinkService.createLinkUrl(param);
    }

}
