feat: 添加 spring-boot-mybatis starter.
This commit is contained in:
@@ -75,6 +75,11 @@
|
||||
<artifactId>orion-ops-spring-boot-starter-datasource</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.orion.ops</groupId>
|
||||
<artifactId>orion-ops-spring-boot-starter-mybatis</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- spring -->
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.orion.ops.framework.common.constant;
|
||||
|
||||
/**
|
||||
* 常量
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/6/23 18:49
|
||||
*/
|
||||
public class Const extends com.orion.lang.constant.Const {
|
||||
|
||||
private Const() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.orion.ops.framework.common.enums;
|
||||
package com.orion.ops.framework.common.constant;
|
||||
|
||||
/**
|
||||
* 消息常量
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.orion.ops.framework.common.enums;
|
||||
package com.orion.ops.framework.common.constant;
|
||||
|
||||
/**
|
||||
* 过滤器排序常量
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.orion.ops.framework.common.enums;
|
||||
package com.orion.ops.framework.common.constant;
|
||||
|
||||
/**
|
||||
* 拦截器排序常量
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.orion.ops.framework.common.enums;
|
||||
package com.orion.ops.framework.common.constant;
|
||||
|
||||
/**
|
||||
* 项目常量
|
||||
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.orion.ops</groupId>
|
||||
<artifactId>orion-ops-framework</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>orion-ops-spring-boot-starter-mybatis</artifactId>
|
||||
<name>${project.artifactId}</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<description>项目 mybatis 配置包</description>
|
||||
<url>https://github.com/lijiahangmax/orion-ops-pro</url>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.orion.ops</groupId>
|
||||
<artifactId>orion-ops-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- datasource -->
|
||||
<dependency>
|
||||
<groupId>com.orion.ops</groupId>
|
||||
<artifactId>orion-ops-spring-boot-starter-datasource</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- mybatis -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.orion.ops.framework.mybatis.config;
|
||||
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import com.orion.ops.framework.mybatis.handler.FieldFillHandler;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
* mybatis 配置类
|
||||
* TODO 扫描的包
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/6/23 18:35
|
||||
*/
|
||||
@AutoConfiguration
|
||||
@MapperScan(value = "com.orion.ops.module.*.dao", lazyInitialization = "true")
|
||||
public class OrionMybatisAutoConfiguration {
|
||||
|
||||
/**
|
||||
* @return 字段填充元数据处理器
|
||||
*/
|
||||
@Bean
|
||||
public MetaObjectHandler defaultMetaObjectHandler() {
|
||||
return new FieldFillHandler();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.orion.ops.framework.mybatis.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import lombok.Data;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 公共实体对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/6/23 18:42
|
||||
*/
|
||||
@Data
|
||||
public class BaseDO implements Serializable {
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT, jdbcType = JdbcType.VARCHAR)
|
||||
private String creator;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE, jdbcType = JdbcType.VARCHAR)
|
||||
private String updater;
|
||||
|
||||
/**
|
||||
* 是否删除 1未删除 2已删除
|
||||
*
|
||||
* @see com.orion.lang.constant.Const#NOT_DELETED
|
||||
* @see com.orion.lang.constant.Const#IS_DELETED
|
||||
*/
|
||||
@TableLogic
|
||||
private Boolean deleted;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.orion.ops.framework.mybatis.handler;
|
||||
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import com.orion.ops.framework.mybatis.domain.BaseDO;
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 字段填充处理器
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/6/23 19:01
|
||||
*/
|
||||
public class FieldFillHandler implements MetaObjectHandler {
|
||||
|
||||
@Override
|
||||
public void insertFill(MetaObject metaObject) {
|
||||
if (Objects.nonNull(metaObject) && metaObject.getOriginalObject() instanceof BaseDO) {
|
||||
BaseDO baseDO = (BaseDO) metaObject.getOriginalObject();
|
||||
|
||||
Date now = new Date();
|
||||
// 创建时间
|
||||
if (Objects.isNull(baseDO.getCreateTime())) {
|
||||
baseDO.setCreateTime(now);
|
||||
}
|
||||
// 更新时间
|
||||
if (Objects.isNull(baseDO.getUpdateTime())) {
|
||||
baseDO.setUpdateTime(now);
|
||||
}
|
||||
|
||||
// TODO 当前用户
|
||||
Long userId = null;
|
||||
// 创建人
|
||||
if (Objects.nonNull(userId) && Objects.isNull(baseDO.getCreator())) {
|
||||
baseDO.setCreator(userId.toString());
|
||||
}
|
||||
// 更新人
|
||||
if (Objects.nonNull(userId) && Objects.isNull(baseDO.getUpdater())) {
|
||||
baseDO.setUpdater(userId.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFill(MetaObject metaObject) {
|
||||
// 更新时间
|
||||
Object modifyTime = getFieldValByName("updateTime", metaObject);
|
||||
if (Objects.isNull(modifyTime)) {
|
||||
setFieldValByName("updateTime", new Date(), metaObject);
|
||||
}
|
||||
|
||||
// 更新人
|
||||
Object updater = getFieldValByName("updater", metaObject);
|
||||
// TODO 当前用户
|
||||
Long userId = null;
|
||||
if (Objects.nonNull(userId) && Objects.isNull(updater)) {
|
||||
setFieldValByName("updater", userId.toString(), metaObject);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package com.orion.ops.framework.mybatis.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.toolkit.Db;
|
||||
import com.orion.ops.framework.mybatis.query.DataQuery;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 公共 mapper
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/6/23 18:42
|
||||
*/
|
||||
public interface IMapper<T> extends BaseMapper<T> {
|
||||
|
||||
/**
|
||||
* 批量插入
|
||||
*
|
||||
* @param entities entities
|
||||
* @return 是否成功
|
||||
*/
|
||||
default boolean insertBatch(Collection<T> entities) {
|
||||
return Db.saveBatch(entities);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量插入
|
||||
*
|
||||
* @param entities entities
|
||||
* @param size size
|
||||
* @return 是否成功
|
||||
*/
|
||||
default boolean insertBatch(Collection<T> entities, int size) {
|
||||
return Db.saveBatch(entities, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新 (通过id)
|
||||
*
|
||||
* @param entities entities
|
||||
* @return 是否成功
|
||||
*/
|
||||
default boolean updateBatch(Collection<T> entities) {
|
||||
return Db.updateBatchById(entities);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新 (通过id)
|
||||
*
|
||||
* @param entities entities
|
||||
* @param size size
|
||||
* @return 是否成功
|
||||
*/
|
||||
default boolean updateBatch(Collection<T> entities, int size) {
|
||||
return Db.updateBatchById(entities, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入或更新 (通过id)
|
||||
*
|
||||
* @param entity entity
|
||||
* @return 是否成功
|
||||
*/
|
||||
default boolean insertOrUpdate(T entity) {
|
||||
return Db.saveOrUpdate(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量插入或更新 (通过id)
|
||||
*
|
||||
* @param entities entities
|
||||
* @return 是否成功
|
||||
*/
|
||||
default boolean insertOrUpdateBatch(Collection<T> entities) {
|
||||
return Db.saveOrUpdateBatch(entities);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量插入或更新 (通过id)
|
||||
*
|
||||
* @param entities entities
|
||||
* @param size size
|
||||
* @return 是否成功
|
||||
*/
|
||||
default boolean insertOrUpdateBatch(Collection<T> entities, int size) {
|
||||
return Db.saveOrUpdateBatch(entities, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 DataQuery 对象
|
||||
*
|
||||
* @return DataQuery
|
||||
*/
|
||||
default DataQuery<T> of() {
|
||||
return DataQuery.of(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.orion.ops.framework.mybatis.query;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
|
||||
/**
|
||||
* 条件构建类
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/6/25 12:24
|
||||
*/
|
||||
public class Conditions {
|
||||
|
||||
private Conditions() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 条件有效性验证 wrapper
|
||||
*
|
||||
* @param <T> T
|
||||
* @return wrapper
|
||||
*/
|
||||
public static <T> LambdaQueryWrapper<T> validateWrapper() {
|
||||
return new ValidateLambdaWrapper<>();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.orion.ops.framework.mybatis.query;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.orion.lang.define.wrapper.DataGrid;
|
||||
import com.orion.lang.define.wrapper.PageRequest;
|
||||
import com.orion.lang.define.wrapper.Pager;
|
||||
import com.orion.lang.utils.Valid;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.lang.utils.convert.Converts;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 数据查询器
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/6/23 18:52
|
||||
*/
|
||||
public class DataQuery<T> {
|
||||
|
||||
private final BaseMapper<T> dao;
|
||||
|
||||
private PageRequest page;
|
||||
|
||||
private LambdaQueryWrapper<T> wrapper;
|
||||
|
||||
private DataQuery(BaseMapper<T> dao) {
|
||||
this.dao = dao;
|
||||
}
|
||||
|
||||
public static <T> DataQuery<T> of(BaseMapper<T> dao) {
|
||||
Valid.notNull(dao, "dao is null");
|
||||
return new DataQuery<>(dao);
|
||||
}
|
||||
|
||||
public DataQuery<T> page(PageRequest page) {
|
||||
this.page = Valid.notNull(page, "page is null");
|
||||
return this;
|
||||
}
|
||||
|
||||
public DataQuery<T> wrapper(LambdaQueryWrapper<T> wrapper) {
|
||||
this.wrapper = Valid.notNull(wrapper, "wrapper is null");
|
||||
return this;
|
||||
}
|
||||
|
||||
public Optional<T> get() {
|
||||
return Optional.ofNullable(dao.selectOne(wrapper));
|
||||
}
|
||||
|
||||
// TODO mapstruct
|
||||
public <R> Optional<R> get(Class<R> c) {
|
||||
return Optional.ofNullable(dao.selectOne(wrapper))
|
||||
.map(s -> Converts.to(s, c));
|
||||
}
|
||||
|
||||
public Stream<T> list() {
|
||||
return dao.selectList(wrapper).stream();
|
||||
}
|
||||
|
||||
// TODO mapstruct
|
||||
public <R> List<R> list(Class<R> c) {
|
||||
return Converts.toList(dao.selectList(wrapper), c);
|
||||
}
|
||||
|
||||
public Long count() {
|
||||
return dao.selectCount(wrapper);
|
||||
}
|
||||
|
||||
public boolean present() {
|
||||
return dao.selectCount(wrapper) > 0;
|
||||
}
|
||||
|
||||
public DataGrid<T> dataGrid() {
|
||||
return this.dataGrid(Function.identity());
|
||||
}
|
||||
|
||||
// TODO mapstruct
|
||||
public <R> DataGrid<R> dataGrid(Class<R> c) {
|
||||
return this.dataGrid(t -> Converts.to(t, c));
|
||||
}
|
||||
|
||||
public <R> DataGrid<R> dataGrid(Function<T, R> convert) {
|
||||
Valid.notNull(convert, "convert is null");
|
||||
Valid.notNull(page, "page is null");
|
||||
Valid.notNull(wrapper, "wrapper is null");
|
||||
Long count = dao.selectCount(wrapper);
|
||||
Pager<R> pager = new Pager<>(page);
|
||||
pager.setTotal(count.intValue());
|
||||
boolean next = pager.hasMoreData();
|
||||
if (next) {
|
||||
wrapper.last(pager.getSql());
|
||||
List<R> rows = dao.selectList(wrapper).stream()
|
||||
.map(convert)
|
||||
.collect(Collectors.toList());
|
||||
pager.setRows(rows);
|
||||
} else {
|
||||
pager.setRows(Lists.empty());
|
||||
}
|
||||
return DataGrid.of(pager);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
package com.orion.ops.framework.mybatis.query;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.orion.lang.utils.Strings;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* TODO TEST
|
||||
* <p>
|
||||
* 有效性验证 wrapper
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/6/25 11:43
|
||||
*/
|
||||
public class ValidateLambdaWrapper<T> extends LambdaQueryWrapper<T> {
|
||||
|
||||
/**
|
||||
* 有效性验证
|
||||
*
|
||||
* @param objects objects
|
||||
* @return isValidate
|
||||
*/
|
||||
private boolean isIllegal(Object... objects) {
|
||||
for (Object object : objects) {
|
||||
// 非 null 检测
|
||||
if (object == null) {
|
||||
return false;
|
||||
}
|
||||
// 字符串 非空校验
|
||||
if (object instanceof String) {
|
||||
if (Strings.isBlank((String) object)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// 集合 非空校验
|
||||
if (object instanceof Collection<?>) {
|
||||
if (((Collection<?>) object).isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaQueryWrapper<T> eq(SFunction<T, ?> column, Object val) {
|
||||
if (this.isIllegal(val)) {
|
||||
return this;
|
||||
}
|
||||
return super.eq(column, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaQueryWrapper<T> ne(SFunction<T, ?> column, Object val) {
|
||||
if (this.isIllegal(val)) {
|
||||
return this;
|
||||
}
|
||||
return super.ne(column, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaQueryWrapper<T> gt(SFunction<T, ?> column, Object val) {
|
||||
if (this.isIllegal(val)) {
|
||||
return this;
|
||||
}
|
||||
return super.gt(column, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaQueryWrapper<T> ge(SFunction<T, ?> column, Object val) {
|
||||
if (this.isIllegal(val)) {
|
||||
return this;
|
||||
}
|
||||
return super.ge(column, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaQueryWrapper<T> lt(SFunction<T, ?> column, Object val) {
|
||||
if (this.isIllegal(val)) {
|
||||
return this;
|
||||
}
|
||||
return super.lt(column, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaQueryWrapper<T> le(SFunction<T, ?> column, Object val) {
|
||||
if (this.isIllegal(val)) {
|
||||
return this;
|
||||
}
|
||||
return super.le(column, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaQueryWrapper<T> between(SFunction<T, ?> column, Object val1, Object val2) {
|
||||
if (this.isIllegal(val1, val2)) {
|
||||
return this;
|
||||
}
|
||||
return super.between(column, val1, val2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaQueryWrapper<T> notBetween(SFunction<T, ?> column, Object val1, Object val2) {
|
||||
if (this.isIllegal(val1, val2)) {
|
||||
return this;
|
||||
}
|
||||
return super.notBetween(column, val1, val2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaQueryWrapper<T> like(SFunction<T, ?> column, Object val) {
|
||||
if (this.isIllegal(val)) {
|
||||
return this;
|
||||
}
|
||||
return super.like(column, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaQueryWrapper<T> notLike(SFunction<T, ?> column, Object val) {
|
||||
if (this.isIllegal(val)) {
|
||||
return this;
|
||||
}
|
||||
return super.notLike(column, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaQueryWrapper<T> notLikeLeft(SFunction<T, ?> column, Object val) {
|
||||
if (this.isIllegal(val)) {
|
||||
return this;
|
||||
}
|
||||
return super.notLikeLeft(column, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaQueryWrapper<T> notLikeRight(SFunction<T, ?> column, Object val) {
|
||||
if (this.isIllegal(val)) {
|
||||
return this;
|
||||
}
|
||||
return super.notLikeRight(column, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaQueryWrapper<T> likeLeft(SFunction<T, ?> column, Object val) {
|
||||
if (this.isIllegal(val)) {
|
||||
return this;
|
||||
}
|
||||
return super.likeLeft(column, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaQueryWrapper<T> likeRight(SFunction<T, ?> column, Object val) {
|
||||
if (this.isIllegal(val)) {
|
||||
return this;
|
||||
}
|
||||
return super.likeRight(column, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaQueryWrapper<T> in(SFunction<T, ?> column, Collection<?> coll) {
|
||||
if (this.isIllegal(coll)) {
|
||||
return this;
|
||||
}
|
||||
return super.in(column, coll);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaQueryWrapper<T> in(SFunction<T, ?> column, Object... values) {
|
||||
if (this.isIllegal(values)) {
|
||||
return this;
|
||||
}
|
||||
return super.in(column, values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaQueryWrapper<T> notIn(SFunction<T, ?> column, Collection<?> coll) {
|
||||
if (this.isIllegal(coll)) {
|
||||
return this;
|
||||
}
|
||||
return super.notIn(column, coll);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaQueryWrapper<T> notIn(SFunction<T, ?> column, Object... value) {
|
||||
if (this.isIllegal(value)) {
|
||||
return this;
|
||||
}
|
||||
return super.notIn(column, value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.orion.ops.framework.mybatis.type;
|
||||
|
||||
import org.apache.ibatis.type.TypeHandler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* mybatis 类型转换
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/6/25 10:38
|
||||
*/
|
||||
public interface ITypeHandler<P, R> extends TypeHandler<R> {
|
||||
|
||||
// TODO KIT
|
||||
String COMMA = ",";
|
||||
|
||||
/**
|
||||
* 数据类型转换
|
||||
*
|
||||
* @param param param
|
||||
* @return result
|
||||
*/
|
||||
R getResult(P param);
|
||||
|
||||
/**
|
||||
* // TODO kit
|
||||
* 用 , 连接
|
||||
*
|
||||
* @param list list
|
||||
* @return res
|
||||
*/
|
||||
default String join(List<?> list) {
|
||||
if (list == null) {
|
||||
return null;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
sb.append(list.get(i));
|
||||
if (i != size - 1) {
|
||||
sb.append(COMMA);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.orion.ops.framework.mybatis.type;
|
||||
|
||||
import com.orion.lang.utils.Strings;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.MappedJdbcTypes;
|
||||
import org.apache.ibatis.type.MappedTypes;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* TODO TEST
|
||||
* varchar -> List<Integer>
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/6/25 10:33
|
||||
*/
|
||||
@MappedJdbcTypes(JdbcType.VARCHAR)
|
||||
@MappedTypes(List.class)
|
||||
public class IntegerListTypeHandler implements ITypeHandler<String, List<Integer>> {
|
||||
|
||||
@Override
|
||||
public void setParameter(PreparedStatement ps, int i, List<Integer> res, JdbcType jdbcType) throws SQLException {
|
||||
// 设置占位符
|
||||
ps.setString(i, this.join(res));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getResult(ResultSet rs, String columnName) throws SQLException {
|
||||
return this.getResult(rs.getString(columnName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
return this.getResult(rs.getString(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
return this.getResult(cs.getString(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getResult(String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return Arrays.stream(value.split(COMMA))
|
||||
.filter(Strings::isNumber)
|
||||
.map(Integer::valueOf)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.orion.ops.framework.mybatis.type;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.MappedJdbcTypes;
|
||||
import org.apache.ibatis.type.MappedTypes;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* TODO TEST
|
||||
* varchar -> JSONArray
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/6/25 10:33
|
||||
*/
|
||||
@MappedJdbcTypes(JdbcType.VARCHAR)
|
||||
@MappedTypes(JSONArray.class)
|
||||
public class JSONArrayTypeHandler implements ITypeHandler<String, JSONArray> {
|
||||
|
||||
@Override
|
||||
public void setParameter(PreparedStatement ps, int i, JSONArray res, JdbcType jdbcType) throws SQLException {
|
||||
// todo TEST NULL
|
||||
// 设置占位符
|
||||
ps.setString(i, res.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONArray getResult(ResultSet rs, String columnName) throws SQLException {
|
||||
return this.getResult(rs.getString(columnName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONArray getResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
return this.getResult(rs.getString(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONArray getResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
return this.getResult(cs.getString(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONArray getResult(String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return JSON.parseArray(value);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.orion.ops.framework.mybatis.type;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.MappedJdbcTypes;
|
||||
import org.apache.ibatis.type.MappedTypes;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* TODO TEST
|
||||
* varchar -> JSONObject
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/6/25 10:33
|
||||
*/
|
||||
@MappedJdbcTypes(JdbcType.VARCHAR)
|
||||
@MappedTypes(JSONObject.class)
|
||||
public class JSONObjectTypeHandler implements ITypeHandler<String, JSONObject> {
|
||||
|
||||
@Override
|
||||
public void setParameter(PreparedStatement ps, int i, JSONObject res, JdbcType jdbcType) throws SQLException {
|
||||
// todo TEST NULL
|
||||
// 设置占位符
|
||||
ps.setString(i, res.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getResult(ResultSet rs, String columnName) throws SQLException {
|
||||
return this.getResult(rs.getString(columnName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
return this.getResult(rs.getString(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
return this.getResult(cs.getString(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getResult(String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return JSON.parseObject(value);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.orion.ops.framework.mybatis.type;
|
||||
|
||||
import com.orion.lang.utils.Strings;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.MappedJdbcTypes;
|
||||
import org.apache.ibatis.type.MappedTypes;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* TODO TEST
|
||||
* varchar -> List<Long>
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/6/25 10:33
|
||||
*/
|
||||
@MappedJdbcTypes(JdbcType.VARCHAR)
|
||||
@MappedTypes(List.class)
|
||||
public class LongListTypeHandler implements ITypeHandler<String, List<Long>> {
|
||||
|
||||
@Override
|
||||
public void setParameter(PreparedStatement ps, int i, List<Long> res, JdbcType jdbcType) throws SQLException {
|
||||
// 设置占位符
|
||||
ps.setString(i, this.join(res));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getResult(ResultSet rs, String columnName) throws SQLException {
|
||||
return this.getResult(rs.getString(columnName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
return this.getResult(rs.getString(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
return this.getResult(cs.getString(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getResult(String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return Arrays.stream(value.split(COMMA))
|
||||
.filter(Strings::isNumber)
|
||||
.map(Long::valueOf)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.orion.ops.framework.mybatis.type;
|
||||
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.MappedJdbcTypes;
|
||||
import org.apache.ibatis.type.MappedTypes;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* TODO TEST
|
||||
* varchar -> List<String>
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/6/25 10:33
|
||||
*/
|
||||
@MappedJdbcTypes(JdbcType.VARCHAR)
|
||||
@MappedTypes(List.class)
|
||||
public class StringListTypeHandler implements ITypeHandler<String, List<String>> {
|
||||
|
||||
@Override
|
||||
public void setParameter(PreparedStatement ps, int i, List<String> res, JdbcType jdbcType) throws SQLException {
|
||||
// 设置占位符
|
||||
ps.setString(i, this.join(res));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getResult(ResultSet rs, String columnName) throws SQLException {
|
||||
return this.getResult(rs.getString(columnName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
return this.getResult(rs.getString(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
return this.getResult(cs.getString(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getResult(String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return Lists.of(value.split(COMMA));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
com.orion.ops.framework.mybatis.config.OrionMybatisAutoConfiguration
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.orion.ops.framework.web.config;
|
||||
|
||||
import com.orion.ops.framework.common.enums.InterceptorOrderConst;
|
||||
import com.orion.ops.framework.common.constant.InterceptorOrderConst;
|
||||
import com.orion.ops.framework.web.core.interceptor.LogPrintInterceptor;
|
||||
import org.springframework.aop.aspectj.AspectJExpressionPointcutAdvisor;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.alibaba.fastjson.support.config.FastJsonConfig;
|
||||
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.ops.framework.common.enums.FilterOrderConst;
|
||||
import com.orion.ops.framework.common.constant.FilterOrderConst;
|
||||
import com.orion.ops.framework.web.core.filter.TraceIdFilter;
|
||||
import com.orion.ops.framework.web.core.handler.GlobalExceptionHandler;
|
||||
import com.orion.ops.framework.web.core.handler.WrapperResultHandler;
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.orion.lang.exception.argument.HttpWrapperException;
|
||||
import com.orion.lang.exception.argument.InvalidArgumentException;
|
||||
import com.orion.lang.exception.argument.RpcWrapperException;
|
||||
import com.orion.lang.utils.Exceptions;
|
||||
import com.orion.ops.framework.common.enums.ExceptionMessageConst;
|
||||
import com.orion.ops.framework.common.constant.ExceptionMessageConst;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.EncryptedDocumentException;
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
<module>orion-ops-spring-boot-starter-banner</module>
|
||||
<module>orion-ops-spring-boot-starter-swagger</module>
|
||||
<module>orion-ops-spring-boot-starter-datasource</module>
|
||||
<module>orion-ops-spring-boot-starter-mybatis</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
@@ -40,10 +40,9 @@
|
||||
<groupId>com.orion.ops</groupId>
|
||||
<artifactId>orion-ops-spring-boot-starter-datasource</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<groupId>com.orion.ops</groupId>
|
||||
<artifactId>orion-ops-spring-boot-starter-mybatis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- orion-ops biz-modules -->
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
spring:
|
||||
datasource:
|
||||
druid:
|
||||
url:
|
||||
username:
|
||||
password:
|
||||
url: jdbc:mysql://127.0.0.1:3306/orion-ops-pro?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&autoReconnect=true
|
||||
username: root
|
||||
password: Data@123456
|
||||
initial-size: 0
|
||||
min-idle: 1
|
||||
max-active: 5
|
||||
|
||||
mybatis-plus:
|
||||
configuration:
|
||||
# 日志打印
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
spring:
|
||||
datasource:
|
||||
druid:
|
||||
url:
|
||||
username:
|
||||
password:
|
||||
url: jdbc:mysql://127.0.0.1:3306/orion-ops-pro?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&autoReconnect=true
|
||||
username: root
|
||||
password: Data@123456
|
||||
# 初始连接数
|
||||
initial-size: 5
|
||||
# 最小连接池数量
|
||||
|
||||
@@ -54,6 +54,16 @@ spring:
|
||||
config:
|
||||
multi-statement-allow: true
|
||||
|
||||
mybatis-plus:
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
mapper-locations: classpath*:mapper/*Mapper.xml
|
||||
global-config:
|
||||
db-config:
|
||||
logic-delete-field: deleted
|
||||
logic-not-delete-value: 1
|
||||
logic-delete-value: 2
|
||||
|
||||
springdoc:
|
||||
api-docs:
|
||||
enabled: true
|
||||
|
||||
Reference in New Issue
Block a user