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.ExportItemVo;
import com.ruoyi.export.domain.bo.ExportItemBo;
import com.ruoyi.export.service.IExportItemService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 展示品
 *
 * @author ruoyi
 * @date 2025-07-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/export/item")
public class ExportItemController extends BaseController {

    private final IExportItemService iExportItemService;

    /**
     * 查询展示品列表
     */
    @GetMapping("/list")
    public TableDataInfo<ExportItemVo> list(ExportItemBo bo, PageQuery pageQuery) {
        return iExportItemService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出展示品列表
     */
    @Log(title = "展示品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ExportItemBo bo, HttpServletResponse response) {
        List<ExportItemVo> list = iExportItemService.queryList(bo);
        ExcelUtil.exportExcel(list, "展示品", ExportItemVo.class, response);
    }

    /**
     * 获取展示品详细信息
     *
     * @param itemId 主键
     */
    @GetMapping("/{itemId}")
    public R<ExportItemVo> getInfo(@NotNull(message = "主键不能为空")
                                   @PathVariable Long itemId) {
        return R.ok(iExportItemService.queryById(itemId));
    }

    /**
     * 新增展示品
     */
    @Log(title = "展示品", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ExportItemBo bo) {
        return toAjax(iExportItemService.insertByBo(bo));
    }

    /**
     * 修改展示品
     */
    @Log(title = "展示品", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ExportItemBo bo) {
        return toAjax(iExportItemService.updateByBo(bo));
    }

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