Parcourir la source

核心计算模块更新

wangzaijun il y a 1 an
Parent
commit
5e6885ed06

+ 1 - 1
pom.xml

@@ -46,7 +46,7 @@
         <dependency>
             <groupId>com.smppw</groupId>
             <artifactId>data-calc</artifactId>
-            <version>0.1.4-SNAPSHOT</version>
+            <version>0.1.7-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>cn.hutool</groupId>

+ 120 - 0
src/main/java/com/smppw/analysis/domain/dataobject/IndexesTradeDateDo.java

@@ -0,0 +1,120 @@
+package com.smppw.analysis.domain.dataobject;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Date;
+
+@Setter
+@Getter
+public class IndexesTradeDateDo {
+    /**
+     * 主键ID
+     */
+    private Integer id;
+
+    /**
+     * 指数代码
+     */
+    private String indexCode;
+
+    /**
+     * 日期
+     */
+    private String tradeDate;
+
+    /**
+     * 截止年份
+     */
+    private String endYear;
+
+    /**
+     * 全年的第几周
+     */
+    private Integer weekOfYear;
+
+    /**
+     * 年周
+     */
+    private String yearWeek;
+
+    /**
+     * 星期,周一为1
+     */
+    private Integer dayOfWeek;
+
+    /**
+     * 周的开始日期
+     */
+    private Date weekBegin;
+
+    /**
+     * 周的结束日期
+     */
+    private Date weekEnd;
+
+    /**
+     * 上一周所在的年
+     */
+    private String preYear;
+
+    /**
+     * 上一周
+     */
+    private Byte preWeek;
+
+    /**
+     * 是否为节假日 0 工作日 1 节假日
+     */
+    private Integer isholiday;
+
+    /**
+     * 是否周最后交易日:1-是,2-否
+     */
+    private Integer isWeekend;
+
+    /**
+     * 是否月最后交易日:1-是,2-否
+     */
+    private Integer isMonthend;
+
+    /**
+     * 是否季最后交易日:1-是,2-否
+     */
+    private Integer isQuarterend;
+
+    /**
+     * 是否年最后交易日:1-是,2-否
+     */
+    private Integer isYearend;
+
+    /**
+     * 记录有效性 1 有效 0 无效
+     */
+    private Integer isvalid;
+
+    /**
+     * 创建人id
+     */
+    private Integer creatorid;
+
+    /**
+     * 创建时间
+     */
+    private Date createtime;
+
+    /**
+     * 更新人id
+     */
+    private Integer updaterid;
+
+    /**
+     * 更新时间
+     */
+    private Date updatetime;
+
+    /**
+     * 年月
+     */
+    private String yearmonth;
+}

+ 1 - 1
src/main/java/com/smppw/analysis/domain/mapper/core/IndexesTradeDateMapper.java

@@ -1,6 +1,6 @@
 package com.smppw.analysis.domain.mapper.core;
 
-import com.smppw.common.pojo.IndexesTradeDateDo;
+import com.smppw.analysis.domain.dataobject.IndexesTradeDateDo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 

+ 18 - 3
src/main/java/com/smppw/analysis/domain/service/impl/BaseIndicatorServiceV2Impl.java

@@ -1,11 +1,15 @@
 package com.smppw.analysis.domain.service.impl;
 
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.map.MapUtil;
 import cn.hutool.core.util.StrUtil;
 import com.smppw.analysis.domain.dao.FundInformationDao;
+import com.smppw.analysis.domain.dataobject.IndexesTradeDateDo;
+import com.smppw.analysis.domain.mapper.core.IndexesTradeDateMapper;
 import com.smppw.analysis.domain.service.BaseIndicatorServiceV2;
 import com.smppw.analysis.domain.service.NavService;
 import com.smppw.common.pojo.IStrategy;
