Merge branch '1.0.x' into dev

# Conflicts:
#	README.md
#	continew-starter-dependencies/pom.xml
This commit is contained in:
2023-12-14 00:16:58 +08:00
17 changed files with 167 additions and 40 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

@@ -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>
## 模块结构
| 模块名称 | 模块说明 | 依赖版本 |

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

@@ -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;