package com.gx.obe.evaluation.step.calculator.sampling;

import java.math.BigDecimal;
import java.util.List;

import com.gx.obe.evaluation.step.calculator.PriceScoreCalculator;
import com.gx.obe.formula.FilterCountConditionItem;

/** 
 * @Description: 按投标人数量取样
 * @author guoyr
 */
public class CountSamplingImpl implements ISampling{

	/** 
	 * @Description: 取样
	 * @author guoyr 
	 * @param tool  
	 */
	public void start(PriceScoreCalculator tool) {
		List<FilterCountConditionItem> filterCountConditionItemList = tool.getSpecimenParam().getFilterCountConditionList();
		
		// 如果不是全部取样，且按条件一进行取样
		if(tool.getSpecimenParam().isFilterCountByCondition() && null != filterCountConditionItemList && filterCountConditionItemList.size() > 0){
			int totalSupplierCount = tool.getEffectiveSupplierCount();
			for(int i = filterCountConditionItemList.size() -1; i >= 0; i --){
				FilterCountConditionItem filterCountConditionItem = filterCountConditionItemList.get(i);
				boolean isMeetCondition = false;
				if(filterCountConditionItem.isInclude()){
					if(totalSupplierCount >= filterCountConditionItem.getMorethanCount()){
						isMeetCondition = true;
					}
				}else {
					if(totalSupplierCount > filterCountConditionItem.getMorethanCount()){
						isMeetCondition = true;
					}
				}
				// 如果满足条件中设置的筛选条件
				if(isMeetCondition){
					BigDecimal defaultPriceScore = tool.getSpecimenParam().getPriceScore();
					if(filterCountConditionItem.getFilterHighest() > 0){
						for(int j = 0; j < filterCountConditionItem.getFilterHighest(); j++){
							if(j < tool.getEffectiveEvalPriceList().size()){
								if(null != defaultPriceScore){
									// 将最高分设置为默认值
									tool.setDevaultScore(tool.getEffectiveEvalPriceList().get(j), tool.getSpecimenParam().getPriceScore());
								}
							}
						}
					}
					if(filterCountConditionItem.getFilterLowest() > 0){
						
						for(int j = tool.getEffectiveEvalPriceList().size() -1; j >= (tool.getEffectiveEvalPriceList().size() - filterCountConditionItem.getFilterLowest()) ; j--){
							if(j < tool.getEffectiveEvalPriceList().size()){
								if(null != defaultPriceScore){
									// 将最低分设置为默认值
									tool.setDevaultScore(tool.getEffectiveEvalPriceList().get(j), tool.getSpecimenParam().getPriceScore());
								}
							}
						}
					}
					
					// 取掉最高最低
					tool.removeInvalidHighOrLowEvalPrice(filterCountConditionItem.getFilterHighest(), filterCountConditionItem.getFilterLowest());
					break;
				}
			}
		}else {
			// 全部取样
		}
	
	}

}
