Merge branch 'yunding' of http://120.27.238.55:7000/r/exchange into yunding
1 files added
5 files modified
| | |
| | | package com.xcong.excoin.modules.blackchain.service; |
| | | |
| | | import cn.hutool.core.math.MathUtil; |
| | | import cn.hutool.http.HttpResponse; |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("num", num); |
| | | String param = JSON.toJSONString(map); |
| | | return postForEntity(url, param).getBody(); |
| | | // return postForEntity(url, param).getBody(); |
| | | return postForEntityHuTool(url, param).body(); |
| | | } |
| | | |
| | | |
| | |
| | | return result; |
| | | } |
| | | |
| | | private static HttpResponse postForEntityHuTool(String url, String param) { |
| | | System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2"); |
| | | return HttpUtil.createPost(url).body(param) |
| | | .timeout(20000).contentType("application/json") |
| | | .header("TRON-PRO-API-KEY", Trc20Service.API_KEY) |
| | | .execute(); |
| | | } |
| | | |
| | | /** |
| | | * 比对本地地址 同步充值USDT-TRC20 |
| | | * |
| | |
| | | import com.xcong.excoin.modules.yunding.entity.YdProductEntity; |
| | | import com.xcong.excoin.modules.yunding.service.XchProfitService; |
| | | import com.xcong.excoin.utils.LogRecordUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | |
| | | @Slf4j |
| | | @Service |
| | | public class XchProfitServiceImpl implements XchProfitService { |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void xchProfitDistributor(BigDecimal totalProfit) { |
| | | Date currentDate = new Date(); |
| | | List<YdProductEntity> products = ydProductDao.selectList(null); |
| | |
| | | |
| | | // 单位XCH收益 |
| | | BigDecimal unitProfit = totalProfit.divide(totalCount, 8, BigDecimal.ROUND_DOWN); |
| | | log.info("单位XCH收益:{}", unitProfit); |
| | | |
| | | List<YdOrderEntity> orders = ydOrderDao.selectAllValidOrders(); |
| | | if (CollUtil.isNotEmpty(orders)) { |
| | |
| | | } |
| | | } |
| | | |
| | | remainProfit = remainProfit.subtract(orderProfit.subtract(orderProfit.multiply(order.getYdProductEntity().getManageExpense()))); |
| | | String content = "XCH收益"; |
| | | LogRecordUtils.insertMemberAccountMoneyChangeWithId(order.getMemberId(), content, remainProfit, "XCH", 1, 4, order.getId()); |
| | | MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(order.getMemberId(), "XCH"); |
| | |
| | | package com.xcong.excoin.quartz.job; |
| | | |
| | | import cn.hutool.http.HttpException; |
| | | import com.xcong.excoin.modules.blackchain.service.TrxUsdtUpdateService; |
| | | import com.xcong.excoin.modules.coin.service.BlockCoinService; |
| | | import com.xcong.excoin.utils.RedisUtils; |
| | |
| | | **/ |
| | | @Slf4j |
| | | @Component |
| | | @ConditionalOnProperty(prefix = "app", name = "block-job", havingValue = "true") |
| | | //@ConditionalOnProperty(prefix = "app", name = "block-job", havingValue = "true") |
| | | public class BlockCoinUpdateJob { |
| | | |
| | | @Resource |
| | |
| | | redisUtils.set("USDT_TRC20_CURRENT_BLOCK_NUM", blocnNum); |
| | | try { |
| | | trxUsdtUpdateService.monitorCoinListener(blocnNum); |
| | | } catch (RestClientException e) { |
| | | } catch (RestClientException | HttpException e) { |
| | | // 此时是连接问题 这个块需要重新扫描 |
| | | log.info("查询区块超时:" + blocnNum); |
| | | TRC_BLOCK.add(blocnNum); |
| | |
| | | |
| | | } |
| | | |
| | | @Scheduled(cron = "0/2 * * * * ? ") |
| | | @Scheduled(cron = "0 0/1 * * * ? ") |
| | | public void usdtTc20UpdateQueue() { |
| | | // 查询最新区块号 |
| | | long getnowblock = trxUsdtUpdateService.getnowblockFromTronScan() - 25; |
| | | // 生成块到队列 |
| | | // 拿到redis里最新区块 |
| | | Object trc20BlockNum = redisUtils.get("USDT_TRC20_BLOCK_NUM"); |
| | | if (trc20BlockNum == null) { |
| | | // 没有则取最新的块 |
| | |
| | | redisUtils.set("USDT_TRC20_BLOCK_NUM", getnowblock); |
| | | } |
| | | Long blockNum = Long.valueOf(trc20BlockNum.toString()); |
| | | if (getnowblock < blockNum) { |
| | | if (getnowblock <= blockNum) { |
| | | // 如果当前区块比最新已确认区块还大,则不继续执行 |
| | | return; |
| | | } |
| | | // 将得到的区块+1 放入队列 |
| | | TRC_BLOCK.add(blockNum + 1L); |
| | | redisUtils.incr("USDT_TRC20_BLOCK_NUM", 1); |
| | | // 得到最新区块和当前区块的差值 |
| | | Long diff = getnowblock-blockNum; |
| | | for(long i=1;i<=diff;i++){ |
| | | blockNum++; |
| | | TRC_BLOCK.add(blockNum); |
| | | } |
| | | // 将最新的最大区块放入redis |
| | | redisUtils.set("USDT_TRC20_BLOCK_NUM", blockNum); |
| | | } |
| | | |
| | | /** |
| | |
| | | <association property="ydProductEntity" javaType="com.xcong.excoin.modules.yunding.entity.YdProductEntity"> |
| | | <id column="p_id" property="id" /> |
| | | <result column="pro_unit" property="proUnit" /> |
| | | <result column="manage_expense" property="manageExpense" /> |
| | | </association> |
| | | </resultMap> |
| | | |
| | | <select id="selectAllValidOrders" resultMap="orderMap"> |
| | | select a.*, b.id p_id, b.pro_unit from yd_order a |
| | | select a.*, b.id p_id, b.pro_unit, b.manage_expense from yd_order a |
| | | inner join yd_product b on a.product_id=b.id |
| | | where a.state=2 |
| | | where a.state=2 and a.type = 1 |
| | | </select> |
| | | |
| | | <update id="UpdateByIdAndState"> |
New file |
| | |
| | | package com.xcong.excoin; |
| | | |
| | | import cn.hutool.http.HttpResponse; |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.xcong.excoin.modules.blackchain.service.Trc20Service; |
| | | import com.xcong.excoin.utils.RedisUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2021-05-04 |
| | | **/ |
| | | @Slf4j |
| | | @SpringBootTest |
| | | public class TrcTest { |
| | | |
| | | @Autowired |
| | | private RedisUtils redisUtils; |
| | | |
| | | @Test |
| | | public void trc20Test() { |
| | | String url = "https://api.trongrid.io/wallet/getblockbynum"; |
| | | |
| | | while(true) { |
| | | Object current = redisUtils.get("USDT_TRC20_CURRENT_BLOCK_NUM"); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("num", current); |
| | | String param = JSON.toJSONString(map); |
| | | System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2"); |
| | | HttpResponse response = HttpUtil.createPost(url).body(param).contentType("application/json").header("TRON-PRO-API-KEY", Trc20Service.API_KEY).execute(); |
| | | // log.info(response.body()); |
| | | |
| | | try { |
| | | Thread.sleep(2000); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | orderEntity.setAmount(BigDecimal.TEN); |
| | | ydOrderDao.insert(orderEntity); |
| | | } |
| | | |
| | | @Test |
| | | public void xchProfitTest() { |
| | | xchProfitService.xchProfitDistributor(BigDecimal.valueOf(1)); |
| | | } |
| | | } |