Pārlūkot izejas kodu

注释又拍云代码

xiatian 8 mēneši atpakaļ
vecāks
revīzija
60291e717b

+ 43 - 34
src/main/java/cn/com/qmth/dp/examcloud/oe/Task.java

@@ -19,9 +19,9 @@ import com.mongodb.client.MongoCursor;
 import cn.com.qmth.dp.examcloud.oe.modules.findreduplicatequestion.ExportReduplicateQuestionService;
 import cn.com.qmth.examcloud.commons.util.JsonUtil;
 import cn.com.qmth.examcloud.web.support.SpringContextHolder;
-import cn.com.qmth.examcloud.web.upyun.UpYunPathInfo;
-import cn.com.qmth.examcloud.web.upyun.UpyunPathEnvironmentInfo;
-import cn.com.qmth.examcloud.web.upyun.UpyunService;
+// import cn.com.qmth.examcloud.web.upyun.UpYunPathInfo;
+// import cn.com.qmth.examcloud.web.upyun.UpyunPathEnvironmentInfo;
+// import cn.com.qmth.examcloud.web.upyun.UpyunService;
 
 /**
  * 任务
@@ -46,13 +46,16 @@ public class Task {
             // SpringContextHolder.getBean(ImportPaperDzkdService.class).start();
             // SpringContextHolder.getBean(FixCorrectAnswerAndResetScoreService.class).start();
             // SpringContextHolder.getBean(ExportExamStudentScore.class).start(123L);
-            // SpringContextHolder.getBean(GetStduentOneAnswerService.class).start(1213L, 1, "01");
-            // SpringContextHolder.getBean(GetStduentAnswerDetailService.class).start(1627L, "000004");
+            // SpringContextHolder.getBean(GetStduentOneAnswerService.class).start(1213L,
+            // 1, "01");
+            // SpringContextHolder.getBean(GetStduentAnswerDetailService.class).start(1627L,
+            // "000004");
             // SpringContextHolder.getBean(InitUserDataRule.class).start();
-            // SpringContextHolder.getBean(FixExamStudentId.class).start(2843L, null);
+            // SpringContextHolder.getBean(FixExamStudentId.class).start(2843L,
+            // null);
             // SpringContextHolder.getBean(MarkingItemChangeService.class).start();
-             SpringContextHolder.getBean(ExportReduplicateQuestionService.class).start();
-             System.out.println("finish *********************");
+            SpringContextHolder.getBean(ExportReduplicateQuestionService.class).start();
+            System.out.println("finish *********************");
         } catch (Exception e) {
             log.error("unexpected", e);
             throw new RuntimeException(e);
@@ -66,32 +69,38 @@ public class Task {
      */
     public static void test() {
 
-        UpyunService upyunService = SpringContextHolder.getBean(UpyunService.class);
-        UpyunPathEnvironmentInfo env = new UpyunPathEnvironmentInfo();
-        env.setFileSuffix(".jpg");
-        env.setRootOrgId(String.valueOf(RandomUtils.nextLong()));
-        UpYunPathInfo upYunPathInfo = upyunService.writeFile("test", env,
-                new File("D:/Temp/111111X.jpg"), true);
-        System.out.println("upYunPathInfo: " + JsonUtil.toPrettyJson(upYunPathInfo));
-
-        JdbcTemplate jdbcTemplate = SpringContextHolder.getBean(JdbcTemplate.class);
-        List<Map<String, Object>> list = jdbcTemplate.queryForList("SELECT now() FROM dual");
-        System.out.println(JsonUtil.toJson(list));
-
-        MongoTemplate mongoTemplate = SpringContextHolder.getBean(MongoTemplate.class);
-        String dbName = mongoTemplate.getDb().getName();
-        System.out.println("mongo.db=" + dbName);
-        MongoCollection<Document> collection = mongoTemplate.getCollection("examRecordQuestions");
-        Document filter = new Document();
-        filter.append("examRecordDataId", 101373L);
-        FindIterable<Document> iterable = collection.find(filter);
-        MongoCursor<Document> iterator = iterable.iterator();
-        while (iterator.hasNext()) {
-            Document next = iterator.next();
-
-            System.out.println("_id=" + next.getObjectId("_id"));
-            System.out.println(JsonUtil.toPrettyJson(next));
-        }
+        // UpyunService upyunService =
+        // SpringContextHolder.getBean(UpyunService.class);
+        // UpyunPathEnvironmentInfo env = new UpyunPathEnvironmentInfo();
+        // env.setFileSuffix(".jpg");
+        // env.setRootOrgId(String.valueOf(RandomUtils.nextLong()));
+        // UpYunPathInfo upYunPathInfo = upyunService.writeFile("test", env,
+        // new File("D:/Temp/111111X.jpg"), true);
+        // System.out.println("upYunPathInfo: " +
+        // JsonUtil.toPrettyJson(upYunPathInfo));
+        //
+        // JdbcTemplate jdbcTemplate =
+        // SpringContextHolder.getBean(JdbcTemplate.class);
+        // List<Map<String, Object>> list = jdbcTemplate.queryForList("SELECT
+        // now() FROM dual");
+        // System.out.println(JsonUtil.toJson(list));
+        //
+        // MongoTemplate mongoTemplate =
+        // SpringContextHolder.getBean(MongoTemplate.class);
+        // String dbName = mongoTemplate.getDb().getName();
+        // System.out.println("mongo.db=" + dbName);
+        // MongoCollection<Document> collection =
+        // mongoTemplate.getCollection("examRecordQuestions");
+        // Document filter = new Document();
+        // filter.append("examRecordDataId", 101373L);
+        // FindIterable<Document> iterable = collection.find(filter);
+        // MongoCursor<Document> iterator = iterable.iterator();
+        // while (iterator.hasNext()) {
+        // Document next = iterator.next();
+        //
+        // System.out.println("_id=" + next.getObjectId("_id"));
+        // System.out.println(JsonUtil.toPrettyJson(next));
+        // }
     }
 
 }

