|
|
@@ -63,13 +63,11 @@ public class BehaviorRecordServiceImpl implements BehaviorRecordService {
|
|
|
|
|
|
@Override
|
|
|
public BehaviorRecordVO findALL(Long assignmentId, Long studentId) {
|
|
|
- // 使用MongoDB聚合管道,直接在数据库层面展开events并投影所需字段
|
|
|
+ // 从behaviorOverviews集合中获取数据,因为其中的events时间戳已经是连续的
|
|
|
Aggregation aggregation = Aggregation.newAggregation(
|
|
|
// 匹配条件 - 使用MongoDB字段名
|
|
|
Aggregation.match(Criteria.where("assignment_id").is(assignmentId)
|
|
|
.and("student_id").is(studentId)),
|
|
|
- // 按创建时间降序排序 - 使用MongoDB字段名
|
|
|
- Aggregation.sort(Sort.by(Sort.Direction.ASC, "created_at")),
|
|
|
// 展开events数组
|
|
|
Aggregation.unwind("events"),
|
|
|
// 投影所需字段
|
|
|
@@ -80,9 +78,10 @@ public class BehaviorRecordServiceImpl implements BehaviorRecordService {
|
|
|
.and("events.startStamp").as("startStamp")
|
|
|
.and("events.endStamp").as("endStamp")
|
|
|
.and("events.pauseTime").as("pauseTime")
|
|
|
+ .and("events.docLength").as("docLength")
|
|
|
.and("created_at").as("createdAt"));
|
|
|
|
|
|
- AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, "behaviorRecords", Map.class);
|
|
|
+ AggregationResults<Map> results = mongoTemplate.aggregate(aggregation, "behaviorOverviews", Map.class);
|
|
|
List<Map> mappedResults = results.getMappedResults();
|
|
|
|
|
|
BehaviorRecordVO vo = new BehaviorRecordVO();
|
|
|
@@ -90,7 +89,7 @@ public class BehaviorRecordServiceImpl implements BehaviorRecordService {
|
|
|
vo.setAssignmentId(assignmentId);
|
|
|
|
|
|
if (!mappedResults.isEmpty()) {
|
|
|
- // 获取第一条记录的创建时间
|
|
|
+ // 获取创建时间
|
|
|
vo.setCreatedAt((Date) mappedResults.get(0).get("createdAt"));
|
|
|
|
|
|
// 转换为SimplifiedEvent列表
|
|
|
@@ -116,6 +115,7 @@ public class BehaviorRecordServiceImpl implements BehaviorRecordService {
|
|
|
simplified.setStartStamp((Long) map.get("startStamp"));
|
|
|
simplified.setEndStamp((Long) map.get("endStamp"));
|
|
|
simplified.setPauseTime((Long) map.get("pauseTime"));
|
|
|
+ simplified.setDocLength((Integer) map.get("docLength"));
|
|
|
|
|
|
return simplified;
|
|
|
}
|