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; /** * * * @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 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 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); } } } }