Helius
2020-05-28 d775bb5dacca4c6ff33c65a0cb891f5992cc1bed
同步k线、最新价、人民币美元汇率、homesymbols接口
2 files deleted
2 files renamed
19 files modified
6 files added
598 ■■■■ changed files
src/main/java/com/xcong/excoin/ExcoinApplication.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/common/contants/AppContants.java 12 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/entity/CnyUsdtExchange.java 27 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java 17 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/service/impl/OrderCoinServiceImpl.java 8 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/contract/controller/ContractEntrustOrderController.java 21 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/contract/dao/ContractEntrustOrderDao.java 3 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/contract/entity/ContractEntrustOrderEntity.java 14 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/contract/mapper/ContractEntrustOrderEntityMapper.java 18 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/contract/service/ContractEntrustOrderService.java 4 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractEntrustOrderServiceImpl.java 53 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/platform/dao/CnyUsdtExchangeDao.java 12 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/platform/dao/PlatformCnyUsdtExchangeDao.java 5 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/platform/entity/PlatformSymbolsSkuEntity.java 4 ●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/platform/service/impl/PlatformCnyUsdtExchangeServiceImpl.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/symbols/controller/SymbolsController.java 33 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/symbols/dao/PlatformSymbolsContractDao.java 6 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/symbols/entity/PlatformSymbolsContractEntity.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/symbols/parameter/vo/HomeSymbolsVo.java 31 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/symbols/service/SymbolsService.java 4 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/symbols/service/impl/SymbolsServiceImpl.java 65 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/quartz/job/KlineDataUpdateJob.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/quartz/job/NewestPriceUpdateJob.java 65 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/quartz/job/UsdtCnyExchangePriceUpdateJob.java 65 ●●●●● patch | view | raw | blame | history
src/main/resources/application-test.yml 102 ●●●●● patch | view | raw | blame | history
src/main/resources/application.yml 8 ●●●●● patch | view | raw | blame | history
src/main/resources/mapper/contract/ContractEntrustOrderDao.xml 5 ●●●●● patch | view | raw | blame | history
src/main/resources/mapper/platform/PlatformCnyUsdtExchangeDao.xml 4 ●●●● patch | view | raw | blame | history
src/main/resources/mapper/platform/PlatformSymbolsContractDao.xml 4 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/ExcoinApplication.java
@@ -3,11 +3,13 @@
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
 * @author helius
 */
@EnableScheduling
@EnableSwagger2
@SpringBootApplication
@MapperScan("com.xcong.excoin.modules.*.dao")
src/main/java/com/xcong/excoin/common/contants/AppContants.java
@@ -47,6 +47,16 @@
    /**
     * 初始化金额
     */
    public static final BigDecimal INIT_MONEY = new BigDecimal(0.000000);
    public static final BigDecimal INIT_MONEY = BigDecimal.ZERO;
    /**
     * homeSymbols 接口状态值 币币
     */
    public static final int HOME_SYMBOLS_COIN = 1;
    /**
     * homeSymbols 接口状态值 合约
     */
    public static final int HOME_SYMBOLS_CONTRACT = 2;
}
src/main/java/com/xcong/excoin/modules/coin/entity/CnyUsdtExchange.java
File was deleted
src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java
@@ -5,6 +5,7 @@
import java.util.List;
import javax.annotation.Resource;
import com.xcong.excoin.modules.platform.entity.PlatformCnyUsdtExchangeEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -13,7 +14,6 @@
import com.xcong.excoin.common.enumerates.MemberWalletCoinEnum;
import com.xcong.excoin.common.response.Result;
import com.xcong.excoin.modules.coin.dao.MemberAccountMoneyChangeDao;
import com.xcong.excoin.modules.coin.entity.CnyUsdtExchange;
import com.xcong.excoin.modules.coin.entity.MemberAccountMoneyChange;
import com.xcong.excoin.modules.coin.parameter.vo.MemberAccountMoneyChangeInfoVo;
import com.xcong.excoin.modules.coin.parameter.vo.MemberWalletAgentInfoVo;
@@ -27,7 +27,7 @@
import com.xcong.excoin.modules.member.entity.MemberWalletAgentEntity;
import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity;
import com.xcong.excoin.modules.member.entity.MemberWalletContractEntity;
import com.xcong.excoin.modules.platform.dao.CnyUsdtExchangeDao;
import com.xcong.excoin.modules.platform.dao.PlatformCnyUsdtExchangeDao;
import com.xcong.excoin.utils.MessageSourceUtils;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
@@ -39,7 +39,7 @@
    //@Resource
    //SymbolsService symbolsService;
    @Resource
    CnyUsdtExchangeDao cnyUsdtExchangeDao;
    PlatformCnyUsdtExchangeDao cnyUsdtExchangeDao;
    @Resource
    MemberWalletCoinDao memberWalletCoinDao;
    @Resource
