use of org.jeecg.modules.message.entity.SysMessage in project jeecg-boot by jeecgboot.
the class PushMsgUtil method sendMessage.
/**
* @param msgType 消息类型 1短信 2邮件 3微信
* @param templateCode 消息模板码
* @param map 消息参数
* @param sentTo 接收消息方
*/
public boolean sendMessage(String msgType, String templateCode, Map<String, String> map, String sentTo) {
List<SysMessageTemplate> sysSmsTemplates = sysMessageTemplateService.selectByCode(templateCode);
SysMessage sysMessage = new SysMessage();
if (sysSmsTemplates.size() > 0) {
SysMessageTemplate sysSmsTemplate = sysSmsTemplates.get(0);
sysMessage.setEsType(msgType);
sysMessage.setEsReceiver(sentTo);
// 模板标题
String title = sysSmsTemplate.getTemplateName();
// 模板内容
String content = sysSmsTemplate.getTemplateContent();
StringWriter stringWriter = new StringWriter();
Template template = null;
try {
template = new Template("SysMessageTemplate", content, freemarkerConfig);
template.process(map, stringWriter);
} catch (IOException e) {
e.printStackTrace();
return false;
} catch (TemplateException e) {
e.printStackTrace();
return false;
}
content = stringWriter.toString();
sysMessage.setEsTitle(title);
sysMessage.setEsContent(content);
sysMessage.setEsParam(JSONObject.toJSONString(map));
sysMessage.setEsSendTime(new Date());
sysMessage.setEsSendStatus(SendMsgStatusEnum.WAIT.getCode());
sysMessage.setEsSendNum(0);
if (sysMessageService.save(sysMessage)) {
return true;
}
}
return false;
}
use of org.jeecg.modules.message.entity.SysMessage in project kykms by mahonelau.
the class SendMsgJob method execute.
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
log.info(String.format(" Jeecg-Boot 发送消息任务 SendMsgJob ! 时间:" + DateUtils.getTimestamp()));
// 1.读取消息中心数据,只查询未发送的和发送失败不超过次数的
QueryWrapper<SysMessage> queryWrapper = new QueryWrapper<SysMessage>();
queryWrapper.eq("es_send_status", SendMsgStatusEnum.WAIT.getCode()).or(i -> i.eq("es_send_status", SendMsgStatusEnum.FAIL.getCode()).lt("es_send_num", 6));
List<SysMessage> sysMessages = sysMessageService.list(queryWrapper);
System.out.println(sysMessages);
// 2.根据不同的类型走不通的发送实现类
for (SysMessage sysMessage : sysMessages) {
ISendMsgHandle sendMsgHandle = null;
try {
if (sysMessage.getEsType().equals(SendMsgTypeEnum.EMAIL.getType())) {
sendMsgHandle = (ISendMsgHandle) Class.forName(SendMsgTypeEnum.EMAIL.getImplClass()).newInstance();
} else if (sysMessage.getEsType().equals(SendMsgTypeEnum.SMS.getType())) {
sendMsgHandle = (ISendMsgHandle) Class.forName(SendMsgTypeEnum.SMS.getImplClass()).newInstance();
} else if (sysMessage.getEsType().equals(SendMsgTypeEnum.WX.getType())) {
sendMsgHandle = (ISendMsgHandle) Class.forName(SendMsgTypeEnum.WX.getImplClass()).newInstance();
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
Integer sendNum = sysMessage.getEsSendNum();
try {
sendMsgHandle.SendMsg(sysMessage.getEsReceiver(), sysMessage.getEsTitle(), sysMessage.getEsContent().toString());
// 发送消息成功
sysMessage.setEsSendStatus(SendMsgStatusEnum.SUCCESS.getCode());
} catch (Exception e) {
e.printStackTrace();
// 发送消息出现异常
sysMessage.setEsSendStatus(SendMsgStatusEnum.FAIL.getCode());
}
sysMessage.setEsSendNum(++sendNum);
// 发送结果回写到数据库
sysMessageService.updateById(sysMessage);
}
}
use of org.jeecg.modules.message.entity.SysMessage in project kms by mahonelau.
the class SendMsgJob method execute.
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
log.info(String.format(" Jeecg-Boot 发送消息任务 SendMsgJob ! 时间:" + DateUtils.getTimestamp()));
// 1.读取消息中心数据,只查询未发送的和发送失败不超过次数的
QueryWrapper<SysMessage> queryWrapper = new QueryWrapper<SysMessage>();
queryWrapper.eq("es_send_status", SendMsgStatusEnum.WAIT.getCode()).or(i -> i.eq("es_send_status", SendMsgStatusEnum.FAIL.getCode()).lt("es_send_num", 6));
List<SysMessage> sysMessages = sysMessageService.list(queryWrapper);
System.out.println(sysMessages);
// 2.根据不同的类型走不通的发送实现类
for (SysMessage sysMessage : sysMessages) {
ISendMsgHandle sendMsgHandle = null;
try {
if (sysMessage.getEsType().equals(SendMsgTypeEnum.EMAIL.getType())) {
sendMsgHandle = (ISendMsgHandle) Class.forName(SendMsgTypeEnum.EMAIL.getImplClass()).newInstance();
} else if (sysMessage.getEsType().equals(SendMsgTypeEnum.SMS.getType())) {
sendMsgHandle = (ISendMsgHandle) Class.forName(SendMsgTypeEnum.SMS.getImplClass()).newInstance();
} else if (sysMessage.getEsType().equals(SendMsgTypeEnum.WX.getType())) {
sendMsgHandle = (ISendMsgHandle) Class.forName(SendMsgTypeEnum.WX.getImplClass()).newInstance();
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
Integer sendNum = sysMessage.getEsSendNum();
try {
sendMsgHandle.SendMsg(sysMessage.getEsReceiver(), sysMessage.getEsTitle(), sysMessage.getEsContent().toString());
// 发送消息成功
sysMessage.setEsSendStatus(SendMsgStatusEnum.SUCCESS.getCode());
} catch (Exception e) {
e.printStackTrace();
// 发送消息出现异常
sysMessage.setEsSendStatus(SendMsgStatusEnum.FAIL.getCode());
}
sysMessage.setEsSendNum(++sendNum);
// 发送结果回写到数据库
sysMessageService.updateById(sysMessage);
}
}
use of org.jeecg.modules.message.entity.SysMessage in project kms by mahonelau.
the class PushMsgUtil method sendMessage.
/**
* @param msgType 消息类型 1短信 2邮件 3微信
* @param templateCode 消息模板码
* @param map 消息参数
* @param sentTo 接收消息方
*/
public boolean sendMessage(String msgType, String templateCode, Map<String, String> map, String sentTo) {
List<SysMessageTemplate> sysSmsTemplates = sysMessageTemplateService.selectByCode(templateCode);
SysMessage sysMessage = new SysMessage();
if (sysSmsTemplates.size() > 0) {
SysMessageTemplate sysSmsTemplate = sysSmsTemplates.get(0);
sysMessage.setEsType(msgType);
sysMessage.setEsReceiver(sentTo);
// 模板标题
String title = sysSmsTemplate.getTemplateName();
// 模板内容
String content = sysSmsTemplate.getTemplateContent();
StringWriter stringWriter = new StringWriter();
Template template = null;
try {
template = new Template("SysMessageTemplate", content, freemarkerConfig);
template.process(map, stringWriter);
} catch (IOException e) {
e.printStackTrace();
return false;
} catch (TemplateException e) {
e.printStackTrace();
return false;
}
content = stringWriter.toString();
sysMessage.setEsTitle(title);
sysMessage.setEsContent(content);
sysMessage.setEsParam(JSONObject.toJSONString(map));
sysMessage.setEsSendTime(new Date());
sysMessage.setEsSendStatus(SendMsgStatusEnum.WAIT.getCode());
sysMessage.setEsSendNum(0);
if (sysMessageService.save(sysMessage)) {
return true;
}
}
return false;
}
use of org.jeecg.modules.message.entity.SysMessage in project jeecg-boot by jeecgboot.
the class SendMsgJob method execute.
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
log.info(String.format(" Jeecg-Boot 发送消息任务 SendMsgJob ! 时间:" + DateUtils.getTimestamp()));
// 1.读取消息中心数据,只查询未发送的和发送失败不超过次数的
QueryWrapper<SysMessage> queryWrapper = new QueryWrapper<SysMessage>();
queryWrapper.eq("es_send_status", SendMsgStatusEnum.WAIT.getCode()).or(i -> i.eq("es_send_status", SendMsgStatusEnum.FAIL.getCode()).lt("es_send_num", 6));
List<SysMessage> sysMessages = sysMessageService.list(queryWrapper);
System.out.println(sysMessages);
// 2.根据不同的类型走不通的发送实现类
for (SysMessage sysMessage : sysMessages) {
ISendMsgHandle sendMsgHandle = null;
try {
if (sysMessage.getEsType().equals(SendMsgTypeEnum.EMAIL.getType())) {
sendMsgHandle = (ISendMsgHandle) Class.forName(SendMsgTypeEnum.EMAIL.getImplClass()).newInstance();
} else if (sysMessage.getEsType().equals(SendMsgTypeEnum.SMS.getType())) {
sendMsgHandle = (ISendMsgHandle) Class.forName(SendMsgTypeEnum.SMS.getImplClass()).newInstance();
} else if (sysMessage.getEsType().equals(SendMsgTypeEnum.WX.getType())) {
sendMsgHandle = (ISendMsgHandle) Class.forName(SendMsgTypeEnum.WX.getImplClass()).newInstance();
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
Integer sendNum = sysMessage.getEsSendNum();
try {
sendMsgHandle.SendMsg(sysMessage.getEsReceiver(), sysMessage.getEsTitle(), sysMessage.getEsContent().toString());
// 发送消息成功
sysMessage.setEsSendStatus(SendMsgStatusEnum.SUCCESS.getCode());
} catch (Exception e) {
e.printStackTrace();
// 发送消息出现异常
sysMessage.setEsSendStatus(SendMsgStatusEnum.FAIL.getCode());
}
sysMessage.setEsSendNum(++sendNum);
// 发送结果回写到数据库
sysMessageService.updateById(sysMessage);
}
}
Aggregations