package com.ruoyi.system.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 cn.dev33.satoken.annotation.SaCheckPermission;
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.ZsProductVo;
import com.ruoyi.system.domain.bo.ZsProductBo;
import com.ruoyi.system.service.IZsProductService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 站点产品管理
 *
 * @author 王强
 * @date 2025-04-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/product")
public class ZsProductController extends BaseController {

    private final IZsProductService iZsProductService;

    /**
     * 查询站点产品管理列表
     */
    @SaCheckPermission("system:product:list")
    @GetMapping("/list")
    public TableDataInfo<ZsProductVo> list(ZsProductBo bo, PageQuery pageQuery) {
        return iZsProductService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出站点产品管理列表
     */
    @SaCheckPermission("system:product:export")
    @Log(title = "站点产品管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ZsProductBo bo, HttpServletResponse response) {
        List<ZsProductVo> list = iZsProductService.queryList(bo);
        ExcelUtil.exportExcel(list, "站点产品管理", ZsProductVo.class, response);
    }

    /**
     * 获取站点产品管理详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:product:query")
    @GetMapping("/{id}")
    public R<ZsProductVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iZsProductService.queryById(id));
    }

    /**
     * 新增站点产品管理
     */
    @SaCheckPermission("system:product:add")
    @Log(title = "站点产品管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ZsProductBo bo) {
        return toAjax(iZsProductService.insertByBo(bo));
    }

    /**
     * 修改站点产品管理
     */
    @SaCheckPermission("system:product:edit")
    @Log(title = "站点产品管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ZsProductBo bo) {
        return toAjax(iZsProductService.updateByBo(bo));
    }

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