From dbee3a5b12e933f27aba3c87fcb3f76ab79c3287 Mon Sep 17 00:00:00 2001 From: wonder Date: Sun, 26 Oct 2025 16:07:38 +0800 Subject: [PATCH] =?UTF-8?q?=20=E2=9C=A8Feat:=20=E5=AE=9E=E7=8E=B0=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stardewvalley/handle/WeatherHandle.java | 2 ++ .../stardewvalley/lark/card/CardTemplate.java | 3 ++- .../util/bean/SpringContextUtil.java | 25 +++++++++++++++++++ .../util/lark/EventListener.java | 6 ++++- 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/wonderland/stardewvalley/util/bean/SpringContextUtil.java diff --git a/src/main/java/com/wonderland/stardewvalley/handle/WeatherHandle.java b/src/main/java/com/wonderland/stardewvalley/handle/WeatherHandle.java index 125ca4a..0779519 100644 --- a/src/main/java/com/wonderland/stardewvalley/handle/WeatherHandle.java +++ b/src/main/java/com/wonderland/stardewvalley/handle/WeatherHandle.java @@ -5,7 +5,9 @@ import com.wonderland.stardewvalley.entity.game.Weather; import com.wonderland.stardewvalley.util.lark.LarkUtil; import com.wonderland.stardewvalley.util.weather.WeatherUtil; import jakarta.annotation.Resource; +import org.springframework.stereotype.Component; +@Component public class WeatherHandle { @Resource diff --git a/src/main/java/com/wonderland/stardewvalley/lark/card/CardTemplate.java b/src/main/java/com/wonderland/stardewvalley/lark/card/CardTemplate.java index 03fb1c7..e85e053 100644 --- a/src/main/java/com/wonderland/stardewvalley/lark/card/CardTemplate.java +++ b/src/main/java/com/wonderland/stardewvalley/lark/card/CardTemplate.java @@ -4,7 +4,8 @@ import lombok.Getter; @Getter public enum CardTemplate { - CARD_TEMPLATE_WEATHER("AAqxas5etOJDx", "1.0.5"); + CARD_TEMPLATE_WEATHER("AAqxas5etOJDx", "1.0.5"), + CARD_TEMPLATE_FRAM("AAqxaYo9rbXPa", "1.0.7"); private String cardId; private String version; diff --git a/src/main/java/com/wonderland/stardewvalley/util/bean/SpringContextUtil.java b/src/main/java/com/wonderland/stardewvalley/util/bean/SpringContextUtil.java new file mode 100644 index 0000000..6e3c6a9 --- /dev/null +++ b/src/main/java/com/wonderland/stardewvalley/util/bean/SpringContextUtil.java @@ -0,0 +1,25 @@ +package com.wonderland.stardewvalley.util.bean; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +@Component +public class SpringContextUtil implements ApplicationContextAware { + + private static ApplicationContext context; + public static T getBean(Class beanClass) { + return context.getBean(beanClass); + } + public static T getBean(String name, Class beanClass) { + return context.getBean(name, beanClass); + } + public static Object getBean(String name) { + return context.getBean(name); + } + @Override + public void setApplicationContext(ApplicationContext appContext) throws BeansException { + context = appContext; + } +} diff --git a/src/main/java/com/wonderland/stardewvalley/util/lark/EventListener.java b/src/main/java/com/wonderland/stardewvalley/util/lark/EventListener.java index 86b117c..cfbdabc 100644 --- a/src/main/java/com/wonderland/stardewvalley/util/lark/EventListener.java +++ b/src/main/java/com/wonderland/stardewvalley/util/lark/EventListener.java @@ -8,6 +8,8 @@ import com.lark.oapi.service.im.ImService; import com.lark.oapi.service.im.v1.model.P2MessageReceiveV1; import com.lark.oapi.ws.Client; import com.wonderland.stardewvalley.common.constant.LarkConstant; +import com.wonderland.stardewvalley.handle.WeatherHandle; +import com.wonderland.stardewvalley.util.bean.SpringContextUtil; public class EventListener { @@ -33,7 +35,9 @@ public class EventListener { String eventKey = event.getEvent().getEventKey(); if (eventKey.equals("weather")) { // TODO 完善调用,发送天气卡片 - } + WeatherHandle weatherHandle = SpringContextUtil.getBean(WeatherHandle.class); + weatherHandle.sendCard(); + } System.out.printf("[ onP2BotMenuV6 access ], data: %s\n", Jsons.DEFAULT.toJson(event.getEvent())); }