@@ -54,7 +54,7 @@
    public Result getWalletCoin() {
            //获取用户ID
            Long memberId = LoginUserUtils.getAppLoginUser().getId();
            CnyUsdtExchange cnyUsdtExchange =cnyUsdtExchangeDao.getCNYAndUSDTOne();
        PlatformCnyUsdtExchangeEntity cnyUsdtExchange = cnyUsdtExchangeDao.getCNYAndUSDTOne();
            BigDecimal cnyUsdt = cnyUsdtExchange.getValue();
            
            BigDecimal totalUsdts = BigDecimal.ZERO;
@@ -125,7 +125,8 @@
                MemberWalletCoinVo memberWalletCoinVo = new MemberWalletCoinVo();
                memberWalletCoinVo.setTotalUsdt(totalUsdts.setScale(4, BigDecimal.ROUND_DOWN));
                memberWalletCoinVo.setTotalCny(totalUsdts.multiply(cnyUsdt).setScale(4, BigDecimal.ROUND_DOWN));
                memberWalletCoinVo.setMemberWalletCoinInfoVo(memberWalletCoinlist);;
            memberWalletCoinVo.setMemberWalletCoinInfoVo(memberWalletCoinlist);
            ;
                return Result.ok(memberWalletCoinVo);
            }
    }
@@ -141,7 +142,7 @@
            memberWalletCoinInfoVo.setMemberId(memberId);
            memberWalletCoinInfoVo.setWalletCode(symbol);
            if(!StrUtil.isEmpty(memberId.toString())) {
                CnyUsdtExchange cnyUsdtExchange =cnyUsdtExchangeDao.getCNYAndUSDTOne();
            PlatformCnyUsdtExchangeEntity cnyUsdtExchange = cnyUsdtExchangeDao.getCNYAndUSDTOne();
                BigDecimal cnyUsdt = cnyUsdtExchange.getValue();
                BigDecimal total = walletCoin.getAvailableBalance().add(walletCoin.getFrozenBalance());
                
@@ -163,7 +164,7 @@
            //获取用户ID
            Long memberId = LoginUserUtils.getAppLoginUser().getId();
            
            CnyUsdtExchange cnyUsdtExchange =cnyUsdtExchangeDao.getCNYAndUSDTOne();
        PlatformCnyUsdtExchangeEntity cnyUsdtExchange = cnyUsdtExchangeDao.getCNYAndUSDTOne();
            BigDecimal cnyUsdt = cnyUsdtExchange.getValue();
            
            String walletCode = MemberWalletCoinEnum.WALLETCOINCODE.getValue();
@@ -500,7 +501,7 @@
        MemberWalletAgentEntity walletAgent = memberWalletAgentDao.selectWalletAgentBymIdAndCode(memberId, walletCode);
        BigDecimal availableBalance = walletAgent.getAvailableBalance();
        
        CnyUsdtExchange cnyUsdtExchange =cnyUsdtExchangeDao.getCNYAndUSDTOne();
        PlatformCnyUsdtExchangeEntity cnyUsdtExchange = cnyUsdtExchangeDao.getCNYAndUSDTOne();
        BigDecimal cnyUsdt = cnyUsdtExchange.getValue();
        BigDecimal multiply = availableBalance.multiply(cnyUsdt);
        
src/main/java/com/xcong/excoin/modules/coin/service/impl/OrderCoinServiceImpl.java
@@ -12,6 +12,7 @@
import javax.annotation.Resource;
import com.xcong.excoin.modules.platform.entity.PlatformCnyUsdtExchangeEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -23,7 +24,6 @@
import com.xcong.excoin.modules.coin.dao.MemberSelectSymbolsDao;
import com.xcong.excoin.modules.coin.dao.OrderCoinDealDao;
import com.xcong.excoin.modules.coin.dao.OrderCoinsDao;
import com.xcong.excoin.modules.coin.entity.CnyUsdtExchange;
import com.xcong.excoin.modules.coin.entity.MemberAccountFlowEntity;
import com.xcong.excoin.modules.coin.entity.OrderCoinsDealEntity;
import com.xcong.excoin.modules.coin.entity.OrderCoinsEntity;
@@ -39,7 +39,7 @@
import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao;
import com.xcong.excoin.modules.member.entity.MemberSelectSymbolsEntity;
import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity;
import com.xcong.excoin.modules.platform.dao.CnyUsdtExchangeDao;
import com.xcong.excoin.modules.platform.dao.PlatformCnyUsdtExchangeDao;
import com.xcong.excoin.modules.platform.dao.TradeSettingDao;
import com.xcong.excoin.modules.platform.entity.PlatformTradeSettingEntity;
import com.xcong.excoin.utils.MessageSourceUtils;
@@ -59,7 +59,7 @@
    @Resource
    MemberSelectSymbolsDao memberSelectSymbolsDao;
    @Resource
    CnyUsdtExchangeDao cnyUsdtExchangeDao;
    PlatformCnyUsdtExchangeDao cnyUsdtExchangeDao;
    @Resource
    OrderCoinsDao orderCoinsDao;
    @Resource
@@ -118,7 +118,7 @@
        
        List<MemberSelectSymbolsEntity> memSymbols = memberSelectSymbolsDao.selectSymbolByMemIdAndSymbol(memberId, symbol);
        
        CnyUsdtExchange cnyUsdtExchange = cnyUsdtExchangeDao.getCNYAndUSDTOne();
        PlatformCnyUsdtExchangeEntity cnyUsdtExchange = cnyUsdtExchangeDao.getCNYAndUSDTOne();
        BigDecimal cnyUsdt = cnyUsdtExchange.getValue();
        TransactionPageOfWalletCoinVo transactionPageOfWalletCoinVo = new TransactionPageOfWalletCoinVo();
        //是否自选
src/main/java/com/xcong/excoin/modules/contract/controller/ContractEntrustOrderController.java
@@ -9,12 +9,10 @@
import com.xcong.excoin.utils.api.response.Symbol;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@@ -44,6 +42,19 @@
            return Result.fail("非法类型");
        }
        return Result.ok("123");
        return contractEntrustOrderService.addContractEntrustOrder(submitEntrustDto);
    }
    @ApiOperation(value = "获取当前委托单列表", notes = "获取当前委托单列表")
    @GetMapping(value = "/findCurrentEntrustOrderList")
    public Result findCurrentEntrustOrderList() {
        return null;
    }
    @ApiOperation(value = "撤销委托单", notes = "撤销委托单")
    @GetMapping(value = "/cancelEntrustOrder")
    public Result cancelEntrustOrder(@ApiParam(name = "id", value="委托单ID", required = true, example = "1") Long id) {
        return null;
    }
}
src/main/java/com/xcong/excoin/modules/contract/dao/ContractEntrustOrderDao.java
@@ -2,9 +2,12 @@
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xcong.excoin.modules.contract.entity.ContractEntrustOrderEntity;
import org.apache.ibatis.annotations.Param;
/**
 * @author helius
 */
