Search in sources :

Example 1 with ForeignFundHoldingsTracking

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();
            }
        });
    }
}
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)

Example 2 with ForeignFundHoldingsTracking

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("更新外资最新持仓数据完成!");
}
Also used : DateUtil(cn.hutool.core.date.DateUtil) Date(java.util.Date) DailyRecord(com.mistra.plank.pojo.entity.DailyRecord) DragonList(com.mistra.plank.pojo.entity.DragonList) HoldShares(com.mistra.plank.pojo.entity.HoldShares) PlankConfig(com.mistra.plank.config.PlankConfig) Clearance(com.mistra.plank.pojo.entity.Clearance) BigDecimal(java.math.BigDecimal) Map(java.util.Map) TradeRecord(com.mistra.plank.pojo.entity.TradeRecord) Days(org.joda.time.Days) HoldSharesMapper(com.mistra.plank.mapper.HoldSharesMapper) HttpUtil(com.mistra.plank.util.HttpUtil) RoundingMode(java.math.RoundingMode) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) FundHoldingsParam(com.mistra.plank.pojo.param.FundHoldingsParam) TradeRecordMapper(com.mistra.plank.mapper.TradeRecordMapper) FundHoldingsTrackingMapper(com.mistra.plank.mapper.FundHoldingsTrackingMapper) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) Stock(com.mistra.plank.pojo.entity.Stock) UploadDataListener(com.mistra.plank.util.UploadDataListener) Objects(java.util.Objects) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) JSONObject(com.alibaba.fastjson.JSONObject) StockRealTimePrice(com.mistra.plank.pojo.dto.StockRealTimePrice) DragonListMapper(com.mistra.plank.mapper.DragonListMapper) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) OptionalDouble(java.util.OptionalDouble) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) EasyExcel(com.alibaba.excel.EasyExcel) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) JSONArray(com.alibaba.fastjson.JSONArray) CommandLineRunner(org.springframework.boot.CommandLineRunner) ExecutorService(java.util.concurrent.ExecutorService) DailyRecordMapper(com.mistra.plank.mapper.DailyRecordMapper) DateTime(org.joda.time.DateTime) IOException(java.io.IOException) DateUtils(org.apache.commons.lang3.time.DateUtils) TimeUnit(java.util.concurrent.TimeUnit) LocalDate(org.joda.time.LocalDate) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) Component(org.springframework.stereotype.Component) ClearanceReasonEnum(com.mistra.plank.pojo.enums.ClearanceReasonEnum) JSON(com.alibaba.fastjson.JSON) NamedThreadFactory(cn.hutool.core.thread.NamedThreadFactory) ForeignFundHoldingsTracking(com.mistra.plank.pojo.entity.ForeignFundHoldingsTracking) StockMapper(com.mistra.plank.mapper.StockMapper) Collections(java.util.Collections) ClearanceMapper(com.mistra.plank.mapper.ClearanceMapper) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) BigDecimal(java.math.BigDecimal) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) IOException(java.io.IOException) JSONObject(com.alibaba.fastjson.JSONObject) ForeignFundHoldingsTracking(com.mistra.plank.pojo.entity.ForeignFundHoldingsTracking) Stock(com.mistra.plank.pojo.entity.Stock)

Aggregations

QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)2 DailyRecord (com.mistra.plank.pojo.entity.DailyRecord)2 ForeignFundHoldingsTracking (com.mistra.plank.pojo.entity.ForeignFundHoldingsTracking)2 Stock (com.mistra.plank.pojo.entity.Stock)2 UploadDataListener (com.mistra.plank.util.UploadDataListener)2 IOException (java.io.IOException)2 BigDecimal (java.math.BigDecimal)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 LocalDate (org.joda.time.LocalDate)2 DateUtil (cn.hutool.core.date.DateUtil)1 NamedThreadFactory (cn.hutool.core.thread.NamedThreadFactory)1 EasyExcel (com.alibaba.excel.EasyExcel)1 JSON (com.alibaba.fastjson.JSON)1 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 PlankConfig (com.mistra.plank.config.PlankConfig)1 ClearanceMapper (com.mistra.plank.mapper.ClearanceMapper)1