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

📄 productservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                productAssocs = product.getRelatedCache("MainProductAssoc", UtilMisc.toMap("productAssocTypeId", type), UtilMisc.toList("sequenceNum"));            } else {                productAssocs = product.getRelatedCache("AssocProductAssoc", UtilMisc.toMap("productAssocTypeId", type), UtilMisc.toList("sequenceNum"));            }            // filter the list by date            productAssocs = EntityUtil.filterByDate(productAssocs, true);            // first check to see if there is a view allow category and if these producta are in it...            if (checkViewAllow && prodCatalogId != null && productAssocs != null && productAssocs.size() > 0) {                String viewProductCategoryId = CatalogWorker.getCatalogViewAllowCategoryId(delegator, prodCatalogId);                if (viewProductCategoryId != null) {                    if (productIdTo == null) {                        productAssocs = CategoryWorker.filterProductsInCategory(delegator, productAssocs, viewProductCategoryId, "productIdTo");                    } else {                        productAssocs = CategoryWorker.filterProductsInCategory(delegator, productAssocs, viewProductCategoryId, "productId");                    }                }            }            result.put("assocProducts", productAssocs);            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);        } catch (GenericEntityException e) {            Map messageMap = UtilMisc.toMap("errMessage", e.getMessage());            errMsg = UtilProperties.getMessage(resource,"productservices.problems_product_association_relation_error", messageMap, locale);            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);            result.put(ModelService.ERROR_MESSAGE, errMsg);            return result;        }        return result;    }    // Builds a product feature tree    private static Map makeGroup(GenericDelegator delegator, Map featureList, List items, List order, int index)        throws IllegalArgumentException, IllegalStateException {        //List featureKey = new ArrayList();        Map tempGroup = new HashMap();        Map group = new LinkedMap();        String orderKey = (String) order.get(index);        if (featureList == null) {            throw new IllegalArgumentException("Cannot build feature tree: featureList is null");        }        if (index < 0) {            throw new IllegalArgumentException("Invalid index '" + index + "' min index '0'");        }        if (index + 1 > order.size()) {            throw new IllegalArgumentException("Invalid index '" + index + "' max index '" + (order.size() - 1) + "'");        }        // loop through items and make the lists        Iterator itemIterator = items.iterator();        while (itemIterator.hasNext()) {            // -------------------------------            // Gather the necessary data            // -------------------------------            String thisItem = (String) itemIterator.next();            if (Debug.verboseOn()) Debug.logVerbose("ThisItem: " + thisItem, module);            List features = null;            try {                Map fields = UtilMisc.toMap("productId", thisItem, "productFeatureTypeId", orderKey,                        "productFeatureApplTypeId", "STANDARD_FEATURE");                List sort = UtilMisc.toList("sequenceNum");                // get the features and filter out expired dates                features = delegator.findByAndCache("ProductFeatureAndAppl", fields, sort);                features = EntityUtil.filterByDate(features, true);            } catch (GenericEntityException e) {                throw new IllegalStateException("Problem reading relation: " + e.getMessage());            }            if (Debug.verboseOn()) Debug.logVerbose("Features: " + features, module);            // -------------------------------            Iterator featuresIterator = features.iterator();            while (featuresIterator.hasNext()) {                GenericValue item = (GenericValue) featuresIterator.next();                Object itemKey = item.get("description");                if (tempGroup.containsKey(itemKey)) {                    List itemList = (List) tempGroup.get(itemKey);                    if (!itemList.contains(thisItem))                        itemList.add(thisItem);                } else {                    List itemList = UtilMisc.toList(thisItem);                    tempGroup.put(itemKey, itemList);                }            }        }        if (Debug.verboseOn()) Debug.logVerbose("TempGroup: " + tempGroup, module);        // Loop through the feature list and order the keys in the tempGroup        List orderFeatureList = (List) featureList.get(orderKey);        if (orderFeatureList == null) {            throw new IllegalArgumentException("Cannot build feature tree: orderFeatureList is null for orderKey=" + orderKey);        }        Iterator featureListIt = orderFeatureList.iterator();        while (featureListIt.hasNext()) {            String featureStr = (String) featureListIt.next();            if (tempGroup.containsKey(featureStr))                group.put(featureStr, tempGroup.get(featureStr));        }        if (Debug.verboseOn()) Debug.logVerbose("Group: " + group, module);        // no groups; no tree        if (group.size() == 0) {            return group;            //throw new IllegalStateException("Cannot create tree from group list; error on '" + orderKey + "'");        }        if (index + 1 == order.size()) {            return group;        }        // loop through the keysets and get the sub-groups        Iterator groupIterator = group.keySet().iterator();        while (groupIterator.hasNext()) {            Object key = groupIterator.next();            List itemList = (List) group.get(key);            if (itemList != null && itemList.size() > 0) {                Map subGroup = makeGroup(delegator, featureList, itemList, order, index + 1);                group.put(key, subGroup);            } else {                // do nothing, ie put nothing in the Map                //throw new IllegalStateException("Cannot create tree from an empty list; error on '" + key + "'");            }        }        return group;    }    // builds a variant sample (a single sku for a featureType)    private static Map makeVariantSample(GenericDelegator delegator, Map featureList, List items, String feature) {        Map tempSample = new HashMap();        Map sample = new LinkedMap();        Iterator itemIt = items.iterator();        while (itemIt.hasNext()) {            String productId = (String) itemIt.next();            List features = null;            try {                Map fields = UtilMisc.toMap("productId", productId, "productFeatureTypeId", feature,                        "productFeatureApplTypeId", "STANDARD_FEATURE");                List sort = UtilMisc.toList("sequenceNum", "description");                // get the features and filter out expired dates                features = delegator.findByAndCache("ProductFeatureAndAppl", fields, sort);                features = EntityUtil.filterByDate(features, true);            } catch (GenericEntityException e) {                throw new IllegalStateException("Problem reading relation: " + e.getMessage());            }            Iterator featureIt = features.iterator();            while (featureIt.hasNext()) {                GenericValue featureAppl = (GenericValue) featureIt.next();                try {                    GenericValue product = delegator.findByPrimaryKeyCache("Product",                            UtilMisc.toMap("productId", productId));                    tempSample.put(featureAppl.getString("description"), product);                } catch (GenericEntityException e) {                    throw new RuntimeException("Cannot get product entity: " + e.getMessage());                }            }        }        // Sort the sample based on the feature list.        List features = (LinkedList) featureList.get(feature);        Iterator fi = features.iterator();        while (fi.hasNext()) {            String f = (String) fi.next();            if (tempSample.containsKey(f))                sample.put(f, tempSample.get(f));        }        return sample;    }    public static Map quickAddVariant(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        Map result = new HashMap();        Locale locale = (Locale) context.get("locale");        String errMsg=null;        String productId = (String) context.get("productId");        String variantProductId = (String) context.get("productVariantId");        String productFeatureIds = (String) context.get("productFeatureIds");                try {            // read the product, duplicate it with the given id            GenericValue product = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId));            if (product == null) {                Map messageMap = UtilMisc.toMap("productId", productId);                errMsg = UtilProperties.getMessage(resource,"productservices.product_not_found_with_ID", messageMap, locale);                result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);                result.put(ModelService.ERROR_MESSAGE, errMsg);                return result;            }            // check if product exists            GenericValue variantProduct = delegator.findByPrimaryKey("Product",UtilMisc.toMap("productId", variantProductId));            boolean variantProductExists = (variantProduct != null);            if (variantProduct == null) {                //if product does not exist                variantProduct = GenericValue.create(product);                variantProduct.set("productId", variantProductId);                variantProduct.set("isVirtual", "N");                variantProduct.set("isVariant", "Y");                variantProduct.set("primaryProductCategoryId", null);                //create new                variantProduct.create();            } else {                //if product does exist                variantProduct.set("isVirtual", "N");                variantProduct.set("isVariant", "Y");                variantProduct.set("primaryProductCategoryId", null);                //update entry                variantProduct.store();            }            GenericValue variantProductAssoc = null;            if (variantProductExists) {                // Since the variant product is already a variant, first of all we remove the old features                // and the associations of type PRODUCT_VARIANT: a given product can be a variant of only one product.                delegator.removeByAnd("ProductAssoc", UtilMisc.toMap("productIdTo", variantProductId,                                                                     "productAssocTypeId", "PRODUCT_VARIANT"));                delegator.removeByAnd("ProductFeatureAppl", UtilMisc.toMap("productId", variantProductId,

⌨️ 快捷键说明

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