├── docs ├── .nojekyll ├── CNAME ├── assets │ └── images │ │ ├── favicon.png │ │ └── oxygen-logo.png ├── en-us │ ├── _navbar.md │ ├── _sidebar.md │ ├── advance │ │ ├── Database-Config.md │ │ ├── Advance-Usage.md │ │ └── Flysql-Builder.md │ └── contributing.md ├── _coverpage.md ├── _404.md └── index.html ├── VERSION.md ├── .mailmap ├── spring-oxygen-core ├── src │ ├── main │ │ ├── resources │ │ │ ├── test.txt │ │ │ ├── templates2 │ │ │ │ └── test.ftl │ │ │ ├── META-INF │ │ │ │ └── spring.factories │ │ │ └── config │ │ │ │ └── application.yml │ │ └── java │ │ │ └── com │ │ │ └── isxcode │ │ │ └── oxygen │ │ │ └── core │ │ │ ├── date │ │ │ └── DateUtils.java │ │ │ ├── exception │ │ │ └── OxygenException.java │ │ │ ├── secret │ │ │ ├── SecretConstants.java │ │ │ ├── AesUtils.java │ │ │ └── RsaUtils.java │ │ │ ├── random │ │ │ └── RandomUtils.java │ │ │ ├── matcher │ │ │ └── MatcherUtils.java │ │ │ ├── reflect │ │ │ ├── FieldBody.java │ │ │ ├── ReflectConstants.java │ │ │ └── ReflectUtils.java │ │ │ ├── excel │ │ │ └── ExcelType.java │ │ │ ├── package-info.java │ │ │ ├── snowflake │ │ │ └── SnowflakeUtils.java │ │ │ ├── xml │ │ │ └── XmlUtils.java │ │ │ ├── config │ │ │ └── OxygenCoreAutoConfiguration.java │ │ │ ├── freemarker │ │ │ └── FreemarkerUtils.java │ │ │ ├── http │ │ │ └── HttpUtils.java │ │ │ ├── file │ │ │ └── FileUtils.java │ │ │ └── email │ │ │ └── EmailUtils.java │ └── test │ │ ├── resources │ │ ├── templates2 │ │ │ └── test.ftl │ │ └── application-test.yml │ │ └── java │ │ └── com │ │ └── isxcode │ │ └── oxygen │ │ └── core │ │ ├── DateUtilsTests.java │ │ ├── RandomUtilsTests.java │ │ ├── MatcherUtilsTests.java │ │ ├── CommandUtilsTests.java │ │ ├── SnowflakeUtilsTests.java │ │ ├── FileUtilsTests.java │ │ ├── XmlUtilsTests.java │ │ ├── ExcelUtilsTests.java │ │ ├── HttpUtilsTests.java │ │ ├── ReflectUtilsTests.java │ │ ├── EmailUtilsTests.java │ │ ├── pojo │ │ └── Dog.java │ │ ├── FreemarkerUtilsTests.java │ │ └── SecretUtilsTest.java └── build.gradle ├── spring-oxygen-cli ├── src │ └── main │ │ ├── resources │ │ ├── templates │ │ │ ├── project │ │ │ │ ├── application-properties.ftl │ │ │ │ ├── settings-gradle.ftl │ │ │ │ ├── application-test.ftl │ │ │ │ ├── application-controller.ftl │ │ │ │ ├── build-gradle.ftl │ │ │ │ ├── gitignore.ftl │ │ │ │ └── readme.ftl │ │ │ └── entity │ │ │ │ ├── innerService.java.ftl │ │ │ │ ├── repository.java.ftl │ │ │ │ ├── service.java.ftl │ │ │ │ ├── entity.java.ftl │ │ │ │ └── controller.java.ftl │ │ ├── banner.txt │ │ └── application.yml │ │ └── java │ │ └── com │ │ └── isxcode │ │ └── oxygen │ │ └── cli │ │ ├── entity │ │ ├── TableInfo.java │ │ ├── FreecodeInfo.java │ │ └── TableColumnInfo.java │ │ ├── exception │ │ └── FreecodeException.java │ │ ├── pojo │ │ └── ProjectInfo.java │ │ ├── OxygenCliApplication.java │ │ ├── annotation │ │ └── EnableFreecode.java │ │ ├── store │ │ └── LocalStorage.java │ │ ├── constant │ │ └── FreecodeConstants.java │ │ ├── config │ │ ├── BashConfig.java │ │ └── FreecodeAutoConfiguration.java │ │ ├── controller │ │ └── FreecodeController.java │ │ ├── properties │ │ └── FreecodeProperties.java │ │ ├── repository │ │ └── FreecodeRepository.java │ │ └── service │ │ └── FreecodeService.java ├── README.md └── build.gradle ├── .github ├── FUNDING.yml ├── secring.gpg ├── PULL_REQUEST_TEMPLATE.md ├── codeql │ └── codeql-config.yml ├── ISSUE_TEMPLATE │ ├── arts.md │ ├── features.md │ └── issues.md ├── dependabot.yml └── workflows │ ├── deploy-docs.yml │ ├── release-sonatype.yml │ ├── release-github.yml │ └── build.yml ├── .gitpod.yml ├── CHANGELOG.md ├── .vscode └── settings.json ├── CONTRIBUTING.md ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .lgtm.yml ├── spring-oxygen-flysql ├── src │ ├── main │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── spring.factories │ │ └── java │ │ │ └── com │ │ │ └── isxcode │ │ │ └── oxygen │ │ │ └── flysql │ │ │ ├── parse │ │ │ ├── MongoSqlValue.java │ │ │ ├── MysqlSqlValue.java │ │ │ ├── H2SqlValue.java │ │ │ ├── SqlValueFactory.java │ │ │ ├── SqlValue.java │ │ │ ├── OracleSqlValue.java │ │ │ └── SqlServerSqlValue.java │ │ │ ├── entity │ │ │ ├── ColumnProperties.java │ │ │ ├── FlysqlPage.java │ │ │ ├── SqlCondition.java │ │ │ └── FlysqlKey.java │ │ │ ├── response │ │ │ ├── AbstractExceptionEnum.java │ │ │ ├── ResponseConstant.java │ │ │ ├── SuccessException.java │ │ │ ├── SuccessResponse.java │ │ │ ├── BizException.java │ │ │ ├── AbstractException.java │ │ │ ├── SuccessResponseAdvice.java │ │ │ └── GlobalExceptionAdvice.java │ │ │ ├── annotation │ │ │ ├── LastModifiedDate.java │ │ │ ├── Version.java │ │ │ ├── CreatedBy.java │ │ │ ├── IsDelete.java │ │ │ ├── CreatedDate.java │ │ │ ├── LastModifiedBy.java │ │ │ ├── FlysqlViews.java │ │ │ ├── ColumnName.java │ │ │ ├── TableName.java │ │ │ ├── RowId.java │ │ │ └── FlysqlView.java │ │ │ ├── enums │ │ │ ├── IdGenerateType.java │ │ │ ├── SqlType.java │ │ │ ├── OrderType.java │ │ │ ├── DataBaseType.java │ │ │ └── SqlOperateType.java │ │ │ ├── exception │ │ │ └── FlysqlException.java │ │ │ ├── common │ │ │ ├── BaseResponse.java │ │ │ ├── LocalDateTimeDeserializer.java │ │ │ ├── LocalDateDeserializer.java │ │ │ ├── LocalDateSerializer.java │ │ │ ├── LocalDateTimeSerializer.java │ │ │ ├── BaseEntity.java │ │ │ └── OxygenHolder.java │ │ │ ├── package-info.java │ │ │ ├── properties │ │ │ └── FlysqlProperties.java │ │ │ ├── constant │ │ │ └── FlysqlConstants.java │ │ │ ├── core │ │ │ ├── FlysqlExecutor.java │ │ │ └── Flysql.java │ │ │ ├── utils │ │ │ └── FlysqlUtils.java │ │ │ └── config │ │ │ └── FlysqlAutoConfiguration.java │ └── test │ │ ├── resources │ │ ├── application-mongo.yml │ │ ├── db │ │ │ ├── schema_mysql.sql │ │ │ ├── schema_sqlserver.sql │ │ │ ├── schema_h2.sql │ │ │ └── schema_oracle.sql │ │ ├── application-h2.yml │ │ ├── application-oracle.yml │ │ ├── application-mysql.yml │ │ └── application-sqlserver.yml │ │ └── java │ │ └── com │ │ └── isxcode │ │ └── oxygen │ │ └── flysql │ │ ├── Dog.java │ │ ├── TestOracle.java │ │ ├── TestSqlServer.java │ │ ├── TestMongo.java │ │ └── TestMysql.java └── build.gradle ├── oxygen-spring-boot-starter ├── build.gradle └── src │ ├── main │ ├── resources │ │ └── META-INF │ │ │ └── spring.factories │ └── java │ │ └── com │ │ └── isxcode │ │ └── oxygen │ │ └── starter │ │ ├── package-info.java │ │ └── OxygenStarterAutoConfiguration.java │ └── test │ └── java │ └── com │ └── isxcode │ └── oxygen │ └── starter │ └── OxygenSpringBootStarterTests.java ├── settings.gradle ├── .gitignore ├── gradle.properties ├── .editorconfig ├── .gitattributes ├── SECURITY.md ├── gradlew.bat ├── CODE_OF_CONDUCT.md └── README.md /docs/.nojekyll: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /VERSION.md: -------------------------------------------------------------------------------- 1 | 1.10.3 2 | -------------------------------------------------------------------------------- /docs/CNAME: -------------------------------------------------------------------------------- 1 | spring-oxygen.isxcode.com -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | ispong Owner 2 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/main/resources/test.txt: -------------------------------------------------------------------------------- 1 | hello world 2 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/resources/templates/project/application-properties.ftl: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | open_collective: spring-oxygen 2 | issuehunt: isxcode/spring-oxygen -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | Welcome to use Spring Oxygen Cli ! 2 | -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | image: gitpod/workspace-full 2 | 3 | tasks: 4 | - init: gradle build -x test -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## changelog 2 | 3 | - https://spring-oxygen.isxcode.com/#/en-us/changelog 4 | -------------------------------------------------------------------------------- /.github/secring.gpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isxcode/spring-oxygen/HEAD/.github/secring.gpg -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "java.configuration.updateBuildConfiguration": "disabled" 3 | } -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## contributing 2 | 3 | - https://spring-oxygen.isxcode.com/#/en-us/contributing 4 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/resources/templates/project/settings-gradle.ftl: -------------------------------------------------------------------------------- 1 | rootProject.name = 'demo' 2 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/main/resources/templates2/test.ftl: -------------------------------------------------------------------------------- 1 | this dog name is ${name} and age is ${age} 2 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/test/resources/templates2/test.ftl: -------------------------------------------------------------------------------- 1 | this dog name is ${name} and age is ${age} 2 | -------------------------------------------------------------------------------- /.github/codeql/codeql-config.yml: -------------------------------------------------------------------------------- 1 | name: 'codeql config' 2 | 3 | queries: 4 | - uses: security-and-quality 5 | -------------------------------------------------------------------------------- /docs/assets/images/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isxcode/spring-oxygen/HEAD/docs/assets/images/favicon.png -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isxcode/spring-oxygen/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.lgtm.yml: -------------------------------------------------------------------------------- 1 | extraction: 2 | java: 3 | index: 4 | java_version: "11" 5 | build_command: ./gradlew build test 6 | -------------------------------------------------------------------------------- /docs/assets/images/oxygen-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isxcode/spring-oxygen/HEAD/docs/assets/images/oxygen-logo.png -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8899 3 | 4 | logging: 5 | level: 6 | root: error 7 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration= 2 | 3 | -------------------------------------------------------------------------------- /oxygen-spring-boot-starter/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile project(path: ':spring-oxygen-core') 3 | compile project(path: ':spring-oxygen-flysql') 4 | } 5 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration= 2 | org.springframework.boot.env.EnvironmentPostProcessor= 3 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/parse/MongoSqlValue.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.parse; 2 | 3 | public class MongoSqlValue implements SqlValue {} 4 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/parse/MysqlSqlValue.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.parse; 2 | 3 | public class MysqlSqlValue implements SqlValue {} 4 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'spring-oxygen' 2 | 3 | include 'oxygen-spring-boot-starter' 4 | include 'spring-oxygen-core' 5 | include 'spring-oxygen-flysql' 6 | include 'spring-oxygen-cli' 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.iml 3 | 4 | .gradle 5 | gradle 6 | gradle.properties 7 | 8 | **/build 9 | **/target 10 | 11 | **/bin 12 | **/.project 13 | **/.classpath 14 | **/.settings 15 | 16 | **/*.log 17 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/arts.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: For Art Project 3 | about: Use this template for arts. 4 | title: "" 5 | labels: art 6 | assignees: 7 | --- 8 | 11 | **Describe the question** 12 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | signing.keyId=57CA7F60 2 | signing.password=spring-oxygen 3 | signing.secretKeyRingFile=../.github/secring.gpg 4 | 5 | sonatypeUsername=isxcode 6 | #sonatypePassword=xxx 7 | 8 | gpr.user=isxcode 9 | #gpr.key=xxx 10 | 11 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/features.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: For Project New Features 3 | about: Use this template for new features. 4 | title: "" 5 | labels: feature 6 | assignees: 7 | --- 8 | 9 | 12 | **Describe the features** 13 | -------------------------------------------------------------------------------- /docs/en-us/_navbar.md: -------------------------------------------------------------------------------- 1 | * Community 2 | * [Contributing](https://spring-oxygen.isxcode.com/#/en-us/contributing) 3 | * [Changelog](https://spring-oxygen.isxcode.com/#/en-us/changelog) 4 | * [License](https://github.com/isxcode/spring-oxygen/blob/latest/LICENSE) 5 | 6 | -------------------------------------------------------------------------------- /spring-oxygen-cli/README.md: -------------------------------------------------------------------------------- 1 | #### oxygen-cli 2 | 3 | > 下载oxygen-cli 4 | 5 | ```bash 6 | curl -O https://github.com/ispong/spring-oxygen-cli.jar 7 | ``` 8 | 9 | ```bash 10 | java -jar spring-oxygen-cli.jar 11 | ``` 12 | 13 | ```bash 14 | cd leo-spring 15 | oxygen-cli start 16 | ``` 17 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/entity/ColumnProperties.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.entity; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class ColumnProperties { 7 | 8 | private String type; 9 | 10 | private String name; 11 | } 12 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/entity/FlysqlPage.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.entity; 2 | 3 | import java.util.List; 4 | import lombok.Data; 5 | 6 | @Data 7 | public class FlysqlPage { 8 | 9 | private List page; 10 | 11 | private Integer total; 12 | } 13 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/resources/templates/project/application-test.ftl: -------------------------------------------------------------------------------- 1 | package com.example.demo; 2 | import org.junit.jupiter.api.Test; 3 | import org.springframework.boot.test.context.SpringBootTest; 4 | @SpringBootTest 5 | class DemoApplicationTests { 6 | @Test 7 | void contextLoads() { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/main/java/com/isxcode/oxygen/core/date/DateUtils.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core.date; 2 | 3 | import java.time.LocalDate; 4 | 5 | public class DateUtils { 6 | 7 | public static LocalDate parseLocalDateStr(String dateStr) { 8 | 9 | return LocalDate.parse(dateStr); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | max_line_length = off 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | 15 | [*.yml] 16 | indent_size = 2 17 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/response/AbstractExceptionEnum.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.response; 2 | 3 | /** 4 | * exception enum template 5 | * 6 | * @since 0.0.1 7 | */ 8 | public interface AbstractExceptionEnum { 9 | 10 | String getCode(); 11 | 12 | String getMsg(); 13 | } 14 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/test/resources/application-mongo.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | data: 3 | mongodb: 4 | uri: ENC(f5tA0YiQyIhLdS7TdXED5ml4UsIEM5hH7q1TumWdxcRg78crDAu3j4ix7b9ZYdjcLpp0tr9wPgTTHoKiaZKgqR5zARJ7HehbnMc+rg7//pc=) 5 | 6 | jasypt: 7 | encryptor: 8 | password: oxygen 9 | 10 | oxygen: 11 | flysql: 12 | show-log: true 13 | -------------------------------------------------------------------------------- /docs/en-us/_sidebar.md: -------------------------------------------------------------------------------- 1 | - **Getting Started** 2 | - [Overview](README.md) 3 | - [Getting started](/en-us/start/Start.md) 4 | - **Frameworks** 5 | - Flysql 6 | - [Database Config](/en-us/advance/Database-Config.md) 7 | - [Flysql Builder](/en-us/advance/Flysql-Builder.md) 8 | - [Advance Usage](/en-us/advance/Advance-Usage.md) 9 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/java/com/isxcode/oxygen/cli/entity/TableInfo.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.cli.entity; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * table info 7 | * 8 | * @author ispong 9 | * @version v0.1.0 10 | */ 11 | @Data 12 | public class TableInfo { 13 | 14 | /** table comment */ 15 | private String tableComment; 16 | } 17 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.bat text eol=crlf 3 | *.bash text eol=lf 4 | *.sh text eol=lf 5 | *.java text diff=java 6 | 7 | *.png binary 8 | *.jpg binary 9 | *.jpeg binary 10 | *.gif binary 11 | *.ico binary 12 | *.zip binary 13 | *.gpg binary 14 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/annotation/LastModifiedDate.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** sys column last_modified_date */ 6 | @Target(ElementType.FIELD) 7 | @Retention(RetentionPolicy.RUNTIME) 8 | @Inherited 9 | @Documented 10 | public @interface LastModifiedDate {} 11 | -------------------------------------------------------------------------------- /oxygen-spring-boot-starter/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.isxcode.oxygen.starter.OxygenStarterAutoConfiguration, \ 3 | com.isxcode.oxygen.core.config.OxygenCoreAutoConfiguration,\ 4 | com.isxcode.oxygen.flysql.config.FlysqlAutoConfiguration 5 | org.springframework.boot.env.EnvironmentPostProcessor= 6 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/test/java/com/isxcode/oxygen/core/DateUtilsTests.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core; 2 | 3 | import com.isxcode.oxygen.core.date.DateUtils; 4 | import org.junit.jupiter.api.Test; 5 | 6 | public class DateUtilsTests { 7 | 8 | @Test 9 | public void testUtils() { 10 | 11 | System.out.println(DateUtils.parseLocalDateStr("2020-12-12")); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/resources/templates/entity/innerService.java.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | /** 6 | * Interface - ${tableComment!""} 7 | * 8 | * @author ${freecodeProperties.author} 9 | * @since ${freecodeProperties.version} 10 | */ 11 | @Service 12 | public interface ${className?cap_first}InnerService { 13 | 14 | } -------------------------------------------------------------------------------- /spring-oxygen-core/src/test/java/com/isxcode/oxygen/core/RandomUtilsTests.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core; 2 | 3 | import com.isxcode.oxygen.core.random.RandomUtils; 4 | import org.junit.jupiter.api.Test; 5 | 6 | public class RandomUtilsTests { 7 | 8 | @Test 9 | public void testRandom() { 10 | 11 | System.out.println("data-->" + RandomUtils.generateNumber(7)); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/enums/IdGenerateType.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.enums; 2 | 3 | /** 4 | * id generate type enum 5 | * 6 | * @author ispong 7 | * @since 0.0.1 8 | */ 9 | public enum IdGenerateType { 10 | 11 | /** snowflake */ 12 | SNOW_FLACK, 13 | 14 | /** UUID */ 15 | UUID, 16 | 17 | /** increment */ 18 | INCREMENT, 19 | } 20 | -------------------------------------------------------------------------------- /docs/_coverpage.md: -------------------------------------------------------------------------------- 1 | ![logo](assets/images/oxygen-logo.png) 2 | 3 |

4 | Spring Oxygen 5 |

