package com.gx.obe.management.composite;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
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.CallBack;
import org.eclipse.swt.graphics.Image;
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.DictEnum;
import com.gx.obe.business.enumeration.SupplierEnum;
import com.gx.obe.common.dialog.ImportBidPriceFromExcelDialog;
import com.gx.obe.common.icons.IconsActivator;
import com.gx.obe.common.widget.dialog.MessageViewDialog;
import com.gx.obe.components.core.Constants;
import com.gx.obe.components.core.I18N;
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.report.poi.Excel;
import com.gx.obe.report.poi.ExcelRow;
import com.gx.obe.util.utils.BigDecimalUtils;
import com.gx.obe.util.utils.CollectionUtils;
import com.gx.obe.util.utils.ObjectUtils;
import com.gx.obe.util.utils.StringUtils;
import com.gx.obe.web.entity.DictionaryValue;
import com.gx.obe.web.entity.Supplier;
import com.gx.obe.web.entity.SupplierOpeningResult;
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.utils.DictionaryUtils;
import com.gx.utils.NowTimeUtils;
import com.swtdesigner.ResourceManager;
import com.swtdesigner.SWTResourceManager;

import de.kupzog.ktable.KTable;
import de.kupzog.ktable.SWTX;
import de.kupzog.ktable.editors.KTableCellEditorText;
import de.kupzog.ktable.model.CommonKtableCModel;
import de.kupzog.ktable.renderers.CellAlignmentRender;
import de.kupzog.ktable.renderers.CellContentRender;
import de.kupzog.ktable.renderers.CellEditContentRender;
import de.kupzog.ktable.renderers.CellEditorRender;
import de.kupzog.ktable.renderers.CellImageRender;
import de.kupzog.ktable.renderers.CellRender;
import de.kupzog.ktable.renderers.FixedCellRenderer;
import de.kupzog.ktable.renderers.TextCellRenderer;

/**
 * @Description: 投标总报价管理
 * @author guoyr
 */
public class SubBidPriceTableComposite extends Composite implements IBidPriceResultTable{
	
//	private SupplierService supplierService = new SupplierService();
	private BidPriceResultService bidPriceResultService = new  BidPriceResultService();
	private TenderProjectEntity tenderProject;
	private TenderProjectRuleEntity projectRule;
	private List<Supplier> supplierList = new ArrayList<Supplier>();
	private KTable bidPriceTable;
	private CommonKtableCModel commKTableModel;
	private Map<String, BidPriceResult> supplierBidPriceResultMap;
	private String SUPPLIER_NAME;
	private List<BidPrice> bidPriceList;

	
	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public SubBidPriceTableComposite(Composite parent, int style) {
		super(parent, style);
		setBackground(ColorConstants.BORDER_LINE_COLOR);
		GridLayout gridLayout = new GridLayout(1, false);
		gridLayout.verticalSpacing = 0;
		gridLayout.horizontalSpacing = 0;
		gridLayout.marginHeight = 1;
		gridLayout.marginWidth = 1;
		setLayout(gridLayout);
		
		Composite composite = new Composite(this, SWT.NONE);
		composite.setBackgroundMode(SWT.INHERIT_FORCE);
		composite.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		GridLayout gl_composite = new GridLayout(1, false);
		gl_composite.marginHeight = 0;
		gl_composite.marginWidth = 0;
		composite.setLayout(gl_composite);
		
		bidPriceTable = new KTable(composite, SWTX.AUTO_SCROLL | SWT.FULL_SELECTION | SWTX.EDIT_ON_KEY | SWTX.FILL_WITH_LASTCOL);
		bidPriceTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
	}
	
