📄 bomnode.java
字号:
// ----------------------------------------------------------- // We try to apply directly the selected features if (newNode == oneChildNode) { Map selectedFeatures = new HashMap(); if (productFeatures != null) { GenericValue feature = null; for (int j = 0; j < productFeatures.size(); j++) { feature = (GenericValue)productFeatures.get(j); selectedFeatures.put((String)feature.get("productFeatureTypeId"), (String)feature.get("productFeatureId")); // FIXME } } if (selectedFeatures.size() > 0) { Map context = new HashMap(); context.put("productId", node.get("productIdTo")); context.put("selectedFeatures", selectedFeatures); Map storeResult = null; GenericValue variantProduct = null; try { storeResult = dispatcher.runSync("getProductVariant", context); List variantProducts = (List) storeResult.get("products"); if (variantProducts.size() == 1) { variantProduct = (GenericValue)variantProducts.get(0); } } catch (GenericServiceException e) { String service = e.getMessage(); if (Debug.infoOn()) Debug.logInfo("Error calling getProductVariant service", module); } if (variantProduct != null) { newNode = new BOMNode(variantProduct, dispatcher, userLogin); newNode.setTree(tree); newNode.setSubstitutedNode(oneChildNode); newNode.setQuantityMultiplier(oneChildNode.getQuantityMultiplier()); newNode.setScrapFactor(oneChildNode.getScrapFactor()); newNode.setProductAssoc(oneChildNode.getProductAssoc()); } } } // ----------------------------------------------------------- } } } } // end of if (isVirtual()) return newNode; } protected void loadParents(String partBomTypeId, Date inDate, List productFeatures) throws GenericEntityException { if (product == null) { throw new GenericEntityException("product is null"); } // If the date is null, set it to today. if (inDate == null) inDate = new Date(); bomTypeId = partBomTypeId;// GenericDelegator delegator = product.getDelegator(); List rows = delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productIdTo", product.get("productId"), "productAssocTypeId", partBomTypeId), UtilMisc.toList("sequenceNum")); rows = EntityUtil.filterByDate(rows, inDate); if ((rows == null || rows.size() == 0) && substitutedNode != null) { // If no parent is found and this is a substituted node // we try to search for substituted node's parents. rows = delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productIdTo", substitutedNode.getProduct().get("productId"), "productAssocTypeId", partBomTypeId), UtilMisc.toList("sequenceNum")); rows = EntityUtil.filterByDate(rows, inDate); } children = new ArrayList(rows); childrenNodes = new ArrayList(); Iterator childrenIterator = children.iterator(); GenericValue oneChild = null; BOMNode oneChildNode = null; while(childrenIterator.hasNext()) { oneChild = (GenericValue)childrenIterator.next(); oneChildNode = new BOMNode(oneChild.getString("productId"), delegator, dispatcher, userLogin); // Configurator //oneChildNode = configurator(oneChild, productFeatures, getRootNode().getProductForRules(), delegator); // If the node is null this means that the node has been discarded by the rules. if (oneChildNode != null) { oneChildNode.setParentNode(this); oneChildNode.setTree(tree); oneChildNode.loadParents(partBomTypeId, inDate, productFeatures); } childrenNodes.add(oneChildNode); } } /** Getter for property parentNode. * @return Value of property parentNode. * */ public BOMNode getParentNode() { return parentNode; } public BOMNode getRootNode() { return (parentNode != null? getParentNode(): this); } /** Setter for property parentNode. * @param parentNode New value of property parentNode. * */ public void setParentNode(BOMNode parentNode) { this.parentNode = parentNode; } // ------------------------------------ // Method used for TEST and DEBUG purposes public void print(StringBuffer sb, double quantity, int depth) { for (int i = 0; i < depth; i++) { sb.append("<b> * </b>"); } sb.append(product.get("productId")); sb.append(" - "); sb.append("" + quantity); GenericValue oneChild = null; BOMNode oneChildNode = null; depth++; for (int i = 0; i < children.size(); i++) { oneChild = (GenericValue)children.get(i); double bomQuantity = 0; try { bomQuantity = oneChild.getDouble("quantity").doubleValue(); } catch(Exception exc) { bomQuantity = 1; } oneChildNode = (BOMNode)childrenNodes.get(i); sb.append("<br/>"); if (oneChildNode != null) { oneChildNode.print(sb, (quantity * bomQuantity), depth); } } } public void print(ArrayList arr, double quantity, int depth, boolean excludeWIPs) { // Now we set the depth and quantity of the current node // in this breakdown. this.depth = depth; //this.quantity = Math.floor(quantity * quantityMultiplier / scrapFactor + 0.5); String serviceName = null; if (this.productAssoc != null && this.productAssoc.getString("estimateCalcMethod") != null) { try { GenericValue genericService = productAssoc.getRelatedOne("CustomMethod"); if (genericService != null && genericService.getString("customMethodName") != null) { serviceName = genericService.getString("customMethodName"); } } catch(Exception exc) { } } if (serviceName != null) { Map resultContext = null; Map arguments = UtilMisc.toMap("neededQuantity", new Double(quantity * quantityMultiplier), "amount", new Double((tree!=null? tree.getRootAmount():0))); Double width = null; if (getProduct().get("productWidth") != null) { width = getProduct().getDouble("productWidth"); } if (width == null) { width = new Double(0); } arguments.put("width", width); Map inputContext = UtilMisc.toMap("arguments", arguments, "userLogin", userLogin); try { resultContext = dispatcher.runSync(serviceName, inputContext); Double calcQuantity = (Double)resultContext.get("quantity"); if (calcQuantity != null) { this.quantity = calcQuantity.doubleValue(); } } catch (GenericServiceException e) { //Debug.logError(e, "Problem calling the getManufacturingComponents service", module); } } else { this.quantity = quantity * quantityMultiplier * scrapFactor; } // First of all we visit the current node. arr.add(this); // Now (recursively) we visit the children. GenericValue oneChild = null; BOMNode oneChildNode = null; depth++; for (int i = 0; i < children.size(); i++) { oneChild = (GenericValue)children.get(i); oneChildNode = (BOMNode)childrenNodes.get(i); if (excludeWIPs && "WIP".equals(oneChildNode.getProduct().getString("productTypeId"))) { continue; } if (oneChildNode != null) { oneChildNode.print(arr, this.quantity, depth, excludeWIPs); } } } public void getProductsInPackages(ArrayList arr, double quantity, int depth, boolean excludeWIPs) { // Now we set the depth and quantity of the current node // in this breakdown. this.depth = depth; //this.quantity = Math.floor(quantity * quantityMultiplier / scrapFactor + 0.5); this.quantity = quantity * quantityMultiplier * scrapFactor; // First of all we visit the current node. if (this.getProduct().getString("shipmentBoxTypeId") != null) { arr.add(this); } else { GenericValue oneChild = null; BOMNode oneChildNode = null; depth++; for (int i = 0; i < children.size(); i++) { oneChild = (GenericValue)children.get(i); oneChildNode = (BOMNode)childrenNodes.get(i); if (excludeWIPs && "WIP".equals(oneChildNode.getProduct().getString("productTypeId"))) { continue; } if (oneChildNode != null) { oneChildNode.getProductsInPackages(arr, this.quantity, depth, excludeWIPs); } } } } public void sumQuantity(HashMap nodes) { // First of all, we try to fetch a node with the same partId BOMNode sameNode = (BOMNode)nodes.get(product.getString("productId")); // If the node is not found we create a new node for the current product if (sameNode == null) { sameNode = new BOMNode(product, dispatcher, userLogin); nodes.put(product.getString("productId"), sameNode); } // Now we add the current quantity to the node sameNode.setQuantity(sameNode.getQuantity() + quantity); // Now (recursively) we visit the children. BOMNode oneChildNode = null; for (int i = 0; i < childrenNodes.size(); i++) { oneChildNode = (BOMNode)childrenNodes.get(i); if (oneChildNode != null) { oneChildNode.sumQuantity(nodes); } } } public String createManufacturingOrder(String orderId, String orderItemSeqId, String shipmentId, String facilityId, Date date, boolean useSubstitute) throws GenericEntityException { String productionRunId = null; if (isManufactured()) { BOMNode oneChildNode = null; ArrayList childProductionRuns = new ArrayList(); for (int i = 0; i < childrenNodes.size(); i++) { oneChildNode = (BOMNode)childrenNodes.get(i); if (oneChildNode != null) { String childProductionRunId = oneChildNode.createManufacturingOrder(null, null, shipmentId, facilityId, date, false); if (childProductionRunId != null) { childProductionRuns.add(childProductionRunId); } } } Timestamp startDate = UtilDateTime.toTimestamp(UtilDateTime.toDateTimeString(date)); Map serviceContext = new HashMap(); if (!useSubstitute) { serviceContext.put("productId", getProduct().getString("productId"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -