| | |
| | | List<CurrencyMexcBo> getList = gson.fromJson(symbolsJson, new TypeToken<List<CurrencyMexcBo>>() { |
| | | }.getType()); |
| | | |
| | | // 获取数据库中已有的symbol列表 |
| | | List<Currency> dbList = currencyService.list(new LambdaQueryWrapper<Currency>().eq(Currency::getSource, "mexc")); |
| | | Set<String> symbolSet = dbList.stream().map(Currency::getSymbol).collect(Collectors.toSet()); |
| | | |
| | | // 比对接口返回的数据和数据库中已有的数据,找出新增的数据 |
| | | List<CurrencyMexcBo> saveList = getList.stream() |
| | | .filter(CurrencyMexcBo -> !symbolSet.contains(CurrencyMexcBo.getSymbol())) |
| | | .collect(Collectors.toList()); |
| | | List<Currency> currencies = ConverterUtil.convertToList(saveList, Currency.class); |
| | | currencyService.remove(new LambdaQueryWrapper<Currency>().eq(Currency::getSource,"mexc")); |
| | | List<Currency> currencies = ConverterUtil.convertToList(getList, Currency.class); |
| | | // 批量保存新增数据到数据库 |
| | | if(CollectionUtils.isNotEmpty(currencies)){ |
| | | currencyService.saveBatch(currencies); |