|
|
@@ -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;
|
|
|
+ }
|
|
|
}
|