♻️Refactor: 微服务重构

This commit is contained in:
2025-10-28 23:09:46 +08:00
parent 44607b5e1b
commit c0b89fcd95
30 changed files with 279 additions and 40 deletions
+17
View File
@@ -12,15 +12,32 @@
<artifactId>weather</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-openai</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<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>
@@ -1,16 +0,0 @@
package cn.hezhaohui.entity;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
public class Weather {
private String weather;
private String temperature;
private String windPower;
private String windDirection;
private String reportTime;
private String humidity;
private String content;
}
@@ -1,11 +1,11 @@
package cn.hezhaohui;
package cn.hezhaohui.weather;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public class WeatherApplication {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
SpringApplication.run(WeatherApplication.class, args);
}
}
@@ -0,0 +1,15 @@
package cn.hezhaohui.weather.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping
public class HealthController {
@GetMapping("health")
public String health() {
return "Hello wonder!";
}
}
@@ -0,0 +1,17 @@
package cn.hezhaohui.weather.controller;
import cn.hezhaohui.weather.entity.Weather;
import cn.hezhaohui.weather.util.WeatherUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping
public class WeatherController {
@GetMapping("get")
public Weather getWeather() {
return WeatherUtil.getWeather();
}
}
@@ -1,6 +1,6 @@
package cn.hezhaohui.service;
package cn.hezhaohui.weather.service;
import cn.hezhaohui.common.AIConstant;
import cn.hezhaohui.weather.common.AIConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.stereotype.Service;
@@ -1,4 +1,4 @@
package cn.hezhaohui.util;
package cn.hezhaohui.weather.util;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
@@ -1,14 +1,14 @@
package cn.hezhaohui.util;
package cn.hezhaohui.weather.util;
import cn.hezhaohui.common.AIConstant;
import cn.hezhaohui.entity.Weather;
import cn.hezhaohui.service.ChatService;
import cn.hezhaohui.weather.common.AIConstant;
import cn.hezhaohui.weather.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.common.WeatherConstant.*;
import static cn.hezhaohui.weather.common.WeatherConstant.*;
@Slf4j
public class WeatherUtil {
@@ -1,4 +1,7 @@
spring:
application:
name: service-weather
ai:
openai:
api-key: sk-ihsqnxhnzmgsaojdkxomcmgdypdfpzojymfndfklgzfchlgz
@@ -7,3 +10,10 @@ 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,11 +1,11 @@
package cn.hezhaohui.service;
package cn.hezhaohui.weather.service;
import cn.hezhaohui.common.AIConstant;
import cn.hezhaohui.weather.common.AIConstant;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
@SpringBootTest
class ChatServiceTest {
@Resource
@@ -1,10 +1,10 @@
package cn.hezhaohui.util;
package cn.hezhaohui.weather.util;
import cn.hezhaohui.entity.Weather;
import cn.hezhaohui.weather.entity.Weather;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
@SpringBootTest
class WeatherUtilTest {
@Test