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

📄 leadhelper.java

📁 国外的一套开源CRM
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * 
 * Copyright (c) 2004 SourceTap - www.sourcetap.com
 *
 *  The contents of this file are subject to the SourceTap Public License 
 * ("License"); You may not use this file except in compliance with the 
 * License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
 * Software distributed under the License is distributed on an  "AS IS"  basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 */

package com.sourcetap.sfa.lead;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Vector;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilCache;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericPK;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.condition.EntityComparisonOperator;
import org.ofbiz.entity.condition.EntityConditionList;
import org.ofbiz.entity.condition.EntityExpr;
import org.ofbiz.entity.condition.EntityOperator;

import com.sourcetap.sfa.security.SecurityLinkInfo;
import com.sourcetap.sfa.security.SecurityWrapper;
import com.sourcetap.sfa.util.EmailProperties;
import com.sourcetap.sfa.util.SimpleExpression;
import com.sourcetap.sfa.util.StringHelper;
import com.sourcetap.sfa.util.UserInfo;


/**
 *
 *
 *
 */
public class LeadHelper {
    private static LeadHelper globalLeadHelper = null;
	public static final String module = LeadHelper.class.getName();

    private GenericDelegator delegator = null;

    /** Hashtable to cache lead assignment rules.
       * For each PartyAttributePK there is a String in the cache specifying the preference value.
       * In this way the cache speeds things up whether or not the user has a particular preference.
       */
    public UtilCache leadAssignemtRuleCache = new UtilCache(
            "LeadAssignmentRuleCache");

    public LeadHelper() {
    }

    public LeadHelper(GenericDelegator delegator) {
        this.delegator = delegator;
    }

