Compare commits

..

8 Commits

Author SHA1 Message Date
e3de3b6721 release: v2.0.1 2024-05-13 22:51:54 +08:00
5b76534df7 feat(extension/crud): 新增多种实体 Base 模型降低 BaseService 耦合 2024-05-13 22:30:40 +08:00
57eef274a3 refactor(web): 优化部分方法使用 2024-05-13 22:07:18 +08:00
f138e5cd45 fix(extension/crud): 修复查询树列表方法中的错误判断 2024-05-13 22:06:57 +08:00
ca6c7098b1 feat(core): 新增字符串工具类 2024-05-13 21:58:13 +08:00
596605b27b feat(cache/redisson): RedisUtils 新增递增、递减方法 2024-05-13 21:57:42 +08:00
b5dd5c7f18 chore: 升级依赖
SaToken 1.37.0 => 1.38.0
Redisson 3.28.0 => 3.30.0
Crane4j 2.7.0 => 2.8.0
AWS S3 1.12.702 => 1.12.720
IP2Region 3.1.10 => 3.1.11
2024-05-13 21:56:14 +08:00
macroju
cde9b01fc1 chore: 升级依赖修复安全漏洞 (#2) 2024-05-06 20:31:19 +08:00
14 changed files with 349 additions and 48 deletions

View File

@@ -1,3 +1,28 @@
## [v2.0.1](https://github.com/Charles7c/continew-starter/compare/v2.0.0...v2.0.1) (2024-05-13)
### ✨ 新特性
- 【cache/redisson】RedisUtils 新增递增、递减方法 ([596605b](https://github.com/Charles7c/continew-starter/commit/596605b27b046fa0488b113b1c3d87c60277e4ec))
- 【core】新增字符串工具类 ([ca6c709](https://github.com/Charles7c/continew-starter/commit/ca6c7098b124c3121fe626811ea61d53c80a9a4e))
- 【extension/crud】新增多种实体 Base 模型降低 BaseService 耦合 ([5b76534](https://github.com/Charles7c/continew-starter/commit/5b76534df7a54aa6d696515cfbf8059fcdc4a067))
### 🐛 问题修复
- 【extension/crud】修复查询树列表方法中的错误判断 ([f138e5c](https://github.com/Charles7c/continew-starter/commit/f138e5cd4526d8be0fe5e7ae54833b4541748346))
### 💎 功能优化
- 【web】优化部分方法使用 ([57eef27](https://github.com/Charles7c/continew-starter/commit/57eef274a3e34e8bb4de6073452080b2bbdbee53))
### 📦 依赖升级
- 【dependencies】Spring Boot 3.1.10 => 3.1.11 ([GitHub#2](https://github.com/Charles7c/continew-starter/pull/2))
- 【dependencies】SaToken 1.37.0 => 1.38.0 ([b5dd5c7](https://github.com/Charles7c/continew-starter/commit/b5dd5c7f18603b5bd5a509c04ef410c1d64bc2e9))
- 【dependencies】Redisson 3.28.0 => 3.30.0 ([b5dd5c7](https://github.com/Charles7c/continew-starter/commit/b5dd5c7f18603b5bd5a509c04ef410c1d64bc2e9))
- 【dependencies】Crane4j 2.7.0 => 2.8.0 ([b5dd5c7](https://github.com/Charles7c/continew-starter/commit/b5dd5c7f18603b5bd5a509c04ef410c1d64bc2e9))
- 【dependencies】AWS S3 1.12.702 => 1.12.720 ([b5dd5c7](https://github.com/Charles7c/continew-starter/commit/b5dd5c7f18603b5bd5a509c04ef410c1d64bc2e9))
- 【dependencies】IP2Region 3.1.10 => 3.1.11 ([b5dd5c7](https://github.com/Charles7c/continew-starter/commit/b5dd5c7f18603b5bd5a509c04ef410c1d64bc2e9))
## [v2.0.0](https://github.com/Charles7c/continew-starter/compare/v1.5.1...v2.0.0) (2024-04-17)
### ✨ 新特性

View File

@@ -7,7 +7,7 @@
<img src="https://img.shields.io/maven-central/v/top.continew/continew-starter.svg?label=Maven%20Central&logo=sonatype&logoColor=FFF" alt="Release" />
</a>
<a href="https://github.com/Charles7c/continew-starter" target="_blank">
<img src="https://img.shields.io/badge/RELEASE-v2.0.0-%23ff3f59.svg" alt="Release" />
<img src="https://img.shields.io/badge/RELEASE-v2.0.1-%23ff3f59.svg" alt="Release" />
</a>
<a href="https://app.codacy.com/gh/Charles7c/continew-starter/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade" target="_blank">
<img src="https://app.codacy.com/project/badge/Grade/90ed633957a9410aa8745f0654827c01" alt="Codacy Badge" />

View File

@@ -74,6 +74,6 @@ public class JustAuthStateCacheRedisImpl implements AuthStateCache {
*/
@Override
public boolean containsKey(String key) {
return RedisUtils.hasKey(RedisUtils.formatKey(KEY_PREFIX, key));
return RedisUtils.exists(RedisUtils.formatKey(KEY_PREFIX, key));
}
}

View File

@@ -22,7 +22,6 @@ import top.continew.starter.core.constant.StringConstants;
import java.time.Duration;
import java.util.Collection;
import java.util.stream.Stream;
/**
* Redis 工具类
@@ -92,6 +91,28 @@ public class RedisUtils {
CLIENT.getKeys().deleteByPattern(pattern);
}
/**
* 递增 1
*
* @param key 键
* @return 当前值
* @since 2.0.1
*/
public static long incr(String key) {
return CLIENT.getAtomicLong(key).incrementAndGet();
}
/**
* 递减 1
*
* @param key 键
* @return 当前值
* @since 2.0.1
*/
public static long decr(String key) {
return CLIENT.getAtomicLong(key).decrementAndGet();
}
/**
* 设置缓存过期时间
*
@@ -130,9 +151,8 @@ public class RedisUtils {
* @param key 键
* @return true存在false不存在
*/
public static boolean hasKey(String key) {
RKeys keys = CLIENT.getKeys();
return keys.countExists(key) > 0;
public static boolean exists(String key) {
return CLIENT.getKeys().countExists(key) > 0;
}
/**
@@ -142,8 +162,7 @@ public class RedisUtils {
* @return 缓存列表
*/
public static Collection<String> keys(String pattern) {
Stream<String> stream = CLIENT.getKeys().getKeysStreamByPattern(pattern);
return stream.toList();
return CLIENT.getKeys().getKeysStreamByPattern(pattern).toList();
}
/**

View File

@@ -36,7 +36,7 @@ public class BehaviorCaptchaCacheServiceImpl implements CaptchaCacheService {
@Override
public boolean exists(String key) {
return RedisUtils.hasKey(key);
return RedisUtils.exists(key);
}
@Override

View File

@@ -0,0 +1,46 @@
/*
* 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.continew.starter.core.util;
import cn.hutool.core.text.CharSequenceUtil;
import java.util.function.Function;
/**
* 字符串工具类
*
* @author Charles7c
* @since 2.0.1
*/
public class StrUtils {
private StrUtils() {
}
/**
* 如果字符串是{@code null}或者&quot;&quot;或者空白,则返回指定默认字符串,否则针对字符串处理后返回
*
* @param str 要转换的字符串
* @param defaultValue 默认值
* @param mapping 针对字符串的转换方法
* @return 转换后的字符串或指定的默认字符串
* @since 2.0.1
*/
public static <T> T blankToDefault(CharSequence str, T defaultValue, Function<String, T> mapping) {
return CharSequenceUtil.isBlank(str) ? defaultValue : mapping.apply(str.toString());
}
}

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>3.1.10</version>
<version>3.1.11</version>
<relativePath/>
</parent>
@@ -19,7 +19,7 @@
<licenses>
<license>
<name>GNU LESSER GENERAL PUBLIC LICENSE</name>
<url>http://www.gnu.org/licenses/lgpl.html</url>
<url>https://www.gnu.org/licenses/lgpl.html</url>
</license>
</licenses>
<developers>
@@ -43,14 +43,14 @@
<properties>
<!-- 项目版本号 -->
<revision>2.0.0</revision>
<sa-token.version>1.37.0</sa-token.version>
<revision>2.0.1</revision>
<sa-token.version>1.38.0</sa-token.version>
<just-auth.version>1.16.6</just-auth.version>
<mybatis-plus.version>3.5.5</mybatis-plus.version>
<dynamic-datasource.version>4.3.0</dynamic-datasource.version>
<p6spy.version>3.9.1</p6spy.version>
<jetcache.version>2.7.5</jetcache.version>
<redisson.version>3.28.0</redisson.version>
<redisson.version>3.30.0</redisson.version>
<cosid.version>2.6.8</cosid.version>
<sms4j.version>3.2.1</sms4j.version>
<aj-captcha.version>1.3.0</aj-captcha.version>
@@ -58,12 +58,17 @@
<easy-excel.version>3.3.4</easy-excel.version>
<nashorn.version>15.4</nashorn.version>
<x-file-storage.version>2.1.0</x-file-storage.version>
<aws-s3.version>1.12.702</aws-s3.version>
<crane4j.version>2.7.0</crane4j.version>
<aws-s3.version>1.12.720</aws-s3.version>
<crane4j.version>2.8.0</crane4j.version>
<knife4j.version>4.5.0</knife4j.version>
<tlog.version>1.5.2</tlog.version>
<ql-express.version>3.3.2</ql-express.version>
<snakeyaml.version>2.2</snakeyaml.version>
<okhttp.version>4.12.0</okhttp.version>
<plexus.version>4.0.0</plexus.version>
<commons-compress.version>1.26.1</commons-compress.version>
<ttl.version>2.14.5</ttl.version>
<ip2region.version>3.1.10</ip2region.version>
<ip2region.version>3.1.11</ip2region.version>
<hutool.version>5.8.27</hutool.version>
<!-- Maven Plugin Versions -->
<flatten.version>1.6.0</flatten.version>
@@ -254,6 +259,41 @@
<version>${tlog.version}</version>
</dependency>
<!-- QLExpress一种强大的、轻量级的、动态的 Java 平台语言,旨在提高开发人员在不同业务场景中的生产力) -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>QLExpress</artifactId>
<version>${ql-express.version}</version>
</dependency>
<!-- SnakeYAML适用于 Java 的 YAML 1.1 解析器和发射器) -->
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>${snakeyaml.version}</version>
</dependency>
<!-- Plexus Utils各种实用程序类的集合可轻松处理字符串、文件、命令行等 -->
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>${plexus.version}</version>
</dependency>
<!-- OkHTTP一个默认高效的 HTTP 客户端) -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>${okhttp.version}</version>
</dependency>
<!-- Apache Commons Compress一套用于处理压缩和存档格式的 API -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>${commons-compress.version}</version>
</dependency>
<!-- TTL线程间传递 ThreadLocal异步执行时上下文传递的解决方案 -->
<dependency>
<groupId>com.alibaba</groupId>
@@ -436,6 +476,7 @@
<artifactId>continew-starter-core</artifactId>
<version>${revision}</version>
</dependency>
</dependencies>
</dependencyManagement>

View File

@@ -0,0 +1,67 @@
/*
* 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.continew.starter.extension.crud.model.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import java.io.Serial;
import java.time.LocalDateTime;
/**
* 实体类基类
*
* <p>
* 通用字段:创建人、创建时间
* </p>
*
* @author Charles7c
* @since 2.0.1
*/
public class BaseCreateDO extends BaseIdDO {
@Serial
private static final long serialVersionUID = 1L;
/**
* 创建人
*/
@TableField(fill = FieldFill.INSERT)
private Long createUser;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
public Long getCreateUser() {
return createUser;
}
public void setCreateUser(Long createUser) {
this.createUser = createUser;
}
public LocalDateTime getCreateTime() {
return createTime;
}
public void setCreateTime(LocalDateTime createTime) {
this.createTime = createTime;
}
}

View File

@@ -18,10 +18,8 @@ package top.continew.starter.extension.crud.model.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
@@ -30,17 +28,11 @@ import java.time.LocalDateTime;
* @author Charles7c
* @since 1.0.0
*/
public class BaseDO implements Serializable {
public class BaseDO extends BaseIdDO {
@Serial
private static final long serialVersionUID = 1L;
/**
* ID
*/
@TableId
private Long id;
/**
* 创建人
*/
@@ -65,14 +57,6 @@ public class BaseDO implements Serializable {
@TableField(fill = FieldFill.UPDATE)
private LocalDateTime updateTime;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getCreateUser() {
return createUser;
}

View File

@@ -0,0 +1,52 @@
/*
* 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.continew.starter.extension.crud.model.entity;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serial;
import java.io.Serializable;
/**
* 实体类基类
*
* <p>
* 通用字段ID 主键
* </p>
*
* @author Charles7c
* @since 2.0.1
*/
public class BaseIdDO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* ID
*/
@TableId
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}

View File

@@ -0,0 +1,67 @@
/*
* 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.continew.starter.extension.crud.model.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import java.io.Serial;
import java.time.LocalDateTime;
/**
* 实体类基类
*
* <p>
* 通用字段:创建人、创建时间
* </p>
*
* @author Charles7c
* @since 2.0.1
*/
public class BaseUpdateDO extends BaseIdDO {
@Serial
private static final long serialVersionUID = 1L;
/**
* 修改人
*/
@TableField(fill = FieldFill.UPDATE)
private Long updateUser;
/**
* 修改时间
*/
@TableField(fill = FieldFill.UPDATE)
private LocalDateTime updateTime;
public Long getUpdateUser() {
return updateUser;
}
public void setUpdateUser(Long updateUser) {
this.updateUser = updateUser;
}
public LocalDateTime getUpdateTime() {
return updateTime;
}
public void setUpdateTime(LocalDateTime updateTime) {
this.updateTime = updateTime;
}
}

View File

@@ -18,7 +18,6 @@ package top.continew.starter.extension.crud.service;
import cn.hutool.core.lang.tree.Tree;
import jakarta.servlet.http.HttpServletResponse;
import top.continew.starter.extension.crud.model.req.BaseReq;
import top.continew.starter.extension.crud.model.query.PageQuery;
import top.continew.starter.extension.crud.model.query.SortQuery;
import top.continew.starter.extension.crud.model.resp.PageResp;
@@ -35,7 +34,7 @@ import java.util.List;
* @author Charles7c
* @since 1.0.0
*/
public interface BaseService<L, D, Q, C extends BaseReq> {
public interface BaseService<L, D, Q, C> {
/**
* 分页查询列表

View File

@@ -39,8 +39,7 @@ import top.continew.starter.data.mybatis.plus.base.BaseMapper;
import top.continew.starter.data.mybatis.plus.query.QueryWrapperHelper;
import top.continew.starter.data.mybatis.plus.service.impl.ServiceImpl;
import top.continew.starter.extension.crud.annotation.TreeField;
import top.continew.starter.extension.crud.model.entity.BaseDO;
import top.continew.starter.extension.crud.model.req.BaseReq;
import top.continew.starter.extension.crud.model.entity.BaseIdDO;
import top.continew.starter.extension.crud.model.query.PageQuery;
import top.continew.starter.extension.crud.model.query.SortQuery;
import top.continew.starter.extension.crud.model.resp.PageResp;
@@ -65,7 +64,7 @@ import java.util.Optional;
* @author Charles7c
* @since 1.0.0
*/
public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO, L, D, Q, C extends BaseReq> extends ServiceImpl<M, T> implements BaseService<L, D, Q, C> {
public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseIdDO, L, D, Q, C> extends ServiceImpl<M, T> implements BaseService<L, D, Q, C> {
private final Class<?>[] typeArgumentCache = ClassUtils.getTypeArguments(this.getClass());
protected final Class<L> listClass = this.currentListClass();
@@ -75,7 +74,7 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
@Override
public PageResp<L> page(Q query, PageQuery pageQuery) {
QueryWrapper<T> queryWrapper = this.handleQueryWrapper(query);
QueryWrapper<T> queryWrapper = this.buildQueryWrapper(query);
IPage<T> page = baseMapper.selectPage(pageQuery.toPage(), queryWrapper);
PageResp<L> pageResp = PageResp.build(page, listClass);
pageResp.getList().forEach(this::fill);
@@ -104,7 +103,7 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
tree.setWeight(ReflectUtil.invoke(node, CharSequenceUtil.genGetter(treeField.weightKey())));
if (!isSimple) {
List<Field> fieldList = ReflectUtils.getNonStaticFields(listClass);
fieldList.removeIf(f -> CharSequenceUtil.containsAnyIgnoreCase(f.getName(), treeField.value(), treeField
fieldList.removeIf(f -> CharSequenceUtil.equalsAnyIgnoreCase(f.getName(), treeField.value(), treeField
.parentIdKey(), treeField.nameKey(), treeField.weightKey(), treeField.childrenKey()));
fieldList.forEach(f -> tree.putExtra(f.getName(), ReflectUtil.invoke(node, CharSequenceUtil.genGetter(f
.getName()))));
@@ -171,7 +170,7 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
* @return 列表信息
*/
protected <E> List<E> list(Q query, SortQuery sortQuery, Class<E> targetClass) {
QueryWrapper<T> queryWrapper = this.handleQueryWrapper(query);
QueryWrapper<T> queryWrapper = this.buildQueryWrapper(query);
// 设置排序
this.sort(queryWrapper, sortQuery);
List<T> entityList = baseMapper.selectList(queryWrapper);
@@ -222,11 +221,12 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
}
/**
* 处理查询条件
* 构建 QueryWrapper
*
* @param query 查询条件
* @return QueryWrapper
*/
protected QueryWrapper<T> handleQueryWrapper(Q query) {
protected QueryWrapper<T> buildQueryWrapper(Q query) {
QueryWrapper<T> queryWrapper = new QueryWrapper<>();
// 解析并拼接查询条件
return QueryWrapperHelper.build(query, queryFields, queryWrapper);

View File

@@ -18,6 +18,7 @@ package top.continew.starter.web.autoconfigure.xss;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.*;
import cn.hutool.http.HtmlUtil;
import cn.hutool.http.Method;
@@ -49,10 +50,10 @@ public class XssServletRequestWrapper extends HttpServletRequestWrapper {
public XssServletRequestWrapper(HttpServletRequest request, XssProperties xssProperties) throws IOException {
super(request);
this.xssProperties = xssProperties;
if (StrUtil.containsAny(request.getMethod().toUpperCase(), Method.POST.name(), Method.PATCH.name(), Method.PUT
.name())) {
if (CharSequenceUtil.equalsAnyIgnoreCase(request.getMethod().toUpperCase(), Method.POST.name(), Method.PATCH
.name(), Method.PUT.name())) {
body = IoUtil.getReader(request.getReader()).readLine();
if (StrUtil.isEmpty(body)) {
if (CharSequenceUtil.isBlank(body)) {
return;
}
body = this.handleTag(body);
@@ -100,7 +101,7 @@ public class XssServletRequestWrapper extends HttpServletRequestWrapper {
* @return 返回处理过后内容
*/
private String handleTag(String content) {
if (StrUtil.isEmpty(content)) {
if (CharSequenceUtil.isBlank(content)) {
return content;
}
XssMode mode = xssProperties.getMode();