购物车相关代码
This commit is contained in:
@@ -13,6 +13,8 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商城首页商品 Controller(Feign 端)
|
||||
*/
|
||||
@@ -39,4 +41,12 @@ public class ListingMallController {
|
||||
ListingDetailVO detail = listingMallService.getListingDetail(id);
|
||||
return Response.success(detail);
|
||||
}
|
||||
|
||||
@Operation(summary = "批量获取商品简要信息(购物车用)", description = "返回指定商品ID列表的基本信息")
|
||||
@PostMapping("/mall/batch")
|
||||
public Response<List<ListingMallVO>> getListingSummaries(
|
||||
@RequestBody List<Long> listingIds) {
|
||||
List<ListingMallVO> result = listingMallService.getListingSummaries(listingIds);
|
||||
return Response.success(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import com.aida.seller.module.listing.vo.ListingDetailVO;
|
||||
import com.aida.seller.module.listing.vo.ListingMallVO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商城首页商品 Service 接口
|
||||
*/
|
||||
@@ -25,4 +27,12 @@ public interface ListingMallService {
|
||||
* @return 商品详情
|
||||
*/
|
||||
ListingDetailVO getListingDetail(Long id);
|
||||
|
||||
/**
|
||||
* 批量获取商品简要信息(购物车用)
|
||||
*
|
||||
* @param listingIds 商品ID列表
|
||||
* @return 商品简要信息列表
|
||||
*/
|
||||
List<ListingMallVO> getListingSummaries(List<Long> listingIds);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.aida.seller.module.listing.vo.ListingMallVO;
|
||||
|
||||
/**
|
||||
* 商城首页商品 Service 实现
|
||||
*/
|
||||
@@ -164,4 +166,31 @@ public class ListingMallServiceImpl extends ServiceImpl<ListingMallMapper, Listi
|
||||
vo.setImages(imageMap);
|
||||
return vo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ListingMallVO> getListingSummaries(List<Long> listingIds) {
|
||||
if (listingIds == null || listingIds.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
List<ListingEntity> entities = this.list(
|
||||
new LambdaQueryWrapper<ListingEntity>()
|
||||
.in(ListingEntity::getId, listingIds)
|
||||
.eq(ListingEntity::getDeleted, 0));
|
||||
Map<Long, ListingEntity> entityMap = entities.stream()
|
||||
.collect(Collectors.toMap(ListingEntity::getId, e -> e));
|
||||
List<ListingMallVO> listingMallVOS = listingIds.stream()
|
||||
.filter(entityMap::containsKey)
|
||||
.map(id -> {
|
||||
ListingEntity entity = entityMap.get(id);
|
||||
ListingMallVO vo = new ListingMallVO();
|
||||
vo.setId(entity.getId());
|
||||
vo.setCover(minioUtil.processMinioResource(entity.getCover(), CommonConstants.MINIO_PATH_TIMEOUT));
|
||||
vo.setTitle(entity.getTitle());
|
||||
vo.setPrice(entity.getPrice());
|
||||
vo.setStatus(entity.getStatus());
|
||||
return vo;
|
||||
})
|
||||
.toList();
|
||||
return listingMallVOS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,4 +22,6 @@ public class ListingMallVO implements Serializable {
|
||||
private String title;
|
||||
|
||||
private BigDecimal price;
|
||||
|
||||
private Integer status;
|
||||
}
|
||||
|
||||
@@ -66,4 +66,13 @@ public interface OrderService {
|
||||
* @return 已购商品分页列表,按购买时间降序排列
|
||||
*/
|
||||
IPage<AssetsItemVO> getAssetsPage(AssetsDTO dto);
|
||||
|
||||
/**
|
||||
* 批量查询指定商品是否已被买家购买
|
||||
*
|
||||
* @param listingIds 商品ID列表
|
||||
* @param buyerId 买家ID
|
||||
* @return 已购买的商品ID列表
|
||||
*/
|
||||
List<Long> getPurchasedListingIds(List<Long> listingIds, Long buyerId);
|
||||
}
|
||||
|
||||
@@ -209,12 +209,22 @@ public class OrderServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
||||
throw new BusinessException("买家账号不能为空");
|
||||
}
|
||||
|
||||
List<Long> purchasedListingIds = getPurchasedListingIds(dto.getListingIds(), dto.getBuyerId());
|
||||
List<Long> unpurchasedListingIds = dto.getListingIds().stream()
|
||||
.filter(id -> !purchasedListingIds.contains(id))
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtils.isEmpty(unpurchasedListingIds)) {
|
||||
throw new BusinessException("所有商品均已购买,无需重复下单");
|
||||
}
|
||||
dto.setListingIds(unpurchasedListingIds);
|
||||
|
||||
List<ListingEntity> listings = listingMapper.selectBatchIds(dto.getListingIds());
|
||||
if (CollectionUtils.isEmpty(listings)) {
|
||||
throw new BusinessException("未找到对应的商品");
|
||||
}
|
||||
|
||||
Map<Long, List<ListingEntity>> listingsBySeller = listings.stream()
|
||||
.filter(l -> l.getStatus() == 1)
|
||||
.collect(Collectors.groupingBy(ListingEntity::getSellerId));
|
||||
|
||||
List<Long> orderIds = new ArrayList<>();
|
||||
@@ -279,6 +289,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
||||
BigDecimal grandTotal = totalPrices.stream()
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
result.setTotalAmount(grandTotal);
|
||||
result.setUnpurchasedListingIds(dto.getListingIds());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -321,4 +332,18 @@ public class OrderServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
||||
resultPage.setRecords(records);
|
||||
return resultPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getPurchasedListingIds(List<Long> listingIds, Long buyerId) {
|
||||
if (CollectionUtils.isEmpty(listingIds) || buyerId == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
LambdaQueryWrapper<OrderItemEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(OrderItemEntity::getBuyerId, buyerId)
|
||||
.in(OrderItemEntity::getListingId, listingIds);
|
||||
return orderItemMapper.selectList(wrapper).stream()
|
||||
.map(OrderItemEntity::getListingId)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,4 +18,7 @@ public class CreateOrderResultVO implements Serializable {
|
||||
|
||||
@Schema(description = "所有订单总金额(HK$)")
|
||||
private BigDecimal totalAmount;
|
||||
|
||||
@Schema(description = "本次成功下单的未购买商品ID列表")
|
||||
private List<Long> unpurchasedListingIds;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ CREATE TABLE seller_listing (
|
||||
title VARCHAR(255) NOT NULL COMMENT '商品标题',
|
||||
description TEXT COMMENT '商品描述',
|
||||
price DECIMAL(10,2) COMMENT '价格',
|
||||
stock INT COMMENT '库存数量',
|
||||
cover VARCHAR(200) COMMENT '封面图URL',
|
||||
view_count INT DEFAULT 0 COMMENT '浏览量',
|
||||
status INT(1) DEFAULT 0 COMMENT '状态: 0-草稿, 1-已发布, 2-已删除',
|
||||
|
||||
Reference in New Issue
Block a user