新增 sqlite 支持、新增时间类型处理器、修复一些bug、升级了一些依赖。

This commit is contained in:
besscroft
2023-03-02 22:42:25 +08:00
parent 4ec8d811b8
commit 95bb599878
14 changed files with 229 additions and 30 deletions

View File

@@ -1,7 +1,7 @@
# 该镜像需要依赖的基础镜像
FROM eclipse-temurin:17.0.5_8-jre-jammy
# 设置环境变量
ENV TZ=Asia/Shanghai JAVA_OPTS="-Xms512m -Xmx512m -Dfile.encoding=utf-8" SPRING_CONFIG="--spring.profiles.active=prod"
ENV TZ=Asia/Shanghai JAVA_OPTS="-Xms512m -Xmx512m -Dfile.encoding=utf-8" SPRING_CONFIG="--spring.profiles.active=mysql"
# 设置时区
RUN set -eux; \
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime; \

14
.github/docker/sqlite/Dockerfile vendored Normal file
View File

@@ -0,0 +1,14 @@
# 该镜像需要依赖的基础镜像
FROM eclipse-temurin:17.0.5_8-jre-jammy
# 设置环境变量
ENV TZ=Asia/Shanghai JAVA_OPTS="-Xms512m -Xmx512m -Dfile.encoding=utf-8" SPRING_CONFIG="--spring.profiles.active=sqlite"
# 设置时区
RUN set -eux; \
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime; \
echo $TZ > /etc/timezone
# 拷贝jar包并重命名
COPY ./diyfile-system/target/diyfile-system.jar /diyfile-system.jar
# 指定docker容器启动时运行jar包
ENTRYPOINT exec java ${JAVA_OPTS} -jar /diyfile-system.jar ${SPRING_CONFIG}
# 指定维护者的名字
MAINTAINER besscroft

View File

@@ -0,0 +1,43 @@
name: "Java CI with MySql Multi-arch Docker Image"
on:
push:
tags:
- 'v*'
jobs:
docker:
name: Running Compile Java Multi-arch Docker Image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Get Version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/}
- name: Setup Java
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'
- name: Build with Maven
run: mvn -B package -Dmaven.test.skip=true --file pom.xml
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Build and push diyfile-mysql version
id: docker_build_xanadu_version
uses: docker/build-push-action@v3
with:
context: ./
file: ./.github/docker/mysql/Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le,linux/s390x
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/diyfile:${{ steps.get_version.outputs.VERSION }}-mysql

View File

@@ -1,4 +1,4 @@
name: "Java CI with Multi-arch Docker Image Test"
name: "Java CI with Multi-arch Docker Test Image"
on:
push:
@@ -32,12 +32,21 @@ jobs:
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Build and push diyfile test
- name: Build and push diyfile sqlite test
id: docker_build_xanadu_test
uses: docker/build-push-action@v3
with:
context: ./
file: ./.github/docker/Dockerfile
file: ./.github/docker/sqlite/Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le,linux/s390x
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/diyfile:test
tags: ${{ secrets.DOCKERHUB_USERNAME }}/diyfile:test-sqlite
- name: Build and push diyfile mysql test
id: docker_build_xanadu_test
uses: docker/build-push-action@v3
with:
context: ./
file: ./.github/docker/mysql/Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le,linux/s390x
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/diyfile:test-mysql

View File

@@ -1,4 +1,4 @@
name: "Java CI with Multi-arch Docker Image"
name: "Java CI with Sqlite Multi-arch Docker Image"
on:
push:
@@ -37,7 +37,7 @@ jobs:
uses: docker/build-push-action@v3
with:
context: ./
file: ./.github/docker/Dockerfile
file: ./.github/docker/sqlite/Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le,linux/s390x
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/diyfile:${{ steps.get_version.outputs.VERSION }}
@@ -46,7 +46,7 @@ jobs:
uses: docker/build-push-action@v3
with:
context: ./
file: ./.github/docker/Dockerfile
file: ./.github/docker/sqlite/Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le,linux/s390x
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/diyfile:latest

View File

