|
@@ -20,6 +20,7 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -46,30 +47,44 @@ public class TeachCloudReportTaskUtils {
|
|
|
/**
|
|
|
* 学期创建/更新接口
|
|
|
*
|
|
|
- * @param id 学期id
|
|
|
+ * @param thirdSemesterId
|
|
|
* @param semesterName 学期名称
|
|
|
* @param startTime 学期开始时间
|
|
|
* @param endTime 学期结束时间
|
|
|
* @param enable 启用/禁用,ture:启用,false:禁用,默认启用
|
|
|
*/
|
|
|
- public Long syncSemester(Long schoolId, String semesterName, Long startTime, Long endTime, Boolean enable) {
|
|
|
+ public Long syncSemester(Long schoolId, Long thirdSemesterId, String semesterName, Long startTime, Long endTime, Boolean enable) {
|
|
|
String hostUrl = dictionaryConfig.reportOpenDomain().getHostUrl();
|
|
|
String saveUrl = dictionaryConfig.reportOpenDomain().getSemesterApi();
|
|
|
validUrl(hostUrl, saveUrl);
|
|
|
String postUrl = hostUrl.concat(saveUrl);
|
|
|
+ long timestamp = System.currentTimeMillis();
|
|
|
//参数
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("semesterName", validParam(semesterName, null, true, "学期名称"));
|
|
|
- map.put("startTime", validParam(startTime, null, true, "学期开始时间"));
|
|
|
- map.put("endTime", validParam(endTime, null, true, "学期结束时间"));
|
|
|
- map.put("enable", validParam(enable, true, true, "是否启用标记"));
|
|
|
+ try {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("id", validParam(thirdSemesterId, null, false, "学期ID"));
|
|
|
+ map.put("semesterName", validParam(semesterName, null, true, "学期名称"));
|
|
|
+ map.put("startTime", validParam(startTime, null, true, "学期开始时间"));
|
|
|
+ map.put("endTime", validParam(endTime, null, true, "学期结束时间"));
|
|
|
+ map.put("enable", validParam(enable, true, true, "是否启用标记"));
|
|
|
+
|
|
|
+ String accessToken = createSign(schoolId, timestamp, saveUrl);
|
|
|
+ String result = HttpUtil.postJson(postUrl, JacksonUtil.parseJson(map), accessToken, timestamp);
|
|
|
|
|
|
- String result = HttpKit.sendPost(postUrl, getHeaders(schoolId, saveUrl), map, null, null, null);
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
- if (jsonObject.containsKey("id")) {
|
|
|
- return Long.valueOf(jsonObject.get("id").toString());
|
|
|
- } else {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("学期同步失败");
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ if (jsonObject.containsKey("code")) {
|
|
|
+ String code = jsonObject.getString("code");
|
|
|
+ if("200".equals(code)) {
|
|
|
+ return jsonObject.getLong("data");
|
|
|
+ } else {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(jsonObject.getString("error"));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("学期同步失败");
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -88,19 +103,26 @@ public class TeachCloudReportTaskUtils {
|
|
|
String saveUrl = dictionaryConfig.reportOpenDomain().getExamApi();
|
|
|
validUrl(hostUrl, saveUrl);
|
|
|
String postUrl = hostUrl.concat(saveUrl);
|
|
|
+ long timestamp = System.currentTimeMillis();
|
|
|
try {
|
|
|
//参数
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("id", validParam(id, null, true, "考试ID"));
|
|
|
+ map.put("id", validParam(id, null, false, "考试ID"));
|
|
|
map.put("examName", validParam(examName, null, true, "考试名称"));
|
|
|
map.put("examTime", validParam(examTime, null, true, "考试时间"));
|
|
|
map.put("semesterId", validParam(semesterId, null, true, "学期ID"));
|
|
|
map.put("enable", validParam(enable, null, true, "是否启用标记"));
|
|
|
|
|
|
- String result = HttpKit.sendPost(postUrl, getHeaders(schoolId, saveUrl), map, null, null, null);
|
|
|
+ String accessToken = createSign(schoolId, timestamp, saveUrl);
|
|
|
+ String result = HttpUtil.postJson(postUrl, JacksonUtil.parseJson(map), accessToken, timestamp);
|
|
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
- if (jsonObject.containsKey("id")) {
|
|
|
- return Long.valueOf(jsonObject.get("id").toString());
|
|
|
+ if (jsonObject.containsKey("code")) {
|
|
|
+ String code = jsonObject.getString("code");
|
|
|
+ if("200".equals(code)) {
|
|
|
+ return jsonObject.getLong("data");
|
|
|
+ } else {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(jsonObject.getString("error"));
|
|
|
+ }
|
|
|
} else {
|
|
|
throw ExceptionResultEnum.ERROR.exception("考试同步失败");
|
|
|
}
|
|
@@ -124,6 +146,7 @@ public class TeachCloudReportTaskUtils {
|
|
|
String saveUrl = dictionaryConfig.reportOpenDomain().getCourseEditApi();
|
|
|
validUrl(hostUrl, saveUrl);
|
|
|
String postUrl = hostUrl.concat(saveUrl);
|
|
|
+ long timestamp = System.currentTimeMillis();
|
|
|
try {
|
|
|
//参数
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
@@ -134,10 +157,17 @@ public class TeachCloudReportTaskUtils {
|
|
|
map.put("teachCollegeName", validParam(teachCollegeName, null, true, "开课机构名称"));
|
|
|
map.put("enable", validParam(enable, true, true, "是否启用标记"));
|
|
|
|
|
|
- String result = HttpKit.sendPost(postUrl, getHeaders(schoolId, saveUrl), map, null, null, null);
|
|
|
+ String accessToken = createSign(schoolId, timestamp, saveUrl);
|
|
|
+ String result = HttpUtil.postJson(postUrl, JacksonUtil.parseJson(map), accessToken, timestamp);
|
|
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
- if (jsonObject.containsKey("success")) {
|
|
|
- return Boolean.valueOf(jsonObject.get("success").toString());
|
|
|
+ if (jsonObject.containsKey("code")) {
|
|
|
+ String code = jsonObject.getString("code");
|
|
|
+ if("200".equals(code)) {
|
|
|
+ JSONObject successJson = JSONObject.parseObject(jsonObject.getString("data"));
|
|
|
+ return successJson.getBoolean("success");
|
|
|
+ } else {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(jsonObject.getString("error"));
|
|
|
+ }
|
|
|
} else {
|
|
|
throw ExceptionResultEnum.ERROR.exception("分析课程同步失败");
|
|
|
}
|