public interface ContractEntrustOrderDao extends BaseMapper<ContractEntrustOrderEntity> {
    public ContractEntrustOrderEntity selectEntrustOrderByIdAndMemberId(@Param("id") Long id, @Param("memberId") Long memberId);
}
src/main/java/com/xcong/excoin/modules/contract/entity/ContractEntrustOrderEntity.java
@@ -23,6 +23,16 @@
    public static final int ENTRUST_TYPE_CLOSE_LESS = 4;
    /**
     * 逐仓
     */
    public static final int POSITION_TYPE_ADD = 1;
    /**
     * 全仓
     */
    public static final int POSITION_TYPE_ALL = 2;
    /**
     * 会员ID
@@ -62,12 +72,12 @@
    /**
     * 币种规格
     */
    private Long symbolSku;
    private BigDecimal symbolSku;
    /**
     * 杠杆倍率
     */
    private int leverRatio;
    private BigDecimal leverRatio;
    /**
     * 保证金
src/main/java/com/xcong/excoin/modules/contract/mapper/ContractEntrustOrderEntityMapper.java
New file
@@ -0,0 +1,18 @@
package com.xcong.excoin.modules.contract.mapper;
import com.xcong.excoin.modules.contract.entity.ContractEntrustOrderEntity;
import com.xcong.excoin.modules.contract.parameter.dto.SubmitEntrustDto;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
/**
 * @author wzy
 * @date 2020-05-28
 **/
@Mapper
public abstract class ContractEntrustOrderEntityMapper {
    public static final ContractEntrustOrderEntityMapper INSTANCE = Mappers.getMapper(ContractEntrustOrderEntityMapper.class);
    public abstract ContractEntrustOrderEntity submitEntrustDtoToEntity(SubmitEntrustDto dto);
}
src/main/java/com/xcong/excoin/modules/contract/service/ContractEntrustOrderService.java
@@ -11,4 +11,8 @@
public interface ContractEntrustOrderService extends IService<ContractEntrustOrderEntity> {
    public Result addContractEntrustOrder(SubmitEntrustDto submitEntrustDto);
    public Result findEntrustOrderList();
    public Result cancelEntrustOrder(Long id);
}
src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractEntrustOrderServiceImpl.java
@@ -4,7 +4,9 @@
import com.xcong.excoin.common.LoginUserUtils;
import com.xcong.excoin.common.response.Result;
import com.xcong.excoin.modules.contract.dao.ContractEntrustOrderDao;
import com.xcong.excoin.modules.contract.dao.ContractOrderDao;
import com.xcong.excoin.modules.contract.entity.ContractEntrustOrderEntity;
import com.xcong.excoin.modules.contract.mapper.ContractEntrustOrderEntityMapper;
import com.xcong.excoin.modules.contract.parameter.dto.SubmitEntrustDto;
import com.xcong.excoin.modules.contract.service.ContractEntrustOrderService;
import com.xcong.excoin.modules.member.dao.MemberWalletContractDao;
@@ -15,6 +17,7 @@
import com.xcong.excoin.utils.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
@@ -39,13 +42,16 @@
    @Resource
    private CacheSettingUtils cacheSettingUtils;
    @Resource
    private ContractOrderDao contractOrderDao;
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result addContractEntrustOrder(SubmitEntrustDto submitEntrustDto) {
        MemberEntity memberEntity = LoginUserUtils.getAppLoginUser();
        // 获取最新价
        BigDecimal newPirce  = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(submitEntrustDto.getSymbol())));
        // 委托开仓
        if (submitEntrustDto.getEntrustType() == ContractEntrustOrderEntity.ENTRUST_TYPE_OPEN_MORE || submitEntrustDto.getEntrustType() == ContractEntrustOrderEntity.ENTRUST_TYPE_OPEN_LESS) {
@@ -67,21 +73,60 @@
            // 委托总额
            BigDecimal entrustTotalAmount = submitEntrustDto.getEntrustPrice().multiply(BigDecimal.valueOf(submitEntrustDto.getSymbolCnt()));
            if (entrustTotalAmount.compareTo(walletContract.getAvailableBalance()) > -1) {
            BigDecimal lotNumber = cacheSettingUtils.getSymbolSku(submitEntrustDto.getSymbol());
            // 保证金计算 -- 建仓价X规格X手数X(1/杠杆倍率)
            BigDecimal bondAmount = entrustTotalAmount.multiply(lotNumber).multiply((BigDecimal.ONE.divide(BigDecimal.valueOf(submitEntrustDto.getLeverRatio()), 8, BigDecimal.ROUND_DOWN)));
            if (entrustTotalAmount.add(bondAmount).compareTo(walletContract.getAvailableBalance()) > -1) {
                return Result.fail("可用余额不足");
            }
            BigDecimal lotNumber = cacheSettingUtils.getSymbolSku(submitEntrustDto.getSymbol());
            ContractEntrustOrderEntityMapper convert = ContractEntrustOrderEntityMapper.INSTANCE;
            ContractEntrustOrderEntity entrustOrderEntity = convert.submitEntrustDtoToEntity(submitEntrustDto);
            entrustOrderEntity.setMemberId(memberEntity.getId());
            entrustOrderEntity.setBondAmount(bondAmount);
            entrustOrderEntity.setSymbolSku(lotNumber);
            // 暂默认逐仓
            entrustOrderEntity.setPositionType(ContractEntrustOrderEntity.POSITION_TYPE_ADD);
            int i = contractEntrustOrderDao.insert(entrustOrderEntity);
            walletContract.setFrozenBalance(walletContract.getFrozenBalance().add(entrustTotalAmount.add(bondAmount)));
            walletContract.setAvailableBalance(walletContract.getAvailableBalance().subtract(entrustTotalAmount.add(bondAmount)));
            memberWalletContractDao.updateById(walletContract);
            if (i > 0) {
                return Result.ok("委托成功");
            } else {
                return Result.fail("委托失败");
            }
        }
        // 委托平仓 (全仓模式)
        if (submitEntrustDto.getEntrustType() == ContractEntrustOrderEntity.ENTRUST_TYPE_CLOSE_MORE || submitEntrustDto.getEntrustType() == ContractEntrustOrderEntity.ENTRUST_TYPE_CLOSE_LESS) {
            return Result.fail("功能暂未开放,敬请期待");
        }
        return Result.fail("未知错误");
    }
    @Override
    public Result findEntrustOrderList() {
        return null;
    }
    @Override
    public Result cancelEntrustOrder(Long id) {
        MemberEntity memberEntity = LoginUserUtils.getAppLoginUser();
        // 查询该委托单是否为该用户所有
        ContractEntrustOrderEntity entrustOrderEntity = contractEntrustOrderDao.selectEntrustOrderByIdAndMemberId(id, memberEntity.getId());
        if (entrustOrderEntity == null) {
            return Result.fail("该委托单不存在");
        }
        return null;
    }
}
src/main/java/com/xcong/excoin/modules/platform/dao/CnyUsdtExchangeDao.java
File was deleted
src/main/java/com/xcong/excoin/modules/platform/dao/PlatformCnyUsdtExchangeDao.java
@@ -3,7 +3,12 @@
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xcong.excoin.modules.platform.entity.PlatformCnyUsdtExchangeEntity;
import java.math.BigDecimal;
public interface PlatformCnyUsdtExchangeDao extends BaseMapper<PlatformCnyUsdtExchangeEntity> {
    PlatformCnyUsdtExchangeEntity getCNYAndUSDTOne();
    void updateUsdt(BigDecimal value);
    
}
src/main/java/com/xcong/excoin/modules/platform/entity/PlatformSymbolsSkuEntity.java
@@ -1,6 +1,7 @@
package com.xcong.excoin.modules.platform.entity;
import java.io.Serializable;
import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
@@ -10,6 +11,7 @@
/**
 * 币种规格表
 * @author helius
 */
