Skip to content

Commit

Permalink
1.依赖升级
Browse files Browse the repository at this point in the history
    spring.boot.version -> 2.2.7.RELEASE
    spring.cloud.version -> Hoxton.SR3
    dynamic.datasource.version -> 3.1.0
    mybatis.version -> 3.5.4
    mybatis-spring.version -> 2.0.4
    mybatisplus.version -> 3.3.2
    p6spy.version -> 3.9.0
    fastjson.version -> 1.2.72  (修复安全漏洞)
    druid.version -> 1.1.22   (修复编译时,IDEA的警告)
    knife4j.version -> 2.0.4
    swagger.version -> 1.5.22
    hutool.version -> 5.3.9
    jjwt.version -> 0.11.1

### zuihou-gateway-server
1. 优化gateway网关的熔断配置
2. AccessFilter为TokenContextFilter

### zuihou-injection-starter
1. 修改 InjectionFieldPo 和 InjectionField 类的 feign 字段为 apiClass,使得字段命名更加合理
2. InjectionField注解类新增dictType属性,解决字典类型数据注入bug
3. 修复自动注入器注入字典类型的数据时,无法区分不同字典类型的值

### zuihou-validator-starter
1. 修复表单统一验证模块不支持Restful风格 + BaseController接口的验证规则获取bug
2. com.github.zuihou.validator.config.EnableFormValidator 注解移动到 com.github.zuihou.validator.annotation.EnableFormValidator

### zuihou-databases
1. 优化SCHEMA模式全局拦截器代码功能和可读性
2. 优化非DATASOURCE模式数据源配置
3. 优化分页插件每次查询最大500条的限制
4. PageParams类的 getPage() 方法修改成 buildPage(),并支持多字段排序
5. 删除 MultiTenantInterceptor ,新增 ReplaceSql
6. 新增MasterDatabaseConfiguration, 优化NONE、SCHEMA、COLUMN模式的数据源配置和事务配置
7. 修复NONE、SCHEMA、COLUMN模式事务失效的bug

### zuihou-core
1. 新增JsonUtil工具类(jackson)

### zuihou-boot
1. 优化枚举字段反序列化全局配置类:EnumDeserializer, 提高可读性和性能
2. 新增枚举类型字段的全局序列化配置类:EnumSerializer, 实现了BaseEnum接口的枚举按照规范序列化
3. 优化 BaseConfig 类中全局的 ObjectMapper 配置
3. 优化LocalDateTime类型参数的Jackson反序列化规则
4. 优化LocalDateTime、Date、LocalDate、LocalTime等日期类型表单参数传递时的转换规则
5. 全局统一异常的状态码修改为400
6. 优化PageController类handlerWrapper方法的逻辑

### zuihou-cloud-starter
1. 优化服务远程调用时,请求头和线程变量的传递
2. 新增全局的支持负载均衡策略、请求头和LocalThread参数传递的LbRestTemplate
3. 新增全局的熔断回调, @FeignClient 注解无需单独配置 fallback 和 fallbackFactory 即可实现回调

### zuihou-swagger2-starter
1. 使得通过 zuihou.swaggger.enabled 可以全局禁用swagger功能
2. 优化SwaggerProperties类的配置和默认值

### zuihou-log-starter
1. 为了减少zuihou-log-starter模块体积,将ip2region.db移动到oauth服务。
2. 修复操作日志根据参数控制是否记录请求参数的bug
  • Loading branch information
