zouxuan il y a 3 ans
Parent
commit
13f94a1ed3

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

@@ -4,6 +4,7 @@ import org.springframework.data.annotation.Id;
 import org.springframework.data.mongodb.core.mapping.Document;
 
 import java.io.Serializable;
+import java.util.Objects;
 
 @Document(collection = "im_history_message")
 public class HistoryMessage implements Serializable {
@@ -147,4 +148,17 @@ public class HistoryMessage implements Serializable {
     public void setContent(String content) {
         this.content = content;
     }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        HistoryMessage that = (HistoryMessage) o;
+        return msgUID.equals(that.msgUID);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(msgUID);
+    }
 }

+ 8 - 8
mec-common/audit-log/src/main/java/com/yonge/log/service/impl/HistoryMessageServiceImpl.java

@@ -13,8 +13,8 @@ import java.io.*;
 import java.nio.ByteBuffer;
 import java.nio.channels.FileChannel;
 import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 import java.util.zip.ZipInputStream;
@@ -50,17 +50,17 @@ public class HistoryMessageServiceImpl extends BaseServiceImplWithMongo<String,
 			zin = new ZipInputStream(new FileInputStream(file), StandardCharsets.UTF_8);
 			ZipFile zf = new ZipFile(file);
 			ZipEntry ze;
-			List<HistoryMessage> historyMessages = new ArrayList<>();
+			Set<HistoryMessage> historyMessages = new HashSet<>();
 			while ((ze = zin.getNextEntry()) != null) {
 				BufferedReader br = new BufferedReader(new InputStreamReader(zf.getInputStream(ze)));
 				String line;
 				while ((line = br.readLine()) != null) {
 					try {
 						historyMessages.add(JSONObject.parseObject(line.substring(line.indexOf("{")), HistoryMessage.class));
-						if(historyMessages.size() >= 2000){
-							historyMessageDao.batchInsert(historyMessages,HistoryMessage.class);
-							historyMessages.clear();
-						}
+//						if(historyMessages.size() >= 2000){
+//							historyMessageDao.batchInsert(new ArrayList<>(historyMessages),HistoryMessage.class);
+//							historyMessages.clear();
+//						}
 					}catch (Exception e){
 						e.printStackTrace();
 					}
@@ -69,7 +69,7 @@ public class HistoryMessageServiceImpl extends BaseServiceImplWithMongo<String,
 				break;
 			}
 			if(historyMessages.size() > 0){
-				historyMessageDao.batchInsert(historyMessages,HistoryMessage.class);
+				historyMessageDao.batchInsert(historyMessages.stream().sorted(Comparator.comparing(HistoryMessage::getDateTime)).collect(Collectors.toList()),HistoryMessage.class);
 			}
 		} catch (IOException e) {
 			e.printStackTrace();

+ 1 - 1
mec-web/src/main/java/com/ym/mec/web/controller/TaskController.java

@@ -120,7 +120,7 @@ public class TaskController extends BaseController {
 	@GetMapping(value = "/syncImHistoryMessageTask")
 	// 同步即时通讯聊天记录
 	public void syncImHistoryMessageTask(String date) throws Exception {
-//		date = "2021060214";
+//		date = "2021060710";
 		if(date == null){
 			date = DateUtil.format(DateUtil.addHours(new Date(),-2), DateUtil.YEAR_MONTH_DAY_HOUR);
 		}