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

📄 productservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                                                                           "productFeatureApplTypeId", "STANDARD_FEATURE"));            }            // add an association from productId to variantProductId of the PRODUCT_VARIANT            GenericValue productAssoc = delegator.makeValue("ProductAssoc",                                                            UtilMisc.toMap("productId", productId, "productIdTo", variantProductId,                                                                           "productAssocTypeId", "PRODUCT_VARIANT", "fromDate", UtilDateTime.nowTimestamp()));            productAssoc.create();            // add the selected standard features to the new product given the productFeatureIds            java.util.StringTokenizer st = new java.util.StringTokenizer(productFeatureIds, "|");            while (st.hasMoreTokens()) {                String productFeatureId = st.nextToken();                               GenericValue productFeature = delegator.findByPrimaryKey("ProductFeature", UtilMisc.toMap("productFeatureId", productFeatureId));                                GenericValue productFeatureAppl = delegator.makeValue("ProductFeatureAppl",                UtilMisc.toMap("productId", variantProductId, "productFeatureId", productFeatureId,                "productFeatureApplTypeId", "STANDARD_FEATURE", "fromDate", UtilDateTime.nowTimestamp()));                                // set the default seq num if it's there...                if (productFeature != null) {                    productFeatureAppl.set("sequenceNum", productFeature.get("defaultSequenceNum"));                }                                productFeatureAppl.create();            }                    } catch (GenericEntityException e) {            Debug.logError(e, "Entity error creating quick add variant data", module);            Map messageMap = UtilMisc.toMap("errMessage", e.toString());            errMsg = UtilProperties.getMessage(resource,"productservices.entity_error_quick_add_variant_data", messageMap, locale);            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);            result.put(ModelService.ERROR_MESSAGE, errMsg);            return result;        }        result.put("productVariantId", variantProductId);        return result;    }    /**      * This will create a virtual product and return its ID, and associate all of the variants with it.     * It will not put the selectable features on the virtual or standard features on the variant.      */    public static Map quickCreateVirtualWithVariants(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        Locale locale = (Locale) context.get("locale");        Timestamp nowTimestamp = UtilDateTime.nowTimestamp();                // get the various IN attributes        String variantProductIdsBag = (String) context.get("variantProductIdsBag");        String productFeatureIdOne = (String) context.get("productFeatureIdOne");        String productFeatureIdTwo = (String) context.get("productFeatureIdTwo");        String productFeatureIdThree = (String) context.get("productFeatureIdThree");        Map successResult = ServiceUtil.returnSuccess();                try {            // Generate new virtual productId, prefix with "VP", put in successResult            String productId = (String) context.get("productId");                        if (UtilValidate.isEmpty(productId)) {                productId = "VP" + delegator.getNextSeqId("VirtualProduct");                // Create new virtual product...                GenericValue product = delegator.makeValue("Product", null);                product.set("productId", productId);                // set: isVirtual=Y, isVariant=N, productTypeId=FINISHED_GOOD, introductionDate=now                product.set("isVirtual", "Y");                product.set("isVariant", "N");                product.set("productTypeId", "FINISHED_GOOD");                product.set("introductionDate", nowTimestamp);                // set all to Y: returnable, taxable, chargeShipping, autoCreateKeywords, includeInPromotions                product.set("returnable", "Y");                product.set("taxable", "Y");                product.set("chargeShipping", "Y");                product.set("autoCreateKeywords", "Y");                product.set("includeInPromotions", "Y");                // in it goes!                product.create();            }            successResult.put("productId", productId);                        // separate variantProductIdsBag into a Set of variantProductIds            //note: can be comma, tab, or white-space delimited            Set prelimVariantProductIds = new HashSet();            List splitIds = Arrays.asList(variantProductIdsBag.split("[,\\p{Space}]"));            Debug.logInfo("Variants: bag=" + variantProductIdsBag, module);            Debug.logInfo("Variants: split=" + splitIds, module);            prelimVariantProductIds.addAll(splitIds);            //note: should support both direct productIds and GoodIdentification entries (what to do if more than one GoodID? Add all?            Map variantProductsById = new HashMap();            Iterator variantProductIdIter = prelimVariantProductIds.iterator();            while (variantProductIdIter.hasNext()) {                String variantProductId = (String) variantProductIdIter.next();                if (UtilValidate.isEmpty(variantProductId)) {                    // not sure why this happens, but seems to from time to time with the split method                    continue;                }                // is a Product.productId?                GenericValue variantProduct = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", variantProductId));                if (variantProduct != null) {                    variantProductsById.put(variantProductId, variantProduct);                } else {                    // is a GoodIdentification.idValue?                    List goodIdentificationList = delegator.findByAnd("GoodIdentification", UtilMisc.toMap("idValue", variantProductId));                    if (goodIdentificationList == null || goodIdentificationList.size() == 0) {                        // whoops, nothing found... return error                        return ServiceUtil.returnError("Error creating a virtual with variants: the ID [" + variantProductId + "] is not a valid Product.productId or a GoodIdentification.idValue");                    }                                        if (goodIdentificationList.size() > 1) {                        // what to do here? for now just log a warning and add all of them as variants; they can always be dissociated later                        Debug.logWarning("Warning creating a virtual with variants: the ID [" + variantProductId + "] was not a productId and resulted in [" + goodIdentificationList.size() + "] GoodIdentification records: " + goodIdentificationList, module);                    }                                        Iterator goodIdentificationIter = goodIdentificationList.iterator();                    while (goodIdentificationIter.hasNext()) {                        GenericValue goodIdentification = (GenericValue) goodIdentificationIter.next();                        GenericValue giProduct = goodIdentification.getRelatedOne("Product");                        if (giProduct != null) {                            variantProductsById.put(giProduct.get("productId"), giProduct);                        }                    }                }            }            // Attach productFeatureIdOne, Two, Three to the new virtual and all variant products as a standard feature            Set featureProductIds = new HashSet();            featureProductIds.add(productId);            featureProductIds.addAll(variantProductsById.keySet());            Set productFeatureIds = new HashSet();            productFeatureIds.add(productFeatureIdOne);            productFeatureIds.add(productFeatureIdTwo);            productFeatureIds.add(productFeatureIdThree);                        Iterator featureProductIdIter = featureProductIds.iterator();            while (featureProductIdIter.hasNext()) {                Iterator productFeatureIdIter = productFeatureIds.iterator();                String featureProductId = (String) featureProductIdIter.next();                while (productFeatureIdIter.hasNext()) {                    String productFeatureId = (String) productFeatureIdIter.next();                    if (UtilValidate.isNotEmpty(productFeatureId)) {                        GenericValue productFeatureAppl = delegator.makeValue("ProductFeatureAppl",                                 UtilMisc.toMap("productId", featureProductId, "productFeatureId", productFeatureId,                                        "productFeatureApplTypeId", "STANDARD_FEATURE", "fromDate", nowTimestamp));                        productFeatureAppl.create();                    }                }            }                        Iterator variantProductIter = variantProductsById.values().iterator();            while (variantProductIter.hasNext()) {                // for each variant product set: isVirtual=N, isVariant=Y, introductionDate=now                GenericValue variantProduct = (GenericValue) variantProductIter.next();                variantProduct.set("isVirtual", "N");                variantProduct.set("isVariant", "Y");                variantProduct.set("introductionDate", nowTimestamp);                variantProduct.store();                // for each variant product create associate with the new virtual as a PRODUCT_VARIANT                GenericValue productAssoc = delegator.makeValue("ProductAssoc",                         UtilMisc.toMap("productId", productId, "productIdTo", variantProduct.get("productId"),                                "productAssocTypeId", "PRODUCT_VARIANT", "fromDate", nowTimestamp));                productAssoc.create();            }        } catch (GenericEntityException e) {            String errMsg = "Error creating new virtual product from variant products: " + e.toString();            Debug.logError(e, errMsg, module);            return ServiceUtil.returnError(errMsg);        }                return successResult;    }    public static Map updateProductIfAvailableFromShipment(DispatchContext dctx, Map context) {        if ("Y".equals(UtilProperties.getPropertyValue("catalog.properties", "reactivate.product.from.receipt", "N"))) {            LocalDispatcher dispatcher = dctx.getDispatcher();            GenericDelegator delegator = dctx.getDelegator();            GenericValue userLogin = (GenericValue) context.get("userLogin");            String inventoryItemId = (String) context.get("inventoryItemId");            GenericValue inventoryItem = null;            try {                inventoryItem = delegator.findByPrimaryKeyCache("InventoryItem", UtilMisc.toMap("inventoryItemId", inventoryItemId));            } catch (GenericEntityException e) {                Debug.logError(e, module);                return ServiceUtil.returnError(e.getMessage());            }            if (inventoryItem != null) {                String productId = inventoryItem.getString("productId");                GenericValue product = null;                try {                    product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId));                } catch (GenericEntityException e) {                    Debug.logError(e, module);                    return ServiceUtil.returnError(e.getMessage());                }                if (product != null) {                    Timestamp salesDiscontinuationDate = product.getTimestamp("salesDiscontinuationDate");                    if (salesDiscontinuationDate != null && salesDiscontinuationDate.before(UtilDateTime.nowTimestamp())) {                        Map invRes = null;                        try {                            invRes = dispatcher.runSync("getProductInventoryAvailable", UtilMisc.toMap("productId", productId, "userLogin", userLogin));                        } catch (GenericServiceException e) {                            Debug.logError(e, module);                            return ServiceUtil.returnError(e.getMessage());                        }                        Double availableToPromiseTotal = (Double) invRes.get("availableToPromiseTotal");                        if (availableToPromiseTotal != null && availableToPromiseTotal.doubleValue() > 0) {                            // refresh the product so we can update it                            GenericValue productToUpdate = null;                            try {                                productToUpdate = delegator.findByPrimaryKey("Product", product.getPrimaryKey());                            } catch (GenericEntityException e) {                                Debug.logError(e, module);                                return ServiceUtil.returnError(e.getMessage());                            }                            // set and save                            productToUpdate.set("salesDiscontinuationDate", null);                            try {                                delegator.store(productToUpdate);                            } catch (GenericEntityException e) {                                Debug.logError(e, module);                                return ServiceUtil.returnError(e.getMessage());                            }                        }                    }                }            }        }        return ServiceUtil.returnSuccess();    }}

⌨️ 快捷键说明

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