📄 productsearchevents.java
字号:
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, errMsg, e); 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 search 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"); Locale locale = UtilHttp.getLocale(request); 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"); 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) { String errorMsg = UtilProperties.getMessage(resource, "productSearchEvents.error_casting_types", locale) + " : " + e.toString(); request.setAttribute("_ERROR_MESSAGE_", errorMsg); Debug.logError(e, errorMsg, module); return "error"; } EntityListIterator eli = getProductSearchResults(request); if (eli == null) { String 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++; } Map messageMap = UtilMisc.toMap("numAdded", new Integer(numAdded), "productFeatureId", productFeatureId); String eventMsg = UtilProperties.getMessage(resource, "productSearchEvents.added_param_features", messageMap, locale) + "."; request.setAttribute("_EVENT_MESSAGE_", eventMsg); eli.close(); TransactionUtil.commit(beganTransaction); } catch (GenericEntityException e) { String errorMsg = UtilProperties.getMessage(resource, "productSearchEvents.error_getting_results", locale) + " : " + e.toString(); request.setAttribute("_ERROR_MESSAGE_", errorMsg); Debug.logError(e, errorMsg, module); TransactionUtil.rollback(beganTransaction, errorMsg, e); return "error"; } } catch (GenericTransactionException e) { String errorMsg = UtilProperties.getMessage(resource, "productSearchEvents.error_getting_results", locale) + " : " + e.toString(); request.setAttribute("_ERROR_MESSAGE_", errorMsg); Debug.logError(e, errorMsg, module); return "error"; } return "success"; } /** Removes a feature from search 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 searchRemoveFeature(HttpServletRequest request, HttpServletResponse response) { GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); Locale locale = UtilHttp.getLocale(request); String productFeatureId = request.getParameter("productFeatureId"); EntityListIterator eli = getProductSearchResults(request); if (eli == null) { String 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 numRemoved = 0; while ((searchResultView = (GenericValue) eli.next()) != null) { String productId = searchResultView.getString("productId"); numRemoved += delegator.removeByAnd("ProductFeatureAppl", UtilMisc.toMap("productId", productId, "productFeatureId", productFeatureId)); } Map messageMap = UtilMisc.toMap("numRemoved", new Integer(numRemoved), "productFeatureId", productFeatureId); String eventMsg = UtilProperties.getMessage(resource, "productSearchEvents.removed_param_features", messageMap, locale) + "."; request.setAttribute("_EVENT_MESSAGE_", eventMsg); eli.close(); TransactionUtil.commit(beganTransaction); } catch (GenericEntityException e) { String errorMsg = UtilProperties.getMessage(resource, "productSearchEvents.error_getting_results", locale) + " : " + e.toString(); request.setAttribute("_ERROR_MESSAGE_", errorMsg); Debug.logError(e, errorMsg, module); TransactionUtil.rollback(beganTransaction, errorMsg, e); return "error"; } } catch (GenericTransactionException e) { String errorMsg = UtilProperties.getMessage(resource, "productSearchEvents.error_getting_results", locale) + " : " + e.toString(); request.setAttribute("_ERROR_MESSAGE_", errorMsg); Debug.logError(e, errorMsg, module); 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 = ProductSearchSession.ProductSearchOptions.getConstraintList(session); // if no constraints, don't do a search... if (productSearchConstraintList != null && productSearchConstraintList.size() > 0) { ResultSortOrder resultSortOrder = ProductSearchSession.ProductSearchOptions.getResultSortOrder(session); ProductSearchSession.checkSaveSearchOptionsHistory(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 + -