Authored by qinchao

报警添加开发

@@ -16,9 +16,17 @@ public class OpsSmsOnOffController { @@ -16,9 +16,17 @@ public class OpsSmsOnOffController {
16 @Autowired 16 @Autowired
17 SmsLogService smsLogService; 17 SmsLogService smsLogService;
18 18
  19 + /// 短信开发
19 @RequestMapping("/turn") 20 @RequestMapping("/turn")
20 @ResponseBody 21 @ResponseBody
21 public BaseResponse turn(String key){ 22 public BaseResponse turn(String key){
22 return smsLogService.setSmsTurnOnOff(key); 23 return smsLogService.setSmsTurnOnOff(key);
23 } 24 }
  25 +
  26 + // 语音电话开关
  27 + @RequestMapping("/turnVoice")
  28 + @ResponseBody
  29 + public BaseResponse turnVoice(String key){
  30 + return smsLogService.setVoiceSmsTurnOnOff(key);
  31 + }
24 } 32 }
@@ -13,4 +13,6 @@ public interface SmsLogService { @@ -13,4 +13,6 @@ public interface SmsLogService {
13 PageResponse<SMSLogs> getSmsLogs(PageRequest req); 13 PageResponse<SMSLogs> getSmsLogs(PageRequest req);
14 14
15 BaseResponse setSmsTurnOnOff(String key); 15 BaseResponse setSmsTurnOnOff(String key);
  16 +
  17 + BaseResponse setVoiceSmsTurnOnOff(String key);
16 } 18 }
@@ -8,6 +8,7 @@ import com.monitor.model.response.BaseResponse; @@ -8,6 +8,7 @@ import com.monitor.model.response.BaseResponse;
8 import com.monitor.model.response.PageResponse; 8 import com.monitor.model.response.PageResponse;
9 import com.monitor.mysql.mapper.SMSLogsMapper; 9 import com.monitor.mysql.mapper.SMSLogsMapper;
10 import com.monitor.other.sms.service.SmsLogService; 10 import com.monitor.other.sms.service.SmsLogService;
  11 +import org.apache.zookeeper.data.Stat;
11 import org.slf4j.Logger; 12 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory; 13 import org.slf4j.LoggerFactory;
13 import org.springframework.beans.factory.annotation.Autowired; 14 import org.springframework.beans.factory.annotation.Autowired;
@@ -31,6 +32,7 @@ public class SmsLogServiceImpl implements SmsLogService { @@ -31,6 +32,7 @@ public class SmsLogServiceImpl implements SmsLogService {
31 32
32 private String ZK_PATH = "/yh/config/"; 33 private String ZK_PATH = "/yh/config/";
33 private String smsSendSwitch="ops.sendsms.open"; 34 private String smsSendSwitch="ops.sendsms.open";
  35 + private String smsSendVoiceSwitch="ops.sendvoicesms.open";
34 36
35 public BaseResponse setSmsTurnOnOff(String key){ 37 public BaseResponse setSmsTurnOnOff(String key){
36 BaseResponse res=null; 38 BaseResponse res=null;
@@ -39,8 +41,13 @@ public class SmsLogServiceImpl implements SmsLogService { @@ -39,8 +41,13 @@ public class SmsLogServiceImpl implements SmsLogService {
39 if("off".equals(key)){ 41 if("off".equals(key)){
40 value="false"; 42 value="false";
41 } 43 }
42 - zkClient.getCuratorFramework().setData().forPath(ZK_PATH + smsSendSwitch,"false".getBytes("UTF-8"));  
43 - res= new BaseResponse(200,"ok"); 44 + Stat stat=zkClient.getCuratorFramework().checkExists().forPath(ZK_PATH + smsSendSwitch);
  45 + // Stat 就是对zonde所有属性的一个映射, stat=null表示节点不存在!
  46 + if(stat==null){
  47 + zkClient.getCuratorFramework().create().forPath(ZK_PATH + smsSendSwitch);
  48 + }
  49 + zkClient.getCuratorFramework().setData().forPath(ZK_PATH + smsSendSwitch,value.getBytes("UTF-8"));
  50 + res= new BaseResponse(200,"sms send is "+value);
44 } catch (Exception e) { 51 } catch (Exception e) {
45 logger.error("set ZK_PATH smsSendSwitch error",e); 52 logger.error("set ZK_PATH smsSendSwitch error",e);
46 res=new BaseResponse("set zk data error"); 53 res=new BaseResponse("set zk data error");
@@ -48,6 +55,27 @@ public class SmsLogServiceImpl implements SmsLogService { @@ -48,6 +55,27 @@ public class SmsLogServiceImpl implements SmsLogService {
48 return res; 55 return res;
49 } 56 }
50 57
  58 + public BaseResponse setVoiceSmsTurnOnOff(String key){
  59 + BaseResponse res=null;
  60 + try{
  61 + String value="true";
  62 + if("off".equals(key)){
  63 + value="false";
  64 + }
  65 + Stat stat=zkClient.getCuratorFramework().checkExists().forPath(ZK_PATH + smsSendVoiceSwitch);
  66 + // Stat 就是对zonde所有属性的一个映射, stat=null表示节点不存在!
  67 + if(stat==null){
  68 + zkClient.getCuratorFramework().create().forPath(ZK_PATH + smsSendVoiceSwitch);
  69 + }
  70 + zkClient.getCuratorFramework().setData().forPath(ZK_PATH + smsSendVoiceSwitch,value.getBytes("UTF-8"));
  71 + res= new BaseResponse(200,"sms voice send is "+value);
  72 + } catch (Exception e) {
  73 + logger.error("set ZK_PATH smsVoiceSendSwitch error",e);
  74 + res=new BaseResponse("set zk data error");
  75 + }
  76 + return res;
  77 + }
  78 +
51 public PageResponse<SMSLogs> getSmsLogs(PageRequest req){ 79 public PageResponse<SMSLogs> getSmsLogs(PageRequest req){
52 // 组装分页对象 80 // 组装分页对象
53 PageBean page = PageBean.initPageInfo(req.getCurrentPage(), 81 PageBean page = PageBean.initPageInfo(req.getCurrentPage(),