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

📄 forecasthelper.java

📁 国外的一套开源CRM
💻 JAVA
字号:
/*
 * 
 * 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.forecast;

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

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.EntityCondition;
import org.ofbiz.entity.condition.EntityConditionList;
import org.ofbiz.entity.condition.EntityExpr;
import org.ofbiz.entity.condition.EntityOperator;
import org.ofbiz.entity.model.DynamicViewEntity;
import org.ofbiz.entity.model.ModelField;
import org.ofbiz.entity.model.ModelKeyMap;

import com.sourcetap.sfa.util.EntityHelper;

/**
 *
 * @author  Chris Maurer
 * @version 1.0
 */
public class ForecastHelper {
	public static final String module = ForecastHelper.class.getName();
	
    /**
     * DOCUMENT ME!
     *
     * @param partyId 
     * @param beginDate 
     * @param endDate 
     * @param delegator 
     *
     * @return 
     *
     * @throws GenericEntityException 
     */
    public static List getForecastForParty(String partyId,
        java.sql.Date beginDate, java.sql.Date endDate,
        GenericDelegator delegator) throws GenericEntityException {
        ArrayList list = new ArrayList();
        List returnList = null;
        
		// select X from Deal d, entity_access ea, team_member tm where ea.entity = "Deal" and ea.partyEntityType = "Team" 
		//  and ea.party_id = tm.team_id and tm.party_id = <partyId> and ea.entity_id = d.deal_id
		DynamicViewEntity dve = EntityHelper.createDynamicViewEntity( delegator, "Deal"); 
		dve.addMemberEntity("EntityAccess", "EntityAccess");
		dve.addMemberEntity("TeamMember", "TeamMember");
		dve.addViewLink("Deal", "EntityAccess", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("dealId", "entityId")));
		dve.addViewLink("EntityAccess", "TeamMember", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("partyId", "teamId")));
		dve.addAlias("EntityAccess", "partyEntityType", null, null, null, null, null);
		dve.addAlias("EntityAccess", "entity", null, null, null, null, null);
		dve.addAlias("TeamMember", "tmPartyId", "partyId", null, null, null, null);
     
		EntityCondition condition = new EntityConditionList(UtilMisc.toList(
				new EntityExpr("entity", EntityOperator.EQUALS, "Deal"),
   			    new EntityExpr("partyEntityType", EntityOperator.EQUALS, "Team"),
				new EntityExpr("tmPartyId", EntityOperator.EQUALS, partyId),
				new EntityExpr("projectedCloseDate", EntityOperator.LESS_THAN_EQUAL_TO, endDate),
				new EntityExpr("projectedCloseDate", EntityOperator.GREATER_THAN_EQUAL_TO, beginDate),
				new EntityExpr("isInForecast", EntityOperator.EQUALS, "1")
				),
				EntityOperator.AND);
                
		return EntityHelper.findByCondition( delegator, dve, condition, UtilMisc.toList("projectedCloseDate") );
    }

    /**
     * DOCUMENT ME!
     *
     * @param partyId 
     * @param beginDate 
     * @param endDate 
     * @param delegator 
     *
     * @return 
     *
     * @throws GenericEntityException 
     */
    public static String getForecastForPartyXML(String partyId,
        java.sql.Date beginDate, java.sql.Date endDate,
        GenericDelegator delegator) throws GenericEntityException {
        return convertListToXML(getForecastForParty(partyId, beginDate,
                endDate, delegator));
    }

    /**
     * DOCUMENT ME!
     *
     * @param list 
     *
     * @return 
     *
     * @throws GenericEntityException 
     */
    public static String convertListToXML(List list)
        throws GenericEntityException {
        Iterator iter = list.iterator();
        StringBuffer returnString = new StringBuffer();
        returnString.append("<?xml version=\"1.0\"?>\n\r");

        GenericValue value = null;
        String entity = "";
        List fields = null;

        while (iter.hasNext()) {
            value = (GenericValue) iter.next();
            entity = value.getModelEntity().getEntityName();
            returnString.append("<" + entity + ">\n\r");
            fields = value.getModelEntity().getFieldsCopy();

            for (int i = 0; i < fields.size(); i++) {
                ModelField field = (ModelField) fields.get(i);
                returnString.append("< ");
                returnString.append(field.getName());
                returnString.append(" type=");
                returnString.append(field.getType());
                returnString.append(" colName=");
                returnString.append(field.getColName());
                returnString.append(" isPk=");
                returnString.append(field.getIsPk());

                returnString.append(" >");

                returnString.append(String.valueOf(value.get(field.getName())));

                returnString.append("</");
                returnString.append(field.getName());
                returnString.append(">");
            }

            returnString.append("</" + entity + ">\n\r");
        }

        return "";
    }
}

⌨️ 快捷键说明

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