Browse Source

分销商模块提交

lishiqiang 1 month ago
parent
commit
83d0a2098c

+ 2 - 2
script/idea/http-client.env.json

@@ -1,6 +1,6 @@
 {
   "local": {
-    "baseUrl": "http://127.0.0.1:48080/admin-api",
+    "baseUrl": "http://127.0.0.1:48080/ship-ota-api",
     "token": "test1",
     "adminTenantId": "1",
 
@@ -9,7 +9,7 @@
     "appTenantId": "1"
   },
   "gateway": {
-    "baseUrl": "http://127.0.0.1:8888/admin-api",
+    "baseUrl": "http://127.0.0.1:8888/ship-ota-api",
     "token": "test1",
     "adminTenantId": "1",
 

+ 19 - 1
ship-server-web/pom.xml

@@ -149,5 +149,23 @@
         </dependency>
 
     </dependencies>
-
+    <build>
+        <!-- 设置构建的 jar 包名 -->
+        <finalName>${project.artifactId}</finalName>
+        <plugins>
+            <!-- 打包 -->
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <version>${spring.boot.version}</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>repackage</goal> <!-- 将引入的 jar 打入其中 -->
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
 </project>

+ 66 - 0
ship-server-web/src/main/java/com/yc/ship/framework/web/config/WebProperties.java

@@ -0,0 +1,66 @@
+package com.yc.ship.framework.web.config;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
+
+import javax.validation.Valid;
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+
+@ConfigurationProperties(prefix = "yudao.web")
+@Validated
+@Data
+public class WebProperties {
+
+    @NotNull(message = "APP API 不能为空")
+    private Api appApi = new Api("/app-api", "**.controller.app.**");
+    @NotNull(message = "Admin API 不能为空")
+    private Api adminApi = new Api("/ota-api", "**.controller.admin.**");
+
+    @NotNull(message = "Admin UI 不能为空")
+    private Ui adminUi;
+
+    @Data
+    @AllArgsConstructor
+    @NoArgsConstructor
+    @Valid
+    public static class Api {
+
+        /**
+         * API 前缀,实现所有 Controller 提供的 RESTFul API 的统一前缀
+         *
+         *
+         * 意义:通过该前缀,避免 Swagger、Actuator 意外通过 Nginx 暴露出来给外部,带来安全性问题
+         *      这样,Nginx 只需要配置转发到 /api/* 的所有接口即可。
+         *
+         * @see YudaoWebAutoConfiguration#configurePathMatch(PathMatchConfigurer)
+         */
+        @NotEmpty(message = "API 前缀不能为空")
+        private String prefix;
+
+        /**
+         * Controller 所在包的 Ant 路径规则
+         *
+         * 主要目的是,给该 Controller 设置指定的 {@link #prefix}
+         */
+        @NotEmpty(message = "Controller 所在包不能为空")
+        private String controller;
+
+    }
+
+    @Data
+    @Valid
+    public static class Ui {
+
+        /**
+         * 访问地址
+         */
+        private String url;
+
+    }
+
+}

+ 132 - 0
ship-server-web/src/main/java/com/yc/ship/framework/web/config/YudaoWebAutoConfiguration.java

@@ -0,0 +1,132 @@
+package com.yc.ship.framework.web.config;
+
+import com.yc.ship.framework.common.enums.WebFilterOrderEnum;
+import com.yc.ship.framework.web.core.filter.CacheRequestBodyFilter;
+import com.yc.ship.framework.web.core.filter.DemoFilter;
+import com.yc.ship.framework.web.core.handler.GlobalExceptionHandler;
+import com.yc.ship.framework.web.core.handler.GlobalResponseBodyHandler;
+import com.yc.ship.framework.web.core.util.WebFrameworkUtils;
+import com.yc.ship.module.infra.api.logger.ApiErrorLogApi;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.AutoConfiguration;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.boot.web.client.RestTemplateBuilder;
+import org.springframework.boot.web.servlet.FilterRegistrationBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.util.AntPathMatcher;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.web.cors.CorsConfiguration;
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
+import org.springframework.web.filter.CorsFilter;
+import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+import javax.annotation.Resource;
+import javax.servlet.Filter;
+
+@AutoConfiguration
+@EnableConfigurationProperties(WebProperties.class)
+public class YudaoWebAutoConfiguration implements WebMvcConfigurer {
+
+    @Resource
+    private WebProperties webProperties;
+    /**
+     * 应用名
+     */
+    @Value("${spring.application.name}")
+    private String applicationName;
+
+    @Override
+    public void configurePathMatch(PathMatchConfigurer configurer) {
+        configurePathMatch(configurer, webProperties.getAdminApi());
+        configurePathMatch(configurer, webProperties.getAppApi());
+    }
+
+    /**
+     * 设置 API 前缀,仅仅匹配 controller 包下的
+     *
+     * @param configurer 配置
+     * @param api        API 配置
+     */
+    private void configurePathMatch(PathMatchConfigurer configurer, WebProperties.Api api) {
+        AntPathMatcher antPathMatcher = new AntPathMatcher(".");
+        configurer.addPathPrefix(api.getPrefix(), clazz -> clazz.isAnnotationPresent(RestController.class)
+                && antPathMatcher.match(api.getController(), clazz.getPackage().getName())); // 仅仅匹配 controller 包
+    }
+
+    @Bean
+    @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
+    public GlobalExceptionHandler globalExceptionHandler(ApiErrorLogApi apiErrorLogApi) {
+        return new GlobalExceptionHandler(applicationName, apiErrorLogApi);
+    }
+
+    @Bean
+    public GlobalResponseBodyHandler globalResponseBodyHandler() {
+        return new GlobalResponseBodyHandler();
+    }
+
+    @Bean
+    @SuppressWarnings("InstantiationOfUtilityClass")
+    public WebFrameworkUtils webFrameworkUtils(WebProperties webProperties) {
+        // 由于 WebFrameworkUtils 需要使用到 webProperties 属性,所以注册为一个 Bean
+        return new WebFrameworkUtils(webProperties);
+    }
+
+    // ========== Filter 相关 ==========
+
+    /**
+     * 创建 CorsFilter Bean,解决跨域问题
+     */
+    @Bean
+    public FilterRegistrationBean<CorsFilter> corsFilterBean() {
+        // 创建 CorsConfiguration 对象
+        CorsConfiguration config = new CorsConfiguration();
+        config.setAllowCredentials(true);
+        config.addAllowedOriginPattern("*"); // 设置访问源地址
+        config.addAllowedHeader("*"); // 设置访问源请求头
+        config.addAllowedMethod("*"); // 设置访问源请求方法
+        // 创建 UrlBasedCorsConfigurationSource 对象
+        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
+        source.registerCorsConfiguration("/**", config); // 对接口配置跨域设置
+        return createFilterBean(new CorsFilter(source), WebFilterOrderEnum.CORS_FILTER);
+    }
+
+    /**
+     * 创建 RequestBodyCacheFilter Bean,可重复读取请求内容
+     */
+    @Bean
+    public FilterRegistrationBean<CacheRequestBodyFilter> requestBodyCacheFilter() {
+        return createFilterBean(new CacheRequestBodyFilter(), WebFilterOrderEnum.REQUEST_BODY_CACHE_FILTER);
+    }
+
+    /**
+     * 创建 DemoFilter Bean,演示模式
+     */
+    @Bean
+    @ConditionalOnProperty(value = "yudao.demo", havingValue = "true")
+    public FilterRegistrationBean<DemoFilter> demoFilter() {
+        return createFilterBean(new DemoFilter(), WebFilterOrderEnum.DEMO_FILTER);
+    }
+
+    public static <T extends Filter> FilterRegistrationBean<T> createFilterBean(T filter, Integer order) {
+        FilterRegistrationBean<T> bean = new FilterRegistrationBean<>(filter);
+        bean.setOrder(order);
+        return bean;
+    }
+
+    /**
+     * 创建 RestTemplate 实例
+     *
+     * @param restTemplateBuilder {@link RestTemplateAutoConfiguration#restTemplateBuilder}
+     */
+    @Bean
+    @ConditionalOnMissingBean
+    public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
+        return restTemplateBuilder.build();
+    }
+
+}

+ 1 - 1
ship-server-web/src/main/java/com/yc/ship/server/controller/DefaultController.java

@@ -71,7 +71,7 @@ public class DefaultController {
                 "[AI 大模型 yudao-module-ai - 已禁用][参考 https://doc.iocoder.cn/ai/build/ 开启]");
     }
 
