Jelajahi Sumber

第一步,初始化题干hash,查询某机构下,所有试题,并去除题干中html标签。

weiwenhai 7 tahun lalu
induk
melakukan
1a08b290e4

+ 36 - 0
examcloud-core-questions-api-provider/src/main/java/cn/com/qmth/examcloud/service/core/api/initQuesHash/InitQuesHashController.java

@@ -0,0 +1,36 @@
+package cn.com.qmth.examcloud.service.core.api.initQuesHash;
+
+import io.swagger.annotations.ApiOperation;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
+import cn.com.qmth.examcloud.core.questions.service.initQuesHash.InitQuesHashService;
+
+/**
+ * @author 		weiwenhai
+ * @date 		2018.7.17
+ * @company		qmth
+ * @describle	初始化所有题目题干的Hash
+ */
+
+@RestController
+@RequestMapping("${api_cqb}/")
+public class InitQuesHashController extends ControllerSupport{
+
+	@Autowired
+	private InitQuesHashService initQuesHashService;
+	
+	@ApiOperation(value="根据机构初始化题干hash", notes="根据机构初始化题干hash")
+	@GetMapping(value="/initQuesHash/{orgId}")
+	public ResponseEntity<Object> initQuesHash(@PathVariable String orgId){
+		initQuesHashService.initHash(orgId);
+		return new ResponseEntity<Object>(HttpStatus.OK);
+	}
+}

+ 7 - 0
examcloud-core-questions-base/pom.xml

@@ -89,6 +89,13 @@
 			<artifactId>java-sdk</artifactId>
 			<version>3.16</version>
 		</dependency>
+		<dependency>
+		  	<!-- jsoup HTML parser library @ https://jsoup.org/ -->
+		  	<groupId>org.jsoup</groupId>
+		  	<artifactId>jsoup</artifactId>
+		  	<version>1.11.3</version>
+		</dependency>
+		
 	</dependencies>
 
 </project>

+ 15 - 0
examcloud-core-questions-base/src/main/java/cn/com/qmth/examcloud/core/questions/base/CommonUtils.java

@@ -1,10 +1,12 @@
 package cn.com.qmth.examcloud.core.questions.base;
 
 import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
+
 import org.apache.commons.lang3.StringEscapeUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.text.translate.*;
 import org.dom4j.*;
+import org.jsoup.Jsoup;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -784,5 +786,18 @@ public final class CommonUtils {
             return sb.toString();
         }
     }
+    
+    /**
+     * 去除字符串中所有的html标签
+     * @param html
+     * @return
+     */
+    public static String parseHtml(String html) {
+        if(html==null) {
+            return null;
+        }
+        org.jsoup.nodes.Document document = Jsoup.parse(html);
+        return document.text();
+    }
 
 }

+ 18 - 0
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/initQuesHash/InitQuesHashService.java

@@ -0,0 +1,18 @@
+package cn.com.qmth.examcloud.core.questions.service.initQuesHash;
+
+/**
+ * @author 		weiwenhai
+ * @date 		2018.7.17
+ * @company		qmth
+ * @describle	InitQuesHashService
+ */
+
+public interface InitQuesHashService {
+
+	/**
+	 * 根据orgId初始化所有小题的题干hash
+	 * @param orgId
+	 */
+	public void initHash(String orgId);
+	
+}

+ 39 - 0
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/initQuesHash/InitQuesHashServiceImpl.java

@@ -0,0 +1,39 @@
+package cn.com.qmth.examcloud.core.questions.service.initQuesHash;
+
+import java.util.List;
+
+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 cn.com.qmth.examcloud.core.questions.base.CommonUtils;
+import cn.com.qmth.examcloud.core.questions.dao.entity.Question;
+
+/**
+ * @author 		weiwenhai
+ * @date 		2018.7.17
+ * @company		qmth
+ * @describle	InitQuesHashServiceImpl
+ */
+
+public class InitQuesHashServiceImpl implements InitQuesHashService{
+
+	@Autowired
+    private MongoTemplate mongoTemplate;
+	
+	@Override
+	public void initHash(String orgId) {
+		Query query = new Query();
+		query.addCriteria(Criteria.where("orgId").is(orgId));
+		List<Question> questions = this.mongoTemplate.find(query, Question.class);
+		if(questions != null && questions.size()>0){
+			for(Question question:questions){
+				String bodyHtml = question.getQuesBody();
+				String newBody = CommonUtils.parseHtml(bodyHtml);
+				//newBody转化成bodyHash。
+			}
+		}
+	}
+
+}