From c865fa836fe9146754094eb135d10ca90588afba Mon Sep 17 00:00:00 2001 From: xiaoyong931011 <15274802129@163.com> Date: Tue, 06 Apr 2021 16:12:28 +0800 Subject: [PATCH] 20210406 交易员列表查询 --- src/main/resources/mapper/contract/ContractOrderDao.xml | 4 src/main/java/com/xcong/excoin/quartz/job/FollowProfitUpdateJob.java | 2 src/test/java/com/xcong/excoin/LocalTest.java | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 177 insertions(+), 3 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 0977da0..e005fc5 100644 --- a/src/main/java/com/xcong/excoin/quartz/job/FollowProfitUpdateJob.java +++ b/src/main/java/com/xcong/excoin/quartz/job/FollowProfitUpdateJob.java @@ -102,7 +102,7 @@ } Date date = new Date(); DateTime offsetDay = DateUtil.offsetDay(new Date(), -30); - //30天胜率(30天盈利总张数/30平仓总张数) + //30天胜率(30天盈利总单数/30平仓总单数) BigDecimal thirtyTotalCnt = contractOrderDao.selectThirtyTotalCntByMemberId(tradeMemberId,date,offsetDay); BigDecimal thirtyWinCnt = contractOrderDao.selectThirtyWinCntByMemberId(tradeMemberId,date,offsetDay); BigDecimal thirtyTotalCntRatio = (thirtyTotalCnt == null?BigDecimal.ZERO:thirtyTotalCnt.setScale(2, BigDecimal.ROUND_DOWN)); diff --git a/src/main/resources/mapper/contract/ContractOrderDao.xml b/src/main/resources/mapper/contract/ContractOrderDao.xml index 4df2c4c..730ca5f 100644 --- a/src/main/resources/mapper/contract/ContractOrderDao.xml +++ b/src/main/resources/mapper/contract/ContractOrderDao.xml @@ -128,7 +128,7 @@ </select> <select id="selectThirtyTotalCntByMemberId" resultType="java.math.BigDecimal"> - select sum(symbol_cnt)/2 + select count(id)/2 from contract_order where member_id=#{memberId} @@ -137,7 +137,7 @@ </select> <select id="selectThirtyWinCntByMemberId" resultType="java.math.BigDecimal"> - select sum(symbol_cnt)/2 + select count(id)/2 from contract_order where member_id=#{memberId} diff --git a/src/test/java/com/xcong/excoin/LocalTest.java b/src/test/java/com/xcong/excoin/LocalTest.java new file mode 100644 index 0000000..03b5c02 --- /dev/null +++ b/src/test/java/com/xcong/excoin/LocalTest.java @@ -0,0 +1,174 @@ +package com.xcong.excoin; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.annotation.Resource; + +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import com.xcong.excoin.modules.contract.entity.ContractOrderEntity; +import org.springframework.boot.test.context.SpringBootTest; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.xcong.excoin.common.LoginUserUtils; +import com.xcong.excoin.common.response.Result; +import com.xcong.excoin.modules.coin.dao.OrderCoinsDao; +import com.xcong.excoin.modules.contract.dao.ContractHoldOrderDao; +import com.xcong.excoin.modules.contract.dao.ContractOrderDao; +import com.xcong.excoin.modules.documentary.dao.FollowFollowerNoticeDao; +import com.xcong.excoin.modules.documentary.dao.FollowFollowerOrderRelationDao; +import com.xcong.excoin.modules.documentary.dao.FollowFollowerProfitDao; +import com.xcong.excoin.modules.documentary.dao.FollowFollowerSettingDao; +import com.xcong.excoin.modules.documentary.dao.FollowTraderInfoDao; +import com.xcong.excoin.modules.documentary.dao.FollowTraderLabelDao; +import com.xcong.excoin.modules.documentary.dao.FollowTraderProfitDetailDao; +import com.xcong.excoin.modules.documentary.dao.FollowTraderProfitInfoDao; +import com.xcong.excoin.modules.documentary.dto.FollowTraderProfitInfoDto; +import com.xcong.excoin.modules.documentary.entity.FollowFollowerProfitEntity; +import com.xcong.excoin.modules.documentary.entity.FollowFollowerSettingEntity; +import com.xcong.excoin.modules.documentary.entity.FollowTraderInfoEntity; +import com.xcong.excoin.modules.documentary.entity.FollowTraderLabelEntity; +import com.xcong.excoin.modules.documentary.entity.FollowTraderProfitInfoEntity; +import com.xcong.excoin.modules.documentary.vo.FollowTraderProfitInfoVo; +import com.xcong.excoin.modules.documentary.vo.TradeProfitInfoVo; +import com.xcong.excoin.modules.member.dao.MemberDao; +import com.xcong.excoin.modules.member.dao.MemberLevelRateDao; +import com.xcong.excoin.modules.member.dao.MemberSettingDao; +import com.xcong.excoin.modules.member.dao.MemberWalletContractDao; +import com.xcong.excoin.modules.member.entity.MemberEntity; +import com.xcong.excoin.utils.CacheSettingUtils; +import com.xcong.excoin.utils.RedisUtils; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Test; + +@Slf4j +@SpringBootTest +public class LocalTest { + + @Resource + private MemberDao memberDao; + @Resource + private FollowTraderInfoDao followTraderInfoDao; + @Resource + private FollowTraderProfitDetailDao followTraderProfitDetailDao; + @Resource + private FollowTraderProfitInfoDao followTraderProfitInfoDao; + @Resource + private FollowFollowerProfitDao followFollowerProfitDao; + @Resource + private OrderCoinsDao orderCoinsDao; + @Resource + private RedisUtils redisUtils; + @Resource + private CacheSettingUtils cacheSettingUtils; + @Resource + private ContractHoldOrderDao contractHoldOrderDao; + @Resource + private ContractOrderDao contractOrderDao; + @Resource + private MemberLevelRateDao memberLevelRateDao; + @Resource + private MemberWalletContractDao memberWalletContractDao; + @Resource + private FollowFollowerSettingDao followFollowerSettingDao; + @Resource + private FollowFollowerOrderRelationDao followFollowerOrderRelationDao; + @Resource + private FollowFollowerNoticeDao followFollowerNoticeDao; + @Resource + private FollowTraderLabelDao followTraderLabelDao; + @Resource + private MemberSettingDao memberSettingDao; + + @Test + public void traderProfitUpdate() { + log.info("交易员定时任务执行"); + // 查询所有交易员信息 + List<FollowTraderInfoEntity> allTraders = followTraderInfoDao.selectAllTraderInfo(); + if (CollUtil.isNotEmpty(allTraders)) { + for (FollowTraderInfoEntity trader : allTraders) { + Long tradeMemberId = trader.getMemberId(); + //获取交易员的当前跟随者 + Map<String, Object> hashMap = new HashMap<>(); + hashMap.put("trade_member_id", tradeMemberId); + hashMap.put("is_follow", FollowFollowerProfitEntity.IS_FOLLOW_Y); + List<FollowFollowerProfitEntity> followFollowerProfitEntityList = followFollowerProfitDao.selectByMap(hashMap); + if(CollUtil.isNotEmpty(followFollowerProfitEntityList)) { + for(FollowFollowerProfitEntity followFollowerProfitEntity : followFollowerProfitEntityList) { + //获取当前跟随者的跟随本金 + Long memberId = followFollowerProfitEntity.getMemberId(); + BigDecimal sumBondAmountBigDecimal = followFollowerProfitDao.selectSumBondAmountBymemberId(memberId,trader.getId()); + sumBondAmountBigDecimal = (sumBondAmountBigDecimal == null?BigDecimal.ZERO:sumBondAmountBigDecimal.setScale(2, BigDecimal.ROUND_DOWN)); + followFollowerProfitEntity.setTotalPrincipal(sumBondAmountBigDecimal); + //获取当前的盈亏 + BigDecimal sumRewardAmountBigDecimal = followFollowerProfitDao.selectSumRewardAmountByMemberId(memberId,trader.getId()); + sumRewardAmountBigDecimal = (sumRewardAmountBigDecimal == null?BigDecimal.ZERO:sumRewardAmountBigDecimal.setScale(2, BigDecimal.ROUND_DOWN)); + followFollowerProfitEntity.setTotalProfit(sumRewardAmountBigDecimal); + followFollowerProfitDao.updateById(followFollowerProfitEntity); + } + } + + + FollowTraderProfitInfoEntity traderInfoProfit = followTraderProfitInfoDao.selectTraderInfoProfitByMemberId(tradeMemberId); + // 累计收益率 + BigDecimal ljsyl = contractOrderDao.selectFollowOrderTotalProfitByMemberId(tradeMemberId); + BigDecimal totalProfitRatio = (ljsyl == null?BigDecimal.ZERO:ljsyl.setScale(2, BigDecimal.ROUND_DOWN)); + traderInfoProfit.setTotalProfitRatio(totalProfitRatio); + // 带单总收益,只查询交易员自己的带单总收益 + BigDecimal totalProfit = followFollowerOrderRelationDao.selectTraderTotalProfitSelf(tradeMemberId); + //BigDecimal totalProfit = followFollowerOrderRelationDao.selectTraderTotalProfit(tradeMemberId); + traderInfoProfit.setTotalProfit(totalProfit); + // 交易笔数 +// List<ContractOrderEntity> orders = contractOrderDao.selectFollowOrderByMemberId(tradeMemberId); + List<ContractOrderEntity> orders = contractOrderDao.selectFollowOrderListByMemberId(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); + } + Date date = new Date(); + DateTime offsetDay = DateUtil.offsetDay(new Date(), -30); + //30天胜率(30天盈利总单数/30平仓总单数) + BigDecimal thirtyTotalCnt = contractOrderDao.selectThirtyTotalCntByMemberId(tradeMemberId,date,offsetDay); + BigDecimal thirtyWinCnt = contractOrderDao.selectThirtyWinCntByMemberId(tradeMemberId,date,offsetDay); + BigDecimal thirtyTotalCntRatio = (thirtyTotalCnt == null?BigDecimal.ZERO:thirtyTotalCnt.setScale(2, BigDecimal.ROUND_DOWN)); + BigDecimal thirtyWinCntRatio = (thirtyWinCnt == null?BigDecimal.ZERO:thirtyWinCnt.setScale(2, BigDecimal.ROUND_DOWN)); + BigDecimal thirtyProfitRatio = BigDecimal.ZERO.setScale(2, BigDecimal.ROUND_DOWN);; + if(thirtyTotalCnt.compareTo(BigDecimal.ZERO) > 0) { + thirtyProfitRatio = thirtyWinCntRatio.divide(thirtyTotalCntRatio, 2, BigDecimal.ROUND_DOWN).setScale(2, BigDecimal.ROUND_DOWN); + } + traderInfoProfit.setThirtyProfitRatio(thirtyProfitRatio); + //30天最大回撤率(30天最高收益率-30天最低收益率) + BigDecimal thirtyMaxRatio = contractOrderDao.selectThirtyMaxRatioByMemberId(tradeMemberId,date,offsetDay); + BigDecimal thirtyMinRatio = contractOrderDao.selectThirtyMinRatioByMemberId(tradeMemberId,date,offsetDay); + BigDecimal thirtyRatio = (thirtyMaxRatio == null?BigDecimal.ZERO:thirtyMaxRatio.setScale(2, BigDecimal.ROUND_DOWN)) + .subtract((thirtyMinRatio == null?BigDecimal.ZERO:thirtyMinRatio.setScale(2, BigDecimal.ROUND_DOWN))); + traderInfoProfit.setThirtyRatio(thirtyRatio); + // 当前跟随者总收益 + BigDecimal followerProfit = followFollowerProfitDao.selectAllFollowerProfit(tradeMemberId); + traderInfoProfit.setFollowerTotalProfit(followerProfit); + // 当前跟随人数 + int followerCnt = followFollowerProfitDao.selectFollowerCntByTradeMemberId(tradeMemberId); + traderInfoProfit.setTotalFollowerCnt(followerCnt); + + followTraderProfitInfoDao.updateById(traderInfoProfit); + } + } + } + +} -- Gitblit v1.9.1