indicator update

pull/1/head
fengyu.wang 5 years ago
parent 2e4670a975
commit 2d88c28ccd
  1. 5
      blockchain-server/blockchain-server-yyyf/pom.xml
  2. 4
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/UserTimeMoneyDto.java
  3. 70
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/DefaultIndicatorsManager.java
  4. 26
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsManager.java
  5. 31
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/AssetsReporter.java
  6. 2
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/IndicatorsDetail.java
  7. 46
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/IndicatorsTypeEnum.java
  8. 48
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/task/ExamProcessTask.java

@ -68,6 +68,11 @@
<artifactId>poi-ooxml-schemas</artifactId> <artifactId>poi-ooxml-schemas</artifactId>
<version>3.10-FINAL</version> <version>3.10-FINAL</version>
</dependency> </dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-core</artifactId>
<version>5.3.6</version>
</dependency>
</dependencies> </dependencies>

@ -1,6 +1,8 @@
package com.blockchain.server.yyyf.dto; package com.blockchain.server.yyyf.dto;
import com.blockchain.server.yyyf.entity.YyyfMoney; import com.blockchain.server.yyyf.entity.YyyfMoney;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
@ -12,6 +14,8 @@ import java.util.Date;
* @description 包含以渔有方userId本系统userId开始时间以及各个币种余额情况 * @description 包含以渔有方userId本系统userId开始时间以及各个币种余额情况
* @date 2020-06-01 21:23 * @date 2020-06-01 21:23
*/ */
@Data
@EqualsAndHashCode(callSuper = true)
public class UserTimeMoneyDto extends YyyfMoney implements Serializable { public class UserTimeMoneyDto extends YyyfMoney implements Serializable {
private static final long serialVersionUID = 5093452353347277920L; private static final long serialVersionUID = 5093452353347277920L;

@ -0,0 +1,70 @@
package com.blockchain.server.yyyf.indicators;
import cn.hutool.core.map.MapUtil;
import com.blockchain.server.yyyf.entity.AssessUserTarget;
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.stereotype.Service;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
/**
* @author fengyu
*/
@Service
@AllArgsConstructor
public class DefaultIndicatorsManager implements IndicatorsManager {
private final AssessUserTargetMapper assessUserTargetMapper;
@Override
public void saveAssetsReporter(List<AssetsReporter> assetsReporterList) {
//TODO save to db
}
@Override
public List<AssetsReporter> getAssetsReporterListByAssessUserId(String assessUserId) {
//TODO select from db
return null;
}
@Override
public Map<String, Float> calculatePageIndicators(String assessUserId) {
List<AssessUserTarget> assessUserTargets = assessUserTargetMapper.selectAllStudentAssessUserTargetByIssueId(assessUserId);
Map<String, Float> result = MapUtil.newHashMap();
assessUserTargets.parallelStream().forEach(assessUser -> {
Float total = this.calculateIndicators(assessUserId, IndicatorsTypeEnum.parseCode(assessUser.getCode()));
result.put(assessUser.getCode(), total);
});
return result;
}
@Override
public BigDecimal calculateCurrentTotalAssets(String userId) {
//feign interface call
//1.获取 币币总资产 + 法币总资产 + 数字钱包 + 初始资产 + 挂单资金
//cache rate
//2.计算总资产 转换成RMB
//cache RMB rate
return null;
}
/**
* calculate single indicator
*
* @param assessUserId page result id
* @param type indicators type
* @return indicators result
* @author fengyu.wang
* @date 2020-05-27 22:34:19
*/
private Float calculateIndicators(String assessUserId, IndicatorsTypeEnum type) {
//indicator impl
return null;
}
}

@ -2,13 +2,18 @@ package com.blockchain.server.yyyf.indicators;
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; import com.blockchain.server.yyyf.indicators.dto.AssetsReporter;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
/**
* @author fengyu
*/
public interface IndicatorsManager { public interface IndicatorsManager {
/** /**
* save assets reporter item * save assets reporter item
* *
* @param assetsReporterList assets reporter list to do save
* @author fengyu.wang * @author fengyu.wang
* @date 2020-05-27 22:32:30 * @date 2020-05-27 22:32:30
*/ */
@ -18,22 +23,12 @@ public interface IndicatorsManager {
* get assets reporter item by assessUserId * get assets reporter item by assessUserId
* *
* @param assessUserId page result id * @param assessUserId page result id
* @return assets reporter list
* @author fengyu.wang * @author fengyu.wang
* @date 2020-05-27 22:32:49 * @date 2020-05-27 22:32:49
*/ */
List<AssetsReporter> getAssetsReporterListByAssessUserId(String assessUserId); List<AssetsReporter> getAssetsReporterListByAssessUserId(String assessUserId);
/**
* calculate single indicator
*
* @param assessUserId page result id
* @param type indicators type
* @return indicators result
* @author fengyu.wang
* @date 2020-05-27 22:34:19
*/
float calculateIndicators(String assessUserId, String type);
/** /**
* calculate indicator by full exam * calculate indicator by full exam
* *
@ -44,4 +39,13 @@ public interface IndicatorsManager {
*/ */
Map<String, Float> calculatePageIndicators(String assessUserId); Map<String, Float> calculatePageIndicators(String assessUserId);
/**
* calculate current total asset
*
* @param userId system user id
* @return current total assets (RMB)
* @author fengyu.wang
* @date 2020-06-02 20:15:15
*/
BigDecimal calculateCurrentTotalAssets(String userId);
} }

@ -1,6 +1,9 @@
package com.blockchain.server.yyyf.indicators.dto; package com.blockchain.server.yyyf.indicators.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
@ -12,10 +15,28 @@ import java.util.Date;
* @date 2020-05-27 22:59:34 * @date 2020-05-27 22:59:34
*/ */
@Data @Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AssetsReporter { public class AssetsReporter {
private String assessUserId;//成绩id /**
private String coinName;//币种 * 成绩id
private int days;//交易天数 */
private BigDecimal assets;//资产总额 private String assessUserId;
private Date createTime;//创建时间 /**
* 币种
*/
private String coinName;
/**
* 交易天数
*/
private long days;
/**
* 资产总额
*/
private BigDecimal assets;
/**
* 创建时间
*/
private Date createTime;
} }

@ -11,6 +11,6 @@ import lombok.Data;
@Data @Data
public class IndicatorsDetail { public class IndicatorsDetail {
private String assessUserId; private String assessUserId;
private String type;//indicator type private IndicatorsTypeEnum type;
private float indicator; private float indicator;
} }

@ -0,0 +1,46 @@
package com.blockchain.server.yyyf.indicators.dto;
import lombok.Getter;
/**
* @author fengyu
*/
public enum IndicatorsTypeEnum {
/*年化收益率*/
ANNUAL_GROWTH_RATE("AnnualGrowthRate"),
/*收益率*/
GROWTH_RATE("GrowthRate"),
/*累计收益率*/
TOTAL_GROWTH_RATE("TotalGrowthRate"),
/*波动率*/
FLUCTUATION_RATE("FluctuationRate"),
/*夏普比率*/
SHAPE_RATE("ShapeRate"),
/*盈亏比*/
PROFIT_LOSS_RATE("ProfitLossRate"),
/*最大回撤率*/
MAX_DRAWDOWN_RATE("MaxDrawdownRate"),
/*最大亏损率*/
MAX_LOSS_RATE("MaxLossRate"),
/*风险率(资产负债比)*/
ASSET_LIABILITY_RISK_RATE("AssetLiabilityRiskRate"),
/*TVPI*/
TVPI("TVPI");
@Getter
private final String code;
IndicatorsTypeEnum(String code) {
this.code = code;
}
public static IndicatorsTypeEnum parseCode(String code) {
for (IndicatorsTypeEnum value : IndicatorsTypeEnum.values()) {
if (code.equals(value.getCode())) {
return value;
}
}
throw new IllegalArgumentException();
}
}

@ -1,39 +1,47 @@
package com.blockchain.server.yyyf.task; package com.blockchain.server.yyyf.task;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.blockchain.server.yyyf.dto.UserTimeMoneyDto; import com.blockchain.server.yyyf.dto.UserTimeMoneyDto;
import com.blockchain.server.yyyf.entity.AssessUser; import com.blockchain.server.yyyf.indicators.IndicatorsManager;
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter;
import com.blockchain.server.yyyf.service.AssessUserService; import com.blockchain.server.yyyf.service.AssessUserService;
import org.springframework.beans.factory.annotation.Autowired; import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/**
* @author fengyu
*/
@Configuration @Configuration
@EnableScheduling @EnableScheduling
@AllArgsConstructor
public class ExamProcessTask { public class ExamProcessTask {
@Autowired private final AssessUserService assessUserService;
private AssessUserService assessUserService; private final IndicatorsManager indicatorsManager;
//下面的原注解报错,先注释掉:llegalStateException: Encountered invalid
// @Scheduled method 'processRecording': Cron expression must consist of 6 fields (found 7 in "0 0 0 1/1 * ? *")
//@Scheduled(cron="0 0 0 1/1 * ? *")
//每天 00:01:00 执行
@Scheduled(cron = "0 1 0 * * ?") @Scheduled(cron = "0 1 0 * * ?")
public void processRecording() { public void processRecording() {
//1.获取所有正在进行的考核、练习的 学生id(子系统userId),注意可能多个练习和一个考试并存 List<UserTimeMoneyDto> userTimeMoneyList = this.assessUserService.selectUserTimeMoneyDtosForNotEnd();
//包含以渔有方userId、本系统userId(qUserId)、开始时间(startTime)以及各个币种余额情况 List<AssetsReporter> assetsReporterList = new ArrayList<>(userTimeMoneyList.size());
List<UserTimeMoneyDto> userTimeMoneyDtos = this.assessUserService.selectUserTimeMoneyDtosForNotEnd(); DateTime now = DateUtil.date();
userTimeMoneyList.forEach(entity -> {
//2.获取 币币总资产 + 法币总资产 + 数据钱包 + 初始资产 + 挂单资金 BigDecimal assets = indicatorsManager.calculateCurrentTotalAssets(entity.getQUserId());
//3.计算总资产 转换成RMB assetsReporterList.add(AssetsReporter.builder()
.assessUserId(entity.getAssessUserId())
//4.获取学生考核开始时间 计算当前进行到第几天 .assets(assets)
//5.获取学生试卷Id assessUserId .days(DateUtil.between(entity.getStartTime(), now, DateUnit.DAY))
//6.保存到DB .coinName("RMB")
.createTime(now)
.build());
});
indicatorsManager.saveAssetsReporter(assetsReporterList);
} }
} }

Loading…
Cancel
Save