-    @RequestMapping(value = { "/admin-api/iot/**"})
+    @RequestMapping(value = { "/ota-api/iot/**"})
     public CommonResult<Boolean> iot404() {
         return CommonResult.error(NOT_IMPLEMENTED.getCode(),
                 "[IoT 物联网 yudao-module-iot - 已禁用][参考 https://doc.iocoder.cn/iot/build/ 开启]");

+ 3 - 8
ship-server-web/src/main/resources/application-dev.yaml

@@ -4,11 +4,6 @@ server:
 --- #################### 数据库相关配置 ####################
 
 spring:
-  autoconfigure:
-    exclude:
-      - org.springframework.ai.autoconfigure.vectorstore.qdrant.QdrantVectorStoreAutoConfiguration # 禁用 AI 模块的 Qdrant,手动创建
-      - org.springframework.ai.autoconfigure.vectorstore.milvus.MilvusVectorStoreAutoConfiguration # 禁用 AI 模块的 Milvus,手动创建
-  # 数据源配置项
   autoconfigure:
     exclude:
       - com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure # 排除 Druid 的自动配置,使用 dynamic-datasource-spring-boot-starter 配置多数据源
@@ -169,9 +164,9 @@ wx: # 参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-sta
 # 芋道配置项,设置当前项目所有自定义的配置
 yudao:
   pay:
-    order-notify-url: http://yunai.natapp1.cc/admin-api/pay/notify/order # 支付渠道的【支付】回调地址
-    refund-notify-url: http://yunai.natapp1.cc/admin-api/pay/notify/refund # 支付渠道的【退款】回调地址
-    transfer-notify-url: https://yunai.natapp1.cc/admin-api/pay/notify/transfer # 支付渠道的【转账】回调地址
+    order-notify-url: http://yunai.natapp1.cc/ship-ota-api/pay/notify/order # 支付渠道的【支付】回调地址
+    refund-notify-url: http://yunai.natapp1.cc/ship-ota-api/pay/notify/refund # 支付渠道的【退款】回调地址
+    transfer-notify-url: https://yunai.natapp1.cc/ship-ota-api/pay/notify/transfer # 支付渠道的【转账】回调地址
   demo: false # 开启演示模式
   tencent-lbs-key: TVDBZ-TDILD-4ON4B-PFDZA-RNLKH-VVF6E # QQ 地图的密钥 https://lbs.qq.com/service/staticV2/staticGuide/staticDoc
 

+ 18 - 15
ship-server-web/src/main/resources/application-local.yaml

@@ -49,21 +49,21 @@ spring:
       primary: master
       datasource:
         master:
-          url: jdbc:mysql://webapplication.rwlb.rds.aliyuncs.com:3306/db_yc_ship?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true # MySQL Connector/J 8.X 连接的示例
-          username: ycship
-          password: ycship#2025
+          url: jdbc:mysql://10.3.10.50:43306/db_yc_ship?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true # MySQL Connector/J 8.X 连接的示例
+          username: root
+          password: W1ses0ft@zshl
         slave: # 模拟从库,可根据自己需要修改
           lazy: true # 开启懒加载,保证启动速度
-          url: jdbc:mysql://webapplication.rwlb.rds.aliyuncs.com:3306/db_yc_ship?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&rewriteBatchedStatements=true&nullCatalogMeansCurrent=true
-          username: ycship
-          password: ycship#2025
+          url: jdbc:mysql://10.3.10.50:43306/db_yc_ship?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&rewriteBatchedStatements=true&nullCatalogMeansCurrent=true
+          username: root
+          password: W1ses0ft@zshl
 
   # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
   redis:
-    host: 127.0.0.1 # 地址
+    host: 10.3.10.50 # 地址
     port: 6379 # 端口
     database: 2 # 数据库索引
-    password: 123456 # 密码,建议生产环境开启
+    password: redis123 # 密码,建议生产环境开启
 
 --- #################### 定时任务相关配置 ####################
 
@@ -105,10 +105,10 @@ rocketmq:
 spring:
   # RabbitMQ 配置项,对应 RabbitProperties 配置类
   rabbitmq:
-    host: 127.0.0.1 # RabbitMQ 服务的地址
-    port: 5672 # RabbitMQ 服务的端口
-    username: ticket # RabbitMQ 服务的账号
-    password: ticket # RabbitMQ 服务的密码
+    host: 10.3.10.50 # RabbitMQ 服务的地址
+    port: 55672 # RabbitMQ 服务的端口
+    username: rabbitmq # RabbitMQ 服务的账号
+    password: rabbitmq # RabbitMQ 服务的密码
   # Kafka 配置项,对应 KafkaProperties 配置类
   kafka:
     bootstrap-servers: 127.0.0.1:9092 # 指定 Kafka Broker 地址,可以设置多个,以逗号分隔
@@ -168,6 +168,9 @@ logging:
     com.yc.ship.module.iot.dal.tdengine: DEBUG
     com.yc.ship.module.ai.dal.mysql: debug
     com.yc.ship.module.buss.dal.mysql: debug
+    com.yc.ship.module.ota.dal.mysql: debug
+    com.yc.ship.module.product.dal.mysql: debug
+    com.yc.ship.module.otc.dal.mysql: debug
     org.springframework.context.support.PostProcessorRegistrationDelegate: ERROR # TODO 芋艿:先禁用,Spring Boot 3.X 存在部分错误的 WARN 提示
 
 debug: false
@@ -209,9 +212,9 @@ yudao:
   security:
     mock-enable: true
   pay:
-    order-notify-url: http://yunai.natapp1.cc/admin-api/pay/notify/order # 支付渠道的【支付】回调地址
-    refund-notify-url: http://yunai.natapp1.cc/admin-api/pay/notify/refund # 支付渠道的【退款】回调地址
-    transfer-notify-url: http://yunai.natapp1.cc/admin-api/pay/notify/transfer # 支付渠道的【转账】回调地址
+    order-notify-url: http://yunai.natapp1.cc/ship-ota-api/pay/notify/order # 支付渠道的【支付】回调地址
+    refund-notify-url: http://yunai.natapp1.cc/ship-ota-api/pay/notify/refund # 支付渠道的【退款】回调地址
+    transfer-notify-url: http://yunai.natapp1.cc/ship-ota-api/pay/notify/transfer # 支付渠道的【转账】回调地址
   access-log: # 访问日志的配置项
     enable: false
   demo: false # 关闭演示模式

+ 3 - 4
ship-server-web/src/main/resources/application.yaml

@@ -1,6 +1,6 @@
 spring:
   application:
-    name: admin-api
+    name: yudao-server
 
   profiles:
     active: local
@@ -221,11 +221,11 @@ yudao:
   #    base-url: https://api.holdai.top/mj-relax/mj
       base-url: https://api.holdai.top/mj
       api-key: sk-dZEPiVaNcT3FHhef51996bAa0bC74806BeAb620dA5Da10Bf
-      notify-url: http://java.nat300.top/admin-api/ai/image/midjourney/notify
+      notify-url: http://java.nat300.top/ship-ota-api/ai/image/midjourney/notify
     suno:
       enable: true
   #    base-url: https://suno-55ishh05u-status2xxs-projects.vercel.app
-      base-url: http://127.0.0.admin-api1:3001
+      base-url: http://127.0.0.1:3001
 
 --- #################### 芋道相关配置 ####################
 
@@ -276,7 +276,6 @@ yudao:
       - /jmreport/* # 积木报表,无法携带租户编号
     ignore-visit-urls:
       - /admin-api/system/user/profile/**
-      - /admin-api/system/auth/**
     ignore-tables:
     ignore-caches:
       - user_role_ids