| | |
| | | package org.example.task; |
| | | |
| | | import cn.hutool.core.convert.Convert; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | |
| | | import com.google.common.reflect.TypeToken; |
| | | import com.google.gson.Gson; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.beanutils.ConvertUtils; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.apache.http.HttpEntity; |
| | | import org.apache.http.HttpResponse; |
| | |
| | | import org.example.pojo.Currency; |
| | | import org.example.pojo.bo.CurrencyBitgetBo; |
| | | import org.example.server.impl.CurrencySerivceImpl; |
| | | import org.example.util.ConverterUtil; |
| | | import org.example.util.RedisUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | import java.io.InputStreamReader; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | import java.sql.SQLOutput; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | |
| | | |
| | | getList.parallelStream().forEach(person -> person.setSymbol(StringUtils.remove(person.getSymbol(), "-"))); |
| | | |
| | | // 获取数据库中已有的symbol列表 |
| | | List<Currency> dbList = currencyService.list(new LambdaQueryWrapper<Currency>().eq(Currency::getSource,"bitget")); |
| | | Set<String> symbolSet = dbList.stream().map(Currency::getSymbol).collect(Collectors.toSet()); |
| | | |
| | | // 比对接口返回的数据和数据库中已有的数据,找出新增的数据 |
| | | List<Currency> saveList = getList.stream() |
| | | Set<String> symbolSet = getList.stream().map(CurrencyBitgetBo::getSymbol).collect(Collectors.toSet()); |
| | | List<Currency> removeList = dbList.stream() |
| | | .filter(currency -> !symbolSet.contains(currency.getSymbol())) |
| | | .collect(Collectors.toList()); |
| | | |
| | | if(CollectionUtils.isNotEmpty(removeList)){ |
| | | removeList.forEach(f->{ |
| | | RedisUtil.delete("bitget"+f.getSymbol()); |
| | | }); |
| | | } |
| | | |
| | | // 获取数据库中已有的symbol列表 |
| | | currencyService.remove(new LambdaQueryWrapper<Currency>().eq(Currency::getSource,"bitget")); |
| | | |
| | | List<Currency> saveList = getList.stream() |
| | | .map(currency -> { |
| | | Currency newCurrency = new Currency(); |
| | | newCurrency.setSymbol(currency.getSymbol()); |
| | |
| | | return newCurrency; |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 批量保存新增数据到数据库 |
| | | if (CollectionUtils.isNotEmpty(saveList)) { |
| | | currencyService.saveBatch(saveList); |