zuihou committed Jul 13, 2020
1 parent e8ce2b1 commit 1e34e4c
Show file tree
Hide file tree
Showing 131 changed files with 2,530 additions and 1,832 deletions.
7 changes: 3 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.zuihou</groupId>
<artifactId>zuihou-commons</artifactId>
<version>2.3</version>
<version>2.4</version>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
<description>zuihou项目公共模块</description>
Expand All @@ -27,7 +27,6 @@
<module>zuihou-cache-starter</module>
<module>zuihou-mq-starter</module>
<module>zuihou-zipkin-client-starter</module>
<module>zuihou-scan-starter</module>
<module>zuihou-injection-starter</module>
</modules>
<properties>
Expand Down Expand Up @@ -55,7 +54,7 @@
<developer>
<id>zuihou</id>
<name>zuihou</name>
<email>244387066@qq.com</email>
<email>306479353@qq.com</email>
<roles>
<role>Java Development Engineer</role>
</roles>
Expand Down Expand Up @@ -84,7 +83,7 @@
<dependency>
<groupId>com.github.zuihou</groupId>
<artifactId>zuihou-dependencies</artifactId>
<version>2.3</version>
<version>2.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
19 changes: 17 additions & 2 deletions zuihou-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>zuihou-commons</artifactId>
<groupId>com.github.zuihou</groupId>
<version>2.3</version>
<version>2.4</version>
<relativePath>../</relativePath>
</parent>

Expand All @@ -20,6 +20,11 @@
<groupId>com.github.zuihou</groupId>
<artifactId>zuihou-core</artifactId>
</dependency>
<!-- @ApiIgnore 注解使用 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-core</artifactId>
</dependency>
<dependency>
<groupId>com.github.zuihou</groupId>
<artifactId>zuihou-databases</artifactId>
Expand Down Expand Up @@ -80,7 +85,17 @@
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>


<!-- jdk8 Time-->
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-parameter-names</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,18 @@
*/
public interface BaseController<Entity> {

/**
* 获取实体的类型
*
* @return
*/
Class<Entity> getEntityClass();

/**
* 获取Service
*
* @return
*/
SuperService<Entity> getBaseService();


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ default void query(PageParams<PageDTO> params, IPage<Entity> page, Long defSize)
page.setSize(defSize);
}
Entity model = BeanUtil.toBean(params.getModel(), getEntityClass());
QueryWrap<Entity> wrapper = Wraps.q(model);

handlerWrapper(wrapper, params);
QueryWrap<Entity> wrapper = handlerWrapper(model, params);
getBaseService().page(page, wrapper);

