5 Commits

Author SHA1 Message Date
bamanker
408d8d0ed2 修改了日期错误和日志不显示问题
All checks were successful
Build Push and Deploy Image / build (push) Successful in 25m5s
2026-01-16 09:29:03 +08:00
bamanker
a3f93b4eec 增加了日志输出
All checks were successful
Build Push and Deploy Image / build (push) Successful in 23m41s
2026-01-15 17:47:44 +08:00
bamanker
33dbefff85 修复了一些问题 2026-01-14 14:04:49 +08:00
bamanker
369285004a Update Dockerfile to use LABEL for maintainer information 2026-01-14 13:37:49 +08:00
bamanker
922ab1b15a 修复printPushLog 已定义但未被调用的问题 2026-01-14 13:32:09 +08:00
7 changed files with 37 additions and 31 deletions

View File

@@ -1,5 +1,5 @@
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/ubuntu:jammy
MAINTAINER bamanker
LABEL maintainer="bamanker"
COPY target/dailylove /root/dailylove/
EXPOSE 13145
CMD /root/dailylove/dailylove -XX:StartFlightRecording='filename=recording.jfr,dumponexit=true,duration=10s'

View File

@@ -23,7 +23,7 @@
</scm>
<groupId>com.bamanker</groupId>
<artifactId>dailylove</artifactId>
<version>v3.1.2-native</version>
<version>v3.1.4-native</version>
<name>dailylove</name>
<description>dailylove-forK8S</description>
<properties>

View File

@@ -2,7 +2,6 @@ package com.bamanker.dailylove.config;
import cn.hutool.core.util.ClassUtil;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

View File

