package com.ruoyi.web.controller.hyperlink;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Hyperlink;
import com.ruoyi.system.service.IHyperlinkService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 超链接Controller
 *
 * @author boman
 * @date 2024-04-30
 */
@RestController
@RequestMapping("/system/hyperlink")
public class HyperlinkController extends BaseController
{
    @Autowired
    private IHyperlinkService hyperlinkService;

/**
 * 查询超链接列表
 */
@PreAuthorize("@ss.hasPermi('system:hyperlink:list')")
@GetMapping("/list")
    public TableDataInfo list(Hyperlink hyperlink)
    {
        startPage();
        List<Hyperlink> list = hyperlinkService.selectHyperlinkList(hyperlink);
        return getDataTable(list);
    }

    /**
     * 导出超链接列表
     */
    @PreAuthorize("@ss.hasPermi('system:hyperlink:export')")
    @Log(title = "超链接", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Hyperlink hyperlink)
    {
        List<Hyperlink> list = hyperlinkService.selectHyperlinkList(hyperlink);
        ExcelUtil<Hyperlink> util = new ExcelUtil<Hyperlink>(Hyperlink.class);
        util.exportExcel(response, list, "超链接数据");
    }

    /**
     * 获取超链接详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:hyperlink:query')")
    @GetMapping(value = "/{hyperlinkId}")
    public AjaxResult getInfo(@PathVariable("hyperlinkId") Long hyperlinkId)
    {
        return success(hyperlinkService.selectHyperlinkByHyperlinkId(hyperlinkId));
    }

    /**
     * 新增超链接
     */
    @PreAuthorize("@ss.hasPermi('system:hyperlink:add')")
    @Log(title = "超链接", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Hyperlink hyperlink)
    {
        return toAjax(hyperlinkService.insertHyperlink(hyperlink));
    }

    /**
     * 修改超链接
     */
    @PreAuthorize("@ss.hasPermi('system:hyperlink:edit')")
    @Log(title = "超链接", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody Hyperlink hyperlink)
    {
        return toAjax(hyperlinkService.updateHyperlink(hyperlink));
    }

    /**
     * 删除超链接
     */
    @PreAuthorize("@ss.hasPermi('system:hyperlink:remove')")
    @Log(title = "超链接", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{hyperlinkIds}")
    public AjaxResult remove(@PathVariable Long[] hyperlinkIds)
    {
        return toAjax(hyperlinkService.deleteHyperlinkByHyperlinkIds(hyperlinkIds));
    }
}