+import com.smppw.common.pojo.IndexesTradeDate;
 import com.smppw.common.pojo.dto.DateValue;
 import com.smppw.common.pojo.dto.calc.IndicatorCalcPropertyDto;
 import com.smppw.common.pojo.dto.indicator.CalcMultipleSecMultipleTimeRangeIndicatorReq;
@@ -17,16 +21,19 @@ import org.springframework.stereotype.Service;
 import java.math.BigDecimal;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.stream.Collectors;
 
 @Service
 public class BaseIndicatorServiceV2Impl implements BaseIndicatorServiceV2 {
     private final NavService navService;
     private final FundInformationDao fundInformationDao;
+    private final IndexesTradeDateMapper indexesTradeDateMapper;
 
-    public BaseIndicatorServiceV2Impl(NavService navService, FundInformationDao fundInformationDao) {
+    public BaseIndicatorServiceV2Impl(NavService navService, FundInformationDao fundInformationDao, IndexesTradeDateMapper indexesTradeDateMapper) {
         this.navService = navService;
         this.fundInformationDao = fundInformationDao;
+        this.indexesTradeDateMapper = indexesTradeDateMapper;
     }
 
     @Override
@@ -47,7 +54,8 @@ public class BaseIndicatorServiceV2Impl implements BaseIndicatorServiceV2 {
         Map<String, List<DateValue>> allNavMap = navService.getSecIdDateValueNavListMapFromRedisAndDB(mainSecIdList, benchmarkIdList, indexIdList,
                 null, null, curveType.getId(), strategy.getStrategyId(), navType, visibility, MapUtil.empty());
         Map<String, Frequency> secFreqMap = this.fundInformationDao.getNavFrequency(mainSecIdList);
-        return IndicatorService.getInstance().calcMultipleSecMultipleTimeRangeIndicator(req, allNavMap, secFreqMap);
+        List<IndexesTradeDate> tradeDates = this.getTradeDates();
+        return IndicatorService.getInstance().calcMultipleSecMultipleTimeRangeIndicator(req, allNavMap, secFreqMap, tradeDates);
     }
 
     @Override
@@ -69,7 +77,14 @@ public class BaseIndicatorServiceV2Impl implements BaseIndicatorServiceV2 {
                                                                              String startDate, String endDate, boolean ifExcessReturn, String benchmarkId, RaiseType raiseType, IStrategy strategy,
                                                                              Visibility visible, NavType navType, Map<String, List<DateValue>> allNavMap) {
         Map<String, Frequency> secFreqMap = this.fundInformationDao.getNavFrequency(mainSecIdList);
+        List<IndexesTradeDate> tradeDates = this.getTradeDates();
         return IndicatorService.getInstance().getMultiSecRetListNew(mainSecIdList, indexIds, frequency, rollingFrequency, startDate, endDate, ifExcessReturn,
-                benchmarkId, raiseType, strategy, visible, navType, allNavMap, secFreqMap);
+                benchmarkId, raiseType, strategy, visible, navType, allNavMap, secFreqMap, tradeDates);
+    }
+
+    private List<IndexesTradeDate> getTradeDates() {
+        List<IndexesTradeDateDo> dataList = this.indexesTradeDateMapper.listNatureDays();
+        return dataList.stream().filter(e -> Objects.equals(0, e.getIsholiday()))
+                .map(e -> BeanUtil.copyProperties(e, IndexesTradeDate.class)).collect(Collectors.toList());
     }
 }

+ 33 - 33
src/main/java/com/smppw/analysis/infrastructure/task/NonTradingDayTask.java

