⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 productworker.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                if (includeAdjustment) {                    newOrderAdjustmentsList.add(orderAdjustment);                }            }        }        return newOrderAdjustmentsList;    }    public static double getAverageProductRating(GenericDelegator delegator, String productId) {        return getAverageProductRating(delegator, productId, null);    }        public static double getAverageProductRating(GenericDelegator delegator, String productId, String productStoreId) {        GenericValue product = null;        try {            product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId));        } catch (GenericEntityException e) {            Debug.logError(e, module);        }        return ProductWorker.getAverageProductRating(product, productStoreId);    }    public static double getAverageProductRating(GenericValue product, String productStoreId) {        return getAverageProductRating(product, null, productStoreId);    }    public static double getAverageProductRating(GenericValue product, List reviews, String productStoreId) {        if (product == null) {            Debug.logWarning("Invalid product entity passed; unable to obtain valid product rating", module);            return 0.00;        }        double productRating = 0.00;        Double productEntityRating = product.getDouble("productRating");        String entityFieldType = product.getString("ratingTypeEnum");        // null check        if (productEntityRating == null) {            productEntityRating = new Double(0);        }        if (entityFieldType == null) {            entityFieldType = new String();        }        if ("PRDR_FLAT".equals(entityFieldType)) {            productRating = productEntityRating.doubleValue();        } else {            // get the product rating from the ProductReview entity; limit by product store if ID is passed            Map reviewByAnd = UtilMisc.toMap("statusId", "PRR_APPROVED");            if (productStoreId != null) {                reviewByAnd.put("productStoreId", productStoreId);            }            // lookup the reviews if we didn't pass them in            if (reviews == null) {                try {                    reviews = product.getRelatedCache("ProductReview", reviewByAnd, UtilMisc.toList("-postedDateTime"));                } catch (GenericEntityException e) {                    Debug.logError(e, module);                }            }            // tally the average            double ratingTally = 0;            double numRatings = 0;            if (reviews != null) {                Iterator i = reviews.iterator();                while (i.hasNext()) {                    GenericValue productReview = (GenericValue) i.next();                    Double rating = productReview.getDouble("productRating");                    if (rating != null) {                        ratingTally += rating.doubleValue();                        numRatings++;                    }                }            }            if (ratingTally > 0 && numRatings > 0) {                productRating = ratingTally /  numRatings;            }            if ("PRDR_MIN".equals(entityFieldType)) {                // check for min                if (productEntityRating.doubleValue() > productRating) {                    productRating = productEntityRating.doubleValue();                }            } else if ("PRDR_MAX".equals(entityFieldType)) {                // check for max                if (productRating > productEntityRating.doubleValue()) {                    productRating = productEntityRating.doubleValue();                }            }        }        return productRating;    }    public static List getCurrentProductCategories(GenericDelegator delegator, String productId) {        GenericValue product = null;        try {            product = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId));        } catch (GenericEntityException e) {            Debug.logError(e, module);        }        return getCurrentProductCategories(delegator, product);    }    public static List getCurrentProductCategories(GenericDelegator delegator, GenericValue product) {        if (product == null) {            return null;        }        List categories = new ArrayList();        try {            List categoryMembers = product.getRelated("ProductCategoryMember");            categoryMembers = EntityUtil.filterByDate(categoryMembers);            categories = EntityUtil.getRelated("ProductCategory", categoryMembers);        } catch (GenericEntityException e) {            Debug.logError(e, module);        }        return categories;    }        //get parent product    public static GenericValue getParentProduct(String productId, GenericDelegator delegator) {  	  GenericValue _parentProduct = null;  	  if (productId == null) {            Debug.logWarning("Bad product id", module);        }        try {            List virtualProductAssocs = delegator.findByAndCache("ProductAssoc", UtilMisc.toMap("productIdTo", productId, "productAssocTypeId", "PRODUCT_VARIANT"), UtilMisc.toList("-fromDate"));            virtualProductAssocs = EntityUtil.filterByDate(virtualProductAssocs, true);            if (virtualProductAssocs == null || virtualProductAssocs.size() == 0) {                //okay, not a variant, try a UNIQUE_ITEM                virtualProductAssocs = delegator.findByAndCache("ProductAssoc", UtilMisc.toMap("productIdTo", productId, "productAssocTypeId", "UNIQUE_ITEM"), UtilMisc.toList("-fromDate"));                virtualProductAssocs = EntityUtil.filterByDate(virtualProductAssocs, true);            }            if (virtualProductAssocs != null && virtualProductAssocs.size() > 0) {                //found one, set this first as the parent product                GenericValue productAssoc = EntityUtil.getFirst(virtualProductAssocs);                _parentProduct = productAssoc.getRelatedOneCache("MainProduct");            }        } catch (GenericEntityException e) {            throw new RuntimeException("Entity Engine error getting Parent Product (" + e.getMessage() + ")");        }        return _parentProduct;    }    public static boolean isDigital(GenericValue product) {        boolean isDigital = false;        if (product != null) {            GenericValue productType = null;            try {                productType = product.getRelatedOneCache("ProductType");            } catch (GenericEntityException e) {                Debug.logWarning(e.getMessage(), module);            }            String isDigitalValue = (productType != null? productType.getString("isDigital"): null);            isDigital = isDigitalValue != null && "Y".equalsIgnoreCase(isDigitalValue);        }        return isDigital;    }    public static boolean isPhysical(GenericValue product) {        boolean isPhysical = false;        if (product != null) {            GenericValue productType = null;            try {                productType = product.getRelatedOneCache("ProductType");            } catch (GenericEntityException e) {                Debug.logWarning(e.getMessage(), module);            }            String isPhysicalValue = (productType != null? productType.getString("isPhysical"): null);            isPhysical = isPhysicalValue != null && "Y".equalsIgnoreCase(isPhysicalValue);        }        return isPhysical;    }    public static String findProductId(GenericDelegator delegator, String idToFind, String goodIdentificationTypeId) throws GenericEntityException {        // first lookup and see if this is the Product PK        GenericValue product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", idToFind));        String productId = null;        if (product == null) {            // no product record found; no check good identification            Map goodIdLookup = UtilMisc.toMap("idValue", idToFind);            if (UtilValidate.isNotEmpty(goodIdentificationTypeId)) {                goodIdLookup.put("goodIdentificationTypeId", goodIdentificationTypeId);            }            List goodIds = delegator.findByAndCache("GoodIdentification", goodIdLookup, UtilMisc.toList("-createdStamp"));            // sorted by createdStamp; so pull out the most current entry            GenericValue lastGoodId = EntityUtil.getFirst(goodIds);            if (lastGoodId != null) {                productId = lastGoodId.getString("productId");            }        } else {            productId = product.getString("productId");        }        if (productId != null) {            return productId;        } else {            return null;        }    }    public static String findProductId(GenericDelegator delegator, String idToFind) throws GenericEntityException {        return findProductId(delegator, idToFind, null);    }    public static GenericValue findProduct(GenericDelegator delegator, String idToFind, String goodIdentificationTypeId) throws GenericEntityException {        // first lookup and see if this is the Product PK        GenericValue product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", idToFind));        String productId = null;        if (product == null) {            // no product record found; no check good identification            Map goodIdLookup = UtilMisc.toMap("idValue", idToFind);            if (UtilValidate.isNotEmpty(goodIdentificationTypeId)) {                goodIdLookup.put("goodIdentificationTypeId", goodIdentificationTypeId);            }            List goodIds = delegator.findByAndCache("GoodIdentification", goodIdLookup, UtilMisc.toList("-createdStamp"));            // sorted by createdStamp; so pull out the most current entry            GenericValue lastGoodId = EntityUtil.getFirst(goodIds);            if (lastGoodId != null) {                product = lastGoodId.getRelatedOneCache("Product");            }        }        if (product != null) {            return product;        } else {            return null;        }    }    public static GenericValue findProduct(GenericDelegator delegator, String idToFind) throws GenericEntityException {        return findProduct(delegator, idToFind, null);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -