Kaynağa Gözat

初始化消息体

liujc 1 yıl önce
ebeveyn
işleme
807952e8ca

+ 9 - 17
.idea/httpRequests/http-requests-log.http

@@ -1,3 +1,12 @@
+POST http://127.0.0.1:8805/api-web/imHistoryMessage/initMsgBodyJson
+Authorization: bearer f63411e7-63e0-48e4-bbfa-40413b97b744
+Content-Length: 0
+Connection: Keep-Alive
+User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.6)
+Accept-Encoding: br,deflate,gzip,x-gzip
+
+###
+
 POST http://127.0.0.1:8805/api-web/imHistoryMessage/historyMessage
 Authorization: bearer f63411e7-63e0-48e4-bbfa-40413b97b744
 Content-Type: application/json
@@ -872,20 +881,3 @@ Accept-Encoding: br,deflate,gzip,x-gzip
 
 ###
 
-POST http://127.0.0.1:8805/api-web/imHistoryMessage/historyMessage
-Authorization: bearer 3526591a-a4e9-488c-82f1-4a1e56a0c6a4
-Content-Type: application/json
-Content-Length: 29
-Connection: Keep-Alive
-User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.6)
-Accept-Encoding: br,deflate,gzip,x-gzip
-
-{
-  "page": 1,
-  "rows": 10
-}
-
-<> 2023-10-23T111115.200.json
-
-###
-

+ 2 - 0
mec-application/src/main/java/com/ym/mec/AppServerApplication.java

@@ -1,5 +1,6 @@
 package com.ym.mec;
 
+import com.spring4all.swagger.EnableSwagger2Doc;
 import com.ym.mec.config.AppBeanNameGenerator;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -15,6 +16,7 @@ import org.springframework.context.annotation.Configuration;
 @ComponentScan(basePackages = {"com.ym.mec", "org.snaker.engine", "com.yonge.log", "com.mec.redisson"})
 @MapperScan(basePackages = {"com.ym.mec.biz.**.dao", "com.yonge.datasource.dao", "com.ym.mec.biz.dal.mapper"})
 @Configuration
