|
|
@@ -0,0 +1,62 @@
|
|
|
+package com.njuzr.eaibackend.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.njuzr.eaibackend.exception.MyException;
|
|
|
+import com.njuzr.eaibackend.mapper.BehaviorRecordMapper;
|
|
|
+import com.njuzr.eaibackend.po.BehaviorRecord;
|
|
|
+import com.njuzr.eaibackend.service.BehaviorRecordService;
|
|
|
+import com.njuzr.eaibackend.utils.OssUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author BaiBai
|
|
|
+ * @date 2025-02-10 17:03
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class BehaviorRecordServiceImpl implements BehaviorRecordService {
|
|
|
+
|
|
|
+ private final BehaviorRecordMapper behaviorRecordMapper;
|
|
|
+
|
|
|
+ private final OssUtil ossUtil;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public BehaviorRecordServiceImpl(BehaviorRecordMapper behaviorRecordMapper, OssUtil ossUtil) {
|
|
|
+ this.behaviorRecordMapper = behaviorRecordMapper;
|
|
|
+ this.ossUtil = ossUtil;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<BehaviorRecord> find(Long assignmentId, Long studentId) {
|
|
|
+ QueryWrapper<BehaviorRecord> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("assignment_id", assignmentId);
|
|
|
+ queryWrapper.eq("student_id", studentId);
|
|
|
+ queryWrapper.orderByDesc("time");
|
|
|
+ return behaviorRecordMapper.selectList(queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ public String upload(Long assignmentId, Long studentId, MultipartFile file) {
|
|
|
+ try {
|
|
|
+ Date now = new Date();
|
|
|
+ String filePath = "uploads/" + assignmentId + "_" + studentId + "_" + now.getTime() + file.getOriginalFilename();
|
|
|
+ String url = ossUtil.uploadFile(file.getInputStream(), filePath);
|
|
|
+ BehaviorRecord behaviorRecord = new BehaviorRecord();
|
|
|
+ behaviorRecord.setAssignmentId(assignmentId);
|
|
|
+ behaviorRecord.setStudentId(studentId);
|
|
|
+ behaviorRecord.setRecordFileUrl(url);
|
|
|
+ behaviorRecord.setTime(now);
|
|
|
+ behaviorRecordMapper.insert(behaviorRecord);
|
|
|
+ return url;
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ throw MyException.create(HttpStatus.BAD_REQUEST, "文件上传失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|