zyx преди 2 години
родител
ревизия
42d671a623

+ 0 - 1
src/main/java/com/cxzx/config/KafkaConfig.java

@@ -50,7 +50,6 @@ public class KafkaConfig {
         //根证书store的密码,保持不变。
         //接入协议,目前支持使用SASL_SSL协议接入。
         props.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "SASL_SSL");
-        props.put(CommonClientConfigs.GROUP_ID_CONFIG, "cxzx");
         //SASL鉴权方式,保持不变。
         props.put(SaslConfigs.SASL_MECHANISM, "PLAIN");
         props.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, jksPath);

+ 78 - 0
src/main/java/com/cxzx/taide/CreateAction.java

@@ -0,0 +1,78 @@
+package com.cxzx.taide;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@NoArgsConstructor
+@Data
+public class CreateAction {
+
+    @JsonProperty("data")
+    private DataDTO data;
+    @JsonProperty("eventType")
+    private String eventType;
+
+    @NoArgsConstructor
+    @Data
+    public static class DataDTO {
+        @JsonProperty("itemType")
+        private Integer itemType;
+        @JsonProperty("playTimes")
+        private Integer playTimes;
+        @JsonProperty("publishDate")
+        private String publishDate;
+        @JsonProperty("recommend")
+        private Integer recommend;
+        @JsonProperty("title")
+        private String title;
+        @JsonProperty("content")
+        private String content;
+        @JsonProperty("photo4")
+        private String photo4;
+        @JsonProperty("duration")
+        private String duration;
+        @JsonProperty("idaasGroupId")
+        private String idaasGroupId;
+        @JsonProperty("videoUrl")
+        private String videoUrl;
+        @JsonProperty("handlerPhone")
+        private String handlerPhone;
+        @JsonProperty("appId")
+        private String appId;
+        @JsonProperty("likeShare")
+        private Integer likeShare;
+        @JsonProperty("action")
+        private Integer action;
+        @JsonProperty("tag")
+        private String tag;
+        @JsonProperty("keyword")
+        private String keyword;
+        @JsonProperty("contentType")
+        private String contentType;
+        @JsonProperty("docZan")
+        private Integer docZan;
+        @JsonProperty("author")
+        private String author;
+        @JsonProperty("docType")
+        private Integer docType;
+        @JsonProperty("fuseId")
+        private Long fuseId;
+        @JsonProperty("allowComment")
+        private Integer allowComment;
+        @JsonProperty("token")
+        private String token;
+        @JsonProperty("docFrom")
+        private String docFrom;
+        @JsonProperty("allowAdvert")
+        private Integer allowAdvert;
+        @JsonProperty("isAudio")
+        private Integer isAudio;
+        @JsonProperty("showAvatar")
+        private Integer showAvatar;
+        @JsonProperty("channelID")
+        private Integer channelID;
+        @JsonProperty("showRead")
+        private Integer showRead;
+    }
+}

+ 32 - 0
src/main/java/com/cxzx/taide/PublishAction.java

@@ -0,0 +1,32 @@
+package com.cxzx.taide;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@NoArgsConstructor
+@Data
+public class PublishAction {
+
+    @JsonProperty("data")
+    private DataDTO data;
+    @JsonProperty("eventType")
+    private String eventType;
+
+    @NoArgsConstructor
+    @Data
+    public static class DataDTO {
+        @JsonProperty("idaasGroupId")
+        private String idaasGroupId;
+        @JsonProperty("appId")
+        private String appId;
+        @JsonProperty("fuseId")
+        private Long fuseId;
+        @JsonProperty("action")
+        private Integer action;
+        @JsonProperty("channelID")
+        private Integer channelID;
+        @JsonProperty("token")
+        private String token;
+    }
+}

+ 61 - 12
src/main/java/com/cxzx/taide/PushTestData.java

@@ -1,30 +1,79 @@
 package com.cxzx.taide;
 
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.util.IdUtil;
 import com.cxzx.config.KafkaConfig;
-import com.cxzx.db.KafkaData;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import lombok.Cleanup;
+import lombok.SneakyThrows;
 import org.apache.kafka.clients.producer.KafkaProducer;
 import org.apache.kafka.clients.producer.ProducerRecord;
 
 import java.util.Date;
 
