Authored by LUOXC

只展示入职商家邀请数据

package com.yohoufo.order.service.impl;
import com.github.rholder.retry.Retryer;
import com.github.rholder.retry.RetryerBuilder;
import com.github.rholder.retry.StopStrategies;
import com.google.common.base.Predicates;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yoho.message.sdk.utils.DateUtils;
import com.yohobuy.ufo.model.order.resp.InviteInfoResp;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.*;
import com.yohoufo.dal.order.model.*;
import com.yohoufo.dal.order.InviteActivityMapper;
import com.yohoufo.dal.order.InviteRecordMapper;
import com.yohoufo.dal.order.InviteSettlementItemMapper;
import com.yohoufo.dal.order.InviterMapper;
import com.yohoufo.dal.order.model.InviteActivity;
import com.yohoufo.dal.order.model.InviteRecord;
import com.yohoufo.dal.order.model.InviteSettlementItem;
import com.yohoufo.dal.order.model.Inviter;
import com.yohoufo.order.common.InviteRecordStatusEnum;
import com.yohoufo.order.common.InviterStatus;
import com.yohoufo.order.common.InviterType;
... ... @@ -19,6 +21,7 @@ import com.yohoufo.order.service.IInviteService;
import com.yohoufo.order.service.IStoredSellerService;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.service.support.InviteCodeGenerator;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -187,15 +190,23 @@ public class InviteServiceImpl implements IInviteService {
}
// 获取展示用的邀请码
String showInviteCode = getShowInviteCode(uid);
Pair<String,List<Inviter>> showInviteCodeAndInviter = getShowInviteCode(uid);
if (StringUtils.isEmpty(showInviteCode)){
if (StringUtils.isEmpty(showInviteCodeAndInviter.getLeft())){
LOGGER.warn("has no showInviteCode. uid is {}", uid);
throw new ServiceException(ServiceError.HAS_NO_ENTER);
}
// 有邀请码的场合,获取邀请的好友
List<InviteRecord> inviteRecords = inviteRecordMapper.selectByInviterUid(uid);
// 入驻商户角色的邀请记录
Integer storedInviterId = showInviteCodeAndInviter.getRight().stream()
.filter(e->e.getType().intValue() == InviterType.STORED_SELLER.getType())
.map(Inviter::getId)
.findFirst()
.orElse(null);
List<InviteRecord> inviteRecords = inviteRecordMapper.selectByInviterUid(uid).stream()
.filter(e->e.getInviterId().equals(storedInviterId))
.collect(Collectors.toList());
if (!CollectionUtils.isEmpty(inviteRecords)){
List<Integer> inviteeUidList = inviteRecords.stream().map(InviteRecord::getInviteeUid).collect(Collectors.toList());
... ... @@ -213,7 +224,7 @@ public class InviteServiceImpl implements IInviteService {
return InviteInfoResp.builder()
.uid(uid)
.showInviteCode(showInviteCode)
.showInviteCode(showInviteCodeAndInviter.getLeft())
.inviteeUidNum(inviteeUidList.size())
.finishedOrderNum(orderNumMap.values().stream().collect(Collectors.summingInt(Integer::intValue)))
.inviteRecordList(getInviteRecordList(inviteRecords, orderNumMap, nickNameMap))
... ... @@ -221,21 +232,21 @@ public class InviteServiceImpl implements IInviteService {
}
return InviteInfoResp.builder().uid(uid).showInviteCode(showInviteCode).build();
return InviteInfoResp.builder().uid(uid).showInviteCode(showInviteCodeAndInviter.getLeft()).build();
}
private List<InviteInfoResp.InviteRecord> getInviteRecordList(List<InviteRecord> inviteRecords,
Map<Integer, Integer> orderNumMap,
Map<Integer, String> nickNameMap) {
return inviteRecords.stream().map(x ->{
return InviteInfoResp.InviteRecord.builder()
return inviteRecords.stream()
.map(x -> InviteInfoResp.InviteRecord.builder()
.inviteeUid(x.getInviteeUid())
.nickName(Objects.isNull(nickNameMap.get(x.getInviteeUid())) ? "" : nickNameMap.get(x.getInviteeUid()))
.enterTime(DateUtil.formatYYMMddHHmmssPoint(x.getCreateTime()))
.orderNum(Objects.isNull(orderNumMap.get(x.getInviteeUid())) ? 0 : orderNumMap.get(x.getInviteeUid()))
.build();
}).collect(Collectors.toList());
.build())
.collect(Collectors.toList());
}
/**
... ... @@ -243,7 +254,7 @@ public class InviteServiceImpl implements IInviteService {
* @param uid
* @return
*/
private String getShowInviteCode(int uid) {
private Pair<String,List<Inviter>> getShowInviteCode(int uid) {
// 查看是否已经有邀请码
List<Inviter> inviters = inviterMapper.selectInviteCodeByUid(uid);
... ... @@ -292,7 +303,7 @@ public class InviteServiceImpl implements IInviteService {
}
}
return lastShowInvite;
return Pair.of(lastShowInvite,inviters);
}
... ...