今日指数项目个股周K线功能实现

个股周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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

攒了一袋星辰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值