|
|
@@ -2,13 +2,19 @@ package com.seec.bok.service;
|
|
|
|
|
|
import com.seec.bok.back.entity.InteractiveCollect;
|
|
|
import com.seec.bok.back.entity.InteractiveRate;
|
|
|
+import com.seec.bok.back.entity.Record;
|
|
|
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.dto.PageDTO;
|
|
|
+import com.seec.bok.web.util.GuavaCacheUtil;
|
|
|
+import com.seec.bok.web.vo.InteractionVO;
|
|
|
import com.seec.bok.web.vo.InteractiveVO;
|
|
|
import com.seec.bok.web.vo.PageableQuestionListVO;
|
|
|
import com.seec.bok.web.vo.QuestionVO;
|
|
|
+import com.seec.bok.web.vo.constant.EventType;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -24,6 +30,10 @@ public class InteractiveService {
|
|
|
private InteractiveRateRepository rateRepository;
|
|
|
@Autowired
|
|
|
private QuestionService questionService;
|
|
|
+ @Autowired
|
|
|
+ private GuavaCacheUtil cacheUtils;
|
|
|
+ @Autowired
|
|
|
+ private RecordService recordService;
|
|
|
public InteractiveRate addRate(String userId,String questionId,Integer rate){
|
|
|
InteractiveRate ir=new InteractiveRate();
|
|
|
ir.setQuestionId(questionId);
|
|
|
@@ -90,4 +100,76 @@ public class InteractiveService {
|
|
|
interactiveRateList.forEach(i->{qid2InteractiveVOS.get(i.getQuestionId()).setRate(i.getRate());});
|
|
|
return new ArrayList<>(qid2InteractiveVOS.values());
|
|
|
}
|
|
|
+
|
|
|
+ public List<InteractionVO> getAllInteraction(String knowledgeId) {
|
|
|
+ final List<String> idList = fromKnowledgeIdGetQuestionIds(knowledgeId);
|
|
|
+
|
|
|
+ final List<Record> recordList = recordService.findRecordByUidAndQidAndRidIn(null, idList, null, PageDTO.of(null)).getContent();
|
|
|
+ final List<InteractiveCollect> collectList = collectRepository.findAllByQuestionIdIn(idList);
|
|
|
+ final List<InteractiveRate> rateList = rateRepository.findAllByQuestionIdIn(idList);
|
|
|
+
|
|
|
+ checkList(recordList);
|
|
|
+ checkList(collectList);
|
|
|
+ checkList(rateList);
|
|
|
+
|
|
|
+ List<InteractionVO> list=new ArrayList<>(recordList.size()+collectList.size()+rateList.size());
|
|
|
+
|
|
|
+ for(Record r:recordList){
|
|
|
+ EventType type;
|
|
|
+ if(r.getPass()==null|| !r.getPass()){
|
|
|
+ type=EventType.NOT_PASS;
|
|
|
+ }else{
|
|
|
+ type=EventType.PASS;
|
|
|
+ }
|
|
|
+ String id=r.getUserId()+type+r.getQuestionId();
|
|
|
+ InteractionVO vo=new InteractionVO(id,type,r.getUserId(),r.getQuestionId());
|
|
|
+ list.add(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ for(InteractiveCollect ic:collectList){
|
|
|
+ EventType type;
|
|
|
+ if(ic.getCollection()!=null&&ic.getCollection()){
|
|
|
+ type=EventType.COLLECT;
|
|
|
+ }else {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String id=ic.getUserId()+type+ic.getQuestionId();
|
|
|
+ InteractionVO vo=new InteractionVO(id,type,ic.getUserId(),ic.getQuestionId());
|
|
|
+ list.add(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ for(InteractiveRate rate:rateList){
|
|
|
+ EventType type;
|
|
|
+ if(rate.getRate()!=null){
|
|
|
+ type=EventType.RATE;
|
|
|
+ }else {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String id=rate.getUserId()+type+rate.getQuestionId();
|
|
|
+ InteractionVO vo=new InteractionVO(id,type,rate.getUserId(),rate.getQuestionId());
|
|
|
+ list.add(vo);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ private static String CACHE_NAME="Kid2QidS";
|
|
|
+ private List<String> fromKnowledgeIdGetQuestionIds(String knowledgeId){
|
|
|
+
|
|
|
+ final Object ret = (List<String>) cacheUtils.get(CACHE_NAME, knowledgeId);
|
|
|
+ if(ret==null){
|
|
|
+ Pageable pageable =PageDTO.of(null);
|
|
|
+ final PageableQuestionListVO search = questionService.search(null, null, knowledgeId, pageable);
|
|
|
+ final List<String> idList = search.getQuestions().stream().map(QuestionVO::getId).collect(Collectors.toList());
|
|
|
+ cacheUtils.set(CACHE_NAME,knowledgeId,idList);
|
|
|
+ return idList;
|
|
|
+ }else{
|
|
|
+ return (List<String>) ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ private boolean isEmpty(List list){
|
|
|
+ return list==null||list.size()==0;
|
|
|
+ }
|
|
|
+ private void checkList(List list){
|
|
|
+ if(isEmpty(list)){list=new ArrayList<>();}
|
|
|
+ }
|
|
|
}
|