package com.huaheng.common.utils; import com.huaheng.common.constant.SendTypeConstants; import com.huaheng.framework.web.domain.AjaxResult; import com.huaheng.framework.web.service.WebSocketServer; import com.huaheng.pc.config.sendMail.service.MailService; import com.huaheng.pc.system.notice.domain.SysNotice; import com.huaheng.pc.system.notice.service.SysNoticeService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import javax.annotation.Resource; import java.io.IOException; /** * 发送通知工具类 * @author mahua */ @Component public class SendNoticeUtils { private static SendNoticeUtils staticInstance; @Resource private MailService mailService; @Resource private SysNoticeService noticeService; public SendNoticeUtils() { super(); // TODO Auto-generated constructor stub } @PostConstruct public void init() { staticInstance = this; staticInstance.mailService = this.mailService; staticInstance.noticeService = this.noticeService; } public static AjaxResult sendNotice(String subject, String body, Integer type, String[] to, String[] cc) { SysNotice notice = new SysNotice(); staticInstance.noticeService.save(notice); if (type.equals(SendTypeConstants.EMAIL)) { // mailService.sendSimpleMail(to, subject, body, cc); } else if (type.equals(SendTypeConstants.WEBSOCKET_USER)) { for (String userId : to) { try { WebSocketServer.sendInfo(body, userId); } catch (IOException e) { e.printStackTrace(); } } } else if (type.equals(SendTypeConstants.WEBSOCKET_BROADCAST)) { try { WebSocketServer.sendInfo(body, ""); } catch (IOException e) { e.printStackTrace(); } } return AjaxResult.success(); } }