浏览代码

修复代码

Huanyi 1 周之前
父节点
当前提交
7c715c067c

+ 0 - 2
.gitignore

@@ -47,7 +47,5 @@ nbdist/
 
 .flattened-pom.xml
 
-ruoyi-visual/ruoyi-nacos/src/main/resources/application.properties
-
 logs
 .vscode

+ 101 - 0
ruoyi-common/yingpaipay-common-rabbitmq/src/main/java/org/dromara/common/rabbitmq/config/RabbitMqQueueAutoConfiguration.java

@@ -0,0 +1,101 @@
+package org.dromara.common.rabbitmq.config;
+
+import lombok.extern.slf4j.Slf4j;
+import org.dromara.common.rabbitmq.constants.RabbitMqConstants;
+import org.springframework.amqp.core.Binding;
+import org.springframework.amqp.core.BindingBuilder;
+import org.springframework.amqp.core.DirectExchange;
+import org.springframework.amqp.core.Queue;
+import org.springframework.amqp.rabbit.core.RabbitAdmin;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.beans.factory.ObjectProvider;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.boot.autoconfigure.AutoConfiguration;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.context.annotation.Bean;
+
+/**
+ * RabbitMQ 队列自动声明配置
+ * 服务启动时自动检测队列/交换机/绑定是否已存在,若不存在则自动创建
+ *
+ * @Author: Antigravity
+ */
+@Slf4j
+@AutoConfiguration
+@ConditionalOnClass(RabbitTemplate.class)
+public class RabbitMqQueueAutoConfiguration {
+
+    /**
+     * 应用启动后自动检测并创建 RabbitMQ 队列/交换机/绑定
+     * 使用 ObjectProvider 延迟获取 RabbitAdmin 避免时序问题
+     */
+    @Bean
+    public ApplicationRunner rabbitMqQueueInitializer(ObjectProvider<RabbitAdmin> rabbitAdminProvider) {
+        return args -> {
+            RabbitAdmin rabbitAdmin = rabbitAdminProvider.getIfAvailable();
+            if (rabbitAdmin == null) {
+                log.info("RabbitMQ 未配置,跳过队列初始化");
+                return;
+            }
+            log.info("=== 开始检测 RabbitMQ 队列/交换机/绑定 ===");
+            try {
+                declareExchange(rabbitAdmin);
+                declareQueues(rabbitAdmin);
+                declareBindings(rabbitAdmin);
+                log.info("=== RabbitMQ 队列/交换机/绑定 检测完成 ===");
+            } catch (Exception e) {
+                log.error("RabbitMQ 队列初始化失败,服务将继续启动", e);
+            }
+        };
+    }
+
+    /**
+     * 声明交换机(若已存在则忽略)
+     */
+    private void declareExchange(RabbitAdmin rabbitAdmin) {
+        DirectExchange exchange = new DirectExchange(RabbitMqConstants.ORDER_EXCHANGE, true, false);
+        rabbitAdmin.declareExchange(exchange);
+        log.info("RabbitMQ 交换机已确保存在: {}", RabbitMqConstants.ORDER_EXCHANGE);
+    }
+
+    /**
+     * 声明所有队列(若已存在则忽略)
+     */
+    private void declareQueues(RabbitAdmin rabbitAdmin) {
+        Queue[] queues = {
+            new Queue(RabbitMqConstants.ORDER_QUEUE, true),
+            new Queue(RabbitMqConstants.ORDER_REJECT_QUEUE, true),
+            new Queue(RabbitMqConstants.ORDER_ANOMALY_QUEUE, true),
+            new Queue(RabbitMqConstants.ORDER_APPEAL_QUEUE, true),
+            new Queue(RabbitMqConstants.ORDER_COMPLAINT_QUEUE, true),
+        };
+        for (Queue queue : queues) {
+            rabbitAdmin.declareQueue(queue);
+            log.info("RabbitMQ 队列已确保存在: {}", queue.getName());
+        }
+    }
+
+    /**
+     * 声明所有绑定关系(若已存在则忽略)
+     */
+    private void declareBindings(RabbitAdmin rabbitAdmin) {
+        DirectExchange exchange = new DirectExchange(RabbitMqConstants.ORDER_EXCHANGE, true, false);
+
+        Binding[] bindings = {
+            BindingBuilder.bind(new Queue(RabbitMqConstants.ORDER_QUEUE, true))
+                .to(exchange).with(RabbitMqConstants.ORDER_ROUTING_KEY),
+            BindingBuilder.bind(new Queue(RabbitMqConstants.ORDER_REJECT_QUEUE, true))
+                .to(exchange).with(RabbitMqConstants.ORDER_REJECT_ROUTING_KEY),
+            BindingBuilder.bind(new Queue(RabbitMqConstants.ORDER_ANOMALY_QUEUE, true))
+                .to(exchange).with(RabbitMqConstants.ORDER_ANOMALY_ROUTING_KEY),
+            BindingBuilder.bind(new Queue(RabbitMqConstants.ORDER_APPEAL_QUEUE, true))
+                .to(exchange).with(RabbitMqConstants.ORDER_APPEAL_ROUTING_KEY),
+            BindingBuilder.bind(new Queue(RabbitMqConstants.ORDER_COMPLAINT_QUEUE, true))
+                .to(exchange).with(RabbitMqConstants.ORDER_COMPLAINT_ROUTING_KEY),
+        };
+        for (Binding binding : bindings) {
+            rabbitAdmin.declareBinding(binding);
+            log.info("RabbitMQ 绑定已确保存在: {}", binding.getRoutingKey());
+        }
+    }
+}

