提交 0fff3487 编写于 作者: xiaonannet's avatar xiaonannet

优化

上级 5977328e
......@@ -12,7 +12,7 @@ ribbon:
# feign 配置
feign:
hystrix:
hystrix:
enabled: true
sentinel:
enabled: true
......
......@@ -71,15 +71,15 @@ seata:
config:
type: nacos
nacos:
serverAddr: 49.235.122.136:8848
serverAddr: 127.0.0.1:8848
group: SEATA_GROUP
namespace: 8ea40c2e-64ba-4430-9bd8-a25336b2b45a
namespace: 1e1aff6c-da73-43e2-9e5f-8e0b890189d9
registry:
type: nacos
nacos:
application: seata-server
server-addr: 49.235.122.136:8848
namespace: 8ea40c2e-64ba-4430-9bd8-a25336b2b45a
server-addr: 127.0.0.1:8848
namespace: 1e1aff6c-da73-43e2-9e5f-8e0b890189d9
#smqtt官方配置文件V1.1.2
smqtt:
......@@ -143,10 +143,10 @@ smqtt:
chain: # 规则链(支持多个)
- ruleType: ROCKET_MQ # 过滤器类型
script: '{"topic":"${topic}","msg":${msg},"qos":${qos}}'
# - ruleName: KAFKA # 过滤器名称
# chain: # 规则链(支持多个)
# - ruleType: KAFKA # 过滤器类型
# script: '{"topic":"${topic}","msg":${msg},"qos":${qos}}'
- ruleName: KAFKA # 过滤器名称
chain: # 规则链(支持多个)
- ruleType: KAFKA # 过滤器类型
script: '{"topic":"${topic}","msg":${msg},"qos":${qos}}'
# - ruleName: HTTP # 过滤器名称
# chain: # 规则链(支持多个)
# - ruleType: HTTP
......@@ -172,13 +172,13 @@ smqtt:
namesrvAddr: 127.0.0.1:9876
instanceName: wt9zfxnoukxsrngp-0721852
producerGroup: thinglinks
# - source: KAFKA # kafka配置
# sourceName: kafka
# sourceAttributes:
# topic: thinglinks
# bootstrap-servers: 127.0.0.1:9092
# key-serializer: org.apache.kafka.common.serialization.StringSerializer
# value-serializer: org.apache.kafka.common.serialization.StringSerializer
- source: KAFKA # kafka配置
sourceName: kafka
sourceAttributes:
topic: thinglinks
bootstrap-servers: 127.0.0.1:9092
key-serializer: org.apache.kafka.common.serialization.StringSerializer
value-serializer: org.apache.kafka.common.serialization.StringSerializer
# - source: HTTP
# sourceName: http
# sourceAttributes:
......
......@@ -44,7 +44,14 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/wgcloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: wgcloud
password: wgcloud
password: ATP5j3KXP8s62FPN
# 从库数据源
# slave:
# username:
# password:
# url:
# driver-class-name:
# seata: true # 开启seata代理,开启后默认每个数据源都代理,如果某个不需要代理可单独关闭
# mybatis配置
mybatis:
......@@ -53,6 +60,33 @@ mybatis:
# 配置mapper的扫描,找到所有的mapper.xml映射文件
mapperLocations: classpath:mapper/**/*.xml
# seata配置
seata:
enabled: true
# Seata 应用编号,默认为 ${spring.application.name}
application-id: thinglinks-collection
# Seata 事务组编号,用于 TC 集群名
tx-service-group: thinglinks-collection-group
# 关闭自动代理
enable-auto-data-source-proxy: false
# 服务配置项
service:
# 虚拟组和分组的映射
vgroup-mapping:
thinglinks-collection-group: default
config:
type: nacos
nacos:
serverAddr: 127.0.0.1:8848
group: SEATA_GROUP
namespace:
registry:
type: nacos
nacos:
application: seata-server
server-addr: 127.0.0.1:8848
namespace:
rocketmq:
# 系统
systemTopic: thinglinks_collection_system
......
......@@ -23,8 +23,8 @@ spring:
loginUsername: admin
loginPassword: 123456
dynamic:
# 开启seata代理
seata: true
# 开启seata代理,开启后默认每个数据源都代理,如果某个不需要代理可单独关闭
seata: false
druid:
initial-size: 5
min-idle: 5
......@@ -41,19 +41,18 @@ spring:
filters: stat,slf4j
connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
datasource:
# 主库数据源
master:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/thinglinks?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: thinglinks
password: NAhtGR8ByPpymakG
# 从库数据源
# slave:
# username:
# password:
# url:
# driver-class-name:
# seata: true # 开启seata代理,开启后默认每个数据源都代理,如果某个不需要代理可单独关闭
# 主库数据源
master:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/thinglinks?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: thinglinks
password: NAhtGR8ByPpymakG
# 从库数据源
# slave:
# username:
# password:
# url:
# driver-class-name:
# rocketmq地址
rocketmq:
......@@ -79,7 +78,7 @@ thinglinks:
# seata配置
seata:
enabled: true
enabled: false
# Seata 应用编号,默认为 ${spring.application.name}
application-id: thinglinks-link
# Seata 事务组编号,用于 TC 集群名
......@@ -94,14 +93,14 @@ seata:
config:
type: nacos
nacos:
serverAddr: 49.235.122.136:8848
serverAddr: 127.0.0.1:8848
group: SEATA_GROUP
namespace:
registry:
type: nacos
nacos:
application: seata-server
server-addr: 49.235.122.136:8848
server-addr: 127.0.0.1:8848
namespace:
# mybatis配置
......
# spring
# spring配置
spring:
security:
user:
......@@ -8,3 +8,89 @@ spring:
admin:
ui:
title: thinglinks服务状态监控
redis:
database: 0
host: 127.0.0.1
port: 6379
password: thinglinks
timeout: 30000
jedis:
pool:
# 连接池中的最大空闲连接
max-idle: 20
# 连接池中的最小空闲连接
min-idle: 0
# 连接池最大连接数(使用负值表示没有限制)
max-active: -1
# 连接池最大阻塞等待时间(使用负值表示没有限制)
max-wait: -1
datasource:
druid:
stat-view-servlet:
enabled: true
loginUsername: admin
loginPassword: 123456
dynamic:
druid:
initial-size: 5
min-idle: 5
maxActive: 20
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
filters: stat,slf4j
connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
datasource:
# 主库数据源
master:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/wgcloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: wgcloud
password: ATP5j3KXP8s62FPN
# 从库数据源
# slave:
# username:
# password:
# url:
# driver-class-name:
# seata: true # 开启seata代理,开启后默认每个数据源都代理,如果某个不需要代理可单独关闭
# mybatis配置
mybatis:
# 搜索指定包别名
typeAliasesPackage: com.mqttsnet.thinglinks.monitor
# 配置mapper的扫描,找到所有的mapper.xml映射文件
mapperLocations: classpath:mapper/**/*.xml
# seata配置
seata:
enabled: true
# Seata 应用编号,默认为 ${spring.application.name}
application-id: thinglinks-monitor
# Seata 事务组编号,用于 TC 集群名
tx-service-group: thinglinks-monitor-group
# 关闭自动代理
enable-auto-data-source-proxy: false
# 服务配置项
service:
# 虚拟组和分组的映射
vgroup-mapping:
thinglinks-monitor-group: default
config:
type: nacos
nacos:
serverAddr: 127.0.0.1:8848
group: SEATA_GROUP
namespace:
registry:
type: nacos
nacos:
application: seata-server
server-addr: 127.0.0.1:8848
namespace:
\ No newline at end of file
......@@ -71,14 +71,14 @@ seata:
config:
type: nacos
nacos:
serverAddr: 49.235.122.136:8848
serverAddr: 127.0.0.1:8848
group: SEATA_GROUP
namespace: fffe6c69-d6cb-44fd-b542-8167d8a0c29d
registry:
type: nacos
nacos:
application: seata-server
server-addr: 49.235.122.136:8848
server-addr: 127.0.0.1:8848
namespace: fffe6c69-d6cb-44fd-b542-8167d8a0c29d
# mybatis配置
......
......@@ -15,23 +15,77 @@ spring:
max-active: -1
# 连接池最大阻塞等待时间(使用负值表示没有限制)
max-wait: -1
datasource:
driver-class-name: com.taosdata.jdbc.rs.RestfulDriver
url: jdbc:TAOS-RS://124.223.113.139:6041/thinglinks?timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8
username: root
password: taosdata
druid:
initial-size: 5
min-idle: 5
max-active: 5
max-wait: 30000
validation-query: select server_status();
datasource:
druid:
stat-view-servlet:
enabled: true
loginUsername: admin
loginPassword: 123456
dynamic:
# 开启seata代理,开启后默认每个数据源都代理,如果某个不需要代理可单独关闭
seata: false
druid:
initial-size: 5
min-idle: 5
maxActive: 20
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT SERVER_STATUS();
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
filters: stat,slf4j
connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
datasource:
# 主库数据源
master:
driver-class-name: com.taosdata.jdbc.rs.RestfulDriver
url: jdbc:TAOS-RS://127.0.0.1:6041/${spring.datasource.dynamic.datasource.master.dbName}?user=root&password=taosdata&timezone=GMT%2b8
dbName: thinglinks
username: root
password: taosdata
# 从库数据源
# slave:
# username:
# password:
# url:
# driver-class-name:
aop:
auto: true
proxy-target-class: true
mybatis:
mapper-locations: classpath:mapper/*.xml
# seata配置
seata:
enabled: false
# Seata 应用编号,默认为 ${spring.application.name}
application-id: thinglinks-tdengine
# Seata 事务组编号,用于 TC 集群名
tx-service-group: thinglinks-tdengine-group
# 关闭自动代理
enable-auto-data-source-proxy: false
# 服务配置项
service:
# 虚拟组和分组的映射
vgroup-mapping:
thinglinks-tdengine-group: default
config:
type: nacos
nacos:
serverAddr: 127.0.0.1:8848
group: SEATA_GROUP
namespace:
registry:
type: nacos
nacos:
application: seata-server
server-addr: 127.0.0.1:8848
namespace:
# rocketmq地址
rocketmq:
name-server: 127.0.0.1:9876
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -11,6 +11,10 @@
<artifactId>thinglinks-api-broker</artifactId>
<description>
thinglinks-api-broker Broker模块API
</description>
<dependencies>
<!-- thinglinks Common Core-->
<dependency>
......
......@@ -11,9 +11,8 @@
<artifactId>thinglinks-api-link</artifactId>
<description>
thinglinks-api-link 设备集成Link模块
thinglinks-api-link 设备集成Link模块API
</description>
<dependencies>
......
......@@ -11,6 +11,10 @@
<artifactId>thinglinks-api-monitor</artifactId>
<description>
thinglinks-api-monitor 监控模块API
</description>
<dependencies>
<!-- thinglinks Common Core-->
<dependency>
......
......@@ -12,7 +12,7 @@
<artifactId>thinglinks-api-system</artifactId>
<description>
thinglinks-api-system系统接口模块
thinglinks-api-system系统模块API
</description>
<dependencies>
......
......@@ -11,6 +11,10 @@
<artifactId>thinglinks-api-tdengine</artifactId>
<description>
thinglinks-api-tdengine TDengine模块API
</description>
<dependencies>
<!-- thinglinks Common Core-->
<dependency>
......
......@@ -31,7 +31,7 @@ public interface RemoteTdEngineService {
* @Date 2021/12/31 11:05
*/
@PostMapping("/dataOperation/createDb")
R<?> createDataBase(@RequestParam("dbName") String databaseName);
R<?> createDataBase(@RequestParam("databaseName") String databaseName);
/**
* @param superTableDto 创建超级表需要的入参的实体类
......
package com.mqttsnet.thinglinks.tdengine.api.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.sql.Timestamp;
public class IotSequential extends BaseEntity {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS", timezone = "GMT+8")
private Timestamp statetime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS", timezone = "GMT+8")
private Timestamp endtime;
private String deviceid;
private String eventtime;
private String serviceid;
private String devices;
public String getDeviceid() {
return deviceid;
}
public void setDeviceid(String deviceid) {
this.deviceid = deviceid;
}
public String getEventtime() {
return eventtime;
}
public void setEventtime(String eventtime) {
this.eventtime = eventtime;
}
public String getServiceid() {
return serviceid;
}
public void setServiceid(String serviceid) {
this.serviceid = serviceid;
}
public String getDevices() {
return devices;
}
public void setDevices(String devices) {
this.devices = devices;
}
public Timestamp getStatetime() {
return statetime;
}
public void setStatetime(Timestamp statetime) {
this.statetime = statetime;
}
public Timestamp getEndtime() {
return endtime;
}
public void setEndtime(Timestamp endtime) {
this.endtime = endtime;
}
}
......@@ -24,7 +24,7 @@ public class RemoteTdEngineFallbackFactory implements FallbackFactory<RemoteTdEn
@Override
public RemoteTdEngineService create(Throwable throwable) {
log.error("时序性数据库服务调用失败:{}", throwable.getMessage());
log.error("TDengine服务调用失败:{}", throwable.getMessage());
return new RemoteTdEngineService()
{
......
org.springframework.boot.autoconfigure.EnableAutoConfiguration=
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.mqttsnet.thinglinks.tdengine.api.factory.RemoteTdEngineFallbackFactory
......@@ -5,7 +5,7 @@
<!-- 日志输出格式 -->
<property name="log.pattern" value="%black(thinglinks.mqttsnet.com) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger) - %cyan(%msg%n)" />
<!-- mqtts.net输出 -->
<!-- thinglinks.mqttsnet.com输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
......
......@@ -137,4 +137,9 @@ public class Constants
*/
public static final String RESUBMIT_URL_KEY = "resubmit_url:";
/**
* TDengine superTableFields cache key
*/
public static final String TDENGINE_SUPERTABLEFILELDS = "TDengine_superTableFields:";
}
......@@ -5,7 +5,7 @@
<!-- 日志输出格式 -->
<property name="log.pattern" value="%black(thinglinks.mqttsnet.com) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger) - %cyan(%msg%n)" />
<!-- mqtts.net输出 -->
<!-- thinglinks.mqttsnet.com输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
......
......@@ -5,7 +5,7 @@
<!-- 日志输出格式 -->
<property name="log.pattern" value="%black(thinglinks.mqttsnet.com) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger) - %cyan(%msg%n)" />
<!-- mqtts.net输出 -->
<!-- thinglinks.mqttsnet.com输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
......
......@@ -5,7 +5,7 @@
<!-- 日志输出格式 -->
<property name="log.pattern" value="%black(thinglinks.mqttsnet.com) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger) - %cyan(%msg%n)" />
<!-- mqtts.net输出 -->
<!-- thinglinks.mqttsnet.com输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
......
......@@ -5,7 +5,7 @@
<!-- 日志输出格式 -->
<property name="log.pattern" value="%black(thinglinks.mqttsnet.com) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger) - %cyan(%msg%n)" />
<!-- mqtts.net输出 -->
<!-- thinglinks.mqttsnet.com输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
......
......@@ -5,7 +5,7 @@
<!-- 日志输出格式 -->
<property name="log.pattern" value="%black(thinglinks.mqttsnet.com) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger) - %cyan(%msg%n)" />
<!-- mqtts.net输出 -->
<!-- thinglinks.mqttsnet.com输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
......
......@@ -120,6 +120,13 @@
<version>${thinglinks.version}</version>
</dependency>
<!-- thinglinks Api tdengine -->
<dependency>
<groupId>com.mqttsnet</groupId>
<artifactId>thinglinks-api-tdengine</artifactId>
<version>${thinglinks.version}</version>
</dependency>
</dependencies>
<build>
......
......@@ -111,7 +111,9 @@ public class DeviceDatasServiceImpl implements DeviceDatasService {
log.error("topic:{},报文体为空已忽略处理", topic);
return;
}
if (topic.contains("datas")) {
//边设备上报数据处理
if (topic.startsWith("/v1/devices/") && topic.endsWith("/datas")) {
log.info("边设备上报数据处理,Topic:{},Msg:{}", topic, msg);
}
}
......
......@@ -4,11 +4,15 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.jayway.jsonpath.JsonPath;
import com.mqttsnet.thinglinks.common.core.constant.Constants;
import com.mqttsnet.thinglinks.common.core.domain.R;
import com.mqttsnet.thinglinks.common.core.enums.DataTypeEnum;
import com.mqttsnet.thinglinks.common.core.text.CharsetKit;
import com.mqttsnet.thinglinks.common.core.text.UUID;
import com.mqttsnet.thinglinks.common.core.utils.DateUtils;
import com.mqttsnet.thinglinks.common.core.utils.StringUtils;
import com.mqttsnet.thinglinks.common.core.web.domain.AjaxResult;
import com.mqttsnet.thinglinks.common.redis.service.RedisService;
import com.mqttsnet.thinglinks.common.security.service.TokenService;
import com.mqttsnet.thinglinks.link.api.domain.product.entity.Product;
import com.mqttsnet.thinglinks.link.api.domain.product.entity.ProductProperties;
......@@ -22,11 +26,18 @@ import com.mqttsnet.thinglinks.link.mapper.product.ProductServicesMapper;
import com.mqttsnet.thinglinks.link.service.product.ProductService;
import com.mqttsnet.thinglinks.system.api.domain.SysUser;
import com.mqttsnet.thinglinks.system.api.model.LoginUser;
import com.mqttsnet.thinglinks.tdengine.api.RemoteTdEngineService;
import com.mqttsnet.thinglinks.tdengine.api.domain.Fields;
import com.mqttsnet.thinglinks.tdengine.api.domain.SuperTableDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
......@@ -58,10 +69,11 @@ import static cn.hutool.json.XMLTokener.entity;
*/
@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
@RefreshScope
@Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class ProductServiceImpl implements ProductService{
@Resource
@Autowired
private ProductMapper productMapper;
@Autowired
private TokenService tokenService;
......@@ -69,6 +81,16 @@ public class ProductServiceImpl implements ProductService{
private ProductServicesMapper productServicesMapper;
@Autowired
private ProductPropertiesMapper productPropertiesMapper;
@Resource
private RemoteTdEngineService remoteTdEngineService;
@Autowired
private RedisService redisService;
/**
* 数据库名称
*/
@Value("${spring.datasource.dynamic.datasource.master.dbName:thinglinks}")
private String databaseName;
@Override
public int deleteByPrimaryKey(Long id) {
......@@ -189,7 +211,8 @@ public class ProductServiceImpl implements ProductService{
while ((line = reader.readLine()) != null) {
sb.append(line);
}
return productJsonDataAnalysis(JSONObject.parseObject(sb.toString()),appId,templateId,status);
//解析产品模型数据
return this.productJsonDataAnalysis(JSONObject.parseObject(sb.toString()), appId, templateId, status);
} catch (IOException e) {
e.printStackTrace();
} finally {
......@@ -216,6 +239,7 @@ public class ProductServiceImpl implements ProductService{
* @param status 状态(字典值:启用 停用)
* @return 解析结果
*/
@Transactional(rollbackFor = Exception.class)
public AjaxResult productJsonDataAnalysis(JSONObject content,String appId,String templateId,String status) throws Exception{
LoginUser loginUser = tokenService.getLoginUser();
SysUser sysUser = loginUser.getSysUser();
......@@ -272,7 +296,9 @@ public class ProductServiceImpl implements ProductService{
//服务属性解析处理
Product product = new Product();
product.setAppId(appId);
product.setTemplateId(Long.valueOf(templateId));
if (StringUtils.isNotEmpty(templateId)){
product.setTemplateId(Long.valueOf(templateId));
}
product.setProductName(productName);
product.setProductIdentification(UUID.getUUID());
product.setProductType(String.valueOf(productType));
......@@ -316,8 +342,9 @@ public class ProductServiceImpl implements ProductService{
productProperties.setCreateTime(DateUtils.getNowDate());
final int batchInsert = productPropertiesMapper.insertSelective(productProperties);
}
}
//解析入库成功创建TD超级表及子表
this.createSuperTable(product,services);
}catch (Exception e){
log.error(e.getMessage());
return AjaxResult.error("操作失败");
......@@ -325,6 +352,87 @@ public class ProductServiceImpl implements ProductService{
return AjaxResult.success("操作成功");
}
/**
* 创建TD超级表
* @param product
* @param services
* @return
* @throws Exception
*/
@Transactional(rollbackFor = Exception.class)
public AjaxResult createSuperTable(Product product,JSONArray services) throws Exception{
//构建超级表入参对象
SuperTableDto superTableDto = new SuperTableDto();
try {
loop:
for (int i = 0; i < services.size(); i++) {
JSONObject service = services.getJSONObject(i);
//超级表名称命名规则:产品类型_产品标识_服务名称
String superTableName = product.getProductType()+"_"+product.getProductIdentification()+"_"+service.getString("serviceId");
//设置数据库名称和超级表名称
superTableDto.setDatabaseName(databaseName);
superTableDto.setSuperTableName(superTableName);
//构建超级表的表结构字段列表
JSONArray properties = service.getJSONArray("properties");
//如果服务下属性值为空,没必要为该服务创建超级表,跳过该循环,进入下个服务
if (properties.isEmpty()) {
continue loop;
}
//构建超级表的表结构字段列表
List<Fields> schemaFields = new ArrayList<>();
//超级表第一个字段数据类型必须为时间戳
Fields firstColumn = new Fields();
firstColumn.setFieldName("ts");
firstColumn.setDataType(DataTypeEnum.TIMESTAMP);
schemaFields.add(firstColumn);
//根据属性对象列表循环构建超级表表结构
for (int j = 0; j < properties.size(); j++) {
JSONObject propertie = properties.getJSONObject(j);
//获取字段名称
String filedName = (String) propertie.get("name");
//获取该属性数据类型
String datatype = (String) propertie.get("datatype");
//获取该属性的数据大小
Integer size = (Integer) propertie.get("maxlength");
//添加超级表表结构字段
Fields fields = new Fields(filedName, datatype, size);
schemaFields.add(fields);
}
//构建超级表标签字段列表
//根据业务逻辑,将超级表的标签字段定为
// 1:设备标识:deviceIdentification
List<Fields> tagsFields = new ArrayList<>();
Fields tags = new Fields();
tags.setFieldName("deviceIdentification");
tags.setDataType(DataTypeEnum.BINARY);
tags.setSize(64);
tagsFields.add(tags);
//设置超级表表结构列表
superTableDto.setSchemaFields(schemaFields);
//设置超级表标签字段列表
superTableDto.setTagsFields(tagsFields);
R<?> cstResult = remoteTdEngineService.createSuperTable(superTableDto);
//创建超级表报错,打印报错信息,并跳过该循环,继续为下个服务创建表
if (cstResult.getCode() != 200) {
log.error("Create SuperTable Exception: " + cstResult.getMsg());
continue loop;
}
log.info("Create SuperTable Result: {}",cstResult.getCode());
//将之前存在redis里的同样的名称的超级表的表结构信息删除
if (redisService.hasKey(Constants.TDENGINE_SUPERTABLEFILELDS+superTableName)) {
redisService.deleteObject(Constants.TDENGINE_SUPERTABLEFILELDS+superTableName);
}
//在redis里存入新的超级表对的表结构信息
redisService.setCacheList(Constants.TDENGINE_SUPERTABLEFILELDS+superTableName, schemaFields);
}
}catch (Exception e){
log.error(e.getMessage());
}
return AjaxResult.success("操作成功");
}
/**
* 查询产品管理
*
......
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<!-- 日志存放路径 -->
<property name="log.path" value="logs/thinglinks-system" />
<property name="log.path" value="logs/thinglinks-link" />
<!-- 日志输出格式 -->
<property name="log.pattern" value="%black(thinglinks.mqttsnet.com) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger) - %cyan(%msg%n)" />
<!-- mqtts.net输出 -->
<!-- thinglinks.mqttsnet.com输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
......
......@@ -94,24 +94,6 @@
</dependencies>
<!--<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.5.5</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>-->
<build>
<plugins>
<!--打包jar-->
......
......@@ -5,7 +5,7 @@
<!-- 日志输出格式 -->
<property name="log.pattern" value="%black(thinglinks.mqttsnet.com) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger) - %cyan(%msg%n)" />
<!-- mqtts.net输出 -->
<!-- thinglinks.mqttsnet.com输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
......
......@@ -51,6 +51,12 @@
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- SpringBoot Web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Swagger UI -->
<dependency>
<groupId>io.springfox</groupId>
......@@ -82,7 +88,7 @@
<dependency>
<groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId>
<version>2.0.36</version>
<version>2.0.37</version>
</dependency>
<!-- thinglinks Common Datasource -->
......@@ -115,33 +121,7 @@
</dependencies>
<!--<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.5.5</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>-->
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
<plugins>
<!--打包jar-->
<plugin>
......
## TDengine SpringBoot + Mybatis Demo 超级表设计概念:每个设备一张表,每类设备一个超级表 ;命名规则 : 产品类型_产品标识_服务名称_设备标识
## TDengine SpringBoot + Mybatis Demo
## 超级表设计概念:每个设备一张表,每类设备一个超级表 ;
## 超级表命名规则 : 产品类型_产品标识_服务名称
## 子表命名规则 : 产品类型_产品标识_服务名称_设备标识(非ClientId)
## TDengine 服务端版本及搭建
### 推荐版本 tdengine/tdengine:2.4.0.4
### 搭建教程:https://www.taosdata.com/docs/cn/v2.0/getting-started/docker
### 配置 application.properties
```properties
......
......@@ -3,7 +3,6 @@ package com.mqttsnet.thinglinks.tdengine;
import com.mqttsnet.thinglinks.common.security.annotation.EnableCustomConfig;
import com.mqttsnet.thinglinks.common.security.annotation.EnableRyFeignClients;
import com.mqttsnet.thinglinks.common.swagger.annotation.EnableCustomSwagger2;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.CrossOrigin;
......@@ -16,7 +15,6 @@ import org.springframework.web.bind.annotation.CrossOrigin;
//maxAge飞行前响应的缓存持续时间的最大年龄,简单来说就是Cookie的有效期 单位为秒
//若maxAge是负数,则代表为临时Cookie,不会被持久化,Cookie信息保存在浏览器内存中,浏览器关闭Cookie就消失
@CrossOrigin(origins = "*",maxAge = 3600)
@MapperScan(basePackages = {"com.mqttsnet.thinglinks.tdengine"})
@SpringBootApplication
public class ThingLinksTdengineApplication {
......
package com.mqttsnet.thinglinks.tdengine.controller;
import com.mqttsnet.thinglinks.common.core.web.controller.BaseController;
import com.mqttsnet.thinglinks.common.core.web.domain.AjaxResult;
import com.mqttsnet.thinglinks.common.core.web.page.TableDataInfo;
import com.mqttsnet.thinglinks.tdengine.api.domain.IotSequential;
import com.mqttsnet.thinglinks.tdengine.service.IotSequentialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RequestMapping("/sequential")
@RestController
public class IotSequentialController extends BaseController {
@Autowired
private IotSequentialService iotSequentialService;
/**
* 查询时序列表
* @param iotSequential
* @return
*/
@GetMapping("/getList")
public TableDataInfo getList(@RequestBody IotSequential iotSequential){
startPage();
List<IotSequential> list = iotSequentialService.getList(iotSequential);
return getDataTable(list);
}
/**
* 根据时序时间查询详情
* @param startTime
* @return
*/
@GetMapping("/selectByTime")
public AjaxResult selectByTime(@PathVariable String startTime){
IotSequential iotSequential = iotSequentialService.selectByTime(startTime);
return AjaxResult.success(iotSequential);
}
/**
* 添加
* @param iotSequential
* @return
*/
@PostMapping("/save")
public int save(@RequestBody IotSequential iotSequential){
return iotSequentialService.save(iotSequential);
}
}
......@@ -37,17 +37,17 @@ public class TdEngineController {
private static final Logger log = LoggerFactory.getLogger(TdEngineController.class);
/**
* @param dbName 数据库名称
* @param databaseName 数据库名称
* @return R
* @MethodDescription 创建tdEngine数据库
* @author thinglinks
* @Date 2021/12/27 16:26
*/
@PostMapping("/createDb")
public R createDataBase(@RequestBody() String dbName) {
public R createDataBase(@RequestBody() String databaseName) {
//调用创建数据库方法
this.tdEngineService.createDateBase(dbName);
log.info("successful operation: created database '" + dbName + "' success");
this.tdEngineService.createDateBase(databaseName);
log.info("successful operation: created database '" + databaseName + "' success");
return R.ok();
}
......
package com.mqttsnet.thinglinks.tdengine.mapper;
import com.mqttsnet.thinglinks.tdengine.api.domain.IotSequential;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface IotSequentialMapper {
List<IotSequential> getList(IotSequential iotSequential);
IotSequential selectByTime(String startTime);
int save(IotSequential iotSequential);
}
package com.mqttsnet.thinglinks.tdengine.service;
import com.mqttsnet.thinglinks.tdengine.api.domain.IotSequential;
import com.mqttsnet.thinglinks.tdengine.mapper.IotSequentialMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class IotSequentialService {
@Autowired
private IotSequentialMapper iotSequentialMapper;
public IotSequential selectByTime(String startTime){
return iotSequentialMapper.selectByTime(startTime);
}
public List<IotSequential> getList(IotSequential iotSequential){
return iotSequentialMapper.getList(iotSequential);
}
public int save(IotSequential iotSequential){
return iotSequentialMapper.save(iotSequential);
}
}
......@@ -5,7 +5,7 @@
<!-- 日志输出格式 -->
<property name="log.pattern" value="%black(thinglinks.mqttsnet.com) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger) - %cyan(%msg%n)" />
<!-- mqtts.net输出 -->
<!-- thinglinks.mqttsnet.com输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mqttsnet.thinglinks.tdengine.mapper.IotSequentialMapper">
<resultMap id="map" type="com.mqttsnet.thinglinks.tdengine.api.domain.IotSequential">
<id column="statetime" jdbcType="TIMESTAMP" property="statetime"/>
<result column="endTime" jdbcType="TIMESTAMP" property="endtime"/>
<result column="deviceid" jdbcType="VARCHAR" property="deviceid"/>
<result column="eventtime" jdbcType="VARCHAR" property="eventtime"/>
<result column="serviceid" jdbcType="VARCHAR" property="serviceid"/>
<result column="devices" jdbcType="VARCHAR" property="devices"/>
</resultMap>
<select id="getList" parameterType="com.mqttsnet.thinglinks.tdengine.api.domain.IotSequential" resultMap="map">
select * from sequential
<where>
<if test="statetime != null and sequential != null">
statetime = #{statetime}
</if>
</where>
</select>
<select id="selectByTime" parameterType="String" resultMap="map">
select * from sequential where statetime = #{statetime}
</select>
<insert id="save">
insert into sequential(statetime,endtime,deviceid,eventtime,serviceid,devices) values(statetime = #{statetime},endtime = #{endtime},deviceid = #{deviceid},eventtime = #{eventtime},
serviceid = #{serviceid},devices =#{devices})
</insert>
</mapper>
\ No newline at end of file
......@@ -15,7 +15,41 @@
#{item.fieldName}
</if>
<if test="item.dataType != null || item.dataType != ''">
#{item.dataType}
<choose>
<when test="item.dataType == 'timestamp'">
timestamp
</when>
<when test="item.dataType == 'tinyint'">
tinyint
</when>
<when test="item.dataType == 'smallint'">
smallint
</when>
<when test="item.dataType == 'int'">
int
</when>
<when test="item.dataType == 'bigint'">
bigint
</when>
<when test="item.dataType == 'float'">
float
</when>
<when test="item.dataType == 'double'">
double
</when>
<when test="item.dataType == 'binary'">
binary
</when>
<when test="item.dataType == 'nchar'">
nchar
</when>
<when test="item.dataType == 'bool'">
bool
</when>
<when test="item.dataType == 'json'">
json
</when>
</choose>
</if>
<if test="item.size != null">
(#{item.size})
......@@ -108,8 +142,45 @@
<if test="fieldsVo.fieldName != null || fieldsVo.fieldName != ''">
#{fieldsVo.fieldName}
</if>
<if test="fieldsVo.dataType != null || fieldsVo.dataType != ''">
<!--<if test="fieldsVo.dataType != null || fieldsVo.dataType != ''">
#{fieldsVo.dataType}
</if>-->
<if test="fieldsVo.dataType != null || fieldsVo.dataType != ''">
<choose>
<when test="fieldsVo.dataType == 'timestamp'">
timestamp
</when>
<when test="fieldsVo.dataType == 'tinyint'">
tinyint
</when>
<when test="fieldsVo.dataType == 'smallint'">
smallint
</when>
<when test="fieldsVo.dataType == 'int'">
int
</when>
<when test="fieldsVo.dataType == 'bigint'">
bigint
</when>
<when test="fieldsVo.dataType == 'float'">
float
</when>
<when test="fieldsVo.dataType == 'double'">
double
</when>
<when test="fieldsVo.dataType == 'binary'">
binary
</when>
<when test="fieldsVo.dataType == 'nchar'">
nchar
</when>
<when test="fieldsVo.dataType == 'bool'">
bool
</when>
<when test="fieldsVo.dataType == 'json'">
json
</when>
</choose>
</if>
<if test="fieldsVo.size != null">
(#{fieldsVo.size})
......
......@@ -476,11 +476,11 @@ export default {
// 是否禁用上传
isUploading: false,
// 应用ID
appId: null,
appId: "",
// 产品模型模板
templateId: null,
templateId: "",
// 状态
status: null,
status: "",
// 是否更新已经存在的用户数据
updateSupport: 0,
// 设置上传的请求头部
......
......@@ -11,7 +11,6 @@ spring:
# 环境配置
active: dev
main:
allow-circular-references: true
allow-bean-definition-overriding: true
cloud:
nacos:
......@@ -19,12 +18,12 @@ spring:
# 配置中心地址
server-addr: 127.0.0.1:8848
#命名空间
namespace: 05545134-ed4b-4647-89ff-f83bed4db8f2
namespace: 8ea40c2e-64ba-4430-9bd8-a25336b2b45a
config:
# 配置中心地址
server-addr: 127.0.0.1:8848
#命名空间
namespace: 05545134-ed4b-4647-89ff-f83bed4db8f2
namespace: 8ea40c2e-64ba-4430-9bd8-a25336b2b45a
# 配置文件格式
file-extension: yml
# 共享配置
......@@ -34,4 +33,4 @@ spring:
#自定义配置参数
base:
#本机内网ip,不要用localhost或127.0.0.1
bindIp: 127.0.0.1
\ No newline at end of file
bindIp: 10.75.2.164
\ No newline at end of file
......@@ -5,7 +5,7 @@
<!-- 日志输出格式 -->
<property name="log.pattern" value="%black(thinglinks.mqttsnet.com) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger) - %cyan(%msg%n)" />
<!-- mqtts.net输出 -->
<!-- thinglinks.mqttsnet.com输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
......
......@@ -11,7 +11,6 @@ spring:
# 环境配置
active: dev
main:
allow-circular-references: true
allow-bean-definition-overriding: true
cloud:
nacos:
......
......@@ -5,7 +5,7 @@
<!-- 日志输出格式 -->
<property name="log.pattern" value="%black(thinglinks.mqttsnet.com) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger) - %cyan(%msg%n)" />
<!-- mqtts.net输出 -->
<!-- thinglinks.mqttsnet.com输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册