⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 activitiesservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        } catch (GenericEntityException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorUpdateActivityFail", locale, module);        }        return ServiceUtil.returnSuccess();    }    /*************************************************************************/    /*                           Find Activities                             */    /*************************************************************************/    public static Map findActivities(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        Locale locale = (Locale) context.get("locale");        String partyId = (String) context.get("partyId");        String salesOpportunityId = (String) context.get("salesOpportunityId");        String custRequestId = (String) context.get("custRequestId");        List pendingOrderByFields = (List) context.get("pendingOrderByFields");        List completedOrderByFields = (List) context.get("completedOrderByFields");                Map results = ServiceUtil.returnSuccess();                // determine which entity to search and the key relationship for searching it        String entityName = null;        EntityExpr keyCondition = null;                if ((partyId != null) && !(partyId.equals(""))) {            entityName = "WorkEffortAndPartyAssign";            keyCondition = new EntityExpr("partyId", EntityOperator.EQUALS, partyId);        } else if ((salesOpportunityId != null) && !(salesOpportunityId.equals(""))) {            entityName = "WorkEffortAndSalesOpportunity";            keyCondition = new EntityExpr("salesOpportunityId", EntityOperator.EQUALS, salesOpportunityId);        } else if ((custRequestId != null) && !(custRequestId.equals(""))) {            entityName = "WorkEffortCustRequestView";            keyCondition = new EntityExpr("custRequestId", EntityOperator.EQUALS, custRequestId);        }                if ((entityName == null) || (keyCondition == null)) {            return UtilCommon.createAndLogServiceError("No parameters specified for crmsfa.findActivities", "CrmErrorFindActivitiesFail", locale, module);        }                try {            List fieldsToSelect = UtilMisc.toList("workEffortId", "workEffortTypeId", "workEffortName", "currentStatusId", "estimatedStartDate", "estimatedCompletionDate");            fieldsToSelect.add("workEffortPurposeTypeId");            fieldsToSelect.add("actualStartDate");            fieldsToSelect.add("actualCompletionDate");                        List pendingActivitiesCondList = UtilMisc.toList(keyCondition);            for (Iterator iter = UtilActivity.ACT_STATUSES_COMPLETED.iterator(); iter.hasNext(); ) {                pendingActivitiesCondList.add(new EntityExpr("currentStatusId", EntityOperator.NOT_EQUAL, (String) iter.next()));            }            if (entityName.equals("WorkEffortAndPartyAssign")) {                pendingActivitiesCondList.add(EntityUtil.getFilterByDateExpr());            }            EntityConditionList pendingActivitiesCond = new EntityConditionList(pendingActivitiesCondList, EntityOperator.AND);            List pendingActivities = delegator.findByCondition(entityName, pendingActivitiesCond, fieldsToSelect, pendingOrderByFields);                        List completedActivitiesCondList = UtilMisc.toList(keyCondition);            for (Iterator iter = UtilActivity.ACT_STATUSES_PENDING.iterator(); iter.hasNext(); ) {                completedActivitiesCondList.add(new EntityExpr("currentStatusId", EntityOperator.NOT_EQUAL, (String) iter.next()));            }            if (entityName.equals("WorkEffortAndPartyAssign")) {                completedActivitiesCondList.add(EntityUtil.getFilterByDateExpr());            }            EntityConditionList completedActivitiesCond = new EntityConditionList(completedActivitiesCondList, EntityOperator.AND);            List completedActivities = delegator.findByCondition(entityName, completedActivitiesCond, fieldsToSelect, completedOrderByFields);                        results.put("pendingActivities", pendingActivities);            results.put("completedActivities", completedActivities);        } catch (GenericEntityException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorFindActivitiesFail", locale, module);        }        return results;    }    /*************************************************************************/    /*                            Helper Methods                             */    /*************************************************************************/    /**     * Helper method to create WorkEffort associations for an internal party (account, contact or lead), a case and an opportunity.     * If you need to remove existing ones, use the method removeAllAssociationsForWorkEffort() first.     *     * @param   reassign    Whether the CAL_OWNER should be overwritten by the userLogin or not     * @return  If an error occurs, returns service error which can be tested with ServiceUtil.isError(), otherwise a service success     */    private static Map createWorkEffortPartyAssociations(DispatchContext dctx, Map context, String workEffortId, String errorLabel, boolean reassign)         throws GenericEntityException, GenericServiceException {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        GenericValue userLogin = (GenericValue) context.get("userLogin");        Locale locale = (Locale) context.get("locale");        Map input = null;        Map serviceResults = null;        // association IDs        String internalPartyId = (String) context.get("internalPartyId");        String salesOpportunityId = (String) context.get("salesOpportunityId");        String custRequestId = (String) context.get("custRequestId");        /*         * The first step is to collect all the ACCOUNT, CONTACT or PROSPECT parties that we should associate with the workEffort.         * This includes those ACCOUNTS and CONTACTS that are associated with the case or opportunity that was specified in the input.         * Then we find the first valid role type for each, which is required for the work effort association. If any of these parties         * has no valid role types, then a bad ID was passed in. This serves to validate the association input.         */        List partyAssociationIds = new ArrayList();        if (internalPartyId != null) partyAssociationIds.add(internalPartyId);        if (salesOpportunityId != null) {            partyAssociationIds.addAll(UtilOpportunity.getOpportunityAccountPartyIds(delegator, salesOpportunityId));            partyAssociationIds.addAll(UtilOpportunity.getOpportunityContactPartyIds(delegator, salesOpportunityId));        }        if (custRequestId != null) {            List parties = UtilCase.getCaseAccountsAndContacts(delegator, custRequestId);            for (Iterator iter = parties.iterator(); iter.hasNext(); ) {                partyAssociationIds.add(((GenericValue) iter.next()).getString("partyId"));            }        }        // now get the roles        List partyAssocRoleTypeIds = new ArrayList();        for (Iterator iter = partyAssociationIds.iterator(); iter.hasNext(); ) {            String partyId = (String) iter.next();            String roleTypeId = PartyHelper.getFirstValidRoleTypeId(partyId, PartyHelper.CLIENT_PARTY_ROLES, delegator);            if (roleTypeId == null) {                return UtilCommon.createAndLogServiceError("Unknown recepient, opportunity or case with ID [" + partyId + "].", errorLabel, locale, module);            }            partyAssocRoleTypeIds.add(roleTypeId);        }        /*         * The remaining task is to create the associations to work effort.         */        if (reassign) {            // expire all associations of type CAL_OWNER for this work effort            List oldOwners = EntityUtil.filterByDate(delegator.findByAnd("WorkEffortPartyAssignment", UtilMisc.toMap("workEffortId", workEffortId, "roleTypeId", "CAL_OWNER")));            for (Iterator iter = oldOwners.iterator(); iter.hasNext(); ) {                GenericValue old = (GenericValue) iter.next();                old.set("thruDate", UtilDateTime.nowTimestamp());                old.store();            }            // first make sure the userlogin has a role CAL_OWNER            input = UtilMisc.toMap("partyId", userLogin.getString("partyId"), "roleTypeId", "CAL_OWNER");            List partyRoles = delegator.findByAnd("PartyRole", input);            if (partyRoles.size() == 0)  {                input.put("userLogin", userLogin);                serviceResults = dispatcher.runSync("createPartyRole", input);                if (ServiceUtil.isError(serviceResults)) {                    return UtilCommon.createAndLogServiceError(serviceResults, errorLabel, locale, module);                }            }            // then create the assignment            input.put("workEffortId", workEffortId);            input.put("userLogin", userLogin);            input.put("roleTypeId", "CAL_OWNER");            input.put("statusId", "PRTYASGN_ASSIGNED");            input.put("availabilityStatusId", context.get("availabilityStatusId")); // add our availability status            serviceResults = dispatcher.runSync("assignPartyToWorkEffort", input);            if (ServiceUtil.isError(serviceResults)) {                return UtilCommon.createAndLogServiceError(serviceResults, errorLabel, locale, module);            }        }        // associate the opportunity with the work effort        if (salesOpportunityId != null) {            input = UtilMisc.toMap("salesOpportunityId", salesOpportunityId, "workEffortId", workEffortId);            GenericValue map = delegator.findByPrimaryKey("SalesOpportunityWorkEffort", input);            if (map == null) {                map = delegator.makeValue("SalesOpportunityWorkEffort", input);                // TODO: created by hand because we don't have a service for this yet                map.create();            }        }        // associate the case with the work effort        if (custRequestId != null) {            serviceResults = dispatcher.runSync("createWorkEffortRequest",                     UtilMisc.toMap("workEffortId", workEffortId, "custRequestId", custRequestId, "userLogin", userLogin));            if (ServiceUtil.isError(serviceResults)) {                return UtilCommon.createAndLogServiceError(serviceResults, errorLabel, locale, module);            }        }         // now for each party association, assign the party and its role to the work effort        if (partyAssociationIds != null) {            Iterator roleIter = partyAssocRoleTypeIds.iterator();            Iterator partyIter = partyAssociationIds.iterator();            while (partyIter.hasNext()) {                String partyId = (String) partyIter.next();                String roleTypeId = (String) roleIter.next();                // if an unexpired existing relationship exists, then skip (this is to avoid duplicates)                List oldAssocs = EntityUtil.filterByDate(delegator.findByAnd("WorkEffortPartyAssignment",                             UtilMisc.toMap("workEffortId", workEffortId, "roleTypeId", roleTypeId, "partyId", partyId)));                if (oldAssocs.size() > 0) continue;                // now create the new one                input = UtilMisc.toMap("workEffortId", workEffortId, "partyId", partyId, "roleTypeId", roleTypeId, "statusId", "PRTYASGN_ASSIGNED");                input.put("userLogin", userLogin);                serviceResults = dispatcher.runSync("assignPartyToWorkEffort", input);                if (ServiceUtil.isError(serviceResults)) {                    return UtilCommon.createAndLogServiceError(serviceResults, errorLabel, locale, module);                }            }        }        return ServiceUtil.returnSuccess();    }    /**     * Helper method to validate the work effort associations that will be created.     */    private static Map validateWorkEffortAssociations(DispatchContext dctx, Map context)         throws GenericEntityException, GenericServiceException {        GenericDelegator delegator = dctx.getDelegator();        GenericValue userLogin = (GenericValue) context.get("userLogin");        Security security = dctx.getSecurity();        // association IDs        String internalPartyId = (String) context.get("internalPartyId");        String salesOpportunityId = (String) context.get("salesOpportunityId");        String custRequestId = (String) context.get("custRequestId");        // if there's an internal party, check if we have update on that party        if (internalPartyId != null) {            String module = CrmsfaSecurity.getSecurityModuleOfInternalParty(internalPartyId, delegator);            if (!CrmsfaSecurity.hasPartyRelationSecurity(security, module, "_UPDATE", userLogin, internalPartyId)) {                return ServiceUtil.returnError("Cannot perform this operation because you do not have permission to update the account, contact or lead with ID [" + internalPartyId + "]");            }        }        // if there's an opportunity, check if we can update it        if (salesOpportunityId != null) {            if (!CrmsfaSecurity.hasOpportunityPermission(security, "_UPDATE", userLogin, salesOpportunityId)) {                return ServiceUtil.returnError("Cannot perform this operation because you do not have permission to update the opportunity with ID [" + salesOpportunityId + "]");            }        }        // if there's an opportunity, check if we can update it        if (custRequestId != null) {            if (!CrmsfaSecurity.hasCasePermission(security, "_UPDATE", userLogin, custRequestId)) {                return ServiceUtil.returnError("Cannot perform this operation because you do not have permission to update the case with ID [" + custRequestId + "]");            }        }        // if we get here, all checks passed        return ServiceUtil.returnSuccess();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -