优化代码

This commit is contained in:
smallchill 2019-02-21 14:22:01 +08:00
parent f8963a439a
commit c7112fd9d7
21 changed files with 88 additions and 60 deletions

View File

@ -176,7 +176,7 @@ recommend that a file or class name and description of purpose be included on
the same "printed page" as the copyright notice for easier identification within the same "printed page" as the copyright notice for easier identification within
third-party archives. third-party archives.
Copyright 2019 smallchill Copyright 2019 ZhuangQian (smallchill@163.com)
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

View File

@ -6,17 +6,23 @@
* 官网地址:[https://bladex.vip](https://bladex.vip) * 官网地址:[https://bladex.vip](https://bladex.vip)
## 在线演示 ## 在线演示
* 演示地址:[https://sword.bladex.vip](https://sword.bladex.vip) * Sword演示地址[https://sword.bladex.vip](https://sword.bladex.vip)
* Saber演示地址[https://saber.avue.top](https://saber.avue.top)
## 项目地址 ## 后端项目地址
* [github](https://github.com/chillzhuang/SpringBlade) * [Gitee地址](https://gitee.com/smallc/SpringBlade)
* [gitee](https://gitee.com/smallc/SpringBlade) * [Github地址](https://github.com/chillzhuang/SpringBlade)
## 前端项目地址
* [Sword--基于React](https://gitee.com/smallc/Sword)
* [Saber--基于Vue](https://gitee.com/smallc/Saber)
## 主要特性&&变化 ## 主要特性&&变化
* 采用前后端分离的模式,前端单独开源出一个框架:[Sword](https://github.com/chillzhuang/Sword)主要选型技术为React、Ant Design、Umi、Dva * 采用前后端分离的模式前端开源出一个基于React的框架[Sword](https://gitee.com/smallc/Sword)主要选型技术为React、Ant Design、Umi、Dva
* 后端采用SpringCloud全家桶并同时对其基础组件做了高度的封装单独开源出一个框架[BladeTool](https://github.com/chillzhuang/blade-tool.git) * 采用前后端分离的模式前端开源出一个基于Vue的框架[Saber](https://gitee.com/smallc/Saber)主要选型技术为Vue、VueX、Avue、Element-UI
* [BladeTool](https://github.com/chillzhuang/blade-tool.git)已推送至Maven中央库直接引入即可减少了工程的臃肿也可更注重于业务开发 * 后端采用SpringCloud全家桶并同时对其基础组件做了高度的封装单独开源出一个框架[BladeTool](https://github.com/chillzhuang/blade-tool)
* 集成Sentinel从流量控制、熔断降级、系统负载保护等多个维度保护服务的稳定性。 * [BladeTool](https://github.com/chillzhuang/blade-tool)已推送至Maven中央库直接引入即可减少了工程的臃肿也可更注重于业务开发
* 集成Sentinel从流量控制、熔断降级、系统负载等多个维度保护服务的稳定性。
* 注册中心、配置中心选型Nacos为工程瘦身的同时加强各模块之间的联动。 * 注册中心、配置中心选型Nacos为工程瘦身的同时加强各模块之间的联动。
* 使用Traefik进行反向代理监听后台变化自动化应用新的配置文件。 * 使用Traefik进行反向代理监听后台变化自动化应用新的配置文件。
* 部署使用Docker或K8s + Jenkins * 部署使用Docker或K8s + Jenkins
@ -31,6 +37,9 @@
## 技术文档 ## 技术文档
* [SpringBlade开发手册](https://gitee.com/smallc/SpringBlade/wikis/SpringBlade开发手册) * [SpringBlade开发手册](https://gitee.com/smallc/SpringBlade/wikis/SpringBlade开发手册)
## 单工程SpringBoot版
* [SpringBoot版](https://gitee.com/smallc/SpringBlade/tree/2.0-boot/)
## 工程结构 ## 工程结构
``` ```
SpringBlade SpringBlade
@ -39,7 +48,7 @@ SpringBlade
├── blade-gateway -- Spring Cloud 网关 ├── blade-gateway -- Spring Cloud 网关
├── blade-ops -- 运维中心 ├── blade-ops -- 运维中心
├ ├── blade-admin -- spring-cloud后台管理 ├ ├── blade-admin -- spring-cloud后台管理
├ ├── blade-codegen -- 代码生成 ├ ├── blade-develop -- 代码生成
├── blade-service -- 业务模块 ├── blade-service -- 业务模块
├ ├── blade-desk -- 工作台模块 ├ ├── blade-desk -- 工作台模块
├ ├── blade-log -- 日志模块 ├ ├── blade-log -- 日志模块
@ -80,12 +89,14 @@ Apache Licence也是对商业应用友好的许可。使用者也可以在需要
注意若禁止条款被发现有权追讨19999的授权费。 注意若禁止条款被发现有权追讨19999的授权费。
## 注 ## 注
* SpringBlade前端UI项目地址[Sword](https://gitee.com/smallc/Sword) * 前端UI项目地址(基于React)[Sword](https://gitee.com/smallc/Sword)
* SpringBlade核心框架项目地址[Blade-Tool](https://github.com/chillzhuang/blade-tool.git) * 前端UI项目地址(基于Vue)[Saber](https://gitee.com/smallc/Saber)
* SpringBlade交流群`477853168` * 核心框架项目地址:[BladeTool](https://github.com/chillzhuang/blade-tool.git)
* 交流群:`477853168`
# 界面一览 # 界面
## 监控界面一览
<table> <table>
<tr> <tr>
<td><img src="https://gitee.com/smallc/SpringBlade/raw/master/pic/springblade-k8s1.png"/></td> <td><img src="https://gitee.com/smallc/SpringBlade/raw/master/pic/springblade-k8s1.png"/></td>
@ -111,6 +122,10 @@ Apache Licence也是对商业应用友好的许可。使用者也可以在需要
<td><img src="https://gitee.com/smallc/SpringBlade/raw/master/pic/springblade-swagger1.png"/></td> <td><img src="https://gitee.com/smallc/SpringBlade/raw/master/pic/springblade-swagger1.png"/></td>
<td><img src="https://gitee.com/smallc/SpringBlade/raw/master/pic/springblade-swagger2.png"/></td> <td><img src="https://gitee.com/smallc/SpringBlade/raw/master/pic/springblade-swagger2.png"/></td>
</tr> </tr>
</table>
## Sword界面一览
<table>
<tr> <tr>
<td><img src="https://gitee.com/smallc/SpringBlade/raw/master/pic/sword-main.png"/></td> <td><img src="https://gitee.com/smallc/SpringBlade/raw/master/pic/sword-main.png"/></td>
<td><img src="https://gitee.com/smallc/SpringBlade/raw/master/pic/sword-menu.png"/></td> <td><img src="https://gitee.com/smallc/SpringBlade/raw/master/pic/sword-menu.png"/></td>
@ -131,4 +146,20 @@ Apache Licence也是对商业应用友好的许可。使用者也可以在需要
<td><img src="https://gitee.com/smallc/SpringBlade/raw/master/pic/sword-locale-cn.png"/></td> <td><img src="https://gitee.com/smallc/SpringBlade/raw/master/pic/sword-locale-cn.png"/></td>
<td><img src="https://gitee.com/smallc/SpringBlade/raw/master/pic/sword-locale-us.png"/></td> <td><img src="https://gitee.com/smallc/SpringBlade/raw/master/pic/sword-locale-us.png"/></td>
</tr> </tr>
</table>
## Saber界面一览
<table>
<tr>
<td><img src="https://gitee.com/smallc/SpringBlade/raw/master/pic/saber-user.png"/></td>
<td><img src="https://gitee.com/smallc/SpringBlade/raw/master/pic/saber-role.png"/></td>
</tr>
<tr>
<td><img src="https://gitee.com/smallc/SpringBlade/raw/master/pic/saber-dict.png"/></td>
<td><img src="https://gitee.com/smallc/SpringBlade/raw/master/pic/saber-dict-select.png"/></td>
</tr>
<tr>
<td><img src="https://gitee.com/smallc/SpringBlade/raw/master/pic/saber-log.png"/></td>
<td><img src="https://gitee.com/smallc/SpringBlade/raw/master/pic/saber-code.png"/></td>
</tr>
</table> </table>

View File

@ -62,7 +62,7 @@ public class AuthController {
User user = res.getData().getUser(); User user = res.getData().getUser();
//验证用户 //验证用户
if (user == null) { if (user == null || Func.isEmpty(user.getId())) {
return R.fail("用户名或密码不正确"); return R.fail("用户名或密码不正确");
} }

View File

@ -23,6 +23,11 @@
<artifactId>blade-core-boot</artifactId> <artifactId>blade-core-boot</artifactId>
<version>${blade.tool.version}</version> <version>${blade.tool.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-common</artifactId>
<version>${blade.project.version}</version>
</dependency>
<dependency> <dependency>
<groupId>com.baomidou</groupId> <groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId> <artifactId>mybatis-plus-generator</artifactId>

View File

@ -248,7 +248,7 @@ public class BladeGenerator {
*/ */
private Properties getProperties() { private Properties getProperties() {
// 读取配置文件 // 读取配置文件
Resource resource = new ClassPathResource("generator.properties"); Resource resource = new ClassPathResource("/templates/props/generator.properties");
Properties props = new Properties(); Properties props = new Properties();
try { try {
props = PropertiesLoaderUtils.loadProperties(resource); props = PropertiesLoaderUtils.loadProperties(resource);

View File

@ -30,7 +30,7 @@ class $!{entity}View extends PureComponent {
params: { id }, params: { id },
}, },
} = this.props; } = this.props;
router.push(`/$!{cfg.servicePackage}/$!{table.entityPath}/edit/${id}`); router.push(`/$!{cfg.servicePackage}/$!{table.entityPath}/edit/$!{id}`);
}; };
render() { render() {

View File

@ -23,7 +23,6 @@ import org.springblade.core.secure.BladeUser;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springblade.core.tool.support.Kv; import org.springblade.core.tool.support.Kv;
import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.Func;
import org.springblade.system.dto.MenuDTO;
import org.springblade.system.entity.Menu; import org.springblade.system.entity.Menu;
import org.springblade.system.feign.IDictClient; import org.springblade.system.feign.IDictClient;
import org.springblade.system.service.IMenuService; import org.springblade.system.service.IMenuService;
@ -33,7 +32,6 @@ import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -154,10 +152,7 @@ public class MenuController extends BladeController {
@GetMapping("auth-routes") @GetMapping("auth-routes")
@ApiOperation(value = "菜单的角色权限", position = 8) @ApiOperation(value = "菜单的角色权限", position = 8)
public R<List<Kv>> authRoutes(BladeUser user) { public R<List<Kv>> authRoutes(BladeUser user) {
List<Kv> list = new ArrayList<>(); return R.data(menuService.authRoutes(user));
List<MenuDTO> routes = menuService.authRoutes(Func.toIntList(user.getRoleId()));
routes.forEach(route -> list.add(Kv.init().set(route.getPath(), Kv.init().set("authority", Func.toStrArray(route.getAlias())))));
return R.data(list);
} }
} }

View File

@ -17,7 +17,8 @@ package org.springblade.system.service;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import org.springblade.system.dto.MenuDTO; import org.springblade.core.secure.BladeUser;
import org.springblade.core.tool.support.Kv;
import org.springblade.system.entity.Menu; import org.springblade.system.entity.Menu;
import org.springblade.system.vo.MenuVO; import org.springblade.system.vo.MenuVO;
@ -80,9 +81,9 @@ public interface IMenuService extends IService<Menu> {
/** /**
* 获取配置的角色权限 * 获取配置的角色权限
* @param roleIds * @param user
* @return * @return
*/ */
List<MenuDTO> authRoutes(List<Integer> roleIds); List<Kv> authRoutes(BladeUser user);
} }

View File

@ -19,7 +19,9 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.tool.node.ForestNodeMerger; import org.springblade.core.tool.node.ForestNodeMerger;
import org.springblade.core.tool.support.Kv;
import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.Func;
import org.springblade.system.dto.MenuDTO; import org.springblade.system.dto.MenuDTO;
import org.springblade.system.entity.Menu; import org.springblade.system.entity.Menu;
@ -31,10 +33,7 @@ import org.springblade.system.vo.MenuVO;
import org.springblade.system.wrapper.MenuWrapper; import org.springblade.system.wrapper.MenuWrapper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Comparator; import java.util.*;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -98,8 +97,14 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM
} }
@Override @Override
public List<MenuDTO> authRoutes(List<Integer> roleIds) { public List<Kv> authRoutes(BladeUser user) {
return baseMapper.authRoutes(roleIds); if (Func.isEmpty(user)) {
return null;
}
List<MenuDTO> routes = baseMapper.authRoutes(Func.toIntList(user.getRoleId()));
List<Kv> list = new ArrayList<>();
routes.forEach(route -> list.add(Kv.init().set(route.getPath(), Kv.init().set("authority", Func.toStrArray(route.getAlias())))));
return list;
} }
} }

View File

@ -69,8 +69,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
roleMenus.add(roleMenu); roleMenus.add(roleMenu);
})); }));
// 新增配置 // 新增配置
roleMenuService.saveBatch(roleMenus); return roleMenuService.saveBatch(roleMenus);
return true;
} }
} }

View File

@ -30,6 +30,7 @@ import org.springblade.core.tool.utils.Func;
import org.springblade.system.feign.IDictClient; import org.springblade.system.feign.IDictClient;
import org.springblade.system.user.entity.User; import org.springblade.system.user.entity.User;
import org.springblade.system.user.service.IUserService; import org.springblade.system.user.service.IUserService;
import org.springblade.system.user.vo.UserVO;
import org.springblade.system.user.wrapper.UserWrapper; import org.springblade.system.user.wrapper.UserWrapper;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
@ -56,7 +57,7 @@ public class UserController {
*/ */
@ApiOperation(value = "查看详情", notes = "传入id", position = 1) @ApiOperation(value = "查看详情", notes = "传入id", position = 1)
@GetMapping("/detail") @GetMapping("/detail")
public R<User> detail(User user) { public R<UserVO> detail(User user) {
User detail = userService.getOne(Condition.getQueryWrapper(user)); User detail = userService.getOne(Condition.getQueryWrapper(user));
UserWrapper userWrapper = new UserWrapper(userService, dictClient); UserWrapper userWrapper = new UserWrapper(userService, dictClient);
return R.data(userWrapper.entityVO(detail)); return R.data(userWrapper.entityVO(detail));
@ -71,9 +72,10 @@ public class UserController {
@ApiImplicitParam(name = "realName", value = "姓名", paramType = "query", dataType = "string") @ApiImplicitParam(name = "realName", value = "姓名", paramType = "query", dataType = "string")
}) })
@ApiOperation(value = "列表", notes = "传入account和realName", position = 2) @ApiOperation(value = "列表", notes = "传入account和realName", position = 2)
public R<IPage<User>> list(@ApiIgnore @RequestParam Map<String, Object> user, Query query) { public R<IPage<UserVO>> list(@ApiIgnore @RequestParam Map<String, Object> user, Query query) {
IPage<User> pages = userService.page(Condition.getPage(query), Condition.getQueryWrapper(user, User.class)); IPage<User> pages = userService.page(Condition.getPage(query), Condition.getQueryWrapper(user, User.class));
return R.data(pages); UserWrapper userWrapper = new UserWrapper(userService, dictClient);
return R.data(userWrapper.pageVO(pages));
} }
/** /**

View File

@ -4,18 +4,18 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>blade-service</artifactId>
<name>${project.artifactId}</name>
<version>2.0.0</version>
<packaging>pom</packaging>
<description>SpringBlade 微服务集合</description>
<parent> <parent>
<groupId>org.springblade</groupId> <groupId>org.springblade</groupId>
<artifactId>SpringBlade</artifactId> <artifactId>SpringBlade</artifactId>
<version>2.0.0</version> <version>2.0.0</version>
</parent> </parent>
<artifactId>blade-service</artifactId>
<name>${project.artifactId}</name>
<version>2.0.0</version>
<packaging>pom</packaging>
<description>SpringBlade 微服务集合</description>
<modules> <modules>
<module>blade-desk</module> <module>blade-desk</module>
<module>blade-log</module> <module>blade-log</module>

View File

@ -18,10 +18,10 @@ spring:
#feign配置 #feign配置
feign: feign:
#hystrix: hystrix:
#enabled: true
sentinel:
enabled: true enabled: true
#sentinel:
#enabled: true
okhttp: okhttp:
enabled: true enabled: true
httpclient: httpclient:
@ -39,7 +39,7 @@ hystrix:
execution: execution:
isolation: isolation:
thread: thread:
timeoutInMilliseconds: 720000 timeoutInMilliseconds: 5000
#ribbon配置 #ribbon配置
ribbon: ribbon:

BIN
pic/saber-code.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 KiB

BIN
pic/saber-dict-select.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 352 KiB

BIN
pic/saber-dict.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 388 KiB

BIN
pic/saber-log.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 468 KiB

BIN
pic/saber-role.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 KiB

BIN
pic/saber-user.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 300 KiB

16
pom.xml
View File

@ -9,13 +9,13 @@
<packaging>pom</packaging> <packaging>pom</packaging>
<properties> <properties>
<blade.tool.version>2.0.0</blade.tool.version> <blade.tool.version>2.0.6</blade.tool.version>
<blade.project.version>2.0.0</blade.project.version> <blade.project.version>2.0.0</blade.project.version>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<swagger.version>2.9.2</swagger.version> <swagger.version>2.9.2</swagger.version>
<swagger.models.version>1.5.21</swagger.models.version> <swagger.models.version>1.5.21</swagger.models.version>
<swagger.bootstrapui.version>1.8.8</swagger.bootstrapui.version> <swagger.bootstrapui.version>1.8.9</swagger.bootstrapui.version>
<mybatis.plus.version>3.0.7.1</mybatis.plus.version> <mybatis.plus.version>3.0.7.1</mybatis.plus.version>
<curator.framework.version>4.0.1</curator.framework.version> <curator.framework.version>4.0.1</curator.framework.version>
<protostuff.version>1.6.0</protostuff.version> <protostuff.version>1.6.0</protostuff.version>
@ -25,7 +25,7 @@
<spring.boot.version>2.0.8.RELEASE</spring.boot.version> <spring.boot.version>2.0.8.RELEASE</spring.boot.version>
<spring.cloud.version>Finchley.SR2</spring.cloud.version> <spring.cloud.version>Finchley.SR2</spring.cloud.version>
<spring.platform.version>Cairo-SR5</spring.platform.version> <spring.platform.version>Cairo-SR7</spring.platform.version>
<!-- 推荐使用Harbor --> <!-- 推荐使用Harbor -->
<docker.registry.url>192.168.186.129</docker.registry.url> <docker.registry.url>192.168.186.129</docker.registry.url>
@ -79,16 +79,6 @@
<artifactId>spring-boot-devtools</artifactId> <artifactId>spring-boot-devtools</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies> </dependencies>
<build> <build>