Compare commits

...

6 Commits

Author SHA1 Message Date
63d9e80240 release: v1.5.0 2024-03-08 23:11:43 +08:00
98261b96da chore: 升级依赖
1.Spring Boot 3.1.8 => 3.1.9
2.Redisson 3.26.0 => 3.27.1
3.Crane4j 2.5.0 => 2.6.0(适配条件注解)
4.Hutool 5.8.25 => 5.8.26
5.CosId 2.6.5 => 2.6.6
6.AWS S3 1.12.651 => 1.12.675
7.IP2Region 3.1.7 => 3.1.9
8.ttl 2.14.4 => 2.14.5
2024-03-08 22:33:39 +08:00
a54294df6e chore(json/jackson): 优化 Jackson 默认配置 2024-03-06 22:05:45 +08:00
12bdf3e44a chore(extension/crud): 调整 BaseController checkPermission 方法的访问修饰符 private => protected 2024-03-06 21:57:46 +08:00
36ce07b600 refactor(data/mybatis-plus): 重构 IService 及 BaseService 体系结构 2024-02-21 21:58:35 +08:00
244a4db17c chore: 更新版本号为 1.5.0-SNAPSHOT 2024-02-21 20:53:36 +08:00
10 changed files with 118 additions and 92 deletions

View File

