package com.zcxk.rmcp.web.controller;


import com.zcxk.core.common.pojo.AjaxMessage;
import com.zcxk.core.mysql.pageing.Pagination;
import com.zcxk.rmcp.api.dto.alarm.AlarmRuleDto;
import com.zcxk.rmcp.api.dto.alarm.AlarmRulePageDto;
import com.zcxk.rmcp.api.dto.alarm.ConfigDataDto;
import com.zcxk.rmcp.api.dto.alarm.RuleMeasuringDto;
import com.zcxk.rmcp.web.service.AlarmRuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 * @author heyumin
 * @date 2021-07-30 9:44
 */
@Controller
@ResponseBody
@RequestMapping("alarmRule")
@Api(tags  = "规则管理")
public class AlarmRuleController {

    @Autowired
    private AlarmRuleService deviceAlarmRuleService;

    @PostMapping ("/getPage")
    @ApiOperation(value = "查询异常规则列表")
    public AjaxMessage<Pagination<AlarmRuleDto>> getList(
             @RequestBody AlarmRulePageDto alarmRulePageDto
            ) {
        Pagination<AlarmRuleDto> list = deviceAlarmRuleService.getList(alarmRulePageDto);
        return AjaxMessage.success(list);
    }

    @PostMapping("add")
    @ApiOperation(value = "添加规则")
    public AjaxMessage <Void>add(
            @ApiParam(value = "规则", required = true) @RequestBody AlarmRuleDto deviceAlarmRule
    ) {
        deviceAlarmRuleService.add(deviceAlarmRule);
        return AjaxMessage.success();
    }

    @PostMapping("edit")
    @ApiOperation(value = "编辑规则")
    public AjaxMessage <Void> edit(
            @ApiParam(value = "规则", required = true) @RequestBody AlarmRuleDto deviceAlarmRule
    ) {
        deviceAlarmRuleService.edit(deviceAlarmRule);
        return AjaxMessage.success();
    }

    @PostMapping("delete")
    @ApiOperation(value = "删除规则")
    public AjaxMessage  <Void>delete(
            @ApiParam(value = "规则id", required = true) @RequestBody List<Integer>ids
    ) {
        deviceAlarmRuleService.delete(ids);
        return AjaxMessage.success();
    }

    @PostMapping("deleteAll")
    @ApiOperation(value = "删除规则")
    public AjaxMessage <Void> deleteAll(@RequestParam Integer alarmTypeId) {
        deviceAlarmRuleService.deleteAll(alarmTypeId);
        return AjaxMessage.success();
    }

    @GetMapping("/getRuleMeasuringList")
    @ApiOperation(value = "查询规则的测点列表")
    public AjaxMessage<List<RuleMeasuringDto>> getRuleMeasuringList(
            @ApiParam(value = "异常类型id", required = true) @RequestParam  Integer deviceTypeId
    ) {
        List<RuleMeasuringDto> list = deviceAlarmRuleService.getRuleMeasuringList(deviceTypeId);
        return AjaxMessage.success(list);
    }

    @GetMapping("/getMeasuringOptionList")
    @ApiOperation(value = "查询测点的选择项目")
    public AjaxMessage<List<ConfigDataDto>> getMeasuringOptionList(
            @ApiParam(value = "异常类型id", required = true)@RequestParam  Integer deviceTypeId,
            @ApiParam(value = "测点id", required = true) @RequestParam Integer measuringId
    ) {
        List<ConfigDataDto> list = deviceAlarmRuleService.getMeasuringOptionList(deviceTypeId, measuringId);
        return AjaxMessage.success(list);
    }
}
