...
|
...
|
@@ -103,20 +103,25 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
if(userId==null){
|
|
|
return Lists.newArrayList();
|
|
|
}
|
|
|
CutDownPriceUserRecord record = cutDownPriceUserRecordMapper.selectCutDownPriceUserRecord(userId, activityId, productSkn);
|
|
|
if(record==null){
|
|
|
return Lists.newArrayList();
|
|
|
}
|
|
|
Integer recordId = record.getId();
|
|
|
// 取缓存
|
|
|
String redisKeySuffix = userId + ":" + activityId + ":" + productSkn;
|
|
|
String redisKeySuffix = userId + ":" + activityId + ":" + productSkn + ":" + recordId;
|
|
|
CutDownPriceProductHelpUserWrapper helpUserWrapper = redisValueCache.get(CacheKeyEnum.CUTDOWN_PRICE_HELP_USERLIST_INFO, redisKeySuffix, CutDownPriceProductHelpUserWrapper.class);
|
|
|
if (null != helpUserWrapper){
|
|
|
return helpUserWrapper.getHelpUserBoList();
|
|
|
}
|
|
|
List<CutDownPriceProductHelpUser> helpUsers = cutPriceUserHelpMapper.selectHelpInfo(userId, activityId, productSkn);
|
|
|
List<CutDownPriceProductHelpUser> helpUsers = cutPriceUserHelpMapper.selectHelpInfo(userId, activityId, productSkn, recordId);
|
|
|
if (CollectionUtils.isEmpty(helpUsers)){
|
|
|
logger.info("CutDownPriceServiceImpl :: queryHelpInfo result is null");
|
|
|
return Lists.newArrayList();
|
|
|
}
|
|
|
List<CutDownPriceProductHelpUserBo> helpUsersBoList = convert.convertFromList(helpUsers, CutDownPriceProductHelpUserBo.class);
|
|
|
//获取用户头像
|
|
|
getUserInfo(userId, helpUsersBoList);
|
|
|
getUserInfo(helpUsersBoList);
|
|
|
helpUserWrapper = new CutDownPriceProductHelpUserWrapper();
|
|
|
helpUserWrapper.setHelpUserBoList(helpUsersBoList);
|
|
|
redisValueCache.set(CacheKeyEnum.CUTDOWN_PRICE_HELP_USERLIST_INFO, redisKeySuffix, helpUserWrapper, 300, TimeUnit.SECONDS);
|
...
|
...
|
@@ -126,7 +131,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
/**
|
|
|
* 查询某一个用户的帮砍记录
|
|
|
*/
|
|
|
private List<CutDownPriceProductHelpUserBo> queryHelpInfoList(Integer userId, List<CutPriceHelpUserRequestBO> requestList) {
|
|
|
private List<CutDownPriceProductHelpUserBo> queryHelpInfoList(List<CutPriceHelpUserRequestBO> requestList) {
|
|
|
List<CutDownPriceProductHelpUser> helpUsers = cutPriceUserHelpMapper.selectHelpInfoList(requestList);
|
|
|
if (CollectionUtils.isEmpty(helpUsers)){
|
|
|
logger.info("CutDownPriceServiceImpl :: queryHelpInfoList result is null");
|
...
|
...
|
@@ -134,7 +139,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
}
|
|
|
List<CutDownPriceProductHelpUserBo> helpUsersBoList = convert.convertFromList(helpUsers, CutDownPriceProductHelpUserBo.class);
|
|
|
//获取用户头像
|
|
|
getUserInfo(userId, helpUsersBoList);
|
|
|
getUserInfo(helpUsersBoList);
|
|
|
return helpUsersBoList;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -152,13 +157,20 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
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, cutPriceHelpUserRequestBO.getActivityId(), cutPriceHelpUserRequestBO.getProductSkn());
|
|
|
// 查询已砍价记录
|
|
|
List<CutDownPriceProductHelpUserBo> helpUserBos = this.queryHelpInfo(cutPriceHelpUserRequestBO);
|
|
|
// 调product接口查询商品信息
|
|
|
ProductBo[] productBoArray = invokeBatchQueryNamesAndImageBySkns(Lists.newArrayList(productSkn));
|
|
|
// 调uid查询用户头像
|
|
|
UserInfoRspBO[] userInfoBoArray = invokeUicGetUserInfo(userId.toString());
|
|
|
// 组装信息
|
|
|
CutDownPriceActivityProductBo bo = buildCutDownPriceActivityProductBo(activityBo, cutDownPriceProductBo, helpUserBos, productBoArray);
|
|
|
bo.setCanUseCount(selectCutdownPriceOrderRecordCount(cutPriceHelpUserRequestBO));
|
|
|
bo.setUserImgUrl(buildUserImage(userId, userInfoBoArray));
|
|
|
bo.setCanUseCount(record!=null ? record.getUseCount() : 1);
|
|
|
bo.setCutTime(record!=null ? record.getCutTime() : record.getCreateTime());
|
|
|
bo.setCreateTime(record.getCreateTime());
|
|
|
buildCutStatus(bo);
|
|
|
return bo;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -223,6 +235,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
bo.setCanUseCount(record.getUseCount());
|
|
|
// 设置已砍价记录
|
|
|
bo.setHasJoinNum(record.getHelpCount());
|
|
|
bo.setCutRecordId(record.getId());
|
|
|
}
|
|
|
|
|
|
// 校验是否已经砍价成功
|
...
|
...
|
@@ -291,7 +304,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(uid, userRequestList);
|
|
|
List<CutDownPriceProductHelpUserBo> helpUserBoList = this.queryHelpInfoList(userRequestList);
|
|
|
// 根据skn列表查询商品信息
|
|
|
ProductBo[] productBoArray = invokeBatchQueryNamesAndImageBySkns(Lists.newArrayList(productSkns));
|
|
|
// 组装返回值
|
...
|
...
|
@@ -305,7 +318,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
public void addCutPriceUseRecord(CutPriceHelpUserRequestBO requestBO) {
|
|
|
try{
|
|
|
// 扣减可使用次数
|
|
|
int affectRow = cutDownPriceUserRecordMapper.updateDecreaseUseCount(requestBO.getUserId(), requestBO.getActivityId(), requestBO.getProductSkn());
|
|
|
int affectRow = cutDownPriceUserRecordMapper.updateDecreaseUseCount(requestBO.getUserId(), requestBO.getActivityId(), requestBO.getProductSkn(), requestBO.getCutRecordId());
|
|
|
if(affectRow<=0){
|
|
|
logger.warn("updateDecreaseUseCount success!!!,affectRow is:{} ", affectRow);
|
|
|
throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_YOU_HAS_USED_CUTDOWNORDER_ERROR);
|
...
|
...
|
@@ -319,7 +332,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
@Override
|
|
|
public int cancelCutPriceUseRecord(CutPriceHelpUserRequestBO requestBO) {
|
|
|
// 回补可使用次数
|
|
|
int result = cutDownPriceUserRecordMapper.updateIncreaseUseCount(requestBO.getUserId(), requestBO.getActivityId(), requestBO.getProductSkn());
|
|
|
int result = cutDownPriceUserRecordMapper.updateIncreaseUseCount(requestBO.getUserId(), requestBO.getActivityId(), requestBO.getProductSkn(), requestBO.getCutRecordId());
|
|
|
// 清理缓存
|
|
|
return result;
|
|
|
}
|
...
|
...
|
@@ -357,12 +370,20 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
logger.warn(" the cutdown product not exist, activityId is {}, productSkn is {}", activityId, productSkn);
|
|
|
throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_PRODUCT_NOTEXIST_ERROR);
|
|
|
}
|
|
|
// 查询已砍的价格,判断是否已经砍价成功
|
|
|
List<CutDownPriceProductHelpUser> helpUsers = cutPriceUserHelpMapper.selectHelpInfo(userId, activityId, productSkn);
|
|
|
if(helpUsers!=null && helpUsers.size()>=cutDownPriceProductBo.getJoinNum()+1){
|
|
|
// 查询该用户是否已经发起过(之前发起过,没砍价成功,发起时间超过24小时)
|
|
|
CutDownPriceUserRecord recordDb = cutDownPriceUserRecordMapper.selectCutDownPriceUserRecord(userId, activityId, productSkn);
|
|
|
if(recordDb==null){
|
|
|
logger.warn(" you have not create cutprice, activityId is {}, productSkn is {}", activityId, productSkn);
|
|
|
throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_YOU_HASNOT_CREATE_CUTDOWN_ERROR);
|
|
|
}
|
|
|
|
|
|
if(recordDb!=null && (recordDb.getHelpCount()>=cutDownPriceProductBo.getJoinNum()+1)){
|
|
|
logger.warn(" this activity have help full, activityId is {}, productSkn is {}", activityId, productSkn);
|
|
|
throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_HAS_HELPED_FULL_ERROR);
|
|
|
}
|
|
|
// 查询已砍的价格
|
|
|
List<CutDownPriceProductHelpUser> helpUsers = cutPriceUserHelpMapper.selectHelpInfo(userId, activityId, productSkn, recordDb.getId());
|
|
|
|
|
|
// 计算本次应该砍的价格
|
|
|
BigDecimal cutPrice = new BigDecimal(0);
|
|
|
if(SYSTEM_HELP_ID.equals(helpUserId)){
|
...
|
...
|
@@ -375,10 +396,11 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
CutDownPriceProductHelpUser helpUser = convertCutDownPriceProductHelpUser(cutPriceHelpUserRequestBO);
|
|
|
helpUser.setCutPrice(cutPrice);
|
|
|
helpUser.setCreateTime(DateUtils.getCurrentTimeSecond());
|
|
|
helpUser.setCutRecordId(recordDb.getId());
|
|
|
// 插入好友帮砍记录表
|
|
|
cutPriceUserHelpMapper.addHelpUserInfo(helpUser);
|
|
|
// 修改用户发起砍价记录表中的帮砍次数
|
|
|
cutDownPriceUserRecordMapper.updateCutDownHelpCount(userId, activityId, productSkn);
|
|
|
cutDownPriceUserRecordMapper.updateCutDownHelpCount(userId, activityId, productSkn, recordDb.getId());
|
|
|
// 用户帮忙砍价后,自动发起砍价活动,系统帮助砍价除外
|
|
|
if(!SYSTEM_HELP_ID.equals(helpUserId)){
|
|
|
try{
|
...
|
...
|
@@ -503,9 +525,11 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
return new BigDecimal(averagePrice).add(randomPrice);
|
|
|
}
|
|
|
|
|
|
private void getUserInfo(Integer userId, List<CutDownPriceProductHelpUserBo> helpUserBos) {
|
|
|
private void getUserInfo(List<CutDownPriceProductHelpUserBo> helpUserBos) {
|
|
|
if(CollectionUtils.isEmpty(helpUserBos)){
|
|
|
return;
|
|
|
}
|
|
|
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());
|
...
|
...
|
@@ -525,14 +549,6 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
for (CutDownPriceProductHelpUserBo helpUserBo : helpUserBos){
|
|
|
for (UserInfoRspBO userInfoRspBO : userInfoBoArray){
|
|
|
if (userId.equals(userInfoRspBO.getUid())){
|
|
|
helpUserBo.setUserImgUrl(userInfoRspBO.getHeadIco());
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private UserInfoRspBO[] invokeUicGetUserInfo(String uids) {
|
...
|
...
|
@@ -597,11 +613,11 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
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());
|
|
|
}
|
|
|
|
|
|
return activityProductBo;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -701,6 +717,21 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
}
|
|
|
}
|
|
|
|
|
|
private String buildUserImage(Integer userId, UserInfoRspBO[] userInfoBoArray) {
|
|
|
String imageUrl = null;
|
|
|
if(ArrayUtils.isEmpty(userInfoBoArray)){
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
for(UserInfoRspBO userInfoRspBO : userInfoBoArray){
|
|
|
if(userInfoRspBO.getUid().equals(userId)){
|
|
|
imageUrl = userInfoRspBO.getHeadIco();
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
return imageUrl;
|
|
|
}
|
|
|
|
|
|
private void pushSuccessMessage(Integer userId, CutDownPriceActivityBo activityBo, CutDownPriceProductBo cutDownPriceProductBo) {
|
|
|
executorService.execute(new Runnable() {
|
|
|
@Override
|
...
|
...
|
|