|
|
@@ -2,6 +2,7 @@ package com.liangjiang.price_collection.controller;
|
|
|
|
|
|
import com.liangjiang.price_collection.dto.PriceInfoDto;
|
|
|
import com.liangjiang.price_collection.dto.PriceListDto;
|
|
|
+import com.liangjiang.price_collection.res.R;
|
|
|
import com.liangjiang.price_collection.service.ITableService;
|
|
|
import com.liangjiang.price_collection.service.impl.QueryService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
@@ -13,7 +14,6 @@ import javax.jms.Queue;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
|
|
|
@Slf4j
|
|
|
@RestController
|
|
|
@@ -22,52 +22,53 @@ import java.util.Set;
|
|
|
public class ApiController {
|
|
|
private final ITableService tableService;
|
|
|
private final QueryService queryService;
|
|
|
- private final JmsTemplate jmsTemplate;
|
|
|
+ private final JmsTemplate myJmsTemplate;
|
|
|
private final Queue priceQueue;
|
|
|
|
|
|
@PostMapping("/add")
|
|
|
public void saveInfo(@RequestBody List<PriceInfoDto> priceInfoDtos){
|
|
|
// 开启持久化
|
|
|
- jmsTemplate.setDeliveryMode(2);
|
|
|
- jmsTemplate.setExplicitQosEnabled(true);
|
|
|
- jmsTemplate.setDeliveryPersistent(true);
|
|
|
+ myJmsTemplate.setDeliveryMode(2);
|
|
|
+ myJmsTemplate.setExplicitQosEnabled(true);
|
|
|
+ myJmsTemplate.setDeliveryPersistent(true);
|
|
|
// 写入队列
|
|
|
- jmsTemplate.convertAndSend(priceQueue, priceInfoDtos);
|
|
|
+ myJmsTemplate.convertAndSend(priceQueue, priceInfoDtos);
|
|
|
}
|
|
|
|
|
|
@GetMapping("/getExchange")
|
|
|
- public Set<String> exchangeSelect(){
|
|
|
- return tableService.getExchangeSelect();
|
|
|
+ public R exchangeSelect(){
|
|
|
+
|
|
|
+ return R.ok(tableService.getExchangeSelect());
|
|
|
}
|
|
|
|
|
|
@GetMapping("/getCoin")
|
|
|
- public Set<String> coinSelect(@RequestParam("exchange") String exchange){
|
|
|
+ public R coinSelect(@RequestParam("exchange") String exchange){
|
|
|
String[] params = exchange.split(",");
|
|
|
- return tableService.getCoinSelect(params);
|
|
|
+ return R.ok(tableService.getCoinSelect(params));
|
|
|
}
|
|
|
|
|
|
@GetMapping("/getPrices")
|
|
|
- public PriceListDto getPriceRest(@RequestParam("exchange") String exchange, @RequestParam("coin")String coin){
|
|
|
+ public R getPriceRest(@RequestParam("exchange") String exchange, @RequestParam("coin")String coin){
|
|
|
Integer[] times = QueryService.getDaysAgoTime(System.currentTimeMillis(), 3L);
|
|
|
// Integer start = 1705916692;
|
|
|
// Integer end = 1705916714;
|
|
|
try {
|
|
|
- return queryService.performQueries(exchange.split(","), coin, times[1], times[0]);
|
|
|
+ return R.ok(queryService.performQueries(exchange.split(","), coin, times[1], times[0]));
|
|
|
// return queryService.performQueries(exchange.split(","), coin, start, end);
|
|
|
} catch (Exception ex){
|
|
|
log.error("查询出错", ex);
|
|
|
- return PriceListDto.builder().time(new HashSet<>()).values(new LinkedList<>()).build();
|
|
|
+ return R.ok(PriceListDto.builder().time(new HashSet<>()).values(new LinkedList<>()).build());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@GetMapping("/getAddPrices")
|
|
|
- public PriceListDto getAddPrices(@RequestParam("exchange") String exchange, @RequestParam("coin")String coin,@RequestParam("startTime") Integer startTime){
|
|
|
+ public R getAddPrices(@RequestParam("exchange") String exchange, @RequestParam("coin")String coin,@RequestParam("startTime") Integer startTime){
|
|
|
Integer endTime = Math.toIntExact(System.currentTimeMillis()/1000);
|
|
|
try {
|
|
|
- return queryService.performQueries(exchange.split(","), coin, startTime, endTime);
|
|
|
+ return R.ok(queryService.performQueries(exchange.split(","), coin, startTime, endTime));
|
|
|
} catch (Exception ex){
|
|
|
log.error("查询出错", ex);
|
|
|
- return PriceListDto.builder().time(new HashSet<>()).values(new LinkedList<>()).build();
|
|
|
+ return R.ok(PriceListDto.builder().time(new HashSet<>()).values(new LinkedList<>()).build());
|
|
|
}
|
|
|
}
|
|
|
}
|