public List viewCart()

in src/cartservice/cartservice-provider/src/main/java/com/alibabacloud/hipstershop/cartserviceprovider/service/CartServiceImpl.java [36:68]


    public List<CartItem> viewCart(String userId) {

        if (throwException) {
            throw new RuntimeException();
        }

        // 模拟运行时异常
        if (exceptionIp != null && exceptionIp.equals(getLocalIp())) {
            throw new RuntimeException("runtime exception");
        }
        // 模拟慢调用
        if (slowCallIp != null && slowCallIp.equals(getLocalIp())) {
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
            }
        }

        List<CartItem> res = redisRepository.getUserCartItems(userId);
        String ip = getLocalIp();
        List<CartItem> newRes = new ArrayList<>();
        if (res != null) {
            for (CartItem cartItem : res) {
                CartItem newCart = new CartItem(cartItem.getProductID(), cartItem.getQuantity());
                newCart.setProductName(" from userId: " + userId + "; ip: " + ip);
                newCart.setProductPicture(cartItem.getProductPicture());
                newCart.setPrice(cartItem.getPrice());
                newRes.add(newCart);
//                System.out.println(newCart);
            }
        }
        return newRes;
    }