diff --git a/src/main/java/com/rymcu/vertical/config/WebMvcConfigurer.java b/src/main/java/com/rymcu/vertical/config/WebMvcConfigurer.java index 4987214..c45c0b0 100644 --- a/src/main/java/com/rymcu/vertical/config/WebMvcConfigurer.java +++ b/src/main/java/com/rymcu/vertical/config/WebMvcConfigurer.java @@ -23,29 +23,33 @@ import java.util.List; /** * Spring MVC 配置 + * @author ronger */ @Configuration public class WebMvcConfigurer extends WebMvcConfigurationSupport { private final Logger logger = LoggerFactory.getLogger(WebMvcConfigurer.class); -// @Value("${env}") -// private String env;//当前激活的配置文件 @Override public void extendMessageConverters(List> converters) { FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter(); FastJsonConfig config = new FastJsonConfig(); - config.setSerializerFeatures(SerializerFeature.WriteMapNullValue,//保留空的字段 - SerializerFeature.WriteNullStringAsEmpty);//String null -> "" - //SerializerFeature.WriteNullNumberAsZero);//Number null -> 0 - config.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect); //关闭循环引用 + // 保留空的字段 + config.setSerializerFeatures(SerializerFeature.WriteMapNullValue, + //String null -> "" + SerializerFeature.WriteNullStringAsEmpty); + // SerializerFeature.WriteNullNumberAsZero);//Number null -> 0 + //关闭循环引用 + config.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect); converter.setFastJsonConfig(config); converter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON)); converter.setDefaultCharset(Charset.forName("UTF-8")); converters.add(0, converter); } - //解决跨域问题 + /** + * 解决跨域问题 + * */ @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") @@ -59,10 +63,11 @@ public class WebMvcConfigurer extends WebMvcConfigurationSupport { return new RestAuthTokenInterceptor(); } - //添加拦截器 + /** + * 添加拦截器 + * */ @Override public void addInterceptors(InterceptorRegistry registry) { - // TODO 先不拦截接口,进行测试 registry.addInterceptor(restAuthTokenInterceptor()).addPathPatterns("/api/**") .excludePathPatterns("/api/v1/console/**","/api/v1/article/articles/**","/api/v1/article/detail/**","/api/v1/topic/**","/api/v1/user/**"); diff --git a/src/main/java/com/rymcu/vertical/dto/admin/Dashboard.java b/src/main/java/com/rymcu/vertical/dto/admin/Dashboard.java new file mode 100644 index 0000000..d754087 --- /dev/null +++ b/src/main/java/com/rymcu/vertical/dto/admin/Dashboard.java @@ -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; +} diff --git a/src/main/java/com/rymcu/vertical/entity/Permission.java b/src/main/java/com/rymcu/vertical/entity/Permission.java index 5fc7688..aba2aef 100644 --- a/src/main/java/com/rymcu/vertical/entity/Permission.java +++ b/src/main/java/com/rymcu/vertical/entity/Permission.java @@ -11,6 +11,9 @@ import javax.persistence.Table; import java.io.Serializable; import java.util.Date; +/** + * @author ronger + */ @Data @Table(name = "vertical_permission") public class Permission implements Serializable,Cloneable { diff --git a/src/main/java/com/rymcu/vertical/mapper/DashboardMapper.java b/src/main/java/com/rymcu/vertical/mapper/DashboardMapper.java new file mode 100644 index 0000000..398afe9 --- /dev/null +++ b/src/main/java/com/rymcu/vertical/mapper/DashboardMapper.java @@ -0,0 +1,22 @@ +package com.rymcu.vertical.mapper; + +/** + * @author ronger + */ +public interface DashboardMapper { + /** + * 获取总用户数 + * @return + * */ + Integer selectUserCount(); + + /** + * 获取新注册用户数 + * @return + * */ + Integer selectNewUserCount(); + + Integer selectArticleCount(); + + Integer selectNewArticleCount(); +} diff --git a/src/main/java/com/rymcu/vertical/service/DashboardService.java b/src/main/java/com/rymcu/vertical/service/DashboardService.java new file mode 100644 index 0000000..33c2bb3 --- /dev/null +++ b/src/main/java/com/rymcu/vertical/service/DashboardService.java @@ -0,0 +1,15 @@ +package com.rymcu.vertical.service; + +import com.rymcu.vertical.dto.admin.Dashboard; + +/** + * @author ronger + */ +public interface DashboardService { + + /** + * 统计系统数据 + * @return + * */ + Dashboard dashboard(); +} diff --git a/src/main/java/com/rymcu/vertical/service/impl/DashboardServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/DashboardServiceImpl.java new file mode 100644 index 0000000..985c64a --- /dev/null +++ b/src/main/java/com/rymcu/vertical/service/impl/DashboardServiceImpl.java @@ -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; + } +} diff --git a/src/main/java/com/rymcu/vertical/web/api/admin/DashboardController.java b/src/main/java/com/rymcu/vertical/web/api/admin/DashboardController.java new file mode 100644 index 0000000..3a22b91 --- /dev/null +++ b/src/main/java/com/rymcu/vertical/web/api/admin/DashboardController.java @@ -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); + } +} diff --git a/src/main/java/mapper/DashboardMapper.xml b/src/main/java/mapper/DashboardMapper.xml new file mode 100644 index 0000000..0802056 --- /dev/null +++ b/src/main/java/mapper/DashboardMapper.xml @@ -0,0 +1,18 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/java/mapper/PermissionMapper.xml b/src/main/java/mapper/PermissionMapper.xml index 106503b..1120571 100644 --- a/src/main/java/mapper/PermissionMapper.xml +++ b/src/main/java/mapper/PermissionMapper.xml @@ -5,7 +5,7 @@ - +