📄 bomservices.java
字号:
try { duplicatedProductAssoc = BOMHelper.searchDuplicatedAncestor(productId, productIdKey, bomType, fromDate, delegator, dispatcher, userLogin); } catch(GenericEntityException gee) { return ServiceUtil.returnError("Error running duplicated ancestor search: " + gee.getMessage()); } result.put("duplicatedProductAssoc", duplicatedProductAssoc); return result; } /** It reads the product's bill of materials, * if necessary configures it, and it returns * an object (see {@link BOMTree} * and {@link BOMNode}) that represents a * configured bill of material tree. * Useful for tree traversal (breakdown, explosion, implosion). * @param dctx * @param context * @return */ public static Map getBOMTree(DispatchContext dctx, Map context) { Map result = new HashMap(); Security security = dctx.getSecurity(); GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); GenericValue userLogin = (GenericValue)context.get("userLogin"); String productId = (String) context.get("productId"); String fromDateStr = (String) context.get("fromDate"); String bomType = (String) context.get("bomType"); Integer type = (Integer) context.get("type"); Double quantity = (Double) context.get("quantity"); Double amount = (Double) context.get("amount"); if (type == null) { type = new Integer(0); } Date fromDate = null; if (UtilValidate.isNotEmpty(fromDateStr)) { try { fromDate = Timestamp.valueOf(fromDateStr); } catch (Exception e) { } } if (fromDate == null) { fromDate = new Date(); } BOMTree tree = null; try { tree = new BOMTree(productId, bomType, fromDate, type.intValue(), delegator, dispatcher, userLogin); } catch(GenericEntityException gee) { return ServiceUtil.returnError("Error creating bill of materials tree: " + gee.getMessage()); } if (tree != null && quantity != null) { tree.setRootQuantity(quantity.doubleValue()); } if (tree != null && amount != null) { tree.setRootAmount(amount.doubleValue()); } result.put("tree", tree); 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 getManufacturingComponents(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"); Double amount = (Double) context.get("amount"); String fromDateStr = (String) context.get("fromDate"); Boolean excludeWIPs = (Boolean) context.get("excludeWIPs"); if (quantity == null) { quantity = new Double(1); } if (amount == null) { amount = new Double(0); } Date fromDate = null; if (UtilValidate.isNotEmpty(fromDateStr)) { try { fromDate = Timestamp.valueOf(fromDateStr); } catch (Exception e) { } } if (fromDate == null) { fromDate = new Date(); } if (excludeWIPs == null) { excludeWIPs = new Boolean(true); } // // Components // BOMTree tree = null; ArrayList components = new ArrayList(); try { tree = new BOMTree(productId, "MANUF_COMPONENT", fromDate, BOMTree.EXPLOSION_SINGLE_LEVEL, delegator, dispatcher, userLogin); tree.setRootQuantity(quantity.doubleValue()); tree.setRootAmount(amount.doubleValue()); tree.print(components, excludeWIPs.booleanValue()); if (components.size() > 0) components.remove(0); } catch(GenericEntityException gee) { return ServiceUtil.returnError("Error creating bill of materials tree: " + gee.getMessage()); } // // Product routing // String workEffortId = null; try { Map routingInMap = UtilMisc.toMap("productId", productId, "ignoreDefaultRouting", "Y", "userLogin", userLogin); Map routingOutMap = dispatcher.runSync("getProductRouting", routingInMap); GenericValue routing = (GenericValue)routingOutMap.get("routing"); if (routing == null) { // try to find a routing linked to the virtual product routingInMap = UtilMisc.toMap("productId", tree.getRoot().getProduct().getString("productId"), "userLogin", userLogin); routingOutMap = dispatcher.runSync("getProductRouting", routingInMap); routing = (GenericValue)routingOutMap.get("routing"); } if (routing != null) { workEffortId = routing.getString("workEffortId"); } } catch(GenericServiceException gse) { Debug.logWarning(gse.getMessage(), module); } if (workEffortId != null) { result.put("workEffortId", workEffortId); } result.put("components", components); // also return a componentMap (useful in scripts and simple language code) List componentsMap = new ArrayList(); Iterator componentsIt = components.iterator(); while (componentsIt.hasNext()) { Map componentMap = new HashMap(); BOMNode node = (BOMNode)componentsIt.next(); componentMap.put("product", node.getProduct()); componentMap.put("quantity", new Double(node.getQuantity())); componentsMap.add(componentMap); } result.put("componentsMap", componentsMap); return result; } public static Map getNotAssembledComponents(DispatchContext dctx, Map context) { Map result = new HashMap(); Security security = dctx.getSecurity(); GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); String productId = (String) context.get("productId"); Double quantity = (Double) context.get("quantity"); Double amount = (Double) context.get("amount"); String fromDateStr = (String) context.get("fromDate"); GenericValue userLogin = (GenericValue)context.get("userLogin"); if (quantity == null) { quantity = new Double(1); } if (amount == null) { amount = new Double(0); } Date fromDate = null; if (UtilValidate.isNotEmpty(fromDateStr)) { try { fromDate = Timestamp.valueOf(fromDateStr); } catch (Exception e) { } } if (fromDate == null) { fromDate = new Date(); } BOMTree tree = null; ArrayList components = new ArrayList(); ArrayList notAssembledComponents = new ArrayList(); try { tree = new BOMTree(productId, "MANUF_COMPONENT", fromDate, BOMTree.EXPLOSION_MANUFACTURING, delegator, dispatcher, userLogin); tree.setRootQuantity(quantity.doubleValue()); tree.setRootAmount(amount.doubleValue()); tree.print(components); } catch(GenericEntityException gee) { return ServiceUtil.returnError("Error creating bill of materials tree: " + gee.getMessage()); } Iterator componentsIt = components.iterator(); while (componentsIt.hasNext()) { BOMNode oneComponent = (BOMNode)componentsIt.next(); if (!oneComponent.isManufactured()) { notAssembledComponents.add(oneComponent); } } result.put("notAssembledComponents" , notAssembledComponents); return result; } // --------------------------------------------- // Service for the Product (Shipment) component // public static Map createShipmentPackages(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 shipmentId = (String) context.get("shipmentId"); try { List packages = delegator.findByAnd("ShipmentPackage", UtilMisc.toMap("shipmentId", shipmentId)); if (!UtilValidate.isEmpty(packages)) { return ServiceUtil.returnError("Packages already found."); } } catch(GenericEntityException gee) { return ServiceUtil.returnError("Error loading the ShipmentPackages"); } // ShipmentItems are loaded List shipmentItems = null; try { shipmentItems = delegator.findByAnd("ShipmentItem", UtilMisc.toMap("shipmentId", shipmentId)); } catch(GenericEntityException gee) { return ServiceUtil.returnError("Error loading the ShipmentItems"); } Iterator shipmentItemsIt = shipmentItems.iterator(); HashMap orderReadHelpers = new HashMap(); HashMap partyOrderShipments = new HashMap(); while (shipmentItemsIt.hasNext()) { GenericValue shipmentItem = (GenericValue)shipmentItemsIt.next(); // Get the OrderShipments List orderShipments = null; try { orderShipments = delegator.findByAnd("OrderShipment", UtilMisc.toMap("shipmentId", shipmentId, "shipmentItemSeqId", shipmentItem.getString("shipmentItemSeqId"))); } catch (GenericEntityException e) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingPackageConfiguratorError", locale)); } GenericValue orderShipment = org.ofbiz.entity.util.EntityUtil.getFirst(orderShipments); if (orderShipment != null && !orderReadHelpers.containsKey(orderShipment.getString("orderId"))) { orderReadHelpers.put(orderShipment.getString("orderId"), new OrderReadHelper(delegator, orderShipment.getString("orderId"))); } OrderReadHelper orderReadHelper = (OrderReadHelper)orderReadHelpers.get(orderShipment.getString("orderId")); if (orderReadHelper != null) { Map orderShipmentReadMap = UtilMisc.toMap("orderShipment", orderShipment, "orderReadHelper", orderReadHelper); String partyId = (orderReadHelper.getPlacingParty() != null? orderReadHelper.getPlacingParty().getString("partyId"): null); // FIXME: is it the customer? if (partyId != null) { if (!partyOrderShipments.containsKey(partyId)) { ArrayList orderShipmentReadMapList = new ArrayList(); partyOrderShipments.put(partyId, orderShipmentReadMapList); } ArrayList orderShipmentReadMapList = (ArrayList)partyOrderShipments.get(partyId); orderShipmentReadMapList.add(orderShipmentReadMap); } } } // For each party: try to expand the shipment item products // (search for components that needs to be packaged).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -