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

📄 accounteventprocessor.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.account;

import java.sql.Timestamp;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Vector;

import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.condition.EntityConditionList;
import org.ofbiz.entity.condition.EntityExpr;
import org.ofbiz.entity.condition.EntityOperator;
import org.ofbiz.entity.model.ModelEntity;

import com.sourcetap.sfa.activity.ActivityEventProcessor;
import com.sourcetap.sfa.address.AddressHelper;
import com.sourcetap.sfa.attachment.AbstractAttachmentEP;
import com.sourcetap.sfa.contact.ContactEventProcessor;
import com.sourcetap.sfa.event.DataMatrix;
import com.sourcetap.sfa.event.GenericEventProcessor;
import com.sourcetap.sfa.forecast.ForecastEventProcessor;
import com.sourcetap.sfa.opportunity.OpportunityEventProcessor;
import com.sourcetap.sfa.replication.GenericReplicator;
import com.sourcetap.sfa.security.EntityAccessEventProcessor;
import com.sourcetap.sfa.security.EntityAccessHelper;
import com.sourcetap.sfa.security.SecurityLinkInfo;
import com.sourcetap.sfa.security.SecurityWrapper;
import com.sourcetap.sfa.ui.UIScreenSectionEntity;
import com.sourcetap.sfa.util.QueryInfo;
import com.sourcetap.sfa.util.UserInfo;


/**
 * DOCUMENT ME!
 *
 */
public class AccountEventProcessor extends GenericEventProcessor {
	public static final String module = AccountEventProcessor.class.getName();

