|
@@ -0,0 +1,167 @@
|
|
|
+package cn.com.qmth.dp.examcloud.oe.modules.debug;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
+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.stereotype.Service;
|
|
|
+
|
|
|
+import cn.com.qmth.dp.examcloud.oe.util.BatchSetDataUtil;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class FixService {
|
|
|
+ private static String[] sucStr=new String[] {"对","正确","√","是","True"};
|
|
|
+ private static String[] errStr=new String[] {"错","错误","×","不正确","否","False"};
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ MongoTemplate mongoTemplate;
|
|
|
+
|
|
|
+ public void start() throws IOException {
|
|
|
+ int pageSize=10000;
|
|
|
+ int curPage=0;
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("orgId").is("17351"));
|
|
|
+ query.addCriteria(Criteria.where("questionType").is("BOOL_ANSWER_QUESTION"));
|
|
|
+ query.addCriteria(Criteria.where("fromId").exists(true));
|
|
|
+ query.limit(pageSize);
|
|
|
+ List<QuestionFromIdVo> ps=new ArrayList<>();
|
|
|
+ for(;;) {
|
|
|
+ query.skip(curPage * pageSize);
|
|
|
+ List<QuestionFromIdVo> tem = mongoTemplate.find(query, QuestionFromIdVo.class, "question");
|
|
|
+ if(CollectionUtils.isEmpty(tem)) {
|
|
|
+ break;
|
|
|
+ }else {
|
|
|
+ ps.addAll(tem);
|
|
|
+// break;
|
|
|
+ System.out.println("*****page:"+(curPage+1));
|
|
|
+ }
|
|
|
+ curPage++;
|
|
|
+ }
|
|
|
+ Map<String,String> ans=readAnwser();
|
|
|
+ List<String> lines=new ArrayList<>();
|
|
|
+ for(QuestionFromIdVo p:ps) {
|
|
|
+ lines.add(p.getId()+","+ans.get(p.getFromId()));
|
|
|
+ }
|
|
|
+ File file=new File("d:/sql_info.txt");
|
|
|
+ if(file.exists()) {
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
+ file.createNewFile();
|
|
|
+ FileUtils.writeLines(file, StandardCharsets.UTF_8.name(), lines, true);
|
|
|
+ System.out.println("*****成功结束");
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Map<String,String> readAnwser() throws IOException {
|
|
|
+ Map<String,String> map = new HashMap<>();
|
|
|
+ File file=new File("d:/answer.txt");
|
|
|
+ List<String> ret=FileUtils.readLines(file, "utf-8");
|
|
|
+ for(String s:ret) {
|
|
|
+ String[] ss=s.split(",");
|
|
|
+ map.put(ss[0], ss[1]);
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ public static void main(String[] args) throws Exception {
|
|
|
+// parseAnswer();
|
|
|
+ creatSql();
|
|
|
+ }
|
|
|
+ public static void creatSql() throws Exception {
|
|
|
+ File file=new File("d:/sql_info.txt");
|
|
|
+ List<String> ret=FileUtils.readLines(file, "utf-8");
|
|
|
+ List<String> errIds=new ArrayList<>();
|
|
|
+ List<String> sucIds=new ArrayList<>();
|
|
|
+ for(String s:ret) {
|
|
|
+ String[] ss=s.split(",");
|
|
|
+ if(ss[1].equals("正确")) {
|
|
|
+ sucIds.add(ss[0]);
|
|
|
+ }else {
|
|
|
+ errIds.add(ss[0]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> lines=new ArrayList<>();
|
|
|
+ new BatchSetDataUtil<String>() {
|
|
|
+ @Override
|
|
|
+ protected void setData(List<String> dataList) {
|
|
|
+ StringBuilder sb=new StringBuilder();
|
|
|
+ int index=0;
|
|
|
+ for(String s:dataList) {
|
|
|
+ index++;
|
|
|
+ if(index!=dataList.size()) {
|
|
|
+ sb.append("ObjectId('"+s+"'),");
|
|
|
+ }else {
|
|
|
+ sb.append("ObjectId('"+s+"')");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ lines.add("db.getCollection('question').update({'_id':{$in:["+sb+"]}},{$set:{'quesAnswer':'正确'}},{multi:true});");
|
|
|
+ }
|
|
|
+ }.setDataForBatch(sucIds, 20000);
|
|
|
+ new BatchSetDataUtil<String>() {
|
|
|
+ @Override
|
|
|
+ protected void setData(List<String> dataList) {
|
|
|
+ StringBuilder sb=new StringBuilder();
|
|
|
+ int index=0;
|
|
|
+ for(String s:dataList) {
|
|
|
+ index++;
|
|
|
+ if(index!=dataList.size()) {
|
|
|
+ sb.append("ObjectId('"+s+"'),");
|
|
|
+ }else {
|
|
|
+ sb.append("ObjectId('"+s+"')");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ lines.add("db.getCollection('question').update({'_id':{$in:["+sb+"]}},{$set:{'quesAnswer':'错误'}},{multi:true});");
|
|
|
+ }
|
|
|
+ }.setDataForBatch(errIds, 20000);
|
|
|
+ File bfile=new File("d:/batch_sql.txt");
|
|
|
+ if(bfile.exists()) {
|
|
|
+ bfile.delete();
|
|
|
+ }
|
|
|
+ bfile.createNewFile();
|
|
|
+ FileUtils.writeLines(bfile, StandardCharsets.UTF_8.name(), lines, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void parseAnswer() throws IOException {
|
|
|
+ Map<String,String> ans=readAnwser();
|
|
|
+ List<String> lines=new ArrayList<>();
|
|
|
+ for(String k:ans.keySet()) {
|
|
|
+ lines.add(k+","+getBool(ans.get(k)));
|
|
|
+ }
|
|
|
+ File file=new File("d:/answer.txt");
|
|
|
+ if(file.exists()) {
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
+ file.createNewFile();
|
|
|
+ FileUtils.writeLines(file, StandardCharsets.UTF_8.name(), lines, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String getBool(String val) {
|
|
|
+ String valid="错答案:正确";
|
|
|
+ if(val.contains(valid)) {
|
|
|
+ return "正确";
|
|
|
+ }
|
|
|
+ for(String suc:sucStr) {
|
|
|
+ if(val.contains(suc)) {
|
|
|
+ return "正确";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(String err:errStr) {
|
|
|
+ if(val.contains(err)) {
|
|
|
+ return "错误";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "正确";
|
|
|
+ }
|
|
|
+}
|