✨ 仪表盘-访客数查询接口
This commit is contained in:
parent
28641bb942
commit
38f211480a
@ -54,13 +54,13 @@ public interface DashboardMapper {
|
|||||||
List<DashboardData> selectLastThirtyDaysArticleData();
|
List<DashboardData> selectLastThirtyDaysArticleData();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取最近 30 天文章数据
|
* 获取最近 30 天用户数据
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<DashboardData> selectLastThirtyDaysUserData();
|
List<DashboardData> selectLastThirtyDaysUserData();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取最近 30 天文章数据
|
* 获取最近 30 天流量数据
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<DashboardData> selectLastThirtyDaysVisitData();
|
List<DashboardData> selectLastThirtyDaysVisitData();
|
||||||
@ -100,4 +100,16 @@ public interface DashboardMapper {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<ArticleDTO> selectNewArticles();
|
List<ArticleDTO> selectNewArticles();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取最近 30 天访客数据
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<DashboardData> selectLastThirtyDaysVisitIpData();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取历史 1 年访客数据
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<DashboardData> selectHistoryVisitIpData();
|
||||||
}
|
}
|
||||||
|
@ -40,20 +40,22 @@ public class DashboardServiceImpl implements DashboardService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map lastThirtyDaysData() {
|
public Map lastThirtyDaysData() {
|
||||||
Map map = new HashMap(4);
|
Map map = new HashMap(5);
|
||||||
ArrayList<String> dates = new ArrayList(30);
|
ArrayList<String> dates = new ArrayList(30);
|
||||||
ArrayList<Integer> articleData = new ArrayList(30);
|
ArrayList<Integer> articleData = new ArrayList(30);
|
||||||
ArrayList<Integer> userData = new ArrayList(30);
|
ArrayList<Integer> userData = new ArrayList(30);
|
||||||
ArrayList<Integer> visitData = new ArrayList(30);
|
ArrayList<Integer> visitData = new ArrayList(30);
|
||||||
|
ArrayList<Integer> visitIpData = new ArrayList(30);
|
||||||
List<DashboardData> articles = dashboardMapper.selectLastThirtyDaysArticleData();
|
List<DashboardData> articles = dashboardMapper.selectLastThirtyDaysArticleData();
|
||||||
List<DashboardData> users = dashboardMapper.selectLastThirtyDaysUserData();
|
List<DashboardData> users = dashboardMapper.selectLastThirtyDaysUserData();
|
||||||
List<DashboardData> visits = dashboardMapper.selectLastThirtyDaysVisitData();
|
List<DashboardData> visits = dashboardMapper.selectLastThirtyDaysVisitData();
|
||||||
|
List<DashboardData> visitIps = dashboardMapper.selectLastThirtyDaysVisitIpData();
|
||||||
LocalDate now = LocalDate.now().plusDays(1);
|
LocalDate now = LocalDate.now().plusDays(1);
|
||||||
LocalDate localDate = LocalDate.now().plusDays(-29);
|
LocalDate localDate = LocalDate.now().plusDays(-29);
|
||||||
while (now.isAfter(localDate)) {
|
while (now.isAfter(localDate)) {
|
||||||
String date = localDate.toString();
|
String date = localDate.toString();
|
||||||
dates.add(date);
|
dates.add(date);
|
||||||
articles.forEach(article->{
|
articles.forEach(article -> {
|
||||||
if (date.equals(article.getLabel())) {
|
if (date.equals(article.getLabel())) {
|
||||||
articleData.add(article.getValue());
|
articleData.add(article.getValue());
|
||||||
return;
|
return;
|
||||||
@ -63,7 +65,7 @@ public class DashboardServiceImpl implements DashboardService {
|
|||||||
articleData.add(0);
|
articleData.add(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
users.forEach(user->{
|
users.forEach(user -> {
|
||||||
if (date.equals(user.getLabel())) {
|
if (date.equals(user.getLabel())) {
|
||||||
userData.add(user.getValue());
|
userData.add(user.getValue());
|
||||||
return;
|
return;
|
||||||
@ -73,7 +75,7 @@ public class DashboardServiceImpl implements DashboardService {
|
|||||||
userData.add(0);
|
userData.add(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
visits.forEach(visit->{
|
visits.forEach(visit -> {
|
||||||
if (date.equals(visit.getLabel())) {
|
if (date.equals(visit.getLabel())) {
|
||||||
visitData.add(visit.getValue());
|
visitData.add(visit.getValue());
|
||||||
return;
|
return;
|
||||||
@ -83,34 +85,47 @@ public class DashboardServiceImpl implements DashboardService {
|
|||||||
visitData.add(0);
|
visitData.add(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
visitIps.forEach(visitIp -> {
|
||||||
|
if (date.equals(visitIp.getLabel())) {
|
||||||
|
visitIpData.add(visitIp.getValue());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (visitIpData.size() < dates.size()) {
|
||||||
|
visitIpData.add(0);
|
||||||
|
}
|
||||||
|
|
||||||
localDate = localDate.plusDays(1);
|
localDate = localDate.plusDays(1);
|
||||||
}
|
}
|
||||||
map.put("dates", dates);
|
map.put("dates", dates);
|
||||||
map.put("articles", articleData);
|
map.put("articles", articleData);
|
||||||
map.put("users", userData);
|
map.put("users", userData);
|
||||||
map.put("visits", visitData);
|
map.put("visits", visitData);
|
||||||
|
map.put("visitIps", visitIpData);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map history() {
|
public Map history() {
|
||||||
Map<String, Object> map = new HashMap(4);
|
Map<String, Object> map = new HashMap(5);
|
||||||
ArrayList<String> dates = new ArrayList(30);
|
ArrayList<String> dates = new ArrayList(30);
|
||||||
ArrayList<Integer> articleData = new ArrayList(30);
|
ArrayList<Integer> articleData = new ArrayList(30);
|
||||||
ArrayList<Integer> userData = new ArrayList(30);
|
ArrayList<Integer> userData = new ArrayList(30);
|
||||||
ArrayList<Integer> visitData = new ArrayList(30);
|
ArrayList<Integer> visitData = new ArrayList(30);
|
||||||
|
ArrayList<Integer> visitIpData = new ArrayList(30);
|
||||||
List<DashboardData> articles = dashboardMapper.selectHistoryArticleData();
|
List<DashboardData> articles = dashboardMapper.selectHistoryArticleData();
|
||||||
List<DashboardData> users = dashboardMapper.selectHistoryUserData();
|
List<DashboardData> users = dashboardMapper.selectHistoryUserData();
|
||||||
List<DashboardData> visits = dashboardMapper.selectHistoryVisitData();
|
List<DashboardData> visits = dashboardMapper.selectHistoryVisitData();
|
||||||
|
List<DashboardData> visitIps = dashboardMapper.selectHistoryVisitIpData();
|
||||||
LocalDate now = LocalDate.now().plusMonths(1);
|
LocalDate now = LocalDate.now().plusMonths(1);
|
||||||
LocalDate localDate = LocalDate.now().plusYears(-1).plusMonths(1);
|
LocalDate localDate = LocalDate.now().plusYears(-1).plusMonths(1);
|
||||||
while (now.getYear() >= localDate.getYear()) {
|
while (now.getYear() >= localDate.getYear()) {
|
||||||
if (now.getYear() == localDate.getYear()) {
|
if (now.getYear() == localDate.getYear()) {
|
||||||
if (now.getMonthValue() > localDate.getMonthValue()){
|
if (now.getMonthValue() > localDate.getMonthValue()) {
|
||||||
String date = localDate.getYear() + "-" + (localDate.getMonthValue() < 10 ? "0" + localDate.getMonthValue() : localDate.getMonthValue());
|
String date = localDate.getYear() + "-" + (localDate.getMonthValue() < 10 ? "0" + localDate.getMonthValue() : localDate.getMonthValue());
|
||||||
dates.add(date);
|
dates.add(date);
|
||||||
|
|
||||||
articles.forEach(article->{
|
articles.forEach(article -> {
|
||||||
if (date.equals(article.getLabel())) {
|
if (date.equals(article.getLabel())) {
|
||||||
articleData.add(article.getValue());
|
articleData.add(article.getValue());
|
||||||
return;
|
return;
|
||||||
@ -120,7 +135,7 @@ public class DashboardServiceImpl implements DashboardService {
|
|||||||
articleData.add(0);
|
articleData.add(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
users.forEach(user->{
|
users.forEach(user -> {
|
||||||
if (date.equals(user.getLabel())) {
|
if (date.equals(user.getLabel())) {
|
||||||
userData.add(user.getValue());
|
userData.add(user.getValue());
|
||||||
return;
|
return;
|
||||||
@ -130,7 +145,7 @@ public class DashboardServiceImpl implements DashboardService {
|
|||||||
userData.add(0);
|
userData.add(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
visits.forEach(visit->{
|
visits.forEach(visit -> {
|
||||||
if (date.equals(visit.getLabel())) {
|
if (date.equals(visit.getLabel())) {
|
||||||
visitData.add(visit.getValue());
|
visitData.add(visit.getValue());
|
||||||
return;
|
return;
|
||||||
@ -139,12 +154,22 @@ public class DashboardServiceImpl implements DashboardService {
|
|||||||
if (visitData.size() < dates.size()) {
|
if (visitData.size() < dates.size()) {
|
||||||
visitData.add(0);
|
visitData.add(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
visitIps.forEach(visitIp -> {
|
||||||
|
if (date.equals(visitIp.getLabel())) {
|
||||||
|
visitIpData.add(visitIp.getValue());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (visitIpData.size() < dates.size()) {
|
||||||
|
visitIpData.add(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String date = localDate.getYear() + "-" + (localDate.getMonthValue() < 10 ? "0" + localDate.getMonthValue() : localDate.getMonthValue());
|
String date = localDate.getYear() + "-" + (localDate.getMonthValue() < 10 ? "0" + localDate.getMonthValue() : localDate.getMonthValue());
|
||||||
dates.add(date);
|
dates.add(date);
|
||||||
|
|
||||||
articles.forEach(article->{
|
articles.forEach(article -> {
|
||||||
if (date.equals(article.getLabel())) {
|
if (date.equals(article.getLabel())) {
|
||||||
articleData.add(article.getValue());
|
articleData.add(article.getValue());
|
||||||
return;
|
return;
|
||||||
@ -154,7 +179,7 @@ public class DashboardServiceImpl implements DashboardService {
|
|||||||
articleData.add(0);
|
articleData.add(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
users.forEach(user->{
|
users.forEach(user -> {
|
||||||
if (date.equals(user.getLabel())) {
|
if (date.equals(user.getLabel())) {
|
||||||
userData.add(user.getValue());
|
userData.add(user.getValue());
|
||||||
return;
|
return;
|
||||||
@ -164,7 +189,7 @@ public class DashboardServiceImpl implements DashboardService {
|
|||||||
userData.add(0);
|
userData.add(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
visits.forEach(visit->{
|
visits.forEach(visit -> {
|
||||||
if (date.equals(visit.getLabel())) {
|
if (date.equals(visit.getLabel())) {
|
||||||
visitData.add(visit.getValue());
|
visitData.add(visit.getValue());
|
||||||
return;
|
return;
|
||||||
@ -173,6 +198,16 @@ public class DashboardServiceImpl implements DashboardService {
|
|||||||
if (visitData.size() < dates.size()) {
|
if (visitData.size() < dates.size()) {
|
||||||
visitData.add(0);
|
visitData.add(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
visitIps.forEach(visitIp -> {
|
||||||
|
if (date.equals(visitIp.getLabel())) {
|
||||||
|
visitIpData.add(visitIp.getValue());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (visitIpData.size() < dates.size()) {
|
||||||
|
visitIpData.add(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
localDate = localDate.plusMonths(1);
|
localDate = localDate.plusMonths(1);
|
||||||
@ -181,6 +216,7 @@ public class DashboardServiceImpl implements DashboardService {
|
|||||||
map.put("articles", articleData);
|
map.put("articles", articleData);
|
||||||
map.put("users", userData);
|
map.put("users", userData);
|
||||||
map.put("visits", visitData);
|
map.put("visits", visitData);
|
||||||
|
map.put("visitIps", visitIpData);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@
|
|||||||
<select id="selectNewUsers" resultMap="UserInfoResultMapper">
|
<select id="selectNewUsers" resultMap="UserInfoResultMapper">
|
||||||
select id, nickname, avatar_url, account, created_time
|
select id, nickname, avatar_url, account, created_time
|
||||||
from forest_user
|
from forest_user
|
||||||
where created_time > str_to_date(date_format(date_sub(sysdate(), interval + 1 year), '%Y-%m-%d'), '%Y-%m-%d')
|
where created_time > str_to_date(date_format(date_sub(sysdate(), interval + 7 day), '%Y-%m-%d'), '%Y-%m-%d')
|
||||||
order by created_time desc
|
order by created_time desc
|
||||||
</select>
|
</select>
|
||||||
<select id="selectNewBankAccounts" resultMap="BankAccountResultMap">
|
<select id="selectNewBankAccounts" resultMap="BankAccountResultMap">
|
||||||
@ -117,7 +117,7 @@
|
|||||||
from forest_bank_account fba
|
from forest_bank_account fba
|
||||||
join forest_user fu on fba.account_owner = fu.id
|
join forest_user fu on fba.account_owner = fu.id
|
||||||
where fba.created_time >
|
where fba.created_time >
|
||||||
str_to_date(date_format(date_sub(sysdate(), interval + 1 year), '%Y-%m-%d'), '%Y-%m-%d')
|
str_to_date(date_format(date_sub(sysdate(), interval + 7 day), '%Y-%m-%d'), '%Y-%m-%d')
|
||||||
order by fba.created_time desc
|
order by fba.created_time desc
|
||||||
</select>
|
</select>
|
||||||
<select id="selectNewArticles" resultMap="ArticleResultMap">
|
<select id="selectNewArticles" resultMap="ArticleResultMap">
|
||||||
@ -131,7 +131,29 @@
|
|||||||
from forest_article art
|
from forest_article art
|
||||||
where article_status = 0
|
where article_status = 0
|
||||||
and art.created_time >
|
and art.created_time >
|
||||||
str_to_date(date_format(date_sub(sysdate(), interval + 1 year), '%Y-%m-%d'), '%Y-%m-%d')
|
str_to_date(date_format(date_sub(sysdate(), interval + 7 day), '%Y-%m-%d'), '%Y-%m-%d')
|
||||||
order by art.created_time desc
|
order by art.created_time desc
|
||||||
</select>
|
</select>
|
||||||
|
<select id="selectLastThirtyDaysVisitIpData" resultMap="DashboardDataResultMap">
|
||||||
|
select count(t.label) as value, t.label
|
||||||
|
from (
|
||||||
|
select distinct visit_ip as ip, date_format(created_time, '%Y-%m-%d') as label
|
||||||
|
from forest_visit
|
||||||
|
where created_time >
|
||||||
|
str_to_date(date_format(date_sub(sysdate(), interval + 30 day), '%Y-%m-%d'), '%Y-%m-%d')
|
||||||
|
GROUP BY date_format(created_time, '%Y-%m-%d'), visit_ip
|
||||||
|
) t
|
||||||
|
group by t.label
|
||||||
|
</select>
|
||||||
|
<select id="selectHistoryVisitIpData" resultMap="DashboardDataResultMap">
|
||||||
|
select count(t.label) as value, t.label
|
||||||
|
from (
|
||||||
|
select distinct visit_ip as ip, date_format(created_time, '%Y-%m') as label
|
||||||
|
from forest_visit
|
||||||
|
where created_time >
|
||||||
|
str_to_date(date_format(date_sub(sysdate(), interval + 1 year), '%Y-%m-%d'), '%Y-%m-%d')
|
||||||
|
GROUP BY date_format(created_time, '%Y-%m'), visit_ip
|
||||||
|
) t
|
||||||
|
group by t.label
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
Loading…
Reference in New Issue
Block a user