记得上下班打卡 | git大法好,push需谨慎

Commit 9162686b authored by jiangxiulong's avatar jiangxiulong

库存

parent 15ab1d71
...@@ -102,6 +102,7 @@ public class SweetIntegralActivityServiceImpl extends ServiceImpl<SweetIntegralA ...@@ -102,6 +102,7 @@ public class SweetIntegralActivityServiceImpl extends ServiceImpl<SweetIntegralA
sweetIntegralActivityPrize, sweetIntegralActivityPrize,
Wrappers.lambdaUpdate(SweetIntegralActivityPrize.class).eq(SweetIntegralActivityPrize::getPrizeId, prize.getPrizeId()) Wrappers.lambdaUpdate(SweetIntegralActivityPrize.class).eq(SweetIntegralActivityPrize::getPrizeId, prize.getPrizeId())
); );
// TODO: 2021/10/27 处理奖品库存
} }
} }
// 活动redis处理 // 活动redis处理
......
...@@ -97,4 +97,6 @@ public class SweetConstant { ...@@ -97,4 +97,6 @@ public class SweetConstant {
public static final String REDIS_KEY_SWEET_INTEGRAL_ACTIVITY_DRAW_ALL_LIST = "sweet:integralActivity:Draw:activityId:"; public static final String REDIS_KEY_SWEET_INTEGRAL_ACTIVITY_DRAW_ALL_LIST = "sweet:integralActivity:Draw:activityId:";
public static final String REDIS_KEY_SWEET_INTEGRAL_ACTIVITY_DRAW_USER = "sweet:integralActivity:Draw:activityId:"; public static final String REDIS_KEY_SWEET_INTEGRAL_ACTIVITY_DRAW_USER = "sweet:integralActivity:Draw:activityId:";
public static final String REDIS_KEY_SWEET_INTEGRAL_ACTIVITY_DRAW_IN_USER = "sweet:integralActivity:DrawIn:activityId:"; public static final String REDIS_KEY_SWEET_INTEGRAL_ACTIVITY_DRAW_IN_USER = "sweet:integralActivity:DrawIn:activityId:";
public static final String REDIS_KEY_SWEET_INTEGRAL_ACTIVITY_PRIZE_NUM = "sweet:integralActivity:prizeNum:activityId:";
public static final String REDIS_KEY_SWEET_INTEGRAL_ACTIVITY_PRIZE_WINNERS_NUM = "sweet:integralActivity:prizeWinnersNum:activityId:";
} }
...@@ -16,6 +16,7 @@ import com.liquidnet.service.sweet.utils.SweetNewObjectUtil; ...@@ -16,6 +16,7 @@ import com.liquidnet.service.sweet.utils.SweetNewObjectUtil;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
...@@ -60,17 +61,29 @@ public class SweetIntegralActivityDrawServiceImpl extends ServiceImpl<SweetInteg ...@@ -60,17 +61,29 @@ public class SweetIntegralActivityDrawServiceImpl extends ServiceImpl<SweetInteg
// TODO: 2021/10/27 判断用户积分是否>=integralActivity.setActivityNum(); // TODO: 2021/10/27 判断用户积分是否>=integralActivity.setActivityNum();
// TODO 如果库存没了 限制的中奖人数到了就从列表剔出 // 如果库存没了 限制的中奖人数到了就从列表剔出 列表为空就都没有库存了
List<SweetIntegralActivityPrize> prizeList = integralActivity.getPrizeList(); List<SweetIntegralActivityPrize> prizeList = integralActivity.getPrizeList();
ArrayList<SweetIntegralActivityPrize> sweetIntegralActivityPrizeArrayList = SweetNewObjectUtil.getSweetIntegralActivityPrizeArrayList(); ArrayList<SweetIntegralActivityPrize> sweetIntegralActivityPrizeArrayList = SweetNewObjectUtil.getSweetIntegralActivityPrizeArrayList();
for (SweetIntegralActivityPrize info : prizeList) { for (SweetIntegralActivityPrize info : prizeList) {
int integralActivityPrizeNum = redisDataUtils.getIntegralActivityPrizeNum(integralActivityId, info.getPrizeId());
int integralActivityPrizeWinnersNum = redisDataUtils.getIntegralActivityPrizeWinnersNum(integralActivityId, info.getPrizeId());
if (integralActivityPrizeNum > 0 && integralActivityPrizeWinnersNum > 0) {
sweetIntegralActivityPrizeArrayList.add(info); sweetIntegralActivityPrizeArrayList.add(info);
} }
}
if (CollectionUtils.isEmpty(sweetIntegralActivityPrizeArrayList)) {
return ResponseDto.failure("活动太火爆了,奖品已经没有库存啦~");
}
SweetIntegralActivityPrize sweetIntegralActivityPrize = this.lotteryDraw(sweetIntegralActivityPrizeArrayList); SweetIntegralActivityPrize sweetIntegralActivityPrize = this.lotteryDraw(sweetIntegralActivityPrizeArrayList);
SweetIntegralActivityPrizeVo sweetIntegralActivityPrizeVo = SweetIntegralActivityPrizeVo.getNew().copy(sweetIntegralActivityPrize); SweetIntegralActivityPrizeVo sweetIntegralActivityPrizeVo = SweetIntegralActivityPrizeVo.getNew().copy(sweetIntegralActivityPrize);
// 记录 // 记录
long activityPrizeNum = redisDataUtils.setIntegralActivityPrizeNum(integralActivityId, sweetIntegralActivityPrizeVo.getPrizeId(), 1);
long activityPrizeWinnersNum = redisDataUtils.setIntegralActivityPrizeWinnersNum(integralActivityId, sweetIntegralActivityPrizeVo.getPrizeId(), 1);
if (activityPrizeNum < 0 || activityPrizeWinnersNum < 0) {// 库存不够了
return ResponseDto.failure("活动太火爆了,请稍后再试");
}
SweetIntegralActivityDraw sweetIntegralActivityDraw = SweetIntegralActivityDraw.getNew(); SweetIntegralActivityDraw sweetIntegralActivityDraw = SweetIntegralActivityDraw.getNew();
sweetIntegralActivityDraw.setDrawId(IDGenerator.nextSnowId()); sweetIntegralActivityDraw.setDrawId(IDGenerator.nextSnowId());
sweetIntegralActivityDraw.setIntegralActivityId(integralActivityId); sweetIntegralActivityDraw.setIntegralActivityId(integralActivityId);
......
...@@ -674,4 +674,47 @@ public class RedisDataUtils { ...@@ -674,4 +674,47 @@ public class RedisDataUtils {
// TODO: 2021/10/27 page大于1 去mongo里面取 // TODO: 2021/10/27 page大于1 去mongo里面取
} }
public int getIntegralActivityPrizeNum(String integralActivityId, String prizeId) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_INTEGRAL_ACTIVITY_PRIZE_NUM
.concat(integralActivityId)
.concat(":prizeId:")
.concat(prizeId);
Object obj = redisUtil.get(redisKey);
if (null == obj) {
return 0;
} else {
return (int) obj;
}
}
public int getIntegralActivityPrizeWinnersNum(String integralActivityId, String prizeId) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_INTEGRAL_ACTIVITY_PRIZE_WINNERS_NUM
.concat(integralActivityId)
.concat(":prizeId:")
.concat(prizeId);
Object obj = redisUtil.get(redisKey);
if (null == obj) {
return 0;
} else {
return (int) obj;
}
}
public long setIntegralActivityPrizeNum(String integralActivityId, String prizeId, int num) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_INTEGRAL_ACTIVITY_PRIZE_NUM
.concat(integralActivityId)
.concat(":prizeId:")
.concat(prizeId);
long decr = redisUtil.decr(redisKey, num);
return decr;
}
public long setIntegralActivityPrizeWinnersNum(String integralActivityId, String prizeId, int num) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_INTEGRAL_ACTIVITY_PRIZE_WINNERS_NUM
.concat(integralActivityId)
.concat(":prizeId:")
.concat(prizeId);
long decr = redisUtil.decr(redisKey, num);
return decr;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment