A patch from Ray Barlow " Small change that can greatly reduce the amount of processing that autoCancelOrderItems does..." (https://issues.apache.org/jira/browse/OFBIZ-523).

git-svn-id: https://svn.apache.org/repos/asf/incubator/ofbiz/trunk@485087 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jacques Le Roux
2006-12-09 23:22:47 +00:00
parent 10a243ade4
commit ccee7f2ccf
2 changed files with 21 additions and 9 deletions
+7 -4
View File
@@ -315,10 +315,13 @@ under the License.
<service name="autoCancelOrderItems" engine="java"
location="org.ofbiz.order.order.OrderServices" invoke="cancelFlaggedSalesOrders">
<description>Batch service which automatically canels sales order items. Items will be canceled if (a) they are on
orders in the CREATED state and it has been either 30 days or ProductStore.daysCancelNoPay since the order was created or
(b) if the item is flagged with an autoCancelDate and does not have a dontCancelDate and dontCancelUserLogin associated with it,
and it is past the autoCancelDate.</description>
<description>Batch service which automatically cancels sales order and/or sales order items.
Sales orders : These will be cancelled if the order status equals CREATED and it has been
either 30 days or ProductStore.daysCancelNoPay since the order was created. A value of 0 for
ProductStore.daysCancelNoPay means do not auto-cancel.
Sales order items : This is only for orders on the APPROVED status. Items will be cancelled if the
item is flagged with an autoCancelDate and does not have a dontCancelDate and dontCancelUserLogin
associated with it, and it is past the autoCancelDate.</description>
<!-- this service has no parameters IN or OUT -->
</service>
@@ -29,6 +29,7 @@ import org.ofbiz.base.util.*;
import org.ofbiz.base.util.collections.ResourceBundleMapWrapper;
import org.ofbiz.common.DataModelConstants;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntity;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.condition.EntityCondition;
@@ -2512,6 +2513,7 @@ public class OrderServices {
return ServiceUtil.returnSuccess();
}
Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
Iterator i = ordersToCheck.iterator();
while (i.hasNext()) {
GenericValue orderHeader = (GenericValue) i.next();
@@ -2560,9 +2562,19 @@ public class OrderServices {
}
} else {
// check for auto-cancel items
List itemsExprs = new ArrayList();
// create the query expressions
itemsExprs.add(new EntityExpr("orderId", EntityOperator.EQUALS, orderId));
itemsExprs.add(new EntityConditionList(UtilMisc.toList(new EntityExpr("statusId", EntityOperator.EQUALS, "ITEM_CREATED"),
new EntityExpr("statusId", EntityOperator.EQUALS, "ITEM_APPROVED")), EntityOperator.OR));
itemsExprs.add(new EntityExpr("dontCancelSetUserLogin", EntityOperator.EQUALS, GenericEntity.NULL_FIELD));
itemsExprs.add(new EntityExpr("dontCancelSetDate", EntityOperator.EQUALS, GenericEntity.NULL_FIELD));
itemsExprs.add(new EntityExpr("autoCancelDate", EntityOperator.NOT_EQUAL, GenericEntity.NULL_FIELD));
List orderItems = null;
try {
orderItems = orderHeader.getRelated("OrderItem");
orderItems = delegator.findByAnd("OrderItem", itemsExprs, null);
} catch (GenericEntityException e) {
Debug.logError(e, "Problem getting order item records", module);
}
@@ -2571,12 +2583,9 @@ public class OrderServices {
while (oii.hasNext()) {
GenericValue orderItem = (GenericValue) oii.next();
String orderItemSeqId = orderItem.getString("orderItemSeqId");
Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
Timestamp autoCancelDate = orderItem.getTimestamp("autoCancelDate");
Timestamp dontCancelDate = orderItem.getTimestamp("dontCancelSetDate");
String dontCancelUserLogin = orderItem.getString("dontCancelSetUserLogin");
if (dontCancelUserLogin == null && dontCancelDate == null && autoCancelDate != null) {
if (autoCancelDate != null) {
if (nowTimestamp.equals(autoCancelDate) || nowTimestamp.after(autoCancelDate)) {
// cancel the order item
Map svcCtx = UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItemSeqId, "statusId", "ITEM_CANCELLED", "userLogin", userLogin);