From 3b31e14e178f73fdb2605436cbd5f544ddc2de02 Mon Sep 17 00:00:00 2001 From: Helius <wangdoubleone@gmail.com> Date: Fri, 07 Aug 2020 17:02:25 +0800 Subject: [PATCH] modify --- src/main/java/com/xcong/excoin/quartz/job/FollowProfitUpdateJob.java | 64 ++++++++++++++++++++++++++++++++ 1 files changed, 64 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/xcong/excoin/quartz/job/FollowProfitUpdateJob.java b/src/main/java/com/xcong/excoin/quartz/job/FollowProfitUpdateJob.java index bb155af..c396ee9 100644 --- a/src/main/java/com/xcong/excoin/quartz/job/FollowProfitUpdateJob.java +++ b/src/main/java/com/xcong/excoin/quartz/job/FollowProfitUpdateJob.java @@ -1,6 +1,23 @@ package com.xcong.excoin.quartz.job; +import cn.hutool.core.collection.CollUtil; +import com.xcong.excoin.modules.contract.dao.ContractOrderDao; +import com.xcong.excoin.modules.contract.entity.ContractOrderEntity; +import com.xcong.excoin.modules.documentary.dao.FollowFollowerOrderRelationDao; +import com.xcong.excoin.modules.documentary.dao.FollowFollowerProfitDao; +import com.xcong.excoin.modules.documentary.dao.FollowTraderInfoDao; +import com.xcong.excoin.modules.documentary.dao.FollowTraderProfitInfoDao; +import com.xcong.excoin.modules.documentary.entity.FollowTraderInfoEntity; +import com.xcong.excoin.modules.documentary.entity.FollowTraderProfitInfoEntity; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.util.List; /** * @@ -8,11 +25,58 @@ * @author wzy * @date 2020-08-06 **/ +@Slf4j @Component +@ConditionalOnProperty(prefix = "app", name = "loop-job", havingValue = "true") public class FollowProfitUpdateJob { + @Resource + private FollowTraderInfoDao followTraderInfoDao; + @Resource + private FollowFollowerProfitDao followFollowerProfitDao; + @Resource + private ContractOrderDao contractOrderDao; + @Resource + private FollowFollowerOrderRelationDao followFollowerOrderRelationDao; + @Resource + private FollowTraderProfitInfoDao followTraderProfitInfoDao; + @Scheduled(cron = "0 0/30 * * * ? ") public void traderProfitUpdate() { + log.info("交易员定时任务执行"); + // 查询所有交易员信息 + List<FollowTraderInfoEntity> allTraders = followTraderInfoDao.selectAllTraderInfo(); + if (CollUtil.isNotEmpty(allTraders)) { + for (FollowTraderInfoEntity trader : allTraders) { + Long tradeMemberId = trader.getMemberId(); + FollowTraderProfitInfoEntity traderInfoProfit = followTraderProfitInfoDao.selectTraderInfoProfitByMemberId(tradeMemberId); + // 累计收益率 + BigDecimal totalProfitRatio = contractOrderDao.selectFollowOrderTotalProfitByMemberId(tradeMemberId); + traderInfoProfit.setTotalProfitRatio(totalProfitRatio); + // 带单总收益 + BigDecimal totalProfit = followFollowerOrderRelationDao.selectTraderTotalProfit(tradeMemberId); + traderInfoProfit.setTotalProfit(totalProfit); + // 交易笔数 + List<ContractOrderEntity> orders = contractOrderDao.selectFollowOrderByMemberId(tradeMemberId); + traderInfoProfit.setTotalOrderCnt(CollUtil.isNotEmpty(orders) ? orders.size() : 0); + // 近三周胜率 + Integer winCnt = contractOrderDao.selectFollowOrderCntForWinRate(tradeMemberId, 1); + Integer allCnt = contractOrderDao.selectFollowOrderCntForWinRate(tradeMemberId, null); + if (winCnt != null && allCnt != null && allCnt!=0) { + BigDecimal winRate = BigDecimal.valueOf(winCnt).divide(BigDecimal.valueOf(allCnt), 4, BigDecimal.ROUND_DOWN); + traderInfoProfit.setWinRate(winRate); + } + + // 跟随者总收益 + BigDecimal followerProfit = followFollowerProfitDao.selectAllFollowerProfit(tradeMemberId); + traderInfoProfit.setFollowerTotalProfit(followerProfit); + // 累计跟随人数 + int followerCnt = followFollowerProfitDao.selectFollowerCntByTradeMemberId(tradeMemberId); + traderInfoProfit.setTotalFollowerCnt(followerCnt); + + followTraderProfitInfoDao.updateById(traderInfoProfit); + } + } } } -- Gitblit v1.9.1