♻️Refactor: 简化微服务

This commit is contained in:
2025-10-29 16:08:19 +08:00
parent c0b89fcd95
commit 060466b7b7
26 changed files with 20 additions and 195 deletions
@@ -1,4 +1,4 @@
package cn.hezhaohui.weather.common;
package cn.hezhaohui.common;
public class AIConstant {
@@ -1,4 +1,4 @@
package cn.hezhaohui.weather.common;
package cn.hezhaohui.common;
public class AppConstant {
@@ -1,4 +1,4 @@
package cn.hezhaohui.weather.common;
package cn.hezhaohui.common;
public enum CardEnum {
CARD_WEATHER("AAqxas5etOJDx", "1.0.5");
@@ -1,4 +1,4 @@
package cn.hezhaohui.weather.common;
package cn.hezhaohui.common;
public class WeatherConstant {
@@ -1,4 +1,4 @@
package cn.hezhaohui.weather.entity;
package cn.hezhaohui.entity;
import lombok.Builder;
import lombok.Data;
-27
View File
@@ -1,27 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.hezhaohui</groupId>
<artifactId>lark-panel</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>eureka</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
@@ -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);
}
}
-16
View File
@@ -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/
-35
View File
@@ -1,35 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.hezhaohui</groupId>
<artifactId>lark-panel</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>gateway</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
@@ -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);
}
}
@@ -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/
-5
View File
@@ -17,11 +17,6 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>com.larksuite.oapi</groupId>
<artifactId>oapi-sdk</artifactId>
@@ -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) {
@@ -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")
@@ -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;
@@ -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;
@@ -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;
-9
View File
@@ -16,8 +16,6 @@
<module>lark</module>
<module>weather</module>
<module>common</module>
<module>eureka</module>
<module>gateway</module>
</modules>
<!-- 依赖管理 -->
@@ -30,13 +28,6 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2023.0.6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
-10
View File
@@ -28,16 +28,6 @@
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
@@ -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!";
}
@@ -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();
}
@@ -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;
@@ -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=" +
@@ -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
@@ -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;
@@ -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;