✨ 开放数据信息接口
This commit is contained in:
parent
38f211480a
commit
9019e515d3
@ -71,7 +71,7 @@ public class WebMvcConfigurer extends WebMvcConfigurationSupport {
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(restAuthTokenInterceptor()).addPathPatterns("/api/**")
|
||||
.excludePathPatterns("/api/v1/console/**", "/api/v1/article/articles/**", "/api/v1/article/detail/**"
|
||||
, "/api/v1/topic/**", "/api/v1/user/**", "/api/v1/article/*/comments", "/api/v1/rule/currency/**", "/api/v1/lucene/**");
|
||||
, "/api/v1/topic/**", "/api/v1/user/**", "/api/v1/article/*/comments", "/api/v1/rule/currency/**", "/api/v1/lucene/**", "/api/v1/open-data/**");
|
||||
|
||||
}
|
||||
|
||||
|
26
src/main/java/com/rymcu/forest/service/OpenDataService.java
Normal file
26
src/main/java/com/rymcu/forest/service/OpenDataService.java
Normal file
@ -0,0 +1,26 @@
|
||||
package com.rymcu.forest.service;
|
||||
|
||||
import com.rymcu.forest.dto.admin.Dashboard;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created on 2022/3/14 13:51.
|
||||
*
|
||||
* @author ronger
|
||||
* @email ronger-x@outlook.com
|
||||
* @packageName com.rymcu.forest.service
|
||||
*/
|
||||
public interface OpenDataService {
|
||||
/**
|
||||
* 获取最近 30 天开放数据
|
||||
* @return
|
||||
*/
|
||||
Map lastThirtyDaysData();
|
||||
|
||||
/**
|
||||
* 获取统计数据
|
||||
* @return
|
||||
*/
|
||||
Dashboard dashboard();
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package com.rymcu.forest.service.impl;
|
||||
|
||||
import com.rymcu.forest.dto.admin.Dashboard;
|
||||
import com.rymcu.forest.dto.admin.DashboardData;
|
||||
import com.rymcu.forest.mapper.DashboardMapper;
|
||||
import com.rymcu.forest.service.OpenDataService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created on 2022/3/14 13:51.
|
||||
*
|
||||
* @author ronger
|
||||
* @email ronger-x@outlook.com
|
||||
* @packageName com.rymcu.forest.service.impl
|
||||
*/
|
||||
@Service
|
||||
public class OpenDataServiceImpl implements OpenDataService {
|
||||
|
||||
@Resource
|
||||
private DashboardMapper dashboardMapper;
|
||||
|
||||
@Override
|
||||
public Map lastThirtyDaysData() {
|
||||
Map map = new HashMap(5);
|
||||
ArrayList<String> dates = new ArrayList(30);
|
||||
ArrayList<Integer> visitData = new ArrayList(30);
|
||||
ArrayList<Integer> visitIpData = new ArrayList(30);
|
||||
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);
|
||||
|
||||
visits.forEach(visit -> {
|
||||
if (date.equals(visit.getLabel())) {
|
||||
visitData.add(visit.getValue());
|
||||
return;
|
||||
}
|
||||
});
|
||||
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.plusDays(1);
|
||||
}
|
||||
map.put("dates", dates);
|
||||
map.put("visits", visitData);
|
||||
map.put("visitIps", visitIpData);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dashboard dashboard() {
|
||||
Dashboard dashboard = new Dashboard();
|
||||
dashboard.setCountUserNum(dashboardMapper.selectUserCount());
|
||||
dashboard.setCountArticleNum(dashboardMapper.selectArticleCount());
|
||||
return dashboard;
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.rymcu.forest.web.api.open;
|
||||
|
||||
import com.rymcu.forest.core.result.GlobalResult;
|
||||
import com.rymcu.forest.core.result.GlobalResultGenerator;
|
||||
import com.rymcu.forest.dto.admin.Dashboard;
|
||||
import com.rymcu.forest.service.OpenDataService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created on 2022/3/14 13:49.
|
||||
*
|
||||
* @author ronger
|
||||
* @email ronger-x@outlook.com
|
||||
* @packageName com.rymcu.forest.web.api.open
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/open-data")
|
||||
public class OpenDataController {
|
||||
|
||||
@Resource
|
||||
private OpenDataService openDataService;
|
||||
|
||||
@GetMapping("/dashboard")
|
||||
public GlobalResult dashboard() {
|
||||
Dashboard dashboard = openDataService.dashboard();
|
||||
return GlobalResultGenerator.genSuccessResult(dashboard);
|
||||
}
|
||||
|
||||
@GetMapping("/last-thirty-days")
|
||||
public GlobalResult LastThirtyDaysData() {
|
||||
Map map = openDataService.lastThirtyDaysData();
|
||||
return GlobalResultGenerator.genSuccessResult(map);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user