package com.ruoyi.bid.controller;

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.bid.domain.BidSite;
import com.ruoyi.bid.service.IBidSiteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 常用网站Controller
 * 
 * @author ruoyi
 * @date 2025-12-09
 */
@RestController
@RequestMapping("/bid/site")
public class BidSiteController extends BaseController
{
    @Autowired
    private IBidSiteService bidSiteService;

    /**
     * 查询常用网站列表
     */
    @PreAuthorize("@ss.hasPermi('bid:site:list')")
    @GetMapping("/list")
    public TableDataInfo list(BidSite bidSite)
    {
        startPage();
        List<BidSite> list = bidSiteService.selectBidSiteList(bidSite);
        return getDataTable(list);
    }

    /**
     * 导出常用网站列表
     */
    @PreAuthorize("@ss.hasPermi('bid:site:export')")
    @Log(title = "常用网站", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BidSite bidSite)
    {
        List<BidSite> list = bidSiteService.selectBidSiteList(bidSite);
        ExcelUtil<BidSite> util = new ExcelUtil<BidSite>(BidSite.class);
        util.exportExcel(response, list, "常用网站数据");
    }

    /**
     * 获取常用网站详细信息
     */
    @PreAuthorize("@ss.hasPermi('bid:site:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bidSiteService.selectBidSiteById(id));
    }

    /**
     * 新增常用网站
     */
    @PreAuthorize("@ss.hasPermi('bid:site:add')")
    @Log(title = "常用网站", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BidSite bidSite)
    {
        return toAjax(bidSiteService.insertBidSite(bidSite));
    }
    /**
     * 新增常用网站
     */
    @PreAuthorize("@ss.hasPermi('bid:site:add')")
    @Log(title = "常用网站", businessType = BusinessType.INSERT)
    @PostMapping("/adds")
    public AjaxResult adds(@RequestBody List<BidSite> bidSites)
    {
        for (BidSite bidSite : bidSites) {
            bidSiteService.insertBidSite(bidSite);
        }
        return toAjax(1);
    }

    /**
     * 修改常用网站
     */
    @PreAuthorize("@ss.hasPermi('bid:site:edit')")
    @Log(title = "常用网站", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BidSite bidSite)
    {
        return toAjax(bidSiteService.updateBidSite(bidSite));
    }

    /**
     * 删除常用网站
     */
    @PreAuthorize("@ss.hasPermi('bid:site:remove')")
    @Log(title = "常用网站", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bidSiteService.deleteBidSiteByIds(ids));
    }
}