+ 27 - 0
ruoyi-common/yingpaipay-common-rabbitmq/src/main/java/org/dromara/common/rabbitmq/constants/RabbitMqConstants.java

@@ -0,0 +1,27 @@
+package org.dromara.common.rabbitmq.constants;
+
+/**
+ * RabbitMQ 队列/交换机/路由键常量
+ * 统一管理所有队列定义,确保各微服务引用一致
+ *
+ * @Author: Antigravity
+ */
+public interface RabbitMqConstants {
+
+    String ORDER_EXCHANGE = "order.exchange";
+
+    String ORDER_QUEUE = "order.notification.queue";
+    String ORDER_ROUTING_KEY = "order.notification";
+
+    String ORDER_REJECT_QUEUE = "order.notification.reject.queue";
+    String ORDER_REJECT_ROUTING_KEY = "order.notification.reject";
+
+    String ORDER_ANOMALY_QUEUE = "order.notification.anomaly.queue";
+    String ORDER_ANOMALY_ROUTING_KEY = "order.notification.anomaly";
+
+    String ORDER_APPEAL_QUEUE = "order.notification.appeal.queue";
+    String ORDER_APPEAL_ROUTING_KEY = "order.notification.appeal";
+
+    String ORDER_COMPLAINT_QUEUE = "order.notification.complaint.queue";
+    String ORDER_COMPLAINT_ROUTING_KEY = "order.notification.complaint";
+}

+ 1 - 0
ruoyi-common/yingpaipay-common-rabbitmq/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports

@@ -1 +1,2 @@
 org.dromara.common.rabbitmq.config.RabbitMqConfig
+org.dromara.common.rabbitmq.config.RabbitMqQueueAutoConfiguration

+ 3 - 2
ruoyi-modules/yingpaipay-fulfiller/src/main/java/org/dromara/fulfiller/service/impl/FlfAnamalyServiceImpl.java

@@ -11,6 +11,7 @@ import org.dromara.common.mybatis.core.page.PageQuery;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
 import org.dromara.common.mybatis.utils.WrapperUtils;
 import org.dromara.common.satoken.utils.LoginHelper;
+import org.dromara.common.rabbitmq.constants.RabbitMqConstants;
 import org.dromara.common.rabbitmq.core.RabbitMqProducer;
 import org.dromara.common.rabbitmq.message.SubOrderAnomalyMessage;
 import org.dromara.fulfiller.domain.FlfAnamaly;
