|
@@ -0,0 +1,94 @@
|
|
|
|
+package cn.com.qmth.dp.examcloud.oe.modules.fix_paper_score;
|
|
|
|
+
|
|
|
|
+import cn.com.qmth.dp.examcloud.oe.modules.fix_paper_score.vo.ExamRecordDataVO;
|
|
|
|
+import cn.com.qmth.dp.examcloud.oe.modules.update_question_score.entity.DefaultPaperBean;
|
|
|
|
+import cn.com.qmth.dp.examcloud.oe.modules.update_question_score.entity.DefaultQuestionGroupBean;
|
|
|
|
+import cn.com.qmth.dp.examcloud.oe.modules.update_question_score.entity.ExamRecordPaperStructBean;
|
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
|
+import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
|
+import org.springframework.data.mongodb.core.query.Query;
|
|
|
|
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
+
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+@Component
|
|
|
|
+public class FixPaperScore {
|
|
|
|
+
|
|
|
|
+ private final static Logger log = LoggerFactory.getLogger(FixPaperScore.class);
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private JdbcTemplate jdbcTemplate;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private MongoTemplate mongoTemplate;
|
|
|
|
+
|
|
|
|
+ private int curTotal = 0, noPaperStructCount = 0;
|
|
|
|
+
|
|
|
|
+ public void start() {
|
|
|
|
+ StringBuilder querySql = new StringBuilder()
|
|
|
|
+ .append(" select id,paper_struct_id,paper_score")
|
|
|
|
+ .append(" from ec_oe_exam_record_data ")
|
|
|
|
+ .append(" where id > %s ")
|
|
|
|
+ .append(" order by id asc limit 0,1000");
|
|
|
|
+
|
|
|
|
+ Long nextId = 0L;
|
|
|
|
+ while (true) {
|
|
|
|
+ log.info("nextId:{} curTotal:{} noPaperStructCount:{}", nextId, curTotal, noPaperStructCount);
|
|
|
|
+ List<ExamRecordDataVO> list = jdbcTemplate.query(String.format(querySql.toString(), nextId), new BeanPropertyRowMapper(ExamRecordDataVO.class));
|
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ nextId = list.get(list.size() - 1).getId();
|
|
|
|
+ curTotal += list.size();
|
|
|
|
+
|
|
|
|
+ this.fix(list);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ log.info("finished! nextId:{} curTotal:{} noPaperStructCount:{}", nextId, curTotal, noPaperStructCount);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void fix(List<ExamRecordDataVO> list) {
|
|
|
|
+ for (ExamRecordDataVO vo : list) {
|
|
|
|
+ if (StringUtils.isEmpty(vo.getPaperStructId()) || vo.getPaperScore() > 0) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Query query = new Query();
|
|
|
|
+ query.addCriteria(Criteria.where("_id").is(vo.getPaperStructId()));
|
|
|
|
+ ExamRecordPaperStructBean paperStruct = mongoTemplate.findOne(query, ExamRecordPaperStructBean.class, "examRecordPaperStruct");
|
|
|
|
+ if (paperStruct == null) {
|
|
|
|
+ log.warn("paperStruct is not exist! examRecordDataId:{} paperStructId:{}", vo.getId(), vo.getPaperStructId());
|
|
|
|
+ noPaperStructCount++;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ vo.setPaperScore(this.parsePaperScore(paperStruct.getDefaultPaper()));
|
|
|
|
+ log.info("examRecordDataId:{} paperScore:{}", vo.getId(), vo.getPaperScore());
|
|
|
|
+ this.updatePaperScore(vo.getId(), vo.getPaperScore());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private double parsePaperScore(DefaultPaperBean defaultPaper) {
|
|
|
|
+ double paperScore = 0d;
|
|
|
|
+ if (CollectionUtils.isNotEmpty(defaultPaper.getQuestionGroupList())) {
|
|
|
|
+ for (DefaultQuestionGroupBean group : defaultPaper.getQuestionGroupList()) {
|
|
|
|
+ paperScore += group.getGroupScore();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return paperScore;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private int updatePaperScore(Long examRecordDataId, Double paperScore) {
|
|
|
|
+ String sql = String.format("update ec_oe_exam_record_data set paper_score = %s where id = %s", paperScore, examRecordDataId);
|
|
|
|
+ return jdbcTemplate.update(sql);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|