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

📄 activitiesservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            //Find WorkEffort from its Id            GenericValue workEffort = delegator.findByPrimaryKey("WorkEffort", UtilMisc.toMap("workEffortId", workEffortId));                        String workEffortStatus = workEffort.getString("currentStatusId");                        List commEvents = null;            /*             * If WorkEffort status is started then change the status of related CommunicationEvents from entered to pending.             * If WorkEffort status is completed then change the status of related CommunicationEvents from pending to completed.             */            if("TASK_STARTED".equals(workEffortStatus)) {                commEvents = delegator.findByAnd("WorkEffortCommunicationEventView", UtilMisc.toMap("workEffortId", workEffortId, "statusId", "COM_ENTERED"));                                if (commEvents.size() == 0) {                    return ServiceUtil.returnSuccess();                }                for (Iterator iter = commEvents.iterator(); iter.hasNext(); ) {                    GenericValue commEvent = (GenericValue) iter.next();                                        input = UtilMisc.toMap("communicationEventId", commEvent.getString("communicationEventId"), "statusId", "COM_PENDING", "userLogin", userLogin);                    serviceResults = dispatcher.runSync("updateCommunicationEvent", input);                    if (ServiceUtil.isError(serviceResults)) {                        return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorUpdateActivityCommEventFail", locale, module);                    }                }            } else if("TASK_COMPLETED".equals(workEffortStatus)) {                commEvents = delegator.findByAnd("WorkEffortCommunicationEventView", UtilMisc.toMap("workEffortId", workEffortId, "statusId", "COM_PENDING"));                                if (commEvents.size() == 0) {                    return ServiceUtil.returnSuccess();                }                for (Iterator iter = commEvents.iterator(); iter.hasNext(); ) {                    GenericValue commEvent = (GenericValue) iter.next();                                        input = UtilMisc.toMap("communicationEventId", commEvent.getString("communicationEventId"), "statusId", "COM_COMPLETE", "userLogin", userLogin);                    serviceResults = dispatcher.runSync("updateCommunicationEvent", input);                    if (ServiceUtil.isError(serviceResults)) {                        return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorUpdateActivityCommEventFail", locale, module);                    }                }            }                        return ServiceUtil.returnSuccess();        } catch (GenericEntityException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorUpdateActivityCommEventFail", locale, module);        } catch (GenericServiceException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorUpdateActivityCommEventFail", locale, module);        }    }        public static Map logTask(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        Security security = dctx.getSecurity();        GenericValue userLogin = (GenericValue) context.get("userLogin");        Locale locale = (Locale) context.get("locale");        String workEffortPurposeTypeId = (String) context.get("workEffortPurposeTypeId");                try {            // get the actual completion date from the duration (default to now and 1 hour)            Timestamp actualStartDate = (Timestamp) context.get("actualStartDate");            if (actualStartDate == null) actualStartDate = UtilDateTime.nowTimestamp();            Timestamp actualCompletionDate = UtilCommon.getEndTimestamp(actualStartDate, (String) context.get("duration"), locale);            // validate the associations            Map serviceResults = validateWorkEffortAssociations(dctx, context);            if (ServiceUtil.isError(serviceResults)) {                return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorLogTaskFail", locale, module);            }            //input.put("partyIdFrom", context.get("fromPartyId"));            //input.put("roleTypeIdFrom", PartyHelper.getFirstValidRoleTypeId((String) context.get("partyId"), PartyHelper.TEAM_MEMBER_ROLES, delegator));            // create the workeffort from the context data, which results in a workEffortId            ModelService service = dctx.getModelService("createWorkEffort");            Map input = service.makeValid(context, "IN");            input.put("actualCompletionDate", actualCompletionDate);            input.put("workEffortTypeId", "TASK");            input.put("currentStatusId", "TASK_COMPLETED");            serviceResults = dispatcher.runSync("createWorkEffort", input);            if (ServiceUtil.isError(serviceResults)) {                return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorLogTaskFail", locale, module);            }            String workEffortId = (String) serviceResults.get("workEffortId");            // create the associations            serviceResults = createWorkEffortPartyAssociations(dctx, context, workEffortId, "CrmErrorLogTaskFail", true);            if (ServiceUtil.isError(serviceResults)) {                return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorLogTaskFail", locale, module);            }            // assumne inbound            boolean outbound = false;            String partyIdTo = userLogin.getString("partyId");            String partyIdFrom = (String) context.get("internalPartyId");            // then change if it's actually outbound            if (context.get("outbound").equals("Y")) {                outbound = true;                partyIdTo = (String) context.get("internalPartyId");                partyIdFrom = userLogin.getString("partyId");            }            // create a completed comm event with as much information as we have            service = dctx.getModelService("createCommunicationEvent");            input = service.makeValid(context, "IN");            input.put("subject", context.get("workEffortName"));            input.put("entryDate", UtilDateTime.nowTimestamp());            input.put("datetimeStarted", actualStartDate);            input.put("datetimeEnded", actualCompletionDate);            if ("WEPT_TASK_EMAIL".equals(workEffortPurposeTypeId)) {                input.put("contactMechTypeId", "EMAIL_ADDRESS");                input.put("communicationEventTypeId", "EMAIL_COMMUNICATION");            } else if ("WEPT_TASK_PHONE_CALL".equals(workEffortPurposeTypeId)) {                input.put("contactMechTypeId", "TELECOM_NUMBER");                input.put("communicationEventTypeId", "PHONE_COMMUNICATION");            } else {                Debug.logWarning("Work effort purpose type [" + workEffortPurposeTypeId + "] not known, not able to set communication event and contact mech types", module);            }            input.put("statusId", "COM_COMPLETE");            input.put("partyIdTo", partyIdTo);            input.put("partyIdFrom", partyIdFrom);            if (outbound) {                if (partyIdTo != null) input.put("roleTypeIdTo", PartyHelper.getFirstValidInternalPartyRoleTypeId(partyIdTo, delegator));                input.put("roleTypeIdFrom", PartyHelper.getFirstValidTeamMemberRoleTypeId(partyIdFrom, delegator));            } else {                if (partyIdFrom != null) input.put("roleTypeIdFrom", PartyHelper.getFirstValidInternalPartyRoleTypeId(partyIdFrom, delegator));                input.put("roleTypeIdTo", PartyHelper.getFirstValidTeamMemberRoleTypeId(partyIdTo, delegator));            }            serviceResults = dispatcher.runSync("createCommunicationEvent", input);            if (ServiceUtil.isError(serviceResults)) {                return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorLogTaskFail", locale, module);            }            String communicationEventId = (String) serviceResults.get("communicationEventId");            // create an association between the task and comm event (safe even if existing)            input = UtilMisc.toMap("userLogin", userLogin, "communicationEventId", communicationEventId, "workEffortId", workEffortId);            serviceResults = dispatcher.runSync("createCommunicationEventWorkEff", input);            if (ServiceUtil.isError(serviceResults)) {                return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorLogTaskFail", locale, module);            }            Map results = ServiceUtil.returnSuccess();            results.put("workEffortId", workEffortId);            return results;        } catch (IllegalArgumentException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorLogTaskFail", locale, module);        } catch (GenericEntityException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorLogTaskFail", locale, module);        } catch (GenericServiceException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorLogTaskFail", locale, module);        }    }    /*************************************************************************/    /*                  WorkEffortPartyAssignment Services                   */    /*************************************************************************/    public static Map addWorkEffortPartyAssignment(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        Security security = dctx.getSecurity();        GenericValue userLogin = (GenericValue) context.get("userLogin");        Locale locale = (Locale) context.get("locale");        String workEffortId = (String) context.get("workEffortId");        String partyId = (String) context.get("partyId");        try {            // check if userlogin can update this work effort            if (!CrmsfaSecurity.hasActivityPermission(security, "_UPDATE", userLogin, workEffortId)) {                return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module);            }            // if an unexpired existing relationship exists, then skip (this is to avoid duplicates)            List oldAssocs = EntityUtil.filterByDate(delegator.findByAnd("WorkEffortPartyAssignment",                         UtilMisc.toMap("workEffortId", workEffortId, "partyId", partyId)));            if (oldAssocs.size() == 0) {                // assign party as a CAL_ATTENDEE with status assigned to the work effort                Map input = UtilMisc.toMap("workEffortId", workEffortId, "partyId", partyId, "roleTypeId", "CAL_ATTENDEE", "statusId", "PRTYASGN_ASSIGNED",                        "availabilityStatusId", "WEPA_AV_AVAILABLE");                input.put("userLogin", userLogin);                Map serviceResults = dispatcher.runSync("assignPartyToWorkEffort", input);                if (ServiceUtil.isError(serviceResults)) {                    return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorUpdateActivityFail", locale, module);                }            }        } catch (GenericEntityException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorUpdateActivityFail", locale, module);        } catch (GenericServiceException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorUpdateActivityFail", locale, module);        }        return ServiceUtil.returnSuccess();    }    public static Map removeWorkEffortPartyAssignment(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        Security security = dctx.getSecurity();        GenericValue userLogin = (GenericValue) context.get("userLogin");        Locale locale = (Locale) context.get("locale");        String workEffortId = (String) context.get("workEffortId");        String partyId = (String) context.get("partyId");        try {            // check if userlogin can update this work effort            if (!CrmsfaSecurity.hasActivityPermission(security, "_UPDATE", userLogin, workEffortId)) {                return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module);            }            // remove by hand because service in work effort uses fromDate as a required field            List associations = EntityUtil.filterByDate(delegator.findByAnd("WorkEffortPartyAssignment",                        UtilMisc.toMap("workEffortId", workEffortId, "partyId", partyId, "roleTypeId", "CAL_ATTENDEE")));            if (associations.size() == 0) {                return UtilCommon.createAndLogServiceError("Cannot remove party with ID [" + partyId + "]", "CrmErrorUpdateActivityFail", locale, module);            }            for (Iterator iter = associations.iterator(); iter.hasNext(); ) {                GenericValue assoc = (GenericValue) iter.next();                assoc.set("thruDate", UtilDateTime.nowTimestamp());                assoc.store();            }        } catch (GenericEntityException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorUpdateActivityFail", locale, module);        }        return ServiceUtil.returnSuccess();    }    public static Map updateWorkEffortPartyAssignment(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        Security security = dctx.getSecurity();        GenericValue userLogin = (GenericValue) context.get("userLogin");        Locale locale = (Locale) context.get("locale");        String workEffortId = (String) context.get("workEffortId");        String partyId = (String) context.get("partyId");        try {            // check if userlogin can update this work effort            if (!CrmsfaSecurity.hasActivityPermission(security, "_UPDATE", userLogin, workEffortId)) {                return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module);            }            // TODO: done by hand because work effort service requires a permission that's not been added to crmsfa            List associations = EntityUtil.filterByDate(delegator.findByAnd("WorkEffortPartyAssignment",                        UtilMisc.toMap("workEffortId", workEffortId, "partyId", partyId)));            if (associations.size() > 0) {                GenericValue assoc = (GenericValue) associations.get(0);                // input context, don't overwrite if context has null or empty, no name prefixes, set both pks and non-pks                assoc.setAllFields(context, false, null, null);                assoc.store();            }

⌨️ 快捷键说明

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