    /**
     * DOCUMENT ME!
     *
     * @param emailTo 
     * @param smsTo 
     * @param leadGV 
     *
     * @return 
     */
    public static String sendLeadNotifyEmail(String emailTo, String smsTo,
        GenericValue leadGV) {
        try {
            EmailProperties emailProperties = EmailProperties.getInstance();

            String SMTP_SERVER = emailProperties.relayHost;
            boolean LEAD_NOTIFY_SMTP_DEBUG = emailProperties.smtpDebug;
            String LEAD_NOTIFY_LINK_URL = emailProperties.notifyLink;
            boolean LEAD_NOTIFY_EMAIL_SEND = emailProperties.sendEmail;
            String LEAD_NOTIFY_EMAIL_FROM = emailProperties.sendEmailFrom;
            String LEAD_NOTIFY_EMAIL_CC = "";
            boolean LEAD_NOTIFY_SMS_SEND = emailProperties.sendSMS;
            String LEAD_NOTIFY_SMS_FROM = emailProperties.sendSMSFrom;
            String LEAD_NOTIFY_SMS_CC = "";

            /*                        final String SMTP_SERVER = UtilProperties.getPropertyValue(sfaPropertiesUrl, "smtp.relay.host");
                                    final String LEAD_NOTIFY_SMTP_DEBUG = UtilProperties.getPropertyValue(sfaPropertiesUrl, "lead.notify.smtp.debug");
                                    final String LEAD_NOTIFY_LINK_URL = UtilProperties.getPropertyValue(sfaPropertiesUrl, "lead.notify.link.url");
                                    final String LEAD_NOTIFY_EMAIL_SEND = UtilProperties.getPropertyValue(sfaPropertiesUrl, "lead.notify.email.send");
                                    final String LEAD_NOTIFY_EMAIL_FROM = UtilProperties.getPropertyValue(sfaPropertiesUrl, "lead.notify.email.from");
                                    final String LEAD_NOTIFY_EMAIL_CC = UtilProperties.getPropertyValue(sfaPropertiesUrl, "lead.notify.email.cc");
                                    final String LEAD_NOTIFY_SMS_SEND = UtilProperties.getPropertyValue(sfaPropertiesUrl, "lead.notify.sms.send");
                                    final String LEAD_NOTIFY_SMS_FROM = UtilProperties.getPropertyValue(sfaPropertiesUrl, "lead.notify.sms.from");
                                    final String LEAD_NOTIFY_SMS_CC = UtilProperties.getPropertyValue(sfaPropertiesUrl, "lead.notify.sms.cc");
            */
            String leadId = (leadGV.getString("leadId") == null) ? ""
                                                                 : leadGV.getString(
                    "leadId");
            String companyName = (leadGV.getString("companyName") == null) ? ""
                                                                           : leadGV.getString(
                    "companyName");
            String firstName = (leadGV.getString("firstName") == null) ? ""
                                                                       : leadGV.getString(
                    "firstName");
            String lastName = (leadGV.getString("lastName") == null) ? ""
                                                                     : leadGV.getString(
                    "lastName");

            try {
                Properties props = new Properties();

                props.put("mail.smtp.host", SMTP_SERVER);

                Session session = Session.getInstance(props, null);

                if (LEAD_NOTIFY_SMTP_DEBUG) {
                    session.setDebug(true);
                } else {
                    session.setDebug(false);
                }

                if (LEAD_NOTIFY_EMAIL_SEND && !emailTo.equals("")) {
                    try {
                        StringBuffer emailContent = new StringBuffer();
                        emailContent.append(
                            "A new sales lead has been assigned to you.<BR>\n");
                        emailContent.append("<BR>\n");

                        if (UtilValidate.isNotEmpty(LEAD_NOTIFY_LINK_URL)) {
                            emailContent.append(
                                "Click the link below to view the lead.<BR>\n");
                            emailContent.append("<BR>\n");
                            emailContent.append("<A HREF=\"" +
                                LEAD_NOTIFY_LINK_URL + leadId + "\">");
                        }

                        emailContent.append(firstName + " " + lastName);

                        if (!companyName.equals("")) {
                            emailContent.append(" (" + companyName + ")");
                        }

                        if (UtilValidate.isNotEmpty(LEAD_NOTIFY_LINK_URL)) {
                            emailContent.append("</A>\n");
                        }

                        MimeMessage emailMessage = new MimeMessage(session);
                        emailMessage.setFrom(new InternetAddress(
                                LEAD_NOTIFY_EMAIL_FROM));
                        emailMessage.addRecipients(Message.RecipientType.TO,
                            emailTo);

                        if (UtilValidate.isNotEmpty(LEAD_NOTIFY_EMAIL_CC)) {
                            emailMessage.addRecipients(Message.RecipientType.CC,
                                LEAD_NOTIFY_EMAIL_CC);
                        }

                        emailMessage.setSubject("New Sales Lead - " +
                            firstName + " " + lastName);
                        emailMessage.addHeaderLine(
                            "MIME-Version: 1.0\nContent-type: text/html; charset=us-ascii\n");
                        emailMessage.setContent(emailContent.toString(),
                            "text/html");
                        Transport.send(emailMessage);
                    } catch (Exception e) {
                        Debug.logError("Error e-mailing lead notification: " +
                            e.getLocalizedMessage(), "sendLeadNotifyEmail");

                        return "Error e-mailing lead notification: " +
                        e.getLocalizedMessage();
                    }
                }

                if (LEAD_NOTIFY_SMS_SEND && !smsTo.equals("")) {
                    try {
                        StringBuffer smsContent = new StringBuffer();
                        smsContent.append(firstName + " " + lastName);

                        if (!companyName.equals("")) {
                            smsContent.append(" (" + companyName + ")");
                        }

                        MimeMessage smsMessage = new MimeMessage(session);
                        smsMessage.setFrom(new InternetAddress(
                                LEAD_NOTIFY_SMS_FROM));

                        if (UtilValidate.isNotEmpty(LEAD_NOTIFY_SMS_CC)) {
                            smsMessage.addRecipients(Message.RecipientType.CC,
                                LEAD_NOTIFY_SMS_CC);
                        }

                        smsMessage.addRecipients(Message.RecipientType.TO, smsTo);
                        smsMessage.setSubject("New Sales Lead");
                        smsMessage.setContent(smsContent.toString(),
                            "text/plain");
                        Transport.send(smsMessage);
                    } catch (Exception e) {
                        Debug.logError("Error sending sms lead notification: " +
                            e.getLocalizedMessage(), "sendLeadNotifyEmail");

                        return "Error sending sms lead notification: " +
                        e.getLocalizedMessage();
                    }
                }
            } catch (Exception e) {
                Debug.logError("Error preparing to send lead notification: " +
                    e.getLocalizedMessage(), "sendLeadNotifyEmail");

                return "Error preparing to send lead notification: " +
                e.getLocalizedMessage();
            }
        } catch (RuntimeException e) {
            Debug.logError("Error e-mailing lead notification: " +
                e.getLocalizedMessage(), "sendLeadNotifyEmail");

            return "Error e-mailing lead notification: " +
            e.getLocalizedMessage();
        } catch (Error e) {
            Debug.logError("Error e-mailing lead notification: " +
                e.getLocalizedMessage(),  module);

            return "Error e-mailing lead notification: " +
            e.getLocalizedMessage();
        }

        return "success";
    }

    /**
     * DOCUMENT ME!
     *
     * @return 
     */
    public GenericDelegator getDelegator() {
        return delegator;
    }

    /**
     * DOCUMENT ME!
     *
     * @param delegator 
     */
    public void setDelegator(GenericDelegator delegator) {
        this.delegator = delegator;
    }

    /**
     * DOCUMENT ME!
     *
     * @param delegator 
     *
     * @return 
     */
    public static LeadHelper getInstance(GenericDelegator delegator) {
        if (globalLeadHelper == null) //don't want to block here
         {
            synchronized (LeadHelper.class) {
                //must check if null again as one of the blocked threads can still enter
                if (globalLeadHelper == null) {
                    globalLeadHelper = new LeadHelper(delegator);
                }
            }
        }

        return globalLeadHelper;
    }


	public List findMatchingAccounts(String leadCompany, UserInfo userInfo)
	{

		try {

⌨️ 快捷键说明

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