Parcourir la source

feat:添加作业修改和查询接口

lalala il y a 1 an
Parent
commit
a85bd78fe1

+ 66 - 0
seecoder-portal-common/src/main/java/cn/seecoder/seecoderportalcommon/vo/dto/AiSpeakingAssignmentDTO.java

@@ -0,0 +1,66 @@
+package cn.seecoder.seecoderportalcommon.vo.dto;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.ToString;
+
+import java.util.List;
+
+/**
+ * @author Liululin
+ * @date 2025/5/29 - 22:08
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+public class AiSpeakingAssignmentDTO extends AssignmentUpdateDTO{
+    private Integer minDuration;
+
+    private Integer minInteraction;
+
+    public Integer getMinDuration() {
+        return minDuration;
+    }
+
+    @Override
+    public String toString() {
+        return "AiSpeakingAssignmentDTO{" +
+                "minDuration=" + minDuration +
+                ", minInteraction=" + minInteraction +
+                ", surveyLinks=" + surveyLinks +
+                ", surveyDuration=" + surveyDuration +
+                '}';
+    }
+
+    public void setMinDuration(Integer minDuration) {
+        this.minDuration = minDuration;
+    }
+
+    public Integer getMinInteraction() {
+        return minInteraction;
+    }
+
+    public void setMinInteraction(Integer minInteraction) {
+        this.minInteraction = minInteraction;
+    }
+
+    public List<String> getSurveyLinks() {
+        return surveyLinks;
+    }
+
+    public void setSurveyLinks(List<String> surveyLinks) {
+        this.surveyLinks = surveyLinks;
+    }
+
+    public Integer getSurveyDuration() {
+        return surveyDuration;
+    }
+
+    public void setSurveyDuration(Integer surveyDuration) {
+        this.surveyDuration = surveyDuration;
+    }
+
+    private List<String> surveyLinks;
+
+    private Integer surveyDuration;
+}

+ 104 - 0
seecoder-portal-common/src/main/java/cn/seecoder/seecoderportalcommon/vo/dto/AssignmentUpdateDTO.java

@@ -0,0 +1,104 @@
+package cn.seecoder.seecoderportalcommon.vo.dto;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author Liululin
+ * @date 2025/5/29 - 12:08
+ */
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class AssignmentUpdateDTO {
+    private String assignmentName;
+
+    private String description;
+
+    private String type;
+
+    private String descriptionFile; // 作业要求,Word/Pdf文件
+
+    private List<String> attachments; // 作业附件
+
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
+    private Date startTime;
+
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
+    private Date endTime;
+
+    public String getAssignmentName() {
+        return assignmentName;
+    }
+
+    public void setAssignmentName(String assignmentName) {
+        this.assignmentName = assignmentName;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    @Override
+    public String toString() {
+        return "AssignmentUpdateDTO{" +
+                "assignmentName='" + assignmentName + '\'' +
+                ", description='" + description + '\'' +
+                ", type='" + type + '\'' +
+                ", descriptionFile='" + descriptionFile + '\'' +
+                ", attachments=" + attachments +
+                ", startTime=" + startTime +
+                ", endTime=" + endTime +
+                '}';
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getDescriptionFile() {
+        return descriptionFile;
+    }
+
+    public void setDescriptionFile(String descriptionFile) {
+        this.descriptionFile = descriptionFile;
+    }
+
+    public List<String> getAttachments() {
+        return attachments;
+    }
+
+    public void setAttachments(List<String> attachments) {
+        this.attachments = attachments;
+    }
+
+    public Date getStartTime() {
+        return startTime;
+    }
+
+    public void setStartTime(Date startTime) {
+        this.startTime = startTime;
+    }
+
+    public Date getEndTime() {
+        return endTime;
+    }
+
+    public void setEndTime(Date endTime) {
+        this.endTime = endTime;
+    }
+}

+ 6 - 1
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/service/ExamService.java

@@ -1,8 +1,9 @@
 package cn.seecoder.seecoderportalserver.service;
 
+import cn.seecoder.seecoderportalcommon.vo.dto.AiSpeakingAssignmentDTO;
+import cn.seecoder.seecoderportalcommon.vo.dto.AssignmentUpdateDTO;
 import cn.seecoder.seecoderportalcommon.vo.CreateEvalExamVO;
 import cn.seecoder.seecoderportalcommon.vo.QuestionScoreMapVO;
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import org.springframework.web.multipart.MultipartFile;
@@ -111,4 +112,8 @@ public interface ExamService {
     JSONObject getExamCodeQuestionAndScoreById(Integer examId);
 
     JSONArray findEaiTeacherExamsByCourseId(int courseId);
+
+    JSONObject updateEaiWritingExam(int assignmentId, AssignmentUpdateDTO assignmentUpdateDTO);
+
+    JSONObject updateEaiSpeakingExam(int assignmentId, AiSpeakingAssignmentDTO assignmentUpdateDTO);
 }

+ 12 - 0
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/serviceImpl/ExamServiceImpl.java

@@ -1,5 +1,7 @@
 package cn.seecoder.seecoderportalserver.serviceImpl;
 
+import cn.seecoder.seecoderportalcommon.vo.dto.AiSpeakingAssignmentDTO;
+import cn.seecoder.seecoderportalcommon.vo.dto.AssignmentUpdateDTO;
 import cn.seecoder.seecoderportalcommon.vo.CourseVO;
 import cn.seecoder.seecoderportalcommon.vo.CreateEvalExamVO;
 import cn.seecoder.seecoderportalcommon.vo.QuestionScoreMapVO;
@@ -365,5 +367,15 @@ public class ExamServiceImpl implements ExamService {
         return eaiService.findTeacherExamsByCourseId(courseId).getJSONArray("result");
     }
 
+    @Override
+    public JSONObject updateEaiWritingExam(int assignmentId, AssignmentUpdateDTO assignmentDTO) {
+        return eaiService.updateWritingAssignment(assignmentId, assignmentDTO);
+    }
+
+    @Override
+    public JSONObject updateEaiSpeakingExam(int assignmentId, AiSpeakingAssignmentDTO assignmentUpdateDTO) {
+        return eaiService.updateSpeakingAssignment(assignmentId, assignmentUpdateDTO);
+    }
+
 
 }

+ 109 - 1
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/serviceImpl/subsystem/EaiService.java

@@ -1,5 +1,7 @@
 package cn.seecoder.seecoderportalserver.serviceImpl.subsystem;
 
+import cn.seecoder.seecoderportalcommon.vo.dto.AiSpeakingAssignmentDTO;
+import cn.seecoder.seecoderportalcommon.vo.dto.AssignmentUpdateDTO;
 import cn.seecoder.seecoderportalcommon.vo.CourseVO;
 import cn.seecoder.seecoderportalserver.service.HttpService;
 import cn.seecoder.seecoderportalserver.service.subsystem.SubsystemService;
@@ -15,6 +17,7 @@ import org.springframework.stereotype.Service;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Optional;
 
 /**
  * @author XiaoYu
@@ -184,13 +187,14 @@ public class EaiService implements SubsystemService {
     @Override
     public JSONObject findTeacherExamsByCourseId(int courseId){
         JSONObject result = new JSONObject();
-        result.put("array", this.getExamsByCourseId(courseId));
+        result.put("result", this.getExamsByCourseId(courseId));
         return result;
     };
 
     private JSONArray getExamsByCourseId(int courseId) {
         String uri = eaiHost+"/api/assignment/query";
         String token = httpService.getToken();
+        System.out.println(token);
         List<NameValuePair> params = new ArrayList<>();
         params.add(new BasicNameValuePair("page", String.valueOf(1)));
         params.add(new BasicNameValuePair("limit", String.valueOf(1000)));
@@ -210,6 +214,7 @@ public class EaiService implements SubsystemService {
             for (int i = 0; i < exams.size(); i++) {
                 result.add(exams.get(i));
             }
+            return result;
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -222,5 +227,108 @@ public class EaiService implements SubsystemService {
 
     public JSONObject findStudentExams(int page, int limit, int state){return null;};
 
+    public JSONObject updateWritingAssignment(int assignmentId, AssignmentUpdateDTO assignmentDTO) {
+        String uri = eaiHost + "/api/assignment/update";
+        JSONObject requestBody = convertEaiWritingAssignmentUpdateDTO(assignmentDTO);
+        List<NameValuePair> params = new ArrayList<>();
+        String token = httpService.getToken();
+        System.out.println("EAI修改作业信息:" + requestBody);
+        params.add(new BasicNameValuePair("assignmentId", String.valueOf(assignmentId)));
+        try{
+            String result = httpService.sendPost(uri, requestBody, params, token);
+            return JSON.parseObject(result);
+        }catch (Exception e){
+            e.printStackTrace();
+            return new JSONObject().fluentPut("修改课程异常,",e.getMessage());
+        }
+    }
+
+    private JSONObject convertEaiWritingAssignmentUpdateDTO(AssignmentUpdateDTO assignmentDTO) {
+        JSONObject requestBody = new JSONObject();
+
+        if (assignmentDTO.getAssignmentName() != null) {
+            requestBody.put("assignmentName", assignmentDTO.getAssignmentName());
+        }
+
+        if (assignmentDTO.getDescription() != null) {
+            requestBody.put("description", assignmentDTO.getDescription());
+        }
+
+        if (assignmentDTO.getDescriptionFile() != null) {
+            requestBody.put("descriptionFile", assignmentDTO.getDescriptionFile());
+        }
+
+        if (assignmentDTO.getAttachments() != null && !assignmentDTO.getAttachments().isEmpty()) {
+            requestBody.put("attachments", assignmentDTO.getAttachments());
+        }
+
+        if (assignmentDTO.getStartTime() != null) {
+            requestBody.put("startTime", Date.from(assignmentDTO.getStartTime().toInstant()));
+        }
+
+        if (assignmentDTO.getEndTime() != null) {
+            requestBody.put("endTime", Date.from(assignmentDTO.getEndTime().toInstant()));
+        }
+        return requestBody;
+    }
+
 
+    public JSONObject updateSpeakingAssignment(int assignmentId, AiSpeakingAssignmentDTO assignmentDTO) {
+        String uri = eaiHost + "/api/aispeaking/update";
+        JSONObject requestBody = convertEaiSpeakingAssignmentUpdateDTO(assignmentDTO);
+        List<NameValuePair> params = new ArrayList<>();
+        String token = httpService.getToken();
+        System.out.println("EAI修改作业信息:" + requestBody);
+        params.add(new BasicNameValuePair("assignmentId", String.valueOf(assignmentId)));
+        try{
+            String result = httpService.sendPost(uri, requestBody, params, token);
+            return JSON.parseObject(result);
+        }catch (Exception e){
+            e.printStackTrace();
+            return new JSONObject().fluentPut("修改课程异常,",e.getMessage());
+        }
+    }
+
+    private JSONObject convertEaiSpeakingAssignmentUpdateDTO(AiSpeakingAssignmentDTO assignmentDTO) {
+        if (assignmentDTO == null) {
+            return new JSONObject();
+        }
+        JSONObject requestBody = new JSONObject();
+
+        // 父类 AssignmentUpdateDTO 的字段
+        Optional.ofNullable(assignmentDTO.getAssignmentName())
+                .ifPresent(v -> requestBody.put("assignmentName", v));
+
+        Optional.ofNullable(assignmentDTO.getDescription())
+                .ifPresent(v -> requestBody.put("description", v));
+
+        Optional.ofNullable(assignmentDTO.getDescriptionFile())
+                .ifPresent(v -> requestBody.put("descriptionFile", v));
+
+        Optional.ofNullable(assignmentDTO.getAttachments())
+                .filter(list -> !list.isEmpty())
+                .ifPresent(v -> requestBody.put("attachments", v));
+
+        Optional.ofNullable(assignmentDTO.getStartTime())
+                .ifPresent(v -> requestBody.put("startTime", Date.from(v.toInstant())));
+
+        Optional.ofNullable(assignmentDTO.getEndTime())
+                .ifPresent(v -> requestBody.put("endTime", Date.from(v.toInstant())));
+
+        // 子类 AiSpeakingAssignmentDTO 新增字段
+        Optional.ofNullable(assignmentDTO.getMinDuration())
+                .ifPresent(v -> requestBody.put("minDuration", v));
+
+        Optional.ofNullable(assignmentDTO.getMinInteraction())
+                .ifPresent(v -> requestBody.put("minInteraction", v));
+
+        Optional.ofNullable(assignmentDTO.getSurveyLinks())
+                .filter(list -> !list.isEmpty())
+                .ifPresent(v -> requestBody.put("surveyLinks", v));
+
+        Optional.ofNullable(assignmentDTO.getSurveyDuration())
+                .ifPresent(v -> requestBody.put("surveyDuration", v));
+
+        return requestBody;
+    }
 }

+ 14 - 3
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/web/rest/ExamController.java

@@ -1,18 +1,17 @@
 package cn.seecoder.seecoderportalserver.web.rest;
 
+import cn.seecoder.seecoderportalcommon.vo.dto.AiSpeakingAssignmentDTO;
+import cn.seecoder.seecoderportalcommon.vo.dto.AssignmentUpdateDTO;
 import cn.seecoder.seecoderportalcommon.vo.CreateEvalExamVO;
 import cn.seecoder.seecoderportalcommon.vo.QuestionScoreMapVO;
 import cn.seecoder.seecoderportalserver.security.SecurityUtils;
 import cn.seecoder.seecoderportalserver.service.ExamService;
 import cn.seecoder.seecoderportalserver.utility.OkResponse;
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
-import springfox.documentation.annotations.ApiIgnore;
 
 import java.util.List;
 
@@ -387,4 +386,16 @@ public class ExamController {
         return OkResponse.of(examService.findEaiTeacherExamsByCourseId(courseId));
     }
 
+
+
+    @PutMapping("/eai/exam/{assignmentId:\\d+}/update/writing")
+    public JSONObject updateEaiWritingExam(@PathVariable int assignmentId, @RequestBody AssignmentUpdateDTO assignmentUpdateDTO) {
+        return examService.updateEaiWritingExam(assignmentId, assignmentUpdateDTO);
+    }
+
+    @PutMapping("/eai/exam/{assignmentId:\\d+}/update/speaking")
+    public JSONObject updateEaiSpeakingExam(@PathVariable int assignmentId, @RequestBody AiSpeakingAssignmentDTO assignmentUpdateDTO) {
+        return examService.updateEaiSpeakingExam(assignmentId, assignmentUpdateDTO);
+    }
+
 }