Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Administrator
/
kmr-h5-java
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
9f2622b9
authored
2017-12-06 13:03:52 +0800
by
ja
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
时间范围查询统计
1 parent
db58f432
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
7 deletions
kmr_dp_HDP/src/main/java/com/example/controller/StatisticsController.java
kmr_dp_HDP/src/main/java/com/example/controller/StatisticsController.java
View file @
9f2622b
...
...
@@ -9,10 +9,9 @@ import org.springframework.web.bind.annotation.RequestParam;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.servlet.http.HttpServletRequest
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.*
;
/**
* Created by JA on 17/7/3.
...
...
@@ -27,12 +26,21 @@ public class StatisticsController {
private
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
@RequestMapping
public
MessageEntity
statistics
(
HttpServletRequest
request
,
@RequestParam
(
required
=
false
)
String
t
ime
)
{
public
MessageEntity
statistics
(
HttpServletRequest
request
,
@RequestParam
(
required
=
false
)
String
startTime
,
@RequestParam
(
required
=
false
)
String
endT
ime
)
{
MessageEntity
.
Builder
builder
=
new
MessageEntity
.
Builder
(
request
);
if
(
StringUtils
.
isBlank
(
time
)){
Map
<
String
,
Object
>
returnMap
=
new
HashMap
<>();
if
(
StringUtils
.
isBlank
(
startTime
)){
Date
date
=
new
Date
();
t
ime
=
this
.
sdf
.
format
(
date
);
startT
ime
=
this
.
sdf
.
format
(
date
);
}
if
(
StringUtils
.
isBlank
(
endTime
)){
Date
date
=
new
Date
();
endTime
=
this
.
sdf
.
format
(
date
);
}
List
<
Date
>
dateList
=
getBetweenDates
(
startTime
,
endTime
);
if
(
dateList
!=
null
&&
dateList
.
size
()
>
0
){
for
(
Date
date:
dateList
){
String
time
=
this
.
sdf
.
format
(
date
);
String
startDate
=
time
+
" 00:00:00"
;
String
endDate
=
time
+
" 23:59:59"
;
int
pv
=
this
.
shareLogMapper
.
findPVByDay
(
startDate
,
endDate
);
...
...
@@ -44,7 +52,38 @@ public class StatisticsController {
map
.
put
(
"uv"
,
uv
);
map
.
put
(
"share"
,
share
);
map
.
put
(
"img"
,
img
);
return
builder
.
success
(
true
).
code
(
"2000"
).
content
(
map
).
create
();
returnMap
.
put
(
time
,
map
);
}
}
return
builder
.
success
(
true
).
code
(
"2000"
).
content
(
returnMap
).
create
();
}
private
List
<
Date
>
getBetweenDates
(
String
startString
,
String
endString
)
{
List
<
Date
>
result
=
new
ArrayList
<>();
Calendar
tempStart
=
Calendar
.
getInstance
();
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
Date
start
=
null
;
Date
end
=
null
;
try
{
start
=
sdf
.
parse
(
startString
);
end
=
sdf
.
parse
(
endString
);
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
tempStart
.
setTime
(
start
);
result
.
add
(
tempStart
.
getTime
());
tempStart
.
add
(
Calendar
.
DAY_OF_YEAR
,
1
);
Calendar
tempEnd
=
Calendar
.
getInstance
();
tempEnd
.
setTime
(
end
);
while
(
tempStart
.
before
(
tempEnd
)
||
tempStart
.
equals
(
tempEnd
))
{
result
.
add
(
tempStart
.
getTime
());
Date
time
=
tempStart
.
getTime
();
tempStart
.
add
(
Calendar
.
DAY_OF_YEAR
,
1
);
}
return
result
;
}
}
...
...
Please
register
or
sign in
to post a comment