+ 44 - 41
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/update_student_answer/FixStudentAnswer.java

@@ -15,45 +15,48 @@ import cn.com.qmth.examcloud.web.support.SpringContextHolder;
  */
 @Service
 public class FixStudentAnswer {
-
-	private static final Logger log = LoggerFactory.getLogger(FixStudentAnswer.class);
-
-	/**
-	 * 修复图片
-	 */
-	public void startFixPicAnswer(Long examId, String courseCode, int order) {
-		FixStudentAnswerService service = SpringContextHolder
-				.getBean(FixStudentAnswerService.class);
-		String srcPicFileDirectory = "D:/Temp/srcPic";
-		try {
-			service.fixStudentAnswer(srcPicFileDirectory, examId, courseCode, order,
-					FixAnswerType.PICTURE);
-		} catch (FileNotFoundException e) {
-			e.printStackTrace();
-			log.error("FileNotFoundException", e);
-		} catch (UnsupportedEncodingException e) {
-			e.printStackTrace();
-			log.error("UnsupportedEncodingException", e);
-		} catch (Exception e) {
-			log.error("UnkonwnException ", e);
-		}
-	}
-
-	public void startFixAudioAnswer(Long examId, String courseCode, int order) {
-		FixStudentAnswerService service = SpringContextHolder
-				.getBean(FixStudentAnswerService.class);
-		String srcPicFileDirectory = "D:/Temp/srcAudio";
-		try {
-			service.fixStudentAnswer(srcPicFileDirectory, examId, courseCode, order,
-					FixAnswerType.AUDIO);
-		} catch (FileNotFoundException e) {
-			e.printStackTrace();
-			log.error("FileNotFoundException", e);
-		} catch (UnsupportedEncodingException e) {
-			e.printStackTrace();
-			log.error("UnsupportedEncodingException", e);
-		} catch (Exception e) {
-			log.error("UnkonwnException ", e);
-		}
-	}
+    //
+    // private static final Logger log =
+    // LoggerFactory.getLogger(FixStudentAnswer.class);
+    //
+    // /**
+    // * 修复图片
+    // */
+    // public void startFixPicAnswer(Long examId, String courseCode, int order)
+    // {
+    // FixStudentAnswerService service = SpringContextHolder
+    // .getBean(FixStudentAnswerService.class);
+    // String srcPicFileDirectory = "D:/Temp/srcPic";
+    // try {
+    // service.fixStudentAnswer(srcPicFileDirectory, examId, courseCode, order,
+    // FixAnswerType.PICTURE);
+    // } catch (FileNotFoundException e) {
+    // e.printStackTrace();
+    // log.error("FileNotFoundException", e);
+    // } catch (UnsupportedEncodingException e) {
+    // e.printStackTrace();
+    // log.error("UnsupportedEncodingException", e);
+    // } catch (Exception e) {
+    // log.error("UnkonwnException ", e);
+    // }
+    // }
+    //
+    // public void startFixAudioAnswer(Long examId, String courseCode, int
+    // order) {
+    // FixStudentAnswerService service = SpringContextHolder
+    // .getBean(FixStudentAnswerService.class);
+    // String srcPicFileDirectory = "D:/Temp/srcAudio";
+    // try {
+    // service.fixStudentAnswer(srcPicFileDirectory, examId, courseCode, order,
+    // FixAnswerType.AUDIO);
+    // } catch (FileNotFoundException e) {
+    // e.printStackTrace();
+    // log.error("FileNotFoundException", e);
+    // } catch (UnsupportedEncodingException e) {
+    // e.printStackTrace();
+    // log.error("UnsupportedEncodingException", e);
+    // } catch (Exception e) {
+    // log.error("UnkonwnException ", e);
+    // }
+    // }
 }

+ 137 - 131
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/update_student_answer/FixStudentAnswerService.java

@@ -27,7 +27,7 @@ import cn.com.qmth.examcloud.commons.exception.StatusException;
 import cn.com.qmth.examcloud.commons.helpers.Counter;
 import cn.com.qmth.examcloud.commons.util.JsonUtil;
 import cn.com.qmth.examcloud.commons.util.Util;
