xiaoyong931011
2020-05-26 995486a0c3b98600c7ff212cc4ba1b05eaccb948
Merge branch 'master' of https://gitee.com/chonggaoxiao/new_excoin.git
16 files added
12 files modified
732 ■■■■ changed files
pom.xml 11 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/configurations/RabbitMqConfig.java 63 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/configurations/properties/CustomRabbitProperties.java 19 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/home/controller/MemberQuickBuySaleController.java 82 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/home/dao/MemberPaymentMethodDao.java 3 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/home/dao/MemberQuickBuySaleDao.java 3 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/home/entity/MemberPaymentMethodEntity.java 70 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/home/service/MemberQuickBuySaleService.java 7 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/home/service/impl/MemberQuickBuySaleServiceImpl.java 114 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/member/dao/MemberWalletCoinDao.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/platform/controller/PlatformController.java 34 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/platform/dao/PlatformCnyUsdtExchangeDao.java 12 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/platform/dao/PlatformPaymentMethodDao.java 9 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/platform/entity/PlatformCnyUsdtExchangeEntity.java 26 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/platform/entity/PlatformPaymentMethodEntity.java 26 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/platform/service/PlatformCnyUsdtExchangeService.java 13 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/platform/service/PlatformPaymentMethodService.java 13 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/platform/service/impl/PlatformCnyUsdtExchangeServiceImpl.java 38 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/platform/service/impl/PlatformPaymentMethodServiceImpl.java 40 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/platform/vo/PlatformCnyUsdtExchangeVo.java 13 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/rabbit/consumer/TestConsumer.java 21 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/rabbit/producer/TestProducer.java 42 ●●●●● patch | view | raw | blame | history
src/main/resources/application.yml 15 ●●●●● patch | view | raw | blame | history
src/main/resources/mapper/home/MemberPaymentMethodDao.xml 9 ●●●●● patch | view | raw | blame | history
src/main/resources/mapper/home/MemberQuickBuySaleDao.xml 5 ●●●● patch | view | raw | blame | history
src/main/resources/mapper/member/MemberWalletCoinDao.xml 11 ●●●●● patch | view | raw | blame | history
src/test/java/com/xcong/excoin/RSATest.java 7 ●●●●● patch | view | raw | blame | history
src/test/java/com/xcong/excoin/RabbitMqTest.java 24 ●●●●● patch | view | raw | blame | history
pom.xml
@@ -27,6 +27,8 @@
        <mapstruct.version>1.3.1.Final</mapstruct.version>
        <hutool.version>5.3.1</hutool.version>
        <fastjson.version>1.2.61</fastjson.version>
        <netty.version>4.1.33.Final</netty.version>
        <dom4j.version>1.6.1</dom4j.version>
    </properties>
    <dependencies>
@@ -43,6 +45,11 @@
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-amqp</artifactId>
        </dependency>
<!--        <dependency>-->
@@ -166,14 +173,14 @@
        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>1.6.1</version>
            <version>${dom4j.version}</version>
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-all</artifactId>
            <version>4.1.33.Final</version>
            <version>${netty.version}</version>
        </dependency>
    </dependencies>
src/main/java/com/xcong/excoin/configurations/RabbitMqConfig.java
New file
@@ -0,0 +1,63 @@
package com.xcong.excoin.configurations;
import com.xcong.excoin.configurations.properties.CustomRabbitProperties;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import javax.annotation.Resource;
/**
 * @author wzy
 * @date 2020-05-25
 **/
@Configuration
public class RabbitMqConfig {
    public static final String EXCHANGE_ONE = "excoin-exchange-one";
    public static final String QUEUE_TEST = "test-queue";
    public static final String ROUTING_KEY_TEST = "test-routingKey";
    @Resource
    private ConnectionFactory connectionFactory;
//    @Bean
//    public ConnectionFactory connectionFactory() {
//        CachingConnectionFactory connectionFactory = new CachingConnectionFactory(customRabbitProperties.getHost(), customRabbitProperties.getPort());
//        connectionFactory.setUsername(customRabbitProperties.getUsername());
//        connectionFactory.setPassword(customRabbitProperties.getPassword());
//        connectionFactory.setPublisherConfirmType(CachingConnectionFactory.ConfirmType.CORRELATED);
//        return connectionFactory;
//    }
    @Bean
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public RabbitTemplate rabbitTemplate() {
        return new RabbitTemplate(connectionFactory);
    }
    @Bean
    public DirectExchange defaultExchange() {
        return new DirectExchange(EXCHANGE_ONE);
    }
    @Bean
    public Queue testQueue() {
        return new Queue(QUEUE_TEST, true);
    }
    @Bean
    public Binding binding() {
        return BindingBuilder.bind(testQueue()).to(defaultExchange()).with(ROUTING_KEY_TEST);
    }
}
src/main/java/com/xcong/excoin/configurations/properties/CustomRabbitProperties.java
New file
@@ -0,0 +1,19 @@
package com.xcong.excoin.configurations.properties;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
 * @author wzy
 * @date 2020-05-25
 **/
