feat:股票数据拉取发送消息
This commit is contained in:
@@ -17,6 +17,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|||||||
"com.xiang.xservice.glados.repository",
|
"com.xiang.xservice.glados.repository",
|
||||||
"com.xiang.xservice.xb.repository",
|
"com.xiang.xservice.xb.repository",
|
||||||
"com.xiang.xservice.stock.gnshyx.mapper",
|
"com.xiang.xservice.stock.gnshyx.mapper",
|
||||||
|
"com.xiang.xservice.stock.data.mapper",
|
||||||
})
|
})
|
||||||
@ConfigurationPropertiesScan(basePackages = {
|
@ConfigurationPropertiesScan(basePackages = {
|
||||||
"com.xiang.xservice.config"
|
"com.xiang.xservice.config"
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.xiang.xservice.stock.data.common.constants;
|
||||||
|
|
||||||
|
import com.xiang.xservice.basic.utils.DateUtils;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
public class RedisConstants {
|
||||||
|
|
||||||
|
public static final String MSG_SEND_REDIS_KEY = "stock:msg:send:";
|
||||||
|
|
||||||
|
|
||||||
|
public static String getDate4Key() {
|
||||||
|
return DateUtils.getDateFromDate(LocalDate.now(), "yyyyMMdd");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.xiang.xservice.stock.data.common.constants;
|
||||||
|
|
||||||
|
public class UrlConstants {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新浪财经 股票数据拉取
|
||||||
|
*/
|
||||||
|
public static final String SINA_STOCK_DATA_PULL_URL = "https://hq.sinajs.cn/list=";
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package com.xiang.xservice.stock.data.entity;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class StockSinaDataRecordDO {
|
||||||
|
/**
|
||||||
|
* 主键id
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 股票名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 今开价格
|
||||||
|
*/
|
||||||
|
private BigDecimal jkPrice;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 昨收价格
|
||||||
|
*/
|
||||||
|
private BigDecimal zsPrice;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 现在价格
|
||||||
|
*/
|
||||||
|
private BigDecimal xjPrice;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最高价格
|
||||||
|
*/
|
||||||
|
private BigDecimal zgPrice;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最低价格
|
||||||
|
*/
|
||||||
|
private BigDecimal zdPrice;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 总手数量
|
||||||
|
*/
|
||||||
|
private String zsNum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 总交易金额
|
||||||
|
*/
|
||||||
|
private BigDecimal price;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.xiang.xservice.stock.data.mapper;
|
||||||
|
|
||||||
|
import com.xiang.xservice.stock.data.entity.StockSinaDataRecordDO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
@Mapper
|
||||||
|
public interface StockSinaDataRecordPullMapper {
|
||||||
|
|
||||||
|
int batchInsert(@Param("list") List<StockSinaDataRecordDO> list);
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package com.xiang.xservice.stock.data.schedule;
|
||||||
|
|
||||||
|
import com.xiang.xservice.basic.utils.DateUtils;
|
||||||
|
import com.xiang.xservice.cache.service.IRedisService;
|
||||||
|
import com.xiang.xservice.stock.data.common.constants.RedisConstants;
|
||||||
|
import com.xiang.xservice.stock.data.entity.StockSinaDataRecordDO;
|
||||||
|
import com.xiang.xservice.stock.data.service.DingTalkScriptStockService;
|
||||||
|
import com.xiang.xservice.stock.data.service.IStockDataService;
|
||||||
|
import com.xiang.xservice.stock.gnshyx.entity.StockGnshyxRecordDataDO;
|
||||||
|
import com.xiang.xservice.stock.gnshyx.service.ICloudRecordDataService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.time.DayOfWeek;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class DataMsgSendJob {
|
||||||
|
|
||||||
|
private final ICloudRecordDataService cloudRecordDataService;
|
||||||
|
private final IStockDataService stockDataService;
|
||||||
|
private final DingTalkScriptStockService dingTalkScriptStockService;
|
||||||
|
private final IRedisService redisService;
|
||||||
|
|
||||||
|
@Scheduled(cron = "0/10 * * * * ?")
|
||||||
|
public void stockGetTargetMsgSend() {
|
||||||
|
if (DateUtils.validWeekTime()) return;
|
||||||
|
|
||||||
|
StringBuilder msg = new StringBuilder("0000");
|
||||||
|
List<StockGnshyxRecordDataDO> list = cloudRecordDataService.getList();
|
||||||
|
for (StockGnshyxRecordDataDO stockGnshyxRecordDataDO : list) {
|
||||||
|
String stockCode = stockGnshyxRecordDataDO.getStockCode();
|
||||||
|
String[] values = stockCode.split("\\.");
|
||||||
|
String c1 = values[1].toLowerCase();
|
||||||
|
String c2 = values[0];
|
||||||
|
String code = c1 + c2;
|
||||||
|
String resp = stockDataService.getStockDataFromHttp(code);
|
||||||
|
StockSinaDataRecordDO recordDO = stockDataService.buildRecordDO(resp);
|
||||||
|
if (Objects.nonNull(recordDO)) {
|
||||||
|
Object o = redisService.hGet(RedisConstants.MSG_SEND_REDIS_KEY + RedisConstants.getDate4Key(), stockGnshyxRecordDataDO.getStockCode());
|
||||||
|
if (Objects.isNull(o)) {
|
||||||
|
if (recordDO.getXjPrice().compareTo(stockGnshyxRecordDataDO.getAttentionPrice()) > 0) {
|
||||||
|
msg.append("股票代码:").append(stockGnshyxRecordDataDO.getStockCode()).append(",名称:").append(stockGnshyxRecordDataDO.getStockName()).append("达到预期的价格:").append(stockGnshyxRecordDataDO.getAttentionPrice()).append("\n");
|
||||||
|
}
|
||||||
|
if (recordDO.getXjPrice().compareTo(stockGnshyxRecordDataDO.getStopPrice()) < 0) {
|
||||||
|
msg.append("股票代码:").append(stockGnshyxRecordDataDO.getStockCode()).append(",名称:").append(stockGnshyxRecordDataDO.getStockName()).append("达到止损的价格:").append(stockGnshyxRecordDataDO.getStopPrice()).append("\n");
|
||||||
|
}
|
||||||
|
redisService.hSet(RedisConstants.MSG_SEND_REDIS_KEY + RedisConstants.getDate4Key(), stockGnshyxRecordDataDO.getStockCode(), "true");
|
||||||
|
redisService.expire("xservice-script-center", RedisConstants.MSG_SEND_REDIS_KEY + RedisConstants.getDate4Key(), 10, TimeUnit.DAYS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(msg)) {
|
||||||
|
log.info("发送钉钉消息:{}", msg);
|
||||||
|
dingTalkScriptStockService.sendScriptMsg(msg.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean validTime() {
|
||||||
|
if (Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SATURDAY) ||
|
||||||
|
Objects.equals(LocalDateTime.now().getDayOfWeek(), DayOfWeek.SUNDAY)) {
|
||||||
|
log.info("当前时间为:{}", LocalDateTime.now());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
LocalTime now = LocalTime.now();
|
||||||
|
|
||||||
|
boolean inMorning = now.isAfter(LocalTime.of(9, 29)) && now.isBefore(LocalTime.of(11, 31));
|
||||||
|
boolean inAfternoon = now.isAfter(LocalTime.of(12, 59)) && now.isBefore(LocalTime.of(15, 1));
|
||||||
|
if (!inAfternoon && !inMorning) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package com.xiang.xservice.stock.data.schedule;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.xiang.xservice.basic.utils.DateUtils;
|
||||||
|
import com.xiang.xservice.stock.data.entity.StockSinaDataRecordDO;
|
||||||
|
import com.xiang.xservice.stock.data.service.IStockDataService;
|
||||||
|
import com.xiang.xservice.stock.gnshyx.entity.StockGnshyxRecordDataDO;
|
||||||
|
import com.xiang.xservice.stock.gnshyx.service.ICloudRecordDataService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class StockDataPullJob {
|
||||||
|
|
||||||
|
private final ICloudRecordDataService cloudRecordDataService;
|
||||||
|
private final IStockDataService stockDataService;
|
||||||
|
private static final Integer BATCH_SIZE = 500;
|
||||||
|
|
||||||
|
@Scheduled(cron = "*/1 * * * * ?")
|
||||||
|
public void sinaDataPullJob() {
|
||||||
|
if (DateUtils.validWeekTime()) return;
|
||||||
|
log.info(">>>>>>>>>>>>>>>>>新浪财经数据拉取开始>>>>>>>>>>>>>>>>>");
|
||||||
|
List<StockGnshyxRecordDataDO> dataList = cloudRecordDataService.getList();
|
||||||
|
List<StockSinaDataRecordDO> result = Lists.newArrayList();
|
||||||
|
for (StockGnshyxRecordDataDO stockGnshyxRecordDataDO : dataList) {
|
||||||
|
String stockCode = stockGnshyxRecordDataDO.getStockCode();
|
||||||
|
String[] values = stockCode.split("\\.");
|
||||||
|
String c1 = values[1].toLowerCase();
|
||||||
|
String c2 = values[0];
|
||||||
|
String code = c1 + c2;
|
||||||
|
String resp = stockDataService.getStockDataFromHttp(code);
|
||||||
|
StockSinaDataRecordDO stockSinaDataRecordDO = stockDataService.buildRecordDO(resp);
|
||||||
|
if (Objects.nonNull(stockSinaDataRecordDO)) {
|
||||||
|
result.add(stockSinaDataRecordDO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CollectionUtils.isNotEmpty(result)) {
|
||||||
|
if (BATCH_SIZE > result.size()) {
|
||||||
|
Lists.partition(result, BATCH_SIZE).forEach(stockDataService::insertData2DB);
|
||||||
|
} else {
|
||||||
|
stockDataService.insertData2DB(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.info(">>>>>>>>>>>>>>>>>新浪财经数据拉取结束>>>>>>>>>>>>>>>>>");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.xiang.xservice.stock.data.service;
|
||||||
|
|
||||||
|
import com.xiang.xservice.basic.xservice.dingTalk.service.DingTalkService;
|
||||||
|
import com.xiang.xservice.config.DingTalkRobotXbConfig;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2025-08-07 10:30
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class DingTalkScriptStockService {
|
||||||
|
|
||||||
|
private final DingTalkService dingTalkService;
|
||||||
|
private final DingTalkRobotXbConfig dingTalkRobotXbConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送脚本消息
|
||||||
|
* @param msg 消息
|
||||||
|
*/
|
||||||
|
public void sendScriptMsg(String msg) {
|
||||||
|
try {
|
||||||
|
dingTalkService.sendRobotMessage(dingTalkRobotXbConfig.getSecret(), dingTalkRobotXbConfig.getToken(), dingTalkRobotXbConfig.getUsers(), msg);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("信息发送异常, 信息:{}", msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.xiang.xservice.stock.data.service;
|
||||||
|
|
||||||
|
import com.xiang.xservice.stock.data.entity.StockSinaDataRecordDO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface IStockDataService {
|
||||||
|
|
||||||
|
String getStockDataFromHttp(String stockCode);
|
||||||
|
|
||||||
|
boolean insertData2DB(List<StockSinaDataRecordDO> stockSinaDataRecordDOs);
|
||||||
|
|
||||||
|
StockSinaDataRecordDO buildRecordDO(String resp);
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
package com.xiang.xservice.stock.data.service;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import com.xiang.xservice.basic.exception.BusinessException;
|
||||||
|
import com.xiang.xservice.basic.utils.HttpUtils;
|
||||||
|
import com.xiang.xservice.stock.data.common.constants.UrlConstants;
|
||||||
|
import com.xiang.xservice.stock.data.entity.StockSinaDataRecordDO;
|
||||||
|
import com.xiang.xservice.stock.data.mapper.StockSinaDataRecordPullMapper;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class StockDataServiceImpl implements IStockDataService{
|
||||||
|
|
||||||
|
private final StockSinaDataRecordPullMapper stockSinaDataRecordPullMapper;
|
||||||
|
|
||||||
|
//文灿股份,22.210,22.240,22.070,22.310,21.960,22.070,22.080,5173623, 114323642.000, 2900, 22.070,7600, 22.060,4600, 22.050,2700, 22.040,4700, 22.030,600, 22.080,29800,22.090,3800, 22.100,3000, 22.120,800, 22.130,2025-09-19,15:00:02,00
|
||||||
|
//浦发银行,12.690,12.750,12.810,12.900,12.560,12.800,12.810,79638295,1015780801.000,78500, 12.800,88400, 12.790,151900,12.780,42900,12.770,71700,12.760,841170, 12.810,1100, 12.830,48100,12.860,128600,12.870,116600,12.880,2025-09-19,15:00:03,00,
|
||||||
|
//平安银行,11.410,11.410,11.450,11.510,11.370,11.450,11.460,83465123,955004096.910, 103813,11.450,321000,11.440,198700,11.430,216100,11.420,553000,11.410,15300,11.460,27500,11.470,28400,11.480,175335,11.490,893111,11.500,2025-09-19,15:00:00,00
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getStockDataFromHttp(String stockCode) {
|
||||||
|
String url = UrlConstants.SINA_STOCK_DATA_PULL_URL + stockCode;
|
||||||
|
|
||||||
|
Map<String, String> headers = Maps.newHashMap();
|
||||||
|
headers.put("Referer", "https://finance.sina.com.cn");
|
||||||
|
headers.put("User-Agent", "Mozilla/5.0");
|
||||||
|
String resp = HttpUtils.doGet(url, headers, null);
|
||||||
|
if (StringUtils.isBlank(resp)) {
|
||||||
|
log.error("http请求拉取新浪财经股票数据失败, 股票代码:{}, 响应结果:{}", stockCode, resp);
|
||||||
|
throw new BusinessException("拉取数据失败");
|
||||||
|
}
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean insertData2DB(List<StockSinaDataRecordDO> stockSinaDataRecordDOs) {
|
||||||
|
return stockSinaDataRecordPullMapper.batchInsert(stockSinaDataRecordDOs) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StockSinaDataRecordDO buildRecordDO(String resp) {
|
||||||
|
if (resp.contains("=")) {
|
||||||
|
resp = resp.split("=")[1].replace("\"", "").replace(";", "");
|
||||||
|
if (StringUtils.equals(resp, "FAILED")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String[] values = resp.split(",");
|
||||||
|
|
||||||
|
// 股票名称
|
||||||
|
String mc = values[0];
|
||||||
|
// 今开价格
|
||||||
|
String jk = values[1];
|
||||||
|
// 昨收价格
|
||||||
|
String zs = values[2];
|
||||||
|
// 现在价格
|
||||||
|
String xj = values[3];
|
||||||
|
// 最高价格
|
||||||
|
String zg = values[4];
|
||||||
|
// 最低价格
|
||||||
|
String zd = values[5];
|
||||||
|
// 总手
|
||||||
|
String zongshou = values[8];
|
||||||
|
// 金额
|
||||||
|
String je = values[9];
|
||||||
|
// 时间
|
||||||
|
String sj = values[values.length - 3];
|
||||||
|
// 日期
|
||||||
|
String rq = values[values.length - 4];
|
||||||
|
|
||||||
|
BigDecimal change = (new BigDecimal(xj).subtract(new BigDecimal(zs))).divide(new BigDecimal(zs), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
|
||||||
|
log.info("股票名称:{}, 当前价格:{}, 昨收价格:{}, 涨跌幅:{}%", mc, xj, zs, change);
|
||||||
|
|
||||||
|
StockSinaDataRecordDO stockSinaDataRecordDO = new StockSinaDataRecordDO();
|
||||||
|
stockSinaDataRecordDO.setName(mc);
|
||||||
|
stockSinaDataRecordDO.setJkPrice(new BigDecimal(jk));
|
||||||
|
stockSinaDataRecordDO.setZsPrice(new BigDecimal(zs));
|
||||||
|
stockSinaDataRecordDO.setXjPrice(new BigDecimal(xj));
|
||||||
|
stockSinaDataRecordDO.setZgPrice(new BigDecimal(zg));
|
||||||
|
stockSinaDataRecordDO.setZdPrice(new BigDecimal(zd));
|
||||||
|
stockSinaDataRecordDO.setZsNum(zs);
|
||||||
|
stockSinaDataRecordDO.setPrice(new BigDecimal(je));
|
||||||
|
stockSinaDataRecordDO.setUpdateTime(LocalDateTime.now());
|
||||||
|
return stockSinaDataRecordDO;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,4 +17,13 @@ public interface StockGnshyxRecordDataMapper {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int batchInsertRecord(@Param("list") List<StockGnshyxRecordDataDO> entities);
|
int batchInsertRecord(@Param("list") List<StockGnshyxRecordDataDO> entities);
|
||||||
|
|
||||||
|
List<StockGnshyxRecordDataDO> getList();
|
||||||
|
|
||||||
|
|
||||||
|
int insert(StockGnshyxRecordDataDO entity);
|
||||||
|
|
||||||
|
StockGnshyxRecordDataDO getByStockCode(@Param("stockCode") String stockCode);
|
||||||
|
|
||||||
|
int update(StockGnshyxRecordDataDO entity);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package com.xiang.xservice.stock.gnshyx.schedule;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.xiang.xservice.basic.utils.DateUtils;
|
import com.xiang.xservice.basic.utils.DateUtils;
|
||||||
import com.xiang.xservice.basic.utils.HttpUtils;
|
import com.xiang.xservice.basic.utils.HttpUtils;
|
||||||
import com.xiang.xservice.stock.gnshyx.common.constants.UrlConstant;
|
import com.xiang.xservice.stock.gnshyx.common.constants.UrlConstant;
|
||||||
@@ -18,6 +17,7 @@ import org.springframework.stereotype.Component;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@@ -26,7 +26,7 @@ public class CloudRecordDataJob {
|
|||||||
|
|
||||||
private final ICloudRecordDataService cloudRecordDataService;
|
private final ICloudRecordDataService cloudRecordDataService;
|
||||||
|
|
||||||
@Scheduled(cron = "0 0/1 * * * ? ")
|
@Scheduled(cron = "0 30 9,14 * * ?")
|
||||||
public void gnshyxRecordDataPullJob() {
|
public void gnshyxRecordDataPullJob() {
|
||||||
log.info("<<<<<gnshyx数据拉取定时任务开始>>>>>, 时间戳:{}", System.currentTimeMillis());
|
log.info("<<<<<gnshyx数据拉取定时任务开始>>>>>, 时间戳:{}", System.currentTimeMillis());
|
||||||
|
|
||||||
@@ -42,28 +42,41 @@ public class CloudRecordDataJob {
|
|||||||
log.info("查询到的数据结果:{}", data);
|
log.info("查询到的数据结果:{}", data);
|
||||||
List<ListLastDataResp> dataRespList = JSON.parseArray(data, ListLastDataResp.class);
|
List<ListLastDataResp> dataRespList = JSON.parseArray(data, ListLastDataResp.class);
|
||||||
if (CollectionUtils.isNotEmpty(dataRespList)) {
|
if (CollectionUtils.isNotEmpty(dataRespList)) {
|
||||||
List<StockGnshyxRecordDataDO> results = Lists.newArrayList();
|
|
||||||
for (ListLastDataResp listLastDataResp : dataRespList) {
|
for (ListLastDataResp listLastDataResp : dataRespList) {
|
||||||
StockGnshyxRecordDataDO stockGnshyxRecordDataDO = new StockGnshyxRecordDataDO();
|
StockGnshyxRecordDataDO stock = cloudRecordDataService.getByStockCode(listLastDataResp.getStockCode());
|
||||||
stockGnshyxRecordDataDO.setSymbolName(listLastDataResp.getSymbolName());
|
if (Objects.nonNull(stock)) {
|
||||||
stockGnshyxRecordDataDO.setStockName(listLastDataResp.getStockName());
|
stock.setSymbolName(listLastDataResp.getSymbolName());
|
||||||
stockGnshyxRecordDataDO.setAttentionPrice(listLastDataResp.getAttentionPrice());
|
stock.setStockName(listLastDataResp.getStockName());
|
||||||
stockGnshyxRecordDataDO.setTargetPriceLow(listLastDataResp.getTargetPriceLow());
|
stock.setAttentionPrice(listLastDataResp.getAttentionPrice());
|
||||||
stockGnshyxRecordDataDO.setTargetPriceHigh(listLastDataResp.getTargetPriceHigh());
|
stock.setTargetPriceLow(listLastDataResp.getTargetPriceLow());
|
||||||
stockGnshyxRecordDataDO.setStopPrice(listLastDataResp.getStopPrice());
|
stock.setTargetPriceHigh(listLastDataResp.getTargetPriceHigh());
|
||||||
stockGnshyxRecordDataDO.setStockDailySelectionId(listLastDataResp.getStockDailySelectionId());
|
stock.setStopPrice(listLastDataResp.getStopPrice());
|
||||||
stockGnshyxRecordDataDO.setStockCode(listLastDataResp.getStockCode());
|
stock.setStockDailySelectionId(listLastDataResp.getStockDailySelectionId());
|
||||||
stockGnshyxRecordDataDO.setSelectionTime(DateUtils.getDateTimeFromStr(listLastDataResp.getSelectionTime()));
|
stock.setStockCode(listLastDataResp.getStockCode());
|
||||||
stockGnshyxRecordDataDO.setMaximumIncrease(listLastDataResp.getMaximumIncrease());
|
stock.setSelectionTime(DateUtils.getDateTimeFromStr(listLastDataResp.getSelectionTime()));
|
||||||
stockGnshyxRecordDataDO.setMaximumIncreaseSeven(listLastDataResp.getMaximumIncreaseSeven());
|
stock.setMaximumIncrease(listLastDataResp.getMaximumIncrease());
|
||||||
stockGnshyxRecordDataDO.setCreateTime(LocalDateTime.now());
|
stock.setMaximumIncreaseSeven(listLastDataResp.getMaximumIncreaseSeven());
|
||||||
results.add(stockGnshyxRecordDataDO);
|
stock.setCreateTime(LocalDateTime.now());
|
||||||
}
|
cloudRecordDataService.updateRecord(stock);
|
||||||
if (CollectionUtils.isNotEmpty(results)) {
|
} else {
|
||||||
cloudRecordDataService.batchInsertRecord(results);
|
StockGnshyxRecordDataDO stockGnshyxRecordDataDO = new StockGnshyxRecordDataDO();
|
||||||
|
stockGnshyxRecordDataDO.setSymbolName(listLastDataResp.getSymbolName());
|
||||||
|
stockGnshyxRecordDataDO.setStockName(listLastDataResp.getStockName());
|
||||||
|
stockGnshyxRecordDataDO.setAttentionPrice(listLastDataResp.getAttentionPrice());
|
||||||
|
stockGnshyxRecordDataDO.setTargetPriceLow(listLastDataResp.getTargetPriceLow());
|
||||||
|
stockGnshyxRecordDataDO.setTargetPriceHigh(listLastDataResp.getTargetPriceHigh());
|
||||||
|
stockGnshyxRecordDataDO.setStopPrice(listLastDataResp.getStopPrice());
|
||||||
|
stockGnshyxRecordDataDO.setStockDailySelectionId(listLastDataResp.getStockDailySelectionId());
|
||||||
|
stockGnshyxRecordDataDO.setStockCode(listLastDataResp.getStockCode());
|
||||||
|
stockGnshyxRecordDataDO.setSelectionTime(DateUtils.getDateTimeFromStr(listLastDataResp.getSelectionTime()));
|
||||||
|
stockGnshyxRecordDataDO.setMaximumIncrease(listLastDataResp.getMaximumIncrease());
|
||||||
|
stockGnshyxRecordDataDO.setMaximumIncreaseSeven(listLastDataResp.getMaximumIncreaseSeven());
|
||||||
|
stockGnshyxRecordDataDO.setCreateTime(LocalDateTime.now());
|
||||||
|
cloudRecordDataService.insertRecord(stockGnshyxRecordDataDO);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,29 @@ import java.util.List;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class CloudRecordDataServiceImpl implements ICloudRecordDataService {
|
public class CloudRecordDataServiceImpl implements ICloudRecordDataService {
|
||||||
private final StockGnshyxRecordDataMapper stockGnshyxRecordDataMapper;
|
private final StockGnshyxRecordDataMapper stockGnshyxRecordDataMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean insertRecord(StockGnshyxRecordDataDO entity) {
|
||||||
|
return stockGnshyxRecordDataMapper.insert(entity) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean batchInsertRecord(List<StockGnshyxRecordDataDO> list) {
|
public Boolean batchInsertRecord(List<StockGnshyxRecordDataDO> list) {
|
||||||
return stockGnshyxRecordDataMapper.batchInsertRecord(list) > 0;
|
return stockGnshyxRecordDataMapper.batchInsertRecord(list) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<StockGnshyxRecordDataDO> getList() {
|
||||||
|
return stockGnshyxRecordDataMapper.getList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean updateRecord(StockGnshyxRecordDataDO entity) {
|
||||||
|
return stockGnshyxRecordDataMapper.update(entity) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StockGnshyxRecordDataDO getByStockCode(String stockCode) {
|
||||||
|
return stockGnshyxRecordDataMapper.getByStockCode(stockCode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,5 +6,13 @@ import java.util.List;
|
|||||||
|
|
||||||
public interface ICloudRecordDataService {
|
public interface ICloudRecordDataService {
|
||||||
|
|
||||||
|
Boolean insertRecord(StockGnshyxRecordDataDO entity);
|
||||||
|
|
||||||
Boolean batchInsertRecord(List<StockGnshyxRecordDataDO> list);
|
Boolean batchInsertRecord(List<StockGnshyxRecordDataDO> list);
|
||||||
|
|
||||||
|
List<StockGnshyxRecordDataDO> getList();
|
||||||
|
|
||||||
|
Boolean updateRecord(StockGnshyxRecordDataDO entity);
|
||||||
|
|
||||||
|
StockGnshyxRecordDataDO getByStockCode(String stockCode);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,6 +151,14 @@
|
|||||||
DELETE FROM stock_gnshyx_record_data
|
DELETE FROM stock_gnshyx_record_data
|
||||||
WHERE id = #{id}
|
WHERE id = #{id}
|
||||||
</delete>
|
</delete>
|
||||||
|
<select id="getList" resultMap="BaseResultMap">
|
||||||
|
select <include refid="Base_Column_List"/>
|
||||||
|
from stock_gnshyx_record_data where 1=1
|
||||||
|
</select>
|
||||||
|
<select id="getByStockCode" resultMap="BaseResultMap">
|
||||||
|
select <include refid="Base_Column_List"/>
|
||||||
|
from stock_gnshyx_record_data where stock_code = #{stockCode}
|
||||||
|
</select>
|
||||||
|
|
||||||
<update id="update" parameterType="com.xiang.xservice.stock.gnshyx.entity.StockGnshyxRecordDataDO">
|
<update id="update" parameterType="com.xiang.xservice.stock.gnshyx.entity.StockGnshyxRecordDataDO">
|
||||||
UPDATE stock_gnshyx_record_data
|
UPDATE stock_gnshyx_record_data
|
||||||
|
|||||||
@@ -0,0 +1,126 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.xiang.xservice.stock.data.mapper.StockSinaDataRecordPullMapper">
|
||||||
|
|
||||||
|
<resultMap id="BaseResultMap" type="com.xiang.xservice.stock.data.entity.StockSinaDataRecordDO" >
|
||||||
|
<result column="id" property="id" />
|
||||||
|
<result column="name" property="name" />
|
||||||
|
<result column="jk_price" property="jkPrice" />
|
||||||
|
<result column="zs_price" property="zsPrice" />
|
||||||
|
<result column="xj_price" property="xjPrice" />
|
||||||
|
<result column="zg_price" property="zgPrice" />
|
||||||
|
<result column="zd_price" property="zdPrice" />
|
||||||
|
<result column="zs_num" property="zsNum" />
|
||||||
|
<result column="price" property="price" />
|
||||||
|
<result column="update_time" property="updateTime" />
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
jk_price,
|
||||||
|
zs_price,
|
||||||
|
xj_price,
|
||||||
|
zg_price,
|
||||||
|
zd_price,
|
||||||
|
zs_num,
|
||||||
|
price,
|
||||||
|
update_time
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<insert id="insert" useGeneratedKeys="true" keyColumn="id" keyProperty="id" parameterType="com.xiang.xservice.stock.data.entity.StockSinaDataRecordDO">
|
||||||
|
INSERT INTO stock_sina_record_data
|
||||||
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="null != name and '' != name">
|
||||||
|
name,
|
||||||
|
</if>
|
||||||
|
<if test="null != jkPrice ">
|
||||||
|
jk_price,
|
||||||
|
</if>
|
||||||
|
<if test="null != zsPrice ">
|
||||||
|
zs_price,
|
||||||
|
</if>
|
||||||
|
<if test="null != xjPrice ">
|
||||||
|
xj_price,
|
||||||
|
</if>
|
||||||
|
<if test="null != zgPrice ">
|
||||||
|
zg_price,
|
||||||
|
</if>
|
||||||
|
<if test="null != zdPrice ">
|
||||||
|
zd_price,
|
||||||
|
</if>
|
||||||
|
<if test="null != zsNum and '' != zsNum">
|
||||||
|
zs_num,
|
||||||
|
</if>
|
||||||
|
<if test="null != price ">
|
||||||
|
price,
|
||||||
|
</if>
|
||||||
|
<if test="null != updateTime ">
|
||||||
|
update_time
|
||||||
|
</if>
|
||||||
|
</trim>
|
||||||
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="null != name and '' != name">
|
||||||
|
#{name},
|
||||||
|
</if>
|
||||||
|
<if test="null != jkPrice ">
|
||||||
|
#{jkPrice},
|
||||||
|
</if>
|
||||||
|
<if test="null != zsPrice ">
|
||||||
|
#{zsPrice},
|
||||||
|
</if>
|
||||||
|
<if test="null != xjPrice ">
|
||||||
|
#{xjPrice},
|
||||||
|
</if>
|
||||||
|
<if test="null != zgPrice ">
|
||||||
|
#{zgPrice},
|
||||||
|
</if>
|
||||||
|
<if test="null != zdPrice ">
|
||||||
|
#{zdPrice},
|
||||||
|
</if>
|
||||||
|
<if test="null != zsNum and '' != zsNum">
|
||||||
|
#{zsNum},
|
||||||
|
</if>
|
||||||
|
<if test="null != price ">
|
||||||
|
#{price},
|
||||||
|
</if>
|
||||||
|
<if test="null != updateTime ">
|
||||||
|
#{updateTime}
|
||||||
|
</if>
|
||||||
|
</trim>
|
||||||
|
</insert>
|
||||||
|
<insert id="batchInsert">
|
||||||
|
INSERT INTO stock_sina_record_data
|
||||||
|
(name, jk_price, zs_price, xj_price, zg_price, zd_price, zs_num, price, update_time)
|
||||||
|
VALUES
|
||||||
|
<foreach collection="list" item="item" separator=",">
|
||||||
|
(#{item.name}, #{item.jkPrice}, #{item.zsPrice}, #{item.xjPrice},
|
||||||
|
#{item.zgPrice}, #{item.zdPrice}, #{item.zsNum}, #{item.price}, #{item.updateTime})
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<delete id="delete" >
|
||||||
|
DELETE FROM stock_sina_record_data
|
||||||
|
WHERE id = #{id}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<update id="update" parameterType="com.xiang.xservice.stock.data.entity.StockSinaDataRecordDO">
|
||||||
|
UPDATE stock_sina_record_data
|
||||||
|
<set>
|
||||||
|
<if test="null != name and '' != name">name = #{name},</if>
|
||||||
|
<if test="null != jkPrice ">jk_price = #{jkPrice},</if>
|
||||||
|
<if test="null != zsPrice ">zs_price = #{zsPrice},</if>
|
||||||
|
<if test="null != xjPrice ">xj_price = #{xjPrice},</if>
|
||||||
|
<if test="null != zgPrice ">zg_price = #{zgPrice},</if>
|
||||||
|
<if test="null != zdPrice ">zd_price = #{zdPrice},</if>
|
||||||
|
<if test="null != zsNum and '' != zsNum">zs_num = #{zsNum},</if>
|
||||||
|
<if test="null != price ">price = #{price},</if>
|
||||||
|
<if test="null != updateTime ">update_time = #{updateTime}</if>
|
||||||
|
</set>
|
||||||
|
WHERE id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Reference in New Issue
Block a user