|
@@ -0,0 +1,62 @@
|
|
|
+package cn.com.qmth.scancloud.tools.service.impl;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import com.google.common.collect.Maps;
|
|
|
+
|
|
|
+import cn.com.qmth.scancloud.tools.config.SysProperty;
|
|
|
+import cn.com.qmth.scancloud.tools.enums.TaskType;
|
|
|
+import cn.com.qmth.scancloud.tools.service.AbstractTask;
|
|
|
+import cn.com.qmth.scancloud.tools.service.CommonService;
|
|
|
+import cn.com.qmth.scancloud.tools.utils.HttpHelper;
|
|
|
+import cn.com.qmth.scancloud.tools.utils.MD5Util;
|
|
|
+import cn.com.qmth.scancloud.tools.utils.StatusException;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 卡格式导入
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class CardImportTask extends AbstractTask {
|
|
|
+
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(CardImportTask.class);
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected String getTaskName() {
|
|
|
+ return TaskType.CARD_IMPORT.getTitle();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void execute() {
|
|
|
+ Long examId = SysProperty.EXAM_ID;
|
|
|
+ if (examId == null) {
|
|
|
+ throw new StatusException("【scan.tool.exam-id】未配置!");
|
|
|
+ }
|
|
|
+ String subjectCode = SysProperty.SUBJECT_CODE;
|
|
|
+ if (StringUtils.isBlank(subjectCode)) {
|
|
|
+ throw new StatusException("【scan.tool.subject-code】未配置!");
|
|
|
+ }
|
|
|
+ if (CommonService.findExam(examId) == null) {
|
|
|
+ throw new StatusException("当前考试不存在!examId = " + examId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CommonService.findCourse(examId, subjectCode) == null) {
|
|
|
+ throw new StatusException("当前科目不存在!subjectCode = "+subjectCode);
|
|
|
+ }
|
|
|
+ File file = new File(SysProperty.DATA_DIR + "/" + SysProperty.CARD_IMPORT);
|
|
|
+ String url = SysProperty.SCAN_SERVER_URL + "/api/tool/import/card/save";
|
|
|
+ Map<String, String> params = Maps.newHashMap();
|
|
|
+ params.put("examId", examId.toString());
|
|
|
+ params.put("subjectCode", subjectCode);
|
|
|
+ params.put("paperCount","2");
|
|
|
+ params.put("singlePage", "false");
|
|
|
+ params.put("md5", MD5Util.md5Hex(file));
|
|
|
+ String ret=HttpHelper.post(url, params,file);
|
|
|
+ log.info("处理完毕,卡格式编号:"+ret);
|
|
|
+ }
|
|
|
+}
|