Search in sources :

Example 1 with FieldsVo

use of com.mqttsnet.thinglinks.tdengine.api.domain.FieldsVo in project thinglinks by mqttsnet.

the class TdEngineController method addColumnForSuperTable.

/**
 * 添加列字段
 * @param superTableDto
 * @return
 */
@PostMapping("/addColumnInStb")
public R addColumnForSuperTable(@RequestBody SuperTableDto superTableDto) {
    String superTableName = superTableDto.getSuperTableName();
    if (StringUtils.isBlank(superTableName)) {
        return R.fail("invalid operation: superTableName can not be empty");
    }
    Fields fields = superTableDto.getFields();
    if (fields == null) {
        return R.fail("invalid operation: fields can not be empty");
    }
    try {
        FieldsVo fieldsVo = FieldsVo.fieldsTranscoding(fields);
        this.tdEngineService.addColumnForSuperTable(superTableName, fieldsVo);
        log.info("successful operation: add column for 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) 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)

Example 2 with FieldsVo

use of com.mqttsnet.thinglinks.tdengine.api.domain.FieldsVo 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

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