package org.dromara.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.domain.vo.SenMonitorTaskAlgorithmsVo;
import org.dromara.domain.bo.SenMonitorTaskAlgorithmsBo;
import org.dromara.service.ISenMonitorTaskAlgorithmsService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 监控点任务-算法配置
 *
 * @author luogang
 * @date 2024-09-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/dromara/monitorTaskAlgorithms")
public class SenMonitorTaskAlgorithmsController extends BaseController {

    private final ISenMonitorTaskAlgorithmsService senMonitorTaskAlgorithmsService;

    /**
     * 查询监控点任务-算法配置列表
     */
    @SaCheckPermission("dromara:monitorTaskAlgorithms:list")
    @GetMapping("/list")
    public TableDataInfo<SenMonitorTaskAlgorithmsVo> list(SenMonitorTaskAlgorithmsBo bo, PageQuery pageQuery) {
        return senMonitorTaskAlgorithmsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出监控点任务-算法配置列表
     */
    @SaCheckPermission("dromara:monitorTaskAlgorithms:export")
    @Log(title = "监控点任务-算法配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SenMonitorTaskAlgorithmsBo bo, HttpServletResponse response) {
        List<SenMonitorTaskAlgorithmsVo> list = senMonitorTaskAlgorithmsService.queryList(bo);
        ExcelUtil.exportExcel(list, "监控点任务-算法配置", SenMonitorTaskAlgorithmsVo.class, response);
    }

    /**
     * 获取监控点任务-算法配置详细信息
     *
     * @param taskId 主键
     */
    @SaCheckPermission("dromara:monitorTaskAlgorithms:query")
    @GetMapping("/{taskId}")
    public R<SenMonitorTaskAlgorithmsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long taskId) {
        return R.ok(senMonitorTaskAlgorithmsService.queryById(taskId));
    }

    /**
     * 新增监控点任务-算法配置
     */
    @SaCheckPermission("dromara:monitorTaskAlgorithms:add")
    @Log(title = "监控点任务-算法配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SenMonitorTaskAlgorithmsBo bo) {
        return toAjax(senMonitorTaskAlgorithmsService.insertByBo(bo));
    }

    /**
     * 修改监控点任务-算法配置
     */
    @SaCheckPermission("dromara:monitorTaskAlgorithms:edit")
    @Log(title = "监控点任务-算法配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SenMonitorTaskAlgorithmsBo bo) {
        return toAjax(senMonitorTaskAlgorithmsService.updateByBo(bo));
    }

    /**
     * 删除监控点任务-算法配置
     *
     * @param taskIds 主键串
     */
    @SaCheckPermission("dromara:monitorTaskAlgorithms:remove")
    @Log(title = "监控点任务-算法配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{taskIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] taskIds) {
        return toAjax(senMonitorTaskAlgorithmsService.deleteWithValidByIds(List.of(taskIds), true));
    }
}
