Skip to content

Commit

Permalink
[🐶加强] example更工程化一些,基础表,权限
Browse files Browse the repository at this point in the history
[🐷变更] 默认关闭redis依赖
[🐵新增] flywave版本支持分隔,便于人眼识别
  • Loading branch information
trydofor committed Jun 21, 2020
1 parent 6c75255 commit a1409a1
Show file tree
Hide file tree
Showing 130 changed files with 8,014 additions and 698 deletions.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<guava.version>29.0-jre</guava.version>
<spring-boot.version>2.2.7.RELEASE</spring-boot.version>
<commons-io.version>2.7</commons-io.version>
<redisson.version>3.12.5</redisson.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -69,7 +70,6 @@
<artifactId>wings-slardar</artifactId>
<version>${wings.version}</version>
</dependency>
<!-- redefine -->
<!--flywave sphere-->
<dependency>
<groupId>org.apache.shardingsphere</groupId>
Expand All @@ -87,6 +87,12 @@
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<!-- for Spring Data Redis v.2.2.x -->
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-data-22</artifactId>
<version>${redisson.version}</version>
</dependency>
<!-- utils -->
<dependency>
<groupId>com.google.guava</groupId>
Expand Down
64 changes: 59 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,39 @@ Wings是springboot的一个脚手架,没有魔法和定制,主要有以下
* [Apache ShardingSphere](https://shardingsphere.apache.org/index_zh.html)
* [Jooq - 强类型 sql-mapping](https://www.jooq.org/)

## 0.2.命名风格
## 0.2.编码风格

使用`idea`作为开发`IDE`,可使用`code style``live templates`
使用`IntelliJIdea`作为开发`IDE`,可使用`code style``live templates`
`wings-idea-style.xml``Setting/Editor/Code Style`导入。

`wings-idea-live.xml`需要手动放到`$config/templates/`
参考 https://www.jetbrains.com/help/idea/sharing-live-templates.html
`wings-idea-live.xml`需要手动放到`$config/templates/`,没有则新建

* WIN `%HOMEPATH%\.IntelliJIdea2019.2\config`
* LIN `~/.IntelliJIdea2019.2/config`
* MAC `~/Library/Preferences/IntelliJIdea2019.2`
* MAC `~/Library/ApplicationSupport/JetBrains/IntelliJIdea2020.1`

参考资料
* [sharing-live-templates](https://www.jetbrains.com/help/idea/sharing-live-templates.html)
* [2020.1 and above versions](https://www.jetbrains.com/help/idea/tuning-the-ide.html#default-dirs)
* [2019.3.x and below versions](https://www.jetbrains.com/help/idea/2019.3/tuning-the-ide.html#default-dirs)


安装以下插件
* .ignore - 和版本管理中ignore有关的。
* CheckStyle - 代码质量
* GeneateAllSetter - alt-enter 生成全部 po.setXxx("")
* Git Flow Integration - 集成了git-flow
* GitToolBox - 自动 fetch
* Grep Console - 控制台的日志分颜色显示和过滤
* kotlin - 默认安装了
* lombok - IntelliJ Lombok plugin
* Maven Helper - 帮助管理maven
* Quick File Preview - 单击快速浏览文件
* Rainbow Brackets - 彩虹括号
* Request mapper - 快速查找 mapping
* Statistic - 统计一下自己的代码
* String Manipulation - 对字符串的各种操作和转换。

### 0.2.1.Java风格,遵循标准的java规范,但**可读性优先**

Expand All @@ -67,7 +89,7 @@ Wings是springboot的一个脚手架,没有魔法和定制,主要有以下

系统内有2种时间`系统时间``本地时间`,数据库和 java 映射上,

* `日期时间`,以`DATETIME``LocalDateTime`存储。
* `日期时间`,以`DATETIME(3)``LocalDateTime`存储。
* `日期`,以`DATE``LocalDate`存储。
* `时间`,以`TIME``LocalTime`存储。

Expand Down Expand Up @@ -121,6 +143,16 @@ public interface TradeService {
}
```

### 0.2.8.枚举类和code/const值

在service层,要求强类型,所以code/const都以enum传递。
通过自动java模板生成enum,通过*EnumUtil,转换。

在db层,以基本类型(int,varchar)读取和写入。

在用户层,以多国语形式显示枚举内容


## 0.3.技术选型

技术选型,遵循Unix哲学,主要回答,`为什么``为什么不?`
Expand Down Expand Up @@ -202,4 +234,26 @@ hostname
cat /etc/hosts
# 在localhost后面,填上 trydofors-Hackintosh.local
127.0.0.1 localhost trydofors-Hackintosh.local
```

### 002.工程中哪些参数是必须打开的

``` bash
# 找到所以开关文件
find . -name 'wings-conditional-manager.properties' \
| egrep -v -E 'target/|example/'

./wings-slardar/src/main/resources/wings-conf/wings-conditional-manager.properties
./wings-faceless/src/main/resources/wings-conf/wings-conditional-manager.properties
./wings-silencer/src/main/resources/wings-conf/wings-conditional-manager.properties

# 找到所false的开关
find . -name 'wings-conditional-manager.properties' \
| egrep -v -E 'target/|example/' \
| xargs grep 'false'

# 以下2个需要在flywave和enum时开启
spring.wings.flywave.enabled=false
spring.wings.enumi18n.enabled=false

```
61 changes: 38 additions & 23 deletions wings-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<properties>
<maven.test.skip>true</maven.test.skip>
<wings.version>2.2.7-SNAPSHOT</wings.version>
<swagger2.version>2.9.2</swagger2.version>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
Expand Down Expand Up @@ -52,6 +53,10 @@
<groupId>pro.fessional</groupId>
<artifactId>wings-slardar</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand All @@ -62,32 +67,26 @@
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<!-- redis -->
<!--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
-->
<!-- <dependency>-->
<!-- <groupId>org.redisson</groupId>-->
<!-- <artifactId>redisson-spring-data-22</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-data-redis</artifactId>-->
<!-- </dependency>-->
<!-- websocket -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-messaging</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-websocket</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.security</groupId>-->
<!-- <artifactId>spring-security-messaging</artifactId>-->
<!-- </dependency>-->
<!-- ops -->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
Expand All @@ -104,7 +103,23 @@
<artifactId>jooq-codegen</artifactId>
<optional>true</optional>
</dependency>
<!-- swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger2.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger2.version}</version>
</dependency>
<!-- test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
1 change: 0 additions & 1 deletion wings-example/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* 了解 `maven`,缺什么,补什么。
* 了解 `spring*``看官方文档,不要百度` x 3!
* 了解 `mysql*`数据库,mysql,mariadb,percona
* 了解 `redis`缓存

## 4.2.演示内容

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package pro.fessional.wings.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import pro.fessional.mirana.data.DataResult;
import pro.fessional.mirana.data.R;

/**
* @author trydofor
* @since 2020-06-21
*/
@ControllerAdvice
@Slf4j
public class ErrorController extends ResponseEntityExceptionHandler {

@ExceptionHandler(OAuth2Exception.class)
@ResponseBody
public DataResult<String> handleOAuth2Exception(OAuth2Exception ex) {
String err = ex.toString();
log.info("wings handle exception, oauth2 {}", err);
return R.ng(err);
}

@ExceptionHandler(Exception.class)
@ResponseBody
public DataResult<String> handleAnyException(Exception ex) {
String c = ex.getClass().getSimpleName();
log.info("wings handle exception, " + c, ex);
return R.ng("unknown exception, " + c + ":" + ex.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package pro.fessional.wings.example.controller;

import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;
import pro.fessional.wings.slardar.security.WingsOAuth2xHelper;
import pro.fessional.wings.slardar.security.WingsTokenStore;
import pro.fessional.wings.slardar.servlet.TypedRequestUtil;

import javax.servlet.http.HttpServletRequest;

/**
* @author trydofor
* @since 2019-11-13
*/
@Controller
public class LoginController {

@Setter(onMethod = @__({@Autowired}))
private WingsOAuth2xHelper wingsOAuth2XHelper;

@Setter(onMethod = @__({@Autowired}))
private WingsTokenStore wingsTokenStore;

@Setter(onMethod = @__({@Autowired}))
private RestTemplate restTemplate;

@Setter(onMethod = @__({@Value("${wings.oauth.token.url}")}))
private String oauthTokenUrl;

@Setter(onMethod = @__({@Value("${wings.slardar.oauth2x.client.staff.client-id}")}))
private String oauthClientId;

@PostMapping(value = {"/login.json"})
@ResponseBody
public OAuth2AccessToken login(@RequestParam("username") String username, @RequestParam("password") String password) {
WingsOAuth2xHelper.Login info = new WingsOAuth2xHelper.Login();
info.setLoginUrl(oauthTokenUrl);
info.setClientId(oauthClientId); // 必须配置中有,否则失败
info.setUsername(username);
info.setPassword(password);
info.setOauthPasswordAlias("name_pass");
info.setClientIdAlias("web_admin");
info.setGrantTypeAlias("admin");
//info.setAccessToken3rd("bac0c873-e1cc-4740-8b9b-a903dcaaedfe");

return wingsOAuth2XHelper.login(restTemplate, info);
}

@RequestMapping(value = {"/logout.json"})
@ResponseBody
public String logout(HttpServletRequest request) {
String accessToken = TypedRequestUtil.getAccessToken(request);
wingsOAuth2XHelper.logout(wingsTokenStore, accessToken);
return "logout " + accessToken;
}
}

0 comments on commit a1409a1

Please sign in to comment.