Search in sources :

Example 1 with DailyFundHistoryValueResponse

use of com.tony.billing.response.fund.DailyFundHistoryValueResponse in project BillingDubbo by TonyJiangWJ.

the class FundHistoryValueServiceImpl method getFundHistoryValuesByAssessmentDate.

@Override
public DailyFundHistoryValueResponse getFundHistoryValuesByAssessmentDate(String assessmentDate) {
    Long userId = UserIdContainer.getUserId();
    List<FundInfo> userFunds = fundInfoMapper.getFundInfoDistinctByUser(userId);
    DailyFundHistoryValueResponse response = ResponseUtil.success(new DailyFundHistoryValueResponse());
    response.setAssessmentDate(assessmentDate);
    if (CollectionUtils.isNotEmpty(userFunds)) {
        Map<String, String> fundInfoMap = new HashMap<>(userFunds.size());
        for (FundInfo fundInfo : userFunds) {
            fundInfoMap.put(fundInfo.getFundCode(), fundInfo.getFundName());
        }
        response.setFundInfoMap(fundInfoMap);
        List<FundHistoryValue> dailyFundHistoryValues = mapper.getFundHistoriesByFundCodes(userFunds.stream().map(FundInfo::getFundCode).collect(Collectors.toList()), assessmentDate);
        if (CollectionUtils.isNotEmpty(dailyFundHistoryValues)) {
            Map<String, List<FundHistoryValue>> fundHistoryValues = dailyFundHistoryValues.parallelStream().collect(Collectors.groupingBy(FundHistoryValue::getFundCode));
            Map<String, List<String>> resultMap = fundHistoryValues.entrySet().stream().map(entry -> {
                String fundCode = entry.getKey();
                List<String> increaseRateList = entry.getValue().stream().map(FundHistoryValue::getAssessmentIncreaseRate).collect(Collectors.toList());
                Map<String, List<String>> map = new HashMap<>(1);
                map.put(fundCode, increaseRateList);
                return map;
            }).reduce(new HashMap<>(userFunds.size()), (a, b) -> {
                a.putAll(b);
                return a;
            });
            response.setIncreaseRateMapping(resultMap);
            // 计算总增长率
            generateTotalIncreaseRateInfo(response, userId);
            response.reverseFundCodeAndName();
            response.reverseRateList();
        }
    }
    return response;
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) DateUtil(com.tony.billing.util.DateUtil) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) FundInfoMapper(com.tony.billing.dao.mapper.FundInfoMapper) LoggerFactory(org.slf4j.LoggerFactory) FundInfoService(com.tony.billing.service.api.FundInfoService) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) UserIdContainer(com.tony.billing.util.UserIdContainer) ArrayList(java.util.ArrayList) ResponseUtil(com.tony.billing.util.ResponseUtil) Value(org.springframework.beans.factory.annotation.Value) DailyFundHistoryValueResponse(com.tony.billing.response.fund.DailyFundHistoryValueResponse) BigDecimal(java.math.BigDecimal) CollectionUtils(org.apache.commons.collections.CollectionUtils) Map(java.util.Map) AbstractServiceImpl(com.tony.billing.service.base.AbstractServiceImpl) Response(okhttp3.Response) FundHistoryValue(com.tony.billing.entity.FundHistoryValue) Service(org.apache.dubbo.config.annotation.Service) EnumYesOrNo(com.tony.billing.constants.enums.EnumYesOrNo) DailyFundChangedResponse(com.tony.billing.response.fund.DailyFundChangedResponse) FundHistoryValueService(com.tony.billing.service.api.FundHistoryValueService) FundHistoryNetValue(com.tony.billing.entity.FundHistoryNetValue) Request(okhttp3.Request) Logger(org.slf4j.Logger) FundHistoryNetValueMapper(com.tony.billing.dao.mapper.FundHistoryNetValueMapper) FundInfo(com.tony.billing.entity.FundInfo) FundHistoryValueMapper(com.tony.billing.dao.mapper.FundHistoryValueMapper) IOException(java.io.IOException) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) FundValueChangedModel(com.tony.billing.model.FundValueChangedModel) List(java.util.List) JSON(com.alibaba.fastjson.JSON) OkHttpClient(okhttp3.OkHttpClient) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) JSONObject(com.alibaba.fastjson.JSONObject) DailyFundHistoryValueResponse(com.tony.billing.response.fund.DailyFundHistoryValueResponse) HashMap(java.util.HashMap) FundHistoryValue(com.tony.billing.entity.FundHistoryValue) FundInfo(com.tony.billing.entity.FundInfo) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

JSON (com.alibaba.fastjson.JSON)1 JSONObject (com.alibaba.fastjson.JSONObject)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 EnumYesOrNo (com.tony.billing.constants.enums.EnumYesOrNo)1 FundHistoryNetValueMapper (com.tony.billing.dao.mapper.FundHistoryNetValueMapper)1 FundHistoryValueMapper (com.tony.billing.dao.mapper.FundHistoryValueMapper)1 FundInfoMapper (com.tony.billing.dao.mapper.FundInfoMapper)1 FundHistoryNetValue (com.tony.billing.entity.FundHistoryNetValue)1 FundHistoryValue (com.tony.billing.entity.FundHistoryValue)1 FundInfo (com.tony.billing.entity.FundInfo)1 FundValueChangedModel (com.tony.billing.model.FundValueChangedModel)1 DailyFundChangedResponse (com.tony.billing.response.fund.DailyFundChangedResponse)1 DailyFundHistoryValueResponse (com.tony.billing.response.fund.DailyFundHistoryValueResponse)1 FundHistoryValueService (com.tony.billing.service.api.FundHistoryValueService)1 FundInfoService (com.tony.billing.service.api.FundInfoService)1 AbstractServiceImpl (com.tony.billing.service.base.AbstractServiceImpl)1 DateUtil (com.tony.billing.util.DateUtil)1 ResponseUtil (com.tony.billing.util.ResponseUtil)1 UserIdContainer (com.tony.billing.util.UserIdContainer)1 IOException (java.io.IOException)1