|
@@ -13,6 +13,7 @@ import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import cn.com.qmth.stmms.admin.utils.HttpUtil;
|
|
import cn.com.qmth.stmms.admin.utils.HttpUtil;
|
|
|
|
+import cn.com.qmth.stmms.admin.utils.UpyunConfig;
|
|
import cn.com.qmth.stmms.biz.exam.model.DataSync;
|
|
import cn.com.qmth.stmms.biz.exam.model.DataSync;
|
|
import cn.com.qmth.stmms.biz.exam.model.Exam;
|
|
import cn.com.qmth.stmms.biz.exam.model.Exam;
|
|
import cn.com.qmth.stmms.biz.exam.model.ExamStudent;
|
|
import cn.com.qmth.stmms.biz.exam.model.ExamStudent;
|
|
@@ -41,6 +42,8 @@ public class DataSyncThread implements Runnable {
|
|
|
|
|
|
private String baseDir;
|
|
private String baseDir;
|
|
|
|
|
|
|
|
+ private UpyunConfig config;
|
|
|
|
+
|
|
private HttpUtil subjectHttp;
|
|
private HttpUtil subjectHttp;
|
|
|
|
|
|
private HttpUtil studentHttp;
|
|
private HttpUtil studentHttp;
|
|
@@ -61,7 +64,7 @@ public class DataSyncThread implements Runnable {
|
|
|
|
|
|
public static final String SIZE = "size";
|
|
public static final String SIZE = "size";
|
|
|
|
|
|
- public DataSyncThread(DataSync dataSync, String secretKey, String appId, Integer pageSize, String baseDir,
|
|
|
|
|
|
+ public DataSyncThread(DataSync dataSync, Integer pageSize, String baseDir, UpyunConfig config,
|
|
LockService lockService, DataSyncService dataSyncService, ExamService examService,
|
|
LockService lockService, DataSyncService dataSyncService, ExamService examService,
|
|
ExamStudentService studentService) {
|
|
ExamStudentService studentService) {
|
|
this.dataSync = dataSync;
|
|
this.dataSync = dataSync;
|
|
@@ -71,8 +74,11 @@ public class DataSyncThread implements Runnable {
|
|
this.studentService = studentService;
|
|
this.studentService = studentService;
|
|
this.pageSize = pageSize;
|
|
this.pageSize = pageSize;
|
|
this.baseDir = baseDir;
|
|
this.baseDir = baseDir;
|
|
- this.subjectHttp = new HttpUtil(dataSync.getUrl(), secretKey, appId, dataSync.getRootOrgId());
|
|
|
|
- this.studentHttp = new HttpUtil(dataSync.getUrl(), secretKey, appId, dataSync.getRootOrgId());
|
|
|
|
|
|
+ this.config = config;
|
|
|
|
+ this.subjectHttp = new HttpUtil(dataSync.getSubjectUrl(), dataSync.getSecretKey(), dataSync.getAppId(),
|
|
|
|
+ dataSync.getRootOrgId());
|
|
|
|
+ this.studentHttp = new HttpUtil(dataSync.getStudentUrl(), dataSync.getSecretKey(), dataSync.getAppId(),
|
|
|
|
+ dataSync.getRootOrgId());
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -86,7 +92,7 @@ public class DataSyncThread implements Runnable {
|
|
sync = dataSync;
|
|
sync = dataSync;
|
|
}
|
|
}
|
|
JSONObject datas = new JSONObject();
|
|
JSONObject datas = new JSONObject();
|
|
- datas.accumulate("examId", dataSync.getCloudExamId());
|
|
|
|
|
|
+ datas.accumulate("examId", sync.getCloudExamId());
|
|
String subjectResult = subjectHttp.httpAction(null, datas.toString());
|
|
String subjectResult = subjectHttp.httpAction(null, datas.toString());
|
|
JSONObject subjectJson = JSONObject.fromObject(subjectResult);
|
|
JSONObject subjectJson = JSONObject.fromObject(subjectResult);
|
|
JSONArray subjectArray = subjectJson.getJSONArray(PAPER_STRUCT);
|
|
JSONArray subjectArray = subjectJson.getJSONArray(PAPER_STRUCT);
|
|
@@ -115,7 +121,7 @@ public class DataSyncThread implements Runnable {
|
|
for (int j = 0; j < studentArray.size(); j++) {
|
|
for (int j = 0; j < studentArray.size(); j++) {
|
|
JSONObject student = studentArray.getJSONObject(i);
|
|
JSONObject student = studentArray.getJSONObject(i);
|
|
ExamStudent examStudent = new ExamStudent();
|
|
ExamStudent examStudent = new ExamStudent();
|
|
- examStudent.setExamId(dataSync.getExamId());
|
|
|
|
|
|
+ examStudent.setExamId(sync.getExamId());
|
|
examStudent.setStudentCode(student.getString("studentCode"));
|
|
examStudent.setStudentCode(student.getString("studentCode"));
|
|
examStudent.setName(student.getString("name"));
|
|
examStudent.setName(student.getString("name"));
|
|
examStudent.setCollege(DEFAULT_NULL);
|
|
examStudent.setCollege(DEFAULT_NULL);
|
|
@@ -138,22 +144,25 @@ public class DataSyncThread implements Runnable {
|
|
list.add(examStudent);
|
|
list.add(examStudent);
|
|
|
|
|
|
String answerJson = student.getString("subjectives");
|
|
String answerJson = student.getString("subjectives");
|
|
- File file = new File(baseDir
|
|
|
|
- + PictureUrlBuilder.getAnswerJson(exam.getId(), subjectCode, null,
|
|
|
|
|
|
+ File file = new File(new File(baseDir, config.getMediaBucket()),
|
|
|
|
+ PictureUrlBuilder.getAnswerJson(exam.getId(), subjectCode, null,
|
|
examStudent.getExamNumber()));
|
|
examStudent.getExamNumber()));
|
|
|
|
+ if (!file.exists()) {
|
|
|
|
+ file.createNewFile();
|
|
|
|
+ }
|
|
FileOutputStream fos = new FileOutputStream(file);
|
|
FileOutputStream fos = new FileOutputStream(file);
|
|
fos.write(answerJson.getBytes());
|
|
fos.write(answerJson.getBytes());
|
|
fos.close();
|
|
fos.close();
|
|
}
|
|
}
|
|
studentService.batchSave(list);
|
|
studentService.batchSave(list);
|
|
- dataSync.setUpdateTime(new Date());
|
|
|
|
- dataSync.setNextId(nextId);
|
|
|
|
- dataSync.setSubjectCode(subjectCode);
|
|
|
|
- dataSyncService.save(dataSync);
|
|
|
|
|
|
+ sync.setUpdateTime(new Date());
|
|
|
|
+ sync.setNextId(nextId);
|
|
|
|
+ sync.setSubjectCode(subjectCode);
|
|
|
|
+ dataSyncService.save(sync);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- dataSync.setFinished(true);
|
|
|
|
- dataSyncService.save(dataSync);
|
|
|
|
|
|
+ sync.setFinished(true);
|
|
|
|
+ dataSyncService.save(sync);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.error("data sync exception for examId=" + dataSync.getExamId(), e);
|
|
log.error("data sync exception for examId=" + dataSync.getExamId(), e);
|
|
} finally {
|
|
} finally {
|