@@ -1,3 +1,22 @@
## [v1.5.0](https://github.com/Charles7c/continew-starter/compare/v1.4.1...v1.5.0) (2024-03-08)
### 💎 功能优化
- 【data/mybatis-plus】重构 IService 及 BaseService 体系结构 ([36ce07b](https://github.com/Charles7c/continew-starter/commit/36ce07b600fc54eeca3682d09aa5992cb2b35c17))
- 【json/jackson】优化 Jackson 默认配置 ([a54294d](https://github.com/Charles7c/continew-starter/commit/a54294df6e24dc36d36cf6a94559af2ed4c32d44))
- 【extension/crud】调整 BaseController checkPermission 方法的访问修饰符 private => protected ([12bdf3e](https://github.com/Charles7c/continew-starter/commit/12bdf3e44a10e9683b8605642eac9c463c590af4))
### 📦 依赖升级
- 【dependencies】Spring Boot 3.1.8 => 3.1.9 ([98261b9](https://github.com/Charles7c/continew-starter/commit/98261b96dacdba9d210790112248d798e292ae0b))
- 【dependencies】Redisson 3.26.0 => 3.27.1 ([98261b9](https://github.com/Charles7c/continew-starter/commit/98261b96dacdba9d210790112248d798e292ae0b))
- 【dependencies】Crane4j 2.5.0 => 2.6.0 ([98261b9](https://github.com/Charles7c/continew-starter/commit/98261b96dacdba9d210790112248d798e292ae0b))
- 【dependencies】Hutool 5.8.25 => 5.8.26 ([98261b9](https://github.com/Charles7c/continew-starter/commit/98261b96dacdba9d210790112248d798e292ae0b))
- 【dependencies】CosId 2.6.5 => 2.6.6 ([98261b9](https://github.com/Charles7c/continew-starter/commit/98261b96dacdba9d210790112248d798e292ae0b))
- 【dependencies】Amazon S3 1.12.651 => 1.12.675 ([98261b9](https://github.com/Charles7c/continew-starter/commit/98261b96dacdba9d210790112248d798e292ae0b))
- 【dependencies】Ip2region 3.1.7 => 3.1.9 ([98261b9](https://github.com/Charles7c/continew-starter/commit/98261b96dacdba9d210790112248d798e292ae0b))
- 【dependencies】TTL 2.14.4 => 2.14.5 ([98261b9](https://github.com/Charles7c/continew-starter/commit/98261b96dacdba9d210790112248d798e292ae0b))
## [v1.4.1](https://github.com/Charles7c/continew-starter/compare/v1.4.0...v1.4.1) (2024-02-21)
### ✨ 新特性

View File

@@ -7,7 +7,7 @@
<img src="https://img.shields.io/maven-central/v/top.charles7c.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-v1.4.1-%23ff3f59.svg" alt="Release" />
<img src="https://img.shields.io/badge/RELEASE-v1.5.0-%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

@@ -14,9 +14,7 @@
* limitations under the License.
*/
package top.charles7c.continew.starter.data.core.service;
import java.io.Serializable;
package top.charles7c.continew.starter.data.mybatis.plus.service;
/**
* 通用业务接口
@@ -25,13 +23,5 @@ import java.io.Serializable;
* @author Charles7c
* @since 1.2.0
*/
public interface IService<T> {
/**
* 根据 ID 查询
*
* @param id ID
* @return 实体信息
*/
T getById(Serializable id);
public interface IService<T> extends com.baomidou.mybatisplus.extension.service.IService<T> {
}

View File

@@ -0,0 +1,60 @@
/*
* 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.data.mybatis.plus.service.impl;
import cn.hutool.core.util.ClassUtil;
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.base.BaseMapper;
import top.charles7c.continew.starter.data.mybatis.plus.service.IService;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.List;
/**
* 通用业务实现类
*
* @param <M> Mapper 接口
* @param <T> 实体类型
* @author Charles7c
* @since 1.5.0
*/
public class ServiceImpl<M extends BaseMapper<T>, T> extends com.baomidou.mybatisplus.extension.service.impl.ServiceImpl<M, T> implements IService<T> {
protected final List<Field> entityFields = ReflectUtils.getNonStaticFields(this.entityClass);
@Override
public T getById(Serializable id) {
return this.getById(id, true);
}
/**
* 根据 ID 查询
*
* @param id ID
* @param isCheckExists 是否检查存在
* @return 实体信息
*/
protected T getById(Serializable id, boolean isCheckExists) {
T entity = baseMapper.selectById(id);
if (isCheckExists) {
CheckUtils.throwIfNotExists(entity, ClassUtil.getClassName(entityClass, true), "ID", id);
}
return entity;
}
}

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>3.1.8</version>
<version>3.1.9</version>
<relativePath/>
</parent>
@@ -53,28 +53,28 @@
<properties>
<!-- 项目版本号 -->
<revision>1.4.1</revision>
<revision>1.5.0</revision>
<sa-token.version>1.37.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.26.0</redisson.version>
<cosid.version>2.6.5</cosid.version>
<redisson.version>3.27.1</redisson.version>
<cosid.version>2.6.6</cosid.version>
<sms4j.version>3.1.1</sms4j.version>
<aj-captcha.version>1.3.0</aj-captcha.version>
<easy-captcha.version>1.6.2</easy-captcha.version>
<easy-excel.version>3.3.3</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.651</aws-s3.version>
<crane4j.version>2.5.0</crane4j.version>
<aws-s3.version>1.12.675</aws-s3.version>
<crane4j.version>2.6.0</crane4j.version>
<knife4j.version>4.5.0</knife4j.version>
<tlog.version>1.5.1</tlog.version>
<ttl.version>2.14.4</ttl.version>
<ip2region.version>3.1.7</ip2region.version>
<hutool.version>5.8.25</hutool.version>
<ttl.version>2.14.5</ttl.version>
<ip2region.version>3.1.9</ip2region.version>
<hutool.version>5.8.26</hutool.version>
<!-- Maven Plugin Versions -->
<flatten.version>1.6.0</flatten.version>
<spotless.version>2.43.0</spotless.version>

View File

@@ -181,7 +181,7 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q,
*
* @param api API 类型
*/
private void checkPermission(Api api) {
protected void checkPermission(Api api) {
CrudRequestMapping crudRequestMapping = this.getClass().getDeclaredAnnotation(CrudRequestMapping.class);
String path = crudRequestMapping.value();
String permissionPrefix = String.join(StringConstants.COLON, CharSequenceUtil

View File

@@ -18,6 +18,7 @@ package top.charles7c.continew.starter.extension.crud.model.resp;
import cn.crane4j.annotation.Assemble;
import cn.crane4j.annotation.Mapping;
import cn.crane4j.annotation.condition.ConditionOnPropertyNotNull;
import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
@@ -41,6 +42,7 @@ public class BaseDetailResp extends BaseResp {
* 修改人
*/
@JsonIgnore
@ConditionOnPropertyNotNull
@Assemble(container = ContainerPool.USER_NICKNAME, props = @Mapping(ref = "updateUserString"))
private Long updateUser;

View File

@@ -65,15 +65,6 @@ public interface BaseService<L, D, Q, C extends BaseReq> {
*/
List<L> list(Q query, SortQuery sortQuery);
/**
* 查询列表
*
* @return 列表信息
*/
default List<L> list() {
return list(null, null);
}
/**
* 查看详情
*

View File

@@ -23,27 +23,24 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Opt;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNodeConfig;
import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import jakarta.servlet.http.HttpServletResponse;
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.constant.StringConstants;
import top.charles7c.continew.starter.core.util.ClassUtils;
import top.charles7c.continew.starter.core.util.ReflectUtils;
import top.charles7c.continew.starter.core.util.validate.CheckUtils;
import top.charles7c.continew.starter.core.util.validate.ValidationUtils;
import top.charles7c.continew.starter.data.mybatis.plus.base.BaseMapper;
import top.charles7c.continew.starter.data.mybatis.plus.query.QueryWrapperHelper;
import top.charles7c.continew.starter.data.mybatis.plus.service.impl.ServiceImpl;
import top.charles7c.continew.starter.extension.crud.annotation.TreeField;
import top.charles7c.continew.starter.extension.crud.model.entity.BaseDO;
import top.charles7c.continew.starter.extension.crud.model.req.BaseReq;
import top.charles7c.continew.starter.data.core.service.IService;
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.PageResp;
@@ -51,7 +48,6 @@ import top.charles7c.continew.starter.extension.crud.service.BaseService;
import top.charles7c.continew.starter.extension.crud.util.TreeUtils;
import top.charles7c.continew.starter.file.excel.util.ExcelUtils;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
@@ -69,17 +65,12 @@ 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> implements BaseService<L, D, Q, C>, IService<T> {
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> {
@Autowired
protected M baseMapper;
private final Class<?>[] typeArguments = ClassUtils.getTypeArguments(this.getClass());
protected final Class<T> entityClass = this.currentEntityClass();
private final Class<?>[] typeArgumentCache = ClassUtils.getTypeArguments(this.getClass());
protected final Class<L> listClass = this.currentListClass();
protected final Class<D> detailClass = this.currentDetailClass();
protected final Class<Q> queryClass = this.currentQueryClass();
private final List<Field> entityFields = ReflectUtils.getNonStaticFields(this.entityClass);
private final List<Field> queryFields = ReflectUtils.getNonStaticFields(this.queryClass);
@Override
@@ -128,28 +119,9 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
return list;
}
/**
* 查询列表
*
* @param query 查询条件
* @param sortQuery 排序查询条件
* @param targetClass 指定类型
* @return 列表信息
*/
protected <E> List<E> list(Q query, SortQuery sortQuery, Class<E> targetClass) {
QueryWrapper<T> queryWrapper = this.handleQueryWrapper(query);
// 设置排序
this.sort(queryWrapper, sortQuery);
List<T> entityList = baseMapper.selectList(queryWrapper);
if (entityClass == targetClass) {
return (List<E>)entityList;
}
return BeanUtil.copyToList(entityList, targetClass);
}
@Override
public D get(Long id) {
T entity = this.getById(id, false);
T entity = super.getById(id, false);
D detail = BeanUtil.toBean(entity, detailClass);
this.fill(detail);
return detail;
@@ -190,24 +162,23 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
ExcelUtils.export(list, "导出数据", detailClass, response);
}
@Override
public T getById(Serializable id) {
return this.getById(id, true);
}
/**
* 根据 ID 查询
* 查询列表
*
* @param id ID
* @param isCheckExists 是否检查存在
* @return 实体信息
* @param query 查询条件
* @param sortQuery 排序查询条件
* @param targetClass 指定类型
* @return 列表信息
*/
protected T getById(Serializable id, boolean isCheckExists) {
T entity = baseMapper.selectById(id);
if (isCheckExists) {
CheckUtils.throwIfNotExists(entity, ClassUtil.getClassName(entityClass, true), "ID", id);
protected <E> List<E> list(Q query, SortQuery sortQuery, Class<E> targetClass) {
QueryWrapper<T> queryWrapper = this.handleQueryWrapper(query);
// 设置排序
this.sort(queryWrapper, sortQuery);
List<T> entityList = baseMapper.selectList(queryWrapper);
if (entityClass == targetClass) {
return (List<E>)entityList;
}
return entity;
return BeanUtil.copyToList(entityList, targetClass);
}
/**
@@ -318,22 +289,13 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
/* 删除后置处理 */
}
/**
* 获取当前实体类型
*
* @return 当前实体类型
*/
protected Class<T> currentEntityClass() {
return (Class<T>)this.typeArguments[1];
}
/**
* 获取当前列表信息类型
*
* @return 当前列表信息类型
*/
protected Class<L> currentListClass() {
return (Class<L>)this.typeArguments[2];
return (Class<L>)this.typeArgumentCache[2];
}
/**
@@ -342,7 +304,7 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
* @return 当前详情信息类型
*/
protected Class<D> currentDetailClass() {
return (Class<D>)this.typeArguments[3];
return (Class<D>)this.typeArgumentCache[3];
}
/**
@@ -351,6 +313,6 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
* @return 当前查询条件类型
*/
protected Class<Q> currentQueryClass() {
return (Class<Q>)this.typeArguments[4];
return (Class<Q>)this.typeArgumentCache[4];
}
}

View File

@@ -13,9 +13,11 @@ spring:
date-format: yyyy-MM-dd HH:mm:ss
# 序列化配置Bean -> JSON
serialization:
# 不允许序列化日期时以 timestamps 输出默认true
write-dates-as-timestamps: false
# 允许序列化无属性的 Bean
FAIL_ON_EMPTY_BEANS: false
fail-on-empty-beans: false
# 反序列化配置JSON -> Bean
deserialization:
# 允许反序列化不存在的属性
FAIL_ON_UNKNOWN_PROPERTIES: false
fail-on-unknown-properties: false