From e08d29b508b4bbed9434328284d9939e6ad8b3ce Mon Sep 17 00:00:00 2001 From: xiaoyong931011 <15274802129@163.com> Date: Wed, 29 Jul 2020 19:09:37 +0800 Subject: [PATCH] 20200729 代码提交 --- src/main/java/com/xcong/excoin/modules/documentary/dto/MyFollowTraderInfoDto.java | 22 ++ src/main/java/com/xcong/excoin/modules/documentary/vo/FollowInfoVo.java | 39 +++ src/main/resources/mapper/documentary/FollowFollowerProfitDao.xml | 46 ++++ src/main/java/com/xcong/excoin/modules/documentary/dto/MyFollowOrderDto.java | 31 ++ src/main/java/com/xcong/excoin/modules/documentary/vo/MyFollowOrderVo.java | 54 ++++ src/main/java/com/xcong/excoin/modules/documentary/controller/DocumentaryController.java | 55 ++++ src/main/java/com/xcong/excoin/modules/documentary/service/DocumentaryService.java | 8 src/main/java/com/xcong/excoin/modules/documentary/service/impl/DocumentaryServiceImpl.java | 275 +++++++++++++++++++++++++ src/main/java/com/xcong/excoin/modules/documentary/vo/MyFollowTraderInfoVo.java | 46 ++++ src/main/java/com/xcong/excoin/modules/documentary/dao/FollowFollowerProfitDao.java | 18 + src/main/java/com/xcong/excoin/modules/documentary/vo/FollowRecordsVo.java | 19 - 11 files changed, 592 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/xcong/excoin/modules/documentary/controller/DocumentaryController.java b/src/main/java/com/xcong/excoin/modules/documentary/controller/DocumentaryController.java index 24941bb..81f1bb4 100644 --- a/src/main/java/com/xcong/excoin/modules/documentary/controller/DocumentaryController.java +++ b/src/main/java/com/xcong/excoin/modules/documentary/controller/DocumentaryController.java @@ -4,6 +4,7 @@ import javax.validation.Valid; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -13,9 +14,14 @@ import com.xcong.excoin.modules.coin.parameter.vo.MemberAgentIntoInfoVo; import com.xcong.excoin.modules.documentary.dto.FollowRecordsDto; import com.xcong.excoin.modules.documentary.dto.HistoryOrderRecordsDto; +import com.xcong.excoin.modules.documentary.dto.MyFollowOrderDto; +import com.xcong.excoin.modules.documentary.dto.MyFollowTraderInfoDto; import com.xcong.excoin.modules.documentary.service.DocumentaryService; +import com.xcong.excoin.modules.documentary.vo.FollowInfoVo; import com.xcong.excoin.modules.documentary.vo.FollowRecordsVo; import com.xcong.excoin.modules.documentary.vo.MemberIsTradeVo; +import com.xcong.excoin.modules.documentary.vo.MyFollowOrderVo; +import com.xcong.excoin.modules.documentary.vo.MyFollowTraderInfoVo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -43,11 +49,11 @@ } /** - * 交易员收益信息列表 + * 交易员列表 */ - @ApiOperation(value="getFollowTraderProfitInfo", notes="交易员收益信息列表") + @ApiOperation(value="getFollowTraderProfitInfo", notes="交易员列表") @ApiResponses({@ApiResponse( code = 200, message = "success", response = MemberIsTradeVo.class)}) - @GetMapping(value = "/getFollowTraderProfitInfo") + @PostMapping(value = "/getFollowTraderProfitInfo") public Result getFollowTraderProfitInfo(@RequestBody @Valid RecordsPageDto recordsPageDto) { return documentaryService.getFollowTraderProfitInfo(recordsPageDto); } @@ -58,7 +64,7 @@ */ @ApiOperation(value="getHistoryOrderRecords", notes="历史带单") @ApiResponses({@ApiResponse( code = 200, message = "success", response = MemberAgentIntoInfoVo.class)}) - @GetMapping(value = "/getHistoryOrderRecords") + @PostMapping(value = "/getHistoryOrderRecords") public Result getHistoryOrderRecords(@RequestBody @Valid HistoryOrderRecordsDto historyOrderRecordsDto) { return documentaryService.getHistoryOrderRecords(historyOrderRecordsDto); } @@ -69,11 +75,50 @@ */ @ApiOperation(value="getFollowRecords", notes="跟随者") @ApiResponses({@ApiResponse( code = 200, message = "success", response = FollowRecordsVo.class)}) - @GetMapping(value = "/getFollowRecords") + @PostMapping(value = "/getFollowRecords") public Result getFollowRecords(@RequestBody @Valid FollowRecordsDto followRecordsDto) { return documentaryService.getFollowRecords(followRecordsDto); } + /** + * 我的跟单--头部 + */ + @ApiOperation(value="getFollowInfo", notes="我的跟单--头部") + @ApiResponses({@ApiResponse( code = 200, message = "success", response = FollowInfoVo.class)}) + @GetMapping(value = "/getFollowInfo") + public Result getFollowInfo() { + return documentaryService.getFollowInfo(); + } + + /** + * 我的跟单--我的跟单 + * @return + */ + @ApiOperation(value="getFollowRecords", notes="我的跟单--我的跟单") + @ApiResponses({@ApiResponse( code = 200, message = "success", response = MyFollowOrderVo.class)}) + @PostMapping(value = "/getMyFollowOrderRecords") + public Result getMyFollowOrderRecords(@RequestBody @Valid MyFollowOrderDto myFollowOrderDto) { + return documentaryService.getMyFollowOrderRecords(myFollowOrderDto); + } + + /** + * 我的跟单--我的交易员 + */ + @ApiOperation(value="getMyFollowTraderInfo", notes="我的跟单--我的交易员") + @ApiResponses({@ApiResponse( code = 200, message = "success", response = MyFollowTraderInfoVo.class)}) + @PostMapping(value = "/getMyFollowTraderInfo") + public Result getMyFollowTraderInfo(@RequestBody @Valid MyFollowTraderInfoDto myFollowTraderInfoDto) { + return documentaryService.getMyFollowTraderInfo(myFollowTraderInfoDto); + } + + + + + + + + + diff --git a/src/main/java/com/xcong/excoin/modules/documentary/dao/FollowFollowerProfitDao.java b/src/main/java/com/xcong/excoin/modules/documentary/dao/FollowFollowerProfitDao.java index 0e2e758..86126a7 100644 --- a/src/main/java/com/xcong/excoin/modules/documentary/dao/FollowFollowerProfitDao.java +++ b/src/main/java/com/xcong/excoin/modules/documentary/dao/FollowFollowerProfitDao.java @@ -1,10 +1,14 @@ package com.xcong.excoin.modules.documentary.dao; +import java.util.List; + import org.apache.ibatis.annotations.Param; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.xcong.excoin.modules.contract.entity.ContractHoldOrderEntity; +import com.xcong.excoin.modules.contract.entity.ContractOrderEntity; import com.xcong.excoin.modules.documentary.entity.FollowFollowerProfitEntity; import com.xcong.excoin.modules.documentary.vo.FollowRecordsVo; @@ -13,6 +17,18 @@ */ public interface FollowFollowerProfitDao extends BaseMapper<FollowFollowerProfitEntity> { - IPage<FollowRecordsVo> selectFollowRecords(Page<FollowRecordsVo> page, @Param("tradeMemberId")Long tradeMemberId); + IPage<FollowRecordsVo> selectFollowRecords(Page<FollowRecordsVo> page, + @Param("tradeMemberId")Long tradeMemberId); + + IPage<ContractOrderEntity> getMyFollowOrderHistoryRecords(Page<ContractOrderEntity> page, + @Param("memberId")Long memberId); + + IPage<ContractHoldOrderEntity> getMyFollowOrderNowRecords(Page<ContractHoldOrderEntity> page, + @Param("memberId")Long memberId); + + List<ContractHoldOrderEntity> getFollowOrderNowRecords(@Param("memberId")Long memberId); + + IPage<FollowFollowerProfitEntity> selectFollowFollowerProfitEntitys(Page<FollowFollowerProfitEntity> page, + @Param("memberId")Long memberId); } diff --git a/src/main/java/com/xcong/excoin/modules/documentary/dto/MyFollowOrderDto.java b/src/main/java/com/xcong/excoin/modules/documentary/dto/MyFollowOrderDto.java new file mode 100644 index 0000000..f940068 --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/documentary/dto/MyFollowOrderDto.java @@ -0,0 +1,31 @@ +package com.xcong.excoin.modules.documentary.dto; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +@ApiModel(value = "MyFollowOrderDto", description = "参数接受类") +public class MyFollowOrderDto { + + @NotNull + @Min(1) + @ApiModelProperty(value = "第几页", example = "1") + private int pageNum; + + @NotNull + @ApiModelProperty(value = "每页数量", example = "10") + private int pageSize; + + @NotNull + @ApiModelProperty(value = "会员ID", example = "12543") + private Long memberId; + + @NotNull + @ApiModelProperty(value = "类型 1:当前跟单2:历史跟单", example = "1") + private int orderType; + +} diff --git a/src/main/java/com/xcong/excoin/modules/documentary/dto/MyFollowTraderInfoDto.java b/src/main/java/com/xcong/excoin/modules/documentary/dto/MyFollowTraderInfoDto.java new file mode 100644 index 0000000..916b3f9 --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/documentary/dto/MyFollowTraderInfoDto.java @@ -0,0 +1,22 @@ +package com.xcong.excoin.modules.documentary.dto; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +@ApiModel(value = "MyFollowTraderInfoDto", description = "参数接受类") +public class MyFollowTraderInfoDto { + @NotNull + @Min(1) + @ApiModelProperty(value = "第几页", example = "1") + private int pageNum; + + @NotNull + @ApiModelProperty(value = "每页数量", example = "10") + private int pageSize; + +} diff --git a/src/main/java/com/xcong/excoin/modules/documentary/service/DocumentaryService.java b/src/main/java/com/xcong/excoin/modules/documentary/service/DocumentaryService.java index f58bdc7..72b253a 100644 --- a/src/main/java/com/xcong/excoin/modules/documentary/service/DocumentaryService.java +++ b/src/main/java/com/xcong/excoin/modules/documentary/service/DocumentaryService.java @@ -7,6 +7,8 @@ import com.xcong.excoin.modules.coin.parameter.dto.RecordsPageDto; import com.xcong.excoin.modules.documentary.dto.FollowRecordsDto; import com.xcong.excoin.modules.documentary.dto.HistoryOrderRecordsDto; +import com.xcong.excoin.modules.documentary.dto.MyFollowOrderDto; +import com.xcong.excoin.modules.documentary.dto.MyFollowTraderInfoDto; import com.xcong.excoin.modules.documentary.entity.FollowTraderProfitInfoEntity; public interface DocumentaryService extends IService<FollowTraderProfitInfoEntity> { @@ -19,4 +21,10 @@ public Result getFollowRecords(@Valid FollowRecordsDto followRecordsDto); + public Result getFollowInfo(); + + public Result getMyFollowOrderRecords(@Valid MyFollowOrderDto myFollowOrderDto); + + public Result getMyFollowTraderInfo(@Valid MyFollowTraderInfoDto myFollowTraderInfoDto); + } diff --git a/src/main/java/com/xcong/excoin/modules/documentary/service/impl/DocumentaryServiceImpl.java b/src/main/java/com/xcong/excoin/modules/documentary/service/impl/DocumentaryServiceImpl.java index f2c4ef9..e5ee7d0 100644 --- a/src/main/java/com/xcong/excoin/modules/documentary/service/impl/DocumentaryServiceImpl.java +++ b/src/main/java/com/xcong/excoin/modules/documentary/service/impl/DocumentaryServiceImpl.java @@ -1,6 +1,10 @@ package com.xcong.excoin.modules.documentary.service.impl; +import java.math.BigDecimal; +import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.annotation.Resource; import javax.validation.Valid; @@ -14,23 +18,37 @@ import com.xcong.excoin.common.response.Result; import com.xcong.excoin.modules.coin.dao.OrderCoinsDao; import com.xcong.excoin.modules.coin.parameter.dto.RecordsPageDto; +import com.xcong.excoin.modules.contract.dao.ContractHoldOrderDao; +import com.xcong.excoin.modules.contract.entity.ContractHoldOrderEntity; +import com.xcong.excoin.modules.contract.entity.ContractOrderEntity; import com.xcong.excoin.modules.documentary.dao.FollowFollowerProfitDao; import com.xcong.excoin.modules.documentary.dao.FollowTraderInfoDao; import com.xcong.excoin.modules.documentary.dao.FollowTraderProfitDetailDao; import com.xcong.excoin.modules.documentary.dao.FollowTraderProfitInfoDao; import com.xcong.excoin.modules.documentary.dto.FollowRecordsDto; import com.xcong.excoin.modules.documentary.dto.HistoryOrderRecordsDto; +import com.xcong.excoin.modules.documentary.dto.MyFollowOrderDto; +import com.xcong.excoin.modules.documentary.dto.MyFollowTraderInfoDto; +import com.xcong.excoin.modules.documentary.entity.FollowFollowerProfitEntity; import com.xcong.excoin.modules.documentary.entity.FollowTraderInfoEntity; import com.xcong.excoin.modules.documentary.entity.FollowTraderProfitInfoEntity; import com.xcong.excoin.modules.documentary.service.DocumentaryService; +import com.xcong.excoin.modules.documentary.vo.FollowInfoVo; import com.xcong.excoin.modules.documentary.vo.FollowRecordsVo; import com.xcong.excoin.modules.documentary.vo.FollowTraderProfitInfoVo; import com.xcong.excoin.modules.documentary.vo.HistoryOrderRecordsVo; import com.xcong.excoin.modules.documentary.vo.MemberIsTradeVo; +import com.xcong.excoin.modules.documentary.vo.MyFollowOrderVo; +import com.xcong.excoin.modules.documentary.vo.MyFollowTraderInfoVo; import com.xcong.excoin.modules.member.dao.MemberDao; import com.xcong.excoin.modules.member.entity.MemberEntity; +import com.xcong.excoin.modules.platform.entity.PlatformTradeSettingEntity; +import com.xcong.excoin.utils.CacheSettingUtils; +import com.xcong.excoin.utils.CoinTypeConvert; +import com.xcong.excoin.utils.RedisUtils; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; import lombok.extern.slf4j.Slf4j; @Slf4j @@ -49,6 +67,12 @@ private FollowFollowerProfitDao followFollowerProfitDao; @Resource private OrderCoinsDao orderCoinsDao; + @Resource + private RedisUtils redisUtils; + @Resource + private CacheSettingUtils cacheSettingUtils; + @Resource + private ContractHoldOrderDao contractHoldOrderDao; @Override public Result getMemberIsTradeInfo() { @@ -106,8 +130,259 @@ Page<FollowRecordsVo> page = new Page<>(followRecordsDto.getPageNum(), followRecordsDto.getPageSize()); IPage<FollowRecordsVo> historyOrderRecordsVoList = followFollowerProfitDao.selectFollowRecords(page, followRecordsDto.getTradeMemberId()); + + List<FollowRecordsVo> records = historyOrderRecordsVoList.getRecords(); + if(CollUtil.isNotEmpty(records)) { + for(FollowRecordsVo followRecordsVo : records) { + Long memberId =followRecordsVo.getMemberId(); + MemberEntity member = memberDao.selectById(memberId); + String email = member.getEmail(); + String phone = member.getPhone(); + if(StrUtil.isNotEmpty(email)) { + followRecordsVo.setAccount(email); + }else { + followRecordsVo.setAccount(phone); + } + } + } return Result.ok(historyOrderRecordsVoList); } + + @Override + public Result getFollowInfo() { + //获取用户ID + Long memberId = LoginUserUtils.getAppLoginUser().getId(); + MemberEntity member = memberDao.selectById(memberId); + + FollowInfoVo followInfoVo = new FollowInfoVo(); + followInfoVo.setMemberId(memberId); + String email = member.getEmail(); + String phone = member.getPhone(); + if(StrUtil.isNotEmpty(email)) { + followInfoVo.setNickname(email); + }else { + followInfoVo.setNickname(phone); + } + + BigDecimal totalPrincipals = BigDecimal.ZERO; + BigDecimal totalProfits = BigDecimal.ZERO; + Map<String, Object> columnMap = new HashMap<>(); + columnMap.put("member_id", memberId); + List<FollowFollowerProfitEntity> selectByMap = followFollowerProfitDao.selectByMap(columnMap); + if(CollUtil.isNotEmpty(selectByMap)) { + for(FollowFollowerProfitEntity followFollowerProfitEntity : selectByMap) { + BigDecimal totalPrincipal = followFollowerProfitEntity.getTotalPrincipal(); + totalPrincipals = totalPrincipals.add(totalPrincipal); + BigDecimal totalProfit = followFollowerProfitEntity.getTotalProfit(); + totalProfits = totalProfits.add(totalProfit); + + //当前跟单 + List<ContractHoldOrderEntity> contractHoldOrderEntitys = followFollowerProfitDao.getFollowOrderNowRecords(memberId); + if(CollUtil.isNotEmpty(contractHoldOrderEntitys)) { + for(ContractHoldOrderEntity contractHoldOrderEntity : contractHoldOrderEntitys) { + // 获取最新价 + BigDecimal newPrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(contractHoldOrderEntity.getSymbol()))); + BigDecimal lotNumber = cacheSettingUtils.getSymbolSku(contractHoldOrderEntity.getSymbol()); + // 盈亏 + BigDecimal rewardRatio = BigDecimal.ZERO; + // 开多 + if (contractHoldOrderEntity.OPENING_TYPE_MORE == contractHoldOrderEntity.getOpeningType()) { + // (最新价-开仓价)*规格*张数 + rewardRatio = newPrice.subtract(contractHoldOrderEntity.getOpeningPrice()).multiply(lotNumber).multiply(new BigDecimal(contractHoldOrderEntity.getSymbolCnt())); + // 开空 + } else { + // (开仓价-最新价)*规格*张数 + rewardRatio = contractHoldOrderEntity.getOpeningPrice().subtract(newPrice).multiply(lotNumber).multiply(new BigDecimal(contractHoldOrderEntity.getSymbolCnt())); + } + + if (member.getIsProfit() == MemberEntity.IS_PROFIT_Y) { + PlatformTradeSettingEntity tradeSettingEntity = cacheSettingUtils.getTradeSetting(); + if (rewardRatio.compareTo(BigDecimal.ZERO) > -1) { + rewardRatio = rewardRatio.multiply(BigDecimal.ONE.subtract(tradeSettingEntity.getProfitParam())); + } + } + totalProfits = totalProfits.add(rewardRatio); + } + } + } + } + followInfoVo.setTotalPrincipal(totalPrincipals.setScale(4, BigDecimal.ROUND_DOWN)); + followInfoVo.setTotalProfit(totalProfits.setScale(4, BigDecimal.ROUND_DOWN)); + + return Result.ok(followInfoVo); + } + + @Override + public Result getMyFollowOrderRecords(@Valid MyFollowOrderDto myFollowOrderDto) { + //获取用户ID + Long memberId = LoginUserUtils.getAppLoginUser().getId(); + MemberEntity member = memberDao.selectById(memberId); + + int type = myFollowOrderDto.getOrderType(); + Page<MyFollowOrderVo> result = new Page<>(); + List<MyFollowOrderVo> myFollowOrderVos = result.getRecords(); + //历史跟单 + if(type == 2) { + Page<ContractOrderEntity> page = new Page<>(myFollowOrderDto.getPageNum(), myFollowOrderDto.getPageSize()); + IPage<ContractOrderEntity> contractOrderEntitys = followFollowerProfitDao.getMyFollowOrderHistoryRecords(page, memberId); + + List<ContractOrderEntity> records = contractOrderEntitys.getRecords(); + if(CollUtil.isNotEmpty(records)) { + for(ContractOrderEntity contractOrderEntity : records) { + MyFollowOrderVo myFollowOrderVo = new MyFollowOrderVo(); + String symbol = contractOrderEntity.getSymbol(); + myFollowOrderVo.setSymbol(symbol); + int orderType = contractOrderEntity.getOrderType(); + myFollowOrderVo.setOrderType(orderType); + int leverRatio = contractOrderEntity.getLeverRatio(); + myFollowOrderVo.setLeverRatio(leverRatio); + BigDecimal rewardAmount = contractOrderEntity.getRewardAmount().setScale(4, BigDecimal.ROUND_DOWN); + myFollowOrderVo.setRewardAmount(rewardAmount); + BigDecimal rewardRatio = contractOrderEntity.getRewardRatio().setScale(4, BigDecimal.ROUND_DOWN); + myFollowOrderVo.setRewardRatio(rewardRatio); + int symbolCnt = contractOrderEntity.getSymbolCnt(); + myFollowOrderVo.setSymbolCnt(symbolCnt); + BigDecimal bondAmount = contractOrderEntity.getBondAmount().setScale(4, BigDecimal.ROUND_DOWN); + myFollowOrderVo.setBondAmount(bondAmount); + BigDecimal openingPrice = contractOrderEntity.getOpeningPrice().setScale(4, BigDecimal.ROUND_DOWN); + myFollowOrderVo.setOpeningPrice(openingPrice); + BigDecimal closingPrice = contractOrderEntity.getClosingPrice().setScale(4, BigDecimal.ROUND_DOWN); + myFollowOrderVo.setClosingPrice(closingPrice); + Date openingTime = contractOrderEntity.getOpeningTime(); + myFollowOrderVo.setOpeningTime(openingTime); + Date closingTime = contractOrderEntity.getClosingTime(); + myFollowOrderVo.setClosingTime(closingTime); + String orderNo = contractOrderEntity.getOrderNo(); + myFollowOrderVo.setOrderNo(orderNo); + myFollowOrderVos.add(myFollowOrderVo); + } + } + }else { + //当前跟单 + Page<ContractHoldOrderEntity> page = new Page<>(myFollowOrderDto.getPageNum(), myFollowOrderDto.getPageSize()); + IPage<ContractHoldOrderEntity> contractHoldOrderEntitys = followFollowerProfitDao.getMyFollowOrderNowRecords(page, myFollowOrderDto.getMemberId()); + + List<ContractHoldOrderEntity> records = contractHoldOrderEntitys.getRecords(); + if(CollUtil.isNotEmpty(records)) { + for(ContractHoldOrderEntity contractHoldOrderEntity : records) { + MyFollowOrderVo myFollowOrderVo = new MyFollowOrderVo(); + String symbol = contractHoldOrderEntity.getSymbol(); + myFollowOrderVo.setSymbol(symbol); + int orderType = contractHoldOrderEntity.getOpeningType(); + myFollowOrderVo.setOrderType(orderType); + int leverRatio = contractHoldOrderEntity.getLeverRatio(); + myFollowOrderVo.setLeverRatio(leverRatio); + int symbolCnt = contractHoldOrderEntity.getSymbolCnt(); + myFollowOrderVo.setSymbolCnt(symbolCnt); + BigDecimal bondAmount = contractHoldOrderEntity.getBondAmount().setScale(4, BigDecimal.ROUND_DOWN); + myFollowOrderVo.setBondAmount(bondAmount); + BigDecimal openingPrice = contractHoldOrderEntity.getOpeningPrice().setScale(4, BigDecimal.ROUND_DOWN); + myFollowOrderVo.setOpeningPrice(openingPrice); + String orderNo = contractHoldOrderEntity.getOrderNo(); + myFollowOrderVo.setOrderNo(orderNo); + Date openingTime = contractHoldOrderEntity.getCreateTime(); + myFollowOrderVo.setOpeningTime(openingTime); + + // 获取最新价 + BigDecimal newPrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(contractHoldOrderEntity.getSymbol()))); + BigDecimal lotNumber = cacheSettingUtils.getSymbolSku(contractHoldOrderEntity.getSymbol()); + // 盈亏 + BigDecimal rewardRatio = BigDecimal.ZERO; + // 开多 + if (contractHoldOrderEntity.OPENING_TYPE_MORE == contractHoldOrderEntity.getOpeningType()) { + // (最新价-开仓价)*规格*张数 + rewardRatio = newPrice.subtract(contractHoldOrderEntity.getOpeningPrice()).multiply(lotNumber).multiply(new BigDecimal(contractHoldOrderEntity.getSymbolCnt())); + // 开空 + } else { + // (开仓价-最新价)*规格*张数 + rewardRatio = contractHoldOrderEntity.getOpeningPrice().subtract(newPrice).multiply(lotNumber).multiply(new BigDecimal(contractHoldOrderEntity.getSymbolCnt())); + } + + if (member.getIsProfit() == MemberEntity.IS_PROFIT_Y) { + PlatformTradeSettingEntity tradeSettingEntity = cacheSettingUtils.getTradeSetting(); + if (rewardRatio.compareTo(BigDecimal.ZERO) > -1) { + rewardRatio = rewardRatio.multiply(BigDecimal.ONE.subtract(tradeSettingEntity.getProfitParam())); + } + } + myFollowOrderVo.setRewardAmount(rewardRatio.setScale(4, BigDecimal.ROUND_DOWN)); + + // 回报率 + BigDecimal returnRate = rewardRatio.divide(contractHoldOrderEntity.getBondAmount().subtract(contractHoldOrderEntity.getOpeningFeeAmount()), 8, BigDecimal.ROUND_DOWN); + myFollowOrderVo.setRewardRatio(returnRate.setScale(4, BigDecimal.ROUND_DOWN)); + + myFollowOrderVos.add(myFollowOrderVo); + } + } + } + + return Result.ok(myFollowOrderVos); + + } + + @Override + public Result getMyFollowTraderInfo(@Valid MyFollowTraderInfoDto myFollowTraderInfoDto) { + //获取用户ID + Long memberId = LoginUserUtils.getAppLoginUser().getId(); + MemberEntity member = memberDao.selectById(memberId); + Page<FollowFollowerProfitEntity> page = new Page<>(myFollowTraderInfoDto.getPageNum(), myFollowTraderInfoDto.getPageSize()); + IPage<FollowFollowerProfitEntity> followFollowerProfitEntitys = followFollowerProfitDao.selectFollowFollowerProfitEntitys(page, memberId); + + List<FollowFollowerProfitEntity> records = followFollowerProfitEntitys.getRecords(); + if(CollUtil.isNotEmpty(records)) { + Page<MyFollowTraderInfoVo> result = new Page<>(); + List<MyFollowTraderInfoVo> myFollowOrderVos = result.getRecords(); + + for(FollowFollowerProfitEntity FollowFollowerProfitEntity : records) { + MyFollowTraderInfoVo myFollowTraderInfoVo = new MyFollowTraderInfoVo(); + + Long tradeId = FollowFollowerProfitEntity.getTradeId(); + FollowTraderInfoEntity followTraderInfoEntity = followTraderInfoDao.selectById(tradeId); + String avatar = followTraderInfoEntity.getAvatar(); + myFollowTraderInfoVo.setAvatar(avatar); + + String nickname = followTraderInfoEntity.getNickname(); + myFollowTraderInfoVo.setNickname(nickname); + + BigDecimal totalPrincipal = FollowFollowerProfitEntity.getTotalPrincipal(); + myFollowTraderInfoVo.setTotalPrincipal(totalPrincipal); + + BigDecimal totalProfit = BigDecimal.ZERO; + Map<String, Object> columnMap = new HashMap<>(); + columnMap.put("member_id", memberId); + contractHoldOrderDao.selectByMap(columnMap ); + List<ContractHoldOrderEntity> contractHoldOrderEntitys = contractHoldOrderDao.selectByMap(columnMap ); + if(CollUtil.isNotEmpty(contractHoldOrderEntitys)) { + for(ContractHoldOrderEntity contractHoldOrderEntity : contractHoldOrderEntitys) { + // 获取最新价 + BigDecimal newPrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(contractHoldOrderEntity.getSymbol()))); + BigDecimal lotNumber = cacheSettingUtils.getSymbolSku(contractHoldOrderEntity.getSymbol()); + // 盈亏 + BigDecimal rewardRatio = BigDecimal.ZERO; + // 开多 + if (ContractHoldOrderEntity.OPENING_TYPE_MORE == contractHoldOrderEntity.getOpeningType()) { + // (最新价-开仓价)*规格*张数 + rewardRatio = newPrice.subtract(contractHoldOrderEntity.getOpeningPrice()).multiply(lotNumber).multiply(new BigDecimal(contractHoldOrderEntity.getSymbolCnt())); + // 开空 + } else { + // (开仓价-最新价)*规格*张数 + rewardRatio = contractHoldOrderEntity.getOpeningPrice().subtract(newPrice).multiply(lotNumber).multiply(new BigDecimal(contractHoldOrderEntity.getSymbolCnt())); + } + + if (member.getIsProfit() == MemberEntity.IS_PROFIT_Y) { + PlatformTradeSettingEntity tradeSettingEntity = cacheSettingUtils.getTradeSetting(); + if (rewardRatio.compareTo(BigDecimal.ZERO) > -1) { + rewardRatio = rewardRatio.multiply(BigDecimal.ONE.subtract(tradeSettingEntity.getProfitParam())); + } + } + totalProfit = totalProfit.add(rewardRatio); + } + myFollowTraderInfoVo.setTotalProfit(totalProfit.setScale(4, BigDecimal.ROUND_DOWN)); + } + myFollowOrderVos.add(myFollowTraderInfoVo); + } + } + return null; + } diff --git a/src/main/java/com/xcong/excoin/modules/documentary/vo/FollowInfoVo.java b/src/main/java/com/xcong/excoin/modules/documentary/vo/FollowInfoVo.java new file mode 100644 index 0000000..b17fcea --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/documentary/vo/FollowInfoVo.java @@ -0,0 +1,39 @@ +package com.xcong.excoin.modules.documentary.vo; + +import java.math.BigDecimal; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +@ApiModel(value = "FollowInfoVo", description = "我的跟单--首页") +public class FollowInfoVo { + + /** + * 跟随者ID + */ + @ApiModelProperty(value = "跟随者ID") + private Long memberId; + /** + * 头像 + */ + @ApiModelProperty("头像") + private String avatar; + /** + * 名称 + */ + @ApiModelProperty("名称") + private String nickname; + /** + * 累计跟随本金 + */ + @ApiModelProperty(value = "累计跟随本金") + private BigDecimal totalPrincipal; + /** + * 累计收益 + */ + @ApiModelProperty(value = "累计收益") + private BigDecimal totalProfit; + +} diff --git a/src/main/java/com/xcong/excoin/modules/documentary/vo/FollowRecordsVo.java b/src/main/java/com/xcong/excoin/modules/documentary/vo/FollowRecordsVo.java index de61253..87e269e 100644 --- a/src/main/java/com/xcong/excoin/modules/documentary/vo/FollowRecordsVo.java +++ b/src/main/java/com/xcong/excoin/modules/documentary/vo/FollowRecordsVo.java @@ -28,16 +28,9 @@ */ @ApiModelProperty(value = "跟随者ID") private Long memberId; - /** - * 交易员ID - */ - @ApiModelProperty(value = "交易员ID") - private Long tradeId; - /** - * 交易员会员ID - */ - @ApiModelProperty(value = "交易员会员ID") - private Long tradeMemberId; + + @ApiModelProperty(value = "跟随者账号") + private String account; /** * 累计跟随本金 */ @@ -48,9 +41,5 @@ */ @ApiModelProperty(value = "累计收益") private BigDecimal totalProfit; - /** - * 是否跟随 1-是 2-否 - */ - @ApiModelProperty(value = "是否跟随 1-是 2-否") - private Integer isFollow; + } diff --git a/src/main/java/com/xcong/excoin/modules/documentary/vo/MyFollowOrderVo.java b/src/main/java/com/xcong/excoin/modules/documentary/vo/MyFollowOrderVo.java new file mode 100644 index 0000000..782a43a --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/documentary/vo/MyFollowOrderVo.java @@ -0,0 +1,54 @@ +package com.xcong.excoin.modules.documentary.vo; + +import java.math.BigDecimal; +import java.util.Date; + +import com.fasterxml.jackson.annotation.JsonFormat; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +@ApiModel(value = "MyFollowOrderVo", description = "返回类") +public class MyFollowOrderVo { + + @ApiModelProperty("币种") + private String symbol; + + @ApiModelProperty("订单类型 -1撤单,1开多,2开空,3平多,4平空") + private int orderType; + + @ApiModelProperty("杠杆") + private int leverRatio; + + @ApiModelProperty("开仓价") + private BigDecimal openingPrice; + + @ApiModelProperty("平仓价") + private BigDecimal closingPrice; + + @ApiModelProperty("盈亏金额") + private BigDecimal rewardAmount; + + @ApiModelProperty("张数") + private BigDecimal rewardRatio; + + @ApiModelProperty("盈亏比例") + private int symbolCnt; + + @ApiModelProperty("保证金") + private BigDecimal bondAmount; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @ApiModelProperty("开仓时间") + private Date openingTime; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @ApiModelProperty("平仓时间") + private Date closingTime; + + @ApiModelProperty("订单编号") + private String orderNo; + +} diff --git a/src/main/java/com/xcong/excoin/modules/documentary/vo/MyFollowTraderInfoVo.java b/src/main/java/com/xcong/excoin/modules/documentary/vo/MyFollowTraderInfoVo.java new file mode 100644 index 0000000..6f0e7da --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/documentary/vo/MyFollowTraderInfoVo.java @@ -0,0 +1,46 @@ +package com.xcong.excoin.modules.documentary.vo; + +import java.math.BigDecimal; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +@ApiModel(value = "MyFollowTraderInfoVo", description = "返回类") +public class MyFollowTraderInfoVo { + + /** + * 跟随者ID + */ + @ApiModelProperty(value = "跟随者ID") + private Long memberId; + + @ApiModelProperty(value = "交易员ID") + private Long tradeId; + + @ApiModelProperty(value = "交易员会员ID") + private Long tradeMemberId; + + /** + * 头像 + */ + @ApiModelProperty("头像") + private String avatar; + /** + * 名称 + */ + @ApiModelProperty("名称") + private String nickname; + /** + * 累计跟随本金 + */ + @ApiModelProperty(value = "累计跟随本金") + private BigDecimal totalPrincipal; + /** + * 累计收益 + */ + @ApiModelProperty(value = "累计收益") + private BigDecimal totalProfit; + +} diff --git a/src/main/resources/mapper/documentary/FollowFollowerProfitDao.xml b/src/main/resources/mapper/documentary/FollowFollowerProfitDao.xml index cc8e13f..5465376 100644 --- a/src/main/resources/mapper/documentary/FollowFollowerProfitDao.xml +++ b/src/main/resources/mapper/documentary/FollowFollowerProfitDao.xml @@ -15,7 +15,53 @@ follow_follower_profit WHERE trade_member_id = #{tradeMemberId} + and is_follow = 1 order by create_time desc </select> + + <select id="selectFollowFollowerProfitEntitys" resultType="com.xcong.excoin.modules.documentary.entity.FollowFollowerProfitEntity"> + SELECT + * + FROM + follow_follower_profit + WHERE + member_id = #{memberId} + and is_follow = 1 + order by create_time desc + </select> + + <select id="getMyFollowOrderHistoryRecords" resultType="com.xcong.excoin.modules.contract.entity.ContractOrderEntity"> + SELECT + * + FROM + contract_order + WHERE + member_id = #{memberId} + and contract_type = 2 + and order_type in (3,4) + and closing_type not in (4,5) + order by opening_time desc + </select> + <select id="getMyFollowOrderNowRecords" resultType="com.xcong.excoin.modules.contract.entity.ContractHoldOrderEntity"> + SELECT + * + FROM + contract_hold_order + WHERE + member_id = #{memberId} + and contract_type = 2 + order by opening_time desc + </select> + + <select id="getFollowOrderNowRecords" resultType="com.xcong.excoin.modules.contract.entity.ContractHoldOrderEntity"> + SELECT + * + FROM + contract_hold_order + WHERE + member_id = #{memberId} + and contract_type = 2 + order by opening_time desc + </select> </mapper> \ No newline at end of file -- Gitblit v1.9.1