Authored by qinchao

报警添加开发

... ... @@ -7,7 +7,7 @@ import java.io.UnsupportedEncodingException;
*/
public interface VoiceMsgService {
void sendVoice(String mobile) throws UnsupportedEncodingException;
//void sendVoice(String mobile) throws UnsupportedEncodingException;
void sendVoiceAlarm(String mobile,String content) throws UnsupportedEncodingException;
... ...
... ... @@ -5,10 +5,12 @@ import com.monitor.common.config.SendsmsConfig;
import com.monitor.common.service.HttpRestClientService;
import com.monitor.common.service.VoiceMsgService;
import com.monitor.common.util.MD5Util;
import com.monitor.common.util.ZkClientUtil;
import com.monitor.influxdb.contants.InfluxDBContants;
import com.monitor.influxdb.mapper.MonitorAlarmMapper;
import com.monitor.model.domain.VoiceSms;
import com.monitor.model.domain.VoiceSmsNotice;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -31,9 +33,15 @@ public class VoiceMsgServiceImpl implements VoiceMsgService {
@Autowired
private SendsmsConfig sendsmsConfig;
@Autowired
private ZkClientUtil zkClient;
public final Logger DEBUG = LoggerFactory.getLogger(getClass());
@Override
private String ZK_PATH = "/yh/config/";
private String smsSendVoiceSwitch="ops.sendvoicesms.open";
/* @Override
public void sendVoice(String mobile) throws UnsupportedEncodingException {
try {
... ... @@ -57,11 +65,23 @@ public class VoiceMsgServiceImpl implements VoiceMsgService {
}
}
}*/
@Override
public void sendVoiceAlarm(String mobile,String content) throws UnsupportedEncodingException {
//根据zk的开关判断是否需要发送数据
String open="";
try{
//zkClient.getCuratorFramework().setData().forPath(ZK_PATH + smsSendSwitch,"true".getBytes("UTF-8"));
open = new String(zkClient.getCuratorFramework().getData().forPath(ZK_PATH + smsSendVoiceSwitch));
} catch (Exception e) {
DEBUG.error("Send msg type get ZK_PATH smsVoiceSendSwitch error",e);
}
if(StringUtils.isNotBlank(open)&&"false".equals(open)){
return ;//开关关掉了,不再发送语音
}
try {
VoiceSmsNotice voiceSms = new VoiceSmsNotice();
String promptfile = "请及时处理故障:紧急故障";
... ... @@ -77,10 +97,9 @@ public class VoiceMsgServiceImpl implements VoiceMsgService {
voiceSms.setSig(MD5Util.encryption(sendsmsConfig.getQcloudSmsKey() + str));
voiceSms.setTel(tel);
DEBUG.info("send voice notice msg,content:{}", JSON.toJSONString(voiceSms));
// String result = httpRestClientService.doPostStringJson(sendsmsConfig.getQcloudVoiceUrl(), JSON.toJSONString(voiceSms));
String result="stop";
String result = httpRestClientService.doPostStringJson(sendsmsConfig.getQcloudVoiceUrl(), JSON.toJSONString(voiceSms));
DEBUG.info("send voice notice msg,result:{}", result);
// monitorAlarmMapper.insertAlarmMsg(InfluxDBContants.AWS, "voice", promptfile, "null", result!=null ? "successed" : "faild", result,mobile);
monitorAlarmMapper.insertAlarmMsg(InfluxDBContants.AWS, "voice", promptfile, "null", result!=null ? "successed" : "faild", result,mobile);
}
} catch (Exception e) {
... ...
... ... @@ -23,10 +23,22 @@ public class OpsSmsOnOffController {
return smsLogService.setSmsTurnOnOff(key);
}
@RequestMapping("/getSmsSwitchValue")
@ResponseBody
public BaseResponse getSmsSwitchValue(){
return smsLogService.getSmsSwitchValue();
}
// 语音电话开关
@RequestMapping("/turnVoice")
@ResponseBody
public BaseResponse turnVoice(String key){
return smsLogService.setVoiceSmsTurnOnOff(key);
}
@RequestMapping("/getVoiceSmsSwitchValue")
@ResponseBody
public BaseResponse getVoiceSmsSwitchValue(){
return smsLogService.getVoiceSmsSwitchValue();
}
}
... ...
... ... @@ -13,6 +13,9 @@ public interface SmsLogService {
PageResponse<SMSLogs> getSmsLogs(PageRequest req);
BaseResponse setSmsTurnOnOff(String key);
BaseResponse getSmsSwitchValue();
BaseResponse setVoiceSmsTurnOnOff(String key);
BaseResponse getVoiceSmsSwitchValue();
}
... ...
... ... @@ -34,6 +34,7 @@ public class SmsLogServiceImpl implements SmsLogService {
private String smsSendSwitch="ops.sendsms.open";
private String smsSendVoiceSwitch="ops.sendvoicesms.open";
@Override
public BaseResponse setSmsTurnOnOff(String key){
BaseResponse res=null;
try{
... ... @@ -55,6 +56,12 @@ public class SmsLogServiceImpl implements SmsLogService {
return res;
}
@Override
public BaseResponse getSmsSwitchValue(){
return getSwitchValue(smsSendVoiceSwitch);
}
@Override
public BaseResponse setVoiceSmsTurnOnOff(String key){
BaseResponse res=null;
try{
... ... @@ -76,6 +83,28 @@ public class SmsLogServiceImpl implements SmsLogService {
return res;
}
@Override
public BaseResponse getVoiceSmsSwitchValue(){
return getSwitchValue(smsSendVoiceSwitch);
}
private BaseResponse getSwitchValue(String key){
BaseResponse res=null;
try{
String value="";
Stat stat=zkClient.getCuratorFramework().checkExists().forPath(ZK_PATH + key);
// Stat 就是对zonde所有属性的一个映射, stat=null表示节点不存在!
if(stat!=null){
value = new String(zkClient.getCuratorFramework().getData().forPath(ZK_PATH + key));
}
res= new BaseResponse(200,value);
} catch (Exception e) {
logger.error("get ZK_PATH "+key+" error",e);
res=new BaseResponse("get zk data error "+key);
}
return res;
}
public PageResponse<SMSLogs> getSmsLogs(PageRequest req){
// 组装分页对象
PageBean page = PageBean.initPageInfo(req.getCurrentPage(),
... ...