Search in sources :

Example 1 with WechatSendRequest

use of com.topcom.cms.yuqing.vo.request.WechatSendRequest in project topcom-cloud by 545314690.

the class WarningJob method sendWechat.

/**
 * 发送微信
 * @param page
 * @param subject
 * @param wangningLogId
 */
private void sendWechat(Page page, CustomSubject subject, Long wangningLogId) {
    WarningTask warningTask = subject.getWarning();
    logger.info("开始推送Wechat消息:" + subject.getName());
    List<Contact> contacts = warningTask.getContacts();
    Set<String> wechatSet = contacts.stream().filter(contact -> Contact.Type.WECHAT.equals(contact.getType())).map(contact -> contact.getAccount()).collect(Collectors.toSet());
    WechatSendRequest wechatSendRequest = new WechatSendRequest();
    JSONObject data = getData(page.getContent());
    User user = userManager.findById(subject.getUserId());
    // userName
    setData(data, "name", user.getFullName() == null ? user.getUsername() : user.getFullName());
    setData(data, "subjectName", subject.getName());
    setData(data, "num", page.getTotalElements());
    wechatSendRequest.setData(data);
    wechatSendRequest.setTemplate_id(TEMPLATE_ID);
    wechatSendRequest.setUrl(warningEmailSetting.getLogUrl());
    if (wechatSet.size() > 0) {
        for (String s : wechatSet) {
            wechatSendRequest.setTouser(s);
            wechatUtil.sendTemplate(JSONObject.fromObject(wechatSendRequest));
        }
        warningTask.setLastWarningDate(new Date());
        warningManager.save(warningTask);
    }
}
Also used : WarningEmailBody(com.topcom.cms.yuqing.vo.email.WarningEmailBody) Date(java.util.Date) TemplateException(freemarker.template.TemplateException) Logger(org.jboss.logging.Logger) Autowired(org.springframework.beans.factory.annotation.Autowired) MessagingException(javax.mail.MessagingException) Job(org.quartz.Job) com.topcom.cms.yuqing.domain(com.topcom.cms.yuqing.domain) SubscriptionFollowerManager(com.topcom.cms.yuqing.service.SubscriptionFollowerManager) Map(java.util.Map) Pageable(org.springframework.data.domain.Pageable) CustomSubjectManager(com.topcom.cms.yuqing.service.CustomSubjectManager) Sender(com.topcom.cms.yuqing.task.sender.Sender) ServerProperties(org.springframework.boot.autoconfigure.web.ServerProperties) WechatUtil(com.topcom.cms.yuqing.utils.WechatUtil) WebUtils(org.springframework.web.util.WebUtils) JobExecutionContext(org.quartz.JobExecutionContext) UserManager(com.topcom.cms.service.UserManager) SenderFactory(com.topcom.cms.yuqing.task.sender.factory.SenderFactory) User(com.topcom.cms.domain.User) WechatSendRequest(com.topcom.cms.yuqing.vo.request.WechatSendRequest) WarningEmailSetting(com.topcom.cms.yuqing.vo.email.WarningEmailSetting) PageRequest(org.springframework.data.domain.PageRequest) Set(java.util.Set) IOException(java.io.IOException) Page(org.springframework.data.domain.Page) WarningManager(com.topcom.cms.yuqing.service.WarningManager) Collectors(java.util.stream.Collectors) EmailSenderFactory(com.topcom.cms.yuqing.task.sender.factory.EmailSenderFactory) JobExecutionException(org.quartz.JobExecutionException) WarningLogManager(com.topcom.cms.yuqing.service.WarningLogManager) Component(org.springframework.stereotype.Component) List(java.util.List) WeChat(com.topcom.cms.data.domain.WeChat) WarningEmail(com.topcom.cms.yuqing.vo.email.WarningEmail) PostConstruct(javax.annotation.PostConstruct) JSONObject(net.sf.json.JSONObject) WechatSendRequest(com.topcom.cms.yuqing.vo.request.WechatSendRequest) User(com.topcom.cms.domain.User) JSONObject(net.sf.json.JSONObject) Date(java.util.Date)

Aggregations

WeChat (com.topcom.cms.data.domain.WeChat)1 User (com.topcom.cms.domain.User)1 UserManager (com.topcom.cms.service.UserManager)1 com.topcom.cms.yuqing.domain (com.topcom.cms.yuqing.domain)1 CustomSubjectManager (com.topcom.cms.yuqing.service.CustomSubjectManager)1 SubscriptionFollowerManager (com.topcom.cms.yuqing.service.SubscriptionFollowerManager)1 WarningLogManager (com.topcom.cms.yuqing.service.WarningLogManager)1 WarningManager (com.topcom.cms.yuqing.service.WarningManager)1 Sender (com.topcom.cms.yuqing.task.sender.Sender)1 EmailSenderFactory (com.topcom.cms.yuqing.task.sender.factory.EmailSenderFactory)1 SenderFactory (com.topcom.cms.yuqing.task.sender.factory.SenderFactory)1 WechatUtil (com.topcom.cms.yuqing.utils.WechatUtil)1 WarningEmail (com.topcom.cms.yuqing.vo.email.WarningEmail)1 WarningEmailBody (com.topcom.cms.yuqing.vo.email.WarningEmailBody)1 WarningEmailSetting (com.topcom.cms.yuqing.vo.email.WarningEmailSetting)1 WechatSendRequest (com.topcom.cms.yuqing.vo.request.WechatSendRequest)1 TemplateException (freemarker.template.TemplateException)1 IOException (java.io.IOException)1 Date (java.util.Date)1 List (java.util.List)1