zainali5120
2020-09-25 286ea89f5f6cade73276f865effa5dcd2b19406d
撮合交易代码提交
11 files modified
2 files added
223 ■■■■ changed files
src/main/java/com/xcong/excoin/configurations/RabbitMqConfig.java 23 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/blackchain/model/RocTransferDetail.java 41 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/service/BlockCoinService.java 4 ●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/service/impl/BlockCoinServiceImpl.java 52 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/member/dao/MemberCoinAddressDao.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/member/service/impl/MemberServiceImpl.java 9 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/rabbit/consumer/RocBlockUpdateConsumer.java 51 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/trade/CoinTrader.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/utils/dingtalk/DingTalkUtils.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/utils/mail/Sms106Send.java 11 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/utils/mail/SubMailSend.java 10 ●●●● patch | view | raw | blame | history
src/main/resources/application-test.yml 2 ●●● patch | view | raw | blame | history
src/main/resources/mapper/member/MemberCoinAddressDao.xml 14 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/configurations/RabbitMqConfig.java
@@ -89,6 +89,13 @@
    // 交易订单处理
    public static final String ROUTINGKEY_HANDLE_TRADE = "ROUTINGKEY_HANDLE_TRADE";
    public static final String EXCHANGE_ROC = "roc-transfer";
    public static final String QUEUE_ROC= "roc-queue";
    public static final String ROUTING_KEY_ROC = "roc-transfer-routingKey";
    @Resource
    private ConnectionFactory connectionFactory;
@@ -351,4 +358,20 @@
        return BindingBuilder.bind(queueHandleTrade()).to(matchTradeExchange()).with(RabbitMqConfig.ROUTINGKEY_HANDLE_TRADE);
    }
    @Bean
    public DirectExchange rocExchange() {
        return new DirectExchange(EXCHANGE_ROC);
    }
    @Bean
    public Queue rocQueue() {
        return new Queue(QUEUE_ROC, true);
    }
    @Bean
    public Binding bindingRoc() {
        return BindingBuilder.bind(rocQueue()).to(rocExchange()).with(ROUTING_KEY_ROC);
    }
}
src/main/java/com/xcong/excoin/modules/blackchain/model/RocTransferDetail.java
New file
@@ -0,0 +1,41 @@
package com.xcong.excoin.modules.blackchain.model;
import lombok.Data;
import java.math.BigDecimal;
/**
 * @description 钱包表
 * @author admin
 * @date 2020-09-17 14:31
 */
@Data
public class RocTransferDetail {
    /**
     * 主键
     */
    private Long  id;
    /**
     * 主地址
     */
    private String  address;
    /**
     * 币种
     */
    private String  symbol;
    /**
     * 余额
     */
    private BigDecimal balance;
}
src/main/java/com/xcong/excoin/modules/coin/service/BlockCoinService.java
@@ -1,5 +1,7 @@
package com.xcong.excoin.modules.coin.service;
import com.xcong.excoin.modules.blackchain.model.RocTransferDetail;
public interface BlockCoinService {
    public void updateEthUsdt();
@@ -16,6 +18,6 @@
    public void updateTrc20();
    public void updateRoc();
    public void updateRoc(RocTransferDetail transferDetail);
}
src/main/java/com/xcong/excoin/modules/coin/service/impl/BlockCoinServiceImpl.java
@@ -482,8 +482,58 @@
    }
    @Override
    public void updateRoc() {
    public void updateRoc(RocTransferDetail transferDetail) {
        // 更新ROC
        // 增加用户余额
        String address = transferDetail.getAddress();
        BigDecimal balance = transferDetail.getBalance();
        String symbol = transferDetail.getSymbol();
        if(org.apache.commons.lang.StringUtils.isBlank(address) || org.apache.commons.lang.StringUtils.isBlank(symbol) || balance ==null ){
            return;
        }
        if(balance.compareTo(new BigDecimal("0.0001"))<=0){
            return;
        }
        MemberCoinAddressEntity memberCoinAddress = memberCoinAddressDao.selectCoinAddressByAddressAndSymbol(address, symbol);
        if(memberCoinAddress==null){
            return;
        }
        Long memberId = memberCoinAddress.getMemberId();
        // 查询钱包 并更新
        MemberWalletCoinEntity walletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.ROC.name());
        if (walletCoinEntity == null) {
           // 创建一个钱包
            // 创建这个钱包
            walletCoinEntity = new MemberWalletCoinEntity();
            walletCoinEntity.setAvailableBalance(BigDecimal.ZERO);
            walletCoinEntity.setFrozenBalance(BigDecimal.ZERO);
            walletCoinEntity.setTotalBalance(BigDecimal.ZERO);
            walletCoinEntity.setBorrowedFund(BigDecimal.ZERO);
            walletCoinEntity.setMemberId(memberId);
            walletCoinEntity.setWalletCode(symbol);
            memberWalletCoinDao.insert(walletCoinEntity);
        }
        memberWalletCoinDao.updateBlockBalance(walletCoinEntity.getId(), balance, BigDecimal.ZERO, 0);
        String orderNo = insertCoinCharge(address, memberId, balance, CoinTypeEnum.ROC.name(), "", BigDecimal.ZERO,null);
        // 插入财务记录
        LogRecordUtils.insertMemberAccountMoneyChange(memberId, "转入", balance, CoinTypeEnum.ROC.name(), 1, 1);
        try{
            ThreadPoolUtils.sendDingTalk(5);
            MemberEntity member = memberDao.selectById(memberId);
            if (StrUtil.isNotBlank(member.getPhone())) {
                String amount = balance.toPlainString() + "ROC";
                Sms106Send.sendRechargeMsg(member.getPhone(), DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN), orderNo);
            } else {
                SubMailSend.sendRechargeMail(member.getEmail(), DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN), orderNo);
            }
        }catch (Exception e){
            //e.printStackTrace();
        }
    }
