Compare commits

..

6 Commits

Author SHA1 Message Date
ac70c385f7 release: v1.0.1 2023-12-14 00:00:58 +08:00
1adfddfa3b fix(extension/crud): 修复使用 CrudRequestMapping 后自定义 API 不显示的问题 2023-12-13 23:44:23 +08:00
bc00c9bab0 refactor(data): MyBatis Plus QueryTypeEnum => QueryType,并取消实现 IBaseEnum 接口 2023-12-13 23:24:17 +08:00
7997267060 refactor(api-doc): 新增鉴权配置 2023-12-12 20:35:13 +08:00
083bc7b38a refactor: 调整部分内容所属模块
1.校验等工具类 crud => core
2.@Query crud => mybatis-plus
2023-12-05 20:57:34 +08:00
af351e04b9 chore: 更新版本号 2023-12-05 20:57:06 +08:00
18 changed files with 190 additions and 63 deletions

View File

@@ -1,3 +1,19 @@
## [v1.0.1](https://github.com/Charles7c/continew-starter/compare/v1.0.0...v1.0.1) (2023-12-13)
### 💎 功能优化
- 【data/mybatis-plus】QueryTypeEnum => QueryType并取消实现 IBaseEnum 接口 ([bc00c9b](https://github.com/Charles7c/continew-starter/commit/bc00c9bab0ed4508fd1dc0da8a76ef96739cce1d))
- 【api-doc】新增鉴权配置 ([7997267](https://github.com/Charles7c/continew-starter/commit/7997267060b3e79f80dd73cec722bc295635a93b))
### 🐛 问题修复
- 【extension/crud】修复使用 @CrudRequestMapping 后自定义 API 不显示的问题 ([1adfddf](https://github.com/Charles7c/continew-starter/commit/1adfddfa3b276e764b098512b2e9c75f007d13c1))
### 💥 破坏性变更
- 【extension/crud】调整通用查询注解所属模块 crud => mybatis-plus ([083bc7b](https://github.com/Charles7c/continew-starter/commit/083bc7b38a861339ceb7a06acdd20ea64bc84990))
- 【extension/crud】调整校验工具类所属模块 crud => core ([083bc7b](https://github.com/Charles7c/continew-starter/commit/083bc7b38a861339ceb7a06acdd20ea64bc84990))
## v1.0.0 (2023-12-02)
### ✨ 新特性

View File

@@ -4,7 +4,7 @@
<img src="https://img.shields.io/badge/License-LGPL--3.0-blue.svg" alt="License" />
</a>
<a href="https://github.com/Charles7c/continew-starter" target="_blank">
<img src="https://img.shields.io/badge/RELEASE-v1.0.0-%23ff3f59.svg" alt="Release" />
<img src="https://img.shields.io/badge/RELEASE-v1.0.1-%23ff3f59.svg" alt="Release" />
</a>
<a href="https://github.com/Charles7c/continew-starter" target="_blank">
<img src="https://img.shields.io/github/stars/Charles7c/continew-starter?style=social" alt="GitHub stars" />
@@ -48,8 +48,8 @@ ContiNew Starter 就是将脚手架项目中的通用基础配置进行了封装
## 项目源码
| 开源平台 | 源码地址 |
| ------------- | ------------------------------------------- |
| 开源平台 | 源码地址 |
| :------------ | :-------------------------------------------- |
| GitHub | https://github.com/Charles7c/continew-starter |
| Gitee码云 | https://gitee.com/Charles7c/continew-starter |
@@ -63,7 +63,7 @@ ContiNew Starter 就是将脚手架项目中的通用基础配置进行了封装
<parent>
<groupId>top.charles7c.continew</groupId>
<artifactId>continew-starter</artifactId>
<version>1.0.0</version>
<version>{latest-version}</version>
</parent>
```
@@ -83,7 +83,7 @@ ContiNew Starter 就是将脚手架项目中的通用基础配置进行了封装
<dependency>
<groupId>top.charles7c.continew</groupId>
<artifactId>continew-starter-dependencies</artifactId>
<version>1.0.0</version>
<version>{latest-version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@@ -121,6 +121,31 @@ cors:
exposed-headers: '*'
```
<details>
<summary>抢先体验快照SNAPSHOT版本💡</summary>
> **注意:** 快照版本目前处于开发测试阶段,其中很多特性或改动尚不稳定,可能会因为修复或优化而频繁调整。因此,仅可用于体验,切勿用于生产环境!
1.在项目 pom.xml 中配置 SNAPSHOT快照仓库地址如果你已配有其他仓库地址追加下方快照仓库地址即可
```xml
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
<snapshots>
<updatePolicy>always</updatePolicy>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
```
2.将 ContiNew Starter 版本改为对应快照版本例如1.0.1-SNAPSHOT
</details>
## 模块结构
| 模块名称 | 模块说明 | 依赖版本 |
@@ -140,6 +165,10 @@ cors:
![模块依赖图](.image/模块依赖图.png)
## 谁在使用?
- ✨[ContiNew Admin](https://github.com/Charles7c/continew-admin)ContiNew Admin Continue New Admin中后台管理框架/脚手架持续以最新流行技术栈构建拥抱变化迭代优化。依托开源协作模式提升技术透明度、放大集体智慧、共创优秀实践源源不断地为企业级项目开发提供助力。当前采用的技术栈Spring Boot3Java17、Vue3 & Arco Design、Sa-Token、MyBatis Plus、Redisson、Liquibase、JustAuth、Easy Excel、Hutool、TypeScript、Vite4 等。
## 贡献代码
### 分支说明
@@ -171,9 +200,24 @@ ContiNew Starter 的分支目前分为下个大版本的开发分支和上个大
> 2. 在提交代码前,请按照 [Angular 提交规范](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-angular) 编写 commit 的 message建议在 IntelliJ IDEA 中下载并安装 Git Commit Template 插件,以便按照规范进行 commit
> 3. 提交代码之前,请关闭所有代码窗口,执行 mvn compile 命令,编译通过后,不要再打开查看任何代码窗口,直接提交即可
## 谁在使用?
## 反馈交流
- ✨[ContiNew Admin](https://github.com/Charles7c/continew-admin)ContiNew Admin Continue New Admin中后台管理框架/脚手架持续以最新流行技术栈构建拥抱变化迭代优化。依托开源协作模式提升技术透明度、放大集体智慧、共创优秀实践源源不断地为企业级项目开发提供助力。当前采用的技术栈Spring Boot3Java17、Vue3 & Arco Design、Sa-Token、MyBatis Plus、Redisson、Liquibase、JustAuth、Easy Excel、Hutool、TypeScript、Vite4 等。
💬 欢迎各位小伙伴儿扫描下方二维码加好友,备注 `cnadmin`,拉你进群,探讨技术、提提需求~
加入交流群后,你将会:
- 第一时间收到框架动态
- 第一时间收到框架更新通知
- 第一时间收到框架 Bug 通知
- 和众多大佬互相 (huá shuǐ) 交流 (mō yú)
<div align="left">
<img src="https://doc.charles7c.top/qrcode.jpg" alt="二维码" width="230px" />
</div>
<details>
<summary>无加群意愿</summary>
💬 如无加群意愿,欢迎在 <a href="https://github.com/Charles7c/continew-starter/issues" target="_blank">Issues</a> 中反馈交流~ 🍻
</details>
## 鸣谢
@@ -195,25 +239,6 @@ ContiNew Starter 的分支目前分为下个大版本的开发分支和上个大
- e.g. 使用 Dante-Engine 项目封装的 Redisson 相关配置
- 感谢项目使用或未使用到的每一款开源组件,致敬各位开源先驱 :fire:
## 反馈交流
💬 欢迎各位小伙伴儿扫描下方二维码加好友,备注 `cnadmin`,拉你进群,探讨技术、提提需求~
加入交流群后,你将会:
- 第一时间收到框架动态
- 第一时间收到框架更新通知
- 第一时间收到框架 Bug 通知
- 和众多大佬互相 (huá shuǐ) 交流 (mō yú)
<div align="left">
<img src="https://doc.charles7c.top/qrcode.jpg" alt="二维码" width="230px" />
</div>
<details>
<summary>无加群意愿</summary>
💬 如无加群意愿,欢迎在 <a href="https://github.com/Charles7c/continew-starter/issues" target="_blank">Issues</a> 中反馈交流~ 🍻
</details>
## License
- 遵循 <a href="https://github.com/Charles7c/continew-starter/blob/dev/LICENSE" target="_blank">LGPL-3.0</a> 开源许可协议

View File

@@ -16,15 +16,21 @@
package top.charles7c.continew.starter.apidoc.autoconfigure;
import cn.hutool.core.map.MapUtil;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.customizers.GlobalOpenApiCustomizer;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.http.CacheControl;
@@ -34,6 +40,8 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import top.charles7c.continew.starter.core.autoconfigure.project.ProjectProperties;
import top.charles7c.continew.starter.core.handler.GeneralPropertySourceFactory;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@@ -47,6 +55,7 @@ import java.util.concurrent.TimeUnit;
@EnableWebMvc
@AutoConfiguration
@ConditionalOnProperty(name = "springdoc.swagger-ui.enabled", havingValue = "true")
@EnableConfigurationProperties(SpringDocExtensionProperties.class)
@PropertySource(value = "classpath:default-api-doc.yml", factory = GeneralPropertySourceFactory.class)
public class SpringDocAutoConfiguration implements WebMvcConfigurer {
@@ -63,23 +72,62 @@ public class SpringDocAutoConfiguration implements WebMvcConfigurer {
*/
@Bean
@ConditionalOnMissingBean
public OpenAPI openApi(ProjectProperties properties) {
public OpenAPI openApi(ProjectProperties projectProperties, SpringDocExtensionProperties properties) {
Info info = new Info()
.title(String.format("%s %s", properties.getName(), "API 文档"))
.version(properties.getVersion())
.description(properties.getDescription());
ProjectProperties.Contact contact = properties.getContact();
.title(String.format("%s %s", projectProperties.getName(), "API 文档"))
.version(projectProperties.getVersion())
.description(projectProperties.getDescription());
ProjectProperties.Contact contact = projectProperties.getContact();
if (null != contact) {
info.contact(new Contact().name(contact.getName())
.email(contact.getEmail())
.url(contact.getUrl()));
}
ProjectProperties.License license = properties.getLicense();
ProjectProperties.License license = projectProperties.getLicense();
if (null != license) {
info.license(new License().name(license.getName())
.url(license.getUrl()));
}
return new OpenAPI().info(info);
OpenAPI openAPI = new OpenAPI();
openAPI.info(info);
Components components = properties.getComponents();
if (null != components) {
openAPI.components(components);
// 鉴权配置
Map<String, SecurityScheme> securitySchemeMap = components.getSecuritySchemes();
if (MapUtil.isNotEmpty(securitySchemeMap)) {
SecurityRequirement securityRequirement = new SecurityRequirement();
List<String> list = securitySchemeMap.values().stream().map(SecurityScheme::getName).toList();
list.forEach(securityRequirement::addList);
openAPI.addSecurityItem(securityRequirement);
}
}
return openAPI;
}
/**
* 全局自定义配置(全局添加鉴权参数)
*/
@Bean
@ConditionalOnMissingBean
public GlobalOpenApiCustomizer globalOpenApiCustomizer(SpringDocExtensionProperties properties) {
return openApi -> {
if (null != openApi.getPaths()) {
openApi.getPaths().forEach((s, pathItem) -> {
// 为所有接口添加鉴权
Components components = properties.getComponents();
if (null != components && MapUtil.isNotEmpty(components.getSecuritySchemes())) {
Map<String, SecurityScheme> securitySchemeMap = components.getSecuritySchemes();
pathItem.readOperations().forEach(operation -> {
SecurityRequirement securityRequirement = new SecurityRequirement();
List<String> list = securitySchemeMap.values().stream().map(SecurityScheme::getName).toList();
list.forEach(securityRequirement::addList);
operation.addSecurityItem(securityRequirement);
});
}
});
}
};
}
@PostConstruct

View File

@@ -0,0 +1,40 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.charles7c.continew.starter.apidoc.autoconfigure;
import io.swagger.v3.oas.models.Components;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
/**
* API 文档扩展配置属性
*
* @author Charles7c
* @since 1.0.1
*/
@Data
@ConfigurationProperties(prefix = "springdoc")
public class SpringDocExtensionProperties {
/**
* 组件配置(包括鉴权配置等)
*/
@NestedConfigurationProperty
private Components components;
}

View File

@@ -14,10 +14,9 @@
* limitations under the License.
*/
package top.charles7c.continew.starter.extension.crud.exception;
package top.charles7c.continew.starter.core.exception;
import lombok.NoArgsConstructor;
import top.charles7c.continew.starter.core.exception.BaseException;
/**
* 自定义验证异常-错误请求

View File

@@ -14,10 +14,9 @@
* limitations under the License.
*/
package top.charles7c.continew.starter.extension.crud.exception;
package top.charles7c.continew.starter.core.exception;
import lombok.NoArgsConstructor;
import top.charles7c.continew.starter.core.exception.BaseException;
/**
* 业务异常

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.charles7c.continew.starter.extension.crud.util;
package top.charles7c.continew.starter.core.util;
import cn.hutool.core.util.ReflectUtil;
import lombok.AccessLevel;

View File

@@ -14,14 +14,14 @@
* limitations under the License.
*/
package top.charles7c.continew.starter.extension.crud.util.validate;
package top.charles7c.continew.starter.core.util.validate;
import cn.hutool.core.util.StrUtil;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import top.charles7c.continew.starter.core.constant.StringConstants;
import top.charles7c.continew.starter.extension.crud.exception.BusinessException;
import top.charles7c.continew.starter.core.exception.BusinessException;
import java.util.function.BooleanSupplier;

View File

@@ -14,13 +14,13 @@
* limitations under the License.
*/
package top.charles7c.continew.starter.extension.crud.util.validate;
package top.charles7c.continew.starter.core.util.validate;
import cn.hutool.core.util.StrUtil;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import top.charles7c.continew.starter.extension.crud.exception.BadRequestException;
import top.charles7c.continew.starter.core.exception.BadRequestException;
import java.util.function.BooleanSupplier;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.charles7c.continew.starter.extension.crud.util.validate;
package top.charles7c.continew.starter.core.util.validate;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReflectUtil;

View File

@@ -14,9 +14,9 @@
* limitations under the License.
*/
package top.charles7c.continew.starter.extension.crud.annotation;
package top.charles7c.continew.starter.data.mybatis.plus.annotation;
import top.charles7c.continew.starter.extension.crud.enums.QueryTypeEnum;
import top.charles7c.continew.starter.data.mybatis.plus.enums.QueryType;
import java.lang.annotation.*;
@@ -40,7 +40,7 @@ public @interface Query {
/**
* 查询类型等值查询模糊查询范围查询等
*/
QueryTypeEnum type() default QueryTypeEnum.EQUAL;
QueryType type() default QueryType.EQUAL;
/**
* 多属性模糊查询仅支持 String 类型属性

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.charles7c.continew.starter.extension.crud.base;
package top.charles7c.continew.starter.data.mybatis.plus.enums;
import com.baomidou.mybatisplus.annotation.IEnum;

View File

@@ -14,11 +14,10 @@
* limitations under the License.
*/
package top.charles7c.continew.starter.extension.crud.enums;
package top.charles7c.continew.starter.data.mybatis.plus.enums;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import top.charles7c.continew.starter.extension.crud.base.IBaseEnum;
/**
* 查询类型枚举
@@ -28,7 +27,7 @@ import top.charles7c.continew.starter.extension.crud.base.IBaseEnum;
*/
@Getter
@RequiredArgsConstructor
public enum QueryTypeEnum implements IBaseEnum<Integer> {
public enum QueryType {
/**
* 等值查询例如WHERE `age` = 18

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.charles7c.continew.starter.extension.crud.util;
package top.charles7c.continew.starter.data.mybatis.plus.util;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
@@ -23,10 +23,11 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import top.charles7c.continew.starter.extension.crud.annotation.Query;
import top.charles7c.continew.starter.extension.crud.enums.QueryTypeEnum;
import top.charles7c.continew.starter.extension.crud.exception.BadRequestException;
import top.charles7c.continew.starter.extension.crud.util.validate.ValidationUtils;
import top.charles7c.continew.starter.core.exception.BadRequestException;
import top.charles7c.continew.starter.core.util.ReflectUtils;
import top.charles7c.continew.starter.core.util.validate.ValidationUtils;
import top.charles7c.continew.starter.data.mybatis.plus.annotation.Query;
import top.charles7c.continew.starter.data.mybatis.plus.enums.QueryType;
import java.lang.reflect.Field;
import java.util.ArrayList;
@@ -129,7 +130,7 @@ public class QueryHelper {
// 注意数据库规范中列采用下划线连接法命名程序规范中变量采用驼峰法命名
String property = queryAnnotation.property();
String columnName = StrUtil.toUnderlineCase(StrUtil.blankToDefault(property, fieldName));
QueryTypeEnum queryType = queryAnnotation.type();
QueryType queryType = queryAnnotation.type();
switch (queryType) {
case EQUAL -> queryWrapper.eq(columnName, fieldValue);
case NOT_EQUAL -> queryWrapper.ne(columnName, fieldValue);

View File

@@ -54,7 +54,7 @@
</scm>
<properties>
<revision>1.0.0</revision>
<revision>1.0.1</revision>
<just-auth.version>1.16.5</just-auth.version>
<sa-token.version>1.37.0</sa-token.version>
<mybatis-plus.version>3.5.4.1</mybatis-plus.version>

View File

@@ -34,14 +34,14 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.transaction.annotation.Transactional;
import top.charles7c.continew.starter.core.util.ExceptionUtils;
import top.charles7c.continew.starter.core.util.ReflectUtils;
import top.charles7c.continew.starter.core.util.validate.CheckUtils;
import top.charles7c.continew.starter.data.mybatis.plus.util.QueryHelper;
import top.charles7c.continew.starter.extension.crud.annotation.TreeField;
import top.charles7c.continew.starter.extension.crud.model.query.PageQuery;
import top.charles7c.continew.starter.extension.crud.model.query.SortQuery;
import top.charles7c.continew.starter.extension.crud.model.resp.PageDataResp;
import top.charles7c.continew.starter.extension.crud.util.QueryHelper;
import top.charles7c.continew.starter.extension.crud.util.ReflectUtils;
import top.charles7c.continew.starter.extension.crud.util.TreeUtils;
import top.charles7c.continew.starter.extension.crud.util.validate.CheckUtils;
import top.charles7c.continew.starter.file.excel.util.ExcelUtils;
import java.lang.reflect.Field;

View File

@@ -49,11 +49,11 @@ public class CrudRequestMappingHandlerMapping extends RequestMappingHandlerMappi
if (!handlerType.isAnnotationPresent(CrudRequestMapping.class)) {
return requestMappingInfo;
}
// 过滤 API如果 API 列表中不包含,则忽略
CrudRequestMapping crudRequestMapping = handlerType.getDeclaredAnnotation(CrudRequestMapping.class);
// 过滤 API如果非本类中定义且 API 列表中不包含,则忽略
Api[] apiArr = crudRequestMapping.api();
Api api = ExceptionUtils.exToNull(() -> Api.valueOf(method.getName().toUpperCase()));
if (!ArrayUtil.containsAny(apiArr, Api.ALL, api)) {
if (method.getDeclaringClass() != handlerType && !ArrayUtil.containsAny(apiArr, Api.ALL, api)) {
return null;
}
// 拼接路径(合并了 @RequestMapping 的部分能力)

View File

@@ -24,8 +24,8 @@ import cn.hutool.core.lang.tree.parser.NodeParser;
import cn.hutool.core.util.ReflectUtil;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import top.charles7c.continew.starter.core.util.validate.CheckUtils;
import top.charles7c.continew.starter.extension.crud.annotation.TreeField;
import top.charles7c.continew.starter.extension.crud.util.validate.CheckUtils;
import java.util.ArrayList;
import java.util.List;