Browse Source

mqtt操作工程

learshaw 5 months ago
parent
commit
af38c4bbf6

+ 1 - 0
ems/README.md

@@ -20,6 +20,7 @@ com.ruoyi
 ├── nrg-modules         // 能源业务模块
 │       └── ruoyi-system                              // 系统模块 [9201]
 │       └── ems-server                                // 能源管理服务 [9202]
+│       └── ems-collect                               // 能源采集工具 [9203]
 ├── ruoyi-ui              // 前端框架 [80]
 ├── ruoyi-gateway         // 网关模块 [9100]
 ├── ruoyi-auth            // 认证中心 [9200]

+ 2 - 2
ems/ems-application/ems-admin/src/main/resources/application.yml

@@ -15,8 +15,8 @@ ruoyi:
 
 # 开发环境配置
 server:
-  # 服务器的HTTP端口,默认为8080
-  port: 8080
+  # 服务器的HTTP端口,默认为9100
+  port: 9100
   servlet:
     # 应用的访问路径
     context-path: /

+ 112 - 0
ems/ems-application/ems-collect/pom.xml

@@ -0,0 +1,112 @@
+<?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.huashe.application</groupId>
+        <artifactId>ems-application</artifactId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+    <packaging>jar</packaging>
+    <artifactId>ems-collect</artifactId>
+
+    <description>
+        采集服务
+    </description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-configuration-processor</artifactId>
+            <optional>true</optional>
+        </dependency>
+
+        <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
+        <dependency>
+            <groupId>com.alibaba.fastjson2</groupId>
+            <artifactId>fastjson2</artifactId>
+        </dependency>
+
+        <!-- mqtt -->
+        <dependency>
+            <groupId>org.springframework.integration</groupId>
+            <artifactId>spring-integration-mqtt</artifactId>
+        </dependency>
+
+        <!-- Swagger依赖 -->
+        <dependency>
+            <groupId>io.springfox</groupId>
+            <artifactId>springfox-swagger2</artifactId>
+            <version>2.6.1</version>
+        </dependency>
+        <dependency>
+            <groupId>io.springfox</groupId>
+            <artifactId>springfox-swagger-ui</artifactId>
+            <version>2.6.1</version>
+        </dependency>
+
+        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+        </dependency>
+
+        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-collections4 -->
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-collections4</artifactId>
+        </dependency>
+
+        <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <version>2.5.15</version>
+                <configuration>
+                    <fork>true</fork> <!-- 如果没有该配置,devtools不会生效 -->
+                </configuration>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>   
+                <groupId>org.apache.maven.plugins</groupId>   
+                <artifactId>maven-war-plugin</artifactId>   
+                <version>3.1.0</version>   
+                <configuration>
+                    <failOnMissingWebXml>false</failOnMissingWebXml>
+                    <warName>${project.artifactId}</warName>
+                </configuration>   
+           </plugin>   
+        </plugins>
+        <finalName>${project.artifactId}</finalName>
+    </build>
+
+</project>

+ 52 - 0
ems/ems-application/ems-collect/src/main/java/com/ruoyi/ClientInit.java

