From 060466b7b757c6a1cf5d55ef258b0f60de0bb6fd Mon Sep 17 00:00:00 2001 From: wonder Date: Wed, 29 Oct 2025 16:08:19 +0800 Subject: [PATCH] =?UTF-8?q?=20=E2=99=BB=EF=B8=8FRefactor:=20=E7=AE=80?= =?UTF-8?q?=E5=8C=96=E5=BE=AE=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{weather => }/common/AIConstant.java | 2 +- .../{weather => }/common/AppConstant.java | 2 +- .../{weather => }/common/CardEnum.java | 2 +- .../{weather => }/common/WeatherConstant.java | 2 +- .../{weather => }/entity/Weather.java | 2 +- eureka/pom.xml | 27 -------------- .../eureka/EurekaServerApplication.java | 13 ------- eureka/src/main/resources/application.yml | 16 --------- gateway/pom.xml | 35 ------------------ .../hezhaohui/gateway/GatewayApplication.java | 13 ------- gateway/src/main/resources/application.yml | 36 ------------------- lark/pom.xml | 5 --- .../cn/hezhaohui/lark/LarkApplication.java | 3 -- .../hezhaohui/lark/client/WeatherClient.java | 3 +- .../hezhaohui/lark/handler/EventListener.java | 2 +- .../java/cn/hezhaohui/lark/util/LarkUtil.java | 4 +-- .../cn/hezhaohui/lark/util/LarkUtilTest.java | 4 +-- pom.xml | 9 ----- weather/pom.xml | 10 ------ .../weather/controller/HealthController.java | 2 +- .../weather/controller/WeatherController.java | 4 +-- .../weather/service/ChatService.java | 2 +- .../hezhaohui/weather/util/WeatherUtil.java | 8 ++--- weather/src/main/resources/application.yml | 5 --- .../weather/service/ChatServiceTest.java | 2 +- .../weather/util/WeatherUtilTest.java | 2 +- 26 files changed, 20 insertions(+), 195 deletions(-) rename common/src/main/java/cn/hezhaohui/{weather => }/common/AIConstant.java (96%) rename common/src/main/java/cn/hezhaohui/{weather => }/common/AppConstant.java (87%) rename common/src/main/java/cn/hezhaohui/{weather => }/common/CardEnum.java (91%) rename common/src/main/java/cn/hezhaohui/{weather => }/common/WeatherConstant.java (87%) rename common/src/main/java/cn/hezhaohui/{weather => }/entity/Weather.java (88%) delete mode 100644 eureka/pom.xml delete mode 100644 eureka/src/main/java/cn/hezhaohui/eureka/EurekaServerApplication.java delete mode 100644 eureka/src/main/resources/application.yml delete mode 100644 gateway/pom.xml delete mode 100644 gateway/src/main/java/cn/hezhaohui/gateway/GatewayApplication.java delete mode 100644 gateway/src/main/resources/application.yml diff --git a/common/src/main/java/cn/hezhaohui/weather/common/AIConstant.java b/common/src/main/java/cn/hezhaohui/common/AIConstant.java similarity index 96% rename from common/src/main/java/cn/hezhaohui/weather/common/AIConstant.java rename to common/src/main/java/cn/hezhaohui/common/AIConstant.java index be8a8f3..bdbf706 100644 --- a/common/src/main/java/cn/hezhaohui/weather/common/AIConstant.java +++ b/common/src/main/java/cn/hezhaohui/common/AIConstant.java @@ -1,4 +1,4 @@ -package cn.hezhaohui.weather.common; +package cn.hezhaohui.common; public class AIConstant { diff --git a/common/src/main/java/cn/hezhaohui/weather/common/AppConstant.java b/common/src/main/java/cn/hezhaohui/common/AppConstant.java similarity index 87% rename from common/src/main/java/cn/hezhaohui/weather/common/AppConstant.java rename to common/src/main/java/cn/hezhaohui/common/AppConstant.java index 2f42515..8578e4a 100644 --- a/common/src/main/java/cn/hezhaohui/weather/common/AppConstant.java +++ b/common/src/main/java/cn/hezhaohui/common/AppConstant.java @@ -1,4 +1,4 @@ -package cn.hezhaohui.weather.common; +package cn.hezhaohui.common; public class AppConstant { diff --git a/common/src/main/java/cn/hezhaohui/weather/common/CardEnum.java b/common/src/main/java/cn/hezhaohui/common/CardEnum.java similarity index 91% rename from common/src/main/java/cn/hezhaohui/weather/common/CardEnum.java rename to common/src/main/java/cn/hezhaohui/common/CardEnum.java index d0ef8a2..b4162b9 100644 --- a/common/src/main/java/cn/hezhaohui/weather/common/CardEnum.java +++ b/common/src/main/java/cn/hezhaohui/common/CardEnum.java @@ -1,4 +1,4 @@ -package cn.hezhaohui.weather.common; +package cn.hezhaohui.common; public enum CardEnum { CARD_WEATHER("AAqxas5etOJDx", "1.0.5"); diff --git a/common/src/main/java/cn/hezhaohui/weather/common/WeatherConstant.java b/common/src/main/java/cn/hezhaohui/common/WeatherConstant.java similarity index 87% rename from common/src/main/java/cn/hezhaohui/weather/common/WeatherConstant.java rename to common/src/main/java/cn/hezhaohui/common/WeatherConstant.java index 6f4a6d5..9ebc7a9 100644 --- a/common/src/main/java/cn/hezhaohui/weather/common/WeatherConstant.java +++ b/common/src/main/java/cn/hezhaohui/common/WeatherConstant.java @@ -1,4 +1,4 @@ -package cn.hezhaohui.weather.common; +package cn.hezhaohui.common; public class WeatherConstant { diff --git a/common/src/main/java/cn/hezhaohui/weather/entity/Weather.java b/common/src/main/java/cn/hezhaohui/entity/Weather.java similarity index 88% rename from common/src/main/java/cn/hezhaohui/weather/entity/Weather.java rename to common/src/main/java/cn/hezhaohui/entity/Weather.java index 8af8d46..65411a5 100644 --- a/common/src/main/java/cn/hezhaohui/weather/entity/Weather.java +++ b/common/src/main/java/cn/hezhaohui/entity/Weather.java @@ -1,4 +1,4 @@ -package cn.hezhaohui.weather.entity; +package cn.hezhaohui.entity; import lombok.Builder; import lombok.Data; diff --git a/eureka/pom.xml b/eureka/pom.xml deleted file mode 100644 index 9eff95e..0000000 --- a/eureka/pom.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - 4.0.0 - - cn.hezhaohui - lark-panel - 1.0.0 - - - eureka - - - - org.springframework.cloud - spring-cloud-starter-netflix-eureka-server - - - - - 21 - 21 - UTF-8 - - - \ No newline at end of file diff --git a/eureka/src/main/java/cn/hezhaohui/eureka/EurekaServerApplication.java b/eureka/src/main/java/cn/hezhaohui/eureka/EurekaServerApplication.java deleted file mode 100644 index b37ba33..0000000 --- a/eureka/src/main/java/cn/hezhaohui/eureka/EurekaServerApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package cn.hezhaohui.eureka; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; - -@SpringBootApplication -@EnableEurekaServer -public class EurekaServerApplication { - public static void main(String[] args) { - SpringApplication.run(EurekaServerApplication.class, args); - } -} diff --git a/eureka/src/main/resources/application.yml b/eureka/src/main/resources/application.yml deleted file mode 100644 index 78ac245..0000000 --- a/eureka/src/main/resources/application.yml +++ /dev/null @@ -1,16 +0,0 @@ -server: - port: 8761 - -spring: - application: - name: eureka-server - -eureka: - instance: - hostname: localhost - client: - register-with-eureka: false - fetch-registry: false - service-url: - defaultZone: - http://${eureka.instance.hostname}:${server.port}/eureka/ \ No newline at end of file diff --git a/gateway/pom.xml b/gateway/pom.xml deleted file mode 100644 index a5637c3..0000000 --- a/gateway/pom.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - 4.0.0 - - cn.hezhaohui - lark-panel - 1.0.0 - - - gateway - - - - org.springframework.cloud - spring-cloud-starter-netflix-eureka-client - - - org.springframework.cloud - spring-cloud-starter-loadbalancer - - - org.springframework.cloud - spring-cloud-starter-gateway - - - - - 21 - 21 - UTF-8 - - - \ No newline at end of file diff --git a/gateway/src/main/java/cn/hezhaohui/gateway/GatewayApplication.java b/gateway/src/main/java/cn/hezhaohui/gateway/GatewayApplication.java deleted file mode 100644 index 3374ec6..0000000 --- a/gateway/src/main/java/cn/hezhaohui/gateway/GatewayApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package cn.hezhaohui.gateway; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; - -@SpringBootApplication -@EnableDiscoveryClient -public class GatewayApplication { - public static void main(String[] args) { - SpringApplication.run(GatewayApplication.class, args); - } -} diff --git a/gateway/src/main/resources/application.yml b/gateway/src/main/resources/application.yml deleted file mode 100644 index 348a229..0000000 --- a/gateway/src/main/resources/application.yml +++ /dev/null @@ -1,36 +0,0 @@ -spring: - application: - name: api-gateway - cloud: - gateway: - routes: - # 路由到service-weather服务 - - id: service-weather - uri: lb://service-weather - predicates: - - Path=/api/weather/** - filters: - - StripPrefix=2 - # 路由到service-consumer服务 - - id: service-consumer - uri: lb://service-consumer - predicates: - - Path=/api/consumer/** - filters: - - StripPrefix=2 - # 全局过滤器配置 - globalcors: - cors-configurations: - "[/**]": - allowedOriginPatterns: "*" - allowedMethods: "*" - allowedHeaders: "*" - -server: - port: 8081 - - -eureka: - client: - service-url: - defaultZone: http://localhost:8761/eureka/ \ No newline at end of file diff --git a/lark/pom.xml b/lark/pom.xml index 24a0103..381b254 100644 --- a/lark/pom.xml +++ b/lark/pom.xml @@ -17,11 +17,6 @@ spring-boot-starter-web - - org.springframework.cloud - spring-cloud-starter-openfeign - - com.larksuite.oapi oapi-sdk diff --git a/lark/src/main/java/cn/hezhaohui/lark/LarkApplication.java b/lark/src/main/java/cn/hezhaohui/lark/LarkApplication.java index 213cb21..c0bd353 100644 --- a/lark/src/main/java/cn/hezhaohui/lark/LarkApplication.java +++ b/lark/src/main/java/cn/hezhaohui/lark/LarkApplication.java @@ -1,14 +1,11 @@ package cn.hezhaohui.lark; -import cn.hezhaohui.lark.client.WeatherClient; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cloud.openfeign.EnableFeignClients; import static cn.hezhaohui.lark.handler.EventListener.larkClientStart; @SpringBootApplication -@EnableFeignClients public class LarkApplication { public static void main(String[] args) { diff --git a/lark/src/main/java/cn/hezhaohui/lark/client/WeatherClient.java b/lark/src/main/java/cn/hezhaohui/lark/client/WeatherClient.java index 9cd813b..0d86606 100644 --- a/lark/src/main/java/cn/hezhaohui/lark/client/WeatherClient.java +++ b/lark/src/main/java/cn/hezhaohui/lark/client/WeatherClient.java @@ -1,8 +1,7 @@ package cn.hezhaohui.lark.client; -import cn.hezhaohui.weather.entity.Weather; +import cn.hezhaohui.entity.Weather; import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.GetMapping; @FeignClient(name = "service-weather") diff --git a/lark/src/main/java/cn/hezhaohui/lark/handler/EventListener.java b/lark/src/main/java/cn/hezhaohui/lark/handler/EventListener.java index f79237b..a09c1e3 100644 --- a/lark/src/main/java/cn/hezhaohui/lark/handler/EventListener.java +++ b/lark/src/main/java/cn/hezhaohui/lark/handler/EventListener.java @@ -1,6 +1,6 @@ package cn.hezhaohui.lark.handler; -import cn.hezhaohui.weather.common.AppConstant; +import cn.hezhaohui.common.AppConstant; import com.lark.oapi.core.request.EventReq; import com.lark.oapi.core.utils.Jsons; import com.lark.oapi.event.CustomEventHandler; diff --git a/lark/src/main/java/cn/hezhaohui/lark/util/LarkUtil.java b/lark/src/main/java/cn/hezhaohui/lark/util/LarkUtil.java index 61458a4..76098a3 100644 --- a/lark/src/main/java/cn/hezhaohui/lark/util/LarkUtil.java +++ b/lark/src/main/java/cn/hezhaohui/lark/util/LarkUtil.java @@ -1,7 +1,7 @@ package cn.hezhaohui.lark.util; -import cn.hezhaohui.weather.common.AppConstant; -import cn.hezhaohui.weather.common.CardEnum; +import cn.hezhaohui.common.AppConstant; +import cn.hezhaohui.common.CardEnum; import cn.hutool.core.util.IdUtil; import cn.hutool.json.JSONUtil; import com.google.gson.JsonParser; diff --git a/lark/src/test/java/cn/hezhaohui/lark/util/LarkUtilTest.java b/lark/src/test/java/cn/hezhaohui/lark/util/LarkUtilTest.java index b8840e7..2a26088 100644 --- a/lark/src/test/java/cn/hezhaohui/lark/util/LarkUtilTest.java +++ b/lark/src/test/java/cn/hezhaohui/lark/util/LarkUtilTest.java @@ -1,8 +1,8 @@ package cn.hezhaohui.lark.util; import cn.hezhaohui.lark.client.WeatherClient; -import cn.hezhaohui.weather.common.CardEnum; -import cn.hezhaohui.weather.entity.Weather; +import cn.hezhaohui.common.CardEnum; +import cn.hezhaohui.entity.Weather; import jakarta.annotation.Resource; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; diff --git a/pom.xml b/pom.xml index bf082b4..ddae592 100644 --- a/pom.xml +++ b/pom.xml @@ -16,8 +16,6 @@ lark weather common - eureka - gateway @@ -30,13 +28,6 @@ pom import - - org.springframework.cloud - spring-cloud-dependencies - 2023.0.6 - pom - import - org.projectlombok lombok diff --git a/weather/pom.xml b/weather/pom.xml index 5ba83d2..2e331dd 100644 --- a/weather/pom.xml +++ b/weather/pom.xml @@ -28,16 +28,6 @@ lombok - - org.springframework.cloud - spring-cloud-netflix-eureka-client - - - - org.springframework.cloud - spring-cloud-starter-loadbalancer - - cn.hutool hutool-all diff --git a/weather/src/main/java/cn/hezhaohui/weather/controller/HealthController.java b/weather/src/main/java/cn/hezhaohui/weather/controller/HealthController.java index 3aa4a87..be7d178 100644 --- a/weather/src/main/java/cn/hezhaohui/weather/controller/HealthController.java +++ b/weather/src/main/java/cn/hezhaohui/weather/controller/HealthController.java @@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.RestController; @RequestMapping public class HealthController { - @GetMapping("health") + @GetMapping("/health") public String health() { return "Hello wonder!"; } diff --git a/weather/src/main/java/cn/hezhaohui/weather/controller/WeatherController.java b/weather/src/main/java/cn/hezhaohui/weather/controller/WeatherController.java index 42098e4..2a07192 100644 --- a/weather/src/main/java/cn/hezhaohui/weather/controller/WeatherController.java +++ b/weather/src/main/java/cn/hezhaohui/weather/controller/WeatherController.java @@ -1,6 +1,6 @@ package cn.hezhaohui.weather.controller; -import cn.hezhaohui.weather.entity.Weather; +import cn.hezhaohui.entity.Weather; import cn.hezhaohui.weather.util.WeatherUtil; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RestController; @RequestMapping public class WeatherController { - @GetMapping("get") + @GetMapping("/get") public Weather getWeather() { return WeatherUtil.getWeather(); } diff --git a/weather/src/main/java/cn/hezhaohui/weather/service/ChatService.java b/weather/src/main/java/cn/hezhaohui/weather/service/ChatService.java index 4be2f25..30509c5 100644 --- a/weather/src/main/java/cn/hezhaohui/weather/service/ChatService.java +++ b/weather/src/main/java/cn/hezhaohui/weather/service/ChatService.java @@ -1,6 +1,6 @@ package cn.hezhaohui.weather.service; -import cn.hezhaohui.weather.common.AIConstant; +import cn.hezhaohui.common.AIConstant; import lombok.extern.slf4j.Slf4j; import org.springframework.ai.chat.client.ChatClient; import org.springframework.stereotype.Service; diff --git a/weather/src/main/java/cn/hezhaohui/weather/util/WeatherUtil.java b/weather/src/main/java/cn/hezhaohui/weather/util/WeatherUtil.java index 2a3d9c6..9344276 100644 --- a/weather/src/main/java/cn/hezhaohui/weather/util/WeatherUtil.java +++ b/weather/src/main/java/cn/hezhaohui/weather/util/WeatherUtil.java @@ -1,14 +1,14 @@ package cn.hezhaohui.weather.util; -import cn.hezhaohui.weather.common.AIConstant; -import cn.hezhaohui.weather.entity.Weather; +import cn.hezhaohui.common.AIConstant; +import cn.hezhaohui.entity.Weather; import cn.hezhaohui.weather.service.ChatService; import cn.hutool.http.HttpUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import lombok.extern.slf4j.Slf4j; -import static cn.hezhaohui.weather.common.WeatherConstant.*; +import static cn.hezhaohui.common.WeatherConstant.*; @Slf4j public class WeatherUtil { @@ -18,8 +18,6 @@ public class WeatherUtil { * */ - - private static String createUrl() { String url = API_BASE_URL + "?key=" + diff --git a/weather/src/main/resources/application.yml b/weather/src/main/resources/application.yml index d20b7ac..996ebb4 100644 --- a/weather/src/main/resources/application.yml +++ b/weather/src/main/resources/application.yml @@ -1,7 +1,6 @@ spring: application: name: service-weather - ai: openai: api-key: sk-ihsqnxhnzmgsaojdkxomcmgdypdfpzojymfndfklgzfchlgz @@ -10,10 +9,6 @@ spring: options: model: Pro/Qwen/Qwen2.5-7B-Instruct temperature: 0.7 -eureka: - client: - service-url: - defaultZone: http://localhost:8761/eureka/ server: port: 8083 diff --git a/weather/src/test/java/cn/hezhaohui/weather/service/ChatServiceTest.java b/weather/src/test/java/cn/hezhaohui/weather/service/ChatServiceTest.java index 1616e13..39cc93b 100644 --- a/weather/src/test/java/cn/hezhaohui/weather/service/ChatServiceTest.java +++ b/weather/src/test/java/cn/hezhaohui/weather/service/ChatServiceTest.java @@ -1,6 +1,6 @@ package cn.hezhaohui.weather.service; -import cn.hezhaohui.weather.common.AIConstant; +import cn.hezhaohui.common.AIConstant; import jakarta.annotation.Resource; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; diff --git a/weather/src/test/java/cn/hezhaohui/weather/util/WeatherUtilTest.java b/weather/src/test/java/cn/hezhaohui/weather/util/WeatherUtilTest.java index dd3e806..d47a81a 100644 --- a/weather/src/test/java/cn/hezhaohui/weather/util/WeatherUtilTest.java +++ b/weather/src/test/java/cn/hezhaohui/weather/util/WeatherUtilTest.java @@ -1,6 +1,6 @@ package cn.hezhaohui.weather.util; -import cn.hezhaohui.weather.entity.Weather; +import cn.hezhaohui.entity.Weather; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest;