|
|
@@ -0,0 +1,65 @@
|
|
|
+package com.seec.bok.service;
|
|
|
+
|
|
|
+import com.seec.bok.back.entity.InteractiveCollect;
|
|
|
+import com.seec.bok.back.entity.InteractiveRate;
|
|
|
+import com.seec.bok.back.repository.InteractiveCollectRepository;
|
|
|
+import com.seec.bok.back.repository.InteractiveRateRepository;
|
|
|
+import com.seec.bok.back.utils.InteractiveMultiKeys;
|
|
|
+import com.seec.bok.web.vo.QuestionVO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class InteractiveService {
|
|
|
+ @Autowired
|
|
|
+ private InteractiveCollectRepository collectRepository;
|
|
|
+ @Autowired
|
|
|
+ private InteractiveRateRepository rateRepository;
|
|
|
+ @Autowired
|
|
|
+ private QuestionService questionService;
|
|
|
+ public InteractiveRate addRate(String userId,String questionId,Integer rate){
|
|
|
+ InteractiveRate ir=new InteractiveRate();
|
|
|
+ ir.setQuestionId(questionId);
|
|
|
+ ir.setRate(rate);
|
|
|
+ ir.setUserId(userId);
|
|
|
+ final InteractiveRate save = rateRepository.save(ir);
|
|
|
+ return save;
|
|
|
+ }
|
|
|
+ public InteractiveCollect addCollect(String userId,String questionId,boolean collect){
|
|
|
+ InteractiveCollect ic=new InteractiveCollect();
|
|
|
+ ic.setQuestionId(questionId);
|
|
|
+ ic.setCollection(collect);
|
|
|
+ ic.setUserId(userId);
|
|
|
+ final InteractiveCollect save = collectRepository.save(ic);
|
|
|
+ return save;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<QuestionVO> findInteractiveQuestions(String userId, Boolean collection, Boolean rate) {
|
|
|
+ List<String> questionIdList=new ArrayList<>();
|
|
|
+ if(collection){
|
|
|
+ final List<InteractiveCollect> allByUserId = collectRepository.findAllByUserId(userId);
|
|
|
+ allByUserId.forEach(i->{
|
|
|
+ if(i.getCollection()!=null&&i.getCollection()){
|
|
|
+ questionIdList.add(i.getQuestionId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(rate){
|
|
|
+ final List<InteractiveRate> allByUserId = rateRepository.findAllByUserId(userId);
|
|
|
+ allByUserId.forEach(i->{
|
|
|
+ questionIdList.add(i.getQuestionId());
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ return questionService.findAllByIdIn(questionIdList)
|
|
|
+ .stream()
|
|
|
+ .map(QuestionVO::of)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+}
|