股票成交量对比功能
1. 股票成交量对比功能分析
1.1 模型示列
功能描述:统计A股大盘T日和T-1日成交量对比功能(成交量为沪深两市成交量之和)
1.2 接口示列
返回数据格式
服务路径:/api/quot/stock/tradeAmt
服务方法:GET
前端请求频率:每分钟
请求参数:无
{
"code": 1,
"data": {
"amtList": [{"count": 3926392,"time": "202112310930"},{"count": 3926392,"time": "202112310931"},...],//T日每分钟成交量信息
"yesAmtList":[{"count": 3926392,"time": "202112310930"},...]//T-1日每分钟成交量信息
}
}
1.3调用表结构
stock_market_index_info
2. 股票sql代码分析
- 确认所要查询的表(stock_market_index_info)
- 确认查询字段 --> 时间(格式化为字符串) , 交易量(需要对沪深两股的交易额进行合并计算)
- 确认查询条件 --> 从开盘到当前时间段沪深两股的交易信息
select
date_format(smi.cur_time,'%Y%m%d%H%i') as time,
sum(smi.trade_amount) as count
from
stock_market_index_info as smi
where
smi.cur_time between '2021-12-28 09:30:00' and '2021-12-28 14:40:00'
and
smi.market_code in ('sh000001','sz399001')
group by time
order by time asc;
3. 代码实现
表现层
/**
* 股票成交量统计
*/
@ApiOperation(value = "股票成交量统计", notes = "股票成交量统计", httpMethod = "GET")
@GetMapping("/stock/tradeAmt")
public R<Map> getTradeAmt(){
return service.getTradeAmt();
}
服务层
@Override
public R<Map> getTradeAmt() {
// 1. 获取当前时间
DateTime curTime = DateTimeUtil.getLastDate4Stock(DateTime.now());
curTime = DateTime.parse("2021-12-28 14:40:00", DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"));
Date nowDate = curTime.toDate();
// 获取开盘时间
Date openDate = DateTimeUtil.getOpenDate(curTime).toDate();
// 获取前一天的当前时间
DateTime previousTradingDay = DateTimeUtil.getPreviousTradingDay(curTime);
Date preDate = previousTradingDay.toDate();
// 获取前一天的开盘时间
Date tOpenDate = DateTimeUtil.getOpenDate(previousTradingDay).toDate();
// 2. 获取当前交易日的数据
List<Map> stockData = stockMarketIndexInfoMapper.getTradeAmt(nowDate,openDate,stockInfoConfig.getInner());
// 3. 获取前一天交易日的数据
List<Map> stockPreData = stockMarketIndexInfoMapper.getTradeAmt(preDate,tOpenDate,stockInfoConfig.getInner());
// 4. 封装数据
HashMap<String, List<Map>> data = new HashMap<>();
data.put("amtList",stockData);
data.put("yesAmtList",stockPreData);
return R.ok(data);
}
Dao层
<select id="getTradeAmt" resultType="java.util.Map">
select
date_format(smi.cur_time,'%Y%m%d%H%i') as time,
sum(smi.trade_amount) as count
from
stock_market_index_info as smi
where
smi.cur_time between #{openDate} and #{nowDate}
and
smi.market_code in
<foreach collection="inner" item="mark" open="(" separator="," close=")">
#{mark}
</foreach>
group by time
order by time asc
</select>
标签:count,功能,成交量,smi,time,对比,market,stock
From: https://blog.csdn.net/xiugtt6141121/article/details/142616526