Authored by wangshusheng

砍价状态

@@ -50,6 +50,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { @@ -50,6 +50,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
50 private static Logger logger = LoggerFactory.getLogger(CutDownPriceServiceImpl.class); 50 private static Logger logger = LoggerFactory.getLogger(CutDownPriceServiceImpl.class);
51 private static final Integer SYSTEM_HELP_ID = 0; 51 private static final Integer SYSTEM_HELP_ID = 0;
52 private static final Integer MAX_HELP_COUNT = 3; 52 private static final Integer MAX_HELP_COUNT = 3;
  53 + private static final Integer TIME_24_HOUR = 24*3600;
53 54
54 private static final String SYSTEM_HELP_NAME = "有货"; 55 private static final String SYSTEM_HELP_NAME = "有货";
55 private static final String SYSTEM_HELP_IMAGE = "https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKic2dZ7ib6p1PJJXFpYl95ibRyvSKCib3icUiaStlRN6PWmcRZjzPn4w4moEk2xhUxpYbibuPtBNPJBMeqQ/132"; 56 private static final String SYSTEM_HELP_IMAGE = "https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKic2dZ7ib6p1PJJXFpYl95ibRyvSKCib3icUiaStlRN6PWmcRZjzPn4w4moEk2xhUxpYbibuPtBNPJBMeqQ/132";
@@ -195,7 +196,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { @@ -195,7 +196,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
195 throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_YOU_HASNOT_CUTDOWN_SUCCESS_ERROR); 196 throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_YOU_HASNOT_CUTDOWN_SUCCESS_ERROR);
196 } 197 }
197 // 用户发起砍价成功后,24小时未付款,则取消 198 // 用户发起砍价成功后,24小时未付款,则取消
198 - if(record.getCutTime()+24*3600 < DateUtils.getCurrentTimeSecond()){ 199 + if(record.getCutTime()+TIME_24_HOUR < DateUtils.getCurrentTimeSecond()){
199 logger.warn(" you create cutprice has expired, activityId is {}, productSkn is {}", activityId, productSkn); 200 logger.warn(" you create cutprice has expired, activityId is {}, productSkn is {}", activityId, productSkn);
200 throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_CREATE_HAS_EXPIRED_ERROR); 201 throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_CREATE_HAS_EXPIRED_ERROR);
201 } 202 }
@@ -226,8 +227,8 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { @@ -226,8 +227,8 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
226 PageResponseBo<CutDownPriceActivityProductBo> cacheResult = getFromRedis(CacheKeyEnum.CUTDOWN_PRICE_MYPRODUCTLIST_INFO, uid, 227 PageResponseBo<CutDownPriceActivityProductBo> cacheResult = getFromRedis(CacheKeyEnum.CUTDOWN_PRICE_MYPRODUCTLIST_INFO, uid,
227 PageResponseBo.class, String.valueOf(request.getPage()), String.valueOf(request.getSize())); 228 PageResponseBo.class, String.valueOf(request.getPage()), String.valueOf(request.getSize()));
228 if (cacheResult != null) { 229 if (cacheResult != null) {
229 - // 赋值当前时间  
230 - buildCurrentTime(cacheResult); 230 + // 处理砍价状态,赋值当前时间
  231 + buildCutStatusAndCurrentTime(cacheResult);
231 return cacheResult; 232 return cacheResult;
232 } 233 }
233 // 查询我的砍价列表 234 // 查询我的砍价列表
@@ -378,7 +379,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { @@ -378,7 +379,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
378 } 379 }
379 // 查询该用户是否已经发起过(之前发起过,没砍价成功,发起时间超过24小时) 380 // 查询该用户是否已经发起过(之前发起过,没砍价成功,发起时间超过24小时)
380 CutDownPriceUserRecord recordDb = cutDownPriceUserRecordMapper.selectCutDownPriceUserRecord(userId, activityId, productSkn); 381 CutDownPriceUserRecord recordDb = cutDownPriceUserRecordMapper.selectCutDownPriceUserRecord(userId, activityId, productSkn);
381 - if(recordDb!=null && (recordDb.getHelpCount()>=cutDownPriceProductBo.getJoinNum()+1 || (DateUtils.getCurrentTimeSecond() - recordDb.getCreateTime() < 24*3600))){ 382 + if(recordDb!=null && (recordDb.getHelpCount()>=cutDownPriceProductBo.getJoinNum()+1 || (DateUtils.getCurrentTimeSecond() - recordDb.getCreateTime() < TIME_24_HOUR))){
382 logger.warn(" the cutdown record has exist, userId is {}, activityId is {}, productSkn is {}", userId, activityId, productSkn); 383 logger.warn(" the cutdown record has exist, userId is {}, activityId is {}, productSkn is {}", userId, activityId, productSkn);
383 throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_YOU_HAS_CREATE_CUTDOWN_ERROR); 384 throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_YOU_HAS_CREATE_CUTDOWN_ERROR);
384 } 385 }
@@ -577,22 +578,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { @@ -577,22 +578,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
577 cutDownPriceActivityProductBo.setCreateTime(record.getCreateTime()); 578 cutDownPriceActivityProductBo.setCreateTime(record.getCreateTime());
578 cutDownPriceActivityProductBo.setCutTime(record.getCutTime()); 579 cutDownPriceActivityProductBo.setCutTime(record.getCutTime());
579 580
580 - if(DateUtils.getCurrentTimeSecond()>activityBo.getEndTime()){  
581 - // 活动已结束  
582 - cutDownPriceActivityProductBo.setCutStatus(CutPriceConstant.CUT_STATUS_END);  
583 - }else{  
584 - // 活动进行中  
585 - if(helpUserBos.size()>cutDownPriceProductBo.getJoinNum()){  
586 - // 砍价已成功  
587 - cutDownPriceActivityProductBo.setCutStatus(CutPriceConstant.CUT_STATUS_SUCCESS);  
588 - }else if(DateUtils.getCurrentTimeSecond()-record.getCreateTime()>24*3600){  
589 - // 未成功,发起已超过24小时,已失效  
590 - cutDownPriceActivityProductBo.setCutStatus(CutPriceConstant.CUT_STATUS_EXPIRE);  
591 - }else{  
592 - // 未成功,发起24小时内,砍价中  
593 - cutDownPriceActivityProductBo.setCutStatus(CutPriceConstant.CUT_STATUS_ONGOING);  
594 - }  
595 - } 581 + buildCutStatus(cutDownPriceActivityProductBo);
596 list.add(cutDownPriceActivityProductBo); 582 list.add(cutDownPriceActivityProductBo);
597 } 583 }
598 return list; 584 return list;
@@ -622,11 +608,34 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { @@ -622,11 +608,34 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
622 return cutDownPriceProductBo; 608 return cutDownPriceProductBo;
623 } 609 }
624 610
625 - private void buildCurrentTime(PageResponseBo<CutDownPriceActivityProductBo> cacheResult) { 611 + private void buildCutStatusAndCurrentTime(PageResponseBo<CutDownPriceActivityProductBo> cacheResult) {
626 List<CutDownPriceActivityProductBo> productList = cacheResult.getList(); 612 List<CutDownPriceActivityProductBo> productList = cacheResult.getList();
627 - if (CollectionUtils.isNotEmpty(productList)) {  
628 - for (CutDownPriceActivityProductBo bo : productList) {  
629 - bo.setCurrentTime(DateUtils.getCurrentTimeSecond()); 613 + if (CollectionUtils.isEmpty(productList)) {
  614 + return;
  615 + }
  616 + for (CutDownPriceActivityProductBo bo : productList) {
  617 + buildCutStatus(bo);
  618 + }
  619 + }
  620 +
  621 + // 设置砍价当前状态
  622 + private void buildCutStatus(CutDownPriceActivityProductBo bo) {
  623 + int currentTime = DateUtils.getCurrentTimeSecond();
  624 + bo.setCurrentTime(currentTime);
  625 + if(currentTime>bo.getEndTime()){
  626 + // 活动已结束
  627 + bo.setCutStatus(CutPriceConstant.CUT_STATUS_END);
  628 + }else{
  629 + // 活动进行中
  630 + if(bo.getHasJoinNum() > bo.getJoinNum()){
  631 + // 砍价已成功
  632 + bo.setCutStatus(CutPriceConstant.CUT_STATUS_SUCCESS);
  633 + }else if(currentTime - bo.getCreateTime()>TIME_24_HOUR){
  634 + // 未成功,发起已超过24小时,已失效
  635 + bo.setCutStatus(CutPriceConstant.CUT_STATUS_EXPIRE);
  636 + }else{
  637 + // 未成功,发起24小时内,砍价中
  638 + bo.setCutStatus(CutPriceConstant.CUT_STATUS_ONGOING);
630 } 639 }
631 } 640 }
632 } 641 }