From e94f17973c2196650dc7cacaf9009ae3a520df5e Mon Sep 17 00:00:00 2001 From: van Date: Thu, 9 Apr 2026 00:09:09 +0800 Subject: [PATCH] 1 --- pom.xml | 7 + .../main/java/com/ruoyi/RuoYiApplication.java | 2 + .../common/OpenCallbackController.java | 48 +- .../web/controller/erp/ProductController.java | 63 ++- .../jarvis/ErpGoofishOrderController.java | 82 +++ .../jarvis/ErpOpenConfigController.java | 63 +++ .../src/main/resources/application-dev.yml | 16 + .../main/resources/sql/erp_goofish_init.sql | 63 +++ ruoyi-system/pom.xml | 5 + .../request/AuthorizeListQueryRequest.java | 2 +- .../com/ruoyi/erp/request/ERPAccount.java | 2 +- .../com/ruoyi/erp/request/ERPRequestBase.java | 4 +- .../request/ExpressCompaniesQueryRequest.java | 2 +- .../com/ruoyi/erp/request/IERPAccount.java | 14 + .../erp/request/OrderDetailQueryRequest.java | 2 +- .../erp/request/OrderKamListQueryRequest.java | 2 +- .../erp/request/OrderListQueryRequest.java | 2 +- .../erp/request/OrderModifyPriceRequest.java | 2 +- .../ruoyi/erp/request/OrderShipRequest.java | 2 +- .../request/ProductBatchCreateRequest.java | 2 +- .../ProductCategoryListQueryRequest.java | 2 +- .../erp/request/ProductCreateRequest.java | 2 +- .../erp/request/ProductDeleteRequest.java | 2 +- .../request/ProductDetailQueryRequest.java | 2 +- .../erp/request/ProductDownShelfRequest.java | 2 +- .../ruoyi/erp/request/ProductEditRequest.java | 2 +- .../erp/request/ProductEditStockRequest.java | 2 +- .../erp/request/ProductListQueryRequest.java | 2 +- .../ProductPropertyListQueryRequest.java | 2 +- .../erp/request/ProductPublishRequest.java | 2 +- .../request/ProductSkuListQueryRequest.java | 2 +- .../jarvis/config/GoofishAsyncConfig.java | 22 + .../config/JarvisGoofishProperties.java | 33 ++ .../ruoyi/jarvis/domain/ErpGoofishOrder.java | 44 ++ .../ruoyi/jarvis/domain/ErpOpenConfig.java | 39 ++ .../jarvis/dto/GoofishNotifyMessage.java | 10 + .../jarvis/mapper/ErpGoofishOrderMapper.java | 23 + .../jarvis/mapper/ErpOpenConfigMapper.java | 23 + .../jarvis/mq/GoofishOrderNotifyConsumer.java | 41 ++ .../service/IErpGoofishOrderService.java | 32 ++ .../jarvis/service/IErpOpenConfigService.java | 24 + .../service/erp/ErpAccountResolver.java | 56 ++ .../goofish/GoofishNotifyAsyncFacade.java | 19 + .../service/goofish/GoofishOrderPipeline.java | 479 ++++++++++++++++++ .../impl/ErpGoofishOrderServiceImpl.java | 120 +++++ .../impl/ErpOpenConfigServiceImpl.java | 63 +++ .../service/impl/ErpProductServiceImpl.java | 23 +- .../jarvis/task/GoofishScheduledTasks.java | 63 +++ .../mapper/jarvis/ErpGoofishOrderMapper.xml | 110 ++++ .../mapper/jarvis/ErpOpenConfigMapper.xml | 78 +++ 50 files changed, 1637 insertions(+), 72 deletions(-) create mode 100644 ruoyi-admin/src/main/java/com/ruoyi/web/controller/jarvis/ErpGoofishOrderController.java create mode 100644 ruoyi-admin/src/main/java/com/ruoyi/web/controller/jarvis/ErpOpenConfigController.java create mode 100644 ruoyi-admin/src/main/resources/sql/erp_goofish_init.sql create mode 100644 ruoyi-system/src/main/java/com/ruoyi/erp/request/IERPAccount.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/jarvis/config/GoofishAsyncConfig.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/jarvis/config/JarvisGoofishProperties.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/jarvis/domain/ErpGoofishOrder.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/jarvis/domain/ErpOpenConfig.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/jarvis/dto/GoofishNotifyMessage.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/jarvis/mapper/ErpGoofishOrderMapper.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/jarvis/mapper/ErpOpenConfigMapper.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/jarvis/mq/GoofishOrderNotifyConsumer.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/jarvis/service/IErpGoofishOrderService.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/jarvis/service/IErpOpenConfigService.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/jarvis/service/erp/ErpAccountResolver.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/jarvis/service/goofish/GoofishNotifyAsyncFacade.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/jarvis/service/goofish/GoofishOrderPipeline.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/ErpGoofishOrderServiceImpl.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/ErpOpenConfigServiceImpl.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/jarvis/task/GoofishScheduledTasks.java create mode 100644 ruoyi-system/src/main/resources/mapper/jarvis/ErpGoofishOrderMapper.xml create mode 100644 ruoyi-system/src/main/resources/mapper/jarvis/ErpOpenConfigMapper.xml diff --git a/pom.xml b/pom.xml index f795fad..a798321 100644 --- a/pom.xml +++ b/pom.xml @@ -35,6 +35,7 @@ 1.2.13 5.7.12 5.3.39 + 2.2.3 @@ -218,6 +219,12 @@ ${ruoyi.version} + + org.apache.rocketmq + rocketmq-spring-boot-starter + ${rocketmq-spring.version} + + diff --git a/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java b/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java index b859aa5..96ff5cf 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java @@ -5,6 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.env.Environment; +import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; /** @@ -14,6 +15,7 @@ import org.springframework.scheduling.annotation.EnableScheduling; */ @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) @EnableScheduling +@EnableAsync public class RuoYiApplication { public static void main(String[] args) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/OpenCallbackController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/OpenCallbackController.java index 56fc891..57b792f 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/OpenCallbackController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/OpenCallbackController.java @@ -1,22 +1,32 @@ package com.ruoyi.web.controller.common; import com.alibaba.fastjson2.JSONObject; -import com.ruoyi.common.core.controller.BaseController; -import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.annotation.Anonymous; import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.erp.request.IERPAccount; +import com.ruoyi.jarvis.service.IErpGoofishOrderService; +import com.ruoyi.jarvis.service.erp.ErpAccountResolver; import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; /** - * 开放平台回调接收端 - * 注意:/product/receive 与 /order/receive 为示例路径,请在开放平台配置时使用你自己的正式回调地址 + * 闲管家开放平台推送回调(请在开放平台填写真实 URL) + * 订单:建议 POST .../open/callback/order/receive */ +@Anonymous @RestController @RequestMapping("/open/callback") -public class OpenCallbackController extends BaseController { +public class OpenCallbackController { + + @Resource + private ErpAccountResolver erpAccountResolver; + + @Resource + private IErpGoofishOrderService erpGoofishOrderService; @PostMapping("/product/receive") public JSONObject receiveProductCallback( @@ -25,7 +35,8 @@ public class OpenCallbackController extends BaseController { @RequestParam("sign") String sign, @RequestBody JSONObject body ) { - if (!verifySign(appid, timestamp, sign, body)) { + IERPAccount account = erpAccountResolver.resolveStrict(appid); + if (!verifySign(account, timestamp, sign, body)) { JSONObject fail = new JSONObject(); fail.put("result", "fail"); fail.put("msg", "签名失败"); @@ -44,26 +55,33 @@ public class OpenCallbackController extends BaseController { @RequestParam("sign") String sign, @RequestBody JSONObject body ) { - if (!verifySign(appid, timestamp, sign, body)) { + IERPAccount account = erpAccountResolver.resolveStrict(appid); + if (!verifySign(account, timestamp, sign, body)) { JSONObject fail = new JSONObject(); fail.put("result", "fail"); fail.put("msg", "签名失败"); return fail; } + try { + erpGoofishOrderService.publishOrProcessNotify(appid, timestamp, body); + } catch (Exception e) { + JSONObject fail = new JSONObject(); + fail.put("result", "fail"); + fail.put("msg", "入队异常"); + return fail; + } JSONObject ok = new JSONObject(); ok.put("result", "success"); ok.put("msg", "接收成功"); return ok; } - private boolean verifySign(String appid, Long timestamp, String sign, JSONObject body) { - // TODO: 这里需要根据appid查出对应的 appKey/appSecret - // 为了示例,直接使用 ERPAccount.ACCOUNT_HUGE 的常量。生产请替换为从数据库/配置读取 - String appKey = "1016208368633221"; - String appSecret = "waLiRMgFcixLbcLjUSSwo370Hp1nBcBu"; - + private boolean verifySign(IERPAccount account, Long timestamp, String sign, JSONObject body) { + if (account == null || StringUtils.isEmpty(sign)) { + return false; + } String json = body == null ? "{}" : body.toJSONString(); - String data = appKey + "," + md5(json) + "," + (timestamp == null ? 0 : timestamp) + "," + appSecret; + String data = account.getApiKey() + "," + md5(json) + "," + (timestamp == null ? 0 : timestamp) + "," + account.getApiKeySecret(); String local = md5(data); return StringUtils.equalsIgnoreCase(local, sign); } @@ -82,5 +100,3 @@ public class OpenCallbackController extends BaseController { } } } - - diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/erp/ProductController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/erp/ProductController.java index 7ed9116..aa5dea9 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/erp/ProductController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/erp/ProductController.java @@ -11,6 +11,10 @@ import com.ruoyi.common.utils.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.ruoyi.erp.request.ERPAccount; +import com.ruoyi.erp.request.IERPAccount; +import com.ruoyi.jarvis.domain.ErpOpenConfig; +import com.ruoyi.jarvis.service.IErpOpenConfigService; +import com.ruoyi.jarvis.service.erp.ErpAccountResolver; import com.ruoyi.erp.request.ProductCreateRequest; import com.ruoyi.erp.request.ProductCategoryListQueryRequest; import com.ruoyi.erp.request.ProductPropertyListQueryRequest; @@ -20,6 +24,7 @@ import com.ruoyi.erp.request.ProductDownShelfRequest; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; import javax.validation.constraints.*; import java.util.ArrayList; import java.util.HashMap; @@ -36,13 +41,19 @@ public class ProductController extends BaseController { @Autowired private IOuterIdGeneratorService outerIdGeneratorService; + + @Resource + private ErpAccountResolver erpAccountResolver; + + @Resource + private IErpOpenConfigService erpOpenConfigService; private static final Logger log = LoggerFactory.getLogger(ProductController.class); @PostMapping("/createByPromotion") public R createByPromotion(@RequestBody @Validated CreateProductFromPromotionRequest req) { try { - ERPAccount account = resolveAccount(req.getAppid()); + IERPAccount account = resolveAccount(req.getAppid()); // 1) 组装 ERPShop ERPShop erpShop = new ERPShop(); erpShop.setChannelCatid(req.getChannelCatId()); @@ -143,7 +154,7 @@ public class ProductController extends BaseController { @PostMapping("/publish") public R publish(@RequestBody @Validated PublishRequest req) { try { - ERPAccount account = resolveAccount(req.getAppid()); + IERPAccount account = resolveAccount(req.getAppid()); ProductPublishRequest publishRequest = new ProductPublishRequest(account); publishRequest.setProductId(req.getProductId()); publishRequest.setUserName(req.getUserName()); @@ -344,10 +355,22 @@ public class ProductController extends BaseController { String name = firstNonBlank(row.getString("user_name"), row.getString("xy_name"), row.getString("username"), row.getString("nick")); if (name != null) { String label = name; - for (ERPAccount a : ERPAccount.values()) { - if (name.equals(a.getXyName())) { - label = name + "(" + a.getRemark() + ")"; - break; + List cfgs = erpOpenConfigService.selectEnabledOrderBySort(); + if (cfgs != null) { + for (ErpOpenConfig c : cfgs) { + if (name.equals(c.getXyUserName())) { + String r = c.getRemark() != null ? c.getRemark() : c.getAppKey(); + label = name + "(" + r + ")"; + break; + } + } + } + if (label.equals(name)) { + for (ERPAccount a : ERPAccount.values()) { + if (name.equals(a.getXyName())) { + label = name + "(" + a.getRemark() + ")"; + break; + } } } options.add(new Option(name, label)); @@ -376,20 +399,24 @@ public class ProductController extends BaseController { @GetMapping("/ERPAccount") public R erpAccounts() { java.util.List