package com.ruoyi.web.controller.system;

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.FriendLink;
import com.ruoyi.system.service.IFriendLinkService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 友链导航Controller
 * 
 * @author boman
 * @date 2021-12-29
 */
@RestController
@RequestMapping("/system/friendLink")
public class FriendLinkController extends BaseController
{
    @Autowired
    private IFriendLinkService friendLinkService;

    /**
     * 查询友链导航列表
     */
    @PreAuthorize("@ss.hasPermi('system:friendLink:list')")
    @GetMapping("/list")
    public TableDataInfo list(FriendLink friendLink)
    {
        startPage();
        List<FriendLink> list = friendLinkService.selectFriendLinkList(friendLink);
        return getDataTable(list);
    }

    /**
     * 导出友链导航列表
     */
    @PreAuthorize("@ss.hasPermi('system:friendLink:export')")
    @Log(title = "友链导航", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FriendLink friendLink)
    {
        List<FriendLink> list = friendLinkService.selectFriendLinkList(friendLink);
        ExcelUtil<FriendLink> util = new ExcelUtil<FriendLink>(FriendLink.class);
        util.exportExcel(response, list, "友链导航数据");
    }

    /**
     * 获取友链导航详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:friendLink:query')")
    @GetMapping(value = "/{linkId}")
    public AjaxResult getInfo(@PathVariable("linkId") Long linkId)
    {
        return AjaxResult.success(friendLinkService.selectFriendLinkByLinkId(linkId));
    }

    /**
     * 新增友链导航
     */
    @PreAuthorize("@ss.hasPermi('system:friendLink:add')")
    @Log(title = "友链导航", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FriendLink friendLink)
    {
        friendLink.setCreateBy(getUsername());
        return toAjax(friendLinkService.insertFriendLink(friendLink));
    }

    /**
     * 修改友链导航
     */
    @PreAuthorize("@ss.hasPermi('system:friendLink:edit')")
    @Log(title = "友链导航", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FriendLink friendLink)
    {
        friendLink.setUpdateBy(getUsername());
        return toAjax(friendLinkService.updateFriendLink(friendLink));
    }

    /**
     * 删除友链导航
     */
    @PreAuthorize("@ss.hasPermi('system:friendLink:remove')")
    @Log(title = "友链导航", businessType = BusinessType.DELETE)
	@DeleteMapping("/{linkIds}")
    public AjaxResult remove(@PathVariable Long[] linkIds)
    {
        return toAjax(friendLinkService.deleteFriendLinkByLinkIds(linkIds));
    }
}
