📄 orderservices.java
字号:
Map invCtx = UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItemSeqId, "cancelQuantity", thisCancelQty, "userLogin", userLogin);
try {
dispatcher.runSyncIgnore("cancelOrderItemInvResQty", invCtx);
} catch (GenericServiceException e) {
Debug.logError(e, module);
return ServiceUtil.returnError("Unable to update inventory reservations : " + itemMsgInfo);
}
}
}
}
return ServiceUtil.returnSuccess();
}
/** Service for changing the status on order item(s) */
public static Map setItemStatus(DispatchContext ctx, Map context) {
GenericDelegator delegator = ctx.getDelegator();
GenericValue userLogin = (GenericValue) context.get("userLogin");
String orderId = (String) context.get("orderId");
String orderItemSeqId = (String) context.get("orderItemSeqId");
String fromStatusId = (String) context.get("fromStatusId");
String statusId = (String) context.get("statusId");
// check and make sure we have permission to change the order
Security security = ctx.getSecurity();
if (!security.hasEntityPermission("ORDERMGR", "_UPDATE", userLogin)) {
GenericValue placingCustomer = null;
try {
Map placingCustomerFields = UtilMisc.toMap("orderId", orderId, "partyId", userLogin.getString("partyId"), "roleTypeId", "PLACING_CUSTOMER");
placingCustomer = delegator.findByPrimaryKey("OrderRole", placingCustomerFields);
} catch (GenericEntityException e) {
return ServiceUtil.returnError("ERROR: Cannot get OrderRole entity: " + e.getMessage());
}
if (placingCustomer == null)
return ServiceUtil.returnError("You do not have permission to change this order's status.");
}
Map fields = UtilMisc.toMap("orderId", orderId);
if (orderItemSeqId != null)
fields.put("orderItemSeqId", orderItemSeqId);
if (fromStatusId != null)
fields.put("statusId", fromStatusId);
List orderItems = null;
try {
orderItems = delegator.findByAnd("OrderItem", fields);
} catch (GenericEntityException e) {
return ServiceUtil.returnError("ERROR: Cannot get OrderItem entity: " + e.getMessage());
}
if (orderItems != null && orderItems.size() > 0) {
List toBeStored = new ArrayList();
Iterator itemsIterator = orderItems.iterator();
while (itemsIterator.hasNext()) {
GenericValue orderItem = (GenericValue) itemsIterator.next();
if (orderItem == null)
ServiceUtil.returnError("ERROR: Cannot change item status; item not found.");
if (Debug.verboseOn()) Debug.logVerbose("[OrderServices.setItemStatus] : Status Change: [" + orderId + "] (" + orderItem.getString("orderItemSeqId"), module);
if (Debug.verboseOn()) Debug.logVerbose("[OrderServices.setIte,Status] : From Status : " + orderItem.getString("statusId"), module);
if (Debug.verboseOn()) Debug.logVerbose("[OrderServices.setOrderStatus] : To Status : " + statusId, module);
if (orderItem.getString("statusId").equals(statusId)) {
continue;
}
try {
Map statusFields = UtilMisc.toMap("statusId", orderItem.getString("statusId"), "statusIdTo", statusId);
GenericValue statusChange = delegator.findByPrimaryKeyCache("StatusValidChange", statusFields);
if (statusChange == null) {
Debug.logWarning("Item status not changed " + orderItem.getString("statusId") + " -> " + statusId + " is not a valid change.", module);
continue;
}
} catch (GenericEntityException e) {
return ServiceUtil.returnError("ERROR: Could not change item status: " + e.getMessage());
}
orderItem.set("statusId", statusId);
toBeStored.add(orderItem);
// now create a status change
Map changeFields = new HashMap();
changeFields.put("orderStatusId", delegator.getNextSeqId("OrderStatus").toString());
changeFields.put("statusId", statusId);
changeFields.put("orderId", orderId);
changeFields.put("orderItemSeqId", orderItem.getString("orderItemSeqId"));
changeFields.put("statusDatetime", UtilDateTime.nowTimestamp());
GenericValue orderStatus = delegator.makeValue("OrderStatus", changeFields);
toBeStored.add(orderStatus);
}
// store the changes
if (toBeStored.size() > 0) {
try {
delegator.storeAll(toBeStored);
} catch (GenericEntityException e) {
return ServiceUtil.returnError("ERROR: Cannot store status changes: " + e.getMessage());
}
}
}
return ServiceUtil.returnSuccess();
}
/** Service for changing the status on an order header */
public static Map setOrderStatus(DispatchContext ctx, Map context) {
Map result = new HashMap();
GenericDelegator delegator = ctx.getDelegator();
GenericValue userLogin = (GenericValue) context.get("userLogin");
String orderId = (String) context.get("orderId");
String statusId = (String) context.get("statusId");
// check and make sure we have permission to change the order
Security security = ctx.getSecurity();
if (!security.hasEntityPermission("ORDERMGR", "_UPDATE", userLogin)) {
GenericValue placingCustomer = null;
try {
Map placingCustomerFields = UtilMisc.toMap("orderId", orderId, "partyId", userLogin.getString("partyId"), "roleTypeId", "PLACING_CUSTOMER");
placingCustomer = delegator.findByPrimaryKey("OrderRole", placingCustomerFields);
} catch (GenericEntityException e) {
return ServiceUtil.returnError("ERROR: Cannot get OrderRole entity: " + e.getMessage());
}
if (placingCustomer == null)
return ServiceUtil.returnError("You do not have permission to change this order's status.");
}
try {
GenericValue orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));
if (orderHeader == null) {
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
result.put(ModelService.ERROR_MESSAGE, "ERROR: Could not change order status; order cannot be found.");
return result;
}
if (Debug.verboseOn()) Debug.logVerbose("[OrderServices.setOrderStatus] : From Status : " + orderHeader.getString("statusId"), module);
if (Debug.verboseOn()) Debug.logVerbose("[OrderServices.setOrderStatus] : To Status : " + statusId, module);
if (orderHeader.getString("statusId").equals(statusId)) {
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
return result;
}
try {
Map statusFields = UtilMisc.toMap("statusId", orderHeader.getString("statusId"), "statusIdTo", statusId);
GenericValue statusChange = delegator.findByPrimaryKeyCache("StatusValidChange", statusFields);
if (statusChange == null) {
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
result.put(ModelService.ERROR_MESSAGE, "ERROR: Could not change order status; status is not a valid change.");
return result;
}
} catch (GenericEntityException e) {
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
result.put(ModelService.ERROR_MESSAGE, "ERROR: Could not change order status (" + e.getMessage() + ").");
return result;
}
// update the current status
orderHeader.set("statusId", statusId);
// now create a status change
Map fields = new HashMap();
fields.put("orderStatusId", delegator.getNextSeqId("OrderStatus").toString());
fields.put("statusId", statusId);
fields.put("orderId", orderId);
fields.put("statusDatetime", UtilDateTime.nowTimestamp());
GenericValue orderStatus = delegator.makeValue("OrderStatus", fields);
List toBeStored = new ArrayList();
toBeStored.add(orderHeader);
toBeStored.add(orderStatus);
delegator.storeAll(toBeStored);
} catch (GenericEntityException e) {
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
result.put(ModelService.ERROR_MESSAGE, "ERROR: Could not change order status (" + e.getMessage() + ").");
return result;
}
// release the inital hold if we are cancelled or approved
if ("ORDER_CANCELLED".equals(statusId) || "ORDER_APPROVED".equals(statusId)) {
OrderChangeHelper.releaseInitialOrderHold(ctx.getDispatcher(), orderId);
// cancel any order processing if we are cancelled
if ("ORDER_CANCELLED".equals(statusId)) {
OrderChangeHelper.abortOrderProcessing(ctx.getDispatcher(), orderId);
}
}
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
result.put("orderStatusId", statusId);
return result;
}
/** Service to update the order tracking number */
public static Map updateTrackingNumber(DispatchContext dctx, Map context) {
Map result = new HashMap();
GenericDelegator delegator = dctx.getDelegator();
String orderId = (String) context.get("orderId");
String orderItemSeqId = (String) context.get("orderItemSeqId");
String trackingNumber = (String) context.get("trackingNumber");
if (orderItemSeqId == null || orderItemSeqId.length() == 0)
orderItemSeqId = DataModelConstants.SEQ_ID_NA;
try {
GenericValue shipPref = delegator.findByPrimaryKey("OrderShipmentPreference", UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItemSeqId));
if (shipPref == null) {
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
result.put(ModelService.ERROR_MESSAGE, "ERROR: No order shipment preference found!");
} else {
shipPref.set("trackingNumber", trackingNumber);
shipPref.store();
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
}
} catch (GenericEntityException e) {
Debug.logError(e, module);
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
result.put(ModelService.ERROR_MESSAGE, "ERROR: Could not set tracking number (" + e.getMessage() + ").");
}
return result;
}
/** Service to add a role type to an order */
public static Map addRoleType(DispatchContext ctx, Map context) {
Map result = new HashMap();
GenericDelegator delegator = ctx.getDelegator();
String orderId = (String) context.get("orderId");
String partyId = (String) context.get("partyId");
String roleTypeId = (String) context.get("roleTypeId");
Boolean removeOld = (Boolean) context.get("removeOld");
if (removeOld != null && removeOld.booleanValue()) {
try {
delegator.removeByAnd("OrderRole", UtilMisc.toMap("orderId", orderId, "roleTypeId", roleTypeId));
} catch (GenericEntityException e) {
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
result.put(ModelService.ERROR_MESSAGE, "ERROR: Could not remove old roles (" + e.getMessage() + ").");
return result;
}
}
Map fields = UtilMisc.toMap("orderId", orderId, "partyId", partyId, "roleTypeId", roleTypeId);
try {
// first check and see if we are already there; if so, just return success
GenericValue testValue = delegator.findByPrimaryKey("OrderRole", fields);
if (testValue != null) {
ServiceUtil.returnSuccess();
} else {
GenericValue value = delegator.makeValue("OrderRole", fields);
delegator.create(value);
}
} catch (GenericEntityException e) {
result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
result.put(ModelService.ERROR_MESSAGE, "ERROR: Could not add role to order (" + e.getMessage() + "
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -