|
@@ -18,6 +18,7 @@ import com.zd.model.domain.per.PerFun;
|
|
|
import com.zd.model.domain.per.PerPrefix;
|
|
import com.zd.model.domain.per.PerPrefix;
|
|
|
import com.zd.model.page.TableDataInfo;
|
|
import com.zd.model.page.TableDataInfo;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
@@ -28,6 +29,7 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
|
@RequestMapping("/alarm")
|
|
@RequestMapping("/alarm")
|
|
|
|
|
+@Slf4j
|
|
|
public class AlarmController extends BaseController {
|
|
public class AlarmController extends BaseController {
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -59,65 +61,22 @@ public class AlarmController extends BaseController {
|
|
|
@Async("msgExecutor")
|
|
@Async("msgExecutor")
|
|
|
public ResultData queryOption(@RequestBody AlarmEntrty alarmEntrty) {
|
|
public ResultData queryOption(@RequestBody AlarmEntrty alarmEntrty) {
|
|
|
if (alarmEntrty.getTo() == null || alarmEntrty.getTo().length == 0) {
|
|
if (alarmEntrty.getTo() == null || alarmEntrty.getTo().length == 0) {
|
|
|
- logger.info("打电话发短信电话号码为空!");
|
|
|
|
|
|
|
+ log.info("打电话发短信电话号码为空!");
|
|
|
return ResultData.fail("打电话发短信电话号码为空!");
|
|
return ResultData.fail("打电话发短信电话号码为空!");
|
|
|
}
|
|
}
|
|
|
//处理数据 短信拼装
|
|
//处理数据 短信拼装
|
|
|
String sendType = alarmEntrty.getType();
|
|
String sendType = alarmEntrty.getType();
|
|
|
- if((SendTypes.All.toString()).equals(sendType) || (SendTypes.Call.toString()).equals(sendType)){
|
|
|
|
|
- //打电话
|
|
|
|
|
- alarmEntrty.setType(SendTypes.Call.toString());
|
|
|
|
|
- sendCall(alarmEntrty);
|
|
|
|
|
- }
|
|
|
|
|
if((SendTypes.All.toString()).equals(sendType) || (SendTypes.SMS.toString()).equals(sendType) ){
|
|
if((SendTypes.All.toString()).equals(sendType) || (SendTypes.SMS.toString()).equals(sendType) ){
|
|
|
//发短信
|
|
//发短信
|
|
|
alarmEntrty.setType(SendTypes.SMS.toString());
|
|
alarmEntrty.setType(SendTypes.SMS.toString());
|
|
|
sendSMS(alarmEntrty);
|
|
sendSMS(alarmEntrty);
|
|
|
}
|
|
}
|
|
|
|
|
+ if((SendTypes.All.toString()).equals(sendType) || (SendTypes.Call.toString()).equals(sendType)){
|
|
|
|
|
+ //打电话
|
|
|
|
|
+ alarmEntrty.setType(SendTypes.Call.toString());
|
|
|
|
|
+ sendCall(alarmEntrty);
|
|
|
|
|
+ }
|
|
|
return ResultData.success("拨打电话发送短信完成!");
|
|
return ResultData.success("拨打电话发送短信完成!");
|
|
|
-// Map<String, String> map = alarmUtil.sendPost(alarmEntrty);
|
|
|
|
|
-// String data = map.get("Reply");
|
|
|
|
|
-// if((SendTypes.Call + "").equals(alarmEntrty.getType()) || (SendTypes.All + "").equals(alarmEntrty.getType())){
|
|
|
|
|
-// if("OK".equals(data)) {
|
|
|
|
|
-// String[] phones = alarmEntrty.getTo();
|
|
|
|
|
-// for (String phone : phones) {
|
|
|
|
|
-// AlarmLog alarmLog = new AlarmLog();
|
|
|
|
|
-// alarmLog.setKeyId(alarmLog.getKeyId());
|
|
|
|
|
-// alarmLog.setNickName();
|
|
|
|
|
-// alarmLog.setRoleName();
|
|
|
|
|
-// alarmLog.setIsBack(1);
|
|
|
|
|
-// alarmLog.setPhone(phone);
|
|
|
|
|
-// alarmLog.setNotice(alarmEntrty.getText());
|
|
|
|
|
-// alarmLog.setMethod("电话");
|
|
|
|
|
-// alarmLog.setStatus("成功");
|
|
|
|
|
-// alarmLog.setCreateTime(DateUtils.getNowDate());
|
|
|
|
|
-// alarmLog.setUpdateTime(DateUtils.getNowDate());
|
|
|
|
|
-//
|
|
|
|
|
-// alarmLogService.insertAlarmLog(alarmLog);
|
|
|
|
|
-// }
|
|
|
|
|
-// return AjaxResult.success();
|
|
|
|
|
-// }else {
|
|
|
|
|
-// String[] phones = alarmEntrty.getTo();
|
|
|
|
|
-// for (String phone : phones) {
|
|
|
|
|
-// AlarmLog alarmLog = new AlarmLog();
|
|
|
|
|
-// alarmLog.setIsBack(1);
|
|
|
|
|
-// alarmLog.setPhone(phone);
|
|
|
|
|
-// alarmLog.setNotice(alarmEntrty.getText());
|
|
|
|
|
-// alarmLog.setMethod("电话");
|
|
|
|
|
-// alarmLog.setStatus("失败");
|
|
|
|
|
-// alarmLog.setRemark(data);
|
|
|
|
|
-// alarmLog.setCreateTime(DateUtils.getNowDate());
|
|
|
|
|
-// alarmLog.setUpdateTime(DateUtils.getNowDate());
|
|
|
|
|
-//
|
|
|
|
|
-// alarmLogService.insertAlarmLog(alarmLog);
|
|
|
|
|
-// }
|
|
|
|
|
-// return AjaxResult.error(data);
|
|
|
|
|
-// }
|
|
|
|
|
-// }else if((SendTypes.SMS + "").equals(alarmEntrty.getType())) {
|
|
|
|
|
-// if ("OK".equals(data)) {
|
|
|
|
|
-// return AjaxResult.success();
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void sendCall(AlarmEntrty alarmEntrty) {
|
|
private void sendCall(AlarmEntrty alarmEntrty) {
|
|
@@ -142,7 +101,7 @@ public class AlarmController extends BaseController {
|
|
|
alarmLog.setKeyId(alarmEntrty.getLogId());
|
|
alarmLog.setKeyId(alarmEntrty.getLogId());
|
|
|
alarmLogService.insertAlarmLog(alarmLog);
|
|
alarmLogService.insertAlarmLog(alarmLog);
|
|
|
}
|
|
}
|
|
|
- logger.info("电话预警通知用户成功!===>>>{}", JSON.toJSONString(alarmEntrty.getTo()));
|
|
|
|
|
|
|
+ log.info("电话预警通知用户成功!===>>>{}", JSON.toJSONString(alarmEntrty.getTo()));
|
|
|
}else {
|
|
}else {
|
|
|
String[] phones = alarmEntrty.getTo();
|
|
String[] phones = alarmEntrty.getTo();
|
|
|
for (String phone : phones) {
|
|
for (String phone : phones) {
|
|
@@ -162,24 +121,29 @@ public class AlarmController extends BaseController {
|
|
|
alarmLog.setKeyId(alarmEntrty.getLogId());
|
|
alarmLog.setKeyId(alarmEntrty.getLogId());
|
|
|
alarmLogService.insertAlarmLog(alarmLog);
|
|
alarmLogService.insertAlarmLog(alarmLog);
|
|
|
}
|
|
}
|
|
|
- logger.info("电话预警通知用户失败!===>>>{}", JSON.toJSONString(alarmEntrty.getTo()));
|
|
|
|
|
|
|
+ log.info("电话预警通知用户失败!===>>>{}", JSON.toJSONString(alarmEntrty.getTo()));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void sendSMS(AlarmEntrty alarmEntrty) {
|
|
private void sendSMS(AlarmEntrty alarmEntrty) {
|
|
|
List<UserPhoneInfo> userPhoneInfoList = alarmEntrty.getUserPhoneInfo();
|
|
List<UserPhoneInfo> userPhoneInfoList = alarmEntrty.getUserPhoneInfo();
|
|
|
LinkedHashMap<String, List<UserPhoneInfo>> userPhoneInfoMap = Optional.ofNullable(userPhoneInfoList).orElseGet(Collections::emptyList).stream().collect(Collectors.groupingBy(UserPhoneInfo::getPhone, LinkedHashMap::new, Collectors.toList()));
|
|
LinkedHashMap<String, List<UserPhoneInfo>> userPhoneInfoMap = Optional.ofNullable(userPhoneInfoList).orElseGet(Collections::emptyList).stream().collect(Collectors.groupingBy(UserPhoneInfo::getPhone, LinkedHashMap::new, Collectors.toList()));
|
|
|
- String text = alarmEntrty.getText() + smsRedirect;
|
|
|
|
|
|
|
+ StringBuffer textURL = new StringBuffer();
|
|
|
|
|
+ textURL.append(alarmEntrty.getText());
|
|
|
for (String phone : alarmEntrty.getTo()) {
|
|
for (String phone : alarmEntrty.getTo()) {
|
|
|
- ResultData urlScheme = remoteMessageService.getUrlScheme(alarmEntrty.getLogId());
|
|
|
|
|
- if (urlScheme.getCode() != HttpStatus.SUCCESS) {
|
|
|
|
|
- logger.error("获取urlScheme失败!");
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ ResultData urlScheme = remoteMessageService.getUrlScheme(alarmEntrty.getLogId());
|
|
|
|
|
+ if (urlScheme.getCode() == HttpStatus.SUCCESS) {
|
|
|
|
|
+ textURL.append(smsRedirect).append("?id=").append(alarmEntrty.getLogId()).append("&urlScheme=").append(urlScheme.getData());
|
|
|
|
|
+ }else {
|
|
|
|
|
+ log.error("获取urlScheme失败!");
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("获取urlScheme异常!请检查配置(nacos链接配置,小程序参数配置)!");
|
|
|
}
|
|
}
|
|
|
- String newTest = "";
|
|
|
|
|
- newTest = text + "?id=" + alarmEntrty.getLogId() + "&urlScheme=" + urlScheme.getData();
|
|
|
|
|
- alarmEntrty.setText(newTest);
|
|
|
|
|
|
|
+ alarmEntrty.setText(textURL.toString());
|
|
|
alarmEntrty.setTo(new String[]{phone});
|
|
alarmEntrty.setTo(new String[]{phone});
|
|
|
- logger.info("发送给用户===>>>{},短信内容===>>>{}",phone,newTest);
|
|
|
|
|
|
|
+ log.info("发送给用户===>>>{},短信内容===>>>{}",phone,textURL);
|
|
|
//发送短信
|
|
//发送短信
|
|
|
Map map = alarmUtil.sendPost(alarmEntrty);
|
|
Map map = alarmUtil.sendPost(alarmEntrty);
|
|
|
String data = (String) map.get("Reply");
|
|
String data = (String) map.get("Reply");
|