@Data
@Configuration
@ConfigurationProperties(prefix = "custom.rabbitmq")
public class CustomRabbitProperties {
    private String host;
    private int port;
    private String username;
    private String password;
}
src/main/java/com/xcong/excoin/modules/home/controller/MemberQuickBuySaleController.java
@@ -8,57 +8,103 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.druid.util.StringUtils;
import com.xcong.excoin.common.LoginUserUtils;
import com.xcong.excoin.common.response.Result;
import com.xcong.excoin.modules.home.dto.MemberQuickBuySaleCommitDto;
import com.xcong.excoin.modules.home.dto.MemberQuickBuySaleDto;
import com.xcong.excoin.modules.home.service.MemberQuickBuySaleService;
import com.xcong.excoin.modules.member.entity.MemberEntity;
import cn.hutool.crypto.SecureUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
@RestController
@Slf4j
@RequestMapping(value = "/api/quick")
@Api(value = "USDT快捷买卖类", tags = "USDT快捷买卖类")
@Api(value = "MemberQuickBuySaleController", tags = "USDT快捷买卖类")
public class MemberQuickBuySaleController {
    @Autowired
    MemberQuickBuySaleService memberQuickBuySaleService;
    @ApiOperation(value = "USDT快速充值", notes = "USDT快速充值")
    @ApiOperation(value = "recharge", notes = "USDT快速充值")
    @RequestMapping(value = "/recharge", method = RequestMethod.POST)
    public Result recharge(@RequestBody MemberQuickBuySaleDto memberQuickBuySaleDto) {
        return memberQuickBuySaleService.recharge(memberQuickBuySaleDto);
        log.info("入参----->{}", memberQuickBuySaleDto);
        //获取用户ID
        MemberEntity member = LoginUserUtils.getAppLoginUser();
        log.info("查询到的会员----->{}", member);
        // 验证是否实名认证
        if (MemberEntity.CERTIFY_STATUS_Y.equals(member.getCertifyStatus())) {
            return Result.fail("请先实名认证");
        }
        String tradePasswordWeb = memberQuickBuySaleDto.getTradePassword();
        // 验证支付密码
        String tradePassword = member.getTradePassword();
        log.info("入参交易密码{},用户设置的交易密码{}", tradePasswordWeb,tradePassword);
        if (StringUtils.isEmpty(tradePassword)) {
            return Result.fail("请先配置交易密码");
        }
        if (StringUtils.isEmpty(tradePasswordWeb)) {
            return Result.fail("请输入交易密码");
        }
        // System.out.println("交易密码:"+MD5.GetMD5Code(tradePasswordWeb)+" tradePassword =
        // "+tradePassword);
        // 验证交易密码
        if (!tradePassword.equals(SecureUtil.md5(tradePasswordWeb))) {
            return Result.fail("请输入正确的交易密码");
        }
        return memberQuickBuySaleService.recharge(member, memberQuickBuySaleDto);
    }
    
    
    @ApiOperation(value = "USDT充值支付确认", notes = "USDT充值支付确认")
    @ApiOperation(value = "commitPay", notes = "USDT充值支付确认")
    @RequestMapping(value = "/commitPay", method = RequestMethod.POST)
    public Result commitPay(@RequestBody MemberQuickBuySaleCommitDto memberQuickBuySaleCommitDto) {
        return memberQuickBuySaleService.commitPay(memberQuickBuySaleCommitDto);
    }
    
    @ApiOperation(value = "查询单个买卖记录", notes = "查询单个买卖记录")
    @ApiOperation(value = "selectById", notes = "查询单个买卖记录")
    @GetMapping(value = "/selectById/{id}")
    public Result selectById(@PathVariable(value = "id") Long id) {
        return memberQuickBuySaleService.selectById(id);
    }
    
    /**
     * 充值撤销
     *
     * @param memberChargeUsdt
     * @param page
     * @param rows
     * @return
     */
    @ApiOperation(value = "充值撤销", notes = "充值撤销")
    @ApiOperation(value = "cancel", notes = "充值撤销")
    @GetMapping(value = "/cancel/{id}")
    public Result cancel(@PathVariable(value = "id") Long id) {
        return memberQuickBuySaleService.cancelRecharge(id);
    }
    
