📄 shipmentservices.java
字号:
useQty = true; double min = 0.0001; double max = 0.0001; try { min = qv.getDouble("fromQuantity").doubleValue(); max = qv.getDouble("thruQuantity").doubleValue(); } catch (Exception e) { } if (shippableQuantity.doubleValue() >= min && (max == 0 || shippableQuantity.doubleValue() <= max)) qtyValid = true; } if (pv != null) { usePrice = true; double min = 0.0001; double max = 0.0001; try { min = pv.getDouble("fromQuantity").doubleValue(); max = pv.getDouble("thruQuantity").doubleValue(); } catch (Exception e) { } if (shippableTotal.doubleValue() >= min && (max == 0 || shippableTotal.doubleValue() <= max)) priceValid = true; } // Now check the tests. if ((useWeight && weightValid) || (useQty && qtyValid) || (usePrice && priceValid)) estimateList.add(thisEstimate); } } } if (estimateList.size() < 1) { return ServiceUtil.returnError("No shipping estimate found"); } // make the shippable item size/feature objects List shippableItemSizes = new LinkedList(); Map shippableFeatureMap = new HashMap(); if (shippableItemInfo != null) { Iterator sii = shippableItemInfo.iterator(); while (sii.hasNext()) { Map itemMap = (Map) sii.next(); // add the item sizes Double itemSize = (Double) itemMap.get("size"); if (itemSize != null) { shippableItemSizes.add(itemSize); } // add the feature quantities Double quantity = (Double) itemMap.get("quantity"); Set featureSet = (Set) itemMap.get("featureSet"); if (featureSet != null && featureSet.size() > 0) { Iterator fi = featureSet.iterator(); while (fi.hasNext()) { String featureId = (String) fi.next(); Double featureQuantity = (Double) shippableFeatureMap.get(featureId); if (featureQuantity == null) { featureQuantity = new Double(0.00); } featureQuantity = new Double(featureQuantity.doubleValue() + quantity.doubleValue()); shippableFeatureMap.put(featureId, featureQuantity); } } } } // Calculate priority based on available data. double PRIORITY_PARTY = 9; double PRIORITY_ROLE = 8; double PRIORITY_GEO = 4; double PRIORITY_WEIGHT = 1; double PRIORITY_QTY = 1; double PRIORITY_PRICE = 1; int estimateIndex = 0; if (estimateList.size() > 1) { TreeMap estimatePriority = new TreeMap(); //int estimatePriority[] = new int[estimateList.size()]; for (int x = 0; x < estimateList.size(); x++) { GenericValue currentEstimate = (GenericValue) estimateList.get(x); int prioritySum = 0; if (UtilValidate.isNotEmpty(currentEstimate.getString("partyId"))) prioritySum += PRIORITY_PARTY; if (UtilValidate.isNotEmpty(currentEstimate.getString("roleTypeId"))) prioritySum += PRIORITY_ROLE; if (UtilValidate.isNotEmpty(currentEstimate.getString("geoIdTo"))) prioritySum += PRIORITY_GEO; if (UtilValidate.isNotEmpty(currentEstimate.getString("weightBreakId"))) prioritySum += PRIORITY_WEIGHT; if (UtilValidate.isNotEmpty(currentEstimate.getString("quantityBreakId"))) prioritySum += PRIORITY_QTY; if (UtilValidate.isNotEmpty(currentEstimate.getString("priceBreakId"))) prioritySum += PRIORITY_PRICE; // there will be only one of each priority; latest will replace estimatePriority.put(new Integer(prioritySum), currentEstimate); } // locate the highest priority estimate; or the latest entered Object[] estimateArray = estimatePriority.values().toArray(); estimateIndex = estimateList.indexOf(estimateArray[estimateArray.length - 1]); } // Grab the estimate and work with it. GenericValue estimate = (GenericValue) estimateList.get(estimateIndex); //Debug.log("[ShippingEvents.getShipEstimate] Working with estimate [" + estimateIndex + "]: " + estimate, module); // flat fees double orderFlat = 0.00; if (estimate.getDouble("orderFlatPrice") != null) orderFlat = estimate.getDouble("orderFlatPrice").doubleValue(); double orderItemFlat = 0.00; if (estimate.getDouble("orderItemFlatPrice") != null) orderItemFlat = estimate.getDouble("orderItemFlatPrice").doubleValue(); double orderPercent = 0.00; if (estimate.getDouble("orderPricePercent") != null) orderPercent = estimate.getDouble("orderPricePercent").doubleValue(); double itemFlatAmount = shippableQuantity.doubleValue() * orderItemFlat; double orderPercentage = shippableTotal.doubleValue() * (orderPercent / 100); // flat total double flatTotal = orderFlat + itemFlatAmount + orderPercentage; // spans double weightUnit = 0.00; if (estimate.getDouble("weightUnitPrice") != null) weightUnit = estimate.getDouble("weightUnitPrice").doubleValue(); double qtyUnit = 0.00; if (estimate.getDouble("quantityUnitPrice") != null) qtyUnit = estimate.getDouble("quantityUnitPrice").doubleValue(); double priceUnit = 0.00; if (estimate.getDouble("priceUnitPrice") != null) priceUnit = estimate.getDouble("priceUnitPrice").doubleValue(); double weightAmount = shippableWeight.doubleValue() * weightUnit; double quantityAmount = shippableQuantity.doubleValue() * qtyUnit; double priceAmount = shippableTotal.doubleValue() * priceUnit; // span total double spanTotal = weightAmount + quantityAmount + priceAmount; // feature surcharges double featureSurcharge = 0.00; String featureGroupId = estimate.getString("productFeatureGroupId"); Double featurePercent = estimate.getDouble("featurePercent"); Double featurePrice = estimate.getDouble("featurePrice"); if (featurePercent == null) { featurePercent = new Double(0); } if (featurePrice == null) { featurePrice = new Double(0.00); } if (featureGroupId != null && featureGroupId.length() > 0 && shippableFeatureMap != null) { Iterator fii = shippableFeatureMap.keySet().iterator(); while (fii.hasNext()) { String featureId = (String) fii.next(); Double quantity = (Double) shippableFeatureMap.get(featureId); GenericValue appl = null; Map fields = UtilMisc.toMap("productFeatureGroupId", featureGroupId, "productFeatureId", featureId); try { List appls = delegator.findByAndCache("ProductFeatureGroupAppl", fields); appls = EntityUtil.filterByDate(appls); appl = EntityUtil.getFirst(appls); } catch (GenericEntityException e) { Debug.logError(e, "Unable to lookup feature/group" + fields, module); } if (appl != null) { featureSurcharge += (shippableTotal.doubleValue() * (featurePercent.doubleValue() / 100) * quantity.doubleValue()); featureSurcharge += featurePrice.doubleValue() * quantity.doubleValue(); } } } // size surcharges double sizeSurcharge = 0.00; Double sizeUnit = estimate.getDouble("oversizeUnit"); Double sizePrice = estimate.getDouble("oversizePrice"); if (sizeUnit != null && sizeUnit.doubleValue() > 0) { if (shippableItemSizes != null) { Iterator isi = shippableItemSizes.iterator(); while (isi.hasNext()) { Double size = (Double) isi.next(); if (size != null && size.doubleValue() >= sizeUnit.doubleValue()) { sizeSurcharge += sizePrice.doubleValue(); } } } } // surcharges total double surchargeTotal = featureSurcharge + sizeSurcharge; // shipping total double shippingTotal = spanTotal + flatTotal + surchargeTotal; // prepare the return result Map responseResult = ServiceUtil.returnSuccess(); responseResult.put("shippingEstimateAmount", new Double(shippingTotal)); return responseResult; } public static Map fillShipmentStagingTables(DispatchContext dctx, Map context) { GenericDelegator delegator = dctx.getDelegator(); String shipmentId = (String) context.get("shipmentId"); GenericValue shipment = null; if (shipmentId != null) { try { shipment = delegator.findByPrimaryKey("Shipment", UtilMisc.toMap("shipmentId", shipmentId)); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } } if (shipment == null) { return ServiceUtil.returnError("No shipment found!"); } String shipmentStatusId = shipment.getString("statusId"); if ("SHIPMENT_PACKED".equals(shipmentStatusId)) { GenericValue address = null; try { address = shipment.getRelatedOne("DestinationPostalAddress"); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } if (address == null) { return ServiceUtil.returnError("No address found for shipment!"); } List packages = null; try { packages = shipment.getRelated("ShipmentPackage") ; } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } if (packages == null || packages.size() == 0) { return ServiceUtil.returnError("No packages are available for shipping!"); } List routeSegs = null; try { routeSegs = shipment.getRelated("ShipmentRouteSegment"); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } GenericValue routeSeg = EntityUtil.getFirst(routeSegs); // to store list List toStore = new ArrayList(); String shipGroupSeqId = shipment.getString("primaryShipGroupSeqId"); String orderId = shipment.getString("primaryOrderId"); String orderInfoKey = orderId + "/" + shipGroupSeqId; // make the staging records GenericValue stageShip = delegator.makeValue("OdbcShipmentOut", null); stageShip.set("shipmentId", shipment.get("shipmentId")); stageShip.set("partyId", shipment.get("partyIdTo")); stageShip.set("carrierPartyId", routeSeg.get("carrierPartyId")); stageShip.set("shipmentMethodTypeId", routeSeg.get("shipmentMethodTypeId")); stageShip.set("toName", address.get("toName")); stageShip.set("attnName", address.get("attnName")); stageShip.set("address1", address.get("address1")); stageShip.set("address2", address.get("address2")); stageShip.set("directions", address.get("directions")); stageShip.set("city", address.get("city")); stageShip.set("postalCode", address.get("postalCode")); stageShip.set("postalCodeExt", address.get("postalCodeExt")); stageShip.set("countryGeoId", address.get("countryGeoId")); stageShip.set("stateProvinceGeoId", address.get("stateProvinceGeoId")); stageShip.set("numberOfPackages", new Long(packages.size())); stageShip.set("handlingInstructions", shipment.get("handlingInstructions")); toStore.add(stageShip); Iterator p = packages.iterator(); while (p.hasNext()) { GenericValue shipmentPkg = (GenericValue) p.next(); GenericValue stagePkg = delegator.makeValue("OdbcPackageOut", null); stagePkg.set("shipmentId", shipmentPkg.get("shipmentId"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -