소스 검색

完成日志数据解析功能

Miaomz 4 년 전
부모
커밋
4f71418f74

+ 5 - 5
src/main/java/com/seecoder/dataanalysis/logic/parser/impl/LogParsingServiceImpl.java

@@ -1,10 +1,10 @@
 package com.seecoder.dataanalysis.logic.parser.impl;
 
 import com.alibaba.fastjson.JSONException;
-import com.seecoder.dataanalysis.data.entity.eval.EvalExamInfo;
-import com.seecoder.dataanalysis.data.entity.eval.EvalExamRecord;
 import com.seecoder.dataanalysis.logic.parser.LogParsingService;
 import com.seecoder.dataanalysis.util.JsonUtil;
+import com.seecoder.dataanalysis.vo.EvalExamInfoDTO;
+import com.seecoder.dataanalysis.vo.EvalExamRecordDTO;
 import com.seecoder.dataanalysis.vo.SimpleLog;
 import org.springframework.stereotype.Service;
 
@@ -59,8 +59,8 @@ public class LogParsingServiceImpl implements LogParsingService {
     @PostConstruct
     protected void buildOpTypesTable(){
         opTypesTable = new HashMap<>();
-        opTypesTable.put(0, EvalExamInfo.class.getName());  //试卷数据
-        opTypesTable.put(1, EvalExamInfo.class.getName());  //诗句更新数据
-        opTypesTable.put(2, EvalExamRecord.class.getName());  //学生提交试卷
+        opTypesTable.put(0, EvalExamInfoDTO.class.getName());  //试卷数据
+        opTypesTable.put(1, EvalExamInfoDTO.class.getName());  //诗句更新数据
+        opTypesTable.put(2, EvalExamRecordDTO.class.getName());  //学生提交试卷
     }
 }

+ 10 - 2
src/test/java/com/seecoder/dataanalysis/logic/parser/impl/LogParsingServiceImplTest.java

@@ -1,13 +1,13 @@
 package com.seecoder.dataanalysis.logic.parser.impl;
 
 import com.seecoder.dataanalysis.util.FileUtil;
+import com.seecoder.dataanalysis.vo.EvalExamInfoDTO;
 import com.seecoder.dataanalysis.vo.SimpleLog;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * @author miaomuzhi
@@ -19,6 +19,7 @@ class LogParsingServiceImplTest {
     @BeforeEach
     void setUp() {
         parsingService = new LogParsingServiceImpl();
+        parsingService.buildOpTypesTable();
     }
 
     @AfterEach
@@ -36,9 +37,16 @@ class LogParsingServiceImplTest {
 
     @Test
     void parseLogData() {
+        String logContent = FileUtil.readFile(getClass().getResource("/sample_logs/gen0.log").getFile());
+        SimpleLog simpleLog = parsingService.parseLog(logContent);
+        Object o = parsingService.parseLogData(simpleLog, false);
+        assertTrue(o instanceof EvalExamInfoDTO);
+        System.out.println(o);
     }
 
     @Test
     void parseOpType() {
+        assertEquals("com.seecoder.dataanalysis.data.entity.eval.EvalExamInfo", parsingService.parseOpType(0));
+        assertNull(parsingService.parseOpType(-1));
     }
 }