use of com.mistra.plank.util.UploadDataListener 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();
}
});
}
}
Aggregations