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

📄 orderchangehelper.java

📁 国外的一套开源CRM
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                            product = orderItem.getRelatedOne("Product");
                        } catch (GenericEntityException e) {
                            Debug.logError(e, "ERROR: Unable to get Product record for OrderItem : " + orderId + "/" + orderItemSeqId, module);
                        }
                        if (product != null) {
                            String productType = product.getString("productTypeId");
                            if ("DIGITAL_GOOD".equals(productType) || "FINDIG_GOOD".equals(productType)) {
                                // update the status
                                Map digitalStatusFields = UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItemSeqId, "statusId", digitalItemStatus, "userLogin", userLogin);
                                Map digitalStatusChange = dispatcher.runSync("changeOrderItemStatus", digitalStatusFields);
                                if (ModelService.RESPOND_ERROR.equals(digitalStatusChange.get(ModelService.RESPONSE_MESSAGE))) {
                                    Debug.logError("Problems with digital product status change : " + product, module);
                                }
                            }
                        }
                    }
                }
            }
        }
    } 
    
    public static void cancelInventoryReservations(LocalDispatcher dispatcher, GenericValue userLogin, String orderId) throws GenericServiceException {
        // cancel the inventory reservations
        Map cancelInvFields = UtilMisc.toMap("orderId", orderId, "userLogin", userLogin);
        Map cancelInvResult = dispatcher.runSync("cancelOrderInventoryReservation", cancelInvFields);
        if (ModelService.RESPOND_ERROR.equals(cancelInvResult.get(ModelService.RESPONSE_MESSAGE))) {
            Debug.logError("Problems reversing inventory reservations for order #" + orderId, module);
        }                         
    }

    public static void releasePaymentAuthorizations(LocalDispatcher dispatcher, GenericValue userLogin, String orderId) throws GenericServiceException {
        Map releaseFields = UtilMisc.toMap("orderId", orderId, "userLogin", userLogin);
        Map releaseResult = dispatcher.runSync("releaseOrderPayments", releaseFields);
        if (ModelService.RESPOND_ERROR.equals(releaseResult.get(ModelService.RESPONSE_MESSAGE))) {
            Debug.logError("Problems releasing payment authorizations for order #" + orderId, module);
        }
    }

    public static GenericValue createPaymentFromPreference(GenericValue orderPaymentPreference, String paymentRefNumber, String paymentFromId, String comments) {
        GenericDelegator delegator = orderPaymentPreference.getDelegator();
        
        // get the order header
        GenericValue orderHeader = null;
        try {
            orderHeader = orderPaymentPreference.getRelatedOne("OrderHeader");
        } catch (GenericEntityException e) {
            Debug.logError(e, "Cannot get OrderHeader from payment preference", module);
        }
        
        // get the store for the order
        GenericValue productStore = null;        
        if (orderHeader != null) {
            try {                
                productStore = delegator.findByPrimaryKey("ProductStore", UtilMisc.toMap("productStoreId", orderHeader.getString("productStoreId")));                                                   
            } catch (GenericEntityException e) {
                Debug.logError(e, "Cannot get the ProductStore for the order header", module);
            }
        } else {
            Debug.logWarning("No order header, cannot create payment", module);
            return null;
        }
        
        if (productStore == null) {
            Debug.logWarning("No product store, cannot create payment", module);
            return null;
        }
        
        // set the payToPartyId       
        String payToPartyId = productStore.getString("payToPartyId");
        if (payToPartyId == null) {
            Debug.logWarning("No payToPartyId set on ProductStore : " + productStore.getString("productStoreId"), module);
            return null;
        }
        
        // create the payment
        Long payId = delegator.getNextSeqId("Payment");
        GenericValue payment = delegator.makeValue("Payment", UtilMisc.toMap("paymentId", payId.toString()));
        payment.set("paymentTypeId", "RECEIPT");
        payment.set("paymentMethodTypeId", orderPaymentPreference.getString("paymentMethodTypeId"));
        payment.set("paymentPreferenceId", orderPaymentPreference.getString("orderPaymentPreferenceId"));
        payment.set("amount", orderPaymentPreference.getDouble("maxAmount"));
        payment.set("statusId", "PMNT_RECEIVED");
        payment.set("effectiveDate", UtilDateTime.nowTimestamp());        
        payment.set("partyIdTo", payToPartyId); 
        if (paymentRefNumber != null) { 
            payment.set("paymentRefNum", paymentRefNumber);
        }
        if (paymentFromId != null) {
            payment.set("partyIdFrom", paymentFromId);
        } else {
            payment.set("partyIdFrom", "_NA_"); 
        }
        if (comments != null) {
            payment.set("comments", comments);        
        }        
             
        return payment;
    }

    public static boolean releaseInitialOrderHold(LocalDispatcher dispatcher, String orderId) {
        // get the delegator from the dispatcher
        GenericDelegator delegator = dispatcher.getDelegator();
        
        // find the workEffortId for this order
        List workEfforts = null;
        try {
            workEfforts = delegator.findByAnd("WorkEffort", UtilMisc.toMap("currentStatusId", "WF_SUSPENDED", "sourceReferenceId", orderId));            
        } catch (GenericEntityException e) {
            Debug.logError(e, "Problems getting WorkEffort with order ref number: " + orderId, module);
            return false;
        }        
                         
        if (workEfforts != null) {            
            // attempt to release the order workflow from 'Hold' status (resume workflow)
            boolean allPass = true; 
            Iterator wei = workEfforts.iterator();
            while (wei.hasNext()) {
                GenericValue workEffort = (GenericValue) wei.next();                             
                String workEffortId = workEffort.getString("workEffortId");
                try {                                           
                    if (workEffort.getString("currentStatusId").equals("WF_SUSPENDED")) {
                        WorkflowClient client = new WorkflowClient(dispatcher.getDispatchContext());                
                        client.resume(workEffortId);
                    } else {
                        Debug.logVerbose("Current : --{" + workEffort + "}-- not resuming", module);
                    }                
                } catch (WfException e) {
                    Debug.logError(e, "Problem resuming activity : " + workEffortId, module);
                    allPass = false;                                     
                }
            }
            return allPass;
        } else {
            Debug.logWarning("No WF found for order ID : " + orderId, module);
        }
        return false;               
    }
    
    public static boolean abortOrderProcessing(LocalDispatcher dispatcher, String orderId) {
        Debug.logInfo("Aborting workflow for order " + orderId, module);
        GenericDelegator delegator = dispatcher.getDelegator();
        
        // find the workEffortId for this order
        GenericValue workEffort = null;
        try {
            List workEfforts = delegator.findByAnd("WorkEffort", UtilMisc.toMap("workEffortTypeId", "WORK_FLOW", "sourceReferenceId", orderId));
            if (workEfforts != null && workEfforts.size() > 1) {
                Debug.logWarning("More then one workflow found for defined order: " + orderId, module);                
            }
            workEffort = EntityUtil.getFirst(workEfforts);
        } catch (GenericEntityException e) {
            Debug.logError(e, "Problems getting WorkEffort with order ref number: " + orderId, module);
            return false;
        }  
        
        if (workEffort != null) {
            String workEffortId = workEffort.getString("workEffortId");            
            if (workEffort.getString("currentStatusId").equals("WF_RUNNING")) {
                Debug.logInfo("WF is running; trying to abort", module);
                WorkflowClient client = new WorkflowClient(dispatcher.getDispatchContext());
                try {
                    client.abortProcess(workEffortId);
                } catch (WfException e) {
                    Debug.logError(e, "Problem aborting workflow", module);
                    return false;
                }
                return true;               
            }             
        }                              
        return false;
    }
}

⌨️ 快捷键说明

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