| | |
| | | import com.ruoyi.goods.controller.management.vo.GoodsGroupPurchaseVO; |
| | | import com.ruoyi.goods.domain.MemberGoodsCollection; |
| | | import com.ruoyi.goods.mapper.GoodsGroupPurchaseMapper; |
| | | import com.ruoyi.goods.service.IGoodsGroupPurchaseInfoService; |
| | | import com.ruoyi.goods.service.IGoodsGroupPurchaseService; |
| | | import com.ruoyi.goods.service.IGoodsSkuService; |
| | | import com.ruoyi.goods.service.IMemberGoodsCollectionService; |
| | |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.stream.Collectors; |
| | | import javax.annotation.Resource; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | private final RedisService redisService; |
| | | private final IMemberGoodsCollectionService iMemberGoodsCollectionService; |
| | | private final SysUserClient sysUserClient; |
| | | |
| | | @Resource |
| | | private GoodsGroupPurchaseInfoServiceImpl GoodsGroupPurchaseInfoServiceImpl; |
| | | private final IGoodsGroupPurchaseInfoService goodsGroupPurchaseInfoService; |
| | | // 创建一个静态共享的ObjectMapper实例以重用 |
| | | private static final ObjectMapper objectMapper = new ObjectMapper(); |
| | | /** |
| | |
| | | @Override |
| | | public void saveGoodsGroupPurchase(GoodsGroupPurchaseDTO dto) { |
| | | GoodsGroupPurchase goodsGroupPurchase = BeanUtils.copyBean(dto, GoodsGroupPurchase.class); |
| | | goodsGroupPurchase.setListingStatus(ListingStatusEnum.ON_SHELVES); |
| | | if (StringUtils.isNull(dto.getId())) { |
| | | if (StringUtils.isNull(dto.getGoodsSkuId())) { |
| | | throw new ServiceException("商品id不能为空"); |
| | |
| | | + groupPurchase.getId()); |
| | | redisService.deleteObject( |
| | | DelayTaskEnum.GROUP_PURCHASES_END_TASK.getCode() + "-" + groupPurchase.getId()); |
| | | // 退回剩余库存 |
| | | GoodsStockUpdDTO goodsStockUpdDTO = new GoodsStockUpdDTO(); |
| | | goodsStockUpdDTO.setAuctionStock( |
| | | groupPurchase.getLimitNumber() * groupPurchase.getGroupSize()); |
| | | goodsStockUpdDTO.setGoodsSkuId(groupPurchase.getGoodsSkuId()); |
| | | goodsSkuService.updGoodsStock(Lists.newArrayList(goodsStockUpdDTO)); |
| | | } |
| | | //修改状态 |
| | | groupPurchase.setListingStatus(dto.getListingStatus()); |
| | |
| | | public void endGroupPurchase(Long groupPurchaseId) throws JsonProcessingException { |
| | | log.info(">>>>>>>>>>>>>>>>>>>>{}团购商品结束团购<<<<<<<<<<<<<<<<<<<<", groupPurchaseId); |
| | | GoodsGroupPurchase groupPurchase = this.getById(groupPurchaseId); |
| | | if (StringUtils.isNotNull(groupPurchase) && groupPurchase.getStartStatus() |
| | | .equals(StartStatusEnum.STARTED)) { |
| | | this.lambdaUpdate().set(GoodsGroupPurchase::getStartStatus, StartStatusEnum.ENDED) |
| | | .eq(GoodsGroupPurchase::getId, groupPurchaseId).update(); |
| | | boolean res = handleGroupPurchase(groupPurchaseId); |
| | | if (StringUtils.isNotNull(groupPurchase)) { |
| | | groupPurchase.setStartStatus(StartStatusEnum.ENDED); |
| | | groupPurchase.setGroupStatus( |
| | | res ? GroupStatusEnum.FORMED_INTO_A_GROUP : GroupStatusEnum.GROUP_FAILURE); |
| | | this.updateById(groupPurchase); |
| | | Map<String, Object> map = new ConcurrentHashMap<>(); |
| | | map.put("notification_type", NotificationTypeConstant.GROUP_PURCHASE); |
| | | map.put("notification_time", DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss")); |
| | |
| | | if (StringUtils.isNull(groupPurchase)) { |
| | | throw new ServiceException("团购商品不存在"); |
| | | } |
| | | //判断商品状态,未成团则查询关联订单,进行退款;成团就直接修改状态 |
| | | if (groupPurchase.getGroupStatus().equals(GroupStatusEnum.TO_FORM_A_GROUP)) { |
| | | //查询关联订单 |
| | | List<Order> orderList = orderClient.getOrderByGroupPurchaseId(id, |
| | | // 处理未成团订单退款和成团订单修改展示状态 |
| | | boolean res = handleGroupPurchase(id); |
| | | groupPurchase.setGroupStatus( |
| | | res ? GroupStatusEnum.FORMED_INTO_A_GROUP : GroupStatusEnum.GROUP_FAILURE); |
| | | groupPurchase.setStartStatus(StartStatusEnum.ENDED); |
| | | this.updateById(groupPurchase); |
| | | } |
| | | |
| | | private boolean handleGroupPurchase(Long id) { |
| | | List<GoodsGroupPurchaseInfo> groupPurchaseInfoList = goodsGroupPurchaseInfoService.lambdaQuery() |
| | | .eq(GoodsGroupPurchaseInfo::getGroupPurchaseId, id).list(); |
| | | if (CollUtils.isNotEmpty(groupPurchaseInfoList)) { |
| | | List<String> mubres = groupPurchaseInfoList.stream() |
| | | .filter(g -> g.getCurrentNumber() |
| | | < g.getGroupSize()) |
| | | .map(GoodsGroupPurchaseInfo::getMubre).collect( |
| | | Collectors.toList()); |
| | | List<Order> orderList = orderClient.getOrderListByMubres(mubres, |
| | | SecurityConstants.INNER).getData(); |
| | | if (CollUtils.isNotEmpty(orderList)) { |
| | | |
| | | List<RefundDTO> refundDTOList = orderList.stream().map(order -> { |
| | | RefundDTO refundDTO = new RefundDTO(); |
| | | refundDTO.setOrderNo(order.getOrderNo()); |
| | |
| | | failedOrders.add(key); |
| | | } |
| | | }); |
| | | try { |
| | | log.info( |
| | | "============ =================退款结束============================="); |
| | | log.info("退款成功订单:{}", |
| | | objectMapper.writeValueAsString(successfulOrders)); |
| | | log.info("退款失败订单:{}", objectMapper.writeValueAsString(failedOrders)); |
| | | } catch (JsonProcessingException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | // 处理退款结果 |
| | | List<Order> updateOrderList = orderList.stream() |
| | | .filter(order -> successfulOrders.contains(order.getOrderNo())) |
| | |
| | | orderClient.updateOrderList(orderUpdDTOS, SecurityConstants.INNER); |
| | | } |
| | | } |
| | | groupPurchase.setGroupStatus(GroupStatusEnum.GROUP_FAILURE); |
| | | List<String> formedGroupMubres = groupPurchaseInfoList.stream() |
| | | .filter(g -> g.getCurrentNumber() |
| | | >= g.getGroupSize()) |
| | | .map(GoodsGroupPurchaseInfo::getMubre).collect( |
| | | Collectors.toList()); |
| | | if (CollUtils.isNotEmpty(formedGroupMubres)) { |
| | | orderClient.updateOrderStatusByMubres(formedGroupMubres, SecurityConstants.INNER); |
| | | return true; |
| | | } |
| | | } |
| | | groupPurchase.setStartStatus(StartStatusEnum.ENDED); |
| | | this.updateById(groupPurchase); |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | |
| | | wrapper6.eq(GoodsGroupPurchaseInfo::getDelFlag,0); |
| | | wrapper6.eq(GoodsGroupPurchaseInfo::getGroupStatus,0); |
| | | wrapper6.eq(GoodsGroupPurchaseInfo::getGroupPurchaseId,one.getId()); |
| | | GoodsGroupPurchaseInfo one1 = GoodsGroupPurchaseInfoServiceImpl.getOne(wrapper6); |
| | | GoodsGroupPurchaseInfo one1 = goodsGroupPurchaseInfoService.getOne(wrapper6); |
| | | if (one1!=null){ |
| | | goodsGroupPurchaseInfoVO.setCurrentNumber(one1.getCurrentNumber()); |
| | | if (one1.getGroupStatus()==0){ |
| | |
| | | |
| | | LambdaQueryWrapper<GoodsGroupPurchaseInfo> wrapper7= Wrappers.lambdaQuery(); |
| | | wrapper7.eq(GoodsGroupPurchaseInfo::getMubre,data.getGroupNo()); |
| | | GoodsGroupPurchaseInfo one7 = GoodsGroupPurchaseInfoServiceImpl.getOne(wrapper7); |
| | | GoodsGroupPurchaseInfo one7 = goodsGroupPurchaseInfoService.getOne(wrapper7); |
| | | if (one7!=null){ |
| | | goodsGroupPurchaseInfoVO.setCurrentNumber(one7.getCurrentNumber()); |
| | | if (one7.getGroupStatus()==0){ |