use of com.mistra.plank.pojo.entity.ForeignFundHoldingsTracking in project plank by MistraR.
the class Barbarossa method fundHoldingsImport.
public void fundHoldingsImport(FundHoldingsParam fundHoldingsParam, Date beginTime, Date endTime) {
UploadDataListener<ForeignFundHoldingsTracking> uploadDataListener = new UploadDataListener<>(500);
try {
EasyExcel.read(fundHoldingsParam.getFile().getInputStream(), ForeignFundHoldingsTracking.class, uploadDataListener).sheet().headRowNumber(2).doRead();
} catch (IOException e) {
log.error("read excel file error,file name:{}", fundHoldingsParam.getFile().getName());
}
for (Map.Entry<Integer, ForeignFundHoldingsTracking> entry : uploadDataListener.getMap().entrySet()) {
executorService.submit(() -> {
ForeignFundHoldingsTracking fundHoldingsTracking = entry.getValue();
try {
Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("name", fundHoldingsTracking.getName()));
fundHoldingsTracking.setCode(stock.getCode());
fundHoldingsTracking.setQuarter(fundHoldingsParam.getQuarter());
List<DailyRecord> dailyRecordList = dailyRecordMapper.selectList(new QueryWrapper<DailyRecord>().eq("name", fundHoldingsTracking.getName()).ge("date", beginTime).le("date", endTime));
if (CollectionUtils.isEmpty(dailyRecordList)) {
HashMap<String, String> stockMap = new HashMap<>();
stockMap.put(stock.getCode(), stock.getName());
dailyRecordProcessor.run(stockMap);
Thread.sleep(60 * 1000);
dailyRecordList = dailyRecordMapper.selectList(new QueryWrapper<DailyRecord>().eq("name", fundHoldingsTracking.getName()).ge("date", beginTime).le("date", endTime));
}
double average = dailyRecordList.stream().map(DailyRecord::getClosePrice).mapToInt(BigDecimal::intValue).average().orElse(0D);
fundHoldingsTracking.setAveragePrice(new BigDecimal(average));
fundHoldingsTracking.setShareholdingChangeAmount(average * fundHoldingsTracking.getShareholdingChangeCount());
fundHoldingsTracking.setModifyTime(new Date());
fundHoldingsTracking.setForeignTotalMarketDynamic(0L);
fundHoldingsTracking.setForeignFundTotalMarketDynamic(0L);
fundHoldingsTrackingMapper.insert(fundHoldingsTracking);
log.warn("更新[ {} ]{}季报基金持仓数据完成!", stock.getName(), fundHoldingsParam.getQuarter());
} catch (Exception e) {
e.printStackTrace();
}
});
}
}
use of com.mistra.plank.pojo.entity.ForeignFundHoldingsTracking in project plank by MistraR.
the class Barbarossa method updateForeignFundShareholding.
/**
* 更新 外资+基金 持仓
*/
private void updateForeignFundShareholding(Integer quarter) {
HashMap<String, JSONObject> foreignShareholding = getForeignShareholding();
List<ForeignFundHoldingsTracking> fundHoldings = fundHoldingsTrackingMapper.selectList(new QueryWrapper<ForeignFundHoldingsTracking>().eq("quarter", quarter));
List<Stock> stocks = stockMapper.selectList(new QueryWrapper<>());
if (CollectionUtils.isEmpty(foreignShareholding.values()) || CollectionUtils.isEmpty(fundHoldings) || CollectionUtils.isEmpty(stocks)) {
return;
}
Map<String, Stock> stockMap = stocks.stream().collect(Collectors.toMap(Stock::getName, e -> e));
for (ForeignFundHoldingsTracking tracking : fundHoldings) {
JSONObject jsonObject = foreignShareholding.get(tracking.getName());
try {
if (Objects.nonNull(jsonObject)) {
long foreignTotalMarket = jsonObject.getLong("HOLD_MARKETCAP_CHG10") / 10000;
tracking.setForeignTotalMarketDynamic(foreignTotalMarket);
}
tracking.setFundTotalMarketDynamic(stockMap.get(tracking.getName()).getCurrentPrice().multiply(new BigDecimal(tracking.getShareholdingCount())).longValue());
tracking.setForeignFundTotalMarketDynamic(tracking.getFundTotalMarketDynamic() + tracking.getForeignTotalMarketDynamic());
tracking.setModifyTime(new Date());
fundHoldingsTrackingMapper.updateById(tracking);
} catch (Exception e) {
e.printStackTrace();
}
}
log.warn("更新外资最新持仓数据完成!");
}
Aggregations