diff --git a/blockchain-server/blockchain-server-yyyf/pom.xml b/blockchain-server/blockchain-server-yyyf/pom.xml index 0753e77..220da63 100644 --- a/blockchain-server/blockchain-server-yyyf/pom.xml +++ b/blockchain-server/blockchain-server-yyyf/pom.xml @@ -68,6 +68,11 @@ poi-ooxml-schemas 3.10-FINAL + + cn.hutool + hutool-core + 5.3.6 + @@ -87,4 +92,4 @@ - \ No newline at end of file + diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/UserTimeMoneyDto.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/UserTimeMoneyDto.java index 889328d..7e904a9 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/UserTimeMoneyDto.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/dto/UserTimeMoneyDto.java @@ -1,6 +1,8 @@ package com.blockchain.server.yyyf.dto; import com.blockchain.server.yyyf.entity.YyyfMoney; +import lombok.Data; +import lombok.EqualsAndHashCode; import java.io.Serializable; import java.util.Date; @@ -12,6 +14,8 @@ import java.util.Date; * @description 包含以渔有方userId、本系统userId、开始时间以及各个币种余额情况 * @date 2020-06-01 21:23 */ +@Data +@EqualsAndHashCode(callSuper = true) public class UserTimeMoneyDto extends YyyfMoney implements Serializable { private static final long serialVersionUID = 5093452353347277920L; 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 new file mode 100644 index 0000000..106b22a --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/DefaultIndicatorsManager.java @@ -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 assetsReporterList) { + //TODO save to db + } + + @Override + public List getAssetsReporterListByAssessUserId(String assessUserId) { + //TODO select from db + return null; + } + + @Override + public Map calculatePageIndicators(String assessUserId) { + List assessUserTargets = assessUserTargetMapper.selectAllStudentAssessUserTargetByIssueId(assessUserId); + Map 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; + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsManager.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsManager.java index 01df104..4118f70 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsManager.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsManager.java @@ -2,13 +2,18 @@ package com.blockchain.server.yyyf.indicators; import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; +import java.math.BigDecimal; import java.util.List; import java.util.Map; +/** + * @author fengyu + */ public interface IndicatorsManager { /** * save assets reporter item * + * @param assetsReporterList assets reporter list to do save * @author fengyu.wang * @date 2020-05-27 22:32:30 */ @@ -18,22 +23,12 @@ public interface IndicatorsManager { * get assets reporter item by assessUserId * * @param assessUserId page result id + * @return assets reporter list * @author fengyu.wang * @date 2020-05-27 22:32:49 */ List 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 * @@ -44,4 +39,13 @@ public interface IndicatorsManager { */ Map 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); } diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/AssetsReporter.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/AssetsReporter.java index b7e6ede..273e6f7 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/AssetsReporter.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/AssetsReporter.java @@ -1,6 +1,9 @@ package com.blockchain.server.yyyf.indicators.dto; +import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; import java.math.BigDecimal; import java.util.Date; @@ -12,10 +15,28 @@ import java.util.Date; * @date 2020-05-27 22:59:34 */ @Data +@Builder +@NoArgsConstructor +@AllArgsConstructor public class AssetsReporter { - private String assessUserId;//成绩id - private String coinName;//币种 - private int days;//交易天数 - private BigDecimal assets;//资产总额 - private Date createTime;//创建时间 + /** + * 成绩id + */ + private String assessUserId; + /** + * 币种 + */ + private String coinName; + /** + * 交易天数 + */ + private long days; + /** + * 资产总额 + */ + private BigDecimal assets; + /** + * 创建时间 + */ + private Date createTime; } diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/IndicatorsDetail.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/IndicatorsDetail.java index 29aab25..267d47b 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/IndicatorsDetail.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/IndicatorsDetail.java @@ -11,6 +11,6 @@ import lombok.Data; @Data public class IndicatorsDetail { private String assessUserId; - private String type;//indicator type + private IndicatorsTypeEnum type; private float indicator; } diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/IndicatorsTypeEnum.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/IndicatorsTypeEnum.java new file mode 100644 index 0000000..48b0e2c --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/IndicatorsTypeEnum.java @@ -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(); + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/task/ExamProcessTask.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/task/ExamProcessTask.java index 448503a..d403f62 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/task/ExamProcessTask.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/task/ExamProcessTask.java @@ -1,39 +1,47 @@ 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.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 org.springframework.beans.factory.annotation.Autowired; +import lombok.AllArgsConstructor; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; +import java.math.BigDecimal; +import java.util.ArrayList; import java.util.List; +/** + * @author fengyu + */ @Configuration @EnableScheduling +@AllArgsConstructor public class ExamProcessTask { - @Autowired - private AssessUserService assessUserService; + private final 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 * * ?") public void processRecording() { - //1.获取所有正在进行的考核、练习的 学生id(子系统userId),注意可能多个练习和一个考试并存 - //包含以渔有方userId、本系统userId(qUserId)、开始时间(startTime)以及各个币种余额情况 - List userTimeMoneyDtos = this.assessUserService.selectUserTimeMoneyDtosForNotEnd(); - - //2.获取 币币总资产 + 法币总资产 + 数据钱包 + 初始资产 + 挂单资金 - //3.计算总资产 转换成RMB - - //4.获取学生考核开始时间 计算当前进行到第几天 - //5.获取学生试卷Id assessUserId - //6.保存到DB + List userTimeMoneyList = this.assessUserService.selectUserTimeMoneyDtosForNotEnd(); + List assetsReporterList = new ArrayList<>(userTimeMoneyList.size()); + DateTime now = DateUtil.date(); + userTimeMoneyList.forEach(entity -> { + BigDecimal assets = indicatorsManager.calculateCurrentTotalAssets(entity.getQUserId()); + assetsReporterList.add(AssetsReporter.builder() + .assessUserId(entity.getAssessUserId()) + .assets(assets) + .days(DateUtil.between(entity.getStartTime(), now, DateUnit.DAY)) + .coinName("RMB") + .createTime(now) + .build()); + }); + indicatorsManager.saveAssetsReporter(assetsReporterList); } }