indicator handler

pull/1/head
fengyu.wang 5 years ago
parent 94cb9630a0
commit 0345bf7449
  1. 6
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/DefaultIndicatorsManager.java
  2. 17
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsHandler.java
  3. 42
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/AnnualGrowthRateIndicatorsHandler.java
  4. 17
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/AssetLiabilityRiskRateIndicatorsHandler.java
  5. 17
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/FluctuationRateIndicatorsHandler.java
  6. 37
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/GrowthRateIndicatorsHandler.java
  7. 17
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxDrawdownRateIndicatorsHandler.java
  8. 17
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxLossRateIndicatorsHandler.java
  9. 17
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ProfitLossRateRateIndicatorsHandler.java
  10. 17
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ShapeRateIndicatorsHandler.java
  11. 17
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/TVPIIndicatorsHandler.java
  12. 17
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/TotalGrowthRateIndicatorsHandler.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.indicators.dto.IndicatorsTypeEnum;
import com.blockchain.server.yyyf.mapper.AssessUserTargetMapper; import com.blockchain.server.yyyf.mapper.AssessUserTargetMapper;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal; import java.math.BigDecimal;
@ -18,6 +19,7 @@ import java.util.Map;
@Service @Service
@AllArgsConstructor @AllArgsConstructor
public class DefaultIndicatorsManager implements IndicatorsManager { public class DefaultIndicatorsManager implements IndicatorsManager {
private final ApplicationContext applicationContext;
private final AssessUserTargetMapper assessUserTargetMapper; private final AssessUserTargetMapper assessUserTargetMapper;
@Override @Override
@ -64,7 +66,7 @@ public class DefaultIndicatorsManager implements IndicatorsManager {
* @date 2020-05-27 22:34:19 * @date 2020-05-27 22:34:19
*/ */
private Float calculateIndicators(String assessUserId, IndicatorsTypeEnum type) { private Float calculateIndicators(String assessUserId, IndicatorsTypeEnum type) {
//indicator impl IndicatorsHandler indicatorsHandler = applicationContext.getBean(type.getCode(), IndicatorsHandler.class);
return null; return indicatorsHandler.handleIndicator(assessUserId);
} }
} }

@ -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);
}

@ -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<AssetsReporter> 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();
}
}

@ -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;
}
}

@ -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;
}
}

@ -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<AssetsReporter> 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();
}
}

@ -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;
}
}

@ -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;
}
}

@ -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;
}
}

@ -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;
}
}

@ -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;
}
}

@ -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;
}
}
Loading…
Cancel
Save