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

📄 bomservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        Iterator partyOrderShipmentsIt = partyOrderShipments.entrySet().iterator();        while (partyOrderShipmentsIt.hasNext()) {            Map.Entry partyOrderShipment = (Map.Entry)partyOrderShipmentsIt.next();            String partyId = (String)partyOrderShipment.getKey();            List orderShipmentReadMapList = (List)partyOrderShipment.getValue();            for (int i = 0; i < orderShipmentReadMapList.size(); i++) {                Map orderShipmentReadMap = (Map)orderShipmentReadMapList.get(i);                GenericValue orderShipment = (GenericValue)orderShipmentReadMap.get("orderShipment");                OrderReadHelper orderReadHelper = (OrderReadHelper)orderShipmentReadMap.get("orderReadHelper");                GenericValue orderItem = orderReadHelper.getOrderItem(orderShipment.getString("orderItemSeqId"));                // getProductsInPackages                Map serviceContext = new HashMap();                serviceContext.put("productId", orderItem.getString("productId"));                serviceContext.put("quantity", orderShipment.getDouble("quantity"));                Map resultService = null;                try {                    resultService = dispatcher.runSync("getProductsInPackages", serviceContext);                } catch (GenericServiceException e) {                    return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingPackageConfiguratorError", locale));                }                List productsInPackages = (List)resultService.get("productsInPackages");                if (productsInPackages.size() == 1) {                    BOMNode root = (BOMNode)productsInPackages.get(0);                    String rootProductId = (root.getSubstitutedNode() != null? root.getSubstitutedNode().getProduct().getString("productId"): root.getProduct().getString("productId"));                    if (orderItem.getString("productId").equals(rootProductId)) {                        productsInPackages = null;                    }                }                if (productsInPackages != null && productsInPackages.size() == 0) {                    productsInPackages = null;                }                if (productsInPackages != null && productsInPackages.size() > 0) {                    orderShipmentReadMap.put("productsInPackages", productsInPackages);                }            }        }        // Group together products and components        // of the same box type.        HashMap boxTypes = new HashMap();        partyOrderShipmentsIt = partyOrderShipments.entrySet().iterator();        while (partyOrderShipmentsIt.hasNext()) {            HashMap boxTypeContent = new HashMap();            Map.Entry partyOrderShipment = (Map.Entry)partyOrderShipmentsIt.next();            String partyId = (String)partyOrderShipment.getKey();            List orderShipmentReadMapList = (List)partyOrderShipment.getValue();            for (int i = 0; i < orderShipmentReadMapList.size(); i++) {                Map orderShipmentReadMap = (Map)orderShipmentReadMapList.get(i);                GenericValue orderShipment = (GenericValue)orderShipmentReadMap.get("orderShipment");                OrderReadHelper orderReadHelper = (OrderReadHelper)orderShipmentReadMap.get("orderReadHelper");                List productsInPackages = (List)orderShipmentReadMap.get("productsInPackages");                if (productsInPackages != null) {                    // there are subcomponents:                    // this is a multi package shipment item                    for (int j = 0; j < productsInPackages.size(); j++) {                        BOMNode component = (BOMNode)productsInPackages.get(j);                        HashMap boxTypeContentMap = new HashMap();                        boxTypeContentMap.put("content", orderShipmentReadMap);                        boxTypeContentMap.put("componentIndex", new Integer(j));                        GenericValue product = component.getProduct();                        String boxTypeId = product.getString("shipmentBoxTypeId");                        if (boxTypeId != null) {                            if (!boxTypes.containsKey(boxTypeId)) {                                GenericValue boxType = null;                                try {                                    boxType = delegator.findByPrimaryKey("ShipmentBoxType", UtilMisc.toMap("shipmentBoxTypeId", boxTypeId));                                } catch (GenericEntityException e) {                                    return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingPackageConfiguratorError", locale));                                }                                boxTypes.put(boxTypeId, boxType);                                boxTypeContent.put(boxTypeId, new ArrayList());                            }                            GenericValue boxType = (GenericValue)boxTypes.get(boxTypeId);                            List boxTypeContentList = (List)boxTypeContent.get(boxTypeId);                            boxTypeContentList.add(boxTypeContentMap);                        }                    }                } else {                    // no subcomponents, the product has its own package:                    // this is a single package shipment item                    HashMap boxTypeContentMap = new HashMap();                    boxTypeContentMap.put("content", orderShipmentReadMap);                    GenericValue orderItem = orderReadHelper.getOrderItem(orderShipment.getString("orderItemSeqId"));                    GenericValue product = null;                    try {                        product = orderItem.getRelatedOne("Product");                    } catch (GenericEntityException e) {                        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingPackageConfiguratorError", locale));                    }                    String boxTypeId = product.getString("shipmentBoxTypeId");                    if (boxTypeId != null) {                        if (!boxTypes.containsKey(boxTypeId)) {                            GenericValue boxType = null;                            try {                                boxType = delegator.findByPrimaryKey("ShipmentBoxType", UtilMisc.toMap("shipmentBoxTypeId", boxTypeId));                            } catch (GenericEntityException e) {                                return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingPackageConfiguratorError", locale));                            }                            boxTypes.put(boxTypeId, boxType);                            boxTypeContent.put(boxTypeId, new ArrayList());                        }                        GenericValue boxType = (GenericValue)boxTypes.get(boxTypeId);                        List boxTypeContentList = (List)boxTypeContent.get(boxTypeId);                        boxTypeContentList.add(boxTypeContentMap);                    }                }            }            // The packages and package contents are created.            Iterator boxTypeContentIt = boxTypeContent.entrySet().iterator();            while (boxTypeContentIt.hasNext()) {                Map.Entry boxTypeContentEntry = (Map.Entry)boxTypeContentIt.next();                String boxTypeId = (String)boxTypeContentEntry.getKey();                List contentList = (List)boxTypeContentEntry.getValue();                GenericValue boxType = (GenericValue)boxTypes.get(boxTypeId);                Double boxWidth = boxType.getDouble("boxLength");                double totalWidth = 0;                double boxWidthDbl = 0;                if (boxWidth != null) {                    boxWidthDbl = boxWidth.doubleValue();                }                String shipmentPackageSeqId = null;                for (int i = 0; i < contentList.size(); i++) {                    Map contentMap = (Map)contentList.get(i);                    Map content = (Map)contentMap.get("content");                    OrderReadHelper orderReadHelper = (OrderReadHelper)content.get("orderReadHelper");                    List productsInPackages = (List)content.get("productsInPackages");                    GenericValue orderShipment = (GenericValue)content.get("orderShipment");                    GenericValue product = null;                    double quantity = 0;                    boolean subProduct = contentMap.containsKey("componentIndex");                    if (subProduct) {                        // multi package                        Integer index = (Integer)contentMap.get("componentIndex");                        BOMNode component = (BOMNode)productsInPackages.get(index.intValue());                        product = component.getProduct();                        quantity = component.getQuantity();                    } else {                        // single package                        GenericValue orderItem = orderReadHelper.getOrderItem(orderShipment.getString("orderItemSeqId"));                        try {                            product = orderItem.getRelatedOne("Product");                        } catch (GenericEntityException e) {                            return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingPackageConfiguratorError", locale));                        }                        quantity = orderShipment.getDouble("quantity").doubleValue();                    }                    Double productDepth = product.getDouble("shippingDepth");                    if (productDepth == null) {                        productDepth = product.getDouble("productDepth");                    }                    double productDepthDbl = 1;                    if (productDepth != null) {                        productDepthDbl = productDepth.doubleValue();                    }                                        int firstMaxNumOfProducts = (int)((boxWidthDbl - totalWidth) / productDepthDbl);                    if (firstMaxNumOfProducts == 0) firstMaxNumOfProducts = 1;                    //                     int maxNumOfProducts = (int)(boxWidthDbl / productDepthDbl);                    if (maxNumOfProducts == 0) maxNumOfProducts = 1;                    double remQuantity = quantity;                    boolean isFirst = true;                    while (remQuantity > 0) {                        int maxQuantity = 0;                        if (isFirst) {                            maxQuantity = firstMaxNumOfProducts;                            isFirst = false;                        } else {                            maxQuantity = maxNumOfProducts;                        }                        double qty = (remQuantity < maxQuantity? remQuantity: maxQuantity);                        // If needed, create the package                        if (shipmentPackageSeqId == null) {                            try {                                Map resultService = dispatcher.runSync("createShipmentPackage", UtilMisc.toMap("shipmentId", orderShipment.getString("shipmentId"), "shipmentBoxTypeId", boxTypeId, "userLogin", userLogin));                                shipmentPackageSeqId = (String)resultService.get("shipmentPackageSeqId");                            } catch (GenericServiceException e) {                                return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingPackageConfiguratorError", locale));                            }                            totalWidth = 0;                        }                        try {                            Map inputMap = null;                            if (subProduct) {                                inputMap = UtilMisc.toMap("shipmentId", orderShipment.getString("shipmentId"),                                "shipmentPackageSeqId", shipmentPackageSeqId,                                "shipmentItemSeqId", orderShipment.getString("shipmentItemSeqId"),                                "subProductId", product.getString("productId"),                                "userLogin", userLogin,                                "subProductQuantity", new Double(qty));                            } else {                                inputMap = UtilMisc.toMap("shipmentId", orderShipment.getString("shipmentId"),                                "shipmentPackageSeqId", shipmentPackageSeqId,                                "shipmentItemSeqId", orderShipment.getString("shipmentItemSeqId"),                                "userLogin", userLogin,                                "quantity", new Double(qty));                            }                            Map resultService = dispatcher.runSync("createShipmentPackageContent", inputMap);                        } catch (GenericServiceException e) {                            return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingPackageConfiguratorError", locale));                        }                        totalWidth += qty * productDepthDbl;                        if (qty == maxQuantity) shipmentPackageSeqId = null;                        remQuantity = remQuantity - qty;                    }                }            }        }        return result;    }    /** It reads the product's bill of materials,     * if necessary configures it, and it returns its (possibly configured) components in     * a List of {@link BOMNode}).     * @param dctx     * @param context     * @return     */        public static Map getProductsInPackages(DispatchContext dctx, Map context) {        Map result = new HashMap();        Security security = dctx.getSecurity();        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        Locale locale = (Locale) context.get("locale");        GenericValue userLogin = (GenericValue)context.get("userLogin");                String productId = (String) context.get("productId");        Double quantity = (Double) context.get("quantity");        String fromDateStr = (String) context.get("fromDate");                if (quantity == null) {            quantity = new Double(1);        }        Date fromDate = null;        if (UtilValidate.isNotEmpty(fromDateStr)) {            try {                fromDate = Timestamp.valueOf(fromDateStr);            } catch (Exception e) {            }        }        if (fromDate == null) {            fromDate = new Date();        }               //        // Components        //        BOMTree tree = null;        ArrayList components = new ArrayList();        try {            tree = new BOMTree(productId, "MANUF_COMPONENT", fromDate, BOMTree.EXPLOSION_MANUFACTURING, delegator, dispatcher, userLogin);            tree.setRootQuantity(quantity.doubleValue());            tree.getProductsInPackages(components);        } catch(GenericEntityException gee) {            return ServiceUtil.returnError("Error creating bill of materials tree: " + gee.getMessage());        }                result.put("productsInPackages", components);        return result;    }}

⌨️ 快捷键说明

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