...
|
...
|
@@ -24,12 +24,16 @@ import com.yoho.product.request.BatchBaseRequest; |
|
|
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.request.LimitProductHelpUserRequestBO;
|
|
|
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;
|
|
|
import org.springframework.dao.DataIntegrityViolationException;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
...
|
...
|
@@ -41,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
|
...
|
...
|
@@ -61,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();
|
...
|
...
|
@@ -91,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;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -105,6 +131,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
public CutDownPriceActivityProductBo queryCutProductInfo(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) {
|
|
|
Integer activityId = cutPriceHelpUserRequestBO.getActivityId();
|
|
|
Integer productSkn = cutPriceHelpUserRequestBO.getProductSkn();
|
|
|
Integer userId = cutPriceHelpUserRequestBO.getUserId();
|
|
|
// 查询活动信息
|
|
|
CutDownPriceActivityBo activityBo = cutDownActivityService.queryActivityInfo(activityId);
|
|
|
checkValidActivity(activityBo, activityId);
|
...
|
...
|
@@ -121,7 +148,48 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
request.setParams(Lists.newArrayList(productSkn));
|
|
|
ProductBo[] productBoArray = serviceCaller.call("product.batchQueryNamesAndImageBySkns", request, ProductBo[].class);
|
|
|
// 组装信息
|
|
|
return buildCutDownPriceActivityProductBo(activityBo, cutDownPriceProductBo, helpUserBos, productBoArray);
|
|
|
CutDownPriceActivityProductBo bo = buildCutDownPriceActivityProductBo(activityBo, cutDownPriceProductBo, helpUserBos, productBoArray);
|
|
|
bo.setCanUseCount(selectCutdownPriceOrderRecordCount(cutPriceHelpUserRequestBO));
|
|
|
return bo;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public CutDownPriceActivityProductBo queryCutProductInfoForOrder(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) {
|
|
|
Integer activityId = cutPriceHelpUserRequestBO.getActivityId();
|
|
|
Integer productSkn = cutPriceHelpUserRequestBO.getProductSkn();
|
|
|
Integer userId = cutPriceHelpUserRequestBO.getUserId();
|
|
|
// 查询活动信息
|
|
|
CutDownPriceActivityBo activityBo = cutDownActivityService.queryActivityInfo(activityId);
|
|
|
checkValidActivity(activityBo, activityId);
|
|
|
// 查询商品配置信息
|
|
|
CutDownPriceProductBo cutDownPriceProductBo = cutDownPriceProductService.queryCutDownPriceProductBo(activityId, productSkn);
|
|
|
if(cutDownPriceProductBo==null){
|
|
|
logger.warn(" the cutdown product not exist, activityId is {}, productSkn is {}", activityId, productSkn);
|
|
|
throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_PRODUCT_NOTEXIST_ERROR);
|
|
|
}
|
|
|
CutDownPriceUserRecord record = cutDownPriceUserRecordMapper.selectCutDownPriceUserRecord(userId, activityId, productSkn);
|
|
|
// 组装信息
|
|
|
CutDownPriceActivityProductBo bo = buildCutDownPriceActivityProductBo(activityBo, cutDownPriceProductBo, null, null);
|
|
|
if(record!=null){
|
|
|
// 设置是否已使用
|
|
|
bo.setCanUseCount(record.getUseCount());
|
|
|
// 设置已砍价记录
|
|
|
bo.setHasJoinNum(record.getHelpCount());
|
|
|
}
|
|
|
return bo;
|
|
|
}
|
|
|
|
|
|
private int selectCutdownPriceOrderRecordCount(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) {
|
|
|
Integer userId = cutPriceHelpUserRequestBO.getUserId();
|
|
|
int useCount = 0;
|
|
|
// 登陆情况下查询使用记录
|
|
|
if(userId!=null){
|
|
|
CutDownPriceUserRecord record = cutDownPriceUserRecordMapper.selectCutDownPriceUserRecord(userId, cutPriceHelpUserRequestBO.getActivityId(), cutPriceHelpUserRequestBO.getProductSkn());
|
|
|
if(record!=null){
|
|
|
useCount = record.getUseCount();
|
|
|
}
|
|
|
}
|
|
|
return useCount;
|
|
|
}
|
|
|
|
|
|
@Override
|
...
|
...
|
@@ -157,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));
|
...
|
...
|
@@ -170,11 +238,34 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void addCutPriceUseRecord(CutPriceHelpUserRequestBO requestBO) {
|
|
|
try{
|
|
|
// 扣减可使用次数
|
|
|
int affectRow = cutDownPriceUserRecordMapper.updateDecreaseUseCount(requestBO.getUserId(), requestBO.getActivityId(), requestBO.getProductSkn());
|
|
|
if(affectRow<=0){
|
|
|
logger.warn("updateDecreaseUseCount success!!!,affectRow is:{} ", affectRow);
|
|
|
throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_YOU_HAS_USED_CUTDOWNORDER_ERROR);
|
|
|
}
|
|
|
}catch(DataIntegrityViolationException e){
|
|
|
throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_YOU_HAS_USED_CUTDOWNORDER_ERROR);
|
|
|
}
|
|
|
// 清理缓存
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int cancelCutPriceUseRecord(CutPriceHelpUserRequestBO requestBO) {
|
|
|
// 回补可使用次数
|
|
|
int result = cutDownPriceUserRecordMapper.updateIncreaseUseCount(requestBO.getUserId(), requestBO.getActivityId(), requestBO.getProductSkn());
|
|
|
// 清理缓存
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public BigDecimal addHelpUserInfo(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) {
|
|
|
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);
|
...
|
...
|
@@ -199,8 +290,20 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
CutDownPriceProductHelpUser helpUser = convertCutDownPriceProductHelpUser(cutPriceHelpUserRequestBO);
|
|
|
helpUser.setCutPrice(cutPrice);
|
|
|
helpUser.setCreateTime(DateUtils.getCurrentTimeSecond());
|
|
|
// 插入表
|
|
|
// 插入好友帮砍记录表
|
|
|
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;
|
...
|
...
|
@@ -231,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;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -259,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<>();
|
...
|
...
|
@@ -287,20 +404,49 @@ 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){
|
|
|
if(null!=helpUserBo.getHelpUserId() && SYSTEM_HELP_ID!=helpUserBo.getHelpUserId()){
|
|
|
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,
|
...
|
...
|
@@ -315,21 +461,24 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
activityProductBo.setHighPrice(cutDownPriceProductBo.getHighPrice());
|
|
|
activityProductBo.setLowPrice(cutDownPriceProductBo.getLowPrice());
|
|
|
activityProductBo.setJoinNum(cutDownPriceProductBo.getJoinNum());
|
|
|
Map<Integer, ProductBo> productBoMap = Arrays.asList(productBoArray).stream().parallel().collect(Collectors.toMap(ProductBo::getErpProductId, (p) -> p));
|
|
|
|
|
|
ProductBo productBo = productBoMap.get(cutDownPriceProductBo.getProductSkn());
|
|
|
if(productBo!=null){
|
|
|
activityProductBo.setProductName(productBo.getProductName());
|
|
|
activityProductBo.setDefaultImages(productBo.getDefaultImageUrl());
|
|
|
if(ArrayUtils.isNotEmpty(productBoArray)){
|
|
|
Map<Integer, ProductBo> productBoMap = Arrays.asList(productBoArray).stream().parallel().collect(Collectors.toMap(ProductBo::getErpProductId, (p) -> p));
|
|
|
ProductBo productBo = productBoMap.get(cutDownPriceProductBo.getProductSkn());
|
|
|
if(productBo!=null){
|
|
|
activityProductBo.setProductName(productBo.getProductName());
|
|
|
activityProductBo.setDefaultImages(productBo.getDefaultImageUrl());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
BigDecimal hasCutPrice = new BigDecimal(0);
|
|
|
for(CutDownPriceProductHelpUserBo helpUserBo : helpUserBos){
|
|
|
hasCutPrice = hasCutPrice.add(helpUserBo.getCutPrice());
|
|
|
activityProductBo.setUserImgUrl(helpUserBo.getUserImgUrl());// 赋值一次就可以了
|
|
|
if(CollectionUtils.isNotEmpty(helpUserBos)){
|
|
|
BigDecimal hasCutPrice = new BigDecimal(0);
|
|
|
for(CutDownPriceProductHelpUserBo helpUserBo : helpUserBos){
|
|
|
hasCutPrice = hasCutPrice.add(helpUserBo.getCutPrice());
|
|
|
activityProductBo.setUserImgUrl(helpUserBo.getUserImgUrl());// 赋值一次就可以了
|
|
|
}
|
|
|
activityProductBo.setHasCutPrice(hasCutPrice);
|
|
|
activityProductBo.setHasJoinNum(helpUserBos.size());
|
|
|
}
|
|
|
activityProductBo.setHasCutPrice(hasCutPrice);
|
|
|
activityProductBo.setHasJoinNum(helpUserBos.size());
|
|
|
return activityProductBo;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -384,9 +533,11 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
|
|
|
// 清理缓存,用户帮砍记录列表、商品详情页
|
|
|
private void clearCache(Integer activityId, Integer productSkn, Integer userId) {
|
|
|
// 取缓存
|
|
|
// 清理用户帮砍记录列表
|
|
|
String redisKeySuffix = userId + ":" + activityId + ":" + productSkn;
|
|
|
redisValueCache.delete(CacheKeyEnum.CUTDOWN_PRICE_HELP_USERLIST_INFO, redisKeySuffix);
|
|
|
// 清理我的砍价列表
|
|
|
redisHashCache.delete(CacheKeyEnum.CUTDOWN_PRICE_MYPRODUCTLIST_INFO.getCacheKey(), userId);
|
|
|
|
|
|
}
|
|
|
|
...
|
...
|
|