1
ydj
2024-06-11 14b46ebd008c9f9fbaa0dd43a49783d2f54536a3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package org.example.controller;
 
import cn.hutool.http.HttpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.example.common.ServerResponse;
import org.example.dao.DataServiceKeyMapper;
import org.example.dao.JournalismMapper;
import org.example.dao.StockMarketNewMapper;
import org.example.enums.EStockType;
import org.example.pojo.DataServiceKey;
import org.example.pojo.Journalism;
import org.example.pojo.StockMarketNew;
import org.example.util.HttpClientRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
 
/**
 * @program: webSocketProject
 * @description:
 * @create: 2024-03-26 21:51
 **/
@RestController
@RequestMapping()
public class ApiController {
 
    @Autowired
    JournalismMapper journalismMapper;
 
    @Autowired
    StockMarketNewMapper stockMarketNewMapper;
 
    @Autowired
    DataServiceKeyMapper dataServiceKeyMapper;
 
 
    @GetMapping("/stock-markets")
    public List JournalismAll(@RequestParam(value="key",required = true)String key){
        DataServiceKey data = dataServiceKeyMapper.selectOne(
                new LambdaQueryWrapper<DataServiceKey>().eq(DataServiceKey::getTokenKey,key));
        if(data == null){
            return Collections.singletonList(new ArrayList().add("key invalid"));
        }
        QueryWrapper<Journalism> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("time");
        Page<Journalism> page = new Page<>(1,15);
        return journalismMapper.selectPage(page,queryWrapper).getRecords();
    }
 
    @GetMapping("/list")
    public ServerResponse StockMarketNew(){
        LambdaQueryWrapper<StockMarketNew> queryWrapper = new LambdaQueryWrapper<>();
        return ServerResponse.createBySuccess(stockMarketNewMapper.selectList(queryWrapper));
    }
 
    /*查询股票日线*/
    @RequestMapping({"/api/all/getKData.do"})
    @ResponseBody
    public String getKData(
            @RequestParam("pid") String pid,
            @RequestParam("interval") String interval,
            @RequestParam("stockType") String stockType
    ) {
        EStockType eStockType = null;
        if(stockType.equals("US")){
            eStockType = EStockType.US;
        }else{
            eStockType = EStockType.IN;
        }
        return HttpUtil.get(eStockType.stockUrl + "kline?pid=" + pid + "&interval=" + interval + "&key=" + eStockType.stockKey);
    }
 
 
 
    @RequestMapping("/new-stock")
    @ResponseBody
    public String newStock() {
 
       return HttpClientRequest.doGet(EStockType.IN.getStockUrl()) + "/new-stock?key=" + (EStockType.IN.getStockKey() + "&country_id=14");
    }
}