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

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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.listener.ExpertEvaluationListener;
import com.gx.obe.message.Messages;
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.ObjectUtils;
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.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.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 ComplianceEvaluationResultComposite extends Composite {

	private TenderProjectEntity tenderProjectEntity;
	private TenderProjectRuleEntity tenderProjectRuleEntity;
	private EvaluationStep evaluationStep;
	private Expert CURRENT_EXPERT;
	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;
	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 boolean isShowObjectiveDialog = false;// 是否显示客观项评审意见信息。
	private String hiddenResultTable;
	private String supplierName;
	private Color QUALIFIE_COLOR = SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN);
	private Color UNQUALIFIED_COLOR = SWTResourceManager.getColor(SWT.COLOR_RED);
	private Color rightBgColor = SWTResourceManager.getColor(194, 236, 150);
	private Color errorBgColor = SWTResourceManager.getColor(255, 153, 153);
	private final Map<Keys, Color> objectiveBackgroundMap = new HashMap<Keys, Color>();
	// 记录供应商每个指标的评审结果
	private Map<String, Map<String, EvaluationFactorResult>> supplierEvaluationFactorResultMap;
	// 记录专家对供应商的评审汇总结果
	private Map<String, ExpertEvaluationResult> expertEvaluationResultMap;
	private String EVAL_QUALIFIED = Messages.Qualified;
	private String EVAL_UNQUALIFIED = Messages.Unqualified;
	private String EVAL_ACCESSMENT_YES = Messages.Qualified;
	private String EVAL_ACCESSMENT_NO = Messages.Unqualified;
//	private Logger LOG = Logger.getLogger(ComplianceEvaluationResultComposite.class);
	private Composite expert_list_composite;
	private Composite load_composite;
	private RectangleRadioButton curExpertBtn;
	private AuthUser selectUser;
	private Label message_label;
	private ELink switchCoordinateBtn;
	private Composite tabItem_composite;
	private Map<String, RectangleRadioButton> expertEvaluationBtnMap;
	private ExpertEvaluationListener expertEvaluationListener;
	private ELink applyReEvaluation_link;
	private ELink evaluationOpintion_link;
	private Supplier curSupplier;
	private Composite message_composite;
	private String emptyScoreContent = "";
	private boolean hasObjectiveFactor = false;