// 处理结果
Expand All @@ -82,10 +81,12 @@ default void query(PageParams<PageDTO> params, IPage<Entity> page, Long defSize)
/**
* 处理时间区间,可以覆盖后处理组装查询条件
*
* @param wrapper
* @param model
* @param params
*/
default void handlerWrapper(QueryWrap<Entity> wrapper, PageParams<PageDTO> params) {
default QueryWrap<Entity> handlerWrapper(Entity model, PageParams<PageDTO> params) {
QueryWrap<Entity> wrapper = model == null ? Wraps.q() : Wraps.q(model);

if (CollUtil.isNotEmpty(params.getMap())) {
Map<String, String> map = params.getMap();
//拼装区间
Expand All @@ -105,6 +106,7 @@ default void handlerWrapper(QueryWrap<Entity> wrapper, PageParams<PageDTO> param
}
}
}
return wrapper;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -52,7 +56,7 @@ public interface PoiController<Entity, PageDTO> extends PageController<Entity, P
@SysLog("'导出Excel:'.concat(#params.map[" + NormalExcelConstants.FILE_NAME + "]?:'')")
@PreAuth("hasPermit('{}export')")
default void exportExcel(@RequestBody @Validated PageParams<PageDTO> params, HttpServletRequest request, HttpServletResponse response) {
IPage<Entity> page = params.getPage();
IPage<Entity> page = params.buildPage();
ExportParams exportParams = getExportParams(params, page);

Map<String, Object> map = new HashMap<>(5);
Expand All @@ -75,7 +79,7 @@ default void exportExcel(@RequestBody @Validated PageParams<PageDTO> params, Htt
@RequestMapping(value = "/preview", method = RequestMethod.POST)
@PreAuth("hasPermit('{}export')")
default R<String> preview(@RequestBody @Validated PageParams<PageDTO> params) {
IPage<Entity> page = params.getPage();
IPage<Entity> page = params.buildPage();
ExportParams exportParams = getExportParams(params, page);

Workbook workbook = ExcelExportUtil.exportExcel(exportParams, getEntityClass(), page.getRecords());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ default R<Entity> get(@PathVariable Id id) {
@PreAuth("hasPermit('{}view')")
default R<IPage<Entity>> page(@RequestBody @Validated PageParams<PageDTO> params) {
// 处理参数
IPage<Entity> page = params.getPage();
IPage<Entity> page = params.buildPage();
query(params, page, null);
return success(page);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @author zuihou
* @date 2020年03月06日11:06:46
*/
public class SuperNoPoiController<S extends SuperService<Entity>, Id extends Serializable, Entity, PageDTO, SaveDTO, UpdateDTO> extends SuperSimpleController<S, Entity>
public abstract class SuperNoPoiController<S extends SuperService<Entity>, Id extends Serializable, Entity, PageDTO, SaveDTO, UpdateDTO> extends SuperSimpleController<S, Entity>
implements SaveController<Entity, SaveDTO>, UpdateController<Entity, UpdateDTO>, DeleteController<Entity, Id>, QueryController<Entity, Id, PageDTO> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@

/**
* 简单的实现了BaseController,为了获取注入 Service 和 实体类型
* <p>
* 基类该类后,没有任何方法。
* 可以让业务Controller继承 SuperSimpleController 后,按需实现 *Controller 接口
*
* @param <S> Service
* @param <Entity> 实体
* @author zuihou
* @date 2020年03月07日22:08:27
*/
public class SuperSimpleController<S extends SuperService<Entity>, Entity> implements BaseController<Entity> {
public abstract class SuperSimpleController<S extends SuperService<Entity>, Entity> implements BaseController<Entity> {

protected Class<Entity> entityClass = null;
@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.springframework.web.bind.annotation.RequestBody;

/**
* 修改
* 修改Controller
*
* @param <Entity> 实体
* @param <UpdateDTO> 修改参数
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.github.zuihou.base.entity.Entity;
import com.github.zuihou.base.entity.SuperEntity;
import com.github.zuihou.utils.AntiSqlFilter;
import com.github.zuihou.utils.StrPool;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
Expand Down Expand Up @@ -47,27 +48,46 @@ public class PageParams<T> {
@ApiModelProperty("扩展参数")
private Map<String, String> map = new HashMap<>(1);

/**
* 支持多个字段排序,用法:
* eg.1, 参数:{order:"name,id", order:"descending,ascending" }。 排序: name desc, id asc
* eg.2, 参数:{order:"name", order:"descending,ascending" }。 排序: name desc
* eg.3, 参数:{order:"name,id", order:"descending" }。 排序: name desc
*
* @return
*/
@JsonIgnore
public IPage getPage() {
public IPage buildPage() {
PageParams params = this;
//没有排序参数
if (StrUtil.isEmpty(params.getSort())) {
Page page = new Page(params.getCurrent(), params.getSize());
return page;
}

Page page = new Page(params.getCurrent(), params.getSize());

List<OrderItem> orders = new ArrayList<>();
// 简单的 驼峰 转 下划线
String sort = StrUtil.toUnderlineCase(params.getSort());
String[] sortArr = StrUtil.split(params.getSort(), StrPool.COMMA);
String[] orderArr = StrUtil.split(params.getOrder(), StrPool.COMMA);

int len = sortArr.length < orderArr.length ? sortArr.length : orderArr.length;
for (int i = 0; i < len; i++) {
String humpSort = sortArr[i];
// 简单的 驼峰 转 下划线
String underlineSort = StrUtil.toUnderlineCase(humpSort);

// 除了 create_time 和 updateTime 都过滤sql关键字
if (!StrUtil.equalsAny(humpSort, SuperEntity.CREATE_TIME, Entity.UPDATE_TIME)) {
underlineSort = AntiSqlFilter.getSafeValue(underlineSort);
}

// 除了 create_time 和 updateTime 都过滤sql关键字
if (!StrUtil.equalsAny(params.getSort(), SuperEntity.CREATE_TIME, Entity.UPDATE_TIME)) {
sort = AntiSqlFilter.getSafeValue(sort);
orders.add("ascending".equals(orderArr[i]) ? OrderItem.asc(underlineSort) : OrderItem.desc(underlineSort));
}

orders.add("ascending".equals(params.getOrder()) ? OrderItem.asc(sort) : OrderItem.desc(sort));
page.setOrders(orders);
return page;

return page;
}

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
package com.github.zuihou.base.service;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.enums.SqlMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.core.toolkit.ReflectionKit;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.github.zuihou.base.entity.SuperEntity;
import com.github.zuihou.base.mapper.SuperMapper;
import net.oschina.j2cache.CacheChannel;
import net.oschina.j2cache.CacheObject;
import org.apache.ibatis.binding.MapperMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.Collection;
import java.util.Objects;

/**
* 基于SpringCache + J2Cache 实现的 缓存实现
Expand Down Expand Up @@ -82,7 +91,6 @@ public boolean save(T model) {
return save;
}


@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateAllById(T model) {
Expand All @@ -105,4 +113,69 @@ public boolean updateById(T model) {
return updateBool;
}


// 以下方法还能优化成批量清理缓存和设置缓存-----------
@Override
@Transactional(rollbackFor = Exception.class)
public boolean saveBatch(Collection<T> entityList, int batchSize) {
String sqlStatement = sqlStatement(SqlMethod.INSERT_ONE);
return executeBatch(entityList, batchSize, (sqlSession, entity) -> {
sqlSession.insert(sqlStatement, entity);

// 设置缓存
if (entity instanceof SuperEntity) {
String key = key(((SuperEntity) entity).getId());
cacheChannel.set(getRegion(), key, entity);
}
});
}

@Transactional(rollbackFor = Exception.class)
@Override
public boolean saveOrUpdateBatch(Collection<T> entityList, int batchSize) {
TableInfo tableInfo = TableInfoHelper.getTableInfo(entityClass);
Assert.notNull(tableInfo, "error: can not execute. because can not find cache of TableInfo for entity!");
String keyProperty = tableInfo.getKeyProperty();
Assert.notEmpty(keyProperty, "error: can not execute. because can not find column for id from entity!");
return executeBatch(entityList, batchSize, (sqlSession, entity) -> {
Object idVal = ReflectionKit.getMethodValue(entityClass, entity, keyProperty);
if (StringUtils.checkValNull(idVal) || Objects.isNull(getById((Serializable) idVal))) {
sqlSession.insert(tableInfo.getSqlStatement(SqlMethod.INSERT_ONE.getMethod()), entity);

// 设置缓存
if (entity instanceof SuperEntity) {
String key = key(((SuperEntity) entity).getId());
cacheChannel.set(getRegion(), key, entity);
}
} else {
MapperMethod.ParamMap<T> param = new MapperMethod.ParamMap<>();
param.put(Constants.ENTITY, entity);
sqlSession.update(tableInfo.getSqlStatement(SqlMethod.UPDATE_BY_ID.getMethod()), param);

// 清理缓存
if (entity instanceof SuperEntity) {
String key = key(((SuperEntity) entity).getId());
cacheChannel.evict(getRegion(), key);
}
}
});
}

@Transactional(rollbackFor = Exception.class)
@Override
public boolean updateBatchById(Collection<T> entityList, int batchSize) {
String sqlStatement = sqlStatement(SqlMethod.UPDATE_BY_ID);
return executeBatch(entityList, batchSize, (sqlSession, entity) -> {
MapperMethod.ParamMap<T> param = new MapperMethod.ParamMap<>();
param.put(Constants.ENTITY, entity);
sqlSession.update(sqlStatement, param);

// 清理缓存
if (entity instanceof SuperEntity) {
String key = key(((SuperEntity) entity).getId());
cacheChannel.evict(getRegion(), key);
}
});
}

}
Loading

0 comments on commit 1e34e4c

Please sign in to comment.