Authored by LUOXC

Merge branch 'hotfix-invite-activity' of http://git.yoho.cn/ufo/yohoufo-fore int…

…o hotfix-invite-activity
... ... @@ -47,6 +47,8 @@ public class DateUtil {
public static final String yyyyMM = "yyyyMM";
public static final String MM_dd_yyyy_HH_mm_ssEx = "yyyy.MM.dd HH:mm";
public static final String MM_dd_yyyy_HH_mm_ss_long = "yyyy.MM.dd HH:mm:ss";
private static final int[] dayArray =
new int[]{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
... ... @@ -91,12 +93,12 @@ public class DateUtil {
public static String getDateFormatLong(Long time)
{
if (time == null) {
return "";
if (time == null || time==0) {
return "0";
}
SimpleDateFormat sdf=new SimpleDateFormat(MM_dd_yyyy_HH_mm_ssEx);
SimpleDateFormat sdf=new SimpleDateFormat(MM_dd_yyyy_HH_mm_ss_long);
Calendar c=Calendar.getInstance();
c.setTimeInMillis((time.longValue()));
c.setTimeInMillis((time.longValue()*1000));
return sdf.format(c.getTime());
}
... ...
... ... @@ -12,7 +12,6 @@ public interface InviteRecordMapper {
InviteRecord selectByPrimaryKey(Integer id);
InviteRecord selectByInviterAndInviteeUid(@Param("inviterUid") Integer inviterUid, @Param("inviterUid") Integer inviteeUid);
List<InviteRecord> selectByInviterUid(@Param("inviterUid") Integer inviterUid);
... ...
... ... @@ -25,7 +25,7 @@ public interface InviteSettlementItemMapper {
@Param("type") Integer type,
@Param("inviteSettlementId") Integer inviteSettlementId);
List<InviteSettlementItem> selectByInviterUid(@Param("inviterUid") Integer inviterUid);
List<InviteSettlementItem> selectOrderNumByInviterUid(@Param("inviterUid") Integer inviterUid);
int updateByPrimaryKeySelective(InviteSettlementItem record);
BigDecimal selectTotalOrderAmountByUidTypeAndInviteSettlementId(@Param("uid") Integer uid,
... ...
... ... @@ -42,13 +42,7 @@
</update>
<select id="selectByInviterAndInviteeUid" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from invite_record
where inviter_uid = #{inviterUid,jdbcType=INTEGER}
and invitee_uid = #{inviteeUid,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from invite_record
... ...
... ... @@ -52,6 +52,14 @@
limit 1
</select>
<select id="selectOrderNumByInviterUid" resultMap="BaseResultMap" >
select
seller_uid, count(buyer_order_code) order_num
from invite_settlement_item
where uid = #{inviterUid,jdbcType=INTEGER} and status in (1,3)
GROUP by seller_uid
</select>
<select id="selectCountByUidTypeAndInviteSettlementId" resultType="java.lang.Integer" >
select
count(1)
... ...
... ... @@ -27,7 +27,7 @@
<include refid="Base_Column_List" />
from inviter
where
state=1
status=1
and type = #{type,jdbcType=INTEGER}
and invite_code = #{inviteCode,jdbcType=INTEGER}
limit 1;
... ...
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.*;
... ... @@ -13,15 +18,20 @@ 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 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;
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
... ... @@ -47,6 +57,12 @@ public class InviteServiceImpl implements IInviteService {
@Autowired
InviteSettlementItemMapper inviteSettlementItemMapper;
@Autowired
ServiceCaller serviceCaller;
@Autowired
UserProxyService userProxyService;
/**
* 是否需要跳转到入驻页面
* @param uid
... ... @@ -101,6 +117,7 @@ public class InviteServiceImpl implements IInviteService {
// 校验邀请码的合法性
if (StringUtils.isEmpty(showInviteCode)){
LOGGER.info("enter shop uid[{}] has no inviteCode", uid);
return;
}
... ... @@ -131,10 +148,16 @@ public class InviteServiceImpl implements IInviteService {
throw new ServiceException(ServiceError.INVITE_CODE_NOT_EXIST);
}
// 不能自己邀请自己
if (inviter.getUid() == uid){
LOGGER.info("can not invite self, uid is {}, showInviteCode is {}", uid, showInviteCode);
throw new ServiceException(ServiceError.INVITE_CODE_NOT_EXIST);
}
// 校验是否已经有绑定关系
InviteRecord inviteRecord = inviteRecordMapper.selectByInviterAndInviteeUid(inviter.getUid(), uid);
InviteRecord inviteRecord = inviteRecordMapper.selectByInviteeUid(uid);
if (inviteRecord != null){
LOGGER.warn("has invite bind. showInviteCode is {}, uid is {}", showInviteCode, uid);
LOGGER.warn("has invite bind. showInviteCode is {}, invitee is {}, inviter is {}", showInviteCode, uid, inviteRecord.getInviterUid());
throw new ServiceException(ServiceError.INVITE_HAS_BIND);
}
... ... @@ -150,6 +173,9 @@ public class InviteServiceImpl implements IInviteService {
}
/**
* 获取邀请码信息
* @param uid
... ... @@ -166,7 +192,8 @@ public class InviteServiceImpl implements IInviteService {
String showInviteCode = getShowInviteCode(uid);
if (StringUtils.isEmpty(showInviteCode)){
return null;
LOGGER.warn("has no showInviteCode. uid is {}", uid);
throw new ServiceException(ServiceError.HAS_NO_ENTER);
}
// 有邀请码的场合,获取邀请的好友
... ... @@ -176,22 +203,22 @@ public class InviteServiceImpl implements IInviteService {
List<Integer> inviteeUidList = inviteRecords.stream().map(InviteRecord::getInviteeUid).collect(Collectors.toList());
// 批量查询昵称
Map<Integer, String> nickNameMap = userProxyService.getNickNameByUids(inviteeUidList);
// 批量查询入驻时间
List<StoredSeller> storedSellerList = storedSellerService.batchGetStoredSeller(inviteeUidList);
Map<Integer, Long> storedSellerMap = storedSellerList.stream().collect(Collectors.toMap(StoredSeller::getUid, StoredSeller::getEnterTime));
// 批量查询订单数目
List<InviteSettlementItem> orderNumList = inviteSettlementItemMapper.selectByInviterUid(uid);
List<InviteSettlementItem> orderNumList = inviteSettlementItemMapper.selectOrderNumByInviterUid(uid);
Map<Integer, Integer> orderNumMap = orderNumList.stream().collect(Collectors.toMap(InviteSettlementItem::getSellerUid, InviteSettlementItem::getOrderNum));
return InviteInfoResp.builder()
.uid(uid)
.showInviteCode(showInviteCode)
.inviteeUidNum(inviteeUidList.size())
.finishedOrderNum(orderNumMap.keySet().stream().collect(Collectors.summingInt(Integer::intValue)))
.inviteRecordList(getInviteRecordList(inviteRecords, storedSellerMap, orderNumMap))
.inviteRecordList(getInviteRecordList(inviteRecords, storedSellerMap, orderNumMap, nickNameMap))
.build();
}
... ... @@ -200,13 +227,16 @@ public class InviteServiceImpl implements IInviteService {
}
private List<InviteInfoResp.InviteRecord> getInviteRecordList(List<InviteRecord> inviteRecords, Map<Integer, Long> storedSellerMap, Map<Integer, Integer> orderNumMap) {
private List<InviteInfoResp.InviteRecord> getInviteRecordList(List<InviteRecord> inviteRecords,
Map<Integer, Long> storedSellerMap,
Map<Integer, Integer> orderNumMap,
Map<Integer, String> nickNameMap) {
return inviteRecords.stream().map(x ->{
return InviteInfoResp.InviteRecord.builder()
.inviteeUid(x.getInviteeUid())
.nikeName(null)
.nikeName(Objects.isNull(nickNameMap.get(x.getInviteeUid())) ? "" : nickNameMap.get(x.getInviteeUid()))
.enterTime(storedSellerMap.get(x.getInviteeUid()) == null ? "" : DateUtil.getDateFormatLong(storedSellerMap.get(x.getInviteeUid())))
.orderNum(orderNumMap.get(x.getInviteeUid()))
.orderNum(Objects.isNull(orderNumMap.get(x.getInviteeUid())) ? 0 : orderNumMap.get(x.getInviteeUid()))
.build();
}).collect(Collectors.toList());
}
... ... @@ -231,7 +261,7 @@ public class InviteServiceImpl implements IInviteService {
*/
Integer bClassInviteCode = null;
if (!CollectionUtils.isEmpty(inviters)){
bClassInviteCode = getInviteCode(inviters, InviterType.STORED_SELLER);
bClassInviteCode = getInviteCode(inviters, InviterType.CLASS_B_AGENT);
}
boolean storedSeller = storedSellerService.isStoredSeller(uid);
... ... @@ -270,9 +300,10 @@ public class InviteServiceImpl implements IInviteService {
private Integer getInviteCode(List<Inviter> inviters, InviterType inviterType){
return inviters.stream()
Optional<Inviter> inviter = inviters.stream()
.filter(x -> x.getType().intValue() == inviterType.getType() && x.getStatus().intValue() == InviterStatus.VALID.getCode())
.findAny().get().getInviteCode();
.findAny();
return inviter.isPresent() ? inviter.get().getInviteCode() : null;
}
... ... @@ -375,7 +406,7 @@ public class InviteServiceImpl implements IInviteService {
}
// 首次入驻才可以输入邀请码,如果之前有绑定关系了,则本次无效
InviteRecord inviteRecord = inviteRecordMapper.selectByInviterAndInviteeUid(inviter.getUid(), uid);
InviteRecord inviteRecord = inviteRecordMapper.selectByInviteeUid(uid);
if (inviteRecord!=null){
LOGGER.warn("[{}] [{}] [{}]. has bind. inviter uid is {}", showInviteCode, uid, orderCode, inviter.getUid());
return 0;
... ...
... ... @@ -7,6 +7,7 @@ import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yoho.service.model.request.UserAddressReqBO;
import com.yoho.service.model.social.response.UserInfoRspBO;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.order.convert.AddressInfoConvertor;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
... ... @@ -18,9 +19,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
* Created by chenchao on 2018/9/18.
... ... @@ -146,4 +149,33 @@ public class UserProxyService {
public boolean isEntryShop(int uid){
return storeSellerService.isStoredSeller(uid);
}
public static final String NICK_NAME_API = "/UserInfoRest/getUserInfoListByYohoUid";
/**
* 批量获取昵称
* @param uids
* @return
*/
public Map<Integer, String> getNickNameByUids(List<Integer> uids){
String url = uicUrl + NICK_NAME_API;
Map<String,Object> params = Maps.newHashMap();
params.put("uids", uids.stream().map(String::valueOf).collect(Collectors.joining(",")));
List<UserInfoRspBO> userInfo ;
try {
userInfo = serviceCaller.get("uic.getNickName", url, params,
List.class, null).get(500, TimeUnit.MILLISECONDS);
Map<Integer, String> nickNameMap = userInfo.stream().collect(Collectors.toMap(UserInfoRspBO::getYohoUid, UserInfoRspBO::getNickName));
return nickNameMap;
}catch (Exception ex){
logger.warn("getNickNameByUids fail, uids {}", uids, ex);
}
return Maps.newHashMap();
}
}
... ...