|
|
@@ -138,6 +138,18 @@ public class MongoStartup {
|
|
|
return mongodbIndexEntity;
|
|
|
}
|
|
|
|
|
|
+ public MongodbIndexEntity IotDeviceGeoLocationGeoCreateIndex() {
|
|
|
+ log.info("开始创建IotXphGssqdata索引");
|
|
|
+ List<String[]> indexNameList = new ArrayList<>();
|
|
|
+ indexNameList.add(new String[]{"devGeoLocation"});
|
|
|
+
|
|
|
+ MongodbIndexEntity mongodbIndexEntity = new MongodbIndexEntity();
|
|
|
+ mongodbIndexEntity.setIotBaseEntity(IotDeviceGeoLocation.class);
|
|
|
+ mongodbIndexEntity.setIndexNameList(indexNameList);
|
|
|
+
|
|
|
+ return mongodbIndexEntity;
|
|
|
+ }
|
|
|
+
|
|
|
@PostConstruct
|
|
|
public void start() {
|
|
|
log.info("开始创建mongodb索引");
|
|
|
@@ -156,12 +168,22 @@ public class MongoStartup {
|
|
|
Class<?> entity = mongodbIndexEntity.getIotBaseEntity();
|
|
|
|
|
|
List<IndexModel> indexModelList = new ArrayList<>();
|
|
|
+ List<IndexModel> geoIndexModelList = new ArrayList<>();
|
|
|
indexNameList.forEach((String[] indexNames) -> {
|
|
|
BasicDBObject basicDBObject = new BasicDBObject();
|
|
|
Arrays.stream(indexNames).forEach(indexName -> basicDBObject.put(indexName, 1));
|
|
|
- indexModelList.add(new IndexModel(basicDBObject, indexOptions));
|
|
|
+ if(methodName.endsWith("GeoCreateIndex")){
|
|
|
+ geoIndexModelList.add(new IndexModel(basicDBObject, indexOptions));
|
|
|
+ }else{
|
|
|
+ indexModelList.add(new IndexModel(basicDBObject, indexOptions));
|
|
|
+ }
|
|
|
});
|
|
|
- mongoService.createIndexes(entity, indexModelList);
|
|
|
+ if(!indexModelList.isEmpty()){
|
|
|
+ mongoService.createIndexes(entity, indexModelList);
|
|
|
+ }
|
|
|
+ if(!geoIndexModelList.isEmpty()){
|
|
|
+ mongoService.createGeoIndexes(entity, geoIndexModelList);
|
|
|
+ }
|
|
|
|
|
|
}catch (Exception e) {
|
|
|
log.error("创建{}索引失败:{}", method.getName(), e.getMessage());
|