mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2024-12-23 13:03:43 +08:00
feat:购物车优化
This commit is contained in:
parent
4a78b09fd3
commit
dcafce487a
@ -25,13 +25,29 @@ public class CartController {
|
|||||||
|
|
||||||
private ICartService cartService;
|
private ICartService cartService;
|
||||||
|
|
||||||
@ApiOperation(value = "查询用户购物车", httpMethod = "GET")
|
@ApiOperation(value = "查询购物车", httpMethod = "GET")
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public Result get() {
|
public Result getCart() {
|
||||||
CartVO cart = cartService.getCart();
|
CartVO cart = cartService.getCart();
|
||||||
return Result.success(cart);
|
return Result.success(cart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "全选/全不选 购物车商品", httpMethod = "PUT")
|
||||||
|
@ApiImplicitParam(name = "checked", value = "全选/全不选", required = true, paramType = "param", dataType = "Boolean")
|
||||||
|
@PatchMapping("/_check")
|
||||||
|
public Result check(boolean checked) {
|
||||||
|
boolean result = cartService.checkAll(checked);
|
||||||
|
return Result.judge(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "清空购物车", httpMethod = "DELETE")
|
||||||
|
@DeleteMapping
|
||||||
|
public Result deleteCart() {
|
||||||
|
boolean result = cartService.deleteCart();
|
||||||
|
return Result.judge(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@ApiOperation(value = "添加购物车商品", httpMethod = "POST")
|
@ApiOperation(value = "添加购物车商品", httpMethod = "POST")
|
||||||
@ApiImplicitParam(name = "skuId", value = "SKU ID", required = true, paramType = "param", dataType = "Long")
|
@ApiImplicitParam(name = "skuId", value = "SKU ID", required = true, paramType = "param", dataType = "Long")
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@ -47,13 +63,6 @@ public class CartController {
|
|||||||
return Result.judge(result);
|
return Result.judge(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "全选/全不选择购物车商品", httpMethod = "PUT")
|
|
||||||
@ApiImplicitParam(name = "checked", value = "全选/全不选", required = true, paramType = "param", dataType = "Boolean")
|
|
||||||
@PatchMapping("/batch")
|
|
||||||
public Result checkAll(boolean checked) {
|
|
||||||
boolean result = cartService.checkAll(checked);
|
|
||||||
return Result.judge(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation(value = "删除购物车商品", httpMethod = "DELETE")
|
@ApiOperation(value = "删除购物车商品", httpMethod = "DELETE")
|
||||||
@ApiImplicitParam(name = "skuId", value = "SKU ID", required = true, paramType = "param", dataType = "Long")
|
@ApiImplicitParam(name = "skuId", value = "SKU ID", required = true, paramType = "param", dataType = "Long")
|
||||||
@ -63,10 +72,5 @@ public class CartController {
|
|||||||
return Result.judge(result);
|
return Result.judge(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "清空购物车", httpMethod = "DELETE")
|
|
||||||
@DeleteMapping
|
|
||||||
public Result deleteCart() {
|
|
||||||
boolean result = cartService.deleteCart();
|
|
||||||
return Result.judge(result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,16 @@
|
|||||||
package com.youlai.mall.oms.listener;
|
package com.youlai.mall.oms.listener;
|
||||||
|
|
||||||
import com.rabbitmq.client.Channel;
|
import com.rabbitmq.client.Channel;
|
||||||
import com.youlai.mall.oms.pojo.domain.OmsOrderItem;
|
|
||||||
import com.youlai.mall.oms.service.IOrderItemService;
|
import com.youlai.mall.oms.service.IOrderItemService;
|
||||||
import com.youlai.mall.oms.service.IOrderService;
|
import com.youlai.mall.oms.service.IOrderService;
|
||||||
import com.youlai.mall.pms.api.app.PmsSkuFeignService;
|
import com.youlai.mall.pms.api.app.PmsSkuFeignService;
|
||||||
import com.youlai.mall.pms.pojo.dto.SkuLockDTO;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.amqp.core.Message;
|
import org.springframework.amqp.core.Message;
|
||||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hxr
|
* @author hxr
|
||||||
@ -29,14 +23,10 @@ import java.util.stream.Collectors;
|
|||||||
public class OmsListener {
|
public class OmsListener {
|
||||||
|
|
||||||
IOrderService orderService;
|
IOrderService orderService;
|
||||||
|
|
||||||
IOrderItemService orderItemService;
|
IOrderItemService orderItemService;
|
||||||
|
|
||||||
PmsSkuFeignService skuFeignService;
|
PmsSkuFeignService skuFeignService;
|
||||||
|
|
||||||
RabbitTemplate rabbitTemplate;
|
RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单超时未支付,关闭订单,释放库存
|
* 订单超时未支付,关闭订单,释放库存
|
||||||
*/
|
*/
|
||||||
@ -48,6 +38,7 @@ public class OmsListener {
|
|||||||
skuFeignService.unlockStock(orderToken);
|
skuFeignService.unlockStock(orderToken);
|
||||||
} else {
|
} else {
|
||||||
// 如果关单失败,则订单可能已经被处理,直接手动ACK确认消息
|
// 如果关单失败,则订单可能已经被处理,直接手动ACK确认消息
|
||||||
|
// basicAck(tag,multiple),multiple为true开启批量确认,小于tag值队列中未被消费的消息一次性确认
|
||||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
|
channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -109,6 +109,10 @@ public class CartServiceImpl implements ICartService {
|
|||||||
BoundHashOperations cartHashOperations = getCartHashOperations();
|
BoundHashOperations cartHashOperations = getCartHashOperations();
|
||||||
String hKey = cartItem.getSkuId() + "";
|
String hKey = cartItem.getSkuId() + "";
|
||||||
if (cartHashOperations.get(hKey) != null) {
|
if (cartHashOperations.get(hKey) != null) {
|
||||||
|
|
||||||
|
CartVO.CartItem cacheCartItem = (CartVO.CartItem) cartHashOperations.get(hKey);
|
||||||
|
|
||||||
|
|
||||||
cartHashOperations.put(hKey, cartItem);
|
cartHashOperations.put(hKey, cartItem);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user