@@ -0,0 +1,52 @@
+/*
+ * 文 件 名:  ClientInit
+ * 版    权:  浩鲸云计算科技股份有限公司
+ * 描    述:  <描述>
+ * 修 改 人:  lvwenbin
+ * 修改时间:  2024/4/30
+ * 跟踪单号:  <跟踪单号>
+ * 修改单号:  <修改单号>
+ * 修改内容:  <修改内容>
+ */
+package com.ruoyi;
+
+import com.ruoyi.core.MqttTemplate;
+import com.ruoyi.handle.RootMsgHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+
+/**
+ * 连接初始化
+ * <功能详细描述>
+ *
+ * @author lvwenbin
+ * @version [版本号, 2024/4/30]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+@Component
+public class ClientInit implements CommandLineRunner {
+    private static final Logger log = LoggerFactory.getLogger(ClientInit.class);
+
+    @Resource
+    @Qualifier("mqttTemplate")
+    private MqttTemplate template;
+
+    @Resource
+    private RootMsgHandler rootMsgHandler;
+
+    @Override
+    public void run(String... args) {
+        try {
+            template.subscribe("testtopic/#", 0, rootMsgHandler);
+        }
+        catch (Exception e) {
+            log.error("init fail!", e);
+        }
+    }
+}

+ 32 - 0
ems/ems-application/ems-collect/src/main/java/com/ruoyi/SpingMqttApplication.java

@@ -0,0 +1,32 @@
+/*
+ * 文 件 名:  ConfigServerApplication
+ * 版    权:
+ * 描    述:  <描述>
+ * 修 改 人:  learshaw
+ * 修改时间:  2018/12/18
+ */
+package com.ruoyi;
+
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.scheduling.annotation.EnableScheduling;
+
+/**
+ * Mqtt启动入口
+ * <功能详细描述>
+ *
+ * @author learshaw
+ * @version [版本号, 2021/04/26]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+@EnableScheduling
+@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
+public class SpingMqttApplication {
+    public static void main(String[] args) {
+        SpringApplicationBuilder builder = new SpringApplicationBuilder(SpingMqttApplication.class);
+//        builder.web(WebApplicationType.NONE);
+        builder.run(args);
+    }
+}

+ 39 - 0
ems/ems-application/ems-collect/src/main/java/com/ruoyi/config/MqttConfig.java

@@ -0,0 +1,39 @@
+/*
+ * 文 件 名:  MqttConfig
+ * 版    权:  浩鲸云计算科技股份有限公司
+ * 描    述:  <描述>
+ * 修 改 人:  lvwenbin
+ * 修改时间:  2024/5/6
+ * 跟踪单号:  <跟踪单号>
+ * 修改单号:  <修改单号>
+ * 修改内容:  <修改内容>
+ */
+package com.ruoyi.config;
+
+
+import com.ruoyi.core.MqttTemplate;
+import org.eclipse.paho.client.mqttv3.MqttException;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import javax.annotation.Resource;
+
+/**
+ * Mqtt配置Bean
+ * <功能详细描述>
+ *
+ * @author lvwenbin
+ * @version [版本号, 2024/5/6]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+@Configuration
+public class MqttConfig {
+    @Resource
+    private MqttProperty mqttProperty;
+
+    @Bean(name = "mqttTemplate")
+    public MqttTemplate getMqttTemplate() throws MqttException {
+        return new MqttTemplate(mqttProperty.getHost(), mqttProperty.getClientId());
+    }
+}

+ 47 - 0
ems/ems-application/ems-collect/src/main/java/com/ruoyi/config/MqttProperty.java

@@ -0,0 +1,47 @@
+/*
+ * 文 件 名:  MqttProperty
+ * 版    权:  浩鲸云计算科技股份有限公司
+ * 描    述:  <描述>
+ * 修 改 人:  lvwenbin
+ * 修改时间:  2024/4/30
+ * 跟踪单号:  <跟踪单号>
+ * 修改单号:  <修改单号>
+ * 修改内容:  <修改内容>
+ */
+package com.ruoyi.config;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * 连接配置
+ * <功能详细描述>
+ *
+ * @author lvwenbin
+ * @version [版本号, 2024/4/30]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+@Configuration
+@ConfigurationProperties(prefix = "mqtt")
+public class MqttProperty {
+    private String host;
+
+    private String clientId;
+
+    public String getHost() {
+        return host;
+    }
+
+    public void setHost(String host) {
+        this.host = host;
+    }
+
+    public String getClientId() {
+        return clientId;
+    }
+
+    public void setClientId(String clientId) {
+        this.clientId = clientId;
+    }
+}

+ 77 - 0
ems/ems-application/ems-collect/src/main/java/com/ruoyi/controller/TestController.java

