| package com.xcong.excoin.rabbit.consumer; | 
|   | 
| import com.alibaba.fastjson.JSONObject; | 
| import com.xcong.excoin.configurations.RabbitMqConfig; | 
| import com.xcong.excoin.modules.blackchain.model.EthUsdtChargeDto; | 
| import com.xcong.excoin.modules.blackchain.service.Trc20Service; | 
| import com.xcong.excoin.modules.blackchain.service.TrxUsdtUpdateService; | 
| import com.xcong.excoin.modules.blackchain.service.UsdtErc20UpdateService; | 
| import com.xcong.excoin.modules.coin.service.BlockCoinService; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.apache.commons.lang.StringUtils; | 
| import org.springframework.amqp.rabbit.annotation.RabbitListener; | 
| import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | 
| import org.springframework.stereotype.Component; | 
|   | 
| import javax.annotation.Resource; | 
| import java.math.BigDecimal; | 
|   | 
| /** | 
|  * @author wzy | 
|  * @date 2020-05-25 | 
|  **/ | 
| @Slf4j | 
| @Component | 
| @ConditionalOnProperty(prefix = "app", name = "block-job", havingValue = "true") | 
| public class UsdtUpdateConsumer { | 
|   | 
|   | 
|     @Resource | 
|     private BlockCoinService blockCoinService; | 
|   | 
|     @Resource | 
|     TrxUsdtUpdateService trxUsdtUpdateService; | 
|   | 
|   | 
|     @RabbitListener(queues = RabbitMqConfig.QUEUE_USDT_UPDATE) | 
|     public void doSomething(String content) { | 
|         log.info("#USDT同步---->{}#", content); | 
|         EthUsdtChargeDto ethUsdtChargeDto = JSONObject.parseObject(content, EthUsdtChargeDto.class); | 
|         // 更新这个用户的余额 | 
|         if(EthUsdtChargeDto.Symbol.USDT_ERC20.equals(ethUsdtChargeDto.getSymbol())){ | 
|             blockCoinService.updateEthUsdtNew(ethUsdtChargeDto); | 
|         } | 
|         if(EthUsdtChargeDto.Symbol.USDT_TRC20.equals(ethUsdtChargeDto.getSymbol())){ | 
|             blockCoinService.updateTrc20(ethUsdtChargeDto); | 
|             // 同步完直接归集 | 
|             trxUsdtUpdateService.poolByAddress(ethUsdtChargeDto.getAddress()); | 
|         } | 
|   | 
|     } | 
|   | 
|     @RabbitListener(queues = RabbitMqConfig.QUEUE_USDT_ADDRESS) | 
|     public void addUsdtAddress(String content) { | 
|         if(!UsdtErc20UpdateService.ALL_ADDRESS_LIST.contains(content)){ | 
|             log.debug("#添加新地址---->{}#", content); | 
|             if(StringUtils.isBlank(content)){ | 
|                 return; | 
|             } | 
|             String[] split = content.split(","); | 
|             if(split.length<2){ | 
|                 return; | 
|             } | 
|             String address = split[0]; | 
|             String tag = split[1]; | 
|             if("ERC20".equals(tag)){ | 
|                 UsdtErc20UpdateService.ALL_ADDRESS_LIST.add(address); | 
|             } | 
|             if("TRC20".equals(tag)){ | 
|                 TrxUsdtUpdateService.addressList.add(address); | 
|                 // 此时还需要给这个地址转账用于激活及后续手续费 | 
|                 Trc20Service.sendTrx(Trc20Service.TRX_PRIVATE_KEY,address,new BigDecimal(10)); | 
|             } | 
|   | 
|         } | 
|     } | 
| } |