| | |
| | | package org.example.controller; |
| | | |
| | | import cn.hutool.core.date.DateUtil; |
| | | 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; |
| | | |
| | | /** |
| | |
| | | @Autowired |
| | | StockMarketNewMapper stockMarketNewMapper; |
| | | |
| | | @Autowired |
| | | DataServiceKeyMapper dataServiceKeyMapper; |
| | | |
| | | |
| | | @GetMapping("/stock-markets") |
| | | public List JournalismAll(){ |
| | | public List JournalismAll(@RequestParam(value="key",required = true)String key){ |
| | | DataServiceKey data = dataServiceKeyMapper.selectOne(new LambdaQueryWrapper<DataServiceKey>() |
| | | .eq(DataServiceKey::getTokenKey, key) |
| | | .gt(DataServiceKey::getExpirationTime, DateUtil.date()) |
| | | .eq(DataServiceKey::getIsAvailable, 1)); |
| | | 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); |
| | |
| | | } |
| | | |
| | | @GetMapping("/list") |
| | | public ServerResponse StockMarketNew(){ |
| | | public ServerResponse StockMarketNew(@RequestParam(value="key",required = true)String key){ |
| | | DataServiceKey data = dataServiceKeyMapper.selectOne(new LambdaQueryWrapper<DataServiceKey>() |
| | | .eq(DataServiceKey::getTokenKey, key) |
| | | .gt(DataServiceKey::getExpirationTime, DateUtil.date()) |
| | | .eq(DataServiceKey::getIsAvailable, 1)); |
| | | if(data == null){ |
| | | return ServerResponse.createByErrorMsg("key invalid"); |
| | | } |
| | | LambdaQueryWrapper<StockMarketNew> queryWrapper = new LambdaQueryWrapper<>(); |
| | | return ServerResponse.createBySuccess(stockMarketNewMapper.selectList(queryWrapper)); |
| | | } |
| | |
| | | public String getKData( |
| | | @RequestParam("pid") String pid, |
| | | @RequestParam("interval") String interval, |
| | | @RequestParam("stockType") String stockType |
| | | @RequestParam("stockType") String stockType, |
| | | @RequestParam(value="key",required = true)String key |
| | | ) { |
| | | EStockType eStockType = null; |
| | | DataServiceKey data = dataServiceKeyMapper.selectOne(new LambdaQueryWrapper<DataServiceKey>() |
| | | .eq(DataServiceKey::getTokenKey, key) |
| | | .gt(DataServiceKey::getExpirationTime, DateUtil.date()) |
| | | .eq(DataServiceKey::getIsAvailable, 1)); |
| | | if(data == null){ |
| | | return "key invalid"; |
| | | } |
| | | if(stockType.equals("US")){ |
| | | eStockType = EStockType.US; |
| | | }else{ |
| | |
| | | |
| | | @RequestMapping("/new-stock") |
| | | @ResponseBody |
| | | public String newStock() { |
| | | |
| | | public String newStock(@RequestParam(value="key",required = true)String key) { |
| | | DataServiceKey data = dataServiceKeyMapper.selectOne(new LambdaQueryWrapper<DataServiceKey>() |
| | | .eq(DataServiceKey::getTokenKey, key) |
| | | .gt(DataServiceKey::getExpirationTime, DateUtil.date()) |
| | | .eq(DataServiceKey::getIsAvailable, 1)); |
| | | if(data == null){ |
| | | return "key invalid"; |
| | | } |
| | | return HttpClientRequest.doGet(EStockType.IN.getStockUrl()) + "/new-stock?key=" + (EStockType.IN.getStockKey() + "&country_id=14"); |
| | | } |
| | | } |