|
@@ -1,7 +1,9 @@
|
|
package cn.com.qmth.dp.examcloud.oe.modules.fill_course_id;
|
|
package cn.com.qmth.dp.examcloud.oe.modules.fill_course_id;
|
|
|
|
|
|
-import cn.com.qmth.dp.examcloud.oe.entity.question.PaperStruct;
|
|
|
|
-import com.mongodb.client.result.UpdateResult;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.bson.types.ObjectId;
|
|
import org.bson.types.ObjectId;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -12,8 +14,9 @@ import org.springframework.data.mongodb.core.query.Update;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.Date;
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import com.mongodb.client.result.UpdateResult;
|
|
|
|
+
|
|
|
|
+import cn.com.qmth.dp.examcloud.oe.entity.question.PaperStruct;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 题库试卷结构写入课程ID
|
|
* 题库试卷结构写入课程ID
|
|
@@ -23,56 +26,64 @@ import java.util.List;
|
|
@Service
|
|
@Service
|
|
public class FillCourseIdService {
|
|
public class FillCourseIdService {
|
|
|
|
|
|
- @Autowired
|
|
|
|
- MongoTemplate mongoTemplate;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private JdbcTemplate jdbcTemplate;
|
|
|
|
-
|
|
|
|
- public void start() {
|
|
|
|
- Date start = new Date();
|
|
|
|
- int updateCount = 0;
|
|
|
|
-
|
|
|
|
- //查找试卷
|
|
|
|
- List<PaperStruct> ps = mongoTemplate.findAll(PaperStruct.class);
|
|
|
|
- if (ps != null && ps.size() > 0) {
|
|
|
|
- System.out.println("总条数:" + ps.size());
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ MongoTemplate mongoTemplate;
|
|
|
|
|
|
- int index = 0;
|
|
|
|
- for (PaperStruct paper : ps) {
|
|
|
|
- if (paper.getCourseId() == null && StringUtils.isNotBlank(paper.getCourseNo())) {
|
|
|
|
- Long courseId = queryCourseId(Long.valueOf(paper.getOrgId()), paper.getCourseNo());
|
|
|
|
- updatePaperStruct(paper.getId(), courseId);
|
|
|
|
- updateCount++;
|
|
|
|
- }
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
- index++;
|
|
|
|
- System.out.println(String.format("%s--> id:%s, rootOrgId:%s, courseCode:%s, courseId:%s",
|
|
|
|
- index, paper.getId(), paper.getOrgId(), paper.getCourseNo(), paper.getCourseId()));
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- System.out.println("总条数:0");
|
|
|
|
- }
|
|
|
|
|
|
+ public void start() {
|
|
|
|
+ int pageSize = 200;
|
|
|
|
+ int curPage = 1;
|
|
|
|
+ Date start = new Date();
|
|
|
|
+ int updateCount = 0;
|
|
|
|
+ Query query = new Query();
|
|
|
|
+ long count = this.mongoTemplate.count(query, PaperStruct.class);
|
|
|
|
+ query.limit(pageSize);
|
|
|
|
+ System.out.println("总条数:" + count);
|
|
|
|
+ int index = 0;
|
|
|
|
+ for (;;) {
|
|
|
|
+ query.skip((curPage - 1L) * pageSize);
|
|
|
|
+ List<PaperStruct> ps = mongoTemplate.find(query, PaperStruct.class);
|
|
|
|
+ curPage++;
|
|
|
|
+ if (CollectionUtils.isEmpty(ps)) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ for (PaperStruct paper : ps) {
|
|
|
|
+ index++;
|
|
|
|
+ if (paper.getCourseId() == null && StringUtils.isNotBlank(paper.getCourseNo())) {
|
|
|
|
+ Long courseId = queryCourseId(Long.valueOf(paper.getOrgId()), paper.getCourseNo());
|
|
|
|
+ updatePaperStruct(paper.getId(), courseId);
|
|
|
|
+ updateCount++;
|
|
|
|
+ System.out.println(String.format("处理:%s--> id:%s, rootOrgId:%s, courseCode:%s, courseId:%s", index,
|
|
|
|
+ paper.getId(), paper.getOrgId(), paper.getCourseNo(), paper.getCourseId()));
|
|
|
|
+ }else {
|
|
|
|
+ System.out.println(String.format("无需处理:%s--> id:%s, rootOrgId:%s, courseCode:%s, courseId:%s", index,
|
|
|
|
+ paper.getId(), paper.getOrgId(), paper.getCourseNo(), paper.getCourseId()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- Date end = new Date();
|
|
|
|
- System.out.println("实际修改条数:" + updateCount);
|
|
|
|
- System.out.println("耗时:" + ((end.getTime() - start.getTime()) / (1000 * 60)) + "分钟");
|
|
|
|
- }
|
|
|
|
|
|
+ Date end = new Date();
|
|
|
|
+ System.out.println("实际修改条数:" + updateCount);
|
|
|
|
+ System.out.println("耗时:" + ((end.getTime() - start.getTime()) / (1000 * 60)) + "分钟");
|
|
|
|
+ }
|
|
|
|
|
|
- public long updatePaperStruct(String id, Long courseId) {
|
|
|
|
- // 查询相应的题目
|
|
|
|
- Query query = Query.query(Criteria.where("_id").is(new ObjectId(id)));
|
|
|
|
- Update update = new Update();
|
|
|
|
- update.set("courseId", courseId);
|
|
|
|
- UpdateResult upResult = mongoTemplate.updateFirst(query, update, "paperStruct");
|
|
|
|
- long res = upResult.getMatchedCount();
|
|
|
|
|
|
+ public long updatePaperStruct(String id, Long courseId) {
|
|
|
|
+ // 查询相应的题目
|
|
|
|
+ Query query = Query.query(Criteria.where("_id").is(new ObjectId(id)));
|
|
|
|
+ Update update = new Update();
|
|
|
|
+ update.set("courseId", courseId);
|
|
|
|
+ UpdateResult upResult = mongoTemplate.updateFirst(query, update, "paperStruct");
|
|
|
|
+ long res = upResult.getMatchedCount();
|
|
|
|
|
|
- return res;
|
|
|
|
- }
|
|
|
|
|
|
+ return res;
|
|
|
|
+ }
|
|
|
|
|
|
- private Long queryCourseId(Long rootOrgId, String courseCode) {
|
|
|
|
- final String querySql = String.format("select id from ec_b_course where root_org_id = %s and code = '%s' ", rootOrgId, courseCode);
|
|
|
|
- return jdbcTemplate.queryForObject(querySql, Long.class);
|
|
|
|
- }
|
|
|
|
|
|
+ private Long queryCourseId(Long rootOrgId, String courseCode) {
|
|
|
|
+ final String querySql = String.format("select id from ec_b_course where root_org_id = %s and code = '%s' ",
|
|
|
|
+ rootOrgId, courseCode);
|
|
|
|
+ return jdbcTemplate.queryForObject(querySql, Long.class);
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|