parent
2e4670a975
commit
2d88c28ccd
8 changed files with 196 additions and 38 deletions
@ -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; |
||||||
|
} |
||||||
|
} |
@ -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…
Reference in new issue