@Data
@TableName("platform_symbols_sku")
@@ -27,6 +29,6 @@
    /**
     * 规格
     */
    private String lotnumber;
    private BigDecimal lotnumber;
}
src/main/java/com/xcong/excoin/modules/platform/service/impl/PlatformCnyUsdtExchangeServiceImpl.java
@@ -6,11 +6,11 @@
import javax.annotation.Resource;
import com.xcong.excoin.modules.platform.dao.PlatformCnyUsdtExchangeDao;
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;
src/main/java/com/xcong/excoin/modules/symbols/controller/SymbolsController.java
New file
@@ -0,0 +1,33 @@
package com.xcong.excoin.modules.symbols.controller;
import com.xcong.excoin.common.response.Result;
import com.xcong.excoin.modules.symbols.service.SymbolsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
 * @author wzy
 * @date 2020-05-28
 **/
@Api(value = "币种相关轮询接口类", tags = "币种相关轮询接口类")
@Slf4j
@RestController
@RequestMapping(value = "/api/symbols")
public class SymbolsController {
    @Resource
    private SymbolsService symbolsService;
    @ApiOperation(value = "轮询获取app首页币种交易信息", notes = "轮询获取app首页币种交易信息")
    @GetMapping(value = "/homeSymbols")
    public Result homeSymbols(Integer type) {
        return symbolsService.homeSymbols(type);
    }
}
src/main/java/com/xcong/excoin/modules/symbols/dao/PlatformSymbolsContractDao.java
@@ -1,11 +1,15 @@
package com.xcong.excoin.modules.symbols.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xcong.excoin.modules.symbols.Entity.PlatformSymbolsContractEntity;
import com.xcong.excoin.modules.symbols.entity.PlatformSymbolsContractEntity;
import java.util.List;
/**
 *
 * @author wzy
 */
public interface PlatformSymbolsContractDao extends BaseMapper<PlatformSymbolsContractEntity> {
    List<PlatformSymbolsContractEntity> selectAllContractSymbols();
}
src/main/java/com/xcong/excoin/modules/symbols/entity/PlatformSymbolsContractEntity.java
File was renamed from src/main/java/com/xcong/excoin/modules/symbols/Entity/PlatformSymbolsContractEntity.java
@@ -1,4 +1,4 @@
package com.xcong.excoin.modules.symbols.Entity;
package com.xcong.excoin.modules.symbols.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
src/main/java/com/xcong/excoin/modules/symbols/parameter/vo/HomeSymbolsVo.java
New file
@@ -0,0 +1,31 @@
package com.xcong.excoin.modules.symbols.parameter.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
/**
 * @author wzy
 * @date 2020-05-28
 **/
