Search in sources :

Example 1 with UploadDataListener

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();
            }
        });
    }
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) HashMap(java.util.HashMap) IOException(java.io.IOException) DailyRecord(com.mistra.plank.pojo.entity.DailyRecord) BigDecimal(java.math.BigDecimal) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) IOException(java.io.IOException) UploadDataListener(com.mistra.plank.util.UploadDataListener) ForeignFundHoldingsTracking(com.mistra.plank.pojo.entity.ForeignFundHoldingsTracking) Map(java.util.Map) HashMap(java.util.HashMap) Stock(com.mistra.plank.pojo.entity.Stock)

Aggregations

QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 DailyRecord (com.mistra.plank.pojo.entity.DailyRecord)1 ForeignFundHoldingsTracking (com.mistra.plank.pojo.entity.ForeignFundHoldingsTracking)1 Stock (com.mistra.plank.pojo.entity.Stock)1 UploadDataListener (com.mistra.plank.util.UploadDataListener)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 LocalDate (org.joda.time.LocalDate)1