package org.dromara.controller.checkPoint;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
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.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.domain.checkPoint.bo.CheckPointManageBo;
import org.dromara.domain.checkPoint.vo.CheckPointManageVo;
import org.dromara.service.ICheckPointManageService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 巡更点管理
 *
 * @author boman
 * @date 2025-04-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wuYe/checkPointManage")
public class CheckPointManageController extends BaseController {

    private final ICheckPointManageService checkPointManageService;

    /**
     * 查询巡更点管理列表
     */
    @SaCheckPermission("wuYe:checkPointManage:list")
    @GetMapping("/list")
    public TableDataInfo<CheckPointManageVo> list(CheckPointManageBo bo, PageQuery pageQuery) {
        return checkPointManageService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出巡更点管理列表
     */
    @SaCheckPermission("wuYe:checkPointManage:export")
    @Log(title = "巡更点管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(CheckPointManageBo bo, HttpServletResponse response) {
        List<CheckPointManageVo> list = checkPointManageService.queryList(bo);
        ExcelUtil.exportExcel(list, "巡更点管理", CheckPointManageVo.class, response);
    }

    /**
     * 获取巡更点管理详细信息
     *
     * @param checkPointManageId 主键
     */
    @SaCheckPermission("wuYe:checkPointManage:query")
    @GetMapping("/{checkPointManageId}")
    public R<CheckPointManageVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long checkPointManageId) {
        return R.ok(checkPointManageService.queryById(checkPointManageId));
    }

    /**
     * 新增巡更点管理
     */
    @SaCheckPermission("wuYe:checkPointManage:add")
    @Log(title = "巡更点管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody CheckPointManageBo bo) {
        return toAjax(checkPointManageService.insertByBo(bo));
    }

    /**
     * 批量新增巡更点管理
     */
    @SaCheckPermission("wuYe:checkPointManage:addList")
    @PostMapping("/addList")
    public R<Void> addList( @RequestBody CheckPointManageBo bo) {
        return toAjax(checkPointManageService.batchCheckPointManage(bo.getCheckPointManageList()));
    }

    /**
     * 修改巡更点管理
     */
    @SaCheckPermission("wuYe:checkPointManage:edit")
    @Log(title = "巡更点管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/put")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody CheckPointManageBo bo) {
        return toAjax(checkPointManageService.updateByBo(bo));
    }

    /**
     * 删除巡更点管理
     *
     * @param checkPointManageIds 主键串
     */
    @SaCheckPermission("wuYe:checkPointManage:remove")
    @Log(title = "巡更点管理", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{checkPointManageIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] checkPointManageIds) {
        return toAjax(checkPointManageService.deleteWithValidByIds(List.of(checkPointManageIds), true));
    }
}
