Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mqttsnet
thinglinks
提交
27885ecf
thinglinks
项目概览
mqttsnet
/
thinglinks
通知
1
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
thinglinks
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
27885ecf
编写于
10月 13, 2021
作者:
xiaonannet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
新增hutool依赖,td示例保存数据bug修改
上级
ed97daf0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
260 addition
and
1 deletion
+260
-1
mqtts-common/mqtts-common-core/pom.xml
mqtts-common/mqtts-common-core/pom.xml
+7
-0
mqtts-modules/mqtts-modules-tdengine/pom.xml
mqtts-modules/mqtts-modules-tdengine/pom.xml
+8
-0
mqtts-modules/mqtts-modules-tdengine/src/main/java/net/mqtts/tdengine/service/WeatherService.java
.../main/java/net/mqtts/tdengine/service/WeatherService.java
+5
-1
mqtts-modules/mqtts-modules-tdengine/src/main/java/net/mqtts/tdengine/util/DateUntils.java
...ine/src/main/java/net/mqtts/tdengine/util/DateUntils.java
+240
-0
未找到文件。
mqtts-common/mqtts-common-core/pom.xml
浏览文件 @
27885ecf
...
@@ -107,6 +107,13 @@
...
@@ -107,6 +107,13 @@
<artifactId>
swagger-annotations
</artifactId>
<artifactId>
swagger-annotations
</artifactId>
</dependency>
</dependency>
<!-- https://mvnrepository.com/artifact/cn.hutool/hutool-all -->
<dependency>
<groupId>
cn.hutool
</groupId>
<artifactId>
hutool-all
</artifactId>
<version>
5.7.14
</version>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
mqtts-modules/mqtts-modules-tdengine/pom.xml
浏览文件 @
27885ecf
...
@@ -97,6 +97,14 @@
...
@@ -97,6 +97,14 @@
</build>-->
</build>-->
<build>
<build>
<resources>
<resource>
<directory>
src/main/java
</directory>
<includes>
<include>
**/*.xml
</include>
</includes>
</resource>
</resources>
<plugins>
<plugins>
<!--打包jar-->
<!--打包jar-->
<plugin>
<plugin>
...
...
mqtts-modules/mqtts-modules-tdengine/src/main/java/net/mqtts/tdengine/service/WeatherService.java
浏览文件 @
27885ecf
...
@@ -2,6 +2,7 @@ package net.mqtts.tdengine.service;
...
@@ -2,6 +2,7 @@ package net.mqtts.tdengine.service;
import
net.mqtts.tdengine.dao.WeatherMapper
;
import
net.mqtts.tdengine.dao.WeatherMapper
;
import
net.mqtts.tdengine.domain.Weather
;
import
net.mqtts.tdengine.domain.Weather
;
import
net.mqtts.tdengine.util.DateUntils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -41,10 +42,13 @@ public class WeatherService {
...
@@ -41,10 +42,13 @@ public class WeatherService {
}
}
public
int
save
(
float
temperature
,
float
humidity
)
{
public
int
save
(
float
temperature
,
float
humidity
)
{
long
ts
=
System
.
currentTimeMillis
();
long
thirtySec
=
1000
*
30
;
Weather
weather
=
new
Weather
();
Weather
weather
=
new
Weather
();
weather
.
setTs
(
new
Timestamp
(
ts
+
(
thirtySec
)));
weather
.
setTemperature
(
temperature
);
weather
.
setTemperature
(
temperature
);
weather
.
setHumidity
(
humidity
);
weather
.
setHumidity
(
humidity
);
weather
.
setNote
(
"1"
);
return
weatherMapper
.
insert
(
weather
);
return
weatherMapper
.
insert
(
weather
);
}
}
...
...
mqtts-modules/mqtts-modules-tdengine/src/main/java/net/mqtts/tdengine/util/DateUntils.java
0 → 100644
浏览文件 @
27885ecf
package
net.mqtts.tdengine.util
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* @Description 时间工具类
* @author mqtts.net
* @Email 13733918655@163.com
* @Date 2019/12/9 20:45
* @Version 1.0
*/
public
class
DateUntils
{
public
static
Date
getCurrentDate
()
{
return
new
Date
();
}
public
static
String
getDateString
(
Date
date
)
{
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
String
previousDate
=
dateFormat
.
format
(
date
);
return
previousDate
;
}
public
static
String
getDateStrings
(
Date
date
)
{
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
String
previousDate
=
dateFormat
.
format
(
date
);
return
previousDate
;
}
public
static
String
getDateStampString
(
Date
date
)
{
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss:SSS"
);
String
previousDate
=
dateFormat
.
format
(
date
);
return
previousDate
;
}
public
static
Date
getDateString
(
String
date
)
{
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
Date
date1
=
null
;
try
{
date1
=
dateFormat
.
parse
(
date
);
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
return
date1
;
}
public
static
String
strToDateFormat
(
String
date
)
throws
ParseException
{
SimpleDateFormat
formatter
=
new
SimpleDateFormat
(
"yyyyMMdd"
);
formatter
.
setLenient
(
false
);
Date
newDate
=
formatter
.
parse
(
date
);
formatter
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
return
formatter
.
format
(
newDate
);
}
public
static
String
getDateFormatString
(
Date
date
)
{
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyyMMdd"
);
String
previousDate
=
dateFormat
.
format
(
date
);
return
previousDate
;
}
public
static
String
getDateFormatTostr
(
Date
date
)
{
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyyMMddHHmmss"
);
String
previousDate
=
dateFormat
.
format
(
date
);
return
previousDate
;
}
public
static
String
getCurrentDateWithZero
(
Date
date
)
{
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd 00:00:00"
);
String
previousDate
=
dateFormat
.
format
(
date
);
return
previousDate
;
}
public
static
String
getCurrentDateWithNight
(
Date
date
)
{
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd 23:59:59"
);
String
previousDate
=
dateFormat
.
format
(
date
);
return
previousDate
;
}
public
static
String
getPreviousDateWithZero
(
Date
date
)
{
Date
prevDate
=
new
Date
(
date
.
getTime
()
-
(
24
*
3600000
));
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd 00:00:00"
);
String
previousDate
=
dateFormat
.
format
(
prevDate
);
return
previousDate
;
}
public
static
Date
getFomatDate
(
String
str
)
{
//创建SimpleDateFormat对象实例并定义好转换格式
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
Date
date
=
null
;
try
{
// 注意格式需要与上面一致,不然会出现异常
date
=
sdf
.
parse
(
str
);
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
return
date
;
}
/**
* 将时间戳转换为日期
*
* @param stamp 时间戳
* @return 时间,返回格式为 yyyy-MM-dd-HH-mm-ss
*/
public
static
String
Stamp2Date
(
Long
stamp
)
{
String
result
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
format
(
stamp
);
return
result
;
}
/**
* 取得当前时间戳(精确到秒)
*
* @return
*/
public
static
String
timeStamp
()
{
long
time
=
System
.
currentTimeMillis
();
String
t
=
String
.
valueOf
(
time
/
1000
);
return
t
;
}
/**
* 取得当前时间戳(精确到秒)Long 类型
*
* @return
*/
public
static
Long
timeStampL
()
{
long
time
=
System
.
currentTimeMillis
();
return
time
/
1000
;
}
/**
* 获取指定url中的某个参数
*
* @param url
* @param name
* @return
*/
public
static
String
getParamByUrl
(
String
url
,
String
name
)
{
url
+=
"&"
;
String
pattern
=
"(\\?|&){1}#{0,1}"
+
name
+
"=[a-zA-Z0-9]*(&{1})"
;
Pattern
r
=
Pattern
.
compile
(
pattern
);
Matcher
m
=
r
.
matcher
(
url
);
if
(
m
.
find
())
{
System
.
out
.
println
(
m
.
group
(
0
));
return
m
.
group
(
0
).
split
(
"="
)[
1
].
replace
(
"&"
,
""
);
}
else
{
return
null
;
}
}
public
static
void
main
(
String
[]
args
)
throws
ParseException
{
String
sTime
=
"2019-05-17 00:00:00"
;
String
eTime
=
"2019-05-19 16:00:00"
;
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
Date
d1
=
getFomatDate
(
sTime
);
Date
d2
=
getFomatDate
(
eTime
);
List
<
String
>
times
=
getTimes
(
d1
,
d2
,
3600000L
);
for
(
String
str:
times
)
{
System
.
out
.
println
(
"得到的时间集合=:"
+
str
);
}
List
<
String
>
times1
=
getTimes
(
getFomatDate
(
"2021-09-22 00:00:00"
),
getFomatDate
(
"2021-09-30 00:00:00"
),
86400000
);
System
.
out
.
println
(
times1
);
}
//获取时间段内,时间间隔的所以时间点集合
public
static
List
<
String
>
getTimes
(
Date
startTime
,
Date
endTime
,
long
ll
)
throws
ParseException
{
List
<
String
>
times
=
new
ArrayList
<>();
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
startTime
);
long
startTimeStamp
=
calendar
.
getTimeInMillis
();
//起始的毫秒数
calendar
.
setTime
(
endTime
);
long
endTimeStamp
=
calendar
.
getTimeInMillis
();
//截止时间毫秒数
while
(
true
){
long
temp
=
startTimeStamp
+
ll
;
if
(
temp
<=
endTimeStamp
){
startTimeStamp
=
temp
;
Calendar
_calendar
=
Calendar
.
getInstance
();
_calendar
.
setTimeInMillis
(
temp
);
int
year
=
_calendar
.
get
(
Calendar
.
YEAR
);
int
month
=
_calendar
.
get
(
Calendar
.
MONTH
);
int
day
=
_calendar
.
get
(
Calendar
.
DAY_OF_MONTH
);
int
hour
=
_calendar
.
get
(
Calendar
.
HOUR_OF_DAY
);
//24小时制
//int hour = calendar.get(Calendar.HOUR);//12小时制
int
minute
=
_calendar
.
get
(
Calendar
.
MINUTE
);
int
second
=
_calendar
.
get
(
Calendar
.
SECOND
);
String
time
=
year
+
"-"
+
(
month
+
1
)
+
"-"
+
day
+
" "
+
hour
+
":"
+
minute
+
":"
+
second
;
//时间格式处理
String
res
;
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
Date
date
=
simpleDateFormat
.
parse
(
time
);
long
ts
=
date
.
getTime
();
long
lt
=
new
Long
(
String
.
valueOf
(
ts
));
Date
date1
=
new
Date
(
lt
);
res
=
simpleDateFormat
.
format
(
date1
);
times
.
add
(
res
);
}
else
{
break
;
}
}
return
times
;
}
/*
* 将时间转换为时间戳
*/
public
static
String
dateToStamp
(
String
s
)
throws
ParseException
{
String
res
;
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
Date
date
=
simpleDateFormat
.
parse
(
s
);
long
ts
=
date
.
getTime
();
res
=
String
.
valueOf
(
ts
);
return
res
;
}
/*
* 将时间戳转换为时间
*/
public
static
String
stampToDate
(
String
s
){
String
res
;
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
long
lt
=
new
Long
(
s
);
Date
date
=
new
Date
(
lt
);
res
=
simpleDateFormat
.
format
(
date
);
return
res
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录