|
@@ -41,20 +41,20 @@ public class CreateRandomPaperTemplateTask implements TaskService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void start(TaskEntity task) {
|
|
public void start(TaskEntity task) {
|
|
- JsonNode jsonParams = new JsonMapper().getNode(task.getParams());
|
|
|
|
- if (jsonParams == null) {
|
|
|
|
- throw new StatusException("任务参数解析错误!");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- User user = LoginSessionManager.getLoginSession(task.getUserToken());
|
|
|
|
- if (user == null) {
|
|
|
|
|
|
+ User loginUser = LoginSessionManager.getLoginSession(task.getUserToken());
|
|
|
|
+ if (loginUser == null) {
|
|
throw new StatusException("用户未登录!");
|
|
throw new StatusException("用户未登录!");
|
|
}
|
|
}
|
|
|
|
|
|
- this.execute(user, jsonParams, task);
|
|
|
|
|
|
+ this.execute(loginUser, task);
|
|
}
|
|
}
|
|
|
|
|
|
- private void execute(User user, JsonNode jsonParams, TaskEntity task) {
|
|
|
|
|
|
+ private void execute(User loginUser, TaskEntity task) {
|
|
|
|
+ JsonNode jsonParams = new JsonMapper().getNode(task.getParams());
|
|
|
|
+ if (jsonParams == null) {
|
|
|
|
+ throw new StatusException("任务参数解析错误!");
|
|
|
|
+ }
|
|
|
|
+
|
|
Long examId = jsonParams.get("examId").asLong(0L);
|
|
Long examId = jsonParams.get("examId").asLong(0L);
|
|
String questionPool = jsonParams.get("questionPool").asInt(1) == 1 ? "IMPORT" : "GENERATE";
|
|
String questionPool = jsonParams.get("questionPool").asInt(1) == 1 ? "IMPORT" : "GENERATE";
|
|
String structType = jsonParams.get("structType").asInt(1) == 1 ? "EXACT" : "BLUEPRINT";
|
|
String structType = jsonParams.get("structType").asInt(1) == 1 ? "EXACT" : "BLUEPRINT";
|
|
@@ -73,7 +73,7 @@ public class CreateRandomPaperTemplateTask implements TaskService {
|
|
log.info("examId:{} questionPool:{} structType:{} structName:{} paperKeywords:{} paperStartTime:{}", examId,
|
|
log.info("examId:{} questionPool:{} structType:{} structName:{} paperKeywords:{} paperStartTime:{}", examId,
|
|
questionPool, structType, structName, paperKeywords, paperStartTime);
|
|
questionPool, structType, structName, paperKeywords, paperStartTime);
|
|
|
|
|
|
- List<CourseVO> courses = commonService.getExamCourseList(user, examId);
|
|
|
|
|
|
+ List<CourseVO> courses = commonService.getExamCourseList(loginUser, examId);
|
|
log.info("待处理课程总数为:{} examId:{}", courses.size(), examId);
|
|
log.info("待处理课程总数为:{} examId:{}", courses.size(), examId);
|
|
|
|
|
|
if (courses.isEmpty()) {
|
|
if (courses.isEmpty()) {
|
|
@@ -87,7 +87,7 @@ public class CreateRandomPaperTemplateTask implements TaskService {
|
|
// 按考试课程逐个处理
|
|
// 按考试课程逐个处理
|
|
index++;
|
|
index++;
|
|
|
|
|
|
- if (this.existRandomPaperTemplate(user, course.getCourseId())) {
|
|
|
|
|
|
+ if (this.existRandomPaperTemplate(loginUser, course.getCourseId())) {
|
|
String msg = String.format("【%s】 课程代码:%s 已存在随机抽卷模板!", index, course.getCourseCode());
|
|
String msg = String.format("【%s】 课程代码:%s 已存在随机抽卷模板!", index, course.getCourseCode());
|
|
messages.add(msg);
|
|
messages.add(msg);
|
|
log.warn(msg);
|
|
log.warn(msg);
|
|
@@ -95,7 +95,7 @@ public class CreateRandomPaperTemplateTask implements TaskService {
|
|
}
|
|
}
|
|
|
|
|
|
// 获取试卷结构
|
|
// 获取试卷结构
|
|
- String paperStructId = this.getPaperStructId(user, course.getCourseCode(), structType, structName);
|
|
|
|
|
|
+ String paperStructId = this.getPaperStructId(loginUser, course.getCourseCode(), structType, structName);
|
|
if (paperStructId == null) {
|
|
if (paperStructId == null) {
|
|
String msg = String.format("【%s】 课程代码:%s 未找到匹配的试卷结构!", index, course.getCourseCode());
|
|
String msg = String.format("【%s】 课程代码:%s 未找到匹配的试卷结构!", index, course.getCourseCode());
|
|
messages.add(msg);
|
|
messages.add(msg);
|
|
@@ -104,7 +104,7 @@ public class CreateRandomPaperTemplateTask implements TaskService {
|
|
}
|
|
}
|
|
|
|
|
|
// 获取试卷列表
|
|
// 获取试卷列表
|
|
- List<String> paperIds = this.getPapers(user, course.getCourseCode(), questionPool, paperKeywords,
|
|
|
|
|
|
+ List<String> paperIds = this.getPapers(loginUser, course.getCourseCode(), questionPool, paperKeywords,
|
|
startTime);
|
|
startTime);
|
|
if (paperIds.isEmpty()) {
|
|
if (paperIds.isEmpty()) {
|
|
String msg = String.format("【%s】 课程代码:%s 未找到相关试卷!", index, course.getCourseCode());
|
|
String msg = String.format("【%s】 课程代码:%s 未找到相关试卷!", index, course.getCourseCode());
|
|
@@ -115,7 +115,7 @@ public class CreateRandomPaperTemplateTask implements TaskService {
|
|
|
|
|
|
// 保存随机抽卷模板
|
|
// 保存随机抽卷模板
|
|
try {
|
|
try {
|
|
- this.saveRandomPaperTemplate(user, course, structType, paperStructId, questionPool, paperIds);
|
|
|
|
|
|
+ this.saveRandomPaperTemplate(loginUser, course, structType, paperStructId, questionPool, paperIds);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
String msg = String.format("【%s】 课程代码:%s 处理失败!%s", index, course.getCourseCode(),
|
|
String msg = String.format("【%s】 课程代码:%s 处理失败!%s", index, course.getCourseCode(),
|
|
e.getMessage());
|
|
e.getMessage());
|
|
@@ -134,16 +134,16 @@ public class CreateRandomPaperTemplateTask implements TaskService {
|
|
/**
|
|
/**
|
|
* 获取试卷结构信息
|
|
* 获取试卷结构信息
|
|
*/
|
|
*/
|
|
- private String getPaperStructId(User user, String courseCode, String structType, String structName) {
|
|
|
|
|
|
+ private String getPaperStructId(User loginUser, String courseCode, String structType, String structName) {
|
|
Map<String, String> headers = new HashMap<>();
|
|
Map<String, String> headers = new HashMap<>();
|
|
- headers.put("key", user.getKey());
|
|
|
|
- headers.put("token", user.getToken());
|
|
|
|
|
|
+ headers.put("key", loginUser.getKey());
|
|
|
|
+ headers.put("token", loginUser.getToken());
|
|
|
|
|
|
Map<String, String> params = new HashMap<>();
|
|
Map<String, String> params = new HashMap<>();
|
|
params.put("courseNo", courseCode);
|
|
params.put("courseNo", courseCode);
|
|
params.put("type", structType);
|
|
params.put("type", structType);
|
|
|
|
|
|
- String url = user.getServerUrl() + "/api/ecs_ques/paperStruct";
|
|
|
|
|
|
+ String url = loginUser.getServerUrl() + "/api/ecs_ques/paperStruct";
|
|
String json = HttpHelper.get(url, headers, params);
|
|
String json = HttpHelper.get(url, headers, params);
|
|
|
|
|
|
JsonMapper jsonMapper = new JsonMapper();
|
|
JsonMapper jsonMapper = new JsonMapper();
|
|
@@ -161,12 +161,12 @@ public class CreateRandomPaperTemplateTask implements TaskService {
|
|
/**
|
|
/**
|
|
* 判断课程是否已存在随机抽卷模板
|
|
* 判断课程是否已存在随机抽卷模板
|
|
*/
|
|
*/
|
|
- private boolean existRandomPaperTemplate(User user, Long courseId) {
|
|
|
|
|
|
+ private boolean existRandomPaperTemplate(User loginUser, Long courseId) {
|
|
Map<String, String> headers = new HashMap<>();
|
|
Map<String, String> headers = new HashMap<>();
|
|
- headers.put("key", user.getKey());
|
|
|
|
- headers.put("token", user.getToken());
|
|
|
|
|
|
+ headers.put("key", loginUser.getKey());
|
|
|
|
+ headers.put("token", loginUser.getToken());
|
|
|
|
|
|
- String url = user.getServerUrl() + "/api/ecs_ques/randompaper/page?pageSize=1&courseId=" + courseId;
|
|
|
|
|
|
+ String url = loginUser.getServerUrl() + "/api/ecs_ques/randompaper/page?pageSize=1&courseId=" + courseId;
|
|
String json = HttpHelper.post(url, headers, null);
|
|
String json = HttpHelper.post(url, headers, null);
|
|
|
|
|
|
JsonMapper jsonMapper = new JsonMapper();
|
|
JsonMapper jsonMapper = new JsonMapper();
|
|
@@ -181,11 +181,11 @@ public class CreateRandomPaperTemplateTask implements TaskService {
|
|
/**
|
|
/**
|
|
* 获取试卷列表
|
|
* 获取试卷列表
|
|
*/
|
|
*/
|
|
- private List<String> getPapers(User user, String courseCode, String questionPool, String paperKeywords,
|
|
|
|
- Date paperStartTime) {
|
|
|
|
|
|
+ private List<String> getPapers(User loginUser, String courseCode, String questionPool, String paperKeywords,
|
|
|
|
+ Date paperStartTime) {
|
|
Map<String, String> headers = new HashMap<>();
|
|
Map<String, String> headers = new HashMap<>();
|
|
- headers.put("key", user.getKey());
|
|
|
|
- headers.put("token", user.getToken());
|
|
|
|
|
|
+ headers.put("key", loginUser.getKey());
|
|
|
|
+ headers.put("token", loginUser.getToken());
|
|
|
|
|
|
Map<String, String> params = new HashMap<>();
|
|
Map<String, String> params = new HashMap<>();
|
|
params.put("courseNo", courseCode);
|
|
params.put("courseNo", courseCode);
|
|
@@ -195,9 +195,9 @@ public class CreateRandomPaperTemplateTask implements TaskService {
|
|
|
|
|
|
final String url;
|
|
final String url;
|
|
if ("IMPORT".equals(questionPool)) {
|
|
if ("IMPORT".equals(questionPool)) {
|
|
- url = user.getServerUrl() + "/api/ecs_ques/importPaper/huoge/%s/" + pageSize;
|
|
|
|
|
|
+ url = loginUser.getServerUrl() + "/api/ecs_ques/importPaper/huoge/%s/" + pageSize;
|
|
} else {
|
|
} else {
|
|
- url = user.getServerUrl() + "/api/ecs_ques/genPaper/huoge/%s/" + pageSize;
|
|
|
|
|
|
+ url = loginUser.getServerUrl() + "/api/ecs_ques/genPaper/huoge/%s/" + pageSize;
|
|
}
|
|
}
|
|
|
|
|
|
List<String> paperIds = new ArrayList<>();
|
|
List<String> paperIds = new ArrayList<>();
|
|
@@ -247,11 +247,11 @@ public class CreateRandomPaperTemplateTask implements TaskService {
|
|
/**
|
|
/**
|
|
* 保存随机抽卷模板
|
|
* 保存随机抽卷模板
|
|
*/
|
|
*/
|
|
- public void saveRandomPaperTemplate(User user, CourseVO course, String paperStructType, String paperStructId,
|
|
|
|
- String paperType, List<String> paperIds) {
|
|
|
|
|
|
+ public void saveRandomPaperTemplate(User loginUser, CourseVO course, String paperStructType, String paperStructId,
|
|
|
|
+ String paperType, List<String> paperIds) {
|
|
Map<String, String> headers = new HashMap<>();
|
|
Map<String, String> headers = new HashMap<>();
|
|
- headers.put("key", user.getKey());
|
|
|
|
- headers.put("token", user.getToken());
|
|
|
|
|
|
+ headers.put("key", loginUser.getKey());
|
|
|
|
+ headers.put("token", loginUser.getToken());
|
|
|
|
|
|
Map<String, String> params = new HashMap<>();
|
|
Map<String, String> params = new HashMap<>();
|
|
params.put("name", course.getCourseName() + "-抽题模板");//todo
|
|
params.put("name", course.getCourseName() + "-抽题模板");//todo
|
|
@@ -261,7 +261,7 @@ public class CreateRandomPaperTemplateTask implements TaskService {
|
|
params.put("paperType", paperType);
|
|
params.put("paperType", paperType);
|
|
params.put("paperIds", StringUtils.join(paperIds, ","));
|
|
params.put("paperIds", StringUtils.join(paperIds, ","));
|
|
|
|
|
|
- final String url = user.getServerUrl() + "/api/ecs_ques/randompaper/save?" + HttpHelper.toUrlParams(params);
|
|
|
|
|
|
+ final String url = loginUser.getServerUrl() + "/api/ecs_ques/randompaper/save?" + HttpHelper.toUrlParams(params);
|
|
String json = HttpHelper.post(url, headers, null);
|
|
String json = HttpHelper.post(url, headers, null);
|
|
TemplateStructInfo info = new JsonMapper().parseJson(json, TemplateStructInfo.class);
|
|
TemplateStructInfo info = new JsonMapper().parseJson(json, TemplateStructInfo.class);
|
|
if (info != null && info.getValid()) {
|
|
if (info != null && info.getValid()) {
|