📄 findorders.bsh
字号:
/*
* Copyright (c) 2003 The Open For Business Project - www.ofbiz.org
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
* OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*@author Andy Zeneski (jaz@ofbiz.org)
*@version $Revision: 1.11 $
*@since 2.2
*/
import java.util.*;
import java.sql.Timestamp;
import org.ofbiz.entity.*;
import org.ofbiz.entity.util.*;
import org.ofbiz.entity.condition.*;
import org.ofbiz.base.util.*;
delegator = request.getAttribute("delegator");
// get the order types
orderTypes = delegator.findAll("OrderType", UtilMisc.toList("description"));
context.put("orderTypes", orderTypes);
// get the role types
roleTypes = delegator.findAll("RoleType", UtilMisc.toList("description"));
context.put("roleTypes", roleTypes);
// get the order statuses
orderStatuses = delegator.findByAnd("StatusItem", UtilMisc.toMap("statusTypeId", "ORDER_STATUS"), UtilMisc.toList("sequenceId", "description"));
context.put("orderStatuses", orderStatuses);
// get websites
websites = delegator.findAll("WebSite", UtilMisc.toList("siteName"));
context.put("webSites", websites);
// get the stores
stores = delegator.findAll("ProductStore", UtilMisc.toList("storeName"));
context.put("productStores", stores);
// current role type
currentRoleTypeId = request.getParameter("roleTypeId");
if (currentRoleTypeId != null && currentRoleTypeId.length() > 0) {
currentRole = delegator.findByPrimaryKeyCache("RoleType", UtilMisc.toMap("roleTypeId", currentRoleTypeId));
context.put("currentRole", currentRole);
}
// current selected type
currentTypeId = request.getParameter("orderTypeId");
if (currentTypeId != null && currentTypeId.length() > 0) {
currentType = delegator.findByPrimaryKeyCache("OrderType", UtilMisc.toMap("orderTypeId", currentTypeId));
context.put("currentType", currentType);
}
// current selected status
currentStatusId = request.getParameter("orderStatusId");
if (currentStatusId != null && currentStatusId.length() > 0) {
currentStatus = delegator.findByPrimaryKeyCache("StatusItem", UtilMisc.toMap("statusId", currentStatusId));
context.put("currentStatus", currentStatus);
}
// current website
currentWebSiteId = request.getParameter("webSiteId");
if (currentWebSiteId != null && currentWebSiteId.length() > 0) {
currentWebSite = delegator.findByPrimaryKeyCache("WebSite", UtilMisc.toMap("webSiteId", currentWebSiteId));
context.put("currentWebSite", currentWebSite);
}
// current store
currentProductStoreId = request.getParameter("productStoreId");
if (currentProductStoreId != null && currentProductStoreId.length() > 0) {
currentProductStore = delegator.findByPrimaryKeyCache("ProductStore", UtilMisc.toMap("productStoreId", currentProductStoreId));
context.put("currentProductStore", currentProductStore);
}
// create the fromDate for calendar
fromCal = Calendar.getInstance();
fromCal.setTime(new java.util.Date());
//fromCal.set(Calendar.DAY_OF_WEEK, fromCal.getActualMinimum(Calendar.DAY_OF_WEEK));
fromCal.set(Calendar.HOUR_OF_DAY, fromCal.getActualMinimum(Calendar.HOUR_OF_DAY));
fromCal.set(Calendar.MINUTE, fromCal.getActualMinimum(Calendar.MINUTE));
fromCal.set(Calendar.SECOND, fromCal.getActualMinimum(Calendar.SECOND));
fromCal.set(Calendar.MILLISECOND, fromCal.getActualMinimum(Calendar.MILLISECOND));
fromTs = new Timestamp(fromCal.getTimeInMillis());
fromStr = fromTs.toString();
fromStr = fromStr.substring(0, fromStr.indexOf('.'));
context.put("fromDateStr", fromStr);
// create the thruDate for calendar
toCal = Calendar.getInstance();
toCal.setTime(new java.util.Date());
//toCal.set(Calendar.DAY_OF_WEEK, toCal.getActualMaximum(Calendar.DAY_OF_WEEK));
toCal.set(Calendar.HOUR_OF_DAY, toCal.getActualMaximum(Calendar.HOUR_OF_DAY));
toCal.set(Calendar.MINUTE, toCal.getActualMaximum(Calendar.MINUTE));
toCal.set(Calendar.SECOND, toCal.getActualMaximum(Calendar.SECOND));
toCal.set(Calendar.MILLISECOND, toCal.getActualMaximum(Calendar.MILLISECOND));
toTs = new Timestamp(toCal.getTimeInMillis());
toStr = toTs.toString();
context.put("thruDateStr", toStr);
// set the page parameters
viewIndex = 1;
try {
viewIndex = Integer.valueOf((String) request.getParameter("VIEW_INDEX")).intValue();
} catch (Exception e) {
viewIndex = 1;
}
context.put("viewIndex", viewIndex);
viewSize = 20;
try {
viewSize = Integer.valueOf((String) request.getParameter("VIEW_SIZE")).intValue();
} catch (Exception e) {
viewSize = 20;
}
context.put("viewSize", viewSize);
// get the lookup flag
lookupFlag = request.getParameter("lookupFlag");
// blank param list
paramList = "";
// defined
orderHeaderList = null;
orderHeaderListSize = 0;
lowIndex = 0;
highIndex = 0;
if (lookupFlag != null) {
showAll = request.getParameter("showAll") != null ? request.getParameter("showAll") : "N";
paramList = paramList + "&lookupFlag=" + lookupFlag + "&showAll=" + showAll;
lookupErrorMessage = null;
andExprs = new ArrayList();
entityName = "OrderHeader";
// check for a orderId (happens in some browsers)
orderId = request.getParameter("order_id");
if (orderId != null && orderId.length() > 0) {
paramList = paramList + "&order_id=" + orderId;
andExprs.add(new EntityExpr("orderId", EntityOperator.EQUALS, orderId));
}
// find the orders for party
partyId = request.getParameter("partyId");
userLoginId = request.getParameter("userLoginId");
if (userLoginId != null && userLoginId.length() > 0) {
requestedUserLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", userLoginId));
if (requestedUserLogin != null) {
partyId = requestedUserLogin.getString("partyId");
} else {
lookupErrorMessage = "No userLogin found for userLoginId: " + userLoginId;
}
}
if (partyId != null && partyId.length() > 0) {
paramList = paramList + "&partyId=" + partyId;
entityName = "OrderHeaderAndRoles";
andExprs.add(new EntityExpr("partyId", EntityOperator.EQUALS, partyId));
}
// item related
correspondingPoId = request.getParameter("correspondingPoId");
if (correspondingPoId != null && correspondingPoId.length() > 0) {
paramList = paramList + "&correspondingPoId=" + correspondingPoId;
entityName= "OrderHeaderItemAndRoles";
andExprs.add(new EntityExpr("correspondingPoId", EntityOperator.EQUALS, correspondingPoId));
}
productId = request.getParameter("productId");
if (productId != null && productId.length() > 0) {
paramList = paramList + "&productId=" + productId;
entityName= "OrderHeaderItemAndRoles";
andExprs.add(new EntityExpr("productId", EntityOperator.EQUALS, productId));
}
// define the main condition
mainCond = null;
// now do the filtering
if (lookupErrorMessage == null) {
roleType = request.getParameter("roleTypeId");
orderType = request.getParameter("orderTypeId");
orderStatus = request.getParameter("orderStatusId");
productStoreId = request.getParameter("productStoreId");
webSiteId = request.getParameter("webSiteId");
createdBy = request.getParameter("createdBy");
billAcct = request.getParameter("billingAccountId");
minDate = request.getParameter("minDate");
maxDate = request.getParameter("maxDate");
if (productStoreId == null) productStoreId = "ANY";
if (webSiteId == null) webSiteId = "ANY";
if (roleType == null) roleType = "ANY";
if (orderType == null) orderType = "ANY";
if (orderStatus == null) orderStatus = "ANY";
paramList = paramList + "&productStoreId=" + productStoreId;
if (!"ANY".equals(productStoreId)) {
andExprs.add(new EntityExpr("productStoreId", EntityOperator.EQUALS, productStoreId));
}
paramList = paramList + "&webSiteId=" + webSiteId;
if (!"ANY".equals(webSiteId)) {
andExprs.add(new EntityExpr("webSiteId", EntityOperator.EQUALS, webSiteId));
}
paramList = paramList + "&roleTypeId=" + roleType;
if (!"ANY".equals(roleType)) {
entityName = "OrderHeaderAndRoles";
andExprs.add(new EntityExpr("roleTypeId", EntityOperator.EQUALS, roleType));
}
paramList = paramList + "&orderTypeId=" + orderType;
if (!"ANY".equals(orderType)) {
andExprs.add(new EntityExpr("orderTypeId", EntityOperator.EQUALS, orderType));
}
paramList = paramList + "&orderStatusId=" + orderStatus;
if (!"ANY".equals(orderStatus)) {
andExprs.add(new EntityExpr("statusId", EntityOperator.EQUALS, orderStatus));
}
if (billAcct != null && billAcct.length() > 0) {
paramList = paramList + "&billingAccountId=" + billAcct;
andExprs.add(new EntityExpr("billingAccountId", EntityOperator.EQUALS, billAcct));
}
if (createdBy != null && createdBy.length() > 0) {
paramList = paramList + "&createdBy=" + createdBy;
andExprs.add(new EntityExpr("createdBy", EntityOperator.EQUALS, createdBy));
}
if (minDate != null && minDate.length() > 8) {
minDate = minDate.trim();
if (minDate.length() < 14) minDate = minDate + " " + "00:00:00.000";
paramList = paramList + "&minDate=" + minDate;
andExprs.add(new EntityExpr("orderDate", EntityOperator.GREATER_THAN_EQUAL_TO, ObjectType.simpleTypeConvert(minDate, "Timestamp", null, null)));
}
if (maxDate != null && maxDate.length() > 8) {
maxDate = maxDate.trim();
if (maxDate.length() < 14) maxDate = maxDate + " " + "23:59:59.999";
paramList = paramList + "&maxDate=" + maxDate;
andExprs.add(new EntityExpr("orderDate", EntityOperator.LESS_THAN_EQUAL_TO, ObjectType.simpleTypeConvert(maxDate, "Timestamp", null, null)));
}
if (andExprs.size() > 0 || showAll.equalsIgnoreCase("Y")) mainCond = new EntityConditionList(andExprs, EntityOperator.AND);
}
// do the lookup
if (lookupErrorMessage == null && mainCond != null) {
// field we need to select; will be used to set distinct
List fieldsToSelect = UtilMisc.toList("orderId", "orderTypeId", "orderDate", "grandTotal", "statusId");
if (!"OrderHeader".equals(entityName)) {
if (partyId != null) {
fieldsToSelect.add("partyId");
}
if (!"ANY".equals(roleType)) {
fieldsToSelect.add("roleTypeId");
}
}
// sorting by order date newest first
List orderBy = UtilMisc.toList("-orderDate");
// set distinct on so we only get one row per order
EntityFindOptions findOpts = new EntityFindOptions(true, EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, true);
// using list iterator
EntityListIterator ohli = delegator.findListIteratorByCondition(entityName, mainCond, null, fieldsToSelect, orderBy, findOpts);
// get the indexes for the partial list
lowIndex = (((viewIndex - 1) * viewSize) + 1);
highIndex = viewIndex * viewSize;
// attempt to get the full size
ohli.last();
orderHeaderListSize = ohli.currentIndex();
if (highIndex > orderHeaderListSize) {
highIndex = orderHeaderListSize;
}
// get the partial list for this page
ohli.first();
if (orderHeaderListSize > 0) {
orderHeaderList = ohli.getPartialList(lowIndex, viewSize);
} else {
orderHeaderList = new ArrayList();
}
// close the iterator
ohli.close();
} else {
orderHeaderList = new ArrayList();
orderHeaderListSize = 0;
}
context.put("orderHeaderList", orderHeaderList);
context.put("orderHeaderListSize", orderHeaderListSize);
if (lookupErrorMessage != null) {
context.put("lookupErrorMessage", lookupErrorMessage);
}
}
context.put("paramList", paramList);
context.put("highIndex", highIndex);
context.put("lowIndex", lowIndex);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -