feat:基金定时任务

This commit is contained in:
xiang
2026-02-07 20:12:45 +08:00
parent e22bc012c9
commit c506a850c3
3 changed files with 383 additions and 383 deletions

View File

@@ -1,105 +1,105 @@
package com.xiang.xservice.application.script.xb.schedule.xb; //package com.xiang.xservice.application.script.xb.schedule.xb;
//
import com.alibaba.fastjson2.JSONObject; //import com.alibaba.fastjson2.JSONObject;
import com.google.common.collect.Lists; //import com.google.common.collect.Lists;
import com.xiang.xservice.application.script.xb.entity.pojo.xb.XbFundCount; //import com.xiang.xservice.application.script.xb.entity.pojo.xb.XbFundCount;
import com.xiang.xservice.application.script.xb.entity.pojo.xb.XbFundList; //import com.xiang.xservice.application.script.xb.entity.pojo.xb.XbFundList;
import com.xiang.xservice.application.script.xb.entity.response.xbyj.fund.FundList; //import com.xiang.xservice.application.script.xb.entity.response.xbyj.fund.FundList;
import com.xiang.xservice.application.script.xb.service.FundService; //import com.xiang.xservice.application.script.xb.service.FundService;
import com.xiang.xservice.basic.utils.DateUtils; //import com.xiang.xservice.basic.utils.DateUtils;
import com.xiang.xservice.common.service.dingTalk.StockDingTalkFactory; //import com.xiang.xservice.common.service.dingTalk.StockDingTalkFactory;
import lombok.RequiredArgsConstructor; //import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; //import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; //import org.apache.commons.lang3.StringUtils;
import org.springframework.scheduling.annotation.Scheduled; //import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; //import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RestController; //import org.springframework.web.bind.annotation.RestController;
//
import java.math.BigDecimal; //import java.math.BigDecimal;
import java.math.RoundingMode; //import java.math.RoundingMode;
import java.time.DayOfWeek; //import java.time.DayOfWeek;
import java.time.LocalDate; //import java.time.LocalDate;
import java.time.LocalDateTime; //import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; //import java.time.format.DateTimeFormatter;
import java.util.Collections; //import java.util.Collections;
import java.util.List; //import java.util.List;
import java.util.Map; //import java.util.Map;
import java.util.Objects; //import java.util.Objects;
import java.util.stream.Collectors; //import java.util.stream.Collectors;
//
/** ///**
* @Author: xiang // * @Author: xiang
* @Date: 2025-05-21 13:59 // * @Date: 2025-05-21 13:59
*/ // */
@Component //@Component
@RequiredArgsConstructor //@RequiredArgsConstructor
@Slf4j //@Slf4j
@RestController //@RestController
public class FundCountJob { //public class FundCountJob {
//
private final FundService fundService; // private final FundService fundService;
private final StockDingTalkFactory dingTalkService; // private final StockDingTalkFactory dingTalkService;
@Scheduled(cron = "0 0 22 * * ?") // @Scheduled(cron = "0 0 22 * * ?")
public void countFundJob() { // public void countFundJob() {
// 周六周日过滤 // // 周六周日过滤
if (Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SATURDAY) || // if (Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SATURDAY) ||
Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SUNDAY)) { // Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SUNDAY)) {
return; // return;
} // }
log.info("==========================[基金统计] 基金统计定时任务启动!=========================="); // log.info("==========================[基金统计] 基金统计定时任务启动!==========================");
List<XbFundList> lists = fundService.queryFundList(); // List<XbFundList> lists = fundService.queryFundList();
if (CollectionUtils.isEmpty(lists)) { // if (CollectionUtils.isEmpty(lists)) {
return; // return;
} // }
List<XbFundCount> counts = Lists.newCopyOnWriteArrayList(); // List<XbFundCount> counts = Lists.newCopyOnWriteArrayList();
String date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); // String date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
lists.parallelStream().forEach(xbFundList -> { // lists.parallelStream().forEach(xbFundList -> {
List<FundList> fund = fundService.queryTodayList(date, "2", Boolean.TRUE, Collections.singletonList(xbFundList.getCode())); // List<FundList> fund = fundService.queryTodayList(date, "2", Boolean.TRUE, Collections.singletonList(xbFundList.getCode()));
if (CollectionUtils.isNotEmpty(fund)) { // if (CollectionUtils.isNotEmpty(fund)) {
XbFundCount xbFundCount = new XbFundCount(); // XbFundCount xbFundCount = new XbFundCount();
xbFundCount.setLId(xbFundList.getId()); // xbFundCount.setLId(xbFundList.getId());
xbFundCount.setCode(xbFundList.getCode()); // xbFundCount.setCode(xbFundList.getCode());
xbFundCount.setName(xbFundList.getName()); // xbFundCount.setName(xbFundList.getName());
xbFundCount.setChange(fund.get(0).getChange().multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)); // xbFundCount.setChange(fund.get(0).getChange().multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
xbFundCount.setUpdateTime(LocalDateTime.now()); // xbFundCount.setUpdateTime(LocalDateTime.now());
counts.add(xbFundCount); // counts.add(xbFundCount);
} // }
}); // });
if (CollectionUtils.isNotEmpty(counts)) { // if (CollectionUtils.isNotEmpty(counts)) {
log.info("[基金统计] 基金统计记录,需要插入的数据:{}", JSONObject.toJSONString(counts)); // log.info("[基金统计] 基金统计记录,需要插入的数据:{}", JSONObject.toJSONString(counts));
fundService.addCounts(counts); // fundService.addCounts(counts);
} // }
log.info("==========================[基金统计] 基金统计定时任务结束!=========================="); // log.info("==========================[基金统计] 基金统计定时任务结束!==========================");
} // }
//
@Scheduled(cron = "0 40 14 * * ? ") // @Scheduled(cron = "0 40 14 * * ? ")
public void countFundInWeek() throws Exception { // public void countFundInWeek() throws Exception {
if (DateUtils.validWeekTime()) return; // if (DateUtils.validWeekTime()) return;
log.info("==========================[基金统计] 基金本周涨跌幅消息发送定时任务启动!=========================="); // log.info("==========================[基金统计] 基金本周涨跌幅消息发送定时任务启动!==========================");
List<XbFundCount> xbFundCounts = fundService.queryFundCountInWeek(); // List<XbFundCount> xbFundCounts = fundService.queryFundCountInWeek();
if (CollectionUtils.isEmpty(xbFundCounts)) { // if (CollectionUtils.isEmpty(xbFundCounts)) {
return; // return;
} // }
StringBuilder sb = new StringBuilder(); // StringBuilder sb = new StringBuilder();
Map<String, List<XbFundCount>> map = xbFundCounts.stream().collect(Collectors.groupingBy(XbFundCount::getCode)); // Map<String, List<XbFundCount>> map = xbFundCounts.stream().collect(Collectors.groupingBy(XbFundCount::getCode));
map.forEach((k, v) -> { // map.forEach((k, v) -> {
List<XbFundCount> fundCounts = map.get(k); // List<XbFundCount> fundCounts = map.get(k);
if (CollectionUtils.isEmpty(fundCounts)) { // if (CollectionUtils.isEmpty(fundCounts)) {
return; // return;
} // }
List<BigDecimal> decimals = fundCounts.stream().map(XbFundCount::getChange).collect(Collectors.toList()); // List<BigDecimal> decimals = fundCounts.stream().map(XbFundCount::getChange).collect(Collectors.toList());
BigDecimal sum = BigDecimal.ZERO; // BigDecimal sum = BigDecimal.ZERO;
for (BigDecimal decimal : decimals) { // for (BigDecimal decimal : decimals) {
sum = sum.add(decimal); // sum = sum.add(decimal);
} // }
BigDecimal avg = sum.divide(BigDecimal.valueOf(decimals.size()), 2, RoundingMode.HALF_UP); // BigDecimal avg = sum.divide(BigDecimal.valueOf(decimals.size()), 2, RoundingMode.HALF_UP);
sb.append("").append(fundCounts.get(0).getName()).append("】本周平均涨跌幅为:").append(avg).append("\n"); // sb.append("【").append(fundCounts.get(0).getName()).append("】本周平均涨跌幅为:").append(avg).append("\n");
}); // });
if (StringUtils.isNotBlank(sb)) { // if (StringUtils.isNotBlank(sb)) {
dingTalkService.sendMsg(sb.toString()); // dingTalkService.sendMsg(sb.toString());
} // }
log.info("==========================[基金统计] 基金本周涨跌幅消息发送定时任务结束!=========================="); // log.info("==========================[基金统计] 基金本周涨跌幅消息发送定时任务结束!==========================");
} // }
//
} //}

View File

@@ -1,134 +1,134 @@
package com.xiang.xservice.application.script.xb.schedule.xb; //package com.xiang.xservice.application.script.xb.schedule.xb;
//
import com.alibaba.fastjson2.JSONObject; //import com.alibaba.fastjson2.JSONObject;
import com.google.common.collect.Lists; //import com.google.common.collect.Lists;
import com.xiang.xservice.application.script.xb.entity.pojo.xb.FundMessage; //import com.xiang.xservice.application.script.xb.entity.pojo.xb.FundMessage;
import com.xiang.xservice.application.script.xb.entity.pojo.xb.XbFundList; //import com.xiang.xservice.application.script.xb.entity.pojo.xb.XbFundList;
import com.xiang.xservice.application.script.xb.entity.response.xbyj.fund.FundInfo; //import com.xiang.xservice.application.script.xb.entity.response.xbyj.fund.FundInfo;
import com.xiang.xservice.application.script.xb.entity.response.xbyj.fund.FundList; //import com.xiang.xservice.application.script.xb.entity.response.xbyj.fund.FundList;
import com.xiang.xservice.application.script.xb.repository.XBFundMapper; //import com.xiang.xservice.application.script.xb.repository.XBFundMapper;
import com.xiang.xservice.application.script.xb.service.FundService; //import com.xiang.xservice.application.script.xb.service.FundService;
import com.xiang.xservice.basic.config.MyThreadFactory; //import com.xiang.xservice.basic.config.MyThreadFactory;
import lombok.RequiredArgsConstructor; //import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; //import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Value; //import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled; //import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; //import org.springframework.stereotype.Component;
//
import java.math.BigDecimal; //import java.math.BigDecimal;
import java.math.RoundingMode; //import java.math.RoundingMode;
import java.time.DayOfWeek; //import java.time.DayOfWeek;
import java.time.LocalDate; //import java.time.LocalDate;
import java.time.LocalDateTime; //import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; //import java.time.format.DateTimeFormatter;
import java.util.Arrays; //import java.util.Arrays;
import java.util.List; //import java.util.List;
import java.util.Objects; //import java.util.Objects;
import java.util.concurrent.CompletableFuture; //import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService; //import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue; //import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor; //import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; //import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; //import java.util.stream.Collectors;
//
/** ///**
* @Author: xiang // * @Author: xiang
* @Date: 2025-05-14 17:15 // * @Date: 2025-05-14 17:15
*/ // */
@Component //@Component
@RequiredArgsConstructor //@RequiredArgsConstructor
@Slf4j //@Slf4j
public class FundInfoQueryJob { //public class FundInfoQueryJob {
//
private final FundService fundService; // private final FundService fundService;
private final XBFundMapper xbFundMapper; // private final XBFundMapper xbFundMapper;
private final ExecutorService es = // private final ExecutorService es =
new ThreadPoolExecutor( // new ThreadPoolExecutor(
10, // 10,
20, // 20,
1000, // 1000,
TimeUnit.MILLISECONDS, // TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(), // new LinkedBlockingQueue<>(),
new MyThreadFactory("xb-query-thread", Boolean.TRUE), // new MyThreadFactory("xb-query-thread", Boolean.TRUE),
new ThreadPoolExecutor.AbortPolicy()); // new ThreadPoolExecutor.AbortPolicy());
@Value("${xiaobei.codeArr}") // @Value("${xiaobei.codeArr}")
private String codeArr; // private String codeArr;
//
//
/** // /**
* 基金每分钟涨幅记录 // * 基金每分钟涨幅记录
*/ // */
@Scheduled(cron = "0 0/1 9,10,11,13,14 * * ?") // @Scheduled(cron = "0 0/1 9,10,11,13,14 * * ?")
public void queryFundInfoInMinJob() { // public void queryFundInfoInMinJob() {
// 周六周日过滤 // // 周六周日过滤
if (Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SATURDAY) || // if (Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SATURDAY) ||
Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SUNDAY)) { // Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SUNDAY)) {
return; // return;
} // }
List<FundMessage> fundMessageList = queryFund(null); // List<FundMessage> fundMessageList = queryFund(null);
if (CollectionUtils.isEmpty(fundMessageList)) { // if (CollectionUtils.isEmpty(fundMessageList)) {
return; // return;
} // }
List<CompletableFuture> futures = Lists.newArrayList(); // List<CompletableFuture> futures = Lists.newArrayList();
List<com.xiang.xservice.application.script.xb.entity.pojo.xb.FundInfo> fundInfoList = Lists.newCopyOnWriteArrayList(); // List<com.xiang.xservice.application.script.xb.entity.pojo.xb.FundInfo> fundInfoList = Lists.newCopyOnWriteArrayList();
fundMessageList.parallelStream().forEach(fundMessage -> { // fundMessageList.parallelStream().forEach(fundMessage -> {
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> { // CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
FundInfo fundInfo = fundService.queryFundInfo(fundMessage.getCode()); // FundInfo fundInfo = fundService.queryFundInfo(fundMessage.getCode());
//
com.xiang.xservice.application.script.xb.entity.pojo.xb.FundInfo info = com.xiang.xservice.application.script.xb.entity.pojo.xb.FundInfo.builder() // com.xiang.xservice.application.script.xb.entity.pojo.xb.FundInfo info = com.xiang.xservice.application.script.xb.entity.pojo.xb.FundInfo.builder()
.code(fundMessage.getCode()) // .code(fundMessage.getCode())
.name(fundInfo.getName()) // .name(fundInfo.getName())
.change(fundMessage.getChange().multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP).toString()) // .change(fundMessage.getChange().multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP).toString())
.updateTime(getTimeFromStr(fundMessage.getDate(), fundMessage.getUpdate())) // .updateTime(getTimeFromStr(fundMessage.getDate(), fundMessage.getUpdate()))
.build(); // .build();
fundInfoList.add(info); // fundInfoList.add(info);
}, es); // }, es);
futures.add(future); // futures.add(future);
}); // });
//
CompletableFuture[] futureArr = futures // CompletableFuture[] futureArr = futures
.toArray(futures.toArray(new CompletableFuture[0])); // .toArray(futures.toArray(new CompletableFuture[0]));
CompletableFuture.allOf(futureArr).join(); // CompletableFuture.allOf(futureArr).join();
//
if (CollectionUtils.isNotEmpty(fundInfoList)) { // if (CollectionUtils.isNotEmpty(fundInfoList)) {
log.info("[基金查询] 每分钟基金涨跌幅查询记录,需要插入的数据:{}", JSONObject.toJSONString(fundInfoList)); // log.info("[基金查询] 每分钟基金涨跌幅查询记录,需要插入的数据:{}", JSONObject.toJSONString(fundInfoList));
xbFundMapper.batchSave(fundInfoList); // xbFundMapper.batchSave(fundInfoList);
} // }
} // }
//
private List<FundMessage> queryFund(Integer type) { // private List<FundMessage> queryFund(Integer type) {
String date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); // String date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
List<String> code = Lists.newArrayList(); // List<String> code = Lists.newArrayList();
List<XbFundList> lists = xbFundMapper.queryFundList(type); // List<XbFundList> lists = xbFundMapper.queryFundList(type);
if (CollectionUtils.isEmpty(lists)) { // if (CollectionUtils.isEmpty(lists)) {
if (Objects.equals(type, 1)) { // if (Objects.equals(type, 1)) {
code = Arrays.stream(codeArr.split(", ")).collect(Collectors.toList()); // code = Arrays.stream(codeArr.split(", ")).collect(Collectors.toList());
} // }
return Lists.newArrayList(); // return Lists.newArrayList();
} else { // } else {
code = lists.stream().map(XbFundList::getCode).collect(Collectors.toList()); // code = lists.stream().map(XbFundList::getCode).collect(Collectors.toList());
} // }
List<FundList> fundLists = fundService.queryTodayList(date, "2", Boolean.TRUE, code); // List<FundList> fundLists = fundService.queryTodayList(date, "2", Boolean.TRUE, code);
if (CollectionUtils.isEmpty(fundLists)) { // if (CollectionUtils.isEmpty(fundLists)) {
return Lists.newArrayList(); // return Lists.newArrayList();
} // }
List<FundMessage> result = Lists.newCopyOnWriteArrayList(); // List<FundMessage> result = Lists.newCopyOnWriteArrayList();
fundLists.parallelStream().forEach(fundList -> { // fundLists.parallelStream().forEach(fundList -> {
FundInfo fundInfo = fundService.queryFundInfo(fundList.getCode()); // FundInfo fundInfo = fundService.queryFundInfo(fundList.getCode());
if (Objects.nonNull(fundInfo)) { // if (Objects.nonNull(fundInfo)) {
FundMessage fund = FundMessage.builder().name(fundInfo.getName()).date(fundList.getDate()) // FundMessage fund = FundMessage.builder().name(fundInfo.getName()).date(fundList.getDate())
.code(fundList.getCode()).change(fundList.getChange()).update(fundList.getUpdate()).build(); // .code(fundList.getCode()).change(fundList.getChange()).update(fundList.getUpdate()).build();
result.add(fund); // result.add(fund);
} // }
}); // });
return result; // return result;
} // }
//
private LocalDateTime getTimeFromStr(String date, String time) { // private LocalDateTime getTimeFromStr(String date, String time) {
String dateTimeStr = date + " " + time; // String dateTimeStr = date + " " + time;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); // DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
return LocalDateTime.parse(dateTimeStr, formatter); // return LocalDateTime.parse(dateTimeStr, formatter);
} // }
//
} //}

