Merge branch 'EP-Indicator' of zhixinlian/client-server into master

master
fengyu.wang 4 years ago
commit e8824d8b65
  1. 4
      blockchain-server/blockchain-server-currency/src/main/java/com/blockchain/server/currency/Scheduling/CurrencyMarketScheduling.java
  2. 13
      blockchain-server/blockchain-server-currency/src/main/java/com/blockchain/server/currency/Scheduling/HuobiMarketScheduling.java
  3. 5
      blockchain-server/blockchain-server-currency/src/main/java/com/blockchain/server/currency/redis/MarketKCache.java
  4. 54
      blockchain-server/blockchain-server-currency/src/main/java/com/blockchain/server/currency/service/impl/CurrencyMarketServiceImpl.java
  5. 5
      pom.xml
  6. 1
      spring-cloud/pom.xml
  7. 2
      spring-cloud/spring-cloud-config/src/main/resources/properties/dbconf-dev.yml
  8. 2
      spring-cloud/spring-cloud-config/src/main/resources/properties/txconf-dev.yml
  9. 41
      spring-cloud/spring-cloud-gateway/pom.xml
  10. 14
      spring-cloud/spring-cloud-gateway/src/main/java/com/blockchain/spring/cloud/gateway/GatewayApplication.java
  11. 82
      spring-cloud/spring-cloud-gateway/src/main/resources/application.yml

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.blockchain.server.currency.common.constant.BaseCoinEnums;
import com.blockchain.server.currency.common.constant.RatesEnums;
import com.blockchain.server.currency.redis.MarketLegalCache;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.beans.factory.annotation.Value;
@ -15,6 +16,7 @@ import org.springframework.web.client.RestTemplate;
import java.util.List;
import java.util.Map;
@Slf4j
@Component
@Configurable
@EnableScheduling
@ -37,7 +39,7 @@ public class CurrencyMarketScheduling {
try {
setLegalMarket();
} catch (Exception e) {
// e.printStackTrace();
log.error("CurrencyMarketScheduling.getCurrencyMarket: get currency market error", e);
}
}

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.blockchain.common.base.util.HttpUtilManager;
import com.blockchain.server.currency.dto.CurrencyMarketDTO;
import com.blockchain.server.currency.service.CurrencyMarketService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.beans.factory.annotation.Value;
@ -19,6 +20,7 @@ import java.util.concurrent.Executors;
@Component
@Configurable
@EnableScheduling
@Slf4j
public class HuobiMarketScheduling {
@Autowired
@ -45,8 +47,12 @@ public class HuobiMarketScheduling {
private void setHuobiMarket() {
List<List> currencys = JSONObject.parseArray(huobiCurrencys,List.class);
for (List data : currencys){
saveMarket(getHuobiMarket(huobiUrl + data.get(0).toString()),
data.get(1).toString(),data.get(2).toString());
try {
saveMarket(getHuobiMarket(huobiUrl + data.get(0).toString()),
data.get(1).toString(),data.get(2).toString());
} catch (Exception e) {
log.error("HuobiMarketScheduling.setHuobiMarket: save market error, data={}", data, e);
}
}
}
@ -60,13 +66,14 @@ public class HuobiMarketScheduling {
CurrencyMarketDTO now = currencyMarketService.get(coinName + "-" + unitName);
for (JSONObject obj : list) {
Long timestamp = Long.parseLong(obj.get("ts").toString());
if(timestamp >= now.getTimestamp()) {
if(now == null || timestamp >= now.getTimestamp()) {
List<JSONObject> data = (List<JSONObject>)obj.get("data");
currencyMarketService.save(coinName, unitName,
new BigDecimal(data.get(0).get("price").toString()),
new BigDecimal(data.get(0).get("amount").toString()),
timestamp,data.get(0).get("direction").toString().toUpperCase());
} else {
log.warn("HuobiMarketScheduling.saveMarket: save market ignore");
break;
}
}

@ -51,8 +51,9 @@ public class MarketKCache {
}
public void setMarketKListCache(SortedMap<String,CurrencyMarketKDTO> map, String currencyPair, String timeType, int timeNumber){
redisTemplate.opsForValue().set(MARKET_LIST_CACHE + currencyPair + ":" + timeNumber + timeType
,map);
if (map != null && !map.isEmpty()) {
redisTemplate.opsForValue().set(MARKET_LIST_CACHE + currencyPair + ":" + timeNumber + timeType, map);
}
}
public SortedMap<String,CurrencyMarketKDTO> getMarketKListCache(String currencyPair, String timeType, int timeNumber){

@ -21,8 +21,10 @@ import com.blockchain.server.currency.redis.MarketLegalCache;
import com.blockchain.server.currency.service.CurrencyMarketService;
import com.blockchain.server.currency.service.CurrencyPairService;
import com.blockchain.server.currency.websocket.WebSocketSendMsgUtils;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RedissonClient;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;
@ -32,6 +34,7 @@ import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@Slf4j
@Service
public class CurrencyMarketServiceImpl implements CurrencyMarketService {
@ -95,24 +98,30 @@ public class CurrencyMarketServiceImpl implements CurrencyMarketService {
*/
@Override
public CurrencyMarketDTO save(String coinName, String unitName, BigDecimal amount, BigDecimal total, Long timestamp, String tradingType) {
String currencyPair = coinName + "-" + unitName;
//检测币对是否合法
checkCurrency(currencyPair);
CurrencyMarket currencyMarket = new CurrencyMarket();
currencyMarket.setCurrencyPair(currencyPair);
currencyMarket.setTotal(total);
currencyMarket.setAmount(amount);
currencyMarket.setTimestamp(timestamp);
//保存新数据
save(currencyMarket);
CurrencyMarketDTO dto = new CurrencyMarketDTO();
BeanUtils.copyProperties(currencyMarket, dto);
//发送历史成交记录信息
sendHistoryMsg(dto, tradingType);
//添加缓存数据,发送行情变动信息
setMarketCache(dto);
return dto;
try {
String currencyPair = coinName + "-" + unitName;
//检测币对是否合法
checkCurrency(currencyPair);
CurrencyMarket currencyMarket = new CurrencyMarket();
currencyMarket.setCurrencyPair(currencyPair);
currencyMarket.setTotal(total);
currencyMarket.setAmount(amount);
currencyMarket.setTimestamp(timestamp);
//保存新数据
save(currencyMarket);
CurrencyMarketDTO dto = new CurrencyMarketDTO();
BeanUtils.copyProperties(currencyMarket, dto);
//发送历史成交记录信息
sendHistoryMsg(dto, tradingType);
//添加缓存数据,发送行情变动信息
setMarketCache(dto);
return dto;
} catch (BeansException e) {
log.error("CurrencyMarketServiceImpl.save: save error, coinName={}, unitName={}, amount={}, total={}, timestamp={}, tradingType={}",
coinName, unitName, amount, total, timestamp, tradingType);
return null;
}
}
@Override
@ -122,6 +131,9 @@ public class CurrencyMarketServiceImpl implements CurrencyMarketService {
//获取一天的K线行情
SortedMap<String, CurrencyMarketKDTO> map = getOneDayMarketK(currencyPair,
MarketKTypeEnums.ONEDAY.getTimeType(), MarketKTypeEnums.ONEDAY.getTimeNumber());
if (map == null || map.isEmpty()) {
return null;
}
CurrencyMarketDTO dto = getMarketInfo(currencyPair, map);
return dto;
}
@ -432,9 +444,9 @@ public class CurrencyMarketServiceImpl implements CurrencyMarketService {
ktype.getTimeType(), ktype.getTimeNumber());
if (lock) {
SortedMap<String, CurrencyMarketKDTO> map = marketKCache.getMarketKListCache(dto.getCurrencyPair(), ktype.getTimeType(), ktype.getTimeNumber());
if (map == null)
if (map == null || map.isEmpty())
map = selectMarketK(dto.getCurrencyPair(), ktype.getTimeType(), ktype.getTimeNumber());
if (map == null) continue;
if (map == null || map.isEmpty()) continue;
Long timestamp = (dto.getTimestamp() / (ktype.getTimeNumber() * MarketKEnums.valueOf(ktype.getTimeType()).getSecond())) * ktype.getTimeNumber() * MarketKEnums.valueOf(ktype.getTimeType()).getSecond();
CurrencyMarketKDTO kdto = map.get(timestamp.toString());
if (kdto == null) {
@ -608,7 +620,7 @@ public class CurrencyMarketServiceImpl implements CurrencyMarketService {
*/
private SortedMap<String, CurrencyMarketKDTO> getOneDayMarketK(String currencyPair, String timeType, Integer timeNumber) {
SortedMap<String, CurrencyMarketKDTO> map = marketKCache.getMarketKListCache(currencyPair, timeType, timeNumber);
if (map == null) {
if (map == null || map.isEmpty()) {
boolean lock = marketKCache.tryFairLock(redissonClient, currencyPair,
timeType, timeNumber);
if (lock) {

@ -33,8 +33,9 @@
<custom-project-version>latest</custom-project-version>
<!-- 配置信息 -->
<eureka-host>zhixinlian:zhi123xin678lian@127.0.0.1</eureka-host>
<redis-host>127.0.0.1</redis-host>
<eureka-host>zhixinlian:zhi123xin678lian@spring-cloud-eureka</eureka-host>
<redis-host>redis</redis-host>
<tx-host>tx-manager</tx-host>
</properties>
<dependencies>

@ -16,6 +16,7 @@
<module>spring-cloud-eureka</module>
<module>spring-cloud-hystrix-dashboard</module>
<module>spring-cloud-config</module>
<module>spring-cloud-gateway</module>
</modules>

@ -1,6 +1,6 @@
spring:
datasource:
url: jdbc:mysql://127.0.0.1:3306/zhixinlian?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowMultiQueries=true
url: jdbc:mysql://mysql:3306/zhixinlian?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowMultiQueries=true
username: root
password: 123456
driver-class-name: com.mysql.jdbc.Driver

@ -1,4 +1,4 @@
#分布式事务配置
tm:
manager:
url: http://${redis-host}:7000/tx/manager/
url: http://${tx-host}:7000/tx/manager/

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-cloud</artifactId>
<groupId>com.blockchain</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-cloud-gateway</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,14 @@
package com.blockchain.spring.cloud.gateway;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@SpringBootApplication
@EnableEurekaClient
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class,args);
}
}

@ -0,0 +1,82 @@
server:
port: 8003
spring:
application:
name: dapp-gateway-server
cloud:
gateway:
routes:
- id: blockchain-server-btc
uri: lb://dapp-btc-server
predicates:
- Path=/btc/**
filters:
- StripPrefix=1
- id: blockchain-server-cct
uri: lb://dapp-cct-server
predicates:
- Path=/cct/**
filters:
- StripPrefix=1
- id: blockchain-server-currency
uri: lb://dapp-currency-server
predicates:
- Path=/currency/**
filters:
- StripPrefix=1
- id: blockchain-server-databot
uri: lb://dapp-databot-server
predicates:
- Path=/databot/**
filters:
- StripPrefix=1
- id: blockchain-server-eos
uri: lb://dapp-eos-server
predicates:
- Path=/eos/**
filters:
- StripPrefix=1
- id: blockchain-server-eth
uri: lb://dapp-eth-server
predicates:
- Path=/eth/**
filters:
- StripPrefix=1
- id: blockchain-server-imjg
uri: lb://dapp-imjg-server
predicates:
- Path=/imjg/**
filters:
- StripPrefix=1
- id: blockchain-server-otc
uri: lb://dapp-otc-server
predicates:
- Path=/otc/**
filters:
- StripPrefix=1
- id: blockchain-server-sysconf
uri: lb://dapp-sysconf-server
predicates:
- Path=/sysconf/**
filters:
- StripPrefix=1
- id: blockchain-server-user
uri: lb://dapp-user-server
predicates:
- Path=/user/**
filters:
- StripPrefix=1
- id: blockchain-server-yyyf
uri: lb://dapp-yyyf-server
predicates:
- Path=/yyyfuser/**
filters:
- StripPrefix=1
eureka:
client:
service-url:
defaultZone: http://${eureka-host}:8001/eureka/
instance:
prefer-ip-address: true
instance-id: ${spring.cloud.client.ip-address}:${server.port}
hostname: ${spring.cloud.client.ip-address}
Loading…
Cancel
Save