package cn.com.qmth.examcloud.core.questions.service.initQuesHash;

import cn.com.qmth.examcloud.core.questions.base.CommonUtils;
import cn.com.qmth.examcloud.core.questions.dao.entity.Question;
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 java.util.List;

/**
 * @author weiwenhai
 * @date 2018.7.17
 * @company qmth
 * @describle InitQuesHashServiceImpl
 */
@Service("initQuesHashService")
public class InitQuesHashServiceImpl implements InitQuesHashService {

    @Autowired
    private MongoTemplate mongoTemplate;

    @SuppressWarnings("unused")
    @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。
            }
        }
    }

}
