use of org.jeecg.modules.message.entity.SysMessageTemplate 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.SysMessageTemplate in project jeecg-boot by jeecgboot.
the class SysBaseApiImpl method parseTemplateByCode.
@Override
public String parseTemplateByCode(TemplateDTO templateDTO) {
String templateCode = templateDTO.getTemplateCode();
Map<String, String> map = templateDTO.getTemplateParam();
List<SysMessageTemplate> sysSmsTemplates = sysMessageTemplateService.selectByCode(templateCode);
if (sysSmsTemplates == null || sysSmsTemplates.size() == 0) {
throw new JeecgBootException("消息模板不存在,模板编码:" + templateCode);
}
SysMessageTemplate sysSmsTemplate = sysSmsTemplates.get(0);
// 模板内容
String content = sysSmsTemplate.getTemplateContent();
if (map != null) {
for (Map.Entry<String, String> entry : map.entrySet()) {
String str = "${" + entry.getKey() + "}";
content = content.replace(str, entry.getValue());
}
}
return content;
}
use of org.jeecg.modules.message.entity.SysMessageTemplate in project jeecg-boot by jeecgboot.
the class SysBaseApiImpl method sendTemplateAnnouncement.
@Override
public void sendTemplateAnnouncement(TemplateMessageDTO message) {
String templateCode = message.getTemplateCode();
String title = message.getTitle();
Map<String, String> map = message.getTemplateParam();
String fromUser = message.getFromUser();
String toUser = message.getToUser();
List<SysMessageTemplate> sysSmsTemplates = sysMessageTemplateService.selectByCode(templateCode);
if (sysSmsTemplates == null || sysSmsTemplates.size() == 0) {
throw new JeecgBootException("消息模板不存在,模板编码:" + templateCode);
}
SysMessageTemplate sysSmsTemplate = sysSmsTemplates.get(0);
// 模板标题
title = title == null ? sysSmsTemplate.getTemplateName() : title;
// 模板内容
String content = sysSmsTemplate.getTemplateContent();
if (map != null) {
for (Map.Entry<String, String> entry : map.entrySet()) {
String str = "${" + entry.getKey() + "}";
if (oConvertUtils.isNotEmpty(title)) {
title = title.replace(str, entry.getValue());
}
content = content.replace(str, entry.getValue());
}
}
SysAnnouncement announcement = new SysAnnouncement();
announcement.setTitile(title);
announcement.setMsgContent(content);
announcement.setSender(fromUser);
announcement.setPriority(CommonConstant.PRIORITY_M);
announcement.setMsgType(CommonConstant.MSG_TYPE_UESR);
announcement.setSendStatus(CommonConstant.HAS_SEND);
announcement.setSendTime(new Date());
announcement.setMsgCategory(CommonConstant.MSG_CATEGORY_2);
announcement.setDelFlag(String.valueOf(CommonConstant.DEL_FLAG_0));
sysAnnouncementMapper.insert(announcement);
// 2.插入用户通告阅读标记表记录
String userId = toUser;
String[] userIds = userId.split(",");
String anntId = announcement.getId();
for (int i = 0; i < userIds.length; i++) {
if (oConvertUtils.isNotEmpty(userIds[i])) {
SysUser sysUser = userMapper.getUserByName(userIds[i]);
if (sysUser == null) {
continue;
}
SysAnnouncementSend announcementSend = new SysAnnouncementSend();
announcementSend.setAnntId(anntId);
announcementSend.setUserId(sysUser.getId());
announcementSend.setReadFlag(CommonConstant.NO_READ_FLAG);
sysAnnouncementSendMapper.insert(announcementSend);
JSONObject obj = new JSONObject();
obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_USER);
obj.put(WebsocketConst.MSG_USER_ID, sysUser.getId());
obj.put(WebsocketConst.MSG_ID, announcement.getId());
obj.put(WebsocketConst.MSG_TXT, announcement.getTitile());
webSocket.sendMessage(sysUser.getId(), obj.toJSONString());
}
}
try {
// 同步企业微信、钉钉的消息通知
dingtalkService.sendActionCardMessage(announcement, true);
wechatEnterpriseService.sendTextCardMessage(announcement, true);
} catch (Exception e) {
log.error("同步发送第三方APP消息失败!", e);
}
}
use of org.jeecg.modules.message.entity.SysMessageTemplate in project kms by mahonelau.
the class SysBaseApiImpl method sendBusTemplateAnnouncement.
@Override
public void sendBusTemplateAnnouncement(BusTemplateMessageDTO message) {
String templateCode = message.getTemplateCode();
String title = message.getTitle();
Map<String, String> map = message.getTemplateParam();
String fromUser = message.getFromUser();
String toUser = message.getToUser();
String busId = message.getBusId();
String busType = message.getBusType();
List<SysMessageTemplate> sysSmsTemplates = sysMessageTemplateService.selectByCode(templateCode);
if (sysSmsTemplates == null || sysSmsTemplates.size() == 0) {
throw new JeecgBootException("消息模板不存在,模板编码:" + templateCode);
}
SysMessageTemplate sysSmsTemplate = sysSmsTemplates.get(0);
// 模板标题
title = title == null ? sysSmsTemplate.getTemplateName() : title;
// 模板内容
String content = sysSmsTemplate.getTemplateContent();
if (map != null) {
for (Map.Entry<String, String> entry : map.entrySet()) {
String str = "${" + entry.getKey() + "}";
title = title.replace(str, entry.getValue());
content = content.replace(str, entry.getValue());
}
}
SysAnnouncement announcement = new SysAnnouncement();
announcement.setTitile(title);
announcement.setMsgContent(content);
announcement.setSender(fromUser);
announcement.setPriority(CommonConstant.PRIORITY_M);
announcement.setMsgType(CommonConstant.MSG_TYPE_UESR);
announcement.setSendStatus(CommonConstant.HAS_SEND);
announcement.setSendTime(new Date());
announcement.setMsgCategory(CommonConstant.MSG_CATEGORY_2);
announcement.setDelFlag(String.valueOf(CommonConstant.DEL_FLAG_0));
announcement.setBusId(busId);
announcement.setBusType(busType);
announcement.setOpenType(SysAnnmentTypeEnum.getByType(busType).getOpenType());
announcement.setOpenPage(SysAnnmentTypeEnum.getByType(busType).getOpenPage());
sysAnnouncementMapper.insert(announcement);
// 2.插入用户通告阅读标记表记录
String userId = toUser;
String[] userIds = userId.split(",");
String anntId = announcement.getId();
for (int i = 0; i < userIds.length; i++) {
if (oConvertUtils.isNotEmpty(userIds[i])) {
SysUser sysUser = userMapper.getUserByName(userIds[i]);
if (sysUser == null) {
continue;
}
SysAnnouncementSend announcementSend = new SysAnnouncementSend();
announcementSend.setAnntId(anntId);
announcementSend.setUserId(sysUser.getId());
announcementSend.setReadFlag(CommonConstant.NO_READ_FLAG);
sysAnnouncementSendMapper.insert(announcementSend);
JSONObject obj = new JSONObject();
obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_USER);
obj.put(WebsocketConst.MSG_USER_ID, sysUser.getId());
obj.put(WebsocketConst.MSG_ID, announcement.getId());
obj.put(WebsocketConst.MSG_TXT, announcement.getTitile());
webSocket.sendMessage(sysUser.getId(), obj.toJSONString());
}
}
try {
// 同步企业微信、钉钉的消息通知
dingtalkService.sendActionCardMessage(announcement, true);
wechatEnterpriseService.sendTextCardMessage(announcement, true);
} catch (Exception e) {
log.error("同步发送第三方APP消息失败!", e);
}
}
use of org.jeecg.modules.message.entity.SysMessageTemplate in project kms by mahonelau.
the class SysBaseApiImpl method sendTemplateAnnouncement.
@Override
public void sendTemplateAnnouncement(TemplateMessageDTO message) {
String templateCode = message.getTemplateCode();
String title = message.getTitle();
Map<String, String> map = message.getTemplateParam();
String fromUser = message.getFromUser();
String toUser = message.getToUser();
List<SysMessageTemplate> sysSmsTemplates = sysMessageTemplateService.selectByCode(templateCode);
if (sysSmsTemplates == null || sysSmsTemplates.size() == 0) {
throw new JeecgBootException("消息模板不存在,模板编码:" + templateCode);
}
SysMessageTemplate sysSmsTemplate = sysSmsTemplates.get(0);
// 模板标题
title = title == null ? sysSmsTemplate.getTemplateName() : title;
// 模板内容
String content = sysSmsTemplate.getTemplateContent();
if (map != null) {
for (Map.Entry<String, String> entry : map.entrySet()) {
String str = "${" + entry.getKey() + "}";
if (oConvertUtils.isNotEmpty(title)) {
title = title.replace(str, entry.getValue());
}
content = content.replace(str, entry.getValue());
}
}
SysAnnouncement announcement = new SysAnnouncement();
announcement.setTitile(title);
announcement.setMsgContent(content);
announcement.setSender(fromUser);
announcement.setPriority(CommonConstant.PRIORITY_M);
announcement.setMsgType(CommonConstant.MSG_TYPE_UESR);
announcement.setSendStatus(CommonConstant.HAS_SEND);
announcement.setSendTime(new Date());
announcement.setMsgCategory(CommonConstant.MSG_CATEGORY_2);
announcement.setDelFlag(String.valueOf(CommonConstant.DEL_FLAG_0));
sysAnnouncementMapper.insert(announcement);
// 2.插入用户通告阅读标记表记录
String userId = toUser;
String[] userIds = userId.split(",");
String anntId = announcement.getId();
for (int i = 0; i < userIds.length; i++) {
if (oConvertUtils.isNotEmpty(userIds[i])) {
SysUser sysUser = userMapper.getUserByName(userIds[i]);
if (sysUser == null) {
continue;
}
SysAnnouncementSend announcementSend = new SysAnnouncementSend();
announcementSend.setAnntId(anntId);
announcementSend.setUserId(sysUser.getId());
announcementSend.setReadFlag(CommonConstant.NO_READ_FLAG);
sysAnnouncementSendMapper.insert(announcementSend);
JSONObject obj = new JSONObject();
obj.put(WebsocketConst.MSG_CMD, WebsocketConst.CMD_USER);
obj.put(WebsocketConst.MSG_USER_ID, sysUser.getId());
obj.put(WebsocketConst.MSG_ID, announcement.getId());
obj.put(WebsocketConst.MSG_TXT, announcement.getTitile());
webSocket.sendMessage(sysUser.getId(), obj.toJSONString());
}
}
try {
// 同步企业微信、钉钉的消息通知
dingtalkService.sendActionCardMessage(announcement, true);
wechatEnterpriseService.sendTextCardMessage(announcement, true);
} catch (Exception e) {
log.error("同步发送第三方APP消息失败!", e);
}
}
Aggregations