|
|
package com.yohoufo.order.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.common.collect.Maps;
|
|
|
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.yoho.service.model.social.response.UserInfoRspBO;
|
|
|
import com.yohobuy.ufo.model.order.resp.InviteInfoResp;
|
|
|
import com.yohoufo.common.ApiResponse;
|
|
|
import com.yohoufo.common.exception.UfoServiceException;
|
|
|
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;
|
|
|
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;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
...
|
...
|
@@ -31,7 +33,6 @@ import java.util.List; |
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
import java.util.Optional;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
...
|
...
|
@@ -43,9 +44,6 @@ public class InviteServiceImpl implements IInviteService { |
|
|
IStoredSellerService storedSellerService;
|
|
|
|
|
|
@Autowired
|
|
|
InviteCodeSequenceMapper inviteCodeSequenceMapper;
|
|
|
|
|
|
@Autowired
|
|
|
InviterMapper inviterMapper;
|
|
|
|
|
|
@Autowired
|
...
|
...
|
@@ -60,9 +58,12 @@ public class InviteServiceImpl implements IInviteService { |
|
|
@Autowired
|
|
|
ServiceCaller serviceCaller;
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
UserProxyService userProxyService;
|
|
|
|
|
|
@Autowired
|
|
|
InviteCodeGenerator inviteCodeGenerator;
|
|
|
|
|
|
/**
|
|
|
* 是否需要跳转到入驻页面
|
|
|
* @param uid
|
...
|
...
|
@@ -189,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());
|
...
|
...
|
@@ -215,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))
|
...
|
...
|
@@ -223,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());
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -245,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);
|
...
|
...
|
@@ -272,7 +281,7 @@ public class InviteServiceImpl implements IInviteService { |
|
|
|
|
|
// 已入驻
|
|
|
if (storedSeller){
|
|
|
Integer generateAInviteCode = generateInviteCodeSequence(uid);
|
|
|
Integer generateAInviteCode = saveInviteCode(uid);
|
|
|
|
|
|
lastShowInvite = generateAInviteCode != null ?
|
|
|
getShowInviteCode(InviterType.STORED_SELLER, generateAInviteCode)
|
...
|
...
|
@@ -288,13 +297,13 @@ public class InviteServiceImpl implements IInviteService { |
|
|
if (!storedSeller){
|
|
|
lastShowInvite = null;
|
|
|
}else{
|
|
|
Integer generateAInviteCode = generateInviteCodeSequence(uid);
|
|
|
Integer generateAInviteCode = saveInviteCode(uid);
|
|
|
|
|
|
lastShowInvite = generateAInviteCode != null ? getShowInviteCode(InviterType.STORED_SELLER, generateAInviteCode) : null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return lastShowInvite;
|
|
|
return Pair.of(lastShowInvite,inviters);
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
@@ -318,7 +327,7 @@ public class InviteServiceImpl implements IInviteService { |
|
|
* @param uid
|
|
|
* @return
|
|
|
*/
|
|
|
private Integer generateInviteCodeSequence(int uid) {
|
|
|
private Integer saveInviteCode(int uid) {
|
|
|
|
|
|
// 是否存在A类邀请码,(即使是无效的也不会继续生成)
|
|
|
Inviter aClassInviter = inviterMapper.selectInviteCodeByUidType(uid, InviterType.STORED_SELLER.getType());
|
...
|
...
|
@@ -329,25 +338,25 @@ public class InviteServiceImpl implements IInviteService { |
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 生成邀请码
|
|
|
InviteCodeSequence inviteCodeSequence = new InviteCodeSequence();
|
|
|
inviteCodeSequence.setCreateTime(DateUtil.getCurrentTimeSecond());
|
|
|
inviteCodeSequenceMapper.insert(inviteCodeSequence);
|
|
|
Integer codeSequence = inviteCodeGenerator.generateCodeSequenceRandom();
|
|
|
|
|
|
// 插入邀请码
|
|
|
Inviter inviter = new Inviter();
|
|
|
inviter.setUid(uid);
|
|
|
inviter.setType(InviterType.STORED_SELLER.getType());
|
|
|
inviter.setInviteCode(inviteCodeSequence.getId());
|
|
|
inviter.setInviteCode(codeSequence);
|
|
|
int now = DateUtil.getCurrentTimeSecond();
|
|
|
inviter.setUpdateTime(now);
|
|
|
inviter.setCreateTime(now);
|
|
|
inviterMapper.insertSelective(inviter);
|
|
|
|
|
|
return inviteCodeSequence.getId();
|
|
|
return codeSequence;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 邀请者退驻则之前的所有绑定关系无效
|
|
|
* @param uid
|
...
|
...
|
|