个股周K线功能实现
1 个股周K线功能实现功能分析
1)个股周K线功能原型分析
2)个股周K线功能接口分析
个股周K线数据主要包含:
股票ID、 一周内最高价、 一周内最低价 、周1开盘价、周5的收盘价、
整周均价、以及一周内最大交易日期(一般是周五所对应日期)
接口要求:
功能描述:统计每周内的股票数据信息,信息包含:
股票ID、 一周内最高价、 一周内最低价 、周1开盘价、周5的收盘价、
整周均价、以及一周内最大交易日期(一般是周五所对应日期);
服务路径:/api/quot/stock/screen/weekkline
服务方法:GET
请求参数:code //股票编码
响应数据格式:
{
"code": 1,
"data": [
{
"avgPrice": 8.574954,//一周内平均价
"minPrice": 8.56,//一周内最低价
"openPrice": 8.6,//周一开盘价
"maxPrice": 8.6,//一周内最高价
"closePrice": 8.57,//周五收盘价(如果当前日期不到周五,则显示最新价格)
"mxTime": "2021-12-19 15:00",//一周内最大时间
"stockCode": "600000"//股票编码
}
]
}
代码实现
1. 表现层
/**
* 个股周K线功能
*/
@ApiOperation(value = "个股周K线功能", notes = "个股周K线功能", httpMethod = "GET")
@GetMapping("/stock/screen/weekkline")
public R<List<WeekklineDomain>> getWeekkline(@RequestParam String code){
return service.getWeekkline(code);
}
2. 服务层
R<List<WeekklineDomain>> getWeekkline(String code);
@Override
public R<List<WeekklineDomain>> getWeekkline(String code) {
// 获取当前时间点
DateTime curDate = DateTimeUtil.getLastDate4Stock(DateTime.now());
// 制造mock数据
curDate = DateTime.parse("2022-07-07 14:55:00", DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"));
Date endDate = curDate.toDate();
Date startDate = curDate.minusMonths(3).toDate();
List<WeekklineDomain> date = stockRtInfoMapper.getWeekkline(startDate,endDate,code);
return R.ok(date);
}
3. Dao层
List<WeekklineDomain> getWeekkline(@Param("startDate") Date startDate, @Param("endDate") Date endDate, @Param("code") String code);
<select id="getWeekkline" resultType="com.jixu.stock.pojo.domain.WeekklineDomain">
CREATE TEMPORARY TABLE sir1
select
min(min_price) as minPrice ,
max(max_price) as maxPrice,
max(cur_time) as mxTime,
stock_code as stockCode,
sum(cur_price)/count(cur_price) as avgPrice,
YEARWEEK(cur_time) as week
from stock_rt_info
where stock_code = #{code}
group by yearweek(cur_time);
CREATE TEMPORARY TABLE sir2
select cur_price ,
stock_code,
YEARWEEK(cur_time) as week
from stock_rt_info
where stock_code = #{code} and cur_time in (
select
max(cur_time) as mxTime
from stock_rt_info
where stock_code = #{code}
group by yearweek(cur_time)
) ;
CREATE TEMPORARY TABLE sir3
select open_price ,
stock_code,
YEARWEEK(cur_time) as week,
cur_time
from stock_rt_info
where stock_code = #{code} and cur_time in (
select
min(cur_time) as minTime
from stock_rt_info
where stock_code = #{code}
group by yearweek(cur_time)
)
;
select sir1.stockCode as stockCode,
sir1.avgPrice as avgPrice ,
sir1.minPrice as minPrice,
sir1.mxTime as mxTime,
sir1.maxPrice as maxPrice,
sir2.cur_price as closePrice,
sir3.open_price as openPrice
from sir1 join sir2 on sir1.stockCode = sir2.stock_code and sir1.week = sir2.week
join sir3 on sir3.stock_code=sir2.stock_code and sir2.week=sir3.week
where sir3.cur_time between #{startDate} and #{endDate}
;
</select>