Search in sources :

Example 1 with DataTypeEnum

use of com.mqttsnet.thinglinks.common.core.enums.DataTypeEnum in project thinglinks by mqttsnet.

the class TdEngineServiceImpl method initSTableFrame.

@Override
public void initSTableFrame(String msg) throws Exception {
    final SuperTableDto superTableDto = JSONObject.toJavaObject(JSONObject.parseObject(msg), SuperTableDto.class);
    // 从入参对象获取列字段(超级表结构)对象集合
    List<Fields> schemaFields = superTableDto.getSchemaFields();
    // 从入参对象获取标签字段对象集合
    List<Fields> tagsFields = superTableDto.getTagsFields();
    // 从入参获取数据库名称
    String dataBaseName = superTableDto.getDataBaseName();
    // 从入参获取超级表名称
    String superTableName = superTableDto.getSuperTableName();
    final boolean tableExists = this.checkTableExists(dataBaseName, superTableName);
    if (tableExists) {
        log.info("超级表{}已存在", superTableName);
        return;
    }
    // 获取列字段对象集合的第一个对象的字段数据类型
    DataTypeEnum dataType = schemaFields.get(0).getDataType();
    // 如果该数据类型不是时间戳,打印和返回报错信息
    if (dataType == null || !"timestamp".equals(dataType.getDataType())) {
        log.error("invalid operation: first column must be timestamp");
        return;
    }
    // 将列字段对象集合和标签字段对象集合转码为字段Vo类对象集合
    List<FieldsVo> schemaFieldsVoList = FieldsVo.fieldsTranscoding(schemaFields);
    List<FieldsVo> tagsFieldsVoList = FieldsVo.fieldsTranscoding(tagsFields);
    // 创建超级表
    this.createSuperTable(schemaFieldsVoList, tagsFieldsVoList, dataBaseName, superTableName);
    log.info("create {} super table success", superTableName);
}
Also used : DataTypeEnum(com.mqttsnet.thinglinks.common.core.enums.DataTypeEnum)

Example 2 with DataTypeEnum

use of com.mqttsnet.thinglinks.common.core.enums.DataTypeEnum in project thinglinks by mqttsnet.

the class TdEngineController method createSuperTable.

/**
 * @param superTableDto 创建超级表需要的入参的实体类
 * @return R
 * @MethodDescription 创建超级表
 * @author thinglinks
 * @Date 2021/12/27 16:26
 */
@PostMapping("/createSTb")
public R createSuperTable(@Validated @RequestBody SuperTableDto superTableDto) {
    // 从入参对象获取列字段(超级表结构)对象集合
    List<Fields> schemaFields = superTableDto.getSchemaFields();
    // 从入参对象获取标签字段对象集合
    List<Fields> tagsFields = superTableDto.getTagsFields();
    // 从入参获取数据库名称
    String dataBaseName = superTableDto.getDataBaseName();
    // 从入参获取超级表名称
    String superTableName = superTableDto.getSuperTableName();
    // 获取列字段对象集合的第一个对象的字段数据类型
    DataTypeEnum dataType = schemaFields.get(0).getDataType();
    // 如果该数据类型不是时间戳,打印和返回报错信息
    if (dataType == null || !"timestamp".equals(dataType.getDataType())) {
        log.error("invalid operation: first column must be timestamp");
        return R.fail("invalid operation: the first column must be timestamp");
    }
    try {
        // 将列字段对象集合和标签字段对象集合转码为字段Vo类对象集合
        List<FieldsVo> schemaFieldsVoList = FieldsVo.fieldsTranscoding(schemaFields);
        List<FieldsVo> tagsFieldsVoList = FieldsVo.fieldsTranscoding(tagsFields);
        // 创建超级表
        this.tdEngineService.createSuperTable(schemaFieldsVoList, tagsFieldsVoList, dataBaseName, superTableName);
        log.info("successful operation: created superTable '" + superTableName + "' success");
        return R.ok();
    } catch (UncategorizedSQLException e) {
        String message = e.getCause().getMessage();
        try {
            message = message.substring(message.lastIndexOf("invalid operation"));
        } catch (Exception ex) {
        }
        log.error(message);
        return R.fail(message);
    } catch (SQLException e) {
        log.error(e.getMessage());
        return R.fail(e.getMessage());
    }
}
Also used : UncategorizedSQLException(org.springframework.jdbc.UncategorizedSQLException) Fields(com.mqttsnet.thinglinks.tdengine.api.domain.Fields) DataTypeEnum(com.mqttsnet.thinglinks.common.core.enums.DataTypeEnum) UncategorizedSQLException(org.springframework.jdbc.UncategorizedSQLException) SQLException(java.sql.SQLException) FieldsVo(com.mqttsnet.thinglinks.tdengine.api.domain.FieldsVo) UncategorizedSQLException(org.springframework.jdbc.UncategorizedSQLException) SQLException(java.sql.SQLException)

Aggregations

DataTypeEnum (com.mqttsnet.thinglinks.common.core.enums.DataTypeEnum)2 Fields (com.mqttsnet.thinglinks.tdengine.api.domain.Fields)1 FieldsVo (com.mqttsnet.thinglinks.tdengine.api.domain.FieldsVo)1 SQLException (java.sql.SQLException)1 UncategorizedSQLException (org.springframework.jdbc.UncategorizedSQLException)1