仪表盘-访客数查询接口

This commit is contained in:
ronger 2022-03-14 13:48:41 +08:00
parent 28641bb942
commit 38f211480a
3 changed files with 87 additions and 17 deletions

View File

@ -54,13 +54,13 @@ public interface DashboardMapper {
List<DashboardData> selectLastThirtyDaysArticleData();
/**
* 获取最近 30 文章数据
* 获取最近 30 用户数据
* @return
*/
List<DashboardData> selectLastThirtyDaysUserData();
/**
* 获取最近 30 文章数据
* 获取最近 30 流量数据
* @return
*/
List<DashboardData> selectLastThirtyDaysVisitData();
@ -100,4 +100,16 @@ public interface DashboardMapper {
* @return
*/
List<ArticleDTO> selectNewArticles();
/**
* 获取最近 30 天访客数据
* @return
*/
List<DashboardData> selectLastThirtyDaysVisitIpData();
/**
* 获取历史 1 年访客数据
* @return
*/
List<DashboardData> selectHistoryVisitIpData();
}

View File

@ -40,20 +40,22 @@ public class DashboardServiceImpl implements DashboardService {
@Override
public Map lastThirtyDaysData() {
Map map = new HashMap(4);
Map map = new HashMap(5);
ArrayList<String> dates = new ArrayList(30);
ArrayList<Integer> articleData = new ArrayList(30);
ArrayList<Integer> userData = new ArrayList(30);
ArrayList<Integer> visitData = new ArrayList(30);
ArrayList<Integer> visitIpData = new ArrayList(30);
List<DashboardData> articles = dashboardMapper.selectLastThirtyDaysArticleData();
List<DashboardData> users = dashboardMapper.selectLastThirtyDaysUserData();
List<DashboardData> visits = dashboardMapper.selectLastThirtyDaysVisitData();
List<DashboardData> visitIps = dashboardMapper.selectLastThirtyDaysVisitIpData();
LocalDate now = LocalDate.now().plusDays(1);
LocalDate localDate = LocalDate.now().plusDays(-29);
while (now.isAfter(localDate)) {
String date = localDate.toString();
dates.add(date);
articles.forEach(article->{
articles.forEach(article -> {
if (date.equals(article.getLabel())) {
articleData.add(article.getValue());
return;
@ -63,7 +65,7 @@ public class DashboardServiceImpl implements DashboardService {
articleData.add(0);
}
users.forEach(user->{
users.forEach(user -> {
if (date.equals(user.getLabel())) {
userData.add(user.getValue());
return;
@ -73,7 +75,7 @@ public class DashboardServiceImpl implements DashboardService {
userData.add(0);
}
visits.forEach(visit->{
visits.forEach(visit -> {
if (date.equals(visit.getLabel())) {
visitData.add(visit.getValue());
return;
@ -83,34 +85,47 @@ public class DashboardServiceImpl implements DashboardService {
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);
}
map.put("dates", dates);
map.put("articles", articleData);
map.put("users", userData);
map.put("visits", visitData);
map.put("visitIps", visitIpData);
return map;
}
@Override
public Map history() {
Map<String, Object> map = new HashMap(4);
Map<String, Object> map = new HashMap(5);
ArrayList<String> dates = new ArrayList(30);
ArrayList<Integer> articleData = new ArrayList(30);
ArrayList<Integer> userData = new ArrayList(30);
ArrayList<Integer> visitData = new ArrayList(30);
ArrayList<Integer> visitIpData = new ArrayList(30);
List<DashboardData> articles = dashboardMapper.selectHistoryArticleData();
List<DashboardData> users = dashboardMapper.selectHistoryUserData();
List<DashboardData> visits = dashboardMapper.selectHistoryVisitData();
List<DashboardData> visitIps = dashboardMapper.selectHistoryVisitIpData();
LocalDate now = LocalDate.now().plusMonths(1);
LocalDate localDate = LocalDate.now().plusYears(-1).plusMonths(1);
while (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());
dates.add(date);
articles.forEach(article->{
articles.forEach(article -> {
if (date.equals(article.getLabel())) {
articleData.add(article.getValue());
return;
@ -120,7 +135,7 @@ public class DashboardServiceImpl implements DashboardService {
articleData.add(0);
}
users.forEach(user->{
users.forEach(user -> {
if (date.equals(user.getLabel())) {
userData.add(user.getValue());
return;
@ -130,7 +145,7 @@ public class DashboardServiceImpl implements DashboardService {
userData.add(0);
}
visits.forEach(visit->{
visits.forEach(visit -> {
if (date.equals(visit.getLabel())) {
visitData.add(visit.getValue());
return;
@ -139,12 +154,22 @@ public class DashboardServiceImpl implements DashboardService {
if (visitData.size() < dates.size()) {
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 {
String date = localDate.getYear() + "-" + (localDate.getMonthValue() < 10 ? "0" + localDate.getMonthValue() : localDate.getMonthValue());
dates.add(date);
articles.forEach(article->{
articles.forEach(article -> {
if (date.equals(article.getLabel())) {
articleData.add(article.getValue());
return;
@ -154,7 +179,7 @@ public class DashboardServiceImpl implements DashboardService {
articleData.add(0);
}
users.forEach(user->{
users.forEach(user -> {
if (date.equals(user.getLabel())) {
userData.add(user.getValue());
return;
@ -164,7 +189,7 @@ public class DashboardServiceImpl implements DashboardService {
userData.add(0);
}
visits.forEach(visit->{
visits.forEach(visit -> {
if (date.equals(visit.getLabel())) {
visitData.add(visit.getValue());
return;
@ -173,6 +198,16 @@ public class DashboardServiceImpl implements DashboardService {
if (visitData.size() < dates.size()) {
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);
@ -181,6 +216,7 @@ public class DashboardServiceImpl implements DashboardService {
map.put("articles", articleData);
map.put("users", userData);
map.put("visits", visitData);
map.put("visitIps", visitIpData);
return map;
}

View File

@ -109,7 +109,7 @@
<select id="selectNewUsers" resultMap="UserInfoResultMapper">
select id, nickname, avatar_url, account, created_time
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
</select>
<select id="selectNewBankAccounts" resultMap="BankAccountResultMap">
@ -117,7 +117,7 @@
from forest_bank_account fba
join forest_user fu on fba.account_owner = fu.id
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
</select>
<select id="selectNewArticles" resultMap="ArticleResultMap">
@ -131,7 +131,29 @@
from forest_article art
where article_status = 0
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
</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>