Helius
2020-11-11 25c3288859d660507dd78be62dadecfa3c543180
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.xcong.excoin.quartz.job;
 
import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSONObject;
import com.xcong.excoin.modules.coin.dao.MemberAccountMoneyChangeDao;
import com.xcong.excoin.modules.coin.entity.MemberAccountMoneyChange;
import com.xcong.excoin.modules.member.dao.MemberCoinWithdrawDao;
import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao;
import com.xcong.excoin.modules.member.entity.MemberCoinWithdrawEntity;
import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity;
import com.xcong.excoin.utils.TRC20ApiUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * @author wzy
 * @date 2020-11-05
 **/
@Slf4j
@Component
@ConditionalOnProperty(prefix = "app", name = "block-job", havingValue = "true")
public class TRC20OrderJob {
 
    @Resource
    private MemberCoinWithdrawDao memberCoinWithdrawDao;
    @Resource
    private MemberWalletCoinDao memberWalletCoinDao;
    @Resource
    private MemberAccountMoneyChangeDao memberAccountMoneyChangeDao;
 
 
    @Transactional(rollbackFor = Exception.class)
    public void trc20WithdrawOrder() {
        log.info("trc20订单查询");
        Map<String, Object> param = new HashMap<>();
        param.put("label", "TRC20");
        param.put("status", 1);
        List<MemberCoinWithdrawEntity> withdrawEntities = memberCoinWithdrawDao.selectByMap(param);
        if (CollUtil.isNotEmpty(withdrawEntities)) {
            for (MemberCoinWithdrawEntity withdrawEntity : withdrawEntities) {
                MemberWalletCoinEntity wallet = memberWalletCoinDao.selectWalletCoinBymIdAndCode(withdrawEntity.getMemberId(), withdrawEntity.getSymbol());
                String applyOrderInfo = TRC20ApiUtils.getApplyOrderInfo(withdrawEntity.getTag());
                Integer transStatus = JSONObject.parseObject(applyOrderInfo).getInteger("transStatus");
 
                Map<String, Object> columnMaps = new HashMap<>();
                columnMaps.put("withdraw_id", withdrawEntity.getId());
                MemberAccountMoneyChange accountMoneyChanges = memberAccountMoneyChangeDao.selectByMap(columnMaps).get(0);
                // 状态:2待审核3提币中(审核成功)4提币成功5审核失败
                if (transStatus == 4) {
                    memberWalletCoinDao.updateWalletBalance(wallet.getId(), null, null, withdrawEntity.getAmount().negate());
 
                    accountMoneyChanges.setStatus(MemberAccountMoneyChange.STATUS_SUCCESS_INTEGER);
                    accountMoneyChanges.setAmount(withdrawEntity.getAmount().negate());
                    memberAccountMoneyChangeDao.updateById(accountMoneyChanges);
 
                    withdrawEntity.setStatus(MemberCoinWithdrawEntity.IS_STATUS_Y);
                    memberCoinWithdrawDao.updateById(withdrawEntity);
                } else if (transStatus == 5) {
                    memberWalletCoinDao.updateWalletBalance(wallet.getId(), withdrawEntity.getAmount(), null, withdrawEntity.getAmount().negate());
 
                    accountMoneyChanges.setStatus(MemberAccountMoneyChange.STATUS_FAIL_INTEGER);
                    accountMoneyChanges.setAmount(withdrawEntity.getAmount());
                    memberAccountMoneyChangeDao.updateById(accountMoneyChanges);
 
                    withdrawEntity.setStatus(MemberCoinWithdrawEntity.IS_STATUS_N);
                    memberCoinWithdrawDao.updateById(withdrawEntity);
                }
            }
        }
    }
}