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.HttpServletRequest;
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.ZsOperationWarnconfigVo;
import com.ruoyi.system.domain.bo.ZsOperationWarnconfigBo;
import com.ruoyi.system.service.IZsOperationWarnconfigService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预警配置
 *
 * @author 王强
 * @date 2025-05-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/operationWarnconfig")
public class ZsOperationWarnconfigController extends BaseController {

    private final IZsOperationWarnconfigService iZsOperationWarnconfigService;

    /**
     * 查询预警配置列表
     */
    @SaCheckPermission("system:operationWarnconfig:list")
    @GetMapping("/list")
    public TableDataInfo<ZsOperationWarnconfigVo> list(ZsOperationWarnconfigBo bo, PageQuery pageQuery) {
        return iZsOperationWarnconfigService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询预警配置列表
     */
    @SaIgnore
    @GetMapping("/noVerifyList")
    public TableDataInfo<ZsOperationWarnconfigVo> listspe(HttpServletRequest request, ZsOperationWarnconfigBo bo, PageQuery pageQuery) {
        //String secretKey = request.getHeader("secret_key");
        return iZsOperationWarnconfigService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出预警配置列表
     */
    @SaCheckPermission("system:operationWarnconfig:export")
    @Log(title = "预警配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ZsOperationWarnconfigBo bo, HttpServletResponse response) {
        List<ZsOperationWarnconfigVo> list = iZsOperationWarnconfigService.queryList(bo);
        ExcelUtil.exportExcel(list, "预警配置", ZsOperationWarnconfigVo.class, response);
    }

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

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

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

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