|
@@ -0,0 +1,85 @@
|
|
|
+package com.simuwang.manage.service.competition;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.simuwang.base.common.conts.DateConst;
|
|
|
+import com.simuwang.base.mapper.FundInfoMapper;
|
|
|
+import com.simuwang.base.mapper.RcCompetitionResultMapper;
|
|
|
+import com.simuwang.base.pojo.dos.FundInfoDO;
|
|
|
+import com.simuwang.base.pojo.dos.RcCompetitionResultDO;
|
|
|
+import com.simuwang.base.pojo.dto.competition.ZJCompetitionResultDTO;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.Comparator;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class ZJCompetitionResultServiceService extends AbstractCompetitionResultService {
|
|
|
+
|
|
|
+ private final RcCompetitionResultMapper rcCompetitionResultMapper;
|
|
|
+ private final FundStrategyService fundStrategyService;
|
|
|
+ private final FundInfoMapper fundInfoMapper;
|
|
|
+
|
|
|
+ public ZJCompetitionResultServiceService(RcCompetitionResultMapper rcCompetitionResultMapper, FundStrategyService fundStrategyService,
|
|
|
+ FundInfoMapper fundInfoMapper) {
|
|
|
+ this.rcCompetitionResultMapper = rcCompetitionResultMapper;
|
|
|
+
|
|
|
+ this.fundStrategyService = fundStrategyService;
|
|
|
+ this.fundInfoMapper = fundInfoMapper;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean isSupport(Integer competitionId) {
|
|
|
+ return competitionId != null && competitionId == 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected List<ZJCompetitionResultDTO> getCompetitionResult(Integer competitionId, String period) {
|
|
|
+ List<ZJCompetitionResultDTO> competitionResultDTOList = CollUtil.newArrayList();
|
|
|
+ List<RcCompetitionResultDO> resultDOList = rcCompetitionResultMapper.queryCompetitionResult(competitionId, period);
|
|
|
+ if (CollUtil.isEmpty(resultDOList)) {
|
|
|
+ return competitionResultDTOList;
|
|
|
+ }
|
|
|
+ // 策略名称
|
|
|
+ Map<Integer, String> strategyNameMap = fundStrategyService.getStrategyName(competitionId);
|
|
|
+ List<String> fundIdList = resultDOList.stream().map(RcCompetitionResultDO::getFundId).distinct().toList();
|
|
|
+ List<FundInfoDO> fundInfoDOList = fundInfoMapper.queryFundInfoByFundId(fundIdList);
|
|
|
+ Map<String, String> fundIdInceptionDateMap = fundInfoDOList.stream().collect(Collectors.toMap(FundInfoDO::getFundId, FundInfoDO::getInceptionDate));
|
|
|
+ competitionResultDTOList = resultDOList.stream().map(e -> convertToResultDTO(e, strategyNameMap.get(e.getStrategy()), fundIdInceptionDateMap.get(e.getFundId()))).toList();
|
|
|
+
|
|
|
+ // 策略分组和排名降序输出
|
|
|
+ return competitionResultDTOList.stream()
|
|
|
+ .sorted(Comparator.comparing(ZJCompetitionResultDTO::getStrategyName).reversed()
|
|
|
+ .thenComparing(ZJCompetitionResultDTO::getRank))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ private ZJCompetitionResultDTO convertToResultDTO(RcCompetitionResultDO resultDO, String strategyName, String inceptionDate) {
|
|
|
+ ZJCompetitionResultDTO resultDTO = BeanUtil.copyProperties(resultDO, ZJCompetitionResultDTO.class);
|
|
|
+ resultDTO.setStrategyName(strategyName);
|
|
|
+ resultDTO.setRegisterNumber(resultDO.getFundRegisterNumber());
|
|
|
+ resultDTO.setStartPriceDate(DateUtil.format(resultDO.getPrePriceDate(), DateConst.YYYY_MM_DD));
|
|
|
+ resultDTO.setStartCumulativeNavWithdrawal(resultDO.getPreCumulativeNavWithdrawal() != null ? String.valueOf(resultDO.getPreCumulativeNavWithdrawal()) : null);
|
|
|
+ resultDTO.setEndPriceDate(DateUtil.format(resultDO.getPriceDate(), DateConst.YYYY_MM_DD));
|
|
|
+ resultDTO.setEndCumulativeNavWithdrawal(resultDO.getCumulativeNavWithdrawal() != null ? String.valueOf(resultDO.getCumulativeNavWithdrawal()) : null);
|
|
|
+ resultDTO.setScore(resultDO.getScore());
|
|
|
+ resultDTO.setRet(resultDO.getRet());
|
|
|
+ resultDTO.setMaxdown(resultDO.getMaxdrawdown());
|
|
|
+ resultDTO.setSharpeRatio(resultDO.getSharperatio());
|
|
|
+ resultDTO.setCalmarRatio(resultDO.getCalmarratio());
|
|
|
+ resultDTO.setWinrate(resultDO.getWinrate());
|
|
|
+ resultDTO.setProductScale(resultDO.getProductScale());
|
|
|
+ resultDTO.setExcessRet(resultDO.getExcessRet());
|
|
|
+ resultDTO.setExcessMaxdown(resultDO.getExcessMaxdown());
|
|
|
+ resultDTO.setExcessSharpeRatio(resultDO.getExcessSharperatio());
|
|
|
+ resultDTO.setInceptionDate(inceptionDate);
|
|
|
+ if (resultDO.getRank() == null) {
|
|
|
+ resultDTO.setRank(999999);
|
|
|
+ }
|
|
|
+ return resultDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|