From 2bb8508ca47d60a28d3930691d8406cef9351966 Mon Sep 17 00:00:00 2001 From: Zhujx Date: Thu, 31 Jul 2025 18:31:55 +0800 Subject: [PATCH] =?UTF-8?q?perf:=E5=9F=BA=E9=87=91=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=8F=98=E6=9B=B4=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xservice/xb/schedule/xb/FundCountJob.java | 2 +- .../xb/schedule/xb/FundInfoQueryJob.java | 11 +- .../xb/schedule/xb/FundMsgReportJob.java | 152 ++++++++++++++++++ 3 files changed, 158 insertions(+), 7 deletions(-) create mode 100644 script/src/main/java/com/xiang/xservice/xb/schedule/xb/FundMsgReportJob.java diff --git a/script/src/main/java/com/xiang/xservice/xb/schedule/xb/FundCountJob.java b/script/src/main/java/com/xiang/xservice/xb/schedule/xb/FundCountJob.java index 0cc9e02..e1aee66 100644 --- a/script/src/main/java/com/xiang/xservice/xb/schedule/xb/FundCountJob.java +++ b/script/src/main/java/com/xiang/xservice/xb/schedule/xb/FundCountJob.java @@ -61,7 +61,7 @@ public class FundCountJob { xbFundCount.setLId(xbFundList.getId()); xbFundCount.setCode(xbFundList.getCode()); xbFundCount.setName(xbFundList.getName()); - xbFundCount.setChange(fund.get(0).getChange()); + xbFundCount.setChange(fund.get(0).getChange().multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)); xbFundCount.setUpdateTime(LocalDateTime.now()); counts.add(xbFundCount); } diff --git a/script/src/main/java/com/xiang/xservice/xb/schedule/xb/FundInfoQueryJob.java b/script/src/main/java/com/xiang/xservice/xb/schedule/xb/FundInfoQueryJob.java index e092c69..6673380 100644 --- a/script/src/main/java/com/xiang/xservice/xb/schedule/xb/FundInfoQueryJob.java +++ b/script/src/main/java/com/xiang/xservice/xb/schedule/xb/FundInfoQueryJob.java @@ -66,7 +66,7 @@ public class FundInfoQueryJob { * 基金增长定时任务查询 * 半个小时一次 9点开始到3.30结束 */ - @Scheduled(cron = "0 1,31 9,10,11,13,14 * * ? ") +// @Scheduled(cron = "0 1,31 9,10,11,13,14 * * ? ") public void queryFundJob() throws Exception { // 周六周日过滤 if (Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SATURDAY) || @@ -96,10 +96,9 @@ public class FundInfoQueryJob { log.info("==========================[基金查询] 基金查询定时任务结束!=========================="); } /** - * 基金增长定时任务查询 - * 半个小时一次 9点开始到3.30结束 + * 美股基金每日早上9点消息一次 */ - @Scheduled(cron = "0 0 9 * * ? ") +// @Scheduled(cron = "0 0 9 * * ? ") public void queryFundJob3() throws Exception { // 周六周日过滤 if (Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SATURDAY) || @@ -129,10 +128,10 @@ public class FundInfoQueryJob { log.info("==========================[基金查询] 基金查询定时任务结束!=========================="); } /** - * 基金增长定时任务查询 + * 港股基金增长定时任务查询 * 半个小时一次 9点开始到3.30结束 */ - @Scheduled(cron = "0 1,31 9,10,11,13,14,15 * * ? ") +// @Scheduled(cron = "0 1,31 9,10,11,13,14,15 * * ? ") public void queryFundJob2() throws Exception { // 周六周日过滤 if (Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SATURDAY) || diff --git a/script/src/main/java/com/xiang/xservice/xb/schedule/xb/FundMsgReportJob.java b/script/src/main/java/com/xiang/xservice/xb/schedule/xb/FundMsgReportJob.java new file mode 100644 index 0000000..9ce3dc4 --- /dev/null +++ b/script/src/main/java/com/xiang/xservice/xb/schedule/xb/FundMsgReportJob.java @@ -0,0 +1,152 @@ +package com.xiang.xservice.xb.schedule.xb; + +import com.alibaba.fastjson.JSON; +import com.xiang.xservice.basic.xservice.dingTalk.service.DingTalkService; +import com.xiang.xservice.xb.entity.pojo.xb.XbFundList; +import com.xiang.xservice.xb.entity.response.xbyj.fund.FundList; +import com.xiang.xservice.xb.service.FundService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.time.DayOfWeek; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * @Author: xiang + * @Date: 2025-07-31 18:10 + */ +@Component +@Slf4j +@RequiredArgsConstructor +public class FundMsgReportJob { + + private final FundService fundService; + private final DingTalkService dingTalkService; + @Value("${DingTalk.chatId}") + private String chatId; + private static final Integer TYPE_A = 1; + private static final Integer TYPE_M = 3; + private static final Integer TYPE_G = 2; + + @Scheduled(cron = "0 1,31 9,10,11,13,14 * * ?") + public void fundReport4A() { + log.info("===========A股基金变化通知!==========="); + // 周六周日过滤 + if (Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SATURDAY) || + Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SUNDAY)) { + log.info("当前时间为:{}", LocalDateTime.now()); + return; + } + List fundLists = fundService.queryFundList(TYPE_A); + if (CollectionUtils.isEmpty(fundLists)) { + log.info("查询配置的A股信息为空"); + return; + } + Map fundMap = fundLists.stream().collect(Collectors.toMap(XbFundList::getCode, Function.identity(), (a, b) -> a)); + String date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); + List funds = fundService.queryTodayList(date, "2", Boolean.TRUE, new ArrayList<>(fundMap.keySet())); + if (CollectionUtils.isEmpty(funds)) { + log.info("http请求查询基金信息为空"); + return; + } + log.info("http查询基金信息:{}", JSON.toJSONString(funds)); + StringBuilder msg = new StringBuilder(date).append("===》A股基金变化通知:\n"); + buildMsg(funds, fundMap, msg); + try { + dingTalkService.sendChatMessage(chatId, msg.toString()); + } catch (Exception e) { + log.error("钉钉消息通知异常.", e); + } + } + + @Scheduled(cron = "0 1,31 9,10,11,13,14,15 * * ?") + public void fundReport4G() { + log.info("===========港股基金变化通知!==========="); + // 周六周日过滤 + if (Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SATURDAY) || + Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SUNDAY)) { + log.info("当前时间为:{}", LocalDateTime.now()); + return; + } + List fundLists = fundService.queryFundList(TYPE_G); + if (CollectionUtils.isEmpty(fundLists)) { + log.info("查询配置的港股信息为空"); + return; + } + Map fundMap = fundLists.stream().collect(Collectors.toMap(XbFundList::getCode, Function.identity(), (a, b) -> a)); + String date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); + List funds = fundService.queryTodayList(date, "2", Boolean.TRUE, new ArrayList<>(fundMap.keySet())); + if (CollectionUtils.isEmpty(funds)) { + log.info("http请求查询基金信息为空"); + return; + } + log.info("http查询港股基金信息:{}", JSON.toJSONString(funds)); + StringBuilder msg = new StringBuilder(date).append("===》港股基金变化通知:\n"); + buildMsg(funds, fundMap, msg); + try { + dingTalkService.sendChatMessage(chatId, msg.toString()); + } catch (Exception e) { + log.error("钉钉消息通知异常.", e); + } + } + + @Scheduled(cron = "0 0 9 * * ?") + public void fundReport4M() { + log.info("===========美股基金变化通知!==========="); + // 周六周日过滤 + if (Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SATURDAY) || + Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SUNDAY)) { + log.info("当前时间为:{}", LocalDateTime.now()); + return; + } + List fundLists = fundService.queryFundList(TYPE_M); + if (CollectionUtils.isEmpty(fundLists)) { + log.info("查询配置的美股信息为空"); + return; + } + Map fundMap = fundLists.stream().collect(Collectors.toMap(XbFundList::getCode, Function.identity(), (a, b) -> a)); + String date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); + List funds = fundService.queryTodayList(date, "2", Boolean.TRUE, new ArrayList<>(fundMap.keySet())); + if (CollectionUtils.isEmpty(funds)) { + log.info("http请求查询基金信息为空"); + return; + } + log.info("http查询美股基金信息:{}", JSON.toJSONString(funds)); + StringBuilder msg = new StringBuilder(date).append("===》美股基金变化通知:\n"); + buildMsg(funds, fundMap, msg); + try { + dingTalkService.sendChatMessage(chatId, msg.toString()); + } catch (Exception e) { + log.error("钉钉消息通知异常.", e); + } + } + + private static void buildMsg(List funds, Map fundMap, StringBuilder msg) { + for (FundList fund : funds) { + if (fundMap.containsKey(fund.getCode())) { + XbFundList fundList = fundMap.get(fund.getCode()); + msg.append("基金名称:") + .append(fundList.getName()) + .append("涨跌幅:") + .append(fund.getChange() + .multiply(new BigDecimal("100")) + .setScale(2, RoundingMode.HALF_UP)) + .append("\n"); + } + } + } +}