|
@@ -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);
|
|
|
+ // }
|
|
|
}
|