@@ -1,33 +1,33 @@
-package com.smppw.analysis.infrastructure.task;
-
-import com.smppw.analysis.domain.mapper.core.IndexesTradeDateMapper;
-import com.smppw.common.cache.CaffeineLocalCache;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.stereotype.Component;
-
-import java.util.List;
-
-@Component
-public class NonTradingDayTask {
-
-    private static final Logger logger = LoggerFactory.getLogger(NonTradingDayTask.class);
-
-    @Autowired
-    private IndexesTradeDateMapper indexesTradeDateMapper;
-
-    /**
-     * 将非交易日日期放入本地缓存,启动后十秒,及之后每24小时执行一次
-     * 所有机器启动时均需加载,且执行间隔较长,不适宜用XxlJob进行管理
-     */
-    @Scheduled(initialDelay = 10000, fixedRate = 24 * 3600 * 1000)
-    public void cacheNonTradingDays() {
-        logger.info("start cacheNonTradingDays");
-        List<String> allHolidayDays = indexesTradeDateMapper.listHolidays();
-
-        CaffeineLocalCache.addNonTradingDay(allHolidayDays);
-        logger.info("finish cacheNonTradingDays");
-    }
-}
+//package com.smppw.analysis.infrastructure.task;
+//
+//import com.smppw.analysis.domain.mapper.core.IndexesTradeDateMapper;
+//import com.smppw.common.cache.CaffeineLocalCache;
+//import org.slf4j.Logger;
+//import org.slf4j.LoggerFactory;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.scheduling.annotation.Scheduled;
+//import org.springframework.stereotype.Component;
+//
+//import java.util.List;
+//
+//@Component
+//public class NonTradingDayTask {
+//
+//    private static final Logger logger = LoggerFactory.getLogger(NonTradingDayTask.class);
+//
+//    @Autowired
+//    private IndexesTradeDateMapper indexesTradeDateMapper;
+//
+//    /**
+//     * 将非交易日日期放入本地缓存,启动后十秒,及之后每24小时执行一次
+//     * 所有机器启动时均需加载,且执行间隔较长,不适宜用XxlJob进行管理
+//     */
+//    @Scheduled(initialDelay = 10000, fixedRate = 24 * 3600 * 1000)
+//    public void cacheNonTradingDays() {
+//        logger.info("start cacheNonTradingDays");
+//        List<String> allHolidayDays = indexesTradeDateMapper.listHolidays();
+//
+//        CaffeineLocalCache.addNonTradingDay(allHolidayDays);
+//        logger.info("finish cacheNonTradingDays");
+//    }
+//}

+ 97 - 97
src/main/java/com/smppw/analysis/infrastructure/task/TrendDateTask.java

