فهرست منبع

消息通知base

huey 1 سال پیش
والد
کامیت
8f89b5af5e

+ 1 - 1
src/main/java/com/dragon/tj/portal/common/convert/notice/NoticeReqConvert.java

@@ -18,7 +18,7 @@ public interface NoticeReqConvert {
      * <p>
      * Mapping可以处理变量名不一致映射关系以及指定日期格式等等
      */
-    MessageInfoItem reqToItem(MessageInfoReq messageInfoReq);
+    MessageInfoItem reqToItem(NoticeInfoReq messageInfoReq);
 
     NoticeInfo reqToInfo(NoticeInfoReq noticeInfoReq);
 

+ 1 - 1
src/main/java/com/dragon/tj/portal/common/dto/notice/NoticeInfoReq.java

@@ -21,7 +21,7 @@ public class NoticeInfoReq {
     /**
     *范围id 为appCode
     */
-    private String scopeId = "appId";
+    private String scopeId;
 
     @Range(min = 4, max = 6, message = "请填入4~6,4 任务类 5 通知类 6 超期提醒类")
     private Integer messageType;

+ 10 - 4
src/main/java/com/dragon/tj/portal/component/message/MessageConsumer.java

@@ -4,9 +4,12 @@ import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.dragon.tj.portal.common.convert.mesage.MessageReqConvert;
+import com.dragon.tj.portal.common.convert.notice.NoticeReqConvert;
 import com.dragon.tj.portal.common.dto.message.MessageInfoItem;
 import com.dragon.tj.portal.common.dto.message.MessageInfoReq;
 import com.dragon.tj.portal.common.dto.message.MessageInfoSend;
+import com.dragon.tj.portal.common.dto.notice.NoticeInfoReq;
+import com.dragon.tj.portal.common.dto.notice.NoticeInfoSend;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.MediaType;
@@ -33,6 +36,9 @@ public class MessageConsumer {
     @Autowired
     private MessageReqConvert messageReqConvert;
 
+    @Autowired
+    private NoticeReqConvert noticeReqConvert;
+
     /**
      * get client published message from kafka,process it according to the serverId
      *
@@ -84,15 +90,15 @@ public class MessageConsumer {
             log.error("kafka msg is empty, no process");
             return;
         }
-        MessageInfoSend reqDTO;
+        NoticeInfoSend reqDTO;
         try {
-            reqDTO = JSONObject.parseObject(msg, MessageInfoSend.class);
+            reqDTO = JSONObject.parseObject(msg, NoticeInfoSend.class);
         } catch (Exception e) {
             log.error("parsing string to obj failed, msg={}, e={}", msg, e);
             return;
         }
         Set<String> clientIds = reqDTO.getClientIds();
-        MessageInfoReq messageInfoReq = reqDTO.getMessageInfoReq();
+        NoticeInfoReq noticeInfoReq = reqDTO.getNoticeInfoReq();
 
         for (String clientId : clientIds) {
             OpenApiSseEmitter emitter = sseEmitters.get(clientId);
@@ -101,7 +107,7 @@ public class MessageConsumer {
                 continue;
             }
             try {
-                MessageInfoItem messageInfoItem = messageReqConvert.reqToItem(messageInfoReq);
+                MessageInfoItem messageInfoItem = noticeReqConvert.reqToItem(noticeInfoReq);
                 messageInfoItem.setClientId(clientId);
 
                 String sendMsg = JSON.toJSONString(messageInfoItem);

+ 0 - 3
src/main/java/com/dragon/tj/portal/controller/MessageCenterController.java

@@ -37,9 +37,6 @@ public class MessageCenterController {
     @Autowired
     private NoticeInfoService noticeInfoService;
 
-    @Autowired
-    private MessageProducer producer;
-
     /**
      * @author huey China.
      * @Description : 信息发送

+ 1 - 1
src/main/java/com/dragon/tj/portal/service/impl/NoticeInfoServiceImpl.java

@@ -136,7 +136,7 @@ public class NoticeInfoServiceImpl extends ServiceImpl<NoticeInfoMapper, NoticeI
         log.info("transferIds-scopeId-{}-{}",scopeId,messageClientIds);
         if (CollUtil.isNotEmpty(messageClientIds)) {
             NoticeInfoSend noticeInfoSend = this.doSaveNoticeInfo(noticeInfoReq, messageClientIds);
-            isSend = producer.send(KafkaInitialConfiguration.sseTopic + "a1", JSON.toJSONString(noticeInfoSend));
+            isSend = producer.send("sseTopic-a1", JSON.toJSONString(noticeInfoSend));
             if (isSend) {
                 MsgRecord msgRecord = new MsgRecord();
                 msgRecord.setCreateBy("admin");