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

📄 leadsservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 2006  Open Source Strategies, Inc. *  * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. *  * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. *  * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA *//* *  Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org * *  Permission is hereby granted, free of charge, to any person obtaining a *  copy of this software and associated documentation files (the "Software"), *  to deal in the Software without restriction, including without limitation *  the rights to use, copy, modify, merge, publish, distribute, sublicense, *  and/or sell copies of the Software, and to permit persons to whom the *  Software is furnished to do so, subject to the following conditions: * *  The above copyright notice and this permission notice shall be included *  in all copies or substantial portions of the Software. * *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY *  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT *  OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *  THE USE OR OTHER DEALINGS IN THE SOFTWARE. */package com.opensourcestrategies.crmsfa.leads;import java.util.Map;import java.util.List;import java.util.Locale;import java.util.Iterator;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.UtilDateTime;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.util.EntityUtil;import org.ofbiz.service.DispatchContext;import org.ofbiz.service.GenericServiceException;import org.ofbiz.service.LocalDispatcher;import org.ofbiz.service.ServiceUtil;import org.ofbiz.service.ModelService;import org.ofbiz.security.Security;import com.opensourcestrategies.crmsfa.party.PartyHelper;import com.opensourcestrategies.crmsfa.security.CrmsfaSecurity;import com.opensourcestrategies.crmsfa.util.UtilCommon;/** * Leads services. The service documentation is in services_leads.xml. * * @author     <a href="mailto:leon@opensourcestrategies.com">Leon Torres</a> */public class LeadsServices {    public static final String module = LeadsServices.class.getName();    public static Map createLead(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");        if (!security.hasPermission("CRMSFA_LEAD_CREATE", userLogin)) {            return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module);        }        // the net result of creating an lead is the generation of a Lead partyId        String leadPartyId = null;        try {            // set statusId is PTYLEAD_ASSIGNED, because we are assigning to the user down below.            // perhaps a better alternative is to create the lead as NEW, call the reassignLeadResponsibleParty service below, and have it update it to ASSIGNED if not already so.            String statusId = "PTYLEAD_ASSIGNED";                        // create the Party and Person, which results in a partyId            Map input = UtilMisc.toMap("firstName", context.get("firstName"), "lastName", context.get("lastName"));            input.put("firstNameLocal", context.get("firstNameLocal"));            input.put("lastNameLocal", context.get("lastNameLocal"));            input.put("personalTitle", context.get("personalTitle"));            input.put("preferredCurrencyUomId", context.get("currencyUomId"));            input.put("description", context.get("description"));            input.put("birthDate", context.get("birthDate"));            input.put("statusId", statusId); // initial status            Map serviceResults = dispatcher.runSync("createPerson", input);            if (ServiceUtil.isError(serviceResults)) {                return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorCreateLeadFail", locale, module);            }            leadPartyId = (String) serviceResults.get("partyId");            // create a PartyRole for the resulting Lead partyId with roleTypeId = PROSPECT            serviceResults = dispatcher.runSync("createPartyRole", UtilMisc.toMap("partyId", leadPartyId, "roleTypeId", "PROSPECT", "userLogin", userLogin));            if (ServiceUtil.isError(serviceResults)) {                return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorCreateLeadFail", locale, module);            }            // create PartySupplementalData            GenericValue partyData = delegator.makeValue("PartySupplementalData", UtilMisc.toMap("partyId", leadPartyId));            partyData.setNonPKFields(context);            partyData.create();            // create a party relationship between the userLogin and the Lead with partyRelationshipTypeId RESPONSIBLE_FOR            PartyHelper.createNewPartyToRelationship(userLogin.getString("partyId"), leadPartyId, "PROSPECT", "RESPONSIBLE_FOR",                    "LEAD_OWNER", PartyHelper.TEAM_MEMBER_ROLES, true, userLogin, delegator, dispatcher);            // if initial data source is provided, add it            String dataSourceId = (String) context.get("dataSourceId");            if (dataSourceId != null) {                serviceResults = dispatcher.runSync("crmsfa.addLeadDataSource",                         UtilMisc.toMap("partyId", leadPartyId, "dataSourceId", dataSourceId, "userLogin", userLogin));                if (ServiceUtil.isError(serviceResults)) {                    return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorCreateLeadFail", locale, module);                }            }                    } catch (GenericServiceException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorCreateLeadFail", locale, module);        } catch (GenericEntityException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorCreateLeadFail", locale, module);        }        // return the partyId of the newly created Lead        Map results = ServiceUtil.returnSuccess();        results.put("partyId", leadPartyId);        return results;    }    public static Map updateLead(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 leadPartyId = (String) context.get("partyId");                 // make sure userLogin has CRMSFA_LEAD_UPDATE permission for this lead        if (!CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_LEAD", "_UPDATE", userLogin, leadPartyId)) {            return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module);        }        try {            // get the party            GenericValue party = delegator.findByPrimaryKey("Party", UtilMisc.toMap("partyId", leadPartyId));            if (party == null) {                return UtilCommon.createAndLogServiceError("CrmErrorUpdateLeadFail", locale, module);            }            // change status if passed in statusId is different            String statusId = (String) context.get("statusId");            if ((statusId != null) && (!statusId.equals(party.getString("statusId")))) {                Map serviceResults = dispatcher.runSync("setPartyStatus", UtilMisc.toMap("partyId", leadPartyId, "statusId", statusId, "userLogin", userLogin));                if (ServiceUtil.isError(serviceResults)) {                    return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorUpdateLeadFail", locale, module);                }            }             // update the Party and Person            Map input = UtilMisc.toMap("partyId", leadPartyId, "firstName", context.get("firstName"), "lastName", context.get("lastName"));            input.put("firstNameLocal", context.get("firstNameLocal"));            input.put("lastNameLocal", context.get("lastNameLocal"));            input.put("personalTitle", context.get("personalTitle"));            input.put("preferredCurrencyUomId", context.get("currencyUomId"));            input.put("description", context.get("description"));            input.put("birthDate", context.get("birthDate"));            input.put("userLogin", userLogin);            Map serviceResults = dispatcher.runSync("updatePerson", input);            if (ServiceUtil.isError(serviceResults)) {                return UtilCommon.createAndLogServiceError(serviceResults, "CrmErrorUpdateLeadFail", locale, module);            }            // update PartySupplementalData            GenericValue partyData = delegator.findByPrimaryKey("PartySupplementalData", UtilMisc.toMap("partyId", leadPartyId));            if (partyData == null) {                // create a new one                partyData = delegator.makeValue("PartySupplementalData", UtilMisc.toMap("partyId", leadPartyId));                partyData.create();            }            partyData.setNonPKFields(context);            partyData.store();        } catch (GenericServiceException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorUpdateLeadFail", locale, module);        } catch (GenericEntityException e) {            return UtilCommon.createAndLogServiceError(e, "CrmErrorUpdateLeadFail", locale, module);        }        return ServiceUtil.returnSuccess();    }    public static Map convertLead(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 leadPartyId = (String) context.get("leadPartyId");        String accountPartyId = (String) context.get("accountPartyId");        // make sure userLogin has CRMSFA_LEAD_UPDATE permission for this lead        if (!CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_LEAD", "_UPDATE", userLogin, leadPartyId)) {            return UtilCommon.createAndLogServiceError("CrmErrorPermissionDenied", locale, module);

⌨️ 快捷键说明

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