@@ -26,12 +26,12 @@ public class BaseEntity implements Serializable {
/** 创建者 */
@Schema(title = "创建者", type = "String")
@TableField(fill = FieldFill.INSERT)
@TableField(fill = FieldFill.INSERT, value = "creator")
private String creator;
/** 更新者 */
@Schema(title = "更新者", type = "String")
@TableField(fill = FieldFill.INSERT_UPDATE)
@TableField(fill = FieldFill.INSERT_UPDATE, value = "updater")
private String updater;
/** 创建时间 */
@@ -39,7 +39,7 @@ public class BaseEntity implements Serializable {
@JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@TableField(fill = FieldFill.INSERT)
@TableField(fill = FieldFill.INSERT, value = "create_time")
private LocalDateTime createTime;
/** 更新时间 */
@@ -47,7 +47,7 @@ public class BaseEntity implements Serializable {
@JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@TableField(fill = FieldFill.INSERT_UPDATE)
@TableField(fill = FieldFill.INSERT_UPDATE, value = "update_time")
private LocalDateTime updateTime;
/**

View File

@@ -0,0 +1,40 @@
package com.besscroft.diyfile.common.handler;
import cn.hutool.core.convert.Convert;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.LocalDateTimeTypeHandler;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;
import org.springframework.stereotype.Component;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDateTime;
/**
* @Description LocalDateTime 类型处理器
* @Author Bess Croft
* @Date 2023/3/2 22:24
*/
@Component
@MappedTypes(LocalDateTime.class)
@MappedJdbcTypes(value = JdbcType.TIMESTAMP, includeNullJdbcType = true)
public class LocalDateTimeTypeHandlerInjector extends LocalDateTimeTypeHandler {
@Override
public LocalDateTime getNullableResult(ResultSet rs, String columnName) throws SQLException {
return Convert.toLocalDateTime(rs.getObject(columnName));
}
@Override
public LocalDateTime getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
return Convert.toLocalDateTime(rs.getObject(columnIndex));
}
@Override
public LocalDateTime getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
return Convert.toLocalDateTime(cs.getObject(columnIndex));
}
}

View File

@@ -19,10 +19,14 @@
<artifactId>diyfile-common</artifactId>
<version>${revision}</version>
</dependency>
<!-- 数据库存储 -->
<!-- 数据库 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
</dependency>
<!-- http 请求 -->
<dependency>

View File

@@ -1,6 +1,6 @@
spring:
datasource:
driverClassName: com.mysql.jdbc.Driver
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://${DB_URL:localhost:3306}/${DB_NAME:diyfile}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=${DB_SSL:false}
username: ${DB_USERNAME:root}
password: ${DB_PASSWORD:666666}
@@ -32,6 +32,9 @@ mybatis:
# mybatis-plus 配置
mybatis-plus:
# 启动 mybatis 本身的 log 日志,但是不建议在生产环境使用,这里仅在开发环境启用,方便排查问题!
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
global-config:
db-config:
logic-delete-field: del # 全局逻辑删除的实体字段名(since 3.3.0,配置后可以忽略不配置步骤2)

View File

@@ -1,6 +1,6 @@
spring:
datasource:
driverClassName: com.mysql.jdbc.Driver
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://${DB_URL:localhost:3306}/${DB_NAME:diyfile}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=${DB_SSL:false}
username: ${DB_USERNAME:root}
password: ${DB_PASSWORD:666666}

View File

@@ -0,0 +1,93 @@
spring:
datasource:
driverClassName: org.sqlite.JDBC
url: jdbc:sqlite:doc/data/diyfile.db?date_string_format=yyyy-MM-dd HH:mm:ss
hikari:
# 连接池最大连接数
maximum-pool-size: 20
# 空闲时保持最小连接数
minimum-idle: 5
# 空闲连接存活时间
idle-timeout: 300000
# 连接超时时间
connection-timeout: 5000
# 检测连接是否有效
connection-test-query: select 1
# 缓存
cache:
type: CAFFEINE
caffeine:
spec: maximumSize=500,initialCapacity=100,expireAfterAccess=600s
# MyBatis配置
mybatis:
# 搜索指定包别名
typeAliasesPackage: com.besscroft.diyfile.common.entity
# 配置mapper的扫描找到所有的mapper.xml映射文件
mapperLocations: classpath*:mapper/*Mapper.xml
configuration:
cache-enabled: false
# mybatis-plus 配置
mybatis-plus:
global-config:
db-config:
logic-delete-field: del # 全局逻辑删除的实体字段名(since 3.3.0,配置后可以忽略不配置步骤2)
logic-delete-value: 0 # 逻辑已删除值(默认为 1)
logic-not-delete-value: 1 # 逻辑未删除值(默认为 0)
# Actuator 配置
management:
endpoints:
web:
exposure:
# 监控项配置
include: '*'
endpoint:
health:
# 开启显示全部细节
show-details: always
shutdown:
# 启用接口关闭 SpringBoot
enabled: false
# Micrometer 配置
metrics:
tags:
application: ${spring.application.name}
# SpringDoc 配置
springdoc:
api-docs:
enabled: ${DOC_ENABLE:false}
path: "/api-docs"
swagger-ui:
enabled: ${DOC_ENABLE:false}
path: "/swagger-ui.html"
# 配置扫描的包
packagesToScan: com.besscroft.diyfile.controller
show-actuator: false
cache:
disabled: false
pre-loading-enabled: true
sa-token:
# token名称 (同时也是cookie名称)
token-name: Authorization
# token前缀
token-prefix: Bearer
# token有效期单位s 默认30天, -1代表永不过期
timeout: 2592000
# token临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
activity-timeout: -1
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
is-concurrent: true
# 在多人登录同一账号时是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token)
is-share: true
# token风格
token-style: uuid
# 是否输出操作日志
is-log: false
# Cookie配置
is-read-cookie: false
# logo打印
isPrint: false

View File

@@ -134,8 +134,8 @@
remark,
creator,
updater,
create_time,
update_time,
date(create_time),
date(update_time),
del
FROM
storage

BIN
doc/data/diyfile.db Normal file

Binary file not shown.

15
pom.xml
View File

@@ -27,7 +27,6 @@
<spring-boot.version>3.0.2</spring-boot.version>
<mapstruct.version>1.5.3.Final</mapstruct.version>
<lombok-mapstruct-binding.version>0.2.0</lombok-mapstruct-binding.version>
<mysql.version>5.1.49</mysql.version>
<mybatis-plus.version>3.5.3.1</mybatis-plus.version>
<springdoc.version>2.0.2</springdoc.version>
<sa-token.version>1.34.0</sa-token.version>
@@ -95,12 +94,6 @@
<artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
</dependency>
<!-- 数据库存储 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<!-- mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>
@@ -187,17 +180,17 @@
</activation>
</profile>
<profile>
<!-- 测试环境 -->
<!-- mysql -->
<id>test</id>
<properties>
<spring.active>test</spring.active>
<spring.active>mysql</spring.active>
</properties>
</profile>
<profile>
<!-- 生产环境 -->
<!-- sqlite -->
<id>prod</id>
<properties>
<spring.active>prod</spring.active>
<spring.active>sqlite</spring.active>
</properties>
</profile>
</profiles>