6 | 7 | - 🦄 Spring rapid development integration framework. 8 | 9 |
10 | GitHub 11 | Get Started 12 |
13 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/main/java/com/isxcode/oxygen/core/exception/OxygenException.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core.exception; 2 | 3 | /** 4 | * Oxygen exception 5 | * 6 | * @author ispong 7 | * @since 0.0.1 8 | */ 9 | public class OxygenException extends RuntimeException { 10 | 11 | public OxygenException(String message) { 12 | 13 | super("[oxygen-core]==> " + message); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/java/com/isxcode/oxygen/cli/exception/FreecodeException.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.cli.exception; 2 | 3 | /** 4 | * freecode exception 5 | * 6 | * @author ispong 7 | * @since 0.0.1 8 | */ 9 | public class FreecodeException extends RuntimeException { 10 | 11 | public FreecodeException(String message) { 12 | 13 | super("[oxygen-freecode] " + message); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/annotation/Version.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * sys column version 7 | * 8 | * @author ispong 9 | * @since 0.0.1 10 | */ 11 | @Target(ElementType.FIELD) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Inherited 14 | @Documented 15 | public @interface Version {} 16 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/resources/templates/project/application-controller.ftl: -------------------------------------------------------------------------------- 1 | package com.example.demo; 2 | import org.springframework.boot.SpringApplication; 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | @SpringBootApplication 5 | public class DemoApplication { 6 | public static void main(String[] args) { 7 | SpringApplication.run(DemoApplication.class, args); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/annotation/CreatedBy.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * sys column created_by 7 | * 8 | * @author ispong 9 | * @since 0.0.1 10 | */ 11 | @Target(ElementType.FIELD) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Inherited 14 | @Documented 15 | public @interface CreatedBy {} 16 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/annotation/IsDelete.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * sys column is_detele 7 | * 8 | * @author ispong 9 | * @since 0.0.1 10 | */ 11 | @Target(ElementType.FIELD) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Inherited 14 | @Documented 15 | public @interface IsDelete {} 16 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/annotation/CreatedDate.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * sys column created_date 7 | * 8 | * @author ispong 9 | * @since 0.0.1 10 | */ 11 | @Target(ElementType.FIELD) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Inherited 14 | @Documented 15 | public @interface CreatedDate {} 16 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/annotation/LastModifiedBy.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * sys column last_modified_by 7 | * 8 | * @author ispong 9 | * @since 0.0.1 10 | */ 11 | @Target(ElementType.FIELD) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Inherited 14 | @Documented 15 | public @interface LastModifiedBy {} 16 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/annotation/FlysqlViews.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * views 7 | * 8 | * @author ispong 9 | * @since 0.0.1 10 | */ 11 | @Target(ElementType.TYPE) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Inherited 14 | @Documented 15 | public @interface FlysqlViews { 16 | 17 | FlysqlView[] value(); 18 | } 19 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/test/resources/application-test.yml: -------------------------------------------------------------------------------- 1 | test: 2 | email: ispong@outlook.com 3 | emailContent: hello,test for oxygen 4 | senderName: ispong 5 | templateName: test.ftl 6 | 7 | spring: 8 | mail: 9 | host: smtp.qq.com 10 | port: 465 11 | username: 450065195@qq.com 12 | password: mykzuzuyxphzbghb 13 | freemarker: 14 | suffix: .ftl 15 | template-loader-path: 16 | - classpath:templates2/ 17 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/enums/SqlType.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.enums; 2 | 3 | /** 4 | * sql type 5 | * 6 | * @author ispong 7 | * @since 0.0.1 8 | */ 9 | public enum SqlType { 10 | 11 | /** insert sql */ 12 | INSERT, 13 | 14 | /** delete sql */ 15 | DELETE, 16 | 17 | /** update sql */ 18 | UPDATE, 19 | 20 | /** sql view select */ 21 | VIEW, 22 | 23 | /** select sql */ 24 | SELECT, 25 | } 26 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/exception/FlysqlException.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.exception; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | /** 6 | * flysql exception 7 | * 8 | * @author ispong 9 | * @since 0.0.1 10 | */ 11 | @Slf4j 12 | public class FlysqlException extends RuntimeException { 13 | 14 | public FlysqlException(String message) { 15 | 16 | super("[oxygen-flysql]==> " + message); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/java/com/isxcode/oxygen/cli/pojo/ProjectInfo.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.cli.pojo; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * project basic info 7 | * 8 | * @author ispong 9 | * @since 0.0.2 10 | */ 11 | @Data 12 | public class ProjectInfo { 13 | 14 | private String group; 15 | 16 | private String artifact; 17 | 18 | private String name; 19 | 20 | private String description; 21 | 22 | private String packageName; 23 | } 24 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/enums/OrderType.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.enums; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | 6 | /** 7 | * 排序 8 | * 9 | * @author ispong 10 | * @since 0.0.1 11 | */ 12 | @AllArgsConstructor 13 | public enum OrderType { 14 | 15 | /** 降序 */ 16 | DESC("desc"), 17 | 18 | /** 升序 */ 19 | ASC("asc"), 20 | ; 21 | 22 | @Getter private final String orderType; 23 | } 24 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/response/ResponseConstant.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.response; 2 | 3 | /** 4 | * success constants 5 | * 6 | * @author ispong 7 | * @since 0.0.2 8 | */ 9 | public interface ResponseConstant { 10 | 11 | /** success code */ 12 | String SUCCESS_CODE = "200"; 13 | 14 | /** forbidden code */ 15 | String FORBIDDEN_CODE = "403"; 16 | 17 | /** error code */ 18 | String ERROR_CODE = "500"; 19 | } 20 | -------------------------------------------------------------------------------- /docs/_404.md: -------------------------------------------------------------------------------- 1 |

2 | 404 3 | Not 4 | Found 5 |

6 | 7 | --- 8 | 9 |

10 | 11 | Spring Oxygen 12 | 13 |

14 | 15 |
16 | 🦄 Spring rapid development integration framework. 17 |
18 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/test/java/com/isxcode/oxygen/core/MatcherUtilsTests.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core; 2 | 3 | import com.isxcode.oxygen.core.matcher.MatcherUtils; 4 | import org.junit.jupiter.api.Test; 5 | 6 | public class MatcherUtilsTests { 7 | 8 | @Test 9 | public void testExcelParseFile() { 10 | 11 | String url = "https://baidu.com"; 12 | String matcherParse = MatcherUtils.matcherParse("https://", ".com", url); 13 | System.out.println(matcherParse); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/enums/DataBaseType.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.enums; 2 | 3 | /** 4 | * dataBase type enum 5 | * 6 | * @author ispong 7 | * @since 0.0.1 8 | */ 9 | public enum DataBaseType { 10 | 11 | /** H2 */ 12 | H2, 13 | 14 | /** Mysql */ 15 | MYSQL, 16 | 17 | /** Oracle */ 18 | ORACLE, 19 | 20 | /** mongoDB */ 21 | MONGO, 22 | 23 | /** SqlServer */ 24 | SQL_SERVER, 25 | 26 | /** nothing */ 27 | DEFAULT, 28 | } 29 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/main/java/com/isxcode/oxygen/core/secret/SecretConstants.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core.secret; 2 | 3 | /** 4 | * secret constants 5 | * 6 | * @author ispong 7 | * @since 0.0.1 8 | */ 9 | public interface SecretConstants { 10 | 11 | /** RSA */ 12 | String RSA = "RSA"; 13 | 14 | /** AES */ 15 | String AES = "AES"; 16 | 17 | /** aes default key */ 18 | String AES_KEY = "OXYGEN"; 19 | 20 | /** jwt default claim key */ 21 | String CLAIM_KEY = "CLAIM"; 22 | } 23 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/annotation/ColumnName.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * for db column name 7 | * 8 | * @author ispong 9 | * @since 0.0.1 10 | */ 11 | @Target(ElementType.FIELD) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Documented 14 | public @interface ColumnName { 15 | 16 | /** 17 | * db column name 18 | * 19 | * @return column name 20 | */ 21 | String value(); 22 | } 23 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/annotation/TableName.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * config bean from which table 7 | * 8 | * @author ispong 9 | * @since 0.0.1 10 | */ 11 | @Target(ElementType.TYPE) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Documented 14 | public @interface TableName { 15 | 16 | /** 17 | * table name 18 | * 19 | * @return table name 20 | */ 21 | String value(); 22 | } 23 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/response/SuccessException.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.response; 2 | 3 | import com.isxcode.oxygen.flysql.common.BaseResponse; 4 | import lombok.Getter; 5 | import lombok.Setter; 6 | 7 | public class SuccessException extends RuntimeException { 8 | 9 | @Setter @Getter private BaseResponse baseResponse; 10 | 11 | public SuccessException(BaseResponse baseResponse) { 12 | 13 | this.baseResponse = baseResponse; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/issues.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: For Tracking Issues 3 | about: Use this template for issues. 4 | title: "" 5 | labels: bug 6 | assignees: 7 | --- 8 | 9 | 12 | **Describe the question** 13 | 14 | 15 | 18 | **To Show code** 19 | 20 | 21 | 24 | **Additional context** 25 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/java/com/isxcode/oxygen/cli/OxygenCliApplication.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.cli; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * start up 8 | * 9 | * @author ispong 10 | * @since 0.0.2 11 | */ 12 | @SpringBootApplication 13 | public class OxygenCliApplication { 14 | 15 | public static void main(String[] args) { 16 | 17 | SpringApplication.run(OxygenCliApplication.class, args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/annotation/RowId.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.annotation; 2 | 3 | import com.isxcode.oxygen.flysql.enums.IdGenerateType; 4 | import java.lang.annotation.*; 5 | 6 | /** 7 | * sys column id 8 | * 9 | * @author ispong 10 | * @since 0.0.1 11 | */ 12 | @Target(ElementType.FIELD) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Inherited 15 | @Documented 16 | public @interface RowId { 17 | 18 | IdGenerateType generateType() default IdGenerateType.SNOW_FLACK; 19 | } 20 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | 4 | - package-ecosystem: 'github-actions' 5 | directory: '/' 6 | target-branch: 'latest' 7 | open-pull-requests-limit: 30 8 | schedule: 9 | interval: 'monthly' 10 | timezone: 'Asia/Shanghai' 11 | time: '09:00' 12 | 13 | - package-ecosystem: 'gradle' 14 | directory: '/' 15 | target-branch: 'latest' 16 | open-pull-requests-limit: 30 17 | schedule: 18 | interval: 'monthly' 19 | timezone: 'Asia/Shanghai' 20 | time: '09:00' 21 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/response/SuccessResponse.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.response; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Target(ElementType.METHOD) 6 | @Retention(RetentionPolicy.RUNTIME) 7 | @Inherited 8 | @Documented 9 | public @interface SuccessResponse { 10 | 11 | /** 12 | * default msg 13 | * 14 | * @return default msg 15 | */ 16 | String value() default ""; 17 | 18 | /** 19 | * msg 20 | * 21 | * @return msg 22 | */ 23 | String msg() default ""; 24 | } 25 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/test/resources/db/schema_mysql.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE IF EXISTS DOGS_T; 2 | 3 | CREATE TABLE DOGS_T 4 | ( 5 | id INT NOT NULL, 6 | name VARCHAR(100) NOT NULL, 7 | amount_double DOUBLE NOT NULL, 8 | amount_big_decimal DECIMAL NOT NULL, 9 | is_alive BOOLEAN NOT NULL, 10 | birth_date DATE NOT NULL, 11 | birth_local_date DATE NOT NULL, 12 | birth_local_date_time DATETIME NOT NULL 13 | ); 14 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/resources/templates/project/build-gradle.ftl: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.4.2' 3 | id 'io.spring.dependency-management' version '1.0.12.RELEASE' 4 | id 'java' 5 | } 6 | group = 'com.example' 7 | version = '0.0.1-SNAPSHOT' 8 | sourceCompatibility = '11' 9 | repositories { 10 | mavenCentral() 11 | } 12 | dependencies { 13 | implementation 'org.springframework.boot:spring-boot-starter' 14 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 15 | } 16 | test { 17 | useJUnitPlatform() 18 | } 19 | -------------------------------------------------------------------------------- /oxygen-spring-boot-starter/src/test/java/com/isxcode/oxygen/starter/OxygenSpringBootStarterTests.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.starter; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | import org.springframework.test.context.ContextConfiguration; 6 | 7 | @SpringBootTest 8 | @ContextConfiguration(classes = OxygenStarterAutoConfiguration.class) 9 | public class OxygenSpringBootStarterTests { 10 | 11 | @Test 12 | public void testStarter() { 13 | System.out.println("hello oxygen"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/java/com/isxcode/oxygen/cli/annotation/EnableFreecode.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.cli.annotation; 2 | 3 | import com.isxcode.oxygen.cli.config.FreecodeAutoConfiguration; 4 | import java.lang.annotation.*; 5 | import org.springframework.context.annotation.Import; 6 | 7 | /** 8 | * freecode starter 9 | * 10 | * @author ispong 11 | * @since 0.0.1 12 | */ 13 | @Target(ElementType.TYPE) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Import(FreecodeAutoConfiguration.class) 16 | @Documented 17 | public @interface EnableFreecode {} 18 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/common/BaseResponse.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.common; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | /** 8 | * base response 9 | * 10 | * @author ispong 11 | * @version v0.1.0 12 | */ 13 | @Data 14 | @AllArgsConstructor 15 | @NoArgsConstructor 16 | public class BaseResponse { 17 | 18 | /** code */ 19 | private String code; 20 | 21 | /** msg */ 22 | private String msg; 23 | 24 | /** data */ 25 | private T data; 26 | } 27 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/response/BizException.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.response; 2 | 3 | /** 4 | * biz exception 5 | * 6 | * @author ispong 7 | * @since 0.0.2 8 | */ 9 | public class BizException extends AbstractException { 10 | 11 | public BizException(AbstractExceptionEnum abstractExceptionEnum) { 12 | 13 | super(abstractExceptionEnum); 14 | } 15 | 16 | public BizException(String code, String msg) { 17 | 18 | super(code, msg); 19 | } 20 | 21 | public BizException(String msg) { 22 | 23 | super(msg); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | | Version | Supported | 6 | |---------|--------------------| 7 | | 0.0.1 | :white_check_mark: | 8 | | 0.0.2 | :white_check_mark: | 9 | | 0.0.3 | :white_check_mark: | 10 | | 0.6.7 | :white_check_mark: | 11 | | 0.7.3 | :white_check_mark: | 12 | | 0.8.1 | :white_check_mark: | 13 | | 0.11.5 | :white_check_mark: | 14 | | 1.2.1 | :white_check_mark: | 15 | | 1.9.1 | :white_check_mark: | 16 | | 1.10.3 | :white_check_mark: | 17 | 18 | ## Reporting a Vulnerability 19 | 20 | - https://spring-oxygen.isxcode.com 21 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/java/com/isxcode/oxygen/cli/store/LocalStorage.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.cli.store; 2 | 3 | import com.isxcode.oxygen.cli.pojo.ProjectInfo; 4 | 5 | /** 6 | * cache project info 7 | * 8 | * @author ispong 9 | * @since 0.0.2 10 | */ 11 | public class LocalStorage { 12 | 13 | /** project basic info */ 14 | public static ProjectInfo projectInfo = new ProjectInfo(); 15 | 16 | /** now command code to show which command */ 17 | public static String nowCommandCode = "INIT"; 18 | 19 | /** project local path */ 20 | public static String localPath = null; 21 | } 22 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/test/resources/application-h2.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | driver-class-name: org.h2.Driver 4 | url: ENC(4jGi1DIi1rqECJjsX6GP0qNO1A+aJXNDht3pzV98vIiZ0jLkZBcGSPPPZEvef4j/) 5 | username: ENC(kkLAiwmWB5veDk7JVT5ieNy/8Yihaq/5bZfqukb5ulZ17HCj6JR7oF+5mkjgAKtw) 6 | password: ENC(kkLAiwmWB5veDk7JVT5ieNy/8Yihaq/5bZfqukb5ulZ17HCj6JR7oF+5mkjgAKtw) 7 | sql: 8 | init: 9 | mode: always 10 | schema-locations: classpath:db/schema_h2.sql 11 | 12 | jasypt: 13 | encryptor: 14 | password: oxygen 15 | 16 | oxygen: 17 | flysql: 18 | show-log: true 19 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/test/resources/db/schema_sqlserver.sql: -------------------------------------------------------------------------------- 1 | IF EXISTS(Select 1 From Sysobjects Where Name='DOGS_T') 2 | DROP table DOGS_T; 3 | 4 | CREATE TABLE DOGS_T 5 | ( 6 | id int not null, 7 | name varchar(100) not null, 8 | amount_double float not null, 9 | amount_big_decimal decimal(10, 5) not null, 10 | is_alive bit not null, 11 | birth_date date not null, 12 | birth_local_date date not null, 13 | birth_local_date_time datetime not null 14 | ); 15 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/resources/templates/project/gitignore.ftl: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | bin/ 16 | !**/src/main/**/bin/ 17 | !**/src/test/**/bin/ 18 | ### IntelliJ IDEA ### 19 | .idea 20 | *.iws 21 | *.iml 22 | *.ipr 23 | out/ 24 | !**/src/main/**/out/ 25 | !**/src/test/**/out/ 26 | ### NetBeans ### 27 | /nbproject/private/ 28 | /nbbuild/ 29 | /dist/ 30 | /nbdist/ 31 | /.nb-gradle/ 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/resources/templates/project/readme.ftl: -------------------------------------------------------------------------------- 1 | # Getting Started 2 | ### Reference Documentation 3 | For further reference, please consider the following sections: 4 | * [Official Gradle documentation](https://docs.gradle.org) 5 | * [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/2.4.2/gradle-plugin/reference/html/) 6 | * [Create an OCI image](https://docs.spring.io/spring-boot/docs/2.4.2/gradle-plugin/reference/html/#build-image) 7 | ### Additional Links 8 | These additional references should also help you: 9 | * [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle) 10 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/main/java/com/isxcode/oxygen/core/random/RandomUtils.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core.random; 2 | 3 | /** 4 | * random utils 5 | * 6 | * @author ispong 7 | * @since 0.0.2 8 | */ 9 | public class RandomUtils { 10 | 11 | /** 12 | * generate custom number 13 | * 14 | * @param number number 15 | * @return string 16 | * @since 0.0.2 17 | */ 18 | public static String generateNumber(int number) { 19 | 20 | int templateNumber = 1; 21 | while (number > 1) { 22 | templateNumber = templateNumber * 10; 23 | number--; 24 | } 25 | 26 | return String.valueOf((int) ((Math.random() * 9 + 1) * templateNumber)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/test/java/com/isxcode/oxygen/core/CommandUtilsTests.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core; 2 | 3 | import com.isxcode.oxygen.core.command.CommandUtils; 4 | import com.isxcode.oxygen.core.file.FileUtils; 5 | import lombok.SneakyThrows; 6 | import org.junit.jupiter.api.Test; 7 | 8 | public class CommandUtilsTests { 9 | 10 | @Test 11 | @SneakyThrows 12 | public void testCommand() { 13 | 14 | System.out.println(CommandUtils.executeBack("dir")); 15 | 16 | System.out.println(CommandUtils.execute("dir")); 17 | 18 | System.out.println(CommandUtils.execute("dir", "command.log")); 19 | 20 | FileUtils.recursionDeleteFile("command.log"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/main/java/com/isxcode/oxygen/core/matcher/MatcherUtils.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core.matcher; 2 | 3 | import static java.util.regex.Pattern.compile; 4 | 5 | import java.util.regex.Matcher; 6 | import java.util.regex.Pattern; 7 | 8 | public class MatcherUtils { 9 | 10 | public static String matcherParse(String startPattern, String endPattern, String content) { 11 | 12 | Pattern pattern = compile(startPattern + ".+?" + endPattern); 13 | Matcher matcher = pattern.matcher(content); 14 | if (matcher.find()) { 15 | return matcher.group().replace(startPattern, "").replace(endPattern, ""); 16 | } else { 17 | return null; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/test/resources/application-oracle.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | driver-class-name: oracle.jdbc.driver.OracleDriver 4 | url: ENC(gC3zjgAI97DFFonJMFwIUruwC4TicKGiq8ZcsjtdUBYmkZGAV9ZJAZS0fffKoDYlX+HLiI58EM6GaCdiLDGGOTunoRsswxl09FkJD4EU3gi1DrJ1URBLyQNXrRayhEAp) 5 | username: ENC(7EkFVwd7X7EEoTuqEM52wEncGY2a5jVPqBYrduvUJHfKqouL66DgkxAHqhVc5hn0) 6 | password: ENC(XyXWm1ks9vlygcFsJtArQxAn6zCOq/qeU/cNtCgkcqgy2fB4BV8viepbU0c2GFPa) 7 | sql: 8 | init: 9 | mode: always 10 | schema-locations: classpath:db/schema_oracle.sql 11 | 12 | jasypt: 13 | encryptor: 14 | password: oxygen 15 | 16 | oxygen: 17 | flysql: 18 | show-log: true 19 | -------------------------------------------------------------------------------- /spring-oxygen-cli/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | 3 | /** 4 | * spring shell 5 | */ 6 | implementation 'org.springframework.shell:spring-shell-starter:2.1.3' 7 | 8 | /** 9 | * spring oxygen core 10 | */ 11 | implementation(project(':spring-oxygen-core')) 12 | 13 | implementation(project(':spring-oxygen-flysql')) 14 | 15 | implementation 'org.springframework.boot:spring-boot-starter' 16 | testImplementation('org.springframework.boot:spring-boot-starter-test') { 17 | exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' 18 | } 19 | } 20 | 21 | bootJar { 22 | enabled(true) 23 | } 24 | 25 | jar { 26 | enabled(false) 27 | } 28 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/test/resources/application-mysql.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | driver-class-name: com.mysql.cj.jdbc.Driver 4 | url: ENC(SfOzgWryQ7kCDbAVu9x5b4evrv/Cr6bSyBtNai2IOakNdhHjtLTpe7K5Ui5+ZJZZvLHEYuKC6I+Uk0bWyZ9T0G1HTz6j8Ke9S6va2D9J6ZbOWg1ZpezKZYpkw5dFtAw0+VlwOrqxQkj5KPXiDOngXA==) 5 | username: ENC(3V37ICjNHD4NDRvv/PzI8VLdGQ0rIFLmrDetXwFsJO5NtEZI1u2GIz1Zr9EtqVXp) 6 | password: ENC(CuHnl943sXWN6yK3cl0hoSF1C92Tp4WklErGc3zxrDadGwP5Mm4QKylWMiYPcON1) 7 | sql: 8 | init: 9 | mode: always 10 | schema-locations: classpath:db/schema_mysql.sql 11 | 12 | jasypt: 13 | encryptor: 14 | password: oxygen 15 | 16 | oxygen: 17 | flysql: 18 | show-log: true 19 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/test/resources/application-sqlserver.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver 4 | url: ENC(nUu+Cv5xc8xkHzJoHsGjU8dCaPaUP11dTjRg8F1xJTx5lmRft95D44L7BAjptdJUE8OBTqTX8e1UsKD4HGGSkfZtXM7x2gyfuGJiBdZi8ayCLcLch8d5HSQvRVRHfNz7) 5 | username: ENC(QpGPl4q1Ay4y8ZueCQVkSJITAdd2UAsPL7mwEgZcfaE4rksXMtPXVOM3n9i/nzlC) 6 | password: ENC(voGCSNtoMYzrVd6JnAz3Xfe8cCl3YeGgv75m8ZbFpQ4Ij/4zt8T+NYc15UFTCoem) 7 | sql: 8 | init: 9 | mode: always 10 | schema-locations: classpath:db/schema_sqlserver.sql 11 | 12 | jasypt: 13 | encryptor: 14 | password: oxygen 15 | 16 | oxygen: 17 | flysql: 18 | show-log: true 19 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/test/resources/db/schema_h2.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE IF EXISTS DOGS_T; 2 | 3 | CREATE TABLE DOGS_T 4 | ( 5 | id INT NOT NULL, 6 | name VARCHAR(100) NOT NULL, 7 | amount_double DOUBLE NOT NULL, 8 | amount_big_decimal DECIMAL NOT NULL, 9 | is_alive BOOLEAN NOT NULL, 10 | birth_date TIMESTAMP NOT NULL, 11 | birth_local_date TIMESTAMP NOT NULL, 12 | birth_local_date_time DATETIME NOT NULL, 13 | is_delete INT NOT NULL, 14 | last_modified_by VARCHAR(100) NOT NULL, 15 | last_modified_date DATETIME NOT NULL 16 | ); 17 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/java/com/isxcode/oxygen/cli/constant/FreecodeConstants.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.cli.constant; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | /** 7 | * freecode constants 8 | * 9 | * @author ispong 10 | * @since 0.0.1 11 | */ 12 | public interface FreecodeConstants { 13 | 14 | /** java file suffix */ 15 | String JAVA_FILE_SUFFIX = ".java"; 16 | 17 | /** table name split str */ 18 | String splitStr = ","; 19 | 20 | /** sys columns */ 21 | List sysColumns = 22 | Arrays.asList( 23 | "created_date", 24 | "created_by", 25 | "last_modified_date", 26 | "last_modified_by", 27 | "version", 28 | "is_delete"); 29 | } 30 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/parse/H2SqlValue.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.parse; 2 | 3 | import com.isxcode.oxygen.flysql.core.FlysqlExecute; 4 | import java.text.ParseException; 5 | import java.text.SimpleDateFormat; 6 | 7 | public class H2SqlValue implements SqlValue { 8 | 9 | @Override 10 | public String getDateValue(String val) { 11 | SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"); 12 | SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 13 | try { 14 | return FlysqlExecute.addSingleQuote(sdf2.format(sdf.parse(String.valueOf(val)))); 15 | } catch (ParseException ignored) { 16 | return null; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring-oxygen-core/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | 3 | implementation 'org.springframework.boot:spring-boot-starter-mail' 4 | 5 | implementation 'org.springframework.boot:spring-boot-starter-freemarker' 6 | 7 | def jjwtVersion = '0.11.5' 8 | implementation 'io.jsonwebtoken:jjwt-api:'+jjwtVersion 9 | implementation 'io.jsonwebtoken:jjwt-jackson:'+jjwtVersion 10 | runtime 'io.jsonwebtoken:jjwt-impl:' + jjwtVersion, 11 | 'io.jsonwebtoken:jjwt-jackson:' + jjwtVersion 12 | 13 | def poiVersion = '5.2.2' 14 | implementation 'org.apache.poi:poi:'+poiVersion 15 | implementation 'org.apache.poi:poi-ooxml:' + poiVersion 16 | 17 | implementation 'org.apache.commons:commons-exec:1.3' 18 | } 19 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/java/com/isxcode/oxygen/cli/config/BashConfig.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.cli.config; 2 | 3 | import org.jline.utils.AttributedString; 4 | import org.jline.utils.AttributedStyle; 5 | import org.springframework.shell.jline.PromptProvider; 6 | import org.springframework.stereotype.Component; 7 | 8 | import java.util.regex.Pattern; 9 | 10 | @Component 11 | public class BashConfig implements PromptProvider { 12 | 13 | @Override 14 | public AttributedString getPrompt() { 15 | 16 | return new AttributedString("oxygen-cli:>", new AttributedStyle(AttributedStyle.RED, AttributedStyle.RED)) 17 | .styleMatches(Pattern.compile("oxygen-cli"), AttributedStyle.BOLD); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2020] [ispong] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.isxcode.oxygen.flysql; 17 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/main/java/com/isxcode/oxygen/core/reflect/FieldBody.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core.reflect; 2 | 3 | import java.lang.reflect.Field; 4 | import java.lang.reflect.Method; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Builder; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | 10 | /** 11 | * class properties 12 | * 13 | * @author ispong 14 | * @since 0.0.1 15 | */ 16 | @Data 17 | @Builder 18 | @NoArgsConstructor 19 | @AllArgsConstructor 20 | public class FieldBody { 21 | 22 | /** read method */ 23 | private Method readMethod; 24 | 25 | /** write method */ 26 | private Method writeMethod; 27 | 28 | /** field */ 29 | private Field field; 30 | 31 | /** className */ 32 | private String className; 33 | } 34 | -------------------------------------------------------------------------------- /oxygen-spring-boot-starter/src/main/java/com/isxcode/oxygen/starter/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2020] [ispong] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.isxcode.oxygen.starter; 17 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/main/resources/config/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | 3 | ## 4 | # default freemarker config 5 | ## 6 | freemarker: 7 | enabled: true 8 | charset: UTF-8 9 | cache: false 10 | check-template-location: false 11 | prefer-file-system-access: false 12 | template-loader-path: 13 | - classpath:/templates/ 14 | 15 | ## 16 | # default jpa config 17 | ## 18 | jpa: 19 | open-in-view: true 20 | 21 | ## 22 | # default mail config 23 | ## 24 | mail: 25 | default-encoding: UTF-8 26 | protocol: smtp 27 | test-connection: true 28 | properties: 29 | mail.smtp.ssl.enable: true 30 | mail.smtp.connectiontimeout: 10000 31 | mail.smtp.timeout: 10000 32 | mail.smtp.writetimeout: 10000 33 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/test/resources/db/schema_oracle.sql: -------------------------------------------------------------------------------- 1 | -- declare 2 | -- num number; 3 | -- begin 4 | -- select count(1) into num from user_tables where table_name = 'DOGS_T'; 5 | -- if num > 0 then 6 | -- execute immediate 'drop table DOGS_T'; 7 | -- end if; 8 | -- end; 9 | -- drop table DOGS_T; 10 | 11 | CREATE TABLE DOGS_T 12 | ( 13 | id INT NOT NULL, 14 | name VARCHAR(100) NOT NULL, 15 | amount_double NUMBER NOT NULL, 16 | amount_big_decimal NUMBER NOT NULL, 17 | is_alive char(1) NOT NULL, 18 | birth_date date NOT NULL, 19 | birth_local_date date NOT NULL, 20 | birth_local_date_time date NOT NULL 21 | ); 22 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/test/java/com/isxcode/oxygen/core/SnowflakeUtilsTests.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core; 2 | 3 | import com.isxcode.oxygen.core.snowflake.SnowflakeUtils; 4 | import org.junit.jupiter.api.Test; 5 | 6 | public class SnowflakeUtilsTests { 7 | 8 | @Test 9 | public void testSnowflake() { 10 | 11 | Thread thread1 = 12 | new Thread( 13 | () -> { 14 | for (int i = 0; i < 100; i++) { 15 | System.out.println("thread1-->" + SnowflakeUtils.getNextUuid()); 16 | } 17 | }); 18 | 19 | Thread thread2 = 20 | new Thread( 21 | () -> { 22 | for (int i = 0; i < 100; i++) { 23 | System.out.println("thread2-->" + SnowflakeUtils.getNextUuid()); 24 | } 25 | }); 26 | 27 | thread1.start(); 28 | thread2.start(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/parse/SqlValueFactory.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.parse; 2 | 3 | import com.isxcode.oxygen.core.exception.OxygenException; 4 | import com.isxcode.oxygen.flysql.enums.DataBaseType; 5 | import org.springframework.lang.NonNull; 6 | 7 | public class SqlValueFactory { 8 | 9 | public static SqlValue getSqlValue(@NonNull DataBaseType dataBaseType) { 10 | 11 | switch (dataBaseType) { 12 | case ORACLE: 13 | return new OracleSqlValue(); 14 | case H2: 15 | return new H2SqlValue(); 16 | case MYSQL: 17 | return new MysqlSqlValue(); 18 | case MONGO: 19 | return new MongoSqlValue(); 20 | case SQL_SERVER: 21 | return new SqlServerSqlValue(); 22 | default: 23 | throw new OxygenException("not support db"); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | implementation(project(':spring-oxygen-core')) 3 | implementation 'org.springframework.security:spring-security-core' 4 | implementation 'org.springframework.boot:spring-boot-starter-aop' 5 | 6 | // jdbc 7 | implementation 'org.springframework.boot:spring-boot-starter-jdbc' 8 | implementation 'org.springframework.boot:spring-boot-starter-data-mongodb' 9 | 10 | testImplementation 'de.flapdoodle.embed:de.flapdoodle.embed.mongo' 11 | 12 | // other driver 13 | runtimeOnly 'com.h2database:h2' 14 | runtimeOnly 'mysql:mysql-connector-java' 15 | runtimeOnly 'com.microsoft.sqlserver:mssql-jdbc' 16 | runtimeOnly 'com.oracle.database.jdbc:ojdbc8' 17 | 18 | // jasypt 19 | compile 'com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.4' 20 | } 21 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/common/LocalDateTimeDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.common; 2 | 3 | import com.fasterxml.jackson.core.JsonParser; 4 | import com.fasterxml.jackson.databind.DeserializationContext; 5 | import com.fasterxml.jackson.databind.JsonDeserializer; 6 | import java.io.IOException; 7 | import java.time.LocalDateTime; 8 | import java.time.ZoneOffset; 9 | 10 | /** 11 | * LocalDateTime Deserializer 12 | * 13 | * @author ispong 14 | * @since 0.0.1 15 | */ 16 | public class LocalDateTimeDeserializer extends JsonDeserializer { 17 | 18 | @Override 19 | public LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { 20 | 21 | return LocalDateTime.ofEpochSecond(p.getLongValue() / 1000, 0, ZoneOffset.ofHours(8)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/resources/templates/entity/repository.java.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.stereotype.Repository; 5 | import com.isxcode.oxygen.flysql.core.Flysql; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Repository - ${tableComment!""} 11 | * 12 | * @author ${freecodeProperties.author} 13 | * @since ${freecodeProperties.version} 14 | */ 15 | @Slf4j 16 | @Repository 17 | public class ${className?cap_first}Repository { 18 | 19 | /** 20 | * query ${className?cap_first}Entity 21 | * 22 | * @return List[${className?cap_first}Entity] 23 | * @since ${freecodeProperties.version} 24 | */ 25 | public List<${className?cap_first}Entity> query${className?cap_first}(){ 26 | 27 | return Flysql.select(${className?cap_first}Entity.class).query(); 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/annotation/FlysqlView.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.annotation; 2 | 3 | import com.isxcode.oxygen.flysql.constant.FlysqlConstants; 4 | import java.lang.annotation.*; 5 | 6 | /** 7 | * sql view 8 | * 9 | * @author ispong 10 | * @since 0.0.1 11 | */ 12 | @Target(ElementType.TYPE) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Inherited 15 | @Documented 16 | @Repeatable(FlysqlViews.class) 17 | public @interface FlysqlView { 18 | 19 | /** 20 | * datasource name 21 | * 22 | * @return datasource name 23 | */ 24 | String datasource(); 25 | 26 | /** 27 | * view name 28 | * 29 | * @return view name 30 | */ 31 | String name() default FlysqlConstants.PRIMARY_VIEW_NAME; 32 | 33 | /** 34 | * view sql 35 | * 36 | * @return view sql 37 | */ 38 | String value(); 39 | } 40 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/properties/FlysqlProperties.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.properties; 2 | 3 | import java.util.Map; 4 | import lombok.Data; 5 | import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; 6 | import org.springframework.boot.autoconfigure.mongo.MongoProperties; 7 | import org.springframework.boot.context.properties.ConfigurationProperties; 8 | 9 | /** 10 | * config flysql 11 | * 12 | * @author ispong 13 | * @since 0.0.1 14 | */ 15 | @Data 16 | @ConfigurationProperties("oxygen.flysql") 17 | public class FlysqlProperties { 18 | 19 | /** jdbc properties */ 20 | private Map datasource; 21 | 22 | /** mongo properties */ 23 | private Map mongodb; 24 | 25 | /** show logs */ 26 | private Boolean showLog = true; 27 | } 28 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/common/LocalDateDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.common; 2 | 3 | import com.fasterxml.jackson.core.JsonParser; 4 | import com.fasterxml.jackson.databind.DeserializationContext; 5 | import com.fasterxml.jackson.databind.JsonDeserializer; 6 | import java.io.IOException; 7 | import java.time.LocalDate; 8 | import java.time.format.DateTimeFormatter; 9 | 10 | /** 11 | * LocalDate Deserializer 12 | * 13 | * @author ispong 14 | * @since 0.0.1 15 | */ 16 | public class LocalDateDeserializer extends JsonDeserializer { 17 | 18 | @Override 19 | public LocalDate deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { 20 | 21 | DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd"); 22 | return LocalDate.parse(p.getText(), dtf); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/main/java/com/isxcode/oxygen/core/reflect/ReflectConstants.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core.reflect; 2 | 3 | /** 4 | * Reflect Constants 5 | * 6 | * @author ispong 7 | * @since 0.0.1 8 | */ 9 | public interface ReflectConstants { 10 | 11 | /** class */ 12 | String CLASS = "class"; 13 | 14 | /** string */ 15 | String STRING = "java.lang.String"; 16 | 17 | /** double */ 18 | String DOUBLE = "java.lang.Double"; 19 | 20 | /** local_date_time */ 21 | String LOCAL_DATE_TIME = "java.time.LocalDateTime"; 22 | 23 | /** local_date */ 24 | String LOCAL_DATE = "java.time.LocalDate"; 25 | 26 | /** date */ 27 | String DATE = "java.util.Date"; 28 | 29 | /** integer */ 30 | String INTEGER = "java.lang.Integer"; 31 | 32 | /** Boolean */ 33 | String BOOLEAN = "java.lang.Boolean"; 34 | 35 | /** boolean */ 36 | String BOOLEAN_LOWER = "boolean"; 37 | } 38 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/java/com/isxcode/oxygen/cli/entity/FreecodeInfo.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.cli.entity; 2 | 3 | import com.isxcode.oxygen.cli.properties.FreecodeProperties; 4 | import java.util.List; 5 | import lombok.Data; 6 | 7 | /** 8 | * freemarker all info 9 | * 10 | * @author ispong 11 | * @since 0.0.1 12 | */ 13 | @Data 14 | public class FreecodeInfo { 15 | 16 | /** table columns list */ 17 | private List tableColumns; 18 | 19 | /** entity class package */ 20 | private List entityPackageList; 21 | 22 | /** table name */ 23 | private String tableName; 24 | 25 | /** table comment */ 26 | private String tableComment; 27 | 28 | /** class name */ 29 | private String className; 30 | 31 | /** package name */ 32 | private String packageName; 33 | 34 | /** freecdoe config */ 35 | private FreecodeProperties freecodeProperties; 36 | } 37 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/response/AbstractException.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.response; 2 | 3 | import lombok.Getter; 4 | 5 | /** 6 | * Abstract Exception Template 7 | * 8 | * @author ispong 9 | * @since 0.0.1 10 | */ 11 | public abstract class AbstractException extends RuntimeException { 12 | 13 | /** code */ 14 | @Getter private final String code; 15 | 16 | /** msg */ 17 | @Getter private final String msg; 18 | 19 | public AbstractException(AbstractExceptionEnum abstractExceptionEnum) { 20 | 21 | this.code = abstractExceptionEnum.getCode(); 22 | this.msg = abstractExceptionEnum.getMsg(); 23 | } 24 | 25 | public AbstractException(String code, String msg) { 26 | 27 | this.code = code; 28 | this.msg = msg; 29 | } 30 | 31 | public AbstractException(String msg) { 32 | 33 | this.code = null; 34 | this.msg = msg; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/main/java/com/isxcode/oxygen/core/excel/ExcelType.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core.excel; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * excel style annotation 7 | * 8 | * @author ispon 9 | * @since 2019-10-31 10 | */ 11 | @Target(value = {ElementType.METHOD, ElementType.TYPE, ElementType.FIELD}) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Inherited 14 | @Documented 15 | public @interface ExcelType { 16 | 17 | /** @return cell name */ 18 | String cellName(); 19 | 20 | /** @return cell width */ 21 | int cellWidth() default 10000; 22 | 23 | /** @return cell index */ 24 | int cellIndex() default -1; 25 | 26 | /** @return cell color */ 27 | int[] cellColor() default {245, 247, 250}; 28 | 29 | /** @return data format */ 30 | String cellDateFormat() default "yyyy/mm/dd"; 31 | 32 | /** @return number format */ 33 | String cellDoubleFormat() default "0.00"; 34 | } 35 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/common/LocalDateSerializer.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.common; 2 | 3 | import com.fasterxml.jackson.core.JsonGenerator; 4 | import com.fasterxml.jackson.databind.JsonSerializer; 5 | import com.fasterxml.jackson.databind.ObjectMapper; 6 | import com.fasterxml.jackson.databind.SerializerProvider; 7 | import java.io.IOException; 8 | import java.time.LocalDate; 9 | import java.time.format.DateTimeFormatter; 10 | 11 | /** 12 | * LocalDate Serializer 13 | * 14 | * @author ispong 15 | * @since 0.0.1 16 | */ 17 | public class LocalDateSerializer extends JsonSerializer { 18 | 19 | @Override 20 | public void serialize(LocalDate value, JsonGenerator gen, SerializerProvider serializers) 21 | throws IOException { 22 | 23 | DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd"); 24 | new ObjectMapper().writeValue(gen, dtf.format(value)); 25 | // gen.writeNumber(value.toInstant(ZoneOffset.ofHours(8)).toEpochMilli()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/test/java/com/isxcode/oxygen/core/FileUtilsTests.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core; 2 | 3 | import com.isxcode.oxygen.core.file.FileUtils; 4 | import java.io.File; 5 | import java.nio.file.StandardOpenOption; 6 | import org.junit.jupiter.api.Test; 7 | 8 | public class FileUtilsTests { 9 | 10 | private final String dirPath = "file"; 11 | 12 | @Test 13 | public void testGenerateDir() { 14 | 15 | FileUtils.generateDirs(dirPath); 16 | } 17 | 18 | @Test 19 | public void testGenerateFile() { 20 | 21 | FileUtils.generateFile(dirPath + File.separator + "file1.txt"); 22 | } 23 | 24 | @Test 25 | public void testStringToFile() { 26 | 27 | FileUtils.StringToFile( 28 | "hello", dirPath + File.separator + "file2.txt", StandardOpenOption.WRITE); 29 | } 30 | 31 | @Test 32 | public void testCopyResourceFile() { 33 | 34 | FileUtils.copyResourceFile( 35 | "application-test.yml", dirPath + File.separator + "file3.txt", StandardOpenOption.WRITE); 36 | 37 | FileUtils.recursionDeleteFile(dirPath); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/common/LocalDateTimeSerializer.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.common; 2 | 3 | import com.fasterxml.jackson.core.JsonGenerator; 4 | import com.fasterxml.jackson.databind.JsonSerializer; 5 | import com.fasterxml.jackson.databind.ObjectMapper; 6 | import com.fasterxml.jackson.databind.SerializerProvider; 7 | import java.io.IOException; 8 | import java.time.LocalDateTime; 9 | import java.time.format.DateTimeFormatter; 10 | 11 | /** 12 | * LocalDateTime Serializer 13 | * 14 | * @author ispong 15 | * @since 0.0.1 16 | */ 17 | public class LocalDateTimeSerializer extends JsonSerializer { 18 | 19 | @Override 20 | public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers) 21 | throws IOException { 22 | 23 | DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); 24 | new ObjectMapper().writeValue(gen, dtf.format(value)); 25 | // gen.writeNumber(value.toInstant(ZoneOffset.ofHours(8)).toEpochMilli()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/main/java/com/isxcode/oxygen/core/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2020] [ispong] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * reflect : provide java reflect utils xml : parse xml file secret : provide ase rsa jwt encrypt 19 | * utils snowflake : snowflake id random : generate phone verifty number http : provide http utils 20 | * freemarker: provide tool to generate file or string excel : excel utils to parse and generate 21 | * email : add send email utils 22 | */ 23 | package com.isxcode.oxygen.core; 24 | -------------------------------------------------------------------------------- /.github/workflows/deploy-docs.yml: -------------------------------------------------------------------------------- 1 | name: deploy-docs 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | branch: 7 | description: 'which branch' 8 | required: true 9 | default: 'latest' 10 | 11 | jobs: 12 | build: 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - name: checkout repository 17 | uses: actions/checkout@v3.0.2 18 | with: 19 | ref: ${{ github.event.inputs.branch }} 20 | 21 | - name: clean docs 22 | uses: appleboy/ssh-action@v0.1.5 23 | with: 24 | host: ${{ secrets.HOST }} 25 | username: ${{ secrets.USERNAME }} 26 | password: ${{ secrets.PASSWORD }} 27 | script_stop: false 28 | script: | 29 | rm -rf /data/nginx/html/spring-oxygen/docs 30 | 31 | - name: publish blogs 32 | uses: appleboy/scp-action@master 33 | with: 34 | host: ${{ secrets.HOST }} 35 | username: ${{ secrets.USERNAME }} 36 | password: ${{ secrets.PASSWORD }} 37 | port: ${{ secrets.PORT }} 38 | source: "docs" 39 | target: "/data/nginx/html/spring-oxygen/" 40 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/java/com/isxcode/oxygen/cli/controller/FreecodeController.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.cli.controller; 2 | 3 | import com.isxcode.oxygen.cli.service.FreecodeService; 4 | import com.isxcode.oxygen.flysql.response.SuccessResponse; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestParam; 8 | 9 | /** 10 | * freecode controller 11 | * 12 | * @author ispong 13 | * @since 0.0.1 14 | */ 15 | @RequestMapping("/freecode") 16 | public class FreecodeController { 17 | 18 | private final FreecodeService freecodeService; 19 | 20 | public FreecodeController(FreecodeService freecodeService) { 21 | 22 | this.freecodeService = freecodeService; 23 | } 24 | 25 | /** 26 | * generate code api 27 | * 28 | * @param tableNames tableNames(split ,) 29 | * @since 0.0.1 30 | */ 31 | @SuccessResponse("generate success!!!") 32 | @GetMapping("/generate") 33 | public void generateCode(@RequestParam String tableNames) { 34 | 35 | freecodeService.startFreecode(tableNames); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/resources/templates/entity/service.java.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.stereotype.Service; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Service - ${tableComment!""} 10 | * 11 | * @author ${freecodeProperties.author} 12 | * @since ${freecodeProperties.version} 13 | */ 14 | @Slf4j 15 | @Service 16 | public class ${className?cap_first}Service implements ${className}InnerService{ 17 | 18 | private final ${className?cap_first}Repository ${className?uncap_first}Repository; 19 | 20 | public ${className?cap_first}Service(${className?cap_first}Repository ${className?uncap_first}Repository){ 21 | 22 | this.${className?uncap_first}Repository=${className?uncap_first}Repository; 23 | } 24 | 25 | /** 26 | * query ${className?cap_first}Entity 27 | * 28 | * @return List[${className?cap_first}Entity] 29 | * @since ${freecodeProperties.version} 30 | */ 31 | public List<${className?cap_first}Entity> query${className?cap_first}(){ 32 | 33 | return ${className?uncap_first}Repository.query${className?cap_first}(); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/resources/templates/entity/entity.java.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}; 2 | 3 | <#list entityPackageList as package> 4 | import ${package}; 5 | 6 | import ${freecodeProperties.baseEntityClass}; 7 | import lombok.EqualsAndHashCode; 8 | import lombok.*; 9 | import com.isxcode.oxygen.flysql.annotation.ColumnName; 10 | import com.isxcode.oxygen.flysql.annotation.TableName; 11 | import java.io.Serializable; 12 | 13 | /** 14 | * Entity - ${tableComment!""} 15 | * 16 | * @author ${freecodeProperties.author} 17 | * @since ${freecodeProperties.version} 18 | */ 19 | @Data 20 | @Builder 21 | @NoArgsConstructor 22 | @AllArgsConstructor 23 | @TableName("${tableName}") 24 | @EqualsAndHashCode(callSuper = true) 25 | public class ${className?cap_first}Entity extends BaseEntity implements Serializable{ 26 | 27 | private static final long serialVersionUID = 1L; 28 | 29 | <#-- 遍历字段 --> 30 | <#list tableColumns as field> 31 | <#if (field.comment)??> 32 | /** 33 | * ${field.comment} 34 | */ 35 | 36 | @ColumnName("${field.originField}") 37 | private ${field.type} ${field.field}; 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/constant/FlysqlConstants.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.constant; 2 | 3 | /** 4 | * flysql constants 5 | * 6 | * @author ispong 7 | * @since 0.0.1 8 | */ 9 | public interface FlysqlConstants { 10 | 11 | /** 默认数据库名称 */ 12 | String PRIMARY_DATASOURCE_NAME = "oxygen_primary_database_name"; 13 | 14 | /** default view name */ 15 | String PRIMARY_VIEW_NAME = "primary"; 16 | 17 | /** replace key */ 18 | String SELECT_REPLACE_CONTENT = "##flysql_columns_info##"; 19 | 20 | /** H2 */ 21 | String H2_DB = "H2"; 22 | 23 | /** MYSQL */ 24 | String MYSQL_DB = "MySQL"; 25 | 26 | /** ORACLE */ 27 | String ORACLE_DB = "Oracle"; 28 | 29 | /** Microsoft SQL Server */ 30 | String SQL_SERVER_DB = "Microsoft SQL Server"; 31 | 32 | /* 33 | * is delete flag 34 | * 35 | * @ispong 36 | */ 37 | String IS_DELETE_COL = "IS_DELETE"; 38 | 39 | /* 40 | * LAST_MODIFIED_DATE flag 41 | * 42 | * @ispong 43 | */ 44 | String LAST_MODIFIED_DATE = "LAST_MODIFIED_DATE"; 45 | 46 | /* 47 | * LAST_MODIFIED_BY flag 48 | * 49 | * @ispong 50 | */ 51 | String LAST_MODIFIED_BY = "LAST_MODIFIED_BY"; 52 | } 53 | -------------------------------------------------------------------------------- /docs/en-us/advance/Database-Config.md: -------------------------------------------------------------------------------- 1 | ### Oracle 2 | 3 | ```yaml 4 | spring: 5 | datasource: 6 | driver-class-name: oracle.jdbc.driver.OracleDriver 7 | url: jdbc:oracle:thin:@${host}:${port}:${db} 8 | username: ${username} 9 | password: ${password} 10 | ``` 11 | 12 | ### Mysql 13 | 14 | ```yaml 15 | spring: 16 | datasource: 17 | driver-class-name: com.mysql.cj.jdbc.Driver 18 | url: jdbc:mysql://${host}:${port}/${db} 19 | username: ${username} 20 | password: ${password} 21 | ``` 22 | 23 | ### MongoDB 24 | 25 | ```yaml 26 | spring: 27 | data: 28 | mongodb: 29 | host: ${host} 30 | port: ${port} 31 | username: ${username} 32 | password: ${password} 33 | database: ${db} 34 | ``` 35 | 36 | or 37 | 38 | ```yaml 39 | spring: 40 | data: 41 | mongodb: 42 | uri: mongodb://${username}:${password}@${host}:${port}/${db} 43 | ``` 44 | 45 | ### H2 46 | 47 | ```yaml 48 | spring: 49 | datasource: 50 | driver-class-name: org.h2.Driver 51 | url: jdbc:h2:${host}:${port}/${db} 52 | username: ${username} 53 | password: ${password} 54 | ``` 55 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/common/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.common; 2 | 3 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 4 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 5 | import com.isxcode.oxygen.flysql.annotation.*; 6 | import com.isxcode.oxygen.flysql.constant.FlysqlConstants; 7 | import java.time.LocalDateTime; 8 | import lombok.Data; 9 | 10 | /** 11 | * base entity 12 | * 13 | * @author ispong 14 | * @since 0.0.1 15 | */ 16 | @Data 17 | public class BaseEntity { 18 | 19 | @CreatedDate 20 | @JsonDeserialize(using = LocalDateTimeDeserializer.class) 21 | @JsonSerialize(using = LocalDateTimeSerializer.class) 22 | private LocalDateTime createdDate; 23 | 24 | @CreatedBy private String createdBy; 25 | 26 | @LastModifiedDate 27 | @JsonDeserialize(using = LocalDateTimeDeserializer.class) 28 | @JsonSerialize(using = LocalDateTimeSerializer.class) 29 | private LocalDateTime lastModifiedDate; 30 | 31 | @LastModifiedBy private String lastModifiedBy; 32 | 33 | @Version private Integer version; 34 | 35 | @IsDelete 36 | @ColumnName(FlysqlConstants.IS_DELETE_COL) 37 | private Integer isDelete; 38 | } 39 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/parse/SqlValue.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.parse; 2 | 3 | import com.isxcode.oxygen.flysql.core.FlysqlExecute; 4 | import java.text.ParseException; 5 | import java.text.SimpleDateFormat; 6 | 7 | public interface SqlValue { 8 | 9 | default String othersValue(String val) { 10 | return FlysqlExecute.addSingleQuote(val); 11 | } 12 | 13 | default String othersVarchar(String val) { 14 | return FlysqlExecute.addSingleQuote(val); 15 | } 16 | 17 | default String getBooleanValue(String val) { 18 | return val; 19 | } 20 | 21 | default String getDateValue(String val) { 22 | SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"); 23 | SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 24 | try { 25 | return FlysqlExecute.addSingleQuote(sdf2.format(sdf.parse(String.valueOf(val)))); 26 | } catch (ParseException e) { 27 | return null; 28 | } 29 | } 30 | 31 | default String getLocalDateTimeValue(String val) { 32 | return FlysqlExecute.addSingleQuote(val); 33 | } 34 | 35 | default String getLocalDateValue(String val) { 36 | return FlysqlExecute.addSingleQuote(val); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/entity/SqlCondition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2020] [ispong] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.isxcode.oxygen.flysql.entity; 17 | 18 | import com.isxcode.oxygen.flysql.enums.SqlOperateType; 19 | import lombok.AllArgsConstructor; 20 | import lombok.Data; 21 | 22 | /** 23 | * sql条件对象 24 | * 25 | * @author ispong 26 | * @since 0.0.1 27 | */ 28 | @Data 29 | @AllArgsConstructor 30 | public class SqlCondition { 31 | 32 | /** 条件类型 */ 33 | private SqlOperateType operateType; 34 | 35 | /** 字段名 */ 36 | private String columnName; 37 | 38 | /** 字段内容 */ 39 | private Object value; 40 | } 41 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/java/com/isxcode/oxygen/cli/properties/FreecodeProperties.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.cli.properties; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | import lombok.Data; 7 | import org.springframework.boot.context.properties.ConfigurationProperties; 8 | 9 | /** 10 | * freecode properties 11 | * 12 | * @author ispong 13 | * @since 0.0.1 14 | */ 15 | @Data 16 | @ConfigurationProperties("oxygen.freecode") 17 | public class FreecodeProperties { 18 | 19 | /** file type */ 20 | private List fileTypes = 21 | Arrays.asList("controller", "entity", "service", "repository", "innerService"); 22 | 23 | /** ignore columns */ 24 | private List ignoreColumns = new ArrayList<>(); 25 | 26 | /** module path (src/main/java/com) end must not has / */ 27 | private String modulePath; 28 | 29 | /** author */ 30 | private String author = "anonymous"; 31 | 32 | /** version */ 33 | private String version = "v0.0.1"; 34 | 35 | /** base entity */ 36 | private String baseEntityClass = "com.isxcode.oxygen.flysql.common.BaseEntity"; 37 | 38 | /** table prefix */ 39 | private String tablePrefix; 40 | 41 | /** template prefix */ 42 | private String templatePrefix = ".java.ftl"; 43 | } 44 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/test/java/com/isxcode/oxygen/core/XmlUtilsTests.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core; 2 | 3 | import com.isxcode.oxygen.core.pojo.Dog; 4 | import com.isxcode.oxygen.core.xml.XmlUtils; 5 | import java.io.IOException; 6 | import java.nio.file.Files; 7 | import java.nio.file.Path; 8 | import java.nio.file.Paths; 9 | import org.junit.jupiter.api.Test; 10 | 11 | public class XmlUtilsTests { 12 | 13 | @Test 14 | public void testXml() { 15 | 16 | String xmlStr = "wang12"; 17 | Path path = Paths.get("Dogs.xml"); 18 | try { 19 | Files.write(path, xmlStr.getBytes()); 20 | } catch (IOException e) { 21 | throw new RuntimeException(e); 22 | } 23 | Dog dog = XmlUtils.parseXmlString(xmlStr, Dog.class); 24 | System.out.println("dog:" + dog); 25 | } 26 | 27 | @Test 28 | public void testXmlFile() { 29 | 30 | Dog dog; 31 | Path path = Paths.get("Dogs.xml"); 32 | try { 33 | dog = XmlUtils.parseXmlInputStream(Files.newInputStream(path), Dog.class); 34 | System.out.println("dog:" + dog); 35 | } catch (IOException e) { 36 | throw new RuntimeException(e); 37 | } 38 | try { 39 | Files.delete(path); 40 | } catch (IOException e) { 41 | throw new RuntimeException(e); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /.github/workflows/release-sonatype.yml: -------------------------------------------------------------------------------- 1 | name: 🔖 release for sonatype 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | branch: 7 | description: 'which branch' 8 | required: true 9 | 10 | jobs: 11 | release: 12 | runs-on: ubuntu-latest 13 | strategy: 14 | matrix: 15 | java: 16 | - 11 17 | 18 | steps: 19 | - name: checkout repository 20 | uses: actions/checkout@v3.0.2 21 | with: 22 | ref: ${{ github.event.inputs.branch }} 23 | 24 | - name: cache gradle 25 | uses: actions/cache@v3.0.9 26 | with: 27 | path: | 28 | ~/.gradle/caches 29 | ~/.gradle/wrapper 30 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} 31 | restore-keys: | 32 | ${{ runner.os }}-gradle- 33 | 34 | - name: gradle build 35 | uses: actions/setup-java@v3 36 | with: 37 | distribution: 'adopt' 38 | java-version: ${{ matrix.java }} 39 | - run: | 40 | chmod +x gradlew 41 | ./gradlew build -x test 42 | 43 | - name: publish to sonatype 44 | run: | 45 | echo 'sonatypePassword=${{ secrets.SONATYPE_PASSWORD }}' >> gradle.properties 46 | ./gradlew publishMavenJavaPublicationToSonatypeRepository 47 | -------------------------------------------------------------------------------- /.github/workflows/release-github.yml: -------------------------------------------------------------------------------- 1 | name: 🔖 release for github 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | branch: 7 | description: 'which branch' 8 | required: true 9 | default: latest 10 | 11 | jobs: 12 | release: 13 | runs-on: ubuntu-latest 14 | strategy: 15 | matrix: 16 | java: 17 | - 11 18 | 19 | steps: 20 | - name: checkout repository 21 | uses: actions/checkout@v3.0.2 22 | with: 23 | ref: ${{ github.event.inputs.branch }} 24 | 25 | - name: cache gradle 26 | uses: actions/cache@v3.0.9 27 | with: 28 | path: | 29 | ~/.gradle/caches 30 | ~/.gradle/wrapper 31 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} 32 | restore-keys: | 33 | ${{ runner.os }}-gradle- 34 | 35 | - name: gradle build 36 | uses: actions/setup-java@v3 37 | with: 38 | distribution: 'adopt' 39 | java-version: ${{ matrix.java }} 40 | - run: | 41 | chmod +x gradlew 42 | ./gradlew build -x test 43 | 44 | - name: publish to github 45 | run: | 46 | echo 'gpr.key=${{ secrets.GITHUB_TOKEN }}' >> gradle.properties 47 | ./gradlew publishGprPublicationToGitHubPackagesRepository 48 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/test/java/com/isxcode/oxygen/core/ExcelUtilsTests.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core; 2 | 3 | import com.isxcode.oxygen.core.excel.ExcelUtils; 4 | import com.isxcode.oxygen.core.exception.OxygenException; 5 | import com.isxcode.oxygen.core.pojo.Dog; 6 | import java.io.IOException; 7 | import java.nio.file.Files; 8 | import java.nio.file.Path; 9 | import java.nio.file.Paths; 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | import org.junit.jupiter.api.Test; 13 | 14 | public class ExcelUtilsTests { 15 | 16 | @Test 17 | public void testGenerateExcelFile() { 18 | 19 | List dogs = new ArrayList<>(); 20 | dogs.add(new Dog("alen", 12)); 21 | dogs.add(new Dog("jack", 14)); 22 | dogs.add(new Dog("john", 18)); 23 | 24 | try { 25 | ExcelUtils.generateFile(dogs, Files.newOutputStream(Paths.get("Dogs.xlsx"))); 26 | } catch (OxygenException | IOException e) { 27 | System.out.println(e.getMessage()); 28 | } 29 | } 30 | 31 | @Test 32 | public void testExcelParseFile() { 33 | 34 | try { 35 | Path path = Paths.get("Dogs.xlsx"); 36 | List dogs = ExcelUtils.parseFile(Files.newInputStream(path), Dog.class); 37 | dogs.forEach(e -> System.out.println(e.toString())); 38 | Files.delete(path); 39 | } catch (IOException e) { 40 | System.out.println(e.getMessage()); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/resources/templates/entity/controller.java.ftl: -------------------------------------------------------------------------------- 1 | package ${packageName}; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | import com.isxcode.oxygen.flysql.response.SuccessResponse; 7 | 8 | import java.util.List; 9 | import lombok.extern.slf4j.Slf4j; 10 | 11 | /** 12 | * Controller - ${tableComment!""} 13 | * 14 | * @author ${freecodeProperties.author} 15 | * @since ${freecodeProperties.version} 16 | */ 17 | @Slf4j 18 | @RestController 19 | @RequestMapping("/${className?uncap_first}") 20 | public class ${className?cap_first}Controller { 21 | 22 | public final ${className?cap_first}Service ${className?uncap_first}Service; 23 | 24 | public ${className?cap_first}Controller(${className?cap_first}Service ${className?uncap_first}Service) { 25 | 26 | this.${className?uncap_first}Service = ${className?uncap_first}Service; 27 | } 28 | 29 | /** 30 | * query ${className?cap_first}Entity 31 | * 32 | * @return String 33 | */ 34 | @SuccessResponse("Success") 35 | @GetMapping("/query${className?cap_first}") 36 | public List<${className?cap_first}Entity> query${className?cap_first}() { 37 | 38 | return ${className?uncap_first}Service.query${className?cap_first}(); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/parse/OracleSqlValue.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.parse; 2 | 3 | import java.text.ParseException; 4 | import java.text.SimpleDateFormat; 5 | 6 | public class OracleSqlValue implements SqlValue { 7 | 8 | @Override 9 | public String getBooleanValue(String val) { 10 | return Boolean.getBoolean(val) ? "1" : "0"; 11 | } 12 | 13 | @Override 14 | public String getDateValue(String val) { 15 | SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"); 16 | SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 17 | try { 18 | return "TO_DATE('" 19 | + sdf2.format(sdf.parse(String.valueOf(val))) 20 | + "', 'YYYY-MM-DD HH24:MI:SS')"; 21 | } catch (ParseException e) { 22 | return null; 23 | } 24 | } 25 | 26 | @Override 27 | public String getLocalDateTimeValue(String val) { 28 | val = val.replace("T", " "); 29 | val = val.substring(0, val.indexOf(".")); 30 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 31 | SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 32 | try { 33 | return "TO_DATE('" + sdf2.format(sdf.parse(val)) + "', 'YYYY-MM-DD HH24:MI:SS')"; 34 | } catch (ParseException e) { 35 | return null; 36 | } 37 | } 38 | 39 | @Override 40 | public String getLocalDateValue(String val) { 41 | return "TO_DATE('" + val + "', 'YYYY-MM-DD')"; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/test/java/com/isxcode/oxygen/core/HttpUtilsTests.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core; 2 | 3 | import com.isxcode.oxygen.core.exception.OxygenException; 4 | import com.isxcode.oxygen.core.http.HttpUtils; 5 | import java.io.IOException; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | import org.junit.jupiter.api.Test; 9 | 10 | public class HttpUtilsTests { 11 | 12 | @Test 13 | public void testPostHttp() throws IOException { 14 | 15 | String url = "https://api.isxcode.com/leo/version"; 16 | 17 | Map headers = new HashMap<>(); 18 | headers.put("user", "ispong"); 19 | 20 | Map requestParams = new HashMap<>(); 21 | requestParams.put("user", "ispong"); 22 | 23 | try { 24 | System.out.println(HttpUtils.doPost(url, headers, requestParams, String.class)); 25 | } catch (OxygenException | IOException e) { 26 | System.out.println(e.getMessage()); 27 | throw e; 28 | } 29 | } 30 | 31 | @Test 32 | public void testGetHttp() { 33 | 34 | String url = "https://api.isxcode.com/leo/version"; 35 | 36 | Map headers = new HashMap<>(); 37 | headers.put("user", "ispong"); 38 | 39 | Map requestParams = new HashMap<>(); 40 | requestParams.put("user", "ispong"); 41 | 42 | try { 43 | System.out.println(HttpUtils.doGet(url, headers, requestParams, String.class)); 44 | } catch (OxygenException e) { 45 | System.out.println(e.getMessage()); 46 | throw e; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/java/com/isxcode/oxygen/cli/entity/TableColumnInfo.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.cli.entity; 2 | 3 | import com.isxcode.oxygen.cli.utils.FreecodeUtils; 4 | import com.isxcode.oxygen.core.reflect.ReflectUtils; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | /** 10 | * table column info 11 | * 12 | * @author ispong 13 | * @version v0.1.0 14 | */ 15 | @Data 16 | @AllArgsConstructor 17 | @NoArgsConstructor 18 | public class TableColumnInfo { 19 | 20 | /** field */ 21 | private String field; 22 | 23 | /** type */ 24 | private String type; 25 | 26 | /** collation */ 27 | private String collation; 28 | 29 | /** key */ 30 | private String key; 31 | 32 | /** extra */ 33 | private String extra; 34 | 35 | /** privileges */ 36 | private String privileges; 37 | 38 | /** comment */ 39 | private String comment; 40 | 41 | /** origin field */ 42 | private String originField; 43 | 44 | /** 45 | * get origin field 46 | * 47 | * @return OriginField 48 | */ 49 | public String getOriginField() { 50 | 51 | return this.field.toLowerCase(); 52 | } 53 | 54 | /** 55 | * get data type 56 | * 57 | * @return data type 58 | */ 59 | public String getType() { 60 | 61 | return FreecodeUtils.parseDataType(this.type); 62 | } 63 | 64 | /** 65 | * get data field 66 | * 67 | * @return data field 68 | */ 69 | public String getField() { 70 | 71 | return ReflectUtils.lineToHump(this.field); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /oxygen-spring-boot-starter/src/main/java/com/isxcode/oxygen/starter/OxygenStarterAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.starter; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 5 | import org.springframework.context.annotation.Bean; 6 | 7 | /** 8 | * print terminal banner 9 | * 10 | * @author ispong 11 | * @since 0.0.1 12 | */ 13 | @Slf4j 14 | public class OxygenStarterAutoConfiguration { 15 | 16 | /** 17 | * init oxygen banner 18 | * 19 | * @since 0.0.1 20 | */ 21 | @Bean 22 | @ConditionalOnClass(OxygenStarterAutoConfiguration.class) 23 | private void initOxygenBanner() { 24 | 25 | log.debug("welcome to use spring-oxygen"); 26 | System.out.println(" _____ _ ____ "); 27 | System.out.println(" / ___/____ _____(_)___ ____ _ / __ \\_ ____ ______ ____ ____ "); 28 | System.out.println( 29 | " \\__ \\/ __ \\/ ___/ / __ \\/ __ `/_____/ / / / |/_/ / / / __ `/ _ \\/ __ \\"); 30 | System.out.println(" ___/ / /_/ / / / / / / / /_/ /_____/ /_/ /> { 13 | 14 | /** 15 | * select 16 | * 17 | * @return list[data] 18 | * @since 2019-12-26 19 | */ 20 | List query(); 21 | 22 | /** 23 | * page select 24 | * 25 | * @param page page 26 | * @param size size 27 | * @return list[data] 28 | * @since 2019-12-26 29 | */ 30 | FlysqlPage queryPage(Integer page, Integer size); 31 | 32 | /** 33 | * select one 34 | * 35 | * @return data 36 | * @since 2019-12-26 37 | */ 38 | A getOne(); 39 | 40 | /** 41 | * update data 42 | * 43 | * @since 2019-12-26 44 | */ 45 | void doUpdate(); 46 | 47 | /** 48 | * save data 49 | * 50 | * @param entity model object 51 | * @since 2019-12-26 52 | */ 53 | void save(A entity); 54 | 55 | /** 56 | * batch save data 57 | * 58 | * @param entity model object 59 | * @since 2019-12-26 60 | */ 61 | void batchSave(List entity); 62 | 63 | /** 64 | * delete data 65 | * 66 | * @since 2019-12-26 67 | */ 68 | void doDelete(); 69 | 70 | /* 71 | * update is_delete 72 | * 73 | * @ispong 74 | */ 75 | void doIsDelete(); 76 | 77 | /** 78 | * count data 79 | * 80 | * @return countNum 81 | * @since 0.0.1 82 | */ 83 | Integer count(); 84 | } 85 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/enums/SqlOperateType.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.enums; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | 6 | /** 7 | * sql operate type 8 | * 9 | * @author ispong 10 | * @since 0.0.1 11 | */ 12 | @AllArgsConstructor 13 | public enum SqlOperateType { 14 | 15 | /** select() */ 16 | SELECT(""), 17 | 18 | /** eq() */ 19 | EQ(" = "), 20 | 21 | /** ne() */ 22 | NE(" != "), 23 | 24 | /** setVar() */ 25 | SET_VALUE(""), 26 | 27 | /** between() */ 28 | BETWEEN(" between "), 29 | 30 | /** lt() */ 31 | LT(" < "), 32 | 33 | /** ltEq() */ 34 | LT_EQ(" <= "), 35 | 36 | /** gt() */ 37 | GT(" > "), 38 | 39 | /** gtEq() */ 40 | GT_EQ(" >= "), 41 | 42 | /** orderBy() */ 43 | ORDER_BY(""), 44 | 45 | /** like() */ 46 | LIKE(" like "), 47 | 48 | /** notIn() */ 49 | NOT_IN(" not in "), 50 | 51 | /** in() */ 52 | IN(" in "), 53 | 54 | /** or() */ 55 | OR(" or "), 56 | 57 | /** and() */ 58 | AND(" and "), 59 | 60 | /** limit() */ 61 | LIMIT(" limit "), 62 | 63 | /** update() */ 64 | UPDATE(" update "), 65 | 66 | /** isNull() */ 67 | IS_NULL(" is null "), 68 | 69 | /** isNull() */ 70 | IS_NOT_NULL(" is not null "), 71 | 72 | /** notBetween() */ 73 | NOT_BETWEEN(" not between "), 74 | 75 | /** notLike() */ 76 | NOT_LIKE(" not like "), 77 | 78 | /** sql() */ 79 | SQL(""), 80 | 81 | /** andStart() */ 82 | AND_START(" and ( "), 83 | 84 | /** andEnd() */ 85 | AND_END(" ) "), 86 | ; 87 | 88 | @Getter private final String code; 89 | } 90 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/test/java/com/isxcode/oxygen/core/ReflectUtilsTests.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core; 2 | 3 | import com.isxcode.oxygen.core.pojo.Dog; 4 | import com.isxcode.oxygen.core.reflect.FieldBody; 5 | import com.isxcode.oxygen.core.reflect.ReflectUtils; 6 | import java.lang.reflect.InvocationTargetException; 7 | import java.lang.reflect.Method; 8 | import java.util.List; 9 | import org.junit.jupiter.api.Test; 10 | 11 | public class ReflectUtilsTests { 12 | 13 | @Test 14 | public void testNewInstance() { 15 | 16 | Dog dog = ReflectUtils.newInstance(Dog.class); 17 | dog.setAge(12); 18 | dog.setName("alen"); 19 | System.out.println("dog:" + dog); 20 | } 21 | 22 | @Test 23 | public void testQueryFieldsBody() { 24 | 25 | List fieldBodies = ReflectUtils.queryFields(Dog.class); 26 | Dog dog = new Dog(); 27 | for (FieldBody metaFieldBody : fieldBodies) { 28 | Method writeMethod = metaFieldBody.getWriteMethod(); 29 | Method readMethod = metaFieldBody.getReadMethod(); 30 | try { 31 | if ("name".equals(metaFieldBody.getField().getName())) { 32 | writeMethod.invoke(dog, "alen"); 33 | Object dogName = readMethod.invoke(dog); 34 | System.out.println("dogName" + dogName); 35 | System.out.println(dog); 36 | } 37 | } catch (IllegalAccessException | InvocationTargetException e) { 38 | e.printStackTrace(); 39 | } 40 | } 41 | } 42 | 43 | @Test 44 | public void testName() { 45 | 46 | System.out.println(ReflectUtils.upperFirstCase("userName")); 47 | 48 | System.out.println(ReflectUtils.humpToLine("userName")); 49 | 50 | System.out.println(ReflectUtils.lineToHump("user_name")); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /docs/en-us/advance/Advance-Usage.md: -------------------------------------------------------------------------------- 1 | ### Oracle/Mysql/H2 2 | 3 | ```yaml 4 | oxygen: 5 | flysql: 6 | datasource: 7 | dbSource1: 8 | driver-class-name: oracle.jdbc.driver.OracleDriver 9 | url: jdbc:oracle:thin:@${host}:${port}:${db} 10 | username: ${username} 11 | password: ${password} 12 | dbSource2: 13 | driver-class-name: com.mysql.cj.jdbc.Driver 14 | url: jdbc:mysql://${host}:${port}/${db} 15 | username: ${username} 16 | password: ${password} 17 | dbSource3: 18 | driver-class-name: org.h2.Driver 19 | url: jdbc:h2:${host}:${port}/${db} 20 | username: ${username} 21 | password: ${password} 22 | ${oxygen_db_name}: 23 | driver-class-name: org.h2.Driver 24 | url: jdbc:h2:${host}:${port}/${db} 25 | username: ${username} 26 | password: ${password} 27 | ``` 28 | 29 | ### MongoDB 30 | 31 | ```yaml 32 | oxygen: 33 | flysql: 34 | mongodb: 35 | dbSource1: 36 | uri: mongodb://${username}:${password}@${host}:${port}/${db} 37 | dbSource2: 38 | host: ${host} 39 | port: ${port} 40 | username: ${username} 41 | password: ${password} 42 | database: ${db} 43 | ${oxygen_db_name}: 44 | host: ${host} 45 | port: ${port} 46 | username: ${username} 47 | password: ${password} 48 | database: ${db} 49 | ``` 50 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/main/java/com/isxcode/oxygen/core/snowflake/SnowflakeUtils.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core.snowflake; 2 | 3 | public class SnowflakeUtils { 4 | 5 | private static final int TIME_LEN = 41; 6 | private static final int DATA_LEN = 5; 7 | private static final int WORK_LEN = 5; 8 | private static final int SEQ_LEN = 12; 9 | 10 | private static final long START_TIME = 1420041600000L; 11 | private static long LAST_TIME_STAMP = -1L; 12 | private static final int TIME_LEFT_BIT = 64 - 1 - TIME_LEN; 13 | 14 | private static final long DATA_ID = 1; 15 | private static final long WORK_ID = 1; 16 | private static final int DATA_LEFT_BIT = TIME_LEFT_BIT - DATA_LEN; 17 | private static final int WORK_LEFT_BIT = DATA_LEFT_BIT - WORK_LEN; 18 | 19 | private static long LAST_SEQ = 0L; 20 | private static final long SEQ_MAX_NUM = ~(-1 << SEQ_LEN); 21 | 22 | public static long nextMillis(long lastMillis) { 23 | long now = System.currentTimeMillis(); 24 | while (now <= lastMillis) { 25 | now = System.currentTimeMillis(); 26 | } 27 | return now; 28 | } 29 | 30 | public static synchronized String getNextUuid() { 31 | long now = System.currentTimeMillis(); 32 | if (now < LAST_TIME_STAMP) { 33 | throw new RuntimeException("sys error, too fast"); 34 | } 35 | if (now == LAST_TIME_STAMP) { 36 | LAST_SEQ = (LAST_SEQ + 1) & SEQ_MAX_NUM; 37 | if (LAST_SEQ == 0) { 38 | now = nextMillis(LAST_TIME_STAMP); 39 | } 40 | } else { 41 | LAST_SEQ = 0; 42 | } 43 | LAST_TIME_STAMP = now; 44 | long uuidLong = 45 | ((now - START_TIME) << TIME_LEFT_BIT) 46 | | (DATA_ID << DATA_LEFT_BIT) 47 | | (WORK_ID << WORK_LEFT_BIT) 48 | | LAST_SEQ; 49 | return String.valueOf(uuidLong); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/test/java/com/isxcode/oxygen/flysql/Dog.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql; 2 | 3 | import com.isxcode.oxygen.flysql.annotation.IsDelete; 4 | import com.isxcode.oxygen.flysql.annotation.LastModifiedBy; 5 | import com.isxcode.oxygen.flysql.annotation.LastModifiedDate; 6 | import com.isxcode.oxygen.flysql.annotation.TableName; 7 | import java.math.BigDecimal; 8 | import java.time.LocalDate; 9 | import java.time.LocalDateTime; 10 | import java.util.Date; 11 | import lombok.AllArgsConstructor; 12 | import lombok.Data; 13 | import lombok.NoArgsConstructor; 14 | 15 | /** 16 | * dog meta date 17 | * 18 | * @author ispong 19 | * @since 0.0.2 20 | */ 21 | @Data 22 | @AllArgsConstructor 23 | @NoArgsConstructor 24 | @TableName("DOGS_T") 25 | public class Dog { 26 | 27 | private Integer id; 28 | 29 | private String name; 30 | 31 | private Double amountDouble; 32 | 33 | private BigDecimal amountBigDecimal; 34 | 35 | private Date birthDate; 36 | 37 | private LocalDate birthLocalDate; 38 | 39 | private LocalDateTime birthLocalDateTime; 40 | 41 | private Boolean isAlive; 42 | 43 | @IsDelete private Integer isDelete; 44 | 45 | @LastModifiedBy private String lastModifiedBy; 46 | 47 | @LastModifiedDate private LocalDateTime lastModifiedDate; 48 | 49 | public Dog( 50 | Integer id, 51 | String name, 52 | Double amountDouble, 53 | BigDecimal amountBigDecimal, 54 | Date birthDate, 55 | LocalDate birthLocalDate, 56 | LocalDateTime birthLocalDateTime, 57 | Boolean isAlive) { 58 | this.id = id; 59 | this.name = name; 60 | this.amountDouble = amountDouble; 61 | this.amountBigDecimal = amountBigDecimal; 62 | this.birthDate = birthDate; 63 | this.birthLocalDate = birthLocalDate; 64 | this.birthLocalDateTime = birthLocalDateTime; 65 | this.isAlive = isAlive; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/main/java/com/isxcode/oxygen/core/xml/XmlUtils.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core.xml; 2 | 3 | import com.isxcode.oxygen.core.exception.OxygenException; 4 | import com.isxcode.oxygen.core.reflect.ReflectUtils; 5 | import java.io.ByteArrayInputStream; 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | import javax.xml.parsers.ParserConfigurationException; 9 | import javax.xml.parsers.SAXParser; 10 | import javax.xml.parsers.SAXParserFactory; 11 | import lombok.extern.slf4j.Slf4j; 12 | import org.xml.sax.SAXException; 13 | import org.xml.sax.helpers.DefaultHandler; 14 | 15 | /** 16 | * xml utils 17 | * 18 | * @author ispong 19 | * @since 0.0.1 20 | */ 21 | @Slf4j 22 | public class XmlUtils { 23 | 24 | /** 25 | * parse inputSteam content 26 | * 27 | * @param inputStream inputStream 28 | * @param targetClass targetClass 29 | * @param T 30 | * @return target 31 | * @since 0.0.1 32 | */ 33 | public static T parseXmlInputStream( 34 | InputStream inputStream, Class targetClass) { 35 | 36 | SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); 37 | 38 | try { 39 | SAXParser saxParser = saxParserFactory.newSAXParser(); 40 | T target = ReflectUtils.newInstance(targetClass); 41 | saxParser.parse(inputStream, target); 42 | return target; 43 | } catch (ParserConfigurationException | SAXException | IOException e) { 44 | 45 | log.error(e.getMessage()); 46 | throw new OxygenException(e.getMessage()); 47 | } 48 | } 49 | 50 | /** 51 | * parse string content 52 | * 53 | * @param data stringData 54 | * @param targetClass targetClass 55 | * @param T 56 | * @return target 57 | * @since 0.0.1 58 | */ 59 | public static T parseXmlString(String data, Class targetClass) { 60 | 61 | return parseXmlInputStream(new ByteArrayInputStream(data.getBytes()), targetClass); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/test/java/com/isxcode/oxygen/core/EmailUtilsTests.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core; 2 | 3 | import com.isxcode.oxygen.core.config.OxygenCoreAutoConfiguration; 4 | import com.isxcode.oxygen.core.email.EmailUtils; 5 | import com.isxcode.oxygen.core.exception.OxygenException; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import org.junit.jupiter.api.Test; 9 | import org.springframework.beans.factory.annotation.Value; 10 | import org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.test.context.ActiveProfiles; 13 | import org.springframework.test.context.ContextConfiguration; 14 | import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; 15 | 16 | @SpringBootTest 17 | @ActiveProfiles("test") 18 | @ContextConfiguration( 19 | classes = { 20 | MailSenderAutoConfiguration.class, 21 | OxygenCoreAutoConfiguration.class, 22 | FreeMarkerConfigurer.class 23 | }) 24 | public class EmailUtilsTests { 25 | 26 | @Value("${test.email}") 27 | private String email; 28 | 29 | @Value("${test.emailContent}") 30 | private String emailContent; 31 | 32 | @Value("${test.senderName}") 33 | private String senderName; 34 | 35 | @Test 36 | public void testSendEmail() { 37 | 38 | try { 39 | EmailUtils.sendSimpleEmail(email, emailContent, "test1", senderName); 40 | } catch (OxygenException e) { 41 | System.out.println(e.getMessage()); 42 | throw e; 43 | } 44 | 45 | try { 46 | List emails = new ArrayList<>(); 47 | emails.add(email); 48 | EmailUtils.sendSimpleEmail(emails, emailContent, "test2", senderName); 49 | } catch (OxygenException e) { 50 | System.out.println(e.getMessage()); 51 | throw e; 52 | } 53 | 54 | try { 55 | EmailUtils.sendNormalHtmlEmail(email, emailContent, "test3", senderName); 56 | } catch (OxygenException e) { 57 | System.out.println(e.getMessage()); 58 | throw e; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/test/java/com/isxcode/oxygen/core/pojo/Dog.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core.pojo; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.isxcode.oxygen.core.excel.ExcelType; 5 | import org.xml.sax.Attributes; 6 | import org.xml.sax.helpers.DefaultHandler; 7 | 8 | @JsonIgnoreProperties({"location"}) 9 | public class Dog extends DefaultHandler { 10 | 11 | @ExcelType(cellName = "name") 12 | private String name; 13 | 14 | @ExcelType(cellName = "age") 15 | private Integer age; 16 | 17 | private String localName; 18 | 19 | public Dog(String name, Integer age) { 20 | this.name = name; 21 | this.age = age; 22 | } 23 | 24 | public Dog() {} 25 | 26 | public String getName() { 27 | return name; 28 | } 29 | 30 | public void setName(String name) { 31 | this.name = name; 32 | } 33 | 34 | public Integer getAge() { 35 | return age; 36 | } 37 | 38 | public void setAge(Integer age) { 39 | this.age = age; 40 | } 41 | 42 | public String getLocalName() { 43 | return localName; 44 | } 45 | 46 | public void setLocalName(String localName) { 47 | this.localName = localName; 48 | } 49 | 50 | @Override 51 | public void startElement(String uri, String localName, String qName, Attributes attributes) { 52 | 53 | this.localName = qName; 54 | } 55 | 56 | @Override 57 | public void characters(char[] ch, int start, int length) { 58 | 59 | String date = new String(ch, start, length); 60 | if (!"\n".equals(date)) { 61 | switch (this.localName) { 62 | case "name": 63 | this.name = date; 64 | break; 65 | case "age": 66 | try { 67 | this.age = Integer.parseInt(date); 68 | } catch (NumberFormatException e) { 69 | this.age = 0; 70 | } 71 | break; 72 | default: 73 | } 74 | } 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | return "Dog{" 80 | + "name='" 81 | + name 82 | + '\'' 83 | + ", age=" 84 | + age 85 | + ", localName='" 86 | + localName 87 | + '\'' 88 | + '}'; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/java/com/isxcode/oxygen/cli/config/FreecodeAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.cli.config; 2 | 3 | import com.isxcode.oxygen.cli.controller.FreecodeController; 4 | import com.isxcode.oxygen.cli.properties.FreecodeProperties; 5 | import com.isxcode.oxygen.cli.repository.FreecodeRepository; 6 | import com.isxcode.oxygen.cli.service.FreecodeService; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; 9 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 10 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 11 | import org.springframework.context.annotation.Bean; 12 | 13 | /** 14 | * freecode auto configure 15 | * 16 | * @author ispong 17 | * @since 0.0.1 18 | */ 19 | @Slf4j 20 | @EnableConfigurationProperties(FreecodeProperties.class) 21 | public class FreecodeAutoConfiguration { 22 | 23 | /** 24 | * init freecode repository 25 | * 26 | * @return FreecodeRepository 27 | * @since 0.0.1 28 | */ 29 | @Bean 30 | @ConditionalOnClass(FreecodeAutoConfiguration.class) 31 | public FreecodeRepository initFreecodeRepository() { 32 | 33 | return new FreecodeRepository(); 34 | } 35 | 36 | /** 37 | * init freecode service 38 | * 39 | * @param freecodeProperties freecodeProperties 40 | * @param freecodeRepository freecodeRepository 41 | * @return FreecodeService 42 | * @since 0.0.1 43 | */ 44 | @Bean 45 | @ConditionalOnClass(FreecodeRepository.class) 46 | public FreecodeService initFreecodeService( 47 | FreecodeRepository freecodeRepository, FreecodeProperties freecodeProperties) { 48 | 49 | return new FreecodeService(freecodeRepository, freecodeProperties); 50 | } 51 | 52 | /** 53 | * init freecode controller 54 | * 55 | * @param freecodeService freecodeService 56 | * @return FreecodeController 57 | * @since 0.0.1 58 | */ 59 | @Bean 60 | @ConditionalOnBean(FreecodeService.class) 61 | public FreecodeController initFreecodeController(FreecodeService freecodeService) { 62 | 63 | return new FreecodeController(freecodeService); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | branches: 6 | - latest 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | strategy: 12 | fail-fast: false 13 | matrix: 14 | language: ['java'] 15 | java: 16 | - 8 17 | 18 | steps: 19 | - name: checkout repository 20 | uses: actions/checkout@v3.0.2 21 | 22 | - name: cache gradle 23 | uses: actions/cache@v3.0.9 24 | with: 25 | path: | 26 | ~/.gradle/caches 27 | ~/.gradle/wrapper 28 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} 29 | restore-keys: | 30 | ${{ runner.os }}-gradle- 31 | 32 | - name: inititalize codeql 33 | uses: github/codeql-action/init@v2 34 | with: 35 | languages: ${{ matrix.language }} 36 | config-file: ./.github/codeql/codeql-config.yml 37 | 38 | - name: gradle build 39 | uses: actions/setup-java@v3 40 | with: 41 | distribution: 'adopt' 42 | java-version: ${{ matrix.java }} 43 | - run: | 44 | chmod +x gradlew 45 | echo 'project.version=0.0.1' >> gradle.properties 46 | ./gradlew build test 47 | 48 | - name: codeql analysis 49 | uses: github/codeql-action/analyze@v2 50 | 51 | - name: setup .net env 52 | uses: actions/setup-dotnet@v3.0.3 53 | with: 54 | dotnet-version: 3.1.401 55 | 56 | - name: report generator 57 | uses: danielpalme/ReportGenerator-GitHub-Action@5.1.10 58 | with: 59 | reports: ./oxygen-spring-boot-starter/build/reports/jacoco/test/jacocoTestReport.xml;./spring-oxygen-core/build/reports/jacoco/test/jacocoTestReport.xml;./spring-oxygen-flysql/build/reports/jacoco/test/jacocoTestReport.xml;./spring-oxygen-freecode/build/reports/jacoco/test/jacocoTestReport.xml; 60 | sourcedirs: ./oxygen-spring-boot-starter/src/main/java/;./spring-oxygen-core/src/main/java/;./spring-oxygen-flysql/src/main/java/;./spring-oxygen-freecode/src/main/java/; 61 | targetdir: ./coverage/ 62 | reporttypes: lcov 63 | 64 | - name: coveralls analysis 65 | uses: coverallsapp/github-action@1.1.3 66 | with: 67 | github-token: ${{ secrets.GITHUB_TOKEN }} 68 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/common/OxygenHolder.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.common; 2 | 3 | import java.util.Collection; 4 | import org.springframework.security.core.Authentication; 5 | import org.springframework.security.core.GrantedAuthority; 6 | import org.springframework.security.core.context.SecurityContextHolder; 7 | 8 | public class OxygenHolder { 9 | 10 | public static String getUserUuid() { 11 | 12 | if (SecurityContextHolder.getContext() == null 13 | || SecurityContextHolder.getContext().getAuthentication() == null 14 | || SecurityContextHolder.getContext().getAuthentication().getPrincipal() == null) { 15 | 16 | return "anonymous"; 17 | } 18 | 19 | return String.valueOf(SecurityContextHolder.getContext().getAuthentication().getPrincipal()); 20 | } 21 | 22 | public static void setUserUuid(String userUuid) { 23 | 24 | Authentication authentication = 25 | new Authentication() { 26 | @Override 27 | public boolean equals(Object another) { 28 | 29 | if (!(another instanceof Authentication)) { 30 | return false; 31 | } 32 | 33 | Authentication auth = (Authentication) another; 34 | return auth.getName().equals(this.getName()); 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return null; 40 | } 41 | 42 | @Override 43 | public int hashCode() { 44 | return 0; 45 | } 46 | 47 | @Override 48 | public String getName() { 49 | return null; 50 | } 51 | 52 | @Override 53 | public Collection getAuthorities() { 54 | return null; 55 | } 56 | 57 | @Override 58 | public Object getCredentials() { 59 | return null; 60 | } 61 | 62 | @Override 63 | public Object getDetails() { 64 | return null; 65 | } 66 | 67 | @Override 68 | public Object getPrincipal() { 69 | return userUuid; 70 | } 71 | 72 | @Override 73 | public boolean isAuthenticated() { 74 | return false; 75 | } 76 | 77 | @Override 78 | public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {} 79 | }; 80 | 81 | SecurityContextHolder.getContext().setAuthentication(authentication); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/entity/FlysqlKey.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.entity; 2 | 3 | import com.isxcode.oxygen.flysql.enums.DataBaseType; 4 | import com.isxcode.oxygen.flysql.enums.SqlType; 5 | import com.isxcode.oxygen.flysql.properties.FlysqlProperties; 6 | import lombok.Data; 7 | import org.springframework.data.mongodb.core.MongoTemplate; 8 | import org.springframework.jdbc.core.JdbcTemplate; 9 | 10 | /** 11 | * flysql的构造器的核心要素 12 | * 13 | * @author ispong 14 | * @since 0.0.1 15 | */ 16 | @Data 17 | public class FlysqlKey { 18 | 19 | /** 临时返回对象 */ 20 | private Class targetClass; 21 | 22 | /** 数据源对应的jdbcTemplate */ 23 | private JdbcTemplate jdbcTemplate; 24 | 25 | /** 视图名称 */ 26 | private String viewSqlName; 27 | 28 | /** 执行器类型 */ 29 | private SqlType sqlType; 30 | 31 | /** 数据源对应的mongoTemplate */ 32 | private MongoTemplate mongoTemplate; 33 | 34 | /** 数据源类型 */ 35 | private DataBaseType dataBaseType; 36 | 37 | /** 暂时日志 */ 38 | private FlysqlProperties flysqlProperties; 39 | 40 | public FlysqlKey( 41 | DataBaseType dataBaseType, 42 | SqlType sqlType, 43 | JdbcTemplate jdbcTemplate, 44 | Class targetClass, 45 | String viewSqlName, 46 | FlysqlProperties flysqlProperties) { 47 | 48 | this.flysqlProperties = flysqlProperties; 49 | this.targetClass = targetClass; 50 | this.jdbcTemplate = jdbcTemplate; 51 | this.viewSqlName = viewSqlName; 52 | this.sqlType = sqlType; 53 | this.dataBaseType = dataBaseType; 54 | } 55 | 56 | public FlysqlKey( 57 | DataBaseType dataBaseType, 58 | SqlType sqlType, 59 | JdbcTemplate jdbcTemplate, 60 | Class targetClass, 61 | FlysqlProperties flysqlProperties) { 62 | 63 | this.flysqlProperties = flysqlProperties; 64 | this.targetClass = targetClass; 65 | this.jdbcTemplate = jdbcTemplate; 66 | this.sqlType = sqlType; 67 | this.dataBaseType = dataBaseType; 68 | } 69 | 70 | public FlysqlKey( 71 | DataBaseType dataBaseType, 72 | SqlType sqlType, 73 | MongoTemplate mongoTemplate, 74 | Class targetClass, 75 | FlysqlProperties flysqlProperties) { 76 | 77 | this.flysqlProperties = flysqlProperties; 78 | this.targetClass = targetClass; 79 | this.mongoTemplate = mongoTemplate; 80 | this.sqlType = sqlType; 81 | this.dataBaseType = dataBaseType; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/core/Flysql.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.core; 2 | 3 | import com.isxcode.oxygen.flysql.constant.FlysqlConstants; 4 | import com.isxcode.oxygen.flysql.properties.FlysqlProperties; 5 | import java.util.Map; 6 | import javax.sql.DataSource; 7 | import org.springframework.data.mongodb.core.MongoTemplate; 8 | import org.springframework.jdbc.core.JdbcTemplate; 9 | 10 | /** 11 | * init Flysql 12 | * 13 | * @author ispong 14 | * @version 0.0.2 15 | */ 16 | public class Flysql { 17 | 18 | /** storage jdbc template */ 19 | private final Map jdbcTemplateMap; 20 | 21 | /** storage mongo template */ 22 | private final Map mongdTemplateMap; 23 | 24 | /** flysql config */ 25 | public final FlysqlProperties flysqlProperties; 26 | 27 | public Flysql( 28 | Map jdbcTemplateMap, 29 | Map mongdTemplateMap, 30 | FlysqlProperties flysqlProperties) { 31 | 32 | this.flysqlProperties = flysqlProperties; 33 | this.mongdTemplateMap = mongdTemplateMap; 34 | this.jdbcTemplateMap = jdbcTemplateMap; 35 | } 36 | 37 | /** 38 | * build jdbc Flysql 39 | * 40 | * @return FlysqlBuilder 41 | */ 42 | public FlysqlBuilder build() { 43 | 44 | return build(FlysqlConstants.PRIMARY_DATASOURCE_NAME); 45 | } 46 | 47 | /** 48 | * build jdbc Flysql 49 | * 50 | * @param dataBaseName dataBaseName 51 | * @return FlysqlBuilder 52 | */ 53 | public FlysqlBuilder build(String dataBaseName) { 54 | 55 | return new FlysqlBuilder(jdbcTemplateMap.get(dataBaseName), flysqlProperties); 56 | } 57 | 58 | /** 59 | * build mongo Flysql 60 | * 61 | * @return FlysqlBuilder 62 | */ 63 | public FlysqlBuilder buildMongo() { 64 | 65 | return buildMongo(FlysqlConstants.PRIMARY_DATASOURCE_NAME); 66 | } 67 | 68 | /** 69 | * build mongo Flysql 70 | * 71 | * @param dataBaseName dataBaseName 72 | * @return FlysqlBuilder 73 | */ 74 | public FlysqlBuilder buildMongo(String dataBaseName) { 75 | 76 | return new FlysqlBuilder(mongdTemplateMap.get(dataBaseName), flysqlProperties); 77 | } 78 | 79 | /** 80 | * get default datasource 81 | * 82 | * @return DataSource 83 | */ 84 | public DataSource getDefaultDataSource() { 85 | 86 | return jdbcTemplateMap.get(FlysqlConstants.PRIMARY_DATASOURCE_NAME).getDataSource(); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/response/SuccessResponseAdvice.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.response; 2 | 3 | import com.isxcode.oxygen.flysql.common.BaseResponse; 4 | import java.io.InputStream; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.aspectj.lang.JoinPoint; 7 | import org.aspectj.lang.annotation.*; 8 | import org.aspectj.lang.reflect.MethodSignature; 9 | import org.springframework.context.MessageSource; 10 | import org.springframework.context.NoSuchMessageException; 11 | import org.springframework.context.i18n.LocaleContextHolder; 12 | 13 | /** 14 | * success response advice 15 | * 16 | * @author ispong 17 | * @since 0.0.2 18 | */ 19 | @Aspect 20 | @Slf4j 21 | public class SuccessResponseAdvice { 22 | 23 | private final MessageSource messageSource; 24 | 25 | public SuccessResponseAdvice(MessageSource messageSource) { 26 | this.messageSource = messageSource; 27 | } 28 | 29 | @Pointcut("@annotation(com.isxcode.oxygen.flysql.response.SuccessResponse)") 30 | public void operateLog() {} 31 | 32 | /** 33 | * has return response 34 | * 35 | * @param data data 36 | * @param successResponse successResponse 37 | * @param joinPoint joinPoint 38 | * @since 0.0.1 39 | */ 40 | @AfterReturning(returning = "data", value = "operateLog()&&@annotation(successResponse)") 41 | public void afterReturning(JoinPoint joinPoint, Object data, SuccessResponse successResponse) { 42 | 43 | MethodSignature signature = (MethodSignature) joinPoint.getSignature(); 44 | BaseResponse baseResponse = new BaseResponse<>(); 45 | if (!"void".equals(signature.getReturnType().getName())) { 46 | if (data instanceof InputStream) { 47 | return; 48 | } 49 | baseResponse.setCode(ResponseConstant.SUCCESS_CODE); 50 | if (data.getClass().getDeclaredFields().length == 0) { 51 | baseResponse.setData(null); 52 | } else { 53 | baseResponse.setData(data); 54 | } 55 | baseResponse.setMsg(getMsg(successResponse)); 56 | successResponse(baseResponse); 57 | } else { 58 | baseResponse.setCode(ResponseConstant.SUCCESS_CODE); 59 | baseResponse.setMsg(getMsg(successResponse)); 60 | successResponse(baseResponse); 61 | } 62 | } 63 | 64 | public String getMsg(SuccessResponse successResponse) { 65 | 66 | if (!successResponse.value().isEmpty()) { 67 | return successResponse.value(); 68 | } 69 | 70 | try { 71 | return messageSource.getMessage(successResponse.msg(), null, LocaleContextHolder.getLocale()); 72 | } catch (NoSuchMessageException e) { 73 | return successResponse.msg(); 74 | } 75 | } 76 | 77 | public void successResponse(BaseResponse baseResponse) { 78 | 79 | throw new SuccessException(baseResponse); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/utils/FlysqlUtils.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.utils; 2 | 3 | import com.isxcode.oxygen.core.reflect.ReflectConstants; 4 | import com.isxcode.oxygen.core.reflect.ReflectUtils; 5 | import com.isxcode.oxygen.flysql.annotation.ColumnName; 6 | import com.isxcode.oxygen.flysql.annotation.TableName; 7 | import com.isxcode.oxygen.flysql.entity.ColumnProperties; 8 | import java.beans.PropertyDescriptor; 9 | import java.lang.reflect.Field; 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | import org.springframework.beans.BeanUtils; 13 | 14 | /** 15 | * flysql utils 16 | * 17 | * @author ispong 18 | * @since 0.0.2 19 | */ 20 | public class FlysqlUtils { 21 | 22 | /** 23 | * parse class to map 记录对象,各个字段的映射关系 24 | * 25 | * @param genericType targetClass 26 | * @return Map[propertiesName, type] 27 | * @since 0.0.1 28 | */ 29 | public static Map parseBeanProperties(Class genericType) { 30 | 31 | // 使用spring自带工具进行解析 32 | PropertyDescriptor[] propertyDescriptors = BeanUtils.getPropertyDescriptors(genericType); 33 | // 返回结果 34 | Map columnNameMap = new HashMap<>(propertyDescriptors.length - 1); 35 | for (PropertyDescriptor propertyMeta : propertyDescriptors) { 36 | // 排除class类型 37 | if (!ReflectConstants.CLASS.equals(propertyMeta.getName())) { 38 | ColumnProperties metaColumnProperty = new ColumnProperties(); 39 | metaColumnProperty.setType(propertyMeta.getPropertyType().getName()); 40 | try { 41 | Field metaField = 42 | propertyMeta 43 | .getReadMethod() 44 | .getDeclaringClass() 45 | .getDeclaredField(propertyMeta.getName()); 46 | // 如果用户自定义注解,则使用用户自己定义的字段 47 | if (metaField.isAnnotationPresent(ColumnName.class)) { 48 | metaColumnProperty.setName(metaField.getAnnotation(ColumnName.class).value()); 49 | } else { 50 | metaColumnProperty.setName(ReflectUtils.humpToLine(propertyMeta.getName())); 51 | } 52 | columnNameMap.put(propertyMeta.getName(), metaColumnProperty); 53 | } catch (NoSuchFieldException e) { 54 | // 如果映射失败,则默认使用下划线分割字段名 55 | metaColumnProperty.setName(ReflectUtils.humpToLine(propertyMeta.getName())); 56 | columnNameMap.put(propertyMeta.getName(), metaColumnProperty); 57 | } 58 | } 59 | } 60 | return columnNameMap; 61 | } 62 | 63 | /* get table name 64 | * 65 | * @param targetClass tCls 66 | * @return tableName 67 | * @since 0.0.1 68 | */ 69 | public static String getTableName(Class targetClass) { 70 | 71 | if (targetClass.isAnnotationPresent(TableName.class)) { 72 | return targetClass.getAnnotation(TableName.class).value(); 73 | } 74 | return null; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/main/java/com/isxcode/oxygen/core/config/OxygenCoreAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core.config; 2 | 3 | import com.isxcode.oxygen.core.email.EmailUtils; 4 | import com.isxcode.oxygen.core.freemarker.FreemarkerUtils; 5 | import com.isxcode.oxygen.core.secret.JwtUtils; 6 | import org.springframework.beans.factory.annotation.Qualifier; 7 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; 8 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.mail.MailSender; 11 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; 12 | import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; 13 | 14 | /** 15 | * oxygen-core init auto configuration 16 | * 17 | * @author ispong 18 | * @since 0.0.1 19 | */ 20 | public class OxygenCoreAutoConfiguration { 21 | 22 | /** 23 | * init email thread 24 | * 25 | * @return ThreadPoolTaskExecutor 26 | * @since 0.0.1 27 | */ 28 | @Bean(name = "emailThread") 29 | @ConditionalOnBean(OxygenCoreAutoConfiguration.class) 30 | public ThreadPoolTaskExecutor initEmailThread() { 31 | 32 | ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); 33 | taskExecutor.setCorePoolSize(10); 34 | taskExecutor.setMaxPoolSize(50); 35 | taskExecutor.setQueueCapacity(200); 36 | taskExecutor.setKeepAliveSeconds(60); 37 | taskExecutor.setWaitForTasksToCompleteOnShutdown(true); 38 | taskExecutor.setAwaitTerminationSeconds(60); 39 | 40 | return taskExecutor; 41 | } 42 | 43 | /** 44 | * init email utils 45 | * 46 | * @param mailSender mailSender 47 | * @param emailThread 邮箱线程 48 | * @return EmailMaker 49 | * @since 0.0.1 50 | */ 51 | @Bean 52 | @ConditionalOnBean(OxygenCoreAutoConfiguration.class) 53 | @ConditionalOnProperty(prefix = "spring.mail", name = "username") 54 | public EmailUtils initEmailUtils( 55 | MailSender mailSender, @Qualifier("emailThread") ThreadPoolTaskExecutor emailThread) { 56 | 57 | return new EmailUtils(mailSender, emailThread); 58 | } 59 | 60 | /** 61 | * freemarker init 62 | * 63 | * @param freeMarkerConfigurer freeMarkerConfigurer 64 | * @return FreemarkerUtils 65 | * @since 0.0.1 66 | */ 67 | @Bean 68 | @ConditionalOnBean(OxygenCoreAutoConfiguration.class) 69 | public FreemarkerUtils initFreemarkerUtils(FreeMarkerConfigurer freeMarkerConfigurer) { 70 | 71 | return new FreemarkerUtils(freeMarkerConfigurer); 72 | } 73 | 74 | /** 75 | * init jwt key 76 | * 77 | * @return JwtUtils 78 | * @since 0.0.1 79 | */ 80 | @Bean(initMethod = "init") 81 | @ConditionalOnBean(OxygenCoreAutoConfiguration.class) 82 | public JwtUtils initJwtUtils() { 83 | 84 | return new JwtUtils(); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/java/com/isxcode/oxygen/cli/repository/FreecodeRepository.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.cli.repository; 2 | 3 | import com.isxcode.oxygen.cli.constant.FreecodeConstants; 4 | import com.isxcode.oxygen.cli.entity.TableColumnInfo; 5 | import com.isxcode.oxygen.cli.exception.FreecodeException; 6 | import com.isxcode.oxygen.cli.utils.FreecodeUtils; 7 | import com.isxcode.oxygen.core.reflect.ReflectUtils; 8 | import com.isxcode.oxygen.flysql.enums.DataBaseType; 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | /** 13 | * freecode repository 14 | * 15 | * @author ispong 16 | * @since 0.0.1 17 | */ 18 | public class FreecodeRepository { 19 | 20 | /** 21 | * get tables columns 22 | * 23 | * @param tableName tableName 24 | * @param ignoreFields ignoreFields 25 | * @return List[TableColumnInfo] 26 | * @since 2020-01-09 27 | */ 28 | public List getTableColumns(String tableName, List ignoreFields) { 29 | 30 | // get sql string 31 | String sqlStr; 32 | if (DataBaseType.MYSQL.name().equals(FreecodeUtils.getDataBaseType())) { 33 | sqlStr = "show full columns from " + tableName; 34 | } else if (DataBaseType.H2.name().equals(FreecodeUtils.getDataBaseType())) { 35 | sqlStr = "show columns from " + tableName; 36 | } else { 37 | throw new FreecodeException("dataSource type not support"); 38 | } 39 | 40 | // get table columns 41 | List columnList = new ArrayList<>(); 42 | // todo 完善freecode 43 | // List tableColumnInfos = 44 | // Flysql.select(TableColumnInfo.class).sql(sqlStr).query(); 45 | List tableColumnInfos = new ArrayList<>(); 46 | // remove ignore columns 47 | ignoreFields.addAll(FreecodeConstants.sysColumns); 48 | tableColumnInfos.forEach( 49 | e -> { 50 | if (!ignoreFields.contains(ReflectUtils.humpToLine(e.getField()))) { 51 | columnList.add(e); 52 | } 53 | }); 54 | 55 | return columnList; 56 | } 57 | 58 | /** 59 | * get table info 60 | * 61 | * @param tableName tableName 62 | * @return table info 63 | * @since 2020-01-09 64 | */ 65 | public String getTableInfo(String tableName) { 66 | 67 | // todo 完善freecode 68 | // if (DataBaseType.MYSQL.name().equals(FreecodeUtils.getDataBaseType())) { 69 | // 70 | // String sqlStr = "SELECT TABLE_COMMENT FROM information_schema.TABLES where 71 | // TABLE_NAME = '" + tableName + "'"; 72 | // TableInfo tableInfo = Flysql.select(TableInfo.class).sql(sqlStr).getOne(); 73 | // if (tableInfo == null || tableInfo.getTableComment() == null) { 74 | // return ""; 75 | // } else { 76 | // return tableInfo.getTableComment(); 77 | // } 78 | // }else{ 79 | return ""; 80 | // } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/test/java/com/isxcode/oxygen/core/FreemarkerUtilsTests.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core; 2 | 3 | import com.isxcode.oxygen.core.config.OxygenCoreAutoConfiguration; 4 | import com.isxcode.oxygen.core.exception.OxygenException; 5 | import com.isxcode.oxygen.core.file.FileUtils; 6 | import com.isxcode.oxygen.core.freemarker.FreemarkerUtils; 7 | import com.isxcode.oxygen.core.pojo.Dog; 8 | import java.nio.file.Files; 9 | import java.nio.file.Paths; 10 | import org.junit.jupiter.api.Test; 11 | import org.springframework.beans.factory.annotation.Value; 12 | import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration; 13 | import org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration; 14 | import org.springframework.boot.test.context.SpringBootTest; 15 | import org.springframework.test.context.ActiveProfiles; 16 | import org.springframework.test.context.ContextConfiguration; 17 | 18 | @SpringBootTest 19 | @ActiveProfiles("test") 20 | @ContextConfiguration( 21 | classes = { 22 | OxygenCoreAutoConfiguration.class, 23 | FreeMarkerAutoConfiguration.class, 24 | MailSenderAutoConfiguration.class 25 | }) 26 | public class FreemarkerUtilsTests { 27 | 28 | @Value("${test.templateName}") 29 | private String templateName; 30 | 31 | private final Dog dog = new Dog("wang", 15); 32 | 33 | private final String templateContent = "this dog name is ${name} and age is ${age}"; 34 | 35 | @Test 36 | public void testContentToFile() { 37 | 38 | if (Files.exists(Paths.get("freemarker1.txt"))) { 39 | FileUtils.recursionDeleteFile("freemarker1.txt"); 40 | } 41 | 42 | try { 43 | FreemarkerUtils.contentToFile(templateContent, dog, "freemarker1.txt"); 44 | } catch (OxygenException e) { 45 | System.out.println(e.getMessage()); 46 | throw e; 47 | } 48 | } 49 | 50 | @Test 51 | public void testContentToString() { 52 | 53 | try { 54 | System.out.println(FreemarkerUtils.contentToString(templateContent, dog)); 55 | } catch (OxygenException e) { 56 | System.out.println(e.getMessage()); 57 | throw e; 58 | } 59 | } 60 | 61 | @Test 62 | public void testTemplateToFile() { 63 | 64 | if (Files.exists(Paths.get("freemarker2.txt"))) { 65 | FileUtils.recursionDeleteFile("freemarker2.txt"); 66 | } 67 | 68 | try { 69 | FreemarkerUtils.templateToFile(templateName, dog, "freemarker2.txt"); 70 | } catch (OxygenException e) { 71 | System.out.println(e.getMessage()); 72 | throw e; 73 | } 74 | } 75 | 76 | @Test 77 | public void testTemplateToString() { 78 | 79 | try { 80 | System.out.println(FreemarkerUtils.templateToString(templateName, dog)); 81 | } catch (OxygenException e) { 82 | System.out.println(e.getMessage()); 83 | throw e; 84 | } 85 | 86 | FileUtils.recursionDeleteFile("freemarker1.txt"); 87 | FileUtils.recursionDeleteFile("freemarker2.txt"); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/main/java/com/isxcode/oxygen/core/secret/AesUtils.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core.secret; 2 | 3 | import com.isxcode.oxygen.core.exception.OxygenException; 4 | import java.nio.charset.StandardCharsets; 5 | import java.security.InvalidKeyException; 6 | import java.security.NoSuchAlgorithmException; 7 | import java.util.Arrays; 8 | import java.util.Base64; 9 | import javax.crypto.BadPaddingException; 10 | import javax.crypto.Cipher; 11 | import javax.crypto.IllegalBlockSizeException; 12 | import javax.crypto.NoSuchPaddingException; 13 | import javax.crypto.spec.SecretKeySpec; 14 | import lombok.extern.slf4j.Slf4j; 15 | 16 | /** 17 | * AES utils 18 | * 19 | * @author ispong 20 | * @since 0.0.1 21 | */ 22 | @Slf4j 23 | public class AesUtils { 24 | 25 | /** 26 | * AES encrypt 27 | * 28 | * @param key key 29 | * @param data data 30 | * @return base64 encrypt data 31 | * @since 0.0.1 32 | */ 33 | public static String encrypt(String key, String data) throws OxygenException { 34 | 35 | try { 36 | Cipher cipher = Cipher.getInstance(SecretConstants.AES); 37 | cipher.init( 38 | Cipher.ENCRYPT_MODE, 39 | new SecretKeySpec(Arrays.copyOf(key.getBytes(), 1 << 5), SecretConstants.AES)); 40 | return Base64.getEncoder() 41 | .encodeToString(cipher.doFinal(data.getBytes(StandardCharsets.UTF_8))); 42 | } catch (NoSuchAlgorithmException 43 | | InvalidKeyException 44 | | NoSuchPaddingException 45 | | BadPaddingException 46 | | IllegalBlockSizeException e) { 47 | log.error(e.getMessage()); 48 | throw new OxygenException(e.getMessage()); 49 | } 50 | } 51 | 52 | /** 53 | * AES encrypt 54 | * 55 | * @param data data 56 | * @return base64 encrypt data 57 | * @since 0.0.1 58 | */ 59 | public static String encrypt(String data) throws OxygenException { 60 | 61 | return encrypt(SecretConstants.AES_KEY, data); 62 | } 63 | 64 | /** 65 | * AES decrypt 66 | * 67 | * @param key key 68 | * @param data data 69 | * @return base64 encrypt data 70 | * @since 0.0.1 71 | */ 72 | public static String decrypt(String key, String data) { 73 | 74 | try { 75 | Cipher cipher = Cipher.getInstance(SecretConstants.AES); 76 | cipher.init( 77 | Cipher.DECRYPT_MODE, 78 | new SecretKeySpec(Arrays.copyOf(key.getBytes(), 1 << 5), SecretConstants.AES)); 79 | return new String(cipher.doFinal(Base64.getDecoder().decode(data)), StandardCharsets.UTF_8); 80 | } catch (NoSuchPaddingException 81 | | NoSuchAlgorithmException 82 | | InvalidKeyException 83 | | BadPaddingException 84 | | IllegalBlockSizeException e) { 85 | log.error(e.getMessage()); 86 | throw new OxygenException(e.getMessage()); 87 | } 88 | } 89 | 90 | /** 91 | * AES decrypt 92 | * 93 | * @param data data 94 | * @return base64 encrypt data 95 | * @since 0.0.1 96 | */ 97 | public static String decrypt(String data) { 98 | 99 | return decrypt(SecretConstants.AES_KEY, data); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/main/java/com/isxcode/oxygen/core/secret/RsaUtils.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core.secret; 2 | 3 | import com.isxcode.oxygen.core.exception.OxygenException; 4 | import java.nio.charset.StandardCharsets; 5 | import java.security.*; 6 | import java.security.spec.InvalidKeySpecException; 7 | import java.security.spec.PKCS8EncodedKeySpec; 8 | import java.security.spec.X509EncodedKeySpec; 9 | import java.util.Base64; 10 | import javax.crypto.BadPaddingException; 11 | import javax.crypto.Cipher; 12 | import javax.crypto.IllegalBlockSizeException; 13 | import javax.crypto.NoSuchPaddingException; 14 | import lombok.extern.slf4j.Slf4j; 15 | 16 | /** 17 | * RSA utils 18 | * 19 | * @author ispong 20 | * @since 0.0.1 21 | */ 22 | @Slf4j 23 | public class RsaUtils { 24 | 25 | /** 26 | * rsa encrypt 27 | * 28 | * @param publicKey publicKey 29 | * @param data data 30 | * @return base64 encrypt data 31 | * @since 0.0.1 32 | */ 33 | public static String encrypt(String publicKey, String data) { 34 | 35 | try { 36 | PublicKey key = 37 | KeyFactory.getInstance(SecretConstants.RSA) 38 | .generatePublic(new X509EncodedKeySpec(Base64.getDecoder().decode(publicKey))); 39 | Cipher cipher = Cipher.getInstance(SecretConstants.RSA); 40 | cipher.init(Cipher.ENCRYPT_MODE, key); 41 | return Base64.getEncoder() 42 | .encodeToString(cipher.doFinal(data.getBytes(StandardCharsets.UTF_8))); 43 | } catch (NoSuchAlgorithmException 44 | | InvalidKeySpecException 45 | | NoSuchPaddingException 46 | | InvalidKeyException 47 | | BadPaddingException 48 | | IllegalBlockSizeException e) { 49 | log.error(e.getMessage()); 50 | throw new OxygenException(e.getMessage()); 51 | } 52 | } 53 | 54 | /** 55 | * rsa decrypt 56 | * 57 | * @param privateKey privateKey 58 | * @param data data 59 | * @return base64 encrypt data 60 | * @since 0.0.1 61 | */ 62 | public static String decrypt(String privateKey, String data) { 63 | 64 | try { 65 | PrivateKey key = 66 | KeyFactory.getInstance(SecretConstants.RSA) 67 | .generatePrivate(new PKCS8EncodedKeySpec(Base64.getDecoder().decode(privateKey))); 68 | Cipher cipher = Cipher.getInstance(SecretConstants.RSA); 69 | cipher.init(Cipher.DECRYPT_MODE, key); 70 | return new String(cipher.doFinal(Base64.getDecoder().decode(data)), StandardCharsets.UTF_8); 71 | } catch (NoSuchAlgorithmException 72 | | InvalidKeySpecException 73 | | NoSuchPaddingException 74 | | BadPaddingException 75 | | IllegalBlockSizeException 76 | | InvalidKeyException e) { 77 | log.error(e.getMessage()); 78 | throw new OxygenException(e.getMessage()); 79 | } 80 | } 81 | 82 | /** 83 | * generate key pair 84 | * 85 | * @return key pair 86 | * @since 0.0.1 87 | */ 88 | public KeyPair generateKeyPair() throws OxygenException { 89 | 90 | try { 91 | KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(SecretConstants.RSA); 92 | keyPairGenerator.initialize(2048); 93 | return keyPairGenerator.generateKeyPair(); 94 | } catch (NoSuchAlgorithmException e) { 95 | log.error(e.getMessage()); 96 | throw new OxygenException(e.getMessage()); 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Isxcode - Spring Oxygen 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | Please wait... 18 |
19 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/test/java/com/isxcode/oxygen/core/SecretUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core; 2 | 3 | import com.isxcode.oxygen.core.config.OxygenCoreAutoConfiguration; 4 | import com.isxcode.oxygen.core.pojo.Dog; 5 | import com.isxcode.oxygen.core.secret.AesUtils; 6 | import com.isxcode.oxygen.core.secret.JwtUtils; 7 | import com.isxcode.oxygen.core.secret.RsaUtils; 8 | import org.junit.jupiter.api.Test; 9 | import org.springframework.boot.test.context.SpringBootTest; 10 | import org.springframework.test.context.ContextConfiguration; 11 | import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; 12 | 13 | @SpringBootTest 14 | @ContextConfiguration(classes = {OxygenCoreAutoConfiguration.class, FreeMarkerConfigurer.class}) 15 | public class SecretUtilsTest { 16 | 17 | @Test 18 | public void testAesNoKey() { 19 | 20 | String data = AesUtils.encrypt("love you"); 21 | System.out.println("data-->" + AesUtils.decrypt(data)); 22 | } 23 | 24 | @Test 25 | public void testJwtNoKey() { 26 | 27 | Dog dog = new Dog("xiao", 12); 28 | String data = JwtUtils.encrypt(dog); 29 | System.out.println("data-->" + JwtUtils.decrypt(data, Dog.class).toString()); 30 | } 31 | 32 | @Test 33 | public void testRsa() { 34 | 35 | String publicKey = 36 | "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkycgTz8VdCSh8fwexX42BYKANDFmrgTbfw4L1xwFp1eqIt/SM4bttjaeugwExhSqzuISBLW6OJ8qKMK26H5hJo1sU+2Z4STi0E3UlgdGZpNMiTLdv4Ge/pH0fpit8P01ahoU94c1Mpo0NMoVsHJ16P4ZqdJruL0ZzHjZF1b0vnETbNuFyrrr/L1cAO+n2LWz6ZCHqqXqc2SalWowIIBZV60ik7+a2rLGEHS+DwQYvRLTFIHFsdeKSD/AIcyhWRkoXH2tJVV5cYuwND+VSiz18Rw1Y2XCPXKKbLeby8odQpuvkk51OcehmEKpmF4BIDA3xBZRlIrb4GThvIHc/uH4hwIDAQAB"; 37 | String privateKey = 38 | "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCTJyBPPxV0JKHx/B7FfjYFgoA0MWauBNt/DgvXHAWnV6oi39Izhu22Np66DATGFKrO4hIEtbo4nyoowrbofmEmjWxT7ZnhJOLQTdSWB0Zmk0yJMt2/gZ7+kfR+mK3w/TVqGhT3hzUymjQ0yhWwcnXo/hmp0mu4vRnMeNkXVvS+cRNs24XKuuv8vVwA76fYtbPpkIeqpepzZJqVajAggFlXrSKTv5rassYQdL4PBBi9EtMUgcWx14pIP8AhzKFZGShcfa0lVXlxi7A0P5VKLPXxHDVjZcI9copst5vLyh1Cm6+STnU5x6GYQqmYXgEgMDfEFlGUitvgZOG8gdz+4fiHAgMBAAECggEAaPem/4BzcEbVUoVS+fPe2y1NAG4g3Y9Pd6FwZsBxc/5/uaLJEcJ0/N6XeQUrvpRth2gSDFQJg2xeKXdD/DJyYIrPNEsv0j96n7Z1J5QG7xKxrMihD4OKA/PfYRLOOTKWEJqMTEmhc/g1t1ZUBGqRm2LusYoNF1mk9otZ6GE58kImCzw9jKlB/A571OvRAwjgwsVHjDJYuN/XECHEv77zteMUlzD8xzJc+bGwswwqPvssXNJ1vFNXmsFqT4n89TQnsoiQ2RODUP1JEnuFK2Doz+ajpf2f8heefSw69imJkUNJwIU3HSH2nNnRhoD73e2VCgCI5tsGGsu8HKYKQNrDiQKBgQDajOtkDkPVcAQkUB1MyvnUPY4wA0cIEc5dgUk0KPivylngwVNvBmfQ+sFN7FjAlsiWQnbuOo6lBs1bJ5iWUl6mCSaAuIc/wVpATwtzK8Xwkr2D7Pw4r4Cn5RU6+nuTNsKH1dwDvjWtdmtOw6qVNjBrYVLonfsSwGnWVN9hG5fguwKBgQCsXjsNA+3Bj0RuLNsxw9iaKpJLjfkpXbZUHzw2OrNp2Zow+H0oeLBJCa7NmiWGQGzF7g8OH6VEFuMJV2HWKjZ3Lvj9IsMKhS+2OFZ8iNAKJ96nlI5yPpUzEp+ffSdPboQ+U21vSO7B+Pn/7p3BmSz52xGuBP3Q8hpoCoZIZahgpQKBgQDK8nVcMor3Vs/h0KuEtjAM0SSKnWCGs9JIrlgGIc3doDCaL6yEuxQI0fJTpBg+r0aRkiLS0nnH8WsdLMXbQZ423ORuP+0IXUqr0Ts2tf1Xi0yFh7ooAYGdZ3OxkwzSBdXbQdLPfwBllkPLnpN3gByyemv9K0cNgLRHngTZLkB5JQKBgBvgVX6CXyZJrFCBMqX2vYYZUnWjrWMyQ7WRI6TFk5SP268F0QAFnMUDKuEXh/ARZUYRfR/UoF7FsMwm9Ky1QP+/egc+YvrFlXTL4bjcS4EI96p0jSEO3ARZg7VAgWYIQpzt0yoHSo3WXWA10A+qXSq/cjmJlx7+uKSQ5yy4PCX9AoGBAI5TjACVq7lr09t+i0N3rdmw9gf2aU+aj8RU6JIlpfASv2tJINYS/Z76giHAKOBdlqSyJwqQylfHxbZdZ155W9j4ExTiQ8J0SQpu+WDvu7OIK8W71516AYopPO1UQVNqLKAyWY9VaDMQqiXlSO0PzvU6jG80uZBmuahxwqk35/8h"; 39 | String data = RsaUtils.encrypt(publicKey, "i love you"); 40 | System.out.println("data-->" + RsaUtils.decrypt(privateKey, data)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/test/java/com/isxcode/oxygen/flysql/TestOracle.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql; 2 | 3 | import com.isxcode.oxygen.flysql.config.FlysqlAutoConfiguration; 4 | import com.isxcode.oxygen.flysql.core.Flysql; 5 | import com.ulisesbocchio.jasyptspringboot.configuration.EnableEncryptablePropertiesConfiguration; 6 | import java.math.BigDecimal; 7 | import java.time.LocalDate; 8 | import java.time.LocalDateTime; 9 | import java.util.Date; 10 | import java.util.List; 11 | import org.junit.jupiter.api.Disabled; 12 | import org.junit.jupiter.api.Test; 13 | import org.springframework.beans.factory.annotation.Qualifier; 14 | import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; 15 | import org.springframework.boot.test.autoconfigure.jdbc.JdbcTest; 16 | import org.springframework.test.context.ActiveProfiles; 17 | import org.springframework.test.context.ContextConfiguration; 18 | 19 | @Disabled 20 | @JdbcTest 21 | @ContextConfiguration( 22 | classes = {EnableEncryptablePropertiesConfiguration.class, FlysqlAutoConfiguration.class}) 23 | @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) 24 | @ActiveProfiles("oracle") 25 | public class TestOracle { 26 | 27 | private final Flysql flysql; 28 | 29 | public TestOracle(@Qualifier("flysql") Flysql flysql) { 30 | 31 | this.flysql = flysql; 32 | } 33 | 34 | @Test 35 | public void testFlysql() { 36 | 37 | Dog dog1 = null; 38 | Dog dog2 = null; 39 | Dog dog3 = null; 40 | 41 | try { 42 | dog1 = 43 | new Dog( 44 | 1, 45 | "jack", 46 | 1.1, 47 | new BigDecimal("1.1"), 48 | new Date(), 49 | LocalDate.now(), 50 | LocalDateTime.now(), 51 | true); 52 | dog2 = 53 | new Dog( 54 | 2, 55 | "john", 56 | 1.2, 57 | new BigDecimal("1.2"), 58 | new Date(), 59 | LocalDate.now(), 60 | LocalDateTime.now(), 61 | true); 62 | dog3 = 63 | new Dog( 64 | 3, 65 | "rose", 66 | 1.3, 67 | new BigDecimal("1.3"), 68 | new Date(), 69 | LocalDate.now(), 70 | LocalDateTime.now(), 71 | true); 72 | } catch (NumberFormatException ignored) { 73 | } 74 | 75 | flysql.build().insert(Dog.class).save(dog1); 76 | flysql.build().insert(Dog.class).save(dog2); 77 | flysql.build().insert(Dog.class).save(dog3); 78 | 79 | System.out.println( 80 | "=========================== show all data ===================================="); 81 | List dogQuery = flysql.build().select(Dog.class).query(); 82 | dogQuery.forEach(System.out::println); 83 | 84 | System.out.println( 85 | "============================ show single data ==================================="); 86 | Dog dogGetOne = flysql.build().select(Dog.class).eq("name", "rose").getOne(); 87 | System.out.println(dogGetOne); 88 | 89 | System.out.println( 90 | "============================= show after delete data ================================="); 91 | flysql.build().delete(Dog.class).eq("name", "john").doDelete(); 92 | dogQuery = flysql.build().select(Dog.class).query(); 93 | dogQuery.forEach(System.out::println); 94 | 95 | System.out.println( 96 | "============================== show after update data ================================="); 97 | flysql.build().update(Dog.class).eq("name", "jack").update("amountDouble", 9.9).doUpdate(); 98 | dogQuery = flysql.build().select(Dog.class).query(); 99 | dogQuery.forEach(System.out::println); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at ispong@outlook.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/test/java/com/isxcode/oxygen/flysql/TestSqlServer.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql; 2 | 3 | import com.isxcode.oxygen.flysql.config.FlysqlAutoConfiguration; 4 | import com.isxcode.oxygen.flysql.core.Flysql; 5 | import com.ulisesbocchio.jasyptspringboot.configuration.EnableEncryptablePropertiesConfiguration; 6 | import java.math.BigDecimal; 7 | import java.time.LocalDate; 8 | import java.time.LocalDateTime; 9 | import java.util.ArrayList; 10 | import java.util.Date; 11 | import java.util.List; 12 | import org.junit.jupiter.api.Disabled; 13 | import org.junit.jupiter.api.Test; 14 | import org.springframework.beans.factory.annotation.Qualifier; 15 | import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; 16 | import org.springframework.boot.test.autoconfigure.jdbc.JdbcTest; 17 | import org.springframework.test.context.ActiveProfiles; 18 | import org.springframework.test.context.ContextConfiguration; 19 | 20 | @Disabled 21 | @JdbcTest 22 | @ContextConfiguration( 23 | classes = {EnableEncryptablePropertiesConfiguration.class, FlysqlAutoConfiguration.class}) 24 | @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) 25 | @ActiveProfiles("sqlserver") 26 | public class TestSqlServer { 27 | 28 | private final Flysql flysql; 29 | 30 | public TestSqlServer(@Qualifier("flysql") Flysql flysql) { 31 | 32 | this.flysql = flysql; 33 | } 34 | 35 | @Test 36 | public void testFlysql() { 37 | 38 | Dog dog1 = null; 39 | Dog dog2 = null; 40 | Dog dog3 = null; 41 | 42 | ArrayList dogList = new ArrayList<>(); 43 | try { 44 | dog1 = 45 | new Dog( 46 | 1, 47 | "jack", 48 | 1.1, 49 | new BigDecimal("1.1"), 50 | new Date(), 51 | LocalDate.now(), 52 | LocalDateTime.now(), 53 | true); 54 | dog2 = 55 | new Dog( 56 | 2, 57 | "john", 58 | 1.2, 59 | new BigDecimal("1.2"), 60 | new Date(), 61 | LocalDate.now(), 62 | LocalDateTime.now(), 63 | true); 64 | dog3 = 65 | new Dog( 66 | 3, 67 | "rose", 68 | 1.3, 69 | new BigDecimal("1.3"), 70 | new Date(), 71 | LocalDate.now(), 72 | LocalDateTime.now(), 73 | true); 74 | } catch (NumberFormatException ignored) { 75 | } 76 | 77 | dogList.add(dog2); 78 | dogList.add(dog3); 79 | 80 | flysql.build().insert(Dog.class).save(dog1); 81 | flysql.build().insert(Dog.class).batchSave(dogList); 82 | 83 | System.out.println( 84 | "=========================== show all data ===================================="); 85 | List dogQuery = flysql.build().select(Dog.class).query(); 86 | dogQuery.forEach(System.out::println); 87 | 88 | System.out.println( 89 | "============================ show single data ==================================="); 90 | Dog dogGetOne = flysql.build().select(Dog.class).eq("name", "rose").getOne(); 91 | System.out.println(dogGetOne); 92 | 93 | System.out.println( 94 | "============================= show after delete data ================================="); 95 | flysql.build().delete(Dog.class).eq("name", "john").doDelete(); 96 | dogQuery = flysql.build().select(Dog.class).query(); 97 | dogQuery.forEach(System.out::println); 98 | 99 | System.out.println( 100 | "============================== show after update data ================================="); 101 | flysql.build().update(Dog.class).eq("name", "jack").update("amountDouble", 9.9).doUpdate(); 102 | dogQuery = flysql.build().select(Dog.class).query(); 103 | dogQuery.forEach(System.out::println); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /spring-oxygen-cli/src/main/java/com/isxcode/oxygen/cli/service/FreecodeService.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.cli.service; 2 | 3 | import com.isxcode.oxygen.cli.constant.FreecodeConstants; 4 | import com.isxcode.oxygen.cli.entity.FreecodeInfo; 5 | import com.isxcode.oxygen.cli.exception.FreecodeException; 6 | import com.isxcode.oxygen.cli.properties.FreecodeProperties; 7 | import com.isxcode.oxygen.cli.repository.FreecodeRepository; 8 | import com.isxcode.oxygen.cli.utils.FreecodeUtils; 9 | import com.isxcode.oxygen.core.reflect.ReflectUtils; 10 | import java.io.IOException; 11 | import lombok.extern.slf4j.Slf4j; 12 | 13 | /** 14 | * freecode service 15 | * 16 | * @author ispong 17 | * @since 0.0.1 18 | */ 19 | @Slf4j 20 | public class FreecodeService { 21 | 22 | private final FreecodeRepository freecodeRepository; 23 | 24 | private final FreecodeProperties freecodeProperties; 25 | 26 | public FreecodeService( 27 | FreecodeRepository freecodeRepository, FreecodeProperties freecodeProperties) { 28 | 29 | this.freecodeProperties = freecodeProperties; 30 | this.freecodeRepository = freecodeRepository; 31 | } 32 | 33 | /** 34 | * start generate code 35 | * 36 | * @param tableNames table names 37 | * @since 0.0.1 38 | */ 39 | public void startFreecode(String tableNames) { 40 | 41 | for (String metaTableName : tableNames.split(FreecodeConstants.splitStr)) { 42 | 43 | metaTableName = metaTableName.trim(); 44 | 45 | // generate freemarker info 46 | FreecodeInfo freecodeInfo = generateFreecodeInfo(metaTableName); 47 | 48 | // pojo name 49 | String pojoName = 50 | ReflectUtils.lineToHump(FreecodeUtils.parseTableName(metaTableName, freecodeProperties)); 51 | 52 | // class name 53 | String className = ReflectUtils.upperFirstCase(pojoName); 54 | 55 | // directory name 56 | String directoryName = pojoName.toLowerCase(); 57 | 58 | freecodeInfo.setClassName(className); 59 | freecodeInfo.setPackageName( 60 | FreecodeUtils.parsePathToPackage(freecodeProperties.getModulePath()) 61 | + "." 62 | + directoryName); 63 | 64 | // foreach generate file 65 | for (String fileType : freecodeProperties.getFileTypes()) { 66 | 67 | // templateName 68 | String templateName = fileType + freecodeProperties.getTemplatePrefix(); 69 | 70 | // fileName 71 | String fileName = 72 | className + ReflectUtils.upperFirstCase(fileType) + FreecodeConstants.JAVA_FILE_SUFFIX; 73 | 74 | // generate file 75 | try { 76 | FreecodeUtils.generateFile(directoryName, fileName, templateName, freecodeInfo); 77 | } catch (IOException e) { 78 | log.error(e.getMessage()); 79 | throw new FreecodeException(e.getMessage()); 80 | } 81 | } 82 | } 83 | } 84 | 85 | /** 86 | * create freemarker params 87 | * 88 | * @param tableName tableName 89 | * @return FreecodeInfo 90 | * @since 0.0.1 91 | */ 92 | public FreecodeInfo generateFreecodeInfo(String tableName) { 93 | 94 | FreecodeInfo freecodeInfo = new FreecodeInfo(); 95 | 96 | // add table columns info 97 | freecodeInfo.setTableColumns( 98 | freecodeRepository.getTableColumns(tableName, freecodeProperties.getIgnoreColumns())); 99 | 100 | // class package list 101 | freecodeInfo.setEntityPackageList( 102 | FreecodeUtils.parseDataPackage(freecodeInfo.getTableColumns())); 103 | 104 | // add user config 105 | freecodeInfo.setFreecodeProperties(freecodeProperties); 106 | 107 | // table name 108 | freecodeInfo.setTableName(tableName); 109 | 110 | // add column comment 111 | freecodeInfo.setTableComment(freecodeRepository.getTableInfo(tableName)); 112 | 113 | return freecodeInfo; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /docs/en-us/advance/Flysql-Builder.md: -------------------------------------------------------------------------------- 1 | #### Select() 2 | ```java 3 | public MetaData getOne(String id) { 4 | 5 | return flysql.build().select(MetaData.class) 6 | .select("name","age") 7 | .eq("id", id) 8 | .getOne(); 9 | } 10 | ``` 11 | 12 | #### Eq() 13 | 14 | ```java 15 | public MetaData getOne(String id, String name) { 16 | 17 | return flysql.build().select(MetaData.class) 18 | .eq("id", id) 19 | .eq("name",name) 20 | .getOne(); 21 | } 22 | ``` 23 | 24 | #### NotEq() 25 | 26 | ```java 27 | public MetaData getOne(String id, String name) { 28 | 29 | return flysql.build().select(MetaData.class) 30 | .ne("id", id) 31 | .ne("name",name) 32 | .getOne(); 33 | } 34 | ``` 35 | 36 | #### Gt() 37 | 38 | ```java 39 | public MetaData getOne(String id, String name) { 40 | 41 | return flysql.build().select(MetaData.class) 42 | .gt("id", id) 43 | .getOne(); 44 | } 45 | ``` 46 | 47 | #### GtEq() 48 | 49 | ```java 50 | public MetaData getOne(String id, String name) { 51 | 52 | return flysql.build().select(MetaData.class) 53 | .gtEq("id", id) 54 | .getOne(); 55 | } 56 | ``` 57 | 58 | #### Lt() 59 | 60 | ```java 61 | public MetaData getOne(String id, String name) { 62 | 63 | return flysql.build().select(MetaData.class) 64 | .lt("id", id) 65 | .getOne(); 66 | } 67 | ``` 68 | 69 | #### LtEq() 70 | 71 | ```java 72 | public MetaData getOne(String id, String name) { 73 | 74 | return flysql.build().select(MetaData.class) 75 | .ltEq("id", id) 76 | .getOne(); 77 | } 78 | ``` 79 | 80 | #### In() 81 | 82 | ```java 83 | public MetaData getOne(String id, String id2) { 84 | 85 | return flysql.build().select(MetaData.class) 86 | .in("id", id, id2) 87 | .getOne(); 88 | } 89 | ``` 90 | 91 | #### NotIn() 92 | 93 | ```java 94 | public MetaData getOne(String id, String id2) { 95 | 96 | return flysql.build().select(MetaData.class) 97 | .notIn("id", id, id2) 98 | .getOne(); 99 | } 100 | ``` 101 | 102 | #### Between() 103 | 104 | ```java 105 | public MetaData getOne(String id, String id2) { 106 | 107 | return flysql.build().select(MetaData.class) 108 | .between("id", id, id2) 109 | .getOne(); 110 | } 111 | ``` 112 | 113 | #### NotBetween() 114 | 115 | ```java 116 | public MetaData getOne(String id, String id2) { 117 | 118 | return flysql.build().select(MetaData.class) 119 | .notBetween("id", id, id2) 120 | .getOne(); 121 | } 122 | ``` 123 | 124 | #### Like() 125 | 126 | ```java 127 | public MetaData getOne(String name) { 128 | 129 | return flysql.build().select(MetaData.class) 130 | .like("name", name) 131 | .getOne(); 132 | } 133 | ``` 134 | 135 | #### NotLike() 136 | 137 | ```java 138 | public MetaData getOne(String name) { 139 | 140 | return flysql.build().select(MetaData.class) 141 | .notLike("name", name) 142 | .getOne(); 143 | } 144 | ``` 145 | 146 | #### IsNull() 147 | 148 | ```java 149 | public MetaData getOne(String name) { 150 | 151 | return flysql.build().select(MetaData.class) 152 | .isNull("name") 153 | .getOne(); 154 | } 155 | ``` 156 | 157 | #### NotNull() 158 | 159 | ```java 160 | public MetaData getOne(String name) { 161 | 162 | return flysql.build().select(MetaData.class) 163 | .isNotNull("name") 164 | .getOne(); 165 | } 166 | ``` 167 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/test/java/com/isxcode/oxygen/flysql/TestMongo.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql; 2 | 3 | import com.isxcode.oxygen.flysql.config.FlysqlAutoConfiguration; 4 | import com.isxcode.oxygen.flysql.core.Flysql; 5 | import com.isxcode.oxygen.flysql.entity.FlysqlPage; 6 | import java.math.BigDecimal; 7 | import java.time.LocalDate; 8 | import java.time.LocalDateTime; 9 | import java.util.ArrayList; 10 | import java.util.Date; 11 | import java.util.List; 12 | import org.junit.jupiter.api.Disabled; 13 | import org.junit.jupiter.api.Test; 14 | import org.springframework.beans.factory.annotation.Qualifier; 15 | import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; 16 | import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; 17 | import org.springframework.test.context.ActiveProfiles; 18 | import org.springframework.test.context.ContextConfiguration; 19 | 20 | @Disabled 21 | @DataMongoTest 22 | @ContextConfiguration(classes = {FlysqlAutoConfiguration.class}) 23 | @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) 24 | @ActiveProfiles("mongo") 25 | public class TestMongo { 26 | 27 | private final Flysql flysql; 28 | 29 | public TestMongo(@Qualifier("flysqlFactory") Flysql flysql) { 30 | 31 | this.flysql = flysql; 32 | } 33 | 34 | @Test 35 | public void testMongo() { 36 | 37 | Dog dog1 = null; 38 | Dog dog2 = null; 39 | Dog dog3 = null; 40 | 41 | ArrayList dogList = new ArrayList<>(); 42 | try { 43 | dog1 = 44 | new Dog( 45 | 1, 46 | "jack", 47 | 1.1, 48 | new BigDecimal("1.1"), 49 | new Date(), 50 | LocalDate.now(), 51 | LocalDateTime.now(), 52 | true); 53 | dog2 = 54 | new Dog( 55 | 2, 56 | "john", 57 | 1.2, 58 | new BigDecimal("1.2"), 59 | new Date(), 60 | LocalDate.now(), 61 | LocalDateTime.now(), 62 | true); 63 | dog3 = 64 | new Dog( 65 | 3, 66 | "rose", 67 | 1.3, 68 | new BigDecimal("1.3"), 69 | new Date(), 70 | LocalDate.now(), 71 | LocalDateTime.now(), 72 | true); 73 | } catch (NumberFormatException ignored) { 74 | } 75 | 76 | dogList.add(dog2); 77 | dogList.add(dog3); 78 | 79 | flysql.buildMongo().insert(Dog.class).save(dog1); 80 | flysql.buildMongo().insert(Dog.class).batchSave(dogList); 81 | 82 | System.out.println( 83 | "=========================== show all data ===================================="); 84 | List dogQuery = flysql.buildMongo().select(Dog.class).query(); 85 | dogQuery.forEach(System.out::println); 86 | 87 | System.out.println( 88 | "=========================== show page data ===================================="); 89 | FlysqlPage dogQueryPage = flysql.buildMongo().select(Dog.class).queryPage(1, 2); 90 | System.out.println(dogQueryPage); 91 | 92 | System.out.println( 93 | "============================ show single data ==================================="); 94 | Dog dogGetOne = flysql.buildMongo().select(Dog.class).eq("name", "rose").getOne(); 95 | System.out.println(dogGetOne); 96 | 97 | System.out.println( 98 | "============================= show after delete data ================================="); 99 | flysql.buildMongo().delete(Dog.class).eq("name", "john").doDelete(); 100 | dogQuery = flysql.buildMongo().select(Dog.class).query(); 101 | dogQuery.forEach(System.out::println); 102 | 103 | System.out.println( 104 | "============================== show after update data ================================="); 105 | flysql.buildMongo().update(Dog.class).eq("name", "jack").update("amountDouble", 9.9).doUpdate(); 106 | dogQuery = flysql.buildMongo().select(Dog.class).query(); 107 | dogQuery.forEach(System.out::println); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/test/java/com/isxcode/oxygen/flysql/TestMysql.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql; 2 | 3 | import com.isxcode.oxygen.flysql.config.FlysqlAutoConfiguration; 4 | import com.isxcode.oxygen.flysql.core.Flysql; 5 | import com.isxcode.oxygen.flysql.entity.FlysqlPage; 6 | import com.ulisesbocchio.jasyptspringboot.configuration.EnableEncryptablePropertiesConfiguration; 7 | import java.math.BigDecimal; 8 | import java.time.LocalDate; 9 | import java.time.LocalDateTime; 10 | import java.util.ArrayList; 11 | import java.util.Date; 12 | import java.util.List; 13 | import org.junit.jupiter.api.Disabled; 14 | import org.junit.jupiter.api.Test; 15 | import org.springframework.beans.factory.annotation.Qualifier; 16 | import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; 17 | import org.springframework.boot.test.autoconfigure.jdbc.JdbcTest; 18 | import org.springframework.test.context.ActiveProfiles; 19 | import org.springframework.test.context.ContextConfiguration; 20 | 21 | @Disabled 22 | @JdbcTest 23 | @ContextConfiguration( 24 | classes = {EnableEncryptablePropertiesConfiguration.class, FlysqlAutoConfiguration.class}) 25 | @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) 26 | @ActiveProfiles("mysql") 27 | public class TestMysql { 28 | 29 | private final Flysql flysql; 30 | 31 | public TestMysql(@Qualifier("flysql") Flysql flysql) { 32 | 33 | this.flysql = flysql; 34 | } 35 | 36 | @Test 37 | public void testFlysql() { 38 | 39 | Dog dog1 = null; 40 | Dog dog2 = null; 41 | Dog dog3 = null; 42 | 43 | ArrayList dogList = new ArrayList<>(); 44 | try { 45 | dog1 = 46 | new Dog( 47 | 1, 48 | "jack", 49 | 1.1, 50 | new BigDecimal("1.1"), 51 | new Date(), 52 | LocalDate.now(), 53 | LocalDateTime.now(), 54 | true); 55 | dog2 = 56 | new Dog( 57 | 2, 58 | "john", 59 | 1.2, 60 | new BigDecimal("1.2"), 61 | new Date(), 62 | LocalDate.now(), 63 | LocalDateTime.now(), 64 | true); 65 | dog3 = 66 | new Dog( 67 | 3, 68 | "rose", 69 | 1.3, 70 | new BigDecimal("1.3"), 71 | new Date(), 72 | LocalDate.now(), 73 | LocalDateTime.now(), 74 | true); 75 | } catch (NumberFormatException ignored) { 76 | } 77 | 78 | dogList.add(dog2); 79 | dogList.add(dog3); 80 | 81 | flysql.build().insert(Dog.class).save(dog1); 82 | flysql.build().insert(Dog.class).batchSave(dogList); 83 | 84 | System.out.println( 85 | "=========================== show all data ===================================="); 86 | List dogQuery = flysql.build().select(Dog.class).query(); 87 | dogQuery.forEach(System.out::println); 88 | 89 | System.out.println( 90 | "=========================== show page data ===================================="); 91 | FlysqlPage dogQueryPage = flysql.build().select(Dog.class).queryPage(1, 2); 92 | System.out.println(dogQueryPage); 93 | 94 | System.out.println( 95 | "============================ show single data ==================================="); 96 | Dog dogGetOne = flysql.build().select(Dog.class).eq("name", "rose").getOne(); 97 | System.out.println(dogGetOne); 98 | 99 | System.out.println( 100 | "============================= show after delete data ================================="); 101 | flysql.build().delete(Dog.class).eq("name", "john").doDelete(); 102 | dogQuery = flysql.build().select(Dog.class).query(); 103 | dogQuery.forEach(System.out::println); 104 | 105 | System.out.println( 106 | "============================== show after update data ================================="); 107 | flysql.build().update(Dog.class).eq("name", "jack").update("amountDouble", 9.9).doUpdate(); 108 | dogQuery = flysql.build().select(Dog.class).query(); 109 | dogQuery.forEach(System.out::println); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/main/java/com/isxcode/oxygen/core/reflect/ReflectUtils.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core.reflect; 2 | 3 | import static java.util.regex.Pattern.compile; 4 | 5 | import com.isxcode.oxygen.core.exception.OxygenException; 6 | import java.beans.PropertyDescriptor; 7 | import java.lang.reflect.InvocationTargetException; 8 | import java.lang.reflect.Method; 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | import java.util.regex.Matcher; 12 | import lombok.extern.slf4j.Slf4j; 13 | import org.springframework.beans.BeanUtils; 14 | 15 | /** 16 | * reflect utils 17 | * 18 | * @author ispong 19 | * @since 0.0.1 20 | */ 21 | @Slf4j 22 | public class ReflectUtils { 23 | 24 | /** 25 | * reflect create instance 26 | * 27 | * @param targetClass targetClass 28 | * @param T 29 | * @return instance 30 | * @since 0.0.1 31 | */ 32 | public static T newInstance(Class targetClass) { 33 | 34 | try { 35 | return targetClass.getDeclaredConstructor().newInstance(); 36 | } catch (InstantiationException 37 | | IllegalAccessException 38 | | InvocationTargetException 39 | | NoSuchMethodException e) { 40 | log.error(e.getMessage()); 41 | throw new OxygenException(e.getMessage()); 42 | } 43 | } 44 | 45 | /** 46 | * query class fields 47 | * 48 | * @param targetClass targetClass 49 | * @return List[FieldBody] 50 | * @since 0.0.1 51 | */ 52 | public static List queryFields(Class targetClass) { 53 | 54 | ArrayList fieldBodyList = new ArrayList<>(); 55 | 56 | PropertyDescriptor[] propertyDescriptors = BeanUtils.getPropertyDescriptors(targetClass); 57 | for (PropertyDescriptor propertyMeta : propertyDescriptors) { 58 | 59 | if (ReflectConstants.CLASS.equals(propertyMeta.getName())) { 60 | continue; 61 | } 62 | 63 | try { 64 | FieldBody.FieldBodyBuilder fieldBodyBuilder = FieldBody.builder(); 65 | Method readMethod = propertyMeta.getReadMethod(); 66 | if (readMethod == null) { 67 | continue; 68 | } 69 | fieldBodyBuilder.field( 70 | readMethod.getDeclaringClass().getDeclaredField(propertyMeta.getName())); 71 | fieldBodyBuilder.readMethod(readMethod); 72 | fieldBodyBuilder.writeMethod(propertyMeta.getWriteMethod()); 73 | fieldBodyBuilder.className(propertyMeta.getPropertyType().getName()); 74 | fieldBodyList.add(fieldBodyBuilder.build()); 75 | } catch (NoSuchFieldException e) { 76 | // do nothing 77 | } 78 | } 79 | 80 | return fieldBodyList; 81 | } 82 | 83 | /** 84 | * hump translate to under_line 85 | * 86 | * @param humpStr humpStr 87 | * @return String 88 | * @since 0.0.1 89 | */ 90 | public static String humpToLine(String humpStr) { 91 | 92 | humpStr = humpStr.substring(0, 1).toLowerCase() + humpStr.substring(1); 93 | 94 | Matcher matcher = compile("[A-Z]").matcher(humpStr); 95 | StringBuffer lineStrBuff = new StringBuffer(); 96 | while (matcher.find()) { 97 | matcher.appendReplacement(lineStrBuff, "_" + matcher.group(0).toLowerCase()); 98 | } 99 | matcher.appendTail(lineStrBuff); 100 | return lineStrBuff.toString(); 101 | } 102 | 103 | /** 104 | * upper first case 105 | * 106 | * @param data data 107 | * @return string 108 | * @since 0.0.1 109 | */ 110 | public static String upperFirstCase(String data) { 111 | 112 | return data.substring(0, 1).toUpperCase() + data.substring(1); 113 | } 114 | 115 | /** 116 | * line to hump 117 | * 118 | * @param lineStr lineStr 119 | * @return String 120 | * @since 0.0.1 121 | */ 122 | public static String lineToHump(String lineStr) { 123 | 124 | StringBuffer humpStrBuff = new StringBuffer(); 125 | lineStr = lineStr.toLowerCase(); 126 | Matcher matcher = compile("_(\\w)").matcher(lineStr); 127 | while (matcher.find()) { 128 | matcher.appendReplacement(humpStrBuff, matcher.group(1).toUpperCase()); 129 | } 130 | return matcher.appendTail(humpStrBuff).toString(); 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /docs/en-us/contributing.md: -------------------------------------------------------------------------------- 1 | ## Welcome to contribute Spring Oxygen 2 | 3 | Hello! Thank you for taking the time to contribute! If you want to join us, please send email to **ispong@outlook.com**. 4 | 5 | #### [How to Contribute to an Open Source Project on GitHub](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github) 6 | 7 | [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) 8 | 9 | --- 10 | 11 | ### Installation Prerequisites 12 | 13 | - Git 2.22+ 14 | - Java 11+ 15 | - Gradle 6.5+ ~ 6.8.3 (not support 7.x) 16 | 17 | ### Contribute (Example developer:**ispong** ) 18 | 19 | 1. Fork Project (_https://github.com/isxcode/spring-oxygen_) 20 | 21 | 2. Clone Project (Branch: **latest**) 22 | 23 | ```bash 24 | git clone -b latest https://github.com/ispong/spring-oxygen.git 25 | ``` 26 | 27 | 3. Build Project 28 | 29 | ```bash 30 | cd spring-oxygen 31 | gradle publishToMavenLocal 32 | ``` 33 | 34 | 4. Install Local 35 | 36 | - Open local spring project and Change file `build.gradle` 37 | 38 | ```groovy 39 | repositories { 40 | // ... 41 | mavenLocal() 42 | } 43 | 44 | dependencies { 45 | // ... 46 | compile group: 'com.isxcode.oxygen', name: 'oxygen-spring-boot-starter', version: '0.0.1', changing: true 47 | } 48 | ``` 49 | 50 | 5. Merge conflict (Branch: **latest**) 51 | 52 | ```bash 53 | git remote add upstream https://github.com/isxcode/spring-oxygen.git 54 | git fetch upstream 55 | git merge upstream/latest 56 | git add . 57 | git commit -m ":sparkles: add new features" 58 | git push origin latest 59 | ``` 60 | 61 | 6. Pull Request 62 | 63 | [https://github.com/isxcode/spring-oxygen/compare](https://github.com/isxcode/spring-oxygen/compare) 64 | 65 | > Note: ispong/spring-oxygen/latest **==squash merge==>** isxcode/spring-oxygen/latest 66 | 67 | ### Build Docs 68 | 69 | ```bash 70 | npm i docsify-cli -g 71 | cd spring-oxygen 72 | docsify serve docs 73 | ``` 74 | [http://localhost:3000](http://localhost:3000) 75 | 76 | ### Publish 77 | 78 | #### publish SNAPSHOT to Sonatype repository 79 | 80 | ```bash 81 | vim VERSION.md 82 | 83 | # -------------- VERSION.md -------------- 84 | 1.0.0-SNAPSHOT 85 | # -------------- VERSION.md -------------- 86 | ``` 87 | 88 | ```bash 89 | vim gradle.properties 90 | 91 | # ------------- gradle.properties ------------- 92 | sonatypePassword=xxx 93 | # ------------- gradle.properties ------------- 94 | ``` 95 | 96 | ```bash 97 | gradle publishMavenJavaPublicationToSonatypeRepository 98 | ``` 99 | 100 | #### publish RELEASE to Sonatype repository 101 | 102 | ```bash 103 | vim VERSION.md 104 | 105 | # -------------- VERSION.md -------------- 106 | 1.0.0 107 | # -------------- VERSION.md -------------- 108 | ``` 109 | 110 | ```bash 111 | vim gradle.properties 112 | 113 | # ------------- gradle.properties ------------- 114 | sonatypePassword=xxx 115 | # ------------- gradle.properties ------------- 116 | ``` 117 | 118 | ```bash 119 | gradle publishMavenJavaPublicationToSonatypeRepository 120 | ``` 121 | 122 | [https://oss.sonatype.org/](https://oss.sonatype.org/) 123 | 124 | #### publish RELEASE to GitHub repository 125 | 126 | [https://github.com/isxcode/spring-oxygen/actions/workflows/release-github.yml](https://github.com/isxcode/spring-oxygen/actions/workflows/release-github.yml) 127 | 128 | ### Release new version 129 | 130 | - [ ] Fix Pull Requests 131 | - [ ] Edit version number(0.11.5-SNAPSHOT/1.9.1) and README.md 132 | - [ ] Edit SECURITY.md version number 133 | - [ ] Edit CHANGELOG.md version number and copy issues record to (## v0.11.5) 134 | - [ ] Copy README.md to /docs/_homepage.md 135 | - [ ] Submit and Check and Fix GitHub Security 136 | - [ ] Merge to isxcode/spring-oxygen/latest 137 | - [ ] Check project badge status 138 | - [ ] Create GitHub new tag (v0.11.5)/release(v1.10.3) and new branch (0.11.5) 139 | - [ ] Run GitHub action publish to GitHub repository 140 | - [ ] Run GitHub action publish to Sonatype repository 141 | - [ ] Publish to Sonatype repository 142 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/response/GlobalExceptionAdvice.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.response; 2 | 3 | import com.isxcode.oxygen.flysql.common.BaseResponse; 4 | import lombok.NonNull; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.core.Ordered; 7 | import org.springframework.core.annotation.Order; 8 | import org.springframework.http.HttpHeaders; 9 | import org.springframework.http.HttpStatus; 10 | import org.springframework.http.ResponseEntity; 11 | import org.springframework.security.access.AccessDeniedException; 12 | import org.springframework.validation.ObjectError; 13 | import org.springframework.web.bind.MethodArgumentNotValidException; 14 | import org.springframework.web.bind.annotation.ControllerAdvice; 15 | import org.springframework.web.bind.annotation.ExceptionHandler; 16 | import org.springframework.web.bind.annotation.ResponseBody; 17 | import org.springframework.web.context.request.WebRequest; 18 | import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; 19 | 20 | /** 21 | * global exception advice 22 | * 23 | * @author isxcode 24 | * @since 0.0.1 25 | */ 26 | @Slf4j 27 | @ControllerAdvice 28 | @ResponseBody 29 | @Order(Ordered.HIGHEST_PRECEDENCE) 30 | public class GlobalExceptionAdvice extends ResponseEntityExceptionHandler { 31 | 32 | /** 33 | * flysql custom exception 34 | * 35 | * @param abstractException abstractException 36 | * @return ResponseEntity 37 | * @since 0.0.1 38 | */ 39 | @ExceptionHandler(AbstractException.class) 40 | public ResponseEntity> customException(AbstractException abstractException) { 41 | 42 | BaseResponse errorResponse = new BaseResponse<>(); 43 | errorResponse.setCode( 44 | abstractException.getCode() == null 45 | ? ResponseConstant.ERROR_CODE 46 | : abstractException.getCode()); 47 | errorResponse.setMsg(abstractException.getMsg()); 48 | return new ResponseEntity<>(errorResponse, HttpStatus.OK); 49 | } 50 | 51 | /** 52 | * access exception 53 | * 54 | * @param accessDeniedException accessDeniedException 55 | * @return ResponseEntity 56 | * @since 0.0.1 57 | */ 58 | @ExceptionHandler(AccessDeniedException.class) 59 | public ResponseEntity> accessDeniedException( 60 | AccessDeniedException accessDeniedException) { 61 | 62 | BaseResponse errorResponse = new BaseResponse<>(); 63 | errorResponse.setCode(ResponseConstant.FORBIDDEN_CODE); 64 | errorResponse.setData(accessDeniedException.getMessage()); 65 | return new ResponseEntity<>(errorResponse, HttpStatus.FORBIDDEN); 66 | } 67 | 68 | /** 69 | * success response throw 70 | * 71 | * @param successException successException 72 | * @return ResponseEntity 73 | * @since 0.0.1 74 | */ 75 | @ExceptionHandler(SuccessException.class) 76 | public ResponseEntity> successException(SuccessException successException) { 77 | 78 | return new ResponseEntity<>(successException.getBaseResponse(), HttpStatus.OK); 79 | } 80 | 81 | /** 82 | * all exception 83 | * 84 | * @param exception exception 85 | * @return ResponseEntity 86 | * @since 0.0.1 87 | */ 88 | @ExceptionHandler(Exception.class) 89 | public ResponseEntity> allException(Exception exception) { 90 | 91 | BaseResponse baseResponse = new BaseResponse<>(); 92 | baseResponse.setCode(ResponseConstant.ERROR_CODE); 93 | baseResponse.setMsg( 94 | exception.getMessage() == null ? exception.getClass().getName() : exception.getMessage()); 95 | exception.printStackTrace(); 96 | return new ResponseEntity<>(baseResponse, HttpStatus.OK); 97 | } 98 | 99 | @Override 100 | @NonNull 101 | protected ResponseEntity handleMethodArgumentNotValid( 102 | MethodArgumentNotValidException ex, 103 | @NonNull HttpHeaders headers, 104 | @NonNull HttpStatus status, 105 | @NonNull WebRequest request) { 106 | ObjectError objectError = ex.getBindingResult().getAllErrors().get(0); 107 | return new ResponseEntity<>( 108 | new BaseResponse<>("400", objectError.getDefaultMessage(), ""), HttpStatus.OK); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /spring-oxygen-flysql/src/main/java/com/isxcode/oxygen/flysql/config/FlysqlAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.flysql.config; 2 | 3 | import com.isxcode.oxygen.flysql.constant.FlysqlConstants; 4 | import com.isxcode.oxygen.flysql.core.Flysql; 5 | import com.isxcode.oxygen.flysql.properties.FlysqlProperties; 6 | import com.isxcode.oxygen.flysql.response.GlobalExceptionAdvice; 7 | import com.isxcode.oxygen.flysql.response.SuccessResponseAdvice; 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | import lombok.extern.slf4j.Slf4j; 11 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 12 | import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; 13 | import org.springframework.boot.autoconfigure.mongo.MongoProperties; 14 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 15 | import org.springframework.context.MessageSource; 16 | import org.springframework.context.annotation.Bean; 17 | import org.springframework.data.mongodb.core.MongoTemplate; 18 | import org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory; 19 | import org.springframework.jdbc.core.JdbcTemplate; 20 | import org.springframework.lang.Nullable; 21 | 22 | /** 23 | * flysql auto configure 24 | * 25 | * @author ispong 26 | * @since 0.0.1 27 | */ 28 | @Slf4j 29 | @EnableConfigurationProperties(FlysqlProperties.class) 30 | public class FlysqlAutoConfiguration { 31 | 32 | /** init SuccessResponseAdvice */ 33 | @Bean 34 | @ConditionalOnClass(FlysqlAutoConfiguration.class) 35 | private SuccessResponseAdvice initSuccessResponseAdvice(MessageSource messageSource) { 36 | 37 | return new SuccessResponseAdvice(messageSource); 38 | } 39 | 40 | /** init GlobalExceptionAdvice */ 41 | @Bean 42 | @ConditionalOnClass(FlysqlAutoConfiguration.class) 43 | private GlobalExceptionAdvice initGlobalExceptionAdvice() { 44 | 45 | return new GlobalExceptionAdvice(); 46 | } 47 | 48 | /** 49 | * 初始化flysql factory 50 | * 51 | * @param flysqlProperties configs 52 | * @param dataSourceProperties dataSourceProperties 53 | * @param mongoTemplate mongoTemplate 54 | * @since 0.0.1 55 | */ 56 | @Bean("flysql") 57 | @ConditionalOnClass(FlysqlAutoConfiguration.class) 58 | private Flysql flysql( 59 | FlysqlProperties flysqlProperties, 60 | @Nullable DataSourceProperties dataSourceProperties, 61 | @Nullable MongoTemplate mongoTemplate) { 62 | 63 | Map jdbcTemplateMap; 64 | Map mongoTemplateMap; 65 | 66 | // 集成oracle/mysql/h2数据库 67 | Map dataSourcePropertiesMap = flysqlProperties.getDatasource(); 68 | if (dataSourcePropertiesMap == null) { 69 | jdbcTemplateMap = new HashMap<>(1); 70 | } else { 71 | jdbcTemplateMap = new HashMap<>(dataSourcePropertiesMap.size() + 1); 72 | dataSourcePropertiesMap.forEach( 73 | (k, v) -> 74 | jdbcTemplateMap.put(k, new JdbcTemplate(v.initializeDataSourceBuilder().build()))); 75 | } 76 | 77 | if (dataSourceProperties != null 78 | && dataSourceProperties.initializeDataSourceBuilder() != null) { 79 | jdbcTemplateMap.put( 80 | FlysqlConstants.PRIMARY_DATASOURCE_NAME, 81 | new JdbcTemplate(dataSourceProperties.initializeDataSourceBuilder().build())); 82 | } 83 | 84 | // 集成mongodb数据库 85 | Map mongodbPropertiesMap = flysqlProperties.getMongodb(); 86 | if (mongodbPropertiesMap == null) { 87 | mongoTemplateMap = new HashMap<>(1); 88 | } else { 89 | mongoTemplateMap = new HashMap<>(mongodbPropertiesMap.size() + 1); 90 | mongodbPropertiesMap.forEach( 91 | (k, v) -> { 92 | String connectSetting; 93 | if (v.getUri() == null) { 94 | connectSetting = 95 | "mongo://" 96 | + v.getUsername() 97 | + ":" 98 | + String.valueOf(v.getPassword()) 99 | + "@" 100 | + v.getHost() 101 | + ":" 102 | + v.getPort() 103 | + "/" 104 | + v.getDatabase(); 105 | } else { 106 | connectSetting = v.getUri(); 107 | } 108 | mongoTemplateMap.put( 109 | k, new MongoTemplate(new SimpleMongoClientDatabaseFactory(connectSetting))); 110 | }); 111 | } 112 | if (mongoTemplate != null) { 113 | mongoTemplateMap.put(FlysqlConstants.PRIMARY_DATASOURCE_NAME, mongoTemplate); 114 | } 115 | 116 | // 储存关系型数据库和非关系型数据库 117 | return new Flysql(jdbcTemplateMap, mongoTemplateMap, flysqlProperties); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/main/java/com/isxcode/oxygen/core/freemarker/FreemarkerUtils.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core.freemarker; 2 | 3 | import com.isxcode.oxygen.core.exception.OxygenException; 4 | import freemarker.cache.StringTemplateLoader; 5 | import freemarker.template.Configuration; 6 | import freemarker.template.Template; 7 | import freemarker.template.TemplateException; 8 | import java.io.IOException; 9 | import java.nio.file.Files; 10 | import java.nio.file.Path; 11 | import java.nio.file.Paths; 12 | import lombok.extern.slf4j.Slf4j; 13 | import org.springframework.ui.freemarker.FreeMarkerTemplateUtils; 14 | import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; 15 | 16 | /** 17 | * freemarker utils 18 | * 19 | * @author ispong 20 | * @since 0.0.1 21 | */ 22 | @Slf4j 23 | public class FreemarkerUtils { 24 | 25 | private static final Configuration configuration = 26 | new Configuration(Configuration.VERSION_2_3_27); 27 | 28 | private static FreeMarkerConfigurer freeMarkerConfigurer; 29 | 30 | public FreemarkerUtils(FreeMarkerConfigurer freeMarkerConfigurer) { 31 | 32 | configuration.setTemplateLoader(new StringTemplateLoader()); 33 | FreemarkerUtils.freeMarkerConfigurer = freeMarkerConfigurer; 34 | } 35 | 36 | /** 37 | * generate template file to file 38 | * 39 | * @param templateFileName template file name 40 | * @param filePath file generate path 41 | * @param params freemarker params 42 | * @throws OxygenException freemarker/io exception 43 | * @since 0.0.1 44 | */ 45 | public static void templateToFile(String templateFileName, Object params, String filePath) 46 | throws OxygenException { 47 | 48 | Path fileIoPath = Paths.get(filePath); 49 | 50 | if (Files.isDirectory(fileIoPath)) { 51 | throw new OxygenException("file is directory"); 52 | } 53 | 54 | if (Files.exists(fileIoPath)) { 55 | throw new OxygenException("file is exist"); 56 | } 57 | 58 | try { 59 | Template template = freeMarkerConfigurer.getConfiguration().getTemplate(templateFileName); 60 | Path path = Files.createFile(fileIoPath); 61 | Files.write( 62 | path, FreeMarkerTemplateUtils.processTemplateIntoString(template, params).getBytes()); 63 | } catch (TemplateException | IOException e) { 64 | log.error(e.getMessage()); 65 | throw new OxygenException(e.getMessage()); 66 | } 67 | } 68 | 69 | /** 70 | * generate template file to string 71 | * 72 | * @param templateFileName templateFileName 73 | * @param params params 74 | * @return string 75 | * @throws OxygenException OxygenException 76 | * @since 0.0.1 77 | */ 78 | public static String templateToString(String templateFileName, Object params) { 79 | 80 | try { 81 | Template template = freeMarkerConfigurer.getConfiguration().getTemplate(templateFileName); 82 | return FreeMarkerTemplateUtils.processTemplateIntoString(template, params); 83 | } catch (TemplateException | IOException e) { 84 | log.error(e.getMessage()); 85 | throw new OxygenException(e.getMessage()); 86 | } 87 | } 88 | 89 | /** 90 | * generate content to file 91 | * 92 | * @param templateContent templateContent 93 | * @param params params 94 | * @param filePath filePath 95 | * @since 0.0.1 96 | */ 97 | public static void contentToFile(String templateContent, Object params, String filePath) { 98 | 99 | Path fileIoPath = Paths.get(filePath); 100 | 101 | if (Files.isDirectory(fileIoPath)) { 102 | throw new OxygenException("file is directory"); 103 | } 104 | 105 | if (Files.exists(fileIoPath)) { 106 | throw new OxygenException("file is exist"); 107 | } 108 | 109 | try { 110 | Template template = new Template("", templateContent, configuration); 111 | Path path = Files.createFile(fileIoPath); 112 | Files.write( 113 | path, FreeMarkerTemplateUtils.processTemplateIntoString(template, params).getBytes()); 114 | } catch (TemplateException | IOException e) { 115 | log.error(e.getMessage()); 116 | throw new OxygenException(e.getMessage()); 117 | } 118 | } 119 | 120 | /** 121 | * generate template content to string 122 | * 123 | * @param templateContent templateContent 124 | * @param params params 125 | * @return string 126 | * @throws OxygenException OxygenException 127 | * @since 0.0.1 128 | */ 129 | public static String contentToString(String templateContent, Object params) { 130 | 131 | try { 132 | Template template = new Template("", templateContent, configuration); 133 | return FreeMarkerTemplateUtils.processTemplateIntoString(template, params); 134 | } catch (TemplateException | IOException e) { 135 | log.error(e.getMessage()); 136 | throw new OxygenException(e.getMessage()); 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/main/java/com/isxcode/oxygen/core/http/HttpUtils.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core.http; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.isxcode.oxygen.core.exception.OxygenException; 5 | import java.io.IOException; 6 | import java.util.Map; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.http.HttpEntity; 9 | import org.springframework.http.HttpHeaders; 10 | import org.springframework.http.HttpMethod; 11 | import org.springframework.web.client.RestTemplate; 12 | 13 | /** 14 | * http utils 15 | * 16 | * @author ispong 17 | * @since 0.0.1 18 | */ 19 | @Slf4j 20 | public class HttpUtils { 21 | 22 | /** 23 | * simple get 24 | * 25 | * @param url url 26 | * @param A 27 | * @param targetClass targetClass 28 | * @return A 29 | * @since 0.0.1 30 | */ 31 | public static A doGet(String url, Class targetClass) { 32 | 33 | return doGet(url, null, null, targetClass); 34 | } 35 | 36 | /** 37 | * simple get 38 | * 39 | * @param url url 40 | * @param A 41 | * @param targetClass targetClass 42 | * @param headerParams headerParams 43 | * @return A 44 | * @since 0.0.1 45 | */ 46 | public static A doGet(String url, Map headerParams, Class targetClass) { 47 | 48 | return doGet(url, null, headerParams, targetClass); 49 | } 50 | 51 | /** 52 | * post http 53 | * 54 | * @param T 55 | * @param url url 56 | * @param requestParams requestParams 57 | * @param targetCls targetCls 58 | * @return T 59 | * @throws IOException JACKSON EXCEPTION 60 | * @since 0.0.1 61 | */ 62 | public static T doPost(String url, Object requestParams, Class targetCls) 63 | throws IOException { 64 | 65 | return doPost(url, null, requestParams, targetCls); 66 | } 67 | 68 | /** 69 | * 执行post请求 70 | * 71 | * @param url url 72 | * @param requestParams requestParams 73 | * @param headerParams headerParams 74 | * @return data string 75 | * @throws IOException JACKSON EXCEPTION 76 | * @since 0.0.1 77 | */ 78 | public static String doPost(String url, Map headerParams, Object requestParams) 79 | throws IOException { 80 | 81 | return doPost(url, headerParams, requestParams, String.class); 82 | } 83 | 84 | /** 85 | * post http 86 | * 87 | * @param T 88 | * @param url url 89 | * @param requestParams requestParams 90 | * @param headerParams headerParams 91 | * @param targetCls targetCls 92 | * @return T 93 | * @throws IOException JACKSON EXCEPTION 94 | * @since 0.0.1 95 | */ 96 | public static T doPost( 97 | String url, Map headerParams, Object requestParams, Class targetCls) 98 | throws IOException { 99 | 100 | HttpHeaders headers = new HttpHeaders(); 101 | 102 | if (headerParams == null || headerParams.get(HttpHeaders.CONTENT_TYPE) == null) { 103 | headers.add(HttpHeaders.CONTENT_TYPE, "application/json;charset=UTF-8"); 104 | } 105 | 106 | if (headerParams != null) { 107 | headerParams.forEach(headers::add); 108 | } 109 | 110 | HttpEntity requestEntity = 111 | new HttpEntity<>(new ObjectMapper().writeValueAsString(requestParams), headers); 112 | try { 113 | return new RestTemplate().exchange(url, HttpMethod.POST, requestEntity, targetCls).getBody(); 114 | } catch (Exception e) { 115 | log.error(e.getMessage()); 116 | throw new OxygenException(e.getMessage()); 117 | } 118 | } 119 | 120 | /** 121 | * http get 122 | * 123 | * @param url url 124 | * @param headerParams header 125 | * @param requestParams params 126 | * @param targetClass targetClass 127 | * @param A 128 | * @return A 129 | * @since 0.0.1 130 | */ 131 | public static A doGet( 132 | String url, 133 | Map requestParams, 134 | Map headerParams, 135 | Class targetClass) { 136 | 137 | StringBuilder requestUrl = new StringBuilder(url); 138 | 139 | // add params 140 | if (requestParams != null) { 141 | requestUrl.append("?"); 142 | requestParams.forEach((k, v) -> requestUrl.append(k).append("=").append(v).append("&")); 143 | } 144 | 145 | // add headers 146 | HttpEntity requestEntity = null; 147 | if (headerParams != null) { 148 | HttpHeaders headers = new HttpHeaders(); 149 | headerParams.forEach(headers::add); 150 | requestEntity = new HttpEntity<>(null, headers); 151 | } 152 | 153 | try { 154 | return new RestTemplate() 155 | .exchange(requestUrl.toString(), HttpMethod.GET, requestEntity, targetClass) 156 | .getBody(); 157 | } catch (Exception e) { 158 | log.error(e.getMessage()); 159 | throw new OxygenException(e.getMessage()); 160 | } 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/main/java/com/isxcode/oxygen/core/file/FileUtils.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core.file; 2 | 3 | import com.isxcode.oxygen.core.exception.OxygenException; 4 | import java.io.File; 5 | import java.io.IOException; 6 | import java.nio.charset.StandardCharsets; 7 | import java.nio.file.Files; 8 | import java.nio.file.OpenOption; 9 | import java.nio.file.Path; 10 | import java.nio.file.Paths; 11 | import lombok.extern.slf4j.Slf4j; 12 | import org.apache.commons.io.IOUtils; 13 | import org.springframework.core.io.DefaultResourceLoader; 14 | import org.springframework.core.io.Resource; 15 | 16 | @Slf4j 17 | public class FileUtils { 18 | 19 | /** 20 | * translate windows path to str 21 | * 22 | * @param pathStr pathStr 23 | * @return windows path 24 | */ 25 | public static String translateWindowsPath(String pathStr) { 26 | 27 | return pathStr.contains("\\") ? pathStr.replace("\\", "\\\\") : pathStr; 28 | } 29 | 30 | /** 31 | * generate dirs 32 | * 33 | * @param dirPath dirPath 34 | */ 35 | public static void generateDirs(String dirPath) { 36 | 37 | Path dir = Paths.get(translateWindowsPath(dirPath)); 38 | if (!Files.exists(dir)) { 39 | try { 40 | Files.createDirectories(dir); 41 | } catch (IOException e) { 42 | log.error(e.getMessage()); 43 | throw new OxygenException("create dir path error"); 44 | } 45 | } 46 | } 47 | 48 | /** 49 | * generate file 50 | * 51 | * @param filePath filePath 52 | * @return filePath 53 | */ 54 | public static Path generateFile(String filePath) { 55 | 56 | // generate dir 57 | int endSeparator = filePath.lastIndexOf(File.separator); 58 | String dirPath = filePath.substring(0, endSeparator); 59 | generateDirs(dirPath); 60 | 61 | // generate file 62 | Path file = Paths.get(filePath); 63 | if (!Files.exists(file)) { 64 | try { 65 | return Files.createFile(file); 66 | } catch (IOException e) { 67 | log.error(e.getMessage()); 68 | throw new OxygenException("create file path error"); 69 | } 70 | } else { 71 | return file; 72 | } 73 | } 74 | 75 | /** 76 | * write string to file or new file 77 | * 78 | * @param content strContent 79 | * @param dirPath dir 80 | * @param fileName fileName+suffix 81 | * @param options StandardOpenOption.WRITE/StandardOpenOption.APPEND 82 | */ 83 | public static void StringToFile( 84 | String content, String dirPath, String fileName, OpenOption... options) { 85 | 86 | // generate filePath 87 | Path file = generateFile(dirPath + File.separator + fileName); 88 | 89 | // write string to file 90 | try { 91 | Files.write(file, content.getBytes(), options); 92 | } catch (IOException e) { 93 | log.error(e.getMessage()); 94 | throw new OxygenException("write content error"); 95 | } 96 | } 97 | 98 | /** 99 | * write string to file or new file 100 | * 101 | * @param content strContent 102 | * @param filePath file 103 | * @param options StandardOpenOption.WRITE/StandardOpenOption.APPEND 104 | */ 105 | public static void StringToFile(String content, String filePath, OpenOption... options) { 106 | 107 | // split filePath 108 | int endSeparator = filePath.lastIndexOf(File.separator); 109 | String dirPath = filePath.substring(0, endSeparator); 110 | String fileName = filePath.substring(endSeparator + 1); 111 | 112 | // generate file 113 | StringToFile(content, dirPath, fileName, options); 114 | } 115 | 116 | /** 117 | * copy resources dir file to new file 118 | * 119 | * @param resourceFilePath resourceFilePath 120 | * @param filePath filePath 121 | * @param options options 122 | */ 123 | public static void copyResourceFile( 124 | String resourceFilePath, String filePath, OpenOption... options) { 125 | 126 | DefaultResourceLoader defaultResourceLoader = new DefaultResourceLoader(); 127 | Resource resource = defaultResourceLoader.getResource(resourceFilePath); 128 | 129 | Path file = generateFile(filePath); 130 | try { 131 | Files.write( 132 | file, 133 | IOUtils.toString(resource.getInputStream(), StandardCharsets.UTF_8).getBytes(), 134 | options); 135 | } catch (IOException e) { 136 | log.error(e.getMessage()); 137 | throw new OxygenException("copy resource file error"); 138 | } 139 | } 140 | 141 | /** 142 | * recursion delete file 143 | * 144 | * @param path path 145 | */ 146 | public static void recursionDeleteFile(Path path) { 147 | 148 | try { 149 | if (Files.isDirectory(path)) { 150 | Files.list(path).forEach(FileUtils::recursionDeleteFile); 151 | } 152 | Files.deleteIfExists(path); 153 | } catch (IOException e) { 154 | log.error(e.getMessage()); 155 | throw new OxygenException("delete dir error"); 156 | } 157 | } 158 | 159 | /** 160 | * recursion delete file 161 | * 162 | * @param path path 163 | */ 164 | public static void recursionDeleteFile(String path) { 165 | 166 | recursionDeleteFile(Paths.get(path)); 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /spring-oxygen-core/src/main/java/com/isxcode/oxygen/core/email/EmailUtils.java: -------------------------------------------------------------------------------- 1 | package com.isxcode.oxygen.core.email; 2 | 3 | import com.isxcode.oxygen.core.exception.OxygenException; 4 | import java.io.File; 5 | import java.util.Collections; 6 | import java.util.List; 7 | import java.util.Map; 8 | import java.util.Objects; 9 | import javax.mail.MessagingException; 10 | import javax.mail.internet.MimeMessage; 11 | import lombok.extern.slf4j.Slf4j; 12 | import org.springframework.mail.MailSender; 13 | import org.springframework.mail.javamail.JavaMailSenderImpl; 14 | import org.springframework.mail.javamail.MimeMessageHelper; 15 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; 16 | 17 | /** 18 | * email utils 19 | * 20 | * @author ispong 21 | * @since 0.0.1 22 | */ 23 | @Slf4j 24 | public class EmailUtils { 25 | 26 | private static JavaMailSenderImpl javaMailSender; 27 | 28 | private static ThreadPoolTaskExecutor emailThread; 29 | 30 | public EmailUtils(MailSender mailSender, ThreadPoolTaskExecutor emailThread) { 31 | 32 | EmailUtils.emailThread = emailThread; 33 | EmailUtils.javaMailSender = (JavaMailSenderImpl) mailSender; 34 | } 35 | 36 | /** 37 | * send simple email 38 | * 39 | * @param email email 40 | * @param content content 41 | * @param subject subject 42 | * @param senderName senderName 43 | * @since 0.0.1 44 | */ 45 | public static void sendSimpleEmail( 46 | String email, String content, String subject, String senderName) { 47 | 48 | try { 49 | sendEmail(Collections.singletonList(email), content, subject, senderName, false, null, null); 50 | } catch (MessagingException e) { 51 | log.error(e.getMessage()); 52 | throw new OxygenException(e.getMessage()); 53 | } 54 | } 55 | 56 | /** 57 | * send simple emails 58 | * 59 | * @param emails emails 60 | * @param content content 61 | * @param subject subject 62 | * @param senderName senderName 63 | * @since 0.0.1 64 | */ 65 | public static void sendSimpleEmail( 66 | List emails, String content, String subject, String senderName) { 67 | 68 | try { 69 | sendEmail(emails, content, subject, senderName, false, null, null); 70 | } catch (Exception e) { 71 | log.error(e.getMessage()); 72 | throw new OxygenException(e.getMessage()); 73 | } 74 | } 75 | 76 | /** 77 | * send html email 78 | * 79 | * @param email email 80 | * @param content content 81 | * @param subject subject 82 | * @param senderName senderName 83 | * @since 0.0.1 84 | */ 85 | public static void sendNormalHtmlEmail( 86 | String email, String content, String subject, String senderName) { 87 | 88 | try { 89 | sendEmail(Collections.singletonList(email), content, subject, senderName, true, null, null); 90 | } catch (Exception e) { 91 | log.error(e.getMessage()); 92 | throw new OxygenException(e.getMessage()); 93 | } 94 | } 95 | 96 | /** 97 | * send email main 98 | * 99 | * @param toEmails toEmails 100 | * @param emailContent emailContent 101 | * @param subject subject 102 | * @param senderName senderName 103 | * @param isHtmlContent isHtmlContent 104 | * @param files files 105 | * @param inlineFiles inlineFiles 106 | * @throws MessagingException MessagingException 107 | * @since 0.0.1 108 | */ 109 | public static void sendEmail( 110 | List toEmails, 111 | String emailContent, 112 | String subject, 113 | String senderName, 114 | boolean isHtmlContent, 115 | List files, 116 | Map inlineFiles) 117 | throws MessagingException { 118 | 119 | MimeMessage message = javaMailSender.createMimeMessage(); 120 | 121 | if (javaMailSender.getUsername() == null) { 122 | throw new OxygenException("email username is null"); 123 | } 124 | 125 | if (senderName == null || senderName.isEmpty()) { 126 | message.setFrom(Objects.requireNonNull(javaMailSender.getUsername())); 127 | } else { 128 | message.setFrom( 129 | senderName + "<" + Objects.requireNonNull(javaMailSender.getUsername()) + ">"); 130 | } 131 | 132 | MimeMessageHelper helper = new MimeMessageHelper(message); 133 | 134 | if (files != null || inlineFiles != null) { 135 | helper = new MimeMessageHelper(message, true); 136 | } 137 | 138 | helper.setSubject(subject); 139 | helper.setText(emailContent, isHtmlContent); 140 | 141 | if (files != null) { 142 | for (File file : files) { 143 | helper.addAttachment(file.getName(), file); 144 | } 145 | } 146 | 147 | if (inlineFiles != null) { 148 | for (Map.Entry entry : inlineFiles.entrySet()) { 149 | helper.addInline(entry.getKey(), entry.getValue()); 150 | } 151 | } 152 | 153 | for (String toEmail : toEmails) { 154 | helper.setTo(toEmail); 155 | emailThread.execute( 156 | () -> { 157 | try { 158 | javaMailSender.send(message); 159 | } catch (Exception e) { 160 | log.error(e.getMessage()); 161 | log.info("email fail to send"); 162 | } 163 | }); 164 | } 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | spring-oxygen 4 | 5 |

6 | 7 |

8 | Spring Oxygen 9 |

10 | 11 |

12 | 🦄 Spring rapid development integration framework. 13 |

14 | 15 |
16 | 17 | [![Github Build](https://github.com/isxcode/spring-oxygen/workflows/build/badge.svg?branch=latest)](https://github.com/isxcode/spring-oxygen/actions?query=workflow%3Abuild) 18 | [![Maven Version](https://img.shields.io/maven-central/v/com.isxcode.oxygen/oxygen-spring-boot-starter)](https://search.maven.org/artifact/com.isxcode.oxygen/oxygen-spring-boot-starter) 19 | [![Language grade: Java](https://img.shields.io/lgtm/grade/java/g/isxcode/spring-oxygen.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/isxcode/spring-oxygen/context:java) 20 | [![Coverage Status](https://coveralls.io/repos/github/isxcode/spring-oxygen/badge.svg?branch=latest)](https://coveralls.io/github/isxcode/spring-oxygen?branch=latest) 21 | [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fisxcode%2Fspring-oxygen.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fisxcode%2Fspring-oxygen?ref=badge_shield) 22 | 23 |
24 | 25 |
26 | 27 | [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://spring-oxygen.isxcode.com/#/en-us/contributing) 28 | [![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/isxcode/spring-oxygen) 29 | [![Discussions on github](https://img.shields.io/badge/Discussions-on%20github-blueviolet)](https://github.com/isxcode/spring-oxygen/discussions) 30 | 31 |
32 | 33 |
34 | 35 | [![Github Watch](https://img.shields.io/github/watchers/isxcode/spring-oxygen?style=social)](https://github.com/isxcode/spring-oxygen/watchers) 36 | [![Github Star](https://img.shields.io/github/stars/isxcode/spring-oxygen?style=social)](https://github.com/isxcode/spring-oxygen/stargazers) 37 | [![Github Fork](https://img.shields.io/github/forks/isxcode/spring-oxygen?style=social)](https://github.com/isxcode/spring-oxygen/network/members) 38 | 39 |
40 | 41 | ## 🐣 Introduce 42 | 43 | [Spring Oxygen](https://github.com/isxcode/spring-oxygen) is rapid development integration framework for [Spring](https://spring.io/) . 44 | **Important statement, enterprise-level development is recommended to be used with caution!** 45 | For instructions on use, please check the [website](https://spring-oxygen.isxcode.com) carefully. 46 | Welcome to develop and maintain together, please follow the [GitHub development](https://spring-oxygen.isxcode.com/#/en-us/contributing) specification. 47 | 48 | ## 📦 Installation 49 | 50 | [![Maven Version](https://img.shields.io/maven-central/v/com.isxcode.oxygen/oxygen-spring-boot-starter)](https://search.maven.org/artifact/com.isxcode.oxygen/oxygen-spring-boot-starter) 51 | 52 | - For Gradle 53 | 54 | ```groovy 55 | dependencies { 56 | implementation 'com.isxcode.oxygen:oxygen-spring-boot-starter:1.9.1' 57 | } 58 | ``` 59 | 60 | - For Maven 61 | 62 | ```xml 63 | 64 | com.isxcode.oxygen 65 | oxygen-spring-boot-starter 66 | 1.10.3 67 | 68 | ``` 69 | 70 | ## 🔨 Usage 71 | 72 | ```yaml 73 | spring: 74 | datasource: 75 | driver-class-name: org.h2.Driver 76 | url: jdbc:h2:~/h2 77 | username: root 78 | password: root 79 | ``` 80 | 81 | ```java 82 | @Repository 83 | public class MetaDataRepository { 84 | 85 | private final Flysql flysql; 86 | 87 | public MetaDataRepository(Flysql flysql) { 88 | this.flysql = flysql; 89 | } 90 | 91 | 92 | public List queryJdbcMetaData() { 93 | 94 | return flysql.build().select(MetaData.class) 95 | .select("col1", "col2", "col3") 96 | .eq("col4", "val1") 97 | .between("col2", 0, 1) 98 | .like("col3", "green") 99 | .orderBy("col4", OrderType.DESC) 100 | .query(); 101 | } 102 | } 103 | ``` 104 | 105 | ## 📒 Documentation 106 | 107 | Check out the [Getting Started](https://spring-oxygen.isxcode.com) page for a quick overview. 108 | 109 | ## 👏 Contributing 110 | 111 | Read our [contributing guide](https://spring-oxygen.isxcode.com/#/en-us/contributing) to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to Spring Oxygen. 112 | 113 | *** 114 | 115 | **Thanks for free JetBrains Open Source license** 116 | 117 | 118 | jetbrains 119 | 120 | --------------------------------------------------------------------------------