@@ -3,7 +3,10 @@ package com.bamanker.dailylove.controller;
import cn.hutool.core.date.ChineseDate;
import cn.hutool.core.date.DateUtil;
import com.bamanker.dailylove.config.DailyLoveConfigure;
import com.bamanker.dailylove.domain.*;
import com.bamanker.dailylove.domain.DataItem;
import com.bamanker.dailylove.domain.ResultVo;
import com.bamanker.dailylove.domain.TianXinReqParam;
import com.bamanker.dailylove.domain.Weather;
import com.bamanker.dailylove.exception.PushException;
import com.bamanker.dailylove.service.DataRemoteService;
import com.bamanker.dailylove.service.WechatRequestService;
@@ -13,12 +16,14 @@ import org.springframework.aot.hint.annotation.RegisterReflectionForBinding;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
import reactor.util.function.Tuple4;
import tools.jackson.databind.JsonNode;
import tools.jackson.databind.json.JsonMapper;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;
import java.util.function.Function;
/**
* @author bamanker
@@ -63,11 +68,11 @@ public class PushDailyController {
String term = chineseDate.getTerm();
// 计算各种日期
int girlBirthdays = DataUtils.getBirthdays(DailyLoveConfigure.Girl_Birthday);
int boyBirthdays = DataUtils.getChineseBirthdays(DailyLoveConfigure.Boy_Birthday);
int catBirthdays = DataUtils.getBirthdays(DailyLoveConfigure.Cat_Birthday);
int loveDays = DataUtils.getDayDiff(DailyLoveConfigure.Love_Day);
int weddingDays = DataUtils.getDayDiff(DailyLoveConfigure.Wedding_Day);
int girlBirthdays = DataUtils.getBirthdays(DailyLoveConfigure.Girl_Birthday) - 1;
int boyBirthdays = DataUtils.getChineseBirthdays(DailyLoveConfigure.Boy_Birthday) - 1;
int catBirthdays = DataUtils.getBirthdays(DailyLoveConfigure.Cat_Birthday) - 1;
int loveDays = DataUtils.getDayDiff(DailyLoveConfigure.Love_Day) + 1;
int weddingDays = DataUtils.getDayDiff(DailyLoveConfigure.Wedding_Day) + 1;
log.info("gbir_days:{}, bbir_days:{}, cbir_days:{}, love_days:{}, wedding_days:{}",
girlBirthdays, boyBirthdays, catBirthdays, loveDays, weddingDays);
@@ -133,21 +138,23 @@ public class PushDailyController {
resultVo.setAttribute("rainbow", new DataItem(rainbowContent, DailyLoveConfigure.Color_dailyCn));
resultVo.setAttribute("lunar", new DataItem(chineseDate.toString(), DailyLoveConfigure.Color_chineseDate));
resultVo.setAttribute("festival", new DataItem(festival + " " + term, DailyLoveConfigure.Color_festival));
resultVo.setAttribute("gbir_day", new DataItem((girlBirthdays - 1) + "", DailyLoveConfigure.Color_gbir));
resultVo.setAttribute("bbir_day", new DataItem((boyBirthdays - 1) + "", DailyLoveConfigure.Color_bbir));
resultVo.setAttribute("cbir_day", new DataItem((catBirthdays - 1) + "", DailyLoveConfigure.Color_cbir));
resultVo.setAttribute("gbir_day", new DataItem(girlBirthdays + "", DailyLoveConfigure.Color_gbir));
resultVo.setAttribute("bbir_day", new DataItem(boyBirthdays + "", DailyLoveConfigure.Color_bbir));
resultVo.setAttribute("cbir_day", new DataItem(catBirthdays + "", DailyLoveConfigure.Color_cbir));
resultVo.setAttribute("words", new DataItem(words, DailyLoveConfigure.Color_remark));
resultVo.setAttribute("love_day", new DataItem((loveDays + 1) + "", DailyLoveConfigure.Color_loveDay));
resultVo.setAttribute("wedding_day", new DataItem((weddingDays + 1) + "", DailyLoveConfigure.Color_weddingDay));
resultVo.setAttribute("love_day", new DataItem(loveDays + "", DailyLoveConfigure.Color_loveDay));
resultVo.setAttribute("wedding_day", new DataItem(weddingDays + "", DailyLoveConfigure.Color_weddingDay));
log.info("推送消息: {}", resultVo);
// 获取微信访问令牌并发送消息
return wechatRequestService.getAccessToken("client_credential", DailyLoveConfigure.App_ID, DailyLoveConfigure.App_Secret)
.onErrorMap(throwable -> new PushException("获取微信访问令牌失败: " + throwable.getMessage(), throwable))
.map(tokenResp -> {
return mapper.readTree(tokenResp).get("access_token").asString();
})
.map(tokenResp -> mapper.readTree(tokenResp).get("access_token").asString())
.flatMap(accessToken -> wechatRequestService.sendMsg(accessToken, resultVo)
.onErrorMap(throwable -> new PushException("发送微信消息失败: " + throwable.getMessage(), throwable)));
.doOnNext(this::printPushLog)
.onErrorMap(throwable -> new PushException("发送微信消息失败: " + throwable.getMessage(), throwable)))
.doOnSuccess(response -> log.info("推送结果: {}", response));
} catch (Exception e) {
log.error("处理晚安推送数据时发生错误", e);
return Mono.error(new PushException("处理晚安推送数据时发生错误", e));
@@ -217,14 +224,14 @@ public class PushDailyController {
try {
// 解析天气数据
String city = mapper.readTree(weatherResp).get("result").get("area").asText();
String city = mapper.readTree(weatherResp).get("result").get("area").asString();
var weatherData = mapper.readTree(weatherResp).get("result").get("list").get(0);
Weather weather = mapper.treeToValue(weatherData, Weather.class);
// 解析其他数据
String tips = mapper.readTree(tipsResp).get("result").get("content").asText();
String morningContent = mapper.readTree(morningResp).get("result").get("content").asText();
String rainbowContent = mapper.readTree(rainbowResp).get("result").get("content").asText();
String tips = mapper.readTree(tipsResp).get("result").get("content").asString();
String morningContent = mapper.readTree(morningResp).get("result").get("content").asString();
String rainbowContent = mapper.readTree(rainbowResp).get("result").get("content").asString();
// 创建结果对象
ResultVo resultVo = ResultVo.initializeResultVo(DailyLoveConfigure.Open_ID,
@@ -250,14 +257,15 @@ public class PushDailyController {
resultVo.setAttribute("love_day", new DataItem(loveDays + "", DailyLoveConfigure.Color_loveDay));
resultVo.setAttribute("wedding_day", new DataItem(weddingDays + "", DailyLoveConfigure.Color_weddingDay));
log.info("推送消息: {}", resultVo);
// 获取微信访问令牌并发送消息
return wechatRequestService.getAccessToken("client_credential", DailyLoveConfigure.App_ID, DailyLoveConfigure.App_Secret)
.onErrorMap(throwable -> new PushException("获取微信访问令牌失败: " + throwable.getMessage(), throwable))
.map(tokenResp -> {
return mapper.readTree(tokenResp).get("access_token").asString();
})
.map(tokenResp -> mapper.readTree(tokenResp).get("access_token").asString())
.flatMap(accessToken -> wechatRequestService.sendMsg(accessToken, resultVo)
.onErrorMap(throwable -> new PushException("发送微信消息失败: " + throwable.getMessage(), throwable)));
.doOnNext(PushDailyController.this::printPushLog)
.onErrorMap(throwable -> new PushException("发送微信消息失败: " + throwable.getMessage(), throwable)))
.doOnSuccess(response -> log.info("推送结果: {}", response));
} catch (Exception e) {
log.error("处理早安推送数据时发生错误", e);
return Mono.error(new PushException("处理早安推送数据时发生错误", e));
@@ -272,8 +280,8 @@ public class PushDailyController {
*/
private void printPushLog(String responseStr) {
JsonNode jsonNode = mapper.readTree(responseStr);
String msgCode = jsonNode.get("errcode").asText();
String msgContent = jsonNode.get("errmsg").asText();
String msgCode = jsonNode.get("errcode").asString();
String msgContent = jsonNode.get("errmsg").asString();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("[ " + dateFormat.format(new Date()) + " ] : messageCode=" + msgCode + ",messageContent=" + msgContent);
}

View File

@@ -1,7 +1,6 @@
package com.bamanker.dailylove.domain;
import lombok.Data;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
* @descriptions 错误响应类

View File

@@ -47,7 +47,7 @@ public class DataUtils {
int gregorianDay = chineseDate.getGregorianDay();
//计算时间差
long days = haveThisDay(chineseMonth, chineseDay, dateToday, todayYear, chineseDate, gregorianDay);
log.info("days:{}", days);
// log.info("days:{}", days);
return (int) days;
}

View File

@@ -15,7 +15,7 @@ daily-love:
app-secret: ${WECHAT_APP_SECRET:834078bb149409bfca4fe693ea7c4c1c}
# ME: oo5bL6bK_4TC0tb-Wa5oiugTPVeQ
#LILI: oo5bL6QafHJa9zQNYKS0fIhFC0zM
open-id: ${WECHAT_OPEN_ID:oo5bL6QafHJa9zQNYKS0fIhFC0zM}
open-id: ${WECHAT_OPEN_ID:oo5bL6bK_4TC0tb-Wa5oiugTPVeQ}
template-id-morning: ${WECHAT_TEMPLATE_ID_MORNING:dWNAL-ZOzpBhnByFoTamt9DlJQYLB5z3ldKLvQstyU4}
template-id-night: ${WECHAT_TEMPLATE_ID_NIGHT:oraLiXC-8740stYc1a7mpzUFHiAIRaM3JikqibZ2grE}
colors: