package com.gx.obe.evaluation.step.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 org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;

import com.gx.obe.ColorConstants;
import com.gx.obe.business.vo.PriceEvaluationFactor;
import com.gx.obe.components.core.I18NEnum;
import com.gx.obe.components.core.enumeration.BidPriceEnum;
import com.gx.obe.components.core.util.MoneyUtils;
import com.gx.obe.message.Messages;
import com.gx.obe.util.utils.NumberFormatUtils;
import com.gx.obe.util.utils.ObjectUtils;
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.SupplierOpeningResult;
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.price.BidPrice;
import com.gx.obe.web.entity.price.BidPriceResult;
import com.gx.obe.web.entity.tender.TenderProjectEntity;
import com.gx.obe.web.entity.tender.TenderProjectRuleEntity;
import com.gx.obe.web.service.BidPriceResultService;
import com.gx.obe.web.service.BidPriceService;
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.swtdesigner.SWTResourceManager;

import de.kupzog.ktable.KTable;
import de.kupzog.ktable.SWTX;
import de.kupzog.ktable.model.CommonKtableCModel;
import de.kupzog.ktable.renderers.CellAlignmentRender;
import de.kupzog.ktable.renderers.CellContentRender;
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 PriceScoreResultTableComposite extends Composite{

	private TenderProjectEntity tenderProjectEntity;
	private EvaluationStep evaluationStep;
	private TenderProjectRuleEntity tenderProjectRuleEntity;
	private Expert CURRENT_EXPERT;
	private EvaluationFactorService evaluationFactorService = new EvaluationFactorService();
	private EvaluationFactorResultService evaluationFactorResultService = new EvaluationFactorResultService();
	private ExpertEvaluationResultService expertEvaluationResultService;
	private BidPriceService bidPriceService ;
	private BidPriceResultService bidPriceResultService;
	private Composite evaluationComposite;
	private Composite evaluationTableComposite;
	private List<EvaluationFactor> evaluationFactorList = new ArrayList<EvaluationFactor>();
	private List<PriceEvaluationFactor> priceEvaluationFactorList;
	private int maxLevel = 1;
	private List<Supplier> supplierList;
	private KTable resultKTable;
	private CommonKtableCModel commKTableModel;
	private String supplierName;
	// 记录供应商每个指标的评审结果
	private Map<String, BidPriceResult> supplierBidPriceResultMap;
	private Map<String, Map<String, EvaluationFactorResult>> supplierEvaluationFactorResultMap;
	// 记录专家对供应商的评审汇总结果
	private Map<String, ExpertEvaluationResult> expertEvaluationResultMap;
//	private User curUser;
	private boolean hasFactorWeight = false;;
	private boolean hasBidPriceTotal = false;
	private int scoreRound = 2;

	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public PriceScoreResultTableComposite(Composite parent, int style) {
		super(parent, style);
		GridLayout gridLayout = new GridLayout(1, false);
		gridLayout.marginHeight = 0;
		gridLayout.marginWidth = 0;
		setLayout(gridLayout);
		
		evaluationComposite = new Composite(this, SWT.NONE);
		evaluationComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		evaluationComposite.setBackground(ColorConstants.BORDER_LINE_COLOR);
		GridLayout gl_evaluationComposite = new GridLayout(1, false);
		gl_evaluationComposite.verticalSpacing = 0;
		gl_evaluationComposite.horizontalSpacing = 0;
		gl_evaluationComposite.marginHeight = 1;
		gl_evaluationComposite.marginWidth = 1;
		evaluationComposite.setLayout(gl_evaluationComposite);
		
		evaluationTableComposite = new Composite(evaluationComposite, SWT.NONE);
		evaluationTableComposite.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		evaluationTableComposite.setLayout(new FillLayout(SWT.HORIZONTAL));
		evaluationTableComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		expertEvaluationResultService = new ExpertEvaluationResultService();
	}
	
	/**
	 * @Description: 初始化
	 * @author guoyr
	 */
	public void refresh(TenderProjectEntity tenderProjectEntity, TenderProjectRuleEntity tenderProjectRuleEntity, Expert curExpert, EvaluationStep evaluationStep, List<Supplier> supplierList){
		this.tenderProjectEntity = tenderProjectEntity;
		this.tenderProjectRuleEntity = tenderProjectRuleEntity;
		this.CURRENT_EXPERT = curExpert;
		this.evaluationStep = evaluationStep;
		this.supplierList = supplierList;
		scoreRound = tenderProjectRuleEntity.getScoreRoundIntVal();
		supplierName = com.gx.obe.components.core.I18N.getString(I18NEnum.SUPPLIERNAME, tenderProjectEntity.getTenderType());
		hasBidPriceTotal = evaluationFactorService.hasTotalBidPriceFactor(tenderProjectEntity.getId(), null);
		drawLeftSupplierEvaluationTable();
	}
	
	/**
	 * @Description: 初始化当前评标步骤的评审指标
	 * @author guoyr
	 */
	private void initEvaluationStepFactor(){
		evaluationFactorList.clear();
		maxLevel = 1;
		List<EvaluationFactor> evaluationTopFactorList = evaluationFactorService.getEvaluationStepFactorTreeList(tenderProjectEntity.getId(), evaluationStep);
		hasFactorWeight = false;
		if(null != evaluationTopFactorList && evaluationTopFactorList.size() > 0){
			for(EvaluationFactor topFactor : evaluationTopFactorList){
				// 当前评标步骤是否存在权重
				if(null != topFactor.getFactorWeight() && (topFactor.getFactorWeight().compareTo(BigDecimal.ZERO) >0 && topFactor.getFactorWeight().compareTo(new BigDecimal(100)) < 0)){
					hasFactorWeight = true;
				}
				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);
		}
	}
	
	/**
	 * @Description: 初始化评标结果
	 * @author guoyr 
	 */
	private void initEvaluationResult(){
		if(null == bidPriceResultService){
			bidPriceResultService = new BidPriceResultService();
		}
		initEvaluationStepFactor();
		if(null == evaluationFactorList)evaluationFactorList = new ArrayList<EvaluationFactor>();
		priceEvaluationFactorList = new ArrayList<PriceEvaluationFactor>();
		
		// 记录供应商每个指标的评审结果
		supplierEvaluationFactorResultMap = new HashMap<String, Map<String, EvaluationFactorResult>>();
		
		// 记录专家对供应商的评审汇总结果
		expertEvaluationResultMap = new HashMap<String, ExpertEvaluationResult>();
		
		// 评审当前评标专家所有的评标结果
		List<EvaluationFactorResult> expertEvaluateFactorResultList = evaluationFactorResultService.getExpertEvaluationFactorResult(tenderProjectEntity.getId(), evaluationStep.getId(), CURRENT_EXPERT.getUserId(), null);
		
		List<ExpertEvaluationResult> queryExpertEvaluationResultList = expertEvaluationResultService.getExpertStepAllSupplierEvaluationResultList(tenderProjectEntity.getId(), evaluationStep.getId(), CURRENT_EXPERT.getUserId());
		
		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;
					}
				}
			}
			if(null == expertEvaluationResult){
				expertEvaluationResult = new ExpertEvaluationResult();
				expertEvaluationResult.setTenderId(tenderProjectEntity.getId());
				expertEvaluationResult.setStepId(evaluationStep.getId());
				expertEvaluationResult.setUserId(CURRENT_EXPERT.getUserId());
				expertEvaluationResult.setSupplierId(supplier.getId());
			}
			
			Map<String, EvaluationFactorResult> evaluationFactorResultMap = new HashMap<String, EvaluationFactorResult>();
			for(EvaluationFactor evaluationFactor : evaluationFactorList){
				
				// 获得已评审的结果
				EvaluationFactorResult evaluationFactorResult = null;
				if(null != expertEvaluateFactorResultList && expertEvaluateFactorResultList.size() > 0){
					for(EvaluationFactorResult factorResult : expertEvaluateFactorResultList){
						if(ObjectUtils.equals(supplier.getId(), factorResult.getSupplierId()) && ObjectUtils.equals(evaluationFactor.getId(), factorResult.getFactorId())){
							evaluationFactorResult = factorResult;
							break;
						}
					}
				}
				if(null == evaluationFactorResult){
					evaluationFactorResult = new EvaluationFactorResult();
					evaluationFactorResult.setTenderId(tenderProjectEntity.getId());
					evaluationFactorResult.setStepId(evaluationStep.getId());
					evaluationFactorResult.setUserId(CURRENT_EXPERT.getUserId());
					evaluationFactorResult.setSupplierId(supplier.getId());
					evaluationFactorResult.setFactorId(evaluationFactor.getId());
					evaluationFactorResult.setFactorName(evaluationFactor.getFactorName());
					evaluationFactorResult.setId(UuidUtils.getUUID());
				}
				evaluationFactorResultMap.put(evaluationFactor.getId(), evaluationFactorResult);
				
			}
			expertEvaluationResultMap.put(supplier.getId(), expertEvaluationResult);
			supplierEvaluationFactorResultMap.put(supplier.getId(), evaluationFactorResultMap);
		}
		
		List<BidPrice> bidPriceList = null;
		if(!hasBidPriceTotal){			
			if(null == bidPriceService){
				bidPriceService = new BidPriceService();
			}
			bidPriceList = bidPriceService.getTenderBidPriceList(tenderProjectEntity.getId());
		}
		
		// 记录供应商分项报价的结果
		supplierBidPriceResultMap = new HashMap<String, BidPriceResult>();
		int index = 0;
		for(EvaluationFactor evaluationFactor : evaluationFactorList){
			index ++;
			BidPrice factorBidPrice = null;
			PriceEvaluationFactor priceEvaluationFactorFinalScore = new PriceEvaluationFactor(evaluationFactor);
			if(null != bidPriceList && bidPriceList.size() > 0){
				for(BidPrice bidPrice : bidPriceList){
					// 如果当前指标是分项报价，且已设置公式，则说明对该报价用公式进行价格得分计算
					if(null != evaluationFactor.getBidPriceCode() && evaluationFactor.getBidPriceCode().equals(bidPrice.getBidPriceCode()) && null != evaluationFactor.getComputerParams()){
						factorBidPrice = bidPrice;
						break;
					}
				}
			}
			
			if(null != factorBidPrice){
				List<BidPriceResult> bidPriceResultList = bidPriceResultService.getBidPriceResultList(tenderProjectEntity.getId(), factorBidPrice.getId());
				if(null != bidPriceResultList && bidPriceResultList.size() > 0){
					for(BidPriceResult bidPriceResult : bidPriceResultList){
						supplierBidPriceResultMap.put(bidPriceResult.getSupplierId()+"_"+bidPriceResult.getBidPriceId(), bidPriceResult);
					}
				}
				priceEvaluationFactorFinalScore.setBidPrice(factorBidPrice);
				// 添加报表列
				priceEvaluationFactorList.add(priceEvaluationFactorFinalScore.clone(PriceEvaluationFactor.BID_PRICE));
				// 添加基准价列
				priceEvaluationFactorList.add(priceEvaluationFactorFinalScore.clone(PriceEvaluationFactor.BASE_PRICE));
				priceEvaluationFactorList.add(priceEvaluationFactorFinalScore);
				if(null != evaluationFactor.getFactorWeight()){
					// 添加价格得分列
					priceEvaluationFactorList.add(priceEvaluationFactorFinalScore.clone(PriceEvaluationFactor.PRICE_FINAL_SCORE));
				}
			}else if(null != evaluationFactor.getBidPriceCode() && evaluationFactor.getBidPriceCode().equals(BidPrice.BID_PRICE_TOTAL_CODE)){
				// 添加报价列
				priceEvaluationFactorList.add(priceEvaluationFactorFinalScore.clone(PriceEvaluationFactor.BID_EVAL_PRICE_TOTAL));
				// 添加基准价列
				priceEvaluationFactorList.add(priceEvaluationFactorFinalScore.clone(PriceEvaluationFactor.BASE_PRICE));
				priceEvaluationFactorList.add(priceEvaluationFactorFinalScore);
				if(null != evaluationFactor.getFactorWeight()){
					// 添加价格得分列
					priceEvaluationFactorList.add(priceEvaluationFactorFinalScore.clone(PriceEvaluationFactor.PRICE_FINAL_SCORE));
				}
			}else {
				priceEvaluationFactorList.add(priceEvaluationFactorFinalScore);
				if(null != evaluationFactor.getFactorWeight()){
					// 添加价格得分列
					priceEvaluationFactorList.add(priceEvaluationFactorFinalScore.clone(PriceEvaluationFactor.PRICE_FINAL_SCORE));
				}
			}
		}
	}
	
	/**
	 * @Description: 左边是供应商表格
	 * @author guoyr 
	 */
	private void drawLeftSupplierEvaluationTable(){
		initEvaluationResult();
		if(null != resultKTable && !resultKTable.isDisposed()){
			resultKTable.dispose();
		}
		resultKTable = new KTable(evaluationTableComposite, SWTX.AUTO_SCROLL /*| SWT.FULL_SELECTION */| SWTX.EDIT_ON_KEY);
		
		boolean hasFinalSumScore = false;// 标记是否存在最终得分
		boolean hasSumScore = false;// 标记是否存在得分汇总
		if(evaluationFactorList.size() > 1){
			hasFinalSumScore = true;
			commKTableModel = new CommonKtableCModel(resultKTable, 2, 1, supplierList.size() , priceEvaluationFactorList.size() + (hasFactorWeight ? 3 : 2));
			if(hasFactorWeight){
				hasSumScore = true;
			}
		}else {
			commKTableModel = new CommonKtableCModel(resultKTable, 1, 1, supplierList.size() , priceEvaluationFactorList.size() + 1);
		}
		commKTableModel.addRowSpan(0, 0, commKTableModel.getFixedRowCount());
		
		commKTableModel.setColumnMinWidth(0, 100);
		
		final Map<String, String> tableTitleMap = new HashMap<String, String>();
		
		// 排名列
		final int sortCol = commKTableModel.getColCount() -1;
		commKTableModel.addRowSpan(0, sortCol, commKTableModel.getFixedRowCount());
		commKTableModel.setColumnWidth(sortCol, 40);
		commKTableModel.setColumnMaxWidth(sortCol, 80);
		tableTitleMap.put("0_"+ sortCol, Messages.SortNo);
		// 最终得分列
		final int finalScoreSumCol= hasFinalSumScore?commKTableModel.getColCount() -2:-1;
		if(finalScoreSumCol > 0){
			commKTableModel.setColumnWidth(finalScoreSumCol, 40);
			commKTableModel.setColumnMaxWidth(finalScoreSumCol, 80);
			commKTableModel.addRowSpan(0, finalScoreSumCol, commKTableModel.getFixedRowCount());
			if(hasFactorWeight){
				tableTitleMap.put("0_"+ finalScoreSumCol, Messages.FinalScore);
			}else {
				tableTitleMap.put("0_"+ finalScoreSumCol, Messages.TotalScore);
			}
		}
		// 得分汇总列
		final int scoreSumCol = hasSumScore?commKTableModel.getColCount() -3 : -1;
		if(scoreSumCol > 0){
			commKTableModel.addRowSpan(0, scoreSumCol, commKTableModel.getFixedRowCount());
			commKTableModel.setColumnWidth(scoreSumCol, 40);
			commKTableModel.setColumnMaxWidth(scoreSumCol, 80);
			tableTitleMap.put("0_"+ scoreSumCol, Messages.TotalScore);
		}
		
		tableTitleMap.put("0_0", MessageFormat.format(Messages.Supplier, Messages.Name));
		commKTableModel.addRowSpan(0, 0, commKTableModel.getFixedRowCount());
		int col = commKTableModel.getFixedColumnCount();
		int margerColCount = 0;
		String preFactorId = null;
		for(PriceEvaluationFactor priceEvaluationFactor : priceEvaluationFactorList){
			EvaluationFactor evaluationFactor = priceEvaluationFactor.getEvaluationFactor();
			if(commKTableModel.getFixedRowCount() > 1){
				if(null == preFactorId){
					preFactorId = evaluationFactor.getId();
				}
				commKTableModel.setColumnWidth(col, 40);
				tableTitleMap.put("0_"+col, evaluationFactor.getFactorName());
				if(null != preFactorId && !evaluationFactor.getId().equals(preFactorId)){
					commKTableModel.addColSpan(0, col - margerColCount, margerColCount);
					margerColCount = 0;
					preFactorId = evaluationFactor.getId();
				}
				margerColCount ++;
			}
			if(priceEvaluationFactor.getFactorType() == PriceEvaluationFactor.BID_PRICE || priceEvaluationFactor.getFactorType() == PriceEvaluationFactor.BID_EVAL_PRICE_TOTAL){
				BidPrice bidPrice = priceEvaluationFactor.getBidPrice();
				String priceUnit = null != tenderProjectRuleEntity ? ("\r\n("+ tenderProjectRuleEntity.getEvalPriceUnit()+")") : "";
				if(null != bidPrice && BidPriceEnum.IS_RATE.equals(bidPrice.getPriceType())) {
					priceUnit = "("+bidPrice.getPriceUnitCN("%")+")";
				}
				tableTitleMap.put((commKTableModel.getFixedRowCount() -1)+"_"+col, Messages.EvaluationPrice+priceUnit);
			}else if(priceEvaluationFactor.getFactorType() == PriceEvaluationFactor.BASE_PRICE){
				BidPrice bidPrice = priceEvaluationFactor.getBidPrice();
				String priceUnit = null != tenderProjectRuleEntity ? ("\r\n("+ tenderProjectRuleEntity.getEvalPriceUnit()+")") : "";
				if(null != bidPrice && BidPriceEnum.IS_RATE.equals(bidPrice.getPriceType())) {
					priceUnit = "("+bidPrice.getPriceUnitCN("%")+")";
				}
				tableTitleMap.put((commKTableModel.getFixedRowCount() -1)+"_"+col, Messages.BasePrice+priceUnit);
				commKTableModel.addRowSpan(commKTableModel.getFixedRowCount(), col, supplierList.size());
			}else if(priceEvaluationFactor.getFactorType() == PriceEvaluationFactor.PRICE_SCORE){
				tableTitleMap.put((commKTableModel.getFixedRowCount() -1)+"_"+col, Messages.PriceScore);
			}else if(priceEvaluationFactor.getFactorType() == PriceEvaluationFactor.PRICE_FINAL_SCORE){
				if(null != evaluationFactor.getFactorFinalWeight()){
					tableTitleMap.put((commKTableModel.getFixedRowCount() -1)+"_"+col, Messages.WeightScore +"\r\n(" + NumberFormat.getInstance().format(evaluationFactor.getFactorFinalWeight())+"%)");
				}else {
					tableTitleMap.put((commKTableModel.getFixedRowCount() -1)+"_"+col, Messages.PriceScore);
					// 如果存在多个指标（多表头），且当前指标是分值录入的指标，且没有权重，则合并行
					if(margerColCount == 1 && commKTableModel.getFixedRowCount() > 1){
						commKTableModel.addRowSpan(0, col, commKTableModel.getFixedRowCount());
					}
				}
			}
			col ++;
		}
		if(margerColCount > 0){
			commKTableModel.addColSpan(0, col - margerColCount, margerColCount);
		}
		
		// 设置单元格渲染器
		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);
		
		// 设置单元格内容
		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() + priceEvaluationFactorList.size()){
						
						PriceEvaluationFactor priceEvaluationFactor = priceEvaluationFactorList.get(col - commKTableModel.getFixedColumnCount());
						EvaluationFactor evaluationFactor = priceEvaluationFactor.getEvaluationFactor();
						BidPrice bidPrice = priceEvaluationFactor.getBidPrice();
						if(priceEvaluationFactor.getFactorType() == PriceEvaluationFactor.BID_EVAL_PRICE_TOTAL){
							SupplierOpeningResult supplierOpeningResult = supplier.getSupplierOpeningResult();
							if(null != supplierOpeningResult && null != supplierOpeningResult.getEvaluationPrice()){
								if(null != bidPrice && BidPriceEnum.IS_RATE.equals(bidPrice.getPriceType())) {
									return NumberFormatUtils.format(supplierOpeningResult.getEvaluationPrice());
								}else {
									return supplierOpeningResult.getFormatEvaluatoinPriceByUnit(tenderProjectRuleEntity.getEvalPriceUnit());
								}
							}
						}else if(priceEvaluationFactor.getFactorType() == PriceEvaluationFactor.BID_PRICE){
							if(null != bidPrice){
								BidPriceResult bidPriceResult = supplierBidPriceResultMap.get(supplier.getId()+"_"+bidPrice.getId());
								if(null != bidPriceResult && null != bidPriceResult.getEvaluationPrice()){
									if(null != bidPrice && BidPriceEnum.IS_RATE.equals(bidPrice.getPriceType())) {
										return NumberFormatUtils.format(bidPriceResult.getEvaluationPrice());
									}else {
										return MoneyUtils.getMoneyFormatByUnit(bidPriceResult.getEvaluationPrice(), tenderProjectRuleEntity.getEvalPriceUnit());
									}
								}
							}
						}else {
							EvaluationFactorResult evalFactorResult = supplierEvaluationFactorResultMap.get(supplier.getId()).get(evaluationFactor.getId());
							if(priceEvaluationFactor.getFactorType() == PriceEvaluationFactor.BASE_PRICE){
								if(null != evalFactorResult.getBasePrice()){
									if(null != bidPrice && BidPriceEnum.IS_RATE.equals(bidPrice.getPriceType())) {
										return NumberFormatUtils.format(evalFactorResult.getBasePrice());
									}else {
										return MoneyUtils.getMoneyFormatByUnit(evalFactorResult.getBasePrice(), tenderProjectRuleEntity.getEvalPriceUnit());
									}
								}
							}else  if(priceEvaluationFactor.getFactorType() == PriceEvaluationFactor.PRICE_SCORE){
								if(null != evalFactorResult.getEvaluationScore()){
									return NumberFormatUtils.format(evalFactorResult.getEvaluationScore(), scoreRound);
								}
							}else if(priceEvaluationFactor.getFactorType() == PriceEvaluationFactor.PRICE_FINAL_SCORE){
								if(null != evalFactorResult.getEvaluationFinalScore()){
									return NumberFormatUtils.format(evalFactorResult.getEvaluationFinalScore(), scoreRound);
								}
							}
						}
					}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);
		
		// 编辑单元格对齐方式
		CellAlignmentRender cellAlignmentRender = new CellAlignmentRender(){
			public int receiveCellAlignment(int row, int col) {
				if(row < commKTableModel.getFixedRowCount()){
					return SWTX.ALIGN_VERTICAL_CENTER | SWTX.ALIGN_HORIZONTAL_CENTER;
				}else {
					if(col < commKTableModel.getFixedColumnCount()){
						return SWTX.ALIGN_VERTICAL_CENTER | SWTX.ALIGN_HORIZONTAL_LEFT;
					}else if(col < commKTableModel.getFixedColumnCount() + priceEvaluationFactorList.size()){
						PriceEvaluationFactor priceEvaluationFactor = priceEvaluationFactorList.get(col - commKTableModel.getFixedColumnCount());
						if(priceEvaluationFactor.getFactorType() == PriceEvaluationFactor.BID_EVAL_PRICE_TOTAL){
							return SWTX.ALIGN_VERTICAL_CENTER | SWTX.ALIGN_HORIZONTAL_RIGHT;
						}else if(priceEvaluationFactor.getFactorType() == PriceEvaluationFactor.BID_PRICE){
							return SWTX.ALIGN_VERTICAL_CENTER | SWTX.ALIGN_HORIZONTAL_RIGHT;
						}else if(priceEvaluationFactor.getFactorType() == PriceEvaluationFactor.BASE_PRICE){
							return SWTX.ALIGN_VERTICAL_CENTER | SWTX.ALIGN_HORIZONTAL_RIGHT;
						}
					}
				}
				return SWTX.ALIGN_VERTICAL_CENTER | SWTX.ALIGN_HORIZONTAL_CENTER;
			}
		};
		commKTableModel.setCellAlignmentRender(cellAlignmentRender);
		
		// 设置单元格内容
		CellTooltipRender cellTooltipRender = new CellTooltipRender(){
			public String receiveCellTooltip(int row, int col) {
				if(row >= commKTableModel.getFixedRowCount() && col >= commKTableModel.getFixedColumnCount() && col < commKTableModel.getFixedColumnCount() + priceEvaluationFactorList.size()){
					Supplier supplier = supplierList.get(row - commKTableModel.getFixedRowCount());
					PriceEvaluationFactor priceEvaluationFactor = priceEvaluationFactorList.get(col - commKTableModel.getFixedColumnCount());
					EvaluationFactor evaluationFactor = priceEvaluationFactor.getEvaluationFactor();
					EvaluationFactorResult evalFactorResult = supplierEvaluationFactorResultMap.get(supplier.getId()).get(evaluationFactor.getId());
					if(null != evalFactorResult && null != evalFactorResult.getEvaluationOpinion()){
						return evalFactorResult.getEvaluationResult();
					}
				}
				return "";
			}
		};	
		commKTableModel.setCellTooltipRender(cellTooltipRender);
		resultKTable.setModel(commKTableModel);
		evaluationTableComposite.layout();
	}
	
	/** 
	 * @Description: 释放资源
	 * @author guoyr 
	 */
	public void dispose() {
		evaluationFactorList.clear();
		evaluationFactorList = null;
		if(null != priceEvaluationFactorList){
			priceEvaluationFactorList.clear();
			priceEvaluationFactorList = null;
		}
		super.dispose();
	}
	@Override
	
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}
}
