|
@@ -0,0 +1,584 @@
|
|
|
|
+//package com.smppw.fofapi.service.position.bond;
|
|
|
|
+//
|
|
|
|
+//import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
+//import cn.hutool.core.collection.ListUtil;
|
|
|
|
+//import cn.hutool.core.date.DateUnit;
|
|
|
|
+//import cn.hutool.core.date.DateUtil;
|
|
|
|
+//import cn.hutool.core.map.MapUtil;
|
|
|
|
+//import com.smppw.fofapi.conts.SecType;
|
|
|
|
+//import com.smppw.fofapi.dos.valuation.CmFundPositionDetailDO;
|
|
|
|
+//import com.smppw.fofapi.dos.valuation.CmUserValuationTableDO;
|
|
|
|
+//import com.smppw.fofapi.enums.valuation.HoldingType;
|
|
|
|
+//import com.smppw.fofapi.mapper.baseinfo.write.hfdbcore.BondBasicInformationDOMapper;
|
|
|
|
+//import com.smppw.fofapi.pojo.ValueLabelVO;
|
|
|
|
+//import com.smppw.fofapi.pojo.core.FundPositionBaseInfoDO;
|
|
|
|
+//import com.smppw.fofapi.pojo.core.FundPositionDetailDO;
|
|
|
|
+//import com.smppw.fofapi.pojo.dos.core.BondBasicInformationDO;
|
|
|
|
+//import com.smppw.fofapi.pojo.dos.core.BondCreditGradingInfo;
|
|
|
|
+//import com.smppw.fofapi.pojo.dos.core.BondIndustryInfo;
|
|
|
|
+//import com.smppw.analysis.application.dto.position.MarketValueRatio;
|
|
|
|
+//import com.smppw.analysis.application.dto.position.RefMarketValueRatio;
|
|
|
|
+//import com.smppw.analysis.application.dto.position.bond.*;
|
|
|
|
+//import com.smppw.analysis.application.dto.position.stock.ConcentrationVO;
|
|
|
|
+//import com.smppw.fofapi.service.CmFundPositionService;
|
|
|
|
+//import com.smppw.fofapi.service.info.type.SecTypeService;
|
|
|
|
+//import com.smppw.fofapi.service.position.FundPositionBaseService;
|
|
|
|
+//import com.smppw.fofapi.util.BigDecimalUtils;
|
|
|
|
+//import com.smppw.fofapi.util.BinarySearchUtil;
|
|
|
|
+//import lombok.extern.slf4j.Slf4j;
|
|
|
|
+//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+//import org.springframework.stereotype.Service;
|
|
|
|
+//
|
|
|
|
+//import javax.annotation.Resource;
|
|
|
|
+//import java.math.BigDecimal;
|
|
|
|
+//import java.util.*;
|
|
|
|
+//import java.util.stream.Collectors;
|
|
|
|
+//
|
|
|
|
+///**
|
|
|
|
+// * @author Rain
|
|
|
|
+// * @date 2023/6/12 10:05
|
|
|
|
+// * @description
|
|
|
|
+// */
|
|
|
|
+//@Service
|
|
|
|
+//@Slf4j
|
|
|
|
+//public class BondPositionService {
|
|
|
|
+//
|
|
|
|
+// /**
|
|
|
|
+// * 国债
|
|
|
|
+// */
|
|
|
|
+// private static final String COUNTRY_BOND = "countryBond";
|
|
|
|
+// /**
|
|
|
|
+// * 公司债
|
|
|
|
+// */
|
|
|
|
+// private static final String COMPANY_BOND = "companyBond";
|
|
|
|
+// /**
|
|
|
|
+// * 可转债
|
|
|
|
+// */
|
|
|
|
+// private static final String CONVERTIBLE_BOND = "convertibleBond";
|
|
|
|
+// /**
|
|
|
|
+// * 金融债
|
|
|
|
+// */
|
|
|
|
+// private static final String FINANCIAL_BOND = "financialBond";
|
|
|
|
+// /**
|
|
|
|
+// * 资产支持证券
|
|
|
|
+// */
|
|
|
|
+// private static final String ASSET_BACK_BOND = "assetBackBond";
|
|
|
|
+// /**
|
|
|
|
+// * 信用风险缓释工具
|
|
|
|
+// */
|
|
|
|
+// private static final String CREDIT_RISK_BOND = "creditRiskBond";
|
|
|
|
+// /**
|
|
|
|
+// * 其他
|
|
|
|
+// */
|
|
|
|
+// private static final String OTHERS = "others";
|
|
|
|
+// private static final Map<String, List<Integer>> BOND_DESC_MAP = new HashMap<String, List<Integer>>() {
|
|
|
|
+// private static final long serialVersionUID = -6269769194874256694L;
|
|
|
|
+//
|
|
|
|
+// {
|
|
|
|
+// put(COUNTRY_BOND, CollectionUtil.newArrayList(4, 5, 16));
|
|
|
|
+// put(COMPANY_BOND, CollectionUtil.newArrayList(1, 6, 13, 14, 15, 17, 18, 19, 20, 22, 24, 26, 32, 33, 34, 35, 36, 40, 23, 31));
|
|
|
|
+// put(CONVERTIBLE_BOND, CollectionUtil.newArrayList(10, 28, 29));
|
|
|
|
+// put(FINANCIAL_BOND, CollectionUtil.newArrayList(2, 3, 9, 27, 39));
|
|
|
|
+// put(ASSET_BACK_BOND, CollectionUtil.newArrayList(7, 8, 12, 21, 25));
|
|
|
|
+// put(CREDIT_RISK_BOND, CollectionUtil.newArrayList(37, 38));
|
|
|
|
+// }
|
|
|
|
+// };
|
|
|
|
+// private static final Map<Long, String> POSITION_NAME = MapUtil.newHashMap(true);
|
|
|
|
+// private static final Map<Long, String> CREDIT_GRADING_NAME = MapUtil.newHashMap(true);
|
|
|
|
+//
|
|
|
|
+// static {
|
|
|
|
+// POSITION_NAME.put(1L, "最大持仓");
|
|
|
|
+// POSITION_NAME.put(3L, "前三大持仓");
|
|
|
|
+// POSITION_NAME.put(5L, "前五大持仓");
|
|
|
|
+// POSITION_NAME.put(-1L, "债券持仓");
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// static {
|
|
|
|
+// CREDIT_GRADING_NAME.put(1000L, "AAA+");
|
|
|
|
+// CREDIT_GRADING_NAME.put(999L, "AAA");
|
|
|
|
+// CREDIT_GRADING_NAME.put(990L, "AAA-");
|
|
|
|
+// CREDIT_GRADING_NAME.put(980L, "AA+");
|
|
|
|
+// CREDIT_GRADING_NAME.put(970L, "AA");
|
|
|
|
+// CREDIT_GRADING_NAME.put(960L, "AA-");
|
|
|
|
+// CREDIT_GRADING_NAME.put(950L, "A+");
|
|
|
|
+// CREDIT_GRADING_NAME.put(940L, "A");
|
|
|
|
+// CREDIT_GRADING_NAME.put(930L, "A-");
|
|
|
|
+// CREDIT_GRADING_NAME.put(899L, "BBB+");
|
|
|
|
+// CREDIT_GRADING_NAME.put(895L, "BBB");
|
|
|
|
+// CREDIT_GRADING_NAME.put(891L, "BBB-");
|
|
|
|
+// CREDIT_GRADING_NAME.put(880L, "BB+");
|
|
|
|
+// CREDIT_GRADING_NAME.put(870L, "BB");
|
|
|
|
+// CREDIT_GRADING_NAME.put(860L, "BB-");
|
|
|
|
+// CREDIT_GRADING_NAME.put(850L, "B+");
|
|
|
|
+// CREDIT_GRADING_NAME.put(840L, "B");
|
|
|
|
+// CREDIT_GRADING_NAME.put(830L, "B-");
|
|
|
|
+// CREDIT_GRADING_NAME.put(799L, "CCC");
|
|
|
|
+// CREDIT_GRADING_NAME.put(770L, "CC");
|
|
|
|
+// CREDIT_GRADING_NAME.put(760L, "C");
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// private final Map<String, String> NAME_MAPPING = new HashMap<String, String>() {
|
|
|
|
+// private static final long serialVersionUID = -8630175938931089463L;
|
|
|
|
+//
|
|
|
|
+// {
|
|
|
|
+// put(COUNTRY_BOND, "国债");
|
|
|
|
+// put(COMPANY_BOND, "企业(公司)债");
|
|
|
|
+// put(CONVERTIBLE_BOND, "可转债");
|
|
|
|
+// put(FINANCIAL_BOND, "金融债");
|
|
|
|
+// put(ASSET_BACK_BOND, "资产支持证券");
|
|
|
|
+// put(CREDIT_RISK_BOND, "信用风险缓释工具");
|
|
|
|
+// put(OTHERS, "其他");
|
|
|
|
+// }
|
|
|
|
+// };
|
|
|
|
+// List<String> bondTypeList = CollectionUtil.newArrayList(COUNTRY_BOND, COMPANY_BOND, CONVERTIBLE_BOND, FINANCIAL_BOND, ASSET_BACK_BOND,
|
|
|
|
+// CREDIT_RISK_BOND, OTHERS);
|
|
|
|
+// @Autowired
|
|
|
|
+// private SecTypeService secTypeService;
|
|
|
|
+// @Autowired
|
|
|
|
+// private CmFundPositionService cmFundPositionService;
|
|
|
|
+// @Autowired
|
|
|
|
+// private FundPositionBaseService fundPositionBaseService;
|
|
|
|
+// @Resource
|
|
|
|
+// private BondBasicInformationDOMapper bondBasicInformationDOMapper;
|
|
|
|
+// @Autowired
|
|
|
|
+// private ConcentrationBizBondHandler concentrationBizBondHandler;
|
|
|
|
+//
|
|
|
|
+// public Map<String, Object> getBondSortAllocation(BondSortAllocationParam param) {
|
|
|
|
+// String fundType = this.secTypeService.getFundType(param.getFundId());
|
|
|
|
+// List<BondBasicInformationDO> bondBasicInformationDOS = bondBasicInformationDOMapper.selectAllMappings();
|
|
|
|
+// Map<String, Integer> collect = bondBasicInformationDOS.stream().collect(Collectors.toMap(BondBasicInformationDO::getSecId, BondBasicInformationDO::getBondNature, (p1, p2) -> p2));
|
|
|
|
+// if (SecType.PUBLICLY_OFFERED_FUNDS.equals(fundType)) {
|
|
|
|
+// List<BondSortAssetDTO> list = CollectionUtil.newArrayList();
|
|
|
|
+// List<FundPositionBaseInfoDO> fundPositionBaseInfoDOS = this.fundPositionBaseService.fundPositionBaseInfos(param.getFundId(),
|
|
|
|
+// param.getStartDate(), param.getEndDate());
|
|
|
|
+// if (CollectionUtil.isNotEmpty(fundPositionBaseInfoDOS)) {
|
|
|
|
+// Map<String, BigDecimal> netMarketValueMap = fundPositionBaseInfoDOS.stream()
|
|
|
|
+// .collect(TreeMap::new, (map, item) -> map.put(DateUtil.formatDate(item.getReportDate()), item.getAssetNv()), TreeMap::putAll);
|
|
|
|
+// List<FundPositionDetailDO> fundPositionDetailDOS = this.fundPositionBaseService.positionDetailList(param.getFundId());
|
|
|
|
+// if (CollectionUtil.isNotEmpty(fundPositionBaseInfoDOS)) {
|
|
|
|
+// handlePublicFundNetValue(collect, list, netMarketValueMap, fundPositionDetailDOS);
|
|
|
|
+// }
|
|
|
|
+// Map<String, List<BondSortAssetDTO>> treeMap = filterUnNeedKey(list);
|
|
|
|
+// return MapUtil.<String, Object>builder().put("dataset", treeMap)
|
|
|
|
+// .put("productNameMapping", NAME_MAPPING)
|
|
|
|
+// .build();
|
|
|
|
+// }
|
|
|
|
+// } else if (SecType.PRIVATE_FUND.equals(fundType)) {
|
|
|
|
+// List<BondSortAssetDTO> list = CollectionUtil.newArrayList();
|
|
|
|
+// List<CmUserValuationTableDO> cmUserValuationTableDOS = cmFundPositionService.fundPositionBaseInfos(param.getFundId(),
|
|
|
|
+// param.getStartDate(), param.getEndDate());
|
|
|
|
+// if (CollectionUtil.isNotEmpty(cmUserValuationTableDOS)) {
|
|
|
|
+// Map<String, BigDecimal> netMarketValueMap = cmUserValuationTableDOS.stream()
|
|
|
|
+// .collect(TreeMap::new, (map, item) -> map.put(DateUtil.formatDate(item.getValuationDate()), item.getNetAssetMarketValue()), TreeMap::putAll);
|
|
|
|
+// List<CmFundPositionDetailDO> cmFundPositionDetailDOS = cmFundPositionService.fundPositionDetailList(param.getFundId());
|
|
|
|
+// if (CollectionUtil.isNotEmpty(cmFundPositionDetailDOS)) {
|
|
|
|
+// List<CmFundPositionDetailDO> filterPositionDetails = cmFundPositionDetailDOS.stream().filter(p -> p.getSecType() != null)
|
|
|
|
+// .filter(p -> Objects.nonNull(p.getLevel()))
|
|
|
|
+// .filter(p -> p.getLevel() >= 4)
|
|
|
|
+// .filter(p -> p.getSecType() == 1)
|
|
|
|
+// .filter(p -> Objects.nonNull(p.getSubType()) && p.getSubType() != HoldingType.BondBack.getId())
|
|
|
|
+// .collect(Collectors.toList());
|
|
|
|
+// handlePrivateFundNetValue(collect, list, netMarketValueMap, filterPositionDetails);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// Map<String, List<BondSortAssetDTO>> treeMap = filterUnNeedKey(list);
|
|
|
|
+// return MapUtil.<String, Object>builder().put("dataset", treeMap)
|
|
|
|
+// .put("productNameMapping", NAME_MAPPING)
|
|
|
|
+// .build();
|
|
|
|
+// }
|
|
|
|
+// return null;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// private void handlePrivateFundNetValue(Map<String, Integer> collect, List<BondSortAssetDTO> list, Map<String, BigDecimal> netMarketValueMap, List<CmFundPositionDetailDO> filterPositionDetails) {
|
|
|
|
+// if (CollectionUtil.isNotEmpty(filterPositionDetails)) {
|
|
|
|
+// Map<String, List<CmFundPositionDetailDO>> filterByDateMap = filterPositionDetails.stream().collect(Collectors.groupingBy(p -> DateUtil.formatDate(p.getValuationDate()), TreeMap::new, Collectors.toList()));
|
|
|
|
+// for (Map.Entry<String, BigDecimal> entry : netMarketValueMap.entrySet()) {
|
|
|
|
+// String date = entry.getKey();
|
|
|
|
+// List<CmFundPositionDetailDO> cmFundPositionDetailDOS1 = filterByDateMap.get(date);
|
|
|
|
+// if (CollectionUtil.isNotEmpty(cmFundPositionDetailDOS1)) {
|
|
|
|
+// for (CmFundPositionDetailDO cmFundPositionDetailDO : cmFundPositionDetailDOS1) {
|
|
|
|
+// String secId = cmFundPositionDetailDO.getSecId();
|
|
|
|
+// Integer integer = collect.get(secId);
|
|
|
|
+// String bondTypeBySecId = getBondTypeBySecId(integer);
|
|
|
|
+// cmFundPositionDetailDO.setBondType(bondTypeBySecId);
|
|
|
|
+// }
|
|
|
|
+// Map<String, List<CmFundPositionDetailDO>> bondTypeMap = cmFundPositionDetailDOS1.stream().collect(Collectors.groupingBy(p -> p.getBondType()));
|
|
|
|
+// for (String type : bondTypeList) {
|
|
|
|
+// BondSortAssetDTO bondSortAssetDTO = new BondSortAssetDTO();
|
|
|
|
+// bondSortAssetDTO.setBondType(type);
|
|
|
|
+// bondSortAssetDTO.setValuationDate(date);
|
|
|
|
+// List<CmFundPositionDetailDO> cmFundPositionDetailDOS2 = bondTypeMap.get(type);
|
|
|
|
+// if (CollectionUtil.isNotEmpty(cmFundPositionDetailDOS2)) {
|
|
|
|
+// BigDecimal curSumMarketValue = cmFundPositionDetailDOS2.stream()
|
|
|
|
+// .map(CmFundPositionDetailDO::getMarketValue).filter(Objects::nonNull)
|
|
|
|
+// .reduce(BigDecimal::add).orElse(null);
|
|
|
|
+// bondSortAssetDTO.setMarketValue(curSumMarketValue);
|
|
|
|
+// bondSortAssetDTO.setNetValueRatio(BigDecimalUtils.divide(curSumMarketValue, entry.getValue()));
|
|
|
|
+// list.add(bondSortAssetDTO);
|
|
|
|
+// } else {
|
|
|
|
+// bondSortAssetDTO.setMarketValue(null);
|
|
|
|
+// bondSortAssetDTO.setNetValueRatio(null);
|
|
|
|
+// list.add(bondSortAssetDTO);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// } else {
|
|
|
|
+// handleEmptyBondAsset(list, date);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// private void handlePublicFundNetValue(Map<String, Integer> collect, List<BondSortAssetDTO> list, Map<String, BigDecimal> netMarketValueMap, List<FundPositionDetailDO> fundPositionDetailDOS) {
|
|
|
|
+// List<FundPositionDetailDO> filterPositionDetails = fundPositionDetailDOS.stream().filter(p -> p.getSecType() != null)
|
|
|
|
+// .filter(p -> p.getSecType() == 1).collect(Collectors.toList());
|
|
|
|
+// Map<String, List<FundPositionDetailDO>> filterByDateMap = filterPositionDetails.stream().collect(Collectors.groupingBy(p -> DateUtil.formatDate(p.getValuationDate()), TreeMap::new, Collectors.toList()));
|
|
|
|
+// for (Map.Entry<String, BigDecimal> entry : netMarketValueMap.entrySet()) {
|
|
|
|
+// String date = entry.getKey();
|
|
|
|
+// List<FundPositionDetailDO> cmFundPositionDetailDOS1 = filterByDateMap.get(date);
|
|
|
|
+// if (CollectionUtil.isNotEmpty(cmFundPositionDetailDOS1)) {
|
|
|
|
+// // 判断是哪种类型
|
|
|
|
+// for (FundPositionDetailDO cmFundPositionDetailDO : cmFundPositionDetailDOS1) {
|
|
|
|
+// String secId = cmFundPositionDetailDO.getSecId();
|
|
|
|
+// Integer integer = collect.get(secId);
|
|
|
|
+// String bondTypeBySecId = getBondTypeBySecId(integer);
|
|
|
|
+// cmFundPositionDetailDO.setBondType(bondTypeBySecId);
|
|
|
|
+// }
|
|
|
|
+// Map<String, List<FundPositionDetailDO>> bondTypeMap = cmFundPositionDetailDOS1.stream().collect(Collectors.groupingBy(p -> p.getBondType()));
|
|
|
|
+// for (String type : bondTypeList) {
|
|
|
|
+// BondSortAssetDTO bondSortAssetDTO = new BondSortAssetDTO();
|
|
|
|
+// bondSortAssetDTO.setBondType(type);
|
|
|
|
+// bondSortAssetDTO.setValuationDate(date);
|
|
|
|
+// List<FundPositionDetailDO> cmFundPositionDetailDOS2 = bondTypeMap.get(type);
|
|
|
|
+// if (CollectionUtil.isNotEmpty(cmFundPositionDetailDOS2)) {
|
|
|
|
+// BigDecimal ratio = cmFundPositionDetailDOS2.stream()
|
|
|
|
+// .map(FundPositionDetailDO::getMarketValueRatio).filter(Objects::nonNull)
|
|
|
|
+// .reduce(BigDecimal::add).orElse(null);
|
|
|
|
+// bondSortAssetDTO.setNetValueRatio(ratio);
|
|
|
|
+// BigDecimal marketValue = cmFundPositionDetailDOS2.stream().map(FundPositionDetailDO::getMarketValue).filter(Objects::nonNull)
|
|
|
|
+// .reduce(BigDecimal::add).orElse(null);
|
|
|
|
+// bondSortAssetDTO.setMarketValue(marketValue);
|
|
|
|
+// list.add(bondSortAssetDTO);
|
|
|
|
+// } else {
|
|
|
|
+// bondSortAssetDTO.setMarketValue(null);
|
|
|
|
+// bondSortAssetDTO.setNetValueRatio(null);
|
|
|
|
+// list.add(bondSortAssetDTO);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
+// } else {
|
|
|
|
+// handleEmptyBondAsset(list, date);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// private void handleEmptyBondAsset(List<BondSortAssetDTO> list, String date) {
|
|
|
|
+// for (String type : bondTypeList) {
|
|
|
|
+// BondSortAssetDTO bondSortAssetDTO = new BondSortAssetDTO();
|
|
|
|
+// bondSortAssetDTO.setBondType(type);
|
|
|
|
+// bondSortAssetDTO.setValuationDate(date);
|
|
|
|
+// bondSortAssetDTO.setMarketValue(null);
|
|
|
|
+// bondSortAssetDTO.setNetValueRatio(null);
|
|
|
|
+// list.add(bondSortAssetDTO);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// private Map<String, List<BondSortAssetDTO>> filterUnNeedKey(List<BondSortAssetDTO> list) {
|
|
|
|
+// Map<String, List<BondSortAssetDTO>> treeMap = list.stream()
|
|
|
|
+// .collect(Collectors.groupingBy(BondSortAssetDTO::getBondType, LinkedHashMap::new, Collectors.toList()));
|
|
|
|
+// List<String> needFilterKey = CollectionUtil.newArrayList();
|
|
|
|
+// for (Map.Entry<String, List<BondSortAssetDTO>> entry : treeMap.entrySet()) {
|
|
|
|
+// String key = entry.getKey();
|
|
|
|
+// List<BondSortAssetDTO> value = entry.getValue();
|
|
|
|
+// if (CollectionUtil.isNotEmpty(value)) {
|
|
|
|
+// int emptyCount = 0;
|
|
|
|
+// for (BondSortAssetDTO bondSortAssetDTO : value) {
|
|
|
|
+// if (bondSortAssetDTO.getMarketValue() == null && bondSortAssetDTO.getNetValueRatio() == null) {
|
|
|
|
+// emptyCount++;
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// if (emptyCount == value.size()) {
|
|
|
|
+// needFilterKey.add(key);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// if (CollectionUtil.isNotEmpty(needFilterKey)) {
|
|
|
|
+// for (String key : needFilterKey) {
|
|
|
|
+// treeMap.remove(key);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// return treeMap;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// private String getBondTypeBySecId(Integer secId) {
|
|
|
|
+// if (secId == null) {
|
|
|
|
+// return OTHERS;
|
|
|
|
+// }
|
|
|
|
+// for (Map.Entry<String, List<Integer>> entry : BOND_DESC_MAP.entrySet()) {
|
|
|
|
+// String key = entry.getKey();
|
|
|
|
+// List<Integer> value = entry.getValue();
|
|
|
|
+// if (value.contains(secId)) {
|
|
|
|
+// return key;
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// return OTHERS;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// public Map<String, Object> getBondConcentration(BondSortAllocationParam param) {
|
|
|
|
+// Map<String, Object> dataset = MapUtil.newHashMap();
|
|
|
|
+// List<ConcentrationVO> concentrationVOS = concentrationBizBondHandler.bizHandle(param);
|
|
|
|
+// List<ConcentrationBondVO> concentrationVOList = transfer2Bond(concentrationVOS);
|
|
|
|
+// Set<String> bondIdSet = CollectionUtil.newHashSet();
|
|
|
|
+// // 获取到所有的债券信息
|
|
|
|
+// if (CollectionUtil.isNotEmpty(concentrationVOS)) {
|
|
|
|
+// for (ConcentrationVO concentrationVO : concentrationVOS) {
|
|
|
|
+// List<RefMarketValueRatio> position = concentrationVO.getPosition();
|
|
|
|
+// if (CollectionUtil.isNotEmpty(position)) {
|
|
|
|
+// List<String> collect = position.stream().map(RefMarketValueRatio::getSecId).distinct().collect(Collectors.toList());
|
|
|
|
+// if (CollectionUtil.isNotEmpty(collect)) {
|
|
|
|
+// bondIdSet.addAll(collect);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// Map<String, BondBasicInformationDO> collect = MapUtil.newHashMap();
|
|
|
|
+// if (CollectionUtil.isNotEmpty(bondIdSet)) {
|
|
|
|
+// List<BondBasicInformationDO> bondBasicInformationDOS = bondBasicInformationDOMapper.queryBondBasicInfo(CollectionUtil.newArrayList(bondIdSet));
|
|
|
|
+// collect = bondBasicInformationDOS.stream()
|
|
|
|
+// .collect(Collectors.toMap(BondBasicInformationDO::getSecId, p -> p, (p1, p2) -> p2));
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// Map<String, BondIndustryInfo> industryInfoMap = MapUtil.newHashMap();
|
|
|
|
+// if (CollectionUtil.isNotEmpty(bondIdSet)) {
|
|
|
|
+// List<BondIndustryInfo> bondIndustryInfos = bondBasicInformationDOMapper.queryBondIndustry(CollectionUtil.newArrayList(bondIdSet));
|
|
|
|
+// if (CollectionUtil.isNotEmpty(bondIndustryInfos)) {
|
|
|
|
+// industryInfoMap = bondIndustryInfos.stream().collect(Collectors.toMap(BondIndustryInfo::getSecId, p -> p, (p1, p2) -> p2));
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// for (ConcentrationBondVO concentrationBondVO : concentrationVOList) {
|
|
|
|
+// List<RefBondMarketValueRatio> position = concentrationBondVO.getPosition();
|
|
|
|
+// for (RefBondMarketValueRatio refBondMarketValueRatio : position) {
|
|
|
|
+// String secId = refBondMarketValueRatio.getSecId();
|
|
|
|
+// BondBasicInformationDO bondBasicInformationDO = collect.get(secId);
|
|
|
|
+// if (bondBasicInformationDO != null) {
|
|
|
|
+// refBondMarketValueRatio.setBondType(bondBasicInformationDO.getBondType());
|
|
|
|
+// refBondMarketValueRatio.setNominalInterestRate(bondBasicInformationDO.getNominalInterestRate());
|
|
|
|
+// refBondMarketValueRatio.setCreditRating(bondBasicInformationDO.getCreditRating());
|
|
|
|
+// BondIndustryInfo bondIndustryInfo = industryInfoMap.get(secId);
|
|
|
|
+// refBondMarketValueRatio.setIndustryName(bondIndustryInfo == null ? null : bondIndustryInfo.getFirstIndustryName());
|
|
|
|
+// Date maturityDate = bondBasicInformationDO.getMaturityDate();
|
|
|
|
+// if (maturityDate != null) {
|
|
|
|
+// String date = concentrationBondVO.getDate();
|
|
|
|
+// long between = DateUtil.between(DateUtil.parse(date), maturityDate, DateUnit.DAY);
|
|
|
|
+// refBondMarketValueRatio.setRemainder(between / 365d);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// for (Long integer : POSITION_NAME.keySet()) {
|
|
|
|
+// List<MarketValueRatio> tempList = ListUtil.list(true);
|
|
|
|
+// for (ConcentrationBondVO vo : concentrationVOList) {
|
|
|
|
+// MarketValueRatio mvr = new MarketValueRatio();
|
|
|
|
+// mvr.setDate(vo.getDate());
|
|
|
|
+// List<RefBondMarketValueRatio> resList = vo.getPosition();
|
|
|
|
+// if (integer != -1L) {
|
|
|
|
+// // 不为-1时取前n条记录求和
|
|
|
|
+// resList = vo.getPosition().stream().limit(integer).collect(Collectors.toList());
|
|
|
|
+// }
|
|
|
|
+// BigDecimal marketValue = resList.stream().map(RefBondMarketValueRatio::getMarketValue)
|
|
|
|
+// .filter(Objects::nonNull).reduce(BigDecimal::add).orElse(null);
|
|
|
|
+// BigDecimal ratio = resList.stream().map(RefBondMarketValueRatio::getRatio).filter(Objects::nonNull)
|
|
|
|
+// .reduce(BigDecimal::add).orElse(null);
|
|
|
|
+// mvr.setMarketValue(marketValue);
|
|
|
|
+// mvr.setRatio(ratio);
|
|
|
|
+// tempList.add(mvr);
|
|
|
|
+// }
|
|
|
|
+// dataset.put(integer.toString(), tempList);
|
|
|
|
+// }
|
|
|
|
+// return MapUtil.<String, Object>builder().put("dataset", dataset)
|
|
|
|
+// .put("productNameMapping", POSITION_NAME).put("table", concentrationVOList).build();
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// private List<ConcentrationBondVO> transfer2Bond(List<ConcentrationVO> concentrationVOS) {
|
|
|
|
+// List<ConcentrationBondVO> res = CollectionUtil.newArrayList();
|
|
|
|
+// if (CollectionUtil.isNotEmpty(concentrationVOS)) {
|
|
|
|
+// for (ConcentrationVO concentrationVO : concentrationVOS) {
|
|
|
|
+// ConcentrationBondVO item = new ConcentrationBondVO();
|
|
|
|
+// item.setAssetNv(concentrationVO.getAssetNv());
|
|
|
|
+// item.setDate(concentrationVO.getDate());
|
|
|
|
+// List<RefMarketValueRatio> position = concentrationVO.getPosition();
|
|
|
|
+// List<RefBondMarketValueRatio> list = CollectionUtil.newArrayList();
|
|
|
|
+// if (CollectionUtil.isNotEmpty(position)) {
|
|
|
|
+// Map<ValueLabelVO, List<RefMarketValueRatio>> collect = position.stream().collect(Collectors.groupingBy(p -> p.getRef()));
|
|
|
|
+// for (Map.Entry<ValueLabelVO, List<RefMarketValueRatio>> entry : collect.entrySet()) {
|
|
|
|
+// ValueLabelVO key = entry.getKey();
|
|
|
|
+// List<RefMarketValueRatio> value = entry.getValue();
|
|
|
|
+// if (CollectionUtil.isNotEmpty(value)) {
|
|
|
|
+// if (value.size() == 1) {
|
|
|
|
+// RefMarketValueRatio refMarketValueRatio = value.get(0);
|
|
|
|
+// RefBondMarketValueRatio refBondMarketValueRatio = new RefBondMarketValueRatio();
|
|
|
|
+// refBondMarketValueRatio.setMarketValue(refMarketValueRatio.getMarketValue());
|
|
|
|
+// refBondMarketValueRatio.setRatio(refMarketValueRatio.getRatio());
|
|
|
|
+// refBondMarketValueRatio.setRef(refMarketValueRatio.getRef());
|
|
|
|
+// refBondMarketValueRatio.setSecId(refMarketValueRatio.getSecId());
|
|
|
|
+// list.add(refBondMarketValueRatio);
|
|
|
|
+// } else {
|
|
|
|
+// // 需要轧差
|
|
|
|
+// BigDecimal totalMarket = null;
|
|
|
|
+// BigDecimal ratio = null;
|
|
|
|
+// for (RefMarketValueRatio refMarketValueRatio : value) {
|
|
|
|
+// totalMarket = BigDecimalUtils.add(totalMarket, refMarketValueRatio.getMarketValue());
|
|
|
|
+// ratio = BigDecimalUtils.add(ratio, refMarketValueRatio.getRatio());
|
|
|
|
+// }
|
|
|
|
+// RefBondMarketValueRatio refBondMarketValueRatio = new RefBondMarketValueRatio();
|
|
|
|
+// refBondMarketValueRatio.setMarketValue(totalMarket);
|
|
|
|
+// refBondMarketValueRatio.setRatio(ratio);
|
|
|
|
+// refBondMarketValueRatio.setRef(value.get(0).getRef());
|
|
|
|
+// refBondMarketValueRatio.setSecId(value.get(0).getSecId());
|
|
|
|
+// list.add(refBondMarketValueRatio);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// list.sort(Comparator.comparing(RefBondMarketValueRatio::getMarketValue).reversed());
|
|
|
|
+// item.setPosition(list);
|
|
|
|
+// res.add(item);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// return res;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// public Map<String, Object> getBondCreditGrading(BondSortAllocationParam param) {
|
|
|
|
+// Map<String, Object> dataset = MapUtil.newHashMap(true);
|
|
|
|
+// List<ConcentrationVO> concentrationVOS = concentrationBizBondHandler.bizHandle(param);
|
|
|
|
+// List<CreditGradingBondVO> creditGradingBondVOS = transfer2BondCreditGrading(concentrationVOS);
|
|
|
|
+// // 获取到评级
|
|
|
|
+// Set<String> bondIdSet = CollectionUtil.newHashSet();
|
|
|
|
+// if (CollectionUtil.isNotEmpty(concentrationVOS)) {
|
|
|
|
+// for (ConcentrationVO concentrationVO : concentrationVOS) {
|
|
|
|
+// List<RefMarketValueRatio> position = concentrationVO.getPosition();
|
|
|
|
+// if (CollectionUtil.isNotEmpty(position)) {
|
|
|
|
+// List<String> collect = position.stream().map(RefMarketValueRatio::getSecId).distinct().collect(Collectors.toList());
|
|
|
|
+// if (CollectionUtil.isNotEmpty(collect)) {
|
|
|
|
+// bondIdSet.addAll(collect);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// Map<String, List<BondCreditGradingInfo>> collect = MapUtil.newHashMap();
|
|
|
|
+// if (CollectionUtil.isNotEmpty(bondIdSet)) {
|
|
|
|
+// List<BondCreditGradingInfo> bondCreditGradingInfos = bondBasicInformationDOMapper.queryCreditGradingByBondId(CollectionUtil.newArrayList(bondIdSet));
|
|
|
|
+// if (CollectionUtil.isNotEmpty(bondCreditGradingInfos)) {
|
|
|
|
+// collect = bondCreditGradingInfos.stream().collect(Collectors.groupingBy(BondCreditGradingInfo::getSecId));
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// for (Map.Entry<String, List<BondCreditGradingInfo>> entry : collect.entrySet()) {
|
|
|
|
+// entry.getValue().sort(Comparator.comparing(BondCreditGradingInfo::getCrDate));
|
|
|
|
+// }
|
|
|
|
+// Map<String, BondIndustryInfo> industryInfoMap = MapUtil.newHashMap();
|
|
|
|
+// if (CollectionUtil.isNotEmpty(bondIdSet)) {
|
|
|
|
+// List<BondIndustryInfo> bondIndustryInfos = bondBasicInformationDOMapper.queryBondIndustry(CollectionUtil.newArrayList(bondIdSet));
|
|
|
|
+// if (CollectionUtil.isNotEmpty(bondIndustryInfos)) {
|
|
|
|
+// industryInfoMap = bondIndustryInfos.stream().collect(Collectors.toMap(BondIndustryInfo::getSecId, p -> p, (p1, p2) -> p2));
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// for (CreditGradingBondVO creditGradingBondVO : creditGradingBondVOS) {
|
|
|
|
+// String date = creditGradingBondVO.getDate();
|
|
|
|
+// List<RefCreditMarketValueRatio> position = creditGradingBondVO.getPosition();
|
|
|
|
+// BigDecimal curTotal = position.stream().map(RefCreditMarketValueRatio::getMarketValue)
|
|
|
|
+// .filter(Objects::nonNull).reduce(BigDecimal::add).orElse(null);
|
|
|
|
+// for (RefCreditMarketValueRatio item : position) {
|
|
|
|
+// String secId = item.getSecId();
|
|
|
|
+// item.setRatioPerBond(BigDecimalUtils.divide(item.getMarketValue(), curTotal));
|
|
|
|
+// List<BondCreditGradingInfo> bondCreditGradingInfos1 = collect.get(secId);
|
|
|
|
+// if (CollectionUtil.isNotEmpty(bondCreditGradingInfos1)) {
|
|
|
|
+//
|
|
|
|
+// List<String> dateList = bondCreditGradingInfos1.stream().map(BondCreditGradingInfo::getCrDate).collect(Collectors.toList());
|
|
|
|
+// Integer nearestIndex = BinarySearchUtil.getMostLeftLessNav(dateList, date);
|
|
|
|
+// int mostLeftLessNav = nearestIndex > 0 ? nearestIndex - 1 : nearestIndex;
|
|
|
|
+// BondCreditGradingInfo lastGradingInfo = bondCreditGradingInfos1.get(mostLeftLessNav);
|
|
|
|
+// BondCreditGradingInfo nearestGradingInfo = bondCreditGradingInfos1.get(nearestIndex);
|
|
|
|
+// item.setMainCode(lastGradingInfo.getMainCode());
|
|
|
|
+// item.setLastCrCode(lastGradingInfo.getCrCode());
|
|
|
|
+// item.setLastCrDate(lastGradingInfo.getCrDate());
|
|
|
|
+// if (lastGradingInfo.getCrCode() == null) {
|
|
|
|
+// item.setLastCrDesc(null);
|
|
|
|
+// } else {
|
|
|
|
+// item.setLastCrDesc(CREDIT_GRADING_NAME.getOrDefault(Long.parseLong(lastGradingInfo.getCrCode()), null));
|
|
|
|
+// }
|
|
|
|
+// item.setNearestCrCode(nearestGradingInfo.getCrCode());
|
|
|
|
+// item.setNearestCrDate(nearestGradingInfo.getCrDate());
|
|
|
|
+// if (nearestGradingInfo.getCrCode() == null) {
|
|
|
|
+// item.setNearestCrDesc(null);
|
|
|
|
+// } else {
|
|
|
|
+// item.setNearestCrDesc(CREDIT_GRADING_NAME.getOrDefault(Long.parseLong(nearestGradingInfo.getCrCode()), null));
|
|
|
|
+// }
|
|
|
|
+// item.setCrAnticipate(nearestGradingInfo.getCrAnticipate());
|
|
|
|
+// BondIndustryInfo bondIndustryInfo = industryInfoMap.get(secId);
|
|
|
|
+// if (bondIndustryInfo != null) {
|
|
|
|
+// item.setIndustryName(bondIndustryInfo.getFirstIndustryName());
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// // 处理汇总计算
|
|
|
|
+// for (Long integer : CREDIT_GRADING_NAME.keySet()) {
|
|
|
|
+// List<MarketValueRatio> tempList = ListUtil.list(true);
|
|
|
|
+// for (CreditGradingBondVO vo : creditGradingBondVOS) {
|
|
|
|
+// MarketValueRatio mvr = new MarketValueRatio();
|
|
|
|
+// mvr.setDate(vo.getDate());
|
|
|
|
+// List<RefCreditMarketValueRatio> resList = vo.getPosition();
|
|
|
|
+// BigDecimal ratio = resList.stream().filter(Objects::nonNull).filter(p -> String.valueOf(integer).equals(p.getNearestCrCode()))
|
|
|
|
+// .map(RefCreditMarketValueRatio::getRatio)
|
|
|
|
+// .filter(Objects::nonNull).reduce(BigDecimal::add).orElse(null);
|
|
|
|
+// mvr.setRatio(ratio);
|
|
|
|
+// tempList.add(mvr);
|
|
|
|
+// }
|
|
|
|
+// // 过滤掉当天没有的评级
|
|
|
|
+// int emptyCount = 0;
|
|
|
|
+// for (MarketValueRatio marketValueRatio : tempList) {
|
|
|
|
+// if (marketValueRatio.getMarketValue() == null && marketValueRatio.getRatio() == null) {
|
|
|
|
+// emptyCount++;
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// if (emptyCount != tempList.size()) {
|
|
|
|
+// dataset.put(integer.toString(), tempList);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// Map<Long, String> needCreditMapping = MapUtil.newHashMap(true);
|
|
|
|
+// for (String code : dataset.keySet()) {
|
|
|
|
+// needCreditMapping.put(Long.parseLong(code), CREDIT_GRADING_NAME.get(Long.parseLong(code)));
|
|
|
|
+// }
|
|
|
|
+// return MapUtil.<String, Object>builder().put("dataset", dataset)
|
|
|
|
+// .put("productNameMapping", needCreditMapping).put("table", creditGradingBondVOS).build();
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// private List<CreditGradingBondVO> transfer2BondCreditGrading(List<ConcentrationVO> concentrationVOS) {
|
|
|
|
+// List<CreditGradingBondVO> res = CollectionUtil.newArrayList();
|
|
|
|
+// if (CollectionUtil.isNotEmpty(concentrationVOS)) {
|
|
|
|
+// for (ConcentrationVO concentrationVO : concentrationVOS) {
|
|
|
|
+// CreditGradingBondVO item = new CreditGradingBondVO();
|
|
|
|
+// item.setAssetNv(concentrationVO.getAssetNv());
|
|
|
|
+// item.setDate(concentrationVO.getDate());
|
|
|
|
+// List<RefMarketValueRatio> position = concentrationVO.getPosition();
|
|
|
|
+// List<RefCreditMarketValueRatio> list = CollectionUtil.newArrayList();
|
|
|
|
+// if (CollectionUtil.isNotEmpty(position)) {
|
|
|
|
+// for (RefMarketValueRatio refMarketValueRatio : position) {
|
|
|
|
+// RefCreditMarketValueRatio refBondMarketValueRatio = new RefCreditMarketValueRatio();
|
|
|
|
+// refBondMarketValueRatio.setMarketValue(refMarketValueRatio.getMarketValue());
|
|
|
|
+// refBondMarketValueRatio.setRatio(refMarketValueRatio.getRatio());
|
|
|
|
+// refBondMarketValueRatio.setRef(refMarketValueRatio.getRef());
|
|
|
|
+// refBondMarketValueRatio.setSecId(refMarketValueRatio.getSecId());
|
|
|
|
+// list.add(refBondMarketValueRatio);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// item.setPosition(list);
|
|
|
|
+// res.add(item);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// return res;
|
|
|
|
+// }
|
|
|
|
+//}
|