package com.gx.obe.evaluation.step.composite;

import java.math.BigDecimal;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;

import org.eclipse.swt.SWT;
import org.eclipse.swt.core.MessageDialog;
import org.eclipse.swt.core.widgets.ESepator;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

import com.gx.obe.ColorConstants;
import com.gx.obe.business.entity.SupplierEvaluationStep;
import com.gx.obe.business.enumeration.SupplierEnum;
import com.gx.obe.business.vo.RecommonedFactor;
import com.gx.obe.common.icons.IconsActivator;
import com.gx.obe.components.core.I18NEnum;
import com.gx.obe.components.core.enumeration.CommonEnum;
import com.gx.obe.components.core.enumeration.EvaluationStepEnum;
import com.gx.obe.components.core.enumeration.TenderProjectEnum;
import com.gx.obe.components.core.util.MoneyUtils;
import com.gx.obe.config.utils.PropertiesUtils;
import com.gx.obe.evaluation.step.inter.IRecommonedTable;
import com.gx.obe.message.Messages;
import com.gx.obe.util.utils.BigDecimalUtils;
import com.gx.obe.util.utils.ListSortUtils;
import com.gx.obe.util.utils.LogUtils;
import com.gx.obe.util.utils.NumberFormatUtils;
import com.gx.obe.util.utils.NumericChineseUtils;
import com.gx.obe.util.utils.ObjectUtils;
import com.gx.obe.util.utils.StringUtils;
import com.gx.obe.web.entity.Supplier;
import com.gx.obe.web.entity.SupplierEvaluationResult;
import com.gx.obe.web.entity.SupplierOpeningResult;
import com.gx.obe.web.entity.auth.AuthUser;
import com.gx.obe.web.entity.evaluation.EvaluationStep;
import com.gx.obe.web.entity.expert.ExpertEvaluationResult;
import com.gx.obe.web.entity.tender.TenderProjectEntity;
import com.gx.obe.web.entity.tender.TenderProjectRuleEntity;
import com.gx.obe.web.service.ProjectRuleService;
import com.gx.obe.web.service.SupplierEvaluationStepService;
import com.gx.obe.web.service.evaluation.EvaluationStepService;
import com.gx.obe.web.service.expert.ExpertEvaluationResultService;
import com.gx.obe.web.service.expert.ExpertEvaluationStepService;
import com.gx.obe.web.service.expert.ExpertService;
import com.swtdesigner.ResourceManager;
import com.swtdesigner.SWTResourceManager;

import de.kupzog.ktable.KTable;
import de.kupzog.ktable.SWTX;
import de.kupzog.ktable.editors.KTableCellEditorCheckbox2;
import de.kupzog.ktable.editors.KTableCellEditorGCombo;
import de.kupzog.ktable.model.CommonKtableCModel;
import de.kupzog.ktable.renderers.CellAlignmentRender;
import de.kupzog.ktable.renderers.CellContentRender;
import de.kupzog.ktable.renderers.CellEditContentRender;
import de.kupzog.ktable.renderers.CellEditorRender;
import de.kupzog.ktable.renderers.CellRender;
import de.kupzog.ktable.renderers.CheckableCellRenderer;
import de.kupzog.ktable.renderers.FixedWrapCellRenderer;
import de.kupzog.ktable.renderers.TextWrapCellRenderer;

/**
 * @Description: 推荐
 * @author guoyr
 */
public class RecommonedEvaluationTableComposite extends Composite implements IRecommonedTable {
	
	private Map<String, SupplierEvaluationStep> supplierEvaluationStepBillResultMap;
	private Map<String, SupplierEvaluationStep> supplierEvaluationStepCreditResultMap;
	private Map<String, List<RecommonedFactor>> supplierRecommonedFactorListMap;
	private List<SupplierEvaluationResult> supplierEvaluationResultList = new ArrayList<SupplierEvaluationResult>();
	private int entryType = 0;// 入围方式
	
	private ExpertService expertService ;
	private ProjectRuleService projectRuleService;
	private EvaluationStepService evaluationStepService = new EvaluationStepService();
	private ExpertEvaluationStepService expertEvaluationStepService ;
	private ExpertEvaluationResultService expertEvaluationResultService;
	private SupplierEvaluationStepService supplierEvaluationStepService;
	
	private Label notLabel;
	private Composite recommonedContentComposite;
	private Combo defaultEvalOpinionCombo;
	private StyledText evaluationOpinion_text;
	
	private TenderProjectEntity tenderProjectEntity;
	private TenderProjectRuleEntity tenderProjectRuleEntity;
	private EvaluationStep evaluationStep;
	private AuthUser CURRENT_USER;
	private List<Supplier> supplierList1;
	
	private String supplierName;
	private String billStepName;
	private String creditStepName;
	
	private boolean hasScoreEvalNode;
	private boolean hasPriceEvalNode;
	private boolean hasBillEvalNode;
	private boolean hasCreditEvalNode;
	
	private boolean isCostPerformance;
	private boolean isQualifiedMethod = false;
	private boolean isPreEvaluation;
	private boolean hasRankExpertCountCal = false;
	private int fixRowCount;
	private int scoreRound;
	
	{
		LogUtils.logClass(RecommonedEvaluationTableComposite.class);
	}
	
	/**
	 * @author chenxw
	 * @param parentShell
	 * @param style
	 */
	public RecommonedEvaluationTableComposite(Composite parentShell, int style) {
		super(parentShell, style);
		GridLayout gridLayout = new GridLayout(1, false);
		gridLayout.verticalSpacing = 0;
		gridLayout.horizontalSpacing = 0;
		gridLayout.marginHeight = 0;
		gridLayout.marginWidth = 0;
		setLayout(gridLayout);
		setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		
		Composite notLabelComposite = new Composite(this, SWT.NONE);
		notLabelComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
		notLabelComposite.setLayout(new GridLayout(1, false));
		
		notLabel = new Label(notLabelComposite, SWT.WRAP);
		notLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		notLabel.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		notLabel.setForeground(ColorConstants.NOTE_TIPS_COLOR);
		notLabel.setText("请在最右侧选择要推荐的供应商！");
		
		Composite container = new Composite(this, SWT.NONE);
		container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		GridLayout gl_container = new GridLayout(1, false);
		gl_container.marginHeight = 1;
		gl_container.marginWidth = 1;
		gl_container.verticalSpacing = 0;
		gl_container.horizontalSpacing = 0;
		container.setLayout(gl_container);
		container.setBackground(ColorConstants.BORDER_LINE_COLOR);
		
		Composite supplierComposite = new Composite(container, SWT.NONE);
		supplierComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		GridLayout gl_supplierComposite = new GridLayout(1, false);
		gl_supplierComposite.horizontalSpacing = 0;
		gl_supplierComposite.marginHeight = 0;
		gl_supplierComposite.verticalSpacing = 0;
		gl_supplierComposite.marginWidth = 0;
		supplierComposite.setLayout(gl_supplierComposite);
		supplierComposite.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		
		recommonedContentComposite = new Composite(supplierComposite, SWT.NONE);
		FillLayout fl_composite_2 = new FillLayout(SWT.HORIZONTAL);
		fl_composite_2.marginWidth = 1;
		recommonedContentComposite.setLayout(fl_composite_2);
		recommonedContentComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		ESepator tableSplabel = new ESepator(container, SWT.SEPARATOR | SWT.HORIZONTAL);
		tableSplabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		tableSplabel.setBackground(ColorConstants.SEP_LIGHT_COLOR);
		
		Composite composite_1 = new Composite(container, SWT.NONE);
		composite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		GridLayout gl_composite_1 = new GridLayout(3, false);
		gl_composite_1.marginHeight = 2;
		gl_composite_1.marginWidth = 1;
		composite_1.setLayout(gl_composite_1);
//		composite_1.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		composite_1.setBackgroundImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/title_bg.png"));
		
		CLabel label_1 = new CLabel(composite_1, SWT.NONE);
		label_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		label_1.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.BOLD));
		label_1.setForeground(ColorConstants.NOTE_TIPS_COLOR);
		label_1.setText(Messages.Title_evaluationOpinion);
		
		Label label_2 = new Label(composite_1, SWT.NONE);
		label_2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_2.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		label_2.setForeground(ColorConstants.NOTE_TIPS_COLOR);
		label_2.setText(Messages.Title_commonOpinions + "：");
		
		defaultEvalOpinionCombo = new Combo(composite_1, SWT.READ_ONLY);
		defaultEvalOpinionCombo.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.NORMAL));
		defaultEvalOpinionCombo.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		defaultEvalOpinionCombo.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				evaluationOpinionCreater();
			}
		});
		GridData gd_defaultEvalOpinionCombo = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
		gd_defaultEvalOpinionCombo.widthHint = 100;
		defaultEvalOpinionCombo.setLayoutData(gd_defaultEvalOpinionCombo);
		
