feat: 项目结构重构
This commit is contained in:
@ -1,47 +1,52 @@
|
||||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>day.gitlab</groupId>
|
||||
<artifactId>dolphin-commons</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>dolphin-common-mybatis</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<artifactId>dolphin-common-mybatis</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<!-- Project -->
|
||||
<dependency>
|
||||
<groupId>day.gitlab</groupId>
|
||||
<artifactId>dolphin-common-core</artifactId>
|
||||
<artifactId>dolphin-common-web</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<!-- Spring Boot -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<artifactId>spring-boot-starter-webmvc</artifactId>
|
||||
</dependency>
|
||||
<!-- MyBatis Flex -->
|
||||
<!-- MyBatis -->
|
||||
<dependency>
|
||||
<groupId>com.mybatis-flex</groupId>
|
||||
<artifactId>mybatis-flex-spring-boot3-starter</artifactId>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-spring-boot4-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- Lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
@ -1,30 +0,0 @@
|
||||
package day.gitlab.dolphin.common.mybatis;
|
||||
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.core.FlexGlobalConfig;
|
||||
import com.mybatisflex.core.audit.AuditManager;
|
||||
import com.mybatisflex.core.keygen.KeyGeneratorFactory;
|
||||
import com.mybatisflex.spring.boot.MyBatisFlexCustomizer;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class MyBatisFlexConfiguration implements MyBatisFlexCustomizer {
|
||||
|
||||
@Resource
|
||||
private UUIDv7KeyGenerator uuidv7KeyGenerator;
|
||||
|
||||
@Override
|
||||
public void customize(FlexGlobalConfig flexGlobalConfig) {
|
||||
KeyGeneratorFactory.register("uuidv7", uuidv7KeyGenerator);
|
||||
|
||||
// 设置默认主键类型
|
||||
FlexGlobalConfig.KeyConfig keyConfig = new FlexGlobalConfig.KeyConfig();
|
||||
keyConfig.setKeyType(KeyType.Generator);
|
||||
keyConfig.setValue("uuidv7");
|
||||
keyConfig.setBefore(true);
|
||||
flexGlobalConfig.setKeyConfig(keyConfig);
|
||||
|
||||
AuditManager.setAuditEnable(true);
|
||||
}
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
package day.gitlab.dolphin.common.mybatis;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import day.gitlab.dolphin.common.core.entity.PageResponse;
|
||||
import day.gitlab.dolphin.common.core.entity.QueryPageRequest;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class Pages {
|
||||
|
||||
public static <T, E> Page<E> paginate(BaseMapper<E> mapper, QueryPageRequest<T> pageRequest, BiFunction<T, QueryWrapper, QueryWrapper> biFunction) {
|
||||
Page<E> page = new Page<>(pageRequest.getPageNumber(), pageRequest.getPageSize());
|
||||
QueryWrapper wrapper = new QueryWrapper();
|
||||
wrapper = biFunction.apply(pageRequest.getQuery(), wrapper);
|
||||
|
||||
return mapper.paginate(page, wrapper);
|
||||
}
|
||||
|
||||
public static <T, E> PageResponse<E> toPageResponse(Page<T> page, Function<T, E> mapFunction) {
|
||||
PageResponse<E> pageResponse = new PageResponse<>();
|
||||
pageResponse.setPageNumber(page.getPageNumber());
|
||||
pageResponse.setPageSize(page.getPageSize());
|
||||
pageResponse.setTotal(page.getTotalRow());
|
||||
|
||||
if (page.getRecords() != null) {
|
||||
pageResponse.setRecords(page.getRecords().stream().map(mapFunction).filter(Objects::nonNull).toList());
|
||||
}
|
||||
|
||||
return pageResponse;
|
||||
}
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
package day.gitlab.dolphin.common.mybatis;
|
||||
|
||||
import com.mybatisflex.core.keygen.IKeyGenerator;
|
||||
import day.gitlab.dolphin.common.core.util.UUIDv7;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class UUIDv7KeyGenerator implements IKeyGenerator {
|
||||
|
||||
@Override
|
||||
public Object generate(Object entity, String keyColumn) {
|
||||
return UUIDv7.randomUUID().toString();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package day.gitlab.dolphin.common.mybatis.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator;
|
||||
import day.gitlab.dolphin.common.core.util.UUIDv7;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
@Component
|
||||
public class UUIDv7Generator extends DefaultIdentifierGenerator {
|
||||
|
||||
public UUIDv7Generator() {
|
||||
super((InetAddress) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nextUUID(Object entity) {
|
||||
return UUIDv7.randomUUID().toString();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
package day.gitlab.dolphin.common.mybatis.util;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import day.gitlab.dolphin.common.web.entity.PageRequest;
|
||||
import day.gitlab.dolphin.common.web.entity.PageResponse;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class Pages {
|
||||
|
||||
public static <T, E> Page<E> paginate(PageRequest<T> pageRequest, BaseMapper<E> mapper, BiFunction<T, QueryWrapper<E>, QueryWrapper<E>> biFunction) {
|
||||
Page<E> page = new Page<>(pageRequest.getPageIndex(), pageRequest.getPageSize());
|
||||
QueryWrapper<E> wrapper = new QueryWrapper<>();
|
||||
wrapper = biFunction.apply(pageRequest.getQuery(), wrapper);
|
||||
|
||||
return mapper.selectPage(page, wrapper);
|
||||
}
|
||||
|
||||
public static <T, E> PageResponse<E> toPageResponse(Page<T> page, Function<T, E> mapFunction) {
|
||||
PageResponse<E> pageResponse = new PageResponse<>();
|
||||
pageResponse.setPageIndex(page.getCurrent());
|
||||
pageResponse.setPageSize(page.getSize());
|
||||
pageResponse.setTotal(page.getTotal());
|
||||
|
||||
if (page.getRecords() != null) {
|
||||
pageResponse.setRecords(page.getRecords().stream().map(mapFunction).filter(Objects::nonNull).toList());
|
||||
}
|
||||
|
||||
return pageResponse;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user