♻️Refactor: 微服务重构
This commit is contained in:
+2
-3
@@ -18,9 +18,8 @@
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hezhaohui</groupId>
|
||||
<artifactId>weather</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
+7
-5
@@ -1,16 +1,18 @@
|
||||
package cn.hezhaohui.lark;
|
||||
|
||||
import cn.hezhaohui.lark.client.WeatherClient;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
import static cn.hezhaohui.lark.handler.EventListener.larkClientStart;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = "cn.hezhaohui")
|
||||
public class Application {
|
||||
public static void main(String[] args) throws Exception {
|
||||
SpringApplication.run(Application.class, args);
|
||||
@EnableFeignClients
|
||||
public class LarkApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(LarkApplication.class, args);
|
||||
larkClientStart();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package cn.hezhaohui.lark.client;
|
||||
|
||||
import cn.hezhaohui.weather.entity.Weather;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@FeignClient(name = "service-weather")
|
||||
public interface WeatherClient {
|
||||
|
||||
@GetMapping("get")
|
||||
Weather getWeather();
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.hezhaohui.lark.handler;
|
||||
|
||||
import cn.hezhaohui.common.AppConstant;
|
||||
import cn.hezhaohui.weather.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.common.AppConstant;
|
||||
import cn.hezhaohui.common.CardEnum;
|
||||
import cn.hezhaohui.weather.common.AppConstant;
|
||||
import cn.hezhaohui.weather.common.CardEnum;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
spring:
|
||||
application:
|
||||
name: lark
|
||||
server:
|
||||
port: 8082
|
||||
|
||||
service-weather:
|
||||
url: http://localhost:8081/api/weather
|
||||
@@ -1,17 +1,17 @@
|
||||
package cn.hezhaohui.lark.util;
|
||||
|
||||
|
||||
import cn.hezhaohui.common.CardEnum;
|
||||
import cn.hezhaohui.util.SpringContextUtil;
|
||||
import cn.hezhaohui.util.WeatherUtil;
|
||||
import cn.hezhaohui.lark.client.WeatherClient;
|
||||
import cn.hezhaohui.weather.common.CardEnum;
|
||||
import cn.hezhaohui.weather.entity.Weather;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class LarkUtilTest {
|
||||
|
||||
@Resource
|
||||
private SpringContextUtil springContextUtil;
|
||||
private WeatherClient weatherClient;
|
||||
|
||||
@Test
|
||||
void sendText() throws Exception {
|
||||
@@ -20,6 +20,7 @@ class LarkUtilTest {
|
||||
|
||||
@Test
|
||||
void sendCard() throws Exception {
|
||||
LarkUtil.sendCard(CardEnum.CARD_WEATHER, WeatherUtil.getWeather());
|
||||
Weather weather = weatherClient.getWeather();
|
||||
LarkUtil.sendCard(CardEnum.CARD_WEATHER, weather);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user