//		ESepator splabel = new ESepator(container, SWT.SEPARATOR | SWT.HORIZONTAL);
//		splabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
//		splabel.setBackground(ColorConstants.SEP_LIGHT_COLOR);
		
		evaluationOpinion_text = new StyledText(container, SWT.WRAP | SWT.V_SCROLL);
		evaluationOpinion_text.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		GridData gd_evaluationOpinion_text = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
		gd_evaluationOpinion_text.minimumHeight = 100;
		gd_evaluationOpinion_text.heightHint = 100;
		evaluationOpinion_text.setLayoutData(gd_evaluationOpinion_text);
		evaluationOpinion_text.setFont(SWTResourceManager.getFont("宋体", 10, SWT.NORMAL));
		evaluationOpinion_text.setTextLimit(1000);
		evaluationOpinion_text.setIndent(25);
		supplierEvaluationStepService = new SupplierEvaluationStepService();
		expertService = new ExpertService();
		expertEvaluationStepService = new ExpertEvaluationStepService();
		expertEvaluationResultService = new ExpertEvaluationResultService();
	}
	
	/**
	 * @Description: 刷新评标界面
	 * @author chenxw
	 * @param tenderProjectEntity
	 * @param _projectRule
	 * @param evaluationStep
	 * @param curUser
	 * @param _supplierList
	 */
	public void refresh(TenderProjectEntity tenderProjectEntity, TenderProjectRuleEntity _projectRule, EvaluationStep evaluationStep, AuthUser curUser, List<Supplier> _supplierList) {
		this.tenderProjectEntity = tenderProjectEntity;
		this.tenderProjectRuleEntity = _projectRule;
		this.evaluationStep = evaluationStep;
		this.CURRENT_USER = curUser;
		if(null == projectRuleService){
			projectRuleService = new ProjectRuleService();
		}
		refreshData();
//		// 修改评标专家的评审记录
//		expertEvaluationStepService.updateExpertEvaluationStatus(CommonEnum.IN_PROGRESS, tenderProjectEntity.getId(), evaluationStep.getId(), CURRENT_USER.getId());
		tenderProjectRuleEntity = projectRuleService.getProjectRule(tenderProjectEntity.getId());
		if (null == tenderProjectRuleEntity) tenderProjectRuleEntity = new TenderProjectRuleEntity();
		if (TenderProjectEnum.MIN_METHOD.equals(tenderProjectRuleEntity.getEvalMethodType())) {
			if (null == tenderProjectRuleEntity.getOrderFirst() || tenderProjectRuleEntity.getOrderFirst().length() == 0) {
				tenderProjectRuleEntity.setOrderFirst(TenderProjectEnum.EVALUATION_PRICE);
				if(hasBillEvalNode){
					tenderProjectRuleEntity.setOrderFirst(TenderProjectEnum.EVAL_TOTAL_SCORE);
				}
			}
		} else if (TenderProjectEnum.METHOD_COST_PERFORMANCE.equals(tenderProjectRuleEntity.getEvalMethodType())) {
			if (null == tenderProjectRuleEntity.getOrderFirst() || tenderProjectRuleEntity.getOrderFirst().length() == 0) {
				tenderProjectRuleEntity.setOrderFirst(TenderProjectEnum.COST_PERFORMANCE);
			}
		}
		
		if (TenderProjectEnum.COST_PERFORMANCE.equals(tenderProjectRuleEntity.getOrderFirst())) {
			//京能屏蔽性价比
//			isCostPerformance = true;
			isQualifiedMethod = true;
		}
		if (TenderProjectEnum.PHASE_TYPE_PRE.equals(tenderProjectEntity.getPhaseType())) {
			isPreEvaluation = true;
		}
		if (TenderProjectEnum.ENTRY_TYPE_FIRST_CHOICE.equals(tenderProjectEntity.getEnterType())) {
			entryType = 1;
		} else if (TenderProjectEnum.ENTRY_TYPE_ENTRY.equals(tenderProjectEntity.getEnterType())) {
			entryType = 2;
		}
		// 计算供应商最终得分汇总时,是否去除最高分和最低分
		boolean isRemoveTotalMaxAndMinScore = false;
		// 记录评标步骤下是否存在多个专家
		boolean stepHasMoreExpert = false;
		List<EvaluationStep> scoreEvaluationStepList = null;
		List<EvaluationStep> billEvaluationStepList = null;
		List<EvaluationStep> creditEvaluationStepList = null;
		List<EvaluationStep> priceEvaluationStepList = null;
		supplierRecommonedFactorListMap = new HashMap<String, List<RecommonedFactor>>();
		
		scoreEvaluationStepList = evaluationStepService.getEvaluationStepListByType(tenderProjectEntity.getId(), com.gx.obe.components.core.enumeration.EvaluationStepEnum.DETAIL);
		if (null != scoreEvaluationStepList && scoreEvaluationStepList.size() > 0) {
			hasScoreEvalNode = true;
		}
		if (hasScoreEvalNode && null != evaluationStep.getSummaryType() && evaluationStep.getSummaryType().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.SUMMARY_REMOVE_MAX_MIN)) {
			isRemoveTotalMaxAndMinScore = true;
		}

		billEvaluationStepList = evaluationStepService.getEvaluationStepListByType(tenderProjectEntity.getId(), com.gx.obe.components.core.enumeration.EvaluationStepEnum.BILL);
		if (null != billEvaluationStepList && billEvaluationStepList.size() > 0) {
			supplierEvaluationStepBillResultMap = new HashMap<String, SupplierEvaluationStep>();
			hasBillEvalNode = true;
			if (billEvaluationStepList.size() == 1) {
				billStepName = billEvaluationStepList.get(0).getStepName();
			} else {
				billStepName = PropertiesUtils.getEnum(I18NEnum.BILL_FACTOR, "清单") + "得分";
			}
		}
		
		priceEvaluationStepList = evaluationStepService.getEvaluationStepListByType(tenderProjectEntity.getId(), com.gx.obe.components.core.enumeration.EvaluationStepEnum.PRICE);
		if (null != priceEvaluationStepList && priceEvaluationStepList.size() > 0) {
			hasPriceEvalNode = true;
		}
		
		creditEvaluationStepList = evaluationStepService.getEvaluationStepListByType(tenderProjectEntity.getId(), com.gx.obe.components.core.enumeration.EvaluationStepEnum.CREDIT);
		if (null != creditEvaluationStepList && creditEvaluationStepList.size() > 0) {
			supplierEvaluationStepCreditResultMap = new HashMap<String, SupplierEvaluationStep>();
			hasCreditEvalNode = true;
			if (creditEvaluationStepList.size() == 1) {
				creditStepName = creditEvaluationStepList.get(0).getStepName();
			} else {
				creditStepName = PropertiesUtils.getEnum(I18NEnum.CREDIT_FACTOR, "综合信用") + "得分";
			}
		}
		
		for (int supplierIndex = 0; supplierIndex < _supplierList.size(); supplierIndex++) {
			Supplier supplier = _supplierList.get(supplierIndex);
			List<RecommonedFactor> recommonedFactorList = new ArrayList<RecommonedFactor>();
			// 查询投标人所有评标步骤的评标结果
			List<SupplierEvaluationStep> supplierEvaluationStepList = supplierEvaluationStepService.getSupplierEvaluationStepByTenderIdAndSupplierId(tenderProjectEntity.getId(),supplier.getId());
			
			// 供应商最终得分汇总
			BigDecimal supplierEvaluationFinalScoreSum = null;
			// 供应商得分汇总
			BigDecimal supplierEvaluationScoreSum = null;
			
			// 价格评标步骤
			BigDecimal priceEvaluationScore = null;
			BigDecimal priceEvaluationFinalScore = null;
			if (null != priceEvaluationStepList && priceEvaluationStepList.size() > 0) {
				for (EvaluationStep priceEvaluationStep : priceEvaluationStepList) {
					
					// 供应商当前评标节点终得分平均分
					BigDecimal stepAvgFinalScore = null;
					// 供应商当前评标节点平均分
					BigDecimal stepAvgScore = null;
					
					SupplierEvaluationStep supplierEvaluationStep = null;
					// 如果当前评标步骤评审完成，则以供应商当前评标步骤的结果为主（有可能去除了最高分或最低分）
					if (null != supplierEvaluationStepList && null != priceEvaluationStep.getStepStatus() && priceEvaluationStep.getStepStatus().equals(CommonEnum.COMPLETE)) {
						for (SupplierEvaluationStep stepResult : supplierEvaluationStepList) {
							if (stepResult.getStepId().equals(priceEvaluationStep.getId())) {
								supplierEvaluationStep = stepResult;
								break;
							}
						}
					}
					if (null != supplierEvaluationStep) {
						stepAvgScore = supplierEvaluationStep.getEvaluationScore();
						stepAvgFinalScore = supplierEvaluationStep.getEvaluationFinalScore();
					} else {
						BigDecimal[] stepAvgResult = expertEvaluationResultService.getSupplierStepAvgResult(tenderProjectEntity.getId(), priceEvaluationStep.getId(), supplier.getId(), false);
						if (null != stepAvgResult) {
							stepAvgScore = stepAvgResult[0];
							stepAvgFinalScore = stepAvgResult[1];
						}
					}
					
					priceEvaluationScore = BigDecimalUtils.add(priceEvaluationScore, stepAvgScore);
					priceEvaluationFinalScore = BigDecimalUtils.add(priceEvaluationFinalScore, stepAvgFinalScore);
				}
			}
			SupplierEvaluationResult supplierEvaluationResult = supplier.getSupplierEvaluationResult();
			if (null == supplierEvaluationResult) {
				supplierEvaluationResult = new SupplierEvaluationResult();
			}
			supplierEvaluationResult.setPriceScore(priceEvaluationScore);
			supplierEvaluationResult.setPriceFinalScore(priceEvaluationFinalScore);
			supplierEvaluationResult.setTenderId(tenderProjectEntity.getId());
			supplierEvaluationResult.setSupplierId(supplier.getId());
			supplier.setSupplierEvaluationResult(supplierEvaluationResult);
			
			// 记每位专家的打分汇总(只用于存在按总分去除最高分和最低分时)
			Map<String, BigDecimal> expertEvaluationFinalScoreMap = null;
			List<String> expertIdList = null;
			if (isRemoveTotalMaxAndMinScore) {
				expertIdList = new ArrayList<String>();
				expertEvaluationFinalScoreMap = new HashMap<String, BigDecimal>();
			}
			// 所有打分评标步骤
			if (null != scoreEvaluationStepList && scoreEvaluationStepList.size() > 0) {
				for (EvaluationStep scoreEvaluationStep : scoreEvaluationStepList) {
					SupplierEvaluationStep supplierEvaluationStep = null;
					// 如果当前评标步骤评审完成，则以供应商当前评标步骤的结果为主（有可能去除了最高分或最低分）
					if (null != supplierEvaluationStepList && null != scoreEvaluationStep.getStepStatus() && scoreEvaluationStep.getStepStatus().equals(CommonEnum.COMPLETE)) {
						for (SupplierEvaluationStep stepResult : supplierEvaluationStepList) {
							if (stepResult.getStepId().equals(scoreEvaluationStep.getId())) {
								supplierEvaluationStep = stepResult;
								break;
							}
						}
					}
					// 供应商当前评标节点终得分平均分
					BigDecimal stepAvgEvaluationFinalScoreSum = null;
					// 供应商当前评标节点平均分
					BigDecimal stepAvgEvaluationScoreSum = null;
					if (null != scoreEvaluationStep.getSummaryType() && scoreEvaluationStep.getSummaryType().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.SUMMARY_SCORE_BY_QUALIFIED)) {
						if (null != supplierEvaluationStep) {
							stepAvgEvaluationScoreSum = supplierEvaluationStep.getEvaluationScore();
							stepAvgEvaluationFinalScoreSum = supplierEvaluationStep.getEvaluationFinalScore();
						}
						// 当前打分步骤专家的得分
						RecommonedFactor recommonedFactor = new RecommonedFactor(scoreEvaluationStep, null, scoreEvaluationStep.getStepName());
						recommonedFactor.setSupplierEvaluationStep(supplierEvaluationStep);
						recommonedFactorList.add(recommonedFactor);
					} else {
						boolean evalByGroup = scoreEvaluationStep.getEvaluationParamByKey(com.gx.obe.components.core.enumeration.EvaluationStepEnum.PARAM_EVAL_BY_GROUP, Boolean.class);
						if (evalByGroup) {
							scoreEvaluationStep.setSummaryType(com.gx.obe.components.core.enumeration.EvaluationStepEnum.SUMMARY_BY_FACTOR_SUM);
						}
						List<AuthUser> userList = expertService.getEvaluationStepUserList(tenderProjectEntity.getId(), scoreEvaluationStep);
						int expertCount = 0;
						if (null != userList && userList.size() > 0) {
							// 供应商当前评标节点所有专家的最终得分汇总
							BigDecimal expertEvaluationFinalScoreSum = null;
							// 供应商当前评标节点所有专家的得分汇总
							BigDecimal expertEvaluationScoreSum = null;
							List<ExpertEvaluationResult> expertEvaluationResultList = expertEvaluationResultService.getSupplierStepAllExpertEvaluationResultList(tenderProjectEntity.getId(), scoreEvaluationStep.getId(), supplier.getId());
							
							for (int i = 0; i < userList.size(); i++) {
								AuthUser user = userList.get(i);
								if (isRemoveTotalMaxAndMinScore && !expertIdList.contains(user.getId())) {
									expertIdList.add(user.getId());
								}
								RecommonedFactor recommonedFactor = new RecommonedFactor(scoreEvaluationStep, user, userList.size() == 1 ? scoreEvaluationStep.getStepName() : user.getUserName());
								if (i == 0 && userList.size() > 1) {
									stepHasMoreExpert = true;
									int mergerCount = userList.size();
									if (scoreEvaluationStepList.size() > 1 || hasPriceEvalNode) {
										mergerCount++;
									}
									if (hasRankExpertCountCal) {
										mergerCount++;
									}
									recommonedFactor.setMergerCount(mergerCount);
								}
								
								ExpertEvaluationResult expertEvaluationResult = null;
								for (ExpertEvaluationResult result : expertEvaluationResultList) {
									if (result.getUserId().equals(user.getId())) {
										expertEvaluationResult = result;
										break;
									}
								}
								if (null != expertEvaluationResult && null != expertEvaluationResult.getEvaluationScore()) {
									expertEvaluationFinalScoreSum = BigDecimalUtils.add(expertEvaluationFinalScoreSum, expertEvaluationResult.getEvaluationFinalScore());
									expertEvaluationScoreSum = BigDecimalUtils.add(expertEvaluationScoreSum, expertEvaluationResult.getEvaluationScore());
									
									if (isRemoveTotalMaxAndMinScore) {
										// 记录每们专家的 评分汇总(只用于存在按总分去除最高分和最低分时)
										BigDecimal expertFinalScoreSum = expertEvaluationFinalScoreMap.get(user.getId());
										expertFinalScoreSum = BigDecimalUtils.add(expertFinalScoreSum, expertEvaluationResult.getEvaluationFinalScore());
										expertEvaluationFinalScoreMap.put(user.getId(), expertFinalScoreSum);
									}
									expertCount++;
								}
								recommonedFactor.setExpertEvaluationResult(expertEvaluationResult);
								recommonedFactorList.add(recommonedFactor);
							}
							
							// 默认以所有专家的平均分作为当前评标步骤的得分
							if (null != expertEvaluationScoreSum && expertCount > 0) {
								stepAvgEvaluationScoreSum = BigDecimalUtils.div(expertEvaluationScoreSum, new BigDecimal(expertCount), scoreRound);
								stepAvgEvaluationFinalScoreSum = BigDecimalUtils.div(expertEvaluationFinalScoreSum, new BigDecimal(expertCount), scoreRound);
							}
							String scoreSumName = "平均分";
							if(null != scoreEvaluationStep.getSummaryType() && scoreEvaluationStep.getSummaryType().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.SUMMARY_BY_FACTOR_SUM)){
								scoreSumName = Messages.TotalScore;
							}
							
							// 如果当前评标步骤评审完成，则以供应商当前评标步骤的结果为主（有可能去除了最高分或最低分）
							if(null != supplierEvaluationStep && CommonEnum.COMPLETE.equals(scoreEvaluationStep.getStepStatus())){
								stepAvgEvaluationScoreSum = supplierEvaluationStep.getEvaluationScore();
								stepAvgEvaluationFinalScoreSum = supplierEvaluationStep.getEvaluationFinalScore();
							} else {
								// 如果还没有完成评审，默认所有专家的评均分
								supplierEvaluationStep = new SupplierEvaluationStep();
								BigDecimal[] stepAvgResult = null;
								if (expertCount > 1 && null != scoreEvaluationStep.getSummaryType() && scoreEvaluationStep.getSummaryType().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.SUMMARY_IGNORE_OVER_WARNING_CORE)) {
									// 如果取掉超出最小偏差率
									stepAvgResult = expertEvaluationResultService.getSupplierStepAvgResult(tenderProjectEntity.getId(), scoreEvaluationStep.getId(), supplier.getId(), false);
									if (null != stepAvgResult) {
										stepAvgEvaluationScoreSum = stepAvgResult[0];
										stepAvgEvaluationFinalScoreSum = stepAvgResult[1];
									} else {
										stepAvgResult = new BigDecimal[] { stepAvgEvaluationScoreSum, stepAvgEvaluationFinalScoreSum };
									}
									BigDecimal warningRange = scoreEvaluationStep.getEvaluationParamByKey(com.gx.obe.components.core.enumeration.EvaluationStepEnum.PARAM_WARNING_RANGE, BigDecimal.class);
									if (null != warningRange && warningRange.compareTo(BigDecimal.ZERO) != 0) {
										// 转换为百分率
										warningRange = BigDecimalUtils.div(warningRange, new BigDecimal(100));
										
										if (null != warningRange) {
											int noIgnoreCount = 0;
											BigDecimal supplierNoignoreEvaluationScoreSum = BigDecimal.ZERO;
											BigDecimal supplierNoignoreEvaluationFinalScoreSum = BigDecimal.ZERO;
											BigDecimal expertMinScore = null;
											BigDecimal expertMinFinalScore = null;
											for (ExpertEvaluationResult expertEvaluationResult : expertEvaluationResultList) {
												if (null != expertEvaluationResult.getEvaluationScore()) {
													BigDecimal percentValue = BigDecimal.ZERO;
													if (null != stepAvgEvaluationScoreSum && stepAvgEvaluationScoreSum.compareTo(BigDecimal.ZERO) != 0) {
														percentValue = BigDecimalUtils.div(BigDecimalUtils.sub(expertEvaluationResult.getEvaluationScore(), stepAvgEvaluationScoreSum), stepAvgEvaluationScoreSum).abs();//偏差率绝对值
													}
													if (percentValue.compareTo(warningRange) < 0) {
														supplierNoignoreEvaluationScoreSum = BigDecimalUtils.add(supplierNoignoreEvaluationScoreSum, expertEvaluationResult.getEvaluationScore());
														supplierNoignoreEvaluationFinalScoreSum = BigDecimalUtils.add(supplierNoignoreEvaluationFinalScoreSum, expertEvaluationResult.getEvaluationFinalScore());
														noIgnoreCount++;
														
													}
													// 记录分项的最小值 
													if (null == expertMinScore || expertEvaluationResult.getEvaluationScore().compareTo(expertMinScore) < 0) {
														expertMinScore = expertEvaluationResult.getEvaluationScore();
														expertMinFinalScore = expertEvaluationResult.getEvaluationFinalScore();
													}
												}
											}
											if (noIgnoreCount > 0) {
												stepAvgResult[0] = BigDecimalUtils.div(supplierNoignoreEvaluationScoreSum, new BigDecimal(noIgnoreCount), tenderProjectRuleEntity.getScoreRoundIntVal());
												stepAvgResult[1] = BigDecimalUtils.div(supplierNoignoreEvaluationFinalScoreSum, new BigDecimal(noIgnoreCount), tenderProjectRuleEntity.getScoreRoundIntVal());
											} else {
												boolean useMinScore = evaluationStep.getEvaluationParamByKey(EvaluationStepEnum.PARAM_IGNORE_OVER_WARNING_USE_MIN, Boolean.class, false);
												if(useMinScore) {
													stepAvgResult[0] = null != expertMinScore ? expertMinScore : BigDecimal.ZERO;
													stepAvgResult[1] = null != expertMinFinalScore ? expertMinFinalScore : BigDecimal.ZERO;
												}
											}
										}
									}
									
								} else if (null != scoreEvaluationStep.getSummaryType() && scoreEvaluationStep.getSummaryType().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.SUMMARY_REMOVE_FACTOR_MAX_MIN)) {
									stepAvgResult = expertEvaluationResultService.getSupplierStepAvgResultByFactor(tenderProjectEntity.getId(), scoreEvaluationStep.getId(), supplier.getId(), expertCount > 2 ? true : false);
								} else if (null != scoreEvaluationStep.getSummaryType() && scoreEvaluationStep.getSummaryType().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.SUMMARY_BY_FACTOR_SUM)) {
									scoreSumName = Messages.TotalScore;
									stepAvgResult = expertEvaluationResultService.getSupplierStepAvgResultByFactor(tenderProjectEntity.getId(), scoreEvaluationStep.getId(), supplier.getId(), false);
								} else {
									boolean removeMaxAndMin = null != scoreEvaluationStep.getSummaryType() && scoreEvaluationStep.getSummaryType().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.SUMMARY_REMOVE_MAX_MIN);
									stepAvgResult = expertEvaluationResultService.getSupplierStepAvgResult(tenderProjectEntity.getId(), scoreEvaluationStep.getId(), supplier.getId(), expertCount > 2 ? removeMaxAndMin : false);
								}
								
								if (null != stepAvgResult) {
									stepAvgEvaluationScoreSum = BigDecimalUtils.round(stepAvgResult[0], scoreRound);
									stepAvgEvaluationFinalScoreSum = BigDecimalUtils.round(stepAvgResult[1], scoreRound);
								}
								
								supplierEvaluationStep.setEvaluationScore(stepAvgEvaluationScoreSum);
								supplierEvaluationStep.setEvaluationFinalScore(stepAvgEvaluationFinalScoreSum);
							}
							if (userList.size() > 1 && (scoreEvaluationStepList.size() > 1 || hasPriceEvalNode)) {
								RecommonedFactor recommonedFactor = new RecommonedFactor(scoreEvaluationStep, null, scoreSumName);
								recommonedFactor.setSupplierEvaluationStep(supplierEvaluationStep);
								recommonedFactorList.add(recommonedFactor);
							}
							if (hasRankExpertCountCal) {
								RecommonedFactor recommonedFactor = new RecommonedFactor(scoreEvaluationStep, null, "排名情况");
								recommonedFactor.setRankExpertCount(getRankExpertCount(expertEvaluationResultList));
								recommonedFactorList.add(recommonedFactor);
							}
						} else {
							// 当前打分步骤专家的得分
							RecommonedFactor recommonedFactor = new RecommonedFactor(scoreEvaluationStep, null, scoreEvaluationStep.getStepName());
							recommonedFactor.setSupplierEvaluationStep(supplierEvaluationStep);
							recommonedFactorList.add(recommonedFactor);
						}
					}
					supplierEvaluationScoreSum = BigDecimalUtils.add(supplierEvaluationScoreSum, stepAvgEvaluationScoreSum);
					supplierEvaluationFinalScoreSum = BigDecimalUtils.add(supplierEvaluationFinalScoreSum, stepAvgEvaluationFinalScoreSum);
				}
			}
			
			// 清单评审
			SupplierEvaluationStep billSupplierEvaluationStep = getSubScoreSupplierEvaluationStep(supplier, supplierEvaluationStepList, billEvaluationStepList);
			if (null != billSupplierEvaluationStep) {
				supplierEvaluationStepBillResultMap.put(supplier.getId(), billSupplierEvaluationStep);
				supplierEvaluationScoreSum = BigDecimalUtils.add(supplierEvaluationScoreSum, billSupplierEvaluationStep.getEvaluationScore());
				supplierEvaluationFinalScoreSum = BigDecimalUtils.add(supplierEvaluationFinalScoreSum, billSupplierEvaluationStep.getEvaluationFinalScore());
			}
			
			// 信用评审
			SupplierEvaluationStep creditSupplierEvaluationStep = getSubScoreSupplierEvaluationStep(supplier, supplierEvaluationStepList, creditEvaluationStepList);
			if (null != creditSupplierEvaluationStep) {
				supplierEvaluationStepCreditResultMap.put(supplier.getId(), creditSupplierEvaluationStep);
				supplierEvaluationScoreSum = BigDecimalUtils.add(supplierEvaluationScoreSum, creditSupplierEvaluationStep.getEvaluationScore());
				supplierEvaluationFinalScoreSum = BigDecimalUtils.add(supplierEvaluationFinalScoreSum, creditSupplierEvaluationStep.getEvaluationFinalScore());
			}
			
			// 供应商最终得分是评分的汇总+价格得分
			supplierEvaluationScoreSum = BigDecimalUtils.add(supplierEvaluationScoreSum, supplierEvaluationResult.getPriceScore());
			supplierEvaluationFinalScoreSum = BigDecimalUtils.add(supplierEvaluationFinalScoreSum, supplierEvaluationResult.getPriceFinalScore());
			
			supplierEvaluationFinalScoreSum = BigDecimalUtils.round(supplierEvaluationFinalScoreSum, scoreRound);
			supplierEvaluationResult.setEvaluationFinalScore(supplierEvaluationFinalScoreSum);
			supplierEvaluationScoreSum = BigDecimalUtils.round(supplierEvaluationScoreSum, scoreRound);
			supplierEvaluationResult.setEvaluationScore(supplierEvaluationScoreSum);
			
			// 如果打分专家超过2人,且去除一个汇总的最高分和最低分
			if (isRemoveTotalMaxAndMinScore && expertIdList.size() > 2) {
				BigDecimal minScore = BigDecimal.ZERO;
				BigDecimal maxScore = BigDecimal.ZERO;
				BigDecimal finalScoreSum = null;
				boolean hasMin = false;
				
				for (Entry<String, BigDecimal> expertFinalScoreEntry : expertEvaluationFinalScoreMap.entrySet()) {
					BigDecimal expertFinalScore = expertFinalScoreEntry.getValue();
					expertFinalScore = BigDecimalUtils.add(expertFinalScore, supplierEvaluationResult.getPriceFinalScore());
					if (null != expertFinalScore) {
						if(!hasMin){
							minScore = expertFinalScore;
							hasMin = true;
						}
						if (expertFinalScore.compareTo(minScore) < 0) {
							minScore = expertFinalScore;
						}
						if (expertFinalScore.compareTo(maxScore) > 0) {
							maxScore = expertFinalScore;
						}
						finalScoreSum = BigDecimalUtils.add(finalScoreSum, expertFinalScore);
					}
					
				}
				if (null != finalScoreSum) {
					finalScoreSum = BigDecimalUtils.sub(finalScoreSum, maxScore);
					finalScoreSum = BigDecimalUtils.sub(finalScoreSum, minScore);
					supplierEvaluationResult.setEvaluationFinalScore(BigDecimalUtils.div(finalScoreSum, new BigDecimal(expertIdList.size() - 2), scoreRound));
				}
			}
			supplierRecommonedFactorListMap.put(supplier.getId(), recommonedFactorList);
		}
		
		if (stepHasMoreExpert) {
			fixRowCount = 2;
			if (scoreEvaluationStepList.size() == 1 && !hasPriceEvalNode) {
				fixRowCount = 1;
			}
			
		}
		// 排序后设置默认推荐
