|
@@ -0,0 +1,77 @@
|
|
|
+package com.redxun.knowledge.common;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.redxun.common.base.entity.IUser;
|
|
|
+import com.redxun.common.utils.ContextUtil;
|
|
|
+import com.redxun.dto.user.OsUserDto;
|
|
|
+import com.redxun.mq.MessageModel;
|
|
|
+import com.redxun.msgsend.util.MesAutoUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class MessageService {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送站内信
|
|
|
+ *
|
|
|
+ * @param title 标题
|
|
|
+ * @param content 内容
|
|
|
+ * @param userDtos 接收对象(内部消息所用)
|
|
|
+ */
|
|
|
+ public boolean sendInnerMsg(String title, String content, List<OsUserDto> userDtos) {
|
|
|
+ return doSendMsg(title, content, "inner", userDtos);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送站内信
|
|
|
+ *
|
|
|
+ * @param title 标题
|
|
|
+ * @param content 内容
|
|
|
+ * @param userDtos 接收对象(内部消息所用)
|
|
|
+ */
|
|
|
+ public boolean sendWechatMsg(String title, String content, List<OsUserDto> userDtos) {
|
|
|
+ return doSendMsg(title, content, "weixin", userDtos);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送消息
|
|
|
+ *
|
|
|
+ * @param title 标题
|
|
|
+ * @param content 内容
|
|
|
+ * @param type 消息类型: inner, weixin
|
|
|
+ * @param userDtos 接收对象(内部消息所用)
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Boolean doSendMsg(String title, String content, String type, List<OsUserDto> userDtos) {
|
|
|
+ try {
|
|
|
+ //获取当前登录的用户
|
|
|
+ IUser curUser = ContextUtil.getCurrentUser();
|
|
|
+ OsUserDto sender = new OsUserDto();
|
|
|
+ sender.setUserId(curUser.getUserId());
|
|
|
+ sender.setFullName(curUser.getFullName());
|
|
|
+
|
|
|
+ //接收者
|
|
|
+ //发送消息
|
|
|
+ MessageModel messageModel = new MessageModel();
|
|
|
+ //发送人
|
|
|
+ messageModel.setSender(sender);
|
|
|
+ //消息类型
|
|
|
+ messageModel.setMsgType(type);
|
|
|
+ //标题
|
|
|
+ messageModel.setSubject(title);
|
|
|
+ //内容
|
|
|
+ messageModel.setContent(content);
|
|
|
+ //接收人
|
|
|
+ messageModel.setReceivers(userDtos);
|
|
|
+ MesAutoUtil.sendMessage(JSONObject.toJSONString(messageModel));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("sendMsg通知发送失败: {}", e.getMessage());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+}
|