|
@@ -135,71 +135,67 @@ public class TicketBoxServiceImpl extends ServiceImpl<TicketBoxMapper, TicketBox
|
|
|
throw new ServiceException("奖品列表不能为空");
|
|
|
}
|
|
|
|
|
|
- Map<String,TicketAwardsPrize> prizeMap = new HashMap<>();
|
|
|
+ List<TicketAwardsPrize> ticketAwardsPrizeList = new ArrayList<>();
|
|
|
List<String> prizeIdList = ticketAwardsParam.getPrizeList().stream().map(ticketAwardsPrizeParam -> {
|
|
|
+ // 奖品id为空则封装要新增的奖品
|
|
|
if (StringUtils.isBlank(ticketAwardsPrizeParam.getPrizeId())) {
|
|
|
- throw new ServiceException("奖品ID不能为空");
|
|
|
- }
|
|
|
- // 封装奖品信息
|
|
|
- TicketAwardsPrize awardsPrize = mapperFacade.map(ticketAwardsPrizeParam, TicketAwardsPrize.class);
|
|
|
- awardsPrize.setPrizeId(ticketAwardsPrizeParam.getPrizeId());
|
|
|
- awardsPrize.setBoxId(ticketBox.getBoxId());
|
|
|
- awardsPrize.setAwardsId(ticketAwardsParam.getAwardsId());
|
|
|
- if (null == awardsPrize.getQuantity() || 0 == awardsPrize.getQuantity()) {
|
|
|
- // 页面没设置奖品的具体数量,则默认为整个奖项的数量
|
|
|
- awardsPrize.setQuantity(ticketAwardsParam.getQuantity());
|
|
|
- }
|
|
|
- awardsPrize.setRemainQty(awardsPrize.getQuantity());
|
|
|
- awardsPrize.setCashedQty(0);
|
|
|
- if (ticketAwardsPrizeParam.getPrizeType() == TicketPrizeTypeEnum.GOODS) {
|
|
|
- Goods goods = goodsService.getById(awardsPrize.getRefId());
|
|
|
- awardsPrize.setTitle(goods.getTitle());
|
|
|
- awardsPrize.setPicUrl(goods.getPicUrl());
|
|
|
- awardsPrize.setValue(goods.getValue());
|
|
|
- } else if (ticketAwardsPrizeParam.getPrizeType() == TicketPrizeTypeEnum.COUPON) {
|
|
|
- Coupon coupon = couponService.getById(awardsPrize.getRefId());
|
|
|
- awardsPrize.setTitle(coupon.getTitle());
|
|
|
- awardsPrize.setPicUrl(coupon.getPicUrl());
|
|
|
- awardsPrize.setValue(coupon.getDiscount());
|
|
|
- } else {
|
|
|
- awardsPrize.setTitle("盲豆");
|
|
|
- awardsPrize.setPicUrl("md.jpeg");
|
|
|
+ // 封装奖品信息
|
|
|
+ TicketAwardsPrize awardsPrize = mapperFacade.map(ticketAwardsPrizeParam, TicketAwardsPrize.class);
|
|
|
+ awardsPrize.setPrizeId(bizIdGenerator.newId());
|
|
|
+ awardsPrize.setBoxId(ticketBox.getBoxId());
|
|
|
+ awardsPrize.setAwardsId(ticketAwardsParam.getAwardsId());
|
|
|
+ if (null == awardsPrize.getQuantity() || 0 == awardsPrize.getQuantity()) {
|
|
|
+ // 页面没设置奖品的具体数量,则默认为整个奖项的数量
|
|
|
+ awardsPrize.setQuantity(ticketAwardsParam.getQuantity());
|
|
|
+ }
|
|
|
+ awardsPrize.setRemainQty(awardsPrize.getQuantity());
|
|
|
+ awardsPrize.setCashedQty(0);
|
|
|
+ if (ticketAwardsPrizeParam.getPrizeType() == TicketPrizeTypeEnum.GOODS) {
|
|
|
+ Goods goods = goodsService.getById(awardsPrize.getRefId());
|
|
|
+ awardsPrize.setTitle(goods.getTitle());
|
|
|
+ awardsPrize.setPicUrl(goods.getPicUrl());
|
|
|
+ awardsPrize.setValue(goods.getValue());
|
|
|
+ } else if (ticketAwardsPrizeParam.getPrizeType() == TicketPrizeTypeEnum.COUPON) {
|
|
|
+ Coupon coupon = couponService.getById(awardsPrize.getRefId());
|
|
|
+ awardsPrize.setTitle(coupon.getTitle());
|
|
|
+ awardsPrize.setPicUrl(coupon.getPicUrl());
|
|
|
+ awardsPrize.setValue(coupon.getDiscount());
|
|
|
+ } else {
|
|
|
+ awardsPrize.setTitle("盲豆");
|
|
|
+ awardsPrize.setPicUrl("md.jpeg");
|
|
|
+ }
|
|
|
+ ticketAwardsPrizeList.add(awardsPrize);
|
|
|
}
|
|
|
- prizeMap.put(ticketAwardsPrizeParam.getPrizeId(), awardsPrize);
|
|
|
return ticketAwardsPrizeParam.getPrizeId();
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
- List<String> tempList = new ArrayList<>();
|
|
|
- tempList.addAll(prizeIdList);
|
|
|
-
|
|
|
- // 查询原来的奖品信息
|
|
|
- List<TicketAwardsPrize> oldTicketAwardsPrizeList = ticketAwardsPrizeService.list(new LambdaQueryWrapper<TicketAwardsPrize>()
|
|
|
- .select(TicketAwardsPrize::getPrizeId)
|
|
|
- .eq(TicketAwardsPrize::getAwardsId, ticketAwardsParam.getAwardsId()));
|
|
|
- if (CollectionUtils.isEmpty(oldTicketAwardsPrizeList)) {
|
|
|
- throw new ServiceException("原奖品列表为空");
|
|
|
- }
|
|
|
- List<String> oldPrizeIdList = oldTicketAwardsPrizeList.stream().map(TicketAwardsPrize::getPrizeId).collect(Collectors.toList());
|
|
|
-
|
|
|
- // 去重原来的奖品信息
|
|
|
- prizeIdList.removeAll(oldPrizeIdList);
|
|
|
+ // 如果新的奖品id为空,则清除原来的所有奖品
|
|
|
+ if (CollectionUtils.isEmpty(prizeIdList)) {
|
|
|
+ ticketAwardsPrizeService.remove(new LambdaUpdateWrapper<TicketAwardsPrize>().eq(TicketAwardsPrize::getAwardsId, ticketAwardsParam.getAwardsId()));
|
|
|
+ } else {
|
|
|
+ // 去重后,清除原来的奖品
|
|
|
+ // 查询原来的奖品信息
|
|
|
+ List<TicketAwardsPrize> oldTicketAwardsPrizeList = ticketAwardsPrizeService.list(new LambdaQueryWrapper<TicketAwardsPrize>()
|
|
|
+ .select(TicketAwardsPrize::getPrizeId)
|
|
|
+ .eq(TicketAwardsPrize::getAwardsId, ticketAwardsParam.getAwardsId()));
|
|
|
+ if (CollectionUtils.isEmpty(oldTicketAwardsPrizeList)) {
|
|
|
+ throw new ServiceException("原奖品列表为空");
|
|
|
+ }
|
|
|
+ List<String> oldPrizeIdList = oldTicketAwardsPrizeList.stream().map(TicketAwardsPrize::getPrizeId).collect(Collectors.toList());
|
|
|
+ // 去重原来的奖品信息
|
|
|
+ oldPrizeIdList.removeAll(prizeIdList);
|
|
|
|
|
|
- // 删除原来的奖品信息
|
|
|
- oldPrizeIdList.removeAll(tempList);
|
|
|
- if (CollectionUtils.isNotEmpty(oldPrizeIdList)) {
|
|
|
- ticketAwardsPrizeService.removeByIds(oldPrizeIdList);
|
|
|
+ if (CollectionUtils.isNotEmpty(oldPrizeIdList)) {
|
|
|
+ // 删除原来的奖品信息
|
|
|
+ ticketAwardsPrizeService.removeByIds(oldPrizeIdList);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- // 新增的奖品信息
|
|
|
- if (CollectionUtils.isNotEmpty(prizeIdList)) {
|
|
|
- List<TicketAwardsPrize> ticketAwardsPrizeList = new ArrayList<>();
|
|
|
- for (String id : prizeIdList) {
|
|
|
- if (prizeMap.get(id) != null) {
|
|
|
- ticketAwardsPrizeList.add(prizeMap.get(id));
|
|
|
- }
|
|
|
- }
|
|
|
+ // 新增奖品
|
|
|
+ if (CollectionUtils.isNotEmpty(ticketAwardsPrizeList)) {
|
|
|
ticketAwardsPrizeService.saveBatch(ticketAwardsPrizeList);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
return true;
|