| | |
| | | import com.yami.trading.common.util.StringUtils; |
| | | import com.yami.trading.dao.item.ItemMapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.checkerframework.checker.units.qual.A; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | private ItemLeverageService itemLeverageService; |
| | | |
| | | private Map<String, Integer> symbolDecimal = Maps.newHashMap(); |
| | | |
| | | |
| | | @Autowired |
| | | private CacheManager cacheManager; |
| | |
| | | public Item findBySymbol(String symbol) { |
| | | List<Item> items = ApplicationContextUtils.getApplicationContext().getBean(ItemService.class).list(); |
| | | if (CollectionUtil.isNotEmpty(items)) { |
| | | Optional<Item> first = items.stream().filter(i -> symbol.equalsIgnoreCase(i.getSymbol())).findFirst(); |
| | | Optional<Item> first = items.stream() |
| | | .filter(i -> { |
| | | String compareField = symbol.indexOf("usdt") > 0 |
| | | ? i.getSymbol() |
| | | : i.getSymbolData(); |
| | | return symbol.equalsIgnoreCase(compareField); |
| | | }) |
| | | .findFirst(); |
| | | return first.orElse(null); |
| | | } |
| | | LambdaQueryWrapper<Item> queryWrapper = new LambdaQueryWrapper<Item>() |
| | | .eq(Item::getSymbol, symbol) |
| | | .last("LIMIT 1"); |
| | | LambdaQueryWrapper<Item> queryWrapper = null; |
| | | if(symbol.indexOf("usdt") > 0){ |
| | | queryWrapper = new LambdaQueryWrapper<Item>() |
| | | .eq(Item::getSymbol, symbol) |
| | | .last("LIMIT 1"); |
| | | }else { |
| | | queryWrapper = new LambdaQueryWrapper<Item>() |
| | | .eq(Item::getSymbolData, symbol) |
| | | .last("LIMIT 1"); |
| | | } |
| | | |
| | | return super.baseMapper.selectOne(queryWrapper); |
| | | } |
| | | |
| | |
| | | @Cached(name = ITEM_CACHE, key = "'all'", expire = 3600) |
| | | @Override |
| | | public List<Item> list() { |
| | | List<Item> list = super.list(); |
| | | List<Item> list = super.list(new LambdaQueryWrapper<>(Item.class).eq(Item::getType,Item.cryptos)); |
| | | symbolDecimal = list.stream() |
| | | .collect(Collectors.toMap(Item::getSymbol, Item::getDecimals, (s1, s2) -> s2)); |
| | | return list; |
| | |
| | | } |
| | | |
| | | public List<Item> cacheGetAll() { |
| | | return ApplicationContextUtils.getApplicationContext().getBean(ItemService.class).list(); |
| | | return ApplicationContextUtils.getApplicationContext().getBean(ItemService.class).list(new LambdaQueryWrapper<>(Item.class).eq(Item::getType,Item.cryptos)); |
| | | } |
| | | |
| | | |