@Data
@ApiModel(value = "HomeSymbolsVo", description = "首页币种行情返回类")
public class HomeSymbolsVo {
    @ApiModelProperty(value = "币种")
    private String symbol;
    @ApiModelProperty("当前价")
    private BigDecimal currentPrice;
    @ApiModelProperty("对应人民币转换")
    private BigDecimal cnyPrice;
    @ApiModelProperty("成交量")
    private BigDecimal volume;
    @ApiModelProperty("涨跌幅")
    private BigDecimal upOrDown;
}
src/main/java/com/xcong/excoin/modules/symbols/service/SymbolsService.java
@@ -1,6 +1,8 @@
package com.xcong.excoin.modules.symbols.service;
import com.xcong.excoin.common.response.Result;
/**
 * @author wzy
 * @date 2020-05-26
@@ -9,4 +11,6 @@
    public void updateSymbolsKine(String time);
    public Result homeSymbols(Integer type);
}
src/main/java/com/xcong/excoin/modules/symbols/service/impl/SymbolsServiceImpl.java
@@ -2,8 +2,14 @@
import com.alibaba.fastjson.JSONObject;
import com.huobi.client.model.Candlestick;
import com.xcong.excoin.common.contants.AppContants;
import com.xcong.excoin.common.enumerates.SymbolEnum;
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.symbols.parameter.vo.HomeSymbolsVo;
import com.xcong.excoin.modules.symbols.service.SymbolsService;
import com.xcong.excoin.utils.CoinTypeConvert;
import com.xcong.excoin.utils.RedisUtils;
import com.xcong.excoin.utils.api.ApiClient;
import com.xcong.excoin.utils.api.response.Kline;
@@ -26,6 +32,9 @@
    @Resource
    private RedisUtils redisUtils;
    @Resource
    private PlatformCnyUsdtExchangeDao platformCnyUsdtExchangeDao;
    private static final String API_KEY = "3938f004-bfe31905-f7581c1a-6abe0";
    private static final String API_SECRET = "a0f7a154-ghxertfvbf-6ce2d90c-a0bab";
@@ -50,11 +59,14 @@
        synchronized (this) {
            //更新币币交易K线历史数据
            for (SymbolEnum symbol : SymbolEnum.values()) {
                log.info(symbol.getValue());
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                String[] symbols = symbol.getValue().toLowerCase().split("/");
                ApiClient client = new ApiClient(API_KEY, API_SECRET);
                ApiClient client = getClient();
                KlineResponse kline = client.kline(symbols[0] + symbols[1], time, 1000 + "");
                log.info("{}", JSONObject.toJSONString(kline));
                if (kline != null) {
                    if ("ok".equalsIgnoreCase(kline.getStatus())) {
                        List<Kline> klines = (List<Kline>) kline.data;
@@ -74,11 +86,56 @@
                        }
                        if (klines.size() > 0) {
//                            redisUtils.set("KINE_" + symbol.getValue() + "_" + time, list);
                            redisUtils.set("KINE_" + symbol.getValue() + "_" + time, list);
                        }
                    }
                }
            }
        }
    }
    @Override
    public Result homeSymbols(Integer type) {
        List<HomeSymbolsVo> list = new ArrayList<>();
        // 币币行情
        if (AppContants.HOME_SYMBOLS_COIN == type) {
            for (SymbolEnum symbolEnum : SymbolEnum.values()) {
                list.add(getSymbolReturnData(symbolEnum.getName()));
            }
            // 合约行情
        } else if (AppContants.HOME_SYMBOLS_CONTRACT == type) {
            for (SymbolEnum symbolEnum : SymbolEnum.values()) {
                list.add(getSymbolReturnData(symbolEnum.getName()));
            }
            // 自选行情
        } else {
        }
        return Result.ok(list);
    }
    public HomeSymbolsVo getSymbolReturnData(String symbol) {
        PlatformCnyUsdtExchangeEntity cnyUsdtExchange = platformCnyUsdtExchangeDao.getCNYAndUSDTOne();
        // 获取当日k线数据
        Candlestick symbolObject = (Candlestick) redisUtils.get(symbol);
        // 获取当前币种最新价
        BigDecimal newestPrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(symbol)));
        // 获取当日k线的开盘价
        BigDecimal openPrice = symbolObject.getOpen();
        BigDecimal upOrDown = newestPrice.subtract(openPrice).divide(openPrice, 8, BigDecimal.ROUND_HALF_UP);
        HomeSymbolsVo homeSymbolsVo = new HomeSymbolsVo();
        homeSymbolsVo.setSymbol(symbol);
        homeSymbolsVo.setCurrentPrice(newestPrice);
        homeSymbolsVo.setUpOrDown(upOrDown);
        homeSymbolsVo.setVolume(symbolObject.getVolume());
        if (cnyUsdtExchange != null) {
            BigDecimal cnyPrice = openPrice.multiply(cnyUsdtExchange.getValue()).setScale(2, BigDecimal.ROUND_HALF_UP);
            homeSymbolsVo.setCnyPrice(cnyPrice);
        }
        return homeSymbolsVo;
    }
}
src/main/java/com/xcong/excoin/quartz/job/KlineDataUpdateJob.java
@@ -1,6 +1,7 @@
package com.xcong.excoin.quartz.job;
import com.xcong.excoin.modules.symbols.service.SymbolsService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -13,6 +14,7 @@
 * @date 2020-05-26
 **/
