From 50ea2fc814d1e2c1e50872c5b9cec05ceb80285c Mon Sep 17 00:00:00 2001 From: xins Date: Wed, 30 Aug 2023 11:28:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8B=A5=E4=BE=9D=E5=BE=AE=E6=9C=8D=E5=8A=A11.?= =?UTF-8?q?05=E7=89=88=E6=9C=AC=EF=BC=8Ctdengine=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=AE=8C=E5=96=84=201=E3=80=81=E5=A2=9E=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E4=BF=AE=E6=94=B9tag=E5=80=BC=E7=9A=84=E6=96=B9=E6=B3=95=202?= =?UTF-8?q?=E3=80=81=E5=9C=A8=E8=8E=B7=E5=8F=96=E5=8E=86=E5=8F=B2=E6=97=B6?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86order=20by=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E9=98=B2=E6=B3=A8=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/tdengine/api/domain/AlterTagVo.java | 34 ++++++++++++ .../api/domain/TdHistorySelectDto.java | 2 +- .../controller/HwSceneController.java | 4 +- .../controller/TdEngineController.java | 52 +++++++++++++++---- .../ruoyi/tdengine/mapper/TdEngineMapper.java | 23 +++++--- .../tdengine/service/ITdEngineService.java | 10 ++++ .../service/impl/TdEngineServiceImpl.java | 25 ++++++--- .../mapper/tdengine/TdEngineMapper.xml | 19 +++++-- 8 files changed, 141 insertions(+), 28 deletions(-) create mode 100644 ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/domain/AlterTagVo.java 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 @@ + +