peixue-dev/Archive/[一次性]添加generateWeeklyFeedback方法.java

72 lines
3.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@Override
public GrowthRecordVO generateWeeklyFeedback(Long studentId, Long teacherId, LocalDate weekStartDate) {
log.info("=== 生成周反馈 ===");
log.info("studentId: {}, teacherId: {}, weekStartDate: {}", studentId, teacherId, weekStartDate);
try {
// 计算周结束日期(周日)
LocalDate weekEndDate = weekStartDate.plusDays(6);
// 查询本周的每日反馈
QueryWrapper<GrowthRecord> wrapper = new QueryWrapper<>();
wrapper.eq("student_id", studentId)
.eq("teacher_id", teacherId)
.eq("record_type", "daily")
.between("record_date", weekStartDate, weekEndDate)
.orderByAsc("record_date");
List<GrowthRecord> dailyRecords = this.list(wrapper);
if (dailyRecords.isEmpty()) {
throw new RuntimeException("本周没有每日反馈记录,无法生成周反馈");
}
// 获取学生信息
Student student = studentService.getById(studentId);
if (student == null) {
throw new RuntimeException("学生不存在");
}
// 汇总内容
StringBuilder content = new StringBuilder();
content.append("本周学习总结:\n\n");
int totalDays = dailyRecords.size();
for (int i = 0; i < dailyRecords.size(); i++) {
GrowthRecord record = dailyRecords.get(i);
content.append("").append(i + 1).append("天(")
.append(record.getRecordDate()).append("\n");
content.append(record.getContent()).append("\n\n");
}
// 生成总结
StringBuilder summary = new StringBuilder();
summary.append("本周").append(student.getName()).append("同学");
summary.append("共完成 ").append(totalDays).append(" 天学习任务,");
summary.append("学习态度认真,知识掌握情况良好。");
summary.append("建议继续保持学习热情,加强薄弱环节的练习。");
// 创建周反馈记录
GrowthRecord weeklyRecord = new GrowthRecord();
weeklyRecord.setTeacherId(teacherId);
weeklyRecord.setStudentId(studentId);
weeklyRecord.setStudentName(student.getName());
weeklyRecord.setRecordType("weekly");
weeklyRecord.setRecordDate(weekEndDate);
weeklyRecord.setWeekStartDate(weekStartDate);
weeklyRecord.setContent(content.toString());
weeklyRecord.setSummary(summary.toString());
weeklyRecord.setStatus(1);
this.save(weeklyRecord);
log.info("周反馈生成成功ID: {}", weeklyRecord.getId());
return convertToVO(weeklyRecord);
} catch (Exception e) {
log.error("生成周反馈失败", e);
throw new RuntimeException("生成周反馈失败:" + e.getMessage());
}
}