@@ -0,0 +1,77 @@
+/*
+ * 文 件 名:  AnalyseSourceController
+ * 版    权:
+ * 描    述:  <描述>
+ * 修 改 人:  learshaw
+ * 修改时间:  2019/8/1
+ * 跟踪单号:  <跟踪单号>
+ * 修改单号:  <修改单号>
+ * 修改内容:  <修改内容>
+ */
+package com.ruoyi.controller;
+
+import com.ruoyi.core.MqttTemplate;
+import com.ruoyi.model.MqttRequest;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.http.MediaType;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+
+/**
+ * Test访问服务
+ * <功能详细描述>
+ *
+ * @author learshaw
+ * @version [版本号, 2019/8/1]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+@RestController
+@CrossOrigin(allowedHeaders = "*", allowCredentials = "false")
+@Api(value = "TestController", description = "Test访问接口")
+@RequestMapping(path = "/mqtt", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
+public class TestController {
+    /**
+     * 日志
+     */
+    private static final Logger log = LoggerFactory.getLogger(TestController.class);
+
+    @Resource
+    @Qualifier("mqttTemplate")
+    private MqttTemplate mqttTemplate;
+
+    /**
+     * 发送
+     *
+     * @return 数据列表
+     */
+    @RequestMapping(value = "/send", method = RequestMethod.POST)
+    @ApiOperation(value = "send", notes = "发送")
+    @ApiResponses({ @ApiResponse(code = 200, message = "success"),
+        @ApiResponse(code = 400, message = "{code:****,message:'fail'}")
+    })
+    public String send(@RequestBody MqttRequest req) {
+        String ret = "success";
+
+        try {
+            mqttTemplate.send(req.getTopic(), req.getPayload(), req.getQos(), req.isRetained());
+        }
+        catch (Exception e) {
+            log.error("send fail!", e);
+            ret = "fail!";
+        }
+
+        return ret;
+    }
+}

+ 28 - 0
ems/ems-application/ems-collect/src/main/java/com/ruoyi/core/MqttMessageHandler.java

@@ -0,0 +1,28 @@
+/*
+ * 文 件 名:  MqttHandler
+ * 版    权:  浩鲸云计算科技股份有限公司
+ * 描    述:  <描述>
+ * 修 改 人:  lvwenbin
+ * 修改时间:  2024/4/30
+ * 跟踪单号:  <跟踪单号>
+ * 修改单号:  <修改单号>
+ * 修改内容:  <修改内容>
+ */
+package com.ruoyi.core;
+
+/**
+ * Mqtt消息处理
+ * <功能详细描述>
+ *
+ * @author lvwenbin
+ * @version [版本号, 2024/4/30]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+public interface MqttMessageHandler {
+    /**
+     * 消息出来
+     * @param payload 消息报文
+     */
+    void handle(String topic, String payload);
+}

+ 122 - 0
ems/ems-application/ems-collect/src/main/java/com/ruoyi/core/MqttTemplate.java

