| | |
| | | package com.yami.trading.admin.task; |
| | | |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.lang.Console; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.http.HttpStatus; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.yami.trading.api.UD.*; |
| | | import com.yami.trading.bean.ico.domain.Ico; |
| | | import com.yami.trading.bean.item.domain.Item; |
| | | import com.yami.trading.bean.model.ChannelBlockchain; |
| | | import com.yami.trading.common.domain.Result; |
| | | import com.yami.trading.common.util.ApplicationContextUtils; |
| | | import com.yami.trading.common.util.StringUtils; |
| | | import com.yami.trading.huobi.data.internal.KlineInitService; |
| | | import com.yami.trading.security.common.enums.CryptoCurrencyEnum; |
| | | import com.yami.trading.security.common.util.SecurityUtils; |
| | | import com.yami.trading.service.ico.IcoService; |
| | | import com.yami.trading.service.item.ItemService; |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | |
| | | @Autowired |
| | | ItemService itemService; |
| | | |
| | | @Autowired |
| | | InitHandle initHandle; |
| | | |
| | | @Autowired |
| | | private KlineInitService klineInitService; |
| | | |
| | | @Autowired |
| | | UdunClient udunClient; |
| | | |
| | | @Autowired |
| | | RedisTemplate redisTemplate; |
| | | |
| | | //@Scheduled(cron = "*/5 * * * * ?") |
| | | public void test() { |
| | | String coin = "usdt"; |
| | | List<ChannelBlockchain> data = new ArrayList<ChannelBlockchain>(); |
| | | Map<String, List<CryptoCurrencyEnum>> allGroupedByCoin = CryptoCurrencyEnum.getAllGroupedByCoin(); |
| | | List<CryptoCurrencyEnum> currencyEnums = allGroupedByCoin.get(coin); |
| | | try { |
| | | String partyId = SecurityUtils.getUser().getUserId(); |
| | | //获取u盾地址 |
| | | //获取商户支持币种 |
| | | List<Coin> coinList = udunClient.listSupportCoin(false); |
| | | |
| | | currencyEnums.forEach((currencyEnum) -> { |
| | | String coinName = currencyEnum.getName(); |
| | | Coin c = coinList.stream().filter(x -> x.getName().equals(coinName)).findFirst().orElse(null); |
| | | if (c != null) { |
| | | ChannelBlockchain rechargeAddressVo = new ChannelBlockchain(); |
| | | //创建地址 |
| | | Address address; |
| | | String ress = (String)redisTemplate.opsForValue().get(partyId + coinName); |
| | | if(StringUtils.isNotEmpty(ress)){ |
| | | rechargeAddressVo.setAddress(ress); |
| | | rechargeAddressVo.setCoin(coinName); |
| | | rechargeAddressVo.setBlockchain_name(coinName); |
| | | rechargeAddressVo.setAuto(false); |
| | | rechargeAddressVo.setImg(null); |
| | | }else{ |
| | | address = udunClient.createAddress(c.getMainCoinType(),null,null); |
| | | rechargeAddressVo.setAddress(address.getAddress()); |
| | | rechargeAddressVo.setCoin(coinName); |
| | | rechargeAddressVo.setBlockchain_name(coinName); |
| | | rechargeAddressVo.setAuto(false); |
| | | rechargeAddressVo.setImg(null); |
| | | redisTemplate.opsForValue().set(partyId + coinName, address.getAddress()); |
| | | } |
| | | data.add(rechargeAddressVo); |
| | | } |
| | | }); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | log.error("获取充值地址错误:",e); |
| | | } |
| | | } |
| | | /** |
| | | * ico转入产品 |
| | | */ |
| | | @Scheduled(cron = "0 */5 * * * ?") |
| | | @Scheduled(cron = "0 */1 * * * ?") |
| | | public void icoToItem() { |
| | | QueryWrapper<Ico> query = new QueryWrapper<>(); |
| | | query.lt("market_date", DateTime.now()); |
| | | List<Ico> icoList = icoService.list(query); |
| | | if (icoList != null && !icoList.isEmpty()) { |
| | | List<String> symbolList = icoList.stream().map(Ico::getSymbol).collect(Collectors.toList()); |
| | | |
| | | if (icoList == null || icoList.isEmpty()) { |
| | | return; |
| | | } |
| | | List<Item> addItemList = new ArrayList<>(); |
| | | for (Ico ico : icoList) { |
| | | //是否已存在币 |
| | | QueryWrapper<Item> iQuery = new QueryWrapper<>(); |
| | | iQuery.in("SYMBOL", symbolList); |
| | | iQuery.eq("currency_type", 1); |
| | | |
| | | List<Item> itemList = itemService.list(iQuery); |
| | | List<Item> addItemList = new ArrayList<>(); |
| | | for (Ico ico : icoList) { |
| | | Item item = itemList.stream().filter(x -> x.getSymbol().equals(ico.getSymbol())).findFirst().orElse(new Item()); |
| | | iQuery.eq("SYMBOL", ico.getSymbol()); |
| | | iQuery.eq("SYMBOL_DATA", ico.getSymbolData()); |
| | | Item item = itemService.getOne(iQuery); |
| | | if (item == null) { |
| | | item = new Item(); |
| | | item =icoService.icoToItem(item, ico); |
| | | addItemList.add(item); |
| | | } |
| | | } |
| | | if (!addItemList.isEmpty()) { |
| | | log.info("ico转入产品 数据 Start>>"); |
| | | itemService.saveOrUpdateBatch(addItemList); |
| | | initHandle.init(); |
| | | log.info("成功ico转入产品 数据 End {}", icoList.size()); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * K线数据修正 |
| | | */ |
| | | @Scheduled(cron = "0 */1 * * * ?") |
| | | public void klineInit() { |
| | | List<Item> items = ApplicationContextUtils.getApplicationContext().getBean(ItemService.class).list(); |
| | | if (CollectionUtil.isNotEmpty(items)) { |
| | | String symbols = items.stream().map(Item::getSymbol).collect(Collectors.joining(",")); |
| | | klineInitService.klineInit(symbols); |
| | | } |
| | | } |
| | | } |