| | |
| | | |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import org.example.common.ServerResponse; |
| | | import org.example.dao.JournalismMapper; |
| | | import org.example.dao.StockMarketNewMapper; |
| | | import org.example.dao.StockNewShareMapper; |
| | | import org.example.enums.EStockType; |
| | | import org.example.pojo.Journalism; |
| | | import org.example.pojo.StockMarketNew; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @program: webSocketProject |
| | |
| | | * @create: 2024-03-26 21:51 |
| | | **/ |
| | | @RestController |
| | | @RequestMapping("/api/all") |
| | | @RequestMapping("/api/stock/") |
| | | public class ApiController { |
| | | |
| | | @Autowired |
| | | StockNewShareMapper stockNewShareMapper; |
| | | |
| | | @Autowired |
| | | StockMarketNewMapper stockMarketNewMapper; |
| | | |
| | | |
| | | /*查询股票日线*/ |
| | |
| | | } |
| | | return HttpUtil.get(eStockType.stockUrl + "kline?pid=" + pid + "&interval=" + interval + "&key=" + eStockType.stockKey); |
| | | } |
| | | |
| | | @GetMapping("getStock.do") |
| | | public ServerResponse StockMarketNew(@RequestParam(value = "stockType", required = false) String stockType){ |
| | | // 将输入的股票类型转换为大写 |
| | | String upperCase = stockType.toUpperCase(); |
| | | // 根据代码获取对应的枚举类型 |
| | | EStockType code = EStockType.getEsByCode(upperCase); |
| | | if(code == null){ |
| | | return ServerResponse.createBySuccessMsg("请输入正确的stockType"); |
| | | } |
| | | |
| | | // 根据枚举类型进行不同的操作 |
| | | switch(code){ |
| | | case XG: |
| | | // 查询新股市场数据 |
| | | return getStockData(stockNewShareMapper); |
| | | case IN: |
| | | // 查询股票数据 |
| | | return getStockData(stockMarketNewMapper); |
| | | default: |
| | | return ServerResponse.createBySuccessMsg("未找到对应的股票数据"); |
| | | } |
| | | } |
| | | |
| | | // 通用方法,根据传入的mapper查询数据 |
| | | private <T> ServerResponse getStockData(BaseMapper<T> mapper){ |
| | | LambdaQueryWrapper<T> wrapper = new LambdaQueryWrapper<>(); |
| | | List<T> list = mapper.selectList(wrapper); |
| | | if(list.isEmpty()){ |
| | | return ServerResponse.createByErrorMsg("查询结果为空"); |
| | | } |
| | | return ServerResponse.createBySuccess(list); |
| | | } |
| | | |
| | | } |