From 4e43b6496e163787ea7397ca422c9e081ac2857a Mon Sep 17 00:00:00 2001 From: Helius <wangdoubleone@gmail.com> Date: Fri, 05 Feb 2021 15:42:32 +0800 Subject: [PATCH] modify --- src/main/java/com/xcong/excoin/modules/documentary/service/impl/DocumentaryServiceImpl.java | 191 ++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 171 insertions(+), 20 deletions(-) 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 48b666d..de44524 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 @@ -16,13 +16,17 @@ import org.springframework.transaction.annotation.Transactional; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.taobao.api.internal.toplink.embedded.websocket.util.StringUtil; 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.coin.parameter.dto.RecordsPageDto; import com.xcong.excoin.modules.contract.dao.ContractHoldOrderDao; +import com.xcong.excoin.modules.contract.dao.ContractOrderDao; +import com.xcong.excoin.modules.contract.entity.ContractEntrustOrderEntity; import com.xcong.excoin.modules.contract.entity.ContractHoldOrderEntity; import com.xcong.excoin.modules.contract.entity.ContractOrderEntity; import com.xcong.excoin.modules.documentary.dao.FollowFollowerNoticeDao; @@ -30,10 +34,12 @@ 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.CancelDocumentaryOrderSetDto; import com.xcong.excoin.modules.documentary.dto.DocumentaryOrderSetDto; +import com.xcong.excoin.modules.documentary.dto.FollowFollowerNoticeDto; import com.xcong.excoin.modules.documentary.dto.FollowRecordsDto; import com.xcong.excoin.modules.documentary.dto.HistoryOrderRecordsDto; import com.xcong.excoin.modules.documentary.dto.MyFollowOrderDto; @@ -48,6 +54,7 @@ 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.service.DocumentaryService; import com.xcong.excoin.modules.documentary.vo.DocumentaryOrderInfoVo; @@ -65,6 +72,7 @@ import com.xcong.excoin.modules.documentary.vo.TradeOrderInfoVo; import com.xcong.excoin.modules.documentary.vo.TradeProfitInfoVo; import com.xcong.excoin.modules.documentary.vo.TradeSetInfoVo; +import com.xcong.excoin.modules.documentary.vo.TradeSetLabelInfoVo; import com.xcong.excoin.modules.documentary.vo.TraderStatusVo; import com.xcong.excoin.modules.member.dao.MemberDao; import com.xcong.excoin.modules.member.dao.MemberLevelRateDao; @@ -77,6 +85,7 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import jnr.ffi.Struct.int16_t; import lombok.extern.slf4j.Slf4j; @Slf4j @@ -102,6 +111,8 @@ @Resource private ContractHoldOrderDao contractHoldOrderDao; @Resource + private ContractOrderDao contractOrderDao; + @Resource private MemberLevelRateDao memberLevelRateDao; @Resource private MemberWalletContractDao memberWalletContractDao; @@ -109,8 +120,10 @@ private FollowFollowerSettingDao followFollowerSettingDao; @Resource private FollowFollowerOrderRelationDao followFollowerOrderRelationDao; - + @Resource private FollowFollowerNoticeDao followFollowerNoticeDao; + @Resource + private FollowTraderLabelDao followTraderLabelDao; @Override @@ -160,9 +173,37 @@ FollowTraderProfitInfoVo.setDeclaration(declaration); Integer isAll = followTraderInfoEntity.getIsAll(); FollowTraderProfitInfoVo.setIsAll(isAll); + + String labels = followTraderInfoEntity.getLabels(); + if(StrUtil.isNotEmpty(labels)) { + ArrayList<FollowTraderLabelEntity> arrayList = new ArrayList<>(); + String[] split = labels.split(","); + int length = split.length; + for(int i = 0;i < length;i++) { + String string = split[i]; + FollowTraderLabelEntity selectById = followTraderLabelDao.selectById(Long.parseLong(string)); + arrayList.add(selectById); + } + FollowTraderProfitInfoVo.setLabels(arrayList); + } + } } return Result.ok(followTraderProfitInfoVoList); + } + + public static void main(String[] args) { + String labels = "1,2,3"; + if(StrUtil.isNotEmpty(labels)) { + String labelsName = ""; + String[] split = labels.split(","); + int length = split.length; + for(int i = 0;i < length;i++) { + String string = split[i]; + labelsName += (string + ","); + } + System.out.println(labelsName); + } } @Override @@ -452,7 +493,21 @@ FollowTraderInfoEntity traderInfoEntity = followTraderInfoDao.selectTraderInfoByMemberId(memberId); if (traderInfoEntity != null) { - return Result.fail("交易员不能进行跟单"); + return Result.fail(MessageSourceUtils.getString("documentary_service_0014")); + } + + //判断当前用户是否是逐仓模式 + MemberEntity selectById2 = memberDao.selectById(memberId); + Integer contractPositionType = selectById2.getContractPositionType(); + if(ContractEntrustOrderEntity.POSITION_TYPE_ADD != contractPositionType) { + return Result.fail(MessageSourceUtils.getString("documentary_service_0017")); + } + + //判断交易员是否开启了跟单 + FollowTraderInfoEntity selectById = followTraderInfoDao.selectById(traderId); + Integer isOpen = selectById.getIsOpen(); + if(FollowTraderInfoEntity.ISOPEN_Y != isOpen) { + return Result.fail(MessageSourceUtils.getString("documentary_service_0016")); } FollowFollowerSettingEntity isExistSetting = followFollowerSettingDao.selectOneBymemberIdAndTradeId(memberId, traderId); @@ -610,7 +665,7 @@ FollowTraderProfitInfoVo followTraderProfitInfoVo = followTraderProfitInfoDao.selectOneByMemberId(memberId); MemberEntity user = LoginUserUtils.getUser(); if(ObjectUtil.isNotEmpty(user)) { - FollowFollowerProfitEntity followFollowerProfitEntity = followFollowerProfitDao.selectDocumentaryOrderSetInfoBymemberIdAndTradeId(memberId, traderId); + FollowFollowerProfitEntity followFollowerProfitEntity = followFollowerProfitDao.selectDocumentaryOrderSetInfoBymemberIdAndTradeId(user.getId(), traderId); if(ObjectUtil.isNotEmpty(followFollowerProfitEntity)) { followTraderProfitInfoVo.setDocumentaryType(followFollowerProfitEntity.getIsFollow()); }else { @@ -638,6 +693,24 @@ if(MemberEntity.CERTIFY_STATUS_Y != certifyStatus) { return Result.fail(MessageSourceUtils.getString("member_controller_0009")); } + + //不可以处于跟单状态 + Map<String, Object> columnMaps = new HashMap<>(); + columnMaps.put("member_id", memberId); + columnMaps.put("is_follow", 1); + List<FollowFollowerProfitEntity> followFollowerProfitEntitys = followFollowerProfitDao.selectByMap(columnMaps); + if(CollUtil.isNotEmpty(followFollowerProfitEntitys)) { + return Result.fail(MessageSourceUtils.getString("documentary_service_0015")); + } + + //合约不能持仓 + Map<String, Object> contractHoldColumnMap = new HashMap<>(); + contractHoldColumnMap.put("member_id", memberId); + List<ContractHoldOrderEntity> contractHoldOrderEntitys = contractHoldOrderDao.selectByMap(contractHoldColumnMap); + if(CollUtil.isNotEmpty(contractHoldOrderEntitys)) { + return Result.fail(MessageSourceUtils.getString("documentary_service_0013")); + } + Map<String, Object> columnMap = new HashMap<>(); columnMap.put("member_id", memberId); List<FollowTraderInfoEntity> selectByMap = followTraderInfoDao.selectByMap(columnMap); @@ -648,13 +721,14 @@ //新增【交易员信息表】数据 FollowTraderInfoEntity followTraderInfoEntity = new FollowTraderInfoEntity(); followTraderInfoEntity.setMemberId(memberId); - followTraderInfoEntity.setAvatar(FollowTraderInfoEntity.AVATAR_DEFAULT); + followTraderInfoEntity.setProfitRatio(BigDecimal.valueOf(0.1)); +// followTraderInfoEntity.setAvatar(FollowTraderInfoEntity.AVATAR_DEFAULT); String phone = memberEntity.getPhone(); String email = memberEntity.getEmail(); if(StrUtil.isNotEmpty(phone)) { - followTraderInfoEntity.setNickname(phone); + followTraderInfoEntity.setNickname(phone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2")); }else { - followTraderInfoEntity.setNickname(email); + followTraderInfoEntity.setNickname(email.replaceAll("(\\w?)(\\w+)(\\w)(@\\w+\\.[a-z]+(\\.[a-z]+)?)","$1****$3$4")); } followTraderInfoEntity.setDeclaration(FollowTraderInfoEntity.DECLARATION_DEFAULT); followTraderInfoEntity.setIsAll(FollowTraderInfoEntity.IS_ALL_N); @@ -696,6 +770,8 @@ FollowTraderInfoEntity followTraderInfoEntity = followTraderInfoDao.selectTraderInfoByMemberId(memberId); TradeSetInfoVo tradeSetInfoVo = new TradeSetInfoVo(); + Long id = followTraderInfoEntity.getId(); + tradeSetInfoVo.setTradeId(id); String avatar = followTraderInfoEntity.getAvatar(); tradeSetInfoVo.setAvatar(avatar); String nickname = followTraderInfoEntity.getNickname(); @@ -704,6 +780,19 @@ tradeSetInfoVo.setDeclaration(declaration); Integer isOpen = followTraderInfoEntity.getIsOpen(); tradeSetInfoVo.setIsOpen(isOpen); + + String labels = followTraderInfoEntity.getLabels(); + if(StrUtil.isNotEmpty(labels)) { + ArrayList<FollowTraderLabelEntity> arrayList = new ArrayList<>(); + String[] split = labels.split(","); + int length = split.length; + for(int i = 0;i < length;i++) { + String string = split[i]; + FollowTraderLabelEntity selectById = followTraderLabelDao.selectById(Long.parseLong(string)); + arrayList.add(selectById); + } + tradeSetInfoVo.setFollowTraderLabelEntitys(arrayList); + } return Result.ok(tradeSetInfoVo); } @@ -712,10 +801,16 @@ //获取用户ID Long memberId = LoginUserUtils.getAppLoginUser().getId(); FollowTraderInfoEntity followTraderInfoEntity = followTraderInfoDao.selectTraderInfoByMemberId(memberId); + /** + * todo + * 当前交易员有合约多单,是否可以直接调整【是否带单】,是否需要在调整前【判断是否已经有带单的合约单】 + */ String avatar = updateTradeSetInfoDto.getAvatar(); String nickname = updateTradeSetInfoDto.getNickname(); String declaration = updateTradeSetInfoDto.getDeclaration(); int isOpen = updateTradeSetInfoDto.getIsOpen(); + String labels = updateTradeSetInfoDto.getLabels(); + followTraderInfoEntity.setLabels(labels); followTraderInfoEntity.setAvatar(avatar); followTraderInfoEntity.setNickname(nickname); followTraderInfoEntity.setDeclaration(declaration); @@ -723,7 +818,7 @@ followTraderInfoDao.updateById(followTraderInfoEntity); return Result.ok(MessageSourceUtils.getString("member_service_0024")); } - + @Override public Result getTradeProfitInfo() { //获取用户ID @@ -824,7 +919,7 @@ // 回报率 BigDecimal returnRate = rewardRatio.divide(contractHoldOrderEntity.getBondAmount().subtract(contractHoldOrderEntity.getOpeningFeeAmount()), 8, BigDecimal.ROUND_DOWN); - myFollowOrderVo.setRewardRatio(returnRate.setScale(2, BigDecimal.ROUND_DOWN)); + myFollowOrderVo.setRewardRatio(returnRate.setScale(4, BigDecimal.ROUND_DOWN)); myFollowOrderVos.add(myFollowOrderVo); } @@ -846,11 +941,42 @@ if(CollUtil.isNotEmpty(records)) { for(ContractOrderEntity contractOrderEntity : records) { TradeHistoryOrderInfoVo myFollowOrderVo = new TradeHistoryOrderInfoVo(); + //获取【跟随者-订单关联表】中的累计数据 + BigDecimal allRewardAmount = BigDecimal.ZERO; + BigDecimal allRewardRatio = BigDecimal.ZERO; + + Long orderId = contractOrderEntity.getId(); + String orderNo = contractOrderEntity.getOrderNo(); + Map<String, Object> columnMapRelation = new HashMap<>(); + columnMapRelation.put("trade_order_no", orderNo); + columnMapRelation.put("trade_member_id", memberId); + columnMapRelation.put("order_type", 2); + columnMapRelation.put("is_show", 1); + List<FollowFollowerOrderRelationEntity> followFollowerOrderRelations = followFollowerOrderRelationDao.selectByMap(columnMapRelation); + if(CollUtil.isNotEmpty(followFollowerOrderRelations)) { + int size = followFollowerOrderRelations.size() - 1; + myFollowOrderVo.setFollowerNumber(size); + for(FollowFollowerOrderRelationEntity followFollowerOrderRelation : followFollowerOrderRelations) { + Long followerMemberId = followFollowerOrderRelation.getMemberId(); + if(!memberId.equals(followerMemberId)) { + Long followerOrderId = followFollowerOrderRelation.getOrderId(); + ContractOrderEntity orderEntity = contractOrderDao.selectById(followerOrderId); + BigDecimal rewardAmount = orderEntity.getRewardAmount(); + allRewardAmount = allRewardAmount.add(rewardAmount); + BigDecimal rewardRatio = orderEntity.getRewardRatio(); + allRewardRatio = allRewardRatio.add(rewardRatio); + } + } + }else { + myFollowOrderVo.setFollowerNumber(0); + } + myFollowOrderVo.setFollowerRewardAmount(allRewardAmount); + myFollowOrderVo.setFollowerRewardRatio(allRewardRatio); + //获取交易员信息 FollowTraderInfoEntity followTraderInfoEntity = followTraderInfoDao.selectTraderInfoByMemberId(memberId); String nickname = followTraderInfoEntity.getNickname(); myFollowOrderVo.setNickname(nickname); - Long orderId = contractOrderEntity.getId(); myFollowOrderVo.setOrderId(orderId); String symbol = contractOrderEntity.getSymbol(); myFollowOrderVo.setSymbol(symbol); @@ -860,7 +986,7 @@ myFollowOrderVo.setLeverRatio(leverRatio); BigDecimal rewardAmount = contractOrderEntity.getRewardAmount().setScale(2, BigDecimal.ROUND_DOWN); myFollowOrderVo.setRewardAmount(rewardAmount); - BigDecimal rewardRatio = contractOrderEntity.getRewardRatio().setScale(2, BigDecimal.ROUND_DOWN); + BigDecimal rewardRatio = contractOrderEntity.getRewardRatio().setScale(4, BigDecimal.ROUND_DOWN); myFollowOrderVo.setRewardRatio(rewardRatio); int symbolCnt = contractOrderEntity.getSymbolCnt(); myFollowOrderVo.setSymbolCnt(symbolCnt); @@ -874,7 +1000,7 @@ myFollowOrderVo.setOpeningTime(openingTime); Date closingTime = contractOrderEntity.getClosingTime(); myFollowOrderVo.setClosingTime(closingTime); - String orderNo = contractOrderEntity.getOrderNo(); + myFollowOrderVo.setOrderNo(orderNo); myFollowOrderVos.add(myFollowOrderVo); } @@ -947,33 +1073,58 @@ FollowTraderInfoEntity traderInfoEntity = followTraderInfoDao.selectTraderInfoByMemberId(memberId); if (traderInfoEntity != null) { - LogRecordUtils.insertFollowerNotice(memberId, NoticeConstant.STOP_FOLLOW_TITLE, StrUtil.format(NoticeConstant.STOP_FOLLOW_CONTENT, traderInfoEntity.getNickname())); + LogRecordUtils.insertFollowerNotice(followMemberId, NoticeConstant.STOP_FOLLOW_TITLE, StrUtil.format(NoticeConstant.STOP_FOLLOW_CONTENT, traderInfoEntity.getNickname())); } return Result.ok(MessageSourceUtils.getString("member_service_0026")); } @Override - public Result getFollowFollowerNoticeList() { + public Result getFollowFollowerNoticeList(FollowFollowerNoticeDto followFollowerNoticeDto) { //获取用户ID Long memberId = LoginUserUtils.getAppLoginUser().getId(); List<FollowFollowerNoticeVo> arrayList = new ArrayList<>(); - Map<String, Object> columnMap = new HashMap<>(); - columnMap.put("member_id", memberId); - List<FollowFollowerNoticeEntity> selectByMap = followFollowerNoticeDao.selectByMap(columnMap ); - if(CollUtil.isNotEmpty(selectByMap)) { - for(FollowFollowerNoticeEntity followFollowerNoticeEntity : selectByMap) { + Page<FollowFollowerNoticeEntity> page = new Page<>(followFollowerNoticeDto.getPageNum(), followFollowerNoticeDto.getPageSize()); + FollowFollowerNoticeEntity followFollowerNoticeEntity = new FollowFollowerNoticeEntity(); + followFollowerNoticeEntity.setMemberId(memberId); + IPage<FollowFollowerNoticeEntity> followFollowerNoticelist = followFollowerNoticeDao.selectFollowFollowerNoticePage(page, followFollowerNoticeEntity); + List<FollowFollowerNoticeEntity> records = followFollowerNoticelist.getRecords(); + if(CollUtil.isNotEmpty(records)) { + for(FollowFollowerNoticeEntity followFollowerNotice : records) { FollowFollowerNoticeVo followFollowerNoticeVo = new FollowFollowerNoticeVo(); - String title = followFollowerNoticeEntity.getTitle(); + String title = followFollowerNotice.getTitle(); followFollowerNoticeVo.setTitle(title); - String content = followFollowerNoticeEntity.getContent(); + String content = followFollowerNotice.getContent(); followFollowerNoticeVo.setContent(content); + Date createTime = followFollowerNotice.getCreateTime(); + followFollowerNoticeVo.setCreateTime(createTime); arrayList.add(followFollowerNoticeVo); } } return Result.ok(arrayList); } + + @Override + public Result getTradeSetLabelInfo() { + //获取用户ID + Long memberId = LoginUserUtils.getAppLoginUser().getId(); + + Map<String, Object> columnMap = new HashMap<>(); + List<FollowTraderLabelEntity> selectByMap = followTraderLabelDao.selectByMap(columnMap); + ArrayList<TradeSetLabelInfoVo> arrayList = new ArrayList<>(); + if(CollUtil.isNotEmpty(selectByMap)) { + for(FollowTraderLabelEntity followTraderLabelEntity : selectByMap) { + TradeSetLabelInfoVo tradeSetLabelInfoVo = new TradeSetLabelInfoVo(); + Long id = followTraderLabelEntity.getId(); + String labels = followTraderLabelEntity.getLabels(); + tradeSetLabelInfoVo.setId(id); + tradeSetLabelInfoVo.setLabels(labels); + arrayList.add(tradeSetLabelInfoVo); + } + } + return Result.ok(arrayList); + } -- Gitblit v1.9.1