Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
黄嘉阳
/
iot-platform-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
271a8168
authored
Nov 02, 2023
by
huangjy
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix:日报周报获取数据问题
parent
bf264817
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
19 deletions
server-common/src/main/java/com/makeit/module/iot/service/IotProductDeviceService.java
server-common/src/main/java/com/makeit/module/iot/service/IotProductDeviceService.java
View file @
271a8168
...
...
@@ -22,6 +22,7 @@ import com.makeit.utils.LongTimestampUtil;
import
com.makeit.utils.data.convert.JsonUtil
;
import
com.makeit.utils.data.convert.StreamUtil
;
import
com.makeit.utils.old.StringUtils
;
import
com.makeit.utils.time.LocalDateTimeUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.RandomUtils
;
...
...
@@ -31,6 +32,7 @@ import org.springframework.stereotype.Component;
import
java.io.IOException
;
import
java.time.*
;
import
java.time.format.DateTimeFormatter
;
import
java.time.temporal.ChronoUnit
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.TreeMap
;
...
...
@@ -178,21 +180,39 @@ public class IotProductDeviceService extends IotCommonService {
}
public
List
<
String
>
getLastDayHourRange
(
LocalDateTime
startDateTime
)
{
int
count
=
24
;
public
List
<
String
>
getLastDayHourRange
(
LocalDateTime
startDateTime
,
long
count
)
{
List
<
String
>
list
=
Lists
.
newArrayList
();
String
startTime
;
String
endTime
;
for
(
int
i
=
count
;
i
>
0
;
i
--
)
{
startTime
=
DateUtil
.
format
(
startDateTime
.
minusHours
(
i
),
DatePattern
.
NORM_DATETIME_PATTERN
);
endTime
=
DateUtil
.
format
(
startDateTime
.
minusHours
(
i
-
1
),
DatePattern
.
NORM_DATETIME_PATTERN
);
for
(
int
i
=
1
;
i
<=
count
;
i
++
)
{
startTime
=
DateUtil
.
format
(
startDateTime
.
plusHours
(
i
-
1
),
DatePattern
.
NORM_DATETIME_PATTERN
);
endTime
=
DateUtil
.
format
(
startDateTime
.
plusHours
(
i
),
DatePattern
.
NORM_DATETIME_PATTERN
);
list
.
add
(
startTime
+
"~"
+
endTime
);
}
return
list
;
}
public
static
void
main
(
String
[]
args
)
{
LocalDate
now
=
LocalDate
.
now
();
LocalDateTime
start
=
dayStartNow
(
now
);
LocalDateTime
end
=
dayEndNow
(
now
);
long
daysBetween
=
ChronoUnit
.
DAYS
.
between
(
start
,
end
);
IotProductDeviceService
iotProductDeviceService
=
new
IotProductDeviceService
();
List
<
String
>
lastDayHourRange
=
iotProductDeviceService
.
getLastDayHourRange
(
start
,
24
);
System
.
out
.
println
(
lastDayHourRange
);
}
private
static
LocalDateTime
dayStartNow
(
LocalDate
now
)
{
return
LocalDateTimeUtils
.
getDayStart
(
now
);
}
private
static
LocalDateTime
dayEndNow
(
LocalDate
now
)
{
return
LocalDateTimeUtils
.
getDayEnd
(
now
);
}
public
List
<
DeviceInfoContentBreathe
>
getDeviceLogByTimeRangeBreathe
(
String
deviceId
,
int
pageSize
,
LocalDateTime
startTime
,
LocalDateTime
endTime
)
{
List
<
String
>
lastDayHourRange
=
getLastDayHourRange
(
startTime
);
long
daysBetween
=
ChronoUnit
.
DAYS
.
between
(
startTime
,
endTime
);
List
<
String
>
lastDayHourRange
=
getLastDayHourRange
(
startTime
,
daysBetween
>
1
?
24
*
daysBetween:
24
);
List
<
DeviceInfoContentBreathe
>
tempList
=
Lists
.
newArrayList
();
for
(
String
hour
:
lastDayHourRange
)
{
String
[]
hourRangeArray
=
hour
.
split
(
"~"
);
...
...
@@ -261,24 +281,14 @@ public class IotProductDeviceService extends IotCommonService {
return breatheList;*/
}
public
static
void
main
(
String
[]
args
)
{
LocalDateTime
localDateTime
=
LocalDateTime
.
now
();
long
timeStamp
=
localDateTime
.
atZone
(
ZoneId
.
systemDefault
()).
toInstant
().
toEpochMilli
();
System
.
out
.
println
(
timeStamp
);
long
timestamp
=
localDateTime
.
toInstant
(
ZoneOffset
.
of
(
"+8"
)).
toEpochMilli
();
System
.
out
.
println
(
"LocalDateTime to Timestamp: "
+
timestamp
);
}
public
static
String
formatLongTime
(
long
time
)
{
return
DEFAULT_FORMATTER
.
format
(
LocalDateTime
.
ofInstant
(
Instant
.
ofEpochMilli
(
time
),
ZoneId
.
systemDefault
()));
}
public
List
<
DeviceInfoContentSpace
>
getDeviceLogByTimeRangeSpace
(
String
deviceId
,
int
pageSize
,
LocalDateTime
startTime
,
LocalDateTime
endTime
)
{
List
<
DeviceInfoContentSpace
>
deviceInfoContentSpaceList
=
Lists
.
newArrayList
();
List
<
String
>
lastDayHourRange
=
getLastDayHourRange
(
startTime
);
long
daysBetween
=
ChronoUnit
.
DAYS
.
between
(
startTime
,
endTime
);
List
<
String
>
lastDayHourRange
=
getLastDayHourRange
(
startTime
,
daysBetween
>
1
?
24
*
daysBetween:
24
);
for
(
String
hourRange
:
lastDayHourRange
)
{
String
[]
hourRangeArray
=
hourRange
.
split
(
"~"
);
List
<
DeviceOperationLogEntity
>
deviceOperationLogList
=
getDeviceLogByTimeRange
(
deviceId
,
REPORT_PROPERTY
,
5000
,
hourRangeArray
[
0
],
hourRangeArray
[
1
]);
...
...
@@ -291,7 +301,8 @@ public class IotProductDeviceService extends IotCommonService {
public
List
<
DeviceInfoContentFall
>
getDeviceLogByTimeRangeFall
(
String
deviceId
,
int
pageSize
,
LocalDateTime
startTime
,
LocalDateTime
endTime
)
{
List
<
DeviceInfoContentFall
>
deviceInfoContentFallList
=
Lists
.
newArrayList
();
List
<
String
>
lastDayHourRange
=
getLastDayHourRange
(
startTime
);
long
daysBetween
=
ChronoUnit
.
DAYS
.
between
(
startTime
,
endTime
);
List
<
String
>
lastDayHourRange
=
getLastDayHourRange
(
startTime
,
daysBetween
>
1
?
24
*
daysBetween:
24
);
for
(
String
hourRange
:
lastDayHourRange
)
{
String
[]
hourRangeArray
=
hourRange
.
split
(
"~"
);
List
<
DeviceOperationLogEntity
>
deviceOperationLogList
=
getDeviceLogByTimeRange
(
deviceId
,
REPORT_PROPERTY
,
5000
,
hourRangeArray
[
0
],
hourRangeArray
[
1
]);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment