创建媒资管理工程,依然是分为三个子模块

learning-online-media
├── learning-online-media-api
├── learning-online-media-model
└── learning-online-media-service

创建工程结构

learning-online-media-model模块的pom文件中添加如下依赖:

pom.xml
<dependency>
<groupId>com.swx</groupId>
<artifactId>learning-online-base</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>

learning-online-media-service模块的pom文件中添加如下依赖:

pom.xml
<dependencies>
<dependency>
<groupId>com.swx</groupId>
<artifactId>learning-online-media-model</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<!-- 根据扩展名获取mineType -->
<dependency>
<groupId>com.j256.simplemagic</groupId>
<artifactId>simplemagic</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!-- 分布式任务调度 xxJob -->
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
</dependency>
<!-- FFmpeg -->
<dependency>
<groupId>ws.schild</groupId>
<artifactId>jave-all-deps</artifactId>
</dependency>
</dependencies>

learning-online-media-api模块的pom文件中添加如下依赖:

pom.xml
<dependencies>
<dependency>
<groupId>com.swx</groupId>
<artifactId>learning-online-media-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- log4j日志 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
</dependencies>

创建启动类,在learning-online-media-api工程的com.swx.media包下创建启动类MediaApplication,内容如下:

ContentApplication
@SpringBootApplication
@EnableTransactionManagement
public class MediaApplication {
public static void main(String[] args) {
SpringApplication.run(MediaApplication.class, args);
}
}

项目配置信息,在learning-online-media-api工程的resources下创建bootstrap.yml

bootstrap.yml
spring:
application:
name: media-api
cloud:
nacos:
discovery:
server-addr: xxx.xxx.xxx.xxx:8848
namespace: learning-online-dev
group: learning-online-project
config:
server-addr: xxx.xxx.xxx.xxx:8848
namespace: learning-online-dev
group: learning-online-project
file-extension: yaml
refresh-enabled: true
extension-configs:
- data-id: media-service-${spring.profiles.active}.yaml
group: learning-online-project
refresh: true
shared-configs:
- data-id: logging-${spring.profiles.active}.yaml
group: learning-online-common
refresh: true
profiles:
active: dev

日志配置,在learning-online-media-api工程的resources下创建log4j2-dev.xml

log4j2-dev.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration monitorInterval="180" packages="">
<properties>
<property name="logdir">logs</property>
<property name="PATTERN">%date{YYYY-MM-dd HH:mm:ss,SSS} %level [%thread][%file:%line] - %msg%n%throwable</property>
</properties>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="${PATTERN}"/>
</Console>

<RollingFile name="ErrorAppender" fileName="${logdir}/error.log"
filePattern="${logdir}/$${date:yyyy-MM-dd}/error.%d{yyyy-MM-dd-HH}.log" append="true">
<PatternLayout pattern="${PATTERN}"/>
<ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
</Policies>
</RollingFile>

<RollingFile name="DebugAppender" fileName="${logdir}/info.log"
filePattern="${logdir}/$${date:yyyy-MM-dd}/info.%d{yyyy-MM-dd-HH}.log" append="true">
<PatternLayout pattern="${PATTERN}"/>
<ThresholdFilter level="DEBUG" onMatch="ACCEPT" onMismatch="DENY"/>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
</Policies>
</RollingFile>

<!--异步appender-->
<Async name="AsyncAppender" includeLocation="true">
<AppenderRef ref="ErrorAppender"/>
<AppenderRef ref="DebugAppender"/>
</Async>
</Appenders>

<Loggers>
<!--过滤掉spring和mybatis的一些无用的debug信息
<logger name="org.springframework" level="INFO">
</logger>
<logger name="org.mybatis" level="INFO">
</logger>-->
<logger name="cn.itcast.wanxinp2p.consumer.mapper" level="DEBUG">
</logger>

<logger name="springfox" level="INFO">
</logger>
<logger name="org.apache.http" level="INFO">
</logger>
<logger name="com.netflix.discovery" level="INFO">
</logger>

<logger name="RocketmqCommon" level="INFO" >
</logger>

<logger name="RocketmqRemoting" level="INFO" >
</logger>

<logger name="RocketmqClient" level="WARN">
</logger>

<logger name="org.dromara.hmily" level="WARN">
</logger>

<logger name="org.dromara.hmily.lottery" level="WARN">
</logger>

<logger name="org.dromara.hmily.bonuspoint" level="WARN">
</logger>

<!--OFF 0-->
<!--FATAL 100-->
<!--ERROR 200-->
<!--WARN 300-->
<!--INFO 400-->
<!--DEBUG 500-->
<!--TRACE 600-->
<!--ALL Integer.MAX_VALUE-->
<Root level="DEBUG" includeLocation="true">
<AppenderRef ref="AsyncAppender"/>
<AppenderRef ref="Console"/>
<AppenderRef ref="DebugAppender"/>
</Root>
</Loggers>
</Configuration>

添加基础代码

实体类

使用代码生成工具生成lo_media表的实体类,将其拷贝到learning-online-media-model工程的com.swx.media.model.po包下,暂时所需实体类如下:

  • MediaFiles.java
  • MediaProcess.java
  • MediaProcessHistory.java

Mapper层

将代码生成的所有Mapper.java文件拷贝到learning-online-media-service工程下的com.swx.media.mapper包下。

将代码生成的所有Mapper.xml文件拷贝到learning-online-media-service工程下的resources/mapper目录下。

Service层

将代码生成的所有Service和ServiceImpl文件拷贝到learning-online-media-service工程下的com.swx.media.service包下。

Controller层

将代码生成的Controller文件拷贝到learning-online-media-api工程下的com.swx.media.api包下,并修改添加注解如下:

MediaFilesController
/**
* <p>
* 媒资信息 前端控制器
* </p>
*
* @author sw-code
* @since 2023-08-21
*/
@Api(value = "媒资文件管理接口", tags = "媒资文件管理接口")
@RestController
@ResponseResult
@RequestMapping("/files")
public class MediaFilesController {


}