package com.ruoyi.export.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.export.domain.vo.ExportCarouselVo;
import com.ruoyi.export.domain.bo.ExportCarouselBo;
import com.ruoyi.export.service.IExportCarouselService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 轮播图
 *
 * @author ruoyi
 * @date 2025-07-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/export/carousel")
public class ExportCarouselController extends BaseController {

    private final IExportCarouselService iExportCarouselService;

    /**
     * 查询轮播图列表
     */
    @GetMapping("/list")
    public TableDataInfo<ExportCarouselVo> list(ExportCarouselBo bo, PageQuery pageQuery) {
        return iExportCarouselService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出轮播图列表
     */
    @Log(title = "轮播图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ExportCarouselBo bo, HttpServletResponse response) {
        List<ExportCarouselVo> list = iExportCarouselService.queryList(bo);
        ExcelUtil.exportExcel(list, "轮播图", ExportCarouselVo.class, response);
    }

    /**
     * 获取轮播图详细信息
     *
     * @param carouselId 主键
     */
    @GetMapping("/{carouselId}")
    public R<ExportCarouselVo> getInfo(@NotNull(message = "主键不能为空")
                                       @PathVariable Long carouselId) {
        return R.ok(iExportCarouselService.queryById(carouselId));
    }

    /**
     * 新增轮播图
     */
    @Log(title = "轮播图", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ExportCarouselBo bo) {
        return toAjax(iExportCarouselService.insertByBo(bo));
    }

    /**
     * 修改轮播图
     */
    @Log(title = "轮播图", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ExportCarouselBo bo) {
        return toAjax(iExportCarouselService.updateByBo(bo));
    }

    /**
     * 删除轮播图
     *
     * @param carouselIds 主键串
     */
    @Log(title = "轮播图", businessType = BusinessType.DELETE)
    @DeleteMapping("/{carouselIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] carouselIds) {
        return toAjax(iExportCarouselService.deleteWithValidByIds(Arrays.asList(carouselIds), true));
    }
}
