|
|
@@ -0,0 +1,76 @@
|
|
|
+package com.seec.bok.service;
|
|
|
+
|
|
|
+import com.seec.bok.back.entity.Record;
|
|
|
+import com.seec.bok.back.repository.RecordRepository;
|
|
|
+import com.seec.bok.web.dto.RecordDTO;
|
|
|
+import com.seec.bok.web.vo.RecordVO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.data.domain.ExampleMatcher;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.persistence.criteria.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
+import java.util.stream.StreamSupport;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class RecordService {
|
|
|
+ @Autowired
|
|
|
+ private RecordRepository recordRepository;
|
|
|
+
|
|
|
+
|
|
|
+ public Record save(RecordDTO dto) {
|
|
|
+ return recordRepository.save(dto.toEntity());
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Record> saveAll(Iterable<RecordDTO> iterable) {
|
|
|
+ final List<Record> collect = StreamSupport
|
|
|
+ .stream(iterable.spliterator(), true)
|
|
|
+ .map(RecordDTO::toEntity)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return recordRepository.saveAll(collect);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Record> findRecordByUidAndQidAndRidIn(List<String> userIdList, List<String> questionIdList, List<String> recordIdList) {
|
|
|
+
|
|
|
+ if(isEmpty(userIdList)&&isEmpty(questionIdList)&&isEmpty(recordIdList)){
|
|
|
+ return recordRepository.findAll();
|
|
|
+ }else{
|
|
|
+ Specification<Record> spec = new Specification<Record>() {
|
|
|
+ @Override
|
|
|
+ public Predicate toPredicate(Root<Record> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
|
|
|
+ List<Predicate> predicateList =new ArrayList<>();
|
|
|
+ if(!isEmpty(userIdList)){
|
|
|
+ Path<Object> userId = root.get("userId");
|
|
|
+ Predicate p = userId.in(userIdList);
|
|
|
+ predicateList.add(p);
|
|
|
+ }
|
|
|
+ if(!isEmpty(questionIdList)){
|
|
|
+ Path<Object> questionId = root.get("questionId");
|
|
|
+ Predicate p = questionId.in(questionIdList);
|
|
|
+ predicateList.add(p);
|
|
|
+ }
|
|
|
+ if(!isEmpty(recordIdList)){
|
|
|
+ Path<Object> id = root.get("id");//客户名
|
|
|
+ Predicate p = id.in(recordIdList);
|
|
|
+ predicateList.add(p);
|
|
|
+ }
|
|
|
+ final Predicate[] predicates = predicateList.toArray(new Predicate[0]);
|
|
|
+ Predicate and = cb.and(predicates);
|
|
|
+ return and;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ List<Record> all = recordRepository.findAll(spec);
|
|
|
+ return all;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ private boolean isEmpty(List list){
|
|
|
+ return list==null||list.size()==0;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|