package com.muyu.controller;

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

import com.muyu.domain.resp.WarnRuleResp;
import com.muyu.service.WarnRuleService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
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;
import com.muyu.domain.WarnRule;

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

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

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

    @GetMapping(value = "selectById/{id}")
    public Result<List<WarnRule>> selectById(@PathVariable("id") Long id)
    {
        return success(warnRuleService.selectWarnRuleById(id));
    }

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

    @PostMapping("/addWarnRule")
    public Result<Integer> addWarnRule(@RequestBody WarnRule warnRule)
    {
        int i = warnRuleService.addWarnRule(warnRule);
        return i>0?Result.success():Result.error();
    }

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

    @PostMapping("/updWarnRule")
    public Result updWarnRule(@RequestBody WarnRule warnRule)
    {
        int i = warnRuleService.updWarnRule(warnRule);
        return i>0?Result.success():Result.error();
    }

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



    //根据策略ID查规则
    @GetMapping("/selectListByStrategyId/{strategyId}")
    public Result selectListByStrategyId(@PathVariable("strategyId") Long strategyId){
        return Result.success(warnRuleService.selectListByStrategyId(strategyId));
    }
}
