package com.guo.learningprogresstracker.controller; import com.guo.learningprogresstracker.dto.ExportResult; import com.guo.learningprogresstracker.entity.CommonResult; import com.guo.learningprogresstracker.exception.NotFindEntitiesException; import com.guo.learningprogresstracker.exception.OperationFailedException; import com.guo.learningprogresstracker.service.ExportService; import java.time.LocalDate; import lombok.RequiredArgsConstructor; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; /** * 数据导出控制层(导出-01):把学习报告、知识碎片与任务统计导出为 Markdown / JSON。 */ @RequestMapping("/export") @RestController @Validated @RequiredArgsConstructor public class ExportController { private final ExportService exportService; /** * 导出单个学习任务的全部学习记录 * @param format markdown(默认)或 json */ @GetMapping("/task/{taskNum}") public CommonResult exportTask( @PathVariable String taskNum, @RequestParam(defaultValue = "markdown") String format) throws NotFindEntitiesException, OperationFailedException { return CommonResult.success(exportService.exportTask(taskNum, format)); } /** * 按时间范围导出学习记录(起止日期都可省略,都省略为全部时间) * @param format markdown(默认)或 json */ @GetMapping("/range") public CommonResult exportRange( @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate, @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate, @RequestParam(defaultValue = "markdown") String format) throws OperationFailedException { return CommonResult.success(exportService.exportRange(startDate, endDate, format)); } }