package com.ruoyi.logistics.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
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.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.logistics.domain.BizBanner;
import com.ruoyi.logistics.service.IBizBannerService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * PC-轮播图
 * 
 * @author RuiJing
 * @date 2026-02-05
 */
@RestController
@RequestMapping("/banner")
public class BizBannerController extends BaseController
{
    @Autowired
    private IBizBannerService bizBannerService;

    /**
     * 查询轮播图列表
     */
    @RequiresPermissions("logistics:banner:list")
    @GetMapping("/list")
    public TableDataInfo list(BizBanner bizBanner)
    {
        startPage();
        List<BizBanner> list = bizBannerService.selectBizBannerList(bizBanner);
        return getDataTable(list);
    }

    /**
     * 导出轮播图列表
     */
    @RequiresPermissions("logistics:banner:export")
    @Log(title = "轮播图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizBanner bizBanner)
    {
        List<BizBanner> list = bizBannerService.selectBizBannerList(bizBanner);
        ExcelUtil<BizBanner> util = new ExcelUtil<BizBanner>(BizBanner.class);
        util.exportExcel(response, list, "轮播图数据");
    }

    /**
     * 获取轮播图详细信息
     */
    @RequiresPermissions("logistics:banner:query")
    @GetMapping(value = "/{bannerId}")
    public AjaxResult getInfo(@PathVariable("bannerId") Long bannerId)
    {
        return success(bizBannerService.selectBizBannerByBannerId(bannerId));
    }

    /**
     * 新增轮播图
     */
    @RequiresPermissions("logistics:banner:add")
    @Log(title = "轮播图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizBanner bizBanner)
    {
        return toAjax(bizBannerService.insertBizBanner(bizBanner));
    }

    /**
     * 修改轮播图
     */
    @RequiresPermissions("logistics:banner:edit")
    @Log(title = "轮播图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizBanner bizBanner)
    {
        return toAjax(bizBannerService.updateBizBanner(bizBanner));
    }

    /**
     * 删除轮播图
     */
    @RequiresPermissions("logistics:banner:remove")
    @Log(title = "轮播图", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bannerIds}")
    public AjaxResult remove(@PathVariable Long[] bannerIds)
    {
        return toAjax(bizBannerService.deleteBizBannerByBannerIds(bannerIds));
    }


    /**
     * 首页-轮播图列表
     */
    @GetMapping("/listByType")
    public AjaxResult listByType()
    {
        BizBanner bizBanner = new BizBanner();
        bizBanner.setSysType("0");
        bizBanner.setIsActive("0");
        List<BizBanner> list = bizBannerService.selectBizBannerList(bizBanner);
        return success(list);
    }
}
