serv-文件管理
This commit is contained in:
62
schoolNewsServ/file/src/main/resources/application.yaml
Normal file
62
schoolNewsServ/file/src/main/resources/application.yaml
Normal file
@@ -0,0 +1,62 @@
|
||||
spring:
|
||||
application:
|
||||
name: file-service
|
||||
|
||||
servlet:
|
||||
multipart:
|
||||
enabled: true
|
||||
max-file-size: 100MB
|
||||
max-request-size: 100MB
|
||||
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/school_news?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: root
|
||||
hikari:
|
||||
minimum-idle: 5
|
||||
maximum-pool-size: 20
|
||||
idle-timeout: 600000
|
||||
max-lifetime: 1800000
|
||||
connection-timeout: 30000
|
||||
|
||||
# MyBatis Plus配置
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath:mapper/*.xml
|
||||
type-aliases-package: org.xyzh.common.dto
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||
global-config:
|
||||
db-config:
|
||||
id-type: assign_uuid
|
||||
logic-delete-field: deleted
|
||||
logic-delete-value: 1
|
||||
logic-not-delete-value: 0
|
||||
|
||||
# 文件存储配置
|
||||
file:
|
||||
storage:
|
||||
# 默认存储类型
|
||||
default-type: local
|
||||
|
||||
# 存储配置列表(只创建配置了的存储策略)
|
||||
storages:
|
||||
# 本地存储配置
|
||||
- type: local
|
||||
enabled: true
|
||||
base-path: ./uploads
|
||||
url-prefix: http://localhost:8080/files
|
||||
|
||||
# MinIO存储配置(如不需要可以删除或设置enabled为false)
|
||||
# - type: minio
|
||||
# enabled: true
|
||||
# endpoint: http://localhost:9000
|
||||
# access-key: minioadmin
|
||||
# secret-key: minioadmin
|
||||
# bucket-name: school-news
|
||||
|
||||
# 服务端口
|
||||
server:
|
||||
port: 8086
|
||||
|
||||
81
schoolNewsServ/file/src/main/resources/log4j2-spring.xml
Normal file
81
schoolNewsServ/file/src/main/resources/log4j2-spring.xml
Normal file
@@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN" monitorInterval="30">
|
||||
<Properties>
|
||||
<Property name="LOG_PATTERN">%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n</Property>
|
||||
<Property name="LOG_PATH">./file/logs</Property>
|
||||
<Property name="APP_NAME">school-news-file</Property>
|
||||
</Properties>
|
||||
|
||||
<Appenders>
|
||||
<!-- 控制台输出 -->
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||
</Console>
|
||||
|
||||
<!-- 文件输出 - INFO级别 -->
|
||||
<RollingFile name="InfoFile" fileName="${LOG_PATH}/${APP_NAME}-info.log"
|
||||
filePattern="${LOG_PATH}/${APP_NAME}-INFO-%d{yyyy-MM-dd}_%i.log.gz">
|
||||
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
|
||||
<SizeBasedTriggeringPolicy size="100MB"/>
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="30"/>
|
||||
<Filters>
|
||||
<ThresholdFilter level="WARN" onMatch="DENY" onMismatch="NEUTRAL"/>
|
||||
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
|
||||
</Filters>
|
||||
</RollingFile>
|
||||
|
||||
<!-- 文件输出 - WARN级别 -->
|
||||
<RollingFile name="WarnFile" fileName="${LOG_PATH}/${APP_NAME}-warn.log"
|
||||
filePattern="${LOG_PATH}/${APP_NAME}-WARN-%d{yyyy-MM-dd}_%i.log.gz">
|
||||
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
|
||||
<SizeBasedTriggeringPolicy size="100MB"/>
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="30"/>
|
||||
<Filters>
|
||||
<ThresholdFilter level="ERROR" onMatch="DENY" onMismatch="NEUTRAL"/>
|
||||
<ThresholdFilter level="WARN" onMatch="ACCEPT" onMismatch="DENY"/>
|
||||
</Filters>
|
||||
</RollingFile>
|
||||
|
||||
<!-- 文件输出 - ERROR级别 -->
|
||||
<RollingFile name="ErrorFile" fileName="${LOG_PATH}/${APP_NAME}-error.log"
|
||||
filePattern="${LOG_PATH}/${APP_NAME}-ERROR-%d{yyyy-MM-dd}_%i.log.gz">
|
||||
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
|
||||
<SizeBasedTriggeringPolicy size="100MB"/>
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="30"/>
|
||||
<ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/>
|
||||
</RollingFile>
|
||||
</Appenders>
|
||||
|
||||
<Loggers>
|
||||
<!-- 应用日志 -->
|
||||
<Logger name="org.xyzh" level="INFO" additivity="false">
|
||||
<AppenderRef ref="Console"/>
|
||||
<AppenderRef ref="InfoFile"/>
|
||||
<AppenderRef ref="WarnFile"/>
|
||||
<AppenderRef ref="ErrorFile"/>
|
||||
</Logger>
|
||||
|
||||
<!-- MyBatis日志 -->
|
||||
<Logger name="org.xyzh.file.mapper" level="DEBUG" additivity="false">
|
||||
<AppenderRef ref="Console"/>
|
||||
<AppenderRef ref="InfoFile"/>
|
||||
</Logger>
|
||||
|
||||
<!-- 根日志 -->
|
||||
<Root level="INFO">
|
||||
<AppenderRef ref="Console"/>
|
||||
<AppenderRef ref="InfoFile"/>
|
||||
<AppenderRef ref="WarnFile"/>
|
||||
<AppenderRef ref="ErrorFile"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
111
schoolNewsServ/file/src/main/resources/mapper/FileMapper.xml
Normal file
111
schoolNewsServ/file/src/main/resources/mapper/FileMapper.xml
Normal file
@@ -0,0 +1,111 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.xyzh.file.mapper.FileMapper">
|
||||
|
||||
<!-- 结果映射 -->
|
||||
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.system.TbSysFile">
|
||||
<id column="id" property="ID" />
|
||||
<result column="file_id" property="fileID" />
|
||||
<result column="file_name" property="fileName" />
|
||||
<result column="original_name" property="originalName" />
|
||||
<result column="file_path" property="filePath" />
|
||||
<result column="file_url" property="fileUrl" />
|
||||
<result column="file_size" property="fileSize" />
|
||||
<result column="file_type" property="fileType" />
|
||||
<result column="mime_type" property="mimeType" />
|
||||
<result column="storage_type" property="storageType" />
|
||||
<result column="module" property="module" />
|
||||
<result column="business_id" property="businessID" />
|
||||
<result column="uploader" property="uploader" />
|
||||
<result column="create_time" property="createTime" />
|
||||
<result column="update_time" property="updateTime" />
|
||||
<result column="delete_time" property="deleteTime" />
|
||||
<result column="deleted" property="deleted" />
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, file_id, file_name, original_name, file_path, file_url, file_size,
|
||||
file_type, mime_type, storage_type, module, business_id, uploader,
|
||||
create_time, update_time, delete_time, deleted
|
||||
</sql>
|
||||
|
||||
<!-- 插入文件记录 -->
|
||||
<insert id="insertFile">
|
||||
INSERT INTO tb_sys_file (
|
||||
id, file_id, file_name, original_name, file_path, file_url, file_size,
|
||||
file_type, mime_type, storage_type, module, business_id, uploader,
|
||||
create_time, update_time, deleted
|
||||
) VALUES (
|
||||
#{file.ID}, #{file.fileID}, #{file.fileName}, #{file.originalName}, #{file.filePath}, #{file.fileUrl}, #{file.fileSize},
|
||||
#{file.fileType}, #{file.mimeType}, #{file.storageType}, #{file.module}, #{file.businessID}, #{file.uploader},
|
||||
#{file.createTime}, #{file.updateTime}, #{file.deleted}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- 根据文件ID查询文件信息 -->
|
||||
<select id="selectFileById" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List" />
|
||||
FROM tb_sys_file
|
||||
WHERE id = #{fileId}
|
||||
AND deleted = 0
|
||||
</select>
|
||||
|
||||
<!-- 根据文件ID查询文件信息(包括已删除) -->
|
||||
<select id="selectFileByIdIncludeDeleted" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List" />
|
||||
FROM tb_sys_file
|
||||
WHERE id = #{fileId}
|
||||
</select>
|
||||
|
||||
<!-- 根据业务ID查询文件列表 -->
|
||||
<select id="selectFilesByBusinessId" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List" />
|
||||
FROM tb_sys_file
|
||||
WHERE module = #{module}
|
||||
AND business_id = #{businessId}
|
||||
AND deleted = 0
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据上传者查询文件列表 -->
|
||||
<select id="selectFilesByUploader" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List" />
|
||||
FROM tb_sys_file
|
||||
WHERE uploader = #{uploader}
|
||||
AND deleted = 0
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 逻辑删除文件 -->
|
||||
<update id="logicDeleteFileById">
|
||||
UPDATE tb_sys_file
|
||||
SET deleted = 1,
|
||||
delete_time = NOW()
|
||||
WHERE id = #{fileId}
|
||||
AND deleted = 0
|
||||
</update>
|
||||
|
||||
<!-- 物理删除文件 -->
|
||||
<delete id="deleteFileById">
|
||||
DELETE FROM tb_sys_file
|
||||
WHERE id = #{fileId}
|
||||
</delete>
|
||||
|
||||
<!-- 批量逻辑删除文件 -->
|
||||
<update id="batchLogicDeleteFiles">
|
||||
UPDATE tb_sys_file
|
||||
SET deleted = 1,
|
||||
delete_time = NOW()
|
||||
WHERE id IN
|
||||
<foreach collection="fileIds" item="fileId" open="(" separator="," close=")">
|
||||
#{fileId}
|
||||
</foreach>
|
||||
AND deleted = 0
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user