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

📄 shipmentservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                stagePkg.set("shipmentPackageSeqId", shipmentPkg.get("shipmentPackageSeqId"));                stagePkg.set("orderId", shipment.get("primaryOrderId"));                stagePkg.set("shipGroupSeqId", shipment.get("primaryShipGroupSeqId"));                stagePkg.set("shipmentBoxTypeId", shipmentPkg.get("shipmentBoxTypeId"));                stagePkg.set("weight", shipmentPkg.get("weight"));                toStore.add(stagePkg);            }            try {                delegator.storeAll(toStore);            } catch (GenericEntityException e) {                Debug.logError(e, module);                return ServiceUtil.returnError(e.getMessage());            }        } else {            Debug.logWarning("Shipment #" + shipmentId + " is not available for shipment; not setting in staging tables.", module);        }        return ServiceUtil.returnSuccess();    }    public static Map updateShipmentsFromStaging(DispatchContext dctx, Map context) {        LocalDispatcher dispatcher = dctx.getDispatcher();        GenericDelegator delegator = dctx.getDelegator();        GenericValue userLogin = (GenericValue) context.get("userLogin");        List orderBy = UtilMisc.toList("shipmentId", "shipmentPackageSeqId", "voidIndicator");        Map shipmentMap = FastMap.newInstance();        EntityListIterator eli = null;        try {            eli = delegator.findListIteratorByCondition("OdbcPackageIn", null, null, orderBy);            GenericValue pkgInfo;            while ((pkgInfo = (GenericValue) eli.next()) != null) {                String packageSeqId = pkgInfo.getString("shipmentPackageSeqId");                String shipmentId = pkgInfo.getString("shipmentId");                // locate the shipment package                GenericValue shipmentPackage = delegator.findByPrimaryKey("ShipmentPackage",                        UtilMisc.toMap("shipmentId", shipmentId, "shipmentPackageSeqId", packageSeqId));                if (shipmentPackage != null) {                    if ("00001".equals(packageSeqId)) {                        // only need to do this for the first package                        GenericValue rtSeg = null;                        try {                            rtSeg = delegator.findByPrimaryKey("ShipmentRouteSegment", UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", "00001"));                        } catch (GenericEntityException e) {                            Debug.logError(e, module);                            return ServiceUtil.returnError(e.getMessage());                        }                        if (rtSeg == null) {                            rtSeg = delegator.makeValue("ShipmentRouteSegment", UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", "00001"));                            try {                                delegator.create(rtSeg);                            } catch (GenericEntityException e) {                                Debug.logError(e, module);                                return ServiceUtil.returnError(e.getMessage());                            }                        }                        rtSeg.set("actualStartDate", pkgInfo.get("shippedDate"));                        rtSeg.set("billingWeight", pkgInfo.get("billingWeight"));                        rtSeg.set("actualCost", pkgInfo.get("shippingTotal"));                        rtSeg.set("trackingIdNumber", pkgInfo.get("trackingNumber"));                        try {                            delegator.store(rtSeg);                        } catch (GenericEntityException e) {                            Debug.logError(e, module);                            return ServiceUtil.returnError(e.getMessage());                        }                    }                    Map pkgCtx = FastMap.newInstance();                    pkgCtx.put("shipmentId", shipmentId);                    pkgCtx.put("shipmentPackageSeqId", packageSeqId);                    // first update the weight of the package                    GenericValue pkg = null;                    try {                        pkg = delegator.findByPrimaryKey("ShipmentPackage", pkgCtx);                    } catch (GenericEntityException e) {                        Debug.logError(e, module);                        return ServiceUtil.returnError(e.getMessage());                    }                    if (pkg == null) {                        return ServiceUtil.returnError("Package not found! - " + pkgCtx);                    }                    pkg.set("weight", pkgInfo.get("packageWeight"));                    try {                        delegator.store(pkg);                    } catch (GenericEntityException e) {                        Debug.logError(e, module);                        return ServiceUtil.returnError(e.getMessage());                    }                    // need if we are the first package (only) update the route seg info                    pkgCtx.put("shipmentRouteSegmentId", "00001");                    GenericValue pkgRtSeg = null;                    try {                        pkgRtSeg = delegator.findByPrimaryKey("ShipmentPackageRouteSeg", pkgCtx);                    } catch (GenericEntityException e) {                        Debug.logError(e, module);                        return ServiceUtil.returnError(e.getMessage());                    }                    if (pkgRtSeg == null) {                        pkgRtSeg = delegator.makeValue("ShipmentPackageRouteSeg", pkgCtx);                        try {                            delegator.create(pkgRtSeg);                        } catch (GenericEntityException e) {                            Debug.logError(e, module);                            return ServiceUtil.returnError(e.getMessage());                        }                    }                    pkgRtSeg.set("trackingCode", pkgInfo.get("trackingNumber"));                    pkgRtSeg.set("boxNumber", pkgInfo.get("shipmentPackageSeqId"));                    pkgRtSeg.set("packageServiceCost", pkgInfo.get("packageTotal"));                    try {                        delegator.store(pkgRtSeg);                    } catch (GenericEntityException e) {                        Debug.logError(e, module);                        return ServiceUtil.returnError(e.getMessage());                    }                    shipmentMap.put(shipmentId, pkgInfo.get("voidIndicator"));                }            }        } catch (GenericEntityException e) {            Debug.logError(e, module);            return ServiceUtil.returnError(e.getMessage());        } finally {            if (eli != null) {                try {                    eli.close();                } catch (GenericEntityException e) {                    Debug.logError(e, module);                }            }        }        // update the status of each shipment        Iterator i = shipmentMap.keySet().iterator();        while (i.hasNext()) {            String shipmentId = (String) i.next();            String voidInd = (String) shipmentMap.get(shipmentId);            Map shipCtx = FastMap.newInstance();            shipCtx.put("shipmentId", shipmentId);            if ("Y".equals(voidInd)) {                shipCtx.put("statusId", "SHIPMENT_CANCELLED");            } else {                shipCtx.put("statusId", "SHIPMENT_SHIPPED");            }            shipCtx.put("userLogin", userLogin);            Map shipResp = null;            try {                shipResp = dispatcher.runSync("updateShipment", shipCtx);            } catch (GenericServiceException e) {                Debug.logError(e, module);                return ServiceUtil.returnError(e.getMessage());            }            if (ServiceUtil.isError(shipResp)) {                return ServiceUtil.returnError(ServiceUtil.getErrorMessage(shipResp));            }            // remove the shipment info            Map clearResp = null;            try {                clearResp = dispatcher.runSync("clearShipmentStaging", UtilMisc.toMap("shipmentId", shipmentId, "userLogin", userLogin));            } catch (GenericServiceException e) {                Debug.logError(e, module);                return ServiceUtil.returnError(e.getMessage());            }            if (ServiceUtil.isError(clearResp)) {                return ServiceUtil.returnError(ServiceUtil.getErrorMessage(clearResp));            }        }        return ServiceUtil.returnSuccess();    }    public static Map clearShipmentStagingInfo(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        String shipmentId = (String) context.get("shipmentId");        try {            delegator.removeByAnd("OdbcPackageIn", UtilMisc.toMap("shipmentId", shipmentId));            delegator.removeByAnd("OdbcPackageOut", UtilMisc.toMap("shipmentId", shipmentId));            delegator.removeByAnd("OdbcShipmentOut", UtilMisc.toMap("shipmentId", shipmentId));        } catch (GenericEntityException e) {            Debug.logError(e, module);            return ServiceUtil.returnError(e.getMessage());        }        return ServiceUtil.returnSuccess();    }    /**     * Whenever a ShipmentReceipt is generated, check the Shipment associated     * with it to see if all items were received. If so, change its status to     * PURCH_SHIP_RECEIVED. The check is accomplished by counting the      * products shipped (from ShipmentAndItem) and matching them with the      * products received (from ShipmentReceipt).     */    public static Map updatePurchaseShipmentFromReceipt(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        String shipmentId = (String) context.get("shipmentId");        GenericValue userLogin = (GenericValue) context.get("userLogin");        try {            List shipmentAndItems = delegator.findByAnd("ShipmentAndItem", UtilMisc.toMap("shipmentId", shipmentId, "statusId", "PURCH_SHIP_SHIPPED"));            if (shipmentAndItems.size() == 0) return ServiceUtil.returnSuccess();            List shipmentReceipts = delegator.findByAnd("ShipmentReceipt", UtilMisc.toMap("shipmentId", shipmentId));            if (shipmentReceipts.size() == 0) return ServiceUtil.returnSuccess();            // store the quanitity of each product shipped in a hashmap keyed to productId            Map shippedCountMap = new HashMap();            Iterator iter = shipmentAndItems.iterator();            while (iter.hasNext()) {                GenericValue item = (GenericValue) iter.next();                double shippedQuantity = item.getDouble("quantity").doubleValue();                Double quantity = (Double) shippedCountMap.get(item.getString("productId"));                quantity = new Double(quantity == null ? shippedQuantity : shippedQuantity + quantity.doubleValue());                shippedCountMap.put(item.getString("productId"), quantity);            }            // store the quanitity of each product received in a hashmap keyed to productId            Map receivedCountMap = new HashMap();            iter = shipmentReceipts.iterator();            while (iter.hasNext()) {                GenericValue item = (GenericValue) iter.next();                double receivedQuantity = item.getDouble("quantityAccepted").doubleValue();                Double quantity = (Double) receivedCountMap.get(item.getString("productId"));                quantity = new Double(quantity == null ? receivedQuantity : receivedQuantity + quantity.doubleValue());                receivedCountMap.put(item.getString("productId"), quantity);            }            // let Map.equals do all the hard comparison work            if (!shippedCountMap.equals(receivedCountMap)) {                return ServiceUtil.returnSuccess();            }            // now update the shipment            dispatcher.runSync("updateShipment", UtilMisc.toMap("shipmentId", shipmentId, "statusId", "PURCH_SHIP_RECEIVED", "userLogin", userLogin));        } catch (GenericEntityException e) {            Debug.logError(e, module);            return ServiceUtil.returnError(e.getMessage());        } catch (GenericServiceException se) {            Debug.logError(se, module);            return ServiceUtil.returnError(se.getMessage());        }        return ServiceUtil.returnSuccess("Intentional error at end to keep from committing.");    }    /**     * Service to call a ShipmentRouteSegment.carrierPartyId's confirm shipment method asynchronously     */    public static Map quickScheduleShipmentRouteSegment(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        GenericValue userLogin = (GenericValue) context.get("userLogin");        String shipmentId = (String) context.get("shipmentId");        String shipmentRouteSegmentId = (String) context.get("shipmentRouteSegmentId");        String carrierPartyId = null;        // get the carrierPartyId        try {            GenericValue shipmentRouteSegment = shipmentRouteSegment = delegator.findByPrimaryKeyCache("ShipmentRouteSegment",                     UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId));            carrierPartyId = shipmentRouteSegment.getString("carrierPartyId");        } catch (GenericEntityException e) {            Debug.logError(e, module);            return ServiceUtil.returnError(e.getMessage());        }        // get the shipment label.  This is carrier specific.        // TODO: This may not need to be done asynchronously.  The reason it's done that way right now is that calling it synchronously means that        // if we can't confirm a single shipment, then all shipment route segments in a multi-form are rolled back.        try {            Map input = UtilMisc.toMap("shipmentId", shipmentId, "shipmentRouteSegmentId", shipmentRouteSegmentId, "userLogin", userLogin);            // for DHL, we just need to confirm the shipment to get the label.  Other carriers may have more elaborate requirements.            if (carrierPartyId.equals("DHL")) {                dispatcher.runAsync("dhlShipmentConfirm", input);            } else {                Debug.logError(carrierPartyId + " is not supported at this time.  Sorry.", module);            }        } catch (GenericServiceException se) {            Debug.logError(se, se.getMessage(), module);        }        // don't return an error        return ServiceUtil.returnSuccess();    }}

⌨️ 快捷键说明

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