	/** 
	 * @Description: 刷新投标报价
	 * @author guoyr
	 * @param tenderProjectEntity
	 * @param tenderProjectRuleEntity
	 * @param supplierList 
	 */
	public void refreshBidPriceResult(final TenderProjectEntity tenderProject, final TenderProjectRuleEntity projectRule, final List<Supplier> supplierList, final List<BidPrice> bidPriceList, final boolean editable){
		this.tenderProject = tenderProject;
		this.projectRule = projectRule;
		this.supplierList = supplierList;
		this.bidPriceList = bidPriceList;
		SUPPLIER_NAME = com.gx.obe.components.core.I18N.getString(I18NEnum.SUPPLIERNAME, tenderProject.getTenderType());
		
		int colIndex = 1;
		final int currencyNameCol = (++colIndex);
		final int unitCol = (++colIndex);
		final int bidPriceStartIndex = (++colIndex);
		
		commKTableModel = new CommonKtableCModel(bidPriceTable, 1, 0, supplierList.size(), colIndex + bidPriceList.size() + (bidPriceList.size() > 1 ? 1 : 0) + 1);
		final int totalBidPriceCol = bidPriceList.size() > 1 ? bidPriceStartIndex + bidPriceList.size() : -1;
		
		commKTableModel.setContentRowHeight(Constants.ROW_HIGHT);
		commKTableModel.setColumnWidth(0, 50);
		commKTableModel.setColumnMaxWidth(0, 50);
		commKTableModel.setColumnWidth(1, 200);
		if(currencyNameCol > 0){
			commKTableModel.setColumnWidth(currencyNameCol, 80);
		}
		if(unitCol > 0){
			commKTableModel.setColumnWidth(unitCol, 80);
		}
		
		if(bidPriceList.size() > 3){
			for(int col = 0; col < bidPriceList.size(); col ++){
				commKTableModel.setColumnWidth(col +bidPriceStartIndex, 100);
			}
			bidPriceTable.setAutoComputerSurplusWidth(true);
		}else {
			for(int col = 0; col < bidPriceList.size(); col ++){
				commKTableModel.setColumnWidth(col +bidPriceStartIndex, 150);
			}
			bidPriceTable.setAutoComputerSurplusWidth(false);
		}
		
		if(totalBidPriceCol > 0){
			commKTableModel.setColumnWidth(totalBidPriceCol, 200);
		}
		
		supplierBidPriceResultMap = new HashMap<String, BidPriceResult>();
		Map<String, BidPriceResult> queryBidPriceResultMap = new HashMap<String, BidPriceResult>();
		List<BidPriceResult> bidPriceResultList = bidPriceResultService.getBidPriceResultList(tenderProject.getId(), null);
		if(CollectionUtils.isNotNull(bidPriceResultList)){
			for(BidPriceResult bidPriceResult : bidPriceResultList){
				queryBidPriceResultMap.put(bidPriceResult.getSupplierId()+"_"+bidPriceResult.getBidPriceId(), bidPriceResult);
			}
		}
		for(Supplier supplier : supplierList){
			BigDecimal bidPriceSum = null;
			for(BidPrice bidPrice : bidPriceList){
				BidPriceResult bidPriceResult = queryBidPriceResultMap.get(supplier.getId()+"_"+bidPrice.getId());
				if(null == bidPriceResult){
					bidPriceResult = new BidPriceResult();
					bidPriceResult.setTenderId(bidPrice.getTenderId());
					bidPriceResult.setBidPriceId(bidPrice.getId());
					bidPriceResult.setSupplierId(supplier.getId());
					bidPriceResult.setBidPriceName(bidPrice.getBidPriceName());
					bidPriceResult.setBidPriceType(BidPriceEnum.IS_PRICE_ITEM);
				}else if(null != bidPriceResult.getBidPrice()){
					if(BidPriceEnum.JOIN_TOTAL.equals(bidPrice.getJoinTotal())){
						bidPriceSum = BigDecimalUtils.add(bidPriceSum, bidPriceResult.getBidPrice());
					}
				}
				if(StringUtils.isEmpty(bidPriceResult.getPriceUnit())){
					bidPriceResult.setPriceUnit(projectRule.getPriceUnitUseDefault());
				}
				if(StringUtils.isEmpty(bidPriceResult.getCurrencyCode())){
					
					bidPriceResult.setCurrencyCode(projectRule.getCurrencyCode());
				}
				if(StringUtils.isEmpty(bidPriceResult.getCurrencyName())){
					bidPriceResult.setCurrencyName(projectRule.getCurrencyName());
				}
				bidPriceResult.setJoinTotal(bidPrice.getJoinTotal());
				bidPriceResult.setBidPriceName(bidPrice.getBidPriceName());
				supplierBidPriceResultMap.put(supplier.getId() + "_" + bidPrice.getId(), bidPriceResult);
			}
		}
		
		final boolean isMoney = !MoneyUtils.PRICE_PERENT.equals(projectRule.getEvalPriceUnit());
		
		// 设置单元格内容
		CellContentRender contentRender = new CellContentRender(){
			public Object receiveContent(int row, int col) {
				if(row < commKTableModel.getFixedRowCount()){
					if(col == 0){
						return Messages.Num ;
					}else if(col == 1){
						return I18N.getString(I18NEnum.SUPPLIERNAME, tenderProject.getTenderType());
					} else if (col == currencyNameCol) {
						return isMoney ? Messages.Currency : Messages.Rate;
					} else if (col == unitCol) {
						return Messages.Unit;
					}else if(col >= bidPriceStartIndex && col < bidPriceStartIndex + bidPriceList.size()){
						BidPrice bidPrice = bidPriceList.get(col - bidPriceStartIndex);
						if(null != bidPrice){
							return ObjectUtils.getObjString(bidPrice.getBidPriceName());
						}
					} else if(col == totalBidPriceCol){
						return Messages.BidPriceTotal;
					}
					return "";
				}else {
					if(col == 0){
						return row +"";
					}else{
						Supplier supplier = supplierList.get(row - commKTableModel.getFixedRowCount());
						if(col == 1){
							return supplier.getSupplierName();
						} else if (col == currencyNameCol) {
							BidPriceResult bidPriceResult = null;
							if (null != bidPriceList && bidPriceList.size() != 0) {
								bidPriceResult = supplierBidPriceResultMap.get(supplier.getId() + "_" + bidPriceList.get(0).getId());
							}
							if(null != bidPriceResult){
								if(StringUtils.isNotEmpty(bidPriceResult.getCurrencyName())){
									return bidPriceResult.getCurrencyName();
								}
								if(StringUtils.isNotEmpty(bidPriceResult.getCurrencyCode())){
									DictionaryValue currency = DictionaryUtils.getDictValue(DictEnum.DIC_CURRENCY, bidPriceResult.getCurrencyCode());
									if (null != currency) {
										return ObjectUtils.getObjString(currency.getDictValueName());
									}
								}
							}
						} else if (col == unitCol) {
							BidPriceResult bidPriceResult = null;
							if (null != bidPriceList && bidPriceList.size() != 0) {
								bidPriceResult = supplierBidPriceResultMap.get(supplier.getId() + "_" + bidPriceList.get(0).getId());
							}
							if(null != bidPriceResult){
								return bidPriceResult.getPriceUnit(projectRule.getPriceUnitUseDefault());
							}
						}else if(col >= bidPriceStartIndex && col < bidPriceStartIndex + bidPriceList.size()){
							BidPrice bidPrice = bidPriceList.get(col -bidPriceStartIndex);
							if (null != bidPrice) {
								BidPriceResult priceResult = supplierBidPriceResultMap.get(supplier.getId() + "_" + bidPrice.getId());
								if (null != priceResult && null != priceResult.getBidPrice(priceResult.getFinalBidPrice())) {
									return priceResult.getFormatFinalBidPriceByUnit(projectRule.getPriceUnitUseDefault());
								}
							}
						} else if (col == totalBidPriceCol) {
							SupplierOpeningResult supplierOpeningResult = supplier.getSupplierOpeningResult();
							if (null != supplierOpeningResult) {
								return supplierOpeningResult.getFinalBidPriceWithUnit(projectRule.getPriceUnitUseDefault());
							}
						}
					}
				}
				return "";
			}
		};
		commKTableModel.setCellContentRender(contentRender);
		
		// 设置单元格渲染器
		CellRender cellRender = new CellRender(){
			public Object receiveCellRender(int row, int col) {
				if(commKTableModel.isFixedCell(col, row)){
					return new FixedCellRenderer();
				}else {
					return new TextCellRenderer();
				}
			}
		};
		commKTableModel.setCellRender(cellRender);
		
		// 设置单元格编辑器
		if(editable){
			final KTableCellEditorText text = new KTableCellEditorText();
			text.setSingleClickEdit(true);
			CellEditorRender cellEditorRender = new CellEditorRender(){
				public Object receiveCellEditor(int row, int col) {
					if(row >= commKTableModel.getFixedRowCount() && col >= bidPriceStartIndex && col < bidPriceStartIndex + bidPriceList.size()){
						return text;
					}
					return null;
				}
			};
			commKTableModel.setCellEditorRender(cellEditorRender);
			
			final Image editImage = ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/edit.png");
			// 设置单元格图片
			CellImageRender cellImageRender = new CellImageRender() {
				public Image receiveCellImage(int row, int col) {
					if(row >= commKTableModel.getFixedRowCount() && col >= bidPriceStartIndex && col < bidPriceStartIndex + bidPriceList.size()){
						return editImage;
					}
					return null;
				}
			};
			commKTableModel.setCellImageRender(cellImageRender);
		}
		
		// 编辑单元格内容
		CellEditContentRender editContentRender = new CellEditContentRender(){
			public void receiveContent(int row, int col, Object content) {
				if(row >= commKTableModel.getFixedRowCount() && col >= bidPriceStartIndex && col < bidPriceStartIndex + bidPriceList.size()){
					Supplier supplier = supplierList.get(row - commKTableModel.getFixedRowCount());
					BidPrice bidPrice = bidPriceList.get(col -bidPriceStartIndex);
					if (null != bidPrice) {
						BidPriceResult bidPriceResult = supplierBidPriceResultMap.get(supplier.getId()+"_"+bidPrice.getId());
						BigDecimal bidPriceMoney = MoneyUtils.getMoneyFromText(MoneyUtils.extractDigits(content.toString()), bidPriceResult.getPriceUnit(projectRule.getPriceUnitUseDefault()));
						bidPriceResult.setBidPrice(bidPriceMoney);
						bidPriceResult.setFinalBidPrice(bidPriceMoney);
					}
					SupplierOpeningResult supplierOpeningResult = supplier.getSupplierOpeningResult();
					resetSupplierTotalBidPrice(supplierOpeningResult);
					commKTableModel.setChanged(true);
				}
			}
		};
		commKTableModel.setCellEditContentRender(editContentRender);
		
		// 编辑单元格对齐方式
		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 == 1){
						return SWTX.ALIGN_VERTICAL_CENTER | SWTX.ALIGN_HORIZONTAL_LEFT;
					}else if(col >= bidPriceStartIndex && col < bidPriceStartIndex + bidPriceList.size()){
						return SWTX.ALIGN_VERTICAL_CENTER | SWTX.ALIGN_HORIZONTAL_RIGHT;
					}
					return SWTX.ALIGN_VERTICAL_CENTER | SWTX.ALIGN_HORIZONTAL_CENTER;
				}
			}
		};
		commKTableModel.setCellAlignmentRender(cellAlignmentRender);
		bidPriceTable.setModel(commKTableModel);
	}
	
	/**
	 * @Description: 重新统计投标总价
	 * @author guoyr
	 * @param supplierOpeningResult 
	 */
	private void resetSupplierTotalBidPrice(SupplierOpeningResult supplierOpeningResult){
		BigDecimal bidPriceSum = null;
		for(Entry<String, BidPriceResult> bidPriceResultEntry : supplierBidPriceResultMap.entrySet()){
			if(bidPriceResultEntry.getKey().startsWith(supplierOpeningResult.getSupplierId())){
				BidPriceResult bidPriceResult = bidPriceResultEntry.getValue();
				if(BidPriceEnum.JOIN_TOTAL.equals(bidPriceResult.getToinTotal())){
					bidPriceSum = BigDecimalUtils.add(bidPriceSum, bidPriceResult.getBidPrice());
				}
			}
		}
		supplierOpeningResult.setBidPrice(bidPriceSum);
		supplierOpeningResult.setFinalBidPrice(bidPriceSum);
		supplierOpeningResult.setEvaluationPrice(bidPriceSum);
		bidPriceTable.redraw();
	}
	
	/** 
	 * @Description: 保存
	 * @author guoyr 
	 */
	public boolean saveBidPriceResult(){
		bidPriceTable.closeCellEditor();
		if(null != supplierList && supplierList.size() > 0){
			List<BidPriceResult> bidPriceResultList = new ArrayList<BidPriceResult>();
			for(Entry<String, BidPriceResult> bidPriceResultEntry : supplierBidPriceResultMap.entrySet()){
				BidPriceResult bidPriceResult = bidPriceResultEntry.getValue();
				bidPriceResult.setEvaluationPriceOriginal(null);
				bidPriceResult.setFinalBidPrice(bidPriceResult.getBidPrice());
				bidPriceResult.setEvaluationPrice(bidPriceResult.getBidPrice());
				bidPriceResultList.add(bidPriceResult);
			}
			List<SupplierOpeningResult> supplierOpeningResultList = new ArrayList<SupplierOpeningResult>();
			Date nowDate = NowTimeUtils.getNowDate();
			for(Supplier supplier : supplierList){
				SupplierOpeningResult supplierOpeningResult = supplier.getSupplierOpeningResult();
				supplierOpeningResult.setTenderId(tenderProject.getId());
				supplierOpeningResult.setSupplierId(supplier.getId());
				supplierOpeningResult.setFinalBidPrice(supplierOpeningResult.getBidPrice());
				supplierOpeningResult.setEvaluationPrice(supplierOpeningResult.getBidPrice());
				if(null != supplierOpeningResult.getBidPrice()){
					supplierOpeningResult.setBidOpeningStatus(SupplierEnum.OPENBID_SUCCESS);
					supplierOpeningResult.setPriceBidStatus(SupplierEnum.OPENBID_SUCCESS);
					supplierOpeningResult.setBusinessBidStatus(SupplierEnum.OPENBID_SUCCESS);
					supplierOpeningResult.setTechnologyBidStatus(SupplierEnum.OPENBID_SUCCESS);
					if(null == supplierOpeningResult.getRevokeStatus() || !supplierOpeningResult.getRevokeStatus().equals(SupplierEnum.REVOKE_YES)){
						supplierOpeningResult.setRevokeStatus(SupplierEnum.REVOKE_NO);
					}
					if(null == supplierOpeningResult.getBidOpeningTime()){
						supplierOpeningResult.setBidOpeningTime(nowDate);
					}
				}
				supplierOpeningResultList.add(supplierOpeningResult);
			}
			if(bidPriceResultService.saveSubBidPriceResult(tenderProject.getId(), supplierOpeningResultList, bidPriceResultList, false)){
				commKTableModel.setChanged(false);
				return true;
			}
		}
		return false;
	}
	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}

	public void importBidPrice() {
		Excel excel = new Excel();
		excel.addRow().setHeight(30).addCell().setValue("投标分项报价").setHead(true);
		ExcelRow row = excel.addRow();
		row.setHeight(30);
		row.addCell().setValue("投标人称").setProperty("supplierName").setWidth(300).setHead(true);
		for(BidPrice bidPrice : bidPriceList){
			row.addCell().setValue(bidPrice.getBidPriceName()).setProperty(bidPrice.getBidPriceCode()).setWidth(300).setHead(true);
		}
		for(int i = 0; i < supplierList.size(); i++){
			ExcelRow supplierRow = excel.addRow();
			supplierRow.setHeight(20);
			supplierRow.addCell().setValue(supplierList.get(i).getSupplierName()).setProperty("supplierName").setWidth(300).setHead(true);
			for(BidPrice bidPrice : bidPriceList){
				if(null != bidPrice){
					BidPriceResult bidPriceResult = supplierBidPriceResultMap.get(supplierList.get(i).getId()+"_"+bidPrice.getId());
					if (null!= bidPriceResult) {
						supplierRow.addCell().setValue(bidPriceResult.getBidPriceWithUnit(projectRule.getPriceUnitUseDefault())).setProperty(bidPrice.getBidPriceCode()).setWidth(100).setHead(true);
					}
				}
			}
		}
		ImportBidPriceFromExcelDialog dialog = new ImportBidPriceFromExcelDialog(getShell(), excel, new ImportBidPriceFromExcelDialog.ImportListener() {
			
			public void onImport(List<Map<String, Object>> excelDataList) {
				
				MessageViewDialog messageDialog = new MessageViewDialog(getShell(), -1);
				new ImportSupplierBidPriceThread(excelDataList, messageDialog.getCallBack()).start();
				messageDialog.setTitle("导入投标分项报价");
				messageDialog.open();
			}
		});
		dialog.setTitle("导入投标分项报价");
		dialog.open();
		
	}
	/**
	 * @Description: 重新统计投标总价
	 * @author guoyr
	 * @param supplierOpeningResult 
	 */
	private void resetSupplierTotalBidPriceFunction(SupplierOpeningResult supplierOpeningResult){
		BigDecimal bidPriceSum = null;
		for(Entry<String, BidPriceResult> bidPriceResultEntry : supplierBidPriceResultMap.entrySet()){
			if(bidPriceResultEntry.getKey().startsWith(supplierOpeningResult.getSupplierId())){
				bidPriceSum = BigDecimalUtils.add(bidPriceSum, bidPriceResultEntry.getValue().getBidPrice());
			}
		}
		supplierOpeningResult.setBidPrice(bidPriceSum);
		supplierOpeningResult.setFinalBidPrice(bidPriceSum);
		supplierOpeningResult.setEvaluationPrice(bidPriceSum);
	}
	
	/** 
	 * @Description: 导入本地Excel文件线程
	 * @author guoyr 
	 */
	class ImportSupplierBidPriceThread implements Runnable{
		
		private Thread thread;
		private List<Map<String, Object>> excelDataList;
		private CallBack callBack;
		
		public ImportSupplierBidPriceThread(List<Map<String, Object>> excelDataList, CallBack callBack){
			this.excelDataList = excelDataList;
			this.callBack = callBack;
		}
		
		public void start(){
			thread = new Thread(this);
			thread.setName("导入本地Excel文件线程");
			thread.start();
		}
		
		public void stop(){
			thread = null;
		}
		
		public void run() {
			if(null != excelDataList && excelDataList.size() > 0){
				callBackMsg("获得"+excelDataList.size()+"家要导入的"+SUPPLIER_NAME+"报价信息！");
				
				//set作为容器存贮当前已经存在的供应商名称
//				Set<String> supplierNameSet = new HashSet<String>();
				Map<String,Integer> supplierNameMap = new HashMap<String,Integer>();
				List<SupplierOpeningResult> supplierOpeningResultList = new ArrayList<SupplierOpeningResult>();
				List<BidPriceResult> bidPriceResultList = new ArrayList<BidPriceResult>();
				int index = 0;
				for(Supplier supplier : supplierList){
//					supplierNameSet.add(supplier.getSupplierName().trim());
					supplierNameMap.put(supplier.getSupplierName().trim(), index++);
				}
//				List<SupplierOpeningResult> resultList = new ArrayList<SupplierOpeningResult>();
				Date nowDate = NowTimeUtils.getNowDate();
				// 获得投标人的最大序号
				for(Map<String, Object> map : excelDataList){
					// 投标人名称
					String supplierName = ObjectUtils.getObjString(map.get("supplierName"));
					if(null != supplierNameMap.get(supplierName.trim())){
						//获取各个分项报价信息
						Supplier supplier = supplierList.get(supplierNameMap.get(supplierName.trim()));
						for(BidPrice bidPrice : bidPriceList){
							if(null != bidPrice){
								BidPriceResult bidPriceResult = supplierBidPriceResultMap.get(supplier.getId()+"_"+bidPrice.getId());
								String bidPriceValue = (String)map.get(bidPrice.getBidPriceCode());
								if(null != bidPriceValue && !"".equals(bidPriceValue)){
									try {
										BigDecimal result = MoneyUtils.getMoneyFromText(bidPriceValue, bidPriceResult.getPriceUnit(projectRule.getPriceUnitUseDefault()));
										
										bidPriceResult.setBidPrice(result);
									} catch (Exception e) {
										bidPriceResult.setBidPrice(BigDecimal.ZERO);
									}
								}
								bidPriceResult.setFinalBidPrice(bidPriceResult.getBidPrice());
								bidPriceResultList.add(bidPriceResult);
							}
						}
						resetSupplierTotalBidPriceFunction(supplier.getSupplierOpeningResult());
						
						SupplierOpeningResult supplierOpeningResult = supplier.getSupplierOpeningResult();
						if(null != supplierOpeningResult.getBidPrice()){
							
							supplierOpeningResult.setBidOpeningStatus(SupplierEnum.OPENBID_SUCCESS);
							supplierOpeningResult.setPriceBidStatus(SupplierEnum.OPENBID_SUCCESS);
							supplierOpeningResult.setBusinessBidStatus(SupplierEnum.OPENBID_SUCCESS);
							supplierOpeningResult.setTechnologyBidStatus(SupplierEnum.OPENBID_SUCCESS);
							if(null == supplierOpeningResult.getRevokeStatus() || !supplierOpeningResult.getRevokeStatus().equals(SupplierEnum.REVOKE_YES)){
								supplierOpeningResult.setRevokeStatus(SupplierEnum.REVOKE_NO);
							}
							if(null == supplierOpeningResult.getBidOpeningTime()){
								supplierOpeningResult.setBidOpeningTime(nowDate);
							}
						}
						supplierOpeningResultList.add(supplierOpeningResult);
					}
				}	
				boolean result = bidPriceResultService.saveSubBidPriceResult(tenderProject.getId(), supplierOpeningResultList, bidPriceResultList, false);
				if(result){
					callBackMsg("\r\n√此次成功导入"+ supplierOpeningResultList.size() +Messages.SupplierCouns+SUPPLIER_NAME+"报价！");
				}else{
					callBackMsg("×导入失败！");
				}
				callBackMsg("导入"+SUPPLIER_NAME+"结束！");
				if(null != callBack){
					callBack.after();
				}
			}
		}
		
		private void callBackMsg(String msg){
			if(null != callBack){
				callBack.callBackString(msg);
			}
		}
	}
}
