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

import java.math.BigDecimal;
import java.text.MessageFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.eclipse.swt.SWT;
import org.eclipse.swt.core.ImageResolver;
import org.eclipse.swt.core.utils.WidgetUtils;
import org.eclipse.swt.core.widgets.ELink;
import org.eclipse.swt.core.widgets.ESepator;
import org.eclipse.swt.core.widgets.RectangleRadioButton;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;

import com.gx.obe.ColorConstants;
import com.gx.obe.business.entity.ExpertEvaluationStep;
import com.gx.obe.business.entity.SupplierEvaluationStep;
import com.gx.obe.common.icons.IconsActivator;
import com.gx.obe.common.widget.utils.MenuFunctionUtils;
import com.gx.obe.components.core.Constants;
import com.gx.obe.components.core.I18NEnum;
import com.gx.obe.components.core.enumeration.CommonEnum;
import com.gx.obe.components.core.enumeration.EvaluationFactorEnum;
import com.gx.obe.components.core.enumeration.EvaluationStepEnum;
import com.gx.obe.components.core.enumeration.ExpertEnum;
import com.gx.obe.evaluation.step.dialog.ApplyReEvaluationDialog;
import com.gx.obe.evaluation.step.dialog.BidFileOpinionDialog;
import com.gx.obe.evaluation.step.dialog.FactorOpinionDialog;
import com.gx.obe.evaluation.step.dialog.SupplierEvaluationOpinionDetailDialog;
import com.gx.obe.evaluation.step.dialog.SupplierExpertScoreDialog;
import com.gx.obe.evaluation.step.listener.ExpertEvaluationListener;
import com.gx.obe.http.json.JsonUtil;
import com.gx.obe.message.Messages;
import com.gx.obe.util.utils.BigDecimalUtils;
import com.gx.obe.util.utils.CollectionUtils;
import com.gx.obe.util.utils.DateUtils;
import com.gx.obe.util.utils.Keys;
import com.gx.obe.util.utils.LogUtils;
import com.gx.obe.util.utils.NumberFormatUtils;
import com.gx.obe.util.utils.ObjectUtils;
import com.gx.obe.util.utils.SortUtils;
import com.gx.obe.util.utils.StringUtils;
import com.gx.obe.util.utils.UuidUtils;
import com.gx.obe.web.entity.EvaluationFactorResult;
import com.gx.obe.web.entity.Supplier;
import com.gx.obe.web.entity.auth.AuthUser;
import com.gx.obe.web.entity.auth.Menu;
import com.gx.obe.web.entity.evaluation.EvaluationFactor;
import com.gx.obe.web.entity.evaluation.EvaluationStep;
import com.gx.obe.web.entity.expert.Expert;
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.SupplierEvaluationStepService;
import com.gx.obe.web.service.SupplierService;
import com.gx.obe.web.service.evaluation.EvaluationFactorResultService;
import com.gx.obe.web.service.evaluation.EvaluationFactorService;
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.gx.obe.web.vo.FixedFactorItemVo;
import com.swtdesigner.ResourceManager;
import com.swtdesigner.SWTResourceManager;

import de.kupzog.ktable.KTable;
import de.kupzog.ktable.KTableCellSelectionAdapter;
import de.kupzog.ktable.SWTX;
import de.kupzog.ktable.model.CommonKtableCModel;
import de.kupzog.ktable.renderers.CellAlignmentRender;
import de.kupzog.ktable.renderers.CellBackgroundRender;
import de.kupzog.ktable.renderers.CellContentRender;
import de.kupzog.ktable.renderers.CellForegroundRender;
import de.kupzog.ktable.renderers.CellRender;
import de.kupzog.ktable.renderers.CellTooltipRender;
import de.kupzog.ktable.renderers.FixedWrapCellRenderer;
import de.kupzog.ktable.renderers.TextWrapCellRenderer;

/**
 * @Description: 
 * @author guoyr
 */
public class ScoreEvaluationResultComposite extends Composite {

	private TenderProjectEntity tenderProjectEntity;
	private TenderProjectRuleEntity tenderProjectRuleEntity;
	private EvaluationStep evaluationStep;
	private ImageResolver imageResolver = new ImageResolver();
	private EvaluationFactorService evaluationFactorService = new EvaluationFactorService();
	private SupplierService supplierService = new SupplierService();
	private ExpertService expertService;
	private EvaluationFactorResultService evaluationFactorResultService = new EvaluationFactorResultService();
	private ExpertEvaluationResultService expertEvaluationResultService;
//	private ExpertEvaluationStepService expertEvaluationStepService ;
	private SupplierEvaluationStepService supplierEvaluationStepService ;
	public EvaluationStepService evaluationStepService = new EvaluationStepService();
	private List<Expert> expertList;
	private List<EvaluationFactor> evaluationFactorList = new ArrayList<EvaluationFactor>();
	private int maxLevel = 1;
	private List<Supplier> supplierList;
	private KTable resultKTable;
	private CommonKtableCModel commKTableModel;
	private Expert CURRENT_EXPERT;
	private boolean isShowObjectiveDialog = false;// 是否显示客观项评审意见信息。
	private Color rightBgColor = SWTResourceManager.getColor(194, 236, 150);
	private Color errorBgColor = SWTResourceManager.getColor(255, 153, 153);
//	private Color fornRightColor = SWTResourceManager.getColor(SWT.COLOR_BLACK);
//	private Color fornErrorColor = SWTResourceManager.getColor(SWT.COLOR_RED);
	private Map<String, Color> contentBackgroundMap = new HashMap<String, Color>();
	private final Map<Keys, Color> objectiveBackgroundMap = new HashMap<Keys, Color>();
	private Map<String, Color> contentForegroundMap = new HashMap<String, Color>();
	// 记录供应商每个指标的评审结果
	private Map<String, Map<String, EvaluationFactorResult>> supplierEvaluationFactorResultMap;
	// 记录专家对供应商的评审汇总结果
	private Map<String, ExpertEvaluationResult> expertEvaluationResultMap;
	private String supplierName;
	private String hiddenResultTable;
	private String EVAL_UNQUALIFIED = Messages.Unqualified;
	private RectangleRadioButton curExpertBtn;
	private AuthUser selectUser;
	private Composite expert_list_composite;
	private Composite load_composite;
	private BigDecimal evaluationStepWeight;
	private Composite composite;
	private Label message_label;
	private ELink switchCoordinateBtn;
	private int scoreRound = 2;
	private int expertScoreRound = 2;
	private Map<String, RectangleRadioButton> expertEvaluationBtnMap;
	private ExpertEvaluationListener expertEvaluationListener;
	private ELink applyReEvaluation_link;
	private BigDecimal warningRange = null;
	private ELink evaluationOpintion_link;;
	private Supplier curSupplier;
	private Composite message_composite;
	private ELink viewScoreChart;
	private String emptyScoreContent = null;
//	private ELink viewSupplierResponse_btn;
	private boolean isByExpertEvaluationGroup = false;
	boolean hasObjectiveFactor = false;
	private Menu menu;
	private MenuFunctionUtils menuFunctionUtils = new MenuFunctionUtils();

	private ExpertEvaluationStepService expertEvaluationStepService = new ExpertEvaluationStepService();
	private ELink viewFactorOpinion_link;
	
	{
		LogUtils.logClass(ScoreEvaluationResultComposite.class);
	}

	/**
	 * @param parent
	 * @param style
	 */
	public ScoreEvaluationResultComposite(Composite parent, int style) {
		super(parent, style);
		menu = (Menu) parent.getData("menu");
		addDisposeListener(new DisposeListener() {
			public void widgetDisposed(DisposeEvent e) {
				imageResolver.disposite();
				if(null != expertList){
					expertList.clear();
				}
				contentBackgroundMap.clear();
			}
		});
		this.tenderProjectRuleEntity = (TenderProjectRuleEntity)parent.getData("tenderProjectRuleEntity");
		this.tenderProjectEntity = (TenderProjectEntity)parent.getData("tenderProjectEntity");
		this.evaluationStep = (EvaluationStep)parent.getData("evaluationStep");
		this.CURRENT_EXPERT = (Expert) parent.getData(Constants.CUR_EXPERT);
		this.hiddenResultTable = (String)parent.getData("hiddenResultTable");
		
		GridLayout gridLayout = new GridLayout(1, false);
		gridLayout.verticalSpacing = 0;
		gridLayout.horizontalSpacing = 0;
		gridLayout.marginHeight = 1;
		gridLayout.marginWidth = 1;
		setLayout(gridLayout);
		
		composite = new Composite(this, SWT.NONE);
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		GridLayout gl_composite = new GridLayout(1, false);
		gl_composite.marginTop = 5;
		gl_composite.verticalSpacing = 0;
		gl_composite.marginWidth = 0;
		gl_composite.marginHeight = 0;
		composite.setLayout(gl_composite);
		
		expert_list_composite = new Composite(composite, SWT.NONE);
		expert_list_composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		RowLayout rl_expert_list_composite = new RowLayout(SWT.HORIZONTAL);
		rl_expert_list_composite.marginLeft = 0;
		rl_expert_list_composite.marginBottom = 0;
		rl_expert_list_composite.spacing = 5;
		expert_list_composite.setLayout(rl_expert_list_composite);
		
		RectangleRadioButton label = new RectangleRadioButton(expert_list_composite, SWT.NONE);
		label.setText("郭永荣");
		
		ESepator expert_tab = new ESepator(composite, SWT.NONE);
		expert_tab.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		expert_tab.setBackground(ColorConstants.SKIN_BG);
		expert_tab.setLineWidth(2);
		
		message_composite = new Composite(this, SWT.NONE);
		GridLayout gl_composite_6 = new GridLayout(7, false);
		gl_composite_6.horizontalSpacing = 2;
		gl_composite_6.marginWidth = 0;
		message_composite.setLayout(gl_composite_6);
		message_composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		message_label = new Label(message_composite, SWT.WRAP);
		message_label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		message_label.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		message_label.setForeground(ColorConstants.NOTE_TIPS_COLOR);
		
		applyReEvaluation_link = new ELink(message_composite, SWT.NONE);
		applyReEvaluation_link.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		applyReEvaluation_link.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/hand.png"));
		applyReEvaluation_link.setText(Messages.Button_appllyForBack);
		applyReEvaluation_link.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				applyReEvaluationAction();
			}
		});
		menuFunctionUtils.addFunction(applyReEvaluation_link, "APPLLY_FOR_BACK");
		
		switchCoordinateBtn = new ELink(message_composite, SWT.NONE);
		switchCoordinateBtn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		switchCoordinateBtn.setText(Messages.Button_switchAxis);
		switchCoordinateBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/switch.png"));
		switchCoordinateBtn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				switchCoordinateAction();
			}
		});
		
		viewScoreChart = new ELink(message_composite, SWT.NONE);
		viewScoreChart.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		viewScoreChart.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				openViewScoreChartAction();
				
			}
		});
		viewScoreChart.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/view.png"));
		viewScoreChart.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		viewScoreChart.setText(Messages.Button_analysisScoreDispersion);
		menuFunctionUtils.addFunction(viewScoreChart, "SCORE_CHART");

				
		evaluationOpintion_link = new ELink(message_composite, SWT.NONE);
		evaluationOpintion_link.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		evaluationOpintion_link.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/edit.png"));
		evaluationOpintion_link.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				evaluationOpinionAction();
			}
		});
		evaluationOpintion_link.setText(MessageFormat.format(Messages.Title_view, Messages.Button_evalOrWasteOpinion));
		menuFunctionUtils.addFunction(evaluationOpintion_link, "EVALUATION_OPINTION");
		
		viewFactorOpinion_link = new ELink(message_composite, SWT.NONE);
		viewFactorOpinion_link.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/view.png"));
		viewFactorOpinion_link.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				viewFactorOpinionAction();
			}
		});
		viewFactorOpinion_link.setText(MessageFormat.format(Messages.Title_view, Messages.Button_factorOpinion));
		menuFunctionUtils.addFunction(viewFactorOpinion_link, "FACTOR_COMMENTS");
		
		ELink viewBidFileOpinion_link = new ELink(message_composite, SWT.NONE);
		viewBidFileOpinion_link.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/view.png"));
		viewBidFileOpinion_link.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				viewBidFileOpinionAction();
			}
		});
		viewBidFileOpinion_link.setText(MessageFormat.format(Messages.Title_view, Messages.BidFileComments));
		menuFunctionUtils.addFunction(viewBidFileOpinion_link, "BIDFILE_COMMENTS");
		
		
