|
|
@@ -38,34 +38,69 @@ public class CoderSchedule {
|
|
|
@Autowired
|
|
|
private RestTemplate restTemplate;
|
|
|
|
|
|
- private final String source = "coder";
|
|
|
+ private final String source1 = "coder1";
|
|
|
|
|
|
// @Scheduled(cron = "00 00 00 * * ?")
|
|
|
- @DataExtractor(source)
|
|
|
+ @DataExtractor(source1)
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void coderDataExtraction() throws Exception {
|
|
|
- LocalDateTime start = extractionLogService.getExtractionStartTime(source,1);
|
|
|
- LocalDateTime end = extractionLogService.getExtractionEndTime(source);
|
|
|
- Map<String,String> param = new HashMap<>();
|
|
|
- param.put("startTime",start.toString());
|
|
|
- param.put("endTime",end.toString());
|
|
|
- System.out.println(param);
|
|
|
+ LocalDateTime start = extractionLogService.getExtractionStartTime(source1,1);
|
|
|
+ LocalDateTime middle = extractionLogService.getExtractionStartTime(source1);
|
|
|
+ LocalDateTime end = extractionLogService.getExtractionEndTime(source1);
|
|
|
+
|
|
|
+ Map<String,String> param1 = new HashMap<>();
|
|
|
+ param1.put("startTime",start.toString());
|
|
|
+ param1.put("endTime",middle.toString());
|
|
|
+ System.out.println(param1);
|
|
|
+
|
|
|
+ Map<String,String> param2 = new HashMap<>();
|
|
|
+ param2.put("startTime",middle.toString());
|
|
|
+ param2.put("endTime",end.toString());
|
|
|
+ System.out.println(param2);
|
|
|
+
|
|
|
+
|
|
|
String coderApi1 = "/xxx?startTime={startTime}&endTime={endTime}";
|
|
|
String url = coderBaseUrl + coderApi1;
|
|
|
ParameterizedTypeReference<Response<List<CoderDto>>> responseType = new ParameterizedTypeReference<Response<List<CoderDto>>>() {};
|
|
|
- ResponseEntity<Response<List<CoderDto>>> r = restTemplate.exchange(url, HttpMethod.GET,null,responseType,param );
|
|
|
+
|
|
|
+ //再pull一次上次pull的时间段的数据,将一些遗漏的数据存入数据库
|
|
|
+ List<CoderDto> source = getCoderApi1Data(url,param1,responseType);
|
|
|
+ source.forEach(data -> {
|
|
|
+ CoderDao coderDao = coderRepository.findCoderDaoByRecordIdAndSubmitAt(data.getRecordId(),data.getSubmitAt());
|
|
|
+ if (coderDao == null) {
|
|
|
+ coderRepository.save(coderDtoAndDaoMapper(data));
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //pull本次的数据
|
|
|
+ List<CoderDto> source2 = getCoderApi1Data(url,param2,responseType);
|
|
|
+ source2.forEach(data -> {
|
|
|
+ coderRepository.save(coderDtoAndDaoMapper(data));
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<CoderDto> getCoderApi1Data(String url1,Map<String,String> params,ParameterizedTypeReference<Response<List<CoderDto>>> responseType) throws Exception {
|
|
|
+ ResponseEntity<Response<List<CoderDto>>> r = restTemplate.exchange(url1, HttpMethod.GET,null,responseType,params );
|
|
|
Response<List<CoderDto>> body = r.getBody();
|
|
|
if (body == null || body.getCode()!=200) throw new GlobalException(ErrorCodeEnum.SERVICE_ERROR_C0002);
|
|
|
List<CoderDto> source = body.getSource();
|
|
|
if(source == null || source.size()==0) throw new GlobalException(ErrorCodeEnum.SERVICE_ERROR_C0003);
|
|
|
- List<CoderDao> target = new LinkedList<>();
|
|
|
- source.forEach(data -> {
|
|
|
- CoderDao c = CoderDao.builder().commitId(data.getCommitId()).examId(data.getExamId()).endAt(data.getEndAt())
|
|
|
- .lastCommitAt(data.getLastCommitAt()).problemId(data.getProblemId()).recordId(data.getRecordId())
|
|
|
- .score(data.getScore()).userId(data.getUserId()).submitAt(data.getSubmitAt()).startAt(data.getStartAt())
|
|
|
- .id(null).createdAt(null).updatedAt(null).build();
|
|
|
- target.add(c);
|
|
|
- });
|
|
|
- coderRepository.saveAll(target);
|
|
|
+ return source;
|
|
|
+ }
|
|
|
+
|
|
|
+ private CoderDao coderDtoAndDaoMapper(CoderDto data) {
|
|
|
+ return CoderDao.builder()
|
|
|
+ .commitId(data.getCommitId())
|
|
|
+ .examId(data.getExamId())
|
|
|
+ .endAt(data.getEndAt())
|
|
|
+ .lastCommitAt(data.getLastCommitAt())
|
|
|
+ .problemId(data.getProblemId())
|
|
|
+ .recordId(data.getRecordId())
|
|
|
+ .score(data.getScore())
|
|
|
+ .userId(data.getUserId())
|
|
|
+ .submitAt(data.getSubmitAt())
|
|
|
+ .startAt(data.getStartAt())
|
|
|
+ .id(null).createdAt(null).updatedAt(null)
|
|
|
+ .build();
|
|
|
}
|
|
|
}
|