-import cn.com.qmth.examcloud.web.upyun.UpyunService;
+// import cn.com.qmth.examcloud.web.upyun.UpyunService;
 
 /**
  * @Description 修复学生作答
@@ -38,134 +38,140 @@ import cn.com.qmth.examcloud.web.upyun.UpyunService;
 @Service
 public class FixStudentAnswerService {
 
-	@Autowired
-	JdbcTemplate jdbcTemplate;
-
-	@Autowired
-	MongoTemplate mongoTemplate;
-
-	@Autowired
-	UpyunService upyunService;
-
-	private static Counter counter = new Counter(0L, 1000000L);
-
-	public void fixStudentAnswer(String filePath, Long examId, String courseCode, Integer order,
-			FixAnswerType fixAnswerType)
-			throws FileNotFoundException, UnsupportedEncodingException {
-		if (fixAnswerType != FixAnswerType.AUDIO && fixAnswerType != FixAnswerType.PICTURE) {
-			throw new StatusException("100001", "修改的文件类型格式不正确");
-		}
-		// 错误提示
-		List<Map<String, Object>> failList = Lists.newArrayList();
-		File file = new File(filePath);
-
-		if (file.isDirectory()) {
-			String[] list = file.list();
-			// 循环查库
-			// 获取身份证键值对信息
-			Map<String, List<Map<String, Object>>> identityMap = getIdentityMap(filePath, list);
-
-			Set<String> keys = identityMap.keySet();
-			Set<String> tempKeys = Sets.newHashSet();
-			int index = 0;
-			int threadSize = 10;
-			int batchSize = keys.size() / threadSize + 1;
-			for (String key : keys) {
-				index++;
-				tempKeys.add(key);
-				if (index == batchSize) {
-					new FixStudentAnswerThread(jdbcTemplate, mongoTemplate, tempKeys, examId,
-							courseCode, failList, identityMap, order, fixAnswerType, upyunService,
-							counter).start();
-					index = 0;
-					tempKeys = Sets.newHashSet();
-				}
-			}
-
-			if (CollectionUtils.isNotEmpty(tempKeys)) {
-				new FixStudentAnswerThread(jdbcTemplate, mongoTemplate, tempKeys, examId,
-						courseCode, failList, identityMap, order, fixAnswerType, upyunService,
-						counter).start();
-			}
-
-		}
-
-		while (true) {
-			Util.sleep(5);
-			System.out.println("count: " + counter.get());
-			System.out.println("failList: \n" + JsonUtil.toPrettyJson(failList));
-		}
-
-	}
-
-	/**
-	 * 获取身份证和文件地址的对应关系
-	 * 
-	 * @param list
-	 * @return
-	 */
-	private Map<String, List<Map<String, Object>>> getIdentityMap(String filePath, String[] list) {
-		// 所有的图片
-		List<Map<String, Object>> fileMapList = new ArrayList<>();
-		for (String fileName : list) {
-			String fullFilePath = filePath + File.separator + fileName;
-			fileName = RegExUtils.replaceAll(fileName, "\\s+", "");
-			// 如果有-,则证明有多张图片
-			if (fileName.indexOf("-") != -1) {
-				String identityNumber = fileName.substring(0, fileName.indexOf("-"));
-				Map<String, Object> map = new HashMap<>();
-				map.put("identityNumber", identityNumber);
-				map.put("filePath", fullFilePath);
-				// 排序号
-				int sortOrder = 0;
-				if (fileName.indexOf("_") != -1) {
-					try {
-						sortOrder = Integer.parseInt(fileName.substring(fileName.indexOf("-") + 1,
-								fileName.indexOf("_")));
-					} catch (NumberFormatException e) {
-						e.printStackTrace();
-					}
-				} else {
-					try {
-						sortOrder = Integer.parseInt(fileName.substring(fileName.indexOf("-") + 1,
-								fileName.indexOf(".")));
-					} catch (NumberFormatException e) {
-						e.printStackTrace();
-					}
-				}
-				map.put("order", sortOrder);
-				fileMapList.add(map);
-			} else {
-				String identityNumber = "";
-				if (fileName.indexOf("_") > -1) {
-					identityNumber = fileName.substring(0, fileName.indexOf("_"));
-				} else {
-					identityNumber = fileName.substring(0, fileName.indexOf("."));
-				}
-				Map<String, Object> map = new HashMap<>();
-				map.put("identityNumber", identityNumber);
-				map.put("filePath", fullFilePath);
-				map.put("order", 0);
-				fileMapList.add(map);
-			}
-		}
-		Map<String, List<Map<String, Object>>> resultMap = new HashMap<>();
-		for (Map<String, Object> fm : fileMapList) {
-			List<Map<String, Object>> mapList = fileMapList.stream()
-					.filter(p -> p.get("identityNumber").equals(fm.get("identityNumber")))
-					.collect(Collectors.toList());
-			// 对文件进行排序
-			Collections.sort(mapList, new Comparator<Map<String, Object>>() {
-				public int compare(Map<String, Object> o1, Map<String, Object> o2) {
-					int map1value = Integer.parseInt(o1.get("order").toString());
-					int map2value = Integer.parseInt(o2.get("order").toString());
-					return map1value - map2value;
-				}
-			});
-			if (resultMap.get(fm.get("identityNumber")) == null) {
-				resultMap.put(fm.get("identityNumber").toString(), mapList);
-			}
-		}
-		return resultMap;
-	}
+    // @Autowired
+    // JdbcTemplate jdbcTemplate;
+    //
+    // @Autowired
+    // MongoTemplate mongoTemplate;
+    //
+    // @Autowired
+    // UpyunService upyunService;
+    //
+    // private static Counter counter = new Counter(0L, 1000000L);
+    //
+    // public void fixStudentAnswer(String filePath, Long examId, String
+    // courseCode, Integer order,
+    // FixAnswerType fixAnswerType)
+    // throws FileNotFoundException, UnsupportedEncodingException {
+    // if (fixAnswerType != FixAnswerType.AUDIO && fixAnswerType !=
+    // FixAnswerType.PICTURE) {
+    // throw new StatusException("100001", "修改的文件类型格式不正确");
+    // }
+    // // 错误提示
+    // List<Map<String, Object>> failList = Lists.newArrayList();
+    // File file = new File(filePath);
+    //
+    // if (file.isDirectory()) {
+    // String[] list = file.list();
+    // // 循环查库
+    // // 获取身份证键值对信息
+    // Map<String, List<Map<String, Object>>> identityMap =
+    // getIdentityMap(filePath, list);
+    //
+    // Set<String> keys = identityMap.keySet();
+    // Set<String> tempKeys = Sets.newHashSet();
+    // int index = 0;
+    // int threadSize = 10;
+    // int batchSize = keys.size() / threadSize + 1;
+    // for (String key : keys) {
+    // index++;
+    // tempKeys.add(key);
+    // if (index == batchSize) {
+    // new FixStudentAnswerThread(jdbcTemplate, mongoTemplate, tempKeys, examId,
+    // courseCode, failList, identityMap, order, fixAnswerType, upyunService,
+    // counter).start();
+    // index = 0;
+    // tempKeys = Sets.newHashSet();
+    // }
+    // }
+    //
+    // if (CollectionUtils.isNotEmpty(tempKeys)) {
+    // new FixStudentAnswerThread(jdbcTemplate, mongoTemplate, tempKeys, examId,
+    // courseCode, failList, identityMap, order, fixAnswerType, upyunService,
+    // counter).start();
+    // }
+    //
+    // }
+    //
+    // while (true) {
+    // Util.sleep(5);
+    // System.out.println("count: " + counter.get());
+    // System.out.println("failList: \n" + JsonUtil.toPrettyJson(failList));
+    // }
+    //
+    // }
+    //
+    // /**
+    // * 获取身份证和文件地址的对应关系
+    // *
+    // * @param list
+    // * @return
+    // */
+    // private Map<String, List<Map<String, Object>>> getIdentityMap(String
+    // filePath, String[] list) {
+    // // 所有的图片
+    // List<Map<String, Object>> fileMapList = new ArrayList<>();
+    // for (String fileName : list) {
+    // String fullFilePath = filePath + File.separator + fileName;
+    // fileName = RegExUtils.replaceAll(fileName, "\\s+", "");
+    // // 如果有-,则证明有多张图片
+    // if (fileName.indexOf("-") != -1) {
+    // String identityNumber = fileName.substring(0, fileName.indexOf("-"));
+    // Map<String, Object> map = new HashMap<>();
+    // map.put("identityNumber", identityNumber);
+    // map.put("filePath", fullFilePath);
+    // // 排序号
+    // int sortOrder = 0;
+    // if (fileName.indexOf("_") != -1) {
+    // try {
+    // sortOrder = Integer.parseInt(fileName.substring(fileName.indexOf("-") +
+    // 1,
+    // fileName.indexOf("_")));
+    // } catch (NumberFormatException e) {
+    // e.printStackTrace();
+    // }
+    // } else {
+    // try {
+    // sortOrder = Integer.parseInt(fileName.substring(fileName.indexOf("-") +
+    // 1,
+    // fileName.indexOf(".")));
+    // } catch (NumberFormatException e) {
+    // e.printStackTrace();
+    // }
+    // }
+    // map.put("order", sortOrder);
+    // fileMapList.add(map);
+    // } else {
+    // String identityNumber = "";
+    // if (fileName.indexOf("_") > -1) {
+    // identityNumber = fileName.substring(0, fileName.indexOf("_"));
+    // } else {
+    // identityNumber = fileName.substring(0, fileName.indexOf("."));
+    // }
+    // Map<String, Object> map = new HashMap<>();
+    // map.put("identityNumber", identityNumber);
+    // map.put("filePath", fullFilePath);
+    // map.put("order", 0);
+    // fileMapList.add(map);
+    // }
+    // }
+    // Map<String, List<Map<String, Object>>> resultMap = new HashMap<>();
+    // for (Map<String, Object> fm : fileMapList) {
+    // List<Map<String, Object>> mapList = fileMapList.stream()
+    // .filter(p -> p.get("identityNumber").equals(fm.get("identityNumber")))
+    // .collect(Collectors.toList());
+    // // 对文件进行排序
+    // Collections.sort(mapList, new Comparator<Map<String, Object>>() {
+    // public int compare(Map<String, Object> o1, Map<String, Object> o2) {
+    // int map1value = Integer.parseInt(o1.get("order").toString());
+    // int map2value = Integer.parseInt(o2.get("order").toString());
+    // return map1value - map2value;
+    // }
+    // });
+    // if (resultMap.get(fm.get("identityNumber")) == null) {
+    // resultMap.put(fm.get("identityNumber").toString(), mapList);
+    // }
+    // }
+    // return resultMap;
+    // }
 }