    @ApiOperation(value = "sell", notes = "USDT快速充值")
    @RequestMapping(value = "/sell", method = RequestMethod.POST)
    public Result sell(MemberQuickBuySaleDto memberQuickBuySaleDto) {
        // 获取当前登录用户
        MemberEntity member = LoginUserUtils.getAppLoginUser();
        if (MemberEntity.CERTIFY_STATUS_Y.equals(member.getCertifyStatus())) {
            return Result.fail("请先实名认证");
        }
        String tradePasswordWeb = memberQuickBuySaleDto.getTradePassword();
        // 验证支付密码
        String tradePassword = member.getTradePassword();
        log.info("入参交易密码{},用户设置的交易密码{}", tradePasswordWeb,tradePassword);
        if (StringUtils.isEmpty(tradePassword)) {
            return Result.fail("请先配置交易密码");
        }
        if (StringUtils.isEmpty(tradePasswordWeb)) {
            return Result.fail("请输入交易密码");
        }
        // 验证交易密码
        if (!tradePassword.equals(SecureUtil.md5(tradePasswordWeb))) {
            return Result.fail("请输入正确的交易密码");
        }
        return memberQuickBuySaleService.sell(member,memberQuickBuySaleDto);
    }
}
src/main/java/com/xcong/excoin/modules/home/dao/MemberPaymentMethodDao.java
@@ -1,8 +1,11 @@
package com.xcong.excoin.modules.home.dao;
import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xcong.excoin.modules.home.entity.MemberPaymentMethodEntity;
public interface MemberPaymentMethodDao extends BaseMapper<MemberPaymentMethodEntity> {
    public List<MemberPaymentMethodEntity> selectByMemberId(Long memberId);
}
src/main/java/com/xcong/excoin/modules/home/dao/MemberQuickBuySaleDao.java
@@ -1,9 +1,12 @@
package com.xcong.excoin.modules.home.dao;
import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xcong.excoin.modules.home.entity.MemberQuickBuySaleEntity;
public interface MemberQuickBuySaleDao extends BaseMapper<MemberQuickBuySaleEntity> {
    
    MemberQuickBuySaleEntity selectByIdAndMemberId(@Param("memberId")Long memberId,@Param("id")Long id);
}
src/main/java/com/xcong/excoin/modules/home/entity/MemberPaymentMethodEntity.java
@@ -1,7 +1,5 @@
package com.xcong.excoin.modules.home.entity;
import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.TableName;
import com.xcong.excoin.common.system.base.BaseEntity;
@@ -10,33 +8,20 @@
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("member_quick_buy_sale")
@TableName("member_payment_method")
public class MemberPaymentMethodEntity  extends BaseEntity{
    /**
     * 订单状态 1-新建
     * 付款方式:支付宝
     */
    public static final Integer CHARGE_STATUS_CREATE = 1;
    public static String PAYMENT_TYPE_ALIPAY = "1";
    /**
     * 订单状态 2-已付款
     * 付款方式:微信
     */
    public static final Integer CHARGE_STATUS_PAID = 2;
    public static String PAYMENT_TYPE_WEPAY = "2";
    /**
     * 订单状态 3-已审核
     * 付款方式:银行卡
     */
    public static final Integer CHARGE_STATUS_CHECKED = 3;
    /**
     * 订单状态 4-撤单
     */
    public static final Integer CHARGE_STATUS_CANCEL_USER = 4;
    /**
     * 订单状态 5-系统取消
     */
    public static final Integer CHARGE_STATUS_CANCEL_SYSTEM = 5;
    public static String PAYMENT_TYPE_BANK = "3";
    private static final long serialVersionUID = 1L;
    /**
@@ -44,43 +29,32 @@
     */
    private Long memberId;
    /**
     * 金额(人民币)
     * 姓名
     */
    private BigDecimal amountCny;
    private String name;
    /**
     * 金额(USDT)
     * 账号
     */
    private BigDecimal amountUsdt;
    private String account;
    /**
     * 付款方式 1-支付宝2-微信3-银行卡
     * 收款二维码
     */
    private Integer paymentType;
    private String paymentQrcode;
    /**
     * 收款账号
     * 银行
     */
    private String paymentAccount;
    private String bank;
    /**
     * 收款人姓名
     * 支行
     */
    private String paymentName;
    private String subBank;
    /**
     * 支付码
     * 类型 1-支付宝2-微信3-银行卡
     */
    private String paymentCode;
    private String paymentType;
    /**
     * 单价
     * 默认收款方式
     */
    private BigDecimal unitPrice;
    /**
     * 订单状态 1-新建2-已付款3-已审核4-撤单5-系统取消
     */
    private int orderStatus;
    /**
     * 订单编号
     */
    private String orderNo;
    /**
     * 订单类型 B买入 S卖出
     */
    private String orderType;
    private int isDefualt;
}
src/main/java/com/xcong/excoin/modules/home/service/MemberQuickBuySaleService.java
@@ -5,16 +5,17 @@
import com.xcong.excoin.modules.home.dto.MemberQuickBuySaleCommitDto;
import com.xcong.excoin.modules.home.dto.MemberQuickBuySaleDto;
import com.xcong.excoin.modules.home.entity.MemberQuickBuySaleEntity;
import com.xcong.excoin.modules.member.entity.MemberEntity;
public interface MemberQuickBuySaleService extends IService<MemberQuickBuySaleEntity> {
    public Result recharge(MemberQuickBuySaleDto memberQuickBuySaleDto);
    public Result recharge(MemberEntity member,MemberQuickBuySaleDto memberQuickBuySaleDto);
    
