diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/DefaultIndicatorsManager.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/DefaultIndicatorsManager.java index 106b22a..3253952 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/DefaultIndicatorsManager.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/DefaultIndicatorsManager.java @@ -6,6 +6,7 @@ import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; import com.blockchain.server.yyyf.indicators.dto.IndicatorsTypeEnum; import com.blockchain.server.yyyf.mapper.AssessUserTargetMapper; import lombok.AllArgsConstructor; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Service; import java.math.BigDecimal; @@ -18,6 +19,7 @@ import java.util.Map; @Service @AllArgsConstructor public class DefaultIndicatorsManager implements IndicatorsManager { + private final ApplicationContext applicationContext; private final AssessUserTargetMapper assessUserTargetMapper; @Override @@ -64,7 +66,7 @@ public class DefaultIndicatorsManager implements IndicatorsManager { * @date 2020-05-27 22:34:19 */ private Float calculateIndicators(String assessUserId, IndicatorsTypeEnum type) { - //indicator impl - return null; + IndicatorsHandler indicatorsHandler = applicationContext.getBean(type.getCode(), IndicatorsHandler.class); + return indicatorsHandler.handleIndicator(assessUserId); } } diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsHandler.java new file mode 100644 index 0000000..9be6507 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsHandler.java @@ -0,0 +1,17 @@ +package com.blockchain.server.yyyf.indicators; + +/** + * @author fengyu + */ +public interface IndicatorsHandler { + String HANDLER_NAME = "IndicatorsHandler"; + /** + * handle indicator + * + * @param assessUserId page result id + * @return indicator result + * @author fengyu.wang + * @date 2020-06-03 21:28:18 + */ + Float handleIndicator(String assessUserId); +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/AnnualGrowthRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/AnnualGrowthRateIndicatorsHandler.java new file mode 100644 index 0000000..e6e822f --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/AnnualGrowthRateIndicatorsHandler.java @@ -0,0 +1,42 @@ +package com.blockchain.server.yyyf.indicators.handle; + +import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import com.blockchain.server.yyyf.indicators.IndicatorsManager; +import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Component; + +import javax.persistence.EntityExistsException; +import java.math.BigDecimal; +import java.util.Comparator; +import java.util.List; + +/** + * @author fengyu + */ +@AllArgsConstructor +@Component(AnnualGrowthRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class AnnualGrowthRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "AnnualGrowthRate"; + + private final IndicatorsManager indicatorsManager; + + @Override + public Float handleIndicator(String assessUserId) { + //TODO should be cached + List reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); + AssetsReporter lastAssets = reporterList + .stream() + .max(Comparator.comparingLong(AssetsReporter::getDays)) + .orElseThrow(() -> new EntityExistsException("assessUser:" + assessUserId)); + AssetsReporter firstAssets = reporterList + .stream() + .min(Comparator.comparingLong(AssetsReporter::getDays)) + .orElseThrow(() -> new EntityExistsException("assessUser:" + assessUserId)); + BigDecimal result = lastAssets.getAssets() + .divide(firstAssets.getAssets()) + .pow((int) (360.0 / lastAssets.getDays())) + .subtract(BigDecimal.valueOf(1)); + return result.divide(BigDecimal.valueOf(100)).floatValue(); + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/AssetLiabilityRiskRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/AssetLiabilityRiskRateIndicatorsHandler.java new file mode 100644 index 0000000..20baedb --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/AssetLiabilityRiskRateIndicatorsHandler.java @@ -0,0 +1,17 @@ +package com.blockchain.server.yyyf.indicators.handle; + +import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import org.springframework.stereotype.Component; + +/** + * @author fengyu + */ +@Component(AssetLiabilityRiskRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class AssetLiabilityRiskRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "AssetLiabilityRiskRate"; + + @Override + public Float handleIndicator(String assessUserId) { + return null; + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/FluctuationRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/FluctuationRateIndicatorsHandler.java new file mode 100644 index 0000000..0921810 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/FluctuationRateIndicatorsHandler.java @@ -0,0 +1,17 @@ +package com.blockchain.server.yyyf.indicators.handle; + +import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import org.springframework.stereotype.Component; + +/** + * @author fengyu + */ +@Component(FluctuationRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class FluctuationRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "FluctuationRate"; + + @Override + public Float handleIndicator(String assessUserId) { + return null; + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/GrowthRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/GrowthRateIndicatorsHandler.java new file mode 100644 index 0000000..28d5f27 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/GrowthRateIndicatorsHandler.java @@ -0,0 +1,37 @@ +package com.blockchain.server.yyyf.indicators.handle; + +import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import com.blockchain.server.yyyf.indicators.IndicatorsManager; +import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Component; + +import javax.persistence.EntityExistsException; +import java.math.BigDecimal; +import java.util.Comparator; +import java.util.List; + +/** + * @author fengyu + */ +@AllArgsConstructor +@Component(GrowthRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class GrowthRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "GrowthRate"; + + private final IndicatorsManager indicatorsManager; + + @Override + public Float handleIndicator(String assessUserId) { + List reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); + AssetsReporter lastAssets = reporterList + .stream() + .max(Comparator.comparingLong(AssetsReporter::getDays)) + .orElseThrow(() -> new EntityExistsException("assessUser:" + assessUserId)); + AssetsReporter firstAssets = reporterList + .stream() + .min(Comparator.comparingLong(AssetsReporter::getDays)) + .orElseThrow(() -> new EntityExistsException("assessUser:" + assessUserId)); + return lastAssets.getAssets().subtract(firstAssets.getAssets()).divide(firstAssets.getAssets()).divide(BigDecimal.valueOf(100)).floatValue(); + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxDrawdownRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxDrawdownRateIndicatorsHandler.java new file mode 100644 index 0000000..c3c4cc7 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxDrawdownRateIndicatorsHandler.java @@ -0,0 +1,17 @@ +package com.blockchain.server.yyyf.indicators.handle; + +import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import org.springframework.stereotype.Component; + +/** + * @author fengyu + */ +@Component(MaxDrawdownRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class MaxDrawdownRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "MaxDrawdownRate"; + + @Override + public Float handleIndicator(String assessUserId) { + return null; + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxLossRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxLossRateIndicatorsHandler.java new file mode 100644 index 0000000..08cb390 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxLossRateIndicatorsHandler.java @@ -0,0 +1,17 @@ +package com.blockchain.server.yyyf.indicators.handle; + +import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import org.springframework.stereotype.Component; + +/** + * @author fengyu + */ +@Component(MaxLossRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class MaxLossRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "MaxLossRate"; + + @Override + public Float handleIndicator(String assessUserId) { + return null; + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ProfitLossRateRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ProfitLossRateRateIndicatorsHandler.java new file mode 100644 index 0000000..d58c537 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ProfitLossRateRateIndicatorsHandler.java @@ -0,0 +1,17 @@ +package com.blockchain.server.yyyf.indicators.handle; + +import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import org.springframework.stereotype.Component; + +/** + * @author fengyu + */ +@Component(ProfitLossRateRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class ProfitLossRateRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "ProfitLossRate"; + + @Override + public Float handleIndicator(String assessUserId) { + return null; + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ShapeRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ShapeRateIndicatorsHandler.java new file mode 100644 index 0000000..01e3ee5 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ShapeRateIndicatorsHandler.java @@ -0,0 +1,17 @@ +package com.blockchain.server.yyyf.indicators.handle; + +import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import org.springframework.stereotype.Component; + +/** + * @author fengyu + */ +@Component(ShapeRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class ShapeRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "AnnualGrowthRate"; + + @Override + public Float handleIndicator(String assessUserId) { + return null; + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/TVPIIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/TVPIIndicatorsHandler.java new file mode 100644 index 0000000..6052a1e --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/TVPIIndicatorsHandler.java @@ -0,0 +1,17 @@ +package com.blockchain.server.yyyf.indicators.handle; + +import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import org.springframework.stereotype.Component; + +/** + * @author fengyu + */ +@Component(TVPIIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class TVPIIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "TVPI"; + + @Override + public Float handleIndicator(String assessUserId) { + return null; + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/TotalGrowthRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/TotalGrowthRateIndicatorsHandler.java new file mode 100644 index 0000000..7b78da6 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/TotalGrowthRateIndicatorsHandler.java @@ -0,0 +1,17 @@ +package com.blockchain.server.yyyf.indicators.handle; + +import com.blockchain.server.yyyf.indicators.IndicatorsHandler; +import org.springframework.stereotype.Component; + +/** + * @author fengyu + */ +@Component(TotalGrowthRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) +public class TotalGrowthRateIndicatorsHandler implements IndicatorsHandler { + public static final String HANDLER_NAME = "TotalGrowthRate"; + + @Override + public Float handleIndicator(String assessUserId) { + return null; + } +}