...
|
...
|
@@ -25,8 +25,11 @@ import com.yoho.product.response.PageResponseBo; |
|
|
import com.yoho.service.model.activity.*;
|
|
|
import com.yoho.service.model.activity.drawline.request.CutPriceHelpUserRequestBO;
|
|
|
import com.yoho.service.model.activity.drawline.response.UserBaseRspBO;
|
|
|
import com.yoho.service.model.social.request.UicUserReqBO;
|
|
|
import com.yoho.service.model.social.response.UserInfoRspBO;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
...
|
...
|
@@ -42,6 +45,9 @@ import java.util.stream.Collectors; |
|
|
@Service
|
|
|
public class CutDownPriceServiceImpl implements ICutDownPriceService {
|
|
|
private static Logger logger = LoggerFactory.getLogger(CutDownPriceServiceImpl.class);
|
|
|
private static final Integer SYSTEM_HELP_ID = 0;
|
|
|
private static final String SYSTEM_HELP_NAME = "有货";
|
|
|
private static final String SYSTEM_HELP_IMAGE = "https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKic2dZ7ib6p1PJJXFpYl95ibRyvSKCib3icUiaStlRN6PWmcRZjzPn4w4moEk2xhUxpYbibuPtBNPJBMeqQ/132";
|
|
|
@Autowired
|
|
|
private RedisValueCache redisValueCache;
|
|
|
@Autowired
|
...
|
...
|
@@ -62,6 +68,23 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
private BeanConvert convert;
|
|
|
|
|
|
@Override
|
|
|
public CutDownPriceActivityBo queryEffectCutPriceActivity() {
|
|
|
CutDownPriceActivityBo activityBo = null;
|
|
|
List<CutDownPriceActivityBo> activityBoList = cutDownActivityService.queryEffectCutPriceActivitys();
|
|
|
if(CollectionUtils.isEmpty(activityBoList)){
|
|
|
return null;
|
|
|
}
|
|
|
int currentTime = DateUtils.getCurrentTimeSecond();
|
|
|
for(CutDownPriceActivityBo bo : activityBoList){
|
|
|
if(bo.getBeginTime()<currentTime && bo.getEndTime()>currentTime){
|
|
|
activityBo = bo;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
return activityBo;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<CutDownPriceProductHelpUserBo> queryHelpInfo(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) {
|
|
|
Integer activityId = cutPriceHelpUserRequestBO.getActivityId();
|
|
|
Integer productSkn = cutPriceHelpUserRequestBO.getProductSkn();
|
...
|
...
|
@@ -92,13 +115,15 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
/**
|
|
|
* 查询某一个用户的帮砍记录
|
|
|
*/
|
|
|
private List<CutDownPriceProductHelpUserBo> queryHelpInfoList(List<CutPriceHelpUserRequestBO> requestList) {
|
|
|
private List<CutDownPriceProductHelpUserBo> queryHelpInfoList(Integer userId, List<CutPriceHelpUserRequestBO> requestList) {
|
|
|
List<CutDownPriceProductHelpUser> helpUsers = cutPriceUserHelpMapper.selectHelpInfoList(requestList);
|
|
|
if (CollectionUtils.isEmpty(helpUsers)){
|
|
|
logger.info("CutDownPriceServiceImpl :: queryHelpInfoList result is null");
|
|
|
return Lists.newArrayList();
|
|
|
}
|
|
|
List<CutDownPriceProductHelpUserBo> helpUsersBoList = convert.convertFromList(helpUsers, CutDownPriceProductHelpUserBo.class);
|
|
|
//获取用户头像
|
|
|
getUserInfo(userId, helpUsersBoList);
|
|
|
return helpUsersBoList;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -200,7 +225,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
List<CutDownPriceProductBo> cutProductBoList = cutDownPriceProductService.queryCutDownPriceProductBoListByRecords(cutPriceUserRecordList);
|
|
|
// 查询已砍价记录
|
|
|
List<CutPriceHelpUserRequestBO> userRequestList = convert.convertFromList(cutPriceUserRecordList, CutPriceHelpUserRequestBO.class);
|
|
|
List<CutDownPriceProductHelpUserBo> helpUserBoList = this.queryHelpInfoList(userRequestList);
|
|
|
List<CutDownPriceProductHelpUserBo> helpUserBoList = this.queryHelpInfoList(uid, userRequestList);
|
|
|
// 根据skn列表查询商品信息
|
|
|
BatchBaseRequest<Integer> productRequest = new BatchBaseRequest<Integer>();
|
|
|
productRequest.setParams(Lists.newArrayList(productSkns));
|
...
|
...
|
@@ -240,7 +265,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
Integer activityId = cutPriceHelpUserRequestBO.getActivityId();
|
|
|
Integer productSkn = cutPriceHelpUserRequestBO.getProductSkn();
|
|
|
Integer userId = cutPriceHelpUserRequestBO.getUserId();
|
|
|
String helpUserId = cutPriceHelpUserRequestBO.getHelpUserId();
|
|
|
Integer helpUserId = cutPriceHelpUserRequestBO.getHelpUserId();
|
|
|
|
|
|
//判断用户是否已经帮助砍价
|
|
|
Integer count = cutPriceUserHelpMapper.selectExistHelpInfo(userId, helpUserId, activityId, productSkn);
|
...
|
...
|
@@ -269,6 +294,16 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
cutPriceUserHelpMapper.addHelpUserInfo(helpUser);
|
|
|
// 修改用户发起砍价记录表中的帮砍次数
|
|
|
cutDownPriceUserRecordMapper.updateCutDownHelpCount(userId, activityId, productSkn);
|
|
|
// 用户帮忙砍价后,自动发起砍价活动,系统帮助砍价除外
|
|
|
if(!SYSTEM_HELP_ID.equals(helpUserId)){
|
|
|
try{
|
|
|
cutPriceHelpUserRequestBO.setUserId(Integer.valueOf(helpUserId));
|
|
|
logger.info(" system start addCutPriceRecord, userId is {}, activityId is {}, productSkn is {}", userId, activityId, productSkn);
|
|
|
addCutPriceRecord(cutPriceHelpUserRequestBO);
|
|
|
}catch(Exception e){
|
|
|
logger.warn(" system addHelpUserInfo failed, userId is {}, activityId is {}, productSkn is {}, exception is {}", userId, activityId, productSkn, e);
|
|
|
}
|
|
|
}
|
|
|
// 清理缓存,用户帮砍记录列表、商品详情页
|
|
|
clearCache(activityId, productSkn, userId);
|
|
|
return cutPrice;
|
...
|
...
|
@@ -299,7 +334,16 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
record.setProductSkn(productSkn);
|
|
|
record.setUserId(userId);
|
|
|
record.setCreateTime(DateUtils.getCurrentTimeSecond());
|
|
|
logger.info(" addCutDownUserRecord, userId is {}, activityId is {}, productSkn is {}", userId, activityId, productSkn);
|
|
|
int num = cutDownPriceUserRecordMapper.addCutDownUserRecord(record);
|
|
|
// 系统帮助砍第一次价
|
|
|
try{
|
|
|
logger.info(" system start addHelpUserInfo, userId is {}, activityId is {}, productSkn is {}", userId, activityId, productSkn);
|
|
|
addHelpUserInfo(convertCutDownPriceProductSystemHelpUser(cutPriceHelpUserRequestBO));
|
|
|
}catch(Exception e){
|
|
|
logger.warn(" system addHelpUserInfo failed, userId is {}, activityId is {}, productSkn is {}, exception is {}", userId, activityId, productSkn, e);
|
|
|
}
|
|
|
|
|
|
return num;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -327,12 +371,17 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
user.setUserId(request.getUserId());
|
|
|
user.setActivityId(request.getActivityId());
|
|
|
user.setProductSkn(request.getProductSkn());
|
|
|
user.setHelpUserName(request.getHelpUserName());
|
|
|
user.setHelpUserId(request.getHelpUserId());
|
|
|
user.setHelpUserImgUrl(request.getHelpUserImgUrl());
|
|
|
return user;
|
|
|
}
|
|
|
|
|
|
private CutPriceHelpUserRequestBO convertCutDownPriceProductSystemHelpUser(CutPriceHelpUserRequestBO request) {
|
|
|
request.setHelpUserName(SYSTEM_HELP_NAME);
|
|
|
request.setHelpUserId(SYSTEM_HELP_ID);
|
|
|
request.setHelpUserImgUrl(SYSTEM_HELP_IMAGE);
|
|
|
return request;
|
|
|
}
|
|
|
|
|
|
private BigDecimal calculateCutPrice(CutDownPriceProductBo cutDownPriceProductBo, List<CutDownPriceProductHelpUser> helpUsers) {
|
|
|
if(helpUsers==null){
|
|
|
helpUsers = new ArrayList<>();
|
...
|
...
|
@@ -355,20 +404,47 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
}
|
|
|
|
|
|
private void getUserInfo(Integer userId, List<CutDownPriceProductHelpUserBo> helpUserBos) {
|
|
|
List<Integer> uidList = new ArrayList<>();
|
|
|
uidList.add(userId);
|
|
|
AsyncFuture<UserBaseRspBO[]> userBaseRspBOArrAsync = drawlineList2MapService.postForUserBaseInfo(uidList);
|
|
|
UserBaseRspBO[] userBaseRspBOs = userBaseRspBOArrAsync.get();
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
sb.append(userId);
|
|
|
for (CutDownPriceProductHelpUserBo helpUserBo : helpUserBos){
|
|
|
sb.append(",").append(helpUserBo.getHelpUserId());
|
|
|
}
|
|
|
UserInfoRspBO[] userInfoBoArray = invokeUicGetUserInfo(sb.toString());
|
|
|
for (CutDownPriceProductHelpUserBo helpUserBo : helpUserBos){
|
|
|
for (UserInfoRspBO userInfoRspBO : userInfoBoArray){
|
|
|
if(helpUserBo.getHelpUserId().equals(SYSTEM_HELP_ID)) {
|
|
|
helpUserBo.setHelpUserImgUrl(SYSTEM_HELP_IMAGE);
|
|
|
helpUserBo.setHelpUserName(SYSTEM_HELP_NAME);
|
|
|
break;
|
|
|
}else if (helpUserBo.getHelpUserId().equals(userInfoRspBO.getUid())){
|
|
|
helpUserBo.setHelpUserImgUrl(userInfoRspBO.getHeadIco());
|
|
|
helpUserBo.setHelpUserName(userInfoRspBO.getNickName());
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
for (CutDownPriceProductHelpUserBo helpUserBo : helpUserBos){
|
|
|
for (UserBaseRspBO userBaseRspBO : userBaseRspBOs){
|
|
|
if (helpUserBo.getUserId().equals(userBaseRspBO.getUid())){
|
|
|
helpUserBo.setUserImgUrl(userBaseRspBO.getHeadIco());
|
|
|
for (UserInfoRspBO userInfoRspBO : userInfoBoArray){
|
|
|
if (userId.equals(userInfoRspBO.getUid())){
|
|
|
helpUserBo.setUserImgUrl(userInfoRspBO.getHeadIco());
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private UserInfoRspBO[] invokeUicGetUserInfo(String uids) {
|
|
|
if(StringUtils.isEmpty(uids)){
|
|
|
return new UserInfoRspBO[0];
|
|
|
}
|
|
|
|
|
|
UicUserReqBO request = new UicUserReqBO();
|
|
|
request.setUids(uids);
|
|
|
logger.info("start invoke uic.getUserInfoListByYohoUid, uids is {}", uids);
|
|
|
UserInfoRspBO[] userInfoBoArray = serviceCaller.call("uic.getUserInfoListByYohoUid", request, UserInfoRspBO[].class);
|
|
|
return userInfoBoArray;
|
|
|
}
|
|
|
|
|
|
private CutDownPriceActivityProductBo buildCutDownPriceActivityProductBo(CutDownPriceActivityBo activityBo,
|
|
|
CutDownPriceProductBo cutDownPriceProductBo,
|
|
|
List<CutDownPriceProductHelpUserBo> helpUserBos,
|
...
|
...
|
|