//	private ELink viewSupplierResponse_btn;
	
	private ExpertEvaluationStepService expertEvaluationStepService = new ExpertEvaluationStepService();
	private MenuFunctionUtils menuFunctionUtils = new MenuFunctionUtils();
	private Menu menu;
	private ELink viewFactorOpinion_link;
	{
		LogUtils.logClass(ComplianceEvaluationResultComposite.class);
	}
	
	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public ComplianceEvaluationResultComposite(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();
				}
				objectiveBackgroundMap.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);
		
		tabItem_composite = new Composite(this, SWT.NONE);
		tabItem_composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		GridLayout gl_tabItem_composite = new GridLayout(1, false);
		gl_tabItem_composite.marginTop = 5;
		gl_tabItem_composite.verticalSpacing = 0;
		gl_tabItem_composite.marginWidth = 0;
		gl_tabItem_composite.marginHeight = 0;
		tabItem_composite.setLayout(gl_tabItem_composite);
		
		expert_list_composite = new Composite(tabItem_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(tabItem_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(6, false);
		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.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/hand.png"));
		applyReEvaluation_link.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		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();
			}
		});
		
		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();
		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();
		}
		initEvaluationStepFactor();
		if(null == evaluationFactorList)evaluationFactorList = new ArrayList<EvaluationFactor>();

		// 为了显示样式，没有专家时生成一个临时专家
		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); 
		}
		if(null != evaluationStep.getSummaryType() && evaluationStep.getSummaryType().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.SUMMARY_SCORE_BY_QUALIFIED)){
			EVAL_ACCESSMENT_YES = "通过";
			EVAL_ACCESSMENT_NO = "不通过";
		}
		
		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){
				AuthUser user = _expert.getUser();
				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);
					}
				});
				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);
			}
		}
		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;
						String evaluationResult = null;
						for (EvaluationFactorResult evaluationFactorResult : factorResultList) {
							String result = evaluationFactorResult.getEvaluationResult();
							if (evaluationResult == null) {
								evaluationResult = result;
							} else if (result != null && !evaluationResult.equals(result)) {
								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 
	 */
	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 complate = expertList.size() == expertEvaluationStepList.size();
			boolean refresh = false;
			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 initEvaluationStepFactor(){
		hasObjectiveFactor = false;
		evaluationFactorList.clear();
		maxLevel = 1;
		List<EvaluationFactor> evaluationTopFactorList = evaluationFactorService.getEvaluationStepFactorTreeList(tenderProjectEntity.getId(), evaluationStep);
		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());
			evaluationFactorList.add(evalFactor);
			
			if(!hasObjectiveFactor && EvaluationFactorEnum.OBJECTIVE_YES.equals(evalFactor.getObjective())){
				hasObjectiveFactor = true;
			}
		}
	}
	/**
	 * @Description: 初始化评标结果
	 * @author guoyr
	 * @param userId 
	 */
	private void initEvaluationResult(String userId){
		// 记录供应商每个指标的评审结果
		supplierEvaluationFactorResultMap = new HashMap<String, Map<String, EvaluationFactorResult>>();
		// 记录专家对供应商的评审汇总结果
		expertEvaluationResultMap = new HashMap<String, ExpertEvaluationResult>();
		
		// 评审当前评标专家所有的评标结果
		List<EvaluationFactorResult> memberEvaluateFactorResultList = evaluationFactorResultService.getExpertEvaluationFactorResult(tenderProjectEntity.getId(), evaluationStep.getId(), userId, null);
		List<ExpertEvaluationResult> queryExpertEvaluationResultList = expertEvaluationResultService.getExpertStepAllSupplierEvaluationResultList(tenderProjectEntity.getId(), evaluationStep.getId(), userId);
		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());
			}
			
			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
	 */
	private void drawLeftSupplierEvaluationTable(){
		resultKTable = new KTable(load_composite, SWTX.AUTO_SCROLL | SWT.FULL_SELECTION | SWTX.FILL_WITH_LASTCOL | 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() + 1);
		commKTableModel.addRowSpan(0, 0, commKTableModel.getFixedRowCount());
		commKTableModel.addRowSpan(0, commKTableModel.getColCount() -1, commKTableModel.getFixedRowCount());
		
		commKTableModel.setColumnMinWidth(0, 100);
		commKTableModel.setColumnMinWidth(1, 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));
			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, 110);
					commKTableModel.setColumnMinWidth(col, 110);
				}
				col ++;
			}
			tableTitleMap.put(row+"_"+(commKTableModel.getColCount() -1), Messages.Conclusion);
		}
		
		// 设置单元格内容
		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 {
					int supplierIndex = row - commKTableModel.getFixedRowCount();
					Supplier supplier = supplierList.get(supplierIndex);
					if(col < commKTableModel.getFixedColumnCount()){
						if(col == 0){
							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());
						return evalFactorResult.getEvalPassTypeCN(evaluationFactor.getEvalContent());
					}else if(col == commKTableModel.getColCount() -1){
						ExpertEvaluationResult expertEvaluationResult  = expertEvaluationResultMap.get(supplier.getId());
						if(null != expertEvaluationResult && null != expertEvaluationResult.getAccessment()){
							if(expertEvaluationResult.getAccessment().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.QUALIFIED)){
								return EVAL_ACCESSMENT_YES;
							}else if(expertEvaluationResult.getAccessment().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.UNQUALIFIED)){
								return EVAL_ACCESSMENT_NO;
							}
							return emptyScoreContent;
						}
					}
				}
				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(col == 0){
						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(row >= commKTableModel.getFixedRowCount()){
					Supplier supplier = supplierList.get(row - commKTableModel.getFixedRowCount());
					ExpertEvaluationResult expertEvaluationResult  = expertEvaluationResultMap.get(supplier.getId());
					if(col >= commKTableModel.getFixedColumnCount() && col < commKTableModel.getFixedColumnCount() + evaluationFactorList.size()){
						EvaluationFactor evaluationFactor = evaluationFactorList.get(col - commKTableModel.getFixedColumnCount());
						EvaluationFactorResult evalFactorResult = supplierEvaluationFactorResultMap.get(supplier.getId()).get(evaluationFactor.getId());
						if(ObjectUtils.equals(evalFactorResult.getEvaluationResult(), EvaluationFactorEnum.CONFORM)){
							return QUALIFIE_COLOR;
						}else if(ObjectUtils.equals(evalFactorResult.getEvaluationResult(), EvaluationFactorEnum.UNCONFORM)){
							return UNQUALIFIED_COLOR;
						}
					}else if(col == commKTableModel.getColCount() -1){
						if(null != expertEvaluationResult && null != expertEvaluationResult.getAccessment()){
							if(expertEvaluationResult.getAccessment().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.QUALIFIED)){
								return QUALIFIE_COLOR;
							}else if(expertEvaluationResult.getAccessment().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.UNQUALIFIED)){
								return UNQUALIFIED_COLOR;
							}
						}
					}
				}
				return null;
			}
		};
		commKTableModel.setCellForegroundRender(cellForegroundRender);
		
		// 设置单元格背景颜色
		CellBackgroundRender cellBackgroundRender = new CellBackgroundRender(){
			public Color receiveCellBackground(int row, int col) {
				if(row >= commKTableModel.getFixedRowCount() && col >= commKTableModel.getFixedColumnCount() && col < commKTableModel.getFixedColumnCount() + evaluationFactorList.size()){
					Supplier supplier = supplierList.get(row - commKTableModel.getFixedRowCount());
					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;
						}
					} 
				}
				return null;
			}
		};
		commKTableModel.setCellBackgroundRender(cellBackgroundRender);
		// 设置单元格内容
		CellTooltipRender cellTooltipRender = new CellTooltipRender(){
			public String receiveCellTooltip(int row, int col) {
				if(row >= commKTableModel.getFixedRowCount() && col >= commKTableModel.getFixedColumnCount() && col < commKTableModel.getFixedColumnCount() + evaluationFactorList.size()){
					Supplier supplier = supplierList.get(row - commKTableModel.getFixedRowCount());
					EvaluationFactor evaluationFactor = evaluationFactorList.get(col - commKTableModel.getFixedColumnCount());
					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
	 */
	private void drawLeftFactorEvaluationTable(){

		if(null != resultKTable && !resultKTable.isDisposed()){
			resultKTable.dispose();
		}
		final Map<String, String> tableTitleMap = new HashMap<String, String>();
		resultKTable = new KTable(load_composite, SWTX.AUTO_SCROLL | SWT.FULL_SELECTION | SWTX.FILL_WITH_LASTCOL | SWTX.EDIT_ON_KEY);
		resultKTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		commKTableModel = new CommonKtableCModel(resultKTable, 1, maxLevel, evaluationFactorList.size() + 1, supplierList.size());
//		tableTitleMap.put("0_0", Messages.EvalFactor);
		tableTitleMap.put("0_0", Messages.Factor_factor);
		tableTitleMap.put("0_"+(commKTableModel.getColCount() -1), Messages.Conclusion);
		commKTableModel.addColSpan(0, 0, commKTableModel.getFixedColumnCount());
		commKTableModel.addColSpan(commKTableModel.getRowCount() -1, 0, commKTableModel.getFixedColumnCount());
		int col = commKTableModel.getFixedColumnCount();
		for(Supplier supplier : supplierList){
			tableTitleMap.put("0_"+col, supplier.getSupplierName());
			commKTableModel.setColumnWidth(col, 110);
			col ++;
		}
		commKTableModel.setColumnWidth(commKTableModel.getColCount() -1, 50);
		
		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.Factor_factor;
					}else if(row < commKTableModel.getFixedRowCount() + evaluationFactorList.size()){
						EvaluationFactor evaluationFactor = evaluationFactorList.get(row - commKTableModel.getFixedRowCount());
						if(col == commKTableModel.getFixedColumnCount() -1){
							return evaluationFactor.getFactorName();
						}else if(null != tableTitleMap.get(row+"_"+col)){
							return tableTitleMap.get(row+"_"+col);
						}
					}else if(row == commKTableModel.getRowCount() -1){
						return Messages.Conclusion;
					}
					return "";
				}else {
					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){
							return evalFactorResult.getEvalPassTypeCN(null != evaluationFactor? evaluationFactor.getEvalContent() : null);
						}
						
					}else if(row == commKTableModel.getRowCount() -1){
						ExpertEvaluationResult expertEvaluationResult  = expertEvaluationResultMap.get(supplier.getId());
						if(null != expertEvaluationResult && null != expertEvaluationResult.getAccessment()){
							if(expertEvaluationResult.getAccessment().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.QUALIFIED)){
								return EVAL_ACCESSMENT_YES;
							}else if(expertEvaluationResult.getAccessment().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.UNQUALIFIED)){
								return EVAL_ACCESSMENT_NO;
							}
							return emptyScoreContent;
						}
					}
				}
				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()){
					Supplier supplier = supplierList.get(col - commKTableModel.getFixedColumnCount());
					if(row >= commKTableModel.getFixedRowCount() && row < commKTableModel.getFixedRowCount() + evaluationFactorList.size()){
						EvaluationFactor evaluationFactor = evaluationFactorList.get(row - commKTableModel.getFixedRowCount());
						EvaluationFactorResult evalFactorResult = supplierEvaluationFactorResultMap.get(supplier.getId()).get(evaluationFactor.getId());
						if(ObjectUtils.equals(evalFactorResult.getEvaluationResult(), EvaluationFactorEnum.CONFORM)){
							return QUALIFIE_COLOR;
						}else if(ObjectUtils.equals(evalFactorResult.getEvaluationResult(), EvaluationFactorEnum.UNCONFORM)){
							return UNQUALIFIED_COLOR;
						}
					}else if(row == commKTableModel.getRowCount() -1){
						ExpertEvaluationResult expertEvaluationResult  = expertEvaluationResultMap.get(supplier.getId());
						if(null != expertEvaluationResult && null != expertEvaluationResult.getAccessment()){
							if(expertEvaluationResult.getAccessment().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.QUALIFIED)){
								return QUALIFIE_COLOR;
							}else if(expertEvaluationResult.getAccessment().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.UNQUALIFIED)){
								return UNQUALIFIED_COLOR;
							}
						}
					}
				
				}
				return null;
			}
		};
		commKTableModel.setCellForegroundRender(cellForegroundRender);
		
		// 设置单元格背景颜色
		CellBackgroundRender cellBackgroundRender = new CellBackgroundRender(){
			public Color receiveCellBackground(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());
					if(EvaluationFactorEnum.OBJECTIVE_YES.equals(evaluationFactor.getObjective())){
						Color bgColor = objectiveBackgroundMap.get(new Keys(supplier.getId(), evaluationFactor.getId()));
						if (null != bgColor) {
							return bgColor;
						}
					} 
				}
				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
	 */
	private void drawEvaluationResultTable(){
		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>(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() + 2);
		
		// 供应商的结果
		final Map<String, SupplierEvaluationStep> SupplierEvaluationStepMap = new HashMap<String, SupplierEvaluationStep>();
		List<SupplierEvaluationStep> supplierEvaluationStepList = supplierEvaluationStepService.getSupplierEvaluationStepByTenderIdAndStepId(tenderProjectEntity.getId(), evaluationStep.getId());
		if(null != supplierEvaluationStepList){
			for(SupplierEvaluationStep supplierEvaluationStep : supplierEvaluationStepList){
				SupplierEvaluationStepMap.put(supplierEvaluationStep.getSupplierId(), supplierEvaluationStep);
			}
		}
		final Map<String, Map<String, ExpertEvaluationResult>> supplierExpertEvaluationResultMap = new HashMap<String, Map<String, ExpertEvaluationResult>>();
		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){
				
				int accessYesCount = 0;
				int accessNoCount = 0;
				for(ExpertEvaluationResult expertEvaluationResult : expertEvaluationResultList){
					expertEvaluationResultMap.put(expertEvaluationResult.getUserId(), expertEvaluationResult);
					if(null != expertEvaluationResult.getAccessment() && expertEvaluationResult.getAccessment().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.UNQUALIFIED)){
						accessNoCount++;
					}else if(null != expertEvaluationResult.getAccessment() && expertEvaluationResult.getAccessment().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.QUALIFIED)){
						accessYesCount++;
					}
				}
				supplierExpertEvaluationResultMap.put(supplier.getId(), expertEvaluationResultMap);
				// 借用该属性显示汇总结果
				supplier.setMemo(null);
				if(accessYesCount > 0 || accessNoCount > 0){
					StringBuilder msg = new StringBuilder();
					if(accessYesCount > 0){
						msg.append(accessYesCount);
						msg.append("位专家评审");
						msg.append(EVAL_QUALIFIED);
					}
					if(accessNoCount > 0){
						if(accessYesCount > 0){
							msg.append("；");
						}
						msg.append(accessNoCount);
						msg.append("位专家评审");
						msg.append(EVAL_UNQUALIFIED);
					}
					msg.append("。");
					supplier.setMemo(msg.toString());
				}
			}
			
		}
		final int memoCol = commKTableModel.getColCount() -2;
		final int accessmentCol = commKTableModel.getColCount() -1;
			
		// 设置单元格内容
		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 == memoCol){
						return Messages.Statistics;
					}else if(col == accessmentCol){
						return Messages.Conclusion;
					}
				}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){
							if(null != expertEvaluationResult.getAccessment() && expertEvaluationResult.getAccessment().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.QUALIFIED)){
								return EVAL_QUALIFIED;
							}else if(null != expertEvaluationResult.getAccessment() && expertEvaluationResult.getAccessment().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.UNQUALIFIED)){
								return EVAL_UNQUALIFIED;
							}
						}
					}else if(col == memoCol){
						if(null != supplier.getMemo()){
							return supplier.getMemo();
						}
					}else if(col == accessmentCol){
						SupplierEvaluationStep supplierEvaluationStep = SupplierEvaluationStepMap.get(supplier.getId());
						if(null != supplierEvaluationStep){
							if(null != supplierEvaluationStep.getAccessment() && supplierEvaluationStep.getAccessment().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.QUALIFIED)){
								return EVAL_QUALIFIED;
							}else if(null != supplierEvaluationStep.getAccessment() && supplierEvaluationStep.getAccessment().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.UNQUALIFIED)){
								return EVAL_UNQUALIFIED;
							}
						}
						return "";
					}
				}
				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);
		
		CellForegroundRender cellForegroundRender = new CellForegroundRender(){
			public Color receiveCellForeground(int row, int col) {
				if(row >= commKTableModel.getFixedRowCount()){

					Supplier supplier = supplierList.get(row - commKTableModel.getFixedRowCount());
					if(col >= commKTableModel.getFixedColumnCount() && 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){
							if(null != expertEvaluationResult.getAccessment() && expertEvaluationResult.getAccessment().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.QUALIFIED)){
								return QUALIFIE_COLOR;
							}else if(null != expertEvaluationResult.getAccessment() && expertEvaluationResult.getAccessment().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.UNQUALIFIED)){
								return UNQUALIFIED_COLOR;
							}
						}
					}else if(col == accessmentCol){
						SupplierEvaluationStep supplierEvaluationStep = SupplierEvaluationStepMap.get(supplier.getId());
						if(null != supplierEvaluationStep){
							if(null != supplierEvaluationStep.getAccessment() && supplierEvaluationStep.getAccessment().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.QUALIFIED)){
								return QUALIFIE_COLOR;
							}else if(null != supplierEvaluationStep.getAccessment() && supplierEvaluationStep.getAccessment().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.UNQUALIFIED)){
								return UNQUALIFIED_COLOR;
							}
						}
					}
				
				}
				return null;
		}};
		commKTableModel.setCellForegroundRender(cellForegroundRender);
		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 factor
	 * @param row
	 * @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 factor
	 * @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();
		}
		emptyScoreContent = "";
		if(null != curExpertBtn && !curExpertBtn.isDisposed()){
			curExpertBtn.setSelection(false);
		}
		curExpertBtn = label;
		curExpertBtn.setSelection(true);
		if(!applyReEvaluation_link.isDisposed()){
			applyReEvaluation_link.setVisible(false);
		}
		StringBuilder msg = new StringBuilder();
		
		if(null != expert){
			selectUser = expert.getUser();
			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()){
						applyReEvaluation_link.setVisible(true);
						applyReEvaluation_link.setData("expertEvaluationStep", expertEvaluationStep);
					}
					// 当完成评审时，未评审的显示斜杠
					emptyScoreContent = "/";
				}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)){
				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(ObjectUtils.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 {
				msg.append(MessageFormat.format(Messages.Tips_evaluationRule_noFilter, supplierName));
			}
			drawEvaluationResultTable();
		}
		message_label.setText(msg.toString());
		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();
		this.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 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
	}
}
