package com.ruoyi.hezhi.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hezhi.domain.TbLink;
import com.ruoyi.hezhi.service.ITbLinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 资源关联Controller
 *
 * @author ruoyi
 * @date 2024-10-22
 */
@RestController
@RequestMapping("/hezhi/link")
public class TbLinkController extends BaseController
{
    @Autowired
    private ITbLinkService tbLinkService;

    /**
     * 查询资源关联列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:link:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbLink tbLink)
    {
        startPage();
        List<TbLink> list = tbLinkService.selectTbLinkList(tbLink);
        return getDataTable(list);
    }

    /**
     * 导出资源关联列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:link:export')")
    @Log(title = "资源关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbLink tbLink)
    {
        List<TbLink> list = tbLinkService.selectTbLinkList(tbLink);
        ExcelUtil<TbLink> util = new ExcelUtil<TbLink>(TbLink.class);
        util.exportExcel(response, list, "资源关联数据");
    }

    /**
     * 获取资源关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:link:query')")
    @GetMapping(value = "/{linkId}")
    public AjaxResult getInfo(@PathVariable("linkId") Long linkId)
    {
        return success(tbLinkService.selectTbLinkByLinkId(linkId));
    }

    /**
     * 新增资源关联
     */
    @PreAuthorize("@ss.hasPermi('hezhi:link:add')")
    @Log(title = "资源关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbLink tbLink)
    {
        return toAjax(tbLinkService.insertTbLink(tbLink));
    }

    /**
     * 修改资源关联
     */
    @PreAuthorize("@ss.hasPermi('hezhi:link:edit')")
    @Log(title = "资源关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbLink tbLink)
    {
        return toAjax(tbLinkService.updateTbLink(tbLink));
    }

    /**
     * 删除资源关联
     */
    @PreAuthorize("@ss.hasPermi('hezhi:link:remove')")
    @Log(title = "资源关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{linkIds}")
    public AjaxResult remove(@PathVariable Long[] linkIds)
    {
        return toAjax(tbLinkService.deleteTbLinkByLinkIds(linkIds));
    }

    /**
     * 查询评价机构与课程关联列表
     */
    @GetMapping("/listLinkEvaluateAgencyCourse")
    public TableDataInfo listLinkEvaluateAgencyCourse(TbLink tbLink)
    {
        startPage();
        List<TbLink> list = tbLinkService.listLinkEvaluateAgencyCourse(tbLink);
        return getDataTable(list);
    }

    /**
     * 查询直播与老师关联列表
     */
    @GetMapping("/listLinkLiveBroadcastTeacher")
    public TableDataInfo listLinkLiveBroadcastTeacher(TbLink tbLink)
    {
        startPage();
        List<TbLink> list = tbLinkService.listLinkLiveBroadcastTeacher(tbLink);
        return getDataTable(list);
    }
}