-import static com.cxzx.db.Tidb.articleData;
-
 public class PushTestData {
+    private static final ObjectMapper objectMapper = new ObjectMapper();
+
+    @SneakyThrows
     public static void main(String[] args) {
         @Cleanup
         var producer = new KafkaProducer<String, String>(KafkaConfig.getKafkaProducerProperties());
-        long offset = 0;
+        var snowflake = IdUtil.getSnowflake();
+
+        var create = newDefaultCreate();
+        var publishOri = newDefaultPublish();
+        var publishRef = newDefaultPublish();
+        var reference = newDefaultReference();
         while (true) {
-            var articleDataList = articleData(offset, 1000);
-            if (articleDataList.size() == 0) {
-                break;
-            }
-            for (KafkaData data : articleDataList) {
-                producer.send(new ProducerRecord<>("article_test", 0, new Date().getTime(), "", data.getData()));
-                offset = data.getOffset();
-            }
+                var time = new DateTime().toString();
+                var fuseId = snowflake.nextId();
+                var newFuseId = snowflake.nextId();
+
+                // 原稿
+                create.getData().setFuseId(fuseId);
+                create.getData().setTitle("张云翔测试 "+time);
+                producer.send(new ProducerRecord<>("article_test", 0, new Date().getTime(), "", objectMapper.writeValueAsString(create)));
+
+                // 引用稿
+                var referenceData = reference.getData();
+                referenceData.setFuseId(fuseId);
+                referenceData.setNewFuseId(newFuseId);
+                producer.send(new ProducerRecord<>("article_test", 0, new Date().getTime(), "", objectMapper.writeValueAsString(reference)));
+
+                // 发布原稿
+                publishOri.getData().setFuseId(fuseId);
+                producer.send(new ProducerRecord<>("article_test", 0, new Date().getTime(), "", objectMapper.writeValueAsString(publishOri)));
+
+                // 发布引用稿
+                var publishRefData = publishRef.getData();
+                publishRefData.setFuseId(newFuseId);
+                publishRefData.setChannelID(referenceData.getRecommendChannel());
+                producer.send(new ProducerRecord<>("article_test", 0, new Date().getTime(), "", objectMapper.writeValueAsString(publishRef)));
+            Thread.sleep(500);
         }
 
     }
+
+    @SneakyThrows
+    private static CreateAction newDefaultCreate() {
+        return objectMapper.readValue("""
+                {"data":{"itemType":2,"playTimes":1,"publishDate":"2023-02-02 10:08:05","recommend":1,"title":"都市热线(2023-02-01)","content":"<!--PLAYERCODESTART--><script type=\\"text/javascript\\" src=\\"https://vmsplayer.chinamcloud.com/cmcMediaPlayer.js\\"></script><div id=\\"db893a34802a4318a915c0b095e22ec9\\"></div><script type=\\"text/javascript\\"> var uuid=\\"db893a34802a4318a915c0b095e22ec9\\"; var options = {}; options.url=\\"https://cdn-ronghe.sxtvs.com.cn/cr/video/xbw-20230202101150-9D28MfmBPi.mp4\\"; options.mediaType=\\"5\\"; options.fileHost=\\"https://vmsplayer.chinamcloud.com/\\"; options.playerMode=\\"default\\"; options.width=\\"650\\"; options.height=\\"485\\"; options.autoPlay=false; options.loadInfo=false; options.skin=\\"blue\\"; options.cross=false; var cmcMediaPlayer = new CmcMediaPlayer(uuid, options);</script><!--PLAYERCODEEND-->","photo4":"https://cdn-ronghe.sxtvs.com.cn/cr/img/xbw-20230202101150-9D28MfmBPi.jpg","duration":"2813110","idaasGroupId":"843ea558d5ef41a1877584c62762632d","videoUrl":"https://cdn-ronghe.sxtvs.com.cn/cr/video/xbw-20230202101150-9D28MfmBPi.mp4","handlerPhone":"18720000037","appId":"0","likeShare":1,"action":7,"tag":"都市热线","keyword":"都市热线","contentType":"","docZan":1,"author":"都市热线","docType":1,"fuseId":663092,"allowComment":1,"token":"62b214606c4411b67fc399d7b76ca69b","docFrom":"都市热线","allowAdvert":1,"isAudio":2,"showAvatar":1,"channelID":1385,"showRead":1},"eventType":"article"}
+                """, CreateAction.class);
+    }
+
+    @SneakyThrows
+    private static PublishAction newDefaultPublish() {
+        return objectMapper.readValue("""
+                {"data":{"idaasGroupId":"843ea558d5ef41a1877584c62762632d","appId":"0","fuseId":663118,"action":4,"channelID":1385,"token":"62b214606c4411b67fc399d7b76ca69b"},"eventType":"article"}
+                                                                                """, PublishAction.class);
+    }
+
+    @SneakyThrows
+    private static ReferenceAction newDefaultReference() {
+        return objectMapper.readValue("""
+                {"data":{"auditFlag":0,"newFuseId":663094,"idaasGroupId":"843ea558d5ef41a1877584c62762632d","handlerPhone":"18720000037","appId":"0","fuseId":663092,"action":9,"recommendChannel":292,"token":"62b214606c4411b67fc399d7b76ca69b"},"eventType":"article"}
+                                                                                                """, ReferenceAction.class);
+    }
+
+
 }

+ 38 - 0
src/main/java/com/cxzx/taide/ReferenceAction.java

@@ -0,0 +1,38 @@
+package com.cxzx.taide;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@NoArgsConstructor
+@Data
+public class ReferenceAction {
+
+    @JsonProperty("data")
+    private DataDTO data;
+    @JsonProperty("eventType")
+    private String eventType;
+
+    @NoArgsConstructor
+    @Data
+    public static class DataDTO {
+        @JsonProperty("auditFlag")
+        private Integer auditFlag;
+        @JsonProperty("newFuseId")
+        private Long newFuseId;
+        @JsonProperty("idaasGroupId")
+        private String idaasGroupId;
+        @JsonProperty("handlerPhone")
+        private String handlerPhone;
+        @JsonProperty("appId")
+        private String appId;
+        @JsonProperty("fuseId")
+        private Long fuseId;
+        @JsonProperty("action")
+        private Integer action;
+        @JsonProperty("recommendChannel")
+        private Integer recommendChannel;
+        @JsonProperty("token")
+        private String token;
+    }
+}