Commit 11268dbc authored by 李成龙's avatar 李成龙

气瓶预警消息

parent 462f2ce7
package com.yeejoin.amos.boot.module.tzs.biz.action;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Date;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.slf4j.Logger;
......@@ -54,6 +58,7 @@ public class CylWarningMsgAction{
CylWarningMsgDto cylWarningMsgDto = (CylWarningMsgDto)bizobj;
//更新气瓶等级
logger.info("更新气瓶等级:"+level);
logger.info("预警区间:"+cylWarningMsgDto.getNum());
cylinderInfoServiceImpl.updateEarlyWarningLevel(cylWarningMsgDto.getCylSeq(), level);
//增加消息日志数据
MsgLog msgLog = new MsgLog();
......@@ -69,7 +74,7 @@ public class CylWarningMsgAction{
logger.info("增加消息日志数据:"+msgLog.toString());
//发送web消息
try {
emqKeeper.getMqttClient().publish(cylpushTopic, text.getBytes("UTF-8"), 2, false);
emqKeeper.getMqttClient().publish(cylpushTopic, instedParams(text,cylWarningMsgDto).getBytes("UTF-8"), 2, false);
logger.info("气瓶预警消息发送成功:");
} catch (MqttException e) {
e.printStackTrace();
......@@ -103,11 +108,51 @@ public class CylWarningMsgAction{
wechatMessageDto1.setTemplateId(templateId_Warning);
Map<String, String> data1 = Maps.newHashMap();
data1.put("first", "【陕西特种设备安全监察局】风险预警提醒");
data1.put("keyword1", text);
data1.put("keyword1", instedParams(text,cylWarningMsgDto));
data1.put("keyword2", DateUtils.date2LongStr(new Date()));
wechatMessageDto1.setData(data1);
wechatServiceImpl.sendWechatModelMessage(wechatRelation.getOpenId(), wechatMessageDto1);
logger.info("公众号消息发送成功:");
}
}
private String instedParams(String content, CylWarningMsgDto contingencyRo) {
// Map<String, String> strengthMap = this.getStrengthMap(contingencyRo);
// for (String key : strengthMap.keySet())
// content = content.replaceAll("\\$\\{" + key + "}", strengthMap.get(key));
Field[] fields = contingencyRo.getClass().getDeclaredFields();
Method getMethod = null;
try {
for (Field field : fields) {
if (field.getName().equals("serialVersionUID"))
continue;
String fileNameInMethod = String.valueOf(field.getName().charAt(0)).toUpperCase() + field.getName().substring(1);
getMethod = contingencyRo.getClass().getMethod("get" + fileNameInMethod);
String value = String.valueOf(getMethod.invoke(contingencyRo));
content = content.replaceAll("\\$\\{" + field.getName() + "}", value);
}
content = getNative(content);
} catch (Exception e) {
e.printStackTrace();
}
return content;
}
public String getNative(String str)
{
Pattern p = Pattern.compile("\\$\\{(.*?)\\}");
Matcher m = p.matcher(str);
while (m.find())
{
String parameter = m.group();
Object parametervalue = ELEvaluationContext
.getValue(parameter.substring(1, parameter.length() - 1));
if(parametervalue != null)
str = str.replace(parameter,
parametervalue != null ? parametervalue.toString() : null);
}
return str;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment