add cache & assetsReporter impl

pull/1/head
fengyu.wang 5 years ago
parent 2451f7205a
commit dc0e7f543d
  1. 12
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/DefaultIndicatorsManager.java
  2. 21
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsManager.java
  3. 4
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/AssetsReporter.java
  4. 18
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/AnnualGrowthRateIndicatorsHandler.java
  5. 11
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/FluctuationRateIndicatorsHandler.java
  6. 6
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/GrowthRateIndicatorsHandler.java
  7. 7
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxDrawdownRateIndicatorsHandler.java
  8. 6
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxLossRateIndicatorsHandler.java
  9. 7
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ProfitLossRateRateIndicatorsHandler.java
  10. 9
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ShapeRateIndicatorsHandler.java
  11. 8
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/TotalGrowthRateIndicatorsHandler.java
  12. 15
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssetsReporterMapper.java
  13. 26
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssetsReporterService.java
  14. 40
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssetsReporterServiceImpl.java
  15. 8
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/task/ExamProcessTask.java
  16. 1
      blockchain-server/blockchain-server-yyyf/src/main/resources/bootstrap.yml
  17. 38
      blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssetsReporterMapper.xml

@ -2,7 +2,6 @@ package com.blockchain.server.yyyf.indicators;
import cn.hutool.core.map.MapUtil; import cn.hutool.core.map.MapUtil;
import com.blockchain.server.yyyf.entity.AssessUserTarget; 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.indicators.dto.IndicatorsTypeEnum;
import com.blockchain.server.yyyf.mapper.AssessUserTargetMapper; import com.blockchain.server.yyyf.mapper.AssessUserTargetMapper;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@ -22,17 +21,6 @@ public class DefaultIndicatorsManager implements IndicatorsManager {
private final ApplicationContext applicationContext; private final ApplicationContext applicationContext;
private final AssessUserTargetMapper assessUserTargetMapper; 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 @Override
public Map<String, Float> calculatePageIndicators(String assessUserId) { public Map<String, Float> calculatePageIndicators(String assessUserId) {
List<AssessUserTarget> assessUserTargets = assessUserTargetMapper.selectAllStudentAssessUserTargetByIssueId(assessUserId); List<AssessUserTarget> assessUserTargets = assessUserTargetMapper.selectAllStudentAssessUserTargetByIssueId(assessUserId);

@ -1,33 +1,12 @@
package com.blockchain.server.yyyf.indicators; package com.blockchain.server.yyyf.indicators;
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
* @author fengyu * @author fengyu
*/ */
public interface IndicatorsManager { 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
*/
void saveAssetsReporter(List<AssetsReporter> assetsReporterList);
/**
* 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<AssetsReporter> getAssetsReporterListByAssessUserId(String assessUserId);
/** /**
* calculate indicator by full exam * calculate indicator by full exam

@ -19,6 +19,10 @@ import java.util.Date;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class AssetsReporter { public class AssetsReporter {
/**
* primary key
*/
private String id;
/** /**
* 成绩id * 成绩id
*/ */

@ -1,11 +1,12 @@
package com.blockchain.server.yyyf.indicators.handle; package com.blockchain.server.yyyf.indicators.handle;
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; import com.blockchain.server.yyyf.indicators.IndicatorsHandler;
import com.blockchain.server.yyyf.indicators.IndicatorsManager;
import com.blockchain.server.yyyf.indicators.IndicatorsUtils; import com.blockchain.server.yyyf.indicators.IndicatorsUtils;
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; import com.blockchain.server.yyyf.indicators.dto.AssetsReporter;
import com.blockchain.server.yyyf.indicators.dto.LastAndFirstAssetsDto; import com.blockchain.server.yyyf.indicators.dto.LastAndFirstAssetsDto;
import com.blockchain.server.yyyf.service.AssetsReporterService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.math.BigDecimal; import java.math.BigDecimal;
@ -18,23 +19,26 @@ import java.util.List;
@Component(AnnualGrowthRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) @Component(AnnualGrowthRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME)
public class AnnualGrowthRateIndicatorsHandler implements IndicatorsHandler { public class AnnualGrowthRateIndicatorsHandler implements IndicatorsHandler {
public static final String HANDLER_NAME = "AnnualGrowthRate"; public static final String HANDLER_NAME = "AnnualGrowthRate";
public static final String CACHE_ANNUAL_GROWTH_RATE = "yyyf_indicator_annualGrowthRate";
public static final String CACHE_KEY_ANNUAL_GROWTH_RATE = "yyyf:annualGrowthRate:";
private final IndicatorsManager indicatorsManager; private final AssetsReporterService assetsReporterService;
@Override @Override
@Cacheable(cacheNames = CACHE_ANNUAL_GROWTH_RATE,
key = "#root.target.CACHE_KEY_ANNUAL_GROWTH_RATE.concat(#assessUserId)", unless = "#result == null")
public Float handleIndicator(String assessUserId) { public Float handleIndicator(String assessUserId) {
//TODO should be cached List<AssetsReporter> reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId);
List<AssetsReporter> reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId);
//获取最初、最后交易的信息 //获取最初、最后交易的信息
LastAndFirstAssetsDto lastAndFirstAssetsDto = IndicatorsUtils.getLastAndFirstAssetsDto(reporterList); LastAndFirstAssetsDto lastAndFirstAssetsDto = IndicatorsUtils.getLastAndFirstAssetsDto(reporterList);
AssetsReporter lastAssets =lastAndFirstAssetsDto.getLastAssets(); AssetsReporter lastAssets = lastAndFirstAssetsDto.getLastAssets();
AssetsReporter firstAssets =lastAndFirstAssetsDto.getFirstAssets(); AssetsReporter firstAssets = lastAndFirstAssetsDto.getFirstAssets();
BigDecimal result = lastAssets.getAssets() BigDecimal result = lastAssets.getAssets()
.divide(firstAssets.getAssets(), 5, BigDecimal.ROUND_HALF_UP) .divide(firstAssets.getAssets(), 5, BigDecimal.ROUND_HALF_UP)
.pow((int) (360.0 / lastAssets.getDays())) .pow((int) (360.0 / lastAssets.getDays()))
.subtract(BigDecimal.valueOf(1)); .subtract(BigDecimal.valueOf(1));
return result.divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP).floatValue(); return result.multiply(BigDecimal.valueOf(100)).floatValue();
} }
} }

@ -1,9 +1,10 @@
package com.blockchain.server.yyyf.indicators.handle; package com.blockchain.server.yyyf.indicators.handle;
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; import com.blockchain.server.yyyf.indicators.IndicatorsHandler;
import com.blockchain.server.yyyf.indicators.IndicatorsManager;
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; import com.blockchain.server.yyyf.indicators.dto.AssetsReporter;
import com.blockchain.server.yyyf.service.AssetsReporterService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.persistence.EntityExistsException; import javax.persistence.EntityExistsException;
@ -19,12 +20,16 @@ import java.util.List;
@Component(FluctuationRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) @Component(FluctuationRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME)
public class FluctuationRateIndicatorsHandler implements IndicatorsHandler { public class FluctuationRateIndicatorsHandler implements IndicatorsHandler {
public static final String HANDLER_NAME = "FluctuationRate"; public static final String HANDLER_NAME = "FluctuationRate";
public static final String CACHE_FLUCTUATION_RATE = "yyyf_indicator_fluctuationRate";
public static final String CACHE_KEY_FLUCTUATION_RATE = "yyyf:fluctuationRate:";
private final IndicatorsManager indicatorsManager; private final AssetsReporterService assetsReporterService;
@Override @Override
@Cacheable(cacheNames = CACHE_FLUCTUATION_RATE,
key = "#root.target.CACHE_KEY_FLUCTUATION_RATE.concat(#assessUserId)", unless = "#result == null")
public Float handleIndicator(String assessUserId) { public Float handleIndicator(String assessUserId) {
List<AssetsReporter> reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); List<AssetsReporter> reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId);
if (reporterList != null && reporterList.size() > 0) { if (reporterList != null && reporterList.size() > 0) {
//排序 //排序
reporterList.sort(Comparator.comparingLong(AssetsReporter::getDays)); reporterList.sort(Comparator.comparingLong(AssetsReporter::getDays));

@ -1,10 +1,10 @@
package com.blockchain.server.yyyf.indicators.handle; package com.blockchain.server.yyyf.indicators.handle;
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; import com.blockchain.server.yyyf.indicators.IndicatorsHandler;
import com.blockchain.server.yyyf.indicators.IndicatorsManager;
import com.blockchain.server.yyyf.indicators.IndicatorsUtils; import com.blockchain.server.yyyf.indicators.IndicatorsUtils;
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; import com.blockchain.server.yyyf.indicators.dto.AssetsReporter;
import com.blockchain.server.yyyf.indicators.dto.LastAndFirstAssetsDto; import com.blockchain.server.yyyf.indicators.dto.LastAndFirstAssetsDto;
import com.blockchain.server.yyyf.service.AssetsReporterService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -19,11 +19,11 @@ import java.util.List;
public class GrowthRateIndicatorsHandler implements IndicatorsHandler { public class GrowthRateIndicatorsHandler implements IndicatorsHandler {
public static final String HANDLER_NAME = "GrowthRate"; public static final String HANDLER_NAME = "GrowthRate";
private final IndicatorsManager indicatorsManager; private final AssetsReporterService assetsReporterService;
@Override @Override
public Float handleIndicator(String assessUserId) { public Float handleIndicator(String assessUserId) {
List<AssetsReporter> reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); List<AssetsReporter> reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId);
//获取最初、最后交易的信息 //获取最初、最后交易的信息
LastAndFirstAssetsDto lastAndFirstAssetsDto = IndicatorsUtils.getLastAndFirstAssetsDto(reporterList); LastAndFirstAssetsDto lastAndFirstAssetsDto = IndicatorsUtils.getLastAndFirstAssetsDto(reporterList);

@ -1,14 +1,13 @@
package com.blockchain.server.yyyf.indicators.handle; package com.blockchain.server.yyyf.indicators.handle;
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; import com.blockchain.server.yyyf.indicators.IndicatorsHandler;
import com.blockchain.server.yyyf.indicators.IndicatorsManager;
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; import com.blockchain.server.yyyf.indicators.dto.AssetsReporter;
import com.blockchain.server.yyyf.service.AssetsReporterService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.persistence.EntityExistsException; import javax.persistence.EntityExistsException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
@ -21,11 +20,11 @@ public class MaxDrawdownRateIndicatorsHandler implements IndicatorsHandler {
public static final String HANDLER_NAME = "MaxDrawdownRate"; public static final String HANDLER_NAME = "MaxDrawdownRate";
private final IndicatorsManager indicatorsManager; private final AssetsReporterService assetsReporterService;
@Override @Override
public Float handleIndicator(String assessUserId) { public Float handleIndicator(String assessUserId) {
List<AssetsReporter> reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); List<AssetsReporter> reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId);
if (reporterList != null && reporterList.size() > 0) { if (reporterList != null && reporterList.size() > 0) {
//排序 //排序
reporterList.sort(Comparator.comparingLong(AssetsReporter::getDays)); reporterList.sort(Comparator.comparingLong(AssetsReporter::getDays));

@ -1,8 +1,8 @@
package com.blockchain.server.yyyf.indicators.handle; package com.blockchain.server.yyyf.indicators.handle;
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; import com.blockchain.server.yyyf.indicators.IndicatorsHandler;
import com.blockchain.server.yyyf.indicators.IndicatorsManager;
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; import com.blockchain.server.yyyf.indicators.dto.AssetsReporter;
import com.blockchain.server.yyyf.service.AssetsReporterService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -17,11 +17,11 @@ import java.util.List;
@Component(MaxLossRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) @Component(MaxLossRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME)
public class MaxLossRateIndicatorsHandler implements IndicatorsHandler { public class MaxLossRateIndicatorsHandler implements IndicatorsHandler {
public static final String HANDLER_NAME = "MaxLossRate"; public static final String HANDLER_NAME = "MaxLossRate";
private final IndicatorsManager indicatorsManager; private final AssetsReporterService assetsReporterService;
@Override @Override
public Float handleIndicator(String assessUserId) { public Float handleIndicator(String assessUserId) {
List<AssetsReporter> reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); List<AssetsReporter> reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId);
if (reporterList != null && reporterList.size() > 0) { if (reporterList != null && reporterList.size() > 0) {
//如果期初资产 //如果期初资产

@ -1,14 +1,13 @@
package com.blockchain.server.yyyf.indicators.handle; package com.blockchain.server.yyyf.indicators.handle;
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; import com.blockchain.server.yyyf.indicators.IndicatorsHandler;
import com.blockchain.server.yyyf.indicators.IndicatorsManager;
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; import com.blockchain.server.yyyf.indicators.dto.AssetsReporter;
import com.blockchain.server.yyyf.service.AssetsReporterService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.persistence.EntityExistsException; import javax.persistence.EntityExistsException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
@ -20,12 +19,12 @@ import java.util.List;
public class ProfitLossRateRateIndicatorsHandler implements IndicatorsHandler { public class ProfitLossRateRateIndicatorsHandler implements IndicatorsHandler {
public static final String HANDLER_NAME = "ProfitLossRate"; public static final String HANDLER_NAME = "ProfitLossRate";
private final IndicatorsManager indicatorsManager; private final AssetsReporterService assetsReporterService;
@Override @Override
public Float handleIndicator(String assessUserId) { public Float handleIndicator(String assessUserId) {
List<AssetsReporter> reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); List<AssetsReporter> reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId);
if (reporterList != null && reporterList.size() > 0) { if (reporterList != null && reporterList.size() > 0) {
//排序 //排序
reporterList.sort(Comparator.comparingLong(AssetsReporter::getDays)); reporterList.sort(Comparator.comparingLong(AssetsReporter::getDays));

@ -1,16 +1,15 @@
package com.blockchain.server.yyyf.indicators.handle; package com.blockchain.server.yyyf.indicators.handle;
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; import com.blockchain.server.yyyf.indicators.IndicatorsHandler;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
/** /**
* @author fengyu * @author fengyu
*/ */
@AllArgsConstructor
@Component(ShapeRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) @Component(ShapeRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME)
public class ShapeRateIndicatorsHandler implements IndicatorsHandler { public class ShapeRateIndicatorsHandler implements IndicatorsHandler {
public static final String HANDLER_NAME = "ShapeRate"; public static final String HANDLER_NAME = "ShapeRate";
@ -19,9 +18,11 @@ public class ShapeRateIndicatorsHandler implements IndicatorsHandler {
@Value("${rate.riskFree}") @Value("${rate.riskFree}")
private BigDecimal riskFree; private BigDecimal riskFree;
private final AnnualGrowthRateIndicatorsHandler annualGrowthRateIndicatorsHandler; @Resource(name = AnnualGrowthRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME)
private AnnualGrowthRateIndicatorsHandler annualGrowthRateIndicatorsHandler;
private final FluctuationRateIndicatorsHandler fluctuationRateIndicatorsHandler; @Resource(name = FluctuationRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME)
private FluctuationRateIndicatorsHandler fluctuationRateIndicatorsHandler;
@Override @Override
public Float handleIndicator(String assessUserId) { public Float handleIndicator(String assessUserId) {

@ -1,16 +1,14 @@
package com.blockchain.server.yyyf.indicators.handle; package com.blockchain.server.yyyf.indicators.handle;
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; import com.blockchain.server.yyyf.indicators.IndicatorsHandler;
import com.blockchain.server.yyyf.indicators.IndicatorsManager;
import com.blockchain.server.yyyf.indicators.IndicatorsUtils; import com.blockchain.server.yyyf.indicators.IndicatorsUtils;
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; import com.blockchain.server.yyyf.indicators.dto.AssetsReporter;
import com.blockchain.server.yyyf.indicators.dto.LastAndFirstAssetsDto; import com.blockchain.server.yyyf.indicators.dto.LastAndFirstAssetsDto;
import com.blockchain.server.yyyf.service.AssetsReporterService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.persistence.EntityExistsException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Comparator;
import java.util.List; import java.util.List;
/** /**
@ -21,11 +19,11 @@ import java.util.List;
public class TotalGrowthRateIndicatorsHandler implements IndicatorsHandler { public class TotalGrowthRateIndicatorsHandler implements IndicatorsHandler {
public static final String HANDLER_NAME = "TotalGrowthRate"; public static final String HANDLER_NAME = "TotalGrowthRate";
private final IndicatorsManager indicatorsManager; private final AssetsReporterService assetsReporterService;
@Override @Override
public Float handleIndicator(String assessUserId) { public Float handleIndicator(String assessUserId) {
List<AssetsReporter> reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); List<AssetsReporter> reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId);
//获取最初、最后交易的信息 //获取最初、最后交易的信息
LastAndFirstAssetsDto lastAndFirstAssetsDto = IndicatorsUtils.getLastAndFirstAssetsDto(reporterList); LastAndFirstAssetsDto lastAndFirstAssetsDto = IndicatorsUtils.getLastAndFirstAssetsDto(reporterList);

@ -0,0 +1,15 @@
package com.blockchain.server.yyyf.mapper;
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;
@Repository
public interface AssetsReporterMapper extends Mapper<AssetsReporter> {
List<AssetsReporter> selectByAssessUserId(String assessUserId);
void insertBatch(List<AssetsReporter> list);
}

@ -0,0 +1,26 @@
package com.blockchain.server.yyyf.service;
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter;
import java.util.List;
public interface AssetsReporterService {
/**
* save assets reporter item
*
* @param assetsReporterList assetsReporter list
* @author fengyu.wang
* @date 2020-06-05 21:37:21
*/
void saveList(List<AssetsReporter> assetsReporterList);
/**
* select assetsReporter list by assessUserId
*
* @param assessUserId exam result id
* @return assetsReporter list
* @author fengyu.wang
* @date 2020-06-05 21:38:09
*/
List<AssetsReporter> selectAssetsReporterListByAssessUserId(String assessUserId);
}

@ -0,0 +1,40 @@
package com.blockchain.server.yyyf.service.impl;
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter;
import com.blockchain.server.yyyf.mapper.AssetsReporterMapper;
import com.blockchain.server.yyyf.service.AssetsReporterService;
import lombok.AllArgsConstructor;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
/**
* @author fengyu
*/
@Service
@AllArgsConstructor
public class AssetsReporterServiceImpl implements AssetsReporterService {
private final AssetsReporterMapper assetsReporterMapper;
private final CacheManager cacheManager;
public static final String CACHE_ASSETS_REPORTER = "yyyf_assets_reporter";
public static final String CACHE_KEY_ASSETS_REPORTER = "yyyf:assetsReporter:";
@Override
public void saveList(List<AssetsReporter> assetsReporterList) {
assetsReporterList.forEach(assetsReporter ->
Optional.ofNullable(cacheManager.getCache(CACHE_ASSETS_REPORTER))
.ifPresent(cache -> cache.evict(CACHE_KEY_ASSETS_REPORTER.concat(assetsReporter.getAssessUserId()))));
assetsReporterMapper.insertBatch(assetsReporterList);
}
@Override
@Cacheable(cacheNames = CACHE_ASSETS_REPORTER,
key = "#root.target.CACHE_KEY_ASSETS_REPORTER.concat(#assessUserId)", unless = "#result == null")
public List<AssetsReporter> selectAssetsReporterListByAssessUserId(String assessUserId) {
return assetsReporterMapper.selectByAssessUserId(assessUserId);
}
}

@ -7,6 +7,8 @@ import com.blockchain.server.yyyf.dto.UserTimeMoneyDto;
import com.blockchain.server.yyyf.indicators.IndicatorsManager; import com.blockchain.server.yyyf.indicators.IndicatorsManager;
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; import com.blockchain.server.yyyf.indicators.dto.AssetsReporter;
import com.blockchain.server.yyyf.service.AssessUserService; import com.blockchain.server.yyyf.service.AssessUserService;
import com.blockchain.server.yyyf.service.AssetsReporterService;
import com.blockchain.server.yyyf.utils.IdGenerator;
import lombok.AllArgsConstructor; 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;
@ -26,6 +28,7 @@ public class ExamProcessTask {
private final AssessUserService assessUserService; private final AssessUserService assessUserService;
private final IndicatorsManager indicatorsManager; private final IndicatorsManager indicatorsManager;
private final AssetsReporterService assetsReporterService;
@Scheduled(cron = "0 1 0 * * ?") @Scheduled(cron = "0 1 0 * * ?")
public void processRecording() { public void processRecording() {
@ -35,6 +38,7 @@ public class ExamProcessTask {
userTimeMoneyList.forEach(entity -> { userTimeMoneyList.forEach(entity -> {
BigDecimal assets = indicatorsManager.calculateCurrentTotalAssets(entity.getQUserId()); BigDecimal assets = indicatorsManager.calculateCurrentTotalAssets(entity.getQUserId());
assetsReporterList.add(AssetsReporter.builder() assetsReporterList.add(AssetsReporter.builder()
.id(IdGenerator.uuid())
.assessUserId(entity.getAssessUserId()) .assessUserId(entity.getAssessUserId())
.assets(assets) .assets(assets)
.days(DateUtil.between(entity.getStartTime(), now, DateUnit.DAY)) .days(DateUtil.between(entity.getStartTime(), now, DateUnit.DAY))
@ -42,6 +46,8 @@ public class ExamProcessTask {
.createTime(now) .createTime(now)
.build()); .build());
}); });
indicatorsManager.saveAssetsReporter(assetsReporterList); if (!assetsReporterList.isEmpty()) {
assetsReporterService.saveList(assetsReporterList);
}
} }
} }

@ -29,3 +29,4 @@ yyyf:
assessment: /api/db/v1.0/assessment assessment: /api/db/v1.0/assessment
#成绩同步(整场考试) #成绩同步(整场考试)
assessmentList: /api/db/v1.0/assessmentList assessmentList: /api/db/v1.0/assessmentList

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.blockchain.server.yyyf.mapper.AssetsReporterMapper">
<resultMap id="BaseResultMap" type="com.blockchain.server.yyyf.indicators.dto.AssetsReporter">
<id column="id" property="id" jdbcType="VARCHAR"/>
<result column="assess_user_id" property="assessUserId" jdbcType="VARCHAR"/>
<result column="coin_name" property="coinName" jdbcType="VARCHAR"/>
<result column="days" property="days" jdbcType="INTEGER"/>
<result column="assets" property="assets" jdbcType="DECIMAL"/>
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id, assess_user_id, coin_name, days, assets, create_time
</sql>
<insert id="insertBatch" parameterType="java.util.List">
insert into yyyf_assets_reporter
(<include refid="Base_Column_List"/>)
values
<foreach collection="list" item="assetsReporter" index="index" separator=",">
(
#{assetsReporter.id},
#{assetsReporter.assess_user_id},
#{assetsReporter.coin_name},
#{assetsReporter.days},
#{assetsReporter.assets},
#{assetsReporter.create_time}
)
</foreach>
</insert>
<select id="selectByAssessUserId" resultMap="BaseResultMap" parameterType="java.lang.String">
select
<include refid="Base_Column_List"/>
from yyyf_assets_reporter
where assess_user_id = #{assessUserId,jdbcType=VARCHAR}
</select>
</mapper>
Loading…
Cancel
Save