src/main/java/com/xcong/excoin/modules/member/dao/MemberCoinAddressDao.java
@@ -15,6 +15,8 @@
    MemberCoinAddressEntity selectBlockAddress(@Param("memberId") Long memberId, @Param("symbol") String symbol);
    MemberCoinAddressEntity selectCoinAddressByAddressAndSymbol(@Param("address") String address, @Param("symbol") String symbol);
    List<MemberCoinAddressEntity> selectCoinAddressListByMap(@Param("symbol") String symbol, @Param("memberId") Long memberId);
    List<MemberCoinAddressEntity> selectAllBlockAddressBySymbolAndTag(@Param("symbol") String symbol, @Param("tag") String tag);
src/main/java/com/xcong/excoin/modules/member/service/impl/MemberServiceImpl.java
@@ -41,6 +41,7 @@
import com.xcong.excoin.utils.ThreadPoolUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -144,12 +145,10 @@
//        }
        if (!AppContants.SYSTEM_REFERER.equals(registerDto.getRefererId())) {
            MemberEntity isExist = memberDao.selectMemberInfoByInviteId(registerDto.getRefererId());
            if (isExist == null) {
                return Result.fail("推荐人不存在");
            if (isExist != null) {
                member.setRefererId(registerDto.getRefererId());
            }
        }
        member.setRefererId(registerDto.getRefererId());
        member.setAccountStatus(MemberEntity.ACCOUNT_STATUS_ENABLE);
        member.setAccountType(MemberEntity.ACCOUNT_TYPE_NORMAL);
        member.setAgentLevel(MemberEntity.ACCOUNT_AGENT_LEVEL);
@@ -171,7 +170,7 @@
        boolean flag = false;
        String parentId = member.getRefererId();
        String ids = "";
        while (!flag) {
        while (!flag && StringUtils.isNotBlank(parentId)) {
            ids += ("," + parentId);
            MemberEntity parentMember = memberDao.selectMemberInfoByInviteId(parentId);
            if (parentMember == null) {
src/main/java/com/xcong/excoin/rabbit/consumer/RocBlockUpdateConsumer.java
New file
@@ -0,0 +1,51 @@
package com.xcong.excoin.rabbit.consumer;
import com.alibaba.fastjson.JSONObject;
import com.rabbitmq.client.Channel;
import com.xcong.excoin.configurations.RabbitMqConfig;
import com.xcong.excoin.modules.blackchain.model.RocTransferDetail;
import com.xcong.excoin.modules.coin.service.BlockCoinService;
import com.xcong.excoin.modules.member.dao.MemberCoinAddressDao;
import com.xcong.excoin.modules.member.entity.MemberCoinAddressEntity;
import com.xcong.excoin.rabbit.pricequeue.OrderModel;
import com.xcong.excoin.rabbit.pricequeue.OrderOperatePriceService;
import org.apache.commons.lang.StringUtils;
import org.springframework.amqp.core.Message;
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;
import java.util.List;
/**
 * 用户修改止损止盈价格、提价限价委托、下单爆仓价等消息
 * 后台打包开启 APP 不开启
 * @author helius
 */
@Component
//@ConditionalOnProperty(prefix = "app", name = "newest-price-update-job-contract", havingValue = "true")
public class RocBlockUpdateConsumer {
    @Resource
    private BlockCoinService blockCoinService;
    /**
     * ROC币种同步
     *
     * @param message 消息体
     * @param channel 信道
     * @date 2019年4月19日
     */
    @RabbitListener(queues = RabbitMqConfig.QUEUE_ROC)
    public void onMessageMorePro(Message message, Channel channel) {
        String content = new String(message.getBody());
        // 操作前的map
        // 转为model
        RocTransferDetail transferDetail = JSONObject.parseObject(content, RocTransferDetail.class);
        blockCoinService.updateRoc(transferDetail);
    }
}
src/main/java/com/xcong/excoin/trade/CoinTrader.java
@@ -261,7 +261,6 @@
            while (iterator.hasNext()) {
                OrderCoinsEntity matchOrder = iterator.next();
                ExchangeTrade trade = processMatch(focusedOrder, matchOrder);
                logger.info(">>>>>" + trade);
                if (trade != null) {
                    exchangeTrades.add(trade);
                }
@@ -410,7 +409,6 @@
        availAmount = calculateTradedAmount(matchOrder, dealPrice);
        //计算成交量 取少的
        BigDecimal tradedAmount = (availAmount.compareTo(needAmount) >= 0 ? needAmount : availAmount);
        System.out.println("成交量:"+tradedAmount);
        //logger.info("dealPrice={},amount={}", dealPrice, tradedAmount);
        //如果成交额为0说明剩余额度无法成交,退出
        if (tradedAmount.compareTo(BigDecimal.ZERO) == 0) {
src/main/java/com/xcong/excoin/utils/dingtalk/DingTalkUtils.java
@@ -46,7 +46,7 @@
            request.setActionCard(actionCard);
            OapiRobotSendResponse response = client.execute(request);
            log.info(JSONObject.toJSONString(response));
            //log.info(JSONObject.toJSONString(response));
        } catch (Exception e) {
            log.error("#dingtalk send error#", e);
        } finally {
src/main/java/com/xcong/excoin/utils/mail/Sms106Send.java
@@ -20,7 +20,7 @@
    private static final String URL = "http://www.qf106.com/sms.aspx";
    private static final String ID = "16606";
    private static final String ACCOUNT = "Biue";
    private static final String ACCOUNT = "golden";
    private static final String PASSWORD = "123456";
@@ -37,13 +37,13 @@
    }
    public static boolean sendRechargeMsg(String phone, String time, String orderNo) {
        String msg = "尊敬的用户,您的帐号于{}有一笔成功充值订单,如有疑问请联系客服,订单编号为{}";
        String msg = "尊敬的用户,您的帐号于{}有一笔成功充值订单,订单编号{}";
        String content = StrUtil.format(msg, time, orderNo);
        return request(phone, content, "充值");
    }
    public static boolean sendWithdrawalMsg(String phone, String time, String orderNo) {
        String msg = "尊敬的用户,您的帐号于{}有一笔成功提现订单,如有疑问请联系客服,订单编号为{}";
        String msg = "尊敬的用户,您的帐号于{}有一笔成功提现订单,订单编号为{}";
        String content = StrUtil.format(msg, time, orderNo);
        return request(phone, content, "提现");
    }
@@ -64,7 +64,7 @@
        param.put("telephonenumber", 0);
        String response = HttpUtil.post(URL, param);
        log.info("短信发送:{}, {}", tagName, response);
        //log.info("短信发送:{}, {}", tagName, response);
        if ("Success".equals(XmlUtil.xmlToMap(response).get("returnstatus"))) {
            return true;
        } else {
@@ -72,7 +72,4 @@
        }
    }
    public static void main(String[] args) {
        System.out.println(sendVerifyCode("15773002834", "123456", 2));
    }
}
src/main/java/com/xcong/excoin/utils/mail/SubMailSend.java
@@ -43,7 +43,7 @@
    private static final String APP_ID = "16082";
    private static final String APP_KEY = "f34c792a1112c16c190ed7190d386c4f";
    private static final String FROM = "biue@submail.biue.me";
    private static final String FROM = "goldenFlame@submail.goldflame.cc";
    private static final String SIGN_TYPE = "";
    /**
@@ -57,7 +57,7 @@
        JSONObject vars = new JSONObject();
        vars.put("code", code);
        String project = "zoKVB";
        String project = "qNv3f4";
        return request(vars, project, to);
    }
@@ -73,14 +73,14 @@
        JSONObject vars = new JSONObject();
        vars.put("time", time);
        vars.put("orderNo", orderNo);
        String project = "x820C2";
        String project = "6dH3j";
        return request(vars, project, to);
    }
    public static boolean sendWithdrawalMail(String to, String time) {
        JSONObject vars = new JSONObject();
        vars.put("time", time);
        String project = "e3BO91";
        String project = "Vyk0y2";
        return request(vars, project, to);
    }
@@ -165,6 +165,6 @@
    public static void main(String[] args) {
//        System.out.println(sendMail("546766039@qq.com", "123456"));
        System.out.println(sendRechargeMail("546766039@qq.com", DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN), "123456"));
        System.out.println(sendRechargeMail("512061637@qq.com",  "wewewewe","123456"));
    }
}
src/main/resources/application-test.yml
@@ -100,7 +100,7 @@
  day-line: false
  other-job: true
  loop-job: true
  rabbit-consumer: true
  rabbit-consumer: false
  block-job: true
aliyun:
src/main/resources/mapper/member/MemberCoinAddressDao.xml
@@ -36,6 +36,20 @@
             </if>
         </where>
    </select>
    <select id="selectCoinAddressByAddressAndSymbol" resultType="com.xcong.excoin.modules.member.entity.MemberCoinAddressEntity">
        select *
          from member_coin_address
         <where>
         is_biyict = 1
             <if test="symbol != null  and  symbol  != ''">
                 and symbol = #{symbol}
             </if>
             <if test="address != null  and  address  != ''">
                 and address = #{address}
             </if>
         </where>
    </select>
    
    <select id="selectCoinAddressListByMap" resultType="com.xcong.excoin.modules.member.entity.MemberCoinAddressEntity">
        select *  from member_coin_address