|
@@ -1,93 +1,92 @@
|
|
|
-package com.bizmatics.service.es.impl;
|
|
|
-
|
|
|
-import com.bizmatics.model.Device;
|
|
|
-import com.bizmatics.model.es.RtAnalog;
|
|
|
-import com.bizmatics.persistence.mapper.DeviceMapper;
|
|
|
-import com.bizmatics.persistence.mapper.es.ElasticRepository;
|
|
|
-import com.bizmatics.service.es.RtAnalogService;
|
|
|
-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.data.elasticsearch.core.ElasticsearchRestTemplate;
|
|
|
-import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
|
|
-import org.springframework.data.elasticsearch.core.query.SearchQuery;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import java.util.Date;
|
|
|
-import java.util.Iterator;
|
|
|
-import java.util.List;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
|
|
|
-import static org.elasticsearch.index.query.QueryBuilders.termsQuery;
|
|
|
-
|
|
|
-/**
|
|
|
- * @author yq
|
|
|
- * @date 2021/7/17 19:18
|
|
|
- */
|
|
|
-@Service
|
|
|
-public class RtAnalogServiceImpl implements RtAnalogService {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ElasticsearchRestTemplate elasticsearchTemplate;
|
|
|
- @Autowired
|
|
|
- private ElasticRepository elasticRepository;
|
|
|
- @Autowired
|
|
|
- private DeviceMapper deviceMapper;
|
|
|
-
|
|
|
- private Pageable pageable = PageRequest.of(0,10);
|
|
|
-
|
|
|
- @Override
|
|
|
- public void createIndex() {
|
|
|
- elasticsearchTemplate.createIndex(RtAnalog.class);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void deleteIndex(String index) {
|
|
|
- elasticsearchTemplate.deleteIndex(index);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void save(RtAnalog docBean) {
|
|
|
- elasticRepository.save(docBean);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void saveAll(List<RtAnalog> list) {
|
|
|
- elasticRepository.saveAll(list);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Iterator<RtAnalog> findAll() {
|
|
|
- return elasticRepository.findAll().iterator();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<RtAnalog> list(Date startTime,Date endTime,Integer userId) {
|
|
|
- List<Device> list = deviceMapper.list(userId, null, null, null, null, null);
|
|
|
- System.out.println(list.size());
|
|
|
- List<String> deviceCodes = list.stream().map(Device::getDeviceCode).collect(Collectors.toList());
|
|
|
- SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
|
|
- .withQuery(boolQuery()
|
|
|
- .must(termsQuery("deviceName", deviceCodes))
|
|
|
- ).build();
|
|
|
- List<RtAnalog> rtAnalogs = elasticsearchTemplate.queryForList(searchQuery, RtAnalog.class);
|
|
|
- System.out.println(rtAnalogs.size());
|
|
|
- return rtAnalogs;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<RtAnalog> page() {
|
|
|
- //构建查询
|
|
|
- SearchQuery query = new NativeSearchQueryBuilder()
|
|
|
- .withPageable(pageable)
|
|
|
- .build();
|
|
|
- Page<RtAnalog> searchResponse = elasticRepository.search(query);
|
|
|
- System.out.println(searchResponse.getTotalPages());
|
|
|
- return searchResponse.getContent();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
+//package com.bizmatics.service.es.impl;
|
|
|
+//
|
|
|
+//import com.bizmatics.model.Device;
|
|
|
+//import com.bizmatics.model.es.RtAnalog;
|
|
|
+//import com.bizmatics.persistence.mapper.DeviceMapper;
|
|
|
+//import com.bizmatics.persistence.mapper.es.ElasticRepository;
|
|
|
+//import com.bizmatics.service.es.RtAnalogService;
|
|
|
+//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.data.elasticsearch.core.ElasticsearchRestTemplate;
|
|
|
+//import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
|
|
+//import org.springframework.data.elasticsearch.core.query.SearchQuery;
|
|
|
+//
|
|
|
+//import java.util.Date;
|
|
|
+//import java.util.Iterator;
|
|
|
+//import java.util.List;
|
|
|
+//import java.util.stream.Collectors;
|
|
|
+//
|
|
|
+//import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
|
|
|
+//import static org.elasticsearch.index.query.QueryBuilders.termsQuery;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * @author yq
|
|
|
+// * @date 2021/7/17 19:18
|
|
|
+// */
|
|
|
+////@Service
|
|
|
+//public class RtAnalogServiceImpl implements RtAnalogService {
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private ElasticsearchRestTemplate elasticsearchTemplate;
|
|
|
+// @Autowired
|
|
|
+// private ElasticRepository elasticRepository;
|
|
|
+// @Autowired
|
|
|
+// private DeviceMapper deviceMapper;
|
|
|
+//
|
|
|
+// private Pageable pageable = PageRequest.of(0,10);
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void createIndex() {
|
|
|
+// elasticsearchTemplate.createIndex(RtAnalog.class);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void deleteIndex(String index) {
|
|
|
+// elasticsearchTemplate.deleteIndex(index);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void save(RtAnalog docBean) {
|
|
|
+// elasticRepository.save(docBean);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void saveAll(List<RtAnalog> list) {
|
|
|
+// elasticRepository.saveAll(list);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public Iterator<RtAnalog> findAll() {
|
|
|
+// return elasticRepository.findAll().iterator();
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public List<RtAnalog> list(Date startTime,Date endTime,Integer userId) {
|
|
|
+// List<Device> list = deviceMapper.list(userId, null, null, null, null, null);
|
|
|
+// System.out.println(list.size());
|
|
|
+// List<String> deviceCodes = list.stream().map(Device::getDeviceCode).collect(Collectors.toList());
|
|
|
+// SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
|
|
+// .withQuery(boolQuery()
|
|
|
+// .must(termsQuery("deviceName", deviceCodes))
|
|
|
+// ).build();
|
|
|
+// List<RtAnalog> rtAnalogs = elasticsearchTemplate.queryForList(searchQuery, RtAnalog.class);
|
|
|
+// System.out.println(rtAnalogs.size());
|
|
|
+// return rtAnalogs;
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public List<RtAnalog> page() {
|
|
|
+// //构建查询
|
|
|
+// SearchQuery query = new NativeSearchQueryBuilder()
|
|
|
+// .withPageable(pageable)
|
|
|
+// .build();
|
|
|
+// Page<RtAnalog> searchResponse = elasticRepository.search(query);
|
|
|
+// System.out.println(searchResponse.getTotalPages());
|
|
|
+// return searchResponse.getContent();
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+//}
|