@Component
@ConditionalOnProperty(prefix = "app", name = "kline-update-job", havingValue = "true")
public class KlineDataUpdateJob {
    @Resource
src/main/java/com/xcong/excoin/quartz/job/NewestPriceUpdateJob.java
New file
@@ -0,0 +1,65 @@
package com.xcong.excoin.quartz.job;
import com.huobi.client.SubscriptionClient;
import com.huobi.client.SubscriptionOptions;
import com.huobi.client.model.Candlestick;
import com.huobi.client.model.enums.CandlestickInterval;
import com.xcong.excoin.modules.symbols.service.SymbolsService;
import com.xcong.excoin.utils.CoinTypeConvert;
import com.xcong.excoin.utils.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
/**
 * 最新价更新
 *
 * @author wzy
 * @date 2020-05-28
 **/
@Slf4j
@Component
@ConditionalOnProperty(prefix = "app", name = "newest-price-update-job", havingValue = "true")
public class NewestPriceUpdateJob {
    @Resource
    private RedisUtils redisUtils;
    @Resource
    private SymbolsService symbolsService;
    @PostConstruct
    public void initNewestPrice() {
        log.info("#=======价格更新开启=======#");
        SubscriptionOptions subscriptionOptions = new SubscriptionOptions();
        subscriptionOptions.setConnectionDelayOnFailure(5);
        subscriptionOptions.setUri("wss://api.hadax.com/ws");
        SubscriptionClient subscriptionClient = SubscriptionClient.create("", "", subscriptionOptions);
        subscriptionClient.subscribeTradeEvent("btcusdt,ethusdt,xrpusdt,ltcusdt,bchusdt,eosusdt,etcusdt", tradeEvent -> {
            String symbol = tradeEvent.getSymbol();
            // 根据symbol判断做什么操作
            symbol = CoinTypeConvert.convert(symbol);
            if (null != symbol) {
                String price = tradeEvent.getTradeList().get(0).getPrice().toPlainString();
                // TODO 测试环境关闭这个插入redis
                redisUtils.set(CoinTypeConvert.convertToKey(symbol), price);
                // 比较
//                websocketPriceService.comparePriceAsc(symbol, price);
//                websocketPriceService.comparePriceDesc(symbol, price);
                //System.out.println("比较完毕:"+symbol+"-"+price);
            }
        });
        subscriptionClient.subscribeCandlestickEvent("btcusdt,ethusdt,eosusdt,etcusdt,ltcusdt,bchusdt,xrpusdt", CandlestickInterval.DAY1, (candlestickEvent) -> {
            Candlestick data = candlestickEvent.getData();
            redisUtils.set(CoinTypeConvert.convert(candlestickEvent.getSymbol()), data);
        });
    }
}
src/main/java/com/xcong/excoin/quartz/job/UsdtCnyExchangePriceUpdateJob.java
New file
@@ -0,0 +1,65 @@
package com.xcong.excoin.quartz.job;
import com.alibaba.fastjson.JSONObject;
import com.xcong.excoin.modules.platform.dao.PlatformCnyUsdtExchangeDao;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.URL;
/**
 * 美元-人民币汇率定时任务
 *
 * @author wzy
 * @date 2020-05-28
 **/
@Component
@ConditionalOnProperty(prefix = "app", name = "other-job", havingValue = "true")
public class UsdtCnyExchangePriceUpdateJob {
    @Resource
    private PlatformCnyUsdtExchangeDao cnyUsdtExchangeDao;
    @Scheduled(cron = "0 */5 * * * ? ")
    public void updateUsdtCnyExchange() {
        BufferedReader reader = null;
        String result = null;
        StringBuffer sbf = new StringBuffer();
        // 模拟浏览器
        String userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36";
        try {
            URL url = new URL("https://otc-api-hk.eiijo.cn/v1/data/config/purchase-price?coinId=2&currencyId=1&matchType=0");
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.setReadTimeout(30000);
            connection.setConnectTimeout(30000);
            connection.setRequestProperty("User-agent", userAgent);
            connection.connect();
            InputStream is = connection.getInputStream();
            reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            String strRead = null;
            while ((strRead = reader.readLine()) != null) {
                sbf.append(strRead);
                sbf.append("\r\n");
            }
            reader.close();
            result = sbf.toString();
            JSONObject jsonObject = (JSONObject) JSONObject.parse(result);
            String code = jsonObject.getString("code");
            if ("200".equals(code)) {
                JSONObject jsonData = (JSONObject) jsonObject.get("data");
                cnyUsdtExchangeDao.updateUsdt(BigDecimal.valueOf(jsonData.getDouble("price")));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
src/main/resources/application-test.yml
New file
@@ -0,0 +1,102 @@
server:
  port: 8888
  servlet:
    context-path: /
spring:
  profiles:
    active: dev
  datasource:
    url: jdbc:mysql://120.27.238.55:3306/kss_framework?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2b8
    username: ct_test
    password: 123456
    driver-class-name: com.mysql.jdbc.Driver
    type: com.alibaba.druid.pool.DruidDataSource
    druid:
      initial-size: ${spring_datasource_druid_initial_size:10}
      max-active: ${spring_datasource_druid_max_active:20}
      min-idle: ${spring_datasource_druid_min_idle:3}
      #配置获取连接等待超时的时间
      max-wait: 60000
      pool-prepared-statements: true
      max-pool-prepared-statement-per-connection-size: 20
      validation-query: SELECT 'x'
      test-on-borrow: true
      test-on-return: true
      test-while-idle: true
      #配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
      time-between-eviction-runs-millis: 60000
      #配置一个连接在池中最小生存的时间,单位是毫秒
      min-evictable-idle-time-millis: 300000
      #spring.datasource.druid.max-evguide.ftlictable-idle-time-millis=
      filters: stat,wall
      stat-view-servlet:
        # 默认true 内置监控页面首页/druid/index.html
        enabled: true
        url-pattern: /druid/*
        # 允许清空统计数据
        reset-enable: true
        login-username: root
        login-password: 123456
        # IP白名单 多个逗号分隔
        allow: ${spring_datasource_stat_view_servlet_allow:}
        # IP黑名单
        deny: ${spring_datasource_stat_view_servlet_deny:}
  ## 国际化配置
  messages:
    basename: i18n/messages
  ## redis配置
  redis:
    ## Redis数据库索引(默认为0)
    database: 1
    ## Redis服务器地址
    host: 47.114.114.219
    ## Redis服务器连接端口
    port: 6379
    ## Redis服务器连接密码(默认为空)
    password: biyi123
    jedis:
      pool:
        ## 连接池最大连接数(使用负值表示没有限制)
        #spring.redis.pool.max-active=8
        max-active: 300
        ## 连接池最大阻塞等待时间(使用负值表示没有限制)
        #spring.redis.pool.max-wait=-1
        max-wait: -1
        ## 连接池中的最大空闲连接
        #spring.redis.pool.max-idle=8
        max-idle: 100
        ## 连接池中的最小空闲连接
        #spring.redis.pool.min-idle=0
        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
app:
  debug: true
  redis_expire: 3000
  kline-update-job: true
  newest-price-update-job: true
  other-job: true
rsa:
  public_key: MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCCf8UFZK54AiK4PRu7tNd+Z8qZ77o/QXCnk25DRmygVpOEu5mGNSAvfnWmKp2pEV2RljeXq3Rid/+LQkonaebMJeXKSF0yxL/VgyeT8JaQ5gNbOrdfdlc+mFkXJyzyJt8YkvApEdPRNSU2ENBn7mgRfD0BYPM4vZ6/rv+de38FJwIDAQAB
  private_key: MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAIJ/xQVkrngCIrg9G7u0135nypnvuj9BcKeTbkNGbKBWk4S7mYY1IC9+daYqnakRXZGWN5erdGJ3/4tCSidp5swl5cpIXTLEv9WDJ5PwlpDmA1s6t192Vz6YWRcnLPIm3xiS8CkR09E1JTYQ0GfuaBF8PQFg8zi9nr+u/517fwUnAgMBAAECgYBhPt9NvpI4wbanvnndLczr2GJkxfzvSE+vwLCJF4C5FusFHVsxZINggQcg1V75bwRgCiXRMyYefreCSdrCditS43PzTOmE4RRrpxLlm8oubJc0C98LQ2qlN9AsUqL5IHpVGgbHDyWAwjc1GBID6nwXKpxq1/VodFqhahG9D5EZsQJBALnkb+5VTxQbiyQI4Uc9NIvAyVcNY1OisbvY6tvNgdBbJkADgAb78M1HWxxYjUqsvzggNHc7cWqWBHMgpnJaqm8CQQCztze4D7uAk7OC9MJHY5eE980J8Kk+GEZKxz4LahzU6V6dcb9GFac3wEtgilj/tOAn9y0/Q8sm9vvCIbMDzgzJAkEAqRYcqhF26LdVDOX25DHMBgLKISDQZFbsjA13M4/usHL4i+mjHrc0BcUOHu59NpuDI65HitzLAUSLr5zXSdUmiQJAW77wOg4GCejdXsB3IhzMsHwU97sdm26nC+vVV9xvJZ6Rx8zW+f9543NOx9U5BCmhuaVtOvvwDU9PTVcI3atmSQJAXAIJ5gGdtXx0DXiX4VvzNFHqgaqHMGvXyjNVkU2FYQbSAd2A6app4uRO+BkZu9dSjh14m+oXMnV2HzAN2rRnjA==
src/main/resources/application.yml
@@ -4,6 +4,8 @@
    context-path: /
spring:
  profiles:
    active: dev
  datasource:
    url: jdbc:mysql://120.27.238.55:3306/kss_framework?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2b8
    username: ct_test
@@ -91,6 +93,12 @@
app:
  debug: true
  redis_expire: 3000
  # k线更新任务控制
  kline-update-job: false
  #最新价任务控制
  newest-price-update-job: true
  #其他任务控制
  other-job: true
rsa:
  public_key: MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCCf8UFZK54AiK4PRu7tNd+Z8qZ77o/QXCnk25DRmygVpOEu5mGNSAvfnWmKp2pEV2RljeXq3Rid/+LQkonaebMJeXKSF0yxL/VgyeT8JaQ5gNbOrdfdlc+mFkXJyzyJt8YkvApEdPRNSU2ENBn7mgRfD0BYPM4vZ6/rv+de38FJwIDAQAB
src/main/resources/mapper/contract/ContractEntrustOrderDao.xml
@@ -2,4 +2,9 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xcong.excoin.modules.contract.dao.ContractEntrustOrderDao">
    <select id="selectEntrustOrderByIdAndMemberId" resultType="com.xcong.excoin.modules.contract.entity.ContractEntrustOrderEntity">
        select * from contract_entrust_order
        where id=#{id} and member_id=#{memberId}
    </select>
</mapper>
src/main/resources/mapper/platform/PlatformCnyUsdtExchangeDao.xml
File was renamed from src/main/resources/mapper/platform/CnyUsdtExchangeDao.xml
@@ -1,8 +1,8 @@
<?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.platform.dao.CnyUsdtExchangeDao">
<mapper namespace="com.xcong.excoin.modules.platform.dao.PlatformCnyUsdtExchangeDao">
    <select id="getCNYAndUSDTOne" resultType="com.xcong.excoin.modules.coin.entity.CnyUsdtExchange">
    <select id="getCNYAndUSDTOne" resultType="com.xcong.excoin.modules.platform.entity.PlatformCnyUsdtExchangeEntity">
        select  * from platform_cny_usdt_exchange limit 1
    </select>
    
src/main/resources/mapper/platform/PlatformSymbolsContractDao.xml
@@ -2,4 +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.symbols.dao.PlatformSymbolsContractDao">
    <select id="selectAllContractSymbols" resultType="com.xcong.excoin.modules.symbols.entity.PlatformSymbolsContractEntity">
        select * from platform_symbols_contract
    </select>
</mapper>