过滤RetifiveStockInfo中的(blank data)

This commit is contained in:
zhangjian
2024-04-23 09:51:44 +08:00
parent 6815ab0c8b
commit 0696f91ef8
2 changed files with 36 additions and 1 deletions

View File

@@ -6,7 +6,10 @@ import com.thomsonreuters.ema.access.DataType;
import com.thomsonreuters.ema.access.FieldEntry; import com.thomsonreuters.ema.access.FieldEntry;
import com.thomsonreuters.ema.access.FieldList; import com.thomsonreuters.ema.access.FieldList;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@@ -125,13 +128,14 @@ public class RefinitivUtil {
} }
} }
} }
return RetifiveStockInfo.builder() RetifiveStockInfo retifiveStockInfo = RetifiveStockInfo.builder()
.stockCode(stockCode).stockName(stockName).symbol(name).status(status) .stockCode(stockCode).stockName(stockName).symbol(name).status(status)
.openPrice(openPrice).lastPrice(price).highPrice(high).lowPrice(low) .openPrice(openPrice).lastPrice(price).highPrice(high).lowPrice(low)
.previousPrice(previousPrice).perchg(percentChange).volume(volume) .previousPrice(previousPrice).perchg(percentChange).volume(volume)
.week52HighPrice(week52High).week52LowPrice(week52Low).stockType(stockType) .week52HighPrice(week52High).week52LowPrice(week52Low).stockType(stockType)
.change(changeValue) .change(changeValue)
.build(); .build();
return handleBlandData(retifiveStockInfo);
} }
@@ -261,6 +265,24 @@ public class RefinitivUtil {
.volume(volume).week52HighPrice(week52High).week52LowPrice(week52Low).stockType(stockType).change(changeValue) .volume(volume).week52HighPrice(week52High).week52LowPrice(week52Low).stockType(stockType).change(changeValue)
.build(); .build();
return handleBlandData(retifiveStockInfo);
}
private static RetifiveStockInfo handleBlandData(RetifiveStockInfo retifiveStockInfo) {
Field[] fields = retifiveStockInfo.getClass().getDeclaredFields();
Arrays.stream(fields).forEach(field -> {
ReflectionUtils.makeAccessible(field);
try {
Object obj = field.get(retifiveStockInfo);
if (obj instanceof String) {
String objStr = (String) obj;
field.set(retifiveStockInfo, objStr.replace("(blank data)", ""));
}
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
});
return retifiveStockInfo; return retifiveStockInfo;
} }
} }

View File

@@ -1,5 +1,6 @@
package cn.stock.market.web; package cn.stock.market.web;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.stock.market.domain.basic.entity.RetifiveStock; import cn.stock.market.domain.basic.entity.RetifiveStock;
import cn.stock.market.domain.basic.service.RetifiveStockService; import cn.stock.market.domain.basic.service.RetifiveStockService;
@@ -108,6 +109,10 @@ public class RefinitivApiController {
RefreshMsg refreshMsg = appClient.getMessageFuture().get(10, TimeUnit.SECONDS);// 设置超时时间例如10秒 RefreshMsg refreshMsg = appClient.getMessageFuture().get(10, TimeUnit.SECONDS);// 设置超时时间例如10秒
if (DataType.DataTypes.FIELD_LIST == refreshMsg.payload().dataType()) { if (DataType.DataTypes.FIELD_LIST == refreshMsg.payload().dataType()) {
List<String> strings = RefinitivUtil.decode(refreshMsg.payload().fieldList()); List<String> strings = RefinitivUtil.decode(refreshMsg.payload().fieldList());
if (CollUtil.isEmpty(strings)) {
return ServerResponse.createBySuccess("操作成功", list);
}
appClient.subscribeList(strings); // 根据itemName订阅 appClient.subscribeList(strings); // 根据itemName订阅
// 等待消息 // 等待消息
List<RefreshMsg> refreshMsgs = appClient.getMessagesFuture().get(10, TimeUnit.SECONDS); List<RefreshMsg> refreshMsgs = appClient.getMessagesFuture().get(10, TimeUnit.SECONDS);
@@ -137,6 +142,10 @@ public class RefinitivApiController {
RefreshMsg refreshMsg = appClient.getMessageFuture().get(10, TimeUnit.SECONDS);// 设置超时时间例如10秒 RefreshMsg refreshMsg = appClient.getMessageFuture().get(10, TimeUnit.SECONDS);// 设置超时时间例如10秒
if (DataType.DataTypes.FIELD_LIST == refreshMsg.payload().dataType()) { if (DataType.DataTypes.FIELD_LIST == refreshMsg.payload().dataType()) {
List<String> strings = RefinitivUtil.decode(refreshMsg.payload().fieldList()); List<String> strings = RefinitivUtil.decode(refreshMsg.payload().fieldList());
if (CollUtil.isEmpty(strings)) {
return ServerResponse.createBySuccess("操作成功", list);
}
appClient.subscribeList(strings); // 根据itemName订阅 appClient.subscribeList(strings); // 根据itemName订阅
// 等待消息 // 等待消息
List<RefreshMsg> refreshMsgs = appClient.getMessagesFuture().get(10, TimeUnit.SECONDS); List<RefreshMsg> refreshMsgs = appClient.getMessagesFuture().get(10, TimeUnit.SECONDS);
@@ -167,6 +176,10 @@ public class RefinitivApiController {
RefreshMsg refreshMsg = appClient.getMessageFuture().get(10, TimeUnit.SECONDS);// 设置超时时间例如10秒 RefreshMsg refreshMsg = appClient.getMessageFuture().get(10, TimeUnit.SECONDS);// 设置超时时间例如10秒
if (DataType.DataTypes.FIELD_LIST == refreshMsg.payload().dataType()){ if (DataType.DataTypes.FIELD_LIST == refreshMsg.payload().dataType()){
List<String> strings = RefinitivUtil.decode(refreshMsg.payload().fieldList()); List<String> strings = RefinitivUtil.decode(refreshMsg.payload().fieldList());
if (CollUtil.isEmpty(strings)) {
return ServerResponse.createBySuccess("操作成功", list);
}
appClient.subscribeList(strings); // 根据itemName订阅 appClient.subscribeList(strings); // 根据itemName订阅
// 等待消息 // 等待消息
List<RefreshMsg> refreshMsgs = appClient.getMessagesFuture().get(10, TimeUnit.SECONDS); List<RefreshMsg> refreshMsgs = appClient.getMessagesFuture().get(10, TimeUnit.SECONDS);