+@EnableSwagger2Doc
 public class AppServerApplication {
     public static void main(String[] args) {
         new SpringApplicationBuilder(AppServerApplication.class)

+ 1 - 1
mec-application/src/main/java/com/ym/mec/config/ResourceServerConfig.java

@@ -32,7 +32,7 @@ public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
                 .authorizeRequests()
                 .antMatchers("/api-web/task/**")
                 .hasIpAddress("0.0.0.0/0")
-                .antMatchers(
+                .antMatchers("/v2/api-docs",
                 //common
                         "/*/v2/api-docs", "/*/code/*",
 

+ 17 - 0
mec-application/src/main/java/com/ym/mec/web/controller/ImHistoryMessageController.java

@@ -99,6 +99,23 @@ public class ImHistoryMessageController extends BaseController {
         }
     }
 
+    @ApiOperation("初始化消息体")
+    @PostMapping(value = "/initMsgBodyJson")
+    public void initMsgBodyJson() throws Exception {
+        //计算总数据量
+        int count = historyMessageTenantService.initMsgBodyJsonCount();
+        log.info("总数据量:"+count);
+        //计算调用次数
+        int num = (int) Math.ceil(count / 100);
+        for (int i = 0; i <=num ; i++) {
+            int size =100;
+            //获取融云消息
+            //List<ImGroup> list = imGroupService.lambdaQuery().last("limit "+(page-1)*size+","+size).list();
+            historyMessageTenantService.initMsgBodyJson(1,size);
+            log.info("已转换:"+(i+1)*size);
+        }
+    }
+
     @ApiOperation("历史聊天记录查询")
     @PostMapping(value = "/historyMessage")
     public HttpResponseResult<PageInfo<HistoryMessageTencentWrapper.HistoryMessageTencent>> historyMessage(@RequestBody  HistoryMessageTencentWrapper.HistoryMessageTencentQuery query) throws Exception {

+ 4 - 0
mec-common/audit-log/src/main/java/com/yonge/log/dal/model/HistoryMessageTencent.java

@@ -67,4 +67,8 @@ public class HistoryMessageTencent implements Serializable {
 
     @Field("msg_body_json")
     private JSONArray msgBodyJson;
+
+
+    @Field("json_flag")
+    private Integer jsonFlag;
 }

+ 4 - 0
mec-common/audit-log/src/main/java/com/yonge/log/service/HistoryMessageTenantService.java

@@ -19,4 +19,8 @@ public interface HistoryMessageTenantService extends BaseServiceWithMongo<String
     PageInfo<HistoryMessageTencentWrapper.HistoryMessageTencent> historyMessage(HistoryMessageTencentWrapper.HistoryMessageTencentQuery query);
 
     void deleteOld();
+
+    int initMsgBodyJsonCount();
+
+    void initMsgBodyJson(int page, int size);
 }

+ 27 - 0
mec-common/audit-log/src/main/java/com/yonge/log/service/impl/HistoryMessageTenantServiceImpl.java

@@ -1,6 +1,7 @@
 package com.yonge.log.service.impl;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.yonge.log.dal.dao.HistoryMessageTenantDao;
 import com.yonge.log.dal.dao.OperationLogDao;
 import com.yonge.log.dal.model.HistoryMessage;
@@ -74,6 +75,32 @@ public class HistoryMessageTenantServiceImpl extends BaseServiceImplWithMongo<St
         mongoTemplate.remove(query,HistoryMessageTencent.class);
     }
 
+    @Override
+    public int initMsgBodyJsonCount() {
+        Query query = new Query();
+        Criteria criteria = Criteria.where("msg_body_json").is(null).orOperator(Criteria.where("json_flag").is(0),Criteria.where("syncFlag").is(null));
+        query.addCriteria(criteria);
+        return Long.valueOf(mongoTemplate.count(query,HistoryMessageTencent.class)).intValue();
+    }
+
+    @Override
+    public void initMsgBodyJson(int page, int size) {
+        Query query = new Query();
+        Criteria criteria = Criteria.where("msg_body_json").is(null).orOperator(Criteria.where("json_flag").is(0),Criteria.where("syncFlag").is(null));
+        query.addCriteria(criteria);
+        query.skip(page).limit(size);
+        List<HistoryMessageTencent> historyMessageTencents = mongoTemplate.find(query, HistoryMessageTencent.class);
+        for (HistoryMessageTencent historyMessageTencent : historyMessageTencents) {
+            historyMessageTencent.setJsonFlag(1);
+            try {
+                historyMessageTencent.setMsgBodyJson(JSON.parseArray(historyMessageTencent.getMsgBody()));
+            } catch (Exception e) {
+                historyMessageTencent.setMsgBodyJson(new JSONArray());
+            }
+            mongoTemplate.save(historyMessageTencent);
+        }
+    }
+
     private static Query getQuery(HistoryMessageTencentWrapper.HistoryMessageTencentQuery param) {
         Query query = new Query();
         Criteria criteria = new Criteria();

+ 1 - 9
mec-common/audit-log/src/main/java/com/yonge/log/wrapper/HistoryMessageTencentWrapper.java

@@ -64,7 +64,7 @@ public class HistoryMessageTencentWrapper {
     public static class HistoryMessageTencent implements Serializable {
 
 
-        @ApiModelProperty("发送日期")
+        @ApiModelProperty(value = "发送日期")
         private Long msgTime;
 
         @ApiModelProperty("类型C2C:单聊,GROUP:群聊")
@@ -73,11 +73,9 @@ public class HistoryMessageTencentWrapper {
         @ApiModelProperty("客户端IP")
         private String clientIp;
 
-        @JSONField(name = "CloudCustomData")
         @ApiModelProperty("自定义数据")
         private String cloudCustomData;
 
-        @JSONField(name = "From_Account")
         @ApiModelProperty("发送人")
         private String fromAccount;
 
@@ -88,27 +86,21 @@ public class HistoryMessageTencentWrapper {
         private String msgFromPlatform;
 
         @ApiModelProperty("消息随机数")
-        @JSONField(name = "MsgRandom")
         private Long msgRandom;
 
         @ApiModelProperty("消息序列号")
-        @JSONField(name = "MsgSeq")
         private Long msgSeq;
 
         @ApiModelProperty("消息时间戳")
-        @JSONField(name = "MsgTimeStamp")
         private Long msgTimestamp;
 
         @ApiModelProperty("接收人")
-        @JSONField(name = "To_Account")
         private String toAccount;
 
         @ApiModelProperty("群ID")
-        @JSONField(name = "GroupId")
         private String groupId;
 
         @ApiModelProperty("消息内容")
-        @JSONField(name = "MsgBody")
         private String msgBody;
 
     }