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

📄 opportunityhelper.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.opportunity;

import java.util.ArrayList;
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.ModelKeyMap;

import com.sourcetap.sfa.util.EntityHelper;


/**
 * DOCUMENT ME!
 *
 */
public class OpportunityHelper {
	public static final String module = OpportunityHelper.class.getName();
    /**
     * DOCUMENT ME!
     *
     * @param productId 
     * @param delegator 
     *
     * @return 
     *
     * @throws GenericEntityException 
     */
    public static List getProductFeaturesForProduct(String productId,
        GenericDelegator delegator) throws GenericEntityException {

        return delegator.findByAnd("ProductFeatureAppl", UtilMisc.toMap("productId", productId), null);
    }

    /**
     * DOCUMENT ME!
     *
     * @param productId 
     * @param delegator 
     *
     * @return 
     *
     * @throws GenericEntityException 
     */
    public static List getFeatureTypesForProduct(String productId,
        GenericDelegator delegator) throws GenericEntityException {
        List productFeaturesList = getProductFeaturesForProduct(productId,
                delegator);

        if ((productFeaturesList != null) && (productFeaturesList.size() == 0)) {
            return new ArrayList();
        }

        GenericValue[] productFeatures = (GenericValue[]) productFeaturesList.toArray(new GenericValue[0]);
        GenericValue productFeature = null;

		DynamicViewEntity dve = EntityHelper.createDynamicViewEntity( delegator, "ProductFeatureType"); 
		dve.addMemberEntity("ProductFeature", "ProductFeature");
		dve.addViewLink("ProductFeatureType", "ProductFeature", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("productFeatureTypeId", "productFeatureTypeId")));
		dve.addAlias("ProductFeature", "productFeatureId", null, null, null, null, null);
     
		List exprList = new ArrayList();
		
		String feature = "";

		for (int i = 0; i < productFeatures.length; i++) {
			productFeature = productFeatures[i];

			if (productFeature != null) {
				feature = productFeature.getString("productFeatureId");

				if (feature != null) {
					exprList.add( new EntityExpr( "productFeatureId", EntityOperator.EQUALS, feature) );
				}
			}
		}
		
		EntityCondition condition = new EntityConditionList( exprList, EntityOperator.OR);

        List productFeatureTypesList = EntityHelper.findByCondition( delegator, dve, condition, null );
        GenericValue[] productFeatureTypes = (GenericValue[]) productFeatureTypesList.toArray(new GenericValue[0]);
        GenericValue productFeatureType = null;
        ArrayList featureTypeList = new ArrayList();

        for (int i = 0; i < productFeatureTypes.length; i++) {
            productFeatureType = productFeatureTypes[i];

            if ((productFeatureType != null) &&
                    !featureTypeList.contains(productFeatureType)) {
                featureTypeList.add(productFeatureType);
            }
        }

        return featureTypeList;
    }

    /**
     * DOCUMENT ME!
     *
     * @param productId 
     * @param productFeatureTypeId 
     * @param delegator 
     *
     * @return 
     *
     * @throws GenericEntityException 
     */
    public static String getProductFeatureDescriptionForProduct(
        String productId, String productFeatureTypeId,
        GenericDelegator delegator) throws GenericEntityException {
        /*
           select
            product_feature.*
           from
            product_feature, product_feature_appl
           where
            product_feature_appl.product_id = 'GZ-2644' and
            product_feature_appl.product_feature_id = product_feature.product_feature_id and
            product_feature.product_feature_type_id = 'SOFTWARE_FEATURE'
        */
        DynamicViewEntity dve = EntityHelper.createDynamicViewEntity( delegator, "ProductFeature"); 
		dve.addMemberEntity("ProductFeatureAppl", "ProductFeatureAppl");
		dve.addViewLink("ProductFeature", "ProductFeatureAppl", Boolean.FALSE, UtilMisc.toList(new ModelKeyMap("productFeatureId", "productFeatureId")));
		dve.addAlias("ProductFeatureAppl", "productId", null, null, null, null, null);
     
		EntityCondition condition = new EntityConditionList(UtilMisc.toList(
				new EntityExpr("productFeatureTypeId", EntityOperator.EQUALS, productFeatureTypeId),
				new EntityExpr("productId", EntityOperator.EQUALS, productId)),
				EntityOperator.AND);
        
	    List pfCol = EntityHelper.findByCondition( delegator, dve, condition, null );
        
        GenericValue[] pfGvs = (GenericValue[]) pfCol.toArray(new GenericValue[0]);

        if ((pfGvs == null) || (pfGvs.length <= 0)) {
            return "";
        } else {
            return pfGvs[0].getString("description");
        }
    }
}

⌨️ 快捷键说明

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