package com.qianwen.mdc.collect.service;
|
|
import java.util.List;
|
|
import org.apache.iotdb.rpc.IoTDBConnectionException;
|
import org.apache.iotdb.rpc.StatementExecutionException;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import com.qianwen.mdc.collect.config.IotDBSessionConfig;
|
|
|
/**
|
* iotdb通用服务
|
*/
|
@Service
|
public class IotDBCommonService {
|
private static final Logger logger = LoggerFactory.getLogger(IotDBCommonService.class);
|
|
@Autowired
|
private IotDBSessionConfig iotdbCfg;
|
|
/**
|
* 模板是否挂载到指定路径了
|
* @param template 模板名称
|
* @param path 设备路径
|
* @return
|
*/
|
public boolean isTemplateSetOnPath(String template,String path) {
|
List<String> pathlist;
|
try {
|
pathlist = iotdbCfg.getSessionPool().showPathsTemplateSetOn(template);
|
//logger.info("pathlist"+pathlist);
|
return pathlist.contains(path);
|
} catch (StatementExecutionException|IoTDBConnectionException e) {
|
logger.error("获取模板使用错误",e);
|
}
|
|
return false;
|
}
|
|
/**
|
* 如果deviceId指定的路径没有挂载模板则执行挂载
|
* @param template 模板名称
|
* @param deviceId 设备路径
|
*/
|
public void setTemmplateIfNotSet(String template,String deviceId) {
|
if(!isTemplateSetOnPath(template, deviceId)) {
|
try {
|
iotdbCfg.getSessionPool().setSchemaTemplate(template, deviceId);
|
} catch (Exception e) {
|
logger.error("为deviceId设置模板错误,template="+template+",deviceId="+deviceId,e);
|
}
|
}
|
}
|
}
|