@@ -0,0 +1,122 @@
+/*
+ * 文 件 名:  MqttClient
+ * 版    权:  浩鲸云计算科技股份有限公司
+ * 描    述:  <描述>
+ * 修 改 人:  lvwenbin
+ * 修改时间:  2024/4/30
+ * 跟踪单号:  <跟踪单号>
+ * 修改单号:  <修改单号>
+ * 修改内容:  <修改内容>
+ */
+package com.ruoyi.core;
+
+import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
+import org.eclipse.paho.client.mqttv3.MqttCallback;
+import org.eclipse.paho.client.mqttv3.MqttClient;
+import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
+import org.eclipse.paho.client.mqttv3.MqttException;
+import org.eclipse.paho.client.mqttv3.MqttMessage;
+import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.nio.charset.StandardCharsets;
+
+/**
+ * Mqtt操作模板
+ * <功能详细描述>
+ *
+ * @author lvwenbin
+ * @version [版本号, 2024/4/30]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+public class MqttTemplate {
+    private static final Logger log = LoggerFactory.getLogger(MqttTemplate.class);
+
+    private MqttClient mqttClient;
+
+    /**
+     * 构造器
+     *
+     * @param broker   服务地址
+     * @param clientId 客户端编码
+     */
+    public MqttTemplate(String broker, String clientId) throws MqttException {
+        MemoryPersistence persistence = new MemoryPersistence();
+
+        mqttClient = new MqttClient(broker, clientId, persistence);
+        // MQTT 连接选项
+        MqttConnectOptions connOpts = new MqttConnectOptions();
+        // 保留会话
+        connOpts.setCleanSession(false);
+        connOpts.setAutomaticReconnect(true);
+        // 建立连接
+        mqttClient.connect(connOpts);
+    }
+
+    /**
+     * 订阅
+     *
+     * @param topic 主题
+     * @param qos   0-最多1次,1-至少1次,2-仅1次
+     */
+    public void subscribe(String topic, Integer qos, MqttMessageHandler handler) {
+        try {
+            mqttClient.subscribe(topic, qos);
+            mqttClient.setCallback(new MqttCallback() {
+                // 链接丢失处理
+                @Override
+                public void connectionLost(Throwable throwable) {
+                    // 连接丢失后,一般在这里面进行重连
+                    log.info("mqtt服务连接断开,进行重连");
+
+                    try {
+                        // 尝试重新连接
+                        if (!mqttClient.isConnected()) {
+                            mqttClient.reconnect();
+                        }
+                    }
+                    catch (MqttException e) {
+                        log.error("重连失败:[{}]", e.getMessage());
+                    }
+                }
+
+                // 消息接收处理
+                @Override
+                public void messageArrived(String topic, MqttMessage message) throws Exception {
+                    String content = new String(message.getPayload(), StandardCharsets.UTF_8);
+                    handler.handle(topic, content);
+                }
+
+                // 消息发送处理
+                @Override
+                public void deliveryComplete(IMqttDeliveryToken token) {
+                    log.info("消息发布结果[{}]", token.isComplete());
+                }
+            });
+        }
+        catch (Exception e) {
+            log.error("mqtt订阅异常", e);
+        }
+    }
+
+    /**
+     * 消息发送
+     * @param topic 主题
+     * @param payload 报文
+     * @param qos 消息级别
+     * @param retained 回复
+     */
+    public void send(String topic, String payload, int qos, boolean retained) {
+        try {
+            MqttMessage message = new MqttMessage();
+            message.setPayload(payload.getBytes(StandardCharsets.UTF_8));
+            message.setQos(qos);
+            message.setRetained(retained);
+            mqttClient.publish(topic, message);
+        } catch (MqttException e) {
+            log.error("[Send]fail!", e);
+        }
+    }
+}

+ 38 - 0
ems/ems-application/ems-collect/src/main/java/com/ruoyi/handle/RootMsgHandler.java

