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 index 3253952..a212e4d 100644 --- 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 @@ -2,7 +2,6 @@ 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; @@ -22,17 +21,6 @@ public class DefaultIndicatorsManager implements IndicatorsManager { private final ApplicationContext applicationContext; 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); 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 4118f70..8fbc58c 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 @@ -1,33 +1,12 @@ 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 - */ - void saveAssetsReporter(List 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 getAssetsReporterListByAssessUserId(String assessUserId); /** * calculate indicator by full exam 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 273e6f7..6484dcf 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 @@ -19,6 +19,10 @@ import java.util.Date; @NoArgsConstructor @AllArgsConstructor public class AssetsReporter { + /** + * primary key + */ + private String id; /** * 成绩id */ diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/AnnualGrowthRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/AnnualGrowthRateIndicatorsHandler.java index d9851bd..0578f9f 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/AnnualGrowthRateIndicatorsHandler.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/AnnualGrowthRateIndicatorsHandler.java @@ -1,11 +1,12 @@ 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.IndicatorsUtils; import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; import com.blockchain.server.yyyf.indicators.dto.LastAndFirstAssetsDto; +import com.blockchain.server.yyyf.service.AssetsReporterService; import lombok.AllArgsConstructor; +import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Component; import java.math.BigDecimal; @@ -18,23 +19,26 @@ import java.util.List; @Component(AnnualGrowthRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) public class AnnualGrowthRateIndicatorsHandler implements IndicatorsHandler { 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 + @Cacheable(cacheNames = CACHE_ANNUAL_GROWTH_RATE, + key = "#root.target.CACHE_KEY_ANNUAL_GROWTH_RATE.concat(#assessUserId)", unless = "#result == null") public Float handleIndicator(String assessUserId) { - //TODO should be cached - List reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); + List reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); //获取最初、最后交易的信息 LastAndFirstAssetsDto lastAndFirstAssetsDto = IndicatorsUtils.getLastAndFirstAssetsDto(reporterList); - AssetsReporter lastAssets =lastAndFirstAssetsDto.getLastAssets(); - AssetsReporter firstAssets =lastAndFirstAssetsDto.getFirstAssets(); + AssetsReporter lastAssets = lastAndFirstAssetsDto.getLastAssets(); + AssetsReporter firstAssets = lastAndFirstAssetsDto.getFirstAssets(); BigDecimal result = lastAssets.getAssets() .divide(firstAssets.getAssets(), 5, BigDecimal.ROUND_HALF_UP) .pow((int) (360.0 / lastAssets.getDays())) .subtract(BigDecimal.valueOf(1)); - return result.divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP).floatValue(); + return result.multiply(BigDecimal.valueOf(100)).floatValue(); } } diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/FluctuationRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/FluctuationRateIndicatorsHandler.java index 326a5ca..facc38d 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/FluctuationRateIndicatorsHandler.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/FluctuationRateIndicatorsHandler.java @@ -1,9 +1,10 @@ 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 com.blockchain.server.yyyf.service.AssetsReporterService; import lombok.AllArgsConstructor; +import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Component; import javax.persistence.EntityExistsException; @@ -19,12 +20,16 @@ import java.util.List; @Component(FluctuationRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) public class FluctuationRateIndicatorsHandler implements IndicatorsHandler { 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 + @Cacheable(cacheNames = CACHE_FLUCTUATION_RATE, + key = "#root.target.CACHE_KEY_FLUCTUATION_RATE.concat(#assessUserId)", unless = "#result == null") public Float handleIndicator(String assessUserId) { - List reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); + List reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); if (reporterList != null && reporterList.size() > 0) { //排序 reporterList.sort(Comparator.comparingLong(AssetsReporter::getDays)); diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/GrowthRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/GrowthRateIndicatorsHandler.java index 7c93d1e..b2408f3 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/GrowthRateIndicatorsHandler.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/GrowthRateIndicatorsHandler.java @@ -1,10 +1,10 @@ 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.IndicatorsUtils; import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; import com.blockchain.server.yyyf.indicators.dto.LastAndFirstAssetsDto; +import com.blockchain.server.yyyf.service.AssetsReporterService; import lombok.AllArgsConstructor; import org.springframework.stereotype.Component; @@ -19,11 +19,11 @@ import java.util.List; public class GrowthRateIndicatorsHandler implements IndicatorsHandler { public static final String HANDLER_NAME = "GrowthRate"; - private final IndicatorsManager indicatorsManager; + private final AssetsReporterService assetsReporterService; @Override public Float handleIndicator(String assessUserId) { - List reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); + List reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); //获取最初、最后交易的信息 LastAndFirstAssetsDto lastAndFirstAssetsDto = IndicatorsUtils.getLastAndFirstAssetsDto(reporterList); diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxDrawdownRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxDrawdownRateIndicatorsHandler.java index e1fffcd..8dbe567 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxDrawdownRateIndicatorsHandler.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxDrawdownRateIndicatorsHandler.java @@ -1,14 +1,13 @@ 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 com.blockchain.server.yyyf.service.AssetsReporterService; import lombok.AllArgsConstructor; import org.springframework.stereotype.Component; import javax.persistence.EntityExistsException; import java.math.BigDecimal; -import java.util.ArrayList; import java.util.Comparator; import java.util.List; @@ -21,11 +20,11 @@ public class MaxDrawdownRateIndicatorsHandler implements IndicatorsHandler { public static final String HANDLER_NAME = "MaxDrawdownRate"; - private final IndicatorsManager indicatorsManager; + private final AssetsReporterService assetsReporterService; @Override public Float handleIndicator(String assessUserId) { - List reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); + List reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); if (reporterList != null && reporterList.size() > 0) { //排序 reporterList.sort(Comparator.comparingLong(AssetsReporter::getDays)); diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxLossRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxLossRateIndicatorsHandler.java index dad8f98..a4f42e3 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxLossRateIndicatorsHandler.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/MaxLossRateIndicatorsHandler.java @@ -1,8 +1,8 @@ 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 com.blockchain.server.yyyf.service.AssetsReporterService; import lombok.AllArgsConstructor; import org.springframework.stereotype.Component; @@ -17,11 +17,11 @@ import java.util.List; @Component(MaxLossRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) public class MaxLossRateIndicatorsHandler implements IndicatorsHandler { public static final String HANDLER_NAME = "MaxLossRate"; - private final IndicatorsManager indicatorsManager; + private final AssetsReporterService assetsReporterService; @Override public Float handleIndicator(String assessUserId) { - List reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); + List reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); if (reporterList != null && reporterList.size() > 0) { //如果期初资产 diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ProfitLossRateRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ProfitLossRateRateIndicatorsHandler.java index 980bac0..c5aa1c7 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ProfitLossRateRateIndicatorsHandler.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ProfitLossRateRateIndicatorsHandler.java @@ -1,14 +1,13 @@ 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 com.blockchain.server.yyyf.service.AssetsReporterService; import lombok.AllArgsConstructor; import org.springframework.stereotype.Component; import javax.persistence.EntityExistsException; import java.math.BigDecimal; -import java.util.ArrayList; import java.util.Comparator; import java.util.List; @@ -20,12 +19,12 @@ import java.util.List; public class ProfitLossRateRateIndicatorsHandler implements IndicatorsHandler { public static final String HANDLER_NAME = "ProfitLossRate"; - private final IndicatorsManager indicatorsManager; + private final AssetsReporterService assetsReporterService; @Override public Float handleIndicator(String assessUserId) { - List reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); + List reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); if (reporterList != null && reporterList.size() > 0) { //排序 reporterList.sort(Comparator.comparingLong(AssetsReporter::getDays)); diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ShapeRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ShapeRateIndicatorsHandler.java index 1d3a1a8..0f4d64d 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ShapeRateIndicatorsHandler.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/ShapeRateIndicatorsHandler.java @@ -1,16 +1,15 @@ package com.blockchain.server.yyyf.indicators.handle; import com.blockchain.server.yyyf.indicators.IndicatorsHandler; -import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; +import javax.annotation.Resource; import java.math.BigDecimal; /** * @author fengyu */ -@AllArgsConstructor @Component(ShapeRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) public class ShapeRateIndicatorsHandler implements IndicatorsHandler { public static final String HANDLER_NAME = "ShapeRate"; @@ -19,9 +18,11 @@ public class ShapeRateIndicatorsHandler implements IndicatorsHandler { @Value("${rate.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 public Float handleIndicator(String assessUserId) { diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/TotalGrowthRateIndicatorsHandler.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/TotalGrowthRateIndicatorsHandler.java index 6be2247..4fe2f31 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/TotalGrowthRateIndicatorsHandler.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/TotalGrowthRateIndicatorsHandler.java @@ -1,16 +1,14 @@ 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.IndicatorsUtils; import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; import com.blockchain.server.yyyf.indicators.dto.LastAndFirstAssetsDto; +import com.blockchain.server.yyyf.service.AssetsReporterService; import lombok.AllArgsConstructor; import org.springframework.stereotype.Component; -import javax.persistence.EntityExistsException; import java.math.BigDecimal; -import java.util.Comparator; import java.util.List; /** @@ -21,11 +19,11 @@ import java.util.List; public class TotalGrowthRateIndicatorsHandler implements IndicatorsHandler { public static final String HANDLER_NAME = "TotalGrowthRate"; - private final IndicatorsManager indicatorsManager; + private final AssetsReporterService assetsReporterService; @Override public Float handleIndicator(String assessUserId) { - List reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); + List reporterList = assetsReporterService.selectAssetsReporterListByAssessUserId(assessUserId); //获取最初、最后交易的信息 LastAndFirstAssetsDto lastAndFirstAssetsDto = IndicatorsUtils.getLastAndFirstAssetsDto(reporterList); diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssetsReporterMapper.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssetsReporterMapper.java new file mode 100644 index 0000000..b512e82 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssetsReporterMapper.java @@ -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 { + + List selectByAssessUserId(String assessUserId); + + void insertBatch(List list); +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssetsReporterService.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssetsReporterService.java new file mode 100644 index 0000000..65ebec0 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/AssetsReporterService.java @@ -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 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 selectAssetsReporterListByAssessUserId(String assessUserId); +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssetsReporterServiceImpl.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssetsReporterServiceImpl.java new file mode 100644 index 0000000..25d895c --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssetsReporterServiceImpl.java @@ -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 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 selectAssetsReporterListByAssessUserId(String assessUserId) { + return assetsReporterMapper.selectByAssessUserId(assessUserId); + } +} 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 d403f62..de72902 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 @@ -7,6 +7,8 @@ import com.blockchain.server.yyyf.dto.UserTimeMoneyDto; 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.AssetsReporterService; +import com.blockchain.server.yyyf.utils.IdGenerator; import lombok.AllArgsConstructor; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; @@ -26,6 +28,7 @@ public class ExamProcessTask { private final AssessUserService assessUserService; private final IndicatorsManager indicatorsManager; + private final AssetsReporterService assetsReporterService; @Scheduled(cron = "0 1 0 * * ?") public void processRecording() { @@ -35,6 +38,7 @@ public class ExamProcessTask { userTimeMoneyList.forEach(entity -> { BigDecimal assets = indicatorsManager.calculateCurrentTotalAssets(entity.getQUserId()); assetsReporterList.add(AssetsReporter.builder() + .id(IdGenerator.uuid()) .assessUserId(entity.getAssessUserId()) .assets(assets) .days(DateUtil.between(entity.getStartTime(), now, DateUnit.DAY)) @@ -42,6 +46,8 @@ public class ExamProcessTask { .createTime(now) .build()); }); - indicatorsManager.saveAssetsReporter(assetsReporterList); + if (!assetsReporterList.isEmpty()) { + assetsReporterService.saveList(assetsReporterList); + } } } diff --git a/blockchain-server/blockchain-server-yyyf/src/main/resources/bootstrap.yml b/blockchain-server/blockchain-server-yyyf/src/main/resources/bootstrap.yml index 8dbe479..9a734a7 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/resources/bootstrap.yml +++ b/blockchain-server/blockchain-server-yyyf/src/main/resources/bootstrap.yml @@ -29,3 +29,4 @@ yyyf: assessment: /api/db/v1.0/assessment #成绩同步(整场考试) assessmentList: /api/db/v1.0/assessmentList + diff --git a/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssetsReporterMapper.xml b/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssetsReporterMapper.xml new file mode 100644 index 0000000..858cb31 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssetsReporterMapper.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + id, assess_user_id, coin_name, days, assets, create_time + + + + insert into yyyf_assets_reporter + () + values + + ( + #{assetsReporter.id}, + #{assetsReporter.assess_user_id}, + #{assetsReporter.coin_name}, + #{assetsReporter.days}, + #{assetsReporter.assets}, + #{assetsReporter.create_time} + ) + + + + +