    public Result commitPay(MemberQuickBuySaleCommitDto memberQuickBuySaleCommitDto);
    
    public Result selectById(Long id);
    
    public Result sell();
    public Result cancelRecharge(Long id);
    public Result sell(MemberEntity member,MemberQuickBuySaleDto memberQuickBuySaleDto);
}
src/main/java/com/xcong/excoin/modules/home/service/impl/MemberQuickBuySaleServiceImpl.java
@@ -8,9 +8,10 @@
import org.springframework.stereotype.Service;
import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xcong.excoin.common.LoginUserUtils;
import com.xcong.excoin.common.enumerates.CoinTypeEnum;
import com.xcong.excoin.common.response.Result;
import com.xcong.excoin.modules.home.dao.MemberPaymentMethodDao;
import com.xcong.excoin.modules.home.dao.MemberQuickBuySaleDao;
@@ -26,11 +27,7 @@
import com.xcong.excoin.modules.member.entity.MemberEntity;
import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity;
import cn.hutool.crypto.SecureUtil;
import lombok.extern.slf4j.Slf4j;
@Service
@Slf4j
public class MemberQuickBuySaleServiceImpl extends ServiceImpl<MemberQuickBuySaleDao, MemberQuickBuySaleEntity> implements MemberQuickBuySaleService{
    
