diff --git a/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/domain/AlterTagVo.java b/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/domain/AlterTagVo.java new file mode 100644 index 0000000..7f63601 --- /dev/null +++ b/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/domain/AlterTagVo.java @@ -0,0 +1,34 @@ +package com.ruoyi.tdengine.api.domain; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +/** + * @Description: 更新子表tag实体类 + * @ClassName: AlterTagVo + * @Author : xins + * @Date :2023-08-30 10:56 + * @Version :1.0 + */ +@Data +public class AlterTagVo { + + //数据库名称 + @NotBlank(message="databaseName cannot be empty") + private String databaseName; + + //子表名称 + @NotBlank(message="tableName cannot be empty") + private String tableName; + + @NotBlank(message="tagName cannot be empty") + private String tagName; + + @NotNull(message="tagValue cannot be empty") + private Object tagValue; + + +} diff --git a/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/domain/TdHistorySelectDto.java b/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/domain/TdHistorySelectDto.java index a712eed..2098d74 100644 --- a/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/domain/TdHistorySelectDto.java +++ b/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/domain/TdHistorySelectDto.java @@ -36,5 +36,5 @@ public class TdHistorySelectDto { private String orderByFieldName; //排序方式 - private String orderByMode; + private String sort; } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwSceneController.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwSceneController.java index d472540..006bc04 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwSceneController.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwSceneController.java @@ -39,7 +39,9 @@ public class HwSceneController extends BaseController @RequestMapping("getLanDemo") public String getLanDemo(HttpServletResponse response) { Locale locale = LocaleContextHolder.getLocale(); - System.out.println(locale.getLanguage()+"---"+locale.getCountry()); + System.out.printf("%s---%s%n", + locale.getLanguage(), + locale.getCountry()); return MessageUtils.getMessage("user.login.username"); } diff --git a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/controller/TdEngineController.java b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/controller/TdEngineController.java index f3832f5..b16b57a 100644 --- a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/controller/TdEngineController.java +++ b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/controller/TdEngineController.java @@ -45,8 +45,8 @@ public class TdEngineController { try { //调用创建数据库方法 this.tdEngineService.createDatabase(databaseName); - log.info("success for create database " + databaseName); - return R.ok(); + log.info("successfully created database " + databaseName); + return R.ok("successfully created database " + databaseName); } catch (UncategorizedSQLException e) { String message = e.getCause().getMessage(); try { @@ -85,8 +85,8 @@ public class TdEngineController { List schemaFieldsVos = TdFieldVo.batchConvertFields(schemaFields); List tagsFieldsVos = TdFieldVo.batchConvertFields(tagsFields); this.tdEngineService.createSuperTable(databaseName, superTableName, firstFieldName, schemaFieldsVos, tagsFieldsVos); - log.info("success for create superTable " + superTableName); - return R.ok("created superTable '" + superTableName + "' success"); + log.info("successfully created superTable " + superTableName); + return R.ok("successfully created superTable " + superTableName); } catch (UncategorizedSQLException e) { String message = e.getCause().getMessage(); try { @@ -116,8 +116,8 @@ public class TdEngineController { String tableName = tdTableVo.getTableName(); List tagsFieldValues = tdTableVo.getTagsFieldValues(); this.tdEngineService.createTable(databaseName, superTableName, tableName, tagsFieldValues); - log.info("success for create table " + tableName); - return R.ok("created table '" + tableName + "' success"); + log.info("successfully created table " + tableName); + return R.ok("successfully created table " + tableName); } catch (Exception e) { String message = e.getCause().getMessage(); try { @@ -146,8 +146,8 @@ public class TdEngineController { try { TdFieldVo addFieldVo = TdFieldVo.convertField(addTdField); this.tdEngineService.addSuperTableColumn(databaseName, superTableName, addFieldVo); - log.info("success for add column for superTable " + superTableName + ""); - return R.ok(); + log.info("successfully added column for superTable " + superTableName); + return R.ok("successfully added column for superTable " + superTableName); } catch (UncategorizedSQLException e) { String message = e.getCause().getMessage(); try { @@ -178,8 +178,40 @@ public class TdEngineController { try { TdFieldVo dropFieldVo = TdFieldVo.convertField(dropField); this.tdEngineService.dropSuperTableColumn(databaseName, superTableName, dropFieldVo); - log.info("successful operation: drop column for superTable '" + superTableName + "' success"); - return R.ok(); + log.info("successfully droped column of superTable " + superTableName); + return R.ok("successfully droped column of superTable " + superTableName); + } 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 (Exception e) { + log.error(e.getMessage()); + return R.fail(e.getMessage()); + } + } + + /** + * @param: alterTagVo + * @description 修改子表tag值 + * @author xins + * @date 2023-08-30 11:17 + * @return R + */ + @PostMapping("/alterTableTag") + public R alterTableTag(@Validated @RequestBody AlterTagVo alterTagVo) { + String databaseName = alterTagVo.getDatabaseName(); + String tableName = alterTagVo.getTableName(); + String tagName = alterTagVo.getTagName(); + Object tagValue = alterTagVo.getTagValue(); + + try { + this.tdEngineService.alterTableTag(databaseName,tableName,tagName,tagValue); + log.info("successfully altered tag "+tagName+" value to "+tagValue+" of tableName"); + return R.ok("successfully altered tag "+tagName+" value to "+tagValue+" of tableName"); } catch (UncategorizedSQLException e) { String message = e.getCause().getMessage(); try { diff --git a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/mapper/TdEngineMapper.java b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/mapper/TdEngineMapper.java index ab04823..05b0a11 100644 --- a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/mapper/TdEngineMapper.java +++ b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/mapper/TdEngineMapper.java @@ -1,9 +1,6 @@ package com.ruoyi.tdengine.mapper; -import com.ruoyi.tdengine.api.domain.TdField; -import com.ruoyi.tdengine.api.domain.TdFieldVo; -import com.ruoyi.tdengine.api.domain.TdHistorySelectDto; -import com.ruoyi.tdengine.api.domain.TdSelectDto; +import com.ruoyi.tdengine.api.domain.*; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -83,6 +80,22 @@ public interface TdEngineMapper { @Param("dropFieldsVo") TdFieldVo dropFieldsVo); + /** + * @param: databaseName + * @param: tableName + * @param: tagName + * @param: tagValue + * @description 修改子表的tagValue + * @author xins + * @date 2023-08-30 11:02 + */ + void alterTableTag(@Param("databaseName") String databaseName, + @Param("tableName") String tableName, + @Param("tagName") String tagName, + @Param("tagValue") Object tagValue + ); + + /** * @param: databaseName * @param: tableName @@ -128,8 +141,6 @@ public interface TdEngineMapper { Map getCountOfHistoryData(TdHistorySelectDto tdHistorySelectDto); - - // /** // * 检查表是否存在 // * @param dataBaseName diff --git a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/ITdEngineService.java b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/ITdEngineService.java index c25c29e..867b6e8 100644 --- a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/ITdEngineService.java +++ b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/ITdEngineService.java @@ -69,6 +69,16 @@ public interface ITdEngineService { */ public void dropSuperTableColumn(String databaseName,String superTableName, TdFieldVo dropFieldsVo) throws Exception; + /** + * @param: databaseName + * @param: tableName + * @param: tagName + * @param: tagValue + * @description 修改子表的tagValue + * @author xins + * @date 2023-08-30 11:03 + */ + public void alterTableTag(String databaseName,String tableName,String tagName,Object tagValue); /** * @param: databaseName * @param: tableName diff --git a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/impl/TdEngineServiceImpl.java b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/impl/TdEngineServiceImpl.java index 3b4ebbe..8f0875c 100644 --- a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/impl/TdEngineServiceImpl.java +++ b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/impl/TdEngineServiceImpl.java @@ -104,6 +104,19 @@ public class TdEngineServiceImpl implements ITdEngineService { this.tdEngineMapper.dropSuperTableColumn(databaseName, superTableName, dropFieldsVo); } + /** + * @param: databaseName + * @param: tableName + * @param: tagName + * @param: tagValue + * @description 修改子表的tagValue + * @author xins + * @date 2023-08-30 11:03 + */ + @Override + public void alterTableTag(String databaseName,String tableName,String tagName,Object tagValue){ + this.tdEngineMapper.alterTableTag(databaseName,tableName,tagName,tagValue); + } /** * @param: databaseName @@ -182,12 +195,12 @@ public class TdEngineServiceImpl implements ITdEngineService { */ @Override public List> getHistoryData(TdHistorySelectDto tdHistorySelectDto) { - if (StringUtils.isBlank(tdHistorySelectDto.getOrderByFieldName())) { - tdHistorySelectDto.setOrderByFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME); - } - if (StringUtils.isBlank(tdHistorySelectDto.getOrderByMode())) { - tdHistorySelectDto.setOrderByMode(TdEngineConstants.DEFAULT_ORDER_BY_MODE); - } +// if (StringUtils.isBlank(tdHistorySelectDto.getOrderByFieldName())) { +// tdHistorySelectDto.setOrderByFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME); +// } +// if (StringUtils.isBlank(tdHistorySelectDto.getOrderByMode())) { +// tdHistorySelectDto.setOrderByMode(TdEngineConstants.DEFAULT_ORDER_BY_MODE); +// } List> historyDataMaps = this.tdEngineMapper.getHistoryData(tdHistorySelectDto); return historyDataMaps; diff --git a/ruoyi-modules/hw-tdengine/src/main/resources/mapper/tdengine/TdEngineMapper.xml b/ruoyi-modules/hw-tdengine/src/main/resources/mapper/tdengine/TdEngineMapper.xml index 1b1570c..0db8c2f 100644 --- a/ruoyi-modules/hw-tdengine/src/main/resources/mapper/tdengine/TdEngineMapper.xml +++ b/ruoyi-modules/hw-tdengine/src/main/resources/mapper/tdengine/TdEngineMapper.xml @@ -173,6 +173,10 @@ + + ALTER TABLE #{databaseName}.#{tableName} SET TAG #{tagName}=#{tagValue}; + + @@ -212,10 +216,15 @@ - order by ${orderByFieldName} - - ${orderByMode} - + + + + order by ${orderByFieldName} ${sort} + + + + + LIMIT #{offset},#{limit} @@ -235,6 +244,8 @@ + +