仪表盘
This commit is contained in:
parent
1f1ce5b4c1
commit
6b363cf37b
@ -23,29 +23,33 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Spring MVC 配置
|
* Spring MVC 配置
|
||||||
|
* @author ronger
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
public class WebMvcConfigurer extends WebMvcConfigurationSupport {
|
public class WebMvcConfigurer extends WebMvcConfigurationSupport {
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(WebMvcConfigurer.class);
|
private final Logger logger = LoggerFactory.getLogger(WebMvcConfigurer.class);
|
||||||
// @Value("${env}")
|
|
||||||
// private String env;//当前激活的配置文件
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||||
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
|
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
|
||||||
FastJsonConfig config = new FastJsonConfig();
|
FastJsonConfig config = new FastJsonConfig();
|
||||||
config.setSerializerFeatures(SerializerFeature.WriteMapNullValue,//保留空的字段
|
// 保留空的字段
|
||||||
SerializerFeature.WriteNullStringAsEmpty);//String null -> ""
|
config.setSerializerFeatures(SerializerFeature.WriteMapNullValue,
|
||||||
//SerializerFeature.WriteNullNumberAsZero);//Number null -> 0
|
//String null -> ""
|
||||||
config.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect); //关闭循环引用
|
SerializerFeature.WriteNullStringAsEmpty);
|
||||||
|
// SerializerFeature.WriteNullNumberAsZero);//Number null -> 0
|
||||||
|
//关闭循环引用
|
||||||
|
config.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect);
|
||||||
converter.setFastJsonConfig(config);
|
converter.setFastJsonConfig(config);
|
||||||
converter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON));
|
converter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON));
|
||||||
converter.setDefaultCharset(Charset.forName("UTF-8"));
|
converter.setDefaultCharset(Charset.forName("UTF-8"));
|
||||||
converters.add(0, converter);
|
converters.add(0, converter);
|
||||||
}
|
}
|
||||||
|
|
||||||
//解决跨域问题
|
/**
|
||||||
|
* 解决跨域问题
|
||||||
|
* */
|
||||||
@Override
|
@Override
|
||||||
public void addCorsMappings(CorsRegistry registry) {
|
public void addCorsMappings(CorsRegistry registry) {
|
||||||
registry.addMapping("/**")
|
registry.addMapping("/**")
|
||||||
@ -59,10 +63,11 @@ public class WebMvcConfigurer extends WebMvcConfigurationSupport {
|
|||||||
return new RestAuthTokenInterceptor();
|
return new RestAuthTokenInterceptor();
|
||||||
}
|
}
|
||||||
|
|
||||||
//添加拦截器
|
/**
|
||||||
|
* 添加拦截器
|
||||||
|
* */
|
||||||
@Override
|
@Override
|
||||||
public void addInterceptors(InterceptorRegistry registry) {
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
// TODO 先不拦截接口,进行测试
|
|
||||||
registry.addInterceptor(restAuthTokenInterceptor()).addPathPatterns("/api/**")
|
registry.addInterceptor(restAuthTokenInterceptor()).addPathPatterns("/api/**")
|
||||||
.excludePathPatterns("/api/v1/console/**","/api/v1/article/articles/**","/api/v1/article/detail/**","/api/v1/topic/**","/api/v1/user/**");
|
.excludePathPatterns("/api/v1/console/**","/api/v1/article/articles/**","/api/v1/article/detail/**","/api/v1/topic/**","/api/v1/user/**");
|
||||||
|
|
||||||
|
22
src/main/java/com/rymcu/vertical/dto/admin/Dashboard.java
Normal file
22
src/main/java/com/rymcu/vertical/dto/admin/Dashboard.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package com.rymcu.vertical.dto.admin;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ronger
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class Dashboard {
|
||||||
|
|
||||||
|
private Integer countUserNum;
|
||||||
|
|
||||||
|
private Integer newUserNum;
|
||||||
|
|
||||||
|
private Integer countArticleNum;
|
||||||
|
|
||||||
|
private Integer newArticleNum;
|
||||||
|
|
||||||
|
private Integer countViewNum;
|
||||||
|
|
||||||
|
private Integer toadyViewNum;
|
||||||
|
}
|
@ -11,6 +11,9 @@ import javax.persistence.Table;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ronger
|
||||||
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Table(name = "vertical_permission")
|
@Table(name = "vertical_permission")
|
||||||
public class Permission implements Serializable,Cloneable {
|
public class Permission implements Serializable,Cloneable {
|
||||||
|
22
src/main/java/com/rymcu/vertical/mapper/DashboardMapper.java
Normal file
22
src/main/java/com/rymcu/vertical/mapper/DashboardMapper.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package com.rymcu.vertical.mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ronger
|
||||||
|
*/
|
||||||
|
public interface DashboardMapper {
|
||||||
|
/**
|
||||||
|
* 获取总用户数
|
||||||
|
* @return
|
||||||
|
* */
|
||||||
|
Integer selectUserCount();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取新注册用户数
|
||||||
|
* @return
|
||||||
|
* */
|
||||||
|
Integer selectNewUserCount();
|
||||||
|
|
||||||
|
Integer selectArticleCount();
|
||||||
|
|
||||||
|
Integer selectNewArticleCount();
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.rymcu.vertical.service;
|
||||||
|
|
||||||
|
import com.rymcu.vertical.dto.admin.Dashboard;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ronger
|
||||||
|
*/
|
||||||
|
public interface DashboardService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计系统数据
|
||||||
|
* @return
|
||||||
|
* */
|
||||||
|
Dashboard dashboard();
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package com.rymcu.vertical.service.impl;
|
||||||
|
|
||||||
|
import com.rymcu.vertical.dto.admin.Dashboard;
|
||||||
|
import com.rymcu.vertical.mapper.DashboardMapper;
|
||||||
|
import com.rymcu.vertical.service.DashboardService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ronger
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class DashboardServiceImpl implements DashboardService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private DashboardMapper dashboardMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dashboard dashboard() {
|
||||||
|
Dashboard dashboard = new Dashboard();
|
||||||
|
dashboard.setCountUserNum(dashboardMapper.selectUserCount());
|
||||||
|
dashboard.setNewUserNum(dashboardMapper.selectNewUserCount());
|
||||||
|
dashboard.setCountArticleNum(dashboardMapper.selectArticleCount());
|
||||||
|
dashboard.setNewArticleNum(dashboardMapper.selectNewArticleCount());
|
||||||
|
// TODO 待完成浏览量统计
|
||||||
|
dashboard.setCountViewNum(1000);
|
||||||
|
dashboard.setToadyViewNum(100);
|
||||||
|
return dashboard;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.rymcu.vertical.web.api.admin;
|
||||||
|
|
||||||
|
import com.rymcu.vertical.core.result.GlobalResult;
|
||||||
|
import com.rymcu.vertical.core.result.GlobalResultGenerator;
|
||||||
|
import com.rymcu.vertical.dto.admin.Dashboard;
|
||||||
|
import com.rymcu.vertical.service.DashboardService;
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ronger
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/v1/admin/dashboard")
|
||||||
|
public class DashboardController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private DashboardService dashboardService;
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public GlobalResult dashboard(){
|
||||||
|
Dashboard dashboard = dashboardService.dashboard();
|
||||||
|
return GlobalResultGenerator.genSuccessResult(dashboard);
|
||||||
|
}
|
||||||
|
}
|
18
src/main/java/mapper/DashboardMapper.xml
Normal file
18
src/main/java/mapper/DashboardMapper.xml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.rymcu.vertical.mapper.DashboardMapper">
|
||||||
|
<select id="selectUserCount" resultType="java.lang.Integer">
|
||||||
|
select count(*) from vertical_user
|
||||||
|
</select>
|
||||||
|
<select id="selectNewUserCount" resultType="java.lang.Integer">
|
||||||
|
select count(*) from vertical_user where created_time between date_sub(sysdate(),interval 1 day)
|
||||||
|
and date_sub(sysdate(),interval - 1 day)
|
||||||
|
</select>
|
||||||
|
<select id="selectArticleCount" resultType="java.lang.Integer">
|
||||||
|
select count(*) from vertical_article
|
||||||
|
</select>
|
||||||
|
<select id="selectNewArticleCount" resultType="java.lang.Integer">
|
||||||
|
select count(*) from vertical_article where created_time between date_sub(sysdate(),interval 1 day)
|
||||||
|
and date_sub(sysdate(),interval - 1 day)
|
||||||
|
</select>
|
||||||
|
</mapper>
|
@ -5,7 +5,7 @@
|
|||||||
<!--
|
<!--
|
||||||
WARNING - @mbg.generated
|
WARNING - @mbg.generated
|
||||||
-->
|
-->
|
||||||
<id column="id" property="id"/>
|
<id column="id" property="idPermission"/>
|
||||||
<result column="permission_category" property="permissionCategory"/>
|
<result column="permission_category" property="permissionCategory"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user