    @Resource
@@ -43,43 +40,17 @@
    MemberPaymentMethodDao memberPaymentMethodDao;
    @Override
    public Result recharge(MemberQuickBuySaleDto memberQuickBuySaleDto) {
        log.info("入参----->{}", memberQuickBuySaleDto);
        //获取用户ID
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        MemberEntity member = memberDao.selectById(memberId);
        log.info("查询到的会员----->{}", member);
        // 验证是否实名认证
        if (MemberEntity.CERTIFY_STATUS_Y.equals(member.getCertifyStatus())) {
            return Result.fail("请先实名认证");
        }
        String tradePasswordWeb = memberQuickBuySaleDto.getTradePassword();
        // 验证支付密码
        String tradePassword = member.getTradePassword();
        log.info("入参交易密码{},用户设置的交易密码{}", tradePasswordWeb,tradePassword);
        if (StringUtils.isEmpty(tradePassword)) {
            return Result.fail("请先配置交易密码");
        }
        if (StringUtils.isEmpty(tradePasswordWeb)) {
            return Result.fail("请输入交易密码");
        }
        // System.out.println("交易密码:"+MD5.GetMD5Code(tradePasswordWeb)+" tradePassword =
        // "+tradePassword);
        // 验证交易密码
        if (!tradePassword.equals(SecureUtil.md5(tradePasswordWeb))) {
            return Result.fail("请输入正确的交易密码");
        }
    public Result recharge(MemberEntity member,MemberQuickBuySaleDto memberQuickBuySaleDto) {
        // 生成订单号
        Long timestamp = System.currentTimeMillis();
        int random = (int) (Math.random() * 10);
        String chargeNo = String.valueOf(timestamp).substring(2) + random;
        // 插入订单表
        MemberQuickBuySaleEntity memberQuickBuySaleEntity = new MemberQuickBuySaleEntity();
        memberQuickBuySaleEntity.setOrderStatus(memberQuickBuySaleEntity.CHARGE_STATUS_CREATE);
        memberQuickBuySaleEntity.setMemberId(memberId);
        memberQuickBuySaleEntity.setOrderStatus(MemberQuickBuySaleEntity.CHARGE_STATUS_CREATE);
        memberQuickBuySaleEntity.setMemberId(member.getId());
        memberQuickBuySaleEntity.setAmountUsdt(memberQuickBuySaleDto.getAmountUsdt());
        memberQuickBuySaleEntity.setAmountCny(memberQuickBuySaleDto.getAmountCny());
        memberQuickBuySaleEntity.setCreateTime(new Date());
        memberQuickBuySaleEntity.setOrderNo(chargeNo);
        memberQuickBuySaleEntity.setOrderType("B");
@@ -120,22 +91,73 @@
        return Result.ok(memberQuickBuySaleVo);
    }
    @Override
    public Result sell(MemberEntity member,MemberQuickBuySaleDto memberQuickBuySaleDto) {
        // 判断是否存在足够余额
        MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(member.getId(),CoinTypeEnum.USDT.toString());
        // 判断是否存在足够余额
        if(walletCoin ==null) {
            return Result.fail("您当前可用USDT额度不够");
        }
        BigDecimal extractUsdt = memberQuickBuySaleDto.getAmountUsdt();
        if (extractUsdt == null) {
            return Result.fail("请输入提币量");
        }
        // 判断是否足够
        System.out.println("提币数:"+extractUsdt.doubleValue()+"   可用:"+walletCoin.getAvailableBalance());
        if (extractUsdt.compareTo(walletCoin.getAvailableBalance())==1) {
            return Result.fail("您当前可用USDT额度不够");
        }
        // 判断是否存在收款方式
        List<MemberPaymentMethodEntity> payMentMethodList = memberPaymentMethodDao.selectByMemberId(member.getId());
        if(CollectionUtils.isEmpty(payMentMethodList)){
            return Result.fail("请配置收款方式");
        }
        // 冻结可用额度
        int i = memberWalletCoinDao.updateFrozenBalance(member.getId(),
                walletCoin.getId(), extractUsdt);
        if (i <= 0) {
            return Result.fail("可用USDT余额不足");
        }
        // 生成订单号
        Long timestamp = System.currentTimeMillis();
        int random = (int) (Math.random() * 10);
        String chargeNo = String.valueOf(timestamp).substring(2) + random;
        // 插入订单表
        MemberQuickBuySaleEntity memberQuickBuySaleEntity = new MemberQuickBuySaleEntity();
        memberQuickBuySaleEntity.setOrderStatus(MemberQuickBuySaleEntity.CHARGE_STATUS_CREATE);
        memberQuickBuySaleEntity.setMemberId(member.getId());
        memberQuickBuySaleEntity.setAmountUsdt(memberQuickBuySaleDto.getAmountUsdt());
        memberQuickBuySaleEntity.setAmountCny(memberQuickBuySaleDto.getAmountCny());
        memberQuickBuySaleEntity.setOrderNo(chargeNo);
        memberQuickBuySaleEntity.setOrderType("S");
        // 支付码 ID+四位随机数
        int ran = (int) (Math.random() * 10000000);
        memberQuickBuySaleEntity.setPaymentCode(ran + "");
        memberQuickBuySaleDao.insert(memberQuickBuySaleEntity);
        // TODO dingtalk
        return Result.ok("下单成功");
    }
    @Override
    public Result cancelRecharge(Long id) {
        // 获取当前登录用户
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        MemberEntity member = memberDao.selectById(memberId);
        if(memberId==null) {
        MemberEntity member = LoginUserUtils.getAppLoginUser();
        if(member==null) {
            return Result.fail("登录用户已失效");
        }
        MemberQuickBuySaleEntity memberQuickBuySaleEntity = memberQuickBuySaleDao.selectById(id);
        MemberQuickBuySaleEntity memberQuickBuySaleEntity = memberQuickBuySaleDao.selectByIdAndMemberId(id,member.getId());
        memberQuickBuySaleEntity.setOrderStatus(MemberQuickBuySaleEntity.CHARGE_STATUS_CANCEL_USER);
        memberQuickBuySaleDao.updateById(memberQuickBuySaleEntity);
        
        // 判断是否存在足够余额
        MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(id,"USDT");
        MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(member.getId(),CoinTypeEnum.USDT.toString());
        boolean flag = true;
        while(flag) {
            walletCoin.setAvailableBalance(walletCoin.getAvailableBalance().add(memberQuickBuySaleEntity.getAmountUsdt()));
@@ -144,14 +166,8 @@
            if(i>0) {
                flag = false;
            }
            walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(id,"USDT");
            walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(member.getId(),CoinTypeEnum.USDT.toString());
        }
        return Result.ok("成功");
    }
    @Override
    public Result sell() {
        // TODO Auto-generated method stub
        return null;
    }
}
src/main/java/com/xcong/excoin/modules/member/dao/MemberWalletCoinDao.java
@@ -1,5 +1,6 @@
package com.xcong.excoin.modules.member.dao;
import java.math.BigDecimal;
import java.util.List;
import org.apache.ibatis.annotations.Param;
@@ -16,4 +17,5 @@
    
    MemberWalletCoinEntity selectWalletCoinBymIdAndCode(@Param("memberId")Long memberId,@Param("walletCode")String walletCode);
    
    int updateFrozenBalance(@Param("memberId")Long memberId,@Param("id")Long id,@Param("memberId")BigDecimal amount);
}
src/main/java/com/xcong/excoin/modules/platform/controller/PlatformController.java
New file
@@ -0,0 +1,34 @@
package com.xcong.excoin.modules.platform.controller;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.xcong.excoin.common.response.Result;
import com.xcong.excoin.modules.platform.service.PlatformCnyUsdtExchangeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
@RestController
@Slf4j
@RequestMapping(value = "/api/exchange")
@Api(value = "PlatformController", tags = "平台系统设置类")
public class PlatformController {
    @Resource
    PlatformCnyUsdtExchangeService platformCnyUsdtExchangeService;
    @ApiOperation(value = "findUsdtCnyExchange", notes = "Cny|Usdt兑换")
    @GetMapping(value = "/findUsdtCnyExchange")
    public Result findUsdtCnyExchange(@ApiParam(name = "type", value = "类型", type="string", required=true) @RequestParam("type") String type) {
        log.info("type值----->{}", type);
        return platformCnyUsdtExchangeService.findUsdtCnyExchange(type);
    }
}
src/main/java/com/xcong/excoin/modules/platform/dao/PlatformCnyUsdtExchangeDao.java
New file
@@ -0,0 +1,12 @@
package com.xcong.excoin.modules.platform.dao;
import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xcong.excoin.modules.home.entity.MemberPaymentMethodEntity;
import com.xcong.excoin.modules.platform.entity.PlatformCnyUsdtExchangeEntity;
public interface PlatformCnyUsdtExchangeDao extends BaseMapper<PlatformCnyUsdtExchangeEntity> {
}
src/main/java/com/xcong/excoin/modules/platform/dao/PlatformPaymentMethodDao.java
New file
@@ -0,0 +1,9 @@
package com.xcong.excoin.modules.platform.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xcong.excoin.modules.platform.entity.PlatformPaymentMethodEntity;
public interface PlatformPaymentMethodDao extends BaseMapper<PlatformPaymentMethodEntity> {
}
src/main/java/com/xcong/excoin/modules/platform/entity/PlatformCnyUsdtExchangeEntity.java
New file
@@ -0,0 +1,26 @@
package com.xcong.excoin.modules.platform.entity;
import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.TableName;
import com.xcong.excoin.common.system.base.BaseEntity;
import lombok.Data;
@Data
@TableName("platform_cny_usdt_exchange")
public class PlatformCnyUsdtExchangeEntity extends BaseEntity{
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    /**
     * 兑换比例
     */
    private BigDecimal value;
    /**
     * 增减偏量
     */
    private BigDecimal diff;
}
src/main/java/com/xcong/excoin/modules/platform/entity/PlatformPaymentMethodEntity.java
New file
@@ -0,0 +1,26 @@
package com.xcong.excoin.modules.platform.entity;
import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.TableName;
import com.xcong.excoin.common.system.base.BaseEntity;
import lombok.Data;
@Data
@TableName("platform_cny_usdt_exchange")
public class PlatformPaymentMethodEntity extends BaseEntity{
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    /**
     * 兑换比例
     */
    private BigDecimal value;
    /**
     * 增减偏量
     */
    private BigDecimal diff;
}
src/main/java/com/xcong/excoin/modules/platform/service/PlatformCnyUsdtExchangeService.java
New file
@@ -0,0 +1,13 @@
package com.xcong.excoin.modules.platform.service;
import org.springframework.web.bind.annotation.RequestParam;
import com.baomidou.mybatisplus.extension.service.IService;
import com.xcong.excoin.common.response.Result;
import com.xcong.excoin.modules.platform.entity.PlatformCnyUsdtExchangeEntity;
public interface PlatformCnyUsdtExchangeService extends IService<PlatformCnyUsdtExchangeEntity> {
    public Result findUsdtCnyExchange(@RequestParam("type") String type);
}
src/main/java/com/xcong/excoin/modules/platform/service/PlatformPaymentMethodService.java
New file
@@ -0,0 +1,13 @@
package com.xcong.excoin.modules.platform.service;
import org.springframework.web.bind.annotation.RequestParam;
import com.baomidou.mybatisplus.extension.service.IService;
import com.xcong.excoin.common.response.Result;
import com.xcong.excoin.modules.platform.entity.PlatformPaymentMethodEntity;
public interface PlatformPaymentMethodService extends IService<PlatformPaymentMethodEntity> {
    public Result findUsdtCnyExchange(@RequestParam("type") String type);
}
src/main/java/com/xcong/excoin/modules/platform/service/impl/PlatformCnyUsdtExchangeServiceImpl.java
New file
@@ -0,0 +1,38 @@
package com.xcong.excoin.modules.platform.service.impl;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xcong.excoin.common.response.Result;
import com.xcong.excoin.modules.platform.dao.PlatformCnyUsdtExchangeDao;
import com.xcong.excoin.modules.platform.entity.PlatformCnyUsdtExchangeEntity;
import com.xcong.excoin.modules.platform.service.PlatformCnyUsdtExchangeService;
@Service
public class PlatformCnyUsdtExchangeServiceImpl extends ServiceImpl<PlatformCnyUsdtExchangeDao, PlatformCnyUsdtExchangeEntity> implements PlatformCnyUsdtExchangeService{
    @Resource
    PlatformCnyUsdtExchangeDao platformCnyUsdtExchangeDao;
    @Override
    public Result findUsdtCnyExchange(String type) {
        // 查询当前兑换价格
        Map<String, Object> map = new HashMap<String, Object>();
        PlatformCnyUsdtExchangeEntity platformCnyUsdtExchangeEntity = platformCnyUsdtExchangeDao.selectById(1);
        BigDecimal cnyUsdt = platformCnyUsdtExchangeEntity.getValue();
        if ("B".equals(type)) {
            // 买的时候提高价格
            map.put("exchange", cnyUsdt.add(platformCnyUsdtExchangeEntity.getDiff()));
        }else {
            // 卖的时候降低
            map.put("exchange", cnyUsdt.subtract(platformCnyUsdtExchangeEntity.getDiff()));
        }
        return Result.ok(map);
    }
}
src/main/java/com/xcong/excoin/modules/platform/service/impl/PlatformPaymentMethodServiceImpl.java
New file
@@ -0,0 +1,40 @@
package com.xcong.excoin.modules.platform.service.impl;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xcong.excoin.common.response.Result;
import com.xcong.excoin.modules.platform.dao.PlatformCnyUsdtExchangeDao;
import com.xcong.excoin.modules.platform.dao.PlatformPaymentMethodDao;
import com.xcong.excoin.modules.platform.entity.PlatformCnyUsdtExchangeEntity;
import com.xcong.excoin.modules.platform.entity.PlatformPaymentMethodEntity;
import com.xcong.excoin.modules.platform.service.PlatformPaymentMethodService;
@Service
public class PlatformPaymentMethodServiceImpl extends ServiceImpl<PlatformPaymentMethodDao, PlatformPaymentMethodEntity> implements PlatformPaymentMethodService{
    @Resource
    PlatformCnyUsdtExchangeDao platformCnyUsdtExchangeDao;
    @Override
    public Result findUsdtCnyExchange(String type) {
        // 查询当前兑换价格
        Map<String, Object> map = new HashMap<String, Object>();
        PlatformCnyUsdtExchangeEntity platformCnyUsdtExchangeEntity = platformCnyUsdtExchangeDao.selectById(1);
        BigDecimal cnyUsdt = platformCnyUsdtExchangeEntity.getValue();
        if ("B".equals(type)) {
            // 买的时候提高价格
            map.put("exchange", cnyUsdt.add(platformCnyUsdtExchangeEntity.getDiff()));
        }else {
            // 卖的时候降低
            map.put("exchange", cnyUsdt.subtract(platformCnyUsdtExchangeEntity.getDiff()));
        }
        return Result.ok(map);
    }
}
src/main/java/com/xcong/excoin/modules/platform/vo/PlatformCnyUsdtExchangeVo.java
New file
@@ -0,0 +1,13 @@
package com.xcong.excoin.modules.platform.vo;
import java.math.BigDecimal;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel(value = "会员快捷买入卖出", description = "会员快捷买入卖出类")
public class PlatformCnyUsdtExchangeVo {
}
src/main/java/com/xcong/excoin/rabbit/consumer/TestConsumer.java
New file
@@ -0,0 +1,21 @@
package com.xcong.excoin.rabbit.consumer;
import com.xcong.excoin.configurations.RabbitMqConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
/**
 * @author wzy
 * @date 2020-05-25
 **/
@Slf4j
@Component
public class TestConsumer {
    @RabbitListener(queues = RabbitMqConfig.QUEUE_TEST)
    public void doSomething(String content) {
        log.info("#---->{}#", content);
    }
}
src/main/java/com/xcong/excoin/rabbit/producer/TestProducer.java
New file
@@ -0,0 +1,42 @@
package com.xcong.excoin.rabbit.producer;
import cn.hutool.core.util.IdUtil;
import com.xcong.excoin.configurations.RabbitMqConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
 * @author wzy
 * @date 2020-05-25
 **/
@Slf4j
@Component
public class TestProducer implements RabbitTemplate.ConfirmCallback {
    private RabbitTemplate rabbitTemplate;
    @Autowired
    public TestProducer(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
        rabbitTemplate.setConfirmCallback(this);
    }
    public void sendTestMsg(String content) {
        CorrelationData correlationData = new CorrelationData(IdUtil.simpleUUID());
        rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_ONE, RabbitMqConfig.ROUTING_KEY_TEST, content, correlationData);
    }
    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        log.info("#----->{}#", correlationData);
        if (ack) {
            log.info("success");
        } else {
            log.info("--->{}", cause);
        }
    }
}
src/main/resources/application.yml
@@ -69,6 +69,21 @@
        min-idle: 8
    ## 连接超时时间(毫秒)
    timeout: 30000
  rabbitmq:
    host: 120.27.238.55
    port: 5672
    username: ct_rabbit
    password: 123456
    publisher-confirm-type: correlated
