📄 utilopportunity.java
字号:
} /** * Returns all account and lead opportunities for an internalPartyId. This is done by looking for all opportunities * belonging to accounts and leads that the internalPartyId is RESPONSIBLE_FOR. * * @param organizationPartyId - filter by organization TODO: not implemented * @param internalPartyId - lookup opportunities for this party * @param customTimePeriodId - if not null, will only get them for this time period * @param additionalConditions - if not null, this EntityConditionList will be added as well * @param orderBy - List of fields to order results by, can be null * @param delegator * @return * @throws GenericEntityException */ public static EntityListIterator getOpportunitiesForMyAccounts(String organizationPartyId, String internalPartyId, String customTimePeriodId, EntityConditionList additionalConditions, List orderBy, GenericDelegator delegator) throws GenericEntityException { // build condition to get list of PROSPECT or ACCOUNT opportunities that the user is RESPONSIBLE_FOR List combinedConditions = UtilMisc.toList( new EntityExpr("partyIdTo", EntityOperator.EQUALS, internalPartyId), new EntityExpr("partyRelationshipTypeId", EntityOperator.EQUALS, "RESPONSIBLE_FOR"), new EntityConditionList( UtilMisc.toList( new EntityExpr("roleTypeIdFrom", EntityOperator.EQUALS, "PROSPECT"), new EntityExpr("roleTypeIdFrom", EntityOperator.EQUALS, "ACCOUNT") ), EntityOperator.OR), EntityUtil.getFilterByDateExpr()); // filter out expired accounts return getOpportunitiesForPartyHelper(customTimePeriodId, combinedConditions, additionalConditions, orderBy, delegator); } /** * As getOpportunitiesForMyAccounts but gets all account opportunities for all teams the party belongs to. * Also includes lead opportunities that the internalPartyId is RESPONSIBLE_FOR. */ public static EntityListIterator getOpportunitiesForMyTeams(String organizationPartyId, String internalPartyId, String customTimePeriodId, EntityConditionList additionalConditions, List orderBy, GenericDelegator delegator) throws GenericEntityException { // strategy: find all the accounts of the internalPartyId, then find all the opportunities of those accounts EntityConditionList conditions = new EntityConditionList( UtilMisc.toList( new EntityExpr("partyIdTo", EntityOperator.EQUALS, internalPartyId), new EntityExpr("roleTypeIdFrom", EntityOperator.EQUALS, "ACCOUNT"), new EntityConditionList( UtilMisc.toList( new EntityExpr("partyRelationshipTypeId", EntityOperator.EQUALS, "RESPONSIBLE_FOR"), new EntityExpr("partyRelationshipTypeId", EntityOperator.EQUALS, "ASSIGNED_TO") ), EntityOperator.OR), EntityUtil.getFilterByDateExpr() ), EntityOperator.AND); List accounts = delegator.findByCondition("PartyRelationship", conditions, null, null); ArrayList accountIds = new ArrayList(); for (Iterator iter = accounts.iterator(); iter.hasNext(); ) { GenericValue account = (GenericValue) iter.next(); accountIds.add(account.get("partyIdFrom")); } // if no accounts are found, then return a null if (accountIds.size() < 1) { return null; } // build the condition to find opportunitied belonging to these accounts List combinedConditions = UtilMisc.toList( new EntityExpr("partyIdFrom", EntityOperator.IN, accountIds), new EntityExpr("roleTypeIdFrom", EntityOperator.EQUALS, "ACCOUNT") ); return getOpportunitiesForPartyHelper(customTimePeriodId, combinedConditions, additionalConditions, orderBy, delegator); } /** * As getOpportunitiesForMyAccounts but returns Account and Lead opportunities that the internalPartyId is assigned to. * Note that this is a superset of getOpportunitiesForMyAccounts, which returns the opportunities that the internalPartyId * is directly responsible for. Use this method to get all opportunities that the internalPartyId can see. */ public static EntityListIterator getOpportunitiesForInternalParty(String organizationPartyId, String internalPartyId, String customTimePeriodId, EntityConditionList additionalConditions, List orderBy, GenericDelegator delegator) throws GenericEntityException { // build condition to get list of ACCOUNT or PROSPECT opportunities for the supplied internal party List combinedConditions = UtilMisc.toList( new EntityExpr("partyIdTo", EntityOperator.EQUALS, internalPartyId), new EntityConditionList( UtilMisc.toList( new EntityExpr("roleTypeIdFrom", EntityOperator.EQUALS, "ACCOUNT"), new EntityExpr("roleTypeIdFrom", EntityOperator.EQUALS, "PROSPECT") ), EntityOperator.OR), EntityUtil.getFilterByDateExpr()); // filter out expired accounts return getOpportunitiesForPartyHelper(customTimePeriodId, combinedConditions, additionalConditions, orderBy, delegator); } private static EntityListIterator getOpportunitiesForPartyHelper(String customTimePeriodId, List combinedConditions, EntityConditionList additionalConditions, List orderBy, GenericDelegator delegator) throws GenericEntityException { // if a time period is supplied, use it as a condition as well if ((customTimePeriodId != null)) { GenericValue timePeriod = delegator.findByPrimaryKeyCache("CustomTimePeriod", UtilMisc.toMap("customTimePeriodId", customTimePeriodId)); if (timePeriod != null) { combinedConditions.add(PeriodWorker.getFilterByPeriodExpr("estimatedCloseDate", timePeriod)); } } // if additional conditions are passed in, add them as well if (additionalConditions != null) { combinedConditions.add(additionalConditions); } EntityConditionList conditionList = new EntityConditionList(combinedConditions, EntityOperator.AND); // fields to select List fields = UtilMisc.toList("salesOpportunityId", "partyIdFrom", "opportunityName", "opportunityStageId", "estimatedAmount", "estimatedCloseDate"); fields.add("estimatedProbability"); fields.add("currencyUomId"); // get the SalesOpportunityAndRoles for these accounts EntityListIterator opportunities = delegator.findListIteratorByCondition("PartyRelationshipAndSalesOpportunity", conditionList, null, fields, orderBy, // fields to order by (can't use fromDate here because it's part of multiple tables => need the alias.fromDate hack) // the first true here is for "specifyTypeAndConcur" // the second true is for a distinct select. Apparently this is the only way the entity engine can do a distinct query new EntityFindOptions(true, EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, true)); return opportunities; } /** * Gets a List of team members for a given opportunity. * @return List of GenericValue PartyToSummaryByRelationship for team members */ public static List getOpportunityTeamMembers(String salesOpportunityId, GenericDelegator delegator) throws GenericEntityException { // At this point, it is sufficient to traverse the directly related primary account // We'll ignore accounts associated through related contacts for now. GenericValue opportunity = delegator.findByPrimaryKey("SalesOpportunity", UtilMisc.toMap("salesOpportunityId", salesOpportunityId)); String accountPartyId = getOpportunityAccountPartyId(opportunity); EntityConditionList conditions = new EntityConditionList(UtilMisc.toList( new EntityExpr("partyIdFrom", EntityOperator.EQUALS, accountPartyId), new EntityExpr("roleTypeIdFrom", EntityOperator.EQUALS, "ACCOUNT"), new EntityExpr("partyRelationshipTypeId", EntityOperator.EQUALS, "ASSIGNED_TO"), EntityUtil.getFilterByDateExpr() ), EntityOperator.AND); return delegator.findByConditionCache("PartyToSummaryByRelationship", conditions, null, null); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -