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.DateUtils;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.course.domain.FsUserTalent;
import com.fs.course.service.IFsUserTalentService;
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-31
 */
@RestController
@RequestMapping("/course/userTalent")
public class FsUserTalentController extends BaseController
{
    @Autowired
    private IFsUserTalentService fsUserTalentService;

    /**
     * 查询达人列表
     */
    @PreAuthorize("@ss.hasPermi('course:userTalent:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsUserTalent fsUserTalent)
    {
        startPage();
        List<FsUserTalent> list = fsUserTalentService.selectFsUserTalentList(fsUserTalent);
        return getDataTable(list);
    }

    /**
     * 导出达人列表
     */
    @PreAuthorize("@ss.hasPermi('course:userTalent:export')")
    @Log(title = "达人", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsUserTalent fsUserTalent)
    {
        List<FsUserTalent> list = fsUserTalentService.selectFsUserTalentList(fsUserTalent);
        ExcelUtil<FsUserTalent> util = new ExcelUtil<FsUserTalent>(FsUserTalent.class);
        return util.exportExcel(list, "达人数据");
    }

    /**
     * 获取达人详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:userTalent:query')")
    @GetMapping(value = "/{talentId}")
    public AjaxResult getInfo(@PathVariable("talentId") Long talentId)
    {
        return AjaxResult.success(fsUserTalentService.selectFsUserTalentByTalentId(talentId));
    }

    /**
     * 新增达人
     */
    @PreAuthorize("@ss.hasPermi('course:userTalent:add')")
    @Log(title = "达人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsUserTalent fsUserTalent)
    {
        return toAjax(fsUserTalentService.insertFsUserTalent(fsUserTalent));
    }

    /**
     * 修改达人
     */
    @PreAuthorize("@ss.hasPermi('course:userTalent:edit')")
    @Log(title = "修改达人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsUserTalent fsUserTalent)
    {
        fsUserTalent.setUpdateTime(DateUtils.getNowDate());
        return toAjax(fsUserTalentService.updateFsUserTalent(fsUserTalent));
    }

    /**
     * 审核达人
     */
    @PreAuthorize("@ss.hasPermi('course:userTalent:audit')")
    @Log(title = "审核达人", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public AjaxResult auditing(@RequestBody FsUserTalent fsUserTalent)
    {
        fsUserTalent.setAuditTime(DateUtils.getNowDate());
        return toAjax(fsUserTalentService.updateFsUserTalent(fsUserTalent));
    }

    /**
     * 删除达人
     */
    @PreAuthorize("@ss.hasPermi('course:userTalent:remove')")
    @Log(title = "达人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{talentIds}")
    public AjaxResult remove(@PathVariable Long[] talentIds)
    {
        return toAjax(fsUserTalentService.deleteFsUserTalentByTalentIds(talentIds));
    }

    @GetMapping("/listBySearch")
    public R listBySearCh(FsUserTalent fsUserTalent)
    {
        List<FsUserTalent> list = fsUserTalentService.selectFsUserTalentList(fsUserTalent);
        return R.ok().put("data",list);
    }
}
