...
|
...
|
@@ -8,10 +8,8 @@ import com.yoho.activity.common.redis.RedisValueCache; |
|
|
import com.yoho.activity.common.utils.DateUtils;
|
|
|
import com.yoho.activity.dal.CutDownPriceUserHelpMapper;
|
|
|
import com.yoho.activity.dal.CutDownPriceUserRecordMapper;
|
|
|
import com.yoho.activity.dal.CutdownPriceOrderRecordMapper;
|
|
|
import com.yoho.activity.dal.model.CutDownPriceProductHelpUser;
|
|
|
import com.yoho.activity.dal.model.CutDownPriceUserRecord;
|
|
|
import com.yoho.activity.dal.model.CutdownPriceOrderRecord;
|
|
|
import com.yoho.activity.queue.service.ICutDownPriceActivityService;
|
|
|
import com.yoho.activity.queue.service.ICutDownPriceProductService;
|
|
|
import com.yoho.activity.queue.service.ICutDownPriceService;
|
...
|
...
|
@@ -26,12 +24,13 @@ 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 org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
|
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;
|
...
|
...
|
@@ -52,8 +51,6 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
@Autowired
|
|
|
private CutDownPriceUserRecordMapper cutDownPriceUserRecordMapper;
|
|
|
@Autowired
|
|
|
private CutdownPriceOrderRecordMapper cutdownPriceOrderRecordMapper;
|
|
|
@Autowired
|
|
|
private ICutDownPriceActivityService cutDownActivityService;
|
|
|
@Autowired
|
|
|
private ICutDownPriceProductService cutDownPriceProductService;
|
...
|
...
|
@@ -131,16 +128,41 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
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.setUseCount(record.getUseCount());
|
|
|
// 设置已砍价记录
|
|
|
bo.setHasJoinNum(record.getHelpCount());
|
|
|
}
|
|
|
return bo;
|
|
|
}
|
|
|
|
|
|
private int selectCutdownPriceOrderRecordCount(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) {
|
|
|
Integer userId = cutPriceHelpUserRequestBO.getUserId();
|
|
|
int useCount = 0;
|
|
|
// 登陆情况下查询使用记录
|
|
|
if(userId!=null){
|
|
|
CutdownPriceOrderRecord record = new CutdownPriceOrderRecord();
|
|
|
record.setActivityId(cutPriceHelpUserRequestBO.getActivityId());
|
|
|
record.setProductSkn(cutPriceHelpUserRequestBO.getProductSkn());
|
|
|
record.setUserId(userId);
|
|
|
useCount = cutdownPriceOrderRecordMapper.selectCutdownPriceOrderRecordCount(record);
|
|
|
CutDownPriceUserRecord record = cutDownPriceUserRecordMapper.selectCutDownPriceUserRecord(userId, cutPriceHelpUserRequestBO.getActivityId(), cutPriceHelpUserRequestBO.getProductSkn());
|
|
|
if(record!=null){
|
|
|
useCount = record.getUseCount();
|
|
|
}
|
|
|
}
|
|
|
return useCount;
|
|
|
}
|
...
|
...
|
@@ -191,30 +213,25 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int addCutPriceUseRecord(CutPriceHelpUserRequestBO requestBO) {
|
|
|
CutdownPriceOrderRecord record = new CutdownPriceOrderRecord();
|
|
|
record.setActivityId(requestBO.getActivityId());
|
|
|
record.setOrderCode(requestBO.getOrderCode());
|
|
|
record.setProductSkn(requestBO.getProductSkn());
|
|
|
record.setUserId(requestBO.getUserId());
|
|
|
record.setCreateTime(DateUtils.getCurrentTimeSecond());
|
|
|
record.setUpdateTime(DateUtils.getCurrentTimeSecond());
|
|
|
int result = cutdownPriceOrderRecordMapper.addCutdownPriceOrderRecord(record);
|
|
|
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);
|
|
|
}
|
|
|
// 清理缓存
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int cancelCutPriceUseRecord(CutPriceHelpUserRequestBO requestBO) {
|
|
|
CutdownPriceOrderRecord record = new CutdownPriceOrderRecord();
|
|
|
record.setActivityId(requestBO.getActivityId());
|
|
|
record.setOrderCode(requestBO.getOrderCode());
|
|
|
record.setProductSkn(requestBO.getProductSkn());
|
|
|
record.setUserId(requestBO.getUserId());
|
|
|
record.setCreateTime(DateUtils.getCurrentTimeSecond());
|
|
|
record.setUpdateTime(DateUtils.getCurrentTimeSecond());
|
|
|
int result = cutdownPriceOrderRecordMapper.cancelCutdownPriceOrderRecord(record);
|
|
|
//让缓存过期 1.列表缓存 2.总数的缓存 3.用户限购码缓存
|
|
|
// 回补可使用次数
|
|
|
int result = cutDownPriceUserRecordMapper.updateIncreaseUseCount(requestBO.getUserId(), requestBO.getActivityId(), requestBO.getProductSkn());
|
|
|
// 清理缓存
|
|
|
return result;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -248,8 +265,10 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
CutDownPriceProductHelpUser helpUser = convertCutDownPriceProductHelpUser(cutPriceHelpUserRequestBO);
|
|
|
helpUser.setCutPrice(cutPrice);
|
|
|
helpUser.setCreateTime(DateUtils.getCurrentTimeSecond());
|
|
|
// 插入表
|
|
|
// 插入好友帮砍记录表
|
|
|
cutPriceUserHelpMapper.addHelpUserInfo(helpUser);
|
|
|
// 修改用户发起砍价记录表中的帮砍次数
|
|
|
cutDownPriceUserRecordMapper.updateCutDownHelpCount(userId, activityId, productSkn);
|
|
|
// 清理缓存,用户帮砍记录列表、商品详情页
|
|
|
clearCache(activityId, productSkn, userId);
|
|
|
return cutPrice;
|
...
|
...
|
@@ -364,21 +383,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;
|
|
|
}
|
|
|
|
...
|
...
|
|