    /**
     * DOCUMENT ME!
     *
     * @param userInfo 
     * @param delegator 
     * @param dataMatrix 
     *
     * @return 
     */
    protected int preUpdate(UserInfo userInfo, GenericDelegator delegator,
        DataMatrix dataMatrix) {

        Timestamp now = new Timestamp(Calendar.getInstance().getTime().getTime());

        // Just process the first row for now.
        GenericValue accountGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
                0);
        GenericValue addressGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
                1);
        GenericValue partyGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
                2);

        String accountId = accountGV.getString("accountId");

        // Update the address if it is new.
        String addressId = addressGV.getString("addressId");
        String mailingAddress = AddressHelper.getMailingAddress( addressGV.getString("mailingAddress"), addressGV.getString("address1"), addressGV.getString("address2"), addressGV.getString("address3"));
        addressGV.set("mailingAddress", mailingAddress);

        if ((addressId == null) || addressId.equals("")) {
            addressId = GenericReplicator.getNextSeqId("Address", delegator);
            addressGV.set("addressId", addressId);
            addressGV.set("addressOwnerId", accountId);
            addressGV.set("addressOwnerType", "Account");
            addressGV.set("isPrimary", "Y");
            addressGV.set("createdDate", now);
            addressGV.set("createdBy", userInfo.getPartyId());
        }

        // Set the time stamps.
        accountGV.set("modifiedDate", now);
        addressGV.set("modifiedDate", now);

        // Store the current user's party ID in the "modified by" field.
        accountGV.set("modifiedBy", userInfo.getPartyId());
        addressGV.set("modifiedBy", userInfo.getPartyId());

        // Set the account owner ID if it is empty.
        String accountOwnerId = accountGV.getString("accountOwnerId");

        if ((accountOwnerId == null) || accountOwnerId.equals("")) {
            accountGV.set("accountOwnerId", userInfo.getPartyId());
        }

        // Update team, role, and access information.
        SecurityWrapper.updateRoleInformation(dataMatrix, 0, userInfo,
            accountOwnerId, "Account", accountId, delegator);

        Debug.logVerbose("[preUpdate] Account GV: " + accountGV.toString(),module);
        Debug.logVerbose("[preUpdate] Address GV: " + addressGV.toString(),module);
        Debug.logVerbose("[preUpdate] Party GV: " + partyGV.toString(),module);

        return STATUS_CONTINUE;
    }

    /**
     * DOCUMENT ME!
     *
     * @param userInfo 
     * @param delegator 
     * @param dataMatrix 
     *
     * @return 
     */
    protected int preInsert(UserInfo userInfo, GenericDelegator delegator,
        DataMatrix dataMatrix) {

        // Just process the first row for now.
        GenericValue accountGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
                0);
        GenericValue addressGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
                1);
        GenericValue partyGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
                2);

        String accountId = GenericReplicator.getNextSeqId("Party", delegator);

        // Account key has been auto-generated. Just read it.
        accountGV.set("accountId", accountId);

        String addressId = GenericReplicator.getNextSeqId("Address", delegator);
        addressGV.set("addressId", addressId);
        addressGV.set("addressOwnerId", accountId);
        addressGV.set("addressOwnerType", "Account");
        addressGV.set("isPrimary", "Y");

        String mailingAddress = AddressHelper.getMailingAddress( addressGV.getString("mailingAddress"), addressGV.getString("address1"), addressGV.getString("address2"), addressGV.getString("address3"));
        addressGV.set("mailingAddress", mailingAddress);

        // Mark the party ID the same as the account ID.
        partyGV.set("partyId", accountId);

        // Set the time stamps.
        Timestamp now = new Timestamp(Calendar.getInstance().getTime().getTime());
        accountGV.set("createdDate", now);
        addressGV.set("createdDate", now);
        accountGV.set("modifiedDate", now);
        addressGV.set("modifiedDate", now);

        // Store the current user ID in the "modified by" field.
        accountGV.set("createdBy", userInfo.getPartyId());
        addressGV.set("createdBy", userInfo.getPartyId());
        accountGV.set("modifiedBy", userInfo.getPartyId());
        addressGV.set("modifiedBy", userInfo.getPartyId());

        // Set the account owner ID if it is empty.
        String accountOwnerId = accountGV.getString("accountOwnerId");

        if ((accountOwnerId == null) || accountOwnerId.equals("")) {
            accountOwnerId = userInfo.getPartyId();
            accountGV.set("accountOwnerId", accountOwnerId);
        }

        // Add team, role, and access information.
        SecurityWrapper.addRoleInformation(dataMatrix, 0, userInfo,
            accountOwnerId, "Account", accountId, delegator);

        Debug.logVerbose("[preInsert] Account GV: " + accountGV.toString(),module);
        Debug.logVerbose("[preInsert] Address GV: " + addressGV.toString(),module);
        Debug.logVerbose("[preInsert] Party GV: " + partyGV.toString(),module);

        return STATUS_CONTINUE;
    }

    /**
     * DOCUMENT ME!
     *
     * @param userInfo 
     * @param entityNameList 
     * @param delegator 
     * @param dataMatrix 
     *
     * @return 
     */
    protected int postCreate(UserInfo userInfo, List entityNameList,
        GenericDelegator delegator, DataMatrix dataMatrix) {

        // Get the empty generic values.
        GenericValue accountGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
                0);
        GenericValue addressGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
                1);
        GenericValue partyGV = dataMatrix.getCurrentBuffer().getGenericValue(0,
                2);

        // Set default values on the new record so they will be displayed for the user to see before saving.
        // Account owner ID
        accountGV.set("accountOwnerId", userInfo.getPartyId());
        accountGV.set("accountTypeId", "cust");

        addressGV.set("country", "USA");

        // Status
        accountGV.set("statusId", "A");

        return STATUS_CONTINUE;
    }

    /**
     * DOCUMENT ME!
     *
     * @param userInfo 
     * @param delegator 
     * @param originatingEntityName 
     * @param entityGV 
     *
     * @return 
     */
    public int deleteAllRelated(UserInfo userInfo, GenericDelegator delegator,
        String originatingEntityName, GenericValue entityGV) {

        int status = STATUS_CONTINUE;

        // Delete related addresses.
        status = deleteOneRelated(userInfo, delegator, entityGV, "", "Address",
                originatingEntityName, new GenericEventProcessor());

⌨️ 快捷键说明

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