+ 228 - 210
src/main/java/cn/com/qmth/dp/examcloud/oe/modules/update_student_answer/FixStudentAnswerThread.java

@@ -19,9 +19,9 @@ import com.mongodb.client.result.UpdateResult;
 import cn.com.qmth.dp.examcloud.oe.modules.update_student_answer.entity.ExamRecordEntity;
 import cn.com.qmth.dp.examcloud.oe.modules.update_student_answer.entity.FixAnswerType;
 import cn.com.qmth.examcloud.commons.helpers.Counter;
-import cn.com.qmth.examcloud.web.upyun.UpYunPathInfo;
-import cn.com.qmth.examcloud.web.upyun.UpyunPathEnvironmentInfo;
-import cn.com.qmth.examcloud.web.upyun.UpyunService;
+// import cn.com.qmth.examcloud.web.upyun.UpYunPathInfo;
+// import cn.com.qmth.examcloud.web.upyun.UpyunPathEnvironmentInfo;
+// import cn.com.qmth.examcloud.web.upyun.UpyunService;
 
 /**
  * @Description TODO
@@ -30,211 +30,229 @@ import cn.com.qmth.examcloud.web.upyun.UpyunService;
  * @Version 1.0
  */
 public class FixStudentAnswerThread extends Thread {
-	private Set<String> identityKeys;
-
-	JdbcTemplate jdbcTemplate;
-
-	MongoTemplate mongoTemplate;
-
-	Long examId;
-
-	String courseCode;
-
-	List<Map<String, Object>> failList;
-
-	Map<String, List<Map<String, Object>>> identityMap;
-
-	Integer order;
-
-	FixAnswerType fixAnswerType;
-
-	UpyunService upyunService;
-
-	Counter counter;
-
-	public FixStudentAnswerThread(JdbcTemplate jdbcTemplate, MongoTemplate mongoTemplate,
-			Set<String> identityKeys, Long examId, String courseCode,
-			List<Map<String, Object>> failList, Map<String, List<Map<String, Object>>> identityMap,
-			Integer order, FixAnswerType fixAnswerType, UpyunService upyunService,
-			Counter counter) {
-		this.identityKeys = identityKeys;
-		this.jdbcTemplate = jdbcTemplate;
-		this.mongoTemplate = mongoTemplate;
-		this.examId = examId;
-		this.courseCode = courseCode;
-		this.failList = failList;
-		this.identityMap = identityMap;
-		this.order = order;
-		this.fixAnswerType = fixAnswerType;
-		this.upyunService = upyunService;
-		this.counter = counter;
-	}
-
-	@Override
-	public void run() {
-		// 改成多线程
-		for (String identityNumber : identityKeys) {
-			List<ExamRecordEntity> recordList = getExamRecordList(examId, courseCode,
-					identityNumber);
-			// 学生的考试记录(一个学生可能有多次考试)
-			List<ExamRecordEntity> examRecords = getExamRecordListByIdentityNumber(identityNumber,
-					recordList);
-			if (examRecords == null || examRecords.isEmpty()) {
-				logErr(identityNumber, "找不到身份证号为:" + identityNumber + "的考试记录数据", failList);
-				continue;
-			}
-			for (ExamRecordEntity examRecord : examRecords) {
-				// 考试记录id
-				Long examRecordDataId = examRecord.getExamRecordDataId();
-				// 学生id
-				Long studnetId = examRecord.getStudentId();
-				// 如果没有找到考试记录id
-				try {
-					String newAnswer = "";
-					// 第一步,上传又拍云(多个文件的话,一个个追加)
-					// 当前学生的文件集合
-					List<Map<String, Object>> fileByIdnetityNumberList = identityMap
-							.get(identityNumber);
-					for (Map<String, Object> m : fileByIdnetityNumberList) {
-						this.counter.next();
-						UpyunPathEnvironmentInfo env = new UpyunPathEnvironmentInfo();
-						env.setUserId(studnetId.toString());
-						env.setExt1(examRecordDataId.toString());
-						env.setExt2(order.toString());
-						env.setFileSuffix(getFileSuffix(fixAnswerType));
-
-						String tempFilePath = m.get("filePath").toString();
-						String fullFilePath = tempFilePath;
-						System.out.println("正在上传文件:" + fullFilePath);
-						UpYunPathInfo upYunPathInfo = upyunService.writeFile(
-								getSiteId(fixAnswerType), env, new File(fullFilePath), true);
-						// 上传U盘云的完整地址
-						String upYunFileUrl = upYunPathInfo.getUrl();
-
-						newAnswer += buildFileAnswer(fixAnswerType, upYunFileUrl) + ",";
-					}
-					if (newAnswer.indexOf(",") > -1) {
-						newAnswer = newAnswer.substring(0, newAnswer.lastIndexOf(","));
-					}
-					// 第二步,更新答案
-					long res = updateAnswer(examRecordDataId, order, newAnswer);
-					if (res < 1) {
-						logErr(identityNumber, "更新答案失败", failList);
-						System.out.println("[Fail]:身份证号:" + identityNumber + ",考试记录id:"
-								+ examRecordDataId + ",答案更新失败");
-					} else {
-						System.out.println("[Success]:身份证号:" + identityNumber + ",考试记录id:"
-								+ examRecordDataId + ",答案更新成功");
-					}
-				} catch (Exception e) {
-					logErr(identityNumber, e.getMessage(), failList);
-					continue;
-				}
-			}
-		}
-	}
-
-	private String getFileSuffix(FixAnswerType fixAnswerType) {
-		if (fixAnswerType == FixAnswerType.PICTURE) {
-			return ".jpg";
-		} else {
-			return ".mp3";
-		}
-	}
-
-	public List<ExamRecordEntity> getExamRecordList(Long examId, String courseCode,
-			String identityNumber) {
-		String strSql = "select erd.id as examRecordDataId,er.exam_id as examId, "
-				+ "er.identity_number as identityNumber,c.`code` as courseCode,er.student_id as studentId "
-				+ "from ec_oe_exam_record er "
-				+ "inner join ec_oe_exam_record_data erd on er.id=erd.exam_record_id "
-				+ "inner join ec_b_course c on er.course_id=c.id " + "where er.exam_id=" + examId
-				+ " and c.`code`='" + courseCode + "'" + " and er.identity_number='"
-				+ identityNumber + "'";
-
-		java.util.List<Map<String, Object>> mapList = jdbcTemplate.queryForList(strSql);
-		java.util.List<ExamRecordEntity> resultList = new ArrayList<ExamRecordEntity>();
-		for (Map<String, Object> map : mapList) {
-			ExamRecordEntity entity = new ExamRecordEntity();
-			if (map.get("courseCode") != null) {
-				entity.setCourseCode(map.get("courseCode").toString());
-			}
-			if (map.get("examId") != null) {
-				entity.setExamId(Long.parseLong(map.get("examId").toString()));
-			}
-			if (map.get("examRecordDataId") != null) {
-				entity.setExamRecordDataId(Long.parseLong(map.get("examRecordDataId").toString()));
-			}
-			if (map.get("identityNumber") != null) {
-				entity.setIdentityNumber(map.get("identityNumber").toString());
-			}
-			if (map.get("studentId") != null) {
-				entity.setStudentId(Long.parseLong(map.get("studentId").toString()));
-			}
-			resultList.add(entity);
-		}
-		return resultList;
-	}
-
-	// 根据身份证号获取考试记录id(同一个学生可能有多次考试)
-	private List<ExamRecordEntity> getExamRecordListByIdentityNumber(String identityNumber,
-			List<ExamRecordEntity> examRecordList) {
-		List<ExamRecordEntity> resultList = examRecordList.stream()
-				.filter(record -> record.getIdentityNumber().equals(identityNumber))
-				.collect(Collectors.toList());
-		return resultList;
-	}
-
-	private String getSiteId(FixAnswerType fixAnswerType) {
-		if (fixAnswerType == FixAnswerType.PICTURE) {
-			return "photoAnswer";
-		} else {
-			return "audioAnswer";
-		}
-	}
-
-	/**
-	 * 更新指定试题的答案
-	 *
-	 * @param examRecordDataId
-	 * @param order
-	 * @param newAnswer
-	 * @return
-	 */
-	public long updateAnswer(Long examRecordDataId, Integer order, String newAnswer) {
-		// 查询相应的题目
-		Query query = Query.query(Criteria.where("examRecordDataId").is(examRecordDataId)
-				.and("examQuestionEntities.order").is(order));
-		Update update = Update.update("examQuestionEntities.$.studentAnswer", newAnswer);
-		UpdateResult upResult = mongoTemplate.updateFirst(query, update, "examRecordQuestions");
-		return upResult.getMatchedCount();
-	}
-
-	/**
-	 * 构建文件格式
-	 *
-	 * @param fileUrl
-	 * @return
-	 */
-	private String buildFileAnswer(FixAnswerType fixAnswerType, String fileUrl) {
-		if (fixAnswerType == FixAnswerType.PICTURE) {
-			StringBuilder sb = new StringBuilder();
-
-			sb.append("<div class='photo-answers-block'>");
-			sb.append("<a href='" + fileUrl + "' target='_blank' >");
-			sb.append("<img class='photo-answer' src='" + fileUrl + "!/both/200x200' />");
-			sb.append("</a>");
-			sb.append("</div>");
-			return sb.toString();
-		} else {
-			return fileUrl;
-		}
-	}
-
-	private void logErr(String identityNumber, String errMsg, List<Map<String, Object>> failList) {
-		Map<String, Object> errMap = new HashMap<>();
-		errMap.put("identityNumber", identityNumber);
-		errMap.put("err", errMsg);
-		failList.add(errMap);
-	}
+    // private Set<String> identityKeys;
+    //
+    // JdbcTemplate jdbcTemplate;
+    //
+    // MongoTemplate mongoTemplate;
+    //
+    // Long examId;
+    //
+    // String courseCode;
+    //
+    // List<Map<String, Object>> failList;
+    //
+    // Map<String, List<Map<String, Object>>> identityMap;
+    //
+    // Integer order;
+    //
+    // FixAnswerType fixAnswerType;
+    //
+    // UpyunService upyunService;
+    //
+    // Counter counter;
+    //
+    // public FixStudentAnswerThread(JdbcTemplate jdbcTemplate, MongoTemplate
+    // mongoTemplate,
+    // Set<String> identityKeys, Long examId, String courseCode,
+    // List<Map<String, Object>> failList, Map<String, List<Map<String,
+    // Object>>> identityMap,
+    // Integer order, FixAnswerType fixAnswerType, UpyunService upyunService,
+    // Counter counter) {
+    // this.identityKeys = identityKeys;
+    // this.jdbcTemplate = jdbcTemplate;
+    // this.mongoTemplate = mongoTemplate;
+    // this.examId = examId;
+    // this.courseCode = courseCode;
+    // this.failList = failList;
+    // this.identityMap = identityMap;
+    // this.order = order;
+    // this.fixAnswerType = fixAnswerType;
+    // this.upyunService = upyunService;
+    // this.counter = counter;
+    // }
+    //
+    // @Override
+    // public void run() {
+    // // 改成多线程
+    // for (String identityNumber : identityKeys) {
+    // List<ExamRecordEntity> recordList = getExamRecordList(examId, courseCode,
+    // identityNumber);
+    // // 学生的考试记录(一个学生可能有多次考试)
+    // List<ExamRecordEntity> examRecords =
+    // getExamRecordListByIdentityNumber(identityNumber,
+    // recordList);
+    // if (examRecords == null || examRecords.isEmpty()) {
+    // logErr(identityNumber, "找不到身份证号为:" + identityNumber + "的考试记录数据",
+    // failList);
+    // continue;
+    // }
+    // for (ExamRecordEntity examRecord : examRecords) {
+    // // 考试记录id
+    // Long examRecordDataId = examRecord.getExamRecordDataId();
+    // // 学生id
+    // Long studnetId = examRecord.getStudentId();
+    // // 如果没有找到考试记录id
+    // try {
+    // String newAnswer = "";
+    // // 第一步,上传又拍云(多个文件的话,一个个追加)
+    // // 当前学生的文件集合
+    // List<Map<String, Object>> fileByIdnetityNumberList = identityMap
+    // .get(identityNumber);
+    // for (Map<String, Object> m : fileByIdnetityNumberList) {
+    // this.counter.next();
+    // UpyunPathEnvironmentInfo env = new UpyunPathEnvironmentInfo();
+    // env.setUserId(studnetId.toString());
+    // env.setExt1(examRecordDataId.toString());
+    // env.setExt2(order.toString());
+    // env.setFileSuffix(getFileSuffix(fixAnswerType));
+    //
+    // String tempFilePath = m.get("filePath").toString();
+    // String fullFilePath = tempFilePath;
+    // System.out.println("正在上传文件:" + fullFilePath);
+    // UpYunPathInfo upYunPathInfo = upyunService.writeFile(
+    // getSiteId(fixAnswerType), env, new File(fullFilePath), true);
+    // // 上传U盘云的完整地址
+    // String upYunFileUrl = upYunPathInfo.getUrl();
+    //
+    // newAnswer += buildFileAnswer(fixAnswerType, upYunFileUrl) + ",";
+    // }
+    // if (newAnswer.indexOf(",") > -1) {
+    // newAnswer = newAnswer.substring(0, newAnswer.lastIndexOf(","));
+    // }
+    // // 第二步,更新答案
+    // long res = updateAnswer(examRecordDataId, order, newAnswer);
+    // if (res < 1) {
+    // logErr(identityNumber, "更新答案失败", failList);
+    // System.out.println("[Fail]:身份证号:" + identityNumber + ",考试记录id:"
+    // + examRecordDataId + ",答案更新失败");
+    // } else {
+    // System.out.println("[Success]:身份证号:" + identityNumber + ",考试记录id:"
+    // + examRecordDataId + ",答案更新成功");
+    // }
+    // } catch (Exception e) {
+    // logErr(identityNumber, e.getMessage(), failList);
+    // continue;
+    // }
+    // }
+    // }
+    // }
+    //
+    // private String getFileSuffix(FixAnswerType fixAnswerType) {
+    // if (fixAnswerType == FixAnswerType.PICTURE) {
+    // return ".jpg";
+    // } else {
+    // return ".mp3";
+    // }
+    // }
+    //
+    // public List<ExamRecordEntity> getExamRecordList(Long examId, String
+    // courseCode,
+    // String identityNumber) {
+    // String strSql = "select erd.id as examRecordDataId,er.exam_id as examId,
+    // "
+    // + "er.identity_number as identityNumber,c.`code` as
+    // courseCode,er.student_id as studentId "
+    // + "from ec_oe_exam_record er "
+    // + "inner join ec_oe_exam_record_data erd on er.id=erd.exam_record_id "
+    // + "inner join ec_b_course c on er.course_id=c.id " + "where er.exam_id="
+    // + examId
+    // + " and c.`code`='" + courseCode + "'" + " and er.identity_number='"
+    // + identityNumber + "'";
+    //
+    // java.util.List<Map<String, Object>> mapList =
+    // jdbcTemplate.queryForList(strSql);
+    // java.util.List<ExamRecordEntity> resultList = new
+    // ArrayList<ExamRecordEntity>();
+    // for (Map<String, Object> map : mapList) {
+    // ExamRecordEntity entity = new ExamRecordEntity();
+    // if (map.get("courseCode") != null) {
+    // entity.setCourseCode(map.get("courseCode").toString());
+    // }
+    // if (map.get("examId") != null) {
+    // entity.setExamId(Long.parseLong(map.get("examId").toString()));
+    // }
+    // if (map.get("examRecordDataId") != null) {
+    // entity.setExamRecordDataId(Long.parseLong(map.get("examRecordDataId").toString()));
+    // }
+    // if (map.get("identityNumber") != null) {
+    // entity.setIdentityNumber(map.get("identityNumber").toString());
+    // }
+    // if (map.get("studentId") != null) {
+    // entity.setStudentId(Long.parseLong(map.get("studentId").toString()));
+    // }
+    // resultList.add(entity);
+    // }
+    // return resultList;
+    // }
+    //
+    // // 根据身份证号获取考试记录id(同一个学生可能有多次考试)
+    // private List<ExamRecordEntity> getExamRecordListByIdentityNumber(String
+    // identityNumber,
+    // List<ExamRecordEntity> examRecordList) {
+    // List<ExamRecordEntity> resultList = examRecordList.stream()
+    // .filter(record -> record.getIdentityNumber().equals(identityNumber))
+    // .collect(Collectors.toList());
+    // return resultList;
+    // }
+    //
+    // private String getSiteId(FixAnswerType fixAnswerType) {
+    // if (fixAnswerType == FixAnswerType.PICTURE) {
+    // return "photoAnswer";
+    // } else {
+    // return "audioAnswer";
+    // }
+    // }
+    //
+    // /**
+    // * 更新指定试题的答案
+    // *
+    // * @param examRecordDataId
+    // * @param order
+    // * @param newAnswer
+    // * @return
+    // */
+    // public long updateAnswer(Long examRecordDataId, Integer order, String
+    // newAnswer) {
+    // // 查询相应的题目
+    // Query query =
+    // Query.query(Criteria.where("examRecordDataId").is(examRecordDataId)
+    // .and("examQuestionEntities.order").is(order));
+    // Update update = Update.update("examQuestionEntities.$.studentAnswer",
+    // newAnswer);
+    // UpdateResult upResult = mongoTemplate.updateFirst(query, update,
+    // "examRecordQuestions");
+    // return upResult.getMatchedCount();
+    // }
+    //
+    // /**
+    // * 构建文件格式
+    // *
+    // * @param fileUrl
+    // * @return
+    // */
+    // private String buildFileAnswer(FixAnswerType fixAnswerType, String
+    // fileUrl) {
+    // if (fixAnswerType == FixAnswerType.PICTURE) {
+    // StringBuilder sb = new StringBuilder();
+    //
+    // sb.append("<div class='photo-answers-block'>");
+    // sb.append("<a href='" + fileUrl + "' target='_blank' >");
+    // sb.append("<img class='photo-answer' src='" + fileUrl + "!/both/200x200'
+    // />");
+    // sb.append("</a>");
+    // sb.append("</div>");
+    // return sb.toString();
+    // } else {
+    // return fileUrl;
+    // }
+    // }
+    //
+    // private void logErr(String identityNumber, String errMsg,
+    // List<Map<String, Object>> failList) {
+    // Map<String, Object> errMap = new HashMap<>();
+    // errMap.put("identityNumber", identityNumber);
+    // errMap.put("err", errMsg);
+    // failList.add(errMap);
+    // }
 }