Search in sources :

Example 1 with SysMessageTemplate

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;
}
Also used : StringWriter(java.io.StringWriter) TemplateException(freemarker.template.TemplateException) SysMessage(org.jeecg.modules.message.entity.SysMessage) SysMessageTemplate(org.jeecg.modules.message.entity.SysMessageTemplate) IOException(java.io.IOException) Date(java.util.Date) SysMessageTemplate(org.jeecg.modules.message.entity.SysMessageTemplate) Template(freemarker.template.Template)

Example 2 with SysMessageTemplate

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;
}
Also used : SysMessageTemplate(org.jeecg.modules.message.entity.SysMessageTemplate) JeecgBootException(org.jeecg.common.exception.JeecgBootException)

Example 3 with SysMessageTemplate

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);
    }
}
Also used : SQLException(java.sql.SQLException) JeecgBootException(org.jeecg.common.exception.JeecgBootException) JSONObject(com.alibaba.fastjson.JSONObject) SysMessageTemplate(org.jeecg.modules.message.entity.SysMessageTemplate) JeecgBootException(org.jeecg.common.exception.JeecgBootException)

Example 4 with SysMessageTemplate

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);
    }
}
Also used : SQLException(java.sql.SQLException) JeecgBootException(org.jeecg.common.exception.JeecgBootException) JSONObject(com.alibaba.fastjson.JSONObject) SysMessageTemplate(org.jeecg.modules.message.entity.SysMessageTemplate) JeecgBootException(org.jeecg.common.exception.JeecgBootException)

Example 5 with SysMessageTemplate

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);
    }
}
Also used : SQLException(java.sql.SQLException) JeecgBootException(org.jeecg.common.exception.JeecgBootException) JSONObject(com.alibaba.fastjson.JSONObject) SysMessageTemplate(org.jeecg.modules.message.entity.SysMessageTemplate) JeecgBootException(org.jeecg.common.exception.JeecgBootException)

Aggregations

SysMessageTemplate (org.jeecg.modules.message.entity.SysMessageTemplate)12 JeecgBootException (org.jeecg.common.exception.JeecgBootException)9 JSONObject (com.alibaba.fastjson.JSONObject)6 SQLException (java.sql.SQLException)6 Template (freemarker.template.Template)3 TemplateException (freemarker.template.TemplateException)3 IOException (java.io.IOException)3 StringWriter (java.io.StringWriter)3 Date (java.util.Date)3 SysMessage (org.jeecg.modules.message.entity.SysMessage)3