|
@@ -1,8 +1,7 @@
|
|
package cn.com.qmth.dp.examcloud.oe.modules.fill_course_id;
|
|
package cn.com.qmth.dp.examcloud.oe.modules.fill_course_id;
|
|
|
|
|
|
-import java.util.Date;
|
|
|
|
-import java.util.List;
|
|
|
|
-
|
|
|
|
|
|
+import cn.com.qmth.dp.examcloud.oe.entity.question.PaperStruct;
|
|
|
|
+import com.mongodb.client.result.UpdateResult;
|
|
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;
|
|
@@ -13,47 +12,54 @@ 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 com.mongodb.client.result.UpdateResult;
|
|
|
|
-
|
|
|
|
-import cn.com.qmth.dp.examcloud.oe.entity.question.PaperStruct;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
-/**题库试卷结构写入课程ID
|
|
|
|
- * @author chenken
|
|
|
|
|
|
+/**
|
|
|
|
+ * 题库试卷结构写入课程ID
|
|
*
|
|
*
|
|
|
|
+ * @author chenken
|
|
*/
|
|
*/
|
|
@Service
|
|
@Service
|
|
public class FillCourseIdService {
|
|
public class FillCourseIdService {
|
|
- @Autowired
|
|
|
|
- MongoTemplate mongoTemplate;
|
|
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ MongoTemplate mongoTemplate;
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private JdbcTemplate jdbcTemplate;
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
- public void start() {
|
|
|
|
- Date start = new Date();
|
|
|
|
- int cc=0;
|
|
|
|
- //查找试卷
|
|
|
|
- List<PaperStruct> ps = mongoTemplate.findAll(PaperStruct.class);
|
|
|
|
- if (ps != null && ps.size() > 0) {
|
|
|
|
- System.out.println("total:" + ps.size());
|
|
|
|
- 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);
|
|
|
|
- cc++;
|
|
|
|
- }
|
|
|
|
- index++;
|
|
|
|
- System.out.println("paper_index:" + index);
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- System.out.println("total:" + 0);
|
|
|
|
- }
|
|
|
|
- Date end = new Date();
|
|
|
|
- System.out.println("dispose total:" + cc);
|
|
|
|
- System.out.println("*****************end:" + ((end.getTime() - start.getTime()) / (1000 * 60)) + "分钟");
|
|
|
|
- }
|
|
|
|
|
|
+ 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());
|
|
|
|
+
|
|
|
|
+ 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++;
|
|
|
|
+ }
|
|
|
|
|
|
- public long updatePaperStruct(String id,Long courseId) {
|
|
|
|
|
|
+ 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");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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)));
|
|
Query query = Query.query(Criteria.where("_id").is(new ObjectId(id)));
|
|
Update update = new Update();
|
|
Update update = new Update();
|
|
@@ -63,9 +69,10 @@ public class FillCourseIdService {
|
|
|
|
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private Long queryCourseId(Long rootOrgId, String courseCode) {
|
|
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);
|
|
|
|
|
|
+ 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);
|
|
return jdbcTemplate.queryForObject(querySql, Long.class);
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|