📄 productsearchevents.java
字号:
}
return "success";
}
/** Adds the results of a search to the specified catogory
*@param request The HTTPRequest object for the current request
*@param response The HTTPResponse object for the current request
*@return String specifying the exit status of this event
*/
public static String searchAddToCategory(HttpServletRequest request, HttpServletResponse response) {
GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");
String productCategoryId = request.getParameter("SE_SEARCH_CATEGORY_ID");
String fromDateStr = request.getParameter("fromDate");
Timestamp fromDate = null;
String errMsg=null;
try {
fromDate = Timestamp.valueOf(fromDateStr);
} catch (RuntimeException e) {
Map messageMap = UtilMisc.toMap("errDateFormat", e.toString());
errMsg = UtilProperties.getMessage(resource,"productsearchevents.fromDate_not_formatted_properly", messageMap, UtilHttp.getLocale(request));
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
EntityListIterator eli = getProductSearchResults(request);
if (eli == null) {
errMsg = UtilProperties.getMessage(resource,"productsearchevents.no_results_found_probably_error_constraints", UtilHttp.getLocale(request));
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
try {
boolean beganTransaction = TransactionUtil.begin();
try {
GenericValue searchResultView = null;
int numAdded=0;
while ((searchResultView = (GenericValue) eli.next()) != null) {
String productId = searchResultView.getString("productId");
GenericValue pcm=delegator.makeValue("ProductCategoryMember", null);
pcm.set("productCategoryId", productCategoryId);
pcm.set("productId", productId);
pcm.set("fromDate", fromDate);
pcm.create();
numAdded++;
}
Map messageMap = UtilMisc.toMap("numAdded", Integer.toString(numAdded));
errMsg = UtilProperties.getMessage(resource,"productsearchevents.added_x_product_category_members", messageMap, UtilHttp.getLocale(request));
request.setAttribute("_EVENT_MESSAGE_", errMsg);
eli.close();
TransactionUtil.commit(beganTransaction);
} catch (GenericEntityException e) {
Map messageMap = UtilMisc.toMap("errSearchResult", e.toString());
errMsg = UtilProperties.getMessage(resource,"productsearchevents.error_getting_search_results", messageMap, UtilHttp.getLocale(request));
Debug.logError(e, errMsg, module);
request.setAttribute("_ERROR_MESSAGE_", errMsg);
TransactionUtil.rollback(beganTransaction);
return "error";
}
} catch (GenericTransactionException e) {
Map messageMap = UtilMisc.toMap("errSearchResult", e.toString());
errMsg = UtilProperties.getMessage(resource,"productsearchevents.error_getting_search_results", messageMap, UtilHttp.getLocale(request));
Debug.logError(e, errMsg, module);
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
return "success";
}
/** Adds a feature to a seach results
*@param request The HTTPRequest object for the current request
*@param response The HTTPResponse object for the current request
*@return String specifying the exit status of this event
*/
public static String searchAddFeature(HttpServletRequest request, HttpServletResponse response) {
GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");
String productFeatureId = request.getParameter("productFeatureId");
String fromDateStr = request.getParameter("fromDate");
String thruDateStr = request.getParameter("thruDate");
String amountStr = request.getParameter("amount");
String sequenceNumStr = request.getParameter("sequenceNum");
String productFeatureApplTypeId = request.getParameter("productFeatureApplTypeId");
String errMsg=null;
Timestamp thruDate=null;
Timestamp fromDate=null;
Double amount=null;
Long sequenceNum=null;
try {
if (UtilValidate.isNotEmpty(fromDateStr)) {
fromDate = Timestamp.valueOf(fromDateStr);
}
if (UtilValidate.isNotEmpty(thruDateStr)) {
thruDate = Timestamp.valueOf(thruDateStr);
}
if (UtilValidate.isNotEmpty(amountStr)) {
amount = Double.valueOf(amountStr);
}
if (UtilValidate.isNotEmpty(sequenceNumStr)) {
sequenceNum= Long.valueOf(sequenceNumStr);
}
} catch (RuntimeException e) {
errMsg = "Error casting data types: " + e.toString();
Debug.logError(e, errMsg, module);
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
EntityListIterator eli = getProductSearchResults(request);
if (eli == null) {
errMsg = UtilProperties.getMessage(resource,"productsearchevents.no_results_found_probably_error_constraints", UtilHttp.getLocale(request));
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
try {
boolean beganTransaction = TransactionUtil.begin();
try {
GenericValue searchResultView = null;
int numAdded=0;
while ((searchResultView = (GenericValue) eli.next()) != null) {
String productId = searchResultView.getString("productId");
GenericValue pfa=delegator.makeValue("ProductFeatureAppl", null);
pfa.set("productId", productId);
pfa.set("productFeatureId", productFeatureId);
pfa.set("fromDate", fromDate);
pfa.set("thruDate", thruDate);
pfa.set("productFeatureApplTypeId", productFeatureApplTypeId);
pfa.set("amount", amount);
pfa.set("sequenceNum", sequenceNum);
pfa.create();
numAdded++;
}
request.setAttribute("_EVENT_MESSAGE_", "Added " + numAdded + " features.");
eli.close();
TransactionUtil.commit(beganTransaction);
} catch (GenericEntityException e) {
errMsg = "Error getting search results: " + e.toString();
Debug.logError(e, errMsg, module);
request.setAttribute("_ERROR_MESSAGE_", errMsg);
TransactionUtil.rollback(beganTransaction);
return "error";
}
} catch (GenericTransactionException e) {
errMsg = "Error getting search results: " + e.toString();
Debug.logError(e, errMsg, module);
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
return "success";
}
public static EntityListIterator getProductSearchResults(HttpServletRequest request) {
HttpSession session = request.getSession();
GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");
String visitId = VisitHandler.getVisitId(session);
List productSearchConstraintList = (List) session.getAttribute(ProductSearchSession.PRODUCT_SEARCH_CONSTRAINT_LIST);
// if no constraints, don't do a search...
if (productSearchConstraintList != null && productSearchConstraintList.size() > 0) {
ResultSortOrder resultSortOrder = ProductSearchSession.getResultSortOrder(session);
ProductSearchContext productSearchContext = new ProductSearchContext(delegator, visitId);
productSearchContext.addProductSearchConstraints(productSearchConstraintList);
productSearchContext.setResultSortOrder(resultSortOrder);
return productSearchContext.doQuery(delegator);
} else {
return null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -