8.7 微服务调用改为dubbo,但保留原来的http调用形式

This commit is contained in:
zhangsan 2025-08-07 16:10:02 +08:00
parent 27f009b375
commit 71690bfac5
8 changed files with 255 additions and 169 deletions

View File

@ -1,65 +0,0 @@
/*
Navicat Premium Data Transfer
Source Server : group_buy_local
Source Server Type : MySQL
Source Server Version : 80042
Source Host : localhost:13306
Source Schema : pay-mall
Target Server Type : MySQL
Target Server Version : 80042
File Encoding : 65001
Date: 16/07/2025 17:08:44
*/
-- 如果存在,则删除旧的数据库
DROP DATABASE IF EXISTS `pay-mall`;
-- 创建新的数据库(可根据需要指定字符集和排序规则)
CREATE DATABASE `pay-mall`
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
-- 切换到新创建的数据库
USE `pay-mall`;
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for pay_order
-- ----------------------------
DROP TABLE IF EXISTS `pay_order`;
CREATE TABLE `pay_order` (
`id` int UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '自增ID',
`user_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '用户ID',
`product_id` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '商品ID',
`product_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '商品名称',
`order_id` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '订单ID',
`order_time` datetime NOT NULL COMMENT '下单时间',
`total_amount` decimal(8, 2) UNSIGNED NULL DEFAULT NULL COMMENT '订单金额',
`status` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '订单状态create-创建完成、pay_wait-等待支付、pay_success-支付成功、deal_done-交易完成、close-订单关单',
`pay_url` varchar(2014) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '支付信息',
`pay_time` datetime NULL DEFAULT NULL COMMENT '支付时间',
`market_type` tinyint(1) NULL DEFAULT NULL COMMENT '营销类型0无营销、1拼团营销',
`market_deduction_amount` decimal(8, 2) NULL DEFAULT NULL COMMENT '营销金额;优惠金额',
`pay_amount` decimal(8, 2) NOT NULL COMMENT '支付金额',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `uq_order_id`(`order_id` ASC) USING BTREE,
INDEX `idx_user_id_product_id`(`user_id` ASC, `product_id` ASC) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 35 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of pay_order
-- ----------------------------
INSERT INTO `pay_order` VALUES (36, 'opEtBvq6go0co-HQC5DSHkKfkdds', '9890001', 'MyBatisBook', '498873906342', '2025-07-16 15:53:11', 100.00, 'DEAL_DONE', '<form name=\"punchout_form\" method=\"post\" action=\"https://openapi-sandbox.dl.alipaydev.com/gateway.do?charset=utf-8&method=alipay.trade.page.pay&sign=YHURFlD5GRayv1bHAezkCE0W%2BJbS5l4pxwR2eH9k6SLfes2DozLEVvgo3H28mMNTRw1EK6lc%2FN56HUvBOTD4DNtpQ72d3S4v51v%2FqV1%2FxPHIC9HDAQD%2FTTTln6ZjRzLSkWQxRn7aQOBiVhTplu7B%2BBkPKIpIEwWsKtlI0GSCM7%2BE9dQdKrv9BYLD9eAGIJNhL%2FRC3Fu1CkbvhyMPmCxkjkH1vrbx5tmeeWXfOaMkXmR3vePVE9f4xcZgKHiYcBPdaSO%2Brs4uzskw9idRwUzL1xX%2BZElA2hZGCtgXCYz40MVsWiPiwT0voUQcbFE48ZfobOAzKtmpfgILFF2p3qLoFQ%3D%3D&return_url=https%3A%2F%2Fblog.bitday.top&notify_url=https%3A%2F%2Fpay.bitday.top%2Fapi%2Fv1%2Falipay%2Falipay_notify_url&version=1.0&app_id=9021000150645052&sign_type=RSA2&timestamp=2025-07-16+15%3A53%3A11&alipay_sdk=alipay-sdk-java-4.38.157.ALL&format=json\">\n<input type=\"hidden\" name=\"biz_content\" value=\"{&quot;out_trade_no&quot;:&quot;498873906342&quot;,&quot;total_amount&quot;:80.00,&quot;subject&quot;:&quot;MyBatisBook&quot;,&quot;product_code&quot;:&quot;FAST_INSTANT_TRADE_PAY&quot;}\">\n<input type=\"submit\" value=\"立即支付\" style=\"display:none\" >\n</form>\n<script>document.forms[0].submit();</script>', '2025-07-16 15:54:03', 1, 20.00, 80.00, '2025-07-16 15:53:11', '2025-07-16 16:44:47');
INSERT INTO `pay_order` VALUES (39, 'smile01', '9890001', 'MyBatisBook', '369511405849', '2025-07-16 16:28:58', 100.00, 'PAY_SUCCESS', '<form name=\"punchout_form\" method=\"post\" action=\"https://openapi-sandbox.dl.alipaydev.com/gateway.do?charset=utf-8&method=alipay.trade.page.pay&sign=O11ikCcaT503aUwewmNj71Y6PZ5IsqAQ3vqrJK3bCahFJe9KmWbAYMkO91%2FGrCmkmekZ%2Bl2wL85OS4IPNlAMRKmtOhRC22VyqHFjhFaLCr5zzQjvoWgFWMOiAt33x8cdeLvi1RW7nQ66ll1SEi33syInH154TO3MrqTMmLGIPdMvXDmz%2FyfmSQ5h6ZQdN9aaSdFSTR8q%2BFgcvGMSVJSTAog%2BJbMHwsRxZXqlFI8LX8%2Fsh7fRoM87l8Ws1jAKRm6BS6sRgbfmEOdtJRO95Uc2LYLVT817%2B3Fvll2B8KwkSa66Ar2Oo6s6emCQJl3IG67TcA5%2FdPhtyYFtFsqSbpAqQw%3D%3D&return_url=https%3A%2F%2Fblog.bitday.top&notify_url=https%3A%2F%2Fpay.bitday.top%2Fapi%2Fv1%2Falipay%2Falipay_notify_url&version=1.0&app_id=9021000150645052&sign_type=RSA2&timestamp=2025-07-16+16%3A28%3A59&alipay_sdk=alipay-sdk-java-4.38.157.ALL&format=json\">\n<input type=\"hidden\" name=\"biz_content\" value=\"{&quot;out_trade_no&quot;:&quot;369511405849&quot;,&quot;total_amount&quot;:80.00,&quot;subject&quot;:&quot;MyBatisBook&quot;,&quot;product_code&quot;:&quot;FAST_INSTANT_TRADE_PAY&quot;}\">\n<input type=\"submit\" value=\"立即支付\" style=\"display:none\" >\n</form>\n<script>document.forms[0].submit();</script>', '2025-07-16 16:30:33', 1, 20.00, 80.00, '2025-07-16 16:28:57', '2025-07-16 16:30:33');
INSERT INTO `pay_order` VALUES (40, 'smile01', '9890001', 'MyBatisBook', '698481154046', '2025-07-16 16:34:25', 100.00, 'DEAL_DONE', '<form name=\"punchout_form\" method=\"post\" action=\"https://openapi-sandbox.dl.alipaydev.com/gateway.do?charset=utf-8&method=alipay.trade.page.pay&sign=nCszW8W%2F%2Fyhu7x9uPcJJmKv8gYoayqFmqLojw8Q%2BDt2bI5OqBKyoZhT61rdexukp%2BLtvZcWOxJ8sDN%2Bf4Zq8FUvb7uxCsWaD7HWTlgm5KXdSc%2BEVawudxr8aWd16ZRI69WDCGiAvKCgTkX20me2%2Bnv2sdHBd2p7G%2FdkhMtVpMPQHxu4a%2BCQ%2Fatlb2JU1qT1GK0SGglQjtQQpb9mNJIIS5NTf2rGF5%2BIB%2BGWU%2Fj0tGl5ney6ZhxuEnRJzIbrgz6riYOsvhguntMIZxws1%2F8ZakrGE2MYsjesahI8v6eaNAJij2jjkLqX40jrleFwLGMZvidRPgOnpr4z3q5n%2FEFo5dQ%3D%3D&return_url=https%3A%2F%2Fblog.bitday.top&notify_url=https%3A%2F%2Fpay.bitday.top%2Fapi%2Fv1%2Falipay%2Falipay_notify_url&version=1.0&app_id=9021000150645052&sign_type=RSA2&timestamp=2025-07-16+16%3A34%3A25&alipay_sdk=alipay-sdk-java-4.38.157.ALL&format=json\">\n<input type=\"hidden\" name=\"biz_content\" value=\"{&quot;out_trade_no&quot;:&quot;698481154046&quot;,&quot;total_amount&quot;:100.00,&quot;subject&quot;:&quot;MyBatisBook&quot;,&quot;product_code&quot;:&quot;FAST_INSTANT_TRADE_PAY&quot;}\">\n<input type=\"submit\" value=\"立即支付\" style=\"display:none\" >\n</form>\n<script>document.forms[0].submit();</script>', '2025-07-16 16:35:36', 0, 0.00, 100.00, '2025-07-16 16:34:24', '2025-07-16 16:35:36');
INSERT INTO `pay_order` VALUES (41, 'smile02', '9890001', 'MyBatisBook', '541129857040', '2025-07-16 16:36:49', 100.00, 'DEAL_DONE', '<form name=\"punchout_form\" method=\"post\" action=\"https://openapi-sandbox.dl.alipaydev.com/gateway.do?charset=utf-8&method=alipay.trade.page.pay&sign=Ot5z8oK7xO7jmA2pzCnVkE32AdUjurl9YPuSgNwtWjI433Ki5ZAuvhxFfW2V6N20JQPYiGA%2FFYwlgPZ2V53DfeYEDwTZ9yXyJ9ZL74J6kUWGsotnp53JUQZkTTTMT6uBIsl2r2lt5YeLo3GvOkTdxBqxpow%2F%2F8ZxvY6xi9IIN5DGQ8inhwNR8p3rAJS82PKHKFHImNeYg51pUPtU0cqJzrXeN4bT0EincERBhT7j6pcvvRjrPDX9VgSRdwtp5duQC2I9PabqihLVXhAMwhafcKkSRPrYVlJmUgedtYw2Z7Y74CTjgMdYuEKznRsEGvabqUCP2nQ2lWssVTsmJ35cJQ%3D%3D&return_url=https%3A%2F%2Fblog.bitday.top&notify_url=https%3A%2F%2Fpay.bitday.top%2Fapi%2Fv1%2Falipay%2Falipay_notify_url&version=1.0&app_id=9021000150645052&sign_type=RSA2&timestamp=2025-07-16+16%3A36%3A49&alipay_sdk=alipay-sdk-java-4.38.157.ALL&format=json\">\n<input type=\"hidden\" name=\"biz_content\" value=\"{&quot;out_trade_no&quot;:&quot;541129857040&quot;,&quot;total_amount&quot;:80.00,&quot;subject&quot;:&quot;MyBatisBook&quot;,&quot;product_code&quot;:&quot;FAST_INSTANT_TRADE_PAY&quot;}\">\n<input type=\"submit\" value=\"立即支付\" style=\"display:none\" >\n</form>\n<script>document.forms[0].submit();</script>', '2025-07-16 16:38:05', 1, 20.00, 80.00, '2025-07-16 16:36:49', '2025-07-16 16:44:47');
INSERT INTO `pay_order` VALUES (42, 'smile04', '9890001', 'MyBatisBook', '381698719384', '2025-07-16 16:43:47', 100.00, 'DEAL_DONE', '<form name=\"punchout_form\" method=\"post\" action=\"https://openapi-sandbox.dl.alipaydev.com/gateway.do?charset=utf-8&method=alipay.trade.page.pay&sign=MN1%2F2PVMYwkEB4VE3SKphhG95QQUGlMeOwN5PwfNd1C4rdGo4PWJpBor5G3FfuHknCcugcwwQ09zhAljDG6ZxggkzwPvkh04zv5eWuWfIXXIl%2Bzj5onXv6rVvElzL1BFUJ8UxpdgjNNFVWQJVLndHA0WuAB4ZQ0W9c4Jew%2FMd1Gd3p7HzESC16Wcy1zMxg%2FSUPSjORA9Cmf2jrT1RqDAy2Sj%2FNZriEByMlX0rIz44LFCciDLBVo3JzYmshOoU%2FtDwSLn3Ob9WMlLRaKmae8X4bSzCesYbEvEmlN9jl9Mc3MN4hJ0RZ8%2FpC%2B9xk6%2FNKNW1VROTzg801iLhxUK0vAc0g%3D%3D&return_url=https%3A%2F%2Fblog.bitday.top&notify_url=https%3A%2F%2Fpay.bitday.top%2Fapi%2Fv1%2Falipay%2Falipay_notify_url&version=1.0&app_id=9021000150645052&sign_type=RSA2&timestamp=2025-07-16+16%3A43%3A47&alipay_sdk=alipay-sdk-java-4.38.157.ALL&format=json\">\n<input type=\"hidden\" name=\"biz_content\" value=\"{&quot;out_trade_no&quot;:&quot;381698719384&quot;,&quot;total_amount&quot;:80.00,&quot;subject&quot;:&quot;MyBatisBook&quot;,&quot;product_code&quot;:&quot;FAST_INSTANT_TRADE_PAY&quot;}\">\n<input type=\"submit\" value=\"立即支付\" style=\"display:none\" >\n</form>\n<script>document.forms[0].submit();</script>', '2025-07-16 16:44:47', 1, 20.00, 80.00, '2025-07-16 16:43:46', '2025-07-16 16:44:47');
INSERT INTO `pay_order` VALUES (45, 'smile04', '9890001', 'MyBatisBook', '380924838419', '2025-07-16 16:54:06', 100.00, 'DEAL_DONE', '<form name=\"punchout_form\" method=\"post\" action=\"https://openapi-sandbox.dl.alipaydev.com/gateway.do?charset=utf-8&method=alipay.trade.page.pay&sign=SsZLFKzuRwKy%2BfH71Qr%2BhpHFi1zoDdb11O7Exl08xstV628NGoRTBzUeLiZqJWAmlCo6CA4y%2F5SLVdE1shz%2FOPYRJfvRvxIkBbn8qfH79bJyMcd3BIt3ETPPMJSHDZ9mWU1HEAhP4n5rsKBRZHG0mjo%2BxQdoApF6pAwqXBXK6xs9McrV9c%2BC77vMlQ7yMTY6LT9uYmNsFoxekbXYXswMLmiEBX2F%2BNXw77RUKhA0jlMuM1xEydy5LrNaukXgrnS9wLORosTNDRvZnvf4TIk4ln1IYFDYz2WMfLO658bXdvVDW2huxWCqn6Br9VX3I6hj6AXSnSVd7HswstXZACiieQ%3D%3D&return_url=https%3A%2F%2Fblog.bitday.top&notify_url=https%3A%2F%2Fpay.bitday.top%2Fapi%2Fv1%2Falipay%2Falipay_notify_url&version=1.0&app_id=9021000150645052&sign_type=RSA2&timestamp=2025-07-16+16%3A54%3A05&alipay_sdk=alipay-sdk-java-4.38.157.ALL&format=json\">\n<input type=\"hidden\" name=\"biz_content\" value=\"{&quot;out_trade_no&quot;:&quot;380924838419&quot;,&quot;total_amount&quot;:100.00,&quot;subject&quot;:&quot;MyBatisBook&quot;,&quot;product_code&quot;:&quot;FAST_INSTANT_TRADE_PAY&quot;}\">\n<input type=\"submit\" value=\"立即支付\" style=\"display:none\" >\n</form>\n<script>document.forms[0].submit();</script>', '2025-07-16 16:55:14', 0, 0.00, 100.00, '2025-07-16 16:54:05', '2025-07-16 16:55:14');
SET FOREIGN_KEY_CHECKS = 1;

View File

@ -0,0 +1,50 @@
/*
Navicat Premium Data Transfer
Source Server : group_buy_local
Source Server Type : MySQL
Source Server Version : 80042
Source Host : localhost:13306
Source Schema : pay-mall
Target Server Type : MySQL
Target Server Version : 80042
File Encoding : 65001
Date: 07/08/2025 16:04:33
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for pay_order
-- ----------------------------
DROP TABLE IF EXISTS `pay_order`;
CREATE TABLE `pay_order` (
`id` int UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '自增ID',
`user_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '用户ID',
`product_id` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '商品ID',
`product_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '商品名称',
`order_id` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '订单ID',
`order_time` datetime NOT NULL COMMENT '下单时间',
`total_amount` decimal(8, 2) UNSIGNED NULL DEFAULT NULL COMMENT '订单金额',
`status` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '订单状态create-创建完成、pay_wait-等待支付、pay_success-支付成功、deal_done-交易完成、close-订单关单',
`pay_url` varchar(2014) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '支付信息',
`pay_time` datetime NULL DEFAULT NULL COMMENT '支付时间',
`market_type` tinyint(1) NULL DEFAULT NULL COMMENT '营销类型0无营销、1拼团营销',
`market_deduction_amount` decimal(8, 2) NULL DEFAULT NULL COMMENT '营销金额;优惠金额',
`pay_amount` decimal(8, 2) NOT NULL COMMENT '支付金额',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `uq_order_id`(`order_id` ASC) USING BTREE,
INDEX `idx_user_id_product_id`(`user_id` ASC, `product_id` ASC) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 46 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of pay_order
-- ----------------------------
INSERT INTO `pay_order` VALUES (49, 'smile01', '9890001', 'MyBatisBook', '651958626376', '2025-08-07 16:03:13', 100.00, 'PAY_SUCCESS', '<form name=\"punchout_form\" method=\"post\" action=\"https://openapi-sandbox.dl.alipaydev.com/gateway.do?charset=utf-8&method=alipay.trade.page.pay&sign=A27cwepfWTkwyKG1o2dIrJg8O8cBdIUzOHzN8dtc2A0G4qVG8Z5UULUn25VSSz0zODhOu5H%2FWWc9RGJMlyREHrQ5up2f6PqMH%2FUOulBgBWdmm6ob3qo8lEGExhSeN%2B0jDzfCmS3nql88IU4rgWgl8BTwmliwDIHzVa7MZZyY2U3LWWAVYLw8guKcJYs%2FQf79GzTnx7yroJdFBuxC6XQ15cOdexrW%2F0Bz4ylKmPf0u6Cu5sMZ4Kw3fLd1t29igOPxFrb4stiYpJ6LLJxGnpcYyAbiqIGj%2B7IwR9M877QrGh9jhD8%2FchbuiYykx%2BLpzoFPDktKH2NQA88lPq84SbkwBw%3D%3D&return_url=http%3A%2F%2Flocalhost%3A63342%2Fgroup-buying-sys%2Fdocs%2Fdev-ops%2Fnginx%2Fhtml%2Findex.html&notify_url=http%3A%2F%2F127.0.0.1%3A8092%2Fapi%2Fv1%2Falipay%2Falipay_notify_url&version=1.0&app_id=9021000150645052&sign_type=RSA2&timestamp=2025-08-07+16%3A03%3A13&alipay_sdk=alipay-sdk-java-4.38.157.ALL&format=json\">\n<input type=\"hidden\" name=\"biz_content\" value=\"{&quot;out_trade_no&quot;:&quot;651958626376&quot;,&quot;total_amount&quot;:80.00,&quot;subject&quot;:&quot;MyBatisBook&quot;,&quot;product_code&quot;:&quot;FAST_INSTANT_TRADE_PAY&quot;}\">\n<input type=\"submit\" value=\"立即支付\" style=\"display:none\" >\n</form>\n<script>document.forms[0].submit();</script>', '2025-08-07 16:04:20', 1, 20.00, 80.00, '2025-08-07 16:03:13', '2025-08-07 16:04:20');
SET FOREIGN_KEY_CHECKS = 1;

View File

@ -1,5 +1,6 @@
package edu.whut;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@ -8,6 +9,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@Configurable
@EnableScheduling
@EnableDubbo(scanBasePackages = "edu.whut.infrastructure")
public class Application {
public static void main(String[] args){

View File

@ -15,7 +15,8 @@ app:
notify-type: MQ
source: s01
chanel: c01
rpc:
mode: DUBBO
# 线程池配置
thread:
pool:
@ -84,12 +85,31 @@ spring:
routing_key: topic.order_pay_success
# 消费队列
queue: pay_mall_queue_2_order_pay_success
topic_team_refund:
# 绑定交换机 - 消息提供者的交换机
exchange: group_buy_market_exchange
# 消息主题
routing_key: topic.team_refund
# 消费队列
queue: s_pay_mall_queue_2_topic_team_refund
# MyBatis 配置【如需使用记得打开】
mybatis:
mapper-locations: classpath:/mybatis/mapper/*.xml
config-location: classpath:/mybatis/config/mybatis-config.xml
dubbo:
application:
name: pay-mall-service # 换成各自服务名
registry:
address: nacos://localhost:8848 # 远程环境写内网地址
# username/password 如果 Nacos 开了鉴权
protocol:
name: dubbo
consumer:
timeout: 3000 # 毫秒
check: false # 忽略启动时服务是否可用
# 微信公众号对接
weixin:
config:

View File

@ -43,6 +43,15 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
</dependency>
<!-- Nacos 注册中心扩展 -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-nacos</artifactId>
</dependency>
<!-- 系统模块 -->
<dependency>
<groupId>edu.whut</groupId>

View File

@ -1,28 +1,39 @@
package edu.whut.infrastructure.adapter.port;
import com.alibaba.fastjson.JSON;
import edu.whut.api.IMarketTradeService; // Dubbo 接口
import edu.whut.api.dto.*;
import edu.whut.api.response.Response;
import edu.whut.domain.order.adapter.port.IProductPort;
import edu.whut.domain.order.model.entity.MarketPayDiscountEntity;
import edu.whut.domain.order.model.entity.ProductEntity;
import edu.whut.infrastructure.gateway.IGroupBuyMarketService;
import edu.whut.infrastructure.gateway.IGroupBuyMarketService; // Retrofit 接口
import edu.whut.infrastructure.gateway.ProductRPC;
import edu.whut.infrastructure.gateway.dto.ProductDTO;
import edu.whut.types.exception.AppException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import retrofit2.Call;
import java.util.Date;
/**
* 商品与营销交易的适配层同时支持 Retrofit(HTTP) Dubbo(RPC)
* 通过配置属性 <pre>app.rpc.mode</pre> 动态切换调用通道
* <ul>
* <li>DUBBO 默认采用 Dubbo + Nacos</li>
* <li>HTTP 走原 Retrofit HTTP 调用</li>
* </ul>
*/
@Component
@RequiredArgsConstructor
@Slf4j
public class ProductPort implements IProductPort {
/* -------------------- 公共配置 -------------------- */
@Value("${app.config.group-buy-market.source}")
private String source;
@Value("${app.config.group-buy-market.chanel}")
@ -30,20 +41,28 @@ public class ProductPort implements IProductPort {
@Value("${app.config.group-buy-market.notify-url}")
private String notifyUrl;
@Value("${app.config.group-buy-market.notify-type}")
private String notifyType; //http or mq
private final IGroupBuyMarketService groupBuyMarketService;
private String notifyType; // HTTP or MQ
/* rpc.mode = DUBBO / HTTP缺省 DUBBO */
@Value("${app.rpc.mode:DUBBO}")
private String rpcMode;
/* -------------------- Retrofit 客户端 -------------------- */
private final IGroupBuyMarketService retrofitService;
/* -------------------- Dubbo 客户端 -------------------- */
@DubboReference(version = "1.0.0", check = false)
private final IMarketTradeService dubboService;
/* -------------------- 产品 RPC -------------------- */
private final ProductRPC productRPC;
/**
* 根据产品ID查询基础商品信息
*/
/* ============================================================ */
/* 商品查询接口 */
/* ============================================================ */
@Override
public ProductEntity queryProductByProductId(String productId) {
// 调用远程产品服务获取 DTO
ProductDTO dto = productRPC.queryProductByProductId(productId);
// 转换为领域实体并返回
return ProductEntity.builder()
.productId(dto.getProductId())
.productName(dto.getProductName())
@ -52,112 +71,156 @@ public class ProductPort implements IProductPort {
.build();
}
/**
* 发起营销锁单请求获取拼团优惠信息
*/
/* ============================================================ */
/* 营销锁单 */
/* ============================================================ */
@Override
public MarketPayDiscountEntity lockMarketPayOrder(String userId, String teamId, Long activityId, String productId, String orderId) {
// 请求参数
LockMarketPayOrderRequestDTO requestDTO = new LockMarketPayOrderRequestDTO();
requestDTO.setUserId(userId);
requestDTO.setTeamId(teamId);
requestDTO.setGoodsId(productId);
requestDTO.setActivityId(activityId);
requestDTO.setSource(source);
requestDTO.setChannel(chanel);
//拼团的外部交易单号等于支付系统的订单号
requestDTO.setOutTradeNo(orderId);
// 根据配置决定用 HTTP 回调还是 MQ
if ("HTTP".equalsIgnoreCase(notifyType)) {
requestDTO.setNotifyUrl(notifyUrl);
} else {
requestDTO.setNotifyMQ();
}
try {
// 发起 HTTP 请求执行营销锁单
Call<Response<LockMarketPayOrderResponseDTO>> call = groupBuyMarketService.lockMarketPayOrder(requestDTO);
// 获取结果
Response<LockMarketPayOrderResponseDTO> response = call.execute().body();
log.info("营销锁单{} requestDTO:{} responseDTO:{}", userId, JSON.toJSONString(requestDTO), JSON.toJSONString(response));
if (null == response) return null;
// 异常判断
if (!"0000".equals(response.getCode())){
throw new AppException(response.getCode(), response.getInfo());
}
LockMarketPayOrderResponseDTO responseDTO = response.getData();
// 获取拼团优惠
return MarketPayDiscountEntity.builder()
.originalPrice(responseDTO.getOriginalPrice())
.deductionPrice(responseDTO.getDeductionPrice())
.payPrice(responseDTO.getPayPrice())
.build();
} catch (Exception e) {
log.error("营销锁单失败{}", userId, e);
return null;
}
public MarketPayDiscountEntity lockMarketPayOrder(String userId,
String teamId,
Long activityId,
String productId,
String orderId) {
LockMarketPayOrderRequestDTO req = buildLockReq(userId, teamId, activityId, productId, orderId);
Response<LockMarketPayOrderResponseDTO> resp = invoke("lockMarketPayOrder", req);
LockMarketPayOrderResponseDTO data = resp.getData();
return MarketPayDiscountEntity.builder()
.originalPrice(data.getOriginalPrice())
.deductionPrice(data.getDeductionPrice())
.payPrice(data.getPayPrice())
.build();
}
/**
* 发起拼团系统的营销结算
*/
/* ============================================================ */
/* 营销结算 */
/* ============================================================ */
@Override
public void settlementMarketPayOrder(String userId, String orderId, Date orderTime) {
SettlementMarketPayOrderRequestDTO requestDTO = new SettlementMarketPayOrderRequestDTO();
requestDTO.setSource(source);
requestDTO.setChannel(chanel);
requestDTO.setUserId(userId);
requestDTO.setOutTradeNo(orderId);
requestDTO.setOutTradeTime(orderTime);
try {
Call<Response<SettlementMarketPayOrderResponseDTO>> call = groupBuyMarketService.settlementMarketPayOrder(requestDTO);
// 获取结果
Response<SettlementMarketPayOrderResponseDTO> response = call.execute().body();
log.info("营销结算{} requestDTO:{} responseDTO:{}", userId, JSON.toJSONString(requestDTO), JSON.toJSONString(response));
if (null == response) return;
// 异常判断
if (!"0000".equals(response.getCode())) {
log.info("营销结算返回code={}, info={}", response.getCode(), response.getInfo());
throw new AppException(response.getCode(), response.getInfo());
}
} catch (Exception e) {
log.error("营销结算失败 {}", userId, e);
}
SettlementMarketPayOrderRequestDTO req = new SettlementMarketPayOrderRequestDTO();
req.setSource(source);
req.setChannel(chanel);
req.setUserId(userId);
req.setOutTradeNo(orderId);
req.setOutTradeTime(orderTime);
invoke("settlementMarketPayOrder", req);
}
/* ============================================================ */
/* 营销退单 */
/* ============================================================ */
@Override
public void refundMarketPayOrder(String userId, String orderId) {
RefundMarketPayOrderRequestDTO requestDTO = new RefundMarketPayOrderRequestDTO();
requestDTO.setSource(source);
requestDTO.setChannel(chanel);
requestDTO.setUserId(userId);
requestDTO.setOutTradeNo(orderId);
RefundMarketPayOrderRequestDTO req = new RefundMarketPayOrderRequestDTO();
req.setSource(source);
req.setChannel(chanel);
req.setUserId(userId);
req.setOutTradeNo(orderId);
invoke("refundMarketPayOrder", req);
}
/* ************************************************************ */
/* 私有工具方法 */
/* ************************************************************ */
/**
* 根据模式调用对应通道
*/
@SuppressWarnings("unchecked")
private <REQ, RESP> Response<RESP> invoke(String method, REQ request) {
log.info("[invoke] RPC 模式 = {}, 调用方法 = {}", rpcMode, method);
try {
Call<Response<RefundMarketPayOrderResponseDTO>> call = groupBuyMarketService.refundMarketPayOrder(requestDTO);
// 获取结果
Response<RefundMarketPayOrderResponseDTO> response = call.execute().body();
log.info("营销退单{} requestDTO:{} responseDTO:{}", userId, JSON.toJSONString(requestDTO), JSON.toJSONString(response));
if (null == response) return;
// 异常判断
if (!"0000".equals(response.getCode())) {
throw new AppException(response.getCode(), response.getInfo());
Response<RESP> resp;
if ("HTTP".equalsIgnoreCase(rpcMode)) {
// ---------------- HTTP 调用 ----------------
switch (method) {
case "lockMarketPayOrder":
resp = (Response<RESP>) httpLock((LockMarketPayOrderRequestDTO) request);
break;
case "settlementMarketPayOrder":
resp = (Response<RESP>) httpSettlement((SettlementMarketPayOrderRequestDTO) request);
break;
case "refundMarketPayOrder":
resp = (Response<RESP>) httpRefund((RefundMarketPayOrderRequestDTO) request);
break;
default:
throw new IllegalStateException("Unsupported HTTP method: " + method);
}
} else {
// ---------------- Dubbo 调用 ----------------
switch (method) {
case "lockMarketPayOrder":
resp = (Response<RESP>) dubboService.lockMarketPayOrder((LockMarketPayOrderRequestDTO) request);
break;
case "settlementMarketPayOrder":
resp = (Response<RESP>) dubboService.settlementMarketPayOrder((SettlementMarketPayOrderRequestDTO) request);
break;
case "refundMarketPayOrder":
resp = (Response<RESP>) dubboService.refundMarketPayOrder((RefundMarketPayOrderRequestDTO) request);
break;
default:
throw new IllegalStateException("Unsupported Dubbo method: " + method);
}
}
// ----------- 统一异常处理 -----------
if (resp == null) {
throw new AppException("RPC_NULL", "rpc response null");
}
if (!"0000".equals(resp.getCode())) {
throw new AppException(resp.getCode(), resp.getInfo());
}
log.info("[{}] 成功 userId={} request={} response={}", method, extractUserId(request), JSON.toJSONString(request), JSON.toJSONString(resp));
return resp;
} catch (AppException e) {
throw e;
} catch (Exception e) {
log.error("营销退单失败{}", userId, e);
log.error("[{}] 调用失败 request={}", method, JSON.toJSONString(request), e);
throw new AppException("RPC_ERR", "rpc call error");
}
}
/* ---------------- 单独封装 Retrofit 调用 ---------------- */
private Response<LockMarketPayOrderResponseDTO> httpLock(LockMarketPayOrderRequestDTO req) throws Exception {
Call<Response<LockMarketPayOrderResponseDTO>> call = retrofitService.lockMarketPayOrder(req);
return call.execute().body();
}
private Response<SettlementMarketPayOrderResponseDTO> httpSettlement(SettlementMarketPayOrderRequestDTO req) throws Exception {
Call<Response<SettlementMarketPayOrderResponseDTO>> call = retrofitService.settlementMarketPayOrder(req);
return call.execute().body();
}
private Response<RefundMarketPayOrderResponseDTO> httpRefund(RefundMarketPayOrderRequestDTO req) throws Exception {
Call<Response<RefundMarketPayOrderResponseDTO>> call = retrofitService.refundMarketPayOrder(req);
return call.execute().body();
}
/* ---------------- DTO 构造 ---------------- */
private LockMarketPayOrderRequestDTO buildLockReq(String userId, String teamId, Long activityId, String goodsId, String orderId) {
LockMarketPayOrderRequestDTO dto = new LockMarketPayOrderRequestDTO();
dto.setUserId(userId);
dto.setTeamId(teamId);
dto.setGoodsId(goodsId);
dto.setActivityId(activityId);
dto.setSource(source);
dto.setChannel(chanel);
dto.setOutTradeNo(orderId);
if ("HTTP".equalsIgnoreCase(notifyType)) {
dto.setNotifyUrl(notifyUrl);
} else {
dto.setNotifyMQ();
}
return dto;
}
/* ---- 从不同请求对象里提取 userId 仅用于日志 ---- */
private String extractUserId(Object req) {
if (req instanceof LockMarketPayOrderRequestDTO) {
return ((LockMarketPayOrderRequestDTO) req).getUserId();
} else if (req instanceof SettlementMarketPayOrderRequestDTO) {
return ((SettlementMarketPayOrderRequestDTO) req).getUserId();
} else if (req instanceof RefundMarketPayOrderRequestDTO) {
return ((RefundMarketPayOrderRequestDTO) req).getUserId();
}
return "-";
}
}

View File

@ -202,10 +202,9 @@ public class AliPayController implements IPayService {
}
/**
* http://localhost:8080/api/v1/alipay/refund_order
* <p>
* http://localhost:8092/api/v1/alipay/refund_order
* {
* "userId": "xfg02",
* "userId": "smile01",
* "orderId": "928263928388"
* }
*/

View File

@ -147,6 +147,14 @@
<artifactId>spring-boot-starter-amqp</artifactId>
<version>3.2.0</version>
</dependency>
<!-- 统一锁版本,避免不同模块写不同小版本 -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-bom</artifactId>
<version>3.3.5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- 工程模块 -->
<dependency>
<groupId>edu.whut</groupId>