package com.ruoyi.system.controller;

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

import cn.dev33.satoken.annotation.SaIgnore;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.apache.http.HttpRequest;
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.system.domain.vo.ZsOperationGoodsVo;
import com.ruoyi.system.domain.bo.ZsOperationGoodsBo;
import com.ruoyi.system.service.IZsOperationGoodsService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品配置
 *
 * @author 王强
 * @date 2025-05-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/operationGoods")
public class ZsOperationGoodsController extends BaseController {

    private final IZsOperationGoodsService iZsOperationGoodsService;

    /**
     * 查询商品配置列表
     */
    @SaCheckPermission("system:operationGoods:list")
    @GetMapping("/list")
    public TableDataInfo<ZsOperationGoodsVo> list(ZsOperationGoodsBo bo, PageQuery pageQuery) {
        return iZsOperationGoodsService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询商品配置列表
     */
    @SaIgnore
    @GetMapping("/noVerifyList")
    public TableDataInfo<ZsOperationGoodsVo> listSpe(HttpRequest httpRequest, ZsOperationGoodsBo bo, PageQuery pageQuery) {

        return iZsOperationGoodsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出商品配置列表
     */
    @SaCheckPermission("system:operationGoods:export")
    @Log(title = "商品配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ZsOperationGoodsBo bo, HttpServletResponse response) {
        List<ZsOperationGoodsVo> list = iZsOperationGoodsService.queryList(bo);
        ExcelUtil.exportExcel(list, "商品配置", ZsOperationGoodsVo.class, response);
    }

    /**
     * 获取商品配置详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:operationGoods:query")
    @GetMapping("/{id}")
    public R<ZsOperationGoodsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iZsOperationGoodsService.queryById(id));
    }

    /**
     * 新增商品配置
     */
    @SaCheckPermission("system:operationGoods:add")
    @Log(title = "商品配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ZsOperationGoodsBo bo) {
        return toAjax(iZsOperationGoodsService.insertByBo(bo));
    }

    /**
     * 修改商品配置
     */
    @SaCheckPermission("system:operationGoods:edit")
    @Log(title = "商品配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ZsOperationGoodsBo bo) {
        return toAjax(iZsOperationGoodsService.updateByBo(bo));
    }

    /**
     * 删除商品配置
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:operationGoods:remove")
    @Log(title = "商品配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iZsOperationGoodsService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
