Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Cart : Read

  {
    "typeId": "api",
    "category": "cartApi",
    "apiId": "svcRead",
    "apiName": "장바구니 조회",
    "method": "GET",
    "parameters": [
    ],
    "config": [
      {
        "configId": "root",
        "tid": "cart",
        "type": "event",
        "allowParams": false,
        "orderNo": 1,
        "event": "svcRead"
      }
    ]
  },
  
  {
    "event": "svcRead",
    "name": "장바구니 조회",
    "noneExecute": true,
    "eventActions": [
      {
        "action": "svcReadAction",
        "actionName": "Read cart(service)",
        "actionType": "service",
        "actionBody": "kwopCartService.svcRead",
        "orderNo": 1
      }
    ]
  },

{
    "typeId": "api",
    "category": "cart",
    "apiId": "read",
    "apiName": "장바구니 조회",
    "method": "GET",
    "parameters": [
    ],
    "config": [
      {
        "configId": "root",
        "tid": "processFlow",
        "type": "process",
        "process": "cartRead",
        "allowParams": false,
        "orderNo": 1
      }
    ]
  }
  

public ExecuteContext svcRead(ExecuteContext context) {
        QueryResult queryResult = new QueryResult();
        Map<String, Object> data = context.getData();

        String deviceType = JsonUtils.getStringValue(data, "_deviceType");
        try {
            List<Map<String, Object>> cartProductList = getCartProductListWithCookie(context.getHttpRequest(),context.getHttpResponse(), deviceType);

            if (SessionHelper.isSignIn()) {
                String cartId = getCartIdWithCustomerNo();
                ValidationUtils.returnApiException(StringUtils.isBlank(cartId), OrderMessage.NOT_FOUND_CART_ID);

                cartProductList.addAll(getCartProductList(cartId, deviceType));
            }

            Map<String, List<Map<String, Object>>> groupingVendorCartProducts = cartProductList
                    .stream()
                    .collect(Collectors.groupingBy(cartProduct -> JsonUtils.getStringValue(cartProduct, "product.vendorId.value")));

            queryResult.put("item", groupingVendorCartProducts);

            context.setResult(queryResult);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new ApiException("420", e.getMessage(), false);
        }
        
  private List<Map<String, Object>>  getCartProductListWithCookie(HttpServletRequest request, HttpServletResponse response, String deviceType) {

        List<Map<String, Object>> cartProductList = new ArrayList<>();
        String cartId = getCartIdWithCookie(request);
        if(StringUtils.isNotEmpty(cartId)){
            return getCartProductList(cartId, deviceType);
        }

        return cartProductList;
    }
    
  public String getCartIdWithCookie(HttpServletRequest request) {
        try {
            String cartString = CookieUtils.getValue(request, "cart");
            logger.info(cartString);
            if(StringUtils.isNotEmpty(cartString)){
                return AES256Util.decrypt(cartString);
            }
        } catch (Exception e) {
            logger.error("쿠키에 저장된 cartId 복호화 오류 : " + e, e);
        }

        return null;
    }
    
private List<Map<String, Object>> getCartProductList(String cartId, String deviceType) {
        logger.info("[cartList] cartId : {}", cartId);
        List<Map<String, Object>> cartProductList = new ArrayList<>();

        List<Map<String, Object>> _cartProducts = getCartProductList(cartId);
        List<Map<String, Object>> cartPackageProductList = new ArrayList<>();
        _cartProducts.forEach(cartProduct -> {
            if(ProductType.SINGLE.equals(JsonUtils.getStringValue(cartProduct, "productType")) && JsonUtils.getStringValue(cartProduct, "upperCartProductId").isEmpty()){ // 단품상품
                cartProduct = CommonOrder.shopOrderItem(cartProduct, deviceType, EventService.READ);
                if(cartProduct != null) {
                    cartProductList.add(cartProduct);
                }
            } else if(ProductType.PACKAGE.equals(JsonUtils.getStringValue(cartProduct, "productType"))){ //패키지 상품
                Node product = nodeService.getNode("product", JsonUtils.getStringValue(cartProduct, "productId"));
                if (product == null) {
                    logger.warn("[cartList] product is null : {}", cartProduct);
                    return;
                }

                product.toDisplay();
                cartProduct.put("product", product);

                cartPackageProductList.add(cartProduct);
            }
        });

        //하위 상품 설정
        Map<String, List<Map<String, Object>>> groupingLowerCartProducts = _cartProducts
                .stream()
                .filter(cartProduct -> !JsonUtils.getStringValue(cartProduct, "upperCartProductId").isEmpty())
                .collect(Collectors.groupingBy(cartProduct -> JsonUtils.getStringValue(cartProduct, "upperCartProductId")));

        cartPackageProductList.forEach(cartPackageProduct -> {
            String cartProductId = JsonUtils.getStringValue(cartPackageProduct, "cartProductId");
            List<Map<String, Object>> lowerCartProducts = groupingLowerCartProducts.get(cartProductId);
            if(lowerCartProducts == null){
                logger.warn("[cartList] lowerCartProducts is null, cartProductId : {}", cartProductId);
                return;
            }

            cartPackageProduct.put("packages", CommonOrder.shopOrderItems(lowerCartProducts, deviceType, EventService.READ));
            CommonOrder.setPackagePrice(cartPackageProduct, productPriceService.getPackageProductPrice(cartPackageProduct, lowerCartProducts));
        });

        cartProductList.addAll(cartPackageProductList);

        return cartProductList;
    }

    private List<Map<String, Object>> getCartProductList(String cartId) {
        NodeQuery cartProductsQuery = NodeQuery.build(CART_PRODUCT);
        cartProductsQuery.equals("cartId", cartId);
        cartProductsQuery.sorting("created desc");

        return (List<Map<String, Object>>) cartProductsQuery.getList();
    }
    
    public String getCartIdWithCustomerNo() {
        String siteId = (String) SessionHelper.getSessionDataValue("siteId");
        String customerNo = SessionHelper.getCustomerNo();
        String cartId = SessionHelper.getCartId();

        if (StringUtils.isAnyBlank(siteId, customerNo)) {
            return null;
        }

        if (StringUtils.isBlank(cartId)) {
            try {
                cartId = createCartIdInDB(customerNo);

                SessionUtils.getSessionService().putSessionValue(customerNo, siteId, "cartId", cartId);
            } catch (Exception e) {
                logger.info(e.getMessage(), e);
                return null;
            }
        }

        return cartId;
    }
    
    public static Map<String, Object> shopOrderItem(Map<String, Object> productMap, String deviceType, String event) {

        String productId = JsonUtils.getStringValue(productMap, "productId");
        String upperCartProductId = JsonUtils.getStringValue(productMap, "upperCartProductId");
        if (StringUtils.isEmpty(productId)) return null;

        Node product = NodeUtils.getNode("product", productId);
        if (product == null || product.isEmpty()) return null;

        try {
            productPriceService.setRealSaleData(product, true, !upperCartProductId.isEmpty());
            setVendorDelivery(product);
            setVendorSellerInfo(product);
        } catch (Exception e) {
            logger.warn("상품 가격 정보 혹은 배송정보를 가져 올 수 없습니다. 제외합니다. , " + product);
            return null;
        }

        product.toDisplay();

        if (EventService.READ.equals(event)) {
            imageDisplayService.setImage(deviceType, product);
        }
        productMap.put("product", product);
        BigDecimal consumerPrice = JsonUtils.getBigDecimalValue(product, "consumerPrice");
        BigDecimal salePrice = JsonUtils.getBigDecimalValue(product, "salePrice");
        BigDecimal deliveryPrice = JsonUtils.getBigDecimalValue(product, "deliveryPrice");
        BigDecimal marginRate = JsonUtils.getBigDecimalValue(product, "margin.marginRate");
        BigDecimal addPrice = BigDecimal.ZERO;

        Node baseOptionItem = NodeUtils.getNode("productOptionItem", JsonUtils.getStringValue(productMap, "baseOptionItemNo"));
        if (baseOptionItem != null) {
            baseOptionItem.put("productOptionCodeNos", baseOptionItem.getReferencesList("productOptionCodeNos"));
            productMap.put("baseOptionItem", baseOptionItem);

            addPrice = JsonUtils.getBigDecimalValue(baseOptionItem, "addPrice");
        }

        BigDecimal orderPrice = JsonUtils.getBigDecimalValue(product, "salePrice")
                .add(JsonUtils.getBigDecimalValue(baseOptionItem, "addPrice"))
                .multiply(JsonUtils.getBigDecimalValue(productMap, "quantity"));

        Long savingPoint = PointRuleService.getSavingPoint(orderPrice.longValue());

        productMap.put("savingPoint", savingPoint);
        productMap.put("salePrice", salePrice);
        productMap.put("baseAddPrice", addPrice);
        productMap.put("deliveryType", product.get("deliveryType"));
        productMap.put("deliveryPrice", deliveryPrice);
        productMap.put("consumerPrice", consumerPrice);
        productMap.put("discountPrice", BigDecimal.ZERO);
        productMap.put("orderPrice", orderPrice);
        productMap.put("feePayment", feePaymentCalculator(orderPrice, marginRate));

        return productMap;
    }
    
     public void setRealSaleData(Map<String, Object> product, boolean showPromotion, boolean isPackageLowerProduct) {
        String productId = JsonUtils.getStringValue(product, "productId");
        String productType = JsonUtils.getStringValue(product, "productType");
        String vendorId = JsonUtils.getStringValue(product, "vendorId");
        BigDecimal consumerPrice = JsonUtils.getBigDecimalValue(product, "consumerPrice");
        BigDecimal originSalePrice = JsonUtils.getBigDecimalValue(product, "salePrice");
        String taxType = JsonUtils.getStringValue(product, "taxType");
        if (ProductType.SINGLE.equals(productType) && StringUtils.isEmpty(taxType)) {
            throw new ApiException("400", "Not Found taxType");
        }

        Map<String, Object> promotion = new HashMap<>();
        //패키지 상품은 프로모션 맵핑 불가
        if (showPromotion && !isPackageLowerProduct && ProductType.SINGLE.equals(productType)) {
            promotion = getPromotionData(productId);
        }
        BigDecimal salePrice = getSalePrice(product, promotion);
        Map<String, Object> margin = getMarginData(vendorId, getMarginType(taxType, promotion));
        product.put("original", setOriginal(product));
        product.put("promotion", promotion);
        product.put("salePrice", salePrice);
        product.put("nonPromotionSalePrice", originSalePrice);
        product.put("discountRate", getDiscountRate(consumerPrice, salePrice));
        product.put("margin", margin);
    }
    
    public static void setVendorDelivery(Node product) {

        String vendorDeliveryNo = product.getStringValue("vendorDeliveryNo");
        if (vendorDeliveryNo == null) {
            throw new ApiException("400", "공급사 배송정보가 존재하지 않습니다.");
        }
        Node vendorDelivery = NodeUtils.getNode("vendorDelivery", vendorDeliveryNo);
        if (vendorDelivery == null || vendorDelivery.isEmpty() || vendorDelivery.get("deliveryType") == null) {
            throw new ApiException("400", "공급사 배송정보가 존재하지 않습니다.");
        }

        product.put("vendorDeliveryInfo", vendorDelivery);
        product.put("deliveryType", vendorDelivery.get("deliveryType"));
        product.put("deliveryPrice", vendorDelivery.get("deliveryPrice") == null ? 0 : vendorDelivery.get("deliveryPrice"));
    }
    
    public static void setVendorSellerInfo(Node product) {
        String vendorId = product.getStringValue("vendorId");
        Node node = NodeUtils.getNode("vendor", vendorId);
        if (node == null) throw new ApiException("404", "공급사 판매 정보를 찾을 수 없습니다.");
        product.put("sellerId", node.getStringValue("sellerId"));
    }            
[
  {
    "typeId": "processFlow",
    "id": "cartRead",
    "name": "장바구니 조회",
    "processType": "",
    "result": "item",
    "flow": [
      {
        "typeId": "mapper",
        "id": 100001,
        "name": "Cart data by session",
        "input": "session",
        "output": "cart",
        "mapperTerms": [
          { "id": 100002, "field": "id", "method": "mapping", "valueType": "string", "value": "cart.id" },
          { "id": 100003, "field": "node", "method": "mapping", "valueType": "node", "value": "{{:getNode('cart',cart.id)}}" },
          { "id": 100005, "field": "cartProducts", "method": "mapping", "valueType": "referenced", "value": "node.cartProducts" }
        ],
        "next": 100006
      },
      {
        "typeId": "mapper",
        "id": 100006,
        "name": "Product data setting for each shopping cart",
        "input": "cart.cartProducts",
        "output": "cartProductList",
        "mapperTerms": [
          { "id": 100007, "field": "siteProduct", "method": "mapping", "valueType": "node", "value": "siteProduct" },
          { "id": 100008, "field": "quantity", "method": "mapping", "valueType": "int", "value": "quantity" },
          { "id": 100010, "field": "seller", "method": "mapping", "valueType": "node", "value": "siteProduct.seller" },
          { "id": 100013, "field": "productDeliveryFee", "method": "mapping", "valueType": "node", "value": "siteProduct.productDeliveryInfo.productDeliveryFee" },
          { "id": 100014, "field": "existOption", "method": "mapping", "valueType": "boolean", "value": "{{:notEquals('none',siteProduct.productDetail.optionType)}}" },
          { "id": 100015, "field": "option", "method": "first", "valueType": "node", "value": "productSingleOption,productMixOptionItem" },
          { "id": 100016, "field": "price.stockQuantity", "method": "first", "valueType": "int", "value": "productSingleOption.stockQuantity,productMixOptionItem.stockQuantity,siteProduct.baseProduct.productSaleInfo.stockQuantity" },
          { "id": 100017, "field": "price.salePrice", "method": "mapping", "valueType": "int", "value": "siteProduct.siteProductSaleInfo.salePrice" },
          { "id": 100018, "field": "price.optionPrice", "method": "first", "valueType": "int", "value": "productSingleOption.optionPrice,productMixOptionItem.optionPrice" },
          { "id": 100019, "field": "price.immediateDiscountSalePrice", "method": "mapping", "valueType": "int", "value": "siteProduct.siteProductSaleInfo.discountSalePrice" },
          { "id": 100020, "field": "price.immediateDiscountPrice", "method": "mapping", "valueType": "int", "value": "{{:subtract(siteProduct.siteProductSaleInfo.salePrice,siteProduct.siteProductSaleInfo.discountSalePrice)}}" },
          { "id": 100021, "field": "price.totalSalePrice", "method": "mapping", "valueType": "int", "value": "{{:multiply(add(siteProductSaleInfo.salePrice,option.optionPrice),quantity)}}" }
        ],
        "next": 100022
      },
      {
        "typeId": "mapper",
        "id": 100022,
        "name": "Group by cartProductList",
        "input": "cartProductList",
        "output": "groups",
        "mapperTerms": [
          { "id": 100023, "field": "list", "method": "groupBy", "valueType": "list", "value": "siteProduct.productDeliveryInfo.deliveryType,seller.id,siteProduct.productDeliveryInfo.deliveryBundleGroup.id,siteProduct.productDeliveryInfo.productDeliveryFee.deliveryFeeType" }
        ],
        "next": 100122
      },
      {
        "typeId": "reducer",
        "id": 100122,
        "name": "TotalSalePrice by group",
        "input": "groups.list",
        "output": "groups.price",
        "reducerTerms": [
          { "id":  null, "field": "totalSalePrice", "method": "sum", "value": "price.salePrice" },
          { "id":  null, "field": "totalQuantity", "method": "sum", "value": "quantity" },
          { "id":  null, "field": "totalDiscountSalePrice", "method": "sum", "value": "price.immediateDiscountSalePrice" },
          { "id":  null, "field": "totalDiscountPrice", "method": "sum", "value": "price.immediateDiscountPrice" }
        ],
        "next": 100028
      },
      {
        "typeId": "mapper",
        "id": 100028,
        "name": "Calculate shipping cost by group",
        "input": "groups",
        "output": "groups.price",
        "mapperTerms": [
          { "id": 100029, "field": "deliveryPrice", "method": "method", "valueType": "bigDecimal", "value": "{{:deliveryFee()}}" }
        ],
        "next": 100030
      },
      {
        "typeId": "mapper",
        "id": 100030,
        "name": "TotalOrderPrice by group",
        "input": "groups.price",
        "output": "groups.price",
        "mapperTerms": [
          { "id": 100031, "field": "totalOrderPrice", "method": "method", "valueType": "bigDecimal", "value": "{{:add(totalDiscountSalePrice,deliveryPrice)}}" }
        ],
        "next": 100130
      },
      {
        "typeId": "reducer",
        "id": 100130,
        "name": "TotalSalePrice by cart",
        "input": "groups",
        "output": "totalPriceSummary",
        "reducerTerms": [
          { "id":  null, "field": "totalSalePrice", "method": "sum", "value": "price.totalSalePrice" },
          { "id":  null, "field": "totalDeliveryPrice", "method": "sum", "value": "price.deliveryPrice" },
          { "id":  null, "field": "totalDiscountPrice", "method": "sum", "value": "price.totalDiscountPrice" },
          { "id":  null, "field": "totalOrderPrice", "method": "sum", "value": "price.totalOrderPrice" }
        ],
        "next": 100036
      },
      {
        "typeId": "mapper",
        "id": 100036,
        "name": "Cart read final response",
        "input": "cart",
        "output": "item",
        "mapperTerms": [
          { "id": 100037, "field": "id", "method": "mapping", "valueType": "string", "value": "context.cart.id" },
          { "id": 100038, "field": "totalPriceSummary", "method": "mapping", "valueType": "map", "value": "context.totalPriceSummary" },
          { "id": 100039, "field": "items", "method": "mapping", "valueType": "list", "value": "context.groups" }
        ]
      }
    ]
  }

]

OrderSheet, OrderProduct : set data, create

//KwopOrderPaymentService.java
  
  public void orderComplete(ExecuteContext context) {
        Map<String, Object> data = context.getData();
        String orderId = JsonUtils.getStringValue(data, ORDER_ID);
        orderLogger.info("({}) Start order !!", orderId);

        // 주문 완료 후 주문 완료 메일 발송을 위한 세팅
        String email = String.valueOf(SessionHelper.getCustomer().get("email"));
        try {

            setData(data);
            setOrderItems(context);
            orderLogger.info("({}) {} {} : {}", orderId, ORDER_SHEET, EventService.CREATE, data);
            nodeService.executeNodeByMap(data, ORDER_SHEET, EventService.CREATE, context);

            kwopOrderPaymentService.order(context);     //PG 결제정보 생성
            kwopPointService.order(context);            //포인트 차감
            kwopOrderCouponService.order(context);      //쿠폰 사용처리

            QueryResult queryResult = new QueryResult();
            queryResult.put("message", OrderMessage.ORDER_COMPLETE.getMessage());
            queryResult.put("orderId", data.get("tempOrderId"));
            queryResult.put("email", email);
            context.setResult(queryResult);

            orderLogger.info("({}) Order Completed !!", orderId);

        } catch (ApiException e) {
            orderLogger.error("({}) {}", orderId, e.getMessage(), e);
            if ("401".equals(e.getResultCode())) {
                throw new ApiException("420", OrderMessage.ORDER_IS_ALREADY_ORDERED.getMessage());
            }
            throw new ApiException(e.getResultCode(), e.getMessage());
        } catch (Exception e) {
            orderLogger.error("({}) {}", orderId, e.getMessage(), e);
            throw new ApiException("400", OrderMessage.ORDER_FAIL.getMessage());
        }
        //rollback(orderId);
    }
    
    /**
     * orderSheet create 하기 위해 필요한 값 셋팅.
     *
     * @param data the data
     */
    public void setData(Map<String, Object> data) {

        String tempOrderId = ValidationUtils.requiredParameterCheckById(data, "tempOrderId");
        String customerNo = SessionHelper.getCustomerNo();
        String customerId = SessionHelper.getCustomerId();
        String buyerName = SessionHelper.getName();
        String buyerTelNo = SessionHelper.getCellPhone();

        List<Map<String, Object>> tempOrders = (List<Map<String, Object>>) NodeQuery.build("tempOrder").equals("tempOrderId", tempOrderId).equals("customerNo", customerNo).equals("finishedYn", "false").getList();

        if (tempOrders.size() == 0) {
            throw new ApiException("420", OrderMessage.NOT_FOUND_TEMP_ORDER.getMessage());
        }

        data.put("customerId", customerId);
        data.put("cartId", tempOrders.get(0).get("cartId"));
        data.put("buyNowYn", tempOrders.get(0).get("buyNowYn"));
        data.put("paymentCompletedDate", data.get("now"));
        data.put("buyerName", buyerName);
        data.put("buyerTelNo", buyerTelNo);
    }
    
    public void setOrderItems(ExecuteContext context) {
        Map<String, Object> data = context.getData();
        String tempOrderId = ValidationUtils.requiredParameterCheckById(data, "tempOrderId");
        String customerNo = SessionHelper.getCustomerNo();

        List<Map<String, Object>> items = CommonOrder.makeTempOrderItems(tempOrderId, customerNo, EventService.CREATE, null);
        Map<String, Object> total = CommonOrder.getTotalPriceMap(items);

        CouponPayment couponPayment = CommonOrder.makeCouponPayment(data);
        BigDecimal totalOrderDiscountPrice = JsonUtils.getBigDecimalValue(total, "totalOrderDiscountPrice");
        data.put("couponDiscountPrice", couponPayment.getCouponDiscountPrice());
        data.put("totalConsumerPrice", total.get("totalOrderConsumerPrice"));
        data.put("totalDeliveryPrice", total.get("totalDeliveryPrice"));
        data.put("totalPackageDiscountPrice", total.get("totalPackageDiscountPrice"));
        data.put("totalDiscountPrice", totalOrderDiscountPrice.add(couponPayment.getCouponDiscountPrice()));
        data.put("totalOrderPrice", total.get("totalOrderPrice"));
        context.setData(data);
    }
    //CommonOrder.java

public static List<Map<String, Object>> makeTempOrderItems(String tempOrderId, String customerNo, String event, String deviceType) {

        List<Map<String, Object>> tempOrders = (List<Map<String, Object>>) NodeQuery.build(TEMPORDER_TID).equals("tempOrderId", tempOrderId).equals("customerNo", customerNo).equals("finishedYn", "false").getList();
        List<Map<String, Object>> tempOrderProducts = (List<Map<String, Object>>) NodeQuery.build(TEMPORDER_PRODUCT_TID).equals("tempOrderId", tempOrderId).getList();

        OrderMessage.NOT_FOUND_TEMP_ORDER.validation(tempOrders.size() == 0 || tempOrderProducts.size() == 0);

        Map<String, List<Map<String, Object>>> groupingTempOrderProduct = tempOrderProducts
                .stream()
                .collect(Collectors.groupingBy(tempOrderProduct -> JsonUtils.getStringValue(tempOrderProduct, "upperTempOrderProductId")));

        List<Map<String, Object>> _tempOrderProducts = groupingTempOrderProduct.get("")
                .stream()
                .peek(tempOrderProduct -> {
                    String upperTempOrderProductId = JsonUtils.getStringValue(tempOrderProduct, "tempOrderProductId");
                    List<Map<String, Object>> lowerTempOrderProducts = groupingTempOrderProduct.get(upperTempOrderProductId);
                    if (lowerTempOrderProducts != null) {
                        lowerTempOrderProducts.forEach(lowerTempOrderProduct -> makeTempOrderItem(lowerTempOrderProduct, event, deviceType));
                        tempOrderProduct.put("packages", lowerTempOrderProducts);
                    }
                }).collect(Collectors.toList());

        for (Map<String, Object> tempProduct : _tempOrderProducts) {
            makeTempOrderItem(tempProduct, event, deviceType);
        }

        List<Map<String, Object>> items = new ArrayList<>();
        setProductViewItems(_tempOrderProducts, items);
        return items;
    }
    
    public static void makeTempOrderItem(Map<String, Object> tempProduct, String event, String deviceType) {
        String productId = JsonUtils.getStringValue(tempProduct, "productId");
        if (StringUtils.isEmpty(productId)) {
            throw new ApiException("420", OrderMessage.NOT_FOUND_PRODUCT.getMessage());
        }

        Node product = NodeUtils.getNode("product", productId);
        if (product == null) {
            throw new ApiException("420", OrderMessage.NOT_FOUND_PRODUCT.getMessage());
        }

        String productType = JsonUtils.getStringValue(product, "productType");
        if (StringUtils.isEmpty(productType)) {
            throw new ApiException("420", OrderMessage.NOT_FOUND_PRODUCT.getMessage());
        }

        String tempOrderProductId = JsonUtils.getStringValue(tempProduct, "tempOrderProductId");
        if (StringUtils.isBlank(tempOrderProductId)) {
            return;
        }

        setVendorDelivery(product);
        setVendorSellerInfo(product);

        product.toDisplay();

        if (EventService.READ.equals(event)) {
            imageDisplayService.setImage(deviceType, product);
        }

        tempProduct.put("product", product);

        if (ProductType.SINGLE.equals(productType)) {
            Node baseOptionItem = NodeUtils.getNode("productOptionItem", JsonUtils.getStringValue(tempProduct, "baseOptionItemNo"));
            if (baseOptionItem == null) {
                throw new ApiException("420", OrderMessage.NOT_FOUND_PRODUCT_OPTION_ITEM.getMessage());
            }

            tempProduct.put("baseOptionItem", baseOptionItem);
        }

        tempProduct.put("productType", productType);
        tempProduct.put("consumerPrice", JsonUtils.getBigDecimalValue(tempProduct, "consumerPrice"));
    }
    
    public static Map<String, Object> getTotalPriceMap(List<Map<String, Object>> items) {

        Map<String, Object> totalPrice = new HashMap<>();
        BigDecimal totalDeliveryPrice = BigDecimal.ZERO;
        BigDecimal totalOrderConsumerPrice = BigDecimal.ZERO;
        BigDecimal totalOrderDiscountPrice = BigDecimal.ZERO;
        BigDecimal totalOrderPackageDiscountPrice = BigDecimal.ZERO;
        BigDecimal totalOrderPrice = BigDecimal.ZERO;

        for (Map<String, Object> item : items) {
            totalDeliveryPrice = totalDeliveryPrice.add(JsonUtils.getBigDecimalValue(item, "deliveryPrice"));
            totalOrderConsumerPrice = totalOrderConsumerPrice.add(JsonUtils.getBigDecimalValue(item, "orderConsumerPrice"));
            totalOrderDiscountPrice = totalOrderDiscountPrice.add(JsonUtils.getBigDecimalValue(item, "orderDiscountPrice"));
            totalOrderPackageDiscountPrice = totalOrderPackageDiscountPrice.add(JsonUtils.getBigDecimalValue(item, "orderPackageDiscountPrice"));
            totalOrderPrice = totalOrderPrice.add(JsonUtils.getBigDecimalValue(item, "orderPrice"));
        }

        totalPrice.put("totalDeliveryPrice", totalDeliveryPrice);
        totalPrice.put("totalOrderConsumerPrice", totalOrderConsumerPrice);
        totalPrice.put("totalOrderPackageDiscountPrice", totalOrderPackageDiscountPrice);
        totalPrice.put("totalOrderDiscountPrice", totalOrderDiscountPrice);
        totalPrice.put("totalOrderPrice", totalOrderPrice);
        totalPrice.put("paymentPrice", totalOrderPrice.add(totalDeliveryPrice).subtract(totalOrderDiscountPrice));

        return totalPrice;
    }
    
    public static Integer setDeliveryTotalPrice(Map<String, Object> deliveryPriceList, List<Map<String, Object>> items) {

        int totalSize = 0;
        for (String key : deliveryPriceList.keySet()) {

            QueryResult itemResult = new QueryResult();

            List<Map<String, Object>> subProductResult = new ArrayList<>();
            BigDecimal totalOrderPrice = BigDecimal.ZERO;
            BigDecimal totalFeePayment = BigDecimal.ZERO;
            BigDecimal totalConsumerPrice = BigDecimal.ZERO;
            BigDecimal totalDiscountPrice = BigDecimal.ZERO;
            BigDecimal totalPackageDiscountPrice = BigDecimal.ZERO;
            long vendorDeliveryPrice = 0;

            List<Map<String, Object>> priceList = (List<Map<String, Object>>) deliveryPriceList.get(key);

            for (Map<String, Object> priceProduct : priceList) {
                subProductResult.add(priceProduct);

                String productType = JsonUtils.getStringValue(priceProduct, "productType");

                BigDecimal consumerPrice = BigDecimal.ZERO;
                BigDecimal discountPrice = BigDecimal.ZERO;
                BigDecimal packageDiscountPrice = BigDecimal.ZERO;
                if (ProductType.SINGLE.equals(productType)) {
                    consumerPrice = JsonUtils.getBigDecimalValue(priceProduct, "consumerPrice");
                    totalOrderPrice = totalOrderPrice.add(JsonUtils.getBigDecimalValue(priceProduct, "orderPrice"));

                } else if (ProductType.PACKAGE.equals(productType)) {
                    consumerPrice = JsonUtils.getBigDecimalValue(priceProduct, "consumerPrice");
                    packageDiscountPrice = JsonUtils.getBigDecimalValue(priceProduct, "packageDiscountPrice");
                    totalOrderPrice = totalOrderPrice.add(JsonUtils.getBigDecimalValue(priceProduct, "orderPrice"));
                }

                BigDecimal quantity = JsonUtils.getBigDecimalValue(priceProduct, "quantity");
                consumerPrice = consumerPrice.multiply(quantity);
                discountPrice = discountPrice.multiply(quantity);

                totalConsumerPrice = totalConsumerPrice.add(consumerPrice);
                totalDiscountPrice = totalDiscountPrice.add(discountPrice);
                totalPackageDiscountPrice = totalPackageDiscountPrice.add(packageDiscountPrice);
                totalFeePayment = totalFeePayment.add(JsonUtils.getBigDecimalValue(priceProduct, "feePayment"));
                long deliveryPrice = JsonUtils.getLongValue(priceProduct, "deliveryPrice");
                if (vendorDeliveryPrice < deliveryPrice) {
                    vendorDeliveryPrice = deliveryPrice;
                }

                priceProduct.put("soldOutStatus", isSoldOutStatus((Map) priceProduct.get("product"), JsonUtils.getStringValue(priceProduct, "baseOptionItemNo")));
                priceProduct.put("endSellingStatus", isEndSellingStatus((Map) priceProduct.get("product")));
                priceProduct.put("discountInfo", getDiscountInfo(priceProduct));
            }

            itemResult.put("deliverySeq", key);
            itemResult.put("deliveryPrice", vendorDeliveryPrice);
            itemResult.put("orderConsumerPrice", totalConsumerPrice);
            itemResult.put("orderDiscountPrice", totalDiscountPrice);
            itemResult.put("orderPackageDiscountPrice", totalPackageDiscountPrice);
            itemResult.put("orderPrice", totalOrderPrice);
            itemResult.put("feePayment", totalFeePayment);
            itemResult.put("item", subProductResult);
            totalSize += subProductResult.size();
            items.add(itemResult);
        }

        return totalSize;
    }
      {
        "typeId": "mapper",
        "id": 339647087,
        "name": "read 임시 주문서",
        "input": "data",
        "output": "tempOrderSheet",
        "mapperTerms": [
          { "id": null, "field": "id", "method": "mapping", "valueType": "string", "value": "id" },
          { "id": null, "field": "node", "method": "mapping", "valueType": "node", "value": "{{:getNode('tempOrderSheet',id)}}" },
          { "id": null, "field": "tempOrderProducts", "method": "mapping", "valueType": "referenced", "value": "node.tempOrderProducts" }
        ],
        "next": 766091204
      },
      {
        "typeId": "mapper",
        "id": 1175445245,
        "name": "set orderSheet",
        "input": "tempOrderSheet",
        "output": "orderSheet",
        "mapperTerms": [
          { "id": null, "field": "id", "method": "mapping", "valueType": "method", "value": "{{:orderId()}}" },
          { "id": null, "field": "orderer", "method": "mapping", "valueType": "object", "value": "orderer" },
          { "id": null, "field": "customer", "method": "mapping", "valueType": "string", "value": "session.customer.id" },
          { "id": null, "field": "site", "method": "mapping", "valueType": "string", "value": "session.siteId" },
          { "id": null, "field": "nonCustomer", "method": "method", "valueType": "boolean", "value": "{{:equals('',session.customer.id)}}" },
          { "id": null, "field": "orderAgree", "method": "mapping", "valueType": "object", "value": "data.orderAgree" },
          { "id": null, "field": "deviceType", "method": "mapping", "valueType": "string", "value": "session.deviceType" },
          { "id": null, "field": "payMethod", "method": "mapping", "valueType": "object", "value": "data.payMethod" },
          { "id": null, "field": "payNo", "method": "mapping", "valueType": "string", "value": "" },
          { "id": null, "field": "deliveryPlace", "method": "method", "valueType": "object", "value": "{{:deliveryPlace()}}" },
          { "id": null, "field": "orderDate", "method": "mapping", "valueType": "date", "value": "{{:now}}" }
        ],
        "next": 77024379
      },
       {
        "typeId": "mapper",
        "id": 1730795885,
        "name": "set orderSheet price info",
        "input": "tempOrderSheet",
        "output": "orderSheet.orderSheetPriceInfo",
        "mapperTerms": [
          { "id": null, "field": "orderSheet", "method": "mapping", "valueType": "method", "value": "context.orderSheet.id" },
          { "id": null, "field": "totalSalePrice", "method": "mapping", "valueType": "long", "value": "totalPriceSummary.totalSalePrice" },
          { "id": null, "field": "totalDeliveryPrice", "method": "mapping", "valueType": "long", "value": "totalPriceSummary.totalDeliveryPrice" },
          { "id": null, "field": "totalOrderPrice", "method": "mapping", "valueType": "long", "value": "totalPriceSummary.totalOrderPrice" },
          { "id": null, "field": "immediateDiscountPrice", "method": "mapping", "valueType": "long", "value": "totalPriceSummary.immediateDiscountPrice" },
          { "id": null, "field": "cartCoupon", "method": "mapping", "valueType": "string", "value": "cartCoupon" },
          { "id": null, "field": "cartCouponDiscountPrice", "method": "mapping", "valueType": "long", "value": "cartCouponDiscountPrice" },
          { "id": null, "field": "totalCouponDiscountPrice", "method": "method", "valueType": "long", "value": "{{:sum(cartCouponDiscountPrice,productCouponDiscountPrice)}}" },
          { "id": null, "field": "totalDiscountPrice", "method": "mapping", "valueType": "long", "value": "{{:sum(totalPriceSummary.totalDiscountPrice,totalCouponDiscountPrice)" },
          { "id": null, "field": "totalPaymentPrice", "method": "method", "valueType": "long", "value": "{{:subtract(subtract(sum(totalOrderPrice,totalDeliveryPrice),totalUsedPoint),totalCouponDiscountPrice)}}" }

        ],
        "next": 1350532542
      },
      {
        "typeId": "trigger",
        "id": 542839712,
        "name": "create OrderSheet",
        "input": "orderSheet",
        "output": "orderSheet",
        "filter": {
          "typeId": "filter", "id": null, "name": "PG 승인 여부", "type": "filter", "isNot": false, "conjunction": "and",
          "filterTerms": [
            { "typeId": "filterTerms", "id": null, "field": "id", "isNot": false, "method": "equals", "value": "context.pg.orderId" },
            { "typeId": "filterTerms", "id": null, "field": "context.pg.result", "isNot": false, "method": "equals", "value": "success" }
          ]
        },
        "processEvent": { "typeId": "processEvent", "id" : "createOrderSheet", "name": "주문서 생성", "tid": "orderSheet", "targetEvent": "save" },
        "next": 2075689757
      },
      {
        "typeId": "mapper",
        "id": 2075689757,
        "name": "set orderProduct",
        "input": "tempOrderSheet.tempOrderProducts",
        "output": "orderProducts",
        "mapperTerms": [
          { "id": null, "field": "orderSheet", "method": "mapping", "valueType": "string", "value": "orderSheet.id" },
          { "id": null, "field": "orderProductPriceInfo", "method": "mapping", "valueType": "object", "value": "tempOrderProductPriceInfo" }
        ],
        "next": 1489407238
      },
      {
        "typeId": "mapper",
        "id": 1489407238,
        "name": "set product price info ",
        "input": "orderProducts",
        "output": "orderProducts.orderProductPriceInfo",
        "mapperTerms": [
          { "id": null, "field": "productCoupon", "method": "mapping", "valueType": "string", "value": "{{:find(coupon.groupByTempOrderProduct.id,id,productCoupon)}}" },
          { "id": null, "field": "productCouponDiscountPrice", "method": "mapping", "valueType": "long", "value": "{{:find(coupon.groupByTempOrderProduct.id,id,productCouponDiscountPrice)}}" },
          { "id": null, "field": "totalDiscountPrice", "method": "method", "valueType": "long", "value": "{{:add(multiply(orderProductPriceInfo.immediateDiscountPrice,orderProductPriceInfo.quantity),productCouponDiscountPrice)}}" },
          { "id": null, "field": "totalPaymentPrice", "method": "mapping", "valueType": "long", "value": "{{:subtract(orderProductPriceInfo.totalOrderPrice,productCouponDiscountPrice)" }

        ],
        "next": 2073631354
      },
      {
        "typeId": "trigger",
        "id": 2073631354,
        "name": "create orderProducts",
        "input": "orderProducts",
        "output": "orderProducts",
        "processEvent": { "typeId": "processEvent", "id" : "createOrderSheet", "name": "주문서 상품 생성", "tid": "orderProduct", "targetEvent": "save" },
        "next": 1654086289
      },

Payment create

//KwopOrderPaymentService.java

public void order(ExecuteContext context) {
        Map<String, Object> data = context.getData();
        String orderId = JsonUtils.getStringValue(data, "orderId");
        orderLogger.info("({}) Start payment !! isPayment : {}", orderId, data.get("payment") != null);
        try {
            if (data.get("payment") != null) {
                Map<String, Object> payment = (Map<String, Object>) data.get("payment");

                orderLogger.info("({}) {} {} : {}", orderId, ORDER_PAYMENT, EventService.CREATE, payment);
                Node paymentNode = (Node) nodeService.executeNodeByMap(payment, ORDER_PAYMENT, EventService.CREATE, context);
                orderLogger.info("({}) Order Payment saved !! PaymentId : {}", orderId, paymentNode.getId());
            }
        } catch (ApiException e) {
            orderLogger.error("({}) {}", orderId, e.getMessage(), e);
            throw new ApiException(e.getResultCode(), e.getMessage());
        } catch (Exception e) {
            orderLogger.error("({}) {}", orderId, e.getMessage(), e);
            throw new ApiException("420", OrderMessage.ORDER_FAIL.getMessage());
        }
    }

{
        "typeId": "trigger",
        "id": 2105442359,
        "name": "create payment",
        "input": "pg",
        "output": "payment",
        "processEvent": { "typeId": "processEvent", "id" : "createPayment", "name": "create  payment", "tid": "payment", "targetEvent": "create" },
        "next": 542839712
      },

  • No labels