package com.muyu.server.controller;

import java.util.Arrays;
import java.util.List;
import javax.annotation.Resource;

import com.muyu.common.domain.WarnRule;
import com.muyu.server.service.WarnRuleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.domain.Result;

/**
 * 预警规则Controller
 *
 * @author sx
 * @date 2024-09-20
 */
@RestController
@RequestMapping("/rule")
@Tag(name = "预警规则管理",description = "预警规则管理")
@Log4j2
public class WarnRuleController extends BaseController
{
    @Resource
    private WarnRuleService warnRuleService;

    /**
     * 查询预警规则列表
     */
    @GetMapping("/selectWarnRuleRespList")
    @Operation(summary = "预警规则列表",description = "预警规则列表")
    public Result selectWarnRuleRespList()
    {
        return Result.success(warnRuleService.selectWarnRuleRespList());
    }

    /**
     * 获取预警规则详细信息
     */

    @GetMapping(value = "selectById/{id}")
    @Operation(summary = "根据ID查询预警规则信息",description = "根据ID查询预警规则信息")
    public Result<List<WarnRule>> selectById(@PathVariable("id") Long id)
    {
        return success(warnRuleService.selectWarnRuleById(id));
    }

    /**
     * 新增预警规则
     */

    @PostMapping("/addWarnRule")
    @Operation(summary = "新增预警规则",description = "新增预警规则")
    public Result<Integer> addWarnRule(@RequestBody WarnRule warnRule)
    {
        int i = warnRuleService.addWarnRule(warnRule);
        return i>0?Result.success():Result.error();
    }

    /**
     * 修改预警规则
     */

    @PostMapping("/updWarnRule")
    @Operation(summary = "修改预警规则",description = "修改预警规则")
    public Result updWarnRule(@RequestBody WarnRule warnRule)
    {
        int i = warnRuleService.updWarnRule(warnRule);
        return i>0?Result.success():Result.error();
    }

    /**
     * 删除预警规则
     */
	@DeleteMapping("/{ids}")
    @Operation(summary = "删除预警规则",description = "删除预警规则")
    public Result remove(@PathVariable("ids") Long[] ids)
    {
        warnRuleService.removeBatchByIds(Arrays.asList(ids));
        return success();
    }



    //根据策略ID查规则
    @GetMapping("/selectListByStrategyId/{strategyId}")
    @Operation(summary = "根据策略ID查询预警规则列表",description = "根据策略ID查询预警规则列表")
    public Result selectListByStrategyId(@PathVariable("strategyId") Long strategyId){
        return Result.success(warnRuleService.selectListByStrategyId(strategyId));
    }
}