View File

@@ -1,144 +1,144 @@
package com.xiang.xservice.application.script.xb.schedule.xb; //package com.xiang.xservice.application.script.xb.schedule.xb;
//
import com.alibaba.fastjson.JSON; //import com.alibaba.fastjson.JSON;
import com.xiang.xservice.application.script.xb.entity.pojo.xb.XbFundList; //import com.xiang.xservice.application.script.xb.entity.pojo.xb.XbFundList;
import com.xiang.xservice.application.script.xb.entity.response.xbyj.fund.FundList; //import com.xiang.xservice.application.script.xb.entity.response.xbyj.fund.FundList;
import com.xiang.xservice.application.script.xb.service.FundService; //import com.xiang.xservice.application.script.xb.service.FundService;
import com.xiang.xservice.common.service.dingTalk.StockDingTalkFactory; //import com.xiang.xservice.common.service.dingTalk.StockDingTalkFactory;
import lombok.RequiredArgsConstructor; //import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; //import org.apache.commons.collections4.CollectionUtils;
import org.springframework.scheduling.annotation.Scheduled; //import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; //import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping; //import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController; //import org.springframework.web.bind.annotation.RestController;
//
import java.math.BigDecimal; //import java.math.BigDecimal;
import java.math.RoundingMode; //import java.math.RoundingMode;
import java.time.DayOfWeek; //import java.time.DayOfWeek;
import java.time.LocalDate; //import java.time.LocalDate;
import java.time.LocalDateTime; //import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; //import java.time.format.DateTimeFormatter;
import java.util.ArrayList; //import java.util.ArrayList;
import java.util.Comparator; //import java.util.Comparator;
import java.util.List; //import java.util.List;
import java.util.Map; //import java.util.Map;
import java.util.Objects; //import java.util.Objects;
import java.util.function.Function; //import java.util.function.Function;
import java.util.stream.Collectors; //import java.util.stream.Collectors;
//
/** ///**
* @Author: xiang // * @Author: xiang
* @Date: 2025-07-31 18:10 // * @Date: 2025-07-31 18:10
*/ // */
@Component //@Component
@Slf4j //@Slf4j
@RestController //@RestController
@RequiredArgsConstructor //@RequiredArgsConstructor
public class FundMsgReportJob { //public class FundMsgReportJob {
//
private final FundService fundService; // private final FundService fundService;
private final StockDingTalkFactory dingTalkService; // private final StockDingTalkFactory dingTalkService;
private static final Integer TYPE_A = 1; // private static final Integer TYPE_A = 1;
private static final Integer TYPE_M = 3; // private static final Integer TYPE_M = 3;
private static final Integer TYPE_G = 2; // private static final Integer TYPE_G = 2;
//
@Scheduled(cron = "0 1,31 9,10,11,13,14 * * ?") // @Scheduled(cron = "0 1,31 9,10,11,13,14 * * ?")
@PostMapping("/asdasda") // @PostMapping("/asdasda")
public void fundReport4A() { // public void fundReport4A() {
log.info("===========A股基金变化通知==========="); // log.info("===========A股基金变化通知===========");
// 周六周日过滤 // // 周六周日过滤
if (Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SATURDAY) || // if (Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SATURDAY) ||
Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SUNDAY)) { // Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SUNDAY)) {
log.info("当前时间为:{}", LocalDateTime.now()); // log.info("当前时间为:{}", LocalDateTime.now());
return; // return;
} // }
List<XbFundList> fundLists = fundService.queryFundList(TYPE_A); // List<XbFundList> fundLists = fundService.queryFundList(TYPE_A);
if (CollectionUtils.isEmpty(fundLists)) { // if (CollectionUtils.isEmpty(fundLists)) {
log.info("查询配置的A股信息为空"); // log.info("查询配置的A股信息为空");
return; // return;
} // }
Map<String, XbFundList> fundMap = fundLists.stream().collect(Collectors.toMap(XbFundList::getCode, Function.identity(), (a, b) -> a)); // Map<String, XbFundList> fundMap = fundLists.stream().collect(Collectors.toMap(XbFundList::getCode, Function.identity(), (a, b) -> a));
String date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); // String date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
List<FundList> funds = fundService.queryTodayList(date, "2", Boolean.TRUE, new ArrayList<>(fundMap.keySet())); // List<FundList> funds = fundService.queryTodayList(date, "2", Boolean.TRUE, new ArrayList<>(fundMap.keySet()));
if (CollectionUtils.isEmpty(funds)) { // if (CollectionUtils.isEmpty(funds)) {
log.info("http请求查询基金信息为空"); // log.info("http请求查询基金信息为空");
return; // return;
} // }
log.info("http查询基金信息:{}", JSON.toJSONString(funds)); // log.info("http查询基金信息:{}", JSON.toJSONString(funds));
StringBuilder msg = new StringBuilder(date).append("===》A股基金变化通知:\n"); // StringBuilder msg = new StringBuilder(date).append("===》A股基金变化通知:\n");
buildMsg(funds, fundMap, msg); // buildMsg(funds, fundMap, msg);
dingTalkService.sendMsg(msg.toString()); // dingTalkService.sendMsg(msg.toString());
} // }
//
@Scheduled(cron = "0 1,31 9,10,11,13,14,15 * * ?") // @Scheduled(cron = "0 1,31 9,10,11,13,14,15 * * ?")
public void fundReport4G() { // public void fundReport4G() {
log.info("===========港股基金变化通知!==========="); // log.info("===========港股基金变化通知!===========");
// 周六周日过滤 // // 周六周日过滤
if (Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SATURDAY) || // if (Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SATURDAY) ||
Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SUNDAY)) { // Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SUNDAY)) {
log.info("当前时间为:{}", LocalDateTime.now()); // log.info("当前时间为:{}", LocalDateTime.now());
return; // return;
} // }
List<XbFundList> fundLists = fundService.queryFundList(TYPE_G); // List<XbFundList> fundLists = fundService.queryFundList(TYPE_G);
if (CollectionUtils.isEmpty(fundLists)) { // if (CollectionUtils.isEmpty(fundLists)) {
log.info("查询配置的港股信息为空"); // log.info("查询配置的港股信息为空");
return; // return;
} // }
Map<String, XbFundList> fundMap = fundLists.stream().collect(Collectors.toMap(XbFundList::getCode, Function.identity(), (a, b) -> a)); // Map<String, XbFundList> fundMap = fundLists.stream().collect(Collectors.toMap(XbFundList::getCode, Function.identity(), (a, b) -> a));
String date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); // String date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
List<FundList> funds = fundService.queryTodayList(date, "2", Boolean.TRUE, new ArrayList<>(fundMap.keySet())); // List<FundList> funds = fundService.queryTodayList(date, "2", Boolean.TRUE, new ArrayList<>(fundMap.keySet()));
if (CollectionUtils.isEmpty(funds)) { // if (CollectionUtils.isEmpty(funds)) {
log.info("http请求查询基金信息为空"); // log.info("http请求查询基金信息为空");
return; // return;
} // }
log.info("http查询港股基金信息:{}", JSON.toJSONString(funds)); // log.info("http查询港股基金信息:{}", JSON.toJSONString(funds));
StringBuilder msg = new StringBuilder(date).append("===》港股基金变化通知:\n"); // StringBuilder msg = new StringBuilder(date).append("===》港股基金变化通知:\n");
buildMsg(funds, fundMap, msg); // buildMsg(funds, fundMap, msg);
dingTalkService.sendMsg(msg.toString()); // dingTalkService.sendMsg(msg.toString());
} // }
//
@Scheduled(cron = "0 0 9 * * ?") // @Scheduled(cron = "0 0 9 * * ?")
public void fundReport4M() { // public void fundReport4M() {
log.info("===========美股基金变化通知!==========="); // log.info("===========美股基金变化通知!===========");
// 周六周日过滤 // // 周六周日过滤
if (Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SATURDAY) || // if (Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SATURDAY) ||
Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SUNDAY)) { // Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SUNDAY)) {
log.info("当前时间为:{}", LocalDateTime.now()); // log.info("当前时间为:{}", LocalDateTime.now());
return; // return;
} // }
List<XbFundList> fundLists = fundService.queryFundList(TYPE_M); // List<XbFundList> fundLists = fundService.queryFundList(TYPE_M);
if (CollectionUtils.isEmpty(fundLists)) { // if (CollectionUtils.isEmpty(fundLists)) {
log.info("查询配置的美股信息为空"); // log.info("查询配置的美股信息为空");
return; // return;
} // }
Map<String, XbFundList> fundMap = fundLists.stream().collect(Collectors.toMap(XbFundList::getCode, Function.identity(), (a, b) -> a)); // Map<String, XbFundList> fundMap = fundLists.stream().collect(Collectors.toMap(XbFundList::getCode, Function.identity(), (a, b) -> a));
String date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); // String date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
List<FundList> funds = fundService.queryTodayList(date, "2", Boolean.TRUE, new ArrayList<>(fundMap.keySet())); // List<FundList> funds = fundService.queryTodayList(date, "2", Boolean.TRUE, new ArrayList<>(fundMap.keySet()));
if (CollectionUtils.isEmpty(funds)) { // if (CollectionUtils.isEmpty(funds)) {
log.info("http请求查询基金信息为空"); // log.info("http请求查询基金信息为空");
return; // return;
} // }
log.info("http查询美股基金信息:{}", JSON.toJSONString(funds)); // log.info("http查询美股基金信息:{}", JSON.toJSONString(funds));
StringBuilder msg = new StringBuilder(date).append("===》美股基金变化通知:\n"); // StringBuilder msg = new StringBuilder(date).append("===》美股基金变化通知:\n");
buildMsg(funds, fundMap, msg); // buildMsg(funds, fundMap, msg);
dingTalkService.sendMsg(msg.toString()); // dingTalkService.sendMsg(msg.toString());
} // }
//
private static void buildMsg(List<FundList> funds, Map<String, XbFundList> fundMap, StringBuilder msg) { // private static void buildMsg(List<FundList> funds, Map<String, XbFundList> fundMap, StringBuilder msg) {
funds = funds.stream().sorted(Comparator.comparing(FundList::getChange).reversed()) // funds = funds.stream().sorted(Comparator.comparing(FundList::getChange).reversed())
.collect(Collectors.toList()); // .collect(Collectors.toList());
for (FundList fund : funds) { // for (FundList fund : funds) {
if (fundMap.containsKey(fund.getCode())) { // if (fundMap.containsKey(fund.getCode())) {
XbFundList fundList = fundMap.get(fund.getCode()); // XbFundList fundList = fundMap.get(fund.getCode());
msg.append("基金名称:") // msg.append("基金名称:")
.append(fundList.getName()) // .append(fundList.getName())
.append("涨跌幅:") // .append("涨跌幅:")
.append(fund.getChange() // .append(fund.getChange()
.multiply(new BigDecimal("100")) // .multiply(new BigDecimal("100"))
.setScale(2, RoundingMode.HALF_UP)) // .setScale(2, RoundingMode.HALF_UP))
.append("\n"); // .append("\n");
} // }
} // }
} // }
} //}