|
|
@@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -19,30 +20,30 @@ public class QuestionServiceImpl implements QuestionService {
|
|
|
|
|
|
@Autowired
|
|
|
private QuestionDao questionDao;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 查找常见问题
|
|
|
*/
|
|
|
@Override
|
|
|
public Page<Question> findCommonQuestion(Long hot, boolean isAuthed, final PageInfo pageInfo) {
|
|
|
- if(isAuthed){ //已登录
|
|
|
+ if (isAuthed) { // 已登录
|
|
|
return questionDao.findCommonQuestion(hot, pageInfo);
|
|
|
- }else{ //未登录
|
|
|
+ } else { // 未登录
|
|
|
return questionDao.findCommonAndPublic(hot, pageInfo);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 分类查找问题
|
|
|
*/
|
|
|
@Override
|
|
|
public Page<Question> findByClassId(Long classId, boolean isAuthed, final PageInfo pageInfo) {
|
|
|
- if(isAuthed){ //已登录
|
|
|
+ if (isAuthed) { // 已登录
|
|
|
return questionDao.findByClassId(classId, pageInfo);
|
|
|
- }else{ //未登录
|
|
|
+ } else { // 未登录
|
|
|
return questionDao.findByClassIdAndIsPublic(classId, (long) 1, pageInfo);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -55,20 +56,21 @@ public class QuestionServiceImpl implements QuestionService {
|
|
|
return questions.get(0);
|
|
|
return null;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 更新问题的热度值
|
|
|
+ *
|
|
|
* @param questionId
|
|
|
*/
|
|
|
@Override
|
|
|
public void updateHot(Long questionId) {
|
|
|
List<Question> questions = questionDao.findQuestion(questionId);
|
|
|
- if(questions.size() > 0){
|
|
|
- questions.get(0).setHot(questions.get(0).getHot()+1);
|
|
|
+ if (CollectionUtils.isNotEmpty(questions)) {
|
|
|
+ questions.get(0).setHot((questions.get(0).getHot() == null) ? 1L : (questions.get(0).getHot() + 1));
|
|
|
questionDao.save(questions.get(0));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 搜索问题(未分词)
|
|
|
*/
|
|
|
@@ -76,8 +78,8 @@ public class QuestionServiceImpl implements QuestionService {
|
|
|
public List<Question> search(String question, Double similarity) {
|
|
|
List<Question> questions = questionDao.findAll();
|
|
|
List<Question> result = new ArrayList<Question>();
|
|
|
- for(int i = 0; i < questions.size(); i++){
|
|
|
- if(CosineSimilarityAlgorithm.getSimilarity(question, questions.get(i).getTitle()) > similarity){
|
|
|
+ for (int i = 0; i < questions.size(); i++) {
|
|
|
+ if (CosineSimilarityAlgorithm.getSimilarity(question, questions.get(i).getTitle()) > similarity) {
|
|
|
result.add(questions.get(i));
|
|
|
}
|
|
|
}
|
|
|
@@ -85,28 +87,28 @@ public class QuestionServiceImpl implements QuestionService {
|
|
|
return result;
|
|
|
return null;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 问题反馈
|
|
|
*/
|
|
|
@Override
|
|
|
- public void feedBackQuestion(Long classId, Long isPublic, String title, Long userUU){
|
|
|
+ public void feedBackQuestion(Long classId, Long isPublic, String title, Long userUU) {
|
|
|
Question question = new Question();
|
|
|
question.setClassId(classId);
|
|
|
question.setIsPublic(isPublic);
|
|
|
question.setTitle(title);
|
|
|
question.setCreateUserUU(userUU);
|
|
|
question.setCreateTime(new Date());
|
|
|
- question.setHot((long) 1); //新问题热度值默认为1
|
|
|
- question.setIsResolved((long) 0); //新问题默认未解决
|
|
|
+ question.setHot((long) 1); // 新问题热度值默认为1
|
|
|
+ question.setIsResolved((long) 0); // 新问题默认未解决
|
|
|
questionDao.save(question);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 查找某用户的反馈问题
|
|
|
*/
|
|
|
@Override
|
|
|
- public Page<Question> findByUserUU(Long userUU, final PageInfo pageInfo){
|
|
|
+ public Page<Question> findByUserUU(Long userUU, final PageInfo pageInfo) {
|
|
|
return questionDao.findByCreateUserUU(userUU, pageInfo);
|
|
|
}
|
|
|
}
|