package com.guo.learningprogresstracker.controller; import com.guo.learningprogresstracker.dto.request.CreateFragmentsRequest; import com.guo.learningprogresstracker.dto.request.UpdateFragmentsRequest; import com.guo.learningprogresstracker.entity.CommonResult; import com.guo.learningprogresstracker.entity.StudyReportFragmentsEntity; import com.guo.learningprogresstracker.exception.NotFindEntitiesException; import com.guo.learningprogresstracker.service.impl.StudyReportFragmentsServiceImpl; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.Map; /** * 知识碎片控制层(归属-01 起同时承载「内容归属」的调整动作)。 */ @RequestMapping("/report-fragments") @RestController @Validated @RequiredArgsConstructor public class reportFragmentsController { private final StudyReportFragmentsServiceImpl studyReportFragmentsServiceImpl; /** * 创建知识碎片(记录上下文为当前学习会话,内容归属默认取该会话所属任务) */ @PostMapping public CommonResult createFragments(@Valid @RequestBody CreateFragmentsRequest request) throws NotFindEntitiesException { studyReportFragmentsServiceImpl.createFragments(request); return CommonResult.success(); } /** * 修改知识碎片正文与内容归属(记录上下文不可变) */ @PutMapping("/{id}") public CommonResult updateFragments(@PathVariable Integer id, @RequestBody UpdateFragmentsRequest request) throws NotFindEntitiesException { studyReportFragmentsServiceImpl.updateFragments(id, request); return CommonResult.success(); } /** * 调整内容归属;body 传 {"ownerTaskNum": "TASK-xxx"},传空字符串表示清空归属(回到待归类) */ @PutMapping("/{id}/ownership") public CommonResult assignOwnership(@PathVariable Integer id, @RequestBody Map body) throws NotFindEntitiesException { String ownerTaskNum = body == null ? null : body.get("ownerTaskNum"); studyReportFragmentsServiceImpl.assignOwnership(id, ownerTaskNum); return CommonResult.success(); } /** * 删除知识碎片(软删除) */ @DeleteMapping("/{id}") public CommonResult deleteFragment(@PathVariable Integer id) throws NotFindEntitiesException { studyReportFragmentsServiceImpl.deleteFragment(id); return CommonResult.success(); } /** * 获取指定会话产生的所有知识碎片(记录上下文为会话) */ @GetMapping("/session/{sessionNum}") public CommonResult> getFragmentsBySession(@PathVariable String sessionNum) { List fragments = studyReportFragmentsServiceImpl.getFragmentsBySession(sessionNum); return CommonResult.success(fragments); } /** * 待归类内容:还没有确定内容归属的碎片 */ @GetMapping("/pending-ownership") public CommonResult> getPendingOwnershipFragments() { return CommonResult.success(studyReportFragmentsServiceImpl.getPendingOwnershipFragments()); } }