@@ -1,97 +1,97 @@
-package com.smppw.analysis.infrastructure.task;
-
-import com.smppw.analysis.domain.mapper.core.IndexesTradeDateMapper;
-import com.smppw.common.cache.CaffeineLocalCache;
-import com.smppw.common.pojo.IndexesTradeDateDo;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.stereotype.Repository;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-@Repository
-public class TrendDateTask {
-    private final static Logger logger = LoggerFactory.getLogger(TrendDateTask.class);
-
-    @Autowired
-    private IndexesTradeDateMapper indexesTradeDateMapper;
-
-    //刷期对应的年周, 月周 进缓存
-    @Scheduled(initialDelay = 1000, fixedRate = 24 * 3600 * 1000)
-    public void refreshData() {
-        long start = System.currentTimeMillis();
-        List<IndexesTradeDateDo> indexesTradeDateDoList = indexesTradeDateMapper.listNatureDays();
-        refreshYearWeekAndWeekOfMonth(indexesTradeDateDoList);
-        refreshYearMonth(indexesTradeDateDoList);
-        long end = System.currentTimeMillis();
-        if (logger.isDebugEnabled()) {
-            logger.debug("TrendDateTask execute cost: " + (end - start) + "s");
-        }
-    }
-
-    //刷期对应的年周, 月周 进缓存
-    private void refreshYearWeekAndWeekOfMonth(List<IndexesTradeDateDo> indexesTradeDateDoList) {
-        CaffeineLocalCache.cleanDateYearWeek();
-        CaffeineLocalCache.addDateYearWeek(indexesTradeDateDoList);
-
-        CaffeineLocalCache.cleanListInfoTrendDate();
-        CaffeineLocalCache.addListInfoTrendDate(indexesTradeDateDoList);
-
-        Map<String, String> dateCateMap = new HashMap<>();
-        List<IndexesTradeDateDo> yearWeekLastTradeDateList = new ArrayList<>();
-        Integer weekOfYear = null;
-        String yearmonth = null;
-        int weekOfMonth = 1;
-        for (IndexesTradeDateDo indexesTradeDateDo : indexesTradeDateDoList) {
-            Integer theWeekOfYear = indexesTradeDateDo.getWeekOfYear();
-            String theYearmonth = indexesTradeDateDo.getYearmonth();
-            if (weekOfYear == null) {
-                weekOfYear = theWeekOfYear;
-            }
-            if (yearmonth == null) {
-                yearmonth = theYearmonth;
-            }
-
-            if (!weekOfYear.equals(theWeekOfYear)) {
-                if (!yearmonth.equals(theYearmonth)) {
-                    weekOfMonth = 1;
-                    yearmonth = theYearmonth;
-                } else {
-                    weekOfMonth++;
-                }
-                weekOfYear = theWeekOfYear;
-            }
-            dateCateMap.put(indexesTradeDateDo.getTradeDate(), yearmonth + "-" + weekOfMonth);
-
-            if (indexesTradeDateDo.getIsWeekend().compareTo(1) == 0) {
-                yearWeekLastTradeDateList.add(indexesTradeDateDo);
-            }
-        }
-        CaffeineLocalCache.cleanDateMonthWeek();
-        CaffeineLocalCache.addDateMonthWeek(dateCateMap);
-
-        CaffeineLocalCache.cleanYearWeekLastTradeDate();
-        CaffeineLocalCache.addYearWeekLastTradeDate(yearWeekLastTradeDateList);
-    }
-
-    // 刷新年月数据
-    private void refreshYearMonth(List<IndexesTradeDateDo> indexesTradeDateDoList) {
-        CaffeineLocalCache.cleanDateYearMonth();
-        CaffeineLocalCache.addDateYearMonth(indexesTradeDateDoList);
-        List<IndexesTradeDateDo> yearMonthLastTradeDateList = new ArrayList<>();
-        for (IndexesTradeDateDo indexesTradeDateDo : indexesTradeDateDoList) {
-            if (indexesTradeDateDo.getIsMonthend().compareTo(1) == 0) {
-                yearMonthLastTradeDateList.add(indexesTradeDateDo);
-            }
-        }
-
-        CaffeineLocalCache.cleanYearMonthLastTradeDate();
-        CaffeineLocalCache.addYearMonthLastTradeDate(yearMonthLastTradeDateList);
-    }
-
-}
+//package com.smppw.analysis.infrastructure.task;
+//
+//import com.smppw.analysis.domain.mapper.core.IndexesTradeDateMapper;
+//import com.smppw.common.cache.CaffeineLocalCache;
+//import com.smppw.common.pojo.IndexesTradeDateDo;
+//import org.slf4j.Logger;
+//import org.slf4j.LoggerFactory;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.scheduling.annotation.Scheduled;
+//import org.springframework.stereotype.Repository;
+//
+//import java.util.ArrayList;
+//import java.util.HashMap;
+//import java.util.List;
+//import java.util.Map;
+//
+//@Repository
+//public class TrendDateTask {
+//    private final static Logger logger = LoggerFactory.getLogger(TrendDateTask.class);
+//
+//    @Autowired
+//    private IndexesTradeDateMapper indexesTradeDateMapper;
+//
+//    //刷期对应的年周, 月周 进缓存
+//    @Scheduled(initialDelay = 1000, fixedRate = 24 * 3600 * 1000)
+//    public void refreshData() {
+//        long start = System.currentTimeMillis();
+//        List<IndexesTradeDateDo> indexesTradeDateDoList = indexesTradeDateMapper.listNatureDays();
+//        refreshYearWeekAndWeekOfMonth(indexesTradeDateDoList);
+//        refreshYearMonth(indexesTradeDateDoList);
+//        long end = System.currentTimeMillis();
+//        if (logger.isDebugEnabled()) {
+//            logger.debug("TrendDateTask execute cost: " + (end - start) + "s");
+//        }
+//    }
+//
+//    //刷期对应的年周, 月周 进缓存
+//    private void refreshYearWeekAndWeekOfMonth(List<IndexesTradeDateDo> indexesTradeDateDoList) {
+//        CaffeineLocalCache.cleanDateYearWeek();
+//        CaffeineLocalCache.addDateYearWeek(indexesTradeDateDoList);
+//
+//        CaffeineLocalCache.cleanListInfoTrendDate();
+//        CaffeineLocalCache.addListInfoTrendDate(indexesTradeDateDoList);
+//
+//        Map<String, String> dateCateMap = new HashMap<>();
+//        List<IndexesTradeDateDo> yearWeekLastTradeDateList = new ArrayList<>();
+//        Integer weekOfYear = null;
+//        String yearmonth = null;
+//        int weekOfMonth = 1;
+//        for (IndexesTradeDateDo indexesTradeDateDo : indexesTradeDateDoList) {
+//            Integer theWeekOfYear = indexesTradeDateDo.getWeekOfYear();
+//            String theYearmonth = indexesTradeDateDo.getYearmonth();
+//            if (weekOfYear == null) {
+//                weekOfYear = theWeekOfYear;
+//            }
+//            if (yearmonth == null) {
+//                yearmonth = theYearmonth;
+//            }
+//
+//            if (!weekOfYear.equals(theWeekOfYear)) {
+//                if (!yearmonth.equals(theYearmonth)) {
+//                    weekOfMonth = 1;
+//                    yearmonth = theYearmonth;
+//                } else {
+//                    weekOfMonth++;
+//                }
+//                weekOfYear = theWeekOfYear;
+//            }
+//            dateCateMap.put(indexesTradeDateDo.getTradeDate(), yearmonth + "-" + weekOfMonth);
+//
+//            if (indexesTradeDateDo.getIsWeekend().compareTo(1) == 0) {
+//                yearWeekLastTradeDateList.add(indexesTradeDateDo);
+//            }
+//        }
+//        CaffeineLocalCache.cleanDateMonthWeek();
+//        CaffeineLocalCache.addDateMonthWeek(dateCateMap);
+//
+//        CaffeineLocalCache.cleanYearWeekLastTradeDate();
+//        CaffeineLocalCache.addYearWeekLastTradeDate(yearWeekLastTradeDateList);
+//    }
+//
+//    // 刷新年月数据
+//    private void refreshYearMonth(List<IndexesTradeDateDo> indexesTradeDateDoList) {
+//        CaffeineLocalCache.cleanDateYearMonth();
+//        CaffeineLocalCache.addDateYearMonth(indexesTradeDateDoList);
+//        List<IndexesTradeDateDo> yearMonthLastTradeDateList = new ArrayList<>();
+//        for (IndexesTradeDateDo indexesTradeDateDo : indexesTradeDateDoList) {
+//            if (indexesTradeDateDo.getIsMonthend().compareTo(1) == 0) {
+//                yearMonthLastTradeDateList.add(indexesTradeDateDo);
+//            }
+//        }
+//
+//        CaffeineLocalCache.cleanYearMonthLastTradeDate();
+//        CaffeineLocalCache.addYearMonthLastTradeDate(yearMonthLastTradeDateList);
+//    }
+//
+//}

+ 1 - 1
src/main/resources/mapping/core/IndexesTradeDateMapper.xml

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.smppw.analysis.domain.mapper.core.IndexesTradeDateMapper">
-    <resultMap id="BaseResultMap" type="com.smppw.common.pojo.IndexesTradeDateDo">
+    <resultMap id="BaseResultMap" type="com.smppw.analysis.domain.dataobject.IndexesTradeDateDo">
         <!--@mbg.generated-->
         <!--@Table indexes_trade_date-->
         <id column="id" property="id"/>