Samples

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")); }

 

 

OrderSheet, OrderProduct : set data, create

 

 

 

Payment create