//		if (tenderProjectRuleEntity.getRecommendCountNotNull() < 1) {
//			tenderProjectRuleEntity.setRecommendCount(1);
//		}
		refreshSupplierList(_supplierList);
		sortSupplier();
		drawEvaluationTable();
		
		refreshDefaultEvalOpinionCombo();
		
	}
	
	/**
	 * @Description: 获取得分求和供应商评审步骤
	 * @author chenxw
	 * @param supplier
	 * @param supplierEvaluationStepList
	 * @param evaluationStepList
	 * @return
	 */
	private SupplierEvaluationStep getSubScoreSupplierEvaluationStep(Supplier supplier, List<SupplierEvaluationStep> supplierEvaluationStepList, List<EvaluationStep> evaluationStepList) {
		SupplierEvaluationStep supplierEvaluationStep = null;
		if (null != evaluationStepList && evaluationStepList.size() > 0) {
			if (evaluationStepList.size() > 1) {
				supplierEvaluationStep = new SupplierEvaluationStep();
				supplierEvaluationStep.setSupplierId(supplier.getId());
			}
			for (EvaluationStep evaluationStep : evaluationStepList) {
				if (null != evaluationStep.getStepStatus() && evaluationStep.getStepStatus().equals(CommonEnum.COMPLETE)) {
					for (SupplierEvaluationStep stepResult : supplierEvaluationStepList) {
						if (stepResult.getStepId().equals(evaluationStep.getId())) {
							if (null != supplierEvaluationStep) {
								supplierEvaluationStep.setEvaluationScore(BigDecimalUtils.add(supplierEvaluationStep.getEvaluationScore(), stepResult.getEvaluationScore()));
								supplierEvaluationStep.setEvaluationFinalScore(BigDecimalUtils.add(supplierEvaluationStep.getEvaluationFinalScore(), stepResult.getEvaluationFinalScore()));
							} else {
								supplierEvaluationStep = stepResult;
							}
							break;
						}
					}
				}
			}
		}
		return supplierEvaluationStep;
	}
	
	private void refreshData() {
		supplierName = com.gx.obe.components.core.I18N.getString(I18NEnum.SUPPLIERNAME, tenderProjectEntity.getTenderType());
		
		hasScoreEvalNode = false;
		hasPriceEvalNode = false;
		hasBillEvalNode = false;
		hasCreditEvalNode = false;
		
		isCostPerformance = false;
		isPreEvaluation = false;
		
		fixRowCount = 1;
		scoreRound = tenderProjectRuleEntity.getScoreRoundIntVal();
	}
	
	private void refreshDefaultEvalOpinionCombo() {
		defaultEvalOpinionCombo.add("   ", 0);
		defaultEvalOpinionCombo.add(Messages.Template + 1, 1);
		defaultEvalOpinionCombo.add(Messages.Template + 2, 2);
		if (StringUtils.isEmpty(tenderProjectEntity.getEvaluationOpinion())) {
			defaultEvalOpinionCombo.select(0);
//			evaluationOpinionCreater();
		} else {
			defaultEvalOpinionCombo.select(0);
			evaluationOpinion_text.setText(tenderProjectEntity.getEvaluationOpinion());
		}
	}
	
	/**
	 * @Description: 刷新供应商列表
	 * @author chenxw
	 * @param supplierList1
	 */
	private void refreshSupplierList(List<Supplier> _supplierList) {
		supplierList1 = new ArrayList<Supplier>();
		BigDecimal evalMinScore = evaluationStep.getEvaluationParamByKey(com.gx.obe.components.core.enumeration.EvaluationStepEnum.EVALUATION_MIN_SCORE, BigDecimal.class);
		for (Supplier supplier : _supplierList) {
			SupplierEvaluationResult supplierEvaluationResult = supplier.getSupplierEvaluationResult();
			supplierEvaluationResult.setAccessment(com.gx.obe.components.core.enumeration.EvaluationStepEnum.QUALIFIED);
			BigDecimal evaluationFinalScore = null != supplier.getSupplierEvaluationResult() ? supplier.getSupplierEvaluationResult().getEvaluationFinalScore() : null;
			if (null != evalMinScore && (null == evaluationFinalScore || evaluationFinalScore.compareTo(evalMinScore) < 0)) {
				supplierEvaluationResult.setAccessment(com.gx.obe.components.core.enumeration.EvaluationStepEnum.UNQUALIFIED);
				supplierEvaluationResultList.add(supplierEvaluationResult);
			} else {
				supplierList1.add(supplier);
			}
		}
	}
	
	/**
	 * @Description: 获取排名专家数量
	 * @author chenxw
	 * @param expertEvaluationResultList
	 * @return
	 */
	private String getRankExpertCount(List<ExpertEvaluationResult> expertEvaluationResultList) {
		Map<Integer, Integer> map = new TreeMap<Integer, Integer>();
		for (ExpertEvaluationResult expertEvaluationResult : expertEvaluationResultList) {
			int sortNo = expertEvaluationResult.getSortNoIntValue();
			if (sortNo != 0) {
				if (map.containsKey(sortNo)) {
					map.put(sortNo, map.get(sortNo) + 1);
				} else {
					map.put(sortNo, 1);
				}
			}
		}
		StringBuilder rankExpertCount = new StringBuilder();
		for (int sortNo : map.keySet()) {
			if (rankExpertCount.length() != 0) {
				rankExpertCount.append("、");
			}
			rankExpertCount.append(String.valueOf(sortNo));
			rankExpertCount.append("×");
			rankExpertCount.append(String.valueOf(map.get(sortNo)));
		}
		return rankExpertCount.toString();
	}
	
	/**
	 * @Description: 实现评审表格
	 * @author guoyr
	 */
	private void drawEvaluationTable() {
		
		if (supplierList1.isEmpty()) return;
		
		KTable resultKTable = new KTable(recommonedContentComposite, SWTX.AUTO_SCROLL | SWT.FULL_SELECTION | SWTX.FILL_WITH_LASTCOL | SWTX.EDIT_ON_KEY);
		resultKTable.setColorLeftBorder(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		resultKTable.setColorTopBorder(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		resultKTable.setColorRightBorder(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		
		final List<RecommonedFactor> recommonedFactorTitleList = supplierRecommonedFactorListMap.get(supplierList1.get(0).getId());
		
		int contentCol = isQualifiedMethod ? 1 : 2;//排序&推荐
		if (hasScoreEvalNode) {
			contentCol += recommonedFactorTitleList.size();//得分汇总
		}
		if (hasBillEvalNode) {
			contentCol += 1;//清单得分
		}
		if (hasCreditEvalNode) {
			contentCol += 1;//信用得分
		}
		if (hasPriceEvalNode) {
			contentCol += 1;//价格得分
		}
		boolean showFinalScore = false;
		if (hasScoreEvalNode || hasPriceEvalNode || hasBillEvalNode) {
			contentCol += 1;//最终得分\
			showFinalScore = true;
		}
		if (isCostPerformance) {
			contentCol += 1;//性价比
		}
		boolean showEvaluationPrice = false;
		if (!isPreEvaluation) {
			contentCol += 1;//评标价
			showEvaluationPrice = true;
			if(hasBillEvalNode && !hasPriceEvalNode){
				showEvaluationPrice = false;
				contentCol -= 1;//评标价
			}
		}
		final CommonKtableCModel commKTableModel = new CommonKtableCModel(resultKTable, fixRowCount, 1, supplierList1.size(), contentCol);
		commKTableModel.setColumnMaxWidth(0, 250);
		
		// 评标价|价格得分|最终得分|性价比|排序|推荐
		int scoreStartCol = hasScoreEvalNode ? recommonedFactorTitleList.size() : 0;
		// 评标价|价格得分|最终得分|性价比|排序|推荐
		final int evalBillFinalScoreCol = hasBillEvalNode ? (++scoreStartCol) : 0;
		final int creditScoreCol = hasCreditEvalNode ? (++scoreStartCol) : 0;
		final int evalPriceCol = showEvaluationPrice ? (++scoreStartCol) : 0;
		final int evalPriceFinalScoreCol = hasPriceEvalNode ? (++scoreStartCol) : 0;
		final int evaluationFinalScore = showFinalScore ? (++scoreStartCol) : 0;
		final int costPerformance = isCostPerformance ? (++scoreStartCol) : 0;
		final int sortNoCol = isQualifiedMethod ? 0 : commKTableModel.getColCount() -2;
		final int recommonedCol = commKTableModel.getColCount() - 1;
		if (fixRowCount > 1) {
			commKTableModel.addRowSpan(0, 0, fixRowCount);
			if (evalBillFinalScoreCol > 0) {
				commKTableModel.addRowSpan(0, evalBillFinalScoreCol, fixRowCount);
			}
			if (creditScoreCol > 0) {
				commKTableModel.addRowSpan(0, creditScoreCol, fixRowCount);
			}
			if (evalPriceCol > 0) {
				commKTableModel.addRowSpan(0, evalPriceCol, fixRowCount);
			}
			if (evalPriceFinalScoreCol > 0) {
				commKTableModel.addRowSpan(0, evalPriceFinalScoreCol, fixRowCount);
			}
			if (evaluationFinalScore > 0) {
				commKTableModel.addRowSpan(0, evaluationFinalScore, fixRowCount);
			}
			if (costPerformance > 0) {
				commKTableModel.addRowSpan(0, costPerformance, fixRowCount);
			}
			if (sortNoCol > 0) {
				commKTableModel.addRowSpan(0, sortNoCol, fixRowCount);
			}
			if (recommonedCol > 0) {
				commKTableModel.addRowSpan(0, recommonedCol, fixRowCount);
			}
			int col = commKTableModel.getFixedColumnCount();
			String curStepId = null;
			for (RecommonedFactor recommonedFactor : recommonedFactorTitleList) {
				if (recommonedFactor.getMergerCount() > 1) {
					curStepId = recommonedFactor.getEvaluationStep().getId();
					commKTableModel.addColSpan(0, col, recommonedFactor.getMergerCount());
				} else if (null != recommonedFactor.getEvaluationStep() && (null == curStepId || (null != curStepId && !curStepId.equals(recommonedFactor.getEvaluationStep().getId())) && recommonedFactor.getMergerCount() == 0)) {
					commKTableModel.addRowSpan(0, col, 2);
				}
				col++;
			}
		}
		
		// 设置单元格内容
		CellContentRender contentRender = new CellContentRender() {
			public Object receiveContent(int row, int col) {
				if (row < commKTableModel.getFixedHeaderRowCount()) {
					if (col < commKTableModel.getFixedColumnCount()) {
						return supplierName;
					} else if (col >= commKTableModel.getFixedColumnCount() && col < commKTableModel.getFixedColumnCount() + recommonedFactorTitleList.size()) {
						RecommonedFactor recommonedFactor = recommonedFactorTitleList.get(col - commKTableModel.getFixedColumnCount());
						if (null != recommonedFactor) {
							if (fixRowCount > 1 && row == 0) {
								return recommonedFactor.getEvaluationStep().getStepName();
							} else {
								return recommonedFactor.getFactorName();
							}
						}
					} else if (col == evalPriceCol) {
						return Messages.EvaluationPrice + "（" + tenderProjectRuleEntity.getPriceUnitUseDefault() + "）";
					} else if (col == evalBillFinalScoreCol) {
						return billStepName;
					} else if (col == creditScoreCol) {
						return creditStepName;
					} else if (col == evalPriceFinalScoreCol) {
						return Messages.PriceScore;
					} else if (col == evaluationFinalScore) {
						return Messages.FinalScore;
					} else if (col == costPerformance) {
						return Messages.CostPerformance;
					} else if (col == sortNoCol  && sortNoCol > 0) {
						return Messages.SortNo;
					} else if (col == recommonedCol) {
						if (entryType == 1) {
							return Messages.Recommoned_chose;
						} else if (entryType == 2) {
							return Messages.Recommoned_shortlisted;
						} else {
							return Messages.Recommoned_recommoned;
						}
					}
					return "";
				} else {
					Supplier supplier = supplierList1.get(row - commKTableModel.getFixedHeaderRowCount());
					SupplierOpeningResult supplierOpeningResult = supplier.getSupplierOpeningResult();
					SupplierEvaluationResult supplierEvaluationResult = supplier.getSupplierEvaluationResult();
					if (col < commKTableModel.getFixedColumnCount()) {
						return supplier.getSupplierName();
					} else if (col >= commKTableModel.getFixedColumnCount() && col < commKTableModel.getFixedColumnCount() + recommonedFactorTitleList.size()) {
						List<RecommonedFactor> recommonedFactorList = supplierRecommonedFactorListMap.get(supplier.getId());
						RecommonedFactor recommonedFactor = recommonedFactorList.get(col - commKTableModel.getFixedColumnCount());
						if (null != recommonedFactor) {
							// 每个专家的打分结果
							if (null != recommonedFactor.getExpertEvaluationResult() && null != recommonedFactor.getExpertEvaluationResult().getEvaluationFinalScore()) {
								return NumberFormatUtils.format(recommonedFactor.getExpertEvaluationResult().getEvaluationFinalScore(), scoreRound);
							} else if (null != recommonedFactor.getSupplierEvaluationStep() && null != recommonedFactor.getSupplierEvaluationStep().getEvaluationFinalScore()) {
								// 供应商当前步骤的汇总
								return NumberFormatUtils.format(recommonedFactor.getSupplierEvaluationStep().getEvaluationFinalScore(), scoreRound);
							} else if (null != recommonedFactor.getRankExpertCount()) {
								return recommonedFactor.getRankExpertCount();
							}
						}
					} else if (col == evalBillFinalScoreCol) {
						SupplierEvaluationStep supplierEvaluationStep = supplierEvaluationStepBillResultMap.get(supplier.getId());
						if (null != supplierEvaluationStep) {
							return NumberFormatUtils.format(supplierEvaluationStep.getEvaluationFinalScore(), scoreRound);
						}
					} else if (col == creditScoreCol) {
						SupplierEvaluationStep supplierEvaluationStep = supplierEvaluationStepCreditResultMap.get(supplier.getId());
						if (null != supplierEvaluationStep) {
							return NumberFormatUtils.format(supplierEvaluationStep.getEvaluationFinalScore(), scoreRound);
						}
					} else if (col == evalPriceCol) {
						if (null != supplierOpeningResult && null != supplierOpeningResult.getEvaluationPrice()) {
							return supplierOpeningResult.getFormatEvaluatoinPriceByUnit(tenderProjectRuleEntity.getEvalPriceUnit());
						}
					} else if (col == evalPriceFinalScoreCol) {
						if (null != supplierEvaluationResult.getPriceFinalScore()) {
							return NumberFormatUtils.format(supplierEvaluationResult.getPriceFinalScore(), scoreRound);
						}
					} else if (col == evaluationFinalScore) {
						if (null != supplierEvaluationResult.getEvaluationFinalScore()) {
							return NumberFormatUtils.format(supplierEvaluationResult.getEvaluationFinalScore(), scoreRound);
						}
					} else if (col == costPerformance) {
						BigDecimal score = supplierEvaluationResult.getEvaluationFinalScore();
						BigDecimal price = supplierOpeningResult.getEvaluationPrice();
						price = MoneyUtils.getMoneyByUnit(price, tenderProjectRuleEntity.getEvalPriceUnit());
						if (null != score && null != price && price.compareTo(BigDecimal.ZERO) != 0) {
							return NumberFormatUtils.format(BigDecimalUtils.div(score, price), 6);
						}
					} else if (col == sortNoCol  && sortNoCol > 0) {
						if (supplierEvaluationResult.getSortNo() > 0) {
							return supplierEvaluationResult.getSortNo();
						}
					} else if (col == recommonedCol) {
						if (entryType == 1) {
							return supplierEvaluationResult.getRecommendCn(tenderProjectEntity.getEnterType());
//							return supplierEvaluationResult.getRecommend();
						} else {
							if (null != supplierEvaluationResult.getRecommend() && supplierEvaluationResult.getRecommend().equals(SupplierEnum.RECOMMONED_YES)) {
								return true;
							} else {
								return false;
							}
						}
					}
				}
				return "";
			}
		};
		commKTableModel.setCellContentRender(contentRender);
		
		// 编辑单元格内容
		CellEditContentRender editContentRender = new CellEditContentRender() {
			private boolean isShowError = false;
			
			public void receiveContent(int row, int col, Object content) {
				if (row >= commKTableModel.getFixedRowCount() && col == commKTableModel.getColumnCount() - 1) {
					if (null == content) return;
					Supplier supplier = supplierList1.get(row - commKTableModel.getFixedHeaderRowCount());
					SupplierEvaluationResult supplierEvaluationResult = supplier.getSupplierEvaluationResult();
					
					boolean checkCount = true;
					// 未设置家数，或资审项目或入围方式不限制家次
					if (tenderProjectRuleEntity.getRecommendCountNotNull() == 0 || isPreEvaluation || entryType == 2) {
						checkCount = false;
					}
					
					if (entryType == 1) {
						if (content.toString().length() > 0) {
							int choseCount = 0;
							int firstCount = 0;
							for (Supplier _supplier : supplierList1) {
								if (supplier.getId().equals(_supplier.getId())) continue;
								if (null != _supplier.getSupplierEvaluationResult().getChoiceType() && _supplier.getSupplierEvaluationResult().getChoiceType().equals(SupplierEnum.CHOICE_FIRST)) {
									choseCount++;
									firstCount++;
									if (firstCount > 1 || (tenderProjectRuleEntity.getRecommendCountNotNull() > 0 && choseCount > tenderProjectRuleEntity.getRecommendCountNotNull())) {
										break;
									}
								} else if (null != _supplier.getSupplierEvaluationResult().getChoiceType() && _supplier.getSupplierEvaluationResult().getChoiceType().equals(SupplierEnum.CHOICE_ALTERNATIVE)) {
									choseCount++;
									if (tenderProjectRuleEntity.getRecommendCountNotNull() > 0 && choseCount > tenderProjectRuleEntity.getRecommendCountNotNull()) {
										break;
									}
								}
							}
							if (content.toString().equals(SupplierEnum.CHOICE_FIRST)) {
								firstCount++;
								choseCount++;
							} else if (content.toString().equals(SupplierEnum.CHOICE_ALTERNATIVE)) {
								choseCount++;
							}
							if (firstCount > 1 || (tenderProjectRuleEntity.getRecommendCountNotNull() > 0 && choseCount > tenderProjectRuleEntity.getRecommendCountNotNull())) {
								if (!isShowError) {
									isShowError = true;
									if (firstCount > 1) {
										MessageDialog.openError(getShell(), MessageFormat.format(Messages.Tips_recommonedPreferredLimit, 1));
									} else if (choseCount + 1 > tenderProjectRuleEntity.getRecommendCountNotNull()) {
										MessageDialog.openError(getShell(), MessageFormat.format(Messages.Tips_recommonedAlternativeLimit, tenderProjectRuleEntity.getRecommendCountNotNull() - 1));
									}
									isShowError = false;
									supplierEvaluationResult.setChoiceType(SupplierEnum.NO_RECOMEND);
									supplierEvaluationResult.setRecommend(null);
								}
								return;
							}
							supplierEvaluationResult.setChoiceType(content.toString());
							//京能不推荐不显示 
							if(SupplierEnum.NO_RECOMEND.equals(content.toString())) {
								supplierEvaluationResult.setRecommend(SupplierEnum.RECOMMONED_NO);
							}else {
								supplierEvaluationResult.setRecommend(SupplierEnum.RECOMMONED_YES);
							}
						} else {
							supplierEvaluationResult.setChoiceType(SupplierEnum.NO_RECOMEND);
							supplierEvaluationResult.setRecommend(SupplierEnum.RECOMMONED_NO);
						}
						
					} else {
						if (content.toString().equals("true")) {
							if (checkCount) {
								int recommonedCount = 0;
								for (Supplier _supplier : supplierList1) {
									if (supplier.getId().equals(_supplier.getId())) continue;
									if (null != _supplier.getSupplierEvaluationResult().getRecommend() && _supplier.getSupplierEvaluationResult().getRecommend().equals(SupplierEnum.RECOMMONED_YES)) {
										recommonedCount++;
										if (recommonedCount > tenderProjectRuleEntity.getRecommendCountNotNull()) {
											break;
										}
									}
								}
								if (recommonedCount + 1 > tenderProjectRuleEntity.getRecommendCountNotNull()) {
									if (!isShowError) {
										isShowError = true;
										if (entryType == 2) {
											MessageDialog.openError(getShell(), MessageFormat.format(Messages.Tips_recommonedEntryLimit, tenderProjectRuleEntity.getRecommendCountNotNull()));
										} else {
											MessageDialog.openError(getShell(), MessageFormat.format(Messages.Tips_recommonedLimit, tenderProjectRuleEntity.getRecommendCountNotNull()));
										}
										isShowError = false;
									}
									return;
								}
							}
							supplierEvaluationResult.setRecommend(SupplierEnum.RECOMMONED_YES);
						} else {
							supplierEvaluationResult.setRecommend(SupplierEnum.RECOMMONED_NO);
						}
					}
					evaluationOpinionCreater();
				}
			}
		};
		commKTableModel.setCellEditContentRender(editContentRender);
		// 设置单元格编辑器
//        final KTableCellEditorText text = new KTableCellEditorText();
//		text.setSingleClickEdit(true);
		CellEditorRender cellEditorRender = new CellEditorRender() {
			public Object receiveCellEditor(int row, int col) {
				if (row >= commKTableModel.getFixedRowCount() && col == commKTableModel.getColumnCount() - 1) {
					
					// 首备选式
					if (entryType == 1) {
						KTableCellEditorGCombo combo = new KTableCellEditorGCombo();
						combo.setSingleClickEdit(true);
						combo.addItem(Messages.Recommoned_preferred, SupplierEnum.CHOICE_FIRST);
						combo.addItem(Messages.Recommoned_alternative, SupplierEnum.CHOICE_ALTERNATIVE);
						combo.addItem("不推荐", SupplierEnum.NO_RECOMEND);
						return combo;
					} else {
						return new KTableCellEditorCheckbox2();
					}
					
				} else {
					return null;
				}
			}
		};
		commKTableModel.setCellEditorRender(cellEditorRender);
		
		// 设置单元格渲染器
		CellRender cellRender = new CellRender() {
			public Object receiveCellRender(int row, int col) {
				if (commKTableModel.isFixedCell(col, row)) {
					return new FixedWrapCellRenderer();
				} else if (row >= commKTableModel.getFixedRowCount() && col == commKTableModel.getColumnCount() - 1) {
					// 首备选式
					if (entryType == 1) {
						return new TextWrapCellRenderer();
					} else {
						
						return new CheckableCellRenderer();
					}
				} else {
					return null;
				}
			}
		};
		commKTableModel.setCellRender(cellRender);
		
		// 编辑单元格对齐方式
		CellAlignmentRender cellAlignmentRender = new CellAlignmentRender() {
			public int receiveCellAlignment(int row, int col) {
				if (commKTableModel.isFixedCell(col, row)) {
					if (row >= commKTableModel.getFixedRowCount() && col < commKTableModel.getFixedColumnCount()) {
						return SWTX.ALIGN_VERTICAL_CENTER | SWTX.ALIGN_HORIZONTAL_LEFT;
					}
				} else if (col == evalPriceCol) {
					return SWTX.ALIGN_VERTICAL_CENTER | SWTX.ALIGN_HORIZONTAL_RIGHT;
				}
				return SWTX.ALIGN_VERTICAL_CENTER | SWTX.ALIGN_HORIZONTAL_CENTER;
			}
		};
		commKTableModel.setCellAlignmentRender(cellAlignmentRender);
		resultKTable.setModel(commKTableModel);
		
	}
	
	/**
	 * @Description: 对供应商进行排序
	 * @author guoyr
	 */
	private void sortSupplier() {
		String firstOrder = tenderProjectRuleEntity.getOrderFirst();
		String secondOrder = tenderProjectRuleEntity.getOrderSecond();
		String thirdOrder = tenderProjectRuleEntity.getOrderThird();
		
		// 如果存在
//		if (isMinMethod) {
//			firstOrder = TenderProjectEnum.EVALUATION_PRICE;
//			secondOrder = TenderProjectEnum.EVAL_TOTAL_SCORE;
//		} else 
		if (hasScoreEvalNode || hasBillEvalNode || hasCreditEvalNode) {
			if (null == firstOrder || "".equals(firstOrder)) {
				firstOrder = TenderProjectEnum.EVAL_TOTAL_SCORE;
			}
			if (null == secondOrder || "".equals(secondOrder)) {
				secondOrder = TenderProjectEnum.EVALUATION_PRICE;
			}
			if (null == thirdOrder || "".equals(thirdOrder)) {
				thirdOrder = TenderProjectEnum.DETAIL_SCORE;
			}
		} else if (hasPriceEvalNode) {
			if (null == firstOrder || "".equals(firstOrder)) {
				firstOrder = TenderProjectEnum.PRICE_SCORE;
			}
			if (null == secondOrder || "".equals(secondOrder)) {
				secondOrder = TenderProjectEnum.EVALUATION_PRICE;
			}
		} else {
			if (null == firstOrder || "".equals(firstOrder)) {
				firstOrder = TenderProjectEnum.EVALUATION_PRICE;
			}
		}
		StringBuilder msg = new StringBuilder();
		if (entryType == 1) {
			if (firstOrder.equals(TenderProjectEnum.EVAL_TOTAL_SCORE)) {
//				msg.append("最终得分最高者优先推荐为首选中标候选人，");
				msg.append(MessageFormat.format(Messages.Tips_recommonedChoseFormat, Messages.FinalScore, Messages.Tips_recommonedHighest));
			} else if (firstOrder.equals(TenderProjectEnum.PRICE_SCORE)) {
//				msg.append("报价得分最高者优先推荐为首选中标候选人，");
				msg.append(MessageFormat.format(Messages.Tips_recommonedChoseFormat, Messages.PriceScore, Messages.Tips_recommonedHighest));
			} else if (firstOrder.equals(TenderProjectEnum.EVALUATION_PRICE_DESC)) {
				msg.append(Messages.EvaluationPrice);
//				msg.append("最低者优先推荐为首选中标候选人，");
				msg.append(MessageFormat.format(Messages.Tips_recommonedChoseFormat, Messages.EvaluationPrice, Messages.Tips_recommonedHighest));
			} else if (firstOrder.equals(TenderProjectEnum.EVALUATION_PRICE)) {
				msg.append(Messages.EvaluationPrice);
//				msg.append("最低者优先推荐为首选中标候选人，");
				msg.append(MessageFormat.format(Messages.Tips_recommonedChoseFormat, Messages.EvaluationPrice, Messages.Tips_recommonedLowest));
			} else if (firstOrder.equals(TenderProjectEnum.COST_PERFORMANCE)) {
//				msg.append("性价比（最终得分/评标价）最高者优先推荐为首选中标候选人，");
				msg.append(MessageFormat.format(Messages.Tips_recommonedChoseFormat, Messages.CostPerformance +"（"+Messages.FinalScore +"/" + Messages.EvaluationPrice + "）", Messages.Tips_recommonedHighest));
			}
//			msg.append("请在最后一列选择要推荐的首备选中标候选人！");
//			msg.append(Messages.Tips_recommonedTypeOfFirst);
		} else if (entryType == 2) {
//			msg.append("请在最后一列选择要入围的" + supplierName + "！");
			msg.append(Messages.Tips_recommonedTypeOfEntry);
		} else {
			if (firstOrder.equals(TenderProjectEnum.EVAL_TOTAL_SCORE)) {
//				msg.append("最终得分最高者优先推荐为中标候选人，");
				msg.append(MessageFormat.format(Messages.Tips_recommonedFormat, Messages.FinalScore, Messages.Tips_recommonedHighest));
			} else if (firstOrder.equals(TenderProjectEnum.PRICE_SCORE)) {
//				msg.append("报价得分最高者优先推荐为中标候选人，");
				msg.append(MessageFormat.format(Messages.Tips_recommonedFormat, Messages.PriceScore, Messages.Tips_recommonedHighest));
			} else if (firstOrder.equals(TenderProjectEnum.EVALUATION_PRICE_DESC)) {
//				msg.append(Messages.EvaluationPrice);
//				msg.append("最低者优先推荐为中标候选人，");
				msg.append(MessageFormat.format(Messages.Tips_recommonedFormat, Messages.EvaluationPrice, Messages.Tips_recommonedHighest));
			} else if (firstOrder.equals(TenderProjectEnum.EVALUATION_PRICE)) {
//				msg.append(Messages.EvaluationPrice);
//				msg.append("最低者优先推荐为中标候选人，");
				msg.append(MessageFormat.format(Messages.Tips_recommonedFormat, Messages.EvaluationPrice, Messages.Tips_recommonedLowest));
			} else if (firstOrder.equals(TenderProjectEnum.COST_PERFORMANCE)) {
//				msg.append("性价比（最终得分/" + Messages.EvaluationPrice + "）最高者优先推荐为中标候选人，");
				msg.append(MessageFormat.format(Messages.Tips_recommonedFormat, Messages.CostPerformance +"（"+Messages.FinalScore +"/" + Messages.EvaluationPrice + "）", Messages.Tips_recommonedHighest));
			}
//			msg.append("请在最后一列选择要推荐的中标候选人！");
			msg.append(Messages.Tips_recommonedTypeOfRecommoned);
		}
		
		notLabel.setText(msg.toString());
		
		SupplierSort sortComparator = new SupplierSort(firstOrder, secondOrder, thirdOrder);
		Collections.sort(supplierList1, sortComparator);
		ListSortUtils<Supplier> listSortUtils = new ListSortUtils<Supplier>(supplierList1, sortComparator);
		
		for (Supplier supplier : supplierList1) {
			int sortNo = listSortUtils.getSortNo(supplier);
			supplier.getSupplierEvaluationResult().setSortNo(sortNo);
			supplier.getSupplierEvaluationResult().setRecommend(SupplierEnum.RECOMMONED_NO);
			if (entryType == 1) {
				if (sortNo == 1) {
					supplier.getSupplierEvaluationResult().setRecommend(SupplierEnum.RECOMMONED_YES);
					supplier.getSupplierEvaluationResult().setChoiceType(SupplierEnum.CHOICE_FIRST);
				} else if (sortNo <= tenderProjectRuleEntity.getRecommendCountNotNull()) {
					supplier.getSupplierEvaluationResult().setRecommend(SupplierEnum.RECOMMONED_YES);
					supplier.getSupplierEvaluationResult().setChoiceType(SupplierEnum.CHOICE_ALTERNATIVE);
				}
			} else if (entryType == 2) {
				if (tenderProjectRuleEntity.getRecommendCountNotNull() > 0) {
					if (sortNo <= tenderProjectRuleEntity.getRecommendCountNotNull()) {
						supplier.getSupplierEvaluationResult().setRecommend(SupplierEnum.RECOMMONED_YES);
					}
				}
			} else {
				if (tenderProjectRuleEntity.getRecommendCountNotNull() > 0) {
					if (sortNo <= tenderProjectRuleEntity.getRecommendCountNotNull()) {
						supplier.getSupplierEvaluationResult().setRecommend(SupplierEnum.RECOMMONED_YES);
					}
				}
			}
		}
	}
	
	/**
	 * @Description:
	 * @author guoyr
	 */
	class SupplierSort implements Comparator<Supplier> {
		private String firstOrder;
		private String secondOrder;
		private String thirdOrder;
		
		public SupplierSort(String firstOrder, String secondOrder, String thirdOrder) {
			this.firstOrder = firstOrder;
			this.secondOrder = secondOrder;
			this.thirdOrder = thirdOrder;
		}
		
		public int compare(Supplier a, Supplier b) {
			int compType = comparScore(a, b, firstOrder);
			if (compType == 0) {
				compType = comparScore(a, b, secondOrder);
				if (compType == 0) {
					return comparScore(a, b, thirdOrder);
				}
			}
			return compType;
		}
		
		private int comparScore(Supplier a, Supplier b, String order) {
			
			if (null == order) {
				return 0;
			}
			if (order.equals(TenderProjectEnum.EVAL_TOTAL_SCORE)) {
				BigDecimal aScore = null;
				BigDecimal bScore = null;
				if (null != a.getSupplierEvaluationResult() && null != a.getSupplierEvaluationResult().getEvaluationFinalScore()) {
					aScore = a.getSupplierEvaluationResult().getEvaluationFinalScore();
				}
				if (null != b.getSupplierEvaluationResult() && null != b.getSupplierEvaluationResult().getEvaluationFinalScore()) {
					bScore = b.getSupplierEvaluationResult().getEvaluationFinalScore();
				}
				if (null != aScore && null != bScore) {
					// 按得分从高到低的顺序
					return bScore.compareTo(aScore);
				}
			} else if(order.equals(TenderProjectEnum.DETAIL_SCORE)){
				BigDecimal aScore = null;
				BigDecimal bScore = null;
				// 总分减去价格分就是商务技术得分
				if(null != a.getSupplierEvaluationResult() && null != a.getSupplierEvaluationResult().getPriceFinalScore()){
					aScore = BigDecimalUtils.sub(a.getSupplierEvaluationResult().getEvaluationFinalScore(), a.getSupplierEvaluationResult().getPriceFinalScore());
				}
				if(null != b.getSupplierEvaluationResult() && null != b.getSupplierEvaluationResult().getPriceFinalScore()){
					bScore = BigDecimalUtils.sub(b.getSupplierEvaluationResult().getEvaluationFinalScore(), b.getSupplierEvaluationResult().getPriceFinalScore());
				}
				if(null != aScore && null != bScore){
					
					// 按得商务技术分从高到低的顺序
					return bScore.compareTo(aScore);
				}
			} else if (order.equals(TenderProjectEnum.PRICE_SCORE)) {
				BigDecimal aScore = null;
				BigDecimal bScore = null;
				if (null != a.getSupplierEvaluationResult() && null != a.getSupplierEvaluationResult().getPriceFinalScore()) {
					aScore = a.getSupplierEvaluationResult().getPriceFinalScore();
				}
				if (null != b.getSupplierEvaluationResult() && null != b.getSupplierEvaluationResult().getPriceFinalScore()) {
					bScore = b.getSupplierEvaluationResult().getPriceFinalScore();
				}
				if (null != aScore && null != bScore) {
					// 按得分从高到低的顺序
					return bScore.compareTo(aScore);
				}else if(null != aScore && null == bScore){
					return -1;
				}
			} else if (order.equals(TenderProjectEnum.EVALUATION_PRICE_DESC)) {
				
				BigDecimal aPrice = null;
				BigDecimal bPrice = null;
				if (null != a.getSupplierOpeningResult() && null != a.getSupplierOpeningResult().getEvaluationPrice()) {
					aPrice = a.getSupplierOpeningResult().getEvaluationPrice();
				}
				if (null != b.getSupplierOpeningResult() && null != b.getSupplierOpeningResult().getEvaluationPrice()) {
					bPrice = b.getSupplierOpeningResult().getEvaluationPrice();
				}
				if (null != aPrice && null != bPrice) {
					// 报价从高到低
					return bPrice.compareTo(aPrice);
				}
			}else if (order.equals(TenderProjectEnum.EVALUATION_PRICE)) {
				
				BigDecimal aPrice = null;
				BigDecimal bPrice = null;
				if (null != a.getSupplierOpeningResult() && null != a.getSupplierOpeningResult().getEvaluationPrice()) {
					aPrice = a.getSupplierOpeningResult().getEvaluationPrice();
				}
				if (null != b.getSupplierOpeningResult() && null != b.getSupplierOpeningResult().getEvaluationPrice()) {
					bPrice = b.getSupplierOpeningResult().getEvaluationPrice();
				}
				if (null != aPrice && null != bPrice) {
					// 报价从低到高排序
					return aPrice.compareTo(bPrice);
				}
			} else if (order.equals(TenderProjectEnum.COST_PERFORMANCE)) {
				BigDecimal aScore = null;
				BigDecimal bScore = null;
				if (null != a.getSupplierEvaluationResult() && null != a.getSupplierEvaluationResult().getEvaluationFinalScore()) {
					aScore = a.getSupplierEvaluationResult().getEvaluationFinalScore();
				}
				if (null != b.getSupplierEvaluationResult() && null != b.getSupplierEvaluationResult().getEvaluationFinalScore()) {
					bScore = b.getSupplierEvaluationResult().getEvaluationFinalScore();
				}
				BigDecimal aPrice = null;
				BigDecimal bPrice = null;
				if (null != a.getSupplierOpeningResult() && null != a.getSupplierOpeningResult().getEvaluationPrice()) {
					aPrice = a.getSupplierOpeningResult().getEvaluationPrice();
				}
				if (null != b.getSupplierOpeningResult() && null != b.getSupplierOpeningResult().getEvaluationPrice()) {
					bPrice = b.getSupplierOpeningResult().getEvaluationPrice();
				}
				if (null != aScore && null != bScore && null != aPrice && null != bPrice && aPrice.doubleValue() != 0 && bPrice.doubleValue() != 0) {
					return BigDecimalUtils.div(bScore, bPrice).compareTo(BigDecimalUtils.div(aScore, aPrice));
				}
			}
			return 0;
		}
	}
	
	/**
	 * @Description: 生成评审意见
	 * @author guoyr
	 */
	private void evaluationOpinionCreater() {
		int recommendCount = 1;
		StringBuffer supplierNameSb = new StringBuffer("");
		for (Supplier supplier : supplierList1) {
			SupplierEvaluationResult supplierEvaluationResult = supplier.getSupplierEvaluationResult();
			SupplierOpeningResult supplierOpeningResult = supplier.getSupplierOpeningResult();
			if (SupplierEnum.RECOMMONED_YES.equals(supplierEvaluationResult.getRecommend())) {
				if (defaultEvalOpinionCombo.getSelectionIndex() == 1) {
					if (recommendCount == 1) {
						supplierNameSb.append("经评标委员会评审，推荐中标候选人如下：\r\n");
					}
					supplierNameSb.append("第");
					supplierNameSb.append(NumericChineseUtils.getChinese(recommendCount));
					supplierNameSb.append("中标候选人：");
					supplierNameSb.append(supplier.getSupplierName());
					supplierNameSb.append("，");
					if (null != supplierOpeningResult.getBidPrice()) {
						
						supplierNameSb.append("中标金额为");
						supplierNameSb.append(supplierOpeningResult.getEvaluationPriceWithUnit(tenderProjectRuleEntity.getEvalPriceUnit()));
						supplierNameSb.append("（");
						supplierNameSb.append(MoneyUtils.amountToChinese(supplierOpeningResult.getEvaluationPrice().doubleValue()));
						supplierNameSb.append("），");
					}
					supplierNameSb.append("排名第");
					supplierNameSb.append(NumericChineseUtils.getChinese(supplierEvaluationResult.getSortNo()));
					supplierNameSb.append("；\r\n");
					
				} else if (defaultEvalOpinionCombo.getSelectionIndex() == 2) {
					if (recommendCount == 1) {
						supplierNameSb.append("经评标委员会评审一致推荐");
					}
					supplierNameSb.append(supplier.getSupplierName());
					supplierNameSb.append("为第");
					supplierNameSb.append(NumericChineseUtils.getChinese(recommendCount));
					supplierNameSb.append("中标候选人，");
					if (null != supplierOpeningResult.getBidPrice()) {
						supplierNameSb.append("中标金额为");
						supplierNameSb.append(supplierOpeningResult.getEvaluationPriceWithUnit(tenderProjectRuleEntity.getEvalPriceUnit()));
						supplierNameSb.append("（");
						supplierNameSb.append(MoneyUtils.amountToChinese(supplierOpeningResult.getEvaluationPrice().doubleValue()));
						supplierNameSb.append("），");
					}
					supplierNameSb.append("排名第");
					supplierNameSb.append(NumericChineseUtils.getChinese(supplierEvaluationResult.getSortNo()));
					supplierNameSb.append("；\r\n");
				}
				recommendCount++;
			}
		}
		supplierNameSb.append("共计推荐");
		supplierNameSb.append(recommendCount - 1);
		supplierNameSb.append("名中标候选人。");
		if (defaultEvalOpinionCombo.getSelectionIndex() > 0 && recommendCount > 0) {
			evaluationOpinion_text.setText(supplierNameSb.toString());
		} else {
			evaluationOpinion_text.setText(ObjectUtils.getObjString(tenderProjectEntity.getEvaluationOpinion()));
		}
	}
	
	/**
	 * @Description: 提交推荐结果
	 * @author guoyr
	 * @return
	 */
	public boolean submitRecommonedEvaluationResult() {
		
		int recommonedCount = 0;
		for (Supplier supplier : supplierList1) {
			SupplierEvaluationResult supplierEvaluationResult = supplier.getSupplierEvaluationResult();
			if (null != supplierEvaluationResult.getRecommend() && supplierEvaluationResult.getRecommend().equals(SupplierEnum.RECOMMONED_YES)) {
				recommonedCount++;
			}
			supplierEvaluationResultList.add(supplierEvaluationResult);
		}
		if (tenderProjectRuleEntity.getRecommendCountNotNull() > 0 ){
			if(recommonedCount == 0) {
				MessageDialog.openInformation(getShell(), Messages.Tips_recommonedAtLeastOne);
				return false;
			}
		}else {
			if(recommonedCount == 0) {
				if(!MessageDialog.openConfirm(getShell(), evaluationStep.getStepName(), Messages.Tips_recommonedEmpty, new String[]{Messages.Button_confirm, Messages.Button_cancel})){
					return false;
				}
			}
		}
		tenderProjectEntity.setEvaluationOpinion(evaluationOpinion_text.getText());
		if (!expertEvaluationStepService.submitRecommonedEvaluationResult(tenderProjectEntity.getId(), CURRENT_USER.getId(), evaluationStep, evaluationOpinion_text.getText(), supplierEvaluationResultList)) {
			MessageDialog.openInformation(getShell(), Messages.Dialog_warmTips, Messages.Tips_submitFail);
			return false;
		}
		return true;
	}
	
	public static void main(String[] arges) {
		BigDecimal aa = new BigDecimal("34.3");
		BigDecimal bb = new BigDecimal("56.5");
		System.out.println(aa.compareTo(bb));
	}
}
