Showing
5 changed files
with
69 additions
and
6 deletions
@@ -7,7 +7,7 @@ import java.io.UnsupportedEncodingException; | @@ -7,7 +7,7 @@ import java.io.UnsupportedEncodingException; | ||
7 | */ | 7 | */ |
8 | public interface VoiceMsgService { | 8 | public interface VoiceMsgService { |
9 | 9 | ||
10 | - void sendVoice(String mobile) throws UnsupportedEncodingException; | 10 | + //void sendVoice(String mobile) throws UnsupportedEncodingException; |
11 | 11 | ||
12 | void sendVoiceAlarm(String mobile,String content) throws UnsupportedEncodingException; | 12 | void sendVoiceAlarm(String mobile,String content) throws UnsupportedEncodingException; |
13 | 13 |
@@ -5,10 +5,12 @@ import com.monitor.common.config.SendsmsConfig; | @@ -5,10 +5,12 @@ import com.monitor.common.config.SendsmsConfig; | ||
5 | import com.monitor.common.service.HttpRestClientService; | 5 | import com.monitor.common.service.HttpRestClientService; |
6 | import com.monitor.common.service.VoiceMsgService; | 6 | import com.monitor.common.service.VoiceMsgService; |
7 | import com.monitor.common.util.MD5Util; | 7 | import com.monitor.common.util.MD5Util; |
8 | +import com.monitor.common.util.ZkClientUtil; | ||
8 | import com.monitor.influxdb.contants.InfluxDBContants; | 9 | import com.monitor.influxdb.contants.InfluxDBContants; |
9 | import com.monitor.influxdb.mapper.MonitorAlarmMapper; | 10 | import com.monitor.influxdb.mapper.MonitorAlarmMapper; |
10 | import com.monitor.model.domain.VoiceSms; | 11 | import com.monitor.model.domain.VoiceSms; |
11 | import com.monitor.model.domain.VoiceSmsNotice; | 12 | import com.monitor.model.domain.VoiceSmsNotice; |
13 | +import org.apache.commons.lang.StringUtils; | ||
12 | import org.slf4j.Logger; | 14 | import org.slf4j.Logger; |
13 | import org.slf4j.LoggerFactory; | 15 | import org.slf4j.LoggerFactory; |
14 | import org.springframework.beans.factory.annotation.Autowired; | 16 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -31,9 +33,15 @@ public class VoiceMsgServiceImpl implements VoiceMsgService { | @@ -31,9 +33,15 @@ public class VoiceMsgServiceImpl implements VoiceMsgService { | ||
31 | @Autowired | 33 | @Autowired |
32 | private SendsmsConfig sendsmsConfig; | 34 | private SendsmsConfig sendsmsConfig; |
33 | 35 | ||
36 | + @Autowired | ||
37 | + private ZkClientUtil zkClient; | ||
38 | + | ||
34 | public final Logger DEBUG = LoggerFactory.getLogger(getClass()); | 39 | public final Logger DEBUG = LoggerFactory.getLogger(getClass()); |
35 | 40 | ||
36 | - @Override | 41 | + private String ZK_PATH = "/yh/config/"; |
42 | + private String smsSendVoiceSwitch="ops.sendvoicesms.open"; | ||
43 | + | ||
44 | + /* @Override | ||
37 | public void sendVoice(String mobile) throws UnsupportedEncodingException { | 45 | public void sendVoice(String mobile) throws UnsupportedEncodingException { |
38 | 46 | ||
39 | try { | 47 | try { |
@@ -57,11 +65,23 @@ public class VoiceMsgServiceImpl implements VoiceMsgService { | @@ -57,11 +65,23 @@ public class VoiceMsgServiceImpl implements VoiceMsgService { | ||
57 | } | 65 | } |
58 | 66 | ||
59 | 67 | ||
60 | - } | 68 | + }*/ |
61 | 69 | ||
62 | 70 | ||
63 | @Override | 71 | @Override |
64 | public void sendVoiceAlarm(String mobile,String content) throws UnsupportedEncodingException { | 72 | public void sendVoiceAlarm(String mobile,String content) throws UnsupportedEncodingException { |
73 | + //根据zk的开关判断是否需要发送数据 | ||
74 | + String open=""; | ||
75 | + try{ | ||
76 | + //zkClient.getCuratorFramework().setData().forPath(ZK_PATH + smsSendSwitch,"true".getBytes("UTF-8")); | ||
77 | + open = new String(zkClient.getCuratorFramework().getData().forPath(ZK_PATH + smsSendVoiceSwitch)); | ||
78 | + } catch (Exception e) { | ||
79 | + DEBUG.error("Send msg type get ZK_PATH smsVoiceSendSwitch error",e); | ||
80 | + } | ||
81 | + if(StringUtils.isNotBlank(open)&&"false".equals(open)){ | ||
82 | + return ;//开关关掉了,不再发送语音 | ||
83 | + } | ||
84 | + | ||
65 | try { | 85 | try { |
66 | VoiceSmsNotice voiceSms = new VoiceSmsNotice(); | 86 | VoiceSmsNotice voiceSms = new VoiceSmsNotice(); |
67 | String promptfile = "请及时处理故障:紧急故障"; | 87 | String promptfile = "请及时处理故障:紧急故障"; |
@@ -77,10 +97,9 @@ public class VoiceMsgServiceImpl implements VoiceMsgService { | @@ -77,10 +97,9 @@ public class VoiceMsgServiceImpl implements VoiceMsgService { | ||
77 | voiceSms.setSig(MD5Util.encryption(sendsmsConfig.getQcloudSmsKey() + str)); | 97 | voiceSms.setSig(MD5Util.encryption(sendsmsConfig.getQcloudSmsKey() + str)); |
78 | voiceSms.setTel(tel); | 98 | voiceSms.setTel(tel); |
79 | DEBUG.info("send voice notice msg,content:{}", JSON.toJSONString(voiceSms)); | 99 | DEBUG.info("send voice notice msg,content:{}", JSON.toJSONString(voiceSms)); |
80 | - // String result = httpRestClientService.doPostStringJson(sendsmsConfig.getQcloudVoiceUrl(), JSON.toJSONString(voiceSms)); | ||
81 | - String result="stop"; | 100 | + String result = httpRestClientService.doPostStringJson(sendsmsConfig.getQcloudVoiceUrl(), JSON.toJSONString(voiceSms)); |
82 | DEBUG.info("send voice notice msg,result:{}", result); | 101 | DEBUG.info("send voice notice msg,result:{}", result); |
83 | - // monitorAlarmMapper.insertAlarmMsg(InfluxDBContants.AWS, "voice", promptfile, "null", result!=null ? "successed" : "faild", result,mobile); | 102 | + monitorAlarmMapper.insertAlarmMsg(InfluxDBContants.AWS, "voice", promptfile, "null", result!=null ? "successed" : "faild", result,mobile); |
84 | } | 103 | } |
85 | 104 | ||
86 | } catch (Exception e) { | 105 | } catch (Exception e) { |
@@ -23,10 +23,22 @@ public class OpsSmsOnOffController { | @@ -23,10 +23,22 @@ public class OpsSmsOnOffController { | ||
23 | return smsLogService.setSmsTurnOnOff(key); | 23 | return smsLogService.setSmsTurnOnOff(key); |
24 | } | 24 | } |
25 | 25 | ||
26 | + @RequestMapping("/getSmsSwitchValue") | ||
27 | + @ResponseBody | ||
28 | + public BaseResponse getSmsSwitchValue(){ | ||
29 | + return smsLogService.getSmsSwitchValue(); | ||
30 | + } | ||
31 | + | ||
26 | // 语音电话开关 | 32 | // 语音电话开关 |
27 | @RequestMapping("/turnVoice") | 33 | @RequestMapping("/turnVoice") |
28 | @ResponseBody | 34 | @ResponseBody |
29 | public BaseResponse turnVoice(String key){ | 35 | public BaseResponse turnVoice(String key){ |
30 | return smsLogService.setVoiceSmsTurnOnOff(key); | 36 | return smsLogService.setVoiceSmsTurnOnOff(key); |
31 | } | 37 | } |
38 | + | ||
39 | + @RequestMapping("/getVoiceSmsSwitchValue") | ||
40 | + @ResponseBody | ||
41 | + public BaseResponse getVoiceSmsSwitchValue(){ | ||
42 | + return smsLogService.getVoiceSmsSwitchValue(); | ||
43 | + } | ||
32 | } | 44 | } |
@@ -13,6 +13,9 @@ public interface SmsLogService { | @@ -13,6 +13,9 @@ 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 | + BaseResponse getSmsSwitchValue(); | ||
17 | + | ||
16 | 18 | ||
17 | BaseResponse setVoiceSmsTurnOnOff(String key); | 19 | BaseResponse setVoiceSmsTurnOnOff(String key); |
20 | + BaseResponse getVoiceSmsSwitchValue(); | ||
18 | } | 21 | } |
@@ -34,6 +34,7 @@ public class SmsLogServiceImpl implements SmsLogService { | @@ -34,6 +34,7 @@ public class SmsLogServiceImpl implements SmsLogService { | ||
34 | private String smsSendSwitch="ops.sendsms.open"; | 34 | private String smsSendSwitch="ops.sendsms.open"; |
35 | private String smsSendVoiceSwitch="ops.sendvoicesms.open"; | 35 | private String smsSendVoiceSwitch="ops.sendvoicesms.open"; |
36 | 36 | ||
37 | + @Override | ||
37 | public BaseResponse setSmsTurnOnOff(String key){ | 38 | public BaseResponse setSmsTurnOnOff(String key){ |
38 | BaseResponse res=null; | 39 | BaseResponse res=null; |
39 | try{ | 40 | try{ |
@@ -55,6 +56,12 @@ public class SmsLogServiceImpl implements SmsLogService { | @@ -55,6 +56,12 @@ public class SmsLogServiceImpl implements SmsLogService { | ||
55 | return res; | 56 | return res; |
56 | } | 57 | } |
57 | 58 | ||
59 | + @Override | ||
60 | + public BaseResponse getSmsSwitchValue(){ | ||
61 | + return getSwitchValue(smsSendVoiceSwitch); | ||
62 | + } | ||
63 | + | ||
64 | + @Override | ||
58 | public BaseResponse setVoiceSmsTurnOnOff(String key){ | 65 | public BaseResponse setVoiceSmsTurnOnOff(String key){ |
59 | BaseResponse res=null; | 66 | BaseResponse res=null; |
60 | try{ | 67 | try{ |
@@ -76,6 +83,28 @@ public class SmsLogServiceImpl implements SmsLogService { | @@ -76,6 +83,28 @@ public class SmsLogServiceImpl implements SmsLogService { | ||
76 | return res; | 83 | return res; |
77 | } | 84 | } |
78 | 85 | ||
86 | + @Override | ||
87 | + public BaseResponse getVoiceSmsSwitchValue(){ | ||
88 | + return getSwitchValue(smsSendVoiceSwitch); | ||
89 | + } | ||
90 | + | ||
91 | + private BaseResponse getSwitchValue(String key){ | ||
92 | + BaseResponse res=null; | ||
93 | + try{ | ||
94 | + String value=""; | ||
95 | + Stat stat=zkClient.getCuratorFramework().checkExists().forPath(ZK_PATH + key); | ||
96 | + // Stat 就是对zonde所有属性的一个映射, stat=null表示节点不存在! | ||
97 | + if(stat!=null){ | ||
98 | + value = new String(zkClient.getCuratorFramework().getData().forPath(ZK_PATH + key)); | ||
99 | + } | ||
100 | + res= new BaseResponse(200,value); | ||
101 | + } catch (Exception e) { | ||
102 | + logger.error("get ZK_PATH "+key+" error",e); | ||
103 | + res=new BaseResponse("get zk data error "+key); | ||
104 | + } | ||
105 | + return res; | ||
106 | + } | ||
107 | + | ||
79 | public PageResponse<SMSLogs> getSmsLogs(PageRequest req){ | 108 | public PageResponse<SMSLogs> getSmsLogs(PageRequest req){ |
80 | // 组装分页对象 | 109 | // 组装分页对象 |
81 | PageBean page = PageBean.initPageInfo(req.getCurrentPage(), | 110 | PageBean page = PageBean.initPageInfo(req.getCurrentPage(), |
-
Please register or login to post a comment