|
|
@@ -0,0 +1,82 @@
|
|
|
+package cn.seecoder.data.server.schedule;
|
|
|
+
|
|
|
+import cn.seecoder.data.server.domain.GeneralRecordDao;
|
|
|
+import cn.seecoder.data.server.domain.PlaygroundDao;
|
|
|
+import cn.seecoder.data.server.repository.GeneralRecordRepository;
|
|
|
+import cn.seecoder.data.server.repository.PlaygroungRepository;
|
|
|
+import cn.seecoder.data.server.service.ExtractionLogService;
|
|
|
+import cn.seecoder.data.server.utils.aspects.dataExtraction.DataExtractor;
|
|
|
+import cn.seecoder.judgement.PlaygroundClient;
|
|
|
+import cn.seecoder.judgement.PlaygroundException;
|
|
|
+import cn.seecoder.judgement.StudentAnswerRecordVO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.format.datetime.standard.DateTimeFormatterFactory;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.LinkedList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class PlaygroundSchedule {
|
|
|
+
|
|
|
+ @Value("${remoteUrls.playground}")
|
|
|
+ private String playgroundBaseUrl;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExtractionLogService extractionLogService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GeneralRecordRepository generalRecordRepository;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PlaygroungRepository playgroungRepository;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate restTemplate;
|
|
|
+
|
|
|
+ private final String source = "playground";
|
|
|
+
|
|
|
+// @Scheduled(cron = "00 00 00 * * ?")
|
|
|
+ @DataExtractor(source)
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void playGroundDataExtraction() throws Exception {
|
|
|
+ PlaygroundClient playgroundClient = new PlaygroundClient(playgroundBaseUrl,"");
|
|
|
+ LocalDateTime start = extractionLogService.getExtractionStartTime(source);
|
|
|
+ LocalDateTime end = extractionLogService.getExtractionEndTime(source);
|
|
|
+ List<StudentAnswerRecordVO> studentAnswerRecordVOList = playgroundClient.getLevel(start.toString(),end.toString());
|
|
|
+
|
|
|
+ DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ studentAnswerRecordVOList.forEach(studentAnswerRecordVO -> {
|
|
|
+ GeneralRecordDao tmpGeneralRecordDao = GeneralRecordDao.builder().dataSource("playground")
|
|
|
+ .answer(studentAnswerRecordVO.getAnswer())
|
|
|
+ .pass(studentAnswerRecordVO.isCorrect()?1:0)
|
|
|
+ .questionId(studentAnswerRecordVO.getQuestionId())
|
|
|
+ .score(studentAnswerRecordVO.isCorrect()?5:0)
|
|
|
+ .scoreTotal(5)
|
|
|
+ .startTime(LocalDateTime.parse(studentAnswerRecordVO.getStartTime(),df)) //playground的开始结束时间就是做每道题的开始结束时间
|
|
|
+ .endTime(LocalDateTime.parse(studentAnswerRecordVO.getEndTime(),df))
|
|
|
+ .submitTime(LocalDateTime.parse(studentAnswerRecordVO.getEndTime(),df))
|
|
|
+ .userId(Math.toIntExact(studentAnswerRecordVO.getUserId()))
|
|
|
+ .id(null)
|
|
|
+ .createTime(null)
|
|
|
+ .updateTime(null).build();
|
|
|
+ tmpGeneralRecordDao = generalRecordRepository.save(tmpGeneralRecordDao);
|
|
|
+
|
|
|
+ PlaygroundDao playgroundDao = PlaygroundDao.builder()
|
|
|
+ .generalId(tmpGeneralRecordDao.getId())
|
|
|
+ .levelId(Math.toIntExact(studentAnswerRecordVO.getLevelId())) // Long转int的问题短期应该不会遇到。。除非这系统亿万并发量(手动滑稽
|
|
|
+ .levelName(studentAnswerRecordVO.getLevelName())
|
|
|
+ .subjectId(Math.toIntExact(studentAnswerRecordVO.getSubjectId()))
|
|
|
+ .id(null)
|
|
|
+ .build();
|
|
|
+ playgroungRepository.save(playgroundDao);
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|