@@ -206,8 +207,8 @@ public class FlfAnamalyServiceImpl implements IFlfAnamalyService {
 
             // 发送消息到交换机
             rabbitMqProducer.sendMessage(
-                "order.exchange",
-                "order.notification.anomaly",
+                RabbitMqConstants.ORDER_EXCHANGE,
+                RabbitMqConstants.ORDER_ANOMALY_ROUTING_KEY,
                 message
             );
         } catch (Exception e) {

+ 3 - 2
ruoyi-modules/yingpaipay-fulfiller/src/main/java/org/dromara/fulfiller/service/impl/FlfComplaintLogServiceImpl.java

@@ -8,6 +8,7 @@ import org.apache.dubbo.config.annotation.DubboReference;
 import org.dromara.common.core.utils.MapstructUtils;
 import org.dromara.common.mybatis.core.page.PageQuery;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
+import org.dromara.common.rabbitmq.constants.RabbitMqConstants;
 import org.dromara.common.rabbitmq.message.ComplaintMessage;
 import org.dromara.common.satoken.utils.LoginHelper;
 import org.dromara.fulfiller.domain.FlfComplaintLog;
@@ -72,8 +73,8 @@ public class FlfComplaintLogServiceImpl implements IFlfComplaintLogService {
             msg.setStoreName("门店");
 
             rabbitTemplate.convertAndSend(
-                "order.exchange",
-                "order.notification.complaint",
+                RabbitMqConstants.ORDER_EXCHANGE,
+                RabbitMqConstants.ORDER_COMPLAINT_ROUTING_KEY,
                 msg
             );
         } catch (Exception e) {

+ 12 - 11
ruoyi-modules/yingpaipay-order/src/main/java/org/dromara/order/config/OrderRabbitMqConfig.java

@@ -1,5 +1,6 @@
 package org.dromara.order.config;
 
+import org.dromara.common.rabbitmq.constants.RabbitMqConstants;
 import org.springframework.amqp.core.Binding;
 import org.springframework.amqp.core.BindingBuilder;
 import org.springframework.amqp.core.DirectExchange;
@@ -19,29 +20,29 @@ public class OrderRabbitMqConfig {
     /**
      * 订单交换机名称
      */
-    public static final String ORDER_EXCHANGE = "order.exchange";
+    public static final String ORDER_EXCHANGE = RabbitMqConstants.ORDER_EXCHANGE;
 
     /**
      * 订单队列名称
      */
-    public static final String ORDER_QUEUE = "order.notification.queue";
+    public static final String ORDER_QUEUE = RabbitMqConstants.ORDER_QUEUE;
 
     /**
      * 订单路由键
      */
-    public static final String ORDER_ROUTING_KEY = "order.notification";
+    public static final String ORDER_ROUTING_KEY = RabbitMqConstants.ORDER_ROUTING_KEY;
 
-    public static final String ORDER_REJECT_QUEUE = "order.notification.reject.queue";
-    public static final String ORDER_REJECT_ROUTING_KEY = "order.notification.reject";
+    public static final String ORDER_REJECT_QUEUE = RabbitMqConstants.ORDER_REJECT_QUEUE;
+    public static final String ORDER_REJECT_ROUTING_KEY = RabbitMqConstants.ORDER_REJECT_ROUTING_KEY;
 
-    public static final String ORDER_ANOMALY_QUEUE = "order.notification.anomaly.queue";
-    public static final String ORDER_ANOMALY_ROUTING_KEY = "order.notification.anomaly";
+    public static final String ORDER_ANOMALY_QUEUE = RabbitMqConstants.ORDER_ANOMALY_QUEUE;
+    public static final String ORDER_ANOMALY_ROUTING_KEY = RabbitMqConstants.ORDER_ANOMALY_ROUTING_KEY;
 
-    public static final String ORDER_APPEAL_QUEUE = "order.notification.appeal.queue";
-    public static final String ORDER_APPEAL_ROUTING_KEY = "order.notification.appeal";
+    public static final String ORDER_APPEAL_QUEUE = RabbitMqConstants.ORDER_APPEAL_QUEUE;
+    public static final String ORDER_APPEAL_ROUTING_KEY = RabbitMqConstants.ORDER_APPEAL_ROUTING_KEY;
 
-    public static final String ORDER_COMPLAINT_QUEUE = "order.notification.complaint.queue";
-    public static final String ORDER_COMPLAINT_ROUTING_KEY = "order.notification.complaint";
+    public static final String ORDER_COMPLAINT_QUEUE = RabbitMqConstants.ORDER_COMPLAINT_QUEUE;
+    public static final String ORDER_COMPLAINT_ROUTING_KEY = RabbitMqConstants.ORDER_COMPLAINT_ROUTING_KEY;
 
     /**
      * 声明订单交换机

+ 231 - 0
ruoyi-visual/ruoyi-nacos/src/main/resources/application.properties

@@ -0,0 +1,231 @@
+#
+# Copyright 1999-2018 Alibaba Group Holding Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+#*************** Spring Boot Related Configurations ***************#
+
+### Default web context path:
+server.servlet.contextPath=/nacos
+### Include message field
+server.error.include-message=ALWAYS
+### Default web server port:
+server.port=8848
+
+#*************** Network Related Configurations ***************#
+### If prefer hostname over ip for Nacos server addresses in cluster.conf:
+# nacos.inetutils.prefer-hostname-over-ip=false
+
+### Specify local server's IP:
+nacos.inetutils.ip-address=@nacos.ip@
+
+spring.application.name=ruoyi-nacos
+#*************** Config Module Related Configurations ***************#
+### Deprecated configuration property, it is recommended to use `spring.sql.init.platform` replaced.
+# spring.datasource.platform=mysql
+nacos.plugin.datasource.log.enabled=true
+spring.sql.init.platform=mysql
+### Count of DB:
+db.num=1
+
+### Connect URL of DB:
+## Development
+
+# Local
+#db.url.0=jdbc:mysql://127.0.0.1:3306/pet_system_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
+#db.user.0=root
+#db.password.0=1234
+
+# Test
+db.url.0=jdbc:mysql://111.228.46.254:3306/pet_system_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
+db.user.0=root
+db.password.0=Yr888888
+
+## Production
+#db.url.0=jdbc:mysql://127.0.0.1:3306/pet_system_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
+#db.user.0=root
+#db.password.0=Yr7777777
+
+### the maximum retry times for push
+nacos.config.push.maxRetryTime=50
+
+#*************** Naming Module Related Configurations ***************#
+
+### If enable data warmup. If set to false, the server would accept request without local data preparation:
+# nacos.naming.data.warmup=true
+
+### If enable the instance auto expiration, kind like of health check of instance:
+# nacos.naming.expireInstance=true
+
+nacos.naming.empty-service.auto-clean=true
+nacos.naming.empty-service.clean.initial-delay-ms=50000
+nacos.naming.empty-service.clean.period-time-ms=30000
+
+
+#*************** CMDB Module Related Configurations ***************#
+### The interval to dump external CMDB in seconds:
+# nacos.cmdb.dumpTaskInterval=3600
+
+### The interval of polling data change event in seconds:
+# nacos.cmdb.eventTaskInterval=10
+
+### The interval of loading labels in seconds:
+# nacos.cmdb.labelTaskInterval=300
+
+### If turn on data loading task:
+# nacos.cmdb.loadDataAtStart=false
+
+
+#*************** Metrics Related Configurations ***************#
+# 指向 ruoyi-monitor 监控
+spring.boot.admin.client.url=http://127.0.0.1:9100
+spring.boot.admin.client.username=ruoyi
+spring.boot.admin.client.password=123456
+spring.boot.admin.client.instance.service-host-type=IP
+spring.boot.admin.client.instance.metadata.username=${spring.boot.admin.client.username}
+spring.boot.admin.client.instance.metadata.userpassword=${spring.boot.admin.client.password}
+
+### Metrics for prometheus
+management.endpoints.web.exposure.include=*
+
+### Metrics for elastic search
+management.metrics.export.elastic.enabled=false
+#management.metrics.export.elastic.host=http://localhost:9200
+
+### Metrics for influx
+management.metrics.export.influx.enabled=false
+#management.metrics.export.influx.db=springboot
+#management.metrics.export.influx.uri=http://localhost:8086
+#management.metrics.export.influx.auto-create-db=true
+#management.metrics.export.influx.consistency=one
+#management.metrics.export.influx.compressed=true
+
+#*************** Access Control Related Configurations ***************#
+### If enable spring security, this option is deprecated in 1.2.0:
+#spring.security.enabled=false
+
+### The ignore urls of auth, is deprecated in 1.2.0:
+nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-ui/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**
+
+### The auth system to use, currently only 'nacos' and 'ldap' is supported:
+nacos.core.auth.system.type=nacos
+
+### If turn on auth system:
+nacos.core.auth.enabled=true
+
+### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay.
+nacos.core.auth.caching.enabled=true
+
+### Since 1.4.1, Turn on/off white auth for user-agent: nacos-server, only for upgrade from old version.
+nacos.core.auth.enable.userAgentAuthWhite=false
+
+### Since 1.4.1, worked when nacos.core.auth.enabled=true and nacos.core.auth.enable.userAgentAuthWhite=false.
+### The two properties is the white list for auth and used by identity the request from other server.
+### 此处为用户名密码 需要自行修改
+nacos.core.auth.server.identity.key=ruoyi-vue-plus-key
+nacos.core.auth.server.identity.value=ruoyi-vue-plus-value
+
+### worked when nacos.core.auth.system.type=nacos
+### The token expiration in seconds:
+nacos.core.auth.plugin.nacos.token.cache.enable=false
+nacos.core.auth.plugin.nacos.token.expire.seconds=18000
+### The default token (Base64 string):
+#nacos.core.auth.plugin.nacos.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789
+### 此处为token密钥 需要自行修改
+nacos.core.auth.plugin.nacos.token.secret.key=rE7bYayhpvduYwCxuhckybEPDXyna6xwm5m7MZjtjrdXjVxAbXAMccXHyaJvB346
+
+### worked when nacos.core.auth.system.type=ldap,{0} is Placeholder,replace login username
+#nacos.core.auth.ldap.url=ldap://localhost:389
+#nacos.core.auth.ldap.basedc=dc=example,dc=org
+#nacos.core.auth.ldap.userDn=cn=admin,${nacos.core.auth.ldap.basedc}
+#nacos.core.auth.ldap.password=admin
+#nacos.core.auth.ldap.userdn=cn={0},dc=example,dc=org
+#nacos.core.auth.ldap.filter.prefix=uid
+#nacos.core.auth.ldap.case.sensitive=true
+#nacos.core.auth.ldap.ignore.partial.result.exception=false
+
+#*************** Control Plugin Related Configurations ***************#
+# plugin type
+#nacos.plugin.control.manager.type=nacos
+
+# local control rule storage dir, default ${nacos.home}/data/connection and ${nacos.home}/data/tps
+#nacos.plugin.control.rule.local.basedir=${nacos.home}
+
+# external control rule storage type, if exist
+#nacos.plugin.control.rule.external.storage=
+
+#*************** Config Change Plugin Related Configurations ***************#
+# webhook
+#nacos.core.config.plugin.webhook.enabled=false
+# It is recommended to use EB https://help.aliyun.com/document_detail/413974.html
+#nacos.core.config.plugin.webhook.url=http://localhost:8080/webhook/send?token=***
+# The content push max capacity ,byte
+#nacos.core.config.plugin.webhook.contentMaxCapacity=102400
+
+# whitelist
+#nacos.core.config.plugin.whitelist.enabled=false
+# The import file suffixs
+#nacos.core.config.plugin.whitelist.suffixs=xml,text,properties,yaml,html
+# fileformatcheck,which validate the import file of type and content
+#nacos.core.config.plugin.fileformatcheck.enabled=false
+#*************** Istio Related Configurations ***************#
+### If turn on the MCP server:
+nacos.istio.mcp.server.enabled=false
+
+
+
+###*************** Add from 1.3.0 ***************###
+
+
+#*************** Core Related Configurations ***************#
+
+### set the WorkerID manually
+# nacos.core.snowflake.worker-id=
+
+### Member-MetaData
+# nacos.core.member.meta.site=
+# nacos.core.member.meta.adweight=
+# nacos.core.member.meta.weight=
+
+### MemberLookup
+### Addressing pattern category, If set, the priority is highest
+# nacos.core.member.lookup.type=[file,address-server]
+## Set the cluster list with a configuration file or command-line argument
+# nacos.member.list=192.168.16.101:8847?raft_port=8807,192.168.16.101?raft_port=8808,192.168.16.101:8849?raft_port=8809
+## for AddressServerMemberLookup
+# Maximum number of retries to query the address server upon initialization
+# nacos.core.address-server.retry=5
+## Server domain name address of [address-server] mode
+# address.server.domain=jmenv.tbsite.net
+## Server port of [address-server] mode
+# address.server.port=8080
+## Request address of [address-server] mode
+# address.server.url=/nacos/serverlist
+
+#*************** JRaft Related Configurations ***************#
+
+### Sets the Raft cluster election timeout, default value is 5 second
+# nacos.core.protocol.raft.data.election_timeout_ms=5000
+### Sets the amount of time the Raft snapshot will execute periodically, default is 30 minute
+# nacos.core.protocol.raft.data.snapshot_interval_secs=30
+### raft internal worker threads
+# nacos.core.protocol.raft.data.core_thread_num=8
+### Number of threads required for raft business request processing
+# nacos.core.protocol.raft.data.cli_service_thread_num=4
+### raft linear read strategy. Safe linear reads are used by default, that is, the Leader tenure is confirmed by heartbeat
+# nacos.core.protocol.raft.data.read_index_type=ReadOnlySafe
+### rpc request timeout, default 5 seconds
+# nacos.core.protocol.raft.data.rpc_request_timeout_ms=5000
+### enable to support prometheus service discovery
+#nacos.prometheus.metrics.enabled=true