1
zj
2024-07-25 bcd96e924ea184da9a4dacfd16a5c3bfba14ac53
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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.JournalismMapper;
import org.example.dao.StockMarketNewMapper;
import org.example.enums.EStockType;
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.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
 
/**
 * @program: webSocketProject
 * @description:
 * @create: 2024-03-26 21:51
 **/
@RestController
@RequestMapping("/v1")
public class ApiController {
 
    @Autowired
    JournalismMapper journalismMapper;
 
    @Autowired
    StockMarketNewMapper stockMarketNewMapper;
 
 
    @GetMapping("/stock-markets")
    public List JournalismAll(){
        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");
    }
 
    @RequestMapping("/stock")
    @ResponseBody
    public String doGet(@RequestParam("pid") String pid){
        String  apiUrl  =  "http://api-in-2.js-stock.top/stock?pid="+pid+"&key=eVKtHt7aG4m6ozwWL9qG";
        try  {
            URL url  =  new  URL(apiUrl);
            HttpURLConnection connection  =  (HttpURLConnection)  url.openConnection();
            connection.setRequestMethod("GET");
 
            BufferedReader in  =  new  BufferedReader(new InputStreamReader(connection.getInputStream()));
            String  inputLine;
            StringBuffer  response  =  new  StringBuffer();
 
            while  ((inputLine  =  in.readLine())  !=  null)  {
                response.append(inputLine);
            }
            in.close();
            return response.toString();
        }  catch  (Exception  e)  {
            e.printStackTrace();
        }
        return null;
    }
}