📄 orderservices.java
字号:
// set the additional party roles Map additionalPartyRole = (Map) context.get("orderAdditionalPartyRoleMap"); if (additionalPartyRole != null) { Iterator aprIt = additionalPartyRole.entrySet().iterator(); while (aprIt.hasNext()) { Map.Entry entry = (Map.Entry) aprIt.next(); String additionalRoleTypeId = (String) entry.getKey(); List parties = (List) entry.getValue(); if (parties != null) { Iterator apIt = parties.iterator(); while (apIt.hasNext()) { String additionalPartyId = (String) apIt.next(); toBeStored.add(delegator.makeValue("PartyRole", UtilMisc.toMap("partyId", additionalPartyId, "roleTypeId", additionalRoleTypeId))); toBeStored.add(delegator.makeValue("OrderRole", UtilMisc.toMap("orderId", orderId, "partyId", additionalPartyId, "roleTypeId", additionalRoleTypeId))); } } } } // set the item survey responses List surveyResponses = (List) context.get("orderItemSurveyResponses"); if (surveyResponses != null && surveyResponses.size() > 0) { Iterator oisr = surveyResponses.iterator(); while (oisr.hasNext()) { GenericValue surveyResponse = (GenericValue) oisr.next(); surveyResponse.set("orderId", orderId); toBeStored.add(surveyResponse); } } // set the item price info; NOTE: this must be after the orderItems are stored for referential integrity if (orderItemPriceInfo != null && orderItemPriceInfo.size() > 0) { Iterator oipii = orderItemPriceInfo.iterator(); while (oipii.hasNext()) { GenericValue oipi = (GenericValue) oipii.next(); try { oipi.set("orderItemPriceInfoId", delegator.getNextSeqId("OrderItemPriceInfo")); } catch (IllegalArgumentException e) { return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorCouldNotGetNextSequenceIdForOrderItemPriceInfoCannotCreateOrder",locale)); } oipi.set("orderId", orderId); toBeStored.add(oipi); } } // set the item associations List orderItemAssociations = (List) context.get("orderItemAssociations"); if (orderItemAssociations != null && orderItemAssociations.size() > 0) { Iterator oia = orderItemAssociations.iterator(); while (oia.hasNext()) { GenericValue orderItemAssociation = (GenericValue) oia.next(); orderItemAssociation.set("purchaseOrderId", orderId); toBeStored.add(orderItemAssociation); } } // store the orderProductPromoUseInfos List orderProductPromoUses = (List) context.get("orderProductPromoUses"); if (orderProductPromoUses != null && orderProductPromoUses.size() > 0) { Iterator orderProductPromoUseIter = orderProductPromoUses.iterator(); while (orderProductPromoUseIter.hasNext()) { GenericValue productPromoUse = (GenericValue) orderProductPromoUseIter.next(); productPromoUse.set("orderId", orderId); toBeStored.add(productPromoUse); } } /* DEJ20050529 the OLD way, where a single party had all roles... no longer doing things this way... // define the roles for the order List userOrderRoleTypes = null; if ("SALES_ORDER".equals(orderTypeId)) { userOrderRoleTypes = UtilMisc.toList("END_USER_CUSTOMER", "SHIP_TO_CUSTOMER", "BILL_TO_CUSTOMER", "PLACING_CUSTOMER"); } else if ("PURCHASE_ORDER".equals(orderTypeId)) { userOrderRoleTypes = UtilMisc.toList("SHIP_FROM_VENDOR", "BILL_FROM_VENDOR", "SUPPLIER_AGENT"); } else { // TODO: some default behavior } // now add the roles if (userOrderRoleTypes != null) { Iterator i = userOrderRoleTypes.iterator(); while (i.hasNext()) { String roleType = (String) i.next(); String thisParty = partyId; if (thisParty == null) { thisParty = "_NA_"; // will always set these roles so we can query } // make sure the party is in the role before adding toBeStored.add(delegator.makeValue("PartyRole", UtilMisc.toMap("partyId", partyId, "roleTypeId", roleType))); toBeStored.add(delegator.makeValue("OrderRole", UtilMisc.toMap("orderId", orderId, "partyId", partyId, "roleTypeId", roleType))); } } */ // see the attributeRoleMap definition near the top of this file for attribute-role mappings Map attributeRoleMap = salesAttributeRoleMap; if ("PURCHASE_ORDER".equals(orderTypeId)) { attributeRoleMap = purchaseAttributeRoleMap; } Iterator attributeRoleEntryIter = attributeRoleMap.entrySet().iterator(); while (attributeRoleEntryIter.hasNext()) { Map.Entry attributeRoleEntry = (Map.Entry) attributeRoleEntryIter.next(); if (UtilValidate.isNotEmpty((String) context.get(attributeRoleEntry.getKey()))) { // make sure the party is in the role before adding toBeStored.add(delegator.makeValue("PartyRole", UtilMisc.toMap("partyId", context.get(attributeRoleEntry.getKey()), "roleTypeId", attributeRoleEntry.getValue()))); toBeStored.add(delegator.makeValue("OrderRole", UtilMisc.toMap("orderId", orderId, "partyId", context.get(attributeRoleEntry.getKey()), "roleTypeId", attributeRoleEntry.getValue()))); } } // set the affiliate -- This is going to be removed... String affiliateId = (String) context.get("affiliateId"); if (UtilValidate.isNotEmpty(affiliateId)) { toBeStored.add(delegator.makeValue("OrderRole", UtilMisc.toMap("orderId", orderId, "partyId", affiliateId, "roleTypeId", "AFFILIATE"))); } // set the distributor String distributorId = (String) context.get("distributorId"); if (UtilValidate.isNotEmpty(distributorId)) { toBeStored.add(delegator.makeValue("OrderRole", UtilMisc.toMap("orderId", orderId, "partyId", distributorId, "roleTypeId", "DISTRIBUTOR"))); } // find all parties in role VENDOR associated with WebSite OR ProductStore (where WebSite overrides, if specified), associated first valid with the Order if (UtilValidate.isNotEmpty((String) context.get("productStoreId"))) { try { List productStoreRoles = delegator.findByAnd("ProductStoreRole", UtilMisc.toMap("roleTypeId", "VENDOR", "productStoreId", context.get("productStoreId")), UtilMisc.toList("-fromDate")); productStoreRoles = EntityUtil.filterByDate(productStoreRoles, true); GenericValue productStoreRole = EntityUtil.getFirst(productStoreRoles); if (productStoreRole != null) { toBeStored.add(delegator.makeValue("OrderRole", UtilMisc.toMap("orderId", orderId, "partyId", productStoreRole.get("partyId"), "roleTypeId", "VENDOR"))); } } catch (GenericEntityException e) { Debug.logError(e, "Error looking up Vendor for the current Product Store", module); } } if (UtilValidate.isNotEmpty((String) context.get("webSiteId"))) { try { List webSiteRoles = delegator.findByAnd("WebSiteRole", UtilMisc.toMap("roleTypeId", "VENDOR", "webSiteId", context.get("webSiteId")), UtilMisc.toList("-fromDate")); webSiteRoles = EntityUtil.filterByDate(webSiteRoles, true); GenericValue webSiteRole = EntityUtil.getFirst(webSiteRoles); if (webSiteRole != null) { toBeStored.add(delegator.makeValue("OrderRole", UtilMisc.toMap("orderId", orderId, "partyId", webSiteRole.get("partyId"), "roleTypeId", "VENDOR"))); } } catch (GenericEntityException e) { Debug.logError(e, "Error looking up Vendor for the current Web Site", module); } } // set the order payment info List orderPaymentInfos = (List) context.get("orderPaymentInfo"); if (orderPaymentInfos != null && orderPaymentInfos.size() > 0) { Iterator oppIter = orderPaymentInfos.iterator(); while (oppIter.hasNext()) { GenericValue valueObj = (GenericValue) oppIter.next(); valueObj.set("orderId", orderId); if ("OrderPaymentPreference".equals(valueObj.getEntityName())) { if (valueObj.get("orderPaymentPreferenceId") == null) { valueObj.set("orderPaymentPreferenceId", delegator.getNextSeqId("OrderPaymentPreference").toString()); valueObj.set("createdDate", UtilDateTime.nowTimestamp()); valueObj.set("createdByUserLogin", userLogin.getString("userLoginId")); } if (valueObj.get("statusId") == null) { valueObj.set("statusId", "PAYMENT_NOT_RECEIVED"); } } toBeStored.add(valueObj); } } // store the trackingCodeOrder entities List trackingCodeOrders = (List) context.get("trackingCodeOrders"); if (trackingCodeOrders != null && trackingCodeOrders.size() > 0) { Iterator tkcdordIter = trackingCodeOrders.iterator(); while (tkcdordIter.hasNext()) { GenericValue trackingCodeOrder = (GenericValue) tkcdordIter.next(); trackingCodeOrder.set("orderId", orderId); toBeStored.add(trackingCodeOrder); } } // store the OrderTerm entities List orderTerms = (List) context.get("orderTerms"); if (orderTerms != null && orderTerms.size() > 0) { Iterator orderTermIter = orderTerms.iterator(); while (orderTermIter.hasNext()) { GenericValue orderTerm = (GenericValue) orderTermIter.next(); orderTerm.set("orderId", orderId); orderTerm.set("orderItemSeqId","_NA_"); toBeStored.add(orderTerm); } } try { // store line items, etc so that they will be there for the foreign key checks delegator.storeAll(toBeStored); // START inventory reservation List resErrorMessages = new LinkedList(); try { reserveInventory(delegator, dispatcher, userLogin, locale, orderItemShipGroupInfo, itemValuesBySeqId, orderTypeId, productStoreId, resErrorMessages); } catch (GeneralException e) { return ServiceUtil.returnError(e.getMessage()); } if (resErrorMessages.size() > 0) { return ServiceUtil.returnError(resErrorMessages); } // END inventory reservation successResult.put("orderId", orderId); } catch (GenericEntityException e) { Debug.logError(e, "Problem with order storage or reservations", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorCouldNotCreateOrderWriteError",locale) + e.getMessage() + ")."); } return successResult; } public static void reserveInventory(GenericDelegator delegator, LocalDispatcher dispatcher, GenericValue userLogin, Locale locale, List orderItemShipGroupInfo, Map itemValuesBySeqId, String orderTypeId, String productStoreId, List resErrorMessages) throws GeneralException { boolean isImmediatelyFulfilled = false; GenericValue productStore = null; if (UtilValidate.isNotEmpty(productStoreId)) { try { productStore = delegator.findByPrimaryKeyCache("ProductStore", UtilMisc.toMap("productStoreId", productStoreId)); } catch (GenericEntityException e) { throw new GeneralException(UtilProperties.getMessage(resource_error, "OrderErrorCouldNotFindProductStoreWithID", UtilMisc.toMap("productStoreId", productStoreId), locale) + e.toString()); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -