Explorar o código

update DiskUnitTest

reghao hai 1 semana
pai
achega
df450620dc
Modificáronse 1 ficheiros con 56 adicións e 17 borrados
  1. 56 17
      file/file-service/src/test/java/DiskUnitTest.java

+ 56 - 17
file/file-service/src/test/java/DiskUnitTest.java

@@ -1,7 +1,6 @@
 import cn.reghao.jutil.jdk.converter.DateTimeConverter;
 import cn.reghao.jutil.jdk.serializer.JsonConverter;
 import cn.reghao.jutil.jdk.string.SnowFlake;
-import cn.reghao.oss.api.constant.ObjectAction;
 import cn.reghao.oss.api.dto.ObjectInfo;
 import cn.reghao.oss.api.dto.ServerInfo;
 import cn.reghao.oss.api.dto.rest.UploadFileRet;
@@ -10,9 +9,9 @@ import cn.reghao.tnb.file.app.FileApplication;
 import cn.reghao.tnb.file.app.zchat.db.mapper.ChatFileMapper;
 import cn.reghao.tnb.file.app.zchat.db.mapper.ChatMessageMapper;
 import cn.reghao.tnb.file.app.zchat.model.constant.ChatMsgType;
-import cn.reghao.tnb.file.app.zchat.model.constant.ChatType;
-import cn.reghao.tnb.file.app.zchat.model.po.chat.ChatMessage;
-import cn.reghao.tnb.file.app.zchat.model.po.message.ChatFile;
+import cn.reghao.tnb.file.app.zchat.model.po.ChatMessage;
+import cn.reghao.tnb.file.app.zchat.model.po.ChatCall;
+import cn.reghao.tnb.file.app.zchat.model.po.ChatFile;
 import com.google.gson.JsonArray;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
@@ -72,8 +71,7 @@ public class DiskUnitTest {
     private void parseTelegram() {
         List<ChatMessage> chatMessageList = new ArrayList<>();
         List<ChatFile> chatFileList = new ArrayList<>();
-
-        Set<String> types = new HashSet<>();
+        List<ChatCall> chatCallList = new ArrayList<>();
 
         String path = baseDir + "/result.json";
         File jsonFile = new File(path);
@@ -86,16 +84,30 @@ public class DiskUnitTest {
             try {
                 long id = jsonObject1.get("id").getAsLong();
                 String date = jsonObject1.get("date").getAsString();
+                LocalDateTime createAt = DateTimeConverter.localDateTime2(date.replace("T", " "));
                 String type = jsonObject1.get("type").getAsString();
                 if ("service".equals(type)) {
-                    System.out.printf("%s service msg type, continue next loop\n", date);
+                    long senderId = jsonObject1.get("actor_id").getAsLong();
+                    long messageId = snowFlake.nextId();
+                    ChatMessage chatMessage = new ChatMessage(messageId, chatId, senderId, createAt);
+                    chatMessage.setMsgType(ChatMsgType.audioCall.getCode());
+
+                    String callType = "audio";
+                    double duration = 0.0D;
+                    String discardReason = jsonObject1.get("discard_reason").getAsString();
+                    if ("hangup".equals(discardReason)) {
+                        duration = jsonObject1.get("duration_seconds").getAsDouble();
+                    }
+
+                    ChatCall chatCall = new ChatCall(messageId, callType, duration, discardReason);
+                    chatCallList.add(chatCall);
+                    chatMessageList.add(chatMessage);
                     continue;
                 }
                 String from = jsonObject1.get("from").getAsString();
                 long fromId = jsonObject1.get("from_id").getAsLong();
 
                 long senderId = userMap.get(fromId);
-                LocalDateTime createAt = DateTimeConverter.localDateTime2(date.replace("T", " "));
                 long messageId = snowFlake.nextId();
                 ChatMessage chatMessage = new ChatMessage(messageId, chatId, senderId, createAt);
 
@@ -138,7 +150,6 @@ public class DiskUnitTest {
                 if (jsonObject1.get("media_type") != null) {
                     mediaType = jsonObject1.get("media_type").getAsString();
                 }
-                //types.add(mediaType);
 
                 if (!mediaType.equals("NoMedia")) {
                     String filePath = jsonObject1.get("file").getAsString();
@@ -173,11 +184,39 @@ public class DiskUnitTest {
                         ChatFile chatFile = new ChatFile(chatMessage.getMessageId(), objectInfo);
                         chatFileList.add(chatFile);
                     } else if ("animation".equals(mediaType)) {
-                        //System.out.println();
-                        types.add(filePath);
+                        if (filePath.endsWith("gif.mp4")) {
+                            String filePath1 = filePath.replace(".mp4", "");
+                            File file1 = new File(baseDir + "/" + filePath1);
+                            if (!file1.exists()) {
+                                System.out.printf("file message %s not exist, continue next loop\n", filePath1);
+                                continue;
+                            }
+                        }
+
+                        chatMessage.setMsgType(ChatMsgType.image.getCode());
+
+                        UploadFileRet uploadFileRet = uploadFile(file);
+                        String objectId = uploadFileRet.getUploadId();
+                        ObjectInfo objectInfo = getOssClient().getObjectInfo(objectId);
+                        ChatFile chatFile = new ChatFile(chatMessage.getMessageId(), objectInfo);
+                        chatFileList.add(chatFile);
                     } else if ("sticker".equals(mediaType)) {
-                        //System.out.println();
-                        types.add(filePath);
+                        if (filePath.endsWith(".tgs")) {
+                            String filePath1 = filePath + "_thumb.jpg";
+                            File file1 = new File(baseDir + "/" + filePath1);
+                            if (!file1.exists()) {
+                                System.out.printf("file message %s not exist, continue next loop\n", filePath1);
+                                continue;
+                            }
+                        }
+
+                        chatMessage.setMsgType(ChatMsgType.image.getCode());
+
+                        UploadFileRet uploadFileRet = uploadFile(file);
+                        String objectId = uploadFileRet.getUploadId();
+                        ObjectInfo objectInfo = getOssClient().getObjectInfo(objectId);
+                        ChatFile chatFile = new ChatFile(chatMessage.getMessageId(), objectInfo);
+                        chatFileList.add(chatFile);
                     }
                 }
 
@@ -194,9 +233,8 @@ public class DiskUnitTest {
                     String objectId = uploadFileRet.getUploadId();
                     ObjectInfo objectInfo = getOssClient().getObjectInfo(objectId);
                     ChatFile chatFile = new ChatFile(chatMessage.getMessageId(), objectInfo);
-                    chatFileList.add(chatFile);;
+                    chatFileList.add(chatFile);
                 }
-                //System.out.printf("%s - %s[%s]: %s\n", date, fromId, from, text);
                 //System.out.printf("%s - %s[%s]\n", date, fromId, from);
                 chatMessageList.add(chatMessage);
             } catch (Exception e) {
@@ -204,8 +242,9 @@ public class DiskUnitTest {
             }
         }
 
-        chatFileMapper.saveAll(chatFileList);
-        chatMessageMapper.saveAll(chatMessageList);
+        System.out.println();
+        /*chatFileMapper.saveAll(chatFileList);
+        chatMessageMapper.saveAll(chatMessageList);*/
     }
 
     long chatId = 10002L;