♻️Refactor: 简化微服务
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package cn.hezhaohui.weather.common;
|
package cn.hezhaohui.common;
|
||||||
|
|
||||||
public class AIConstant {
|
public class AIConstant {
|
||||||
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package cn.hezhaohui.weather.common;
|
package cn.hezhaohui.common;
|
||||||
|
|
||||||
public class AppConstant {
|
public class AppConstant {
|
||||||
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package cn.hezhaohui.weather.common;
|
package cn.hezhaohui.common;
|
||||||
|
|
||||||
public enum CardEnum {
|
public enum CardEnum {
|
||||||
CARD_WEATHER("AAqxas5etOJDx", "1.0.5");
|
CARD_WEATHER("AAqxas5etOJDx", "1.0.5");
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package cn.hezhaohui.weather.common;
|
package cn.hezhaohui.common;
|
||||||
|
|
||||||
public class WeatherConstant {
|
public class WeatherConstant {
|
||||||
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package cn.hezhaohui.weather.entity;
|
package cn.hezhaohui.entity;
|
||||||
|
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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/
|
|
||||||
@@ -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/
|
|
||||||
@@ -17,11 +17,6 @@
|
|||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.cloud</groupId>
|
|
||||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.larksuite.oapi</groupId>
|
<groupId>com.larksuite.oapi</groupId>
|
||||||
<artifactId>oapi-sdk</artifactId>
|
<artifactId>oapi-sdk</artifactId>
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
package cn.hezhaohui.lark;
|
package cn.hezhaohui.lark;
|
||||||
|
|
||||||
import cn.hezhaohui.lark.client.WeatherClient;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
|
||||||
|
|
||||||
import static cn.hezhaohui.lark.handler.EventListener.larkClientStart;
|
import static cn.hezhaohui.lark.handler.EventListener.larkClientStart;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableFeignClients
|
|
||||||
public class LarkApplication {
|
public class LarkApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
package cn.hezhaohui.lark.client;
|
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.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|
||||||
@FeignClient(name = "service-weather")
|
@FeignClient(name = "service-weather")
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package cn.hezhaohui.lark.handler;
|
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.request.EventReq;
|
||||||
import com.lark.oapi.core.utils.Jsons;
|
import com.lark.oapi.core.utils.Jsons;
|
||||||
import com.lark.oapi.event.CustomEventHandler;
|
import com.lark.oapi.event.CustomEventHandler;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package cn.hezhaohui.lark.util;
|
package cn.hezhaohui.lark.util;
|
||||||
|
|
||||||
import cn.hezhaohui.weather.common.AppConstant;
|
import cn.hezhaohui.common.AppConstant;
|
||||||
import cn.hezhaohui.weather.common.CardEnum;
|
import cn.hezhaohui.common.CardEnum;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package cn.hezhaohui.lark.util;
|
package cn.hezhaohui.lark.util;
|
||||||
|
|
||||||
import cn.hezhaohui.lark.client.WeatherClient;
|
import cn.hezhaohui.lark.client.WeatherClient;
|
||||||
import cn.hezhaohui.weather.common.CardEnum;
|
import cn.hezhaohui.common.CardEnum;
|
||||||
import cn.hezhaohui.weather.entity.Weather;
|
import cn.hezhaohui.entity.Weather;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|||||||
@@ -16,8 +16,6 @@
|
|||||||
<module>lark</module>
|
<module>lark</module>
|
||||||
<module>weather</module>
|
<module>weather</module>
|
||||||
<module>common</module>
|
<module>common</module>
|
||||||
<module>eureka</module>
|
|
||||||
<module>gateway</module>
|
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<!-- 依赖管理 -->
|
<!-- 依赖管理 -->
|
||||||
@@ -30,13 +28,6 @@
|
|||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</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>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
|
|||||||
@@ -28,16 +28,6 @@
|
|||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
</dependency>
|
</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>
|
<dependency>
|
||||||
<groupId>cn.hutool</groupId>
|
<groupId>cn.hutool</groupId>
|
||||||
<artifactId>hutool-all</artifactId>
|
<artifactId>hutool-all</artifactId>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@RequestMapping
|
@RequestMapping
|
||||||
public class HealthController {
|
public class HealthController {
|
||||||
|
|
||||||
@GetMapping("health")
|
@GetMapping("/health")
|
||||||
public String health() {
|
public String health() {
|
||||||
return "Hello wonder!";
|
return "Hello wonder!";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package cn.hezhaohui.weather.controller;
|
package cn.hezhaohui.weather.controller;
|
||||||
|
|
||||||
import cn.hezhaohui.weather.entity.Weather;
|
import cn.hezhaohui.entity.Weather;
|
||||||
import cn.hezhaohui.weather.util.WeatherUtil;
|
import cn.hezhaohui.weather.util.WeatherUtil;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@RequestMapping
|
@RequestMapping
|
||||||
public class WeatherController {
|
public class WeatherController {
|
||||||
|
|
||||||
@GetMapping("get")
|
@GetMapping("/get")
|
||||||
public Weather getWeather() {
|
public Weather getWeather() {
|
||||||
return WeatherUtil.getWeather();
|
return WeatherUtil.getWeather();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package cn.hezhaohui.weather.service;
|
package cn.hezhaohui.weather.service;
|
||||||
|
|
||||||
import cn.hezhaohui.weather.common.AIConstant;
|
import cn.hezhaohui.common.AIConstant;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.ai.chat.client.ChatClient;
|
import org.springframework.ai.chat.client.ChatClient;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package cn.hezhaohui.weather.util;
|
package cn.hezhaohui.weather.util;
|
||||||
|
|
||||||
import cn.hezhaohui.weather.common.AIConstant;
|
import cn.hezhaohui.common.AIConstant;
|
||||||
import cn.hezhaohui.weather.entity.Weather;
|
import cn.hezhaohui.entity.Weather;
|
||||||
import cn.hezhaohui.weather.service.ChatService;
|
import cn.hezhaohui.weather.service.ChatService;
|
||||||
import cn.hutool.http.HttpUtil;
|
import cn.hutool.http.HttpUtil;
|
||||||
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONObject;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import static cn.hezhaohui.weather.common.WeatherConstant.*;
|
import static cn.hezhaohui.common.WeatherConstant.*;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class WeatherUtil {
|
public class WeatherUtil {
|
||||||
@@ -18,8 +18,6 @@ public class WeatherUtil {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static String createUrl() {
|
private static String createUrl() {
|
||||||
String url = API_BASE_URL +
|
String url = API_BASE_URL +
|
||||||
"?key=" +
|
"?key=" +
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
name: service-weather
|
name: service-weather
|
||||||
|
|
||||||
ai:
|
ai:
|
||||||
openai:
|
openai:
|
||||||
api-key: sk-ihsqnxhnzmgsaojdkxomcmgdypdfpzojymfndfklgzfchlgz
|
api-key: sk-ihsqnxhnzmgsaojdkxomcmgdypdfpzojymfndfklgzfchlgz
|
||||||
@@ -10,10 +9,6 @@ spring:
|
|||||||
options:
|
options:
|
||||||
model: Pro/Qwen/Qwen2.5-7B-Instruct
|
model: Pro/Qwen/Qwen2.5-7B-Instruct
|
||||||
temperature: 0.7
|
temperature: 0.7
|
||||||
eureka:
|
|
||||||
client:
|
|
||||||
service-url:
|
|
||||||
defaultZone: http://localhost:8761/eureka/
|
|
||||||
server:
|
server:
|
||||||
port: 8083
|
port: 8083
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package cn.hezhaohui.weather.service;
|
package cn.hezhaohui.weather.service;
|
||||||
|
|
||||||
import cn.hezhaohui.weather.common.AIConstant;
|
import cn.hezhaohui.common.AIConstant;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package cn.hezhaohui.weather.util;
|
package cn.hezhaohui.weather.util;
|
||||||
|
|
||||||
import cn.hezhaohui.weather.entity.Weather;
|
import cn.hezhaohui.entity.Weather;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user