OpsSmsOnOffCtrl.java 4.02 KB
package com.ui.ctrl;

import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by craig.qin on 2017/10/20.
 * 运维平台的短信开关
 */
@Controller
@RequestMapping("/OpsSmsOnOff")
public class OpsSmsOnOffCtrl {

    @Autowired
    private HttpRestClient httpRestClient;

    /**
     * 跳转到 告警开关页面
     * @return
     */
    @RequestMapping("/toAlarmSwitch")
    public ModelAndView toAlarmSwitch(){
        ModelAndView mv = new ModelAndView("alarmgroup/alarmSwitch");
        BaseResponse<String> resp =  httpRestClient.defaultGet("/OpsSmsOnOff/getSmsSwitchValue", BaseResponse.class, null);
        mv.addObject("smsSwitchValue",resp.getMessage());

        resp = httpRestClient.defaultGet("/OpsSmsOnOff/getVoiceSmsSwitchValue", BaseResponse.class, null);
        mv.addObject("voiceSwitchValue",resp.getMessage());

        resp = httpRestClient.defaultGet("/OpsSmsOnOff/getDevSmsSwitchValue", BaseResponse.class, null);
        mv.addObject("devSmsSwitchValue",resp.getMessage());

        return mv;
    }

    /**
     *
     * @param switchName--开关名称
     * @param value--切换操作(off:关闭;on:打开)
     * @return
     */
    @RequestMapping("/switchAlarm")//切换告警状态
    @ResponseBody
     public BaseResponse switchAlarm(String switchName,String value){
        BaseResponse resp = null;
        if("smsSwitchValue".equals(switchName) ){
            resp = httpRestClient.defaultGet("/OpsSmsOnOff/turn?key=" + value, BaseResponse.class, null);
        }else if("voiceSwitchValue".equals(switchName)){
            resp = httpRestClient.defaultGet("/OpsSmsOnOff/turnVoice?key=" + value, BaseResponse.class, null);
        }else if("devSmsSwitchValue".equals(switchName)){
            resp = httpRestClient.defaultGet("/OpsSmsOnOff/turnDev?key=" + value, BaseResponse.class, null);
        }

        return resp;


    }


    //短信报警
    @RequestMapping("/turnOn")
    @ResponseBody
    public BaseResponse turnOn() {
        return httpRestClient.defaultGet("/OpsSmsOnOff/turn?key=on", BaseResponse.class, null);
    }

    @RequestMapping("/turnOff")
    @ResponseBody
    public BaseResponse turnOff() {
        return httpRestClient.defaultGet("/OpsSmsOnOff/turn?key=off", BaseResponse.class, null);
    }

    @RequestMapping("/getSmsSwitchValue")
    @ResponseBody
    public BaseResponse getSmsSwitchValue() {
        return httpRestClient.defaultGet("/OpsSmsOnOff/getSmsSwitchValue", BaseResponse.class, null);
    }

    ///语音报警
    @RequestMapping("/turnVoiceOn")
    @ResponseBody
    public BaseResponse turnVoiceOn() {
        return httpRestClient.defaultGet("/OpsSmsOnOff/turnVoice?key=on", BaseResponse.class, null);
    }

    @RequestMapping("/turnVoiceOff")
    @ResponseBody
    public BaseResponse turnVoiceOff() {
        return httpRestClient.defaultGet("/OpsSmsOnOff/turnVoice?key=off", BaseResponse.class, null);
    }

    @RequestMapping("/getVoiceSmsSwitchValue")
    @ResponseBody
    public BaseResponse getVoiceSmsSwitchValue() {
        return httpRestClient.defaultGet("/OpsSmsOnOff/getVoiceSmsSwitchValue", BaseResponse.class, null);
    }


    //短信报警:dev.ops
    @RequestMapping("/turnDevOn")
    @ResponseBody
    public BaseResponse turnDevOn() {
        return httpRestClient.defaultGet("/OpsSmsOnOff/turnDev?key=on", BaseResponse.class, null);
    }

    @RequestMapping("/turnDevOff")
    @ResponseBody
    public BaseResponse turnDevOff() {
        return httpRestClient.defaultGet("/OpsSmsOnOff/turnDev?key=off", BaseResponse.class, null);
    }

    @RequestMapping("/getDevSmsSwitchValue")
    @ResponseBody
    public BaseResponse getDevSmsSwitchValue() {
        return httpRestClient.defaultGet("/OpsSmsOnOff/getDevSmsSwitchValue", BaseResponse.class, null);
    }
}