//		viewSupplierResponse_btn = new ELink(message_composite, SWT.NONE);
//		viewSupplierResponse_btn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/view.png"));
//		viewSupplierResponse_btn.addMouseListener(new MouseAdapter() {
//			@Override
//			public void mouseUp(MouseEvent e) {
//				viewSupplierOpinionAndResponse(false);
//			}
//		});
//		viewSupplierResponse_btn.setText("查看投标响应");
		
		Composite composite_2 = new Composite(this, SWT.NONE);
		composite_2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		composite_2.setBackground(ColorConstants.BORDER_LINE_COLOR);
		GridLayout gl_composite_2 = new GridLayout(1, false);
		gl_composite_2.marginHeight = 1;
		gl_composite_2.marginWidth = 1;
		composite_2.setLayout(gl_composite_2);
		
		load_composite = new Composite(composite_2, SWT.NONE);
		load_composite.setBackgroundMode(SWT.INHERIT_FORCE);
		load_composite.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		GridLayout gl_load_composite = new GridLayout(1, false);
		gl_load_composite.verticalSpacing = 0;
		gl_load_composite.horizontalSpacing = 0;
		gl_load_composite.marginHeight = 0;
		gl_load_composite.marginWidth = 0;
		load_composite.setLayout(gl_load_composite);
		load_composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		init();
	}
	
	/**
	 * @Description: 界面数据初始化
	 * @author guoyr
	 */
	private void init(){
		expertEvaluationResultService = new ExpertEvaluationResultService();
		expertService = new ExpertService();
		supplierEvaluationStepService = new SupplierEvaluationStepService();
		supplierName = com.gx.obe.components.core.I18N.getString(I18NEnum.SUPPLIERNAME, tenderProjectEntity.getTenderType());
		if(null == tenderProjectRuleEntity)tenderProjectRuleEntity = new TenderProjectRuleEntity();
		scoreRound = tenderProjectRuleEntity.getScoreRoundIntVal();
		expertScoreRound = evaluationStep.getEvaluationParamByKey(com.gx.obe.components.core.enumeration.EvaluationStepEnum.EXPERT_SCORE_ROUND, Integer.class, 2);
		warningRange = evaluationStep.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));
		}else {
			warningRange = null;
		}
		supplierList = supplierService.getEvaluationStepSupplierList(tenderProjectEntity.getId(), evaluationStep);
		
		expertList = expertService.getEvaluationStepExpertList(tenderProjectEntity.getId(), evaluationStep);
		boolean isAllowSeeSummary = true;
		if(null != CURRENT_EXPERT && Constants.USER.getId().equals(CURRENT_EXPERT.getUserId())){
			applyReEvaluation_link.setText(MessageFormat.format(Messages.Button_appllyForBackFormat, evaluationStep.getStepName()));
			String showSummaryResult = evaluationStep.getEvaluationParamByKey(com.gx.obe.components.core.enumeration.EvaluationStepEnum.SHOW_SUMMARY_RESULT);
			if (null == showSummaryResult ||!showSummaryResult.equals("01")) {
				isAllowSeeSummary = false;
			}
		} else {
			applyReEvaluation_link.dispose();
		}
		boolean allowEmptyObj = evaluationStep.getEvaluationParamByKey(com.gx.obe.components.core.enumeration.EvaluationStepEnum.PARAM_EVALUATION_EMPTY, Boolean.class);
		if(allowEmptyObj){
			emptyScoreContent = "\\";
		}
		evaluationStepWeight = evaluationStep.getWeight();
		boolean evalByGroup = evaluationStep.getEvaluationParamByKey(com.gx.obe.components.core.enumeration.EvaluationStepEnum.PARAM_EVAL_BY_GROUP, Boolean.class);
		if(evalByGroup){
			isByExpertEvaluationGroup = true;
		}
		
		if(!isByExpertEvaluationGroup){
			initEvaluationStepFactor(null);
		}
		// 为了显示样式，没有专家时生成一个临时专家
		if(null == expertList || expertList.size() == 0){
			expertList = new ArrayList<Expert>();
			Expert expert = new Expert();
			expert.setUserId(UuidUtils.getUUID());
			expertList.add(expert);
		}
		// 为了显示样式，没有投标人时生成临时投标人
		if(null == supplierList || supplierList.size() == 0){
			supplierList = new ArrayList<Supplier>();
			Supplier tempSupplier = new Supplier();
			tempSupplier.setSupplierName("                    ");
			supplierList.add(tempSupplier);
		}else {
			curSupplier = supplierList.get(0);
		}
		for(Control control : expert_list_composite.getChildren()){
			control.dispose();
		}
		if(null != expertList && expertList.size() > 0){
			expertEvaluationBtnMap = new HashMap<String, RectangleRadioButton>();
			int count = 0;
			for(final Expert _expert : expertList){
				if(null != this.CURRENT_EXPERT && !ObjectUtils.equals(this.CURRENT_EXPERT.getUserId(), _expert.getUserId())){
					continue;
				}
				final RectangleRadioButton label = new RectangleRadioButton(expert_list_composite, SWT.NONE);
				label.addMouseListener(new MouseAdapter() {
					@Override
					public void mouseUp(MouseEvent e) {
						slectExpertAction(label, _expert);
					}
				});
				AuthUser user = _expert.getUser();
				if(null != user && null != user.getUserName()){
					if(ExpertEnum.LEADER_YES.equals(_expert.getIsLeader())) {
						label.setText(user.getUserName()+"（"+_expert.getExpertTypeCN()+"）");
					}else {
						label.setText(user.getUserName());
					}
				}else {
					label.setText(Messages.Expert+(count+1));
				}
				expertEvaluationBtnMap.put(_expert.getUserId(), label);
				if(count++ == 0){
					curExpertBtn = label;
				}
			}
			
			if(null == hiddenResultTable){
				if (isAllowSeeSummary) {
					final RectangleRadioButton label = new RectangleRadioButton(expert_list_composite, SWT.NONE);
					label.addMouseListener(new MouseAdapter() {
						@Override
						public void mouseUp(MouseEvent e) {
							slectExpertAction(label, null);
						}
					});
					label.setText(evaluationStep.getStepName());
					expertEvaluationBtnMap.put("totalExpert", label);
				}
			}
			if(null != curExpertBtn){
				curExpertBtn.notifyListeners(SWT.MouseUp, null);
			}
		}
		if(null != menu) {
			menuFunctionUtils.initFunctionAuthority(menu);
		}
	}
	
	/**
	 * @Description: 刷新内容背景颜色map
	 * @author chenxw 
	 */
	private void refreshObjectiveBackgroundMap() {
		boolean sameScoreCheck  = evaluationStep.getEvaluationParamByKey(EvaluationStepEnum.CHECK_SAME_EVALUATION, Boolean.class, true);
		if (hasObjectiveFactor && sameScoreCheck) {
			new Thread(new Runnable(){
				public void run(){
					objectiveBackgroundMap.clear();
					List<EvaluationFactorResult> evaluationFactorResultList = evaluationFactorResultService.getEvaluationFactorResultList(tenderProjectEntity.getId(), evaluationStep.getId(), null);
					Map<Keys, List<EvaluationFactorResult>> evaluationFactorResultListMap = CollectionUtils.toArrayListHashMap(evaluationFactorResultList, new CollectionUtils.NewMap<Keys, EvaluationFactorResult>() {
						public Keys getKey(EvaluationFactorResult t) {
							return new Keys(t.getSupplierId(), t.getFactorId());
						}
					}, new HashMap<Keys, List<EvaluationFactorResult>>());
					
					for (Keys key : evaluationFactorResultListMap.keySet()) {
						List<EvaluationFactorResult> factorResultList = evaluationFactorResultListMap.get(key);
						boolean isEqual = true;
						BigDecimal evaluationScore = null;
						for (EvaluationFactorResult evaluationFactorResult : factorResultList) {
							BigDecimal score = evaluationFactorResult.getEvaluationScore();
							if (evaluationScore == null) {
								evaluationScore = score;
							} else if (score != null && evaluationScore.compareTo(score) != 0) {
								isEqual = false;
							}
						}
						objectiveBackgroundMap.put(key, isEqual ? rightBgColor : errorBgColor);
					}
					
					if(!Display.getDefault().isDisposed()){
						Display.getDefault().syncExec(new Runnable(){
							public void run(){
								if (null != resultKTable && !resultKTable.isDisposed()) {
									resultKTable.redraw();
								}
							}
						});
					}
				}
			}).start();;
			
		}
	}
	
	/**
	 * @Description: 加载 评标步骤评审指标
	 * @author guoyr
	 */
	private void initEvaluationStepFactor(String userId){
		hasObjectiveFactor = false;
		evaluationFactorList.clear();
		maxLevel = 1;
		evaluationStepWeight = evaluationStep.getWeight();
		List<EvaluationFactor> evaluationTopFactorList = evaluationFactorService.getExpertEvaluationStepFactorTreeList(tenderProjectEntity.getId(), evaluationStep, userId);
		if(null != evaluationTopFactorList && evaluationTopFactorList.size() > 0){
			for(EvaluationFactor topFactor : evaluationTopFactorList){
				initAddChildEvaluationFactor(topFactor);
			}
		}
		
	}

	/**
	 * @Description: 加载所有评审子指标
	 * @author guoyr
	 * @param evalFactor
	 */
	private void initAddChildEvaluationFactor(EvaluationFactor evalFactor){
		if(null != evalFactor.getChildFactorList() && evalFactor.getChildFactorList().size() > 0){
			for(EvaluationFactor childFactor : evalFactor.getChildFactorList()){
				childFactor.setLevel(evalFactor.getLevel() + 1);
				initAddChildEvaluationFactor(childFactor);
			}
		}else {
			maxLevel = Math.max(maxLevel, evalFactor.getLevel());
			if(ObjectUtils.equals(evalFactor.getFactorType(), EvaluationFactorEnum.FACTOR_FLOAT)){
				return;
			}
			evaluationFactorList.add(evalFactor);
			if(ObjectUtils.equals(evalFactor.getFactorType(), EvaluationFactorEnum.FACTOR_BASE) && null != evalFactor.getContainFactor()){
				evaluationFactorList.add(evalFactor.getContainFactor());
			}
			if(!hasObjectiveFactor && EvaluationFactorEnum.OBJECTIVE_YES.equals(evalFactor.getObjective())){
				hasObjectiveFactor = true;
			}
		}
	}
	
	/**
	 * @Description: 初始化评标结果
	 * @author guoyr
	 * @param userId 
	 */
	private void initEvaluationResult(String userId){

		// 记录供应商每个指标的评审结果
		if(null == supplierEvaluationFactorResultMap){
			supplierEvaluationFactorResultMap = new HashMap<String, Map<String, EvaluationFactorResult>>();
		}else {
			supplierEvaluationFactorResultMap.clear();
		}
		// 记录专家对供应商的评审汇总结果
		
		if(null == expertEvaluationResultMap){
			expertEvaluationResultMap = new HashMap<String, ExpertEvaluationResult>();
		}else {
			expertEvaluationResultMap.clear();
		}
		
		// 评审当前评标专家所有的评标结果
		List<EvaluationFactorResult> memberEvaluateFactorResultList = evaluationFactorResultService.getExpertEvaluationFactorResult(tenderProjectEntity.getId(), evaluationStep.getId(), userId, null);
		List<ExpertEvaluationResult> queryExpertEvaluationResultList = expertEvaluationResultService.getExpertStepAllSupplierEvaluationResultList(tenderProjectEntity.getId(), evaluationStep.getId(), userId);
		contentBackgroundMap.clear();
		contentForegroundMap.clear();
		List<Map<String, Object>> supplierSumEvaluationScoreList = null;
		if(null != warningRange){
			supplierSumEvaluationScoreList = expertEvaluationResultService.getSupplierSumEvaluationResultList(tenderProjectEntity.getId(), evaluationStep.getId(), null);
		}
		for(Supplier supplier : supplierList){
			// 获取评标专家对投标人的评审记录
			ExpertEvaluationResult expertEvaluationResult = null;
			if(null != queryExpertEvaluationResultList && queryExpertEvaluationResultList.size() > 0){
				for(ExpertEvaluationResult queryExpertEvaluationResult : queryExpertEvaluationResultList){
					if(ObjectUtils.equals(queryExpertEvaluationResult.getSupplierId(), supplier.getId())){
						expertEvaluationResult = queryExpertEvaluationResult;
						break;
					}
				}
			}
			if(null == expertEvaluationResult){
				expertEvaluationResult = new ExpertEvaluationResult();
				expertEvaluationResult.setTenderId(tenderProjectEntity.getId());
				expertEvaluationResult.setStepId(evaluationStep.getId());
				expertEvaluationResult.setUserId(userId);
				expertEvaluationResult.setSupplierId(supplier.getId());
			}
			boolean overRange = false;
			// 判断每个专家的打分是否超出预警
			if(null != supplierSumEvaluationScoreList && null != expertEvaluationResult.getEvaluationScore()){
				int expertCount = 0;
				BigDecimal sumResult = BigDecimal.ZERO;
				for(Map<String, Object> supplierSumEvaluationScore : supplierSumEvaluationScoreList){
					String _supId = (String)supplierSumEvaluationScore.get("SUPPLIER_ID");
					if(null != _supId && _supId.equals(supplier.getId())){
						try {
							expertCount = Integer.parseInt(supplierSumEvaluationScore.get("COUNT").toString());
						} catch (NumberFormatException e) {
						}
						sumResult = ObjectUtils.getObjBigDecimal(supplierSumEvaluationScore.get("SUM_EVALUATION_SCORE"));
						if(expertCount > 1){
							BigDecimal avgValue = BigDecimalUtils.div(sumResult, new BigDecimal(expertCount));
							BigDecimal percentValue = BigDecimalUtils.sub(expertEvaluationResult.getEvaluationScore(), avgValue) ;//获取差值
							if(avgValue.compareTo(BigDecimal.ZERO) != 0){
								percentValue = BigDecimalUtils.div(percentValue, avgValue).abs();//偏差率绝对值
							}
							if(null != warningRange && percentValue.compareTo(warningRange) >= 0){
								overRange = true;
							}
						}
						break;
					}
				}
			}
			contentBackgroundMap.put(supplier.getId(), overRange ? errorBgColor : null);
			
			Map<String, EvaluationFactorResult> evaluationFactorResultMap = new HashMap<String, EvaluationFactorResult>();
			for(EvaluationFactor evaluationFactor : evaluationFactorList){
				
				// 获得已评审的结果
				EvaluationFactorResult  evalFactorResult = null;
				if(null != memberEvaluateFactorResultList && memberEvaluateFactorResultList.size() > 0){
					for(EvaluationFactorResult factorResult : memberEvaluateFactorResultList){
						if(ObjectUtils.equals(supplier.getId(), factorResult.getSupplierId()) && ObjectUtils.equals(evaluationFactor.getId(), factorResult.getFactorId())){
							evalFactorResult = factorResult;
							break;
						}
					}
				}
				if(null == evalFactorResult){
					evalFactorResult = new EvaluationFactorResult();
					evalFactorResult.setTenderId(tenderProjectEntity.getId());
					evalFactorResult.setStepId(evaluationStep.getId());
					evalFactorResult.setUserId(userId);
					evalFactorResult.setSupplierId(supplier.getId());
					evalFactorResult.setFactorId(evaluationFactor.getId());
					evalFactorResult.setFactorName(evaluationFactor.getFactorName());
				}
				evaluationFactorResultMap.put(evaluationFactor.getId(), evalFactorResult);
				
			}
			expertEvaluationResultMap.put(supplier.getId(), expertEvaluationResult);
			supplierEvaluationFactorResultMap.put(supplier.getId(), evaluationFactorResultMap);
		}
	}
	
	/**
	 * @Description: 左边是供应商表格
	 * @author guoyr
	 * @param evaluationTableComposite
	 * @param userId
	 */
	private void drawLeftSupplierEvaluationTable(){
		if(null == evaluationFactorList)evaluationFactorList = new ArrayList<EvaluationFactor>();
		if(null != resultKTable && !resultKTable.isDisposed()){
			resultKTable.dispose();
		}
		
		resultKTable = new KTable(load_composite, SWTX.AUTO_SCROLL | SWT.FULL_SELECTION | SWTX.EDIT_ON_KEY);
		resultKTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		commKTableModel = new CommonKtableCModel(resultKTable, maxLevel, 1, supplierList.size() , evaluationFactorList.size() + 2 + (null != evaluationStepWeight ? 1 : 0));
		commKTableModel.addRowSpan(0, 0, commKTableModel.getFixedRowCount());
		commKTableModel.setColumnMinWidth(0, 80);
		
		// 排名列
		final int sortCol = commKTableModel.getColCount() -1;
		commKTableModel.addRowSpan(0, sortCol, commKTableModel.getFixedRowCount());
		commKTableModel.setColumnWidth(sortCol, 40);
		commKTableModel.setColumnMaxWidth(sortCol, 80);
		// 最终得分列
		final int finalScoreSumCol= commKTableModel.getColCount() -2;
		commKTableModel.setColumnWidth(finalScoreSumCol, 40);
		commKTableModel.setColumnMaxWidth(finalScoreSumCol, 80);
		commKTableModel.addRowSpan(0, finalScoreSumCol, commKTableModel.getFixedRowCount());
		// 得分汇总列
		final int scoreSumCol = null != evaluationStepWeight?commKTableModel.getColCount() -3 : -1;
		if(scoreSumCol > 0){
			commKTableModel.addRowSpan(0, scoreSumCol, commKTableModel.getFixedRowCount());
			commKTableModel.setColumnWidth(scoreSumCol, 40);
			commKTableModel.setColumnMaxWidth(scoreSumCol, 80);
		}
		final Map<String, String> tableTitleMap = new HashMap<String, String>();
		for(int row = 0; row < maxLevel; row++){
			int childCount = 0;
			String parentId = "";
			int col = commKTableModel.getFixedColumnCount();
			tableTitleMap.put(row+"_0", MessageFormat.format(Messages.Supplier, Messages.Name));
			tableTitleMap.put(row+"_"+sortCol, Messages.SortNo);
			if(scoreSumCol > 0){
				tableTitleMap.put(row+"_"+scoreSumCol, Messages.TotalScore);
				tableTitleMap.put(row+"_"+finalScoreSumCol, Messages.FinalScore);
			}else {
				tableTitleMap.put(row+"_"+finalScoreSumCol, Messages.FinalScore);
			}
			for(EvaluationFactor evaluationFactor : evaluationFactorList){
				if(col < commKTableModel.getFixedColumnCount()){
				}else {
					EvaluationFactor parentFactor = getParentFactor(evaluationFactor, row + 1 );
					if(null != parentFactor && StringUtils.isNotEmpty(parentFactor.getId())){
						if(!parentId.equals(parentFactor.getId())){
							childCount = 0;
						}
						if(childCount++ == 0){
							commKTableModel.addColSpan(row, col, getChildCount(parentFactor));
						}
						tableTitleMap.put(row+"_"+col, parentFactor.getFactorName());
						parentId = parentFactor.getId();
					}else {
						childCount = 0;
						tableTitleMap.put(row+"_"+col, evaluationFactor.getFactorName());
					}
					if(row + 1 == evaluationFactor.getLevel()){
						commKTableModel.addRowSpan(row, col, commKTableModel.getFixedRowCount() - row);
					}
					commKTableModel.setColumnWidth(col, 60);
					commKTableModel.setColumnMinWidth(col, 80);
				}
				col ++;
			}
		}
		
		// 设置单元格内容
		CellContentRender contentRender = new CellContentRender(){
			public Object receiveContent(int row, int col) {
				// 表头
				if(row < commKTableModel.getHeadRow()){
					if(null != tableTitleMap.get(row+"_"+col)){
						return tableTitleMap.get(row+"_"+col);
					}else {
						return "";
					}
				}else {
					Supplier supplier = supplierList.get(row - commKTableModel.getFixedRowCount());
					if(col < commKTableModel.getFixedColumnCount()){
						return supplier.getSupplierName();
					}else if(col < commKTableModel.getFixedColumnCount() + evaluationFactorList.size()){
						EvaluationFactor evaluationFactor = evaluationFactorList.get(col - commKTableModel.getFixedColumnCount());
						EvaluationFactorResult evalFactorResult = supplierEvaluationFactorResultMap.get(supplier.getId()).get(evaluationFactor.getId());
						if(null != evalFactorResult && null != evalFactorResult.getEvaluationScore()){
							if(null != emptyScoreContent && evalFactorResult.getEvaluationScore().compareTo(BigDecimal.ZERO) == 0){
								return emptyScoreContent;
							}
							return NumberFormatUtils.format(evalFactorResult.getEvaluationScore(), expertScoreRound);
						}
					}else{
						//供应商的汇总
						ExpertEvaluationResult expertEvaluationResult  = expertEvaluationResultMap.get(supplier.getId());
						if(null != expertEvaluationResult){
							if(col == scoreSumCol){
								if(null != expertEvaluationResult.getEvaluationScore()){
									return NumberFormatUtils.format(expertEvaluationResult.getEvaluationScore(), scoreRound);
								}
							}else if(col == finalScoreSumCol){
								if(null != expertEvaluationResult.getEvaluationFinalScore()){
									return NumberFormatUtils.format(expertEvaluationResult.getEvaluationFinalScore(), scoreRound);
								}
							}else if(col == sortCol){
								if(expertEvaluationResult.getSortNoIntValue() > 0){
									return expertEvaluationResult.getSortNoIntValue();
								}
							}
						}
					}
				}
				return "";
		}};
		commKTableModel.setCellContentRender(contentRender);
		
		// 设置单元格渲染器
		final FixedWrapCellRenderer fixeCellRender = new FixedWrapCellRenderer();
		final TextWrapCellRenderer textCellRender = new TextWrapCellRenderer();
		CellRender cellRender = new CellRender(){
			public Object receiveCellRender(int row, int col) {
				if(commKTableModel.isFixedCell(col, row)){
					return fixeCellRender;
				}else{
					return textCellRender;
				}
		}};
		commKTableModel.setCellRender(cellRender);
		
		// 编辑单元格对齐方式
		CellAlignmentRender cellAlignmentRender = new CellAlignmentRender(){
			public int receiveCellAlignment(int row, int col) {
				if(col < commKTableModel.getFixedColumnCount() && row >= commKTableModel.getFixedRowCount()){
					if(row < commKTableModel.getFixedRowCount() + supplierList.size()){
						return SWTX.ALIGN_VERTICAL_CENTER | SWTX.ALIGN_HORIZONTAL_LEFT;
					}else {
						return SWTX.ALIGN_VERTICAL_CENTER | SWTX.ALIGN_HORIZONTAL_CENTER;
					}
				}
				return SWTX.ALIGN_VERTICAL_CENTER | SWTX.ALIGN_HORIZONTAL_CENTER;
			}
		};
		commKTableModel.setCellAlignmentRender(cellAlignmentRender);
		
		// 设置单元格前景颜色
		CellForegroundRender cellForegroundRender = new CellForegroundRender(){
			public Color receiveCellForeground(int row, int col) {
				if(col >= commKTableModel.getFixedColumnCount() && row >= commKTableModel.getFixedRowCount() && row < commKTableModel.getFixedRowCount() + supplierList.size()){
					Supplier supplier = supplierList.get(row - commKTableModel.getFixedRowCount());
					if(col < commKTableModel.getFixedColumnCount() + evaluationFactorList.size()){
						EvaluationFactor evaluationFactor = evaluationFactorList.get(col - commKTableModel.getFixedColumnCount());
						EvaluationFactorResult  evalFactorResult = supplierEvaluationFactorResultMap.get(supplier.getId()).get(evaluationFactor.getId());
						return contentForegroundMap.get(evalFactorResult.getId());
					}else if(col == scoreSumCol || col == finalScoreSumCol){
						return contentForegroundMap.get(supplier.getId());
					}
				
				}
				return null;
		}};
		commKTableModel.setCellForegroundRender(cellForegroundRender);
		
		// 设置单元格背景颜色
		CellBackgroundRender cellBackgroundRender = new CellBackgroundRender(){
			public Color receiveCellBackground(int row, int col) {
				if(row >= commKTableModel.getFixedRowCount() && row < commKTableModel.getFixedRowCount() + supplierList.size()) {
					Supplier supplier = supplierList.get(row - commKTableModel.getFixedRowCount());
					if(col >= commKTableModel.getFixedColumnCount() && col < commKTableModel.getFixedColumnCount() + evaluationFactorList.size()){
						EvaluationFactor evaluationFactor = evaluationFactorList.get(col - commKTableModel.getFixedColumnCount());
						if(EvaluationFactorEnum.OBJECTIVE_YES.equals(evaluationFactor.getObjective())){
							Color bgColor = objectiveBackgroundMap.get(new Keys(supplier.getId(), evaluationFactor.getId()));
							if (null != bgColor) {
								return bgColor;
							}
						}
					}else if(col == scoreSumCol || col == finalScoreSumCol){
						Color bgColor = contentBackgroundMap.get(supplier.getId());
						return bgColor;
					}
				}
				return null;
			}
		};
		commKTableModel.setCellBackgroundRender(cellBackgroundRender);
		// 设置单元格提示内容
		CellTooltipRender cellTooltipRender = new CellTooltipRender(){
			public String receiveCellTooltip(int row, int col) {
				if(col >= commKTableModel.getFixedColumnCount() && col < commKTableModel.getFixedColumnCount() + evaluationFactorList.size() && row >= commKTableModel.getFixedRowCount() && row < commKTableModel.getFixedRowCount() + supplierList.size()){
					Supplier supplier = supplierList.get(row - commKTableModel.getFixedRowCount());
					EvaluationFactor evaluationFactor = evaluationFactorList.get(col - commKTableModel.getFixedColumnCount());
					EvaluationFactorResult  evalFactorResult = supplierEvaluationFactorResultMap.get(supplier.getId()).get(evaluationFactor.getId());
//					ExpertEvaluationResult expertEvaluationResult  = expertEvaluationResultMap.get(supplier.getId());
					if(null != evalFactorResult && null != evalFactorResult.getEvaluationOpinion()){
						return evalFactorResult.getEvaluationOpinion();
					}
				}
				return "";
			}
		};	
		commKTableModel.setCellTooltipRender(cellTooltipRender);
		resultKTable.setModel(commKTableModel);
	}
	
	/**
	 * @Description: 左边是评审指标表格
	 * @author guoyr
	 * @param evaluationTableComposite
	 * @param userId
	 */
	private void drawLeftFactorEvaluationTable(){

		if(null != resultKTable && !resultKTable.isDisposed()){
			resultKTable.dispose();
		}
		resultKTable = new KTable(load_composite, SWTX.AUTO_SCROLL | SWT.FULL_SELECTION | SWTX.EDIT_ON_KEY);
		resultKTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		commKTableModel = new CommonKtableCModel(resultKTable, 1, maxLevel, evaluationFactorList.size() + 2 + (null != evaluationStepWeight? 1 : 0), supplierList.size());
		final Map<String, String> tableTitleMap = new HashMap<String, String>();
		tableTitleMap.put("0_0", Messages.EvalFactor);
		commKTableModel.addColSpan(0, 0, commKTableModel.getFixedColumnCount());
		
		int col = commKTableModel.getFixedColumnCount();
		for(Supplier supplier : supplierList){
			tableTitleMap.put("0_"+col, supplier.getSupplierName());
			commKTableModel.setColumnWidth(col, 80);
			col ++;
		}
		// 排名列
		final int sortRow = commKTableModel.getRowCount() -1;
		commKTableModel.addColSpan(sortRow, 0, commKTableModel.getFixedColumnCount());
		tableTitleMap.put(sortRow +"_0", Messages.SortNo);
		// 最终得分列
		final int finalScoreSumRow= commKTableModel.getRowCount() -2;
		tableTitleMap.put(finalScoreSumRow +"_0", Messages.EvalFactor);
		commKTableModel.addColSpan(finalScoreSumRow, 0, commKTableModel.getFixedColumnCount());
		// 得分汇总列
		final int scoreSumRow = null != evaluationStepWeight?commKTableModel.getRowCount() -3 : -1;
		if(scoreSumRow > 0){
			commKTableModel.addColSpan(scoreSumRow, 0, commKTableModel.getFixedColumnCount());
			tableTitleMap.put(scoreSumRow+"_0", Messages.TotalScore);
			tableTitleMap.put(finalScoreSumRow+"_0", Messages.FinalScore);
		}else {
			tableTitleMap.put(finalScoreSumRow+"_0", Messages.FinalScore);
		}
		String parentId = "";
		int childCount = 0;
		for(col = 0; col < maxLevel; col++){
			commKTableModel.addRowSpan(0, col, commKTableModel.getFixedRowCount());
			if(col == maxLevel -1){
				// 将指标的最后一列设置宽一点
				commKTableModel.setColumnMaxWidth(col, 250);
			}else {
				commKTableModel.setColumnMaxWidth(col, 200);
			}
			int row = commKTableModel.getFixedRowCount();
			for(EvaluationFactor evaluationFactor : evaluationFactorList){
				EvaluationFactor parentFactor = getParentFactor(evaluationFactor, col + 1 );
				if(null != parentFactor && StringUtils.isNotEmpty(parentFactor.getId())){
					if(!parentId.equals(parentFactor.getId())){
						childCount = 0;
					}
					if(childCount++ == 0 ){
						commKTableModel.addRowSpan(row, col, getChildCount(parentFactor));
					}
					parentId = parentFactor.getId();
					tableTitleMap.put(row+"_"+col, parentFactor.getFactorName());
				}else {
					childCount = 0;
					tableTitleMap.put(row+"_"+col, evaluationFactor.getFactorName());
				}
				if(col + 1 == evaluationFactor.getLevel()){
					commKTableModel.addColSpan(row, col, commKTableModel.getFixedColumnCount() - col);
				}
				if(null != parentFactor){
					tableTitleMap.put(row+"_"+col, parentFactor.getFactorName());
				}
				if(col < commKTableModel.getFixedColumnCount()){
					if(null != evaluationFactor){
						tableTitleMap.put(row+"_"+(maxLevel -1), evaluationFactor.getFactorName());
					}
				}
				row ++;
			}
		}

		// 设置单元格内容
		CellContentRender contentRender = new CellContentRender(){
			public Object receiveContent(int row, int col) {
				// 表头
				if(col < commKTableModel.getFixedColumnCount()){
					if(row < commKTableModel.getFixedRowCount()){
						return Messages.EvalFactor;
					}else if(row < commKTableModel.getFixedRowCount() + evaluationFactorList.size() && col == commKTableModel.getFixedColumnCount() -1){
						EvaluationFactor evaluationFactor = evaluationFactorList.get(row - commKTableModel.getFixedRowCount());
						return evaluationFactor.getFactorName();
					}else if(null != tableTitleMap.get(row+"_"+col)){
						return tableTitleMap.get(row+"_"+col);
					}
					return "";
				}else if(col < commKTableModel.getFixedColumnCount() + supplierList.size()){
					Supplier supplier = supplierList.get(col - commKTableModel.getFixedColumnCount());
					if(row < commKTableModel.getFixedRowCount()){
						return supplier.getSupplierName();
					}else if(row < commKTableModel.getFixedRowCount() + evaluationFactorList.size()){
						EvaluationFactor evaluationFactor = evaluationFactorList.get(row - commKTableModel.getFixedRowCount());
						EvaluationFactorResult evalFactorResult = supplierEvaluationFactorResultMap.get(supplier.getId()).get(evaluationFactor.getId());
						if(null != evalFactorResult && null != evalFactorResult.getEvaluationScore()){
							if(null != emptyScoreContent && evalFactorResult.getEvaluationScore().compareTo(BigDecimal.ZERO) == 0){
								return emptyScoreContent;
							}
							return NumberFormatUtils.format(evalFactorResult.getEvaluationScore(), expertScoreRound);
						}
					}else {
						ExpertEvaluationResult expertEvaluationResult  = expertEvaluationResultMap.get(supplier.getId());
						if(null != expertEvaluationResult){
							if(row == scoreSumRow){
								if(null != expertEvaluationResult.getEvaluationScore()){
									return NumberFormatUtils.format(expertEvaluationResult.getEvaluationScore(), scoreRound);
								}
							}else if(row == finalScoreSumRow){
								if(null != expertEvaluationResult.getEvaluationFinalScore()){
									return NumberFormatUtils.format(expertEvaluationResult.getEvaluationFinalScore(), scoreRound);
								}
							}else if(row == sortRow){
								if(expertEvaluationResult.getSortNoIntValue() > 0){
									return expertEvaluationResult.getSortNoIntValue();
								}
							}
						}
					}
				}
				return "";
			}
		};
		commKTableModel.setCellContentRender(contentRender);
		
		// 设置单元格渲染器
		CellRender cellRender = new CellRender(){
			public Object receiveCellRender(int row, int col) {
				if(commKTableModel.isFixedCell(col, row)){
					return new FixedWrapCellRenderer();
				}else{
					return new TextWrapCellRenderer();
				}
			}
		};
		commKTableModel.setCellRender(cellRender);
		
		// 编辑单元格对齐方式
		CellAlignmentRender cellAlignmentRender = new CellAlignmentRender(){
			public int receiveCellAlignment(int row, int col) {
				if(col < commKTableModel.getFixedColumnCount() && row >= commKTableModel.getFixedRowCount()){
					if(row < commKTableModel.getFixedRowCount() + evaluationFactorList.size()){
						return SWTX.ALIGN_VERTICAL_CENTER | SWTX.ALIGN_HORIZONTAL_LEFT;
					}else {
						return SWTX.ALIGN_VERTICAL_CENTER | SWTX.ALIGN_HORIZONTAL_CENTER;
					}
				}
				return SWTX.ALIGN_VERTICAL_CENTER | SWTX.ALIGN_HORIZONTAL_CENTER;
			}
		};
		commKTableModel.setCellAlignmentRender(cellAlignmentRender);
		
		// 设置单元格前景颜色
		CellForegroundRender cellForegroundRender = new CellForegroundRender(){
			public Color receiveCellForeground(int row, int col) {
				if(col >= commKTableModel.getFixedColumnCount() && row >= commKTableModel.getFixedRowCount() && row < commKTableModel.getFixedRowCount() + evaluationFactorList.size()){
					Supplier supplier = supplierList.get(col - commKTableModel.getFixedColumnCount());
					EvaluationFactor evaluationFactor = evaluationFactorList.get(row - commKTableModel.getFixedRowCount());
					EvaluationFactorResult evalFactorResult = supplierEvaluationFactorResultMap.get(supplier.getId()).get(evaluationFactor.getId());
					Color foreColor = contentForegroundMap.get(evalFactorResult.getId());
					return foreColor;
				}
				return null;
			}
		};
		commKTableModel.setCellForegroundRender(cellForegroundRender);
		
		// 设置单元格背景颜色
		CellBackgroundRender cellBackgroundRender = new CellBackgroundRender(){
			public Color receiveCellBackground(int row, int col) {
				if(col >= commKTableModel.getFixedColumnCount() && row >= commKTableModel.getFixedRowCount()){
					Supplier supplier = supplierList.get(col - commKTableModel.getFixedColumnCount());
					if(row < commKTableModel.getFixedRowCount() + evaluationFactorList.size()){
						
						EvaluationFactor evaluationFactor = evaluationFactorList.get(row - commKTableModel.getFixedRowCount());
						if(EvaluationFactorEnum.OBJECTIVE_YES.equals(evaluationFactor.getObjective())){
							Color bgColor = objectiveBackgroundMap.get(new Keys(supplier.getId(), evaluationFactor.getId()));
							if (null != bgColor) {
								return bgColor;
							}
						}
					}else if(row == scoreSumRow || row == finalScoreSumRow){
						return contentBackgroundMap.get(supplier.getId());
					}
				}
				return null;
			}
		};
		commKTableModel.setCellBackgroundRender(cellBackgroundRender);
		
		// 设置单元格内容
		CellTooltipRender cellTooltipRender = new CellTooltipRender(){
			public String receiveCellTooltip(int row, int col) {
				if(col >= commKTableModel.getFixedColumnCount() && row >= commKTableModel.getFixedRowCount() && row < commKTableModel.getFixedRowCount() + evaluationFactorList.size()){
					Supplier supplier = supplierList.get(col - commKTableModel.getFixedColumnCount());
					EvaluationFactor evaluationFactor = evaluationFactorList.get(row - commKTableModel.getFixedRowCount());
					EvaluationFactorResult evalFactorResult = supplierEvaluationFactorResultMap.get(supplier.getId()).get(evaluationFactor.getId());
					if(null != evalFactorResult && null != evalFactorResult.getEvaluationOpinion()){
						return evalFactorResult.getEvaluationOpinion();
					}
				}
				return "";
			}
		};	
		commKTableModel.setCellTooltipRender(cellTooltipRender);
		resultKTable.setModel(commKTableModel);
	}
	
	/**
	 * @Description: 加载 评审汇总表格并 加载数据
	 * @author guoyr
	 * @param evaluationTableComposite
	 */
	private void drawEvaluationResultTable(){
		
		boolean isFixedFactor = false;
		List<FixedFactorItemVo> fixedFactorItemVoList = null;
		Map<String, String> supplierGradeMap = null;
		//定档评审
		if(EvaluationStepEnum.FIXED_FACTOR.equals(evaluationStep.getStepType())){
			isFixedFactor = true;
			supplierGradeMap = new HashMap<String, String>();
			String PARAM_FIXED_FACTOR_LIST = evaluationStep.getEvaluationParamByKey(EvaluationStepEnum.PARAM_FIXED_FACTOR_LIST);
			if(StringUtils.hasLength(PARAM_FIXED_FACTOR_LIST)) {
				fixedFactorItemVoList = JsonUtil.strToList(PARAM_FIXED_FACTOR_LIST, FixedFactorItemVo.class);
			}
		};
		
		List<AuthUser> userList = expertService.getEvaluationStepUserList(tenderProjectEntity.getId(), evaluationStep);
		if(null == userList){
			userList = new ArrayList<AuthUser>();
		}
		if(userList.size() == 0){
			AuthUser user = new AuthUser();
			user.setId("");
			user.setUserName("评标专家");
			userList.add(user);
		}
		final List<AuthUser> expertList = new ArrayList<AuthUser>();
		expertList.addAll(userList);
		KTable resultKTable = new KTable(load_composite, SWTX.AUTO_SCROLL | SWT.FULL_SELECTION | SWTX.EDIT_ON_KEY);
		resultKTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		final CommonKtableCModel commKTableModel = new CommonKtableCModel(resultKTable, 1, 1, supplierList.size() , expertList.size() + (null != evaluationStepWeight ? 3: 2) + (isFixedFactor ? 1 : 0));
		
		final Map<String, Map<String, ExpertEvaluationResult>> supplierExpertEvaluationResultMap = new HashMap<String, Map<String, ExpertEvaluationResult>>();
		
		List<Double> sortList = null;
		boolean hasSupplierStepResult = false;
		// 供应商的结果
		final Map<String, SupplierEvaluationStep> supplierEvaluationStepMap = new HashMap<String, SupplierEvaluationStep>();
		
		// 只有要完成当前评审时才直接从数据库中读取
		if(null != evaluationStep.getStepStatus() && evaluationStep.getStepStatus().equals(CommonEnum.COMPLETE)){
			
			// 以结果表为准
			List<SupplierEvaluationStep> supplierEvaluationStepList = supplierEvaluationStepService.getSupplierEvaluationStepByTenderIdAndStepId(tenderProjectEntity.getId(),evaluationStep.getId());
			if(null != supplierEvaluationStepList && supplierEvaluationStepList.size() > 0){
				for(SupplierEvaluationStep supplierEvaluationStep : supplierEvaluationStepList){
					supplierEvaluationStepMap.put(supplierEvaluationStep.getSupplierId(), supplierEvaluationStep);
				}
				hasSupplierStepResult = true;
			}else {
				hasSupplierStepResult = false;
				
			}
		}
		if(!hasSupplierStepResult){
			sortList = new ArrayList<Double>();
		}
		final Map<String, Color> resultBackgroundMap = new HashMap<String, Color>();
		for(Supplier supplier : supplierList){
			Map<String, ExpertEvaluationResult>  expertEvaluationResultMap = new HashMap<String, ExpertEvaluationResult>();
			List<ExpertEvaluationResult> expertEvaluationResultList = expertEvaluationResultService.getSupplierStepAllExpertEvaluationResultList(tenderProjectEntity.getId(), evaluationStep.getId(), supplier.getId());
			if(null != expertEvaluationResultList){
				
				// 供应商当前评标节点终得分平均分
				BigDecimal stepAvgEvaluationFinalScoreSum = null;
				// 供应商当前评标节点平均分
				BigDecimal stepAvgEvaluationScoreSum = null;
				int expertCount = 0;
				for(ExpertEvaluationResult expertEvaluationResult : expertEvaluationResultList){
					expertEvaluationResultMap.put(expertEvaluationResult.getUserId(), expertEvaluationResult);
					if(null != expertEvaluationResult.getEvaluationScore()){
						stepAvgEvaluationScoreSum = BigDecimalUtils.add(stepAvgEvaluationScoreSum, expertEvaluationResult.getEvaluationScore());
						stepAvgEvaluationFinalScoreSum = BigDecimalUtils.add(stepAvgEvaluationFinalScoreSum, expertEvaluationResult.getEvaluationFinalScore());
						expertCount ++;
					}
				}
				supplierExpertEvaluationResultMap.put(supplier.getId(), expertEvaluationResultMap);
				if(!isByExpertEvaluationGroup && null != stepAvgEvaluationFinalScoreSum && expertCount > 0){
					stepAvgEvaluationScoreSum = BigDecimalUtils.div(stepAvgEvaluationScoreSum, new BigDecimal(expertCount), scoreRound);
					stepAvgEvaluationFinalScoreSum = BigDecimalUtils.div(stepAvgEvaluationFinalScoreSum, new BigDecimal(expertCount), scoreRound);
				}
				
				boolean ignoreOverWarningCore = false;
				// 按专家分工评审时，不显示预警
				if(!isByExpertEvaluationGroup){
					if(expertCount > 1 && null != warningRange && null != evaluationStep.getSummaryType() && evaluationStep.getSummaryType().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.SUMMARY_IGNORE_OVER_WARNING_CORE)){
						ignoreOverWarningCore = true;
					}
					
					// 显示并计算是否超出预警值
					if(ignoreOverWarningCore){
						BigDecimal[] stepAvgResult = expertEvaluationResultService.getSupplierStepAvgResult(tenderProjectEntity.getId(), evaluationStep.getId(), supplier.getId(), false);
						if(null != stepAvgResult){
							stepAvgEvaluationScoreSum = stepAvgResult[0];
							stepAvgEvaluationFinalScoreSum = stepAvgResult[1];
						}
						int noIgnoreCount = 0;
						BigDecimal supplierNoignoreEvaluationFinalScoreSum = BigDecimal.ZERO;
						BigDecimal supplierNoignoreEvaluationScoreSum = BigDecimal.ZERO;
						BigDecimal expertMinFinalScore = null;
						BigDecimal expertMinScore = 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){
									resultBackgroundMap.put(expertEvaluationResult.getId(), errorBgColor);
								}else {
									supplierNoignoreEvaluationFinalScoreSum = BigDecimalUtils.add(supplierNoignoreEvaluationFinalScoreSum, expertEvaluationResult.getEvaluationFinalScore());
									supplierNoignoreEvaluationScoreSum = BigDecimalUtils.add(supplierNoignoreEvaluationScoreSum, expertEvaluationResult.getEvaluationScore());
									noIgnoreCount ++;
								}
								// 记录分项的最小值 
								if(null == expertMinScore || expertEvaluationResult.getEvaluationScore().compareTo(expertMinScore) < 0){
									expertMinScore = expertEvaluationResult.getEvaluationScore();
									expertMinFinalScore = expertEvaluationResult.getEvaluationFinalScore();
								}
							}
						}
						
						if(noIgnoreCount > 0){
							stepAvgEvaluationScoreSum = BigDecimalUtils.div(supplierNoignoreEvaluationScoreSum, new BigDecimal(noIgnoreCount), tenderProjectRuleEntity.getScoreRoundIntVal());
							stepAvgEvaluationFinalScoreSum = 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) {
								stepAvgEvaluationScoreSum = null != expertMinScore ? expertMinScore : BigDecimal.ZERO;
								stepAvgEvaluationFinalScoreSum = null != expertMinFinalScore ? expertMinFinalScore : BigDecimal.ZERO;
							}
						}
					}
				}
				SupplierEvaluationStep supplierEvaluationStep = supplierEvaluationStepMap.get(supplier.getId());
				if(null == supplierEvaluationStep){
					supplierEvaluationStep = new SupplierEvaluationStep();
					
					BigDecimal[] stepAvgResult = null;
					if(ignoreOverWarningCore){
						if(null == stepAvgResult){
							stepAvgResult = new BigDecimal[]{stepAvgEvaluationScoreSum, stepAvgEvaluationFinalScoreSum};
						}
					}else if(null != evaluationStep.getSummaryType() && evaluationStep.getSummaryType().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.SUMMARY_REMOVE_FACTOR_MAX_MIN)){
						stepAvgResult = expertEvaluationResultService.getSupplierStepAvgResultByFactor(tenderProjectEntity.getId(), evaluationStep.getId(), supplier.getId(), expertCount > 2 ? true : false);
					}else if(null != evaluationStep.getSummaryType() && evaluationStep.getSummaryType().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.SUMMARY_BY_FACTOR_SUM)){
						stepAvgResult = expertEvaluationResultService.getSupplierStepAvgResultByFactor(tenderProjectEntity.getId(), evaluationStep.getId(), supplier.getId(), false);
					}else {
						boolean removeMaxAndMin = null != evaluationStep.getSummaryType() && evaluationStep.getSummaryType().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.SUMMARY_REMOVE_MAX_MIN);
						stepAvgResult = expertEvaluationResultService.getSupplierStepAvgResult(tenderProjectEntity.getId(), evaluationStep.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);
					supplierEvaluationStepMap.put(supplier.getId(), supplierEvaluationStep);
				}
				
				if(null != supplierEvaluationStep.getEvaluationFinalScore() && null != sortList){
					sortList.add(supplierEvaluationStep.getEvaluationFinalScore().doubleValue());
				}
				
				if(null != fixedFactorItemVoList && null != stepAvgEvaluationScoreSum) {
					for(FixedFactorItemVo vo : fixedFactorItemVoList) {
						int mathCount = 0;
						if(null != vo.getItemMinScore()) {
							if(vo.isIncludeMin()) {
								if(stepAvgEvaluationScoreSum.compareTo(vo.getItemMinScore()) >= 0) {
									mathCount ++;
								}
							}else {
								if(stepAvgEvaluationScoreSum.compareTo(vo.getItemMinScore()) > 0) {
									mathCount ++;
								}
							}
						}
						if(null != vo.getItemMaxScore()) {
							if(vo.isIncludeMax()) {
								if(stepAvgEvaluationScoreSum.compareTo(vo.getItemMaxScore()) <= 0) {
									mathCount ++;
								}
							}else {
								if(stepAvgEvaluationScoreSum.compareTo(vo.getItemMaxScore()) < 0) {
									mathCount ++;
								}
							}
						}
						if(mathCount == 2) {
							supplierGradeMap.put(supplier.getId(), vo.getName());
							break;
						}
					}
				}
				
			}
		}
		if(!hasSupplierStepResult && null != sortList){
			SortUtils sortUtil = new SortUtils(sortList);
			for(Entry<String, SupplierEvaluationStep> supplierEvaluationStepEntry : supplierEvaluationStepMap.entrySet()){
				SupplierEvaluationStep supplierEvaluationStep = supplierEvaluationStepEntry.getValue();
				if(null != supplierEvaluationStep.getEvaluationFinalScore()){
					supplierEvaluationStep.setSortNo(sortUtil.getSortNo(supplierEvaluationStepEntry.getValue().getEvaluationFinalScore().doubleValue()));
				}
			}
		}
		int reduceFixedFactorCol = isFixedFactor ? 1 : 0;
		final int evaluationSoreCol = (null != evaluationStepWeight ? commKTableModel.getColCount() - 3 : -1) - reduceFixedFactorCol ;
		final int evaluationFinalSoreCol = commKTableModel.getColCount() - 2 - reduceFixedFactorCol;
		final int sortNo = commKTableModel.getColCount() -1 - reduceFixedFactorCol;
		final int fixedFactorCol = isFixedFactor ? (commKTableModel.getColCount() -1) : -1;
		final Map<String, String> _supplierGradeMap = supplierGradeMap;
		// 设置单元格内容
		CellContentRender contentRender = new CellContentRender(){
			public Object receiveContent(int row, int col) {
				if(row < commKTableModel.getFixedRowCount()){
					if(col == 0){
						return MessageFormat.format(Messages.Supplier, Messages.Name);
					}else if(col < commKTableModel.getFixedColumnCount() + expertList.size()){
						AuthUser user = expertList.get(col - commKTableModel.getFixedColumnCount());
						return user.getUserName();
					}else if(col == evaluationSoreCol){
						return Messages.TotalScore;
					}else if(col == evaluationFinalSoreCol){
						return Messages.FinalScore;
					}else if(col == sortNo){
						return Messages.SortNo;
					}else if(col == fixedFactorCol) {
						return "定档";
					}
				}else {
					Supplier supplier = supplierList.get(row - commKTableModel.getFixedRowCount());
					if(col == 0){
						return supplier.getSupplierName();
					}else if(col < commKTableModel.getFixedColumnCount() + expertList.size()){
						AuthUser user = expertList.get(col - commKTableModel.getFixedColumnCount());
						Map<String, ExpertEvaluationResult> expertEvaluationResultMap = supplierExpertEvaluationResultMap.get(supplier.getId());
						ExpertEvaluationResult expertEvaluationResult = expertEvaluationResultMap.get(user.getId());
						if(null != expertEvaluationResult && null != expertEvaluationResult.getEvaluationScore()){
							return NumberFormatUtils.format(expertEvaluationResult.getEvaluationScore(), expertScoreRound);
						}
					}else{
						SupplierEvaluationStep supplierEvaluationStep = supplierEvaluationStepMap.get(supplier.getId());
						if(null != supplierEvaluationStep){
							if(col == evaluationSoreCol){
								if(null != supplierEvaluationStep.getEvaluationScore()){
									return NumberFormatUtils.format(supplierEvaluationStep.getEvaluationScore(), scoreRound);
								}
							}else if(col == evaluationFinalSoreCol){
								if(null != supplierEvaluationStep.getEvaluationFinalScore()){
									return NumberFormatUtils.format(supplierEvaluationStep.getEvaluationFinalScore(), scoreRound);
								}
							}else if(col == sortNo){
								Integer stepSortNo = supplierEvaluationStep.getSortNo();
								if(null != stepSortNo && stepSortNo > 0){
									return supplierEvaluationStep.getSortNo();
								}
							}else if(col == fixedFactorCol) {
								return ObjectUtils.getObjString(_supplierGradeMap.get(supplier.getId()));
							}
						}
					} 
				}
				return "";
		}};
		commKTableModel.setCellContentRender(contentRender);
		
		// 设置单元格渲染器
		CellRender cellRender = new CellRender(){
			public Object receiveCellRender(int row, int col) {
				if(commKTableModel.isFixedCell(col, row)){
					return new FixedWrapCellRenderer();
				}else{
					return new TextWrapCellRenderer();
				}
		}};
		commKTableModel.setCellRender(cellRender);
		
		// 编辑单元格对齐方式
		CellAlignmentRender cellAlignmentRender = new CellAlignmentRender(){
			public int receiveCellAlignment(int row, int col) {
				if(row >= commKTableModel.getFixedRowCount() && col == 0){
					return SWTX.ALIGN_VERTICAL_CENTER | SWTX.ALIGN_HORIZONTAL_LEFT;
				}else {
					return SWTX.ALIGN_VERTICAL_CENTER | SWTX.ALIGN_HORIZONTAL_CENTER;
				}
			}
		};
		commKTableModel.setCellAlignmentRender(cellAlignmentRender);
		// 设置单元格背景颜色
		CellBackgroundRender cellBackgroundRender = new CellBackgroundRender(){
			public Color receiveCellBackground(int row, int col) {
				
				if(row >= commKTableModel.getFixedRowCount()){
					if(col < commKTableModel.getFixedColumnCount() + expertList.size()){
						Supplier supplier = supplierList.get(row - commKTableModel.getFixedRowCount());
						AuthUser user = expertList.get(col - commKTableModel.getFixedColumnCount());
						Map<String, ExpertEvaluationResult> expertEvaluationResultMap = supplierExpertEvaluationResultMap.get(supplier.getId());
						ExpertEvaluationResult expertEvaluationResult = expertEvaluationResultMap.get(user.getId());
						if(null != expertEvaluationResult && null != expertEvaluationResult.getEvaluationScore()){
							return resultBackgroundMap.get(expertEvaluationResult.getId());
						}
					}
				}
				return null;
			}
		};
		commKTableModel.setCellBackgroundRender(cellBackgroundRender);
		resultKTable.setModel(commKTableModel);
		
		resultKTable.addCellSelectionListener(new KTableCellSelectionAdapter(){
			@Override
			public void cellSelected(int col, int row, int statemask) {
				if(row >= commKTableModel.getFixedRowCount()){
					curSupplier = supplierList.get(row - commKTableModel.getFixedRowCount());
				}
			}
		});
	}

	/**
	 * @Description: 校验客观项与评审是否一致
	 * @author guoyr
	 * @param supplierId
	 * @param factorId
	 */
	private void checklObjectiveFactorResult(EvaluationFactorResult evaluationFactorResult, String supplierId, String factorId){
		boolean equalsResult = true;
		BigDecimal curEvaluationScore = evaluationFactorResult.getEvaluationScore();
		if(null != curEvaluationScore){
			List<BigDecimal> evaluationResultList = evaluationFactorResultService.getEvaluationScoreList(tenderProjectEntity.getId(), evaluationStep.getId(), supplierId, factorId);
			if(null != evaluationResultList){
				for(BigDecimal evaluationResult : evaluationResultList){
					if(null != evaluationResult && curEvaluationScore.compareTo(evaluationResult) != 0){
						equalsResult = false;
						break;
					}
				}
			}
		}
		contentBackgroundMap.put(evaluationFactorResult.getId(), equalsResult ? rightBgColor : errorBgColor);
	}
	
	/**
	 * @Description: 根据 父级数与当前 指标，查找指定 的父级指标 ，如果 没有，则返回本身指标
	 * @author guoyr
	 * @param evaluationFactor
	 * @param level
	 * @return
	 */
	private EvaluationFactor getParentFactor(EvaluationFactor evaluationFactor, int level){
		EvaluationFactor parent = evaluationFactor.getParentFactor();
		if(null != parent){
			if(parent.getLevel() == level){
				return parent;
			}else if(parent.getLevel() > level) {
				return getParentFactor(parent, level);
			}else {
				return evaluationFactor;
			}
		}
		return parent;
	}
	
	/**
	 * @Description: 获取当前指标下子指标 数量 
	 * @author guoyr
	 * @param evaluationFactor
	 * @return
	 */
	private int getChildCount(EvaluationFactor evaluationFactor){
		List<EvaluationFactor> childrenList = evaluationFactor.getChildFactorList();
		int childCount = null != childrenList?childrenList.size():0;
		if(childCount > 0){
			for(EvaluationFactor childrenFactor : childrenList){
				List<EvaluationFactor> subChildrenList = childrenFactor.getChildFactorList();
				if(null != subChildrenList && subChildrenList.size() > 0){
					childCount--;
					childCount += getChildCount(childrenFactor);
				}
			}
		}
		return childCount;
	}
	

	/**
	 * @Description: 专家被选中事件
	 * @author guoyr
	 */
	private void slectExpertAction(final RectangleRadioButton label, final Expert expert){
		for(Control control : load_composite.getChildren()){
			control.dispose();
		}
		if(null != curExpertBtn && !curExpertBtn.isDisposed()){
			curExpertBtn.setSelection(false);
		}
		curExpertBtn = label;
		curExpertBtn.setSelection(true);
		if(!applyReEvaluation_link.isDisposed()){
			WidgetUtils.setControlVisible(applyReEvaluation_link, false);
		}
		StringBuilder msg = new StringBuilder();
		if(null != expert){
			selectUser = expert.getUser();
			if(isByExpertEvaluationGroup){
				initEvaluationStepFactor(expert.getUserId());
			}
			if(null == evaluationFactorList)evaluationFactorList = new ArrayList<EvaluationFactor>();
			
			ExpertEvaluationStep expertEvaluationStep = expertEvaluationStepService.getExpertEvaluationStep(tenderProjectEntity.getId(), evaluationStep.getId(), expert.getUserId());
			if(null != expertEvaluationStep){
				msg.append("[");
				msg.append(evaluationStep.getStepName());
				msg.append("]");
				msg.append(Messages.EvalStartTime);
				msg.append("：");
				msg.append(null != expertEvaluationStep.getStartTime()?DateUtils.getTimestampFormat(expertEvaluationStep.getStartTime()):"");
				msg.append("---");
				if(ObjectUtils.equals(expertEvaluationStep.getStepStatus(), CommonEnum.COMPLETE)){
					msg.append(Messages.EvalEndTime);
					msg.append("：");
					msg.append(null != expertEvaluationStep.getEndTime()?DateUtils.getTimestampFormat(expertEvaluationStep.getEndTime()):"");
					
//					long useTime = expertEvaluationStep.getEndTime().getTime() - expertEvaluationStep.getStartTime().getTime();
//					if(useTime > 0){
//						msg.append("   用时：");
//						msg.append(DateUtils.timeSpan(useTime));
//					}
					if(!applyReEvaluation_link.isDisposed()){
						WidgetUtils.setControlVisible(applyReEvaluation_link, true);
						applyReEvaluation_link.setData("expertEvaluationStep", expertEvaluationStep);
					}
				}else {
					msg.append(MessageFormat.format(Messages.Tips_progressIn, evaluationStep.getStepName()));
				}
			}else {
				msg.append(MessageFormat.format(Messages.Tips_progressNotStart, evaluationStep.getStepName()));
//				msg.append("点击“切换坐标”，可切换指标坐标！");
			}
			
			initEvaluationResult(expert.getUserId());
			if(Constants.FACTOR_IS_HORIZONTAL){
				drawLeftFactorEvaluationTable();
			}else {
				drawLeftSupplierEvaluationTable();
			}
			refreshObjectiveBackgroundMap();
			refreshExpertEvaluationStatus();
		}else {
			selectUser = null;
			if(null != evaluationStep.getStepStatus() &&evaluationStep.getStepStatus().equals(CommonEnum.COMPLETE)){
				msg.append(MessageFormat.format(Messages.Tips_progressComplate, evaluationStep.getStepName()));
			}else if(null != evaluationStep.getStepStatus() && (evaluationStep.getStepStatus().equals(CommonEnum.IN_PROGRESS) || evaluationStep.getStepStatus().equals(CommonEnum.RE_OPERATOR))){
				msg.append(MessageFormat.format(Messages.Tips_progressIn, evaluationStep.getStepName()));
			}else {
				msg.append(MessageFormat.format(Messages.Tips_progressNotStart, evaluationStep.getStepName()));
			}
			msg.append("  ").append(Messages.Title_bidEvaluationRules).append(":");
			if(StringUtils.equals(evaluationStep.getFilterType(), com.gx.obe.components.core.enumeration.EvaluationStepEnum.FILTER_YES)){
				if(ObjectUtils.equals(evaluationStep.getPassType(), com.gx.obe.components.core.enumeration.EvaluationStepEnum.PASS_MORE)){
					msg.append(MessageFormat.format(Messages.Tips_evaluationRule_filter, Messages.MinorityObeyMajority, EVAL_UNQUALIFIED, supplierName));
				}else {
					msg.append(MessageFormat.format(Messages.Tips_evaluationRule_filter, Messages.OneTicketVeto, EVAL_UNQUALIFIED, supplierName));
				}
			}else {
				double filterScore = evaluationStep.getEvaluationParamByKey(com.gx.obe.components.core.enumeration.EvaluationStepEnum.PARAM_FILTER_SCORE, Double.class, Double.valueOf(0));
				if(evaluationStep.getFinalistNumber() > 0){
					msg.append(MessageFormat.format(Messages.Tips_evaluationRule_sortNoFilter, evaluationStep.getFinalistNumber(), supplierName));
				}else if(filterScore > 0){
					msg.append(MessageFormat.format(Messages.Tips_evaluationRule_scoreFilter, filterScore, supplierName));
				}else {
					msg.append(MessageFormat.format(Messages.Tips_evaluationRule_noFilter, supplierName));
				}
			}
			if(null != evaluationStepWeight){
				msg.append(MessageFormat.format(Messages.Tips_evaluationRule_weight, NumberFormat.getInstance().format(evaluationStepWeight)));
			}
			drawEvaluationResultTable();
		}
		message_label.setText(msg.toString());
		WidgetUtils.setControlVisible(viewScoreChart, null == expert);
		WidgetUtils.setControlVisible(viewFactorOpinion_link, null != expert);
		WidgetUtils.setControlVisible(evaluationOpintion_link, null == expert);
		WidgetUtils.setControlVisible(switchCoordinateBtn, null != expert);
		if(null != expert){
			curExpertBtn.setData(expert.getId());
		}else {
			curExpertBtn.setData(null);
		}
		
		message_composite.layout();
		load_composite.layout();
		layout();
	}
	
	/**
	 * @Description: 刷新专家评标进度
	 * @author guoyr 
	 */
	public void refreshExpertEvaluationStatus(){
		// 只有显示全部专家时才刷新专家的评标完成状态
		if(null != this.CURRENT_EXPERT){
			return;
		}
		List<ExpertEvaluationStep> expertEvaluationStepList = expertEvaluationStepService.getEvaluationStepListByStepId(tenderProjectEntity.getId(), evaluationStep.getId());
		if(null != expertEvaluationStepList && expertEvaluationStepList.size() > 0 && null != expertEvaluationBtnMap){
			boolean refresh = false;
			boolean complate = expertList.size() == expertEvaluationStepList.size();
			for(ExpertEvaluationStep expertEvaluationStep : expertEvaluationStepList){
				RectangleRadioButton expertStepBtn = expertEvaluationBtnMap.get(expertEvaluationStep.getUserId());
				if(null != expertStepBtn && !expertStepBtn.isDisposed()){
					if(ObjectUtils.equals(expertEvaluationStep.getStepStatus(), CommonEnum.COMPLETE)){
						if(null == expertStepBtn.getImage()){
							expertStepBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/green/ok.png"));
							refresh = true;
						}
					}else {
						complate = false;
						if(null != expertStepBtn.getImage()){
							expertStepBtn.setImage(null);
							refresh = true;
						}
					}
				}
			}
			RectangleRadioButton totalExpertBtn = expertEvaluationBtnMap.get("totalExpert");
			if(null != totalExpertBtn && !totalExpertBtn.isDisposed()){
				if(complate){
					if(null == totalExpertBtn.getImage()){
						totalExpertBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/green/ok.png"));
						refresh = true;
					}
				}else {
					if(null != totalExpertBtn.getImage()){
						totalExpertBtn.setImage(null);
						refresh = true;
					}
				}
			}
			if(refresh){
				if(null != expertEvaluationListener && complate){
					expertEvaluationListener.refresh();
				}
				expert_list_composite.layout();
			}
		}
	}
	
	/**
	 * @Description: 切换坐标
	 * @author guoyr
	 */
	private void switchCoordinateAction(){
		if(null != resultKTable && !resultKTable.isDisposed()){
			resultKTable.dispose();
		}
		if(null != curExpertBtn && null != curExpertBtn.getData()){
			Constants.FACTOR_IS_HORIZONTAL = !Constants.FACTOR_IS_HORIZONTAL;
			if(Constants.FACTOR_IS_HORIZONTAL){
				drawLeftFactorEvaluationTable();
			}else {
				drawLeftSupplierEvaluationTable();
			}
		}
		load_composite.layout();
	}
	
	/**
	 * @Description: 申请回退
	 * @author guoyr 
	 */
	private void applyReEvaluationAction(){
		if(applyReEvaluation_link.getEnabled()){
			if(null != applyReEvaluation_link.getData("expertEvaluationStep")){
				ExpertEvaluationStep expertEvaluationStep = (ExpertEvaluationStep)applyReEvaluation_link.getData("expertEvaluationStep");
				if(null != expertEvaluationStep){
					ApplyReEvaluationDialog applyReEvaluationDialog = new ApplyReEvaluationDialog(getShell(), evaluationStep, expertEvaluationStep);
					applyReEvaluationDialog.open();
				}
			}
		}
	}
	
	/**
	 * @Description: 打开评分离散度分析表
	 * @author guoyr 
	 */
	private void openViewScoreChartAction(){
		SupplierExpertScoreDialog dialog = new SupplierExpertScoreDialog(getShell(), tenderProjectEntity, evaluationStep);
		dialog.open();
	}
	
	/**
	 * @Description: 供应商评（废）标意见
	 * @author guoyr 
	 */
	private void evaluationOpinionAction(){
		if(null != curSupplier){
			SupplierEvaluationOpinionDetailDialog dialog = new SupplierEvaluationOpinionDetailDialog(getShell(), tenderProjectEntity, curSupplier);
			dialog.open();
		}
	}
	
	public boolean isShowObjectiveDialog() {
		return isShowObjectiveDialog;
	}
	
	
	
	public void addExpertEvaluationListener(ExpertEvaluationListener expertEvaluationListener){
		this.expertEvaluationListener = expertEvaluationListener;
	}
	
	/**
	 * @Description: 查看指标评审意见
	 * @author guoyr
	 * @param isViewSupplierOpinion 
	 */
	private void viewFactorOpinionAction(){
		if(null != selectUser) {
			FactorOpinionDialog dialog = new FactorOpinionDialog(getShell(), tenderProjectEntity, evaluationStep, selectUser, supplierList, evaluationFactorList, null);
			dialog.open();
		}
	}
	/**
	 * @Description: 查看（编辑）投标人评议意见或投标响应
	 * @author guoyr
	 * @param isViewSupplierOpinion true:查看评议意见
	 */
	private void viewBidFileOpinionAction(){
		BidFileOpinionDialog dialog = new BidFileOpinionDialog(getShell(), tenderProjectEntity, evaluationStep, supplierList, evaluationFactorList, null, true, false);
		dialog.open();
	}
	
	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}
}
