package org.dromara.shebei.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.shebei.domain.vo.OpsSbLiebiaoVo;
import org.dromara.shebei.domain.bo.OpsSbLiebiaoBo;
import org.dromara.shebei.service.IOpsSbLiebiaoService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 运维-设备管理-设备列
 * 前端访问路由地址为:/shebei/sbLiebiao
 *
 * @author LionLi
 * @date 2025-10-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/sbLiebiao")
public class OpsSbLiebiaoController extends BaseController {

    private final IOpsSbLiebiaoService opsSbLiebiaoService;

    /**
     * 查询运维-设备管理-设备列列表
     */
    @SaCheckPermission("shebei:sbLiebiao:list")
    @GetMapping("/list")
    public TableDataInfo<OpsSbLiebiaoVo> list(OpsSbLiebiaoBo bo, PageQuery pageQuery) {
        return opsSbLiebiaoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出运维-设备管理-设备列列表
     */
    @SaCheckPermission("shebei:sbLiebiao:export")
    @Log(title = "运维-设备管理-设备列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OpsSbLiebiaoBo bo, HttpServletResponse response) {
        List<OpsSbLiebiaoVo> list = opsSbLiebiaoService.queryList(bo);
        ExcelUtil.exportExcel(list, "运维-设备管理-设备列", OpsSbLiebiaoVo.class, response);
    }

    /**
     * 获取运维-设备管理-设备列详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("shebei:sbLiebiao:query")
    @GetMapping("/{id}")
    public R<OpsSbLiebiaoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable("id") Long id) {
        return R.ok(opsSbLiebiaoService.queryById(id));
    }

    /**
     * 新增运维-设备管理-设备列
     */
    @SaCheckPermission("shebei:sbLiebiao:add")
    @Log(title = "运维-设备管理-设备列", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OpsSbLiebiaoBo bo) {
        return toAjax(opsSbLiebiaoService.insertByBo(bo));
    }

    /**
     * 修改运维-设备管理-设备列
     */
    @SaCheckPermission("shebei:sbLiebiao:edit")
    @Log(title = "运维-设备管理-设备列", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OpsSbLiebiaoBo bo) {
        return toAjax(opsSbLiebiaoService.updateByBo(bo));
    }

    /**
     * 删除运维-设备管理-设备列
     *
     * @param ids 主键串
     */
    @SaCheckPermission("shebei:sbLiebiao:remove")
    @Log(title = "运维-设备管理-设备列", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable("ids") Long[] ids) {
        return toAjax(opsSbLiebiaoService.deleteWithValidByIds(List.of(ids), true));
    }
}