@@ -0,0 +1,38 @@
+/*
+ * 文 件 名:  MessageHandler
+ * 版    权:  浩鲸云计算科技股份有限公司
+ * 描    述:  <描述>
+ * 修 改 人:  lvwenbin
+ * 修改时间:  2024/4/30
+ * 跟踪单号:  <跟踪单号>
+ * 修改单号:  <修改单号>
+ * 修改内容:  <修改内容>
+ */
+package com.ruoyi.handle;
+
+import com.ruoyi.core.MqttMessageHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+/**
+ * 消息处理handle
+ * <功能详细描述>
+ *
+ * @author lvwenbin
+ * @version [版本号, 2024/4/30]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+@Service
+public class RootMsgHandler implements MqttMessageHandler {
+    private static final Logger log = LoggerFactory.getLogger(RootMsgHandler.class);
+
+    @Override
+    public void handle(String topic, String payload) {
+        log.info("[Receive]Topic:{}, message:{}", topic, payload);
+        //TODO
+        //业务逻辑处理
+        //从线程池取一个线程执行处理
+    }
+}

+ 59 - 0
ems/ems-application/ems-collect/src/main/java/com/ruoyi/model/MqttRequest.java

@@ -0,0 +1,59 @@
+/*
+ * 文 件 名:  MqttRequest
+ * 版    权:  浩鲸云计算科技股份有限公司
+ * 描    述:  <描述>
+ * 修 改 人:  lvwenbin
+ * 修改时间:  2024/5/6
+ * 跟踪单号:  <跟踪单号>
+ * 修改单号:  <修改单号>
+ * 修改内容:  <修改内容>
+ */
+package com.ruoyi.model;
+
+/**
+ * 发送请求
+ * <功能详细描述>
+ *
+ * @author lvwenbin
+ * @version [版本号, 2024/5/6]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+public class MqttRequest {
+    private String topic;
+    private String payload;
+    private int qos;
+    private boolean retained;
+
+    public String getTopic() {
+        return topic;
+    }
+
+    public void setTopic(String topic) {
+        this.topic = topic;
+    }
+
+    public String getPayload() {
+        return payload;
+    }
+
+    public void setPayload(String payload) {
+        this.payload = payload;
+    }
+
+    public int getQos() {
+        return qos;
+    }
+
+    public void setQos(int qos) {
+        this.qos = qos;
+    }
+
+    public boolean isRetained() {
+        return retained;
+    }
+
+    public void setRetained(boolean retained) {
+        this.retained = retained;
+    }
+}

+ 66 - 0
ems/ems-application/ems-collect/src/main/resources/application-locale.yml

@@ -0,0 +1,66 @@
+## MQTT##
+mqtt:
+  host: tcp://xt.wenhq.top:8581
+  client_id: ems-collect
+
+# 数据源配置
+spring:
+  datasource:
+    type: com.alibaba.druid.pool.DruidDataSource
+    driverClassName: com.mysql.cj.jdbc.Driver
+    druid:
+      # 主库数据源
+      master:
+        url: jdbc:mysql://172.192.10.105:30002/ems_ct?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
+        username: root
+        password: root
+      # 从库数据源
+      slave:
+        # 从数据源开关/默认关闭
+        enabled: false
+        url:
+        username:
+        password:
+      # 初始连接数
+      initialSize: 5
+      # 最小连接池数量
+      minIdle: 10
+      # 最大连接池数量
+      maxActive: 20
+      # 配置获取连接等待超时的时间
+      maxWait: 60000
+      # 配置连接超时时间
+      connectTimeout: 30000
+      # 配置网络超时时间
+      socketTimeout: 60000
+      # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
+      timeBetweenEvictionRunsMillis: 60000
+      # 配置一个连接在池中最小生存的时间,单位是毫秒
+      minEvictableIdleTimeMillis: 300000
+      # 配置一个连接在池中最大生存的时间,单位是毫秒
+      maxEvictableIdleTimeMillis: 900000
+      # 配置检测连接是否有效
+      validationQuery: SELECT 1 FROM DUAL
+      testWhileIdle: true
+      testOnBorrow: false
+      testOnReturn: false
+      webStatFilter:
+        enabled: true
+      statViewServlet:
+        enabled: true
+        # 设置白名单,不填则允许所有访问
+        allow:
+        url-pattern: /druid/*
+        # 控制台管理用户名和密码
+        login-username: ruoyi
+        login-password: 123456
+      filter:
+        stat:
+          enabled: true
+          # 慢SQL记录
+          log-slow-sql: true
+          slow-sql-millis: 1000
+          merge-sql: true
+        wall:
+          config:
+            multi-statement-allow: true

+ 9 - 0
ems/ems-application/ems-collect/src/main/resources/application.yml

@@ -0,0 +1,9 @@
+spring:
+  application:
+    name: ems-collect
+  profiles:
+    active: locale
+server:
+  port: 9203
+  servlet:
+    context-path: /ems-collect

+ 8 - 0
ems/ems-application/ems-collect/src/main/resources/banner.txt

@@ -0,0 +1,8 @@
+Spring Boot Version: ${spring-boot.version}
+Spring Application Name: ${spring.application.name}
+ _____                         _____       _ _           _
+|  ___|                       /  __ \     | | |         | |
+| |__ _ __ ___  ___   ______  | /  \/ ___ | | | ___  ___| |_
+|  __| '_ ` _ \/ __| |______| | |    / _ \| | |/ _ \/ __| __|
+| |__| | | | | \__ \          | \__/\ (_) | | |  __/ (__| |_
+\____/_| |_| |_|___/           \____/\___/|_|_|\___|\___|\__|

+ 93 - 0
ems/ems-application/ems-collect/src/main/resources/logback.xml

@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+    <!-- 日志存放路径 -->
+	<property name="log.path" value="./ruoyi/logs" />
+    <!-- 日志输出格式 -->
+	<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
+
+	<!-- 控制台输出 -->
+	<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
+		<encoder>
+			<pattern>${log.pattern}</pattern>
+		</encoder>
+	</appender>
+	
+	<!-- 系统日志输出 -->
+	<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
+	    <file>${log.path}/sys-info.log</file>
+        <!-- 循环政策:基于时间创建日志文件 -->
+		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!-- 日志文件名格式 -->
+			<fileNamePattern>${log.path}/sys-info.%d{yyyy-MM-dd}.log</fileNamePattern>
+			<!-- 日志最大的历史 60天 -->
+			<maxHistory>60</maxHistory>
+		</rollingPolicy>
+		<encoder>
+			<pattern>${log.pattern}</pattern>
+		</encoder>
+		<filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <!-- 过滤的级别 -->
+            <level>INFO</level>
+            <!-- 匹配时的操作:接收(记录) -->
+            <onMatch>ACCEPT</onMatch>
+            <!-- 不匹配时的操作:拒绝(不记录) -->
+            <onMismatch>DENY</onMismatch>
+        </filter>
+	</appender>
+	
+	<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
+	    <file>${log.path}/sys-error.log</file>
+        <!-- 循环政策:基于时间创建日志文件 -->
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!-- 日志文件名格式 -->
+            <fileNamePattern>${log.path}/sys-error.%d{yyyy-MM-dd}.log</fileNamePattern>
+			<!-- 日志最大的历史 60天 -->
+			<maxHistory>60</maxHistory>
+        </rollingPolicy>
+        <encoder>
+            <pattern>${log.pattern}</pattern>
+        </encoder>
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <!-- 过滤的级别 -->
+            <level>ERROR</level>
+			<!-- 匹配时的操作:接收(记录) -->
+            <onMatch>ACCEPT</onMatch>
+			<!-- 不匹配时的操作:拒绝(不记录) -->
+            <onMismatch>DENY</onMismatch>
+        </filter>
+    </appender>
+	
+	<!-- 用户访问日志输出  -->
+    <appender name="sys-user" class="ch.qos.logback.core.rolling.RollingFileAppender">
+		<file>${log.path}/sys-user.log</file>
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <!-- 按天回滚 daily -->
+            <fileNamePattern>${log.path}/sys-user.%d{yyyy-MM-dd}.log</fileNamePattern>
+            <!-- 日志最大的历史 60天 -->
+            <maxHistory>60</maxHistory>
+        </rollingPolicy>
+        <encoder>
+            <pattern>${log.pattern}</pattern>
+        </encoder>
+    </appender>
+	
+	<!-- 系统模块日志级别控制  -->
+	<logger name="com.ruoyi" level="info" />
+	<!-- Spring日志级别控制  -->
+	<logger name="org.springframework" level="warn" />
+
+	<root level="info">
+		<appender-ref ref="console" />
+	</root>
+	
+	<!--系统操作日志-->
+    <root level="info">
+        <appender-ref ref="file_info" />
+        <appender-ref ref="file_error" />
+    </root>
+	
+	<!--系统用户操作日志-->
+    <logger name="sys-user" level="info">
+        <appender-ref ref="sys-user"/>
+    </logger>
+</configuration> 

+ 8 - 0
ems/ems-application/pom.xml

@@ -13,6 +13,7 @@
 
     <modules>
         <module>ems-admin</module>
+        <module>ems-collect</module>
     </modules>
     <packaging>pom</packaging>
 
@@ -31,6 +32,7 @@
         <fastjson.version>2.0.53</fastjson.version>
         <oshi.version>6.6.5</oshi.version>
         <commons.io.version>2.13.0</commons.io.version>
+        <commons-collections4.version>4.4</commons-collections4.version>
         <poi.version>4.1.2</poi.version>
         <velocity.version>2.3</velocity.version>
         <jwt.version>0.9.1</jwt.version>
@@ -152,6 +154,12 @@
                 <version>${commons.io.version}</version>
             </dependency>
 
+            <dependency>
+                <groupId>org.apache.commons</groupId>
+                <artifactId>commons-collections4</artifactId>
+                <version>${commons-collections4.version}</version>
+            </dependency>
+
             <!-- excel工具 -->
             <dependency>
                 <groupId>org.apache.poi</groupId>