#custom:
#  rabbitmq:
#    host: 120.27.238.55
#    port: 5672
#    username: ct_rabbit
#    password: 123456
mybatis-plus:
  mapper-locations: classpath:mapper/**/*.xml
src/main/resources/mapper/home/MemberPaymentMethodDao.xml
New file
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
    namespace="com.xcong.excoin.modules.home.dao.MemberPaymentMethodDao">
    <!-- 字段sql -->
    <select id="selectByMemberId" resultType="com.xcong.excoin.modules.home.entity.MemberPaymentMethodEntity">
        SELECT a.* FROM member_payment_method a WHERE a.member_id = #{memberId}
    </select>
</mapper>
src/main/resources/mapper/home/MemberQuickBuySaleDao.xml
@@ -2,5 +2,8 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
    namespace="com.xcong.excoin.modules.home.dao.MemberQuickBuySaleDao">
    <!-- 字段sql -->
    <select id="selectByIdAndMemberId" resultType="com.xcong.excoin.modules.home.entity.MemberQuickBuySaleEntity">
        SELECT a.* FROM member_quick_buy_sale a WHERE a.id = #{id} AND a.member_id = #{memberId}
    </select>
</mapper>
src/main/resources/mapper/member/MemberWalletCoinDao.xml
@@ -9,6 +9,17 @@
    <select id="selectWalletCoinBymIdAndCode" resultType="com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity">
        select * from member_wallet_coin where member_id = #{memberId} and wallet_code = #{walletCode}
    </select>
    <update id="updateFrozenBalance" parameterType="map">
        UPDATE member_wallet_coin
        SET available_balance = available_balance - #{amount},
             frozen_balance = frozen_balance + #{amount}
        WHERE
            id = #{id}
        AND member_id = #{memberId}
    </update>
src/test/java/com/xcong/excoin/RSATest.java
@@ -13,6 +13,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.math.BigDecimal;
import java.security.KeyPair;
/**
@@ -101,4 +102,10 @@
        String md5str = SecureUtil.md5("123456");
        log.info("{}", md5str);
    }
    @Test
    public void bigdecimalTest() {
        BigDecimal bigDecimal = new BigDecimal("123.12345678").setScale(4, BigDecimal.ROUND_DOWN);
        log.info("--->{}", bigDecimal);
    }
}
src/test/java/com/xcong/excoin/RabbitMqTest.java
New file
@@ -0,0 +1,24 @@
package com.xcong.excoin;
import com.xcong.excoin.rabbit.producer.TestProducer;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource;
/**
 * @author wzy
 * @date 2020-05-25
 **/
@SpringBootTest
public class RabbitMqTest {
    @Autowired
    private TestProducer testProducer;
    @Test
    public void sendTestMsg() {
        testProducer.sendTestMsg("this is test msg");
    }
}